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
- 3157 discussions
[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
[Lutinutil-commits] r1527 - in maven-nuiton-project-helper-plugin/trunk/src: main/java/org test/resources/org
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:01 +0000 (Mon, 11 May 2009)
New Revision: 1527
Removed:
maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/
maven-nuiton-project-helper-plugin/trunk/src/test/resources/org/codelutin/
Log:
migrate to nuiton
1
0
[Lutinutil-commits] r1526 - in maven-nuiton-project-helper-plugin/trunk: . src/main/java/org src/main/java/org/nuiton src/test/java/org src/test/java/org/nuiton
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:20:14 +0000 (Mon, 11 May 2009)
New Revision: 1526
Added:
maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/
maven-nuiton-project-helper-plugin/trunk/src/main/java/org/nuiton/license/
maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/
maven-nuiton-project-helper-plugin/trunk/src/test/java/org/nuiton/license/
Modified:
maven-nuiton-project-helper-plugin/trunk/pom.xml
Log:
migrate to nuiton
Modified: maven-nuiton-project-helper-plugin/trunk/pom.xml
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/pom.xml 2009-05-11 19:54:46 UTC (rev 1525)
+++ maven-nuiton-project-helper-plugin/trunk/pom.xml 2009-05-11 21:20:14 UTC (rev 1526)
@@ -6,32 +6,13 @@
<!-- ************************************************************* -->
<!-- *** POM Relationships *************************************** -->
<!-- ************************************************************* -->
- <!--parent>
- <groupId>org.nuiton</groupId>
- <artifactId>nuitonproject</artifactId>
- <version>3.6.0-SNAPSHOT</version>
- </parent-->
-
+
<groupId>org.nuiton</groupId>
<artifactId>maven-nuiton-project-helper-plugin</artifactId>
<version>1.0.0-SNAPSHOT</version>
<dependencies>
-
- <!--dependency>
- <groupId>org.codelutin</groupId>
- <artifactId>lutinprocessor</artifactId>
- <version>${processor.version}</version>
- <scope>compile</scope>
- </dependency>
-
- <dependency>
- <groupId>org.codelutin</groupId>
- <artifactId>lutinpluginutil</artifactId>
- <version>${lutinpluginutil.version}</version>
- <scope>compile</scope>
- </dependency-->
<dependency>
<groupId>org.apache.maven.shared</groupId>
@@ -296,14 +277,92 @@
</pluginManagement>
</build>
+
<reporting>
<plugins>
+
+ <!--
+ The Project Info Reports Plugin has twelve goals:
+ * project-info-reports:cim is used to generate the Project Continuous Integration System report.
+ * project-info-reports:dependencies is used to generate the Project Dependencies report.
+ * project-info-reports:dependency-convergence is used to generate the Project Dependency Convergence report for reactor builds.
+ * project-info-reports:dependency-management is used to generate the Project DependencyManagement report.
+ * project-info-reports:index is used to generate the Project index page.
+ * project-info-reports:issue-tracking is used to generate the Project Issue Tracking report.
+ * project-info-reports:license is used to generate the Project License report.
+ * project-info-reports:mailing-list is used to generate the Project Mailing List report.
+ * project-info-reports:plugin-management is used to generate the Project PluginManagement report.
+ * project-info-reports:project-team is used to generate the Project Team report.
+ * project-info-reports:scm is used to generate the Project Source Code Management report.
+ * project-info-reports:summary is used to generate the Project information reports summary.
+ -->
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.1.1-cl</version>
</plugin>
-
+
<plugin>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>2.5</version>
+ <configuration>
+ <quiet>true</quiet>
+ <docencoding>${project.build.sourceEncoding}</docencoding>
+ <encoding>${project.build.sourceEncoding}</encoding>
+ </configuration>
+ </plugin>
+
+ <!-- changelog:changelog
+ changelog:dev-activity
+ changelog:file-activity -->
+ <plugin>
+ <artifactId>maven-changelog-plugin</artifactId>
+ <version>2.1</version>
+ </plugin>
+
+ <!-- Implicit add of reportSet to not generate jira reports -->
+ <plugin>
+ <artifactId>maven-changes-plugin</artifactId>
+ <version>2.1</version>
+ <reportSets>
+ <reportSet>
+ <reports>
+ <report>changes-report</report>
+ </reports>
+ </reportSet>
+ </reportSets>
+ </plugin>
+
+ <plugin>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <version>2.2</version>
+ <configuration>
+ <encoding>${project.reporting.outputEncoding}</encoding>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <artifactId>maven-pmd-plugin</artifactId>
+ <version>2.4</version>
+ <configuration>
+ <linkXRef>true</linkXRef>
+ <sourceEncoding>${project.reporting.outputEncoding}</sourceEncoding>
+ <minimumTokens>100</minimumTokens>
+ <targetJdk>${maven.compile.target}</targetJdk>
+ </configuration>
+
+ </plugin>
+
+ <plugin>
+ <artifactId>maven-jxr-plugin</artifactId>
+ <version>2.1</version>
+ </plugin>
+
+ <plugin>
+ <artifactId>maven-surefire-report-plugin</artifactId>
+ <version>2.4.3</version>
+ </plugin>
+
+ <plugin>
<artifactId>maven-plugin-plugin</artifactId>
</plugin>
</plugins>
@@ -315,11 +374,35 @@
<!--Source control management-->
<scm>
- <url>${maven.scm.url}</url>
- <connection>${maven.scm.connection}</connection>
- <developerConnection>${maven.scm.developerConnection}</developerConnection>
+ <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>
</scm>
+ <distributionManagement>
+ <repository>
+ <id>labs</id>
+ <url>scpexe://labs.libre-entreprise.org/home/groups/lutinbuilder/htdocs/maven2</url>
+ </repository>
+ <site>
+ <id>labs</id>
+ <url>scpexe://labs.libre-entreprise.org/home/groups/lutinbuilder/htdocs/maven-nu…</url>
+ </site>
+ </distributionManagement>
+
+ <ciManagement>
+ <system>hudson</system>
+ <url>http://hudson.codelutin.com</url>
+ <notifiers>
+ <notifier>
+ <address>admin+hudson(a)codelutin.com</address>
+ <configuration>
+ <recipients>dev(a)codelutin.com</recipients>
+ </configuration>
+ </notifier>
+ </notifiers>
+ </ciManagement>
+
<!--Code Lutin Repository-->
<repositories>
<repository>
@@ -349,21 +432,94 @@
</activation>
<build>
<plugins>
- <!-- always add license and third-party files to classpath -->
+
+ <!-- always check labs properties -->
<plugin>
- <groupId>org.codelutin</groupId>
- <artifactId>maven-license-switcher-plugin</artifactId>
- <version>0.8</version>
+ <artifactId>maven-enforcer-plugin</artifactId>
+ <version>1.0-beta-1</version>
<executions>
<execution>
+ <id>attach-nuiton-enforcer</id>
+ <goals>
+ <goal>enforce</goal>
+ </goals>
+ <phase>initialize</phase>
+ </execution>
+ </executions>
+ <configuration>
+ <rules>
+ <!--requireProperty>
+ <property>labs.id</property>
+ <regex>\d+</regex>
+ <regexMessage>"labs.id can must be a number!"</regexMessage>
+ </requireProperty>
+ <requireProperty>
+ <property>labs.project</property>
+ <regex>\w(\w|\d|-)*</regex>
+ <regexMessage>"labs.project can not be empty!"</regexMessage>
+ </requireProperty-->
+ <requireFilesExist>
+ <files>
+ <file>changelog.txt</file>
+ <file>LICENSE.txt</file>
+ <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 -->
+ <plugin>
+ <artifactId>maven-source-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>attach-sources</id>
+ </execution>
+ </executions>
+ </plugin>
+
+ <!-- always compute javadoc jar -->
+ <plugin>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>attach-javadocs</id>
+ </execution>
+ </executions>
+ </plugin>
+
+ <!-- always add license and third-party files to classpath -->
+ <!--plugin>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>${project.artifactId}</artifactId>
+ <version>${project.version}</version>
+ <executions>
+ <execution>
<id>attach-licenses</id>
<goals>
- <goal>license</goal>
- <goal>third-party</goal>
+ <goal>add-license</goal>
+ <goal>add-third-party</goal>
</goals>
</execution>
</executions>
- </plugin>
+ </plugin-->
</plugins>
</build>
</profile>
1
0
[Lutinutil-commits] r1525 - in maven-nuiton-project-helper-plugin/trunk: . src/main/java/org/codelutin/license src/main/java/org/codelutin/license/plugin src/main/java/org/codelutin/license/plugin/impl src/site src/test/java/org/codelutin/license src/test/java/org/codelutin/license/plugin src/test/java/org/codelutin/license/plugin/impl src/test/resources/org/codelutin/license/plugin/impl/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 19:54:46 +0000 (Mon, 11 May 2009)
New Revision: 1525
Removed:
maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/JavaLicenseGenerator.java
maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/XmlLicenseGenerator.java
maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/plugin/impl/SwitchLicensePlugin.java
maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/JavaLicenseGeneratorTest.java
maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/XmlLicenseGeneratorTest.java
Modified:
maven-nuiton-project-helper-plugin/trunk/pom.xml
maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/License.java
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/codelutin/license/plugin/impl/LicensePlugin.java
maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/plugin/impl/ThirdPartyPlugin.java
maven-nuiton-project-helper-plugin/trunk/src/site/site.xml
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/plugin/BasePluginTestCase.java
maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/plugin/impl/LicensePluginTest.java
maven-nuiton-project-helper-plugin/trunk/src/test/resources/org/codelutin/license/plugin/impl/LicensePluginTest/testOne.xml
Log:
first goals :
* add-license
* add-third-party
Modified: maven-nuiton-project-helper-plugin/trunk/pom.xml
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/pom.xml 2009-05-11 17:49:30 UTC (rev 1524)
+++ maven-nuiton-project-helper-plugin/trunk/pom.xml 2009-05-11 19:54:46 UTC (rev 1525)
@@ -6,19 +6,20 @@
<!-- ************************************************************* -->
<!-- *** POM Relationships *************************************** -->
<!-- ************************************************************* -->
- <parent>
- <groupId>org.codelutin</groupId>
- <artifactId>lutinproject</artifactId>
- <version>3.5.4</version>
- </parent>
+ <!--parent>
+ <groupId>org.nuiton</groupId>
+ <artifactId>nuitonproject</artifactId>
+ <version>3.6.0-SNAPSHOT</version>
+ </parent-->
- <artifactId>maven-license-switcher-plugin</artifactId>
+ <groupId>org.nuiton</groupId>
+ <artifactId>maven-nuiton-project-helper-plugin</artifactId>
<version>1.0.0-SNAPSHOT</version>
<dependencies>
- <dependency>
+ <!--dependency>
<groupId>org.codelutin</groupId>
<artifactId>lutinprocessor</artifactId>
<version>${processor.version}</version>
@@ -30,7 +31,7 @@
<artifactId>lutinpluginutil</artifactId>
<version>${lutinpluginutil.version}</version>
<scope>compile</scope>
- </dependency>
+ </dependency-->
<dependency>
<groupId>org.apache.maven.shared</groupId>
@@ -68,16 +69,53 @@
<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 pour switcher les licenses</name>
+ <name>Plugin maven d'aide pour les projets nuiton</name>
- <description>Plugin pour switcher de license dans un module maven 2</description>
- <inceptionYear>2008</inceptionYear>
+ <url>http://lutinbuilder.labs.libre-entreprise.org/maven-nuiton-project-helper-p…</url>
+ <description>Plugin d'aide pour les projets nuiton</description>
+ <inceptionYear>2009</inceptionYear>
+
+ <licenses>
+ <license>
+ <name>LGPL</name>
+ <url>http://www.gnu.org/licenses/lgpl.txt</url>
+ <distribution>repo</distribution>
+ </license>
+ </licenses>
+
+ <developers>
+ <developer>
+ <id>tchemit</id>
+ <name>Tony Chemit</name>
+ <email>chemit(a)codelutin.com</email>
+ <organization>CodeLutin</organization>
+ <roles>
+ <role>Développeur</role>
+ </roles>
+ <timezone>+2</timezone>
+ </developer>
+ </developers>
+
<!-- ************************************************************* -->
<!-- *** Build Settings ****************************************** -->
<!-- ************************************************************* -->
@@ -85,20 +123,48 @@
<packaging>maven-plugin</packaging>
<properties>
- <labs.id>12</labs.id>
- <labs.project>lutinutil</labs.project>
+
+ <!--labs.id>12</labs.id>
+ <labs.project>lutinutil</labs.project-->
- <processor.version>0.18</processor.version>
- <lutinpluginutil.version>0.5</lutinpluginutil.version>
-
<maven.version>2.0.10</maven.version>
+ <maven.src.dir>${basedir}/src</maven.src.dir>
+ <maven.compile.source>1.6</maven.compile.source>
+ <maven.compile.target>1.6</maven.compile.target>
+
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+
+ <!-- to allow bad tests -->
+ <maven.test.testFailureIgnore>false</maven.test.testFailureIgnore>
+
+ <!-- to skip tests (can use also profile notests) -->
+ <maven.test.skip>false</maven.test.skip>
+
+ <!-- to control fork mode of tests -->
+ <maven.test.forkMode>never</maven.test.forkMode>
+
</properties>
<build>
<defaultGoal>install</defaultGoal>
+ <!--Ressources-->
+
+ <testResources>
+ <testResource>
+ <directory>${maven.src.dir}/test/resources</directory>
+ <includes>
+ <include>**/*</include>
+ </includes>
+ <excludes>
+ <exclude>**/*~</exclude>
+ </excludes>
+ </testResource>
+ </testResources>
+
<plugins>
<!-- plugin plugin -->
@@ -136,25 +202,108 @@
</execution>
</executions>
</plugin>
- <!-- plugin site -->
- <plugin>
- <artifactId>maven-site-plugin</artifactId>
- <dependencies>
- <dependency>
- <groupId>org.codelutin</groupId>
- <artifactId>doxia-module-jrst</artifactId>
- <version>1.0.0</version>
- </dependency>
- </dependencies>
- </plugin>
+
</plugins>
+
+ <pluginManagement>
+
+ <plugins>
+
+ <plugin>
+ <artifactId>maven-resources-plugin</artifactId>
+ <configuration>
+ <encoding>${project.build.sourceEncoding}</encoding>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>${maven.compile.source}</source>
+ <target>${maven.compile.target}</target>
+ <encoding>${project.build.sourceEncoding}</encoding>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.4.3</version>
+ <configuration>
+ <skip>${maven.test.skip}</skip>
+ <testFailureIgnore>${maven.test.testFailureIgnore}</testFailureIgnore>
+ <forkMode>${maven.test.forkMode}</forkMode>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <artifactId>maven-source-plugin</artifactId>
+ <version>2.1</version>
+ <inherited>true</inherited>
+ <executions>
+ <execution>
+ <id>attach-sources</id>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>2.5</version>
+ <configuration>
+ <docencoding>${project.reporting.outputEncoding}</docencoding>
+ <encoding>${project.reporting.outputEncoding}</encoding>
+ <charset>${project.reporting.outputEncoding}</charset>
+ <quiet>true</quiet>
+ </configuration>
+ <executions>
+ <execution>
+ <id>attach-javadocs</id>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ <configuration>
+ <attach>true</attach>
+ <quiet>true</quiet>
+ <!-- uniquement a partir de javadoc 2.5 -->
+ <!--skip>${maven.javadoc.skip}</skip-->
+ </configuration>
+ </execution>
+ </executions>
+
+ </plugin>
+
+ <plugin>
+ <artifactId>maven-site-plugin</artifactId>
+ <version>2.0</version>
+ <configuration>
+ <locales>fr</locales>
+ <siteDirectory>src/site</siteDirectory>
+ <inputEncoding>${project.reporting.outputEncoding}</inputEncoding>
+ <outputEncoding>${project.reporting.outputEncoding}</outputEncoding>
+ <generateReports>true</generateReports>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <artifactId>maven-release-plugin</artifactId>
+ <version>2.0-beta-9</version>
+ </plugin>
+
+ </plugins>
+ </pluginManagement>
</build>
- <!--Site-->
<reporting>
<plugins>
- <!--Site report's plugin-->
<plugin>
+ <artifactId>maven-project-info-reports-plugin</artifactId>
+ <version>2.1.1-cl</version>
+ </plugin>
+
+ <plugin>
<artifactId>maven-plugin-plugin</artifactId>
</plugin>
</plugins>
Deleted: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/JavaLicenseGenerator.java
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/JavaLicenseGenerator.java 2009-05-11 17:49:30 UTC (rev 1524)
+++ maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/JavaLicenseGenerator.java 2009-05-11 19:54:46 UTC (rev 1525)
@@ -1,13 +0,0 @@
-package org.codelutin.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";
- }
-
-}
Modified: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/License.java
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/License.java 2009-05-11 17:49:30 UTC (rev 1524)
+++ maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/License.java 2009-05-11 19:54:46 UTC (rev 1525)
@@ -1,13 +1,12 @@
package org.codelutin.license;
-import org.codelutin.util.FileUtil;
-
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.
@@ -18,10 +17,8 @@
/** 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;
@@ -48,7 +45,8 @@
InputStream inputStream = licenseURL.openStream();
Reader r = new BufferedReader(new InputStreamReader(inputStream, encoding));
try {
- return FileUtil.readAsString(r);
+ return IOUtil.toString(r);
+// return FileUtil.readAsString(r);
} finally {
r.close();
}
@@ -60,7 +58,8 @@
}
Reader r = new BufferedReader(new InputStreamReader(headerURL.openStream(), encoding));
try {
- return FileUtil.readAsString(r);
+ return IOUtil.toString(r);
+// return FileUtil.readAsString(r);
} finally {
r.close();
}
Deleted: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/XmlLicenseGenerator.java
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/XmlLicenseGenerator.java 2009-05-11 17:49:30 UTC (rev 1524)
+++ maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/XmlLicenseGenerator.java 2009-05-11 19:54:46 UTC (rev 1525)
@@ -1,13 +0,0 @@
-package org.codelutin.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
Modified: 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/codelutin/license/plugin/AbstractLicensePlugin.java 2009-05-11 17:49:30 UTC (rev 1524)
+++ maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/plugin/AbstractLicensePlugin.java 2009-05-11 19:54:46 UTC (rev 1525)
@@ -18,12 +18,16 @@
*/
package org.codelutin.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.
@@ -54,7 +58,6 @@
* @throws Exception if any
*/
protected abstract void doAction() throws Exception;
-
/**
* Dependance du projet.
*
@@ -62,7 +65,6 @@
* @required
*/
protected MavenProject project;
-
/**
* Repertoire de sortie des classes (classpath).
*
@@ -70,7 +72,6 @@
* @required
*/
protected File outputDirectory;
-
/**
* Encoding a utiliser pour lire et ecrire les fichiers.
*
@@ -78,7 +79,6 @@
* @required
*/
protected String encoding;
-
/**
* Un flag pour conserver un backup des fichiers modifies.
*
@@ -97,7 +97,6 @@
* @parameter expression="${license-switcher.force}" default-value="false"
*/
protected boolean force;
-
/**
* Fichier ou ecrire les licences des dependances.
*
@@ -195,4 +194,49 @@
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);
+ }
+ }
}
Modified: 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/codelutin/license/plugin/impl/LicensePlugin.java 2009-05-11 17:49:30 UTC (rev 1524)
+++ maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/plugin/impl/LicensePlugin.java 2009-05-11 19:54:46 UTC (rev 1525)
@@ -18,25 +18,23 @@
*/
package org.codelutin.license.plugin.impl;
-import org.apache.maven.plugin.MojoExecutionException;
import org.codelutin.license.License;
import org.codelutin.license.LicenseFactory;
import org.codelutin.license.plugin.AbstractLicensePlugin;
-import org.codelutin.util.FileUtil;
import java.io.File;
-import java.io.IOException;
/**
* Le goal pour ajouter le fichier LICENSE.txt dans le classpath (et le generer s'il n'existe pas).
*
* @author chemit
- * @goal license
+ * @goal add-license
* @phase generate-resources
* @requiresProject true
* @requiresDependencyResolution compile
*/
public class LicensePlugin extends AbstractLicensePlugin {
+
/**
* Fichier de la licence du module.
*
@@ -45,7 +43,6 @@
* @readonly
*/
protected File licenseFile;
-
/**
* Le type de license a appliquer.
*
@@ -53,14 +50,12 @@
* @required
*/
protected String licenseName;
-
/**
* La baseURL d'un resolver de license supplementaire
*
* @parameter expression="${license-switcher.extraResolver}"
*/
protected String[] extraResolver;
-
protected License license;
@Override
@@ -107,23 +102,28 @@
File backup = new File(licenseFile.getAbsolutePath() + "~");
licenseFile.renameTo(backup);
}
- try {
- FileUtil.writeString(licenseFile, license.getLicenseContent(encoding), encoding);
+// try {
+ String licenseContent = license.getLicenseContent(encoding);
- // copy LICENSE.txt to classpath
- File target = new File(outputDirectory, licenseFile.getName());
+ //FileUtil.writeString(licenseFile, licenseContent, encoding);
- try {
+ // copy LICENSE.txt to classpath
+ File target = new File(outputDirectory, licenseFile.getName());
- FileUtil.copy(licenseFile, target);
+// try {
- } catch (IOException e) {
- throw new MojoExecutionException("could not write file " + target + " for reason : " + e.getMessage(), e);
- }
+ copyFile(licenseContent, licenseFile, encoding);
- } catch (IOException e) {
- throw new MojoExecutionException("could not write license file " + licenseFile + " for reason : " + e.getMessage(), e);
- }
+ 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() {
Deleted: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/plugin/impl/SwitchLicensePlugin.java
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/plugin/impl/SwitchLicensePlugin.java 2009-05-11 17:49:30 UTC (rev 1524)
+++ maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/plugin/impl/SwitchLicensePlugin.java 2009-05-11 19:54:46 UTC (rev 1525)
@@ -1,339 +0,0 @@
-/**
- * *##% 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.codelutin.license.plugin.impl;
-
-import org.apache.maven.plugin.MojoExecutionException;
-import org.codehaus.plexus.util.DirectoryScanner;
-import org.codelutin.license.License;
-import org.codelutin.license.LicenseFactory;
-import org.codelutin.license.LicenseGenerator;
-import org.codelutin.license.plugin.AbstractLicensePlugin;
-import org.codelutin.processor.LicenseProcessor;
-import org.codelutin.processor.filters.LicenseFilter;
-import org.codelutin.util.FileUpdater;
-import org.codelutin.util.FileUpdaterHelper;
-import org.codelutin.util.FileUtil;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
-/**
- * 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 AbstractLicensePlugin {
-
- /**
- * l'annee de creation du module (sera place dans le header)
- *
- * @parameter default-value="${project.inceptionYear}"
- * @required
- */
- protected String inceptionYear;
-
- /**
- * le nom de l'organisation (sera place dans le header)
- *
- * @parameter default-value="${project.organization.name}"
- * @required
- * @readonly
- */
- protected String organizationName;
-
- /**
- * le nom du projet (sera place dans le header)
- *
- * @parameter default-value="${project.name}"
- * @required
- * @readonly
- */
- protected String projectName;
-
- /**
- * Le type de license a appliquer.
- *
- * @parameter expression="${license-switcher.licenseName}"
- * @required
- */
- protected String licenseName;
-
- /**
- * Repertoires des fichiers sources a traiter.
- *
- * @parameter expression="${license-switcher.compileSourceRoots}" default-value="${project.compileSourceRoots}"
- * @required
- */
- protected List<String> compileSourceRoots;
-
- /**
- * Repertoires des fichiers sources de test a traiter.
- *
- * @parameter expression="${license-switcher.testCompileSourceRoots}" default-value="${project.testCompileSourceRoots}"
- * @required
- */
- protected List<String> testCompileSourceRoots;
-
- /**
- * Repertoires du build des sources
- *
- * @parameter expression="${license-switcher.outputDirectory}" default-value="${project.build.outputDirectory}"
- * @required
- */
- protected File outputDirectory;
- /**
- * Repertoire du build des tests
- *
- * @parameter expression="${license-switcher.testOutputDirectory}" default-value="${project.build.testOutputDirectory}"
- * @required
- */
- protected File testOutputDirectory;
-
- /**
- * Un resolver externe
- *
- * @parameter expression="${license-switcher.extraResolver}"
- */
- protected String[] extraResolver;
-
- /** 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;
-
- @Override
- protected boolean shouldSkip() {
- return "pom".equals(project.getPackaging()) || "site".equals(project.getPackaging());
- }
-
- @Override
- protected 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() {
-
- // init directory scanner
- DirectoryScanner ds = new DirectoryScanner();
- ds.setIncludes(new String[]{"**\\/*.java"});
-
- Map<File, String[]> files = new java.util.HashMap<File, String[]>();
-
- getFilesToTreateForJavaRoots(ds, compileSourceRoots, outputDirectory, files);
-
- getFilesToTreateForJavaRoots(ds, testCompileSourceRoots, testOutputDirectory, files);
-
- return files;
- }
-
- protected void getFilesToTreateForJavaRoots(DirectoryScanner ds, List<String> roots, File dstRoot, Map<File, String[]> files) {
-
- for (String src : roots) {
-
- File f = new File(src);
- if (!f.exists()) {
- // do nothing on a non-existent
- continue;
- }
-
- if (verbose) {
- getLog().info("discovering java source files in root " + src);
- }
-
- ds.setBasedir(f);
- // scan
- ds.scan();
-
- // get files
- String[] tmp = ds.getIncludedFiles();
-
- if (tmp.length < 1) {
- // no files found
- continue;
- }
-
- FileUpdater updater = FileUpdaterHelper.newJavaFileUpdater(f, dstRoot);
- List<String> toTreate = new ArrayList<String>();
-
- for (String filePath : tmp) {
- File srcFile = new File(f, filePath);
- // check file is up-to-date
- if (!updater.isFileUpToDate(srcFile)) {
- toTreate.add(filePath);
- }
- }
-
- if (toTreate.isEmpty()) {
- // no file or all are up-to-date
- continue;
- }
-
- // register files
- files.put(f, toTreate.toArray(new String[toTreate.size()]));
-
- }
- }
-
- 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 java.io.IOException 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);
- }
-
-}
Modified: 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/codelutin/license/plugin/impl/ThirdPartyPlugin.java 2009-05-11 17:49:30 UTC (rev 1524)
+++ maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/plugin/impl/ThirdPartyPlugin.java 2009-05-11 19:54:46 UTC (rev 1525)
@@ -26,7 +26,6 @@
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.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.ProjectBuildingException;
@@ -34,10 +33,8 @@
import org.apache.maven.shared.dependency.tree.DependencyTreeBuilder;
import org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException;
import org.codelutin.license.plugin.AbstractLicensePlugin;
-import org.codelutin.util.FileUtil;
import java.io.File;
-import java.io.IOException;
import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;
@@ -47,7 +44,7 @@
* dans le classpath (et le generer s'il n'existe pas).
*
* @author chemit
- * @goal third-party
+ * @goal add-third-party
* @phase process-classes
* @requiresDependencyResolution test
* @requiresProject true
@@ -55,7 +52,6 @@
public class ThirdPartyPlugin extends AbstractLicensePlugin {
private static final String unknownLicenseMessage = "Unknown license";
-
/**
* Local Repository.
*
@@ -64,8 +60,6 @@
* @readonly
*/
protected ArtifactRepository localRepository;
-
-
/**
* Remote repositories used for the project.
*
@@ -73,8 +67,7 @@
* @required
* @readonly
*/
- protected List remoteRepositories;
-
+ protected List<?> remoteRepositories;
/**
* Fichier ou ecrire les licences des dependances.
*
@@ -82,42 +75,36 @@
* @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.
@@ -128,7 +115,7 @@
protected boolean shouldSkip() {
return "pom".equals(project.getPackaging()) || "site".equals(project.getPackaging());
}
-
+
@Override
protected boolean init() throws Exception {
@@ -178,11 +165,12 @@
}
thirdPartyFile.renameTo(new File(thirdPartyFile.getAbsolutePath() + '~'));
}
- try {
- FileUtil.writeString(thirdPartyFile, thirdPartyFileContent, encoding);
- } catch (IOException e) {
- throw new MojoExecutionException("could not write file " + thirdPartyFile + " for reason : " + e.getMessage(), e);
- }
+ 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 */
@@ -191,8 +179,7 @@
ArtifactFilter artifactFilter = new ScopeArtifactFilter(Artifact.SCOPE_TEST);
return dependencyTreeBuilder.buildDependencyTree(project, localRepository, factory,
artifactMetadataSource, artifactFilter, collector);
- }
- catch (DependencyTreeBuilderException e) {
+ } catch (DependencyTreeBuilderException e) {
getLog().error("Unable to build dependency tree.", e);
return null;
}
@@ -217,7 +204,7 @@
MavenProject artifactProject = getMavenProjectFromRepository(artifact);
String artifactName = getArtifactName(artifactProject);
- List licenses = artifactProject.getLicenses();
+ List<?> licenses = artifactProject.getLicenses();
if (licenses.isEmpty()) {
// no license found for the dependency
@@ -237,8 +224,7 @@
licenseMap.put(licenseKey, artifactName);
}
}
- }
- catch (ProjectBuildingException e) {
+ } catch (ProjectBuildingException e) {
getLog().error("ProjectBuildingException error : ", e);
}
}
@@ -306,9 +292,9 @@
}
protected class LicenseMap extends java.util.TreeMap<String, SortedSet<String>> {
+
private static final long serialVersionUID = 864199843545688069L;
- /** {@inheritDoc} */
public SortedSet<String> put(String key, String value) {
// handle multiple values as a set to avoid duplicates
SortedSet<String> valueList = get(key);
Modified: maven-nuiton-project-helper-plugin/trunk/src/site/site.xml
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/site/site.xml 2009-05-11 17:49:30 UTC (rev 1524)
+++ maven-nuiton-project-helper-plugin/trunk/src/site/site.xml 2009-05-11 19:54:46 UTC (rev 1525)
@@ -21,9 +21,9 @@
<poweredBy>
<logo href="http://maven.apache.org" name="Maven" img="images/logos/maven-feather.png"/>
- <logo href="http://jrst.labs.libre-entreprise.org" name="JRst" img="images/jrst-logo.png"/>
+ <!--logo href="http://jrst.labs.libre-entreprise.org" name="JRst" img="images/jrst-logo.png"/>
<logo href="http://docutils.sourceforge.net/rst.html" name="ReStructuredText"
- img="images/restructuredtext-logo.png"/>
+ img="images/restructuredtext-logo.png"/-->
</poweredBy>
<body>
@@ -35,29 +35,31 @@
<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="switch" href="switch-mojo.html"/>
+ <item name="add-license" href="add-license-mojo.html"/>
+ <item name="add-third-party" href="add-third-party-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"/>
+ <!--item name="Usage" href="usage.html"/>
+ <item name="FAQ" href="faq.html"/-->
</menu>
- <menu name="Examples">
+
+ <!--menu name="Examples">
<item name="Todo" href="Todo.html"/>
- </menu>
+ </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="${labs.builder.url}/org/codelutin/${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"
+ name="Javadoc (jar)"/>
+ <item href="${labs.builder.url}/org/codelutin/${project.artifactId}/${project.version}/${project.build.finalName}-sources.jar"
+ name="Sources (jar)"/>
</menu>
- <menu name="Développeur">
+ <!--menu name="Développeur">
<item name="A faire" href="Todo.html"/>
- </menu>
+ </menu-->
<menu ref="reports"/>
Modified: 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 17:49:30 UTC (rev 1524)
+++ maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/BaseLicenseTestCase.java 2009-05-11 19:54:46 UTC (rev 1525)
@@ -1,10 +1,15 @@
package org.codelutin.license;
-import org.codelutin.util.FileUtil;
+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 {
@@ -45,16 +50,30 @@
String content = "";
if (defFile.exists()) {
- content = FileUtil.readAsString(defFile, encoding) + "\n";
+
+ content = IOUtil.toString(new FileInputStream(defFile), encoding) + "\n";
+// content = FileUtil.readAsString(defFile, encoding) + "\n";
}
- FileUtil.writeString(defFile, content + licenseName + "=My dummy license\n", encoding);
+
+ 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();
- FileUtil.writeString(new File(file, "license.txt"), "license:" + licenseName, encoding);
- FileUtil.writeString(new File(file, "header.txt"), "header:" + licenseName, encoding);
+ 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/JavaLicenseGeneratorTest.java
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/JavaLicenseGeneratorTest.java 2009-05-11 17:49:30 UTC (rev 1524)
+++ maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/JavaLicenseGeneratorTest.java 2009-05-11 19:54:46 UTC (rev 1525)
@@ -1,24 +0,0 @@
-package org.codelutin.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
- }
-}
Deleted: maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/XmlLicenseGeneratorTest.java
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/XmlLicenseGeneratorTest.java 2009-05-11 17:49:30 UTC (rev 1524)
+++ maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/XmlLicenseGeneratorTest.java 2009-05-11 19:54:46 UTC (rev 1525)
@@ -1,23 +0,0 @@
-package org.codelutin.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
- }
-}
Modified: 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/codelutin/license/plugin/BasePluginTestCase.java 2009-05-11 17:49:30 UTC (rev 1524)
+++ maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/plugin/BasePluginTestCase.java 2009-05-11 19:54:46 UTC (rev 1525)
@@ -42,7 +42,8 @@
String rep = klass.getName();
rep = rep.replaceAll("\\.", File.separator);
- File f = new File(getBaseDir(), "src" + File.separator + "test" + File.separator + "resources");
+ 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);
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 17:49:30 UTC (rev 1524)
+++ maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/plugin/impl/LicensePluginTest.java 2009-05-11 19:54:46 UTC (rev 1525)
@@ -43,11 +43,16 @@
}
@Test
- @PluginConfig(pomName = "testOne.xml", goalName = "license")
+ @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();
}
Modified: maven-nuiton-project-helper-plugin/trunk/src/test/resources/org/codelutin/license/plugin/impl/LicensePluginTest/testOne.xml
===================================================================
--- maven-nuiton-project-helper-plugin/trunk/src/test/resources/org/codelutin/license/plugin/impl/LicensePluginTest/testOne.xml 2009-05-11 17:49:30 UTC (rev 1524)
+++ maven-nuiton-project-helper-plugin/trunk/src/test/resources/org/codelutin/license/plugin/impl/LicensePluginTest/testOne.xml 2009-05-11 19:54:46 UTC (rev 1525)
@@ -2,28 +2,29 @@
<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">
- <parent>
- <groupId>org.codelutin</groupId>
- <artifactId>lutinproject</artifactId>
- <version>3.3</version>
- </parent>
+
+ <groupId>org.nuiton</groupId>
+ <artifactId>maven-nuiton-project-helper-plugin-testOne</artifactId>
+ <version>0</version>
+
<build>
<plugins>
<plugin>
- <groupId>org.codelutin</groupId>
- <artifactId>maven-license-switcher-plugin</artifactId>
+ <groupId>org.nuiton</groupId>
+ <artifactId>maven-nuiton-project-helper-plugin</artifactId>
<configuration>
- <encoding>UTF-8</encoding>
+ <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>license</goal>
+ <goal>add-license</goal>
</goals>
</execution>
</executions>
1
0
[Lutinutil-commits] r1524 - maven-nuiton-project-helper-plugin
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 17:49:30 +0000 (Mon, 11 May 2009)
New Revision: 1524
Added:
maven-nuiton-project-helper-plugin/trunk/
Log:
create new project helper plugin neutral from our libraries
Copied: maven-nuiton-project-helper-plugin/trunk (from rev 1523, maven-license-switcher-plugin/trunk)
1
0
Author: tchemit
Date: 2009-05-11 17:48:58 +0000 (Mon, 11 May 2009)
New Revision: 1523
Added:
maven-nuiton-project-helper-plugin/
Log:
create new project helper plugin neutral from our libraries
1
0