Author: echatellier Date: 2014-03-19 17:05:54 +0100 (Wed, 19 Mar 2014) New Revision: 3898 Url: http://forge.codelutin.com/projects/isis-fish/repository/revisions/3898 Log: fixes #2119: Replace tools.jar compiler by ecj compiler Call javadoc using introspection. Remove tools.jar Modified: branches/4.0.1/pom.xml branches/4.0.1/src/main/java/fr/ifremer/isisfish/util/CompileHelper.java branches/4.0.1/src/main/java/fr/ifremer/isisfish/util/JavadocHelper.java branches/4.0.1/src/main/resources/i18n/isis-fish_en_GB.properties branches/4.0.1/src/main/resources/i18n/isis-fish_fr_FR.properties Modified: branches/4.0.1/pom.xml =================================================================== --- branches/4.0.1/pom.xml 2014-03-19 12:52:39 UTC (rev 3897) +++ branches/4.0.1/pom.xml 2014-03-19 16:05:54 UTC (rev 3898) @@ -283,11 +283,11 @@ <artifactId>aspectjweaver</artifactId> <version>1.7.4</version> </dependency> - <dependency> + <!-- <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjtools</artifactId> <version>1.7.4</version> - </dependency> + </dependency> --> <dependency> <groupId>net.sourceforge</groupId> @@ -321,10 +321,9 @@ </dependency> <dependency> - <groupId>com.sun</groupId> - <artifactId>tools</artifactId> - <version>1.7.0.13</version> - <scope>compile</scope> + <groupId>org.eclipse.jdt.core.compiler</groupId> + <artifactId>ecj</artifactId> + <version>4.3.1</version> </dependency> <dependency> Modified: branches/4.0.1/src/main/java/fr/ifremer/isisfish/util/CompileHelper.java =================================================================== --- branches/4.0.1/src/main/java/fr/ifremer/isisfish/util/CompileHelper.java 2014-03-19 12:52:39 UTC (rev 3897) +++ branches/4.0.1/src/main/java/fr/ifremer/isisfish/util/CompileHelper.java 2014-03-19 16:05:54 UTC (rev 3898) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2006 - 2012 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin, Chatellier Eric + * Copyright (C) 2006 - 2014 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -41,16 +41,14 @@ import javax.tools.JavaCompiler; import javax.tools.JavaFileObject; import javax.tools.StandardJavaFileManager; -import javax.tools.ToolProvider; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.eclipse.jdt.internal.compiler.tool.EclipseCompiler; import org.nuiton.util.FileUtil; -import com.sun.tools.javac.api.JavacTool; - import fr.ifremer.isisfish.IsisFish; import fr.ifremer.isisfish.datastore.CodeSourceStorage.Location; import fr.ifremer.isisfish.datastore.JavaSourceStorage; @@ -218,14 +216,10 @@ int result = -1000; try { - // look for best available Java compiler (if none, use provided) - JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); - if (compiler == null) { - compiler = JavacTool.create(); - } + // use eclipse ecj compiler + JavaCompiler compiler = new EclipseCompiler(); - // Use system compiler - // JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); + // Get compilation units StandardJavaFileManager fileManager = compiler .getStandardFileManager(null, null, null); Iterable<? extends JavaFileObject> compilationUnits = fileManager @@ -234,9 +228,10 @@ // Options de compilations String classpathAsString = getClassPathAsString(classpath); List<String> args = new ArrayList<String>(); + args.add("-1.7"); args.add("-g"); // Show a description of each use or override of a deprecated member or class. - args.add("-deprecation"); + args.add("-warn:deprecation"); // non standard option args.add("-encoding"); args.add("utf-8"); args.add("-classpath"); Modified: branches/4.0.1/src/main/java/fr/ifremer/isisfish/util/JavadocHelper.java =================================================================== --- branches/4.0.1/src/main/java/fr/ifremer/isisfish/util/JavadocHelper.java 2014-03-19 12:52:39 UTC (rev 3897) +++ branches/4.0.1/src/main/java/fr/ifremer/isisfish/util/JavadocHelper.java 2014-03-19 16:05:54 UTC (rev 3898) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2009 - 2012 Ifremer, Code Lutin, Chatellier Eric + * Copyright (C) 2009 - 2014 Ifremer, Code Lutin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -25,22 +25,25 @@ package fr.ifremer.isisfish.util; +import static org.nuiton.i18n.I18n._; + import java.io.File; import java.io.FileFilter; import java.io.PrintWriter; +import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLClassLoader; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; import org.apache.commons.io.FileUtils; +import org.apache.commons.lang3.reflect.MethodUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.util.FileUtil; -import com.sun.tools.doclets.standard.Standard; -import com.sun.tools.javadoc.Main; - import fr.ifremer.isisfish.IsisFish; import fr.ifremer.isisfish.datastore.FormuleStorage; import fr.ifremer.isisfish.datastore.JavaSourceStorage; @@ -64,9 +67,6 @@ /** Logger for this class. */ private static final Log log = LogFactory.getLog(JavadocHelper.class); - - /** Nom du programme dans les outils JDK. */ - protected static final String JAVADOC_TOOL_NAME = "javadoc"; /** * Generate javadoc of current. @@ -173,6 +173,7 @@ dest.mkdirs(); try { + // Options de compilations String classpathAsString = CompileHelper.getClassPathAsString(classpath); @@ -183,25 +184,51 @@ args.add(dest.getAbsolutePath()); args.add("-link"); - args.add("http://docs.oracle.com/javase/6/docs/api/"); + args.add("http://docs.oracle.com/javase/7/docs/api/"); args.add("-link"); args.add(IsisFish.config.getJavadocURL()); // also add author and version args.add("-author"); args.add("-version"); - + for (File srcFile : filesSrc) { args.add(srcFile.getAbsolutePath()); } - //result = Main.execute(JAVADOC_TOOL_NAME, args.toArray(new String[0])); - result = Main.execute(JAVADOC_TOOL_NAME, out, out, out, - Standard.class.getName(), args.toArray(new String[0])); - + + // can throw error in not run with JDK + ClassLoader cl = Thread.currentThread().getContextClassLoader(); + try { + // TODO echatellier 20140319 : replace with DocumentationTool from java 8 + + // on est obligé de changer le classloader, sinon il ne trouve pas la class + // com.sun.tools.doclets.standard.Standard + File jreHome = new File(System.getProperty("java.home")); + File jreLib = new File(jreHome.getParent(), "lib"); + File toolsJar = new File(jreLib, "tools.jar"); + URLClassLoader toolsJarLoader = new URLClassLoader(new URL[] { toolsJar.toURI().toURL() }); + Thread.currentThread().setContextClassLoader(toolsJarLoader); + + // invocation dynamique pour ne pas embarqué le jar + Class<?> mainTool = toolsJarLoader.loadClass("com.sun.tools.javadoc.Main"); + Method method = mainTool.getMethod("execute", String.class, PrintWriter.class, PrintWriter.class, + PrintWriter.class, String.class, String[].class); + method.invoke(null, "javadoc", out, out, out, + "com.sun.tools.doclets.standard.Standard", args.toArray(new String[0])); + toolsJarLoader.close(); + } catch (Exception ex) { + out.println(_("This function is only available with JDK (not JRE)")); + ex.printStackTrace(out); + result = -1; + } finally { + Thread.currentThread().setContextClassLoader(cl); + } + } catch (Exception eee) { if (log.isWarnEnabled()) { log.warn("Can't generate javadoc", eee); } + result = -1; } return result; } Modified: branches/4.0.1/src/main/resources/i18n/isis-fish_en_GB.properties =================================================================== --- branches/4.0.1/src/main/resources/i18n/isis-fish_en_GB.properties 2014-03-19 12:52:39 UTC (rev 3897) +++ branches/4.0.1/src/main/resources/i18n/isis-fish_en_GB.properties 2014-03-19 16:05:54 UTC (rev 3898) @@ -62,6 +62,7 @@ Stop\ simulation\ plan,\ because\ can't\ call\ afterSimulation\ correctly\ on\ plan\ %s= SubProcess\ start\:\ %s\ %s= Switch\ repository\ type\ to\ none= +This\ function\ is\ only\ available\ with\ JDK\ (not\ JRE)= Try\ to\ log\ on\ %s@%s\:%d= Use\ branches,\ switch\ not\ needed= User\ restart\ simulation\ %s= Modified: branches/4.0.1/src/main/resources/i18n/isis-fish_fr_FR.properties =================================================================== --- branches/4.0.1/src/main/resources/i18n/isis-fish_fr_FR.properties 2014-03-19 12:52:39 UTC (rev 3897) +++ branches/4.0.1/src/main/resources/i18n/isis-fish_fr_FR.properties 2014-03-19 16:05:54 UTC (rev 3898) @@ -62,6 +62,7 @@ Stop\ simulation\ plan,\ because\ can't\ call\ afterSimulation\ correctly\ on\ plan\ %s= SubProcess\ start\:\ %s\ %s= Switch\ repository\ type\ to\ none= +This\ function\ is\ only\ available\ with\ JDK\ (not\ JRE)= Try\ to\ log\ on\ %s@%s\:%d= Use\ branches,\ switch\ not\ needed= User\ restart\ simulation\ %s=