[Lutinutil-commits] r1212 - in maven-license-switcher-plugin/tags: . 0.4 0.4/src/main/java/org/codelutin/license/plugin 0.4/src/site
Author: tchemit Date: 2008-10-13 20:28:18 +0000 (Mon, 13 Oct 2008) New Revision: 1212 Added: maven-license-switcher-plugin/tags/0.4/ maven-license-switcher-plugin/tags/0.4/changelog maven-license-switcher-plugin/tags/0.4/pom.xml maven-license-switcher-plugin/tags/0.4/src/main/java/org/codelutin/license/plugin/ThirdPartyMojo.java maven-license-switcher-plugin/tags/0.4/src/site/site.xml Removed: maven-license-switcher-plugin/tags/0.4/changelog maven-license-switcher-plugin/tags/0.4/pom.xml maven-license-switcher-plugin/tags/0.4/src/main/java/org/codelutin/license/plugin/ThirdPartyMojo.java maven-license-switcher-plugin/tags/0.4/src/site/site.xml Log: [maven-release-plugin] copy for tag 0.4 Copied: maven-license-switcher-plugin/tags/0.4 (from rev 1201, maven-license-switcher-plugin/trunk) Deleted: maven-license-switcher-plugin/tags/0.4/changelog =================================================================== --- maven-license-switcher-plugin/trunk/changelog 2008-10-13 19:01:56 UTC (rev 1201) +++ maven-license-switcher-plugin/tags/0.4/changelog 2008-10-13 20:28:18 UTC (rev 1212) @@ -1,4 +0,0 @@ -ver-0-8-2 thimel 20080922 - * 20081013 [chemit] Improve licence resolving - * 20080922 [thimel] Modified version of jrst and plugin's groupId - * 20080922 [chemit] Using lutinpluginproject 3.0 Copied: maven-license-switcher-plugin/tags/0.4/changelog (from rev 1204, maven-license-switcher-plugin/trunk/changelog) =================================================================== --- maven-license-switcher-plugin/tags/0.4/changelog (rev 0) +++ maven-license-switcher-plugin/tags/0.4/changelog 2008-10-13 20:28:18 UTC (rev 1212) @@ -0,0 +1,7 @@ +ver-0-4 chemit 20081013 + * 20081013 [chemit] Improve third-party goal : onyl keep included dependencies + +ver-0-3 chemit 20081013 + * 20081013 [chemit] Improve licence resolving + * 20080922 [thimel] Modified version of jrst and plugin's groupId + * 20080922 [chemit] Using lutinpluginproject 3.0 Deleted: maven-license-switcher-plugin/tags/0.4/pom.xml =================================================================== --- maven-license-switcher-plugin/trunk/pom.xml 2008-10-13 19:01:56 UTC (rev 1201) +++ maven-license-switcher-plugin/tags/0.4/pom.xml 2008-10-13 20:28:18 UTC (rev 1212) @@ -1,105 +0,0 @@ -<?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"> - - <modelVersion>4.0.0</modelVersion> - - <!-- ************************************************************* --> - <!-- *** POM Relationships *************************************** --> - <!-- ************************************************************* --> - <parent> - <groupId>org.codelutin</groupId> - <artifactId>lutinpluginproject</artifactId> - <version>3.0</version> - </parent> - - <!--groupId>org.codelutin</groupId--> - <artifactId>maven-license-switcher-plugin</artifactId> - - <dependencies> - - <dependency> - <groupId>org.apache.maven.shared</groupId> - <artifactId>maven-dependency-tree</artifactId> - <version>1.1</version> - </dependency> - - <dependency> - <groupId>org.codelutin</groupId> - <artifactId>lutinprocessor</artifactId> - <version>0.15</version> - <scope>compile</scope> - </dependency> - - <dependency> - <groupId>org.codelutin</groupId> - <artifactId>lutinpluginutil</artifactId> - <version>0.2</version> - <scope>compile</scope> - </dependency> - - </dependencies> - - <!-- ************************************************************* --> - <!-- *** Project Information ************************************* --> - <!-- ************************************************************* --> - <name>Plugin maven pour switcher les licenses</name> - <version>0.4-SNAPSHOT</version> - <description>Plugin pour switcher de license dans un module maven 2</description> - <inceptionYear>2008</inceptionYear> - - <!-- ************************************************************* --> - <!-- *** Build Settings ****************************************** --> - <!-- ************************************************************* --> - - <packaging>maven-plugin</packaging> - - <build> - <plugins> - <plugin> - <artifactId>maven-antrun-plugin</artifactId> - <executions> - <!--Copy licenses files for site--> - <execution> - <id>CopySiteFiles2</id> - <phase>pre-site</phase> - <configuration> - <tasks> - <mkdir dir="${maven.site.gen.dir}/resources" /> - <copy todir="${maven.site.gen.dir}/resources" verbose="${maven.verbose}" overwrite="false"> - <fileset dir="${maven.src.dir}/main/resources/META-INF"> - <include name="licenses/**" /> - </fileset> - </copy> - </tasks> - </configuration> - <goals> - <goal>run</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - </build> - - <properties> - - <!-- id du projet du labs --> - <labs.id>12</labs.id> - - <!-- nom du projet sur le labs --> - <labs.project>lutinutil</labs.project> - - </properties> - - <!-- ************************************************************* --> - <!-- *** Build Environment ************************************** --> - <!-- ************************************************************* --> - - <!--Source control management--> - <scm> - <connection>scm:svn:svn://anonymous@labs.libre-entreprise.org/svnroot/lutinutil/maven-license-switcher-plugin/tags/0.3</connection> - <developerConnection>scm:svn:svn+ssh://tchemit@labs.libre-entreprise.org/svnroot/lutinutil/maven-license-switcher-plugin/tags/0.3</developerConnection> - <url>http://labs.libre-entreprise.org/plugins/scmsvn/viewcvs.php/maven-license-switcher-plugin/tags/0.3?root=lutinutil</url> - </scm> - -</project> Copied: maven-license-switcher-plugin/tags/0.4/pom.xml (from rev 1211, maven-license-switcher-plugin/trunk/pom.xml) =================================================================== --- maven-license-switcher-plugin/tags/0.4/pom.xml (rev 0) +++ maven-license-switcher-plugin/tags/0.4/pom.xml 2008-10-13 20:28:18 UTC (rev 1212) @@ -0,0 +1,104 @@ +<?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"> + + <modelVersion>4.0.0</modelVersion> + + <!-- ************************************************************* --> + <!-- *** POM Relationships *************************************** --> + <!-- ************************************************************* --> + <parent> + <groupId>org.codelutin</groupId> + <artifactId>lutinpluginproject</artifactId> + <version>3.0</version> + </parent> + + <artifactId>maven-license-switcher-plugin</artifactId> + + <dependencies> + + <dependency> + <groupId>org.apache.maven.shared</groupId> + <artifactId>maven-dependency-tree</artifactId> + <version>1.1</version> + </dependency> + + <dependency> + <groupId>org.codelutin</groupId> + <artifactId>lutinprocessor</artifactId> + <version>0.15</version> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>org.codelutin</groupId> + <artifactId>lutinpluginutil</artifactId> + <version>0.2</version> + <scope>compile</scope> + </dependency> + + </dependencies> + + <!-- ************************************************************* --> + <!-- *** Project Information ************************************* --> + <!-- ************************************************************* --> + <name>Plugin maven pour switcher les licenses</name> + <version>0.4</version> + <description>Plugin pour switcher de license dans un module maven 2</description> + <inceptionYear>2008</inceptionYear> + + <!-- ************************************************************* --> + <!-- *** Build Settings ****************************************** --> + <!-- ************************************************************* --> + + <packaging>maven-plugin</packaging> + + <build> + <plugins> + <plugin> + <artifactId>maven-antrun-plugin</artifactId> + <executions> + <!--Copy licenses files for site--> + <execution> + <id>CopySiteFiles2</id> + <phase>pre-site</phase> + <configuration> + <tasks> + <mkdir dir="${maven.site.gen.dir}/resources" /> + <copy todir="${maven.site.gen.dir}/resources" verbose="${maven.verbose}" overwrite="false"> + <fileset dir="${maven.src.dir}/main/resources/META-INF"> + <include name="licenses/**" /> + </fileset> + </copy> + </tasks> + </configuration> + <goals> + <goal>run</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + + <properties> + + <!-- id du projet du labs --> + <labs.id>12</labs.id> + + <!-- nom du projet sur le labs --> + <labs.project>lutinutil</labs.project> + + </properties> + + <!-- ************************************************************* --> + <!-- *** Build Environment ************************************** --> + <!-- ************************************************************* --> + + <!--Source control management--> + <scm> + <connection>scm:svn:svn://anonymous@labs.libre-entreprise.org/svnroot/lutinutil/maven-license-switcher-plugin/tags/0.4</connection> + <developerConnection>scm:svn:svn+ssh://tchemit@labs.libre-entreprise.org/svnroot/lutinutil/maven-license-switcher-plugin/tags/0.4</developerConnection> + <url>http://labs.libre-entreprise.org/plugins/scmsvn/viewcvs.php/maven-license-switcher-plugin/tags/0.4?root=lutinutil</url> + </scm> + +</project> Deleted: maven-license-switcher-plugin/tags/0.4/src/main/java/org/codelutin/license/plugin/ThirdPartyMojo.java =================================================================== --- maven-license-switcher-plugin/trunk/src/main/java/org/codelutin/license/plugin/ThirdPartyMojo.java 2008-10-13 19:01:56 UTC (rev 1201) +++ maven-license-switcher-plugin/tags/0.4/src/main/java/org/codelutin/license/plugin/ThirdPartyMojo.java 2008-10-13 20:28:18 UTC (rev 1212) @@ -1,300 +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; - -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.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; -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.codelutin.util.FileUtil; - -import java.io.File; -import java.io.IOException; -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 third-party - * @phase process-classes - * @requiresDependencyResolution test - * @requiresProject true - */ -public class ThirdPartyMojo extends AbstractLicenseMojo { - - 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; - - /** - * Un flag pour indiquer la regeneration des fichiers. - * - * @parameter expression="${license-switcher.doGenerate}" default-value="true" - */ - protected boolean doGenerate; - /** - * content of third party file (only computed if {@link #doGenerate} is active or the - * {@link #thirdPartyFile} does not exist. - */ - protected String thirdPartyFileContent; - - protected void init() throws Exception { - - // must generate if file does not exist - doGenerate = doGenerate || !thirdPartyFile.exists(); - - if (doGenerate) { - - // prepare thirdPartyFileContent - - DependencyNode dependencyTreeNode = resolveProject(); - - LicenseMap licenseMap = new LicenseMap(); - - for (Object o : dependencyTreeNode.getChildren()) { - - buildLicenseMap((DependencyNode) o, licenseMap); - } - - thirdPartyFileContent = buildGroupedLicenses(licenseMap); - } - } - - @Override - public void execute() throws MojoExecutionException, MojoFailureException { - - super.execute(); - - if (doGenerate) { - 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() + '~')); - } - 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) { - - Artifact artifact = node.getArtifact(); - - 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 - getLog().warn("no license found for dependency " + artifactName); - - licenseMap.put(unknownLicenseMessage, artifactName); - - } else { - for (Object license : licenses) { - licenseMap.put(((License) license).getName(), 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; - - /** {@inheritDoc} */ - 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); - } - } -} Copied: maven-license-switcher-plugin/tags/0.4/src/main/java/org/codelutin/license/plugin/ThirdPartyMojo.java (from rev 1204, maven-license-switcher-plugin/trunk/src/main/java/org/codelutin/license/plugin/ThirdPartyMojo.java) =================================================================== --- maven-license-switcher-plugin/tags/0.4/src/main/java/org/codelutin/license/plugin/ThirdPartyMojo.java (rev 0) +++ maven-license-switcher-plugin/tags/0.4/src/main/java/org/codelutin/license/plugin/ThirdPartyMojo.java 2008-10-13 20:28:18 UTC (rev 1212) @@ -0,0 +1,317 @@ +/** + * *##% 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; + +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.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +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.codelutin.util.FileUtil; + +import java.io.File; +import java.io.IOException; +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 third-party + * @phase process-classes + * @requiresDependencyResolution test + * @requiresProject true + */ +public class ThirdPartyMojo extends AbstractLicenseMojo { + + 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; + + /** + * Un flag pour indiquer la regeneration des fichiers. + * + * @parameter expression="${license-switcher.doGenerate}" default-value="true" + */ + protected boolean doGenerate; + /** + * content of third party file (only computed if {@link #doGenerate} is active or the + * {@link #thirdPartyFile} does not exist. + */ + protected String thirdPartyFileContent; + + protected void init() throws Exception { + + // must generate if file does not exist + doGenerate = doGenerate || !thirdPartyFile.exists(); + + 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); + } + } + } + } + + @Override + public void execute() throws MojoExecutionException, MojoFailureException { + + super.execute(); + + if (doGenerate) { + 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() + '~')); + } + 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 license : licenses) { + licenseMap.put(((License) license).getName(), 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; + + /** {@inheritDoc} */ + 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); + } + } +} Deleted: maven-license-switcher-plugin/tags/0.4/src/site/site.xml =================================================================== --- maven-license-switcher-plugin/trunk/src/site/site.xml 2008-10-13 19:01:56 UTC (rev 1201) +++ maven-license-switcher-plugin/tags/0.4/src/site/site.xml 2008-10-13 20:28:18 UTC (rev 1212) @@ -1,64 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project name="${project.name}"> - - <publishDate format="dd/MM/yyyy"/> - - <skin> - <groupId>org.codelutin</groupId> - <artifactId>maven-lutin-skin</artifactId> - <version>0.2</version> - </skin> - - <bannerLeft> - <name>${project.name}</name> - </bannerLeft> - - <bannerRight> - <src>http://www.codelutin.com/images/lutinorange-codelutin.png</src> - <href>${project.organization.url}</href> - </bannerRight> - - <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://docutils.sourceforge.net/rst.html" name="ReStructuredText" - img="images/restructuredtext-logo.png"/> - </poweredBy> - - <body> - <links> - <item name="Labs" href="http://labs.libre-entreprise.org"/> - <item name="${project.organization.name}" href="${project.organization.url}"/> - </links> - - <menu name="Utilisateur"> - <item name="Introduction" href="index.html"/> - <item name="Goals" href="plugin-info.html"> - <item name="license" href="license-mojo.html"/> - <item name="third-party" href="third-party-mojo.html"/> - <item name="switch" href="switch-mojo.html"/> - <item name="available-licenses" href="available-licenses-mojo.html"/> - <item name="help" href="help-mojo.html"/> - </item> - <item name="Usage" href="usage.html"/> - <item name="FAQ" href="faq.html"/> - </menu> - <menu name="Examples"> - <item name="Todo" href="Todo.html"/> - </menu> - - <menu name="Téléchargement"> - <item href="${labs.builder.url}/org/codelutin/${project.artifactId}/${project.version}" - name="Télécharger la dernière version"/> - <item href="${labs.builder.url}/org/codelutin/${project.artifactId}" - name="Voir toutes les versions"/> - </menu> - - <menu name="Développeur"> - <item name="A faire" href="Todo.html"/> - </menu> - - <menu ref="reports"/> - - </body> -</project> Copied: maven-license-switcher-plugin/tags/0.4/src/site/site.xml (from rev 1208, maven-license-switcher-plugin/trunk/src/site/site.xml) =================================================================== --- maven-license-switcher-plugin/tags/0.4/src/site/site.xml (rev 0) +++ maven-license-switcher-plugin/tags/0.4/src/site/site.xml 2008-10-13 20:28:18 UTC (rev 1212) @@ -0,0 +1,64 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project name="${project.name}"> + + <publishDate format="dd/MM/yyyy"/> + + <skin> + <groupId>org.codelutin</groupId> + <artifactId>maven-lutin-skin</artifactId> + <version>0.2.1</version> + </skin> + + <bannerLeft> + <name>${project.name}</name> + </bannerLeft> + + <bannerRight> + <src>http://www.codelutin.com/images/lutinorange-codelutin.png</src> + <href>${project.organization.url}</href> + </bannerRight> + + <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://docutils.sourceforge.net/rst.html" name="ReStructuredText" + img="images/restructuredtext-logo.png"/> + </poweredBy> + + <body> + <links> + <item name="Labs" href="http://labs.libre-entreprise.org"/> + <item name="${project.organization.name}" href="${project.organization.url}"/> + </links> + + <menu name="Utilisateur"> + <item name="Introduction" href="index.html"/> + <item name="Goals" href="plugin-info.html"> + <item name="license" href="license-mojo.html"/> + <item name="third-party" href="third-party-mojo.html"/> + <item name="switch" href="switch-mojo.html"/> + <item name="available-licenses" href="available-licenses-mojo.html"/> + <item name="help" href="help-mojo.html"/> + </item> + <item name="Usage" href="usage.html"/> + <item name="FAQ" href="faq.html"/> + </menu> + <menu name="Examples"> + <item name="Todo" href="Todo.html"/> + </menu> + + <menu name="Téléchargement"> + <item href="${labs.builder.url}/org/codelutin/${project.artifactId}/${project.version}" + name="Télécharger la dernière version"/> + <item href="${labs.builder.url}/org/codelutin/${project.artifactId}" + name="Voir toutes les versions"/> + </menu> + + <menu name="Développeur"> + <item name="A faire" href="Todo.html"/> + </menu> + + <menu ref="reports"/> + + </body> +</project>
participants (1)
-
tchemit@users.labs.libre-entreprise.org