Nuiton-utils-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
May 2009
- 3 participants
- 151 discussions
[Lutinutil-commits] r1537 - in maven-i18n-plugin/trunk: . src/main/java/org src/main/java/org/nuiton src/main/java/org/nuiton/i18n src/main/java/org/nuiton/i18n/plugin src/main/java/org/nuiton/i18n/plugin/parser src/main/java/org/nuiton/i18n/plugin/parser/event src/main/java/org/nuiton/i18n/plugin/parser/impl src/site
by tchemit@users.labs.libre-entreprise.org 13 May '09
by tchemit@users.labs.libre-entreprise.org 13 May '09
13 May '09
Author: tchemit
Date: 2009-05-13 20:32:34 +0000 (Wed, 13 May 2009)
New Revision: 1537
Added:
maven-i18n-plugin/trunk/src/main/java/org/nuiton/
maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/
maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/
maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/AbstractI18nPlugin.java
maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/Bundle.java
maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/Generate.java
maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/Getter.java
maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/I18nArtifact.java
maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/I18nLogger.java
maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/PluginHelper.java
maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/SourceEntry.java
maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/
maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/AbstractI18nParser.java
maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/Parser.java
maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/ParserEvent.java
maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/ParserException.java
maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/event/
maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/event/KeysModifier.java
maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/impl/
maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserJava.java
maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserJavaActionConfig.java
maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserJavaTabConfig.java
maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserJaxx.java
maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserSwixat.java
maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserValidation.java
maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserXml.java
Modified:
maven-i18n-plugin/trunk/pom.xml
maven-i18n-plugin/trunk/src/site/site.xml
Log:
maven-i18n-plugin migrates to nuiton
Modified: maven-i18n-plugin/trunk/pom.xml
===================================================================
--- maven-i18n-plugin/trunk/pom.xml 2009-05-13 20:31:49 UTC (rev 1536)
+++ maven-i18n-plugin/trunk/pom.xml 2009-05-13 20:32:34 UTC (rev 1537)
@@ -10,8 +10,12 @@
<groupId>org.codelutin</groupId>
<artifactId>lutinproject</artifactId>
<version>3.5.4</version>
+ <!--groupId>org.nuiton</groupId>
+ <artifactId>mavenpom</artifactId>
+ <version>1.0.0-SNAPSHOT</version-->
</parent>
+ <groupId>org.nuiton</groupId>
<artifactId>maven-i18n-plugin</artifactId>
<version>1.0.0-SNAPSHOT</version>
@@ -19,20 +23,37 @@
<dependencies>
<dependency>
- <groupId>org.codelutin</groupId>
- <artifactId>lutinprocessor</artifactId>
+ <groupId>org.nuiton</groupId>
+ <artifactId>nuitonprocessor</artifactId>
<version>${processor.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
- <groupId>org.codelutin</groupId>
- <artifactId>lutinpluginutil</artifactId>
- <version>${lutinpluginutil.version}</version>
+ <groupId>org.nuiton</groupId>
+ <artifactId>maven-helper-plugin</artifactId>
+ <version>${helper.version}</version>
<scope>compile</scope>
</dependency>
+ <!-- tests dependencies -->
+
<dependency>
+ <groupId>org.nuiton</groupId>
+ <artifactId>maven-helper-plugin</artifactId>
+ <version>${helper.version}</version>
+ <scope>test</scope>
+ <classifier>tests</classifier>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.6</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-dependency-tree</artifactId>
<version>1.2</version>
@@ -93,15 +114,18 @@
<properties>
- <!-- id du projet du labs -->
- <labs.id>12</labs.id>
+ <redmine.project>nuitonutil</redmine.project>
- <!-- nom du projet sur le labs -->
- <labs.project>lutinutil</labs.project>
+ <processor.version>1.0.0-SNAPSHOT</processor.version>
+ <!-- assuprimer du de l'utilisation de mavenpom -->
+ <labs.id>12</labs.id>
+ <labs.project>lutinutil</labs.project>
<maven.version>2.0.10</maven.version>
- <processor.version>0.18</processor.version>
- <lutinpluginutil.version>0.5</lutinpluginutil.version>
+ <helper.version>1.0.0-SNAPSHOT</helper.version>
+ <helper.licenseName>lgpl_v3</helper.licenseName>
+ <site.home.url>http://lutinutil.labs.libre-entreprise.org</site.home.url>
+ <repository.home.url>http://lutinbuilder.labs.libre-entreprise.org/maven2</repository.home.url>
<lutinutil.version>1.0.6</lutinutil.version>
</properties>
@@ -141,9 +165,9 @@
</build>
+ <!--Site-->
<reporting>
<plugins>
- <!--Site report's plugin-->
<plugin>
<artifactId>maven-plugin-plugin</artifactId>
</plugin>
@@ -155,6 +179,7 @@
<!-- ************************************************************* -->
<!--Source control management-->
+ <!-- a supprimer au passage a mavenpom -->
<scm>
<url>${maven.scm.url}</url>
<connection>${maven.scm.connection}</connection>
@@ -178,36 +203,4 @@
</repository>
</repositories>
- <profiles>
- <!-- perform only on a release stage when using the maven-release-plugin -->
- <profile>
- <id>release-profile</id>
- <activation>
- <property>
- <name>performRelease</name>
- <value>true</value>
- </property>
- </activation>
- <build>
- <plugins>
- <!-- always add license and third-party files to classpath -->
- <plugin>
- <groupId>org.codelutin</groupId>
- <artifactId>maven-license-switcher-plugin</artifactId>
- <version>0.8</version>
- <executions>
- <execution>
- <id>attach-licenses</id>
- <goals>
- <goal>license</goal>
- <goal>third-party</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
- </profile>
- </profiles>
-
</project>
\ No newline at end of file
Copied: maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/AbstractI18nPlugin.java (from rev 1522, maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/AbstractI18nPlugin.java)
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/AbstractI18nPlugin.java (rev 0)
+++ maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/AbstractI18nPlugin.java 2009-05-13 20:32:34 UTC (rev 1537)
@@ -0,0 +1,188 @@
+/*
+ * *##% Plugin maven pour lutini18n
+ * Copyright (C) 2007 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */
+package org.nuiton.i18n.plugin;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.nuiton.i18n.plugin.parser.ParserEvent;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import org.codelutin.i18n.I18n;
+
+/**
+ * Classe permettant d'obenir les parametres pendant les différentes phases
+ * du plugin.
+ *
+ * @author julien
+ */
+public abstract class AbstractI18nPlugin extends AbstractMojo {
+
+ /**
+ * Le nombre de getters détectés pendant le cycle de vie du build.
+ */
+ private static int NB_GETTER_FILES = 0;
+ /**
+ * Répertoire de stockage des fichiers i18n pour la recuperation des fichiers
+ * de traduction entre librairie
+ */
+ protected static final String DIRECTORY_INSTALL = "i18n" + File.separatorChar;
+ /**
+ * Nom du projet.
+ *
+ * @parameter expression="${i18n.artifactId}" default-value="${project.artifactId}"
+ * @readonly
+ */
+ protected String artifactId;
+ /**
+ * Langues des bundles generes.
+ * <p/>
+ *
+ * @parameter expression="${i18n.bundles}" default-value="fr_FR,en_GB"
+ * @required
+ */
+ protected String bundles;
+ /**
+ * Repertoire sources des fichiers i18n.
+ *
+ * @parameter expression="${i18n.src}" default-value="${basedir}/src/main/resources/i18n"
+ * @required
+ */
+ protected File src;
+ /**
+ * Repertoire des fichiers generes i18n.
+ *
+ * @parameter expression="${i18n.out}" default-value="${basedir}/target/generated-sources/i18n"
+ * @required
+ */
+ protected File out;
+ /**
+ * encoding a utiliser pour charger et sauver les bundles
+ *
+ * @parameter expression="${i18n.encoding}" default-value="${project.build.sourceEncoding}"
+ * @required
+ */
+ protected String encoding;
+ /**
+ * Met les fichiers generes dans le repertoire des sources i18n.
+ * <p/>
+ * Note: Par défaut active, pour pouvoir paquager avec les bundles mis a jour.
+ *
+ * @parameter expression="${i18n.genSrc}" default-value="true"
+ */
+ protected boolean genSrc;
+ /**
+ * Active la modification de cle.
+ * <p/>
+ * Note: par defaut, on ne l'active pas (build sur serveur non ui).
+ *
+ * @parameter expression="${i18n.keysModifier}" default-value="false"
+ */
+ protected boolean keysModifier;
+ /**
+ * verbose flag
+ * <p/>
+ * Note: si non renseigne, on utilise la propiété <code>maven.verbose</code>.
+ *
+ * @parameter expression="${i18n.verbose}" default-value="${maven.verbose}"
+ */
+ protected boolean verbose;
+ /**
+ * conserve les anciens fichiers de traduction avec un suffix ~
+ * <p/>
+ * Note: par defaut, on ne l'active pas.
+ *
+ * @parameter expression="${i18n.keepBackup}" default-value="false"
+ */
+ protected boolean keepBackup;
+ /**
+ * ne conserve que les clef scannees (et donc traite tous les fichiers)
+ *
+ * <p/>
+ * Note : par default, on ne l'active car rescanne tous les fichiers.
+ *s
+ * @parameter expression="${i18n.strictMode}" default-value="false"
+ */
+ protected boolean strictMode;
+ /** Liste des évènements */
+ protected List<ParserEvent> events = new ArrayList<ParserEvent>();
+ protected Locale[] locales;
+ /**logger verbeux */
+ protected I18nLogger verboseLog;
+
+ /**
+ * Ajoute un évènement
+ *
+ * @param parserEvent l'évènement d'ajout
+ */
+ protected void addParserEvent(ParserEvent parserEvent) {
+ this.events.add(parserEvent);
+ }
+
+ /**
+ * Supprime un évènement
+ *
+ * @param parserEvent l'évènement de suppression
+ */
+ protected void removeParserEvent(ParserEvent parserEvent) {
+ this.events.remove(parserEvent);
+ }
+
+ public void init() {
+
+ verboseLog = new I18nLogger(this);
+
+ if (verbose) {
+ getLog().info("config - verbose mode is on");
+ }
+ locales = I18n.parseLocales(bundles);
+// bundlesToUse = bundles.split(",");
+// for (int i = 0, j = bundlesToUse.length; i < j; i++) {
+// bundlesToUse[i] = bundlesToUse[i].trim();
+// }
+ }
+
+ public String getArtifactId() {
+ return artifactId;
+ }
+
+ /**
+ *
+ * @return <code>true</code> si des getters ont etes enregistres pendant
+ * le cycle de vie, <code>false</code> sinon.
+ */
+ protected boolean needGeneration() {
+ boolean needGeneration = NB_GETTER_FILES > 0;
+ return needGeneration;
+ }
+
+ /**
+ * Prend en compte qu'un getter a été détecté.
+ *
+ * Cela veut dire qu'un goal de parser a détecté des clefs. Il
+ * faudra donc activer les goal get et gen.
+ */
+ protected void addGetter() {
+ NB_GETTER_FILES++;
+ }
+
+ protected I18nLogger getVerboseLog() {
+ return verboseLog;
+ }
+}
Property changes on: maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/AbstractI18nPlugin.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/Bundle.java (from rev 1522, maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/Bundle.java)
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/Bundle.java (rev 0)
+++ maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/Bundle.java 2009-05-13 20:32:34 UTC (rev 1537)
@@ -0,0 +1,327 @@
+/*
+ * *##% Plugin maven pour lutini18n
+ * Copyright (C) 2007 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */
+package org.nuiton.i18n.plugin;
+
+import java.net.MalformedURLException;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.URL;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Properties;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.ArtifactCollector;
+import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
+import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
+import org.apache.maven.model.Resource;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.MavenProjectBuilder;
+import org.apache.maven.shared.dependency.tree.DependencyNode;
+import org.apache.maven.shared.dependency.tree.DependencyTreeBuilder;
+import org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException;
+import org.codelutin.i18n.bundle.I18nBundleEntry;
+import org.codelutin.i18n.bundle.I18nBundleFactory;
+import org.nuiton.i18n.plugin.PluginHelper.I18nProperties;
+import org.nuiton.util.DependencyUtil;
+import org.codelutin.util.StringUtil;
+
+/**
+ * Créer un bundle pour une application finale.
+ *
+ * Cela génère un merge de tous les fichiers i18n utilisés en un seul.
+ *
+ * On utilise la dépendance sur les artifacts pour connaitre l'ordre le chargement
+ * des bundles.
+ *
+ * Si dans un bundle childs, la valeur de la clef est vide, on conserve alors celui
+ * du parent,
+ *
+ * Ainsi on obtient un bundle dont toutes les clefs sont traduites.
+ *
+ * Le but aussi d'utiliser un unique bundle est de gagner du temps au runtime
+ * car la recherche des bundles devient trop couteuse en temps lorsque l'on a de
+ * nombreuses dépendances (au dessus de 100 deps cela peut prendre plusieurs
+ * secondes, ce qui 'est pas acceptable).
+ *
+ * On a ajoute un second mode d'initialisation dans la clesse I18n pour n'utiliser
+ * qu'un seul bundle et courcircuiter le chargement couteux...
+ * *
+ *
+ * @author chemit
+ * @goal bundle
+ * @phase generate-resources
+ * @execute goal=gen
+ * @requiresProject true
+ * @requiresDependencyResolution runtime
+ *
+ * @since 0.12
+ */
+public class Bundle extends AbstractI18nPlugin {
+
+ /**
+ * Repertoire ou generer les bundles.
+ *
+ * @parameter expression="${i18n.bundleOutputDir}" default-value="${basedir}/target/generated-sources/java/META-INF"
+ * @required
+ */
+ protected File bundleOutputDir;
+ /**
+ * Nom du bundle a generer.
+ *
+ * @parameter expression="${i18n.bundleOutputName}" default-value="${project.artifactId}-i18n"
+ * @required
+ */
+ protected String bundleOutputName;
+ /**
+ * Dependance du projet.
+ *
+ * @parameter default-value="${project}"
+ * @required
+ */
+ protected MavenProject project;
+ /**
+ * Local Repository.
+ *
+ * @parameter expression="${localRepository}"
+ * @required
+ * @readonly
+ */
+ protected ArtifactRepository localRepository;
+ /**
+ * Remote repositories used for the project.
+ *
+ * @parameter expression="${project.remoteArtifactRepositories}"
+ * @required
+ * @readonly
+ */
+ protected List<?> remoteRepositories;
+ /**
+ * Dependency tree builder component.
+ *
+ * @component
+ */
+ protected DependencyTreeBuilder dependencyTreeBuilder;
+ /**
+ * Artifact Factory component.
+ *
+ * @component
+ */
+ protected ArtifactFactory factory;
+ /**
+ * Artifact metadata source component.
+ *
+ * @component
+ */
+ protected ArtifactMetadataSource artifactMetadataSource;
+ /**
+ * Artifact collector component.
+ *
+ * @component
+ */
+ protected ArtifactCollector collector;
+ /**
+ * Maven Project Builder component.
+ *
+ * @component
+ */
+ protected MavenProjectBuilder mavenProjectBuilder;
+ protected I18nArtifact[] i18nArtifacts;
+ protected ClassLoader loader;
+ protected URL[] urls;
+
+ @Override
+ public void init() {
+ super.init();
+
+ if (locales == null || locales.length == 0) {
+ throw new IllegalStateException("il faut au moins une locale declaree (utiliser la propriete 'bundles')");
+ }
+
+ if (!bundleOutputDir.exists()) {
+ bundleOutputDir.mkdirs();
+ }
+
+ try {
+ // calcul des artifacts qui ont un bundle i18n et trie selon les
+ // dependances
+
+ i18nArtifacts = detectI18nArtifacts();
+
+ getLog().info("detected " + i18nArtifacts.length + " i18n artifact(s) : ");
+ for (I18nArtifact a : i18nArtifacts) {
+ getLog().info(" - " + a.getArtifact());
+ }
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+
+ // ajout de repertoire de generation (le parent en fait)
+ // dans les resources du projet
+
+ String newresourceDir = bundleOutputDir.getParentFile().getAbsolutePath();
+
+ List<?> resources = project.getResources();
+ boolean shouldAdd = true;
+ for (Object o : resources) {
+ Resource r = (Resource) o;
+ if (!r.getDirectory().equals(newresourceDir)) {
+ continue;
+ }
+
+ r.addInclude("**/*.properties");
+ shouldAdd = false;
+ break;
+ }
+ if (shouldAdd) {
+ Resource r = new Resource();
+ r.setDirectory(newresourceDir);
+ r.addInclude("**/*.properties");
+ //if (verbose) {
+ getLog().info("add resource " + r);
+ //}
+ project.addResource(r);
+ }
+ }
+
+ @Override
+ public void execute() throws MojoExecutionException, MojoFailureException {
+
+ if ("pom".equals(project.getPackaging()) || "site".equals(project.getPackaging())) {
+ return;
+ }
+
+ long t00 = System.nanoTime();
+
+ init();
+
+ Locale defaultLocale = locales[0];
+ try {
+ for (Locale locale : locales) {
+
+ long t0 = System.nanoTime();
+
+ File bundleOut = PluginHelper.getI18nFile(bundleOutputDir, bundleOutputName, locale, false);
+
+ getLog().info("prepare bundle " + bundleOut.getAbsolutePath());
+
+ I18nProperties propertiesOut = new I18nProperties(encoding, false);
+
+ for (I18nArtifact artifact : i18nArtifacts) {
+ I18nBundleEntry[] bundleEntries = artifact.getBundleEntries(locale, defaultLocale);
+ for (I18nBundleEntry bundleEntry : bundleEntries) {
+
+ bundleEntry.load(propertiesOut);
+
+ if (verbose) {
+ getLog().info("loaded " + bundleEntry.getPath() + " in " + StringUtil.convertTime(t0, System.nanoTime()));
+ }
+ }
+ }
+ propertiesOut.store(bundleOut);
+ if (verbose) {
+ getLog().info("bundle created in " + StringUtil.convertTime(t0, System.nanoTime()) + " (detected sentences : " + propertiesOut.size() + ")");
+ }
+ }
+
+ // ecriture du ficher des definitions i18n (permet de faire une
+ // recherche extact sur un fichier puis d'en deduire les bundles a
+ // charger
+ String f = String.format(I18nBundleFactory.UNIQUE_BUNDLE_DEF, bundleOutputName);
+ File defOut = new File(bundleOutputDir, f);
+ getLog().info("prepare i18n definition " + defOut.getAbsolutePath());
+ Properties p = new Properties();
+ p.setProperty(I18nBundleFactory.BUNDLE_DEF_LOCALES, bundles);
+ p.store(new FileOutputStream(defOut), null);
+
+ if (verbose) {
+ getLog().info("done in " + StringUtil.convertTime(t00, System.nanoTime()));
+ }
+ } catch (IOException e) {
+ getLog().error("File Error I/O ", e);
+ throw new MojoFailureException("File Error I/O ");
+ }
+ }
+
+ /**
+ * Detecte les {@link I18nArtifact} et les retourne dans l'ordre de chargement
+ * dans le système i18n, i.e l'ordre des dependances entre artifacts.
+ *
+ * @return les artifacts i18nables triés par leur ordre de chargement dans le système i18n.
+ *
+ * @throws java.net.MalformedURLException
+ * @throws java.io.IOException
+ * @throws org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException
+ */
+ protected I18nArtifact[] detectI18nArtifacts() throws MalformedURLException, IOException, DependencyTreeBuilderException {
+
+ Map<Artifact, I18nArtifact> dico = new java.util.HashMap<Artifact, I18nArtifact>();
+
+ I18nArtifact i18nArtifact;
+ for (Object o : project.getArtifacts()) {
+ i18nArtifact = new I18nArtifact((Artifact) o);
+ if (i18nArtifact.detectBundles()) {
+ if (verbose) {
+ getLog().info("detected artifact " + i18nArtifact.getArtifact());
+ }
+ dico.put(i18nArtifact.getArtifact(), i18nArtifact);
+ } else {
+ if (getLog().isDebugEnabled()) {
+ getLog().debug("reject artifact " + i18nArtifact.getArtifact());
+ }
+ }
+ }
+
+ ArtifactFilter artifactFilter = new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME);
+
+ DependencyNode rootNode = dependencyTreeBuilder.buildDependencyTree(project, localRepository, factory,
+ artifactMetadataSource, artifactFilter, collector);
+
+ List<Artifact> artifacts = new java.util.ArrayList<Artifact>(dico.keySet());
+
+ DependencyUtil.sortArtifacts(rootNode, artifacts, verbose);
+
+ // l'artifact du projet est traite en dernier car s'il possède des
+ // bundles alors ils doivent etre charge en dernier
+
+ Artifact projectArtifact = project.getArtifact();
+ i18nArtifact = new I18nArtifact(projectArtifact, src.getParentFile());
+
+ if (i18nArtifact.detectBundles()) {
+ if (verbose) {
+ getLog().info("detected artifact " + i18nArtifact.getArtifact());
+ }
+ artifacts.add(i18nArtifact.getArtifact());
+ dico.put(i18nArtifact.getArtifact(), i18nArtifact);
+ }
+
+ I18nArtifact[] result = new I18nArtifact[artifacts.size()];
+ int i = 0;
+ for (Artifact artifact : artifacts) {
+ result[i++] = dico.get(artifact);
+ }
+ return result;
+ }
+}
Property changes on: maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/Bundle.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/Generate.java (from rev 1522, maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/Generate.java)
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/Generate.java (rev 0)
+++ maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/Generate.java 2009-05-13 20:32:34 UTC (rev 1537)
@@ -0,0 +1,113 @@
+/*
+ * *##% Plugin maven pour lutini18n
+ * Copyright (C) 2007 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */
+
+package org.nuiton.i18n.plugin;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.nuiton.i18n.plugin.PluginHelper.I18nProperties;
+import org.nuiton.util.FileUtil;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Locale;
+
+/**
+ * Merge des fichiers de propriétés avec les anciens.
+ *
+ * @author julien
+ * @goal gen
+ * @phase generate-resources
+ * @execute goal=get
+ */
+public class Generate extends AbstractI18nPlugin {
+
+ @Override
+ public void execute() throws MojoExecutionException, MojoFailureException {
+
+ init();
+
+ if (!needGeneration()) {
+ getLog().info("Nothing to generate - all files are up to date.");
+ return;
+ }
+
+ for (Locale bundle : locales) {
+ try {
+ // Merge
+ File bundleSrc = PluginHelper.getI18nFile(src, artifactId, bundle, false);
+ File bundleOut = PluginHelper.getI18nFile(out, artifactId, bundle, false);
+
+ if (bundleSrc.exists()) {
+
+ I18nProperties propertiesSrc = new I18nProperties(encoding).load(bundleSrc);
+
+ I18nProperties propertiesOut = new I18nProperties(encoding);
+
+ if (!strictMode) {
+ // push back in bundle out, all the bundle src keys
+ propertiesOut.putAll(propertiesSrc);
+ }
+ propertiesOut.load(bundleOut);
+
+ // Parcours des clés
+ for (Object key : propertiesOut.keySet()) {
+ Object oldKey = propertiesOut.get(key);
+ Object value = propertiesSrc.get(oldKey);
+
+ // Récupération de la clé si elle a été renommée
+ if (!key.equals(oldKey) && value == null) {
+ value = propertiesSrc.get(key);
+ }
+
+ if (value != null) {
+ propertiesOut.put(key, value);
+ } else {
+ propertiesOut.put(key, "");
+ }
+ }
+
+ //fixme : on devrait laisser le fichier en utf8 ?
+ //propertiesOut.store(bundleOut);
+ propertiesOut.store(new FileOutputStream(bundleOut));
+
+ // Sauvegarde avant copie
+ if (genSrc && keepBackup) {
+ FileUtil.copy(bundleSrc, PluginHelper.getI18nFileBackup(src, artifactId, bundle));
+ }
+
+ getLog().info("merge bundle " + bundleSrc.getAbsolutePath());
+ }
+
+ if (genSrc) {
+ // Copie des fichiers dans les sources
+ FileUtil.copy(bundleOut, bundleSrc);
+ if (verbose) {
+ getVerboseLog().infoAction("copy", bundleSrc.getAbsolutePath());
+ }
+ }
+
+ } catch (IOException e) {
+ getLog().error("File Error I/O ", e);
+ throw new MojoFailureException("File Error I/O ");
+ }
+ }
+ }
+
+}
Property changes on: maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/Generate.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/Getter.java (from rev 1522, maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/Getter.java)
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/Getter.java (rev 0)
+++ maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/Getter.java 2009-05-13 20:32:34 UTC (rev 1537)
@@ -0,0 +1,106 @@
+/*
+ * *##% Plugin maven pour lutini18n
+ * Copyright (C) 2007 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */
+
+package org.nuiton.i18n.plugin;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.codehaus.plexus.util.DirectoryScanner;
+import org.nuiton.i18n.plugin.PluginHelper.I18nProperties;
+import org.nuiton.util.FileUtil;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Locale;
+
+/**
+ * Recupere les différents fichiers des parsers en un fichier de proprietes.
+ *
+ * @author julien
+ * @goal get
+ * @phase generate-resources
+ */
+public class Getter extends AbstractI18nPlugin {
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.maven.plugin.AbstractMojo#execute()
+ */
+ @Override
+ public void execute() throws MojoExecutionException, MojoFailureException {
+
+ init();
+
+ if (!needGeneration()) {
+ if (verbose) {
+ getLog().info("Nothing to generate - all files are up to date.");
+ }
+ return;
+ }
+
+ try {
+ File bundleGetters = new File(out.getAbsolutePath() + File.separatorChar + artifactId + ".properties");
+ bundleGetters.createNewFile();
+
+ DirectoryScanner ds = new DirectoryScanner();
+ ds.setBasedir(out);
+ ds.setIncludes(new String[]{"*.getter"});
+ ds.scan();
+ String[] files = ds.getIncludedFiles();
+
+ // Fusion des fichiers propriétés des différents parsers
+ for (String file : files) {
+ File bundleGetter = PluginHelper.getGetterFile(out, file, false);
+ concactProperties(bundleGetter, bundleGetters);
+ if (genSrc) {
+ bundleGetter.delete();
+ }
+ getLog().info("create bundle " + bundleGetter.getAbsolutePath());
+ }
+
+ // Création des bundles
+ for (Locale bundle : locales) {
+ File bundleOut = PluginHelper.getI18nFile(out, artifactId, bundle, false);
+ FileUtil.copy(bundleGetters, bundleOut);
+ if (verbose) {
+ getVerboseLog().infoAction("generate", bundleOut.getAbsolutePath());
+ }
+ }
+
+ bundleGetters.delete();
+ } catch (IOException e) {
+ getLog().error("File Error I/O ", e);
+ throw new MojoFailureException("File Error I/O");
+ }
+ }
+
+ /**
+ * Concatene deux fichiers de proprietes
+ *
+ * @param in le fichier entrant
+ * @param out le fichier sortant
+ * @throws IOException si problème pendant la sauvegarde ou fichier non trouvé.
+ */
+ protected void concactProperties(File in, File out) throws IOException {
+ I18nProperties propertiesIn = new I18nProperties(encoding).load(in);
+
+ I18nProperties propertiesOut = new I18nProperties(encoding).load(out);
+ propertiesOut.putAll(propertiesIn);
+ propertiesOut.store(out);
+ }
+}
Property changes on: maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/Getter.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/I18nArtifact.java (from rev 1522, maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/I18nArtifact.java)
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/I18nArtifact.java (rev 0)
+++ maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/I18nArtifact.java 2009-05-13 20:32:34 UTC (rev 1537)
@@ -0,0 +1,77 @@
+package org.nuiton.i18n.plugin;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.List;
+import java.util.Locale;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.maven.artifact.Artifact;
+import org.codelutin.i18n.bundle.I18nBundle;
+import org.codelutin.i18n.bundle.I18nBundleEntry;
+import org.codelutin.i18n.bundle.I18nBundleFactory;
+
+/**
+ *
+ * @author chemit
+ * @since 0.12
+ */
+public class I18nArtifact {
+
+ static final Log log = LogFactory.getLog(I18nArtifact.class);
+ protected final Artifact artifact;
+ protected final URL url;
+ protected I18nBundle[] bundles;
+
+ public I18nArtifact(Artifact artifact) throws MalformedURLException {
+ this.artifact = artifact;
+ this.url = artifact.getFile().toURI().toURL();
+ }
+
+ public I18nArtifact(Artifact artifact, File file) throws MalformedURLException {
+ this.artifact = artifact;
+ this.url = file.toURI().toURL();
+ }
+
+ public Artifact getArtifact() {
+ return artifact;
+ }
+
+ public URL getUrl() {
+ return url;
+ }
+
+ public I18nBundleEntry[] getBundleEntries(Locale l, Locale defaultLocale) {
+ if (bundles == null) {
+ throw new NullPointerException("le bundleManager n'a pas ete initialise!");
+ }
+ return I18nBundleFactory.getBundleEntries(l, defaultLocale, bundles);
+ }
+
+ public boolean detectBundles() throws IOException {
+
+ URL[] i18nUrls = I18nBundleFactory.getURLs(url);
+
+ if (i18nUrls == null || i18nUrls.length == 0) {
+ // aucune url sur un fichier de traduction trouve
+ // l'artifact n'est pas i18n.
+ if (log.isDebugEnabled()) {
+ log.debug("no i18n url for artifact " + artifact);
+ }
+ return false;
+ }
+
+ List<I18nBundle> listBundles = I18nBundleFactory.detectBundles(i18nUrls);
+
+ if (listBundles.isEmpty()) {
+ // pas de bundle instancie (cela ne devrait jamias arrive...)
+ return false;
+ }
+
+ this.bundles = listBundles.toArray(new I18nBundle[listBundles.size()]);
+
+ return true;
+ }
+}
Property changes on: maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/I18nArtifact.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/I18nLogger.java (from rev 1522, maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/I18nLogger.java)
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/I18nLogger.java (rev 0)
+++ maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/I18nLogger.java 2009-05-13 20:32:34 UTC (rev 1537)
@@ -0,0 +1,98 @@
+package org.nuiton.i18n.plugin;
+
+import org.apache.maven.plugin.logging.SystemStreamLog;
+
+import java.beans.Introspector;
+import java.io.File;
+
+/**
+ * Le logger utilisé par les mojo.
+ *
+ * @author chemit
+ * @since 0.9
+ */
+public class I18nLogger extends SystemStreamLog {
+
+ /** l'entrée en cours de traitement (pour les parseurs) */
+ private SourceEntry entry;
+
+ /** le fichier en cours de traitement (pour les parseurs) */
+ protected File file;
+
+ /** le prefix du mojo courant a ajouter dans les logs. */
+ protected String parser;
+
+ public I18nLogger(AbstractI18nPlugin parser) {
+ this.parser = "i18n:" + Introspector.decapitalize(parser.getClass().getSimpleName()) + " on " + parser.getArtifactId();
+ }
+
+ @Override
+ public void info(CharSequence content) {
+ print(0, "INFO", null, content.toString());
+ }
+
+ @Override
+ public void debug(CharSequence content) {
+ print(0, "DEBUG", null, content.toString());
+ }
+
+ public void infoEntry(String action, CharSequence content) {
+ print(0, "INFO", action, entry.toString() + (content == null ? "" : " - " + content.toString()));
+ }
+
+ public void infoFile(String action, String content) {
+ print(2, "INFO", action, file.toString() + (content == null ? "" : " - " + content));
+ }
+
+ public void infoAction(String action, String content) {
+ print(2, "INFO", action, (content == null ? "" : " - " + content));
+ }
+
+ private void print(int start, String prefix, String context, String content) {
+ StringBuilder sb = new StringBuilder();
+ sb.append("[").append(prefix).append("] [").append(parser).append("] ");
+
+ for (int i = 0; i < start; i++) {
+ sb.append(' ');
+ }
+ if (context != null) {
+ sb.append("<").append(context).append("> ");
+ }
+ sb.append(content);
+ System.out.println(sb.toString());
+ }
+
+ public void setEntry(SourceEntry entry) {
+ this.entry = entry;
+ }
+
+ /**
+ * Construit une chaine de log formatée.
+ *
+ * @param msg le prefix du message
+ * @param nbFiles le nombre de fichiers actuellement traités
+ * @param time le time de traitement de ce fichier
+ * @param all le temps de traitement de tous les fichiers
+ * @return la chaine de log formatée
+ */
+ public String getLogEntry(String msg, int nbFiles, long time, long all) {
+ long now = System.nanoTime();
+ long delta = now - time;
+ String s = msg;
+ if (time > 0) {
+ s += " (" + PluginHelper.convertTime(delta) + ")";
+ }
+ if (all > 0) {
+ s += "(total time:" + PluginHelper.convertTime(now - all) + ")";
+ }
+ if (nbFiles > 0) {
+ s += " ( ~ " + PluginHelper.convertTime(((now - all) / (nbFiles))) + " / file)";
+ }
+ return s;
+ }
+
+ public void setFile(File file) {
+ this.file = file;
+ }
+
+}
Property changes on: maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/I18nLogger.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/PluginHelper.java (from rev 1522, maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/PluginHelper.java)
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/PluginHelper.java (rev 0)
+++ maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/PluginHelper.java 2009-05-13 20:32:34 UTC (rev 1537)
@@ -0,0 +1,278 @@
+/**
+ * *##% Plugin maven pour lutini18n
+ * Copyright (C) 2007 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*
+ */
+package org.nuiton.i18n.plugin;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FilterOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.text.MessageFormat;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Locale;
+import java.util.Properties;
+import java.util.Vector;
+
+/**
+ * Une classe pour mutualiser toutes les méthodes utiles dans ce plugin.
+ * <p/>
+ * Note : On a dupliqué ici du code de la librairie lutinutil, pour casser la dépendance ver ce projet qui utilise ce plugin
+ * et donc introduit un cycle dans le graphe des dépendances, ce qui n'est pas souhaitable.
+ *
+ * @author chemit
+ */
+public class PluginHelper {
+
+ /**
+ * @param root le repertoire ou sont stockes les fichiers i18n
+ * @param artifactId le nom de l'artifact
+ * @param locale le nom du bundle
+ * @param create <code>true</code> pour creer le fichier si non present
+ * @return le fichier i18n
+ * @throws java.io.IOException si probleme lors de la creation du fichier
+ */
+ public static File getI18nFile(File root, String artifactId, Locale locale, boolean create) throws IOException {
+ File file = new File(root.getAbsolutePath() + File.separatorChar + artifactId + "-" + locale.toString() + ".properties");
+ if (create && !file.exists()) {
+ if (!file.exists()) {
+ file.getParentFile().mkdirs();
+ }
+ file.createNewFile();
+ }
+ return file;
+ }
+
+ /**
+ * @param root le repertoire ou sont stockes les fichiers getter
+ * @param getter le nom du getter
+ * @param create <code>true</code> pour creer le fichier si non present
+ * @return le fichier i18n
+ * @throws java.io.IOException si probleme lors de la creation du fichier
+ */
+ public static File getGetterFile(File root, String getter, boolean create) throws IOException {
+ File file = new File(root.getAbsolutePath() + File.separatorChar + getter);
+ if (create && !file.exists()) {
+ if (!file.exists()) {
+ file.getParentFile().mkdirs();
+ }
+ file.createNewFile();
+ }
+ return file;
+ }
+
+ /**
+ * @param root le repertoire ou sont stockes les fichiers getter
+ * @param getter le nom du getter
+ * @return le fichier i18n
+ */
+ public static File getGetterFileBackup(File root, String getter) {
+ return new File(root.getAbsolutePath() + File.separatorChar + getter + '~');
+ }
+
+ /**
+ * @param root le reertoire ou sont stockes les fichiers i18n
+ * @param artifactId le nom de l'artifact
+ * @param bundle le nom du bundle
+ * @return le fichier i18n de backup
+ */
+ public static File getI18nFileBackup(File root, String artifactId, Locale bundle) {
+ return new File(root.getAbsolutePath() + File.separatorChar + artifactId + "-" + bundle.toString() + ".properties~");
+ }
+
+ /**
+ * Permet de convertir une liste non typee, en une liste typee.
+ * <p/>
+ * La liste en entree en juste bien castee.
+ * <p/>
+ * On effectue une verification sur le typage des elements de la liste.
+ * <p/>
+ * Note : <b>Aucune liste n'est creee, ni recopiee</b>
+ *
+ * @param <O> le type des objets de la liste
+ * @param list la liste a convertir
+ * @param type le type des elements de la liste
+ * @return la liste typee
+ * @throws IllegalArgumentException si un element de la liste en entree n'est
+ * pas en adequation avec le type voulue.
+ */
+ @SuppressWarnings({"unchecked"})
+ static public <O> List<O> toGenericList(List<?> list, Class<O> type) throws IllegalArgumentException {
+ if (list.isEmpty()) {
+ return (List<O>) list;
+ }
+ for (Object o : list) {
+ if (!(type.isAssignableFrom(o.getClass()))) {
+ throw new IllegalArgumentException("can not cast List with object of type " + o.getClass() + " to " + type + " type!");
+ }
+ }
+ return (List<O>) list;
+ }
+ static final protected double[] timeFactors = {1000000, 1000, 60, 60, 24};
+ static final protected String[] timeUnites = {"ns", "ms", "s", "m", "h", "d"};
+
+ static public String convertTime(long value) {
+ return convert(value, timeFactors, timeUnites);
+ }
+
+ static public String convertTime(long value, long value2) {
+ return convertTime(value2 - value);
+ }
+
+ static public String convert(long value, double[] factors, String[] unites) {
+ long sign = value == 0 ? 1 : value / Math.abs(value);
+ int i = 0;
+ double tmp = Math.abs(value);
+ while (i < factors.length && i < unites.length && tmp > factors[i]) {
+ tmp = tmp / factors[i++];
+ }
+
+ tmp *= sign;
+ String result;
+ result = MessageFormat.format("{0,number,0.###}{1}", tmp,
+ unites[i]);
+ return result;
+ }
+
+ /**
+ * Permet d'avoir les fichiers de proprietes tries.
+ *
+ * @author julien
+ * @author chemit
+ */
+ public static class I18nProperties extends Properties {
+
+ private static final long serialVersionUID = -1147150444452577558L;
+ /** l'encoding a utiliser pour lire et ecrire le properties. */
+ protected String encoding;
+ /** un drapeau pour savoir s'il faut enlever l'entete generere */
+ protected boolean removeHeader;
+
+ public I18nProperties(String encoding) {
+ this(encoding, true);
+ }
+
+ public I18nProperties(String encoding, boolean removeHeader) {
+ super();
+ this.encoding = encoding;
+ this.removeHeader = removeHeader;
+ }
+
+ public I18nProperties(Properties defaults) {
+ super(defaults);
+ }
+
+ @Override
+ public synchronized Enumeration<Object> keys() {
+ List<Object> objects = Collections.list(super.keys());
+ Vector<Object> result;
+ try {
+ // Attention, si les clef ne sont pas des string, ca ne marchera pas
+ List<String> list = toGenericList(objects, String.class);
+ Collections.sort(list);
+ result = new Vector<Object>(list);
+ } catch (IllegalArgumentException e) {
+ // keys are not string !!!
+ // can not sort keys
+ result = new Vector<Object>(objects);
+ }
+ return result.elements();
+ }
+
+ /**
+ * Charge le properties a partir d'un fichier.
+ *
+ * @param src le fichier src a charger en utilisant l'encoding declare
+ * @return l'instance du properties
+ * @throws IOException if any io pb
+ */
+ public I18nProperties load(File src) throws IOException {
+ super.load(new InputStreamReader(new FileInputStream(src), encoding));
+ return this;
+ }
+
+ /**
+ * Sauvegarde le properties dans un fichier, sans commentaire et en utilisant l'encoding declare.
+ *
+ * @param dst the fichier de destination
+ * @throws IOException if any io pb
+ */
+ public void store(File dst) throws IOException {
+ if (removeHeader) {
+ super.store(new OutputStreamWriter(new PropertiesDateRemoveFilterStream(new FileOutputStream(dst)), encoding), null);
+ } else {
+ super.store(new FileOutputStream(dst), null);
+ }
+ }
+
+ /**
+ * Sauvegarde le properties dans un fichier, sans commentaire en laissant java encode en unicode.
+ *
+ * @param dst le fichier de destination
+ * @throws IOException if any io pb
+ */
+ public void store(OutputStream dst) throws IOException {
+ if (removeHeader) {
+ super.store(new PropertiesDateRemoveFilterStream(dst), null);
+ } else {
+ super.store(dst, null);
+ }
+ }
+ }
+
+ /**
+ * Un ecrivain qui supprime la premiere ligne rencontree dans le flux.
+ *
+ *
+ * <b>Note: </b> Attention, les performance d'utilisation de cet ecrivain
+ * est problèmatique, car sur de gros fichiers (>1000 entrees) les
+ * performances se degradent serieusement : pour 1200 entrees on arrive à
+ * plus de 5 secondes, alors que sans on a 76 ms! ...
+ *
+ * FIXME : implanter quelque chose de plus performant dans tous les cas
+ */
+ public static class PropertiesDateRemoveFilterStream extends FilterOutputStream {
+
+ private boolean firstLineOver;
+ char endChar;
+
+ public PropertiesDateRemoveFilterStream(OutputStream out) {
+ super(out);
+ firstLineOver = false;
+ String lineSeparator = System.getProperty("line.separator");
+ endChar = lineSeparator.charAt(lineSeparator.length() - 1);
+ }
+
+ @Override
+ public void write(int b) throws IOException {
+ if (!firstLineOver) {
+ char c = (char) b;
+ if (c == endChar) {
+ firstLineOver = true;
+ }
+ } else {
+ out.write(b);
+ }
+ }
+ }
+}
Property changes on: maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/PluginHelper.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/SourceEntry.java (from rev 1522, maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/SourceEntry.java)
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/SourceEntry.java (rev 0)
+++ maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/SourceEntry.java 2009-05-13 20:32:34 UTC (rev 1537)
@@ -0,0 +1,261 @@
+/*
+* *##% Plugin maven pour lutini18n
+ * Copyright (C) 2007 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */
+package org.nuiton.i18n.plugin;
+
+import org.apache.maven.plugin.logging.Log;
+import org.codehaus.plexus.util.DirectoryScanner;
+import org.nuiton.util.FileUpdater;
+
+import java.io.File;
+import java.lang.annotation.Annotation;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * A simple model for a sourceEntry represents by a basedir and includes and/or exlucdes pattern.
+ * <p/>
+ * The class offers the usefull method :
+ * {@link #getIncludedFiles(File, String[], String[])}
+ * <p/>
+ * to obtain the list of files from
+ * the {@link #basedir} directory which respects the {@link #includes} and/or
+ * {@link #excludes} patterns using an internal {@link DirectoryScanner} object.
+ * <p/>
+ * Note : <b>The class does not extends <code>DirectoryScanner</code> since we DO not want
+ * to expose his methods.</b>
+ *
+ * @author tony
+ */
+public class SourceEntry {
+ /**
+ * If you want to restrict use of the entry, set the class name goal to
+ * this property via {@link #setSpecificGoal(String)}.
+ * <p/>
+ * If let to <code>null</code>, all goals can use this entry.
+ */
+ protected String specificGoal = null;
+
+ protected File basedir;
+
+ protected String[] includes;
+ protected String[] excludes;
+ /** Files to be find */
+ protected String[] files;
+
+ protected String[] skipFiles;
+
+ protected String skipMessage;
+
+ protected FileUpdater updater;
+
+ public String[] getExcludes() {
+ return excludes;
+ }
+
+ public void setExcludes(String[] excludes) {
+ this.excludes = excludes;
+ }
+
+ public String[] getIncludes() {
+ return includes;
+ }
+
+ public void setIncludes(String[] includes) {
+ this.includes = includes;
+ }
+
+ public File getBasedir() {
+ return basedir;
+ }
+
+ public void setBasedir(File basedir) {
+ this.basedir = basedir;
+ }
+
+ public String getSpecificGoal() {
+ return specificGoal;
+ }
+
+ public void setSpecificGoal(String specificGoal) {
+ this.specificGoal = specificGoal;
+ }
+
+ public boolean useForGoal(String goal) {
+ return specificGoal == null || specificGoal.equalsIgnoreCase(goal);
+ }
+
+ public boolean hasSrc() {
+ return basedir != null;
+ }
+
+ public boolean hasIncludes() {
+ return includes != null && includes.length > 0;
+ }
+
+ public boolean hasExcludes() {
+ return excludes != null && excludes.length > 0;
+ }
+
+ /**
+ * Test if a file is up to date and not to be treated.
+ * <p/>
+ *
+ * @param file the file path to test
+ * @return <code>true</code> if file is up to date and do not need to be parsed
+ * @see FileUpdater
+ */
+ public final boolean isFileUptodate(File file) {
+ return updater != null && updater.isFileUpToDate(file);
+ }
+
+ public String[] getIncludedFiles(File defaultBasedir, String[] defaultIncludes, String[] defaultExcludes) {
+ // normalized entry
+ if (!hasSrc()) {
+ setBasedir(defaultBasedir);
+ }
+ if (!hasIncludes()) {
+ setIncludes(defaultIncludes);
+ }
+ if (!hasExcludes()) {
+ setExcludes(defaultExcludes);
+ }
+ // init directory scanner
+ DirectoryScanner ds = new DirectoryScanner();
+ ds.setBasedir(getBasedir());
+ ds.setIncludes(getIncludes());
+ if (hasExcludes()) {
+ ds.setExcludes(getExcludes());
+ }
+ // scan
+ ds.scan();
+ // get found files
+ String[] foundFiles;
+ foundFiles = ds.getIncludedFiles();
+ return foundFiles;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder("basedir:").append(basedir);
+ if (includes != null) {
+ sb.append(", includes:").append(Arrays.toString(includes));
+ }
+ if (excludes != null) {
+ sb.append(", excludes:").append(Arrays.toString(excludes));
+ }
+ return sb.toString();
+ }
+
+ public String[] getIncludedFiles(File basedir, String[] defaultIncludes, String[] defaultExcludes, URLClassLoader loader, List<String> annotationClass, Log log) {
+ List<String> result = new ArrayList<String>();
+
+ for (String s : getIncludedFiles(basedir, defaultIncludes, defaultExcludes)) {
+ if (filterByAnnotation(s, loader, annotationClass, log)) {
+ result.add(s);
+ }
+ }
+ return result.toArray(new String[result.size()]);
+ }
+
+ protected boolean filterByAnnotation(String file, URLClassLoader loader, List<String> annotationClass, Log log) {
+
+
+ Annotation annotation = getAnnotation(file, loader, annotationClass, log);
+
+ boolean result = annotation != null;
+
+ if (result && log.isDebugEnabled()) {
+ log.debug("find i18n annotated file : " + file);
+ }
+ return result;
+ }
+
+ protected String getFQN(String file) {
+ String filePath = file;
+ filePath = filePath.substring(0, filePath.length() - ".java".length());
+ String replaceEx = File.separator.equals("\\") ? "\\\\" : File.separator;
+ return filePath.replaceAll(replaceEx, ".");
+ }
+
+ public Class<?> getClass(String file, URLClassLoader loader, Log log) {
+ String fqn = getFQN(file);
+ try {
+ return loader.loadClass(fqn);
+
+ } catch (Throwable e) {
+ log.warn("could not find class " + fqn + " " + e);
+ return null;
+ }
+ }
+
+ public Annotation getAnnotation(String file, URLClassLoader loader, List<String> annotationClass, Log log) {
+
+ Class<?> currentClass = getClass(file, loader, log);
+
+ try {
+ Annotation[] annos = currentClass.getAnnotations();
+ if (annos != null && annos.length > 0) {
+ for (Annotation anno : annos) {
+ if (annotationClass.contains(anno.annotationType().getName())) {
+ return anno;
+ }
+ }
+ }
+ } catch (Throwable e) {
+ log.warn("could not find annotation for " + file + " " + e);
+ }
+ return null;
+
+ }
+
+ public Class<?> getClass(File file, URLClassLoader loader, Log log) {
+ String f = file.getAbsolutePath().substring(basedir.getAbsolutePath().length() + 1);
+ return getClass(f, loader, log);
+ }
+
+ public Annotation getAnnotation(File file, URLClassLoader loader, List<String> annotationClass, Log log) {
+ String f = file.getAbsolutePath().substring(basedir.getAbsolutePath().length() + 1);
+ return getAnnotation(f, loader, annotationClass, log);
+ }
+
+ public String getSkipMessage() {
+ return skipMessage;
+ }
+
+ public String[] getFiles() {
+ return files;
+ }
+
+ public String[] getSkipFiles() {
+ return skipFiles;
+ }
+
+ public int getFoudFiles() {
+ return skipFiles.length + files.length;
+ }
+
+ public FileUpdater getUpdater() {
+ return updater;
+ }
+
+ public void setUpdater(FileUpdater updater) {
+ this.updater = updater;
+ }
+}
Property changes on: maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/SourceEntry.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/AbstractI18nParser.java (from rev 1522, maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/AbstractI18nParser.java)
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/AbstractI18nParser.java (rev 0)
+++ maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/AbstractI18nParser.java 2009-05-13 20:32:34 UTC (rev 1537)
@@ -0,0 +1,378 @@
+/*
+* *##% Plugin maven pour lutini18n
+ * Copyright (C) 2007 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */
+package org.nuiton.i18n.plugin.parser;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.nuiton.i18n.plugin.AbstractI18nPlugin;
+import org.nuiton.i18n.plugin.I18nLogger;
+import org.nuiton.i18n.plugin.PluginHelper;
+import org.nuiton.i18n.plugin.PluginHelper.I18nProperties;
+import org.nuiton.i18n.plugin.SourceEntry;
+import org.nuiton.i18n.plugin.parser.event.KeysModifier;
+import org.nuiton.util.FileUpdater;
+import org.nuiton.util.FileUtil;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Abstract implementation for parsing goal.
+ *
+ * @author tony
+ */
+public abstract class AbstractI18nParser extends AbstractI18nPlugin implements Parser {
+
+ /** @return the outGetter to use for the instance (java.getter,...) */
+ protected abstract String getOutGetter();
+
+ /** @return the starting regex expression to catch keys in key modifier */
+ protected abstract String getKeyModifierStart();
+
+ /** @return the ending regex expression to catch keys in key modifier */
+ protected abstract String getKeyModifierEnd();
+
+ /** @return the default includes to add to directory scanner */
+ protected abstract String[] getDefaultIncludes();
+
+ /** @return the default excludes to add to directory scanner */
+ protected abstract String[] getDefaultExcludes();
+
+ /** @return the default src directory to use in directory scanner */
+ protected abstract File getDefaultBasedir();
+
+ public abstract FileUpdater newFileUpdater(SourceEntry entry);
+
+ /**
+ * treate default entry
+ *
+ * @parameter expression="${i18n.treateDefaultEntry}" default-value="true"
+ */
+ protected boolean treateDefaultEntry;
+
+ /**
+ * Source entries (src+includes+excludes) .
+ *
+ * @parameter expression="${i18n.entries}"
+ */
+ protected MySourceEntry[] entries;
+
+ /**
+ * flag to display touched files while parsing.
+ * <p/>
+ * Note: the value will be always <code>true</code> if {@link #verbose} is set
+ * at <code>true</code>.
+ *
+ * @parameter expression="${i18n.showTouchedFiles}" default-value="${maven.verbose}"
+ * @since 0.9
+ */
+ protected boolean showTouchedFiles;
+ /**
+ * flag to save at eachfile treated the getter file
+ *
+ * @parameter expression="${i18n.safeMode}" default-value="false"
+ * @since 0.9
+ */
+ protected boolean safeMode;
+
+ protected I18nProperties result;
+
+ protected I18nProperties oldParser;
+
+ protected I18nProperties oldLanguage;
+ protected int fileTreated = 0;
+ protected long t0;
+
+ protected boolean touchFile;
+ protected List<File> treadedFiles;
+
+ @Override
+ public void init() {
+ super.init();
+ t0 = System.nanoTime();
+ result = new I18nProperties(encoding);
+ oldParser = new I18nProperties(encoding);
+ oldLanguage = new I18nProperties(encoding);
+ out.mkdirs();
+ // evenements
+ if (keysModifier) {
+ addParserEvent(KeysModifier.getInstance(getKeyModifierStart(), getKeyModifierEnd(), encoding));
+ }
+ treadedFiles = new ArrayList<File>();
+ if (verbose) {
+ showTouchedFiles = true;
+ }
+ }
+
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.maven.plugin.AbstractMojo#execute()
+ */
+ @Override
+ public void execute() throws MojoExecutionException, MojoFailureException {
+
+ init();
+ if (entries == null || entries.length == 0 && !treateDefaultEntry) {
+ // nothing to do
+ return;
+ }
+
+ if (safeMode) {
+ getLog().info("config - safeMode is on (could be slower).");
+ }
+ if (strictMode) {
+ getLog().info("config - strictMode is on (all files will be parsed).");
+ }
+
+ try {
+ // Reprise sur un ancien parsing
+ File oldParserFile = PluginHelper.getGetterFile(out, getOutGetter(), true);
+ File saveFile = PluginHelper.getGetterFileBackup(out, getOutGetter());
+
+ oldParser.load(oldParserFile);
+ FileUtil.copy(oldParserFile, saveFile);
+
+ // Anciennes cles disponnibles
+ //fixme : pourquoi on utilise un bundle precis ? le premier ici, je ne comprends pas
+ File oldLanguageFile = PluginHelper.getI18nFile(src, artifactId, locales[0], true);
+
+ oldLanguage.load(oldLanguageFile);
+
+ // Parsing
+ parse();
+
+ // Suppression du fichier sauvegarder
+ saveFile.delete();
+
+ int i = treadedFiles.size();
+ if (fileTreated == 0) {
+ getLog().info("Nothing to generate - all files are up to date.");
+ } else {
+ getLog().info(getVerboseLog().getLogEntry("parsing is done. [treated file(s) : " + i + '/' + fileTreated + "]", fileTreated, 0, t0));
+ addGetter();
+ }
+
+ } catch (Exception e) {
+ getLog().error("Error code parsing ", e);
+ throw new MojoFailureException("Error code parsing");
+ }
+
+ }
+
+ /**
+ * launch the parse on every given entries.
+ *
+ * @throws IOException if any io pb
+ */
+ @Override
+ public void parse() throws IOException {
+ if (treateDefaultEntry) {
+ addDefaultEntry();
+ }
+ long t00 = System.nanoTime();
+ for (MySourceEntry entry : this.entries) {
+ I18nLogger vLog = getVerboseLog();
+
+ vLog.setEntry(entry);
+
+ boolean skip = entry.init(this);
+
+ if (skip) {
+ if (verbose) {
+ getLog().info("skip - " + entry.getSkipMessage());
+ }
+ continue;
+ }
+
+ long t000 = System.nanoTime();
+ int nbFiles = entry.getFiles().length;
+ if (verbose) {
+ vLog.infoEntry("start", vLog.getLogEntry("[incoming file(s) : " + entry.getFoudFiles() + "]", 0, 0, 0));
+ }
+
+ // launch parser for found files
+ parseEntry(entry);
+
+ if (verbose) {
+ // log skipped files
+ for (String skipFile : entry.getSkipFiles()) {
+ vLog.setFile( new File(entry.getBasedir(), skipFile));
+ vLog.infoFile("skip", null);
+ }
+ }
+ fileTreated += nbFiles;
+ if (verbose) {
+ vLog.infoEntry("end", vLog.getLogEntry("[treated file(s) : " + nbFiles + "]", nbFiles, t000, t00));
+ }
+ t00 = System.nanoTime();
+ }
+ }
+
+
+ /**
+ * Add the default entry to entries given in configuration.
+ * <p/>
+ * This is a convinient method to simplify the configuration of the plugin.
+ */
+ protected void addDefaultEntry() {
+ List<MySourceEntry> list;
+
+ if (entries == null || entries.length == 0) {
+ list = new ArrayList<MySourceEntry>();
+ } else {
+ list = new ArrayList<MySourceEntry>(Arrays.asList(entries));
+ }
+ list.add(new MySourceEntry());
+ entries = list.toArray(new MySourceEntry[list.size()]);
+ }
+
+ /**
+ * launch parsing on a given entry.
+ *
+ * @param entry currentEntry to treate
+ * @throws IOException if any io pb.
+ */
+ protected final void parseEntry(SourceEntry entry) throws IOException {
+ long t00 = System.nanoTime();
+ String[] files = entry.getFiles();
+ int beforeEntryResultSize = result.size();
+ for (int i = 0, max = files.length; i < max; i++) {
+ String file1 = files[i];
+ long t000 = System.nanoTime();
+ String fileName = entry.getBasedir().getAbsolutePath() + File.separator + file1;
+ File file = new File(fileName);
+ for (ParserEvent event : events) {
+ event.eventChangeFile(file);
+ }
+ I18nLogger vLog = getVerboseLog();
+ vLog.setFile(file);
+
+ touchFile = false;
+ int size = result.size();
+ if (verbose) {
+ vLog.infoFile("parse", null);
+ }
+ parseFile(file);
+
+ //TC-20090214 pour des questions de performance, on ne sauvegarde pas
+ // a chaque traitement de fichier, les clefs mais une fois pour chaque
+ // source entry
+ // Detection de nouvelles cles, sauvegarde du fichier pour pouvoir le restaurer en cas de plantage
+ if (safeMode) {
+ if (size != result.size()) {
+ saveGetterFile();
+ }
+ }
+ if (touchFile) {
+ if (showTouchedFiles) {
+ vLog.infoFile("touch", null);
+ }
+ treadedFiles.add(file);
+ if (getLog().isDebugEnabled()) {
+ vLog.debug(vLog.getLogEntry(fileName, i, t000, t00));
+ }
+ }
+ for (ParserEvent event : events) {
+ event.eventNextFile(file);
+ }
+ }
+
+ if (!safeMode && beforeEntryResultSize < result.size()) {
+ // Detection de nouvelles cles, sauvegarde du fichier
+ saveGetterFile();
+ }
+ }
+
+ /**
+ * Save the result in the getter file.
+ *
+ * @throws IOException if any io pb
+ */
+ protected void saveGetterFile() throws IOException {
+ File getterFile = PluginHelper.getGetterFile(out, getOutGetter(), false);
+ result.store(getterFile);
+ }
+
+
+ public static class MySourceEntry extends SourceEntry {
+
+ public boolean init(AbstractI18nParser mojo) {
+ if (!useForGoal(mojo.getClass().getSimpleName())) {
+ // skip not for this goal
+ skipMessage = "exclude for this goal.";
+ return true;
+ }
+
+ String[] filesForEntry = getFilesForEntry(mojo);
+
+ if (filesForEntry.length == 0) {
+ // skip no file found
+ skipMessage = "no file found.";
+ return true;
+ }
+ setUpdater(mojo.newFileUpdater(this));
+
+ if (mojo.strictMode || updater == null) {
+ // mojo strict mode or not updater, so force all files
+ skipFiles = new String[0];
+ this.files = filesForEntry;
+ return false;
+ }
+
+ List<String> listFiles = new ArrayList<String>();
+ List<String> listSkipFiles = new ArrayList<String>();
+
+ // test if have any file
+ for (String foundFile : filesForEntry) {
+ File file = new File(getBasedir(), foundFile);
+ if (isFileUptodate(file)) {
+ listSkipFiles.add(foundFile);
+ } else {
+ listFiles.add(foundFile);
+ }
+ }
+ boolean todo = !listFiles.isEmpty();
+ if (!todo) {
+ // skip, no file out-of -date
+ skipMessage = "all files are up to date.";
+ this.skipFiles = listSkipFiles.toArray(new String[listSkipFiles.size()]);
+ this.files = new String[0];
+ return true;
+ }
+ this.skipFiles = listSkipFiles.toArray(new String[listSkipFiles.size()]);
+ this.files = listFiles.toArray(new String[listFiles.size()]);
+ return false;
+ }
+
+
+ /**
+ * Obtain all the relative path of files to treate for a given entry.
+ *
+ * @param mojo the given mojo
+ * @return the list of relative path of files for the given entry
+ */
+ protected String[] getFilesForEntry(AbstractI18nParser mojo) {
+ return getIncludedFiles(mojo.getDefaultBasedir(), mojo.getDefaultIncludes(), mojo.getDefaultExcludes());
+ }
+
+ }
+}
Property changes on: maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/AbstractI18nParser.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/Parser.java (from rev 1522, maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/Parser.java)
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/Parser.java (rev 0)
+++ maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/Parser.java 2009-05-13 20:32:34 UTC (rev 1537)
@@ -0,0 +1,55 @@
+/*
+ * *##% Plugin maven pour lutini18n
+ * Copyright (C) 2007 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */
+
+package org.nuiton.i18n.plugin.parser;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * Interface type pour la définition d'un nouveau parser.
+ * <p/>
+ * Une implantation abstraite est proposée : {@link AbstractI18nParser}.
+ *
+ * @author julien
+ */
+public interface Parser {
+
+ /**
+ * Lancement du parser
+ *
+ * @throws java.io.IOException if any io pb
+ */
+ public void parse() throws IOException;
+
+ /**
+ * Parse sur un fichier
+ *
+ * @param file le fichier à parser
+ */
+ public void parseFile(File file);
+
+ /**
+ * Parse une partie du fichier
+ *
+ * @param file le fichier à parser
+ * @param args ? TODO
+ */
+ public void parseLine(File file, String args);
+
+}
Property changes on: maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/Parser.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/ParserEvent.java (from rev 1522, maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/ParserEvent.java)
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/ParserEvent.java (rev 0)
+++ maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/ParserEvent.java 2009-05-13 20:32:34 UTC (rev 1537)
@@ -0,0 +1,59 @@
+/*
+ * *##% Plugin maven pour lutini18n
+ * Copyright (C) 2007 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */
+
+package org.nuiton.i18n.plugin.parser;
+
+import java.io.File;
+
+/**
+ * Permet d'ajouter des évènements sur les parsers
+ *
+ * @author julien
+ */
+public interface ParserEvent {
+
+ /**
+ * M�thode appelée quand on change de fichier parsé
+ *
+ * @param file
+ */
+ public void eventChangeFile(File file);
+
+ /**
+ * Méthode appelée après le parsing du fichier
+ *
+ * @param file
+ */
+ public void eventNextFile(File file);
+
+ /**
+ * M�thode appelée quand on change de clé
+ *
+ * @param keyI18n
+ * @param newKey
+ */
+ public void eventChangeKey(String keyI18n, boolean newKey);
+
+ /**
+ * M�thode appelée pour récupérer la nouvelle valeur de clé
+ *
+ * @return
+ */
+ public String eventGetRealKey();
+
+}
Property changes on: maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/ParserEvent.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/ParserException.java (from rev 1522, maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/ParserException.java)
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/ParserException.java (rev 0)
+++ maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/ParserException.java 2009-05-13 20:32:34 UTC (rev 1537)
@@ -0,0 +1,45 @@
+/*
+ * *##% Plugin maven pour lutini18n
+ * Copyright (C) 2007 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */
+
+package org.nuiton.i18n.plugin.parser;
+
+/**
+ * Permet la gestion des exceptions dans les parsers et dans les évènements
+ *
+ * @author julien
+ */
+public class ParserException extends RuntimeException {
+
+ private static final long serialVersionUID = 1L;
+
+ public ParserException() {
+ super();
+ }
+
+ public ParserException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public ParserException(String message) {
+ super(message);
+ }
+
+ public ParserException(Throwable cause) {
+ super(cause);
+ }
+}
Property changes on: maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/ParserException.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/event/KeysModifier.java (from rev 1522, maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/event/KeysModifier.java)
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/event/KeysModifier.java (rev 0)
+++ maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/event/KeysModifier.java 2009-05-13 20:32:34 UTC (rev 1537)
@@ -0,0 +1,219 @@
+/*
+ * *##% Plugin maven pour lutini18n
+ * Copyright (C) 2007 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */
+
+package org.nuiton.i18n.plugin.parser.event;
+
+import org.nuiton.i18n.plugin.parser.ParserEvent;
+import org.nuiton.i18n.plugin.parser.ParserException;
+import org.nuiton.util.FileUtil;
+
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JTextField;
+import java.awt.Container;
+import java.awt.GridLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * IHM permettant de modifier les clés de traduction en direct dans les fichiers
+ * parsés et les fichiers de propriétés.
+ *
+ * @author julien
+ */
+public class KeysModifier extends JFrame implements ParserEvent {
+
+ private static final long serialVersionUID = 1L;
+
+ // Modification des clés dans le fichier
+ protected List<String> newKeys;
+ protected boolean needModifiedFile;
+ protected String patternLeft;
+ protected String patternRight;
+ protected String encoding;
+
+ // Interface
+ protected JLabel name = new JLabel();
+ protected JLabel path = new JLabel();
+ protected JTextField key = new JTextField();
+ protected JTextField pattern = new JTextField(".*");
+ protected JCheckBox onlyNewKey = new JCheckBox();
+
+
+ protected JButton next = new JButton("Next >>");
+ private static KeysModifier keysModifier;
+
+ /**
+ * Récupération d'une instance de l'interface
+ *
+ * @param patternLeft left pattern
+ * @param patternRight right pattern
+ * @param encoding encoding
+ * @return the shared instance with new config
+ */
+ public static KeysModifier getInstance(String patternLeft, String patternRight, String encoding) {
+ if (keysModifier == null) {
+ keysModifier = new KeysModifier();
+ }
+
+
+ keysModifier.encoding = encoding;
+ keysModifier.patternLeft = patternLeft;
+ keysModifier.patternRight = patternRight;
+
+ return keysModifier;
+ }
+
+ /** Contructeur de l'interface */
+ private KeysModifier() {
+ setLayout(new GridLayout(9, 2, 10, 10));
+
+ Container pane = getContentPane();
+ pane.add(new JLabel("--- File information ---"));
+ pane.add(new JLabel());
+
+ pane.add(new JLabel("Name :"));
+ pane.add(name);
+
+ pane.add(new JLabel("Path : "));
+ pane.add(path);
+
+ pane.add(new JLabel("--- Files language ---"));
+ pane.add(new JLabel());
+
+ pane.add(new JLabel("Key :"));
+ pane.add(key);
+
+ pane.add(new JLabel("--- Filters ---"));
+ pane.add(new JLabel());
+
+ pane.add(new JLabel("Pattern :"));
+ pane.add(pattern);
+
+ pane.add(new JLabel("Only new key :"));
+ pane.add(onlyNewKey);
+
+ pane.add(new JLabel());
+ pane.add(next);
+
+ next.addActionListener(new EventNextKey());
+ addWindowListener(new EventWindows());
+
+ setTitle("Keys modifier");
+ setSize(800, 400);
+// pack();
+ setVisible(true);
+ }
+
+ @Override
+ public void eventChangeFile(File file) {
+ name.setText(file.getName());
+ path.setText(file.getPath());
+ key.setText("");
+ repaint();
+
+ newKeys = new ArrayList<String>();
+ needModifiedFile = false;
+ }
+
+ @Override
+ public void eventNextFile(File file) {
+ if (needModifiedFile) {
+ String content;
+ int region = 0;
+
+ try {
+ content = FileUtil.readAsString(file, encoding);
+ } catch (IOException e) {
+ throw new ParserException(e);
+ }
+
+ for (Iterator<String> iterator = newKeys.iterator(); iterator.hasNext();) {
+ String oldKey = iterator.next();
+ String realKey = iterator.next();
+ Pattern p = Pattern.compile("(" + patternLeft + ")(" + Pattern.quote(oldKey) + ")(" + patternRight + ")");
+ Matcher matcher = p.matcher(content);
+ matcher.region(region, content.length());
+ matcher.find();
+ region = matcher.start();
+ content = matcher.replaceFirst("$1" + realKey + "$3");
+ }
+
+ try {
+ FileUtil.writeString(file, content, encoding);
+ } catch (IOException e) {
+ throw new ParserException(e);
+ }
+ }
+ }
+
+ @Override
+ public synchronized void eventChangeKey(String keyI18n, boolean newKey) {
+ key.setText(keyI18n);
+ newKeys.add(key.getText());
+ repaint();
+ if (isVisible() && keyI18n.matches(pattern.getText()) && (!onlyNewKey.isSelected() || newKey)) {
+ try {
+ wait();
+ } catch (InterruptedException e) {
+ throw new ParserException(e);
+ }
+ }
+ }
+
+ @Override
+ public String eventGetRealKey() {
+ newKeys.add(key.getText());
+ needModifiedFile |= !newKeys.get(newKeys.size() - 1).equals(newKeys.get(newKeys.size() - 2));
+ return key.getText();
+ }
+
+ /** Action sur le boutton pour passer � la cl� suivante */
+ class EventNextKey implements ActionListener {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ eventNextKey();
+ }
+ }
+
+ /** Action sur la fermeture de la frame */
+ class EventWindows extends WindowAdapter {
+
+ @Override
+ public void windowClosing(WindowEvent e) {
+ setVisible(false);
+ eventNextKey();
+ }
+ }
+
+ /** Permet de passer à la clé suivante */
+ public synchronized void eventNextKey() {
+ notifyAll();
+ }
+}
Property changes on: maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/event/KeysModifier.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserJava.java (from rev 1522, maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserJava.java)
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserJava.java (rev 0)
+++ maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserJava.java 2009-05-13 20:32:34 UTC (rev 1537)
@@ -0,0 +1,164 @@
+/*
+ * *##% Plugin maven pour lutini18n
+ * Copyright (C) 2007 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */
+
+package org.nuiton.i18n.plugin.parser.impl;
+
+import org.apache.maven.project.MavenProject;
+import org.nuiton.i18n.plugin.SourceEntry;
+import org.nuiton.i18n.plugin.parser.AbstractI18nParser;
+import org.nuiton.i18n.plugin.parser.ParserEvent;
+import org.nuiton.i18n.plugin.parser.ParserException;
+import org.nuiton.util.FileUpdater;
+import org.nuiton.util.FileUpdaterHelper;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStreamReader;
+import java.io.LineNumberReader;
+import org.nuiton.processor.filters.I18nFilter;
+
+/**
+ * Récupération des chaine a traduire depuis les fichiers java.
+ *
+ * @author julien
+ * @goal parserJava
+ * @phase generate-resources
+ */
+public class ParserJava extends AbstractI18nParser {
+
+ /**
+ * Source entries (src+includes+excludes) .
+ *
+ * @parameter expression="${i18n.defaultIncludes}" default-value="**\\/*.java"
+ */
+ protected String defaultIncludes;
+
+ /**
+ * default src for an entry.
+ *
+ * @parameter expression="${i18n.defaultBasedir}" default-value="${basedir}/src/main/java"
+ */
+ protected File defaultBasedir;
+
+ /**
+ * Dependance du projet.
+ *
+ * @parameter default-value="${project}"
+ * @readonly
+ */
+ protected MavenProject project;
+
+ /**
+ * Repertoire sources des fichiers i18n.
+ *
+ * @parameter expression="${i18n.cp}" default-value="${basedir}/target/classes"
+ * @required
+ */
+ protected File cp;
+
+ @Override
+ public String[] getDefaultIncludes() {
+ return new String[]{defaultIncludes};
+ }
+
+ @Override
+ public String[] getDefaultExcludes() {
+ return new String[]{};
+ }
+
+ @Override
+ public File getDefaultBasedir() {
+ return defaultBasedir;
+ }
+
+ @Override
+ public FileUpdater newFileUpdater(SourceEntry entry) {
+ return FileUpdaterHelper.newJavaFileUpdater(entry.getBasedir(), cp);
+ }
+
+ @Override
+ protected String getKeyModifierStart() {
+ return "_\\(\\s*\"";
+ }
+
+ @Override
+ protected String getKeyModifierEnd() {
+ return "\"\\s*(\\)|,|\\+|$)";
+ }
+
+ @Override
+ protected String getOutGetter() {
+ return "java.getter";
+ }
+
+ protected I18nFilter filter;
+
+ @Override
+ public void init() {
+ super.init();
+ filter = new I18nFilter();
+ }
+
+ @Override
+ public void parseFile(File srcFile) {
+ LineNumberReader lnr=null;
+ String line=null;
+ try {
+ lnr = new LineNumberReader(new InputStreamReader(new FileInputStream(srcFile)));
+
+ while (lnr.ready()) {
+ line = lnr.readLine();
+ parseLine(srcFile, line);
+ }
+
+ } catch (Exception e) {
+ if (line!=null) {
+ getLog().error("could not parse line "+line);
+ }
+ throw new ParserException(e);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.codelutin.i18n.plugin.core.Parser#parseLine(java.io.File, java.lang.String)
+ */
+ @Override
+ public void parseLine(File srcFile, String line) {
+ String keysSet = filter.parse(line);
+
+ if (!keysSet.equals(I18nFilter.EMPTY_STRING)) {
+ touchFile = true;
+ // Found a set of i18n Strings, split it.
+ String[] keys = keysSet.split("=");
+ for (String key : keys) {
+ String keyModified = key;
+ for (ParserEvent event : events) {
+ event.eventChangeKey(key, !oldLanguage.containsKey(key));
+ keyModified = event.eventGetRealKey();
+ }
+ if (oldParser.containsKey(key)) {
+ result.put(keyModified, oldParser.get(key));
+ } else {
+ result.put(keyModified, key);
+ }
+ }
+ }
+ }
+
+}
Property changes on: maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserJava.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserJavaActionConfig.java (from rev 1522, maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserJavaActionConfig.java)
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserJavaActionConfig.java (rev 0)
+++ maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserJavaActionConfig.java 2009-05-13 20:32:34 UTC (rev 1537)
@@ -0,0 +1,87 @@
+/*
+* *##% Plugin maven pour lutini18n
+ * Copyright (C) 2007 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */
+package org.nuiton.i18n.plugin.parser.impl;
+
+import org.nuiton.i18n.plugin.parser.ParserEvent;
+
+import java.io.File;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Un parseur java pour scanner les annotations ActionConfig
+ *
+ * @author chemit
+ * @goal parserJavaActionConfig
+ * @phase generate-resources
+ */
+public class ParserJavaActionConfig extends ParserJava {
+
+ protected static final Pattern MATCH_PATTERN = Pattern.compile("(name|shortDescription|longDescription|name2|shortDescription2|longDescription2)\\s*=\\s*\"([\\w|\\.]+)\"(|\\s*|\\s*,\\s*$)");
+
+ @Override
+ protected String getKeyModifierStart() {
+ return "[\\w|\\.]+\\s*=\\s*\"";
+ }
+
+ @Override
+ protected String getKeyModifierEnd() {
+ return "\"\\s*(\\)|,|\\+|$)";
+ }
+
+ @Override
+ protected String getOutGetter() {
+ return "java-action-config.getter";
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.codelutin.i18n.plugin.extension.XmlParser#extract(java.lang.String)
+ */
+
+ public String extract(String i18nString) {
+ Matcher matcher = MATCH_PATTERN.matcher(i18nString.trim());
+ if (matcher.matches()) {
+ return matcher.group(2);
+ }
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.codelutin.i18n.plugin.core.Parser#parseLine(java.io.File, java.lang.String)
+ */
+ @Override
+ public void parseLine(File srcFile, String line) {
+ String key = extract(line);
+ if (key != null) {
+ touchFile = true;
+ String keyModified = key;
+ for (ParserEvent event : events) {
+ event.eventChangeKey(key, !oldLanguage.containsKey(key));
+ keyModified = event.eventGetRealKey();
+ }
+ if (oldParser.containsKey(key)) {
+ result.put(keyModified, oldParser.get(key));
+ } else {
+ result.put(keyModified, key);
+ }
+ }
+ }
+
+}
Property changes on: maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserJavaActionConfig.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserJavaTabConfig.java (from rev 1522, maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserJavaTabConfig.java)
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserJavaTabConfig.java (rev 0)
+++ maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserJavaTabConfig.java 2009-05-13 20:32:34 UTC (rev 1537)
@@ -0,0 +1,35 @@
+/**
+ * *##% Plugin maven pour lutini18n
+ * Copyright (C) 2007 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*
+ */
+package org.nuiton.i18n.plugin.parser.impl;
+
+/**
+ * Un parseur java pour scanner les annotations TabContentConfig.
+ *
+ * @author chemit
+ * @goal parserJavaTabConfig
+ * @phase generate-resources
+ */
+public class ParserJavaTabConfig extends ParserJavaActionConfig {
+
+ @Override
+ protected String getOutGetter() {
+ return "java-tab-config.getter";
+ }
+
+}
Property changes on: maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserJavaTabConfig.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserJaxx.java (from rev 1522, maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserJaxx.java)
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserJaxx.java (rev 0)
+++ maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserJaxx.java 2009-05-13 20:32:34 UTC (rev 1537)
@@ -0,0 +1,110 @@
+/*
+ * *##% Plugin maven pour lutini18n
+ * Copyright (C) 2007 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */
+
+package org.nuiton.i18n.plugin.parser.impl;
+
+import org.nuiton.i18n.plugin.SourceEntry;
+import org.nuiton.util.FileUpdater;
+import org.nuiton.util.FileUpdaterHelper;
+
+import java.io.File;
+
+/**
+ * Récupération des chaine à traduire depuis les fichiers xml Jaxx.
+ *
+ * @author julien
+ * @goal parserJaxx
+ * @phase generate-resources
+ */
+public class ParserJaxx extends ParserXml {
+
+ /**
+ * Source entries (src+includes+excludes) .
+ *
+ * @parameter expression="${i18n.defaultIncludes}" default-value="**\\/*.jaxx"
+ */
+ protected String defaultIncludes;
+
+ /**
+ * Where jaxx files should have been generated.
+ *
+ * @parameter expression="${i18n.defaultGenerateBasedir}" default-value="${basedir}/target/generated-sources/java"
+ */
+ protected File defaultGenerateBasedir;
+
+ /**
+ * Regles xml.
+ *
+ * @parameter expression="${i18n.rulesJaxx}" default-value="jaxx.rules"
+ */
+ protected String rulesJaxx;
+
+ @Override
+ public String[] getDefaultIncludes() {
+ return new String[]{defaultIncludes};
+ }
+
+ @Override
+ public String[] getDefaultExcludes() {
+ return new String[]{};
+ }
+
+ @Override
+ public FileUpdater newFileUpdater(SourceEntry entry) {
+ return FileUpdaterHelper.newJavaFileUpdater(entry.getBasedir(), defaultGenerateBasedir);
+ }
+
+ @Override
+ protected String getOutGetter() {
+ return "jaxx.getter";
+ }
+
+ @Override
+ protected String getKeyModifierStart() {
+ return "=\\s*[\"\']";
+ }
+
+ @Override
+ protected String getKeyModifierEnd() {
+ return "[\"\']";
+ }
+
+ @Override
+ protected String getFileRules() {
+ return rulesJaxx;
+ }
+
+ @Override
+ protected String getCoreFileRules() {
+ return "jaxx.rules";
+ }
+
+ public void setRulesJaxx(String rulesJaxx) {
+ this.rulesJaxx = rulesJaxx;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.codelutin.i18n.plugin.extension.XmlParser#extract(java.lang.String)
+ */
+ @Override
+ public String extract(String i18nString) {
+ return i18nString.length() == 0 ? null : i18nString;
+ }
+
+}
Property changes on: maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserJaxx.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserSwixat.java (from rev 1522, maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserSwixat.java)
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserSwixat.java (rev 0)
+++ maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserSwixat.java 2009-05-13 20:32:34 UTC (rev 1537)
@@ -0,0 +1,102 @@
+/*
+ * *##% Plugin maven pour lutini18n
+ * Copyright (C) 2007 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */
+
+package org.nuiton.i18n.plugin.parser.impl;
+
+import org.nuiton.i18n.plugin.SourceEntry;
+import org.nuiton.util.FileUpdater;
+
+/**
+ * Recuperation des chaines à traduire depuis les fichiers xml Swixat.
+ *
+ * @author julien
+ * @goal parserSwixat
+ * @phase generate-resources
+ */
+public class ParserSwixat extends ParserXml {
+
+ /**
+ * Source entries (src+includes) .
+ *
+ * @parameter expression="${i18n.defaultIncludes}" default-value="**\\/*.xml"
+ */
+ protected String defaultIncludes;
+
+ /**
+ * Source entries (src+excludes) .
+ *
+ * @parameter expression="${i18n.defaultIncludes}" default-value="**\\/context.xml"
+ */
+ protected String defaultExcludes;
+
+ /**
+ * Regles xml.
+ *
+ * @parameter expression="${i18n.rulesSwixat}" default-value="swixat.rules"
+ */
+ protected String rulesSwixat;
+
+ @Override
+ public String[] getDefaultIncludes() {
+ return new String[]{defaultIncludes};
+ }
+
+ @Override
+ public String[] getDefaultExcludes() {
+ return new String[]{defaultExcludes};
+ }
+
+ @Override
+ public FileUpdater newFileUpdater(SourceEntry entry) {
+ return null;
+ }
+
+ @Override
+ protected String getKeyModifierStart() {
+ return "=\\s*[\"\']";
+ }
+
+ @Override
+ protected String getKeyModifierEnd() {
+ return "[\"\']";
+ }
+
+ @Override
+ protected String getOutGetter() {
+ return "swixat.getter";
+ }
+
+ @Override
+ protected String getFileRules() {
+ return rulesSwixat;
+ }
+
+ @Override
+ protected String getCoreFileRules() {
+ return "swixat.rules";
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.codelutin.i18n.plugin.extension.XmlParser#extract(java.lang.String)
+ */
+ @Override
+ public String extract(String i18nString) {
+ return i18nString;
+ }
+}
Property changes on: maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserSwixat.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserValidation.java (from rev 1522, maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserValidation.java)
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserValidation.java (rev 0)
+++ maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserValidation.java 2009-05-13 20:32:34 UTC (rev 1537)
@@ -0,0 +1,140 @@
+/*
+ * *##% Plugin maven pour lutini18n
+ * Copyright (C) 2007 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */
+
+package org.nuiton.i18n.plugin.parser.impl;
+
+import org.nuiton.i18n.plugin.SourceEntry;
+import org.nuiton.util.FileUpdater;
+import org.nuiton.util.MirroredFileUpdater;
+
+import java.io.File;
+
+/**
+ * Récupération des chaine à traduire depuis les fichiers xml de validation.
+ * <p/>
+ * Le goal doit etre execute avant que les resources soient copiees dans target/classes
+ * pour rendre operatne le file updater (sinon lesfichiers sont toujours a jour...)
+ *
+ * @author chemit
+ * @goal parserValidation
+ * @phase generate-resources
+ */
+public class ParserValidation extends ParserXml {
+
+ /**
+ * Source entries (src+includes+excludes) .
+ *
+ * @parameter expression="${i18n.defaultIncludes}" default-value="**\\/**-validation.xml"
+ */
+ protected String defaultIncludes;
+
+ /**
+ * Where jaxx files should have been generated.
+ *
+ * @parameter expression="${i18n.cp}" default-value="${basedir}/target/classes"
+ */
+ protected File cp;
+
+ /**
+ * Regles xml.
+ *
+ * @parameter expression="${i18n.rulesValidation}" default-value="validation.rules"
+ */
+ protected String rulesValidation;
+
+ /**
+ * default src for an entry.
+ *
+ * @parameter expression="${i18n.defaultBasedir}" default-value="${basedir}/src/main/resources"
+ * @required
+ */
+ protected File defaultBasedir;
+
+ @Override
+ public String[] getDefaultIncludes() {
+ return new String[]{defaultIncludes};
+ }
+
+ @Override
+ public String[] getDefaultExcludes() {
+ return new String[]{};
+ }
+
+ @Override
+ public File getDefaultBasedir() {
+ return defaultBasedir;
+ }
+
+ @Override
+ public FileUpdater newFileUpdater(SourceEntry entry) {
+ return new MirroredFileUpdater("","",entry.getBasedir(), this.cp) {
+ @Override
+ public File getMirrorFile(File f) {
+ String file = f.getAbsolutePath().substring(this.prefixSourceDirecotory);
+ return new File(this.destinationDirectory + File.separator + file);
+ }
+ };
+ }
+
+ @Override
+ protected String getOutGetter() {
+ return "validation.getter";
+ }
+
+ @Override
+ protected String getKeyModifierStart() {
+ return "=\\s*[\"\']";
+ }
+
+ @Override
+ protected String getKeyModifierEnd() {
+ return "[\"\']";
+ }
+
+ @Override
+ protected String getFileRules() {
+ return rulesValidation;
+ }
+
+ @Override
+ protected String getCoreFileRules() {
+ return "validation.rules";
+ }
+
+ public void setRulesJaxx(String rulesJaxx) {
+ this.rulesValidation = rulesJaxx;
+ }
+
+ @Override
+ public String extract(String i18nString) {
+ String s = null;
+ if (!i18nString.trim().isEmpty()) {
+ s = i18nString.trim();
+ int end = s.indexOf("##");
+ if (end >0) {
+ // remove params from key
+ s = s.substring(0,end);
+ }
+ }
+ if (getLog().isDebugEnabled()) {
+ getLog().debug(i18nString + " = " + s);
+ }
+ return s;
+ }
+
+}
\ No newline at end of file
Copied: maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserXml.java (from rev 1522, maven-i18n-plugin/trunk/src/main/java/org/codelutin/i18n/plugin/parser/impl/ParserXml.java)
===================================================================
--- maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserXml.java (rev 0)
+++ maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserXml.java 2009-05-13 20:32:34 UTC (rev 1537)
@@ -0,0 +1,224 @@
+/*
+ * *##% Plugin maven pour lutini18n
+ * Copyright (C) 2007 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */
+
+package org.nuiton.i18n.plugin.parser.impl;
+
+import org.nuiton.i18n.plugin.parser.AbstractI18nParser;
+import org.nuiton.i18n.plugin.parser.ParserEvent;
+import org.nuiton.i18n.plugin.parser.ParserException;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpression;
+import javax.xml.xpath.XPathFactory;
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Récupération des chaines à traduire depuis les fichiers xml.
+ *
+ * @author julien
+ */
+public abstract class ParserXml extends AbstractI18nParser {
+
+ /** Taille du buffer pour les lectures/écritures */
+ protected static final int BUFFER_SIZE = 8 * 1024;
+
+ /**
+ * default src for an entry.
+ *
+ * @parameter expression="${i18n.defaultBasedir}" default-value="${basedir}/src/main/uimodel"
+ * @required
+ */
+ protected File defaultBasedir;
+
+ protected String rules;
+ protected XPathFactory factory;
+ protected XPath xpath;
+
+ /**
+ * Fonction d'extraction de la chaine
+ *
+ * @param i18nString le clef i18n
+ * @return la chaine
+ */
+ public abstract String extract(String i18nString);
+
+ /** @return le fichier des rules */
+ protected abstract String getFileRules();
+
+ /** @return le fichier des rules de base à toujours charger */
+ protected abstract String getCoreFileRules();
+
+ @Override
+ public void init() {
+ super.init();
+ this.factory = XPathFactory.newInstance();
+ this.rules = getRules(getFileRules());
+ this.xpath = factory.newXPath();
+ }
+
+ @Override
+ public void parseFile(File file) {
+ NodeList list;
+ InputSource inputSource = new InputSource(file.getAbsolutePath()); // TODO: A deplacer pour les performances
+
+ try {
+ int size = result.size();
+
+ // Recherche des clés à partir d'un xpath
+ XPathExpression expression = xpath.compile(rules);
+ list = (NodeList) expression.evaluate(inputSource, XPathConstants.NODESET);
+
+ for (int index = 0; index < list.getLength(); index++) {
+ Node node = list.item(index);
+ parseLine(file, node.getTextContent());
+ }
+ if (safeMode) {
+ // Détection de nouvelles clés, sauvegarde du fichier pour pouvoir le restaurer en cas de plantage
+ if (size != result.size()) {
+ saveGetterFile();
+ }
+ }
+ } catch (Exception e) {
+ throw new ParserException(e);
+ }
+ }
+
+ @Override
+ public void parseLine(File file, String key) {
+ key = extract(key);
+ if (key != null) {
+ touchFile = true;
+ String keyModified = key;
+ for (ParserEvent event : events) {
+ event.eventChangeKey(key, !oldLanguage.containsKey(key));
+ keyModified = event.eventGetRealKey();
+ }
+
+ if (oldParser.containsKey(key)) {
+ result.put(keyModified, oldParser.get(key));
+ } else {
+ result.put(keyModified, key);
+ }
+ }
+ }
+
+ @Override
+ public File getDefaultBasedir() {
+ return defaultBasedir;
+ }
+
+ /**
+ * Récupère le xpath à partir d'un fichier
+ *
+ * @param fileRules le nom du fichier contant les règles
+ * @return le xpath à partir d'un fichier
+ */
+ private String getRules(String fileRules) {
+ StringBuilder buffer = new StringBuilder();
+
+ try {
+ String readInputStream;
+
+ // load core rules
+ readInputStream = loadRulesFile(getCoreFileRules());
+ if (verbose) {
+ getLog().info("core rules : " + getCoreFileRules());
+ }
+ buffer.append(readInputStream);
+
+ if (!fileRules.equals(getCoreFileRules())) {
+ // add custom rules
+ readInputStream = loadRulesFile(fileRules);
+ if (verbose) {
+ getLog().info("custom rules : " + fileRules);
+ }
+ buffer.append(" | ").append(readInputStream);
+ }
+ } catch (IOException e) {
+ throw new ParserException(e);
+ }
+
+ return buffer.toString();
+ }
+
+ private String loadRulesFile(String fileRules) throws IOException {
+ File f = new File(fileRules);
+
+ InputStream inputStream;
+ if (f.exists()) {
+ // load from a file
+ try {
+ inputStream = new FileInputStream(f);
+ } catch (FileNotFoundException e) {
+ throw new ParserException(e);
+ }
+ } else {
+ // load from classpath
+ ClassLoader classLoader = getClass().getClassLoader();
+ inputStream = classLoader.getResourceAsStream(fileRules);
+ }
+ if (inputStream == null) {
+ throw new ParserException("could not found file of rules : " + fileRules);
+ }
+
+ inputStream = new BufferedInputStream(inputStream);
+
+ try {
+ // Lecture
+ String readInputStream;
+ readInputStream = readInputStream(inputStream);
+ return readInputStream;
+ } catch (IOException e) {
+ throw new ParserException(e);
+ } finally {
+ inputStream.close();
+ }
+ }
+
+ /**
+ * Permet la lecture d'un InputStream et Suppressions.
+ *
+ * @param in le flux entrant
+ * @return le contenu du flux
+ * @throws IOException si problème de lecture dans flux entrant
+ */
+ private String readInputStream(InputStream in) throws IOException {
+ StringBuilder sb = new StringBuilder();
+ byte[] buffer = new byte[BUFFER_SIZE];
+ while (in.read(buffer, 0, BUFFER_SIZE) != -1) {
+ String tmp = new String(buffer);
+ sb.append(tmp);
+ }
+ in.close();
+ // Suppression
+ String txt = sb.toString().trim();
+ txt = txt.replaceAll("#.*\n", ""); // suppression des commentaires
+ txt = txt.replaceAll("\\s+", " | "); // contruction du xpath avec des ou
+ txt = txt.replaceAll("(^ \\| )|( \\| $)", ""); // suppression des ou de début ee fin
+ return txt;
+ }
+}
Property changes on: maven-i18n-plugin/trunk/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserXml.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Modified: maven-i18n-plugin/trunk/src/site/site.xml
===================================================================
--- maven-i18n-plugin/trunk/src/site/site.xml 2009-05-13 20:31:49 UTC (rev 1536)
+++ maven-i18n-plugin/trunk/src/site/site.xml 2009-05-13 20:32:34 UTC (rev 1537)
@@ -4,9 +4,9 @@
<publishDate format="dd/MM/yyyy"/>
<skin>
- <groupId>org.codelutin</groupId>
- <artifactId>maven-lutin-skin</artifactId>
- <version>0.2.3</version>
+ <groupId>org.codelutin</groupId>
+ <artifactId>maven-lutin-skin</artifactId>
+ <version>0.2.3</version>
</skin>
<bannerLeft>
@@ -29,12 +29,13 @@
<body>
<links>
<item name="Labs" href="http://labs.libre-entreprise.org/"/>
+ <item name="Nuiton" href="http://www.nuiton.org"/>
<item name="${project.organization.name}" href="${project.organization.url}"/>
</links>
<menu name="Utilisateur">
<item name="Introduction" href="index.html"/>
- <item name="Goals" href="plugin-info.html">
+ <item name="Goals" href="plugin-info.html">
<item name="parserJava" href="parserJava-mojo.html"/>
<item name="parserJaxx" href="parserJaxx-mojo.html"/>
<item name="parserSwixat" href="parserSwixat-mojo.html"/>
@@ -46,20 +47,14 @@
<item name="bundle" href="bundle-mojo.html"/>
<item name="help" href="help-mojo.html"/>
</item>
- <item name="Usage" href="usage.html"/>
- <item name="FAQ" href="faq.html"/>
</menu>
- <menu name="Examples">
- <item name="To be done" />
- <!--item name="To be done" href="/examples/describe-configuration.html"/-->
- </menu>
<menu name="Téléchargement">
- <item href="${labs.builder.url}/org/codelutin/${project.artifactId}/${project.version}/${project.build.finalName}.jar"
+ <item href="${repository.home.url}/org/nuiton/${project.artifactId}/${project.version}/${project.build.finalName}.jar"
name="Librairie (jar)"/>
- <item href="${labs.builder.url}/org/codelutin/${project.artifactId}/${project.version}/${project.build.finalName}-javadoc.jar"
+ <item href="${repository.home.url}/org/nuiton/${project.artifactId}/${project.version}/${project.build.finalName}-javadoc.jar"
name="Javadoc (jar)"/>
- <item href="${labs.builder.url}/org/codelutin/${project.artifactId}/${project.version}/${project.build.finalName}-sources.jar"
+ <item href="${repository.home.url}/org/nuiton/${project.artifactId}/${project.version}/${project.build.finalName}-sources.jar"
name="Sources (jar)"/>
</menu>
1
0
[Lutinutil-commits] r1536 - in maven-i18n-plugin/trunk/src: main/java/org site
by tchemit@users.labs.libre-entreprise.org 13 May '09
by tchemit@users.labs.libre-entreprise.org 13 May '09
13 May '09
Author: tchemit
Date: 2009-05-13 20:31:49 +0000 (Wed, 13 May 2009)
New Revision: 1536
Removed:
maven-i18n-plugin/trunk/src/main/java/org/codelutin/
maven-i18n-plugin/trunk/src/site/apt/
maven-i18n-plugin/trunk/src/site/fml/
Log:
processor migrated to nuiton :)
refactor processor plugin : no more used of AntTask
todo remove from nuitonprocessor the Ant Taskes (at least put them in the plugin)
1
0
[Lutinutil-commits] r1535 - in maven-license-switcher-plugin/trunk: . src/main/java/org/nuiton/license src/main/java/org/nuiton/license/plugin src/site
by tchemit@users.labs.libre-entreprise.org 13 May '09
by tchemit@users.labs.libre-entreprise.org 13 May '09
13 May '09
Author: tchemit
Date: 2009-05-13 20:10:26 +0000 (Wed, 13 May 2009)
New Revision: 1535
Removed:
maven-license-switcher-plugin/trunk/src/site/apt/
maven-license-switcher-plugin/trunk/src/site/fml/
Modified:
maven-license-switcher-plugin/trunk/pom.xml
maven-license-switcher-plugin/trunk/src/main/java/org/nuiton/license/JavaLicenseGenerator.java
maven-license-switcher-plugin/trunk/src/main/java/org/nuiton/license/XmlLicenseGenerator.java
maven-license-switcher-plugin/trunk/src/main/java/org/nuiton/license/plugin/SwitchLicensePlugin.java
maven-license-switcher-plugin/trunk/src/site/site.xml
Log:
processor migrated to nuiton :)
refactor processor plugin : no more used of AntTask
todo remove from nuitonprocessor the Ant Taskes (at least put them in the plugin)
Modified: maven-license-switcher-plugin/trunk/pom.xml
===================================================================
--- maven-license-switcher-plugin/trunk/pom.xml 2009-05-13 15:31:20 UTC (rev 1534)
+++ maven-license-switcher-plugin/trunk/pom.xml 2009-05-13 20:10:26 UTC (rev 1535)
@@ -24,8 +24,8 @@
<dependencies>
<dependency>
- <groupId>org.codelutin</groupId>
- <artifactId>lutinprocessor</artifactId>
+ <groupId>org.nuiton</groupId>
+ <artifactId>nuitonprocessor</artifactId>
<version>${processor.version}</version>
<scope>compile</scope>
</dependency>
@@ -37,28 +37,8 @@
<scope>compile</scope>
</dependency>
- <!--dependency>
- <groupId>org.apache.maven.shared</groupId>
- <artifactId>maven-dependency-tree</artifactId>
- <version>1.2</version>
- </dependency-->
-
<!-- tests dependencies -->
- <!--dependency>
- <groupId>org.apache.maven.shared</groupId>
- <artifactId>maven-plugin-testing-harness</artifactId>
- <version>1.1</version>
- <scope>test</scope>
- </dependency-->
-
- <!--dependency>
- <groupId>org.apache.maven.shared</groupId>
- <artifactId>maven-verifier</artifactId>
- <version>1.0</version>
- <scope>test</scope>
- </dependency-->
-
<dependency>
<groupId>org.nuiton</groupId>
<artifactId>maven-helper-plugin</artifactId>
@@ -106,18 +86,17 @@
<properties>
- <nuiton.project>nuitonbuilder</nuiton.project>
-
- <processor.version>0.18</processor.version>
+ <redmine.project>nuitonutil</redmine.project>
+ <processor.version>1.0.0-SNAPSHOT</processor.version>
<!-- assuprimer du de l'utilisation de mavenpom -->
<labs.id>12</labs.id>
<labs.project>lutinutil</labs.project>
-
<maven.version>2.0.10</maven.version>
-
<helper.version>1.0.0-SNAPSHOT</helper.version>
-
+ <helper.licenseName>lgpl_v3</helper.licenseName>
+ <site.home.url>http://lutinutil.labs.libre-entreprise.org</site.home.url>
+ <repository.home.url>http://lutinbuilder.labs.libre-entreprise.org/maven2</repository.home.url>
</properties>
<build>
@@ -162,16 +141,16 @@
</executions>
</plugin-->
<!-- plugin site -->
- <!--plugin>
+ <plugin>
<artifactId>maven-site-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.codelutin</groupId>
<artifactId>doxia-module-jrst</artifactId>
- <version>1.0.0</version>
+ <version>1.0.1</version>
</dependency>
</dependencies>
- </plugin-->
+ </plugin>
</plugins>
</build>
@@ -190,6 +169,7 @@
<!-- ************************************************************* -->
<!--Source control management-->
+ <!-- a supprimer au passage a mavenpom -->
<scm>
<url>${maven.scm.url}</url>
<connection>${maven.scm.connection}</connection>
Modified: maven-license-switcher-plugin/trunk/src/main/java/org/nuiton/license/JavaLicenseGenerator.java
===================================================================
--- maven-license-switcher-plugin/trunk/src/main/java/org/nuiton/license/JavaLicenseGenerator.java 2009-05-13 15:31:20 UTC (rev 1534)
+++ maven-license-switcher-plugin/trunk/src/main/java/org/nuiton/license/JavaLicenseGenerator.java 2009-05-13 20:10:26 UTC (rev 1535)
@@ -1,6 +1,6 @@
package org.nuiton.license;
-import org.codelutin.processor.filters.LicenseFilter;
+import org.nuiton.processor.filters.LicenseFilter;
/** @author chemit */
public class JavaLicenseGenerator implements LicenseGenerator {
Modified: maven-license-switcher-plugin/trunk/src/main/java/org/nuiton/license/XmlLicenseGenerator.java
===================================================================
--- maven-license-switcher-plugin/trunk/src/main/java/org/nuiton/license/XmlLicenseGenerator.java 2009-05-13 15:31:20 UTC (rev 1534)
+++ maven-license-switcher-plugin/trunk/src/main/java/org/nuiton/license/XmlLicenseGenerator.java 2009-05-13 20:10:26 UTC (rev 1535)
@@ -1,6 +1,6 @@
package org.nuiton.license;
-import org.codelutin.processor.filters.LicenseFilter;
+import org.nuiton.processor.filters.LicenseFilter;
/** @author chemit */
public class XmlLicenseGenerator implements LicenseGenerator {
Modified: maven-license-switcher-plugin/trunk/src/main/java/org/nuiton/license/plugin/SwitchLicensePlugin.java
===================================================================
--- maven-license-switcher-plugin/trunk/src/main/java/org/nuiton/license/plugin/SwitchLicensePlugin.java 2009-05-13 15:31:20 UTC (rev 1534)
+++ maven-license-switcher-plugin/trunk/src/main/java/org/nuiton/license/plugin/SwitchLicensePlugin.java 2009-05-13 20:10:26 UTC (rev 1535)
@@ -20,8 +20,6 @@
import org.apache.maven.plugin.MojoExecutionException;
-import org.codelutin.processor.LicenseProcessor;
-import org.codelutin.processor.filters.LicenseFilter;
import org.nuiton.util.FileUtil;
import java.io.BufferedReader;
@@ -32,10 +30,13 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import org.apache.maven.project.MavenProject;
import org.nuiton.AbstractPlugin;
import org.nuiton.license.License;
import org.nuiton.license.LicenseFactory;
import org.nuiton.license.LicenseGenerator;
+import org.nuiton.processor.LicenseProcessor;
+import org.nuiton.processor.filters.LicenseFilter;
import org.nuiton.util.FileUpdaterHelper;
import org.nuiton.util.MirroredFileUpdater;
@@ -51,9 +52,17 @@
public class SwitchLicensePlugin extends AbstractPlugin {
/**
+ * Dependance du projet.
+ *
+ * @parameter default-value="${project}"
+ * @required
+ * @since 1.0.0
+ */
+ protected MavenProject project;
+ /**
* Encoding a utiliser pour lire et ecrire les fichiers.
*
- * @parameter expression="${helper.encoding}" default-value="${project.build.sourceEncoding}"
+ * @parameter expression="${license-switcher.encoding}" default-value="${project.build.sourceEncoding}"
* @required
* @since 1.0.0
*/
@@ -61,14 +70,14 @@
/**
* Un flag pour forcer la generation.
*
- * @parameter expression="${helper.force}" default-value="false"
+ * @parameter expression="${license-switcher.force}" default-value="false"
* @since 1.0.0
*/
protected boolean force;
/**
* l'annee de creation du module (sera place dans le header)
*
- * @parameter default-value="${project.inceptionYear}"
+ * @parameter expression="${license-switcher.inceptionYear}" default-value="${project.inceptionYear}"
* @required
* @since 1.0.0
*/
@@ -76,25 +85,23 @@
/**
* le nom de l'organisation (sera place dans le header)
*
- * @parameter default-value="${project.organization.name}"
+ * @parameter expression="${license-switcher.organizationName}" default-value="${project.organization.name}"
* @required
- * @readonly
* @since 1.0.0
*/
protected String organizationName;
/**
* le nom du projet (sera place dans le header)
*
- * @parameter default-value="${project.name}"
+ * @parameter expression="${license-switcher.projectName}" default-value="${project.name}"
* @required
- * @readonly
* @since 1.0.0
*/
protected String projectName;
/**
* Le type de license a appliquer.
*
- * @parameter expression="${helper.licenseName}"
+ * @parameter expression="${license-switcher.licenseName}"
* @required
* @since 1.0.0
*/
@@ -102,7 +109,7 @@
/**
* Repertoires des fichiers sources a traiter.
*
- * @parameter expression="${helper.compileSourceRoots}" default-value="${project.compileSourceRoots}"
+ * @parameter expression="${license-switcher.compileSourceRoots}" default-value="${project.compileSourceRoots}"
* @required
* @since 1.0.0
*/
@@ -110,7 +117,7 @@
/**
* Repertoires des fichiers sources de test a traiter.
*
- * @parameter expression="${helper.testCompileSourceRoots}" default-value="${project.testCompileSourceRoots}"
+ * @parameter expression="${license-switcher.testCompileSourceRoots}" default-value="${project.testCompileSourceRoots}"
* @required
* @since 1.0.0
*/
@@ -118,7 +125,7 @@
/**
* Repertoire de sortie des classes (classpath).
*
- * @parameter expression="${helper.outputDirectory}" default-value="${project.build.outputDirectory}"
+ * @parameter expression="${license-switcher.outputDirectory}" default-value="${project.build.outputDirectory}"
* @required
* @since 1.0.0
*/
@@ -126,7 +133,7 @@
/**
* Repertoire du build des tests
*
- * @parameter expression="${helper.testOutputDirectory}" default-value="${project.build.testOutputDirectory}"
+ * @parameter expression="${license-switcher.testOutputDirectory}" default-value="${project.build.testOutputDirectory}"
* @required
* @since 1.0.0
*/
@@ -134,17 +141,24 @@
/**
* Un resolver externe
*
- * @parameter expression="${helper.extraResolver}"
+ * @parameter expression="${license-switcher.extraResolver}"
* @since 1.0.0
*/
protected String[] extraResolver;
/**
* Un flag pour conserver un backup des fichiers modifies.
*
- * @parameter expression="${helper.keepBackup}" default-value="false"
+ * @parameter expression="${license-switcher.keepBackup}" default-value="false"
* @since 1.0.0
*/
protected boolean keepBackup;
+ /**
+ * Un flag pour activer le mode verbeux.
+ *
+ * @parameter expression="${license-switcher.verbose}" default-value="${maven.verbose}"
+ * @since 1.0.0
+ */
+ protected boolean verbose;
/** le header a ajouter dans chaque fichier source java */
protected String licenseHeaderContent;
/** la liste des chemin relatifs des sources java a traiter pour chaque repertoire contenant des sources */
@@ -164,14 +178,12 @@
@Override
public boolean init() throws IOException {
- boolean doGenerate = force;
-
timestamp = System.nanoTime();
// obtain all java source files to be treated
javaFilesToTreate = getFilesToTreate();
- doGenerate &= !javaFilesToTreate.isEmpty();
+ boolean doGenerate = !javaFilesToTreate.isEmpty();
if (doGenerate) {
@@ -211,7 +223,7 @@
Map<File, String[]> files = new java.util.HashMap<File, String[]>();
- MirroredFileUpdater updater = FileUpdaterHelper.newJavaFileUpdater();
+ MirroredFileUpdater updater = force ? null : FileUpdaterHelper.newJavaFileUpdater();
updater.setDestinationDirectory(outputDirectory);
getFilesToTreateForRoots(new String[]{"**\\/*.java"}, null, compileSourceRoots, files, updater);
@@ -267,7 +279,7 @@
getLog().info("process file " + sourceFile);
}
- // file where to write result
+ // file where to writeFile result
File processFile = new File(sourceFile.getAbsolutePath() + "_" + timestamp);
try {
@@ -300,13 +312,33 @@
getLog().warn("no license was found on file " + sourceFile + ", adding one");
String content = FileUtil.readAsString(sourceFile, encoding);
content = "/**\n * " + LicenseFilter.HEADER + " " + licenseHeaderContent + " " + LicenseFilter.FOOTER + "\n */\n" + content;
- FileUtil.writeString(processFile, content, encoding);
+ writeFile(processFile, content, encoding);
}
protected void addLicenseToXmlSourceFile(File sourceFile, File processFile) throws IOException {
getLog().warn("no license was found on file " + sourceFile + ", adding one");
String content = FileUtil.readAsString(sourceFile, encoding);
content = "<!--\n\n/**\n * " + LicenseFilter.HEADER + " " + licenseHeaderContent + " " + LicenseFilter.FOOTER + "\n */\n" + content + " \n\n-->";
- FileUtil.writeString(processFile, content, encoding);
+ writeFile(processFile, content, encoding);
}
+
+ @Override
+ public boolean isVerbose() {
+ return verbose;
+ }
+
+ @Override
+ public void setVerbose(boolean verbose) {
+ this.verbose = verbose;
+ }
+
+ @Override
+ public MavenProject getProject() {
+ return project;
+ }
+
+ @Override
+ public void setProject(MavenProject project) {
+ this.project = project;
+ }
}
Modified: maven-license-switcher-plugin/trunk/src/site/site.xml
===================================================================
--- maven-license-switcher-plugin/trunk/src/site/site.xml 2009-05-13 15:31:20 UTC (rev 1534)
+++ maven-license-switcher-plugin/trunk/src/site/site.xml 2009-05-13 20:10:26 UTC (rev 1535)
@@ -29,36 +29,27 @@
<body>
<links>
<item name="Labs" href="http://labs.libre-entreprise.org"/>
+ <item name="Nuiton" href="http://www.nuiton.org"/>
<item name="${project.organization.name}" href="${project.organization.url}"/>
</links>
<menu name="Utilisateur">
<item name="Introduction" href="index.html"/>
- <item name="Goals" href="plugin-info.html">
- <item name="license" href="license-mojo.html"/>
- <item name="third-party" href="third-party-mojo.html"/>
+ <item name="Goals" href="plugin-info.html">
<item name="switch" href="switch-mojo.html"/>
- <item name="available-licenses" href="available-licenses-mojo.html"/>
<item name="help" href="help-mojo.html"/>
</item>
- <item name="Usage" href="usage.html"/>
- <item name="FAQ" href="faq.html"/>
</menu>
- <menu name="Examples">
- <item name="Todo" href="Todo.html"/>
- </menu>
-
+
<menu name="Téléchargement">
- <item href="${labs.builder.url}/org/codelutin/${project.artifactId}/${project.version}"
- name="Télécharger la dernière version"/>
- <item href="${labs.builder.url}/org/codelutin/${project.artifactId}"
- name="Voir toutes les versions"/>
+ <item href="${repository.home.url}/org/nuiton/${project.artifactId}/${project.version}/${project.build.finalName}.jar"
+ name="Librairie (jar)"/>
+ <item href="${repository.home.url}/org/nuiton/${project.artifactId}/${project.version}/${project.build.finalName}-javadoc.jar"
+ name="Javadoc (jar)"/>
+ <item href="${repository.home.url}/org/nuiton/${project.artifactId}/${project.version}/${project.build.finalName}-sources.jar"
+ name="Sources (jar)"/>
</menu>
- <menu name="Développeur">
- <item name="A faire" href="Todo.html"/>
- </menu>
-
<menu ref="reports"/>
</body>
1
0
[Lutinutil-commits] r1534 - in maven-license-switcher-plugin/trunk: . src/main/java/org src/main/java/org/nuiton src/main/java/org/nuiton/license src/main/java/org/nuiton/license/plugin src/test/java/org src/test/java/org/nuiton src/test/java/org/nuiton/license
by tchemit@users.labs.libre-entreprise.org 13 May '09
by tchemit@users.labs.libre-entreprise.org 13 May '09
13 May '09
Author: tchemit
Date: 2009-05-13 15:31:20 +0000 (Wed, 13 May 2009)
New Revision: 1534
Added:
maven-license-switcher-plugin/trunk/src/main/java/org/nuiton/
maven-license-switcher-plugin/trunk/src/main/java/org/nuiton/license/
maven-license-switcher-plugin/trunk/src/main/java/org/nuiton/license/JavaLicenseGenerator.java
maven-license-switcher-plugin/trunk/src/main/java/org/nuiton/license/XmlLicenseGenerator.java
maven-license-switcher-plugin/trunk/src/main/java/org/nuiton/license/plugin/
maven-license-switcher-plugin/trunk/src/main/java/org/nuiton/license/plugin/SwitchLicensePlugin.java
maven-license-switcher-plugin/trunk/src/test/java/org/nuiton/
maven-license-switcher-plugin/trunk/src/test/java/org/nuiton/license/
maven-license-switcher-plugin/trunk/src/test/java/org/nuiton/license/JavaLicenseGeneratorTest.java
maven-license-switcher-plugin/trunk/src/test/java/org/nuiton/license/XmlLicenseGeneratorTest.java
maven-license-switcher-plugin/trunk/src/test/java/org/nuiton/license/plugin/
Modified:
maven-license-switcher-plugin/trunk/pom.xml
Log:
migrate to nuiton
Modified: maven-license-switcher-plugin/trunk/pom.xml
===================================================================
--- maven-license-switcher-plugin/trunk/pom.xml 2009-05-13 15:31:01 UTC (rev 1533)
+++ maven-license-switcher-plugin/trunk/pom.xml 2009-05-13 15:31:20 UTC (rev 1534)
@@ -10,8 +10,13 @@
<groupId>org.codelutin</groupId>
<artifactId>lutinproject</artifactId>
<version>3.5.4</version>
+ <!--groupId>org.nuiton</groupId>
+ <artifactId>mavenpom</artifactId>
+ <version>1.0.0-SNAPSHOT</version-->
</parent>
+ <groupId>org.nuiton</groupId>
+
<artifactId>maven-license-switcher-plugin</artifactId>
<version>1.0.0-SNAPSHOT</version>
@@ -26,35 +31,50 @@
</dependency>
<dependency>
- <groupId>org.codelutin</groupId>
- <artifactId>lutinpluginutil</artifactId>
- <version>${lutinpluginutil.version}</version>
+ <groupId>org.nuiton</groupId>
+ <artifactId>maven-helper-plugin</artifactId>
+ <version>${helper.version}</version>
<scope>compile</scope>
</dependency>
- <dependency>
+ <!--dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-dependency-tree</artifactId>
<version>1.2</version>
- </dependency>
+ </dependency-->
<!-- tests dependencies -->
- <dependency>
+ <!--dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-plugin-testing-harness</artifactId>
<version>1.1</version>
<scope>test</scope>
- </dependency>
+ </dependency-->
- <dependency>
+ <!--dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-verifier</artifactId>
<version>1.0</version>
<scope>test</scope>
+ </dependency-->
+
+ <dependency>
+ <groupId>org.nuiton</groupId>
+ <artifactId>maven-helper-plugin</artifactId>
+ <version>${helper.version}</version>
+ <scope>test</scope>
+ <classifier>tests</classifier>
</dependency>
<dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.6</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>${maven.version}</version>
@@ -85,14 +105,19 @@
<packaging>maven-plugin</packaging>
<properties>
- <labs.id>12</labs.id>
- <labs.project>lutinutil</labs.project>
- <processor.version>0.18</processor.version>
- <lutinpluginutil.version>0.5</lutinpluginutil.version>
+ <nuiton.project>nuitonbuilder</nuiton.project>
+ <processor.version>0.18</processor.version>
+
+ <!-- assuprimer du de l'utilisation de mavenpom -->
+ <labs.id>12</labs.id>
+ <labs.project>lutinutil</labs.project>
+
<maven.version>2.0.10</maven.version>
+ <helper.version>1.0.0-SNAPSHOT</helper.version>
+
</properties>
<build>
@@ -113,10 +138,10 @@
</executions>
</plugin>
- <plugin>
+ <!--plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
- <!--Copy licenses files for site-->
+
<execution>
<id>CopySiteFiles2</id>
<phase>pre-site</phase>
@@ -135,10 +160,10 @@
</goals>
</execution>
</executions>
- </plugin>
+ </plugin-->
<!-- plugin site -->
- <plugin>
- <artifactId>maven-site-plugin</artifactId>
+ <!--plugin>
+ <artifactId>maven-site-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.codelutin</groupId>
@@ -146,14 +171,14 @@
<version>1.0.0</version>
</dependency>
</dependencies>
- </plugin>
+ </plugin-->
</plugins>
+
</build>
<!--Site-->
<reporting>
- <plugins>
- <!--Site report's plugin-->
+ <plugins>
<plugin>
<artifactId>maven-plugin-plugin</artifactId>
</plugin>
@@ -188,36 +213,4 @@
</repository>
</repositories>
- <profiles>
- <!-- perform only on a release stage when using the maven-release-plugin -->
- <profile>
- <id>release-profile</id>
- <activation>
- <property>
- <name>performRelease</name>
- <value>true</value>
- </property>
- </activation>
- <build>
- <plugins>
- <!-- always add license and third-party files to classpath -->
- <plugin>
- <groupId>org.codelutin</groupId>
- <artifactId>maven-license-switcher-plugin</artifactId>
- <version>0.8</version>
- <executions>
- <execution>
- <id>attach-licenses</id>
- <goals>
- <goal>license</goal>
- <goal>third-party</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
- </profile>
- </profiles>
-
</project>
Added: maven-license-switcher-plugin/trunk/src/main/java/org/nuiton/license/JavaLicenseGenerator.java
===================================================================
--- maven-license-switcher-plugin/trunk/src/main/java/org/nuiton/license/JavaLicenseGenerator.java (rev 0)
+++ maven-license-switcher-plugin/trunk/src/main/java/org/nuiton/license/JavaLicenseGenerator.java 2009-05-13 15:31:20 UTC (rev 1534)
@@ -0,0 +1,13 @@
+package org.nuiton.license;
+
+import org.codelutin.processor.filters.LicenseFilter;
+
+/** @author chemit */
+public class JavaLicenseGenerator implements LicenseGenerator {
+
+ @Override
+ public String getHeader(String licenseHeaderContent) {
+ return "/**\n * " + LicenseFilter.HEADER + " " + licenseHeaderContent + " " + LicenseFilter.FOOTER + "\n */\n";
+ }
+
+}
Added: maven-license-switcher-plugin/trunk/src/main/java/org/nuiton/license/XmlLicenseGenerator.java
===================================================================
--- maven-license-switcher-plugin/trunk/src/main/java/org/nuiton/license/XmlLicenseGenerator.java (rev 0)
+++ maven-license-switcher-plugin/trunk/src/main/java/org/nuiton/license/XmlLicenseGenerator.java 2009-05-13 15:31:20 UTC (rev 1534)
@@ -0,0 +1,13 @@
+package org.nuiton.license;
+
+import org.codelutin.processor.filters.LicenseFilter;
+
+/** @author chemit */
+public class XmlLicenseGenerator implements LicenseGenerator {
+
+ @Override
+ public String getHeader(String licenseHeaderContent) {
+ return "<!--\n\n/**\n * " + LicenseFilter.HEADER + " " + licenseHeaderContent + " " + LicenseFilter.FOOTER + "\n */\n\n-->\n";
+ }
+
+}
\ No newline at end of file
Copied: maven-license-switcher-plugin/trunk/src/main/java/org/nuiton/license/plugin/SwitchLicensePlugin.java (from rev 1522, maven-license-switcher-plugin/trunk/src/main/java/org/codelutin/license/plugin/impl/SwitchLicensePlugin.java)
===================================================================
--- maven-license-switcher-plugin/trunk/src/main/java/org/nuiton/license/plugin/SwitchLicensePlugin.java (rev 0)
+++ maven-license-switcher-plugin/trunk/src/main/java/org/nuiton/license/plugin/SwitchLicensePlugin.java 2009-05-13 15:31:20 UTC (rev 1534)
@@ -0,0 +1,312 @@
+/**
+ * *##% Plugin maven pour switcher les licenses
+ * Copyright (C) 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*
+ */
+package org.nuiton.license.plugin;
+
+import org.apache.maven.plugin.MojoExecutionException;
+
+import org.codelutin.processor.LicenseProcessor;
+import org.codelutin.processor.filters.LicenseFilter;
+import org.nuiton.util.FileUtil;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import org.nuiton.AbstractPlugin;
+import org.nuiton.license.License;
+import org.nuiton.license.LicenseFactory;
+import org.nuiton.license.LicenseGenerator;
+import org.nuiton.util.FileUpdaterHelper;
+import org.nuiton.util.MirroredFileUpdater;
+
+/**
+ * Le goal pour switcher les licenses de tous les sources java d'un module
+ * maven.
+ *
+ * @author chemit
+ * @goal switch
+ * @phase process-resources
+ * @requiresProject true
+ */
+public class SwitchLicensePlugin extends AbstractPlugin {
+
+ /**
+ * Encoding a utiliser pour lire et ecrire les fichiers.
+ *
+ * @parameter expression="${helper.encoding}" default-value="${project.build.sourceEncoding}"
+ * @required
+ * @since 1.0.0
+ */
+ protected String encoding;
+ /**
+ * Un flag pour forcer la generation.
+ *
+ * @parameter expression="${helper.force}" default-value="false"
+ * @since 1.0.0
+ */
+ protected boolean force;
+ /**
+ * l'annee de creation du module (sera place dans le header)
+ *
+ * @parameter default-value="${project.inceptionYear}"
+ * @required
+ * @since 1.0.0
+ */
+ protected String inceptionYear;
+ /**
+ * le nom de l'organisation (sera place dans le header)
+ *
+ * @parameter default-value="${project.organization.name}"
+ * @required
+ * @readonly
+ * @since 1.0.0
+ */
+ protected String organizationName;
+ /**
+ * le nom du projet (sera place dans le header)
+ *
+ * @parameter default-value="${project.name}"
+ * @required
+ * @readonly
+ * @since 1.0.0
+ */
+ protected String projectName;
+ /**
+ * Le type de license a appliquer.
+ *
+ * @parameter expression="${helper.licenseName}"
+ * @required
+ * @since 1.0.0
+ */
+ protected String licenseName;
+ /**
+ * Repertoires des fichiers sources a traiter.
+ *
+ * @parameter expression="${helper.compileSourceRoots}" default-value="${project.compileSourceRoots}"
+ * @required
+ * @since 1.0.0
+ */
+ protected List<String> compileSourceRoots;
+ /**
+ * Repertoires des fichiers sources de test a traiter.
+ *
+ * @parameter expression="${helper.testCompileSourceRoots}" default-value="${project.testCompileSourceRoots}"
+ * @required
+ * @since 1.0.0
+ */
+ protected List<String> testCompileSourceRoots;
+ /**
+ * Repertoire de sortie des classes (classpath).
+ *
+ * @parameter expression="${helper.outputDirectory}" default-value="${project.build.outputDirectory}"
+ * @required
+ * @since 1.0.0
+ */
+ protected File outputDirectory;
+ /**
+ * Repertoire du build des tests
+ *
+ * @parameter expression="${helper.testOutputDirectory}" default-value="${project.build.testOutputDirectory}"
+ * @required
+ * @since 1.0.0
+ */
+ protected File testOutputDirectory;
+ /**
+ * Un resolver externe
+ *
+ * @parameter expression="${helper.extraResolver}"
+ * @since 1.0.0
+ */
+ protected String[] extraResolver;
+ /**
+ * Un flag pour conserver un backup des fichiers modifies.
+ *
+ * @parameter expression="${helper.keepBackup}" default-value="false"
+ * @since 1.0.0
+ */
+ protected boolean keepBackup;
+ /** le header a ajouter dans chaque fichier source java */
+ protected String licenseHeaderContent;
+ /** la liste des chemin relatifs des sources java a traiter pour chaque repertoire contenant des sources */
+ protected Map<File, String[]> javaFilesToTreate;
+ protected Map<LicenseGenerator, List<String>> generators;
+ protected long timestamp;
+
+ public SwitchLicensePlugin() {
+ super("all files are up-to-date.");
+ }
+
+ @Override
+ public boolean ensurePackaging() {
+ return "pom".equals(project.getPackaging()) || "site".equals(project.getPackaging());
+ }
+
+ @Override
+ public boolean init() throws IOException {
+
+ boolean doGenerate = force;
+
+ timestamp = System.nanoTime();
+
+ // obtain all java source files to be treated
+ javaFilesToTreate = getFilesToTreate();
+
+ doGenerate &= !javaFilesToTreate.isEmpty();
+
+ if (doGenerate) {
+
+ LicenseFactory factory = LicenseFactory.newInstance(extraResolver);
+ License license = factory.revolv(licenseName);
+
+ // obtain content of license header
+ licenseHeaderContent = computeHeader(license);
+
+ if (verbose) {
+ getLog().info("header to write on java source files \n" + licenseHeaderContent);
+ }
+ }
+
+ return doGenerate;
+ }
+
+ @Override
+ protected void doAction() throws Exception {
+ // create a licence processor with given header
+ LicenseProcessor p = new LicenseProcessor(licenseHeaderContent);
+
+ for (Entry<File, String[]> entry : javaFilesToTreate.entrySet()) {
+ File src = entry.getKey();
+ for (String javaRelativePath : entry.getValue()) {
+ File sourceFile = new File(src, javaRelativePath);
+ try {
+ processJavaSource(p, sourceFile);
+ } catch (Exception e) {
+ throw new MojoExecutionException("could not treate java source file " + sourceFile + " for reason : " + e.getMessage(), e);
+ }
+ }
+ }
+ }
+
+ protected Map<File, String[]> getFilesToTreate() {
+
+ Map<File, String[]> files = new java.util.HashMap<File, String[]>();
+
+ MirroredFileUpdater updater = FileUpdaterHelper.newJavaFileUpdater();
+
+ updater.setDestinationDirectory(outputDirectory);
+ getFilesToTreateForRoots(new String[]{"**\\/*.java"}, null, compileSourceRoots, files, updater);
+
+ updater.setDestinationDirectory(testOutputDirectory);
+ getFilesToTreateForRoots(new String[]{"**\\/*.java"}, null, testCompileSourceRoots, files, updater);
+
+ return files;
+ }
+
+ protected String computeHeader(License license) throws IOException {
+
+
+ String tmpHeader = license.getHeaderContent(encoding);
+
+ // defined inceptionYear (if year is older than now suffix with a - thisYear)
+ Calendar cal = Calendar.getInstance();
+ cal.setTime(new Date());
+ String thisYear = cal.get(Calendar.YEAR) + "";
+ if (!thisYear.equals(inceptionYear)) {
+ inceptionYear = inceptionYear + " - " + thisYear;
+ }
+
+ // format header with projet informations
+ tmpHeader = String.format(tmpHeader, projectName, inceptionYear, organizationName);
+
+ // add " * " before each line
+ BufferedReader reader = new BufferedReader(new java.io.StringReader(tmpHeader));
+ StringBuilder sb = new StringBuilder();
+
+ String line = reader.readLine();
+ sb.append(line).append('\n');
+ while ((line = reader.readLine()) != null) {
+ line = line.trim();
+ if (line.isEmpty()) {
+ sb.append(" *\n");
+ } else {
+ sb.append(" * ").append(line).append("\n");
+ }
+ }
+ tmpHeader = sb.toString();
+ return tmpHeader.substring(0, tmpHeader.length() - 1);
+ }
+
+ /**
+ * @param p license processor
+ * @param sourceFile the java source file where to switch (or add the licence)
+ * @throws Exception if IO pb
+ */
+ protected void processJavaSource(LicenseProcessor p, File sourceFile) throws Exception {
+
+ if (verbose) {
+ getLog().info("process file " + sourceFile);
+ }
+
+ // file where to write result
+ File processFile = new File(sourceFile.getAbsolutePath() + "_" + timestamp);
+
+ try {
+ p.process(sourceFile, processFile);
+
+ if (!p.getLicenceFilter().wasTouched()) {
+ // no license header found in file, add it
+ addLicenseToJavaSourceFile(sourceFile, processFile);
+ }
+
+ if (keepBackup) {
+ File backupFile = new File(sourceFile.getAbsolutePath() + "~");
+ if (verbose) {
+ getLog().debug("backup original file " + sourceFile);
+ }
+ sourceFile.renameTo(backupFile);
+ }
+ processFile.renameTo(sourceFile);
+
+ } catch (Exception e) {
+ getLog().error("could not process file " + sourceFile + " for reason " + e.getMessage(), e);
+ processFile.delete();
+ throw e;
+ } finally {
+ p.getLicenceFilter().reset();
+ }
+ }
+
+ protected void addLicenseToJavaSourceFile(File sourceFile, File processFile) throws IOException {
+ getLog().warn("no license was found on file " + sourceFile + ", adding one");
+ String content = FileUtil.readAsString(sourceFile, encoding);
+ content = "/**\n * " + LicenseFilter.HEADER + " " + licenseHeaderContent + " " + LicenseFilter.FOOTER + "\n */\n" + content;
+ FileUtil.writeString(processFile, content, encoding);
+ }
+
+ protected void addLicenseToXmlSourceFile(File sourceFile, File processFile) throws IOException {
+ getLog().warn("no license was found on file " + sourceFile + ", adding one");
+ String content = FileUtil.readAsString(sourceFile, encoding);
+ content = "<!--\n\n/**\n * " + LicenseFilter.HEADER + " " + licenseHeaderContent + " " + LicenseFilter.FOOTER + "\n */\n" + content + " \n\n-->";
+ FileUtil.writeString(processFile, content, encoding);
+ }
+}
Property changes on: maven-license-switcher-plugin/trunk/src/main/java/org/nuiton/license/plugin/SwitchLicensePlugin.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: maven-license-switcher-plugin/trunk/src/test/java/org/nuiton/license/JavaLicenseGeneratorTest.java (from rev 1522, maven-license-switcher-plugin/trunk/src/test/java/org/codelutin/license/JavaLicenseGeneratorTest.java)
===================================================================
--- maven-license-switcher-plugin/trunk/src/test/java/org/nuiton/license/JavaLicenseGeneratorTest.java (rev 0)
+++ maven-license-switcher-plugin/trunk/src/test/java/org/nuiton/license/JavaLicenseGeneratorTest.java 2009-05-13 15:31:20 UTC (rev 1534)
@@ -0,0 +1,24 @@
+package org.nuiton.license;
+
+import org.junit.Before;
+import org.junit.After;
+import org.junit.Test;
+
+/** @author chemit */
+public class JavaLicenseGeneratorTest {
+
+ @Before
+ public void setUp() {
+ // Add your code here
+ }
+
+ @After
+ public void tearDown() {
+ // Add your code here
+ }
+
+ @Test
+ public void testGetHeader() {
+ // Add your code here
+ }
+}
Property changes on: maven-license-switcher-plugin/trunk/src/test/java/org/nuiton/license/JavaLicenseGeneratorTest.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: maven-license-switcher-plugin/trunk/src/test/java/org/nuiton/license/XmlLicenseGeneratorTest.java (from rev 1522, maven-license-switcher-plugin/trunk/src/test/java/org/codelutin/license/XmlLicenseGeneratorTest.java)
===================================================================
--- maven-license-switcher-plugin/trunk/src/test/java/org/nuiton/license/XmlLicenseGeneratorTest.java (rev 0)
+++ maven-license-switcher-plugin/trunk/src/test/java/org/nuiton/license/XmlLicenseGeneratorTest.java 2009-05-13 15:31:20 UTC (rev 1534)
@@ -0,0 +1,23 @@
+package org.nuiton.license;
+
+import org.junit.Before;
+import org.junit.After;
+import org.junit.Test;
+
+/** @author chemit */
+public class XmlLicenseGeneratorTest {
+ @Before
+ public void setUp() {
+ // Add your code here
+ }
+
+ @After
+ public void tearDown() {
+ // Add your code here
+ }
+
+ @Test
+ public void testGetHeader() {
+ // Add your code here
+ }
+}
Property changes on: maven-license-switcher-plugin/trunk/src/test/java/org/nuiton/license/XmlLicenseGeneratorTest.java
___________________________________________________________________
Name: svn:mergeinfo
+
1
0
[Lutinutil-commits] r1533 - in maven-license-switcher-plugin/trunk/src: main/java/org main/resources test/java/org test/resources
by tchemit@users.labs.libre-entreprise.org 13 May '09
by tchemit@users.labs.libre-entreprise.org 13 May '09
13 May '09
Author: tchemit
Date: 2009-05-13 15:31:01 +0000 (Wed, 13 May 2009)
New Revision: 1533
Removed:
maven-license-switcher-plugin/trunk/src/main/java/org/codelutin/
maven-license-switcher-plugin/trunk/src/main/resources/META-INF/
maven-license-switcher-plugin/trunk/src/test/java/org/codelutin/
maven-license-switcher-plugin/trunk/src/test/resources/org/
Log:
migrate to nuiton
1
0
[Lutinutil-commits] r1532 - in maven-nuiton-project-helper-plugin/trunk: . src/main/java/org/nuiton/util
by tchemit@users.labs.libre-entreprise.org 12 May '09
by tchemit@users.labs.libre-entreprise.org 12 May '09
12 May '09
Author: tchemit
Date: 2009-05-12 11:24:39 +0000 (Tue, 12 May 2009)
New Revision: 1532
Modified:
maven-nuiton-project-helper-plugin/trunk/pom.xml
maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/util/FileUtil.java
Log:
todo
Modified: maven-nuiton-project-helper-plugin/trunk/pom.xml
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/pom.xml 2009-05-12 10:43:54 UTC (rev 1531)
+++ maven-nuiton-project-helper-plugin/trunk/pom.xml 2009-05-12 11:24:39 UTC (rev 1532)
@@ -10,7 +10,7 @@
<groupId>org.nuiton</groupId>
<artifactId>maven-helper-plugin</artifactId>
- <version>1.0.0</version>
+ <version>1.0.0-SNAPSHOT</version>
<dependencies>
@@ -38,6 +38,10 @@
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>1.5.5</version>
+ <!--
+ devrait etre en provided mais cela ne fonctionne pas
+ car enforcer-api embarque une version 1.4.2 non compatible...
+ -->
<!--scope>provided</scope-->
</dependency>
Modified: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/util/FileUtil.java
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/util/FileUtil.java 2009-05-12 10:43:54 UTC (rev 1531)
+++ maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/util/FileUtil.java 2009-05-12 11:24:39 UTC (rev 1532)
@@ -29,7 +29,13 @@
import java.nio.channels.FileChannel;
import org.codehaus.plexus.util.IOUtil;
-/** @author chemit */
+/**
+ * Methodes utiles pour le traitement de fichiers.
+ *
+ * TODO utiliser l'api offert de maven : plexus-utils par exemple...
+ *
+ * @author chemit
+ */
public class FileUtil {
/**
@@ -61,7 +67,7 @@
*/
static public String readAsString(File file, String encoding) throws IOException {
FileInputStream inf = new FileInputStream(file);
- BufferedReader in = new BufferedReader(new InputStreamReader(inf, encoding));
+ BufferedReader in = new BufferedReader(new InputStreamReader(inf, encoding));
try {
return IOUtil.toString(in);
// return FileUtil.readAsString(r);
@@ -105,5 +111,4 @@
out.write(content);
out.close();
}
-
}
1
0
[Lutinutil-commits] r1531 - in maven-nuiton-project-helper-plugin/trunk: . src/main/java/org/nuiton src/main/java/org/nuiton/enforcer src/main/java/org/nuiton/license/plugin src/main/java/org/nuiton/util src/test/java/org/nuiton src/test/java/org/nuiton/license/plugin src/test/java/org/nuiton/util src/test/resources src/test/resources/org/nuiton src/test/resources/org/nuiton/license/plugin/LicensePluginTest src/test/resources/org/nuiton/util
by tchemit@users.labs.libre-entreprise.org 12 May '09
by tchemit@users.labs.libre-entreprise.org 12 May '09
12 May '09
Author: tchemit
Date: 2009-05-12 10:43:54 +0000 (Tue, 12 May 2009)
New Revision: 1531
Added:
maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/enforcer/
maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/enforcer/CheckLabsPropertiesRule.java
maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/util/
maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/util/DependencyUtil.java
maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/util/FileUpdater.java
maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/util/FileUpdaterHelper.java
maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/util/FileUtil.java
maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/util/MirroredFileUpdater.java
maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/util/package.html
maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/license/plugin/BasePluginTestCase.java
maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/license/plugin/LicensePluginTest.java
maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/license/plugin/PluginConfig.java
maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/util/
maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/util/JavaDummy.java
maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/util/JavaFileUpdaterTest.java
maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/util/JaxxDummy.java
maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/util/JaxxFileUpdaterTest.java
maven-nuiton-project-helper-plugin/trunk/src/test/resources/log4j.properties
maven-nuiton-project-helper-plugin/trunk/src/test/resources/org/nuiton/util/
maven-nuiton-project-helper-plugin/trunk/src/test/resources/org/nuiton/util/JaxxDummy.jaxx
Modified:
maven-nuiton-project-helper-plugin/trunk/pom.xml
maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/plugin/AbstractLicensePlugin.java
maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/plugin/AvailableLicensesPlugin.java
maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/plugin/LicensePlugin.java
maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/plugin/ThirdPartyPlugin.java
maven-nuiton-project-helper-plugin/trunk/src/test/resources/org/nuiton/license/plugin/LicensePluginTest/testOne.xml
Log:
mise en commun des anciens modules lutin-enforcer-rules + lutinpluginutil + maven-license-switcher
dans un unique plugin
Modified: maven-nuiton-project-helper-plugin/trunk/pom.xml
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/pom.xml 2009-05-12 10:43:37 UTC (rev 1530)
+++ maven-nuiton-project-helper-plugin/trunk/pom.xml 2009-05-12 10:43:54 UTC (rev 1531)
@@ -8,18 +8,66 @@
<!-- ************************************************************* -->
<groupId>org.nuiton</groupId>
- <artifactId>maven-nuiton-project-helper-plugin</artifactId>
+ <artifactId>maven-helper-plugin</artifactId>
- <version>1.0.0-SNAPSHOT</version>
+ <version>1.0.0</version>
<dependencies>
-
+
+ <!-- compile dependencies -->
+
<dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>1.1.1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.maven.enforcer</groupId>
+ <artifactId>enforcer-api</artifactId>
+ <version>1.0-beta-1</version>
+ </dependency>
+
+ <dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-dependency-tree</artifactId>
<version>1.2</version>
</dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-utils</artifactId>
+ <version>1.5.5</version>
+ <!--scope>provided</scope-->
+ </dependency>
+
+ <!-- provided dependencies -->
+
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-project</artifactId>
+ <version>${maven.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-core</artifactId>
+ <version>${maven.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-artifact</artifactId>
+ <version>${maven.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>${maven.version}</version>
+ <scope>provided</scope>
+ </dependency>
+
<!-- tests dependencies -->
<dependency>
@@ -37,41 +85,20 @@
</dependency>
<dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-plugin-api</artifactId>
- <version>${maven.version}</version>
- <scope>provided</scope>
- </dependency>
-
- <dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-project</artifactId>
- <version>${maven.version}</version>
- <scope>provided</scope>
- </dependency>
-
- <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.6</version>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- <version>1.1.1</version>
- <scope>compile</scope>
- </dependency>
-
</dependencies>
<!-- ************************************************************* -->
<!-- *** Project Information ************************************* -->
<!-- ************************************************************* -->
- <name>Plugin maven d'aide pour les projets nuiton</name>
+ <name>Maven helper plugin</name>
- <url>http://lutinbuilder.labs.libre-entreprise.org/maven-nuiton-project-helper-p…</url>
+ <url>http://lutinbuilder.labs.libre-entreprise.org/${project.artifactId}</url>
<description>Plugin d'aide pour les projets nuiton</description>
<inceptionYear>2009</inceptionYear>
@@ -132,8 +159,6 @@
<defaultGoal>install</defaultGoal>
- <!--Ressources-->
-
<testResources>
<testResource>
<directory>${maven.src.dir}/test/resources</directory>
@@ -147,8 +172,7 @@
</testResources>
<plugins>
-
- <!-- plugin plugin -->
+
<plugin>
<artifactId>maven-plugin-plugin</artifactId>
<executions>
@@ -165,7 +189,7 @@
<executions>
<!--Copy licenses files for site-->
<execution>
- <id>CopySiteFiles2</id>
+ <id>copy-licenses</id>
<phase>pre-site</phase>
<configuration>
<tasks>
@@ -192,6 +216,7 @@
<plugin>
<artifactId>maven-resources-plugin</artifactId>
+ <version>2.3</version>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
@@ -199,6 +224,7 @@
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
+ <version>2.0.2</version>
<configuration>
<source>${maven.compile.source}</source>
<target>${maven.compile.target}</target>
@@ -265,6 +291,7 @@
<inputEncoding>${project.reporting.outputEncoding}</inputEncoding>
<outputEncoding>${project.reporting.outputEncoding}</outputEncoding>
<generateReports>true</generateReports>
+
</configuration>
</plugin>
@@ -273,6 +300,11 @@
<version>2.0-beta-9</version>
</plugin>
+ <plugin>
+ <artifactId>maven-plugin-plugin</artifactId>
+ <version>2.5</version>
+ </plugin>
+
</plugins>
</pluginManagement>
</build>
@@ -374,9 +406,9 @@
<!--Source control management-->
<scm>
- <connection>scm:svn:svn://anonymous@labs.libre-entreprise.org/svnroot/lutinbuilder/maven-nuiton-project-helper-plugin/trunk</connection>
- <developerConnection>scm:svn:svn+ssh://${username}@labs.libre-entreprise.org/svnroot/lutinbuilder/maven-nuiton-project-helper-plugin/trunk</developerConnection>
- <url>http://labs.libre-entreprise.org/plugins/scmsvn/viewcvs.php/maven-nuiton-pr…</url>
+ <connection>scm:svn:svn://anonymous@labs.libre-entreprise.org/svnroot/lutinbuilder/${project.artifactId}/trunk</connection>
+ <developerConnection>scm:svn:svn+ssh://${username}@labs.libre-entreprise.org/svnroot/lutinbuilder/${project.artifactId}/trunk</developerConnection>
+ <url>http://labs.libre-entreprise.org/plugins/scmsvn/viewcvs.php/${project.artif…</url>
</scm>
<distributionManagement>
@@ -386,7 +418,7 @@
</repository>
<site>
<id>labs</id>
- <url>scpexe://labs.libre-entreprise.org/home/groups/lutinbuilder/htdocs/maven-nu…</url>
+ <url>scpexe://labs.libre-entreprise.org/home/groups/lutinbuilder/htdocs/${projec…</url>
</site>
</distributionManagement>
@@ -465,24 +497,12 @@
<file>README.txt</file>
</files>
</requireFilesExist>
- <!-- on verifie que le labs.id et labs.name sont bien surchargés (sauf pour les project de
- lutinbuilder). -->
- <!--myCustomRule implementation="org.nuiton.enforcer.CheckLabsPropertiesRule" /-->
-
</rules>
<ignoreCache>true</ignoreCache>
<failFast>true</failFast>
<fail>true</fail>
</configuration>
-
- <!--dependencies>
- <dependency>
- <groupId>org.nuiton</groupId>
- <artifactId>nuiton-enforcer-rules</artifactId>
- <version>1.0.0-SNAPSHOT</version>
- </dependency>
- </dependencies-->
</plugin>
<!-- always compute source jar -->
Added: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/enforcer/CheckLabsPropertiesRule.java
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/enforcer/CheckLabsPropertiesRule.java (rev 0)
+++ maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/enforcer/CheckLabsPropertiesRule.java 2009-05-12 10:43:54 UTC (rev 1531)
@@ -0,0 +1,91 @@
+/**
+ * *##% Nuiton enforcer rules
+ * Copyright (C) 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*
+ */
+package org.nuiton.enforcer;
+
+import org.apache.maven.enforcer.rule.api.EnforcerRule;
+import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
+import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
+import org.apache.maven.plugin.logging.Log;
+import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Permet de vérifier que les propriétés <code>labs.id</code> et <code>labs.name</code> sont correctement positionnés.
+ *
+ * @author chemit
+ */
+public class CheckLabsPropertiesRule implements EnforcerRule {
+
+ public static final String NUITONBUILDER_LABS_NAME = "nuitonbuilder";
+ public static final String NUTIONBUILDER_LABS_ID = "1";
+
+ public static final List<String> NUITONBUILDER_PROJECT_ARTIFACT_IDS = Arrays.asList("nuitonproject", "maven-nuiton-skin", "nuiton-enforcer-rules");
+
+ @Override
+ public void execute(EnforcerRuleHelper helper) throws EnforcerRuleException {
+ Log log = helper.getLog();
+
+ try {
+ // get the various expressions out of the helper.
+ //MavenProject project = (MavenProject) helper.evaluate("${project}");
+ //MavenSession session = (MavenSession) helper.evaluate("${session}");
+
+ String labsName = (String) helper.evaluate("${labs.name}");
+ String labsId = (String) helper.evaluate("${labs.id}");
+ String artifactId = (String) helper.evaluate("${project.artifactId}");
+
+ if (log.isDebugEnabled()) {
+ log.debug("Retrieved ArtifactId: " + artifactId);
+ log.debug("Retrieved LabsId: " + labsId);
+ log.debug("Retrieved LabsName: " + labsName);
+
+ }
+ if (NUTIONBUILDER_LABS_ID.equals(labsId) || NUITONBUILDER_LABS_NAME.equals(labsName)) {
+ // must check we are on a lutinbuilder project
+ if (!NUITONBUILDER_PROJECT_ARTIFACT_IDS.contains(artifactId)) {
+ // a none lutinbuilder project can not have this labs.id value
+ throw new EnforcerRuleException("labs.id and labs.name must be override for your project, but was not!");
+ }
+ }
+
+
+ }
+ catch (ExpressionEvaluationException e) {
+ throw new EnforcerRuleException("Unable to lookup an expression " + e.getLocalizedMessage(), e);
+ }
+
+ }
+
+ @Override
+ public boolean isCacheable() {
+ return false;
+ }
+
+ @Override
+ public boolean isResultValid(EnforcerRule cachedRule) {
+ return false;
+ }
+
+ @Override
+ public String getCacheId() {
+ return null;
+ }
+}
Modified: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/plugin/AbstractLicensePlugin.java
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/plugin/AbstractLicensePlugin.java 2009-05-12 10:43:37 UTC (rev 1530)
+++ maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/plugin/AbstractLicensePlugin.java 2009-05-12 10:43:54 UTC (rev 1531)
@@ -82,25 +82,25 @@
/**
* Un flag pour conserver un backup des fichiers modifies.
*
- * @parameter expression="${license-switcher.keepBackup}" default-value="false"
+ * @parameter expression="${helper.keepBackup}" default-value="false"
*/
protected boolean keepBackup;
/**
* Un flag pour activer le mode verbeux.
*
- * @parameter expression="${license-switcher.verbose}" default-value="${maven.verbose}"
+ * @parameter expression="${helper.verbose}" default-value="${maven.verbose}"
*/
protected boolean verbose;
/**
* Un flag pour forcer la generation.
*
- * @parameter expression="${license-switcher.force}" default-value="false"
+ * @parameter expression="${helper.force}" default-value="false"
*/
protected boolean force;
/**
* Fichier ou ecrire les licences des dependances.
*
- * @parameter expression="${license-switcher.pomFile}" default-value="pom.xml"
+ * @parameter expression="${helper.pomFile}" default-value="pom.xml"
* @required
*/
protected File pomFile;
Modified: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/plugin/AvailableLicensesPlugin.java
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/plugin/AvailableLicensesPlugin.java 2009-05-12 10:43:37 UTC (rev 1530)
+++ maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/plugin/AvailableLicensesPlugin.java 2009-05-12 10:43:54 UTC (rev 1531)
@@ -37,7 +37,7 @@
/**
* La baseURL d'un resolver de license supplementaire
*
- * @parameter expression="${license-switcher.extraResolver}"
+ * @parameter expression="${helper.extraResolver}"
*/
protected String extraResolver;
Modified: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/plugin/LicensePlugin.java
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/plugin/LicensePlugin.java 2009-05-12 10:43:37 UTC (rev 1530)
+++ maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/plugin/LicensePlugin.java 2009-05-12 10:43:54 UTC (rev 1531)
@@ -20,7 +20,6 @@
import org.nuiton.license.License;
import org.nuiton.license.LicenseFactory;
-import org.nuiton.license.plugin.AbstractLicensePlugin;
import java.io.File;
@@ -38,7 +37,7 @@
/**
* Fichier de la licence du module.
*
- * @parameter expression="${license-switcher.licenceFile}" default-value="${basedir}/LICENSE.txt"
+ * @parameter expression="${helper.licenceFile}" default-value="${basedir}/LICENSE.txt"
* @required
* @readonly
*/
@@ -46,14 +45,14 @@
/**
* Le type de license a appliquer.
*
- * @parameter expression="${license-switcher.licenseName}"
+ * @parameter expression="${helper.licenseName}"
* @required
*/
protected String licenseName;
/**
* La baseURL d'un resolver de license supplementaire
*
- * @parameter expression="${license-switcher.extraResolver}"
+ * @parameter expression="${helper.extraResolver}"
*/
protected String[] extraResolver;
protected License license;
Modified: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/plugin/ThirdPartyPlugin.java
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/plugin/ThirdPartyPlugin.java 2009-05-12 10:43:37 UTC (rev 1530)
+++ maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/plugin/ThirdPartyPlugin.java 2009-05-12 10:43:54 UTC (rev 1531)
@@ -32,7 +32,6 @@
import org.apache.maven.shared.dependency.tree.DependencyNode;
import org.apache.maven.shared.dependency.tree.DependencyTreeBuilder;
import org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException;
-import org.nuiton.license.plugin.AbstractLicensePlugin;
import java.io.File;
import java.util.List;
@@ -71,7 +70,7 @@
/**
* Fichier ou ecrire les licences des dependances.
*
- * @parameter expression="${license-switcher.thirdPartyFile}" default-value="${project.build.outputDirectory}/THIRD-PARTY.txt"
+ * @parameter expression="${helper.thirdPartyFile}" default-value="${project.build.outputDirectory}/THIRD-PARTY.txt"
* @required
*/
protected File thirdPartyFile;
Copied: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/util/DependencyUtil.java (from rev 1522, nuitonpluginutil/trunk/src/main/java/org/codelutin/util/DependencyUtil.java)
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/util/DependencyUtil.java (rev 0)
+++ maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/util/DependencyUtil.java 2009-05-12 10:43:54 UTC (rev 1531)
@@ -0,0 +1,216 @@
+package org.nuiton.util;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.shared.dependency.tree.DependencyNode;
+
+/**
+ * Une classe de methodes utiles sur les dependences entre artifacts.
+ *
+ * @author chemit
+ * @since 0.5
+ */
+public class DependencyUtil {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ private static final Log log = LogFactory.getLog(DependencyUtil.class);
+
+ public static void sortArtifacts(DependencyNode rootNode, List<Artifact> i18nArtifacts, boolean verbose) {
+
+ if (i18nArtifacts.size() == 1) {
+ return;
+ }
+
+ Map<String, ArtifactDependencyEntry> dico = new java.util.HashMap<String, ArtifactDependencyEntry>(i18nArtifacts.size());
+
+ for (Artifact a : i18nArtifacts) {
+ ArtifactDependencyEntry entry = new ArtifactDependencyEntry(a);
+ dico.put(entry.artifactKey, entry);
+ }
+
+ // contient les artifacts non encore fixes
+ Set<String> universe = new java.util.HashSet<String>(dico.keySet());
+
+ // recupere les noeuds pour chaque artifact en une seule passe
+
+ setNodes(rootNode, dico, universe, verbose);
+
+ // contient les artifacts resouds dans l'ordre de dependances
+ List<String> parsed = new java.util.ArrayList<String>();
+
+ // premiere passe pour recuperer l'ensemble des dependances
+ for (ArtifactDependencyEntry entry : dico.values()) {
+ List<String> dependencies = getDependencies(rootNode, entry, universe, verbose);
+ entry.depIds = dependencies;
+ }
+
+ int level = 0;
+ do {
+ if (verbose) {
+ log.info("run into level " + (level++));
+ }
+ // on parcourt les artifacts pour detecter les nouveau artifacts fixes
+ List<String> levelFixed = new java.util.ArrayList<String>();
+
+ for (String key : universe) {
+ ArtifactDependencyEntry entry = dico.get(key);
+ // cet artifact n'est pas encore fixe
+ if (entry.depIds.isEmpty()) {
+ // plus de dependance pour cet artifact
+ levelFixed.add(key);
+ if (verbose) {
+ log.info("fixed artifact " + key);
+ }
+ }
+ }
+
+ if (levelFixed.isEmpty()) {
+ // aucune modification, c'est un cycle!
+ throw new IllegalStateException("cycle detecte ! entre les artifacts " + universe);
+ }
+
+ // on met a jour les listes
+ universe.removeAll(levelFixed);
+ parsed.addAll(levelFixed);
+
+ if (universe.isEmpty()) {
+ // tout a ete resolu, plus rien a faire
+ break;
+ }
+
+ // on supprime les dependances fixees a ce niveau
+ for (String key : universe) {
+ ArtifactDependencyEntry entry = dico.get(key);
+ entry.depIds.removeAll(levelFixed);
+ }
+
+ levelFixed.clear();
+ } while (true);
+
+ i18nArtifacts.clear();
+ for (String key : parsed) {
+ i18nArtifacts.add(dico.get(key).artifact);
+ }
+
+ }
+
+ protected static String getArtifactId(Artifact artifact) {
+ return artifact.getArtifactId() + ":" + artifact.getGroupId();
+ }
+
+ protected static List<String> getDependencies(DependencyNode rootNode, ArtifactDependencyEntry entry, Set<String> universe, boolean verbose) {
+
+ List<String> order = new java.util.ArrayList<String>();
+ Set<String> exclude = new java.util.HashSet<String>();
+
+ if (verbose) {
+ log.info("start [" + entry.artifactKey + "]");
+ }
+ DependencyNode node = entry.node;
+
+ getDependencies(rootNode, node, entry.artifactKey, universe, verbose, order, exclude);
+
+ return order;
+ }
+
+ private static void getDependencies(DependencyNode rootNode, DependencyNode node, String artifactKey, Set<String> universe, boolean verbose, List<String> order, Set<String> exclude) {
+
+ for (Iterator<?> itr = node.preorderIterator(); itr.hasNext();) {
+ DependencyNode d = (DependencyNode) itr.next();
+ Artifact artifact = d.getArtifact();
+ String key = getArtifactId(artifact);
+ if (artifactKey.equals(key)) {
+ // artifact du noeud en parametre, rien a faire
+ continue;
+ }
+ if (order.contains(key) || exclude.contains(key)) {
+ // artifact deja rencontree
+ continue;
+ }
+
+ if (d.getState() != DependencyNode.INCLUDED) {
+ // on doit recuperer le noeud complete
+ if (log.isDebugEnabled()) {
+ log.debug("!!! doit recuperer le noeud complet pour " + d.getArtifact());
+ }
+ DependencyNode node1 = getNode(rootNode, key, verbose);
+ getDependencies(rootNode, node1, artifactKey, universe, verbose, order, exclude);
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("[" + artifactKey + "] ??????? [" + key + "]");
+ }
+
+ if (universe.contains(key)) {
+ // artifact a retenir
+ if (verbose) {
+ log.info(" << [" + d.getArtifact() + "]");
+ }
+ order.add(key);
+ continue;
+ }
+
+ // cet artifact peut etre marque comme a ne plus etre scanne
+ exclude.add(key);
+ }
+
+ }
+
+ protected static void setNodes(DependencyNode rootNode, Map<String, ArtifactDependencyEntry> dico, Set<String> universe, boolean verbose) {
+
+ for (Iterator<?> itr = rootNode.preorderIterator(); itr.hasNext();) {
+ DependencyNode d = (DependencyNode) itr.next();
+ Artifact artifact = d.getArtifact();
+ String key = getArtifactId(artifact);
+ if (log.isDebugEnabled()) {
+ log.debug("key : " + key);
+ }
+ if (universe.contains(key) && d.getState() == DependencyNode.INCLUDED) {
+ ArtifactDependencyEntry entry = dico.get(key);
+ entry.node = d;
+ if (d == null) {
+ // ce cas ne devrait jamais arrive
+ throw new IllegalStateException("on a pas trouve le node pour l'artifact " + artifact);
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("detected node : " + d);
+ }
+ }
+ }
+ }
+
+ protected static DependencyNode getNode(DependencyNode rootNode, String requiredKey, boolean verbose) {
+
+ for (Iterator<?> itr = rootNode.preorderIterator(); itr.hasNext();) {
+ DependencyNode d = (DependencyNode) itr.next();
+ Artifact artifact = d.getArtifact();
+ String key = getArtifactId(artifact);
+ if (log.isDebugEnabled()) {
+ log.debug("key : " + key);
+ }
+ if (requiredKey.equals(key) && d.getState() == DependencyNode.INCLUDED) {
+ return d;
+ }
+ }
+
+ return null;
+ }
+
+ public static class ArtifactDependencyEntry {
+
+ protected final Artifact artifact;
+ protected final String artifactKey;
+ protected DependencyNode node;
+ protected List<String> depIds;
+
+ public ArtifactDependencyEntry(Artifact artifact) {
+ this.artifact = artifact;
+ this.artifactKey = getArtifactId(artifact);
+ }
+ }
+}
Property changes on: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/util/DependencyUtil.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/util/FileUpdater.java (from rev 1522, nuitonpluginutil/trunk/src/main/java/org/codelutin/util/FileUpdater.java)
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/util/FileUpdater.java (rev 0)
+++ maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/util/FileUpdater.java 2009-05-12 10:43:54 UTC (rev 1531)
@@ -0,0 +1,38 @@
+/**
+ * *##% Lutin plugin utilities library
+ * Copyright (C) 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*
+ */
+package org.nuiton.util;
+
+import java.io.File;
+
+/**
+ * Contract to be realized to test if a file is up to date.
+ * <p/>
+ * use {@link #isFileUpToDate(java.io.File)} to determine if a file is up to date.
+ *
+ * @author chemit
+ */
+public interface FileUpdater {
+
+ /**
+ * @param f file to test
+ * @return <code>true</code> if file is up to date, <code>false</code> otherwise
+ */
+ boolean isFileUpToDate(File f);
+
+}
Property changes on: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/util/FileUpdater.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/util/FileUpdaterHelper.java (from rev 1522, nuitonpluginutil/trunk/src/main/java/org/codelutin/util/FileUpdaterHelper.java)
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/util/FileUpdaterHelper.java (rev 0)
+++ maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/util/FileUpdaterHelper.java 2009-05-12 10:43:54 UTC (rev 1531)
@@ -0,0 +1,70 @@
+/**
+ * *##% Lutin plugin utilities library
+ * Copyright (C) 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*
+ */
+package org.nuiton.util;
+
+import java.io.File;
+
+/** @author chemit */
+public class FileUpdaterHelper {
+
+ static public FileUpdater newJavaFileUpdater(File src, File dst) {
+ return new JavaFileUpdater(src, dst);
+ }
+
+ static public FileUpdater newJaxxFileUpdater(File src, File dst) {
+ return new JaxxFileUpdater(src, dst);
+ }
+
+ /**
+ * To test if a java source file is newser than his compiled class
+ *
+ * @author chemit
+ */
+ public static class JavaFileUpdater extends MirroredFileUpdater {
+
+ protected JavaFileUpdater(File sourceDirectory, File destinationDirectory) {
+ super(sourceDirectory, destinationDirectory);
+ }
+
+ public File getMirrorFile(File f) {
+ String file = f.getAbsolutePath().substring(prefixSourceDirecotory);
+ String mirrorRelativePath = file.substring(0, file.length() - 4) + "class";
+ return new File(destinationDirectory + File.separator + mirrorRelativePath);
+ }
+ }
+
+ /**
+ * To test if a jaxx source file is newser than his generated java source file
+ *
+ * @author chemit
+ */
+ public static class JaxxFileUpdater extends MirroredFileUpdater {
+
+ protected JaxxFileUpdater(File sourceDirectory, File destinationDirectory) {
+ super(sourceDirectory, destinationDirectory);
+ }
+
+ public File getMirrorFile(File f) {
+ String file = f.getAbsolutePath().substring(prefixSourceDirecotory);
+ String mirrorRelativePath = file.substring(0, file.length() - 4) + "java";
+ return new File(destinationDirectory + File.separator + mirrorRelativePath);
+ }
+
+ }
+}
Property changes on: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/util/FileUpdaterHelper.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/util/FileUtil.java (from rev 1522, nuitonpluginutil/trunk/src/main/java/org/codelutin/util/FileUtil.java)
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/util/FileUtil.java (rev 0)
+++ maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/util/FileUtil.java 2009-05-12 10:43:54 UTC (rev 1531)
@@ -0,0 +1,109 @@
+/**
+ * *##% Lutin plugin utilities library
+ * Copyright (C) 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*
+ */
+package org.nuiton.util;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.nio.channels.FileChannel;
+import org.codehaus.plexus.util.IOUtil;
+
+/** @author chemit */
+public class FileUtil {
+
+ /**
+ * Permet de copier le fichier source vers le fichier cible.
+ *
+ * @param source le fichier source
+ * @param target le fichier cible
+ * @throws java.io.IOException Erreur de copie
+ */
+ public static void copy(File source, File target) throws IOException {
+ target.getParentFile().mkdirs();
+ FileChannel sourceChannel = new FileInputStream(source).getChannel();
+ FileChannel targetChannel = new FileOutputStream(target).getChannel();
+ sourceChannel.transferTo(0, sourceChannel.size(), targetChannel);
+ // or
+ // targetChannel.transferFrom(sourceChannel, 0, sourceChannel.size());
+ sourceChannel.close();
+ targetChannel.close();
+ }
+
+ /**
+ * Permet de lire un fichier et de retourner sont contenu sous forme d'une
+ * chaine de carateres
+ *
+ * @param file le fichier a lire
+ * @param encoding encoding to read file
+ * @return the content of the file
+ * @throws IOException if IO pb
+ */
+ static public String readAsString(File file, String encoding) throws IOException {
+ FileInputStream inf = new FileInputStream(file);
+ BufferedReader in = new BufferedReader(new InputStreamReader(inf, encoding));
+ try {
+ return IOUtil.toString(in);
+// return FileUtil.readAsString(r);
+ } finally {
+ in.close();
+ }
+ }
+
+ /**
+ * Permet de lire un fichier et de retourner sont contenu sous forme d'une
+ * chaine de carateres
+ *
+ * @param file le reader a lire
+ * @return the content of the file
+ * @throws IOException if IO pb
+ */
+ static public String readAsString(java.io.Reader file) throws IOException {
+ StringBuffer result = new StringBuffer();
+ char[] cbuf = new char[2000];
+ BufferedReader in = new BufferedReader(file);
+ int nb = in.read(cbuf);
+ while (nb != -1) {
+ result.append(cbuf, 0, nb);
+ nb = in.read(cbuf);
+ }
+ in.close();
+ return result.toString();
+ }
+
+ /**
+ * Sauvegarde un contenu dans un fichier.
+ *
+ * @param file le fichier a ecrire
+ * @param content le contenu du fichier
+ * @param encoding l'encoding d'ecriture
+ * @throws IOException if IO pb
+ */
+ static public void writeString(File file, String content, String encoding) throws IOException {
+ file.getParentFile().mkdirs();
+ BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), encoding));
+ out.write(content);
+ out.close();
+ }
+
+}
Property changes on: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/util/FileUtil.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/util/MirroredFileUpdater.java (from rev 1522, nuitonpluginutil/trunk/src/main/java/org/codelutin/util/MirroredFileUpdater.java)
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/util/MirroredFileUpdater.java (rev 0)
+++ maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/util/MirroredFileUpdater.java 2009-05-12 10:43:54 UTC (rev 1531)
@@ -0,0 +1,73 @@
+/**
+ * *##% Lutin plugin utilities library
+ * Copyright (C) 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*
+ */
+package org.nuiton.util;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.File;
+
+/**
+ * Simple base implementation of a {@link FileUpdater} for an updater with a sourcedir and a destinationdir.
+ *
+ * @author chemit
+ */
+public abstract class MirroredFileUpdater implements FileUpdater {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private final Log log = LogFactory.getLog(MirroredFileUpdater.class);
+
+ /** source basedir */
+ protected File sourceDirectory;
+
+ /** length of source basedir absolute path */
+ protected int prefixSourceDirecotory;
+
+ /** destination basedir */
+ protected File destinationDirectory;
+
+ protected MirroredFileUpdater(File sourceDirectory, File destinationDirectory) {
+ this.sourceDirectory = sourceDirectory;
+ this.destinationDirectory = destinationDirectory;
+ this.prefixSourceDirecotory = sourceDirectory.getAbsolutePath().length();
+ if (log.isDebugEnabled()) {
+ log.debug(this);
+ }
+ }
+
+ public File getSourceDirectory() {
+ return sourceDirectory;
+ }
+
+ public File getDestinationDirectory() {
+ return destinationDirectory;
+ }
+
+ public abstract File getMirrorFile(File f);
+
+ public boolean isFileUpToDate(File f) {
+ File mirror = getMirrorFile(f);
+ return mirror.exists() && f.lastModified() < mirror.lastModified();
+ }
+
+ @Override
+ public String toString() {
+ return super.toString() + "<srcdir:" + sourceDirectory + ", destdir:" + destinationDirectory + ">";
+ }
+}
Property changes on: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/util/MirroredFileUpdater.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/util/package.html (from rev 1522, nuitonpluginutil/trunk/src/main/java/org/codelutin/util/package.html)
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/util/package.html (rev 0)
+++ maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/util/package.html 2009-05-12 10:43:54 UTC (rev 1531)
@@ -0,0 +1,7 @@
+<html>
+<body>
+<h1>Lutin plugin util</h1>
+Ensemble de classe Java permettant de simplifier le developpement de plugins maven en
+factorisant des besoins que l'on retrouve dans tous les developpements.
+</body>
+</html>
\ No newline at end of file
Property changes on: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/util/package.html
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/license/plugin/BasePluginTestCase.java (from rev 1529, maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/plugin/BasePluginTestCase.java)
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/license/plugin/BasePluginTestCase.java (rev 0)
+++ maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/license/plugin/BasePluginTestCase.java 2009-05-12 10:43:54 UTC (rev 1531)
@@ -0,0 +1,99 @@
+package org.nuiton.license.plugin;
+
+import org.apache.maven.plugin.Mojo;
+import org.apache.maven.plugin.testing.AbstractMojoTestCase;
+import org.junit.Before;
+
+import java.io.File;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/** @author chemit */
+public abstract class BasePluginTestCase {
+
+ protected static File basedir;
+ protected static File testDir;
+ protected static Iterator<PluginConfig> configItr;
+ protected static MyAbstractMojoTestCase delegate;
+
+ protected String goalName;
+ protected File pomFile;
+ protected Mojo mojo;
+
+ protected static File getBaseDir() {
+ if (basedir == null) {
+ String path = System.getenv("basedir");
+ if (path == null) {
+ path = new File("").getAbsolutePath();
+ }
+ basedir = new File(path);
+ }
+ return basedir;
+ }
+
+ protected static File getTestDir() {
+ return testDir;
+ }
+
+ protected static void initConfigs(Class<? extends BasePluginTestCase> klass, String... testNames) throws Exception {
+ List<PluginConfig> configs = new ArrayList<PluginConfig>();
+ String rep = klass.getName();
+ rep = rep.replaceAll("\\.", File.separator);
+
+ File f = new File(getBaseDir(), "target" + File.separator + "test-classes");
+ //File f = new File(getBaseDir(), "src" + File.separator + "test" + File.separator + "resources");
+ testDir = new File(f, rep);
+ System.out.println("test dir : " + testDir);
+
+ for (String testName : testNames) {
+ Method m = klass.getMethod(testName);
+ if (m == null) {
+ throw new IllegalAccessException("could not find method " + testName + " on class " + klass.getName());
+ }
+
+ PluginConfig annotation = m.getAnnotation(PluginConfig.class);
+ if (annotation == null) {
+ throw new IllegalAccessException("could not find annotation " + PluginConfig.class.getName() + " on method " + testName);
+ }
+ configs.add(annotation);
+ }
+
+ delegate = new MyAbstractMojoTestCase();
+ delegate.setUp();
+ configItr = configs.iterator();
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ initPomFile(configItr.next());
+ }
+
+ protected void initPomFile(PluginConfig pluginConfig) throws Exception {
+ this.goalName = pluginConfig.goalName();
+ this.pomFile = new File(getTestDir(), pluginConfig.pomName());
+ this.mojo = delegate.lookupMojo(goalName, pomFile);
+
+ }
+
+ public static class MyAbstractMojoTestCase extends AbstractMojoTestCase {
+
+ @Override
+ public Mojo lookupMojo(String goal, File pom) throws Exception {
+ return super.lookupMojo(goal, pom);
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+
+ }
+}
\ No newline at end of file
Property changes on: maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/license/plugin/BasePluginTestCase.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/license/plugin/LicensePluginTest.java (from rev 1529, maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/plugin/impl/LicensePluginTest.java)
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/license/plugin/LicensePluginTest.java (rev 0)
+++ maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/license/plugin/LicensePluginTest.java 2009-05-12 10:43:54 UTC (rev 1531)
@@ -0,0 +1,58 @@
+package org.nuiton.license.plugin;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+import org.junit.AfterClass;
+
+/** @author chemit */
+public class LicensePluginTest extends BasePluginTestCase {
+
+ @BeforeClass
+ public static void initClass() throws Exception {
+ initConfigs(LicensePluginTest.class, "testOne");
+ }
+
+ @AfterClass
+ public static void afterClass() throws Exception {
+ configItr = null;
+ testDir = null;
+ }
+
+ @Before
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ LicensePlugin plugin = (LicensePlugin) mojo;
+ plugin.setPomFile(pomFile);
+ plugin.setOutputDirectory(new File(getBaseDir(), plugin.getOutputDirectory().toString()));
+ if (!plugin.getOutputDirectory().exists()) {
+ if (!plugin.getOutputDirectory().mkdirs()) {
+ throw new IOException("could not create directory : " + plugin.getOutputDirectory());
+ }
+ }
+ plugin.setLicenseFile(new File(pomFile.getParentFile(), plugin.getLicenseFile().toString()));
+ }
+
+ @Test
+ @PluginConfig(pomName = "testOne.xml", goalName = "add-license")
+ public void testOne() throws MojoExecutionException, MojoFailureException {
+ // Add your code here
+ Assert.assertNotNull(this.mojo);
+
+ LicensePlugin p = (LicensePlugin) mojo;
+
+ // always assume pom is older than any file
+ // since we can not ensure order of copy test resources
+ p.getPomFile().setLastModified(0);
+ this.mojo.execute();
+
+ }
+
+}
Property changes on: maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/license/plugin/LicensePluginTest.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/license/plugin/PluginConfig.java (from rev 1529, maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/plugin/PluginConfig.java)
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/license/plugin/PluginConfig.java (rev 0)
+++ maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/license/plugin/PluginConfig.java 2009-05-12 10:43:54 UTC (rev 1531)
@@ -0,0 +1,20 @@
+package org.nuiton.license.plugin;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+
+/** @author chemit */
+(a)Retention(RetentionPolicy.RUNTIME)
+
+(a)Target(ElementType.METHOD)
+@Inherited
+public @interface PluginConfig {
+
+ String goalName();
+
+ String pomName();
+
+}
\ No newline at end of file
Property changes on: maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/license/plugin/PluginConfig.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/util/JavaDummy.java (from rev 1522, nuitonpluginutil/trunk/src/test/java/org/codelutin/util/JavaDummy.java)
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/util/JavaDummy.java (rev 0)
+++ maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/util/JavaDummy.java 2009-05-12 10:43:54 UTC (rev 1531)
@@ -0,0 +1,26 @@
+/**
+ * *##% Lutin plugin utilities library
+ * Copyright (C) 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*
+ */
+package org.nuiton.util;
+
+/** @author chemit */
+public class JavaDummy {
+ /**
+ * A dummy file to test {@link org.codelutin.util.FileUpdaterHelper.JavaFileUpdater} in {@link JavaFileUpdaterTest}
+ */
+}
Property changes on: maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/util/JavaDummy.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/util/JavaFileUpdaterTest.java (from rev 1522, nuitonpluginutil/trunk/src/test/java/org/codelutin/util/JavaFileUpdaterTest.java)
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/util/JavaFileUpdaterTest.java (rev 0)
+++ maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/util/JavaFileUpdaterTest.java 2009-05-12 10:43:54 UTC (rev 1531)
@@ -0,0 +1,157 @@
+/**
+ * *##% Lutin plugin utilities library
+ * Copyright (C) 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. *##%
+ */
+/*
+ * Copyright (C) 2002-2008 Code Lutin, Benjamin Poussin
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ * USA.
+ */
+
+package org.nuiton.util;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.nuiton.util.FileUpdaterHelper.JavaFileUpdater;
+import java.io.File;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ * Test of a {@link JavaFileUpdater} on the test sourcepath and test-classpath
+ *
+ * @author chemit
+ */
+public class JavaFileUpdaterTest {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private final Log log = LogFactory.getLog(FileUpdaterHelper.class);
+
+
+ static final char SEP = File.separatorChar;
+
+ static MirroredFileUpdater fileUpdater;
+
+ static File sourceFile;
+ static File mirrorFile;
+
+ @BeforeClass
+ public static void initClass() throws Exception {
+ String basedir = System.getProperty("basedir");
+ if (basedir == null) {
+ log.warn("basedir not found, test is not executed from maven...");
+ basedir = new File(new File("").getAbsolutePath()).getAbsolutePath();
+ }
+
+ log.info("basedir = " + basedir);
+
+ File src = new File(basedir, "src" + SEP + "test" + SEP + "java");
+ File dir = new File(basedir, "target" + SEP + "test-classes");
+ fileUpdater = (MirroredFileUpdater) FileUpdaterHelper.newJavaFileUpdater(src, dir);
+ log.info(fileUpdater);
+
+ // test source dir exists
+ File sourceDirectory = fileUpdater.getSourceDirectory();
+ assertTrue("sourcedir is null", sourceDirectory != null);
+ assertTrue("sourcedir does not exists " + sourceDirectory, sourceDirectory.exists());
+
+ // test destination dir exists
+ File destinationDirectory = fileUpdater.getDestinationDirectory();
+ assertTrue("destinationDirectory is null", destinationDirectory != null);
+ assertTrue("destinationDirectory does not exists " + destinationDirectory, destinationDirectory.exists());
+
+ sourceFile = new File(fileUpdater.getSourceDirectory(), "org" + SEP + "nuiton" + SEP + "util" + SEP + JavaDummy.class.getSimpleName() + ".java");
+
+ }
+
+@Test
+ public void testSourceFileIsUptoDate() throws Exception {
+
+ assertTrue("fileUpdater was not init", fileUpdater != null);
+ assertTrue("sourceFile was not init ", sourceFile != null);
+ assertTrue("could not find source of this test " + sourceFile, sourceFile.exists());
+
+ // java file is up to date since it was compiled to launch this test
+ assertTrue(sourceFile + " should be uptodate", fileUpdater.isFileUpToDate(sourceFile));
+
+ mirrorFile = fileUpdater.getMirrorFile(sourceFile);
+ }
+
+@Test
+ public void testSourceFileDoesNotHaveMirrorFile() throws Exception {
+
+ assertTrue("fileUpdater was not init", fileUpdater != null);
+ assertTrue("sourceFile was not init ", sourceFile != null);
+ assertTrue("could not find source of this test " + sourceFile, sourceFile.exists());
+ assertTrue("mirrorFile was not init ", mirrorFile != null);
+ assertTrue("could not find mirrorFile " + mirrorFile, mirrorFile.exists());
+
+ // now rename mirror Class, so source file is no more up to date
+ File mirrorClassRenamed = new File(fileUpdater.getMirrorFile(sourceFile).getAbsolutePath() + "2");
+ mirrorFile.renameTo(mirrorClassRenamed);
+
+ // java file is no more up to date
+ assertFalse(sourceFile + " should not be uptodate", fileUpdater.isFileUpToDate(sourceFile));
+
+ // renmae mirror Class to his original name
+ mirrorClassRenamed.renameTo(mirrorFile);
+
+ // java file is now up to date (rename method does not affect lasmodified property on a file)
+ assertTrue(sourceFile + " should be uptodate", fileUpdater.isFileUpToDate(sourceFile));
+ }
+
+@Test
+ public void testSourceFileIsNewerThanMirrorFile() throws Exception {
+
+ assertTrue("fileUpdater was not init", fileUpdater != null);
+ assertTrue("sourceFile was not init ", sourceFile != null);
+ assertTrue("could not find source of this test " + sourceFile, sourceFile.exists());
+ assertTrue("mirrorFile was not init ", mirrorFile != null);
+ assertTrue("could not find mirrorFile " + mirrorFile, mirrorFile.exists());
+
+ long sourceTime = sourceFile.lastModified();
+ long mirrorTime = mirrorFile.lastModified();
+
+ // make source file newer than mirror file
+ sourceFile.setLastModified(mirrorTime + 10);
+
+ // java file is no more up to date
+ assertFalse(sourceFile + " should not be uptodate", fileUpdater.isFileUpToDate(sourceFile));
+
+ // put back old time to source file
+ sourceFile.setLastModified(sourceTime);
+
+ // java file is now up to date (rename method does not affect lasmodified property on a file)
+ assertTrue(sourceFile + " should be uptodate", fileUpdater.isFileUpToDate(sourceFile));
+ }
+
+}
Property changes on: maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/util/JavaFileUpdaterTest.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/util/JaxxDummy.java (from rev 1522, nuitonpluginutil/trunk/src/test/java/org/codelutin/util/JaxxDummy.java)
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/util/JaxxDummy.java (rev 0)
+++ maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/util/JaxxDummy.java 2009-05-12 10:43:54 UTC (rev 1531)
@@ -0,0 +1,26 @@
+/**
+ * *##% Lutin plugin utilities library
+ * Copyright (C) 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*
+ */
+package org.nuiton.util;
+
+/** @author chemit */
+public class JaxxDummy {
+ /**
+ * A dummy file to test {@link org.codelutin.util.FileUpdaterHelper.JaxxFileUpdater} in {@link JaxxFileUpdaterTest}
+ */
+}
Property changes on: maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/util/JaxxDummy.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/util/JaxxFileUpdaterTest.java (from rev 1522, nuitonpluginutil/trunk/src/test/java/org/codelutin/util/JaxxFileUpdaterTest.java)
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/util/JaxxFileUpdaterTest.java (rev 0)
+++ maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/util/JaxxFileUpdaterTest.java 2009-05-12 10:43:54 UTC (rev 1531)
@@ -0,0 +1,160 @@
+/**
+ * *##% Lutin plugin utilities library
+ * Copyright (C) 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. *##%
+ */
+/*
+ * Copyright (C) 2002-2008 Code Lutin, Benjamin Poussin
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ * USA.
+ */
+package org.nuiton.util;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.File;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ * Test of a {@link org.codelutin.util.FileUpdaterHelper.JaxxFileUpdater} on the test sourcepath
+ *
+ * @author chemit
+ */
+public class JaxxFileUpdaterTest {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private final Log log = LogFactory.getLog(FileUpdaterHelper.class);
+ static final char SEP = File.separatorChar;
+ static MirroredFileUpdater fileUpdater;
+ static File sourceFile;
+ static File mirrorFile;
+
+ @BeforeClass
+ public static void initClass() throws Exception {
+
+ String basedir = System.getProperty("basedir");
+ if (basedir == null) {
+ log.warn("basedir not found, test is not executed from maven...");
+ basedir = new File(new File("").getAbsolutePath()).getAbsolutePath();
+ }
+
+ log.info("basedir = " + basedir);
+
+ File src = new File(basedir, "src" + SEP + "test" + SEP + "resources");
+ File dir = new File(basedir, "src" + SEP + "test" + SEP + "java");
+ fileUpdater = (MirroredFileUpdater) FileUpdaterHelper.newJaxxFileUpdater(src, dir);
+ log.info(fileUpdater);
+
+ // test source dir exists
+ File sourceDirectory = fileUpdater.getSourceDirectory();
+ assertTrue("sourcedir is null", sourceDirectory != null);
+ assertTrue("sourcedir does not exists " + sourceDirectory, sourceDirectory.exists());
+
+ // test destination dir exists
+ File destinationDirectory = fileUpdater.getDestinationDirectory();
+ assertTrue("destinationDirectory is null", destinationDirectory != null);
+ assertTrue("destinationDirectory does not exists " + destinationDirectory, destinationDirectory.exists());
+
+ sourceFile = new File(fileUpdater.getSourceDirectory(), "org" + SEP + "nuiton" + SEP + "util" + SEP + JaxxDummy.class.getSimpleName() + ".jaxx");
+
+ }
+
+ @Test
+ public void testSourceFileIsUptoDate() throws Exception {
+
+ assertTrue("fileUpdater was not init", fileUpdater != null);
+
+ assertTrue("sourceFile was not init ", sourceFile != null);
+ assertTrue("could not find source of this test " + sourceFile, sourceFile.exists());
+
+ mirrorFile = fileUpdater.getMirrorFile(sourceFile);
+
+ // we do not know if jaxx file is newer than the dummy java source ?
+
+ sourceFile.setLastModified(mirrorFile.lastModified() - 10);
+
+ // java file is up to date since it was compiled to launch this test
+ assertTrue(sourceFile + " should be uptodate", fileUpdater.isFileUpToDate(sourceFile));
+ }
+
+ @Test
+ public void testSourceFileDoesNotHaveMirrorFile() throws Exception {
+
+ assertTrue("fileUpdater was not init", fileUpdater != null);
+
+ assertTrue("sourceFile was not init ", sourceFile != null);
+ assertTrue("could not find source of this test " + sourceFile, sourceFile.exists());
+
+ assertTrue("mirrorFile was not init ", mirrorFile != null);
+ assertTrue("could not find mirrorFile " + mirrorFile, mirrorFile.exists());
+
+ // now rename mirror Class, so source file is no more up to date
+ File mirrorClassRenamed = new File(fileUpdater.getMirrorFile(sourceFile).getAbsolutePath() + "2");
+ mirrorFile.renameTo(mirrorClassRenamed);
+
+ // java file is no more up to date
+ assertFalse(sourceFile + " should not be uptodate", fileUpdater.isFileUpToDate(sourceFile));
+
+ // renmae mirror Class to his original name
+ mirrorClassRenamed.renameTo(mirrorFile);
+
+ // java file is now up to date (rename method does not affect lasmodified property on a file)
+ assertTrue(sourceFile + " should be uptodate", fileUpdater.isFileUpToDate(sourceFile));
+ }
+
+ @Test
+ public void testSourceFileIsNewerThanMirrorFile() throws Exception {
+
+ assertTrue("fileUpdater was not init", fileUpdater != null);
+
+ assertTrue("sourceFile was not init ", sourceFile != null);
+ assertTrue("could not find source of this test " + sourceFile, sourceFile.exists());
+
+ assertTrue("mirrorFile was not init ", mirrorFile != null);
+ assertTrue("could not find mirrorFile " + mirrorFile, mirrorFile.exists());
+
+ long sourceTime = sourceFile.lastModified();
+ long mirrorTime = mirrorFile.lastModified();
+
+ // make source file newer than mirror file
+ sourceFile.setLastModified(mirrorTime + 10);
+
+ // java file is no more up to date
+ assertFalse(sourceFile + " should not be uptodate", fileUpdater.isFileUpToDate(sourceFile));
+
+ // put back old time to source file
+ sourceFile.setLastModified(sourceTime);
+
+ // java file is now up to date (rename method does not affect lasmodified property on a file)
+ assertTrue(sourceFile + " should be uptodate", fileUpdater.isFileUpToDate(sourceFile));
+ }
+}
\ No newline at end of file
Property changes on: maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/util/JaxxFileUpdaterTest.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: maven-nuiton-project-helper-plugin/trunk/src/test/resources/log4j.properties (from rev 1522, nuitonpluginutil/trunk/src/test/resources/log4j.properties)
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/test/resources/log4j.properties (rev 0)
+++ maven-nuiton-project-helper-plugin/trunk/src/test/resources/log4j.properties 2009-05-12 10:43:54 UTC (rev 1531)
@@ -0,0 +1,10 @@
+# Global logging configuration
+log4j.rootLogger=ERROR, stdout
+# Console output...
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) %M - %m%n
+
+# package level
+log4j.logger.org.nuiton=DEBUG
+
Property changes on: maven-nuiton-project-helper-plugin/trunk/src/test/resources/log4j.properties
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: maven-nuiton-project-helper-plugin/trunk/src/test/resources/org/nuiton/license/plugin/LicensePluginTest/testOne.xml
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/test/resources/org/nuiton/license/plugin/LicensePluginTest/testOne.xml 2009-05-12 10:43:37 UTC (rev 1530)
+++ maven-nuiton-project-helper-plugin/trunk/src/test/resources/org/nuiton/license/plugin/LicensePluginTest/testOne.xml 2009-05-12 10:43:54 UTC (rev 1531)
@@ -4,7 +4,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<groupId>org.nuiton</groupId>
- <artifactId>maven-nuiton-project-helper-plugin-testOne</artifactId>
+ <artifactId>maven-helper-plugin-testOne</artifactId>
<version>0</version>
<build>
@@ -12,13 +12,13 @@
<plugins>
<plugin>
<groupId>org.nuiton</groupId>
- <artifactId>maven-nuiton-project-helper-plugin</artifactId>
+ <artifactId>maven-helper-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
<licenseName>lgpl_v3</licenseName>
<licenseFile>licenseOne.txt</licenseFile>
<pomFile>testOne.xml</pomFile>
- <outputDirectory>target/tests/LicenPluginTest/test-java</outputDirectory>
+ <outputDirectory>target/test-classes/LicenPluginTest/test-java</outputDirectory>
<verbose>true</verbose>
</configuration>
<executions>
Copied: maven-nuiton-project-helper-plugin/trunk/src/test/resources/org/nuiton/util/JaxxDummy.jaxx (from rev 1522, nuitonpluginutil/trunk/src/test/resources/org/codelutin/util/JaxxDummy.jaxx)
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/test/resources/org/nuiton/util/JaxxDummy.jaxx (rev 0)
+++ maven-nuiton-project-helper-plugin/trunk/src/test/resources/org/nuiton/util/JaxxDummy.jaxx 2009-05-12 10:43:54 UTC (rev 1531)
@@ -0,0 +1,3 @@
+<Object>
+ Dummy file to test org.codelutin.util.FileUpdaterHelper.JaxxFileUpdater
+</Object>
\ No newline at end of file
Property changes on: maven-nuiton-project-helper-plugin/trunk/src/test/resources/org/nuiton/util/JaxxDummy.jaxx
___________________________________________________________________
Name: svn:mergeinfo
+
1
0
[Lutinutil-commits] r1530 - maven-nuiton-project-helper-plugin/trunk/src/test/java/org
by tchemit@users.labs.libre-entreprise.org 12 May '09
by tchemit@users.labs.libre-entreprise.org 12 May '09
12 May '09
Author: tchemit
Date: 2009-05-12 10:43:37 +0000 (Tue, 12 May 2009)
New Revision: 1530
Removed:
maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/
Log:
mise en commun des anciens modules lutin-enforcer-rules + lutinpluginutil + maven-license-switcher
dans un unique plugin
1
0
[Lutinutil-commits] r1529 - maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license
by tchemit@users.labs.libre-entreprise.org 11 May '09
by tchemit@users.labs.libre-entreprise.org 11 May '09
11 May '09
Author: tchemit
Date: 2009-05-11 21:25:33 +0000 (Mon, 11 May 2009)
New Revision: 1529
Removed:
maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/BaseLicenseTestCase.java
maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/JarLicenseResolverTest.java
maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/LicenseFactoryTest.java
maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/LicenseGeneratorFactoryTest.java
maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/LicenseResolverTest.java
Log:
migrate to nuiton
Deleted: maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/BaseLicenseTestCase.java
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/BaseLicenseTestCase.java 2009-05-11 21:25:22 UTC (rev 1528)
+++ maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/BaseLicenseTestCase.java 2009-05-11 21:25:33 UTC (rev 1529)
@@ -1,79 +0,0 @@
-package org.codelutin.license;
-
-import java.io.ByteArrayInputStream;
-import org.junit.Assert;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import org.codehaus.plexus.util.FileUtils;
-import org.codehaus.plexus.util.IOUtil;
-import org.codehaus.plexus.util.io.RawInputStreamFacade;
-
-/** @author chemit */
-public abstract class BaseLicenseTestCase extends Assert {
-
- protected static final String encoding = "utf-8";
-
- protected File getBaseDir() {
- String path = System.getenv("basedir");
- if (path == null) {
- path = new File("").getAbsolutePath();
- }
- return new File(path);
- }
-
- protected void assertLicenseFound(String name, License license) throws IOException {
- assertNotNull(license);
- assertEquals(name, license.getName());
- assertNotNull(license.getLicenseContent(encoding));
- assertNotNull(license.getHeaderContent(encoding));
- }
-
- protected File createLicenseRepository(boolean createLicene) throws IOException {
- long timestamp = System.currentTimeMillis();
-
- File repo = new File(getBaseDir(), "target" + File.separator + "licenses_" + timestamp);
-
- if (createLicene) {
-
- String licenseName = "dummy_" + timestamp;
- addLicenseToRepository(repo, licenseName);
- }
- return repo;
- }
-
- protected void addLicenseToRepository(File repo, String licenseName) throws IOException {
-
- File defFile = new File(repo, "licenses.properties");
-
- String content = "";
- if (defFile.exists()) {
-
- content = IOUtil.toString(new FileInputStream(defFile), encoding) + "\n";
-// content = FileUtil.readAsString(defFile, encoding) + "\n";
- }
-
-
- write(defFile, content + licenseName + "=My dummy license\n", encoding);
-// FileUtil.writeString(defFile, content + licenseName + "=My dummy license\n", encoding);
- // create dummy licenses
- File file = new File(repo, licenseName);
- file.mkdirs();
- write(new File(file, "license.txt"), "license:" + licenseName, encoding);
- write(new File(file, "header.txt"), "header:" + licenseName, encoding);
-// FileUtil.writeString(new File(file, "license.txt"), "license:" + licenseName, encoding);
-// FileUtil.writeString(new File(file, "header.txt"), "header:" + licenseName, encoding);
-
- }
-
- protected void write(File destFile, String content, String encoding) throws IOException {
-
- InputStream in = new ByteArrayInputStream(content.getBytes(encoding));
- RawInputStreamFacade facade = new RawInputStreamFacade(in);
-
- FileUtils.copyStreamToFile(facade, destFile);
- }
-}
-
Deleted: maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/JarLicenseResolverTest.java
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/JarLicenseResolverTest.java 2009-05-11 21:25:22 UTC (rev 1528)
+++ maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/JarLicenseResolverTest.java 2009-05-11 21:25:33 UTC (rev 1529)
@@ -1,62 +0,0 @@
-package org.codelutin.license;
-
-import org.junit.Test;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Map;
-
-/** @author chemit */
-public class JarLicenseResolverTest extends BaseLicenseTestCase {
-
- @Test(expected = IllegalArgumentException.class)
- public void testResolvFailed1() throws Exception {
- new JarLicenseResolver().resolv(null);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testResolvFailed2() throws Exception {
- new JarLicenseResolver().resolv("");
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testResolvFailed3() throws Exception {
- new JarLicenseResolver().resolv(" ");
- }
-
- @Test
- public void testResolv() throws Exception {
- JarLicenseResolver resolver = new JarLicenseResolver();
-
- {
- String name = "dummy_" + System.currentTimeMillis();
- License license = resolver.resolv(name);
- assertNull(license);
- }
-
- for (String name : new String[]{
- "gpl_v1",
- "gpl_v2",
- "gpl_v3",
- "lgpl_v2_1",
- "lgpl_v3"}) {
- License license = resolver.resolv(name);
- assertLicenseFound(name, license);
- }
-
- }
-
- @Test
- public void testGetLicenseNames() throws Exception {
- JarLicenseResolver resolver = new JarLicenseResolver();
- Map<String, String> licenseNames = resolver.getLicenseNames();
-
- assertEquals(Arrays.asList("gpl_v1",
- "gpl_v2",
- "gpl_v3",
- "lgpl_v2_1",
- "lgpl_v3"), new ArrayList<String>(licenseNames.keySet()));
- }
-
-
-}
Deleted: maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/LicenseFactoryTest.java
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/LicenseFactoryTest.java 2009-05-11 21:25:22 UTC (rev 1528)
+++ maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/LicenseFactoryTest.java 2009-05-11 21:25:33 UTC (rev 1529)
@@ -1,80 +0,0 @@
-package org.codelutin.license;
-
-import org.junit.Test;
-
-import java.io.File;
-import java.util.Map;
-
-/** @author chemit */
-public class LicenseFactoryTest extends BaseLicenseTestCase {
-
- @Test
- public void testNewInstance() throws Exception {
-
- LicenseFactory factory = LicenseFactory.newInstance();
- assertNotNull(factory);
- assertEquals(1, factory.resolvers.size());
- assertNotNull(factory.resolvers.get(0));
- assertEquals(JarLicenseResolver.class, factory.resolvers.get(0).getClass());
-
- factory = LicenseFactory.newInstance("");
- assertNotNull(factory);
- assertEquals(1, factory.resolvers.size());
- assertNotNull(factory.resolvers.get(0));
- assertEquals(JarLicenseResolver.class, factory.resolvers.get(0).getClass());
-
- factory = LicenseFactory.newInstance("yo");
- assertNotNull(factory);
-
- assertEquals(2, factory.resolvers.size());
- assertNotNull(factory.resolvers.get(0));
- assertEquals(JarLicenseResolver.class, factory.resolvers.get(0).getClass());
- assertNotNull(factory.resolvers.get(1));
- assertEquals(LicenseResolver.class, factory.resolvers.get(1).getClass());
- assertEquals("yo", factory.resolvers.get(1).getBaseURL());
-
- factory.addResolver(new LicenseResolver("yo2"));
- assertEquals(3, factory.resolvers.size());
- assertNotNull(factory.resolvers.get(0));
- assertEquals(JarLicenseResolver.class, factory.resolvers.get(0).getClass());
- assertNotNull(factory.resolvers.get(1));
- assertEquals(LicenseResolver.class, factory.resolvers.get(1).getClass());
- assertEquals("yo", factory.resolvers.get(1).getBaseURL());
- assertEquals(LicenseResolver.class, factory.resolvers.get(2).getClass());
- assertEquals("yo2", factory.resolvers.get(2).getBaseURL());
-
- }
-
- @Test
- public void testGetLicenseNames() throws Exception {
- LicenseFactory factory = LicenseFactory.newInstance();
-
- int expectedJarResolverLicenses = 5;
- Map<String, String> licenseNames = factory.getLicenseNames();
- //todo make dynamic that test
- assertEquals(expectedJarResolverLicenses, licenseNames.size());
-
- // create a new dummy license repository with a license
- File repo = createLicenseRepository(true);
-
- LicenseResolver resolver = new LicenseResolver();
- resolver.setBaseURL(repo.toURI().toURL().toString());
-
- factory.addResolver(resolver);
-
- licenseNames = factory.getLicenseNames();
- assertEquals(expectedJarResolverLicenses + 1, licenseNames.size());
-
- // add a new license to repo
- long timestamp = System.currentTimeMillis();
- String licenseName = "dummy2_" + timestamp;
- addLicenseToRepository(repo, licenseName);
-
- factory = LicenseFactory.newInstance(repo.toURI().toURL().toString());
-
- licenseNames = factory.getLicenseNames();
- assertEquals(expectedJarResolverLicenses + 2, licenseNames.size());
-
- }
-
-}
Deleted: maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/LicenseGeneratorFactoryTest.java
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/LicenseGeneratorFactoryTest.java 2009-05-11 21:25:22 UTC (rev 1528)
+++ maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/LicenseGeneratorFactoryTest.java 2009-05-11 21:25:33 UTC (rev 1529)
@@ -1,34 +0,0 @@
-package org.codelutin.license;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-/** @author chemit */
-public class LicenseGeneratorFactoryTest {
-
- @Before
- public void setUp() {
- // Add your code here
- }
-
- @After
- public void tearDown() {
- // Add your code here
- }
-
- @Test
- public void testGetAvailableGenerator() {
- // Add your code here
- }
-
- @Test
- public void testGetGeneratorMatchers() {
- // Add your code here
- }
-
- @Test
- public void testAddGenerator() {
- // Add your code here
- }
-}
Deleted: maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/LicenseResolverTest.java
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/LicenseResolverTest.java 2009-05-11 21:25:22 UTC (rev 1528)
+++ maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/LicenseResolverTest.java 2009-05-11 21:25:33 UTC (rev 1529)
@@ -1,113 +0,0 @@
-package org.codelutin.license;
-
-import org.junit.Test;
-
-import java.io.File;
-import java.util.Map;
-
-/** @author chemit */
-public class LicenseResolverTest extends BaseLicenseTestCase {
-
- @Test(expected = IllegalArgumentException.class)
- public void testResolvIllegalArgumentException1() throws Exception {
-
- LicenseResolver resolver = new LicenseResolver();
- // no baseURL
- // no licenseName
- // no licenses.txt
- resolver.resolv(null);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testResolvIllegalArgumentException2() throws Exception {
-
- LicenseResolver resolver = new LicenseResolver();
-
- // no baseURL
- // no licenseName
- // no licenses.txt
- resolver.resolv("");
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testResolvIllegalArgumentException3() throws Exception {
-
- LicenseResolver resolver = new LicenseResolver();
-
- // no baseURL
- // no licenseName
- // no licenses.txt
- resolver.resolv(" ");
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testResolvIllegalArgumentException4() throws Exception {
-
- LicenseResolver resolver = new LicenseResolver();
-
- // no baseURL
- // no licenses.txt
- resolver.resolv("dummy");
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testResolvIllegalArgumentException5() throws Exception {
-
- LicenseResolver resolver = new LicenseResolver();
-
-
- resolver.setBaseURL("dummy");
- // no licenses.txt
- resolver.resolv("dummy");
- }
-
- @Test
- public void testResolv() throws Exception {
-
- LicenseResolver resolver = new LicenseResolver();
-
- long timestamp = System.currentTimeMillis();
- String licenseName = "dummy_" + timestamp;
-
- File repo = createLicenseRepository(false);
-
- resolver.setBaseURL(repo.toURI().toURL().toString());
-
- License license;
-
- try {
- // no licenses.properties
- resolver.resolv(licenseName);
- fail();
- } catch (IllegalArgumentException e) {
- assertTrue(true);
- }
-
- addLicenseToRepository(repo, licenseName);
-
- //FileUtil.writeString(new File(repo, "licenses.properties"), licenseName + "=My dummy license\n", encoding);
- //license = resolver.resolv(licenseName);
- //assertNull(license);
-
- Map<String, String> licenseNames = resolver.getLicenseNames();
- assertNotNull(licenseNames);
- assertEquals(1, licenseNames.size());
- assertTrue(licenseNames.containsKey(licenseName));
-
- // create dummy licenses
- //File file = new File(repo, licenseName);
- //file.mkdirs();
- //FileUtil.writeString(new File(file, "license.txt"), "license", encoding);
- //FileUtil.writeString(new File(file, "header.txt"), "header", encoding);
-
- license = resolver.resolv(licenseName);
- assertNotNull(license);
- assertEquals(licenseName, license.getName());
- assertNotNull(license.getLicenseContent(encoding));
- assertNotNull(license.getHeaderContent(encoding));
- assertEquals("license:" + licenseName, license.getLicenseContent(encoding));
- assertEquals("header:" + licenseName, license.getHeaderContent(encoding));
-
- }
-
-}
\ No newline at end of file
1
0
[Lutinutil-commits] r1528 - in maven-nuiton-project-helper-plugin/trunk/src: main/java/org/nuiton/license main/java/org/nuiton/license/plugin test/java/org/codelutin/license/plugin/impl test/java/org/nuiton/license test/resources/org test/resources/org/nuiton test/resources/org/nuiton/license test/resources/org/nuiton/license/plugin test/resources/org/nuiton/license/plugin/LicensePluginTest
by tchemit@users.labs.libre-entreprise.org 11 May '09
by tchemit@users.labs.libre-entreprise.org 11 May '09
11 May '09
Author: tchemit
Date: 2009-05-11 21:25:22 +0000 (Mon, 11 May 2009)
New Revision: 1528
Added:
maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/JarLicenseResolver.java
maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/License.java
maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/LicenseFactory.java
maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/LicenseGenerator.java
maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/LicenseGeneratorFactory.java
maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/LicenseResolver.java
maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/plugin/
maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/plugin/AbstractLicensePlugin.java
maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/plugin/AvailableLicensesPlugin.java
maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/plugin/LicensePlugin.java
maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/plugin/ThirdPartyPlugin.java
maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/license/BaseLicenseTestCase.java
maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/license/JarLicenseResolverTest.java
maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/license/LicenseFactoryTest.java
maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/license/LicenseGeneratorFactoryTest.java
maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/license/LicenseResolverTest.java
maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/license/plugin/
maven-nuiton-project-helper-plugin/trunk/src/test/resources/org/nuiton/
maven-nuiton-project-helper-plugin/trunk/src/test/resources/org/nuiton/license/
maven-nuiton-project-helper-plugin/trunk/src/test/resources/org/nuiton/license/plugin/
maven-nuiton-project-helper-plugin/trunk/src/test/resources/org/nuiton/license/plugin/LicensePluginTest/
maven-nuiton-project-helper-plugin/trunk/src/test/resources/org/nuiton/license/plugin/LicensePluginTest/licenseOne.txt
maven-nuiton-project-helper-plugin/trunk/src/test/resources/org/nuiton/license/plugin/LicensePluginTest/testOne.xml
Modified:
maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/plugin/impl/LicensePluginTest.java
Log:
migrate to nuiton
Copied: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/JarLicenseResolver.java (from rev 1524, maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/JarLicenseResolver.java)
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/JarLicenseResolver.java (rev 0)
+++ maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/JarLicenseResolver.java 2009-05-11 21:25:22 UTC (rev 1528)
@@ -0,0 +1,33 @@
+package org.nuiton.license;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.File;
+import java.net.URL;
+
+/**
+ * Un resolver de license dans le classpath.
+ * <p/>
+ * Le chemin de base est le suivant :
+ * <pre>
+ * /META-INF/licenses/
+ * </pre>
+ *
+ * @author chemit
+ * @see LicenseResolver
+ */
+public class JarLicenseResolver extends LicenseResolver {
+
+ protected static final Log log = LogFactory.getLog(JarLicenseResolver.class);
+
+ public JarLicenseResolver() {
+ super(acquireBaseURL());
+ }
+
+ protected static String acquireBaseURL() {
+ String prefix = File.separator + "META-INF" + File.separator + "licenses";
+ URL licenseURL = JarLicenseResolver.class.getResource(prefix);
+ return licenseURL.toString();
+ }
+}
Property changes on: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/JarLicenseResolver.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/License.java (from rev 1525, maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/License.java)
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/License.java (rev 0)
+++ maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/License.java 2009-05-11 21:25:22 UTC (rev 1528)
@@ -0,0 +1,89 @@
+package org.nuiton.license;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.InputStream;
+import java.net.URL;
+import org.codehaus.plexus.util.IOUtil;
+
+/**
+ * The model of a license.
+ *
+ * @author chemit
+ */
+public class License {
+
+ /** the name of the licenses (ex lgpl-3.0) */
+ protected String name;
+ /** url of the license's content */
+ protected URL licenseURL;
+ /** url of the header's template */
+ protected URL headerURL;
+
+ public License() {
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public URL getLicenseURL() {
+ return licenseURL;
+ }
+
+ public URL getHeaderURL() {
+ return headerURL;
+ }
+
+ public String getLicenseContent(String encoding) throws IOException {
+ if (licenseURL == null) {
+ throw new IllegalStateException("no licenseURL defined in " + this);
+ }
+
+ InputStream inputStream = licenseURL.openStream();
+ Reader r = new BufferedReader(new InputStreamReader(inputStream, encoding));
+ try {
+ return IOUtil.toString(r);
+// return FileUtil.readAsString(r);
+ } finally {
+ r.close();
+ }
+ }
+
+ public String getHeaderContent(String encoding) throws IOException {
+ if (headerURL == null) {
+ throw new IllegalStateException("no headerURL defined in " + this);
+ }
+ Reader r = new BufferedReader(new InputStreamReader(headerURL.openStream(), encoding));
+ try {
+ return IOUtil.toString(r);
+// return FileUtil.readAsString(r);
+ } finally {
+ r.close();
+ }
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void setLicenseURL(URL licenseURL) {
+ this.licenseURL = licenseURL;
+ }
+
+ public void setHeaderURL(URL headerURL) {
+ this.headerURL = headerURL;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder(super.toString());
+ sb.append("<name:").append(name);
+ sb.append(", licenseURL:").append(licenseURL.toString());
+ sb.append(", headerURL:").append(headerURL.toString());
+ sb.append(">");
+ return sb.toString();
+ }
+}
Property changes on: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/License.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/LicenseFactory.java (from rev 1524, maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/LicenseFactory.java)
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/LicenseFactory.java (rev 0)
+++ maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/LicenseFactory.java 2009-05-11 21:25:22 UTC (rev 1528)
@@ -0,0 +1,73 @@
+package org.nuiton.license;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.TreeMap;
+
+/**
+ * Class responsible of instanciate {@link License}.
+ * <p/>
+ * The factory use a table of {@link #resolvers} to lookup for licenses.
+ * <p/>
+ * To obtain an instance of a {@link org.codelutin.license.LicenseFactory} use the method {@link #newInstance(String[])}.
+ *
+ * @author chemit
+ */
+public class LicenseFactory {
+
+ protected List<LicenseResolver> resolvers;
+
+ public static LicenseFactory newInstance(String... extraResolvers) throws IllegalArgumentException {
+ LicenseFactory result = new LicenseFactory();
+ // always put jar resolver first
+ result.addResolver(new JarLicenseResolver());
+
+ if (extraResolvers != null) {
+ for (String extraResolver : extraResolvers) {
+ if (extraResolver != null && !extraResolver.trim().isEmpty()) {
+ // add a extra resolver
+ result.addResolver(new LicenseResolver(extraResolver));
+ }
+ }
+ }
+ return result;
+ }
+
+ public void addResolver(LicenseResolver licenseResolver) {
+ resolvers.add(licenseResolver);
+ }
+
+ public Map<String, String> getLicenseNames() throws IllegalArgumentException {
+ Map<String, String> result = new TreeMap<String, String>();
+ for (LicenseResolver resolver : resolvers) {
+ Map<String, String> tmp = resolver.getLicenseNames();
+ for (Entry<String, String> s : tmp.entrySet()) {
+ if (!result.containsKey(s.getKey())) {
+ result.put(s.getKey(), s.getValue());
+ }
+ }
+ }
+ return result;
+ }
+
+
+ public License revolv(String licenseName) throws IllegalArgumentException {
+ if (licenseName == null) {
+ throw new IllegalArgumentException("licenseName can not be null");
+ }
+ for (LicenseResolver resolver : resolvers) {
+ License result = resolver.resolv(licenseName);
+ if (result != null) {
+ return result;
+ }
+ }
+ throw new IllegalArgumentException("could not find the license " + licenseName + " with resolvers" + resolvers);
+ }
+
+ protected LicenseFactory() throws IllegalArgumentException {
+ this.resolvers = new ArrayList<LicenseResolver>();
+ }
+
+}
Property changes on: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/LicenseFactory.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/LicenseGenerator.java (from rev 1524, maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/LicenseGenerator.java)
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/LicenseGenerator.java (rev 0)
+++ maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/LicenseGenerator.java 2009-05-11 21:25:22 UTC (rev 1528)
@@ -0,0 +1,12 @@
+package org.nuiton.license;
+
+/**
+ * A simple Contract to generate a new header for a given type of file
+ *
+ * @author chemit
+ */
+public interface LicenseGenerator {
+
+ String getHeader(String licenseHeaderContent);
+
+}
Property changes on: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/LicenseGenerator.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/LicenseGeneratorFactory.java (from rev 1524, maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/LicenseGeneratorFactory.java)
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/LicenseGeneratorFactory.java (rev 0)
+++ maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/LicenseGeneratorFactory.java 2009-05-11 21:25:22 UTC (rev 1528)
@@ -0,0 +1,73 @@
+package org.nuiton.license;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A factory of {@link LicenseFactory}
+ *
+ * @author chemit
+ */
+public class LicenseGeneratorFactory {
+
+ public static class LicenceGeneratorContext {
+
+ File src;
+ String[] files;
+
+ public LicenceGeneratorContext(File src, String[] files) {
+ this.src = src;
+ this.files = files;
+ }
+
+ public File getSrc() {
+ return src;
+ }
+
+ public String[] getFiles() {
+ return files;
+ }
+
+ public void setSrc(File src) {
+ this.src = src;
+ }
+
+ public void setFiles(String[] files) {
+ this.files = files;
+ }
+
+ }
+
+ protected static Map<LicenseGenerator, List<String>> availableGenerator;
+
+ public static Map<LicenseGenerator, List<String>> getAvailableGenerator() {
+ if (availableGenerator == null) {
+ availableGenerator = new HashMap<LicenseGenerator, List<String>>();
+ }
+ return availableGenerator;
+ }
+
+ public static List<String> getGeneratorMatchers(LicenseGenerator generator) {
+ List<String> result = null;
+ if (availableGenerator != null) {
+ result = availableGenerator.get(generator);
+ if (result == null) {
+ // add a new empty list in cache
+ result = new ArrayList<String>();
+ availableGenerator.put(generator, result);
+ }
+ }
+ return result;
+ }
+
+ public static void addGenerator(LicenseGenerator generator, String matcher) {
+ List<String> matchers = getGeneratorMatchers(generator);
+ if (matcher.isEmpty() || !matcher.contains(matcher)) {
+ matchers.add(matcher);
+ }
+ }
+
+}
Property changes on: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/LicenseGeneratorFactory.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/LicenseResolver.java (from rev 1524, maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/LicenseResolver.java)
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/LicenseResolver.java (rev 0)
+++ maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/LicenseResolver.java 2009-05-11 21:25:22 UTC (rev 1528)
@@ -0,0 +1,136 @@
+package org.nuiton.license;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Properties;
+import java.util.TreeMap;
+
+/**
+ * Un resolver de license a partir d'un {@link #baseURL} .
+ * <p/>
+ * On doit avoir un fichier
+ * <pre>baseURL/licenses.txt
+ * </pre> qui contient la liste des licenses gerees par ce resolver.
+ * <p/>
+ * Chaque license est definit par deux fichiers :
+ * <pre>
+ * baseURL/licenseName/license.txt
+ * baseURL/licenseName/header.txt
+ * </pre>
+ *
+ * @author chemit
+ */
+public class LicenseResolver {
+
+ protected static final Log log = LogFactory.getLog(LicenseResolver.class);
+
+ /**
+ * BaseURL
+ *
+ * @required
+ */
+ protected String baseURL;
+
+ /** list of known licenses with this resolver */
+ protected Map<String, String> licenseNames;
+
+ public LicenseResolver() {
+ }
+
+ public LicenseResolver(String baseURL) {
+ this.baseURL = baseURL;
+ }
+
+ public String getBaseURL() {
+ return baseURL;
+ }
+
+ public void setBaseURL(String baseURL) {
+ this.baseURL = baseURL;
+ // reset licenseNames
+ licenseNames = null;
+ }
+
+ public Map<String, String> getLicenseNames() {
+ if (licenseNames == null) {
+ if (baseURL == null || baseURL.trim().isEmpty()) {
+ throw new IllegalArgumentException("no baseURL defined in " + this);
+ }
+
+ Map<String, String> list = new TreeMap<String, String>();
+ try {
+ URL licenseURL = new URL(baseURL + "/licenses.properties");
+
+ if (!checkExists(licenseURL)) {
+ throw new IllegalArgumentException("no licenses.properties found withurl [" + licenseURL + "] for resolver " + this);
+ }
+ Properties p = new Properties();
+ p.load(licenseURL.openStream());
+ for (Entry<Object, Object> entry : p.entrySet()) {
+ list.put((String) entry.getKey(), entry.getValue() + " [" + baseURL + "]");
+ }
+ } catch (MalformedURLException e) {
+ throw new IllegalArgumentException(e);
+ } catch (IOException e) {
+ return null;
+ }
+
+ licenseNames = Collections.unmodifiableMap(list);
+ }
+ return licenseNames;
+ }
+
+ public License resolv(String licenseName) throws IllegalArgumentException {
+ if (baseURL == null || baseURL.trim().isEmpty()) {
+ throw new IllegalArgumentException("no baseURL defined in " + this);
+ }
+ if (licenseName == null || licenseName.trim().isEmpty()) {
+ throw new IllegalArgumentException("licenceName can not be null");
+ }
+ licenseName = licenseName.trim().toLowerCase();
+
+ if (!getLicenseNames().containsKey(licenseName)) {
+ // license not found
+ return null;
+ }
+
+ try {
+ URL licenseURL = new URL(baseURL + "/" + licenseName + "/license.txt");
+ URL headerURL = new URL(baseURL + "/" + licenseName + "/header.txt");
+
+ if (!checkExists(licenseURL) || !checkExists(headerURL)) {
+ // no content find
+ return null;
+ }
+
+ License license = new License();
+ license.setName(licenseName);
+ license.setLicenseURL(licenseURL);
+ license.setHeaderURL(headerURL);
+ return license;
+
+
+ } catch (MalformedURLException e) {
+ throw new IllegalArgumentException(e);
+ } catch (IOException e) {
+ return null;
+ }
+ }
+
+ @Override
+ public String toString() {
+ return super.toString() + "<baseURL:" + baseURL + ", licenseNames:" + licenseNames + ">";
+ }
+
+ protected boolean checkExists(URL url) throws IOException {
+ return url.openConnection().getContentLength() > 0;
+ }
+
+}
\ No newline at end of file
Property changes on: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/LicenseResolver.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/plugin/AbstractLicensePlugin.java (from rev 1525, maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/plugin/AbstractLicensePlugin.java)
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/plugin/AbstractLicensePlugin.java (rev 0)
+++ maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/plugin/AbstractLicensePlugin.java 2009-05-11 21:25:22 UTC (rev 1528)
@@ -0,0 +1,242 @@
+/**
+ * *##% Plugin maven pour switcher les licenses
+ * Copyright (C) 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*
+ */
+package org.nuiton.license.plugin;
+
+import java.io.ByteArrayInputStream;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.MavenProject;
+
+import java.io.File;
+import java.io.InputStream;
+import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.io.RawInputStreamFacade;
+
+/**
+ * Un MOJO de base pour les autres MOJO concrets avec les options communes.
+ *
+ * @author chemit
+ */
+public abstract class AbstractLicensePlugin extends AbstractMojo {
+
+ protected abstract boolean shouldSkip();
+
+ /**
+ * la methode qui est lancee au debut de la methode {@link #execute()} pour preparer l'init du goal.
+ *
+ * @return <code>true</code> if there is something to generate, <code>false</code> otherwise.
+ * @throws Exception if any
+ */
+ protected abstract boolean init() throws Exception;
+
+ /**
+ * Do plugin action.
+ * <p/>
+ * The method {@link #execute()} invoke this method only and only if :
+ * <ul>
+ * <li>{@link #shouldSkip()} returns <code>false</code> (filtrer project type, for example).</li>
+ * <li>{@link #force} is activate or method {@link #init()} returns <code>true</code>.</li>
+ * </ul>
+ *
+ * @throws Exception if any
+ */
+ protected abstract void doAction() throws Exception;
+ /**
+ * Dependance du projet.
+ *
+ * @parameter default-value="${project}"
+ * @required
+ */
+ protected MavenProject project;
+ /**
+ * Repertoire de sortie des classes (classpath).
+ *
+ * @parameter expression="${licence-switcher.outputDirectory}" default-value="${project.build.outputDirectory}"
+ * @required
+ */
+ protected File outputDirectory;
+ /**
+ * Encoding a utiliser pour lire et ecrire les fichiers.
+ *
+ * @parameter expression="${licence-switcher.encoding}" default-value="${project.build.sourceEncoding}"
+ * @required
+ */
+ protected String encoding;
+ /**
+ * Un flag pour conserver un backup des fichiers modifies.
+ *
+ * @parameter expression="${license-switcher.keepBackup}" default-value="false"
+ */
+ protected boolean keepBackup;
+ /**
+ * Un flag pour activer le mode verbeux.
+ *
+ * @parameter expression="${license-switcher.verbose}" default-value="${maven.verbose}"
+ */
+ protected boolean verbose;
+ /**
+ * Un flag pour forcer la generation.
+ *
+ * @parameter expression="${license-switcher.force}" default-value="false"
+ */
+ protected boolean force;
+ /**
+ * Fichier ou ecrire les licences des dependances.
+ *
+ * @parameter expression="${license-switcher.pomFile}" default-value="pom.xml"
+ * @required
+ */
+ protected File pomFile;
+
+ @Override
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ try {
+
+ if (shouldSkip()) {
+ getLog().info("skip switch goal for packaging " + project.getPackaging());
+ return;
+ }
+
+ boolean shouldGenerate = init();
+
+ if (!(force || shouldGenerate)) {
+ getLog().info("all files are up-to-date.");
+ return;
+ }
+
+ doAction();
+
+ } catch (Exception e) {
+ throw new MojoExecutionException("could not init goal " + getClass().getSimpleName() + " for reason : " + e.getMessage(), e);
+ }
+ }
+
+ /**
+ * Test if a file exists and is newer than the {@link #pomFile} file.
+ *
+ * @param f the file to test
+ * @return <code>true</code> if file exists and is newer than the pom file,
+ * <code>false</code> otherwise.
+ */
+ protected boolean isFileNewerThanPomFile(File f) {
+ return f.exists() && f.lastModified() > pomFile.lastModified();
+ }
+
+ public MavenProject getProject() {
+ return project;
+ }
+
+ public File getOutputDirectory() {
+ return outputDirectory;
+ }
+
+ public String getEncoding() {
+ return encoding;
+ }
+
+ public boolean isKeepBackup() {
+ return keepBackup;
+ }
+
+ public boolean isVerbose() {
+ return verbose;
+ }
+
+ public boolean isForce() {
+ return force;
+ }
+
+ public File getPomFile() {
+ return pomFile;
+ }
+
+ public void setProject(MavenProject project) {
+ this.project = project;
+ }
+
+ public void setOutputDirectory(File outputDirectory) {
+ this.outputDirectory = outputDirectory;
+ }
+
+ public void setEncoding(String encoding) {
+ this.encoding = encoding;
+ }
+
+ public void setKeepBackup(boolean keepBackup) {
+ this.keepBackup = keepBackup;
+ }
+
+ public void setVerbose(boolean verbose) {
+ this.verbose = verbose;
+ }
+
+ public void setForce(boolean force) {
+ this.force = force;
+ }
+
+ public void setPomFile(File pomFile) {
+ this.pomFile = pomFile;
+ }
+
+ /**
+ * Does the actual copy of the file and logging.
+ *
+ * @param srcFile represents the file to copy.
+ * @param destFile file name of destination file.
+ *
+ * @throws MojoExecutionException with a message if an
+ * error occurs.
+ */
+ protected void copyFile(File srcFile, File destFile)
+ throws MojoExecutionException {
+ try {
+ getLog().info("Copying " + srcFile.getName() + " to " + destFile);
+
+ FileUtils.copyFile(srcFile, destFile);
+
+ } catch (Exception e) {
+ throw new MojoExecutionException("Error copying from " + srcFile + " to " + destFile, e);
+ }
+ }
+
+ /**
+ * Does the actual copy of the content to a fileand logging.
+ *
+ * @param content represents the content to write into file.
+ * @param destFile file name of destination file.
+ * @param encoding encoding to use to write file
+ * @throws MojoExecutionException with a message if an
+ * error occurs.
+ */
+ protected void copyFile(String content, File destFile, String encoding)
+ throws MojoExecutionException {
+ try {
+ getLog().info("Copying content to " + destFile);
+
+ InputStream in = new ByteArrayInputStream(content.getBytes(encoding));
+ RawInputStreamFacade facade = new RawInputStreamFacade(in);
+
+ FileUtils.copyStreamToFile(facade, destFile);
+
+ } catch (Exception e) {
+ throw new MojoExecutionException("Error copying content to " + destFile, e);
+ }
+ }
+}
Property changes on: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/plugin/AbstractLicensePlugin.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/plugin/AvailableLicensesPlugin.java (from rev 1524, maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/plugin/AvailableLicensesPlugin.java)
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/plugin/AvailableLicensesPlugin.java (rev 0)
+++ maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/plugin/AvailableLicensesPlugin.java 2009-05-11 21:25:22 UTC (rev 1528)
@@ -0,0 +1,57 @@
+/**
+ * *##% Plugin maven pour switcher les licenses
+ * Copyright (C) 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*
+ */
+package org.nuiton.license.plugin;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.nuiton.license.LicenseFactory;
+
+import java.util.Map.Entry;
+
+/**
+ * Le goal pour afficher dans la console les differentes licenses connues.
+ *
+ * @author chemit
+ * @goal available-licenses
+ * @requiresProject false
+ */
+public class AvailableLicensesPlugin extends AbstractMojo {
+
+ /**
+ * La baseURL d'un resolver de license supplementaire
+ *
+ * @parameter expression="${license-switcher.extraResolver}"
+ */
+ protected String extraResolver;
+
+ @Override
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ StringBuilder sb = new StringBuilder();
+ sb.append("Available licenses :\n");
+
+ LicenseFactory factory = LicenseFactory.newInstance(extraResolver);
+
+ for (Entry<String, String> license : factory.getLicenseNames().entrySet()) {
+ sb.append(" * ").append(license.getKey()).append(" : ").append(license.getValue()).append('\n');
+ }
+ getLog().info(sb.toString());
+ }
+
+}
Property changes on: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/plugin/AvailableLicensesPlugin.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/plugin/LicensePlugin.java (from rev 1525, maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/plugin/impl/LicensePlugin.java)
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/plugin/LicensePlugin.java (rev 0)
+++ maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/plugin/LicensePlugin.java 2009-05-11 21:25:22 UTC (rev 1528)
@@ -0,0 +1,160 @@
+/**
+ * *##% Plugin maven pour switcher les licenses
+ * Copyright (C) 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*
+ */
+package org.nuiton.license.plugin;
+
+import org.nuiton.license.License;
+import org.nuiton.license.LicenseFactory;
+import org.nuiton.license.plugin.AbstractLicensePlugin;
+
+import java.io.File;
+
+/**
+ * Le goal pour ajouter le fichier LICENSE.txt dans le classpath (et le generer s'il n'existe pas).
+ *
+ * @author chemit
+ * @goal add-license
+ * @phase generate-resources
+ * @requiresProject true
+ * @requiresDependencyResolution compile
+ */
+public class LicensePlugin extends AbstractLicensePlugin {
+
+ /**
+ * Fichier de la licence du module.
+ *
+ * @parameter expression="${license-switcher.licenceFile}" default-value="${basedir}/LICENSE.txt"
+ * @required
+ * @readonly
+ */
+ protected File licenseFile;
+ /**
+ * Le type de license a appliquer.
+ *
+ * @parameter expression="${license-switcher.licenseName}"
+ * @required
+ */
+ protected String licenseName;
+ /**
+ * La baseURL d'un resolver de license supplementaire
+ *
+ * @parameter expression="${license-switcher.extraResolver}"
+ */
+ protected String[] extraResolver;
+ protected License license;
+
+ @Override
+ protected boolean shouldSkip() {
+ return project != null && ("pom".equals(project.getPackaging()) || "site".equals(project.getPackaging()));
+ }
+
+ @Override
+ protected boolean init() throws Exception {
+
+ // must generate if file does not exist
+ boolean doGenerate = false;
+
+ if (!force) {
+ // regenerate only if file exists and is newer than pom file
+ doGenerate = !isFileNewerThanPomFile(licenseFile);
+ }
+
+ if (doGenerate) {
+
+ // acquire license
+
+ LicenseFactory factory = LicenseFactory.newInstance(extraResolver);
+
+ license = factory.revolv(licenseName);
+
+ }
+ return doGenerate;
+ }
+
+ @Override
+ protected void doAction() throws Exception {
+ getLog().info("using licence [" + licenseName + "]");
+
+ if (verbose) {
+ getLog().info("detail : " + license);
+ }
+
+ if (licenseFile.exists() && keepBackup) {
+ if (verbose) {
+ getLog().info("backup " + licenseFile);
+ }
+ // copy it to backup file
+ File backup = new File(licenseFile.getAbsolutePath() + "~");
+ licenseFile.renameTo(backup);
+ }
+// try {
+ String licenseContent = license.getLicenseContent(encoding);
+
+ //FileUtil.writeString(licenseFile, licenseContent, encoding);
+
+ // copy LICENSE.txt to classpath
+ File target = new File(outputDirectory, licenseFile.getName());
+
+// try {
+
+ copyFile(licenseContent, licenseFile, encoding);
+
+ copyFile(licenseFile, target);
+
+
+// } catch (IOException e) {
+// throw new MojoExecutionException("could not write file " + target + " for reason : " + e.getMessage(), e);
+// }
+//
+// } catch (IOException e) {
+// throw new MojoExecutionException("could not write license file " + licenseFile + " for reason : " + e.getMessage(), e);
+// }
+ }
+
+ public File getLicenseFile() {
+ return licenseFile;
+ }
+
+ public String getLicenseName() {
+ return licenseName;
+ }
+
+ public License getLicense() {
+ return license;
+ }
+
+ public String[] getExtraResolver() {
+ return extraResolver;
+ }
+
+ public void setLicenseFile(File licenseFile) {
+ this.licenseFile = licenseFile;
+ }
+
+ public void setLicenseName(String licenseName) {
+ this.licenseName = licenseName;
+ }
+
+ public void setExtraResolver(String[] extraResolver) {
+ this.extraResolver = extraResolver;
+ }
+
+ public void setLicense(License license) {
+ this.license = license;
+ }
+}
Property changes on: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/plugin/LicensePlugin.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/plugin/ThirdPartyPlugin.java (from rev 1525, maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/plugin/impl/ThirdPartyPlugin.java)
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/plugin/ThirdPartyPlugin.java (rev 0)
+++ maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/plugin/ThirdPartyPlugin.java 2009-05-11 21:25:22 UTC (rev 1528)
@@ -0,0 +1,311 @@
+/**
+ * *##% Plugin maven pour switcher les licenses
+ * Copyright (C) 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*
+ */
+package org.nuiton.license.plugin;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.ArtifactCollector;
+import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
+import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
+import org.apache.maven.model.License;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.MavenProjectBuilder;
+import org.apache.maven.project.ProjectBuildingException;
+import org.apache.maven.shared.dependency.tree.DependencyNode;
+import org.apache.maven.shared.dependency.tree.DependencyTreeBuilder;
+import org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException;
+import org.nuiton.license.plugin.AbstractLicensePlugin;
+
+import java.io.File;
+import java.util.List;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+/**
+ * Le goal pour copier le fichier THIRD-PARTY.txt (contenant les licenses de toutes les dependances du projet)
+ * dans le classpath (et le generer s'il n'existe pas).
+ *
+ * @author chemit
+ * @goal add-third-party
+ * @phase process-classes
+ * @requiresDependencyResolution test
+ * @requiresProject true
+ */
+public class ThirdPartyPlugin extends AbstractLicensePlugin {
+
+ private static final String unknownLicenseMessage = "Unknown license";
+ /**
+ * Local Repository.
+ *
+ * @parameter expression="${localRepository}"
+ * @required
+ * @readonly
+ */
+ protected ArtifactRepository localRepository;
+ /**
+ * Remote repositories used for the project.
+ *
+ * @parameter expression="${project.remoteArtifactRepositories}"
+ * @required
+ * @readonly
+ */
+ protected List<?> remoteRepositories;
+ /**
+ * Fichier ou ecrire les licences des dependances.
+ *
+ * @parameter expression="${license-switcher.thirdPartyFile}" default-value="${project.build.outputDirectory}/THIRD-PARTY.txt"
+ * @required
+ */
+ protected File thirdPartyFile;
+ /**
+ * Dependency tree builder component.
+ *
+ * @component
+ */
+ protected DependencyTreeBuilder dependencyTreeBuilder;
+ /**
+ * Artifact Factory component.
+ *
+ * @component
+ */
+ protected ArtifactFactory factory;
+ /**
+ * Artifact metadata source component.
+ *
+ * @component
+ */
+ protected ArtifactMetadataSource artifactMetadataSource;
+ /**
+ * Artifact collector component.
+ *
+ * @component
+ */
+ protected ArtifactCollector collector;
+ /**
+ * Maven Project Builder component.
+ *
+ * @component
+ */
+ protected MavenProjectBuilder mavenProjectBuilder;
+ /**
+ * content of third party file (only computed if {@link #force} is active or the
+ * {@link #thirdPartyFile} does not exist, or is not up-to-date.
+ */
+ protected String thirdPartyFileContent;
+
+ @Override
+ protected boolean shouldSkip() {
+ return "pom".equals(project.getPackaging()) || "site".equals(project.getPackaging());
+ }
+
+ @Override
+ protected boolean init() throws Exception {
+
+ boolean doGenerate = false;
+
+ if (!force) {
+ // regenerate only if file exists and is newer than pom file
+ doGenerate = !isFileNewerThanPomFile(thirdPartyFile);
+ }
+
+ if (doGenerate) {
+
+ // prepare thirdPartyFileContent
+
+ DependencyNode dependencyTreeNode = resolveProject();
+
+ LicenseMap licenseMap = new LicenseMap();
+
+ for (Object o : dependencyTreeNode.getChildren()) {
+
+ buildLicenseMap((DependencyNode) o, licenseMap);
+ }
+
+ thirdPartyFileContent = buildGroupedLicenses(licenseMap);
+
+ // log dependencies with no license
+ SortedSet<String> dependenciesWithNoLicense = licenseMap.get(unknownLicenseMessage);
+ if (dependenciesWithNoLicense != null) {
+ for (String dep : dependenciesWithNoLicense) {
+ // no license found for the dependency
+ getLog().warn("no license found for dependency " + dep);
+ }
+ }
+ }
+
+ return doGenerate;
+ }
+
+ @Override
+ protected void doAction() throws Exception {
+ if (verbose) {
+ getLog().info("writing third-party file : " + thirdPartyFile);
+ }
+ if (keepBackup && thirdPartyFile.exists()) {
+ if (verbose) {
+ getLog().info("backup " + thirdPartyFile);
+ }
+ thirdPartyFile.renameTo(new File(thirdPartyFile.getAbsolutePath() + '~'));
+ }
+ copyFile(thirdPartyFileContent, thirdPartyFile, encoding);
+// try {
+// FileUtil.writeString(thirdPartyFile, thirdPartyFileContent, encoding);
+// } catch (IOException e) {
+// throw new MojoExecutionException("could not write file " + thirdPartyFile + " for reason : " + e.getMessage(), e);
+// }
+ }
+
+ /** @return resolve the dependency tree */
+ protected DependencyNode resolveProject() {
+ try {
+ ArtifactFilter artifactFilter = new ScopeArtifactFilter(Artifact.SCOPE_TEST);
+ return dependencyTreeBuilder.buildDependencyTree(project, localRepository, factory,
+ artifactMetadataSource, artifactFilter, collector);
+ } catch (DependencyTreeBuilderException e) {
+ getLog().error("Unable to build dependency tree.", e);
+ return null;
+ }
+ }
+
+ protected void buildLicenseMap(DependencyNode node, LicenseMap licenseMap) {
+ if (node.getState() != DependencyNode.INCLUDED) {
+ // this dependency is not included, so do not treate it
+ if (verbose) {
+ getLog().info("do not include this dependency " + node.toNodeString());
+ }
+ return;
+ }
+ Artifact artifact = node.getArtifact();
+
+ if (verbose && getLog().isDebugEnabled()) {
+ getLog().debug("treate node " + node.toNodeString());
+ }
+
+ if (!Artifact.SCOPE_SYSTEM.equals(artifact.getScope())) {
+ try {
+ MavenProject artifactProject = getMavenProjectFromRepository(artifact);
+ String artifactName = getArtifactName(artifactProject);
+
+ List<?> licenses = artifactProject.getLicenses();
+
+ if (licenses.isEmpty()) {
+ // no license found for the dependency
+ licenseMap.put(unknownLicenseMessage, artifactName);
+
+ } else {
+ for (Object o : licenses) {
+ if (o == null) {
+ getLog().warn("could not acquire the license for " + artifactName);
+ continue;
+ }
+ License license = (License) o;
+ String licenseKey = license.getName();
+ if (license.getName() == null) {
+ licenseKey = license.getUrl();
+ }
+ licenseMap.put(licenseKey, artifactName);
+ }
+ }
+ } catch (ProjectBuildingException e) {
+ getLog().error("ProjectBuildingException error : ", e);
+ }
+ }
+ if (!node.getChildren().isEmpty()) {
+ for (Object o : node.getChildren()) {
+ buildLicenseMap((DependencyNode) o, licenseMap);
+ }
+ }
+ }
+
+ protected String buildGroupedLicenses(LicenseMap licenseMap) {
+ StringBuilder sb = new StringBuilder();
+ sb.append("List of third-party dependencies grouped by their license type.");
+ for (String licenseName : licenseMap.keySet()) {
+ sb.append("\n\n").append(licenseName).append(" : ");
+
+ SortedSet<String> projects = licenseMap.get(licenseName);
+
+ for (String projectName : projects) {
+ sb.append("\n * ").append(projectName);
+ }
+ }
+ return sb.toString();
+ }
+
+ protected String getArtifactName(MavenProject artifactProject) {
+ StringBuilder sb = new StringBuilder();
+
+ sb.append(artifactProject.getName());
+ sb.append(" (");
+ sb.append(artifactProject.getGroupId());
+ sb.append(":");
+ sb.append(artifactProject.getArtifactId());
+ sb.append(":");
+ sb.append(artifactProject.getVersion());
+ sb.append(" - ");
+ String url = artifactProject.getUrl();
+ sb.append(url == null ? "no url defined" : url);
+ sb.append(")");
+
+ return sb.toString();
+ }
+
+ /**
+ * Get the <code>Maven project</code> from the repository depending the <code>Artifact</code> given.
+ *
+ * @param artifact an artifact
+ * @return the Maven project for the given artifact
+ * @throws ProjectBuildingException if any
+ */
+ protected MavenProject getMavenProjectFromRepository(Artifact artifact)
+ throws ProjectBuildingException {
+
+ boolean allowStubModel = false;
+
+ if (!"pom".equals(artifact.getType())) {
+ artifact = factory.createProjectArtifact(artifact.getGroupId(), artifact.getArtifactId(),
+ artifact.getVersion(), artifact.getScope());
+ allowStubModel = true;
+ }
+
+ // TODO: we should use the MavenMetadataSource instead
+ return mavenProjectBuilder.buildFromRepository(artifact, remoteRepositories, localRepository,
+ allowStubModel);
+ }
+
+ protected class LicenseMap extends java.util.TreeMap<String, SortedSet<String>> {
+
+ private static final long serialVersionUID = 864199843545688069L;
+
+ public SortedSet<String> put(String key, String value) {
+ // handle multiple values as a set to avoid duplicates
+ SortedSet<String> valueList = get(key);
+ if (valueList == null) {
+ valueList = new TreeSet<String>();
+ }
+ if (getLog().isDebugEnabled()) {
+ getLog().debug("key:" + key + ",value: " + value);
+ }
+ valueList.add(value);
+ return put(key, valueList);
+ }
+ }
+}
Property changes on: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/plugin/ThirdPartyPlugin.java
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/plugin/impl/LicensePluginTest.java
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/plugin/impl/LicensePluginTest.java 2009-05-11 21:25:01 UTC (rev 1527)
+++ maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/plugin/impl/LicensePluginTest.java 2009-05-11 21:25:22 UTC (rev 1528)
@@ -1,5 +1,6 @@
package org.codelutin.license.plugin.impl;
+import org.nuiton.license.plugin.LicensePlugin;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.codelutin.license.plugin.BasePluginTestCase;
Copied: maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/license/BaseLicenseTestCase.java (from rev 1525, maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/BaseLicenseTestCase.java)
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/license/BaseLicenseTestCase.java (rev 0)
+++ maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/license/BaseLicenseTestCase.java 2009-05-11 21:25:22 UTC (rev 1528)
@@ -0,0 +1,80 @@
+package org.nuiton.license;
+
+import org.nuiton.license.License;
+import java.io.ByteArrayInputStream;
+import org.junit.Assert;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.io.RawInputStreamFacade;
+
+/** @author chemit */
+public abstract class BaseLicenseTestCase extends Assert {
+
+ protected static final String encoding = "utf-8";
+
+ protected File getBaseDir() {
+ String path = System.getenv("basedir");
+ if (path == null) {
+ path = new File("").getAbsolutePath();
+ }
+ return new File(path);
+ }
+
+ protected void assertLicenseFound(String name, License license) throws IOException {
+ assertNotNull(license);
+ assertEquals(name, license.getName());
+ assertNotNull(license.getLicenseContent(encoding));
+ assertNotNull(license.getHeaderContent(encoding));
+ }
+
+ protected File createLicenseRepository(boolean createLicene) throws IOException {
+ long timestamp = System.currentTimeMillis();
+
+ File repo = new File(getBaseDir(), "target" + File.separator + "licenses_" + timestamp);
+
+ if (createLicene) {
+
+ String licenseName = "dummy_" + timestamp;
+ addLicenseToRepository(repo, licenseName);
+ }
+ return repo;
+ }
+
+ protected void addLicenseToRepository(File repo, String licenseName) throws IOException {
+
+ File defFile = new File(repo, "licenses.properties");
+
+ String content = "";
+ if (defFile.exists()) {
+
+ content = IOUtil.toString(new FileInputStream(defFile), encoding) + "\n";
+// content = FileUtil.readAsString(defFile, encoding) + "\n";
+ }
+
+
+ write(defFile, content + licenseName + "=My dummy license\n", encoding);
+// FileUtil.writeString(defFile, content + licenseName + "=My dummy license\n", encoding);
+ // create dummy licenses
+ File file = new File(repo, licenseName);
+ file.mkdirs();
+ write(new File(file, "license.txt"), "license:" + licenseName, encoding);
+ write(new File(file, "header.txt"), "header:" + licenseName, encoding);
+// FileUtil.writeString(new File(file, "license.txt"), "license:" + licenseName, encoding);
+// FileUtil.writeString(new File(file, "header.txt"), "header:" + licenseName, encoding);
+
+ }
+
+ protected void write(File destFile, String content, String encoding) throws IOException {
+
+ InputStream in = new ByteArrayInputStream(content.getBytes(encoding));
+ RawInputStreamFacade facade = new RawInputStreamFacade(in);
+
+ FileUtils.copyStreamToFile(facade, destFile);
+ }
+}
+
Property changes on: maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/license/BaseLicenseTestCase.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/license/JarLicenseResolverTest.java (from rev 1524, maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/JarLicenseResolverTest.java)
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/license/JarLicenseResolverTest.java (rev 0)
+++ maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/license/JarLicenseResolverTest.java 2009-05-11 21:25:22 UTC (rev 1528)
@@ -0,0 +1,64 @@
+package org.nuiton.license;
+
+import org.nuiton.license.License;
+import org.nuiton.license.JarLicenseResolver;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Map;
+
+/** @author chemit */
+public class JarLicenseResolverTest extends BaseLicenseTestCase {
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testResolvFailed1() throws Exception {
+ new JarLicenseResolver().resolv(null);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testResolvFailed2() throws Exception {
+ new JarLicenseResolver().resolv("");
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testResolvFailed3() throws Exception {
+ new JarLicenseResolver().resolv(" ");
+ }
+
+ @Test
+ public void testResolv() throws Exception {
+ JarLicenseResolver resolver = new JarLicenseResolver();
+
+ {
+ String name = "dummy_" + System.currentTimeMillis();
+ License license = resolver.resolv(name);
+ assertNull(license);
+ }
+
+ for (String name : new String[]{
+ "gpl_v1",
+ "gpl_v2",
+ "gpl_v3",
+ "lgpl_v2_1",
+ "lgpl_v3"}) {
+ License license = resolver.resolv(name);
+ assertLicenseFound(name, license);
+ }
+
+ }
+
+ @Test
+ public void testGetLicenseNames() throws Exception {
+ JarLicenseResolver resolver = new JarLicenseResolver();
+ Map<String, String> licenseNames = resolver.getLicenseNames();
+
+ assertEquals(Arrays.asList("gpl_v1",
+ "gpl_v2",
+ "gpl_v3",
+ "lgpl_v2_1",
+ "lgpl_v3"), new ArrayList<String>(licenseNames.keySet()));
+ }
+
+
+}
Property changes on: maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/license/JarLicenseResolverTest.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/license/LicenseFactoryTest.java (from rev 1524, maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/LicenseFactoryTest.java)
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/license/LicenseFactoryTest.java (rev 0)
+++ maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/license/LicenseFactoryTest.java 2009-05-11 21:25:22 UTC (rev 1528)
@@ -0,0 +1,83 @@
+package org.nuiton.license;
+
+import org.nuiton.license.LicenseFactory;
+import org.nuiton.license.LicenseResolver;
+import org.nuiton.license.JarLicenseResolver;
+import org.junit.Test;
+
+import java.io.File;
+import java.util.Map;
+
+/** @author chemit */
+public class LicenseFactoryTest extends BaseLicenseTestCase {
+
+ @Test
+ public void testNewInstance() throws Exception {
+
+ LicenseFactory factory = LicenseFactory.newInstance();
+ assertNotNull(factory);
+ assertEquals(1, factory.resolvers.size());
+ assertNotNull(factory.resolvers.get(0));
+ assertEquals(JarLicenseResolver.class, factory.resolvers.get(0).getClass());
+
+ factory = LicenseFactory.newInstance("");
+ assertNotNull(factory);
+ assertEquals(1, factory.resolvers.size());
+ assertNotNull(factory.resolvers.get(0));
+ assertEquals(JarLicenseResolver.class, factory.resolvers.get(0).getClass());
+
+ factory = LicenseFactory.newInstance("yo");
+ assertNotNull(factory);
+
+ assertEquals(2, factory.resolvers.size());
+ assertNotNull(factory.resolvers.get(0));
+ assertEquals(JarLicenseResolver.class, factory.resolvers.get(0).getClass());
+ assertNotNull(factory.resolvers.get(1));
+ assertEquals(LicenseResolver.class, factory.resolvers.get(1).getClass());
+ assertEquals("yo", factory.resolvers.get(1).getBaseURL());
+
+ factory.addResolver(new LicenseResolver("yo2"));
+ assertEquals(3, factory.resolvers.size());
+ assertNotNull(factory.resolvers.get(0));
+ assertEquals(JarLicenseResolver.class, factory.resolvers.get(0).getClass());
+ assertNotNull(factory.resolvers.get(1));
+ assertEquals(LicenseResolver.class, factory.resolvers.get(1).getClass());
+ assertEquals("yo", factory.resolvers.get(1).getBaseURL());
+ assertEquals(LicenseResolver.class, factory.resolvers.get(2).getClass());
+ assertEquals("yo2", factory.resolvers.get(2).getBaseURL());
+
+ }
+
+ @Test
+ public void testGetLicenseNames() throws Exception {
+ LicenseFactory factory = LicenseFactory.newInstance();
+
+ int expectedJarResolverLicenses = 5;
+ Map<String, String> licenseNames = factory.getLicenseNames();
+ //todo make dynamic that test
+ assertEquals(expectedJarResolverLicenses, licenseNames.size());
+
+ // create a new dummy license repository with a license
+ File repo = createLicenseRepository(true);
+
+ LicenseResolver resolver = new LicenseResolver();
+ resolver.setBaseURL(repo.toURI().toURL().toString());
+
+ factory.addResolver(resolver);
+
+ licenseNames = factory.getLicenseNames();
+ assertEquals(expectedJarResolverLicenses + 1, licenseNames.size());
+
+ // add a new license to repo
+ long timestamp = System.currentTimeMillis();
+ String licenseName = "dummy2_" + timestamp;
+ addLicenseToRepository(repo, licenseName);
+
+ factory = LicenseFactory.newInstance(repo.toURI().toURL().toString());
+
+ licenseNames = factory.getLicenseNames();
+ assertEquals(expectedJarResolverLicenses + 2, licenseNames.size());
+
+ }
+
+}
Property changes on: maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/license/LicenseFactoryTest.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/license/LicenseGeneratorFactoryTest.java (from rev 1524, maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/LicenseGeneratorFactoryTest.java)
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/license/LicenseGeneratorFactoryTest.java (rev 0)
+++ maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/license/LicenseGeneratorFactoryTest.java 2009-05-11 21:25:22 UTC (rev 1528)
@@ -0,0 +1,34 @@
+package org.nuiton.license;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/** @author chemit */
+public class LicenseGeneratorFactoryTest {
+
+ @Before
+ public void setUp() {
+ // Add your code here
+ }
+
+ @After
+ public void tearDown() {
+ // Add your code here
+ }
+
+ @Test
+ public void testGetAvailableGenerator() {
+ // Add your code here
+ }
+
+ @Test
+ public void testGetGeneratorMatchers() {
+ // Add your code here
+ }
+
+ @Test
+ public void testAddGenerator() {
+ // Add your code here
+ }
+}
Property changes on: maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/license/LicenseGeneratorFactoryTest.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/license/LicenseResolverTest.java (from rev 1524, maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/LicenseResolverTest.java)
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/license/LicenseResolverTest.java (rev 0)
+++ maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/license/LicenseResolverTest.java 2009-05-11 21:25:22 UTC (rev 1528)
@@ -0,0 +1,115 @@
+package org.nuiton.license;
+
+import org.nuiton.license.License;
+import org.nuiton.license.LicenseResolver;
+import org.junit.Test;
+
+import java.io.File;
+import java.util.Map;
+
+/** @author chemit */
+public class LicenseResolverTest extends BaseLicenseTestCase {
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testResolvIllegalArgumentException1() throws Exception {
+
+ LicenseResolver resolver = new LicenseResolver();
+ // no baseURL
+ // no licenseName
+ // no licenses.txt
+ resolver.resolv(null);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testResolvIllegalArgumentException2() throws Exception {
+
+ LicenseResolver resolver = new LicenseResolver();
+
+ // no baseURL
+ // no licenseName
+ // no licenses.txt
+ resolver.resolv("");
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testResolvIllegalArgumentException3() throws Exception {
+
+ LicenseResolver resolver = new LicenseResolver();
+
+ // no baseURL
+ // no licenseName
+ // no licenses.txt
+ resolver.resolv(" ");
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testResolvIllegalArgumentException4() throws Exception {
+
+ LicenseResolver resolver = new LicenseResolver();
+
+ // no baseURL
+ // no licenses.txt
+ resolver.resolv("dummy");
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testResolvIllegalArgumentException5() throws Exception {
+
+ LicenseResolver resolver = new LicenseResolver();
+
+
+ resolver.setBaseURL("dummy");
+ // no licenses.txt
+ resolver.resolv("dummy");
+ }
+
+ @Test
+ public void testResolv() throws Exception {
+
+ LicenseResolver resolver = new LicenseResolver();
+
+ long timestamp = System.currentTimeMillis();
+ String licenseName = "dummy_" + timestamp;
+
+ File repo = createLicenseRepository(false);
+
+ resolver.setBaseURL(repo.toURI().toURL().toString());
+
+ License license;
+
+ try {
+ // no licenses.properties
+ resolver.resolv(licenseName);
+ fail();
+ } catch (IllegalArgumentException e) {
+ assertTrue(true);
+ }
+
+ addLicenseToRepository(repo, licenseName);
+
+ //FileUtil.writeString(new File(repo, "licenses.properties"), licenseName + "=My dummy license\n", encoding);
+ //license = resolver.resolv(licenseName);
+ //assertNull(license);
+
+ Map<String, String> licenseNames = resolver.getLicenseNames();
+ assertNotNull(licenseNames);
+ assertEquals(1, licenseNames.size());
+ assertTrue(licenseNames.containsKey(licenseName));
+
+ // create dummy licenses
+ //File file = new File(repo, licenseName);
+ //file.mkdirs();
+ //FileUtil.writeString(new File(file, "license.txt"), "license", encoding);
+ //FileUtil.writeString(new File(file, "header.txt"), "header", encoding);
+
+ license = resolver.resolv(licenseName);
+ assertNotNull(license);
+ assertEquals(licenseName, license.getName());
+ assertNotNull(license.getLicenseContent(encoding));
+ assertNotNull(license.getHeaderContent(encoding));
+ assertEquals("license:" + licenseName, license.getLicenseContent(encoding));
+ assertEquals("header:" + licenseName, license.getHeaderContent(encoding));
+
+ }
+
+}
\ No newline at end of file
Added: maven-nuiton-project-helper-plugin/trunk/src/test/resources/org/nuiton/license/plugin/LicensePluginTest/licenseOne.txt
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/test/resources/org/nuiton/license/plugin/LicensePluginTest/licenseOne.txt (rev 0)
+++ maven-nuiton-project-helper-plugin/trunk/src/test/resources/org/nuiton/license/plugin/LicensePluginTest/licenseOne.txt 2009-05-11 21:25:22 UTC (rev 1528)
@@ -0,0 +1 @@
+dummy license
\ No newline at end of file
Added: maven-nuiton-project-helper-plugin/trunk/src/test/resources/org/nuiton/license/plugin/LicensePluginTest/testOne.xml
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/test/resources/org/nuiton/license/plugin/LicensePluginTest/testOne.xml (rev 0)
+++ maven-nuiton-project-helper-plugin/trunk/src/test/resources/org/nuiton/license/plugin/LicensePluginTest/testOne.xml 2009-05-11 21:25:22 UTC (rev 1528)
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <groupId>org.nuiton</groupId>
+ <artifactId>maven-nuiton-project-helper-plugin-testOne</artifactId>
+ <version>0</version>
+
+ <build>
+
+ <plugins>
+ <plugin>
+ <groupId>org.nuiton</groupId>
+ <artifactId>maven-nuiton-project-helper-plugin</artifactId>
+ <configuration>
+ <encoding>UTF-8</encoding>
+ <licenseName>lgpl_v3</licenseName>
+ <licenseFile>licenseOne.txt</licenseFile>
+ <pomFile>testOne.xml</pomFile>
+ <outputDirectory>target/tests/LicenPluginTest/test-java</outputDirectory>
+ <verbose>true</verbose>
+ </configuration>
+ <executions>
+ <execution>
+ <goals>
+ <goal>add-license</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
1
0