Skip to content

Commit

Permalink
Fix #413 Use 'GAV' for result keys in LicensedArtifactResolver (#414)
Browse files Browse the repository at this point in the history
Fixes #413

In the result mapping we need to use "GAV" to be compatible with
the other classes in the plugin. While the exclude/includeArtifacts
should still use the Artifact#getId, since the getDependencyTrail
also uses that format, which is considered when we exclude all the
transitive deps of excluded artifacts.

Note that the added it is based on the already existing
download-licenses-include-exclude-types, but with a small change
in the settings to use excludeTransitiveDependencies instead.

---------

Co-authored-by: Attila Puskas <attila.puskas@casrd.net>
Co-authored-by: Slawomir Jaranowski <s.jaranowski@gmail.com>
  • Loading branch information
3 people committed Jul 2, 2023
1 parent d5d48c4 commit a86c98e
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 2 deletions.
@@ -0,0 +1 @@
invoker.goals = clean validate -X
54 changes: 54 additions & 0 deletions src/it/download-licenses-exclude-transitive-deps/pom.xml
@@ -0,0 +1,54 @@
<?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>

<groupId>org.codehaus.mojo.license</groupId>
<artifactId>it-test</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Integration Test</name>
<url>http://maven.apache.org</url>
<description>
Check default execution.
</description>

<dependencies>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-ejb-client-bom</artifactId>
<type>pom</type>
<version>9.0.1.Final</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>license-maven-plugin</artifactId>
<version>@pom.version@</version>
<executions>
<execution>
<id>exclude-pom</id>
<goals>
<goal>download-licenses</goal>
</goals>
<phase>validate</phase>
<configuration>
<excludeTransitiveDependencies>true</excludeTransitiveDependencies>
<excludedTypes>pom</excludedTypes>
<licensesOutputDirectory>${project.build.directory}/generated-resources/licenses</licensesOutputDirectory>
<licensesOutputFile>${project.build.directory}/generated-resources/licenses.xml</licensesOutputFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
51 changes: 51 additions & 0 deletions src/it/download-licenses-exclude-transitive-deps/postbuild.groovy
@@ -0,0 +1,51 @@
/*
* #%L
* License Maven Plugin
* %%
* Copyright (C) 2008 - 2011 CodeLutin, Codehaus, Tony Chemit, Tony chemit
* %%
* 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>.
* #L%
*/
def assertExistsFile(file)
{
if ( !file.exists() || file.isDirectory() )
{
println(file.getAbsolutePath() + " file is missing or a directory.")
assert false
}
assert true
}

def assertNotExistsFile(file)
{
if ( file.exists() )
{
println(file.getAbsolutePath() + " file should not exists.")
assert false
}
assert true
}

file = new File(basedir, 'target/generated-resources/licenses/eclipse public license 1.0 - epl-v10.html');
assertExistsFile(file);

file = new File(basedir, 'target/generated-resources/licenses/lgpl - lgpl-2.1.txt');
assertNotExistsFile(file);

file = new File(basedir, 'target/generated-resources/licenses.xml');
assertExistsFile(file);

return true;
@@ -0,0 +1,15 @@
package org.codehaus.mojo;

public class HelloWorld
{

/**
* @param args
*/
public static void main( String[] args )
{
// TODO Auto-generated method stub

}

}
Expand Up @@ -46,6 +46,7 @@
import org.codehaus.mojo.license.api.MavenProjectDependenciesConfigurator;
import org.codehaus.mojo.license.api.ResolvedProjectDependencies;
import org.codehaus.mojo.license.download.LicensedArtifact.Builder;
import org.codehaus.mojo.license.utils.MojoHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -132,7 +133,7 @@ public void loadProjectDependencies(
continue;
}

final String id = artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion();
final String id = MojoHelper.getArtifactId(artifact);

if (verbose) {
LOG.info("detected artifact {}", id);
Expand Down Expand Up @@ -193,7 +194,7 @@ public void loadProjectDependencies(
}

if (remove) {
result.remove(entry.getKey());
result.remove(MojoHelper.getArtifactId(entry.getValue()));
}
}
}
Expand Down

0 comments on commit a86c98e

Please sign in to comment.