Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
srdo committed Jan 2, 2019
1 parent 2b1dc5f commit 1a2c735
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -562,10 +562,32 @@ public abstract class AbstractAddThirdPartyMojo
*/
private Map<String, String> globalKnownLicenses;

boolean isAggregatorBuild;
/**
* Whether this is an aggregate build, or a single-project goal. This setting determines which dependency artifacts
* will be examined by the plugin. AddThirdParty needs to load dependencies only for the single project it is run
* for, while AggregateAddThirdParty needs to load dependencies for the parent project, as well as all child
* projects in the reactor.
*/
boolean isAggregatorBuild = false;

/**
* Map from reactor project G/A to direct dependencies. When loading dependencies, the aggregator goal replaces all
* reactor projects with their direct dependencies, to avoid trying to load artifacts for projects that haven't been
* built/published yet. This field is used to keep track of which dependencies are also projects in the reactor.
*/
Map<String, List<Dependency>> reactorProjectDependencies;

/**
* Copies of the project's dependency sets. AddThirdParty needs to load dependencies only for the single project it
* is run for, while AggregateAddThirdParty needs to load dependencies for the parent project, as well as all child
* projects in the reactor.
*
* The aggregator goal replaces all reactor projects with their direct dependencies, to avoid trying to load
* artifacts for projects that haven't been built/published yet. This is necessary in cases where one child project
* A in a reactor depends on another project B in the same reactor. Since B is not necessarily built/published, the
* plugin needs to replace B with its dependencies when processing A. This field stores that modified view of the
* project's dependencies.
*/
LoadedProjectDependencies dependencyArtifacts;

// ----------------------------------------------------------------------
Expand Down Expand Up @@ -643,10 +665,10 @@ protected void init()
doGenerateBundle = false;
}

if (isAggregatorBuild) {
if ( isAggregatorBuild ) {
dependencyArtifacts = dependenciesTool.loadProjectArtifacts( localRepository, remoteRepositories, project, reactorProjectDependencies );
} else {
dependencyArtifacts = new LoadedProjectDependencies(project.getArtifacts(), project.getDependencyArtifacts());
dependencyArtifacts = new LoadedProjectDependencies( project.getArtifacts(), project.getDependencyArtifacts() );
}

projectDependencies = loadDependencies();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ protected MavenProject getProject()
protected SortedMap<String, MavenProject> getDependencies( MavenProject project )
{
return dependenciesTool.loadProjectDependencies(
new LoadedProjectDependencies(project.getArtifacts(), project.getDependencyArtifacts()),
new LoadedProjectDependencies( project.getArtifacts(), project.getDependencyArtifacts() ),
this, localRepository, remoteRepositories, null );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ protected void init() throws Exception {
isAggregatorBuild = true;
reactorProjectDependencies = new TreeMap<>();
for (MavenProject reactorProject : this.reactorProjects) {
reactorProjectDependencies.put(String.format("%s:%s", reactorProject.getGroupId(), reactorProject.getArtifactId()), reactorProject.getDependencies());
reactorProjectDependencies.put( String.format( "%s:%s", reactorProject.getGroupId(), reactorProject.getArtifactId() ), reactorProject.getDependencies() );
}
super.init();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -137,12 +136,12 @@ public SortedMap<String, MavenProject> loadProjectDependencies( LoadedProjectDep
if ( configuration.isIncludeTransitiveDependencies() )
{
// All project dependencies
depArtifacts = Collections.unmodifiableSet(artifacts.getAllDependencies());
depArtifacts = artifacts.getAllDependencies();
}
else
{
// Only direct project dependencies
depArtifacts = Collections.unmodifiableSet(artifacts.getDirectDependencies());
depArtifacts = artifacts.getDirectDependencies();
}

List<String> includedScopes = configuration.getIncludedScopes();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,63 @@

package org.codehaus.mojo.license.api;

import edu.emory.mathcs.backport.java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import org.apache.maven.artifact.Artifact;

/*
* #%L
* License Maven Plugin
* %%
* Copyright (C) 2008 - 2012 CodeLutin, Codehaus, 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%
*/

/**
* Copies of the project's dependency sets. AddThirdParty needs to load dependencies only for the single project it is
* run for, while AggregateAddThirdParty needs to load dependencies for the parent project, as well as all child
* projects in the reactor.
*
* The aggregator goal replaces all reactor projects with their direct dependencies, to avoid trying to load artifacts
* for projects that haven't been built/published yet. This is necessary in cases where one child project A in a reactor
* depends on another project B in the same reactor. Since B is not necessarily built/published, the plugin needs to
* replace B with its dependencies when processing A. This field stores that modified view of the project's
* dependencies.
*/
public class LoadedProjectDependencies {

private final Set<Artifact> allDependencies;
private final Set<Artifact> directDependencies;

public LoadedProjectDependencies( Set<Artifact> allDependencies, Set<Artifact> directDependencies )
{
this.allDependencies = allDependencies;
this.directDependencies = directDependencies;
this.allDependencies = new HashSet<>( allDependencies );
this.directDependencies = new HashSet<>( directDependencies );
}

public Set<Artifact> getAllDependencies()
{
return allDependencies;
return Collections.unmodifiableSet( allDependencies );
}

public Set<Artifact> getDirectDependencies()
{
return directDependencies;
return Collections.unmodifiableSet( directDependencies );
}

}

0 comments on commit 1a2c735

Please sign in to comment.