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-plugin</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-project-helper-plugin/trunk/?root=lutinbuilder</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.artifactId}/trunk/?root=lutinbuilder</url> </scm> <distributionManagement> @@ -386,7 +418,7 @@ </repository> <site> <id>labs</id> - <url>scpexe://labs.libre-entreprise.org/home/groups/lutinbuilder/htdocs/maven-nuiton-project-helper-plugin</url> + <url>scpexe://labs.libre-entreprise.org/home/groups/lutinbuilder/htdocs/${project.artifactId}</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 */ +@Retention(RetentionPolicy.RUNTIME) + +@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 +