Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jsystem-assembly/jsystem-install/jsystemGeneric.install4j
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
<entry location="thirdparty/lib/JainSipApi1.2.jar" fileType="regular" />
<entry location="thirdparty/lib/JainSipRi1.2.jar" fileType="regular" />
<entry location="thirdparty/lib/jars.txt" fileType="regular" />
<entry location="thirdparty/lib/java2html.jar" fileType="regular" />
<entry location="thirdparty/commonLib/jhighlight.jar" fileType="regular" />
<entry location="thirdparty/lib/java-getopt-1.0.12.jar" fileType="regular" />
<entry location="thirdparty/lib/javacsv.jar" fileType="regular" />
<entry location="thirdparty/lib/javadoc_net.sourceforge.jpcap-0.01.16.jar" fileType="regular" />
Expand Down
6 changes: 5 additions & 1 deletion jsystem-assembly/jsystem-runner/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@
<artifactId>qdox</artifactId>

</dependency>
<dependency>
<groupId>org.codelibs</groupId>
<artifactId>jhighlight</artifactId>
</dependency>
<dependency>
<groupId>net.javaprog.jwizz</groupId>
<artifactId>jwizz</artifactId>
Expand Down Expand Up @@ -203,4 +207,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
3 changes: 2 additions & 1 deletion jsystem-assembly/jsystem-runner/src/main/assembly/runner.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
<include>*:logkit:*</include>
<include>*:mail:*</include>
<include>*:qdox:*</include>
<include>*:jhighlight:*</include>
<include>*:serializer:*</include>
<include>*:servlet-api:*</include>
<include>*:spring:*</include>
Expand Down Expand Up @@ -170,4 +171,4 @@

</fileSets>

</assembly>
</assembly>
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
6 changes: 5 additions & 1 deletion jsystem-core-projects/jsystemCore/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
<groupId>com.thoughtworks.qdox</groupId>
<artifactId>qdox</artifactId>
</dependency>
<dependency>
<groupId>org.codelibs</groupId>
<artifactId>jhighlight</artifactId>
</dependency>
<dependency>
<groupId>il.co.top-q.difido</groupId>
<artifactId>difido-reports-common</artifactId>
Expand Down Expand Up @@ -84,4 +88,4 @@
<goal>run</goal> </goals> </execution> </executions> </plugin -->
</plugins>
</build>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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");
Expand All @@ -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 = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n" + "<html><head>\n" +
// "<title></title>\n" +
"</head>\n" + "<body>\n" + writer.toString() + "</body>\n" + "</html>\n";
"</head>\n" + "<body>\n" + formatSourceAsHtml(srcFile) + "</body>\n" + "</html>\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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href=\"http://trac.jsystemtest.org/wiki/DetailedOSProjectsList\">JSystem Trac</a>",
"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());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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("<span"));
assertFalse(html.contains("de.java2html"));
} finally {
source.delete();
}
}
}
5 changes: 5 additions & 0 deletions jsystem-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@
<artifactId>qdox</artifactId>
<version>1.9.2</version>
</dependency>
<dependency>
<groupId>org.codelibs</groupId>
<artifactId>jhighlight</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>net.javaprog.jwizz</groupId>
<artifactId>jwizz</artifactId>
Expand Down