This is an automated email from the git hooks/post-receive script. New commit to annotated tag v2.0.0-beta-1 in repository jaxx. See https://gitlab.nuiton.org/nuiton/jaxx.git commit 52a8238fb5c6e2693c04a31bb3d3fe3daa225edc Author: Tony Chemit <chemit@codelutin.com> Date: Thu Oct 8 19:10:44 2009 +0000 - add encoding on goals (should be in JAXXCompiler) - simplify helpIdsStore (only store ids, path will be computed if needed) - maven-helper-plugin common code --- .../java/jaxx/compiler/CompilerConfiguration.java | 6 ++ .../compiler/DefaultCompilerConfiguration.java | 9 ++ .../org/nuiton/jaxx/plugin/AbstractJaxxMojo.java | 20 +++- .../org/nuiton/jaxx/plugin/GenerateHelpMojo.java | 40 +++++--- .../java/org/nuiton/jaxx/plugin/GenerateMojo.java | 113 +++------------------ .../main/java/org/nuiton/jaxx/plugin/NodeItem.java | 4 + .../java/org/nuiton/jaxx/plugin/XmlHelper.java | 2 +- 7 files changed, 77 insertions(+), 117 deletions(-) diff --git a/jaxx-compiler/src/main/java/jaxx/compiler/CompilerConfiguration.java b/jaxx-compiler/src/main/java/jaxx/compiler/CompilerConfiguration.java index eee1681..e9cb408 100644 --- a/jaxx-compiler/src/main/java/jaxx/compiler/CompilerConfiguration.java +++ b/jaxx-compiler/src/main/java/jaxx/compiler/CompilerConfiguration.java @@ -122,4 +122,10 @@ public interface CompilerConfiguration { * @return {@code true} if compiler is verbose */ boolean isVerbose(); + + /** + * + * @return the encoding to use to write files + */ + String getEncoding(); } diff --git a/jaxx-compiler/src/main/java/jaxx/compiler/DefaultCompilerConfiguration.java b/jaxx-compiler/src/main/java/jaxx/compiler/DefaultCompilerConfiguration.java index eb06347..64f9c60 100644 --- a/jaxx-compiler/src/main/java/jaxx/compiler/DefaultCompilerConfiguration.java +++ b/jaxx-compiler/src/main/java/jaxx/compiler/DefaultCompilerConfiguration.java @@ -86,6 +86,10 @@ public class DefaultCompilerConfiguration implements CompilerConfiguration { * 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 @@ public class DefaultCompilerConfiguration implements CompilerConfiguration { } @Override + public String getEncoding() { + return encoding; + } + + @Override public String toString() { return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE); } diff --git a/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/AbstractJaxxMojo.java b/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/AbstractJaxxMojo.java index c55360f..3d96a38 100644 --- a/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/AbstractJaxxMojo.java +++ b/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/AbstractJaxxMojo.java @@ -32,6 +32,9 @@ import org.nuiton.plugin.AbstractPlugin; */ public abstract class AbstractJaxxMojo extends AbstractPlugin { + public abstract File getTargetDirectory(); + + public abstract void setTargetDirectory(File targetDirectory); /** * Dépendance du projet. * @@ -41,6 +44,13 @@ public abstract class AbstractJaxxMojo extends AbstractPlugin { */ 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 @@ public abstract class AbstractJaxxMojo extends AbstractPlugin { * 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 abstract class AbstractJaxxMojo extends AbstractPlugin { public void setHelpIdsStore(File helpIdsStore) { this.helpIdsStore = helpIdsStore; } + + public String getEncoding() { + return encoding; + } + + public void setEncoding(String encoding) { + this.encoding = encoding; + } } diff --git a/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpMojo.java b/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpMojo.java index 559c565..9506dbb 100644 --- a/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpMojo.java +++ b/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpMojo.java @@ -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 @@ public class GenerateHelpMojo extends AbstractJaxxMojo { 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 @@ public class GenerateHelpMojo extends AbstractJaxxMojo { getLog().warn("No helpIds detected, will skip."); return false; } - return true; } @@ -235,7 +235,9 @@ public class GenerateHelpMojo extends AbstractJaxxMojo { 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 @@ public class GenerateHelpMojo extends AbstractJaxxMojo { 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; diff --git a/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateMojo.java b/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateMojo.java index 0fcb1e0..1a54e17 100644 --- a/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateMojo.java +++ b/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateMojo.java @@ -27,27 +27,18 @@ import jaxx.compiler.decorators.HelpRootCompiledObjectDecorator; 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 @@ public class GenerateMojo extends AbstractJaxxMojo implements CompilerConfigurat return true; } -// if (addSourcesToClassPath || addProjectClassPath) { cl = initClassLoader(project, src, addSourcesToClassPath, @@ -346,10 +336,6 @@ public class GenerateMojo extends AbstractJaxxMojo implements CompilerConfigurat 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 @@ public class GenerateMojo extends AbstractJaxxMojo implements CompilerConfigurat 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 @@ public class GenerateMojo extends AbstractJaxxMojo implements CompilerConfigurat } @Override + public void setTargetDirectory(File targetDirectory) { + this.outJava = targetDirectory; + } + + @Override public boolean getOptimize() { return optimize; } @@ -534,16 +525,9 @@ public class GenerateMojo extends AbstractJaxxMojo implements CompilerConfigurat } 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 @@ public class GenerateMojo extends AbstractJaxxMojo implements CompilerConfigurat 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); - } - - FileOutputStream w = new FileOutputStream(idsStore); - - try { - p.store(w, null); - } finally { - w.close(); + buffer.append(removeQuote(helpId)).append('\n'); } + writeFile(idsStore, buffer.toString(), encoding); 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); diff --git a/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/NodeItem.java b/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/NodeItem.java index 8408503..3f4a8e6 100644 --- a/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/NodeItem.java +++ b/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/NodeItem.java @@ -35,6 +35,10 @@ public class NodeItem { return childs; } + public void setText(String text) { + this.text = text; + } + public NodeItem findChild(String path) { NodeItem result = null; String[] paths = path.split("\\."); diff --git a/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/XmlHelper.java b/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/XmlHelper.java index d2119df..631f831 100644 --- a/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/XmlHelper.java +++ b/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/XmlHelper.java @@ -106,7 +106,7 @@ public class XmlHelper { // 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 -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.