diff --git a/jsystem-assembly/jsystem-install/jsystemGeneric.install4j b/jsystem-assembly/jsystem-install/jsystemGeneric.install4j index 399f71bd..f1aa6c79 100644 --- a/jsystem-assembly/jsystem-install/jsystemGeneric.install4j +++ b/jsystem-assembly/jsystem-install/jsystemGeneric.install4j @@ -90,7 +90,7 @@ - + diff --git a/jsystem-assembly/jsystem-runner/pom.xml b/jsystem-assembly/jsystem-runner/pom.xml index 0c7eb3b1..ad2c9a8c 100644 --- a/jsystem-assembly/jsystem-runner/pom.xml +++ b/jsystem-assembly/jsystem-runner/pom.xml @@ -107,6 +107,10 @@ qdox + + org.codelibs + jhighlight + net.javaprog.jwizz jwizz @@ -203,4 +207,4 @@ - \ No newline at end of file + diff --git a/jsystem-assembly/jsystem-runner/src/main/assembly/runner.xml b/jsystem-assembly/jsystem-runner/src/main/assembly/runner.xml index 1577c537..d0aedee7 100644 --- a/jsystem-assembly/jsystem-runner/src/main/assembly/runner.xml +++ b/jsystem-assembly/jsystem-runner/src/main/assembly/runner.xml @@ -93,6 +93,7 @@ *:logkit:* *:mail:* *:qdox:* + *:jhighlight:* *:serializer:* *:servlet-api:* *:spring:* @@ -170,4 +171,4 @@ - \ No newline at end of file + diff --git a/jsystem-core-projects/jsystemApp/src/main/java/jsystem/treeui/teststable/TestsTableController.java b/jsystem-core-projects/jsystemApp/src/main/java/jsystem/treeui/teststable/TestsTableController.java index ae4f614e..8b822901 100644 --- a/jsystem-core-projects/jsystemApp/src/main/java/jsystem/treeui/teststable/TestsTableController.java +++ b/jsystem-core-projects/jsystemApp/src/main/java/jsystem/treeui/teststable/TestsTableController.java @@ -1300,9 +1300,9 @@ public void getTestCode() { JOptionPane .showMessageDialog( null, - "Can't display test code because java2html.jar is missing.\nIf you wish to view code, please install java2html.jar. For instructions go to http://trac.jsystemtest.org/wiki/DetailedOSProjectsList", + "Can't display test code because JHighlight is missing from the runtime classpath.", "View Test Code warning", JOptionPane.INFORMATION_MESSAGE); - log.log(Level.WARNING, "Fail to load test code because java2html jar is missing. " + e.getMessage()); + log.log(Level.WARNING, "Fail to load test code because JHighlight is missing. " + e.getMessage()); } catch (Exception e) { log.log(Level.WARNING, "Fail to load test code. " + e.getMessage()); } diff --git a/jsystem-core-projects/jsystemCore/pom.xml b/jsystem-core-projects/jsystemCore/pom.xml index b2050501..a38ad652 100644 --- a/jsystem-core-projects/jsystemCore/pom.xml +++ b/jsystem-core-projects/jsystemCore/pom.xml @@ -44,6 +44,10 @@ com.thoughtworks.qdox qdox + + org.codelibs + jhighlight + il.co.top-q.difido difido-reports-common @@ -84,4 +88,4 @@ run - \ No newline at end of file + diff --git a/jsystem-core-projects/jsystemCore/src/main/java/jsystem/extensions/report/html/HtmlCodeWriter.java b/jsystem-core-projects/jsystemCore/src/main/java/jsystem/extensions/report/html/HtmlCodeWriter.java index 8f1040ca..1e27fdc4 100644 --- a/jsystem-core-projects/jsystemCore/src/main/java/jsystem/extensions/report/html/HtmlCodeWriter.java +++ b/jsystem-core-projects/jsystemCore/src/main/java/jsystem/extensions/report/html/HtmlCodeWriter.java @@ -5,11 +5,10 @@ import java.io.File; import java.io.FileNotFoundException; +import java.io.IOException; import java.io.Reader; import java.io.StringReader; import java.io.StringWriter; -import java.io.Writer; -import java.lang.reflect.Method; import java.util.HashMap; import java.util.logging.Level; import java.util.logging.Logger; @@ -19,6 +18,8 @@ import jsystem.runner.loader.LoadersManager; import jsystem.utils.FileUtils; +import org.codelibs.jhighlight.renderer.JavaXhtmlRenderer; + import com.thoughtworks.qdox.JavaDocBuilder; import com.thoughtworks.qdox.model.DocletTag; import com.thoughtworks.qdox.model.JavaClass; @@ -112,7 +113,7 @@ public void close (){ * Get the test code formated as HTML. * @param className the test class name. * @return an html with the code formated. - * @throws Exception when java2html class is missing, the file is not found or other error occurs + * @throws Exception when JHighlight is missing, the file is not found or other error occurs */ public String getCode(String className) throws FileNotFoundException, ClassNotFoundException, Exception { File srcFile = new File(srcDir.getPath(), className.replace('.', File.separatorChar) + ".java"); @@ -122,40 +123,22 @@ public String getCode(String className) throws FileNotFoundException, ClassNotFo throw new FileNotFoundException(srcFile.getPath()); } } - // Create a reader of the raw input text - - // Parse the raw text to a JavaSource object - Class sourceParserClass = LoadersManager.getInstance().getLoader().loadClass("de.java2html.javasource.JavaSourceParser"); - Object sourceParser = sourceParserClass.newInstance(); - Method parseMethod = sourceParserClass.getMethod("parse", File.class); - if (parseMethod == null) { - return ""; - } - Object source = parseMethod.invoke(sourceParser, srcFile); - if (source == null) { - return ""; - } - Class converterClass = LoadersManager.getInstance().getLoader().loadClass("de.java2html.converter.JavaSource2HTMLConverter"); - StringWriter writer = new StringWriter(); - Object converter = converterClass.getConstructor(source.getClass()).newInstance(source); - converterClass.getMethod("convert", Writer.class).invoke(converter, writer); - - -// JavaSource source = null; -// source = new JavaSourceParser().parse(srcFile); - - // Create a converter and write the JavaSource object as Html -// JavaSource2HTMLConverter converter = new JavaSource2HTMLConverter(source); -// StringWriter writer = new StringWriter(); -// converter.convert(writer); String toReturn = "\n" + "\n" + // "\n" + - "\n" + "\n" + writer.toString() + "\n" + "\n"; + "\n" + "\n" + formatSourceAsHtml(srcFile) + "\n" + "\n"; return toReturn; } + + static String formatSourceAsHtml(File srcFile) throws ClassNotFoundException, IOException { + try { + return new JavaXhtmlRenderer().highlight(srcFile.getName(), FileUtils.read(srcFile), "UTF-8", true); + } catch (NoClassDefFoundError e) { + throw new ClassNotFoundException("JHighlight is missing from the runtime classpath", e); + } + } /** * Get the class javadoc diff --git a/jsystem-core-projects/jsystemCore/src/main/java/jsystem/framework/report/RunnerListenersManager.java b/jsystem-core-projects/jsystemCore/src/main/java/jsystem/framework/report/RunnerListenersManager.java index da4a61c6..d67eaa09 100644 --- a/jsystem-core-projects/jsystemCore/src/main/java/jsystem/framework/report/RunnerListenersManager.java +++ b/jsystem-core-projects/jsystemCore/src/main/java/jsystem/framework/report/RunnerListenersManager.java @@ -885,10 +885,10 @@ private void addTestInfo(TName tname, String meaningfulName, Test test, boolean log.log(Level.WARNING, "Fail to load test code because source file is missing. " + e.getMessage()); } catch (ClassNotFoundException e) { reportHtml( - "Can't display test code because java2html.jar is missing.", - "If you wish to view code, please install java2html.jar. For instructions go to JSystem Trac", + "Can't display test code because JHighlight is missing.", + "JHighlight must be available on the runtime classpath to render source code.", true); - log.log(Level.WARNING, "Fail to load test code because java2html jar is missing. " + e.getMessage()); + log.log(Level.WARNING, "Fail to load test code because JHighlight is missing. " + e.getMessage()); } catch (Exception e) { log.log(Level.WARNING, "Fail to load test code. " + e.getMessage()); } diff --git a/jsystem-core-projects/jsystemCore/src/test/java/jsystem/extensions/report/html/HtmlCodeWriterTest.java b/jsystem-core-projects/jsystemCore/src/test/java/jsystem/extensions/report/html/HtmlCodeWriterTest.java new file mode 100644 index 00000000..0697e311 --- /dev/null +++ b/jsystem-core-projects/jsystemCore/src/test/java/jsystem/extensions/report/html/HtmlCodeWriterTest.java @@ -0,0 +1,37 @@ +package jsystem.extensions.report.html; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.FileWriter; + +import org.junit.Test; + +public class HtmlCodeWriterTest { + + @Test + public void testFormatSourceAsHtmlUsesJHighlight() throws Exception { + File source = File.createTempFile("HtmlCodeWriterTest", ".java"); + try { + FileWriter writer = new FileWriter(source); + try { + writer.write("public class HtmlCodeWriterTest {\n"); + writer.write("\tpublic void sampleMethod() {\n"); + writer.write("\t\tString value = \"hello\";\n"); + writer.write("\t}\n"); + writer.write("}\n"); + } finally { + writer.close(); + } + + String html = HtmlCodeWriter.formatSourceAsHtml(source); + + assertTrue(html.contains("sampleMethod")); + assertTrue(html.contains("qdox 1.9.2 + + org.codelibs + jhighlight + 1.1.1 + net.javaprog.jwizz jwizz