Author: tchemit Date: 2009-10-08 21:10:44 +0200 (Thu, 08 Oct 2009) New Revision: 1569 Modified: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/CompilerConfiguration.java branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/DefaultCompilerConfiguration.java branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/AbstractJaxxMojo.java branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpMojo.java branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateMojo.java branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/NodeItem.java branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/XmlHelper.java Log: - add encoding on goals (should be in JAXXCompiler) - simplify helpIdsStore (only store ids, path will be computed if needed) - maven-helper-plugin common code Modified: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/CompilerConfiguration.java =================================================================== --- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/CompilerConfiguration.java 2009-10-08 16:48:27 UTC (rev 1568) +++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/CompilerConfiguration.java 2009-10-08 19:10:44 UTC (rev 1569) @@ -122,4 +122,10 @@ * @return {@code true} if compiler is verbose */ boolean isVerbose(); + + /** + * + * @return the encoding to use to write files + */ + String getEncoding(); } Modified: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/DefaultCompilerConfiguration.java =================================================================== --- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/DefaultCompilerConfiguration.java 2009-10-08 16:48:27 UTC (rev 1568) +++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/DefaultCompilerConfiguration.java 2009-10-08 19:10:44 UTC (rev 1569) @@ -86,6 +86,10 @@ * since this class should be in sources (so not yet compiled) */ private String helpBrokerFQN; + /** + * Encoding to use to write files + */ + private String encoding; @Override public File getTargetDirectory() { @@ -182,6 +186,11 @@ } @Override + public String getEncoding() { + return encoding; + } + + @Override public String toString() { return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE); } Modified: branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/AbstractJaxxMojo.java =================================================================== --- branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/AbstractJaxxMojo.java 2009-10-08 16:48:27 UTC (rev 1568) +++ branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/AbstractJaxxMojo.java 2009-10-08 19:10:44 UTC (rev 1569) @@ -32,6 +32,9 @@ */ public abstract class AbstractJaxxMojo extends AbstractPlugin { + public abstract File getTargetDirectory(); + + public abstract void setTargetDirectory(File targetDirectory); /** * Dépendance du projet. * @@ -41,6 +44,13 @@ */ protected MavenProject project; /** + * Encoding pour la generation des fichiers + * + * @parameter expression="${jaxx.encoding}" default-value="${project.build.sourceEncoding}" + * @since 2.0.0 + */ + protected String encoding; + /** * verbose flag * * @parameter expression="${jaxx.verbose}" default-value="false" @@ -52,7 +62,7 @@ * The store of helpIds generated by the goal {@link GenerateMojo} and then * used by the goal {@link GenerateHelpMojo}. * - * @parameter expression="${jaxx.helpIdsStore}" default-value="target/helpIds.properties" + * @parameter expression="${jaxx.helpIdsStore}" default-value="target/generated-sources/jaxx/helpIds.properties" * @required * * @since 1.3 @@ -91,4 +101,12 @@ public void setHelpIdsStore(File helpIdsStore) { this.helpIdsStore = helpIdsStore; } + + public String getEncoding() { + return encoding; + } + + public void setEncoding(String encoding) { + this.encoding = encoding; + } } Modified: branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpMojo.java =================================================================== --- branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpMojo.java 2009-10-08 16:48:27 UTC (rev 1568) +++ branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpMojo.java 2009-10-08 19:10:44 UTC (rev 1569) @@ -18,11 +18,12 @@ *##%*/ package org.nuiton.jaxx.plugin; +import java.io.BufferedReader; import org.apache.maven.plugin.MojoFailureException; import java.io.File; import java.io.FileInputStream; -import java.io.InputStream; +import java.io.InputStreamReader; import java.net.URL; import java.util.ArrayList; import java.util.Enumeration; @@ -185,21 +186,21 @@ checkResource(tocTemplate); checkResource(contentTemplate); - if (!outHelp.exists()) { - getLog().info("mkdir " + outHelp); - outHelp.mkdirs(); + if (!getTargetDirectory().exists()) { + getLog().info("mkdir " + getTargetDirectory()); + getTargetDirectory().mkdirs(); } + // load ids from idsStore file + helpIds = new SortedProperties(); - InputStream stream = new FileInputStream(idsStore); - - try { - helpIds.load(stream); - } finally { - if (stream != null) { - stream.close(); - } + BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(idsStore), getEncoding())); + String id = null; + while ((id = reader.readLine()) != null) { + id = id.trim(); + String path = id.replaceAll("\\.", File.separator) + ".html"; + helpIds.put(id, path); } if (helpIds.isEmpty()) { @@ -208,7 +209,6 @@ getLog().warn("No helpIds detected, will skip."); return false; } - return true; } @@ -235,7 +235,9 @@ localizedTarget.mkdirs(); } getLog().info("Generate help for language " + language); - getLog().info(" Localized target : " + localizedTarget); + if (isVerbose()) { + getLog().info(" Localized target : " + localizedTarget); + } Properties env = new Properties(); @@ -305,6 +307,16 @@ getLog().info(touchedFiles + " file(s) treated."); } + @Override + public File getTargetDirectory() { + return outHelp; + } + + @Override + public void setTargetDirectory(File targetDirectory) { + this.outHelp = targetDirectory; + } + protected int generateContentFiles(File localizedTarget, Properties env, String localePath) throws Exception { int touchedFiles = 0; Modified: branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateMojo.java =================================================================== --- branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateMojo.java 2009-10-08 16:48:27 UTC (rev 1568) +++ branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateMojo.java 2009-10-08 19:10:44 UTC (rev 1569) @@ -27,27 +27,18 @@ import jaxx.compiler.tags.TagManager; import jaxx.runtime.JAXXContext; -import org.apache.maven.artifact.Artifact; -import org.apache.maven.model.Resource; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.project.MavenProject; import org.nuiton.io.FileUpdaterHelper; import org.nuiton.io.MirroredFileUpdater; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; -import java.net.MalformedURLException; import java.util.Map; import java.net.URL; -import java.net.URLClassLoader; -import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; -import java.util.List; -import java.util.Properties; import java.util.Set; import jaxx.runtime.swing.help.JAXXHelpBroker; import org.apache.commons.lang.builder.ToStringBuilder; @@ -336,7 +327,6 @@ return true; } -// if (addSourcesToClassPath || addProjectClassPath) { cl = initClassLoader(project, src, addSourcesToClassPath, @@ -346,10 +336,6 @@ addProjectClassPath); Thread.currentThread().setContextClassLoader(cl); -// } else { -// cl = getClass().getClassLoader(); - //cl = Thread.currentThread().getContextClassLoader(); -// } compilerClass = (Class<? extends JAXXCompiler>) Class.forName(compilerFQN, false, cl); defaultDecoratorClass = (Class<? extends CompiledObjectDecorator>) Class.forName(defaultDecoratorFQN, false, cl); @@ -368,8 +354,8 @@ BeanInfoUtil.addJaxxBeanInfoPath(beanInfoSearchPath); } - if (!outJava.exists()) { - outJava.mkdirs(); + if (!getTargetDirectory().exists()) { + getTargetDirectory().mkdirs(); } // compute extra imports (can not use java classes since some of @@ -442,6 +428,11 @@ } @Override + public void setTargetDirectory(File targetDirectory) { + this.outJava = targetDirectory; + } + + @Override public boolean getOptimize() { return optimize; } @@ -534,16 +525,9 @@ } if (testPhase) { - if (!project.getTestCompileSourceRoots().contains( - outJava.getPath())) { - getLog().info("Add test compile source root : " + outJava); - project.addTestCompileSourceRoot(outJava.getPath()); - } + addTestCompileSourceRoots(getTargetDirectory()); } else { - if (!project.getCompileSourceRoots().contains(outJava.getPath())) { - getLog().info("Add compile source root : " + outJava); - project.addCompileSourceRoot(outJava.getPath()); - } + addCompileSourceRoots(getTargetDirectory()); } } @@ -586,91 +570,18 @@ idsStore.getParentFile().mkdirs(); } - Properties p = new Properties(); + StringBuilder buffer = new StringBuilder(); for (String helpId : helpIds) { - String path = helpId.replaceAll("\\.", File.separator); - path = removeQuote(path) + ".html"; - p.put(removeQuote(helpId), path); + buffer.append(removeQuote(helpId)).append('\n'); } + writeFile(idsStore, buffer.toString(), encoding); - FileOutputStream w = new FileOutputStream(idsStore); - - try { - p.store(w, null); - } finally { - w.close(); - } - getLog().info("helpIdStore generated in " + idsStore); helpIds.clear(); } - //TODO use the AbstractPublig method - @SuppressWarnings({"unchecked"}) - protected URLClassLoader initClasLoader(MavenProject project, org.apache.maven.plugin.logging.Log log) throws MalformedURLException { - URLClassLoader loader = null; - if (project != null) { - - URLClassLoader result; - try { - - List<URL> lUrls = new ArrayList<URL>(); - List<String> sources = project.getCompileSourceRoots(); - - if (addSourcesToClassPath) { - for (String source : sources) { - lUrls.add(new File(source).toURI().toURL()); - } - if (testPhase) { - for (Object source : project.getTestCompileSourceRoots()) { - lUrls.add(new File(source.toString()).toURI().toURL()); - } - } - } - if (addResourcesToClassPath) { - for (Object source : project.getResources()) { - Resource r = (Resource) source; - lUrls.add(new File(r.getDirectory()).toURI().toURL()); - } - } - if (testPhase && addCompileClassPath) { - if (project != null) { - lUrls.add(new File(project.getBuild().getOutputDirectory()).toURI().toURL()); - } - } - if (addProjectClassPath) { - getLog().info("use project compile scope class-path"); - // add also all dependencies of the project in compile scope - Set<?> artifacts = project.getArtifacts(); - for (Object o : artifacts) { - Artifact a = (Artifact) o; - lUrls.add(a.getFile().toURI().toURL()); - } - } - - result = new URLClassLoader(lUrls.toArray(new URL[lUrls.size()]), getClass().getClassLoader()); - - } catch (IOException e) { - throw new RuntimeException("Can't create ClassLoader for reason " + e.getMessage(), e); - } - loader = result; - } else { - List<URL> lUrls = new ArrayList<URL>(); - if (addSourcesToClassPath) { - lUrls.add(src.toURI().toURL()); - } - loader = new URLClassLoader(lUrls.toArray(new URL[lUrls.size()]), getClass().getClassLoader()); - } - if (verbose) { - for (URL entry : loader.getURLs()) { - log.info("classpath : " + entry); - } - } - return loader; - } - protected String removeQuote(String txt) { if (txt.startsWith("\"")) { txt = txt.substring(1); Modified: branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/NodeItem.java =================================================================== --- branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/NodeItem.java 2009-10-08 16:48:27 UTC (rev 1568) +++ branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/NodeItem.java 2009-10-08 19:10:44 UTC (rev 1569) @@ -35,6 +35,10 @@ return childs; } + public void setText(String text) { + this.text = text; + } + public NodeItem findChild(String path) { NodeItem result = null; String[] paths = path.split("\\."); Modified: branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/XmlHelper.java =================================================================== --- branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/XmlHelper.java 2009-10-08 16:48:27 UTC (rev 1568) +++ branches/jaxx-2.X/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/XmlHelper.java 2009-10-08 19:10:44 UTC (rev 1569) @@ -106,7 +106,7 @@ // premier item if (rootItem.getTarget().equals(target)) { // le premier item est bien top - //rootItem.setText(text); + rootItem.setText(text); currentItem = rootItem; } else { // le premier noeud n'est pas top