From ea43fa6ae8b0504d12d794fdb6ff83e995f6a41a Mon Sep 17 00:00:00 2001
From: Michael Osipov
Date: Sat, 26 Nov 2022 22:26:37 +0100
Subject: [PATCH 1/9] [maven-release-plugin] prepare for next development
iteration
---
pom.xml | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/pom.xml b/pom.xml
index a21461262..dc320c1a0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -30,7 +30,7 @@ under the License.
maven-dependency-plugin
- 3.4.0
+ 3.4.1-SNAPSHOT
maven-plugin
Apache Maven Dependency Plugin
@@ -44,7 +44,7 @@ under the License.
scm:git:https://gitbox.apache.org/repos/asf/maven-dependency-plugin.git
scm:git:https://gitbox.apache.org/repos/asf/maven-dependency-plugin.git
https://github.com/apache/maven-dependency-plugin/tree/${project.scm.tag}
- maven-dependency-plugin-3.4.0
+ HEAD
JIRA
@@ -94,7 +94,7 @@ under the License.
3.3.0
1.0.0.v20140518
8
- 2022-11-26T21:25:08Z
+ 2022-11-26T21:26:37Z
1.7.36
4.6.0
From ea2a668dcb21e08c69d42c2cdbcf21483fdb3c01 Mon Sep 17 00:00:00 2001
From: Elliotte Rusty Harold
Date: Sun, 27 Nov 2022 16:08:49 -0500
Subject: [PATCH 2/9] remove unused beanutils dependency (#268)
---
pom.xml | 6 ------
1 file changed, 6 deletions(-)
diff --git a/pom.xml b/pom.xml
index dc320c1a0..f3cd22382 100644
--- a/pom.xml
+++ b/pom.xml
@@ -326,12 +326,6 @@ under the License.
${slf4j.version}
test
-
- commons-beanutils
- commons-beanutils
- 1.9.4
-
-
From a05a2a4f5ce1e6d9053f6db9b84736e8bbc519b7 Mon Sep 17 00:00:00 2001
From: Sylwester Lachiewicz
Date: Sun, 27 Nov 2022 22:29:39 +0100
Subject: [PATCH 3/9] Bump junit from 4.13 to 4.13.2 in
/src/it/projects/tree-verbose-small
---
src/it/projects/tree-verbose-small/expected.txt | 2 +-
src/it/projects/tree-verbose-small/pom.xml | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/it/projects/tree-verbose-small/expected.txt b/src/it/projects/tree-verbose-small/expected.txt
index 4d0120c3d..611614c15 100644
--- a/src/it/projects/tree-verbose-small/expected.txt
+++ b/src/it/projects/tree-verbose-small/expected.txt
@@ -1,4 +1,4 @@
org.apache.maven.its.dependency:tree-verbose2:jar:1.0-SNAPSHOT
+- commons-logging:commons-logging:jar:1.2:compile
-\- junit:junit:jar:4.13:test
+\- junit:junit:jar:4.13.2:test
\- org.hamcrest:hamcrest-core:jar:1.3:test
diff --git a/src/it/projects/tree-verbose-small/pom.xml b/src/it/projects/tree-verbose-small/pom.xml
index 838977a79..104879397 100644
--- a/src/it/projects/tree-verbose-small/pom.xml
+++ b/src/it/projects/tree-verbose-small/pom.xml
@@ -45,7 +45,7 @@
junit
junit
- 4.13
+ 4.13.2
test
From 803433bccf1bb4a562d05a6662189fde91184b6d Mon Sep 17 00:00:00 2001
From: Slawomir Jaranowski
Date: Tue, 22 Nov 2022 20:47:38 +0100
Subject: [PATCH 4/9] [MDEP-837] Upgrade Parent to 38
---
pom.xml | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/pom.xml b/pom.xml
index f3cd22382..95c032f7a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,10 +23,10 @@ under the License.
4.0.0
- maven-plugins
org.apache.maven.plugins
- 37
-
+ maven-plugins
+ 38
+
maven-dependency-plugin
@@ -364,6 +364,13 @@ under the License.
+
+ org.apache.maven.plugins
+ maven-checkstyle-plugin
+
+ config/maven_checks_nocodestyle.xml
+
+
From cc082ea7d4af7db78c521d59360d261ffbc1b184 Mon Sep 17 00:00:00 2001
From: Slawomir Jaranowski
Date: Tue, 22 Nov 2022 20:52:13 +0100
Subject: [PATCH 5/9] [MDEP-837] Reformat code after parent 38
---
pom.xml | 81 +-
.../dependency/AbstractDependencyMojo.java | 321 +++----
.../dependency/DisplayAncestorsMojo.java | 53 +-
.../maven/plugins/dependency/GetMojo.java | 226 ++---
.../plugins/dependency/ListClassesMojo.java | 217 ++---
.../plugins/dependency/PropertiesMojo.java | 45 +-
.../dependency/PurgeLocalRepositoryMojo.java | 527 +++++------
.../analyze/AbstractAnalyzeMojo.java | 400 ++++----
.../dependency/analyze/AnalyzeDepMgt.java | 183 ++--
.../analyze/AnalyzeDuplicateMojo.java | 102 +--
.../dependency/analyze/AnalyzeMojo.java | 13 +-
.../dependency/analyze/AnalyzeOnlyMojo.java | 24 +-
.../dependency/analyze/AnalyzeReportMojo.java | 82 +-
.../dependency/analyze/AnalyzeReportView.java | 118 +--
.../AbstractFromConfigurationMojo.java | 242 ++---
.../fromConfiguration/ArtifactItem.java | 154 ++--
.../fromConfiguration/CopyMojo.java | 100 +-
.../ProcessArtifactItemsRequest.java | 49 +-
.../fromConfiguration/UnpackMojo.java | 128 ++-
.../AbstractDependencyFilterMojo.java | 279 +++---
.../AbstractFromDependenciesMojo.java | 82 +-
.../fromDependencies/BuildClasspathMojo.java | 279 +++---
.../CopyDependenciesMojo.java | 266 +++---
.../UnpackDependenciesMojo.java | 110 ++-
.../resolvers/AbstractResolveMojo.java | 63 +-
.../resolvers/CollectDependenciesMojo.java | 20 +-
.../ExcludeReactorProjectsArtifactFilter.java | 64 +-
...xcludeReactorProjectsDependencyFilter.java | 50 +-
.../dependency/resolvers/GoOfflineMojo.java | 152 ++-
.../dependency/resolvers/ListMojo.java | 13 +-
.../resolvers/ListRepositoriesMojo.java | 142 ++-
.../resolvers/ResolveDependenciesMojo.java | 312 +++----
.../ResolveDependencySourcesMojo.java | 26 +-
.../resolvers/ResolvePluginsMojo.java | 138 ++-
.../tree/AbstractSerializingVisitor.java | 20 +-
.../tree/BuildingDependencyNodeVisitor.java | 116 +--
.../tree/DOTDependencyNodeVisitor.java | 42 +-
.../tree/GraphmlDependencyNodeVisitor.java | 77 +-
.../tree/TGFDependencyNodeVisitor.java | 68 +-
.../plugins/dependency/tree/TreeMojo.java | 269 +++---
.../dependency/utils/DependencySilentLog.java | 106 +--
.../utils/DependencyStatusSets.java | 77 +-
.../dependency/utils/DependencyUtil.java | 205 ++---
.../utils/filters/ArtifactItemFilter.java | 13 +-
.../utils/filters/DestFileFilter.java | 173 ++--
.../utils/filters/MarkerFileFilter.java | 67 +-
.../utils/filters/ResolveFileFilter.java | 33 +-
.../markers/DefaultFileMarkerHandler.java | 104 +--
.../utils/markers/MarkerHandler.java | 25 +-
.../markers/SourcesFileMarkerHandler.java | 115 +--
.../markers/UnpackFileMarkerHandler.java | 56 +-
.../utils/translators/ArtifactTranslator.java | 15 +-
.../translators/ClassifierTypeTranslator.java | 71 +-
.../AbstractDependencyMojoTest.java | 116 ++-
.../AbstractDependencyMojoTestCase.java | 73 +-
.../plugins/dependency/TestCollectMojo.java | 90 +-
.../maven/plugins/dependency/TestGetMojo.java | 224 ++---
.../dependency/TestListClassesMojo.java | 111 ++-
.../dependency/TestPropertiesMojo.java | 50 +-
.../maven/plugins/dependency/TestSkip.java | 175 ++--
.../dependency/analyze/TestAnalyzeDepMgt.java | 171 ++--
.../analyze/TestAnalyzeDuplicateMojo.java | 178 ++--
.../fromConfiguration/TestArtifactItem.java | 46 +-
.../fromConfiguration/TestCopyMojo.java | 866 ++++++++----------
.../TestIncludeExcludeUnpackMojo.java | 326 +++----
.../fromConfiguration/TestUnpackMojo.java | 666 ++++++--------
.../TestBuildClasspathMojo.java | 171 ++--
.../TestCopyDependenciesMojo.java | 652 ++++++-------
.../TestCopyDependenciesMojo2.java | 387 ++++----
...tIncludeExcludeUnpackDependenciesMojo.java | 159 ++--
.../TestUnpackDependenciesMojo.java | 565 +++++-------
.../TestUnpackDependenciesMojo2.java | 188 ++--
...ludeReactorProjectsArtifactFilterTest.java | 72 +-
...deReactorProjectsDependencyFilterTest.java | 103 +--
.../ResolveDependenciesMojoTest.java | 226 +++--
.../dependency/resolvers/TestResolveMojo.java | 64 +-
.../DependencyArtifactStubFactory.java | 89 +-
.../stubs/DependencyProjectStub.java | 638 ++++---------
.../DuplicateDependencies2ProjectStub.java | 50 +-
.../DuplicateDependenciesProjectStub.java | 50 +-
.../stubs/StubDefaultFileMarkerHandler.java | 25 +-
.../testUtils/stubs/StubMarkerFile.java | 39 +-
.../stubs/StubSourcesFileMarkerHandler.java | 33 +-
.../stubs/StubUnpackFileMarkerHandler.java | 46 +-
.../plugins/dependency/tree/TestTreeMojo.java | 181 ++--
.../tree/TestTreeMojo_ContainsVersion.java | 36 +-
.../utils/TestDependencyStatusSets.java | 21 +-
.../dependency/utils/TestDependencyUtil.java | 358 ++++----
.../dependency/utils/TestSilentLog.java | 63 +-
.../utils/filters/TestDestFileFilter.java | 278 +++---
.../utils/filters/TestMarkerFileFilter.java | 173 ++--
.../filters/TestResolveMarkerFileFilter.java | 56 +-
.../markers/TestDefaultMarkerFileHandler.java | 161 ++--
.../markers/TestSourcesMarkerFileHandler.java | 249 +++--
.../markers/TestUnpackMarkerFileHandler.java | 270 +++---
.../TestClassifierTypeTranslator.java | 151 ++-
.../build-classpath-test/plugin-config.xml | 2 +-
.../unit/collect-test/plugin-config.xml | 2 +-
.../copy-dependencies-test/plugin-config.xml | 2 +-
.../unit/copy-test/plugin-config.xml | 2 +-
.../resources/unit/get-test/plugin-config.xml | 2 +-
.../unit/properties-test/plugin-config.xml | 2 +-
.../unit/resolve-test/plugin-config.xml | 2 +-
.../unit/tree-test/plugin-config.xml | 2 +-
.../plugin-config.xml | 2 +-
.../unit/unpack-dependencies-test/test.txt | 2 +-
.../unit/unpack-test/plugin-config.xml | 2 +-
107 files changed, 6455 insertions(+), 8926 deletions(-)
diff --git a/pom.xml b/pom.xml
index 95c032f7a..978fc3af8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,5 +1,4 @@
-
-
+
-
4.0.0
@@ -36,31 +34,6 @@ under the License.
Apache Maven Dependency Plugin
Provides utility goals to work with dependencies like copying, unpacking, analyzing, resolving and many more.
-
- ${mavenVersion}
-
-
-
- scm:git:https://gitbox.apache.org/repos/asf/maven-dependency-plugin.git
- scm:git:https://gitbox.apache.org/repos/asf/maven-dependency-plugin.git
- https://github.com/apache/maven-dependency-plugin/tree/${project.scm.tag}
- HEAD
-
-
- JIRA
- https://issues.apache.org/jira/browse/MDEP
-
-
- Jenkins
- https://ci-maven.apache.org/job/Maven/job/maven-box/job/maven-dependency-plugin/
-
-
-
- apache.website
- scm:svn:https://svn.apache.org/repos/asf/maven/website/components/${maven.site.path}
-
-
-
Bakito
@@ -88,6 +61,31 @@ under the License.
+
+ ${mavenVersion}
+
+
+
+ scm:git:https://gitbox.apache.org/repos/asf/maven-dependency-plugin.git
+ scm:git:https://gitbox.apache.org/repos/asf/maven-dependency-plugin.git
+ HEAD
+ https://github.com/apache/maven-dependency-plugin/tree/${project.scm.tag}
+
+
+ JIRA
+ https://issues.apache.org/jira/browse/MDEP
+
+
+ Jenkins
+ https://ci-maven.apache.org/job/Maven/job/maven-box/job/maven-dependency-plugin/
+
+
+
+ apache.website
+ scm:svn:https://svn.apache.org/repos/asf/maven/website/components/${maven.site.path}
+
+
+
3.2.5
9.4.49.v20220914
@@ -160,7 +158,7 @@ under the License.
${mavenVersion}
provided
-
+
org.apache.maven.reporting
@@ -235,7 +233,7 @@ under the License.
maven-plugin-annotations
provided
-
+
org.eclipse.aether
aether-api
@@ -252,10 +250,11 @@ under the License.
org.sonatype.plexus
plexus-build-api
- 0.0.7
+ 0.0.7
+
compile
-
+
org.eclipse.aether
@@ -428,14 +427,6 @@ under the License.
org.codehaus.mojo
mrm-maven-plugin
1.4.1
-
-
-
- start
- stop
-
-
-
repository.proxy.url
@@ -445,9 +436,17 @@ under the License.
-
+
+
+
+
+ start
+ stop
+
+
+
diff --git a/src/main/java/org/apache/maven/plugins/dependency/AbstractDependencyMojo.java b/src/main/java/org/apache/maven/plugins/dependency/AbstractDependencyMojo.java
index 5294bef87..66c64c8e2 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/AbstractDependencyMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/AbstractDependencyMojo.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.dependency;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
@@ -18,12 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.dependency;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.List;
-
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.execution.MavenSession;
@@ -51,16 +49,13 @@
/**
* @author Brian Fox
*/
-public abstract class AbstractDependencyMojo
- extends AbstractMojo
-{
+public abstract class AbstractDependencyMojo extends AbstractMojo {
/**
* To look up Archiver/UnArchiver implementations
*/
@Component
private ArchiverManager archiverManager;
-
/**
* For IDE build support
*/
@@ -69,11 +64,11 @@ public abstract class AbstractDependencyMojo
/**
* Skip plugin execution only during incremental builds (e.g. triggered from M2E).
- *
+ *
* @since 3.4.0
* @see #skip
*/
- @Parameter( defaultValue = "false" )
+ @Parameter(defaultValue = "false")
private boolean skipDuringIncrementalBuild;
/**
@@ -81,48 +76,48 @@ public abstract class AbstractDependencyMojo
* will use the jvm chmod, this is available for user and all level group level will be ignored
*
* since 2.6 is on by default
- *
+ *
* @since 2.5.1
*/
- @Parameter( property = "dependency.useJvmChmod", defaultValue = "true" )
+ @Parameter(property = "dependency.useJvmChmod", defaultValue = "true")
private boolean useJvmChmod = true;
/**
* ignore to set file permissions when unpacking a dependency
- *
+ *
* @since 2.7
*/
- @Parameter( property = "dependency.ignorePermissions", defaultValue = "false" )
+ @Parameter(property = "dependency.ignorePermissions", defaultValue = "false")
private boolean ignorePermissions;
/**
* POM
*/
- @Parameter( defaultValue = "${project}", readonly = true, required = true )
+ @Parameter(defaultValue = "${project}", readonly = true, required = true)
private MavenProject project;
/**
* Remote repositories which will be searched for artifacts.
*/
- @Parameter( defaultValue = "${project.remoteArtifactRepositories}", readonly = true, required = true )
+ @Parameter(defaultValue = "${project.remoteArtifactRepositories}", readonly = true, required = true)
private List remoteRepositories;
/**
* Remote repositories which will be searched for plugins.
*/
- @Parameter( defaultValue = "${project.pluginArtifactRepositories}", readonly = true, required = true )
+ @Parameter(defaultValue = "${project.pluginArtifactRepositories}", readonly = true, required = true)
private List remotePluginRepositories;
/**
* Contains the full list of projects in the reactor.
*/
- @Parameter( defaultValue = "${reactorProjects}", readonly = true )
+ @Parameter(defaultValue = "${reactorProjects}", readonly = true)
protected List reactorProjects;
/**
* The Maven session
*/
- @Parameter( defaultValue = "${session}", readonly = true, required = true )
+ @Parameter(defaultValue = "${session}", readonly = true, required = true)
protected MavenSession session;
/**
@@ -130,7 +125,7 @@ public abstract class AbstractDependencyMojo
*
* @since 2.0
*/
- @Parameter( property = "silent", defaultValue = "false" )
+ @Parameter(property = "silent", defaultValue = "false")
private boolean silent;
/**
@@ -138,7 +133,7 @@ public abstract class AbstractDependencyMojo
*
* @since 2.0
*/
- @Parameter( property = "outputAbsoluteArtifactFilename", defaultValue = "false" )
+ @Parameter(property = "outputAbsoluteArtifactFilename", defaultValue = "false")
protected boolean outputAbsoluteArtifactFilename;
/**
@@ -146,7 +141,7 @@ public abstract class AbstractDependencyMojo
*
* @since 2.7
*/
- @Parameter( property = "mdep.skip", defaultValue = "false" )
+ @Parameter(property = "mdep.skip", defaultValue = "false")
private boolean skip;
// Mojo methods -----------------------------------------------------------
@@ -155,12 +150,9 @@ public abstract class AbstractDependencyMojo
* @see org.apache.maven.plugin.Mojo#execute()
*/
@Override
- public final void execute()
- throws MojoExecutionException, MojoFailureException
- {
- if ( isSkip() )
- {
- getLog().info( "Skipping plugin execution" );
+ public final void execute() throws MojoExecutionException, MojoFailureException {
+ if (isSkip()) {
+ getLog().info("Skipping plugin execution");
return;
}
@@ -171,14 +163,12 @@ public final void execute()
* @throws MojoExecutionException {@link MojoExecutionException}
* @throws MojoFailureException {@link MojoFailureException}
*/
- protected abstract void doExecute()
- throws MojoExecutionException, MojoFailureException;
+ protected abstract void doExecute() throws MojoExecutionException, MojoFailureException;
/**
* @return Returns the archiverManager.
*/
- public ArchiverManager getArchiverManager()
- {
+ public ArchiverManager getArchiverManager() {
return this.archiverManager;
}
@@ -189,28 +179,22 @@ public ArchiverManager getArchiverManager()
* @param destFile file name of destination file.
* @throws MojoExecutionException with a message if an error occurs.
*/
- protected void copyFile( File artifact, File destFile )
- throws MojoExecutionException
- {
- try
- {
- getLog().info( "Copying "
- + ( this.outputAbsoluteArtifactFilename ? artifact.getAbsolutePath() : artifact.getName() ) + " to "
- + destFile );
-
- if ( artifact.isDirectory() )
- {
+ protected void copyFile(File artifact, File destFile) throws MojoExecutionException {
+ try {
+ getLog().info("Copying "
+ + (this.outputAbsoluteArtifactFilename ? artifact.getAbsolutePath() : artifact.getName()) + " to "
+ + destFile);
+
+ if (artifact.isDirectory()) {
// usual case is a future jar packaging, but there are special cases: classifier and other packaging
- throw new MojoExecutionException( "Artifact has not been packaged yet. When used on reactor artifact, "
- + "copy should be executed after packaging: see MDEP-187." );
+ throw new MojoExecutionException("Artifact has not been packaged yet. When used on reactor artifact, "
+ + "copy should be executed after packaging: see MDEP-187.");
}
- FileUtils.copyFile( artifact, destFile );
- buildContext.refresh( destFile );
- }
- catch ( IOException e )
- {
- throw new MojoExecutionException( "Error copying artifact from " + artifact + " to " + destFile, e );
+ FileUtils.copyFile(artifact, destFile);
+ buildContext.refresh(destFile);
+ } catch (IOException e) {
+ throw new MojoExecutionException("Error copying artifact from " + artifact + " to " + destFile, e);
}
}
@@ -222,10 +206,9 @@ protected void copyFile( File artifact, File destFile )
* shall happen.
* @throws MojoExecutionException in case of an error.
*/
- protected void unpack( Artifact artifact, File location, String encoding, FileMapper[] fileMappers )
- throws MojoExecutionException
- {
- unpack( artifact, location, null, null, encoding, fileMappers );
+ protected void unpack(Artifact artifact, File location, String encoding, FileMapper[] fileMappers)
+ throws MojoExecutionException {
+ unpack(artifact, location, null, null, encoding, fileMappers);
}
/**
@@ -242,10 +225,15 @@ protected void unpack( Artifact artifact, File location, String encoding, FileMa
* shall happen.
* @throws MojoExecutionException In case of errors.
*/
- protected void unpack( Artifact artifact, File location, String includes, String excludes, String encoding,
- FileMapper[] fileMappers ) throws MojoExecutionException
- {
- unpack( artifact, artifact.getType(), location, includes, excludes, encoding, fileMappers );
+ protected void unpack(
+ Artifact artifact,
+ File location,
+ String includes,
+ String excludes,
+ String encoding,
+ FileMapper[] fileMappers)
+ throws MojoExecutionException {
+ unpack(artifact, artifact.getType(), location, includes, excludes, encoding, fileMappers);
}
/**
@@ -259,107 +247,93 @@ protected void unpack( Artifact artifact, File location, String includes, String
* shall happen.
* @throws MojoExecutionException in case of an error.
*/
- protected void unpack( Artifact artifact, String type, File location, String includes, String excludes,
- String encoding, FileMapper[] fileMappers )
- throws MojoExecutionException
- {
+ protected void unpack(
+ Artifact artifact,
+ String type,
+ File location,
+ String includes,
+ String excludes,
+ String encoding,
+ FileMapper[] fileMappers)
+ throws MojoExecutionException {
File file = artifact.getFile();
- try
- {
- logUnpack( file, location, includes, excludes );
+ try {
+ logUnpack(file, location, includes, excludes);
location.mkdirs();
- if ( !location.exists() )
- {
- throw new MojoExecutionException( "Location to write unpacked files to could not be created: "
- + location );
+ if (!location.exists()) {
+ throw new MojoExecutionException(
+ "Location to write unpacked files to could not be created: " + location);
}
- if ( file.isDirectory() )
- {
+ if (file.isDirectory()) {
// usual case is a future jar packaging, but there are special cases: classifier and other packaging
- throw new MojoExecutionException( "Artifact has not been packaged yet. When used on reactor artifact, "
- + "unpack should be executed after packaging: see MDEP-98." );
+ throw new MojoExecutionException("Artifact has not been packaged yet. When used on reactor artifact, "
+ + "unpack should be executed after packaging: see MDEP-98.");
}
UnArchiver unArchiver;
- try
- {
- unArchiver = archiverManager.getUnArchiver( type );
- getLog().debug( "Found unArchiver by type: " + unArchiver );
- }
- catch ( NoSuchArchiverException e )
- {
- unArchiver = archiverManager.getUnArchiver( file );
- getLog().debug( "Found unArchiver by extension: " + unArchiver );
+ try {
+ unArchiver = archiverManager.getUnArchiver(type);
+ getLog().debug("Found unArchiver by type: " + unArchiver);
+ } catch (NoSuchArchiverException e) {
+ unArchiver = archiverManager.getUnArchiver(file);
+ getLog().debug("Found unArchiver by extension: " + unArchiver);
}
- if ( encoding != null && unArchiver instanceof ZipUnArchiver )
- {
- ( (ZipUnArchiver) unArchiver ).setEncoding( encoding );
- getLog().info( "Unpacks '" + type + "' with encoding '" + encoding + "'." );
+ if (encoding != null && unArchiver instanceof ZipUnArchiver) {
+ ((ZipUnArchiver) unArchiver).setEncoding(encoding);
+ getLog().info("Unpacks '" + type + "' with encoding '" + encoding + "'.");
}
- unArchiver.setIgnorePermissions( ignorePermissions );
+ unArchiver.setIgnorePermissions(ignorePermissions);
- unArchiver.setSourceFile( file );
+ unArchiver.setSourceFile(file);
- unArchiver.setDestDirectory( location );
+ unArchiver.setDestDirectory(location);
- if ( StringUtils.isNotEmpty( excludes ) || StringUtils.isNotEmpty( includes ) )
- {
+ if (StringUtils.isNotEmpty(excludes) || StringUtils.isNotEmpty(includes)) {
// Create the selectors that will filter
// based on include/exclude parameters
// MDEP-47
IncludeExcludeFileSelector[] selectors =
- new IncludeExcludeFileSelector[] { new IncludeExcludeFileSelector() };
+ new IncludeExcludeFileSelector[] {new IncludeExcludeFileSelector()};
- if ( StringUtils.isNotEmpty( excludes ) )
- {
- selectors[0].setExcludes( excludes.split( "," ) );
+ if (StringUtils.isNotEmpty(excludes)) {
+ selectors[0].setExcludes(excludes.split(","));
}
- if ( StringUtils.isNotEmpty( includes ) )
- {
- selectors[0].setIncludes( includes.split( "," ) );
+ if (StringUtils.isNotEmpty(includes)) {
+ selectors[0].setIncludes(includes.split(","));
}
- unArchiver.setFileSelectors( selectors );
+ unArchiver.setFileSelectors(selectors);
}
- if ( this.silent )
- {
- silenceUnarchiver( unArchiver );
+ if (this.silent) {
+ silenceUnarchiver(unArchiver);
}
- unArchiver.setFileMappers( fileMappers );
+ unArchiver.setFileMappers(fileMappers);
unArchiver.extract();
+ } catch (NoSuchArchiverException e) {
+ throw new MojoExecutionException("Unknown archiver type", e);
+ } catch (ArchiverException e) {
+ throw new MojoExecutionException("Error unpacking file: " + file + " to: " + location, e);
}
- catch ( NoSuchArchiverException e )
- {
- throw new MojoExecutionException( "Unknown archiver type", e );
- }
- catch ( ArchiverException e )
- {
- throw new MojoExecutionException( "Error unpacking file: " + file + " to: " + location, e );
- }
- buildContext.refresh( location );
+ buildContext.refresh(location);
}
- private void silenceUnarchiver( UnArchiver unArchiver )
- {
+ private void silenceUnarchiver(UnArchiver unArchiver) {
// dangerous but handle any errors. It's the only way to silence the unArchiver.
- try
- {
- Field field = ReflectionUtils.getFieldByNameIncludingSuperclasses( "logger", unArchiver.getClass() );
+ try {
+ Field field = ReflectionUtils.getFieldByNameIncludingSuperclasses("logger", unArchiver.getClass());
- field.setAccessible( true );
+ field.setAccessible(true);
- field.set( unArchiver, this.getLog() );
- }
- catch ( Exception e )
- {
+ field.set(unArchiver, this.getLog());
+ } catch (Exception e) {
// was a nice try. Don't bother logging because the log is silent.
}
}
@@ -368,26 +342,22 @@ private void silenceUnarchiver( UnArchiver unArchiver )
* @return Returns a new ProjectBuildingRequest populated from the current session and the current project remote
* repositories, used to resolve artifacts.
*/
- public ProjectBuildingRequest newResolveArtifactProjectBuildingRequest()
- {
- return newProjectBuildingRequest( remoteRepositories );
+ public ProjectBuildingRequest newResolveArtifactProjectBuildingRequest() {
+ return newProjectBuildingRequest(remoteRepositories);
}
/**
* @return Returns a new ProjectBuildingRequest populated from the current session and the current project remote
* repositories, used to resolve plugins.
*/
- protected ProjectBuildingRequest newResolvePluginProjectBuildingRequest()
- {
- return newProjectBuildingRequest( remotePluginRepositories );
+ protected ProjectBuildingRequest newResolvePluginProjectBuildingRequest() {
+ return newProjectBuildingRequest(remotePluginRepositories);
}
- private ProjectBuildingRequest newProjectBuildingRequest( List repositories )
- {
- ProjectBuildingRequest buildingRequest =
- new DefaultProjectBuildingRequest( session.getProjectBuildingRequest() );
+ private ProjectBuildingRequest newProjectBuildingRequest(List repositories) {
+ ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
- buildingRequest.setRemoteRepositories( repositories );
+ buildingRequest.setRemoteRepositories(repositories);
return buildingRequest;
}
@@ -395,42 +365,36 @@ private ProjectBuildingRequest newProjectBuildingRequest( List ancestors = collectAncestors();
- if ( ancestors.isEmpty() )
- {
- getLog().info( "No Ancestor POMs!" );
+ if (ancestors.isEmpty()) {
+ getLog().info("No Ancestor POMs!");
+ } else {
+ getLog().info(String.format(Locale.US, "Ancestor POMs: %s", StringUtils.join(ancestors, " <- ")));
}
- else
- {
- getLog().info( String.format( Locale.US, "Ancestor POMs: %s", StringUtils.join( ancestors, " <- " ) ) );
- }
-
}
- private ArrayList collectAncestors()
- {
+ private ArrayList collectAncestors() {
final ArrayList ancestors = new ArrayList<>();
MavenProject currentAncestor = project.getParent();
- while ( currentAncestor != null )
- {
- final String gav = String.format( Locale.US, "%s:%s:%s", currentAncestor.getGroupId(),
- currentAncestor.getArtifactId(), currentAncestor.getVersion() );
+ while (currentAncestor != null) {
+ final String gav = String.format(
+ Locale.US,
+ "%s:%s:%s",
+ currentAncestor.getGroupId(),
+ currentAncestor.getArtifactId(),
+ currentAncestor.getVersion());
- ancestors.add( gav );
+ ancestors.add(gav);
currentAncestor = currentAncestor.getParent();
}
return ancestors;
}
-
}
diff --git a/src/main/java/org/apache/maven/plugins/dependency/GetMojo.java b/src/main/java/org/apache/maven/plugins/dependency/GetMojo.java
index 9ddbff35b..283c753c4 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/GetMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/GetMojo.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.dependency;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
@@ -18,13 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.dependency;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
import org.apache.maven.artifact.repository.ArtifactRepository;
@@ -56,13 +54,11 @@
* Resolves a single artifact, eventually transitively, from the specified remote repositories. Caveat: will always
* check the central repository defined in the super pom. You could use a mirror entry in your settings.xml
*/
-@Mojo( name = "get", requiresProject = false, threadSafe = true )
-public class GetMojo
- extends AbstractMojo
-{
- private static final Pattern ALT_REPO_SYNTAX_PATTERN = Pattern.compile( "(.+)::(.*)::(.+)" );
+@Mojo(name = "get", requiresProject = false, threadSafe = true)
+public class GetMojo extends AbstractMojo {
+ private static final Pattern ALT_REPO_SYNTAX_PATTERN = Pattern.compile("(.+)::(.*)::(.+)");
- @Parameter( defaultValue = "${session}", required = true, readonly = true )
+ @Parameter(defaultValue = "${session}", required = true, readonly = true)
private MavenSession session;
@Component
@@ -77,7 +73,7 @@ public class GetMojo
/**
* Map that contains the layouts.
*/
- @Component( role = ArtifactRepositoryLayout.class )
+ @Component(role = ArtifactRepositoryLayout.class)
private Map repositoryLayouts;
/**
@@ -91,19 +87,19 @@ public class GetMojo
/**
* The groupId of the artifact to download. Ignored if {@link #artifact} is used.
*/
- @Parameter( property = "groupId" )
+ @Parameter(property = "groupId")
private String groupId;
/**
* The artifactId of the artifact to download. Ignored if {@link #artifact} is used.
*/
- @Parameter( property = "artifactId" )
+ @Parameter(property = "artifactId")
private String artifactId;
/**
* The version of the artifact to download. Ignored if {@link #artifact} is used.
*/
- @Parameter( property = "version" )
+ @Parameter(property = "version")
private String version;
/**
@@ -111,38 +107,38 @@ public class GetMojo
*
* @since 2.3
*/
- @Parameter( property = "classifier" )
+ @Parameter(property = "classifier")
private String classifier;
/**
* The packaging of the artifact to download. Ignored if {@link #artifact} is used.
*/
- @Parameter( property = "packaging", defaultValue = "jar" )
+ @Parameter(property = "packaging", defaultValue = "jar")
private String packaging = "jar";
/**
* Repositories in the format id::[layout]::url or just url, separated by comma. ie.
* central::default::https://repo.maven.apache.org/maven2,myrepo::::https://repo.acme.com,https://repo.acme2.com
*/
- @Parameter( property = "remoteRepositories" )
+ @Parameter(property = "remoteRepositories")
private String remoteRepositories;
/**
* A string of the form groupId:artifactId:version[:packaging[:classifier]].
*/
- @Parameter( property = "artifact" )
+ @Parameter(property = "artifact")
private String artifact;
/**
*
*/
- @Parameter( defaultValue = "${project.remoteArtifactRepositories}", readonly = true, required = true )
+ @Parameter(defaultValue = "${project.remoteArtifactRepositories}", readonly = true, required = true)
private List pomRemoteRepositories;
/**
* Download transitively, retrieving the specified artifact and all of its dependencies.
*/
- @Parameter( property = "transitive", defaultValue = "true" )
+ @Parameter(property = "transitive", defaultValue = "true")
private boolean transitive = true;
/**
@@ -150,143 +146,118 @@ public class GetMojo
*
* @since 2.7
*/
- @Parameter( property = "mdep.skip", defaultValue = "false" )
+ @Parameter(property = "mdep.skip", defaultValue = "false")
private boolean skip;
@Override
- public void execute()
- throws MojoExecutionException, MojoFailureException
- {
- if ( isSkip() )
- {
- getLog().info( "Skipping plugin execution" );
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ if (isSkip()) {
+ getLog().info("Skipping plugin execution");
return;
}
- if ( coordinate.getArtifactId() == null && artifact == null )
- {
- throw new MojoFailureException( "You must specify an artifact, "
- + "e.g. -Dartifact=org.apache.maven.plugins:maven-downloader-plugin:1.0" );
+ if (coordinate.getArtifactId() == null && artifact == null) {
+ throw new MojoFailureException("You must specify an artifact, "
+ + "e.g. -Dartifact=org.apache.maven.plugins:maven-downloader-plugin:1.0");
}
- if ( artifact != null )
- {
- String[] tokens = StringUtils.split( artifact, ":" );
- if ( tokens.length < 3 || tokens.length > 5 )
- {
- throw new MojoFailureException( "Invalid artifact, you must specify "
- + "groupId:artifactId:version[:packaging[:classifier]] " + artifact );
+ if (artifact != null) {
+ String[] tokens = StringUtils.split(artifact, ":");
+ if (tokens.length < 3 || tokens.length > 5) {
+ throw new MojoFailureException("Invalid artifact, you must specify "
+ + "groupId:artifactId:version[:packaging[:classifier]] " + artifact);
}
- coordinate.setGroupId( tokens[0] );
- coordinate.setArtifactId( tokens[1] );
- coordinate.setVersion( tokens[2] );
- if ( tokens.length >= 4 )
- {
- coordinate.setType( tokens[3] );
+ coordinate.setGroupId(tokens[0]);
+ coordinate.setArtifactId(tokens[1]);
+ coordinate.setVersion(tokens[2]);
+ if (tokens.length >= 4) {
+ coordinate.setType(tokens[3]);
}
- if ( tokens.length == 5 )
- {
- coordinate.setClassifier( tokens[4] );
+ if (tokens.length == 5) {
+ coordinate.setClassifier(tokens[4]);
}
}
- ArtifactRepositoryPolicy always =
- new ArtifactRepositoryPolicy( true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS,
- ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN );
+ ArtifactRepositoryPolicy always = new ArtifactRepositoryPolicy(
+ true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN);
List repoList = new ArrayList<>();
- if ( pomRemoteRepositories != null )
- {
- repoList.addAll( pomRemoteRepositories );
+ if (pomRemoteRepositories != null) {
+ repoList.addAll(pomRemoteRepositories);
}
- if ( remoteRepositories != null )
- {
+ if (remoteRepositories != null) {
// Use the same format as in the deploy plugin id::layout::url
- String[] repos = StringUtils.split( remoteRepositories, "," );
- for ( String repo : repos )
- {
- repoList.add( parseRepository( repo, always ) );
+ String[] repos = StringUtils.split(remoteRepositories, ",");
+ for (String repo : repos) {
+ repoList.add(parseRepository(repo, always));
}
}
- try
- {
+ try {
ProjectBuildingRequest buildingRequest =
- new DefaultProjectBuildingRequest( session.getProjectBuildingRequest() );
+ new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
Settings settings = session.getSettings();
- repositorySystem.injectMirror( repoList, settings.getMirrors() );
- repositorySystem.injectProxy( repoList, settings.getProxies() );
- repositorySystem.injectAuthentication( repoList, settings.getServers() );
-
- buildingRequest.setRemoteRepositories( repoList );
-
- if ( transitive )
- {
- getLog().info( "Resolving " + coordinate + " with transitive dependencies" );
- dependencyResolver.resolveDependencies( buildingRequest, coordinate, null );
- }
- else
- {
- getLog().info( "Resolving " + coordinate );
- artifactResolver.resolveArtifact( buildingRequest, toArtifactCoordinate( coordinate ) );
+ repositorySystem.injectMirror(repoList, settings.getMirrors());
+ repositorySystem.injectProxy(repoList, settings.getProxies());
+ repositorySystem.injectAuthentication(repoList, settings.getServers());
+
+ buildingRequest.setRemoteRepositories(repoList);
+
+ if (transitive) {
+ getLog().info("Resolving " + coordinate + " with transitive dependencies");
+ dependencyResolver.resolveDependencies(buildingRequest, coordinate, null);
+ } else {
+ getLog().info("Resolving " + coordinate);
+ artifactResolver.resolveArtifact(buildingRequest, toArtifactCoordinate(coordinate));
}
- }
- catch ( ArtifactResolverException | DependencyResolverException e )
- {
- throw new MojoExecutionException( "Couldn't download artifact: " + e.getMessage(), e );
+ } catch (ArtifactResolverException | DependencyResolverException e) {
+ throw new MojoExecutionException("Couldn't download artifact: " + e.getMessage(), e);
}
}
- private ArtifactCoordinate toArtifactCoordinate( DependableCoordinate dependableCoordinate )
- {
- ArtifactHandler artifactHandler = artifactHandlerManager.getArtifactHandler( dependableCoordinate.getType() );
+ private ArtifactCoordinate toArtifactCoordinate(DependableCoordinate dependableCoordinate) {
+ ArtifactHandler artifactHandler = artifactHandlerManager.getArtifactHandler(dependableCoordinate.getType());
DefaultArtifactCoordinate artifactCoordinate = new DefaultArtifactCoordinate();
- artifactCoordinate.setGroupId( dependableCoordinate.getGroupId() );
- artifactCoordinate.setArtifactId( dependableCoordinate.getArtifactId() );
- artifactCoordinate.setVersion( dependableCoordinate.getVersion() );
- artifactCoordinate.setClassifier( dependableCoordinate.getClassifier() );
- artifactCoordinate.setExtension( artifactHandler.getExtension() );
+ artifactCoordinate.setGroupId(dependableCoordinate.getGroupId());
+ artifactCoordinate.setArtifactId(dependableCoordinate.getArtifactId());
+ artifactCoordinate.setVersion(dependableCoordinate.getVersion());
+ artifactCoordinate.setClassifier(dependableCoordinate.getClassifier());
+ artifactCoordinate.setExtension(artifactHandler.getExtension());
return artifactCoordinate;
}
- ArtifactRepository parseRepository( String repo, ArtifactRepositoryPolicy policy )
- throws MojoFailureException
- {
+ ArtifactRepository parseRepository(String repo, ArtifactRepositoryPolicy policy) throws MojoFailureException {
// if it's a simple url
String id = "temp";
- ArtifactRepositoryLayout layout = getLayout( "default" );
+ ArtifactRepositoryLayout layout = getLayout("default");
String url = repo;
// if it's an extended repo URL of the form id::layout::url
- if ( repo.contains( "::" ) )
- {
- Matcher matcher = ALT_REPO_SYNTAX_PATTERN.matcher( repo );
- if ( !matcher.matches() )
- {
- throw new MojoFailureException( repo, "Invalid syntax for repository: " + repo,
- "Invalid syntax for repository. Use \"id::layout::url\" or \"URL\"." );
+ if (repo.contains("::")) {
+ Matcher matcher = ALT_REPO_SYNTAX_PATTERN.matcher(repo);
+ if (!matcher.matches()) {
+ throw new MojoFailureException(
+ repo,
+ "Invalid syntax for repository: " + repo,
+ "Invalid syntax for repository. Use \"id::layout::url\" or \"URL\".");
}
- id = matcher.group( 1 ).trim();
- if ( !StringUtils.isEmpty( matcher.group( 2 ) ) )
- {
- layout = getLayout( matcher.group( 2 ).trim() );
+ id = matcher.group(1).trim();
+ if (!StringUtils.isEmpty(matcher.group(2))) {
+ layout = getLayout(matcher.group(2).trim());
}
- url = matcher.group( 3 ).trim();
+ url = matcher.group(3).trim();
}
- return new MavenArtifactRepository( id, url, layout, policy, policy );
+ return new MavenArtifactRepository(id, url, layout, policy, policy);
}
- private ArtifactRepositoryLayout getLayout( String id )
- throws MojoFailureException
- {
- ArtifactRepositoryLayout layout = repositoryLayouts.get( id );
+ private ArtifactRepositoryLayout getLayout(String id) throws MojoFailureException {
+ ArtifactRepositoryLayout layout = repositoryLayouts.get(id);
- if ( layout == null )
- {
- throw new MojoFailureException( id, "Invalid repository layout", "Invalid repository layout: " + id );
+ if (layout == null) {
+ throw new MojoFailureException(id, "Invalid repository layout", "Invalid repository layout: " + id);
}
return layout;
@@ -295,49 +266,42 @@ private ArtifactRepositoryLayout getLayout( String id )
/**
* @return {@link #skip}
*/
- protected boolean isSkip()
- {
+ protected boolean isSkip() {
return skip;
}
/**
* @param groupId The groupId.
*/
- public void setGroupId( String groupId )
- {
- this.coordinate.setGroupId( groupId );
+ public void setGroupId(String groupId) {
+ this.coordinate.setGroupId(groupId);
}
/**
* @param artifactId The artifactId.
*/
- public void setArtifactId( String artifactId )
- {
- this.coordinate.setArtifactId( artifactId );
+ public void setArtifactId(String artifactId) {
+ this.coordinate.setArtifactId(artifactId);
}
/**
* @param version The version.
*/
- public void setVersion( String version )
- {
- this.coordinate.setVersion( version );
+ public void setVersion(String version) {
+ this.coordinate.setVersion(version);
}
/**
* @param classifier The classifier to be used.
*/
- public void setClassifier( String classifier )
- {
- this.coordinate.setClassifier( classifier );
+ public void setClassifier(String classifier) {
+ this.coordinate.setClassifier(classifier);
}
/**
* @param type packaging.
*/
- public void setPackaging( String type )
- {
- this.coordinate.setType( type );
+ public void setPackaging(String type) {
+ this.coordinate.setType(type);
}
-
}
diff --git a/src/main/java/org/apache/maven/plugins/dependency/ListClassesMojo.java b/src/main/java/org/apache/maven/plugins/dependency/ListClassesMojo.java
index 250806c4f..18b11b0d1 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/ListClassesMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/ListClassesMojo.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.dependency;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
@@ -18,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.dependency;
import java.io.IOException;
import java.util.ArrayList;
@@ -28,7 +27,6 @@
import java.util.jar.JarFile;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
import org.apache.maven.artifact.repository.ArtifactRepository;
@@ -56,17 +54,14 @@
import org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolver;
import org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolverException;
-
/**
* Retrieves and lists all classes contained in the specified artifact from the specified remote repositories.
*/
-@Mojo( name = "list-classes", requiresProject = false, threadSafe = true )
-public class ListClassesMojo
- extends AbstractMojo
-{
- private static final Pattern ALT_REPO_SYNTAX_PATTERN = Pattern.compile( "(.+)::(.*)::(.+)" );
+@Mojo(name = "list-classes", requiresProject = false, threadSafe = true)
+public class ListClassesMojo extends AbstractMojo {
+ private static final Pattern ALT_REPO_SYNTAX_PATTERN = Pattern.compile("(.+)::(.*)::(.+)");
- @Parameter( defaultValue = "${session}", required = true, readonly = true )
+ @Parameter(defaultValue = "${session}", required = true, readonly = true)
private MavenSession session;
@Component
@@ -81,7 +76,7 @@ public class ListClassesMojo
/**
* Map that contains the layouts.
*/
- @Component( role = ArtifactRepositoryLayout.class )
+ @Component(role = ArtifactRepositoryLayout.class)
private Map repositoryLayouts;
/**
@@ -95,19 +90,19 @@ public class ListClassesMojo
/**
* The group ID of the artifact to download. Ignored if {@link #artifact} is used.
*/
- @Parameter( property = "groupId" )
+ @Parameter(property = "groupId")
private String groupId;
/**
* The artifact ID of the artifact to download. Ignored if {@link #artifact} is used.
*/
- @Parameter( property = "artifactId" )
+ @Parameter(property = "artifactId")
private String artifactId;
/**
* The version of the artifact to download. Ignored if {@link #artifact} is used.
*/
- @Parameter( property = "version" )
+ @Parameter(property = "version")
private String version;
/**
@@ -115,209 +110,179 @@ public class ListClassesMojo
*
* @since 2.3
*/
- @Parameter( property = "classifier" )
+ @Parameter(property = "classifier")
private String classifier;
/**
* The packaging of the artifact to download. Ignored if {@link #artifact} is used.
*/
- @Parameter( property = "packaging", defaultValue = "jar" )
+ @Parameter(property = "packaging", defaultValue = "jar")
private String packaging = "jar";
/**
* Repositories in the format id::[layout]::url or just URLs, separated by comma. That is,
* central::default::https://repo.maven.apache.org/maven2,myrepo::::https://repo.acme.com,https://repo.acme2.com
*/
- @Parameter( property = "remoteRepositories" )
+ @Parameter(property = "remoteRepositories")
private String remoteRepositories;
/**
* A string of the form groupId:artifactId:version[:packaging[:classifier]].
*/
- @Parameter( property = "artifact" )
+ @Parameter(property = "artifact")
private String artifact;
- @Parameter( defaultValue = "${project.remoteArtifactRepositories}", readonly = true, required = true )
+ @Parameter(defaultValue = "${project.remoteArtifactRepositories}", readonly = true, required = true)
private List pomRemoteRepositories;
/**
* Download transitively, retrieving the specified artifact and all of its dependencies.
*/
- @Parameter( property = "transitive", defaultValue = "false" )
+ @Parameter(property = "transitive", defaultValue = "false")
private boolean transitive = false;
/**
* Skip plugin execution completely.
*/
- @Parameter( property = "mdep.skip", defaultValue = "false" )
+ @Parameter(property = "mdep.skip", defaultValue = "false")
private boolean skip;
@Override
- public void execute() throws MojoExecutionException, MojoFailureException
- {
+ public void execute() throws MojoExecutionException, MojoFailureException {
ProjectBuildingRequest buildingRequest = makeBuildingRequest();
- try
- {
- if ( transitive )
- {
- Iterable artifacts = dependencyResolver
- .resolveDependencies( buildingRequest, coordinate, null );
+ try {
+ if (transitive) {
+ Iterable artifacts =
+ dependencyResolver.resolveDependencies(buildingRequest, coordinate, null);
- for ( ArtifactResult result : artifacts )
- {
- printClassesFromArtifactResult( result );
+ for (ArtifactResult result : artifacts) {
+ printClassesFromArtifactResult(result);
}
- }
- else
- {
- ArtifactResult result = artifactResolver
- .resolveArtifact( buildingRequest, toArtifactCoordinate( coordinate ) );
+ } else {
+ ArtifactResult result =
+ artifactResolver.resolveArtifact(buildingRequest, toArtifactCoordinate(coordinate));
- printClassesFromArtifactResult( result );
+ printClassesFromArtifactResult(result);
}
- }
- catch ( ArtifactResolverException | DependencyResolverException | IOException e )
- {
- throw new MojoExecutionException( "Couldn't download artifact: " + e.getMessage(), e );
+ } catch (ArtifactResolverException | DependencyResolverException | IOException e) {
+ throw new MojoExecutionException("Couldn't download artifact: " + e.getMessage(), e);
}
}
- private void printClassesFromArtifactResult( ArtifactResult result )
- throws IOException
- {
+ private void printClassesFromArtifactResult(ArtifactResult result) throws IOException {
// open jar file in try-with-resources statement to guarantee the file closes after use regardless of errors
- try ( JarFile jarFile = new JarFile( result.getArtifact().getFile() ) )
- {
+ try (JarFile jarFile = new JarFile(result.getArtifact().getFile())) {
Enumeration entries = jarFile.entries();
- while ( entries.hasMoreElements() )
- {
+ while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
String entryName = entry.getName();
// filter out files that do not end in .class
- if ( !entryName.endsWith( ".class" ) )
- {
+ if (!entryName.endsWith(".class")) {
continue;
}
// remove .class from the end and change format to use periods instead of forward slashes
- String className = entryName.substring( 0, entryName.length() - 6 ).replace( '/', '.' );
- getLog().info( className );
+ String className =
+ entryName.substring(0, entryName.length() - 6).replace('/', '.');
+ getLog().info(className);
}
}
}
- private ProjectBuildingRequest makeBuildingRequest()
- throws MojoExecutionException, MojoFailureException
- {
- if ( artifact == null )
- {
- throw new MojoFailureException( "You must specify an artifact, "
- + "e.g. -Dartifact=org.apache.maven.plugins:maven-downloader-plugin:1.0" );
+ private ProjectBuildingRequest makeBuildingRequest() throws MojoExecutionException, MojoFailureException {
+ if (artifact == null) {
+ throw new MojoFailureException("You must specify an artifact, "
+ + "e.g. -Dartifact=org.apache.maven.plugins:maven-downloader-plugin:1.0");
}
- String[] tokens = artifact.split( ":" );
- if ( tokens.length < 3 || tokens.length > 5 )
- {
- throw new MojoFailureException( "Invalid artifact, you must specify "
- + "groupId:artifactId:version[:packaging[:classifier]] " + artifact );
+ String[] tokens = artifact.split(":");
+ if (tokens.length < 3 || tokens.length > 5) {
+ throw new MojoFailureException("Invalid artifact, you must specify "
+ + "groupId:artifactId:version[:packaging[:classifier]] " + artifact);
}
- coordinate.setGroupId( tokens[0] );
- coordinate.setArtifactId( tokens[1] );
- coordinate.setVersion( tokens[2] );
- if ( tokens.length >= 4 )
- {
- coordinate.setType( tokens[3] );
+ coordinate.setGroupId(tokens[0]);
+ coordinate.setArtifactId(tokens[1]);
+ coordinate.setVersion(tokens[2]);
+ if (tokens.length >= 4) {
+ coordinate.setType(tokens[3]);
}
- if ( tokens.length == 5 )
- {
- coordinate.setClassifier( tokens[4] );
+ if (tokens.length == 5) {
+ coordinate.setClassifier(tokens[4]);
}
-
- ArtifactRepositoryPolicy always =
- new ArtifactRepositoryPolicy( true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS,
- ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN );
+ ArtifactRepositoryPolicy always = new ArtifactRepositoryPolicy(
+ true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN);
List repoList = new ArrayList<>();
- if ( pomRemoteRepositories != null )
- {
- repoList.addAll( pomRemoteRepositories );
+ if (pomRemoteRepositories != null) {
+ repoList.addAll(pomRemoteRepositories);
}
- if ( remoteRepositories != null )
- {
+ if (remoteRepositories != null) {
// Use the same format as in the deploy plugin id::layout::url
- String[] repos = remoteRepositories.split( "," );
- for ( String repo : repos )
- {
- repoList.add( parseRepository( repo, always ) );
+ String[] repos = remoteRepositories.split(",");
+ for (String repo : repos) {
+ repoList.add(parseRepository(repo, always));
}
}
- ProjectBuildingRequest buildingRequest =
- new DefaultProjectBuildingRequest( session.getProjectBuildingRequest() );
+ ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
Settings settings = session.getSettings();
- repositorySystem.injectMirror( repoList, settings.getMirrors() );
- repositorySystem.injectProxy( repoList, settings.getProxies() );
- repositorySystem.injectAuthentication( repoList, settings.getServers() );
+ repositorySystem.injectMirror(repoList, settings.getMirrors());
+ repositorySystem.injectProxy(repoList, settings.getProxies());
+ repositorySystem.injectAuthentication(repoList, settings.getServers());
- buildingRequest.setRemoteRepositories( repoList );
+ buildingRequest.setRemoteRepositories(repoList);
return buildingRequest;
}
- private ArtifactCoordinate toArtifactCoordinate( DependableCoordinate dependableCoordinate )
- {
- ArtifactHandler artifactHandler = artifactHandlerManager.getArtifactHandler( dependableCoordinate.getType() );
+ private ArtifactCoordinate toArtifactCoordinate(DependableCoordinate dependableCoordinate) {
+ ArtifactHandler artifactHandler = artifactHandlerManager.getArtifactHandler(dependableCoordinate.getType());
DefaultArtifactCoordinate artifactCoordinate = new DefaultArtifactCoordinate();
- artifactCoordinate.setGroupId( dependableCoordinate.getGroupId() );
- artifactCoordinate.setArtifactId( dependableCoordinate.getArtifactId() );
- artifactCoordinate.setVersion( dependableCoordinate.getVersion() );
- artifactCoordinate.setClassifier( dependableCoordinate.getClassifier() );
- artifactCoordinate.setExtension( artifactHandler.getExtension() );
+ artifactCoordinate.setGroupId(dependableCoordinate.getGroupId());
+ artifactCoordinate.setArtifactId(dependableCoordinate.getArtifactId());
+ artifactCoordinate.setVersion(dependableCoordinate.getVersion());
+ artifactCoordinate.setClassifier(dependableCoordinate.getClassifier());
+ artifactCoordinate.setExtension(artifactHandler.getExtension());
return artifactCoordinate;
}
- protected ArtifactRepository parseRepository( String repo, ArtifactRepositoryPolicy policy )
- throws MojoFailureException
- {
+ protected ArtifactRepository parseRepository(String repo, ArtifactRepositoryPolicy policy)
+ throws MojoFailureException {
// if it's a simple url
String id = "temp";
- ArtifactRepositoryLayout layout = getLayout( "default" );
+ ArtifactRepositoryLayout layout = getLayout("default");
// if it's an extended repo URL of the form id::layout::url
- if ( repo.contains( "::" ) )
- {
- Matcher matcher = ALT_REPO_SYNTAX_PATTERN.matcher( repo );
- if ( !matcher.matches() )
- {
- throw new MojoFailureException( repo, "Invalid syntax for repository: " + repo,
- "Invalid syntax for repository. Use \"id::layout::url\" or \"URL\"." );
+ if (repo.contains("::")) {
+ Matcher matcher = ALT_REPO_SYNTAX_PATTERN.matcher(repo);
+ if (!matcher.matches()) {
+ throw new MojoFailureException(
+ repo,
+ "Invalid syntax for repository: " + repo,
+ "Invalid syntax for repository. Use \"id::layout::url\" or \"URL\".");
}
- id = matcher.group( 1 ).trim();
- if ( !( matcher.group( 2 ) == null || matcher.group( 2 ).trim().isEmpty() ) )
- {
- layout = getLayout( matcher.group( 2 ).trim() );
+ id = matcher.group(1).trim();
+ if (!(matcher.group(2) == null || matcher.group(2).trim().isEmpty())) {
+ layout = getLayout(matcher.group(2).trim());
}
- repo = matcher.group( 3 ).trim();
+ repo = matcher.group(3).trim();
}
- return new MavenArtifactRepository( id, repo, layout, policy, policy );
+ return new MavenArtifactRepository(id, repo, layout, policy, policy);
}
- private ArtifactRepositoryLayout getLayout( String id )
- throws MojoFailureException
- {
- ArtifactRepositoryLayout layout = repositoryLayouts.get( id );
+ private ArtifactRepositoryLayout getLayout(String id) throws MojoFailureException {
+ ArtifactRepositoryLayout layout = repositoryLayouts.get(id);
- if ( layout == null )
- {
- throw new MojoFailureException( id, "Invalid repository layout", "Invalid repository layout: " + id );
+ if (layout == null) {
+ throw new MojoFailureException(id, "Invalid repository layout", "Invalid repository layout: " + id);
}
return layout;
diff --git a/src/main/java/org/apache/maven/plugins/dependency/PropertiesMojo.java b/src/main/java/org/apache/maven/plugins/dependency/PropertiesMojo.java
index 2961599db..54c0eeee6 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/PropertiesMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/PropertiesMojo.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.dependency;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
@@ -18,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.dependency;
import java.util.Set;
-
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
@@ -38,17 +36,19 @@
* @author Paul Gier
* @since 2.2
*/
-//CHECKSTYLE_OFF: LineLength
-@Mojo( name = "properties", requiresDependencyResolution = ResolutionScope.TEST, defaultPhase = LifecyclePhase.INITIALIZE, threadSafe = true )
-//CHECKSTYLE_ON: LineLength
-public class PropertiesMojo
- extends AbstractMojo
-{
+// CHECKSTYLE_OFF: LineLength
+@Mojo(
+ name = "properties",
+ requiresDependencyResolution = ResolutionScope.TEST,
+ defaultPhase = LifecyclePhase.INITIALIZE,
+ threadSafe = true)
+// CHECKSTYLE_ON: LineLength
+public class PropertiesMojo extends AbstractMojo {
/**
* The current Maven project
*/
- @Parameter( defaultValue = "${project}", readonly = true, required = true )
+ @Parameter(defaultValue = "${project}", readonly = true, required = true)
private MavenProject project;
/**
@@ -56,7 +56,7 @@ public class PropertiesMojo
*
* @since 2.7
*/
- @Parameter( property = "mdep.skip", defaultValue = "false" )
+ @Parameter(property = "mdep.skip", defaultValue = "false")
private boolean skip;
/**
@@ -65,29 +65,26 @@ public class PropertiesMojo
* @throws MojoExecutionException with a message if an error occurs.
*/
@Override
- public void execute()
- throws MojoExecutionException
- {
- if ( isSkip() )
- {
- getLog().info( "Skipping plugin execution" );
+ public void execute() throws MojoExecutionException {
+ if (isSkip()) {
+ getLog().info("Skipping plugin execution");
return;
}
Set artifacts = project.getArtifacts();
- for ( Artifact artifact : artifacts )
- {
- project.getProperties().setProperty( artifact.getDependencyConflictId(),
- artifact.getFile().getAbsolutePath() );
+ for (Artifact artifact : artifacts) {
+ project.getProperties()
+ .setProperty(
+ artifact.getDependencyConflictId(),
+ artifact.getFile().getAbsolutePath());
}
}
/**
* @return {@link #skip}
*/
- public boolean isSkip()
- {
+ public boolean isSkip() {
return skip;
}
}
diff --git a/src/main/java/org/apache/maven/plugins/dependency/PurgeLocalRepositoryMojo.java b/src/main/java/org/apache/maven/plugins/dependency/PurgeLocalRepositoryMojo.java
index d76f06911..01be06394 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/PurgeLocalRepositoryMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/PurgeLocalRepositoryMojo.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.dependency;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
@@ -18,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.dependency;
import java.io.File;
import java.io.IOException;
@@ -27,7 +26,6 @@
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
-
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
@@ -72,10 +70,8 @@
* @author jdcasey
* @since 2.0
*/
-@Mojo( name = "purge-local-repository", threadSafe = true, requiresProject = false )
-public class PurgeLocalRepositoryMojo
- extends AbstractMojo
-{
+@Mojo(name = "purge-local-repository", threadSafe = true, requiresProject = false)
+public class PurgeLocalRepositoryMojo extends AbstractMojo {
private static final String VERSION_FUZZINESS = "version";
@@ -86,22 +82,22 @@ public class PurgeLocalRepositoryMojo
/**
* The Maven projects in the reactor.
*/
- @Parameter( defaultValue = "${reactorProjects}", readonly = true, required = true )
+ @Parameter(defaultValue = "${reactorProjects}", readonly = true, required = true)
private List reactorProjects;
/**
* The current Maven project.
*/
- @Parameter( defaultValue = "${project}", readonly = true, required = true )
+ @Parameter(defaultValue = "${project}", readonly = true, required = true)
private MavenProject project;
- @Parameter( defaultValue = "${session}", readonly = true, required = true )
+ @Parameter(defaultValue = "${session}", readonly = true, required = true)
private MavenSession session;
/**
* This mojo execution, used to determine if it was launched from the lifecycle or the command-line.
*/
- @Parameter( defaultValue = "${mojo}", required = true, readonly = true )
+ @Parameter(defaultValue = "${mojo}", required = true, readonly = true)
private MojoExecution mojoExecution;
/**
@@ -128,7 +124,7 @@ public class PurgeLocalRepositoryMojo
*
* @since 2.6
*/
- @Parameter( property = "manualInclude" )
+ @Parameter(property = "manualInclude")
private String manualInclude;
/**
@@ -146,7 +142,7 @@ public class PurgeLocalRepositoryMojo
*
* @since 2.6
*/
- @Parameter( property = "include" )
+ @Parameter(property = "include")
private String include;
/**
@@ -160,20 +156,20 @@ public class PurgeLocalRepositoryMojo
* deletion/refresh. This is a command-line alternative to the excludes
parameter, since List
* parameters are not currently compatible with CLI specification.
*/
- @Parameter( property = "exclude" )
+ @Parameter(property = "exclude")
private String exclude;
/**
* Whether to re-resolve the artifacts once they have been deleted from the local repository. If you are running
* this mojo from the command-line, you may want to disable this. By default, artifacts will be re-resolved.
*/
- @Parameter( property = "reResolve", defaultValue = "true" )
+ @Parameter(property = "reResolve", defaultValue = "true")
private boolean reResolve;
/**
* The local repository, from which to delete artifacts.
*/
- @Parameter( defaultValue = "${localRepository}", readonly = true, required = true )
+ @Parameter(defaultValue = "${localRepository}", readonly = true, required = true)
private ArtifactRepository localRepository;
/**
@@ -197,19 +193,19 @@ public class PurgeLocalRepositoryMojo
* groupId - Eliminate all files associated with the artifact's groupId.
*
*/
- @Parameter( property = "resolutionFuzziness", defaultValue = "version" )
+ @Parameter(property = "resolutionFuzziness", defaultValue = "version")
private String resolutionFuzziness;
/**
* Whether this mojo should act on all transitive dependencies. Default value is true.
*/
- @Parameter( property = "actTransitively", defaultValue = "true" )
+ @Parameter(property = "actTransitively", defaultValue = "true")
private boolean actTransitively;
/**
* Whether this plugin should output verbose messages. Default is false.
*/
- @Parameter( property = "verbose", defaultValue = "false" )
+ @Parameter(property = "verbose", defaultValue = "false")
private boolean verbose;
/**
@@ -217,7 +213,7 @@ public class PurgeLocalRepositoryMojo
*
* @since 2.4
*/
- @Parameter( property = "snapshotsOnly", defaultValue = "false" )
+ @Parameter(property = "snapshotsOnly", defaultValue = "false")
private boolean snapshotsOnly;
/**
@@ -225,15 +221,13 @@ public class PurgeLocalRepositoryMojo
*
* @since 2.7
*/
- @Parameter( property = "skip", defaultValue = "false" )
+ @Parameter(property = "skip", defaultValue = "false")
private boolean skip;
/**
* Includes only direct project dependencies.
*/
- private class DirectDependencyFilter
- extends AbstractFilter
- {
+ private class DirectDependencyFilter extends AbstractFilter {
private final Artifact projectArtifact;
private final List directDependencies;
@@ -243,24 +237,19 @@ private class DirectDependencyFilter
*
* @param directDependencies Set of dependencies objects which represent the direct dependencies of the project
*/
- DirectDependencyFilter( Artifact projectArtifact, List directDependencies )
- {
+ DirectDependencyFilter(Artifact projectArtifact, List directDependencies) {
this.projectArtifact = projectArtifact;
this.directDependencies = directDependencies;
}
@Override
- public boolean accept( Node node, List parents )
- {
+ public boolean accept(Node node, List parents) {
- if ( artifactsGAMatch( node, projectArtifact.getGroupId(), projectArtifact.getArtifactId() ) )
- {
+ if (artifactsGAMatch(node, projectArtifact.getGroupId(), projectArtifact.getArtifactId())) {
return true;
}
- for ( Dependency dep : directDependencies )
- {
- if ( this.artifactsGAMatch( node, dep.getGroupId(), dep.getArtifactId() ) )
- {
+ for (Dependency dep : directDependencies) {
+ if (this.artifactsGAMatch(node, dep.getGroupId(), dep.getArtifactId())) {
return true;
}
}
@@ -270,21 +259,17 @@ public boolean accept( Node node, List parents )
/*
* Compare the groupId:artifactId of two artifacts.
*/
- private boolean artifactsGAMatch( Node node, String groupId, String artifactId )
- {
- if ( node.getDependency() == null )
- {
+ private boolean artifactsGAMatch(Node node, String groupId, String artifactId) {
+ if (node.getDependency() == null) {
return false;
}
- if ( !node.getDependency().getGroupId().equals( groupId ) )
- {
- getLog().debug( "Different groupId: " + node.getDependency() + " " + groupId );
+ if (!node.getDependency().getGroupId().equals(groupId)) {
+ getLog().debug("Different groupId: " + node.getDependency() + " " + groupId);
return false;
}
- if ( !node.getDependency().getArtifactId().equals( artifactId ) )
- {
- getLog().debug( "Different artifactId: " + node.getDependency() + " " + artifactId );
+ if (!node.getDependency().getArtifactId().equals(artifactId)) {
+ getLog().debug("Different artifactId: " + node.getDependency() + " " + artifactId);
return false;
}
return true;
@@ -294,55 +279,40 @@ private boolean artifactsGAMatch( Node node, String groupId, String artifactId )
/**
* Includes only snapshot artifacts
*/
- private static class SnapshotsFilter
- extends AbstractFilter
- {
+ private static class SnapshotsFilter extends AbstractFilter {
@Override
- public boolean accept( Node node, List parents )
- {
- if ( node.getDependency() == null )
- {
+ public boolean accept(Node node, List parents) {
+ if (node.getDependency() == null) {
return false;
- }
- else
- {
- return ArtifactUtils.isSnapshot( node.getDependency().getVersion() );
+ } else {
+ return ArtifactUtils.isSnapshot(node.getDependency().getVersion());
}
}
}
@Override
- public void execute()
- throws MojoExecutionException, MojoFailureException
- {
- if ( isSkip() )
- {
- getLog().info( "Skipping plugin execution" );
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ if (isSkip()) {
+ getLog().info("Skipping plugin execution");
return;
}
- if ( !StringUtils.isEmpty( manualInclude ) )
- {
- manualIncludes = this.parseIncludes( manualInclude );
+ if (!StringUtils.isEmpty(manualInclude)) {
+ manualIncludes = this.parseIncludes(manualInclude);
}
// If it's a manual purge, the only step is to delete from the local repo
- if ( manualIncludes != null && manualIncludes.size() > 0 )
- {
- manualPurge( manualIncludes );
+ if (manualIncludes != null && manualIncludes.size() > 0) {
+ manualPurge(manualIncludes);
return;
}
Set purgedArtifacts = new HashSet<>();
- if ( shouldPurgeAllProjectsInReactor() )
- {
- for ( MavenProject reactorProject : reactorProjects )
- {
- purgeLocalRepository( reactorProject, purgedArtifacts );
+ if (shouldPurgeAllProjectsInReactor()) {
+ for (MavenProject reactorProject : reactorProjects) {
+ purgeLocalRepository(reactorProject, purgedArtifacts);
}
- }
- else
- {
- purgeLocalRepository( project, purgedArtifacts );
+ } else {
+ purgeLocalRepository(project, purgedArtifacts);
}
}
@@ -352,8 +322,7 @@ public void execute()
*
* @return true
if all projects in the reactor should be purged, false
otherwise.
*/
- private boolean shouldPurgeAllProjectsInReactor()
- {
+ private boolean shouldPurgeAllProjectsInReactor() {
Source source = mojoExecution.getSource();
return reactorProjects.size() > 1 && source == Source.CLI;
}
@@ -365,36 +334,30 @@ private boolean shouldPurgeAllProjectsInReactor()
* @param purgedArtifacts The artifacts that were already purged.
* @throws MojoFailureException in case of errors during the purge.
*/
- private void purgeLocalRepository( MavenProject theProject, Set purgedArtifacts )
- throws MojoFailureException
- {
+ private void purgeLocalRepository(MavenProject theProject, Set purgedArtifacts)
+ throws MojoFailureException {
List dependencies = theProject.getDependencies();
- TransformableFilter dependencyFilter = createPurgeArtifactsFilter( theProject, dependencies, purgedArtifacts );
+ TransformableFilter dependencyFilter = createPurgeArtifactsFilter(theProject, dependencies, purgedArtifacts);
Set resolvedArtifactsToPurge =
- getFilteredResolvedArtifacts( theProject, dependencies, dependencyFilter );
+ getFilteredResolvedArtifacts(theProject, dependencies, dependencyFilter);
- if ( resolvedArtifactsToPurge.isEmpty() )
- {
- getLog().info( "No artifacts included for purge for project: " + getProjectKey( theProject ) );
+ if (resolvedArtifactsToPurge.isEmpty()) {
+ getLog().info("No artifacts included for purge for project: " + getProjectKey(theProject));
return;
}
- purgeArtifacts( theProject, resolvedArtifactsToPurge );
- purgedArtifacts.addAll( resolvedArtifactsToPurge );
+ purgeArtifacts(theProject, resolvedArtifactsToPurge);
+ purgedArtifacts.addAll(resolvedArtifactsToPurge);
- if ( reResolve )
- {
- getLog().info( "Re-resolving dependencies" );
- try
- {
- reResolveArtifacts( theProject, resolvedArtifactsToPurge );
- }
- catch ( ArtifactResolutionException e )
- {
+ if (reResolve) {
+ getLog().info("Re-resolving dependencies");
+ try {
+ reResolveArtifacts(theProject, resolvedArtifactsToPurge);
+ } catch (ArtifactResolutionException e) {
String failureMessage = "Failed to refresh project dependencies for: " + theProject.getId();
- throw new MojoFailureException( failureMessage, e );
+ throw new MojoFailureException(failureMessage, e);
}
}
}
@@ -405,49 +368,40 @@ private void purgeLocalRepository( MavenProject theProject, Set purged
* @param theIncludes The includes.
* @throws MojoExecutionException in case of an error.
*/
- private void manualPurge( List theIncludes )
- throws MojoExecutionException
- {
+ private void manualPurge(List theIncludes) throws MojoExecutionException {
MessageBuilder messageBuilder = MessageUtils.buffer();
- getLog().info( messageBuilder.a( "Deleting " ).strong( theIncludes.size() )
- .a( " manual " )
- .a( theIncludes.size() != 1 ? "dependencies" : "dependency" )
- .a( " from " )
- .strong( localRepository.getBasedir() )
- .toString() );
-
- for ( String gavPattern : theIncludes )
- {
- if ( StringUtils.isEmpty( gavPattern ) )
- {
- getLog().debug( "Skipping empty gav pattern" );
+ getLog().info(messageBuilder
+ .a("Deleting ")
+ .strong(theIncludes.size())
+ .a(" manual ")
+ .a(theIncludes.size() != 1 ? "dependencies" : "dependency")
+ .a(" from ")
+ .strong(localRepository.getBasedir())
+ .toString());
+
+ for (String gavPattern : theIncludes) {
+ if (StringUtils.isEmpty(gavPattern)) {
+ getLog().debug("Skipping empty gav pattern");
continue;
}
- String relativePath = gavToPath( gavPattern );
- if ( StringUtils.isEmpty( relativePath ) )
- {
- getLog().debug( "Skipping empty relative path for gav pattern: " + gavPattern );
+ String relativePath = gavToPath(gavPattern);
+ if (StringUtils.isEmpty(relativePath)) {
+ getLog().debug("Skipping empty relative path for gav pattern: " + gavPattern);
continue;
}
- File purgeDir = new File( localRepository.getBasedir(), relativePath );
- if ( purgeDir.exists() )
- {
- getLog().debug( "Deleting directory: " + purgeDir );
- try
- {
- FileUtils.deleteDirectory( purgeDir );
- }
- catch ( IOException e )
- {
- throw new MojoExecutionException( "Unable to purge directory: " + purgeDir );
+ File purgeDir = new File(localRepository.getBasedir(), relativePath);
+ if (purgeDir.exists()) {
+ getLog().debug("Deleting directory: " + purgeDir);
+ try {
+ FileUtils.deleteDirectory(purgeDir);
+ } catch (IOException e) {
+ throw new MojoExecutionException("Unable to purge directory: " + purgeDir);
}
- }
- else
- {
- getLog().debug( "Directory: " + purgeDir + " doesn't exist" );
+ } else {
+ getLog().debug("Directory: " + purgeDir + " doesn't exist");
}
}
}
@@ -458,20 +412,17 @@ private void manualPurge( List theIncludes )
* @param gav the groupId:artifactId:version string
* @return the corresponding path
*/
- private String gavToPath( String gav )
- {
- if ( StringUtils.isEmpty( gav ) )
- {
+ private String gavToPath(String gav) {
+ if (StringUtils.isEmpty(gav)) {
return null;
}
- String[] pathComponents = gav.split( ":" );
+ String[] pathComponents = gav.split(":");
- StringBuilder path = new StringBuilder( pathComponents[0].replace( '.', '/' ) );
+ StringBuilder path = new StringBuilder(pathComponents[0].replace('.', '/'));
- for ( int i = 1; i < pathComponents.length; ++i )
- {
- path.append( "/" ).append( pathComponents[i] );
+ for (int i = 1; i < pathComponents.length; ++i) {
+ path.append("/").append(pathComponents[i]);
}
return path.toString();
@@ -486,57 +437,48 @@ private String gavToPath( String gav )
* @param purgedArtifacts The artifacts already purged.
* @return the created filter
*/
- private TransformableFilter createPurgeArtifactsFilter( MavenProject theProject, List dependencies,
- Set purgedArtifacts )
- {
+ private TransformableFilter createPurgeArtifactsFilter(
+ MavenProject theProject, List dependencies, Set purgedArtifacts) {
List subFilters = new ArrayList<>();
// System dependencies should never be purged
- subFilters.add( ScopeFilter.excluding( Artifact.SCOPE_SYSTEM ) );
+ subFilters.add(ScopeFilter.excluding(Artifact.SCOPE_SYSTEM));
- if ( this.snapshotsOnly )
- {
- subFilters.add( new SnapshotsFilter() );
+ if (this.snapshotsOnly) {
+ subFilters.add(new SnapshotsFilter());
}
// The CLI includes/excludes overrides configuration in the pom
- if ( !StringUtils.isEmpty( this.include ) )
- {
- this.includes = parseIncludes( this.include );
+ if (!StringUtils.isEmpty(this.include)) {
+ this.includes = parseIncludes(this.include);
}
- if ( this.includes != null )
- {
- subFilters.add( new PatternInclusionsFilter( includes ) );
+ if (this.includes != null) {
+ subFilters.add(new PatternInclusionsFilter(includes));
}
- if ( !StringUtils.isEmpty( this.exclude ) )
- {
- this.excludes = parseIncludes( this.exclude );
+ if (!StringUtils.isEmpty(this.exclude)) {
+ this.excludes = parseIncludes(this.exclude);
}
- if ( this.excludes != null )
- {
- subFilters.add( new PatternExclusionsFilter( excludes ) );
+ if (this.excludes != null) {
+ subFilters.add(new PatternExclusionsFilter(excludes));
}
- if ( !actTransitively )
- {
- subFilters.add( new DirectDependencyFilter( theProject.getArtifact(), dependencies ) );
+ if (!actTransitively) {
+ subFilters.add(new DirectDependencyFilter(theProject.getArtifact(), dependencies));
}
- List exclusions = new ArrayList<>( reactorProjects.size() );
+ List exclusions = new ArrayList<>(reactorProjects.size());
// It doesn't make sense to include projects from the reactor here since they're likely not able to be resolved
- for ( MavenProject reactorProject : reactorProjects )
- {
- exclusions.add( toPatternExcludes( reactorProject.getArtifact() ) );
+ for (MavenProject reactorProject : reactorProjects) {
+ exclusions.add(toPatternExcludes(reactorProject.getArtifact()));
}
// There is no need to consider a second time artifacts that were already purged (re-resolved or not)
- for ( Artifact purgedArtifact : purgedArtifacts )
- {
- exclusions.add( toPatternExcludes( purgedArtifact ) );
+ for (Artifact purgedArtifact : purgedArtifacts) {
+ exclusions.add(toPatternExcludes(purgedArtifact));
}
- subFilters.add( new PatternExclusionsFilter( exclusions ) );
+ subFilters.add(new PatternExclusionsFilter(exclusions));
- return new AndFilter( subFilters );
+ return new AndFilter(subFilters);
}
/**
@@ -545,10 +487,9 @@ private TransformableFilter createPurgeArtifactsFilter( MavenProject theProject,
* @param artifact Artifact.
* @return String representation of a pattern for an exclude filter for the given artifact.
*/
- private String toPatternExcludes( Artifact artifact )
- {
+ private String toPatternExcludes(Artifact artifact) {
return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":"
- + artifact.getArtifactHandler().getExtension() + ":" + artifact.getVersion();
+ + artifact.getArtifactHandler().getExtension() + ":" + artifact.getVersion();
}
/**
@@ -557,184 +498,155 @@ private String toPatternExcludes( Artifact artifact )
* @param theInclude The list of includes
* @return the includes list
*/
- private List parseIncludes( String theInclude )
- {
+ private List parseIncludes(String theInclude) {
List theIncludes = new ArrayList<>();
- if ( theInclude != null )
- {
- String[] elements = theInclude.split( "," );
- theIncludes.addAll( Arrays.asList( elements ) );
+ if (theInclude != null) {
+ String[] elements = theInclude.split(",");
+ theIncludes.addAll(Arrays.asList(elements));
}
return theIncludes;
}
- private Set getFilteredResolvedArtifacts( MavenProject theProject, List dependencies,
- TransformableFilter filter )
- {
- try
- {
- Iterable results =
- dependencyResolver.resolveDependencies( session.getProjectBuildingRequest(), theProject.getModel(),
- filter );
+ private Set getFilteredResolvedArtifacts(
+ MavenProject theProject, List dependencies, TransformableFilter filter) {
+ try {
+ Iterable results = dependencyResolver.resolveDependencies(
+ session.getProjectBuildingRequest(), theProject.getModel(), filter);
Set resolvedArtifacts = new LinkedHashSet<>();
- for ( ArtifactResult artResult : results )
- {
- resolvedArtifacts.add( artResult.getArtifact() );
+ for (ArtifactResult artResult : results) {
+ resolvedArtifacts.add(artResult.getArtifact());
}
return resolvedArtifacts;
- }
- catch ( DependencyResolverException e )
- {
- getLog().info( "Unable to resolve all dependencies for: " + getProjectKey( theProject )
- + ". Falling back to non-transitive mode for initial artifact resolution." );
+ } catch (DependencyResolverException e) {
+ getLog().info("Unable to resolve all dependencies for: " + getProjectKey(theProject)
+ + ". Falling back to non-transitive mode for initial artifact resolution.");
}
Set resolvedArtifacts = new LinkedHashSet<>();
- ArtifactFilter artifactFilter = filter.transform( new ArtifactIncludeFilterTransformer() );
+ ArtifactFilter artifactFilter = filter.transform(new ArtifactIncludeFilterTransformer());
- for ( Dependency dependency : dependencies )
- {
+ for (Dependency dependency : dependencies) {
DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate();
- coordinate.setGroupId( dependency.getGroupId() );
- coordinate.setArtifactId( dependency.getArtifactId() );
- coordinate.setVersion( dependency.getVersion() );
- coordinate.setExtension( artifactHandlerManager.getArtifactHandler( dependency.getType() ).getExtension() );
- try
- {
- Artifact artifact =
- artifactResolver.resolveArtifact( session.getProjectBuildingRequest(), coordinate ).getArtifact();
- if ( artifactFilter.include( artifact ) )
- {
- resolvedArtifacts.add( artifact );
+ coordinate.setGroupId(dependency.getGroupId());
+ coordinate.setArtifactId(dependency.getArtifactId());
+ coordinate.setVersion(dependency.getVersion());
+ coordinate.setExtension(artifactHandlerManager
+ .getArtifactHandler(dependency.getType())
+ .getExtension());
+ try {
+ Artifact artifact = artifactResolver
+ .resolveArtifact(session.getProjectBuildingRequest(), coordinate)
+ .getArtifact();
+ if (artifactFilter.include(artifact)) {
+ resolvedArtifacts.add(artifact);
}
- }
- catch ( ArtifactResolverException e )
- {
- getLog().debug( "Unable to resolve artifact: " + coordinate );
+ } catch (ArtifactResolverException e) {
+ getLog().debug("Unable to resolve artifact: " + coordinate);
}
}
return resolvedArtifacts;
}
- private void purgeArtifacts( MavenProject theProject, Set artifacts )
- {
+ private void purgeArtifacts(MavenProject theProject, Set artifacts) {
MessageBuilder messageBuilder = MessageUtils.buffer();
- getLog().info( messageBuilder.a( "Deleting " ).strong( artifacts.size() )
- .a( " " ).strong( actTransitively ? "transitive" : "direct" )
- .a( artifacts.size() != 1 ? " dependencies" : " dependency" )
- .a( " for project " ).strong( getProjectKey( theProject ) )
- .a( " from " ).strong( localRepository.getBasedir() )
- .a( " with artifact " ).strong( resolutionFuzziness ).a( " resolution fuzziness" )
- .toString() );
-
- for ( Artifact artifact : artifacts )
- {
- verbose( "Purging artifact: " + artifact.getId() );
-
- File deleteTarget = findDeleteTarget( artifact );
-
- verbose( "Deleting: " + deleteTarget );
-
- if ( deleteTarget.isDirectory() )
- {
- try
- {
- FileUtils.deleteDirectory( deleteTarget );
- }
- catch ( IOException e )
- {
- getLog().warn( "Unable to purge local repository location: " + deleteTarget, e );
+ getLog().info(messageBuilder
+ .a("Deleting ")
+ .strong(artifacts.size())
+ .a(" ")
+ .strong(actTransitively ? "transitive" : "direct")
+ .a(artifacts.size() != 1 ? " dependencies" : " dependency")
+ .a(" for project ")
+ .strong(getProjectKey(theProject))
+ .a(" from ")
+ .strong(localRepository.getBasedir())
+ .a(" with artifact ")
+ .strong(resolutionFuzziness)
+ .a(" resolution fuzziness")
+ .toString());
+
+ for (Artifact artifact : artifacts) {
+ verbose("Purging artifact: " + artifact.getId());
+
+ File deleteTarget = findDeleteTarget(artifact);
+
+ verbose("Deleting: " + deleteTarget);
+
+ if (deleteTarget.isDirectory()) {
+ try {
+ FileUtils.deleteDirectory(deleteTarget);
+ } catch (IOException e) {
+ getLog().warn("Unable to purge local repository location: " + deleteTarget, e);
}
- }
- else
- {
- if ( !deleteTarget.delete() )
- {
+ } else {
+ if (!deleteTarget.delete()) {
deleteTarget.deleteOnExit();
- getLog().warn( "Unable to purge local repository location immediately: " + deleteTarget );
+ getLog().warn("Unable to purge local repository location immediately: " + deleteTarget);
}
}
- artifact.setResolved( false );
+ artifact.setResolved(false);
}
}
- private void reResolveArtifacts( MavenProject theProject, Set artifacts )
- throws ArtifactResolutionException
- {
+ private void reResolveArtifacts(MavenProject theProject, Set artifacts)
+ throws ArtifactResolutionException {
// Always need to re-resolve the poms in case they were purged along with the artifact
// because Maven 2 will not automatically re-resolve them when resolving the artifact
- for ( Artifact artifact : artifacts )
- {
- verbose( "Resolving artifact: " + artifact.getId() );
-
- try
- {
- //CHECKSTYLE_OFF: LineLength
- artifactResolver.resolveArtifact( session.getProjectBuildingRequest(),
- TransferUtils.toArtifactCoordinate( artifact ) );
- //CHECKSTYLE_ON: LineLength
- }
- catch ( ArtifactResolverException e )
- {
- verbose( e.getMessage() );
+ for (Artifact artifact : artifacts) {
+ verbose("Resolving artifact: " + artifact.getId());
+
+ try {
+ // CHECKSTYLE_OFF: LineLength
+ artifactResolver.resolveArtifact(
+ session.getProjectBuildingRequest(), TransferUtils.toArtifactCoordinate(artifact));
+ // CHECKSTYLE_ON: LineLength
+ } catch (ArtifactResolverException e) {
+ verbose(e.getMessage());
}
}
List missingArtifacts = new ArrayList<>();
- for ( Artifact artifact : artifacts )
- {
- try
- {
- artifactResolver.resolveArtifact( session.getProjectBuildingRequest(), artifact );
- }
- catch ( ArtifactResolverException e )
- {
- verbose( e.getMessage() );
- missingArtifacts.add( artifact );
+ for (Artifact artifact : artifacts) {
+ try {
+ artifactResolver.resolveArtifact(session.getProjectBuildingRequest(), artifact);
+ } catch (ArtifactResolverException e) {
+ verbose(e.getMessage());
+ missingArtifacts.add(artifact);
}
}
- if ( missingArtifacts.size() > 0 )
- {
- StringBuilder message = new StringBuilder( "required artifacts missing:" );
- message.append( System.lineSeparator() );
- for ( Artifact missingArtifact : missingArtifacts )
- {
- message.append( " " ).append( missingArtifact.getId() ).append( System.lineSeparator() );
+ if (missingArtifacts.size() > 0) {
+ StringBuilder message = new StringBuilder("required artifacts missing:");
+ message.append(System.lineSeparator());
+ for (Artifact missingArtifact : missingArtifacts) {
+ message.append(" ").append(missingArtifact.getId()).append(System.lineSeparator());
}
- message.append( System.lineSeparator() );
- message.append( "for the artifact:" );
+ message.append(System.lineSeparator());
+ message.append("for the artifact:");
- throw new ArtifactResolutionException( message.toString(), theProject.getArtifact(),
- theProject.getRemoteArtifactRepositories() );
+ throw new ArtifactResolutionException(
+ message.toString(), theProject.getArtifact(), theProject.getRemoteArtifactRepositories());
}
}
- private File findDeleteTarget( Artifact artifact )
- {
+ private File findDeleteTarget(Artifact artifact) {
// Use localRepository.pathOf() in case artifact.getFile() is not set
- File deleteTarget = new File( localRepository.getBasedir(), localRepository.pathOf( artifact ) );
+ File deleteTarget = new File(localRepository.getBasedir(), localRepository.pathOf(artifact));
- if ( GROUP_ID_FUZZINESS.equals( resolutionFuzziness ) )
- {
+ if (GROUP_ID_FUZZINESS.equals(resolutionFuzziness)) {
// get the groupId dir.
deleteTarget = deleteTarget.getParentFile().getParentFile().getParentFile();
- }
- else if ( ARTIFACT_ID_FUZZINESS.equals( resolutionFuzziness ) )
- {
+ } else if (ARTIFACT_ID_FUZZINESS.equals(resolutionFuzziness)) {
// get the artifactId dir.
deleteTarget = deleteTarget.getParentFile().getParentFile();
- }
- else if ( VERSION_FUZZINESS.equals( resolutionFuzziness ) )
- {
+ } else if (VERSION_FUZZINESS.equals(resolutionFuzziness)) {
// get the version dir.
deleteTarget = deleteTarget.getParentFile();
}
@@ -742,32 +654,27 @@ else if ( VERSION_FUZZINESS.equals( resolutionFuzziness ) )
return deleteTarget;
}
- private void verbose( String message )
- {
- if ( verbose || getLog().isDebugEnabled() )
- {
- getLog().info( message );
+ private void verbose(String message) {
+ if (verbose || getLog().isDebugEnabled()) {
+ getLog().info(message);
}
}
- private String getProjectKey( MavenProject project )
- {
+ private String getProjectKey(MavenProject project) {
return project.getArtifactId();
}
/**
* @return {@link #skip}
*/
- public boolean isSkip()
- {
+ public boolean isSkip() {
return skip;
}
/**
* @param skip {@link #skip}
*/
- public void setSkip( boolean skip )
- {
+ public void setSkip(boolean skip) {
this.skip = skip;
}
}
diff --git a/src/main/java/org/apache/maven/plugins/dependency/analyze/AbstractAnalyzeMojo.java b/src/main/java/org/apache/maven/plugins/dependency/analyze/AbstractAnalyzeMojo.java
index e069bd464..00186de95 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/analyze/AbstractAnalyzeMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/analyze/AbstractAnalyzeMojo.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.dependency.analyze;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
@@ -18,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.dependency.analyze;
import java.io.File;
import java.io.StringWriter;
@@ -29,7 +28,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
-
import org.apache.commons.lang3.StringUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
@@ -55,10 +53,7 @@
* @author Mark Hobson
* @since 2.0-alpha-5
*/
-public abstract class AbstractAnalyzeMojo
- extends AbstractMojo
- implements Contextualizable
-{
+public abstract class AbstractAnalyzeMojo extends AbstractMojo implements Contextualizable {
// fields -----------------------------------------------------------------
/**
@@ -70,7 +65,7 @@ public abstract class AbstractAnalyzeMojo
/**
* The Maven project to analyze.
*/
- @Parameter( defaultValue = "${project}", readonly = true, required = true )
+ @Parameter(defaultValue = "${project}", readonly = true, required = true)
private MavenProject project;
/**
@@ -81,19 +76,19 @@ public abstract class AbstractAnalyzeMojo
*
* @since 2.2
*/
- @Parameter( property = "analyzer", defaultValue = "default" )
+ @Parameter(property = "analyzer", defaultValue = "default")
private String analyzer;
/**
* Whether to fail the build if a dependency warning is found.
*/
- @Parameter( property = "failOnWarning", defaultValue = "false" )
+ @Parameter(property = "failOnWarning", defaultValue = "false")
private boolean failOnWarning;
/**
* Output used dependencies.
*/
- @Parameter( property = "verbose", defaultValue = "false" )
+ @Parameter(property = "verbose", defaultValue = "false")
private boolean verbose;
/**
@@ -101,7 +96,7 @@ public abstract class AbstractAnalyzeMojo
*
* Non-test scoped
list will be not affected.
*/
- @Parameter( property = "ignoreNonCompile", defaultValue = "false" )
+ @Parameter(property = "ignoreNonCompile", defaultValue = "false")
private boolean ignoreNonCompile;
/**
@@ -109,7 +104,7 @@ public abstract class AbstractAnalyzeMojo
*
* @since 3.2.0
*/
- @Parameter( property = "ignoreUnusedRuntime", defaultValue = "false" )
+ @Parameter(property = "ignoreUnusedRuntime", defaultValue = "false")
private boolean ignoreUnusedRuntime;
/**
@@ -120,7 +115,7 @@ public abstract class AbstractAnalyzeMojo
*
* @since 3.3.1-SNAPSHOT
*/
- @Parameter( property = "ignoreAllNonTestScoped", defaultValue = "false" )
+ @Parameter(property = "ignoreAllNonTestScoped", defaultValue = "false")
private boolean ignoreAllNonTestScoped;
/**
@@ -128,7 +123,7 @@ public abstract class AbstractAnalyzeMojo
*
* @since 2.0-alpha-5
*/
- @Parameter( property = "outputXML", defaultValue = "false" )
+ @Parameter(property = "outputXML", defaultValue = "false")
private boolean outputXML;
/**
@@ -136,7 +131,7 @@ public abstract class AbstractAnalyzeMojo
*
* @since 2.0-alpha-5
*/
- @Parameter( property = "scriptableOutput", defaultValue = "false" )
+ @Parameter(property = "scriptableOutput", defaultValue = "false")
private boolean scriptableOutput;
/**
@@ -144,7 +139,7 @@ public abstract class AbstractAnalyzeMojo
*
* @since 2.0-alpha-5
*/
- @Parameter( property = "scriptableFlag", defaultValue = "$$$%%%" )
+ @Parameter(property = "scriptableFlag", defaultValue = "$$$%%%")
private String scriptableFlag;
/**
@@ -152,7 +147,7 @@ public abstract class AbstractAnalyzeMojo
*
* @since 2.0-alpha-5
*/
- @Parameter( defaultValue = "${basedir}", readonly = true )
+ @Parameter(defaultValue = "${basedir}", readonly = true)
private File baseDir;
/**
@@ -160,7 +155,7 @@ public abstract class AbstractAnalyzeMojo
*
* @since 2.0-alpha-5
*/
- @Parameter( defaultValue = "${project.build.directory}", readonly = true )
+ @Parameter(defaultValue = "${project.build.directory}", readonly = true)
private File outputDirectory;
/**
@@ -177,7 +172,7 @@ public abstract class AbstractAnalyzeMojo
*
* @since 2.7
*/
- @Parameter( property = "mdep.analyze.skip", defaultValue = "false" )
+ @Parameter(property = "mdep.analyze.skip", defaultValue = "false")
private boolean skip;
/**
@@ -268,7 +263,7 @@ public abstract class AbstractAnalyzeMojo
// defaultValue value on @Parameter - not work with Maven 3.2.5
// When is set defaultValue always win, and there is no possibility to override by plugin configuration.
@Parameter
- private List ignoredPackagings = Arrays.asList( "pom", "ear" );
+ private List ignoredPackagings = Arrays.asList("pom", "ear");
// Mojo methods -----------------------------------------------------------
@@ -276,32 +271,26 @@ public abstract class AbstractAnalyzeMojo
* @see org.apache.maven.plugin.Mojo#execute()
*/
@Override
- public void execute()
- throws MojoExecutionException, MojoFailureException
- {
- if ( isSkip() )
- {
- getLog().info( "Skipping plugin execution" );
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ if (isSkip()) {
+ getLog().info("Skipping plugin execution");
return;
}
- if ( ignoredPackagings.contains( project.getPackaging() ) )
- {
- getLog().info( "Skipping " + project.getPackaging() + " project" );
+ if (ignoredPackagings.contains(project.getPackaging())) {
+ getLog().info("Skipping " + project.getPackaging() + " project");
return;
}
- if ( outputDirectory == null || !outputDirectory.exists() )
- {
- getLog().info( "Skipping project with no build directory" );
+ if (outputDirectory == null || !outputDirectory.exists()) {
+ getLog().info("Skipping project with no build directory");
return;
}
boolean warning = checkDependencies();
- if ( warning && failOnWarning )
- {
- throw new MojoExecutionException( "Dependency problems found" );
+ if (warning && failOnWarning) {
+ throw new MojoExecutionException("Dependency problems found");
}
}
@@ -309,344 +298,277 @@ public void execute()
* @return {@link ProjectDependencyAnalyzer}
* @throws MojoExecutionException in case of an error.
*/
- protected ProjectDependencyAnalyzer createProjectDependencyAnalyzer()
- throws MojoExecutionException
- {
- try
- {
- final PlexusContainer container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
- return container.lookup( ProjectDependencyAnalyzer.class, analyzer );
- }
- catch ( Exception exception )
- {
- throw new MojoExecutionException( "Failed to instantiate ProjectDependencyAnalyser"
- + " / role-hint " + analyzer, exception );
+ protected ProjectDependencyAnalyzer createProjectDependencyAnalyzer() throws MojoExecutionException {
+ try {
+ final PlexusContainer container = (PlexusContainer) context.get(PlexusConstants.PLEXUS_KEY);
+ return container.lookup(ProjectDependencyAnalyzer.class, analyzer);
+ } catch (Exception exception) {
+ throw new MojoExecutionException(
+ "Failed to instantiate ProjectDependencyAnalyser" + " / role-hint " + analyzer, exception);
}
}
@Override
- public void contextualize( Context theContext )
- {
+ public void contextualize(Context theContext) {
this.context = theContext;
}
/**
* @return {@link #skip}
*/
- protected final boolean isSkip()
- {
+ protected final boolean isSkip() {
return skip;
}
// private methods --------------------------------------------------------
- private boolean checkDependencies()
- throws MojoExecutionException
- {
+ private boolean checkDependencies() throws MojoExecutionException {
ProjectDependencyAnalysis analysis;
- try
- {
- analysis = createProjectDependencyAnalyzer().analyze( project );
+ try {
+ analysis = createProjectDependencyAnalyzer().analyze(project);
- if ( usedDependencies != null )
- {
- analysis = analysis.forceDeclaredDependenciesUsage( usedDependencies );
+ if (usedDependencies != null) {
+ analysis = analysis.forceDeclaredDependenciesUsage(usedDependencies);
}
- }
- catch ( ProjectDependencyAnalyzerException exception )
- {
- throw new MojoExecutionException( "Cannot analyze dependencies", exception );
+ } catch (ProjectDependencyAnalyzerException exception) {
+ throw new MojoExecutionException("Cannot analyze dependencies", exception);
}
- if ( ignoreNonCompile )
- {
+ if (ignoreNonCompile) {
analysis = analysis.ignoreNonCompile();
}
- Set usedDeclared = new LinkedHashSet<>( analysis.getUsedDeclaredArtifacts() );
+ Set usedDeclared = new LinkedHashSet<>(analysis.getUsedDeclaredArtifacts());
Map> usedUndeclaredWithClasses =
- new LinkedHashMap<>( analysis.getUsedUndeclaredArtifactsWithClasses() );
- Set unusedDeclared = new LinkedHashSet<>( analysis.getUnusedDeclaredArtifacts() );
- Set nonTestScope = new LinkedHashSet<>( analysis.getTestArtifactsWithNonTestScope() );
+ new LinkedHashMap<>(analysis.getUsedUndeclaredArtifactsWithClasses());
+ Set unusedDeclared = new LinkedHashSet<>(analysis.getUnusedDeclaredArtifacts());
+ Set nonTestScope = new LinkedHashSet<>(analysis.getTestArtifactsWithNonTestScope());
Set ignoredUsedUndeclared = new LinkedHashSet<>();
Set ignoredUnusedDeclared = new LinkedHashSet<>();
Set ignoredNonTestScope = new LinkedHashSet<>();
- if ( ignoreUnusedRuntime )
- {
- filterArtifactsByScope( unusedDeclared, Artifact.SCOPE_RUNTIME );
+ if (ignoreUnusedRuntime) {
+ filterArtifactsByScope(unusedDeclared, Artifact.SCOPE_RUNTIME);
}
- ignoredUsedUndeclared.addAll( filterDependencies( usedUndeclaredWithClasses.keySet(), ignoredDependencies ) );
- ignoredUsedUndeclared.addAll( filterDependencies( usedUndeclaredWithClasses.keySet(),
- ignoredUsedUndeclaredDependencies ) );
+ ignoredUsedUndeclared.addAll(filterDependencies(usedUndeclaredWithClasses.keySet(), ignoredDependencies));
+ ignoredUsedUndeclared.addAll(
+ filterDependencies(usedUndeclaredWithClasses.keySet(), ignoredUsedUndeclaredDependencies));
- ignoredUnusedDeclared.addAll( filterDependencies( unusedDeclared, ignoredDependencies ) );
- ignoredUnusedDeclared.addAll( filterDependencies( unusedDeclared, ignoredUnusedDeclaredDependencies ) );
+ ignoredUnusedDeclared.addAll(filterDependencies(unusedDeclared, ignoredDependencies));
+ ignoredUnusedDeclared.addAll(filterDependencies(unusedDeclared, ignoredUnusedDeclaredDependencies));
- if ( ignoreAllNonTestScoped )
- {
- ignoredNonTestScope.addAll( filterDependencies ( nonTestScope, new String [] { "*" } ) );
- }
- else
- {
- ignoredNonTestScope.addAll( filterDependencies( nonTestScope, ignoredDependencies ) );
- ignoredNonTestScope.addAll( filterDependencies( nonTestScope, ignoredNonTestScopedDependencies ) );
+ if (ignoreAllNonTestScoped) {
+ ignoredNonTestScope.addAll(filterDependencies(nonTestScope, new String[] {"*"}));
+ } else {
+ ignoredNonTestScope.addAll(filterDependencies(nonTestScope, ignoredDependencies));
+ ignoredNonTestScope.addAll(filterDependencies(nonTestScope, ignoredNonTestScopedDependencies));
}
boolean reported = false;
boolean warning = false;
- if ( verbose && !usedDeclared.isEmpty() )
- {
- getLog().info( "Used declared dependencies found:" );
+ if (verbose && !usedDeclared.isEmpty()) {
+ getLog().info("Used declared dependencies found:");
- logArtifacts( analysis.getUsedDeclaredArtifacts(), false );
+ logArtifacts(analysis.getUsedDeclaredArtifacts(), false);
reported = true;
}
- if ( !usedUndeclaredWithClasses.isEmpty() )
- {
- logDependencyWarning( "Used undeclared dependencies found:" );
+ if (!usedUndeclaredWithClasses.isEmpty()) {
+ logDependencyWarning("Used undeclared dependencies found:");
- if ( verbose )
- {
- logArtifacts( usedUndeclaredWithClasses, true );
- }
- else
- {
- logArtifacts( usedUndeclaredWithClasses.keySet(), true );
+ if (verbose) {
+ logArtifacts(usedUndeclaredWithClasses, true);
+ } else {
+ logArtifacts(usedUndeclaredWithClasses.keySet(), true);
}
reported = true;
warning = true;
}
- if ( !unusedDeclared.isEmpty() )
- {
- logDependencyWarning( "Unused declared dependencies found:" );
+ if (!unusedDeclared.isEmpty()) {
+ logDependencyWarning("Unused declared dependencies found:");
- logArtifacts( unusedDeclared, true );
+ logArtifacts(unusedDeclared, true);
reported = true;
warning = true;
}
- if ( !nonTestScope.isEmpty() )
- {
- logDependencyWarning( "Non-test scoped test only dependencies found:" );
+ if (!nonTestScope.isEmpty()) {
+ logDependencyWarning("Non-test scoped test only dependencies found:");
- logArtifacts( nonTestScope, true );
+ logArtifacts(nonTestScope, true);
reported = true;
warning = true;
}
- if ( verbose && !ignoredUsedUndeclared.isEmpty() )
- {
- getLog().info( "Ignored used undeclared dependencies:" );
+ if (verbose && !ignoredUsedUndeclared.isEmpty()) {
+ getLog().info("Ignored used undeclared dependencies:");
- logArtifacts( ignoredUsedUndeclared, false );
+ logArtifacts(ignoredUsedUndeclared, false);
reported = true;
}
- if ( verbose && !ignoredUnusedDeclared.isEmpty() )
- {
- getLog().info( "Ignored unused declared dependencies:" );
+ if (verbose && !ignoredUnusedDeclared.isEmpty()) {
+ getLog().info("Ignored unused declared dependencies:");
- logArtifacts( ignoredUnusedDeclared, false );
+ logArtifacts(ignoredUnusedDeclared, false);
reported = true;
}
- if ( verbose && !ignoredNonTestScope.isEmpty() )
- {
- getLog().info( "Ignored non-test scoped test only dependencies:" );
+ if (verbose && !ignoredNonTestScope.isEmpty()) {
+ getLog().info("Ignored non-test scoped test only dependencies:");
- logArtifacts( ignoredNonTestScope, false );
+ logArtifacts(ignoredNonTestScope, false);
reported = true;
}
- if ( outputXML )
- {
- writeDependencyXML( usedUndeclaredWithClasses.keySet() );
+ if (outputXML) {
+ writeDependencyXML(usedUndeclaredWithClasses.keySet());
}
- if ( scriptableOutput )
- {
- writeScriptableOutput( usedUndeclaredWithClasses.keySet() );
+ if (scriptableOutput) {
+ writeScriptableOutput(usedUndeclaredWithClasses.keySet());
}
- if ( !reported )
- {
- getLog().info( "No dependency problems found" );
+ if (!reported) {
+ getLog().info("No dependency problems found");
}
return warning;
}
- private void filterArtifactsByScope( Set artifacts, String scope )
- {
- artifacts.removeIf( artifact -> artifact.getScope().equals( scope ) );
+ private void filterArtifactsByScope(Set artifacts, String scope) {
+ artifacts.removeIf(artifact -> artifact.getScope().equals(scope));
}
- private void logArtifacts( Set artifacts, boolean warn )
- {
- if ( artifacts.isEmpty() )
- {
- getLog().info( " None" );
- }
- else
- {
- for ( Artifact artifact : artifacts )
- {
+ private void logArtifacts(Set artifacts, boolean warn) {
+ if (artifacts.isEmpty()) {
+ getLog().info(" None");
+ } else {
+ for (Artifact artifact : artifacts) {
// called because artifact will set the version to -SNAPSHOT only if I do this. MNG-2961
artifact.isSnapshot();
- if ( warn )
- {
- logDependencyWarning( " " + artifact );
- }
- else
- {
- getLog().info( " " + artifact );
+ if (warn) {
+ logDependencyWarning(" " + artifact);
+ } else {
+ getLog().info(" " + artifact);
}
-
}
}
}
- private void logArtifacts( Map> artifacts, boolean warn )
- {
- if ( artifacts.isEmpty() )
- {
- getLog().info( " None" );
- }
- else
- {
- for ( Map.Entry> entry : artifacts.entrySet() )
- {
+ private void logArtifacts(Map> artifacts, boolean warn) {
+ if (artifacts.isEmpty()) {
+ getLog().info(" None");
+ } else {
+ for (Map.Entry> entry : artifacts.entrySet()) {
// called because artifact will set the version to -SNAPSHOT only if I do this. MNG-2961
entry.getKey().isSnapshot();
- if ( warn )
- {
- logDependencyWarning( " " + entry.getKey() );
- for ( String clazz : entry.getValue() )
- {
- logDependencyWarning( " class " + clazz );
+ if (warn) {
+ logDependencyWarning(" " + entry.getKey());
+ for (String clazz : entry.getValue()) {
+ logDependencyWarning(" class " + clazz);
}
- }
- else
- {
- getLog().info( " " + entry.getKey() );
- for ( String clazz : entry.getValue() )
- {
- getLog().info( " class " + clazz );
+ } else {
+ getLog().info(" " + entry.getKey());
+ for (String clazz : entry.getValue()) {
+ getLog().info(" class " + clazz);
}
}
-
}
}
}
- private void logDependencyWarning( CharSequence content )
- {
- if ( failOnWarning )
- {
- getLog().error( content );
- }
- else
- {
- getLog().warn( content );
+ private void logDependencyWarning(CharSequence content) {
+ if (failOnWarning) {
+ getLog().error(content);
+ } else {
+ getLog().warn(content);
}
}
- private void writeDependencyXML( Set artifacts )
- {
- if ( !artifacts.isEmpty() )
- {
- getLog().info( "Add the following to your pom to correct the missing dependencies: " );
+ private void writeDependencyXML(Set artifacts) {
+ if (!artifacts.isEmpty()) {
+ getLog().info("Add the following to your pom to correct the missing dependencies: ");
StringWriter out = new StringWriter();
- PrettyPrintXMLWriter writer = new PrettyPrintXMLWriter( out );
+ PrettyPrintXMLWriter writer = new PrettyPrintXMLWriter(out);
- for ( Artifact artifact : artifacts )
- {
+ for (Artifact artifact : artifacts) {
// called because artifact will set the version to -SNAPSHOT only if I do this. MNG-2961
artifact.isSnapshot();
- writer.startElement( "dependency" );
- writer.startElement( "groupId" );
- writer.writeText( artifact.getGroupId() );
+ writer.startElement("dependency");
+ writer.startElement("groupId");
+ writer.writeText(artifact.getGroupId());
writer.endElement();
- writer.startElement( "artifactId" );
- writer.writeText( artifact.getArtifactId() );
+ writer.startElement("artifactId");
+ writer.writeText(artifact.getArtifactId());
writer.endElement();
- writer.startElement( "version" );
- writer.writeText( artifact.getBaseVersion() );
- if ( !StringUtils.isBlank( artifact.getClassifier() ) )
- {
- writer.startElement( "classifier" );
- writer.writeText( artifact.getClassifier() );
+ writer.startElement("version");
+ writer.writeText(artifact.getBaseVersion());
+ if (!StringUtils.isBlank(artifact.getClassifier())) {
+ writer.startElement("classifier");
+ writer.writeText(artifact.getClassifier());
writer.endElement();
}
writer.endElement();
- if ( !Artifact.SCOPE_COMPILE.equals( artifact.getScope() ) )
- {
- writer.startElement( "scope" );
- writer.writeText( artifact.getScope() );
+ if (!Artifact.SCOPE_COMPILE.equals(artifact.getScope())) {
+ writer.startElement("scope");
+ writer.writeText(artifact.getScope());
writer.endElement();
}
writer.endElement();
}
- getLog().info( System.lineSeparator() + out.getBuffer() );
+ getLog().info(System.lineSeparator() + out.getBuffer());
}
}
- private void writeScriptableOutput( Set artifacts )
- {
- if ( !artifacts.isEmpty() )
- {
- getLog().info( "Missing dependencies: " );
+ private void writeScriptableOutput(Set artifacts) {
+ if (!artifacts.isEmpty()) {
+ getLog().info("Missing dependencies: ");
String pomFile = baseDir.getAbsolutePath() + File.separatorChar + "pom.xml";
StringBuilder buf = new StringBuilder();
- for ( Artifact artifact : artifacts )
- {
+ for (Artifact artifact : artifacts) {
// called because artifact will set the version to -SNAPSHOT only if I do this. MNG-2961
artifact.isSnapshot();
- //CHECKSTYLE_OFF: LineLength
- buf.append( scriptableFlag )
- .append( ":" )
- .append( pomFile )
- .append( ":" )
- .append( artifact.getDependencyConflictId() )
- .append( ":" )
- .append( artifact.getClassifier() )
- .append( ":" )
- .append( artifact.getBaseVersion() )
- .append( ":" )
- .append( artifact.getScope() )
- .append( System.lineSeparator() );
- //CHECKSTYLE_ON: LineLength
+ // CHECKSTYLE_OFF: LineLength
+ buf.append(scriptableFlag)
+ .append(":")
+ .append(pomFile)
+ .append(":")
+ .append(artifact.getDependencyConflictId())
+ .append(":")
+ .append(artifact.getClassifier())
+ .append(":")
+ .append(artifact.getBaseVersion())
+ .append(":")
+ .append(artifact.getScope())
+ .append(System.lineSeparator());
+ // CHECKSTYLE_ON: LineLength
}
- getLog().info( System.lineSeparator() + buf );
+ getLog().info(System.lineSeparator() + buf);
}
}
- private List filterDependencies( Set artifacts, String[] excludes )
- {
- ArtifactFilter filter = new StrictPatternExcludesArtifactFilter( Arrays.asList( excludes ) );
+ private List filterDependencies(Set artifacts, String[] excludes) {
+ ArtifactFilter filter = new StrictPatternExcludesArtifactFilter(Arrays.asList(excludes));
List result = new ArrayList<>();
- for ( Iterator it = artifacts.iterator(); it.hasNext(); )
- {
+ for (Iterator it = artifacts.iterator(); it.hasNext(); ) {
Artifact artifact = it.next();
- if ( !filter.include( artifact ) )
- {
+ if (!filter.include(artifact)) {
it.remove();
- result.add( artifact );
+ result.add(artifact);
}
}
diff --git a/src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeDepMgt.java b/src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeDepMgt.java
index cdc7b963e..afb52f999 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeDepMgt.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeDepMgt.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.dependency.analyze;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
@@ -18,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.dependency.analyze;
import java.util.Collections;
import java.util.HashMap;
@@ -26,7 +25,6 @@
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
-
import org.apache.maven.artifact.Artifact;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.DependencyManagement;
@@ -48,28 +46,26 @@
* @author Brian Fox
* @since 2.0-alpha-3
*/
-@Mojo( name = "analyze-dep-mgt", requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true )
-public class AnalyzeDepMgt
- extends AbstractMojo
-{
+@Mojo(name = "analyze-dep-mgt", requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true)
+public class AnalyzeDepMgt extends AbstractMojo {
// fields -----------------------------------------------------------------
/**
*
*/
- @Parameter( defaultValue = "${project}", readonly = true, required = true )
+ @Parameter(defaultValue = "${project}", readonly = true, required = true)
private MavenProject project;
/**
* Fail the build if a problem is detected.
*/
- @Parameter( property = "mdep.analyze.failBuild", defaultValue = "false" )
+ @Parameter(property = "mdep.analyze.failBuild", defaultValue = "false")
private boolean failBuild = false;
/**
* Ignore Direct Dependency Overrides of dependencyManagement section.
*/
- @Parameter( property = "mdep.analyze.ignore.direct", defaultValue = "true" )
+ @Parameter(property = "mdep.analyze.ignore.direct", defaultValue = "true")
private boolean ignoreDirect = true;
/**
@@ -77,7 +73,7 @@ public class AnalyzeDepMgt
*
* @since 2.7
*/
- @Parameter( property = "mdep.analyze.skip", defaultValue = "false" )
+ @Parameter(property = "mdep.analyze.skip", defaultValue = "false")
private boolean skip;
// Mojo methods -----------------------------------------------------------
@@ -86,26 +82,19 @@ public class AnalyzeDepMgt
* @see org.apache.maven.plugin.Mojo#execute()
*/
@Override
- public void execute()
- throws MojoExecutionException, MojoFailureException
- {
- if ( skip )
- {
- getLog().info( "Skipping plugin execution" );
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ if (skip) {
+ getLog().info("Skipping plugin execution");
return;
}
boolean result = checkDependencyManagement();
- if ( result )
- {
- if ( this.failBuild )
+ if (result) {
+ if (this.failBuild) {
- {
- throw new MojoExecutionException( "Found Dependency errors." );
- }
- else
- {
- getLog().warn( "Potential problems found in Dependency Management " );
+ throw new MojoExecutionException("Found Dependency errors.");
+ } else {
+ getLog().warn("Potential problems found in Dependency Management ");
}
}
}
@@ -116,71 +105,60 @@ public void execute()
* @return true if errors are found.
* @throws MojoExecutionException
*/
- private boolean checkDependencyManagement()
- throws MojoExecutionException
- {
+ private boolean checkDependencyManagement() throws MojoExecutionException {
boolean foundError = false;
- getLog().info( "Found Resolved Dependency/DependencyManagement mismatches:" );
+ getLog().info("Found Resolved Dependency/DependencyManagement mismatches:");
List depMgtDependencies = null;
DependencyManagement depMgt = project.getDependencyManagement();
- if ( depMgt != null )
- {
+ if (depMgt != null) {
depMgtDependencies = depMgt.getDependencies();
}
- if ( depMgtDependencies != null && !depMgtDependencies.isEmpty() )
- {
+ if (depMgtDependencies != null && !depMgtDependencies.isEmpty()) {
// put all the dependencies from depMgt into a map for quick lookup
Map depMgtMap = new HashMap<>();
Map exclusions = new HashMap<>();
- for ( Dependency depMgtDependency : depMgtDependencies )
- {
- depMgtMap.put( depMgtDependency.getManagementKey(), depMgtDependency );
+ for (Dependency depMgtDependency : depMgtDependencies) {
+ depMgtMap.put(depMgtDependency.getManagementKey(), depMgtDependency);
// now put all the exclusions into a map for quick lookup
- exclusions.putAll( addExclusions( depMgtDependency.getExclusions() ) );
+ exclusions.putAll(addExclusions(depMgtDependency.getExclusions()));
}
// get dependencies for the project (including transitive)
- Set allDependencyArtifacts = new LinkedHashSet<>( project.getArtifacts() );
+ Set allDependencyArtifacts = new LinkedHashSet<>(project.getArtifacts());
// don't warn if a dependency that is directly listed overrides
// depMgt. That's ok.
- if ( this.ignoreDirect )
- {
- getLog().info( "\tIgnoring Direct Dependencies." );
+ if (this.ignoreDirect) {
+ getLog().info("\tIgnoring Direct Dependencies.");
Set directDependencies = project.getDependencyArtifacts();
- allDependencyArtifacts.removeAll( directDependencies );
+ allDependencyArtifacts.removeAll(directDependencies);
}
// log exclusion errors
- List exclusionErrors = getExclusionErrors( exclusions, allDependencyArtifacts );
- for ( Artifact exclusion : exclusionErrors )
- {
- getLog().info( StringUtils.stripEnd( getArtifactManagementKey( exclusion ), ":" )
- + " was excluded in DepMgt, but version " + exclusion.getVersion()
- + " has been found in the dependency tree." );
+ List exclusionErrors = getExclusionErrors(exclusions, allDependencyArtifacts);
+ for (Artifact exclusion : exclusionErrors) {
+ getLog().info(StringUtils.stripEnd(getArtifactManagementKey(exclusion), ":")
+ + " was excluded in DepMgt, but version " + exclusion.getVersion()
+ + " has been found in the dependency tree.");
foundError = true;
}
// find and log version mismatches
- Map mismatch = getMismatch( depMgtMap, allDependencyArtifacts );
- for ( Map.Entry entry : mismatch.entrySet() )
- {
- logMismatch( entry.getKey(), entry.getValue() );
+ Map mismatch = getMismatch(depMgtMap, allDependencyArtifacts);
+ for (Map.Entry entry : mismatch.entrySet()) {
+ logMismatch(entry.getKey(), entry.getValue());
foundError = true;
}
- if ( !foundError )
- {
- getLog().info( "\tNone" );
+ if (!foundError) {
+ getLog().info("\tNone");
}
- }
- else
- {
- getLog().info( "\tNothing in DepMgt." );
+ } else {
+ getLog().info("\tNothing in DepMgt.");
}
return foundError;
@@ -192,12 +170,9 @@ private boolean checkDependencyManagement()
* @param exclusionList to be added to the map.
* @return a map of the exclusions using the Dependency ManagementKey as the keyset.
*/
- public Map addExclusions( List exclusionList )
- {
- if ( exclusionList != null )
- {
- return exclusionList.stream()
- .collect( Collectors.toMap( this::getExclusionKey, exclusion -> exclusion ) );
+ public Map addExclusions(List exclusionList) {
+ if (exclusionList != null) {
+ return exclusionList.stream().collect(Collectors.toMap(this::getExclusionKey, exclusion -> exclusion));
}
return Collections.emptyMap();
}
@@ -210,19 +185,17 @@ public Map addExclusions( List exclusionList )
* @param allDependencyArtifacts resolved artifacts to be compared.
* @return list of artifacts that should have been excluded.
*/
- public List getExclusionErrors( Map exclusions, Set allDependencyArtifacts )
- {
+ public List getExclusionErrors(Map exclusions, Set allDependencyArtifacts) {
return allDependencyArtifacts.stream()
- .filter( artifact -> exclusions.containsKey( getExclusionKey( artifact ) ) )
- .collect( Collectors.toList( ) );
+ .filter(artifact -> exclusions.containsKey(getExclusionKey(artifact)))
+ .collect(Collectors.toList());
}
/**
* @param artifact {@link Artifact}
* @return The resulting GA.
*/
- public String getExclusionKey( Artifact artifact )
- {
+ public String getExclusionKey(Artifact artifact) {
return artifact.getGroupId() + ":" + artifact.getArtifactId();
}
@@ -230,8 +203,7 @@ public String getExclusionKey( Artifact artifact )
* @param ex The exclusion key.
* @return The resulting combination of groupId+artifactId.
*/
- public String getExclusionKey( Exclusion ex )
- {
+ public String getExclusionKey(Exclusion ex) {
return ex.getGroupId() + ":" + ex.getArtifactId();
}
@@ -242,23 +214,19 @@ public String getExclusionKey( Exclusion ex )
* @param allDependencyArtifacts contains the set of all artifacts to compare.
* @return a map containing the resolved artifact as the key and the listed dependency as the value.
*/
- public Map getMismatch( Map depMgtMap,
- Set allDependencyArtifacts )
- {
+ public Map getMismatch(
+ Map depMgtMap, Set allDependencyArtifacts) {
Map mismatchMap = new HashMap<>();
- for ( Artifact dependencyArtifact : allDependencyArtifacts )
- {
- Dependency depFromDepMgt = depMgtMap.get( getArtifactManagementKey( dependencyArtifact ) );
- if ( depFromDepMgt != null )
- {
+ for (Artifact dependencyArtifact : allDependencyArtifacts) {
+ Dependency depFromDepMgt = depMgtMap.get(getArtifactManagementKey(dependencyArtifact));
+ if (depFromDepMgt != null) {
// workaround for MNG-2961
dependencyArtifact.isSnapshot();
- if ( depFromDepMgt.getVersion() != null
- && !depFromDepMgt.getVersion().equals( dependencyArtifact.getBaseVersion() ) )
- {
- mismatchMap.put( dependencyArtifact, depFromDepMgt );
+ if (depFromDepMgt.getVersion() != null
+ && !depFromDepMgt.getVersion().equals(dependencyArtifact.getBaseVersion())) {
+ mismatchMap.put(dependencyArtifact, depFromDepMgt);
}
}
}
@@ -273,18 +241,16 @@ public Map getMismatch( Map depMgtMap,
* @param dependencyFromDepMgt the dependency listed in the DependencyManagement section.
* @throws MojoExecutionException in case of errors.
*/
- public void logMismatch( Artifact dependencyArtifact, Dependency dependencyFromDepMgt )
- throws MojoExecutionException
- {
- if ( dependencyArtifact == null || dependencyFromDepMgt == null )
- {
- throw new MojoExecutionException( "Invalid params: Artifact: " + dependencyArtifact + " Dependency: "
- + dependencyFromDepMgt );
+ public void logMismatch(Artifact dependencyArtifact, Dependency dependencyFromDepMgt)
+ throws MojoExecutionException {
+ if (dependencyArtifact == null || dependencyFromDepMgt == null) {
+ throw new MojoExecutionException(
+ "Invalid params: Artifact: " + dependencyArtifact + " Dependency: " + dependencyFromDepMgt);
}
- getLog().info( "\tDependency: " + StringUtils.stripEnd( dependencyFromDepMgt.getManagementKey(), ":" ) );
- getLog().info( "\t\tDepMgt : " + dependencyFromDepMgt.getVersion() );
- getLog().info( "\t\tResolved: " + dependencyArtifact.getBaseVersion() );
+ getLog().info("\tDependency: " + StringUtils.stripEnd(dependencyFromDepMgt.getManagementKey(), ":"));
+ getLog().info("\t\tDepMgt : " + dependencyFromDepMgt.getVersion());
+ getLog().info("\t\tResolved: " + dependencyArtifact.getBaseVersion());
}
/**
@@ -293,57 +259,50 @@ public void logMismatch( Artifact dependencyArtifact, Dependency dependencyFromD
* @param artifact to gen the key for
* @return a string in the form: groupId:ArtifactId:Type[:Classifier]
*/
- public String getArtifactManagementKey( Artifact artifact )
- {
+ public String getArtifactManagementKey(Artifact artifact) {
return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getType()
- + ( ( artifact.getClassifier() != null ) ? ":" + artifact.getClassifier() : "" );
+ + ((artifact.getClassifier() != null) ? ":" + artifact.getClassifier() : "");
}
/**
* @return the failBuild
*/
- protected final boolean isFailBuild()
- {
+ protected final boolean isFailBuild() {
return this.failBuild;
}
/**
* @param theFailBuild the failBuild to set
*/
- public void setFailBuild( boolean theFailBuild )
- {
+ public void setFailBuild(boolean theFailBuild) {
this.failBuild = theFailBuild;
}
/**
* @return the project
*/
- protected final MavenProject getProject()
- {
+ protected final MavenProject getProject() {
return this.project;
}
/**
* @param theProject the project to set
*/
- public void setProject( MavenProject theProject )
- {
+ public void setProject(MavenProject theProject) {
this.project = theProject;
}
/**
* @return the ignoreDirect
*/
- protected final boolean isIgnoreDirect()
- {
+ protected final boolean isIgnoreDirect() {
return this.ignoreDirect;
}
/**
* @param theIgnoreDirect the ignoreDirect to set
*/
- public void setIgnoreDirect( boolean theIgnoreDirect )
- {
+ public void setIgnoreDirect(boolean theIgnoreDirect) {
this.ignoreDirect = theIgnoreDirect;
}
}
diff --git a/src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeDuplicateMojo.java b/src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeDuplicateMojo.java
index 552f4981d..fe6aa8728 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeDuplicateMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeDuplicateMojo.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.dependency.analyze;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.dependency.analyze;
import java.io.IOException;
import java.io.Reader;
@@ -27,7 +26,6 @@
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
-
import org.apache.commons.collections4.CollectionUtils;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Model;
@@ -47,119 +45,99 @@
*
* @author Vincent Siveton
*/
-@Mojo( name = "analyze-duplicate", aggregator = false, threadSafe = true )
-public class AnalyzeDuplicateMojo
- extends AbstractMojo
-{
+@Mojo(name = "analyze-duplicate", aggregator = false, threadSafe = true)
+public class AnalyzeDuplicateMojo extends AbstractMojo {
public static final String MESSAGE_DUPLICATE_DEP_IN_DEPENDENCIES =
- "List of duplicate dependencies defined in in your pom.xml:\n";
+ "List of duplicate dependencies defined in in your pom.xml:\n";
public static final String MESSAGE_DUPLICATE_DEP_IN_DEPMGMT =
- "List of duplicate dependencies defined in in your pom.xml:\n";
+ "List of duplicate dependencies defined in in your pom.xml:\n";
/**
* Skip plugin execution completely.
*
* @since 2.7
*/
- @Parameter( property = "mdep.analyze.skip", defaultValue = "false" )
+ @Parameter(property = "mdep.analyze.skip", defaultValue = "false")
private boolean skip;
/**
* The Maven project to analyze.
*/
- @Parameter( defaultValue = "${project}", readonly = true, required = true )
+ @Parameter(defaultValue = "${project}", readonly = true, required = true)
private MavenProject project;
/**
* {@inheritDoc}
*/
@Override
- public void execute()
- throws MojoExecutionException, MojoFailureException
- {
- if ( skip )
- {
- getLog().info( "Skipping plugin execution" );
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ if (skip) {
+ getLog().info("Skipping plugin execution");
return;
}
MavenXpp3Reader pomReader = new MavenXpp3Reader();
Model model;
- try ( Reader reader = ReaderFactory.newXmlReader( project.getFile() ) )
- {
- model = pomReader.read( reader );
- }
- catch ( IOException | XmlPullParserException e )
- {
- throw new MojoExecutionException( "Exception: " + e.getMessage(), e );
+ try (Reader reader = ReaderFactory.newXmlReader(project.getFile())) {
+ model = pomReader.read(reader);
+ } catch (IOException | XmlPullParserException e) {
+ throw new MojoExecutionException("Exception: " + e.getMessage(), e);
}
Set duplicateDependencies = Collections.emptySet();
- if ( model.getDependencies() != null )
- {
- duplicateDependencies = findDuplicateDependencies( model.getDependencies() );
+ if (model.getDependencies() != null) {
+ duplicateDependencies = findDuplicateDependencies(model.getDependencies());
}
Set duplicateDependenciesManagement = Collections.emptySet();
- if ( model.getDependencyManagement() != null && model.getDependencyManagement().getDependencies() != null )
- {
+ if (model.getDependencyManagement() != null
+ && model.getDependencyManagement().getDependencies() != null) {
duplicateDependenciesManagement =
- findDuplicateDependencies( model.getDependencyManagement().getDependencies() );
+ findDuplicateDependencies(model.getDependencyManagement().getDependencies());
}
- if ( getLog().isInfoEnabled() )
- {
+ if (getLog().isInfoEnabled()) {
StringBuilder sb = new StringBuilder();
- createMessage( duplicateDependencies, sb, MESSAGE_DUPLICATE_DEP_IN_DEPENDENCIES );
- createMessage( duplicateDependenciesManagement, sb, MESSAGE_DUPLICATE_DEP_IN_DEPMGMT );
+ createMessage(duplicateDependencies, sb, MESSAGE_DUPLICATE_DEP_IN_DEPENDENCIES);
+ createMessage(duplicateDependenciesManagement, sb, MESSAGE_DUPLICATE_DEP_IN_DEPMGMT);
- if ( sb.length() > 0 )
- {
- getLog().info( sb.toString() );
- }
- else
- {
- getLog().info( "No duplicate dependencies found in or in " );
+ if (sb.length() > 0) {
+ getLog().info(sb.toString());
+ } else {
+ getLog().info("No duplicate dependencies found in or in ");
}
}
}
- private void createMessage( Set duplicateDependencies, StringBuilder sb,
- String messageDuplicateDepInDependencies )
- {
- if ( !duplicateDependencies.isEmpty() )
- {
- if ( sb.length() > 0 )
- {
- sb.append( "\n" );
+ private void createMessage(
+ Set duplicateDependencies, StringBuilder sb, String messageDuplicateDepInDependencies) {
+ if (!duplicateDependencies.isEmpty()) {
+ if (sb.length() > 0) {
+ sb.append("\n");
}
- sb.append( messageDuplicateDepInDependencies );
- for ( Iterator it = duplicateDependencies.iterator(); it.hasNext(); )
- {
+ sb.append(messageDuplicateDepInDependencies);
+ for (Iterator it = duplicateDependencies.iterator(); it.hasNext(); ) {
String dup = it.next();
- sb.append( "\to " ).append( dup );
- if ( it.hasNext() )
- {
- sb.append( "\n" );
+ sb.append("\to ").append(dup);
+ if (it.hasNext()) {
+ sb.append("\n");
}
}
}
}
- private Set findDuplicateDependencies( List modelDependencies )
- {
+ private Set findDuplicateDependencies(List modelDependencies) {
List modelDependencies2 = new ArrayList<>();
- for ( Dependency dep : modelDependencies )
- {
- modelDependencies2.add( dep.getManagementKey() );
+ for (Dependency dep : modelDependencies) {
+ modelDependencies2.add(dep.getManagementKey());
}
// @formatter:off
return new LinkedHashSet<>(
- CollectionUtils.disjunction( modelDependencies2, new LinkedHashSet<>( modelDependencies2 ) ) );
+ CollectionUtils.disjunction(modelDependencies2, new LinkedHashSet<>(modelDependencies2)));
// @formatter:on
}
}
diff --git a/src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeMojo.java b/src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeMojo.java
index 2bd434144..84907bb60 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeMojo.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.dependency.analyze;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
@@ -18,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.dependency.analyze;
import org.apache.maven.plugins.annotations.Execute;
import org.apache.maven.plugins.annotations.LifecyclePhase;
@@ -38,10 +37,8 @@
* @see AnalyzeOnlyMojo
* @since 2.0-alpha-3
*/
-@Mojo( name = "analyze", requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true )
-@Execute( phase = LifecyclePhase.TEST_COMPILE )
-public class AnalyzeMojo
- extends AbstractAnalyzeMojo
-{
+@Mojo(name = "analyze", requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true)
+@Execute(phase = LifecyclePhase.TEST_COMPILE)
+public class AnalyzeMojo extends AbstractAnalyzeMojo {
// subclassed to provide annotations
}
diff --git a/src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeOnlyMojo.java b/src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeOnlyMojo.java
index 0265661d3..43d1e3021 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeOnlyMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeOnlyMojo.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.dependency.analyze;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
@@ -18,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.dependency.analyze;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
@@ -38,16 +37,13 @@
* @see AnalyzeMojo
* @since 2.0
*/
-//@formatter:off
-@Mojo(
- name = "analyze-only",
- requiresDependencyResolution = ResolutionScope.TEST,
- defaultPhase = LifecyclePhase.VERIFY,
- threadSafe = true
-)
-//@formatter:on
-public class AnalyzeOnlyMojo
- extends AbstractAnalyzeMojo
-{
+// @formatter:off
+@Mojo(
+ name = "analyze-only",
+ requiresDependencyResolution = ResolutionScope.TEST,
+ defaultPhase = LifecyclePhase.VERIFY,
+ threadSafe = true)
+// @formatter:on
+public class AnalyzeOnlyMojo extends AbstractAnalyzeMojo {
// subclassed to provide annotations
}
diff --git a/src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeReportMojo.java b/src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeReportMojo.java
index fd51491f3..5e3e40fa3 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeReportMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeReportMojo.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.dependency.analyze;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
@@ -18,7 +16,10 @@
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.dependency.analyze;
+import java.util.Locale;
+import java.util.ResourceBundle;
import org.apache.maven.doxia.sink.Sink;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Execute;
@@ -32,20 +33,15 @@
import org.apache.maven.shared.dependency.analyzer.ProjectDependencyAnalyzer;
import org.apache.maven.shared.dependency.analyzer.ProjectDependencyAnalyzerException;
-import java.util.Locale;
-import java.util.ResourceBundle;
-
/**
* Analyzes the dependencies of this project and produces a report that summarizes which are: used and declared; used
* and undeclared; unused and declared.
*
* @since 2.0-alpha-5
*/
-@Mojo( name = "analyze-report", requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true )
-@Execute( phase = LifecyclePhase.TEST_COMPILE )
-public class AnalyzeReportMojo
- extends AbstractMavenReport
-{
+@Mojo(name = "analyze-report", requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true)
+@Execute(phase = LifecyclePhase.TEST_COMPILE)
+public class AnalyzeReportMojo extends AbstractMavenReport {
// fields -----------------------------------------------------------------
/**
@@ -59,7 +55,7 @@ public class AnalyzeReportMojo
*
* @since 2.2
*/
- @Parameter( property = "ignoreNonCompile", defaultValue = "false" )
+ @Parameter(property = "ignoreNonCompile", defaultValue = "false")
private boolean ignoreNonCompile;
/**
@@ -76,7 +72,7 @@ public class AnalyzeReportMojo
*
* @since 2.7
*/
- @Parameter( property = "mdep.analyze.skip", defaultValue = "false" )
+ @Parameter(property = "mdep.analyze.skip", defaultValue = "false")
private boolean skip;
// Mojo methods -----------------------------------------------------------
@@ -85,56 +81,45 @@ public class AnalyzeReportMojo
* @see org.apache.maven.plugin.Mojo#execute()
*/
@Override
- public void executeReport( Locale locale )
- throws MavenReportException
- {
+ public void executeReport(Locale locale) throws MavenReportException {
// Step 1: Analyze the project
ProjectDependencyAnalysis analysis;
- try
- {
- analysis = analyzer.analyze( project );
+ try {
+ analysis = analyzer.analyze(project);
- if ( usedDependencies != null )
- {
- analysis = analysis.forceDeclaredDependenciesUsage( usedDependencies );
+ if (usedDependencies != null) {
+ analysis = analysis.forceDeclaredDependenciesUsage(usedDependencies);
}
- }
- catch ( ProjectDependencyAnalyzerException exception )
- {
- throw new MavenReportException( "Cannot analyze dependencies", exception );
+ } catch (ProjectDependencyAnalyzerException exception) {
+ throw new MavenReportException("Cannot analyze dependencies", exception);
}
// remove everything that's not in the compile scope
- if ( ignoreNonCompile )
- {
+ if (ignoreNonCompile) {
analysis = analysis.ignoreNonCompile();
}
// Step 2: Create sink and bundle
Sink sink = getSink();
- ResourceBundle bundle = getBundle( locale );
+ ResourceBundle bundle = getBundle(locale);
// Step 3: Generate the report
AnalyzeReportView analyzethis = new AnalyzeReportView();
- analyzethis.generateReport( analysis, sink, bundle );
+ analyzethis.generateReport(analysis, sink, bundle);
}
// MavenReport methods ----------------------------------------------------
-
@Override
- public boolean canGenerateReport()
- {
- if ( skip )
- {
- getLog().info( "Skipping plugin execution" );
+ public boolean canGenerateReport() {
+ if (skip) {
+ getLog().info("Skipping plugin execution");
return false;
}
// Step 0: Checking pom availability
- if ( "pom".equals( project.getPackaging() ) )
- {
- getLog().info( "Skipping pom project" );
+ if ("pom".equals(project.getPackaging())) {
+ getLog().info("Skipping pom project");
return false;
}
@@ -145,8 +130,7 @@ public boolean canGenerateReport()
* @see org.apache.maven.reporting.AbstractMavenReport#getOutputName()
*/
@Override
- public String getOutputName()
- {
+ public String getOutputName() {
return "dependency-analysis";
}
@@ -154,18 +138,16 @@ public String getOutputName()
* @see org.apache.maven.reporting.AbstractMavenReport#getName(java.util.Locale)
*/
@Override
- public String getName( Locale locale )
- {
- return getBundle( locale ).getString( "analyze.report.name" );
+ public String getName(Locale locale) {
+ return getBundle(locale).getString("analyze.report.name");
}
/*
* @see org.apache.maven.reporting.AbstractMavenReport#getDescription(java.util.Locale)
*/
@Override
- public String getDescription( Locale locale )
- {
- return getBundle( locale ).getString( "analyze.report.description" );
+ public String getDescription(Locale locale) {
+ return getBundle(locale).getString("analyze.report.description");
}
// protected methods ------------------------------------------------------
@@ -174,8 +156,8 @@ public String getDescription( Locale locale )
* @param locale the current locale
* @return The resource bundle {@link ResourceBundle}
*/
- protected ResourceBundle getBundle( Locale locale )
- {
- return ResourceBundle.getBundle( "analyze-report", locale, this.getClass().getClassLoader() );
+ protected ResourceBundle getBundle(Locale locale) {
+ return ResourceBundle.getBundle(
+ "analyze-report", locale, this.getClass().getClassLoader());
}
}
diff --git a/src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeReportView.java b/src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeReportView.java
index 571be741b..4bcc3d47e 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeReportView.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeReportView.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.dependency.analyze;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
@@ -18,10 +16,10 @@
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.dependency.analyze;
import java.util.Iterator;
import java.util.ResourceBundle;
-
import org.apache.maven.artifact.Artifact;
import org.apache.maven.doxia.sink.Sink;
import org.apache.maven.shared.dependency.analyzer.ProjectDependencyAnalysis;
@@ -30,20 +28,18 @@
* This is the view part of the analyze-report mojo. It generates the HTML report for the project website. The HTML
* output is same as the CLI output.
*/
-public class AnalyzeReportView
-{
+public class AnalyzeReportView {
/**
* Generates the HTML report.
- *
+ *
* @param analysis {@link ProjectDependencyAnalysis}
* @param sink {@link Sink}
* @param bundle {@link ResourceBundle}
*/
- public void generateReport( ProjectDependencyAnalysis analysis, Sink sink, ResourceBundle bundle )
- {
+ public void generateReport(ProjectDependencyAnalysis analysis, Sink sink, ResourceBundle bundle) {
sink.head();
sink.title();
- sink.text( bundle.getString( "analyze.report.header" ) );
+ sink.text(bundle.getString("analyze.report.header"));
sink.title_();
sink.head_();
sink.body();
@@ -51,78 +47,69 @@ public void generateReport( ProjectDependencyAnalysis analysis, Sink sink, Resou
// Generate title
sink.section1();
sink.sectionTitle1();
- sink.text( bundle.getString( "analyze.report.mainTitle" ) );
+ sink.text(bundle.getString("analyze.report.mainTitle"));
sink.sectionTitle1_();
// Generate Used Declared dependencies:
sink.section2();
sink.sectionTitle2();
- sink.text( bundle.getString( "analyze.report.UsedDeclaredDependencies" ) );
+ sink.text(bundle.getString("analyze.report.UsedDeclaredDependencies"));
sink.sectionTitle2_();
- if ( analysis.getUsedDeclaredArtifacts().isEmpty() )
- {
+ if (analysis.getUsedDeclaredArtifacts().isEmpty()) {
sink.paragraph();
- sink.text( bundle.getString( "analyze.report.noDependency" ) );
+ sink.text(bundle.getString("analyze.report.noDependency"));
sink.paragraph_();
sink.horizontalRule();
- }
- else
- {
- generateDependenciesTable( sink, analysis.getUsedDeclaredArtifacts().iterator() );
+ } else {
+ generateDependenciesTable(sink, analysis.getUsedDeclaredArtifacts().iterator());
}
sink.section2_();
// Generate Used Undeclared dependencies:
sink.section2();
sink.sectionTitle2();
- sink.text( bundle.getString( "analyze.report.UsedUndeclaredDependencies" ) );
+ sink.text(bundle.getString("analyze.report.UsedUndeclaredDependencies"));
sink.sectionTitle2_();
- if ( analysis.getUsedUndeclaredArtifacts().isEmpty() )
- {
+ if (analysis.getUsedUndeclaredArtifacts().isEmpty()) {
sink.paragraph();
- sink.text( bundle.getString( "analyze.report.noDependency" ) );
+ sink.text(bundle.getString("analyze.report.noDependency"));
sink.paragraph_();
sink.horizontalRule();
- }
- else
- {
- generateDependenciesTable( sink, analysis.getUsedUndeclaredArtifacts().iterator() );
+ } else {
+ generateDependenciesTable(
+ sink, analysis.getUsedUndeclaredArtifacts().iterator());
}
sink.section2_();
// Generate Unused declared dependencies:
sink.section2();
sink.sectionTitle2();
- sink.text( bundle.getString( "analyze.report.UnusedDeclaredDependencies" ) );
+ sink.text(bundle.getString("analyze.report.UnusedDeclaredDependencies"));
sink.sectionTitle2_();
- if ( analysis.getUnusedDeclaredArtifacts().isEmpty() )
- {
+ if (analysis.getUnusedDeclaredArtifacts().isEmpty()) {
sink.paragraph();
- sink.text( bundle.getString( "analyze.report.noDependency" ) );
+ sink.text(bundle.getString("analyze.report.noDependency"));
sink.paragraph_();
sink.horizontalRule();
- }
- else
- {
- generateDependenciesTable( sink, analysis.getUnusedDeclaredArtifacts().iterator() );
+ } else {
+ generateDependenciesTable(
+ sink, analysis.getUnusedDeclaredArtifacts().iterator());
}
sink.section2_();
// Generate Non-Test Scoped Test Dependencies:
sink.section2();
sink.sectionTitle2();
- sink.text( "Compile Scoped Test Dependencies" );
+ sink.text("Compile Scoped Test Dependencies");
sink.sectionTitle2_();
- if ( analysis.getTestArtifactsWithNonTestScope().isEmpty() )
- {
+ if (analysis.getTestArtifactsWithNonTestScope().isEmpty()) {
sink.paragraph();
- sink.text( "None" );
+ sink.text("None");
sink.paragraph_();
sink.horizontalRule();
- }
- else
- {
- generateDependenciesTable( sink, analysis.getTestArtifactsWithNonTestScope().iterator() );
+ } else {
+ generateDependenciesTable(
+ sink, analysis.getTestArtifactsWithNonTestScope().iterator());
}
sink.section2_();
@@ -136,89 +123,84 @@ public void generateReport( ProjectDependencyAnalysis analysis, Sink sink, Resou
/**
* Generate a table for the given dependencies iterator.
- *
+ *
* @param sink {@link Sink}
* @param iter {@link Artifact}
*/
- public void generateDependenciesTable( Sink sink, Iterator iter )
- {
+ public void generateDependenciesTable(Sink sink, Iterator iter) {
sink.table();
sink.tableRow();
sink.tableCell();
sink.bold();
- sink.text( "GroupId" );
+ sink.text("GroupId");
sink.bold_();
sink.tableCell_();
sink.tableCell();
sink.bold();
- sink.text( "ArtifactId" );
+ sink.text("ArtifactId");
sink.bold_();
sink.tableCell_();
sink.tableCell();
sink.bold();
- sink.text( "Version" );
+ sink.text("Version");
sink.bold_();
sink.tableCell_();
sink.tableCell();
sink.bold();
- sink.text( "Scope" );
+ sink.text("Scope");
sink.bold_();
sink.tableCell_();
sink.tableCell();
sink.bold();
- sink.text( "Classifier" );
+ sink.text("Classifier");
sink.bold_();
sink.tableCell_();
sink.tableCell();
sink.bold();
- sink.text( "Type" );
+ sink.text("Type");
sink.bold_();
sink.tableCell_();
sink.tableCell();
sink.bold();
- sink.text( "Optional" );
+ sink.text("Optional");
sink.bold_();
sink.tableCell_();
sink.tableRow_();
- while ( iter.hasNext() )
- {
+ while (iter.hasNext()) {
Artifact artifact = iter.next();
sink.tableRow();
sink.tableCell();
- sink.text( artifact.getGroupId() );
+ sink.text(artifact.getGroupId());
sink.tableCell_();
sink.tableCell();
- sink.text( artifact.getArtifactId() );
+ sink.text(artifact.getArtifactId());
sink.tableCell_();
sink.tableCell();
- sink.text( artifact.getVersion() );
+ sink.text(artifact.getVersion());
sink.tableCell_();
sink.tableCell();
- sink.text( artifact.getScope() );
+ sink.text(artifact.getScope());
sink.tableCell_();
sink.tableCell();
- sink.text( artifact.getClassifier() );
+ sink.text(artifact.getClassifier());
sink.tableCell_();
sink.tableCell();
- sink.text( artifact.getType() );
+ sink.text(artifact.getType());
sink.tableCell_();
sink.tableCell();
- if ( artifact.isOptional() )
- {
- sink.text( "" );
- }
- else
- {
- sink.text( "false" );
+ if (artifact.isOptional()) {
+ sink.text("");
+ } else {
+ sink.text("false");
}
sink.tableCell_();
diff --git a/src/main/java/org/apache/maven/plugins/dependency/fromConfiguration/AbstractFromConfigurationMojo.java b/src/main/java/org/apache/maven/plugins/dependency/fromConfiguration/AbstractFromConfigurationMojo.java
index eed762196..6e6dd5271 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/fromConfiguration/AbstractFromConfigurationMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/fromConfiguration/AbstractFromConfigurationMojo.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.dependency.fromConfiguration;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
@@ -18,12 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.dependency.fromConfiguration;
import java.io.File;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
-
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
@@ -51,15 +49,13 @@
* @author Brian Fox
* @see ArtifactItem
*/
-public abstract class AbstractFromConfigurationMojo
- extends AbstractDependencyMojo
-{
+public abstract class AbstractFromConfigurationMojo extends AbstractDependencyMojo {
/**
* Default output location used for mojo, unless overridden in ArtifactItem.
*
* @since 1.0
*/
- @Parameter( property = "outputDirectory", defaultValue = "${project.build.directory}/dependency" )
+ @Parameter(property = "outputDirectory", defaultValue = "${project.build.directory}/dependency")
private File outputDirectory;
/**
@@ -67,7 +63,7 @@ public abstract class AbstractFromConfigurationMojo
*
* @since 1.0
*/
- @Parameter( property = "mdep.overWriteReleases", defaultValue = "false" )
+ @Parameter(property = "mdep.overWriteReleases", defaultValue = "false")
private boolean overWriteReleases;
/**
@@ -75,7 +71,7 @@ public abstract class AbstractFromConfigurationMojo
*
* @since 1.0
*/
- @Parameter( property = "mdep.overWriteSnapshots", defaultValue = "false" )
+ @Parameter(property = "mdep.overWriteSnapshots", defaultValue = "false")
private boolean overWriteSnapshots;
/**
@@ -83,7 +79,7 @@ public abstract class AbstractFromConfigurationMojo
*
* @since 2.0
*/
- @Parameter( property = "mdep.overIfNewer", defaultValue = "true" )
+ @Parameter(property = "mdep.overIfNewer", defaultValue = "true")
private boolean overWriteIfNewer;
/**
@@ -113,19 +109,16 @@ public abstract class AbstractFromConfigurationMojo
@Component
private ArtifactHandlerManager artifactHandlerManager;
- abstract ArtifactItemFilter getMarkedArtifactFilter( ArtifactItem item );
+ abstract ArtifactItemFilter getMarkedArtifactFilter(ArtifactItem item);
/**
* artifactItems is filled by either field injection or by setArtifact().
- *
+ *
* @throws MojoFailureException in case of an error.
*/
- protected void verifyRequirements()
- throws MojoFailureException
- {
- if ( artifactItems == null || artifactItems.isEmpty() )
- {
- throw new MojoFailureException( "Either artifact or artifactItems is required " );
+ protected void verifyRequirements() throws MojoFailureException {
+ if (artifactItems == null || artifactItems.isEmpty()) {
+ throw new MojoFailureException("Either artifact or artifactItems is required ");
}
}
@@ -138,63 +131,51 @@ protected void verifyRequirements()
* @throws MojoExecutionException with a message if an error occurs.
* @see ArtifactItem
*/
- protected List getProcessedArtifactItems( ProcessArtifactItemsRequest processArtifactItemsRequest )
- throws MojoExecutionException
- {
+ protected List getProcessedArtifactItems(ProcessArtifactItemsRequest processArtifactItemsRequest)
+ throws MojoExecutionException {
boolean removeVersion = processArtifactItemsRequest.isRemoveVersion(),
- prependGroupId = processArtifactItemsRequest.isPrependGroupId(),
- useBaseVersion = processArtifactItemsRequest.isUseBaseVersion();
+ prependGroupId = processArtifactItemsRequest.isPrependGroupId(),
+ useBaseVersion = processArtifactItemsRequest.isUseBaseVersion();
boolean removeClassifier = processArtifactItemsRequest.isRemoveClassifier();
- if ( artifactItems == null || artifactItems.size() < 1 )
- {
- throw new MojoExecutionException( "There are no artifactItems configured." );
+ if (artifactItems == null || artifactItems.size() < 1) {
+ throw new MojoExecutionException("There are no artifactItems configured.");
}
- for ( ArtifactItem artifactItem : artifactItems )
- {
- this.getLog().info( "Configured Artifact: " + artifactItem.toString() );
+ for (ArtifactItem artifactItem : artifactItems) {
+ this.getLog().info("Configured Artifact: " + artifactItem.toString());
- if ( artifactItem.getOutputDirectory() == null )
- {
- artifactItem.setOutputDirectory( this.outputDirectory );
+ if (artifactItem.getOutputDirectory() == null) {
+ artifactItem.setOutputDirectory(this.outputDirectory);
}
artifactItem.getOutputDirectory().mkdirs();
// make sure we have a version.
- if ( StringUtils.isEmpty( artifactItem.getVersion() ) )
- {
- fillMissingArtifactVersion( artifactItem );
+ if (StringUtils.isEmpty(artifactItem.getVersion())) {
+ fillMissingArtifactVersion(artifactItem);
}
- artifactItem.setArtifact( this.getArtifact( artifactItem ) );
+ artifactItem.setArtifact(this.getArtifact(artifactItem));
- if ( StringUtils.isEmpty( artifactItem.getDestFileName() ) )
- {
- artifactItem.setDestFileName( DependencyUtil.getFormattedFileName( artifactItem.getArtifact(),
- removeVersion, prependGroupId,
- useBaseVersion, removeClassifier ) );
+ if (StringUtils.isEmpty(artifactItem.getDestFileName())) {
+ artifactItem.setDestFileName(DependencyUtil.getFormattedFileName(
+ artifactItem.getArtifact(), removeVersion, prependGroupId, useBaseVersion, removeClassifier));
}
- try
- {
- artifactItem.setNeedsProcessing( checkIfProcessingNeeded( artifactItem ) );
- }
- catch ( ArtifactFilterException e )
- {
- throw new MojoExecutionException( e.getMessage(), e );
+ try {
+ artifactItem.setNeedsProcessing(checkIfProcessingNeeded(artifactItem));
+ } catch (ArtifactFilterException e) {
+ throw new MojoExecutionException(e.getMessage(), e);
}
}
return artifactItems;
}
- private boolean checkIfProcessingNeeded( ArtifactItem item )
- throws MojoExecutionException, ArtifactFilterException
- {
- return StringUtils.equalsIgnoreCase( item.getOverWrite(), "true" )
- || getMarkedArtifactFilter( item ).isArtifactIncluded( item );
+ private boolean checkIfProcessingNeeded(ArtifactItem item) throws MojoExecutionException, ArtifactFilterException {
+ return StringUtils.equalsIgnoreCase(item.getOverWrite(), "true")
+ || getMarkedArtifactFilter(item).isArtifactIncluded(item);
}
/**
@@ -205,13 +186,10 @@ private boolean checkIfProcessingNeeded( ArtifactItem item )
* @return Artifact object representing the specified file.
* @throws MojoExecutionException with a message if the version can't be found in DependencyManagement.
*/
- protected Artifact getArtifact( ArtifactItem artifactItem )
- throws MojoExecutionException
- {
+ protected Artifact getArtifact(ArtifactItem artifactItem) throws MojoExecutionException {
Artifact artifact;
- try
- {
+ try {
// mdep-50 - rolledback for now because it's breaking some functionality.
/*
* List listeners = new ArrayList(); Set theSet = new HashSet(); theSet.add( artifact );
@@ -224,36 +202,32 @@ protected Artifact getArtifact( ArtifactItem artifactItem )
ProjectBuildingRequest buildingRequest = newResolveArtifactProjectBuildingRequest();
- if ( localRepositoryDirectory != null )
- {
+ if (localRepositoryDirectory != null) {
buildingRequest =
- repositoryManager.setLocalRepositoryBasedir( buildingRequest, localRepositoryDirectory );
+ repositoryManager.setLocalRepositoryBasedir(buildingRequest, localRepositoryDirectory);
}
// Map dependency to artifact coordinate
DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate();
- coordinate.setGroupId( artifactItem.getGroupId() );
- coordinate.setArtifactId( artifactItem.getArtifactId() );
- coordinate.setVersion( artifactItem.getVersion() );
- coordinate.setClassifier( artifactItem.getClassifier() );
+ coordinate.setGroupId(artifactItem.getGroupId());
+ coordinate.setArtifactId(artifactItem.getArtifactId());
+ coordinate.setVersion(artifactItem.getVersion());
+ coordinate.setClassifier(artifactItem.getClassifier());
final String extension;
- ArtifactHandler artifactHandler = artifactHandlerManager.getArtifactHandler( artifactItem.getType() );
- if ( artifactHandler != null )
- {
+ ArtifactHandler artifactHandler = artifactHandlerManager.getArtifactHandler(artifactItem.getType());
+ if (artifactHandler != null) {
extension = artifactHandler.getExtension();
- }
- else
- {
+ } else {
extension = artifactItem.getType();
}
- coordinate.setExtension( extension );
+ coordinate.setExtension(extension);
- artifact = artifactResolver.resolveArtifact( buildingRequest, coordinate ).getArtifact();
- }
- catch ( ArtifactResolverException e )
- {
- throw new MojoExecutionException( "Unable to find/resolve artifact.", e );
+ artifact = artifactResolver
+ .resolveArtifact(buildingRequest, coordinate)
+ .getArtifact();
+ } catch (ArtifactResolverException e) {
+ throw new MojoExecutionException("Unable to find/resolve artifact.", e);
}
return artifact;
@@ -267,21 +241,19 @@ protected Artifact getArtifact( ArtifactItem artifactItem )
* @param artifact representing configured file.
* @throws MojoExecutionException
*/
- private void fillMissingArtifactVersion( ArtifactItem artifact )
- throws MojoExecutionException
- {
+ private void fillMissingArtifactVersion(ArtifactItem artifact) throws MojoExecutionException {
MavenProject project = getProject();
List deps = project.getDependencies();
- List depMngt = project.getDependencyManagement() == null ? Collections.emptyList()
- : project.getDependencyManagement().getDependencies();
-
- if ( !findDependencyVersion( artifact, deps, false )
- && ( project.getDependencyManagement() == null || !findDependencyVersion( artifact, depMngt, false ) )
- && !findDependencyVersion( artifact, deps, true )
- && ( project.getDependencyManagement() == null || !findDependencyVersion( artifact, depMngt, true ) ) )
- {
- throw new MojoExecutionException( "Unable to find artifact version of " + artifact.getGroupId() + ":"
- + artifact.getArtifactId() + " in either dependency list or in project's dependency management." );
+ List depMngt = project.getDependencyManagement() == null
+ ? Collections.emptyList()
+ : project.getDependencyManagement().getDependencies();
+
+ if (!findDependencyVersion(artifact, deps, false)
+ && (project.getDependencyManagement() == null || !findDependencyVersion(artifact, depMngt, false))
+ && !findDependencyVersion(artifact, deps, true)
+ && (project.getDependencyManagement() == null || !findDependencyVersion(artifact, depMngt, true))) {
+ throw new MojoExecutionException("Unable to find artifact version of " + artifact.getGroupId() + ":"
+ + artifact.getArtifactId() + " in either dependency list or in project's dependency management.");
}
}
@@ -294,16 +266,13 @@ private void fillMissingArtifactVersion( ArtifactItem artifact )
* @param looseMatch only look at artifactId and groupId
* @return the found dependency
*/
- private boolean findDependencyVersion( ArtifactItem artifact, List dependencies, boolean looseMatch )
- {
- for ( Dependency dependency : dependencies )
- {
- if ( Objects.equals( dependency.getArtifactId(), artifact.getArtifactId() )
- && Objects.equals( dependency.getGroupId(), artifact.getGroupId() )
- && ( looseMatch || Objects.equals( dependency.getClassifier(), artifact.getClassifier() ) )
- && ( looseMatch || Objects.equals( dependency.getType(), artifact.getType() ) ) )
- {
- artifact.setVersion( dependency.getVersion() );
+ private boolean findDependencyVersion(ArtifactItem artifact, List dependencies, boolean looseMatch) {
+ for (Dependency dependency : dependencies) {
+ if (Objects.equals(dependency.getArtifactId(), artifact.getArtifactId())
+ && Objects.equals(dependency.getGroupId(), artifact.getGroupId())
+ && (looseMatch || Objects.equals(dependency.getClassifier(), artifact.getClassifier()))
+ && (looseMatch || Objects.equals(dependency.getType(), artifact.getType()))) {
+ artifact.setVersion(dependency.getVersion());
return true;
}
@@ -315,88 +284,77 @@ private boolean findDependencyVersion( ArtifactItem artifact, List d
/**
* @return Returns the artifactItems.
*/
- public List getArtifactItems()
- {
+ public List getArtifactItems() {
return this.artifactItems;
}
/**
* @param theArtifactItems The artifactItems to set.
*/
- public void setArtifactItems( List theArtifactItems )
- {
+ public void setArtifactItems(List theArtifactItems) {
this.artifactItems = theArtifactItems;
}
/**
* @return Returns the outputDirectory.
*/
- public File getOutputDirectory()
- {
+ public File getOutputDirectory() {
return this.outputDirectory;
}
/**
* @param theOutputDirectory The outputDirectory to set.
*/
- public void setOutputDirectory( File theOutputDirectory )
- {
+ public void setOutputDirectory(File theOutputDirectory) {
this.outputDirectory = theOutputDirectory;
}
/**
* @return Returns the overWriteIfNewer.
*/
- public boolean isOverWriteIfNewer()
- {
+ public boolean isOverWriteIfNewer() {
return this.overWriteIfNewer;
}
/**
* @param theOverWriteIfNewer The overWriteIfNewer to set.
*/
- public void setOverWriteIfNewer( boolean theOverWriteIfNewer )
- {
+ public void setOverWriteIfNewer(boolean theOverWriteIfNewer) {
this.overWriteIfNewer = theOverWriteIfNewer;
}
/**
* @return Returns the overWriteReleases.
*/
- public boolean isOverWriteReleases()
- {
+ public boolean isOverWriteReleases() {
return this.overWriteReleases;
}
/**
* @param theOverWriteReleases The overWriteReleases to set.
*/
- public void setOverWriteReleases( boolean theOverWriteReleases )
- {
+ public void setOverWriteReleases(boolean theOverWriteReleases) {
this.overWriteReleases = theOverWriteReleases;
}
/**
* @return Returns the overWriteSnapshots.
*/
- public boolean isOverWriteSnapshots()
- {
+ public boolean isOverWriteSnapshots() {
return this.overWriteSnapshots;
}
/**
* @param theOverWriteSnapshots The overWriteSnapshots to set.
*/
- public void setOverWriteSnapshots( boolean theOverWriteSnapshots )
- {
+ public void setOverWriteSnapshots(boolean theOverWriteSnapshots) {
this.overWriteSnapshots = theOverWriteSnapshots;
}
/**
* @param localRepositoryDirectory {@link #localRepositoryDirectory}
*/
- public void setLocalRepositoryDirectory( File localRepositoryDirectory )
- {
+ public void setLocalRepositoryDirectory(File localRepositoryDirectory) {
this.localRepositoryDirectory = localRepositoryDirectory;
}
@@ -404,43 +362,35 @@ public void setLocalRepositoryDirectory( File localRepositoryDirectory )
* @param artifact The artifact.
* @throws MojoFailureException in case of an error.
*/
- public void setArtifact( String artifact )
- throws MojoFailureException
- {
- if ( artifact != null )
- {
+ public void setArtifact(String artifact) throws MojoFailureException {
+ if (artifact != null) {
String packaging = "jar";
String classifier;
- String[] tokens = StringUtils.split( artifact, ":" );
- if ( tokens.length < 3 || tokens.length > 5 )
- {
- throw new MojoFailureException( "Invalid artifact, "
- + "you must specify groupId:artifactId:version[:packaging[:classifier]] " + artifact );
+ String[] tokens = StringUtils.split(artifact, ":");
+ if (tokens.length < 3 || tokens.length > 5) {
+ throw new MojoFailureException("Invalid artifact, "
+ + "you must specify groupId:artifactId:version[:packaging[:classifier]] " + artifact);
}
String groupId = tokens[0];
String artifactId = tokens[1];
String version = tokens[2];
- if ( tokens.length >= 4 )
- {
+ if (tokens.length >= 4) {
packaging = tokens[3];
}
- if ( tokens.length == 5 )
- {
+ if (tokens.length == 5) {
classifier = tokens[4];
- }
- else
- {
+ } else {
classifier = null;
}
ArtifactItem artifactItem = new ArtifactItem();
- artifactItem.setGroupId( groupId );
- artifactItem.setArtifactId( artifactId );
- artifactItem.setVersion( version );
- artifactItem.setType( packaging );
- artifactItem.setClassifier( classifier );
+ artifactItem.setGroupId(groupId);
+ artifactItem.setArtifactId(artifactId);
+ artifactItem.setVersion(version);
+ artifactItem.setType(packaging);
+ artifactItem.setClassifier(classifier);
- setArtifactItems( Collections.singletonList( artifactItem ) );
+ setArtifactItems(Collections.singletonList(artifactItem));
}
}
}
diff --git a/src/main/java/org/apache/maven/plugins/dependency/fromConfiguration/ArtifactItem.java b/src/main/java/org/apache/maven/plugins/dependency/fromConfiguration/ArtifactItem.java
index 6a8346659..214ca924a 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/fromConfiguration/ArtifactItem.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/fromConfiguration/ArtifactItem.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.dependency.fromConfiguration;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
@@ -18,10 +16,10 @@
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.dependency.fromConfiguration;
import java.io.File;
import java.util.Objects;
-
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.plugins.dependency.utils.DependencyUtil;
@@ -34,9 +32,7 @@
* @since 1.0
* @author Brian Fox
*/
-public class ArtifactItem
- implements DependableCoordinate
-{
+public class ArtifactItem implements DependableCoordinate {
/**
* Group Id of Artifact
*
@@ -133,28 +129,24 @@ public class ArtifactItem
/**
* Default ctor.
*/
- public ArtifactItem()
- {
+ public ArtifactItem() {
// default constructor
}
/**
* @param artifact {@link Artifact}
*/
- public ArtifactItem( Artifact artifact )
- {
- this.setArtifact( artifact );
- this.setArtifactId( artifact.getArtifactId() );
- this.setClassifier( artifact.getClassifier() );
- this.setGroupId( artifact.getGroupId() );
- this.setType( artifact.getType() );
- this.setVersion( artifact.getVersion() );
+ public ArtifactItem(Artifact artifact) {
+ this.setArtifact(artifact);
+ this.setArtifactId(artifact.getArtifactId());
+ this.setClassifier(artifact.getClassifier());
+ this.setGroupId(artifact.getGroupId());
+ this.setType(artifact.getType());
+ this.setVersion(artifact.getVersion());
}
- private String filterEmptyString( String in )
- {
- if ( "".equals( in ) )
- {
+ private String filterEmptyString(String in) {
+ if ("".equals(in)) {
return null;
}
return in;
@@ -163,166 +155,142 @@ private String filterEmptyString( String in )
/**
* @return Returns the artifactId.
*/
- public String getArtifactId()
- {
+ public String getArtifactId() {
return artifactId;
}
/**
* @param theArtifact The artifactId to set.
*/
- public void setArtifactId( String theArtifact )
- {
- this.artifactId = filterEmptyString( theArtifact );
+ public void setArtifactId(String theArtifact) {
+ this.artifactId = filterEmptyString(theArtifact);
}
/**
* @return Returns the groupId.
*/
- public String getGroupId()
- {
+ public String getGroupId() {
return groupId;
}
/**
* @param groupId The groupId to set.
*/
- public void setGroupId( String groupId )
- {
- this.groupId = filterEmptyString( groupId );
+ public void setGroupId(String groupId) {
+ this.groupId = filterEmptyString(groupId);
}
/**
* @return Returns the type.
*/
- public String getType()
- {
+ public String getType() {
return type;
}
/**
* @param type The type to set.
*/
- public void setType( String type )
- {
- this.type = filterEmptyString( type );
+ public void setType(String type) {
+ this.type = filterEmptyString(type);
}
/**
* @return Returns the version.
*/
- public String getVersion()
- {
+ public String getVersion() {
return version;
}
/**
* @param version The version to set.
*/
- public void setVersion( String version )
- {
- this.version = filterEmptyString( version );
+ public void setVersion(String version) {
+ this.version = filterEmptyString(version);
}
/**
* @return Returns the base version.
*/
- public String getBaseVersion()
- {
- return ArtifactUtils.toSnapshotVersion( version );
+ public String getBaseVersion() {
+ return ArtifactUtils.toSnapshotVersion(version);
}
/**
* @return Classifier.
*/
- public String getClassifier()
- {
+ public String getClassifier() {
return classifier;
}
/**
* @param classifier Classifier.
*/
- public void setClassifier( String classifier )
- {
- this.classifier = filterEmptyString( classifier );
+ public void setClassifier(String classifier) {
+ this.classifier = filterEmptyString(classifier);
}
@Override
- public String toString()
- {
- if ( this.classifier == null )
- {
- return groupId + ":" + artifactId + ":" + Objects.toString( version, "?" ) + ":" + type;
- }
- else
- {
- return groupId + ":" + artifactId + ":" + classifier + ":" + Objects.toString( version, "?" ) + ":"
- + type;
+ public String toString() {
+ if (this.classifier == null) {
+ return groupId + ":" + artifactId + ":" + Objects.toString(version, "?") + ":" + type;
+ } else {
+ return groupId + ":" + artifactId + ":" + classifier + ":" + Objects.toString(version, "?") + ":" + type;
}
}
/**
* @return Returns the location.
*/
- public File getOutputDirectory()
- {
+ public File getOutputDirectory() {
return outputDirectory;
}
/**
* @param outputDirectory The outputDirectory to set.
*/
- public void setOutputDirectory( File outputDirectory )
- {
+ public void setOutputDirectory(File outputDirectory) {
this.outputDirectory = outputDirectory;
}
/**
* @return Returns the location.
*/
- public String getDestFileName()
- {
+ public String getDestFileName() {
return destFileName;
}
/**
* @param destFileName The destFileName to set.
*/
- public void setDestFileName( String destFileName )
- {
- this.destFileName = filterEmptyString( destFileName );
+ public void setDestFileName(String destFileName) {
+ this.destFileName = filterEmptyString(destFileName);
}
/**
* @return Returns the needsProcessing.
*/
- public boolean isNeedsProcessing()
- {
+ public boolean isNeedsProcessing() {
return this.needsProcessing;
}
/**
* @param needsProcessing The needsProcessing to set.
*/
- public void setNeedsProcessing( boolean needsProcessing )
- {
+ public void setNeedsProcessing(boolean needsProcessing) {
this.needsProcessing = needsProcessing;
}
/**
* @return Returns the overWriteSnapshots.
*/
- public String getOverWrite()
- {
+ public String getOverWrite() {
return this.overWrite;
}
/**
* @param overWrite The overWrite to set.
*/
- public void setOverWrite( String overWrite )
- {
+ public void setOverWrite(String overWrite) {
this.overWrite = overWrite;
}
@@ -330,8 +298,7 @@ public void setOverWrite( String overWrite )
* @return Returns the encoding.
* @since 3.0
*/
- public String getEncoding()
- {
+ public String getEncoding() {
return this.encoding;
}
@@ -339,56 +306,49 @@ public String getEncoding()
* @param encoding The encoding to set.
* @since 3.0
*/
- public void setEncoding( String encoding )
- {
+ public void setEncoding(String encoding) {
this.encoding = encoding;
}
/**
* @return Returns the artifact.
*/
- public Artifact getArtifact()
- {
+ public Artifact getArtifact() {
return this.artifact;
}
/**
* @param artifact The artifact to set.
*/
- public void setArtifact( Artifact artifact )
- {
+ public void setArtifact(Artifact artifact) {
this.artifact = artifact;
}
/**
* @return Returns a comma separated list of excluded items
*/
- public String getExcludes()
- {
- return DependencyUtil.cleanToBeTokenizedString( this.excludes );
+ public String getExcludes() {
+ return DependencyUtil.cleanToBeTokenizedString(this.excludes);
}
/**
* @param excludes A comma separated list of items to exclude i.e. **\/*.xml, **\/*.properties
*/
- public void setExcludes( String excludes )
- {
+ public void setExcludes(String excludes) {
this.excludes = excludes;
}
/**
* @return Returns a comma separated list of included items
*/
- public String getIncludes()
- {
- return DependencyUtil.cleanToBeTokenizedString( this.includes );
+ public String getIncludes() {
+ return DependencyUtil.cleanToBeTokenizedString(this.includes);
}
/**
* @param includes A comma separated list of items to include i.e. **\/*.xml, **\/*.properties
*/
- public void setIncludes( String includes )
- {
+ public void setIncludes(String includes) {
this.includes = includes;
}
@@ -398,8 +358,7 @@ public void setIncludes( String includes )
*
* @since 3.1.2
*/
- public FileMapper[] getFileMappers()
- {
+ public FileMapper[] getFileMappers() {
return this.fileMappers;
}
@@ -409,8 +368,7 @@ public FileMapper[] getFileMappers()
*
* @since 3.1.2
*/
- public void setFileMappers( FileMapper[] fileMappers )
- {
+ public void setFileMappers(FileMapper[] fileMappers) {
this.fileMappers = fileMappers;
}
}
diff --git a/src/main/java/org/apache/maven/plugins/dependency/fromConfiguration/CopyMojo.java b/src/main/java/org/apache/maven/plugins/dependency/fromConfiguration/CopyMojo.java
index e95d350d1..b6ccb4807 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/fromConfiguration/CopyMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/fromConfiguration/CopyMojo.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.dependency.fromConfiguration;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
@@ -18,17 +16,17 @@
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.dependency.fromConfiguration;
+import java.io.File;
+import java.util.List;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.plugins.dependency.utils.filters.ArtifactItemFilter;
-import org.apache.maven.plugins.dependency.utils.filters.DestFileFilter;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
-
-import java.io.File;
-import java.util.List;
+import org.apache.maven.plugins.dependency.utils.filters.ArtifactItemFilter;
+import org.apache.maven.plugins.dependency.utils.filters.DestFileFilter;
/**
* Goal that copies a list of artifacts from the repository to defined locations.
@@ -36,45 +34,43 @@
* @author Brian Fox
* @since 1.0
*/
-@Mojo( name = "copy", defaultPhase = LifecyclePhase.PROCESS_SOURCES, requiresProject = false, threadSafe = true )
-public class CopyMojo
- extends AbstractFromConfigurationMojo
-{
+@Mojo(name = "copy", defaultPhase = LifecyclePhase.PROCESS_SOURCES, requiresProject = false, threadSafe = true)
+public class CopyMojo extends AbstractFromConfigurationMojo {
/**
* Strip artifact version during copy
*/
- @Parameter( property = "mdep.stripVersion", defaultValue = "false" )
+ @Parameter(property = "mdep.stripVersion", defaultValue = "false")
private boolean stripVersion = false;
/**
* Strip artifact classifier during copy
*/
- @Parameter( property = "mdep.stripClassifier", defaultValue = "false" )
+ @Parameter(property = "mdep.stripClassifier", defaultValue = "false")
private boolean stripClassifier = false;
/**
* Prepend artifact groupId during copy
- *
+ *
* @since 2.7
*/
- @Parameter( property = "mdep.prependGroupId", defaultValue = "false" )
+ @Parameter(property = "mdep.prependGroupId", defaultValue = "false")
private boolean prependGroupId = false;
/**
* Use artifact baseVersion during copy
- *
+ *
* @since 2.7
*/
- @Parameter( property = "mdep.useBaseVersion", defaultValue = "false" )
+ @Parameter(property = "mdep.useBaseVersion", defaultValue = "false")
private boolean useBaseVersion = false;
/**
* The artifact to copy from command line. A string of the form groupId:artifactId:version[:packaging[:classifier]].
* Use {@link #artifactItems} within the POM configuration.
*/
- @SuppressWarnings( "unused" ) // marker-field, setArtifact(String) does the magic
- @Parameter( property = "artifact" )
+ @SuppressWarnings("unused") // marker-field, setArtifact(String) does the magic
+ @Parameter(property = "artifact")
private String artifact;
/**
@@ -99,23 +95,16 @@ public class CopyMojo
* @see #copyArtifact(ArtifactItem)
*/
@Override
- protected void doExecute()
- throws MojoExecutionException, MojoFailureException
- {
+ protected void doExecute() throws MojoExecutionException, MojoFailureException {
verifyRequirements();
- List theArtifactItems =
- getProcessedArtifactItems( new ProcessArtifactItemsRequest( stripVersion, prependGroupId, useBaseVersion,
- stripClassifier ) );
- for ( ArtifactItem artifactItem : theArtifactItems )
- {
- if ( artifactItem.isNeedsProcessing() )
- {
- copyArtifact( artifactItem );
- }
- else
- {
- this.getLog().info( artifactItem + " already exists in " + artifactItem.getOutputDirectory() );
+ List theArtifactItems = getProcessedArtifactItems(
+ new ProcessArtifactItemsRequest(stripVersion, prependGroupId, useBaseVersion, stripClassifier));
+ for (ArtifactItem artifactItem : theArtifactItems) {
+ if (artifactItem.isNeedsProcessing()) {
+ copyArtifact(artifactItem);
+ } else {
+ this.getLog().info(artifactItem + " already exists in " + artifactItem.getOutputDirectory());
}
}
}
@@ -127,59 +116,60 @@ protected void doExecute()
* @throws MojoExecutionException with a message if an error occurs.
* @see #copyFile(File, File)
*/
- protected void copyArtifact( ArtifactItem artifactItem )
- throws MojoExecutionException
- {
- File destFile = new File( artifactItem.getOutputDirectory(), artifactItem.getDestFileName() );
+ protected void copyArtifact(ArtifactItem artifactItem) throws MojoExecutionException {
+ File destFile = new File(artifactItem.getOutputDirectory(), artifactItem.getDestFileName());
- copyFile( artifactItem.getArtifact().getFile(), destFile );
+ copyFile(artifactItem.getArtifact().getFile(), destFile);
}
@Override
- protected ArtifactItemFilter getMarkedArtifactFilter( ArtifactItem item )
- {
- return new DestFileFilter( this.isOverWriteReleases(), this.isOverWriteSnapshots(), this.isOverWriteIfNewer(),
- false, false, false, false, this.stripVersion, prependGroupId, useBaseVersion,
- item.getOutputDirectory() );
+ protected ArtifactItemFilter getMarkedArtifactFilter(ArtifactItem item) {
+ return new DestFileFilter(
+ this.isOverWriteReleases(),
+ this.isOverWriteSnapshots(),
+ this.isOverWriteIfNewer(),
+ false,
+ false,
+ false,
+ false,
+ this.stripVersion,
+ prependGroupId,
+ useBaseVersion,
+ item.getOutputDirectory());
}
/**
* @return Returns the stripVersion.
*/
- public boolean isStripVersion()
- {
+ public boolean isStripVersion() {
return this.stripVersion;
}
/**
* @param stripVersion The stripVersion to set.
*/
- public void setStripVersion( boolean stripVersion )
- {
+ public void setStripVersion(boolean stripVersion) {
this.stripVersion = stripVersion;
}
/**
* @return Returns the stripClassifier.
*/
- public boolean isStripClassifier()
- {
+ public boolean isStripClassifier() {
return this.stripClassifier;
}
/**
* @param stripClassifier The stripClassifier to set.
*/
- public void setStripClassifier( boolean stripClassifier )
- {
+ public void setStripClassifier(boolean stripClassifier) {
this.stripClassifier = stripClassifier;
}
/**
* @param useBaseVersion The useBaseVersion to set.
*/
- public void setUseBaseVersion( boolean useBaseVersion )
- {
+ public void setUseBaseVersion(boolean useBaseVersion) {
this.useBaseVersion = useBaseVersion;
}
}
diff --git a/src/main/java/org/apache/maven/plugins/dependency/fromConfiguration/ProcessArtifactItemsRequest.java b/src/main/java/org/apache/maven/plugins/dependency/fromConfiguration/ProcessArtifactItemsRequest.java
index 0e27b553e..e70897d5d 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/fromConfiguration/ProcessArtifactItemsRequest.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/fromConfiguration/ProcessArtifactItemsRequest.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.dependency.fromConfiguration;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
@@ -18,13 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.dependency.fromConfiguration;
/**
* @author Olivier Lamy
* @since 2.7
*/
-public class ProcessArtifactItemsRequest
-{
+public class ProcessArtifactItemsRequest {
/**
* remove the version from the filename.
*/
@@ -48,8 +46,7 @@ public class ProcessArtifactItemsRequest
/**
* Default ctor.
*/
- public ProcessArtifactItemsRequest()
- {
+ public ProcessArtifactItemsRequest() {
// no op
}
@@ -59,9 +56,8 @@ public ProcessArtifactItemsRequest()
* @param useBaseVersion {@link #useBaseVersion}
* @param removeClassifier {@link #removeClassifier}
*/
- public ProcessArtifactItemsRequest( boolean removeVersion, boolean prependGroupId, boolean useBaseVersion,
- boolean removeClassifier )
- {
+ public ProcessArtifactItemsRequest(
+ boolean removeVersion, boolean prependGroupId, boolean useBaseVersion, boolean removeClassifier) {
this.removeVersion = removeVersion;
this.prependGroupId = prependGroupId;
this.useBaseVersion = useBaseVersion;
@@ -71,32 +67,28 @@ public ProcessArtifactItemsRequest( boolean removeVersion, boolean prependGroupI
/**
* @return {@link #removeVersion}
*/
- public boolean isRemoveVersion()
- {
+ public boolean isRemoveVersion() {
return removeVersion;
}
/**
* @param removeVersion {@link #removeVersion}
*/
- public void setRemoveVersion( boolean removeVersion )
- {
+ public void setRemoveVersion(boolean removeVersion) {
this.removeVersion = removeVersion;
}
/**
* @return {@link #removeClassifier}
*/
- public boolean isRemoveClassifier()
- {
+ public boolean isRemoveClassifier() {
return removeClassifier;
}
/**
* @param removeClassifier {@link #removeClassifier}
*/
- public void setRemoveClassifier( boolean removeClassifier )
- {
+ public void setRemoveClassifier(boolean removeClassifier) {
this.removeClassifier = removeClassifier;
}
@@ -104,8 +96,7 @@ public void setRemoveClassifier( boolean removeClassifier )
* @param theRemoveVersion {@link #removeVersion}
* @return {@link ProcessArtifactItemsRequest}
*/
- public ProcessArtifactItemsRequest removeVersion( boolean theRemoveVersion )
- {
+ public ProcessArtifactItemsRequest removeVersion(boolean theRemoveVersion) {
this.removeVersion = theRemoveVersion;
return this;
}
@@ -113,16 +104,14 @@ public ProcessArtifactItemsRequest removeVersion( boolean theRemoveVersion )
/**
* @return {@link #prependGroupId}
*/
- public boolean isPrependGroupId()
- {
+ public boolean isPrependGroupId() {
return prependGroupId;
}
/**
* @param prependGroupId {@link #prependGroupId}
*/
- public void setPrependGroupId( boolean prependGroupId )
- {
+ public void setPrependGroupId(boolean prependGroupId) {
this.prependGroupId = prependGroupId;
}
@@ -130,8 +119,7 @@ public void setPrependGroupId( boolean prependGroupId )
* @param thePrependGroupId {@link #prependGroupId}
* @return {@link ProcessArtifactItemsRequest}
*/
- public ProcessArtifactItemsRequest prependGroupId( boolean thePrependGroupId )
- {
+ public ProcessArtifactItemsRequest prependGroupId(boolean thePrependGroupId) {
this.prependGroupId = thePrependGroupId;
return this;
}
@@ -139,16 +127,14 @@ public ProcessArtifactItemsRequest prependGroupId( boolean thePrependGroupId )
/**
* @return {@link #useBaseVersion}
*/
- public boolean isUseBaseVersion()
- {
+ public boolean isUseBaseVersion() {
return useBaseVersion;
}
/**
* @param useBaseVersion {@link #useBaseVersion}
*/
- public void setUseBaseVersion( boolean useBaseVersion )
- {
+ public void setUseBaseVersion(boolean useBaseVersion) {
this.useBaseVersion = useBaseVersion;
}
@@ -156,8 +142,7 @@ public void setUseBaseVersion( boolean useBaseVersion )
* @param theUseBaseVersion {@link #useBaseVersion}
* @return {@link ProcessArtifactItemsRequest}
*/
- public ProcessArtifactItemsRequest useBaseVersion( boolean theUseBaseVersion )
- {
+ public ProcessArtifactItemsRequest useBaseVersion(boolean theUseBaseVersion) {
this.useBaseVersion = theUseBaseVersion;
return this;
}
diff --git a/src/main/java/org/apache/maven/plugins/dependency/fromConfiguration/UnpackMojo.java b/src/main/java/org/apache/maven/plugins/dependency/fromConfiguration/UnpackMojo.java
index 8f852767f..b76add1e0 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/fromConfiguration/UnpackMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/fromConfiguration/UnpackMojo.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.dependency.fromConfiguration;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
@@ -18,37 +16,35 @@
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.dependency.fromConfiguration;
+import java.io.File;
+import java.util.List;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.dependency.utils.filters.ArtifactItemFilter;
import org.apache.maven.plugins.dependency.utils.filters.MarkerFileFilter;
import org.apache.maven.plugins.dependency.utils.markers.MarkerHandler;
import org.apache.maven.plugins.dependency.utils.markers.UnpackFileMarkerHandler;
-import org.apache.maven.plugins.annotations.LifecyclePhase;
-import org.apache.maven.plugins.annotations.Mojo;
-import org.apache.maven.plugins.annotations.Parameter;
import org.codehaus.plexus.components.io.filemappers.FileMapper;
import org.codehaus.plexus.util.StringUtils;
-import java.io.File;
-import java.util.List;
-
/**
* Goal that retrieves a list of artifacts from the repository and unpacks them in a defined location.
*
* @author Brian Fox
* @since 1.0
*/
-@Mojo( name = "unpack", defaultPhase = LifecyclePhase.PROCESS_SOURCES, requiresProject = false, threadSafe = true )
-public class UnpackMojo
- extends AbstractFromConfigurationMojo
-{
+@Mojo(name = "unpack", defaultPhase = LifecyclePhase.PROCESS_SOURCES, requiresProject = false, threadSafe = true)
+public class UnpackMojo extends AbstractFromConfigurationMojo {
/**
* Directory to store flag files after unpack
*/
- @Parameter( defaultValue = "${project.build.directory}/dependency-maven-plugin-markers" )
+ @Parameter(defaultValue = "${project.build.directory}/dependency-maven-plugin-markers")
private File markersDirectory;
/**
@@ -58,7 +54,7 @@ public class UnpackMojo
*
* @since 2.0-alpha-5
*/
- @Parameter( property = "mdep.unpack.includes" )
+ @Parameter(property = "mdep.unpack.includes")
private String includes;
/**
@@ -68,7 +64,7 @@ public class UnpackMojo
*
* @since 2.0-alpha-5
*/
- @Parameter( property = "mdep.unpack.excludes" )
+ @Parameter(property = "mdep.unpack.excludes")
private String excludes;
/**
@@ -76,7 +72,7 @@ public class UnpackMojo
*
* @since 3.1.2
*/
- @Parameter( property = "mdep.unpack.filemappers" )
+ @Parameter(property = "mdep.unpack.filemappers")
private FileMapper[] fileMappers;
/**
@@ -84,8 +80,8 @@ public class UnpackMojo
* groupId:artifactId:version[:packaging[:classifier]]
. Use {@link #artifactItems} within the POM
* configuration.
*/
- @SuppressWarnings( "unused" ) // marker-field, setArtifact(String) does the magic
- @Parameter( property = "artifact" )
+ @SuppressWarnings("unused") // marker-field, setArtifact(String) does the magic
+ @Parameter(property = "artifact")
private String artifact;
/**
@@ -98,26 +94,19 @@ public class UnpackMojo
* @see #unpackArtifact(ArtifactItem)
*/
@Override
- protected void doExecute()
- throws MojoExecutionException, MojoFailureException
- {
- if ( isSkip() )
- {
+ protected void doExecute() throws MojoExecutionException, MojoFailureException {
+ if (isSkip()) {
return;
}
verifyRequirements();
- List processedItems = getProcessedArtifactItems( false );
- for ( ArtifactItem artifactItem : processedItems )
- {
- if ( artifactItem.isNeedsProcessing() )
- {
- unpackArtifact( artifactItem );
- }
- else
- {
- this.getLog().info( artifactItem.getArtifact().getFile().getName() + " already unpacked." );
+ List processedItems = getProcessedArtifactItems(false);
+ for (ArtifactItem artifactItem : processedItems) {
+ if (artifactItem.isNeedsProcessing()) {
+ unpackArtifact(artifactItem);
+ } else {
+ this.getLog().info(artifactItem.getArtifact().getFile().getName() + " already unpacked.");
}
}
}
@@ -129,24 +118,26 @@ protected void doExecute()
* @throws MojoExecutionException with a message if an error occurs.
* @see #getArtifact
*/
- private void unpackArtifact( ArtifactItem artifactItem )
- throws MojoExecutionException
- {
- MarkerHandler handler = new UnpackFileMarkerHandler( artifactItem, this.markersDirectory );
-
- unpack( artifactItem.getArtifact(), artifactItem.getType(), artifactItem.getOutputDirectory(),
- artifactItem.getIncludes(), artifactItem.getExcludes(), artifactItem.getEncoding(),
- artifactItem.getFileMappers() );
+ private void unpackArtifact(ArtifactItem artifactItem) throws MojoExecutionException {
+ MarkerHandler handler = new UnpackFileMarkerHandler(artifactItem, this.markersDirectory);
+
+ unpack(
+ artifactItem.getArtifact(),
+ artifactItem.getType(),
+ artifactItem.getOutputDirectory(),
+ artifactItem.getIncludes(),
+ artifactItem.getExcludes(),
+ artifactItem.getEncoding(),
+ artifactItem.getFileMappers());
handler.setMarker();
}
@Override
- ArtifactItemFilter getMarkedArtifactFilter( ArtifactItem item )
- {
- MarkerHandler handler = new UnpackFileMarkerHandler( item, this.markersDirectory );
+ ArtifactItemFilter getMarkedArtifactFilter(ArtifactItem item) {
+ MarkerHandler handler = new UnpackFileMarkerHandler(item, this.markersDirectory);
- return new MarkerFileFilter( this.isOverWriteReleases(), this.isOverWriteSnapshots(), this.isOverWriteIfNewer(),
- handler );
+ return new MarkerFileFilter(
+ this.isOverWriteReleases(), this.isOverWriteSnapshots(), this.isOverWriteIfNewer(), handler);
}
/**
@@ -154,20 +145,15 @@ ArtifactItemFilter getMarkedArtifactFilter( ArtifactItem item )
* @return list of {@link ArtifactItem}
* @throws MojoExecutionException in case of an error.
*/
- protected List getProcessedArtifactItems( boolean removeVersion )
- throws MojoExecutionException
- {
+ protected List getProcessedArtifactItems(boolean removeVersion) throws MojoExecutionException {
List items =
- super.getProcessedArtifactItems( new ProcessArtifactItemsRequest( removeVersion, false, false, false ) );
- for ( ArtifactItem artifactItem : items )
- {
- if ( StringUtils.isEmpty( artifactItem.getIncludes() ) )
- {
- artifactItem.setIncludes( getIncludes() );
+ super.getProcessedArtifactItems(new ProcessArtifactItemsRequest(removeVersion, false, false, false));
+ for (ArtifactItem artifactItem : items) {
+ if (StringUtils.isEmpty(artifactItem.getIncludes())) {
+ artifactItem.setIncludes(getIncludes());
}
- if ( StringUtils.isEmpty( artifactItem.getExcludes() ) )
- {
- artifactItem.setExcludes( getExcludes() );
+ if (StringUtils.isEmpty(artifactItem.getExcludes())) {
+ artifactItem.setExcludes(getExcludes());
}
}
return items;
@@ -176,48 +162,42 @@ protected List getProcessedArtifactItems( boolean removeVersion )
/**
* @return Returns the markersDirectory.
*/
- public File getMarkersDirectory()
- {
+ public File getMarkersDirectory() {
return this.markersDirectory;
}
/**
* @param theMarkersDirectory The markersDirectory to set.
*/
- public void setMarkersDirectory( File theMarkersDirectory )
- {
+ public void setMarkersDirectory(File theMarkersDirectory) {
this.markersDirectory = theMarkersDirectory;
}
/**
* @return Returns a comma separated list of excluded items
*/
- public String getExcludes()
- {
+ public String getExcludes() {
return this.excludes;
}
/**
* @param excludes A comma separated list of items to exclude i.e. **\/*.xml, **\/*.properties
*/
- public void setExcludes( String excludes )
- {
+ public void setExcludes(String excludes) {
this.excludes = excludes;
}
/**
* @return Returns a comma separated list of included items
*/
- public String getIncludes()
- {
+ public String getIncludes() {
return this.includes;
}
/**
* @param includes A comma separated list of items to include i.e. **\/*.xml, **\/*.properties
*/
- public void setIncludes( String includes )
- {
+ public void setIncludes(String includes) {
this.includes = includes;
}
@@ -227,8 +207,7 @@ public void setIncludes( String includes )
*
* @since 3.1.2
*/
- public FileMapper[] getFileMappers()
- {
+ public FileMapper[] getFileMappers() {
return this.fileMappers;
}
@@ -238,8 +217,7 @@ public FileMapper[] getFileMappers()
*
* @since 3.1.2
*/
- public void setFileMappers( FileMapper[] fileMappers )
- {
+ public void setFileMappers(FileMapper[] fileMappers) {
this.fileMappers = fileMappers;
}
}
diff --git a/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/AbstractDependencyFilterMojo.java b/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/AbstractDependencyFilterMojo.java
index 93e96c8cb..7d1ab01a1 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/AbstractDependencyFilterMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/AbstractDependencyFilterMojo.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.dependency.fromDependencies;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
@@ -18,13 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.dependency.fromDependencies;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.Set;
-
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
import org.apache.maven.plugin.MojoExecutionException;
@@ -61,9 +59,7 @@
* @author Brian Fox
* @see org.apache.maven.plugins.dependency.AbstractDependencyMojo
*/
-public abstract class AbstractDependencyFilterMojo
- extends AbstractDependencyMojo
-{
+public abstract class AbstractDependencyFilterMojo extends AbstractDependencyMojo {
@Component
private ArtifactResolver artifactResolver;
@@ -78,7 +74,7 @@ public abstract class AbstractDependencyFilterMojo
*
* @since 1.0
*/
- @Parameter( property = "overWriteReleases", defaultValue = "false" )
+ @Parameter(property = "overWriteReleases", defaultValue = "false")
protected boolean overWriteReleases;
/**
@@ -86,7 +82,7 @@ public abstract class AbstractDependencyFilterMojo
*
* @since 1.0
*/
- @Parameter( property = "overWriteSnapshots", defaultValue = "false" )
+ @Parameter(property = "overWriteSnapshots", defaultValue = "false")
protected boolean overWriteSnapshots;
/**
@@ -94,7 +90,7 @@ public abstract class AbstractDependencyFilterMojo
*
* @since 2.0
*/
- @Parameter( property = "overWriteIfNewer", defaultValue = "true" )
+ @Parameter(property = "overWriteIfNewer", defaultValue = "true")
protected boolean overWriteIfNewer;
/**
@@ -102,7 +98,7 @@ public abstract class AbstractDependencyFilterMojo
*
* @since 2.0
*/
- @Parameter( property = "excludeTransitive", defaultValue = "false" )
+ @Parameter(property = "excludeTransitive", defaultValue = "false")
protected boolean excludeTransitive;
/**
@@ -110,7 +106,7 @@ public abstract class AbstractDependencyFilterMojo
*
* @since 2.0
*/
- @Parameter( property = "includeTypes", defaultValue = "" )
+ @Parameter(property = "includeTypes", defaultValue = "")
protected String includeTypes;
/**
@@ -118,7 +114,7 @@ public abstract class AbstractDependencyFilterMojo
*
* @since 2.0
*/
- @Parameter( property = "excludeTypes", defaultValue = "" )
+ @Parameter(property = "excludeTypes", defaultValue = "")
protected String excludeTypes;
/**
@@ -135,7 +131,7 @@ public abstract class AbstractDependencyFilterMojo
*
* @since 2.0
*/
- @Parameter( property = "includeScope", defaultValue = "" )
+ @Parameter(property = "includeScope", defaultValue = "")
protected String includeScope;
/**
@@ -154,7 +150,7 @@ public abstract class AbstractDependencyFilterMojo
*
* @since 2.0
*/
- @Parameter( property = "excludeScope", defaultValue = "" )
+ @Parameter(property = "excludeScope", defaultValue = "")
protected String excludeScope;
/**
@@ -162,7 +158,7 @@ public abstract class AbstractDependencyFilterMojo
*
* @since 2.0
*/
- @Parameter( property = "includeClassifiers", defaultValue = "" )
+ @Parameter(property = "includeClassifiers", defaultValue = "")
protected String includeClassifiers;
/**
@@ -170,7 +166,7 @@ public abstract class AbstractDependencyFilterMojo
*
* @since 2.0
*/
- @Parameter( property = "excludeClassifiers", defaultValue = "" )
+ @Parameter(property = "excludeClassifiers", defaultValue = "")
protected String excludeClassifiers;
/**
@@ -178,7 +174,7 @@ public abstract class AbstractDependencyFilterMojo
*
* @since 2.0
*/
- @Parameter( property = "classifier", defaultValue = "" )
+ @Parameter(property = "classifier", defaultValue = "")
protected String classifier;
/**
@@ -186,7 +182,7 @@ public abstract class AbstractDependencyFilterMojo
*
* @since 2.0
*/
- @Parameter( property = "type", defaultValue = "" )
+ @Parameter(property = "type", defaultValue = "")
protected String type;
/**
@@ -194,7 +190,7 @@ public abstract class AbstractDependencyFilterMojo
*
* @since 2.0
*/
- @Parameter( property = "excludeArtifactIds", defaultValue = "" )
+ @Parameter(property = "excludeArtifactIds", defaultValue = "")
protected String excludeArtifactIds;
/**
@@ -202,7 +198,7 @@ public abstract class AbstractDependencyFilterMojo
*
* @since 2.0
*/
- @Parameter( property = "includeArtifactIds", defaultValue = "" )
+ @Parameter(property = "includeArtifactIds", defaultValue = "")
protected String includeArtifactIds;
/**
@@ -210,7 +206,7 @@ public abstract class AbstractDependencyFilterMojo
*
* @since 2.0
*/
- @Parameter( property = "excludeGroupIds", defaultValue = "" )
+ @Parameter(property = "excludeGroupIds", defaultValue = "")
protected String excludeGroupIds;
/**
@@ -218,7 +214,7 @@ public abstract class AbstractDependencyFilterMojo
*
* @since 2.0
*/
- @Parameter( property = "includeGroupIds", defaultValue = "" )
+ @Parameter(property = "includeGroupIds", defaultValue = "")
protected String includeGroupIds;
/**
@@ -226,9 +222,11 @@ public abstract class AbstractDependencyFilterMojo
*
* @since 2.0
*/
- //CHECKSTYLE_OFF: LineLength
- @Parameter( property = "markersDirectory", defaultValue = "${project.build.directory}/dependency-maven-plugin-markers" )
- //CHECKSTYLE_ON: LineLength
+ // CHECKSTYLE_OFF: LineLength
+ @Parameter(
+ property = "markersDirectory",
+ defaultValue = "${project.build.directory}/dependency-maven-plugin-markers")
+ // CHECKSTYLE_ON: LineLength
protected File markersDirectory;
/**
@@ -236,7 +234,7 @@ public abstract class AbstractDependencyFilterMojo
*
* @since 2.2
*/
- @Parameter( property = "mdep.prependGroupId", defaultValue = "false" )
+ @Parameter(property = "mdep.prependGroupId", defaultValue = "false")
protected boolean prependGroupId = false;
@Component
@@ -259,11 +257,9 @@ public abstract class AbstractDependencyFilterMojo
* @return A set of artifacts
* @throws MojoExecutionException in case of errors.
*/
- protected Set getResolvedDependencies( boolean stopOnFailure )
- throws MojoExecutionException
+ protected Set getResolvedDependencies(boolean stopOnFailure) throws MojoExecutionException {
- {
- DependencyStatusSets status = getDependencySets( stopOnFailure );
+ DependencyStatusSets status = getDependencySets(stopOnFailure);
return status.getResolvedDependencies();
}
@@ -273,10 +269,8 @@ protected Set getResolvedDependencies( boolean stopOnFailure )
* @return {@link DependencyStatusSets}
* @throws MojoExecutionException in case of an error.
*/
- protected DependencyStatusSets getDependencySets( boolean stopOnFailure )
- throws MojoExecutionException
- {
- return getDependencySets( stopOnFailure, false );
+ protected DependencyStatusSets getDependencySets(boolean stopOnFailure) throws MojoExecutionException {
+ return getDependencySets(stopOnFailure, false);
}
/**
@@ -288,112 +282,97 @@ protected DependencyStatusSets getDependencySets( boolean stopOnFailure )
* @return DependencyStatusSets - Bean of TreeSets that contains information on the projects dependencies
* @throws MojoExecutionException in case of errors.
*/
- protected DependencyStatusSets getDependencySets( boolean stopOnFailure, boolean includeParents )
- throws MojoExecutionException
- {
+ protected DependencyStatusSets getDependencySets(boolean stopOnFailure, boolean includeParents)
+ throws MojoExecutionException {
// add filters in well known order, least specific to most specific
FilterArtifacts filter = new FilterArtifacts();
- filter.addFilter( new ProjectTransitivityFilter( getProject().getDependencyArtifacts(),
- this.excludeTransitive ) );
+ filter.addFilter(new ProjectTransitivityFilter(getProject().getDependencyArtifacts(), this.excludeTransitive));
- if ( "test".equals( this.excludeScope ) )
- {
- throw new MojoExecutionException( "Excluding every artifact inside 'test' resolution scope means "
- + "excluding everything: you probably want includeScope='compile', "
- + "read parameters documentation for detailed explanations" );
+ if ("test".equals(this.excludeScope)) {
+ throw new MojoExecutionException("Excluding every artifact inside 'test' resolution scope means "
+ + "excluding everything: you probably want includeScope='compile', "
+ + "read parameters documentation for detailed explanations");
}
- filter.addFilter( new ScopeFilter( DependencyUtil.cleanToBeTokenizedString( this.includeScope ),
- DependencyUtil.cleanToBeTokenizedString( this.excludeScope ) ) );
+ filter.addFilter(new ScopeFilter(
+ DependencyUtil.cleanToBeTokenizedString(this.includeScope),
+ DependencyUtil.cleanToBeTokenizedString(this.excludeScope)));
- filter.addFilter( new TypeFilter( DependencyUtil.cleanToBeTokenizedString( this.includeTypes ),
- DependencyUtil.cleanToBeTokenizedString( this.excludeTypes ) ) );
+ filter.addFilter(new TypeFilter(
+ DependencyUtil.cleanToBeTokenizedString(this.includeTypes),
+ DependencyUtil.cleanToBeTokenizedString(this.excludeTypes)));
- filter.addFilter( new ClassifierFilter( DependencyUtil.cleanToBeTokenizedString( this.includeClassifiers ),
- DependencyUtil.cleanToBeTokenizedString( this.excludeClassifiers ) ) );
+ filter.addFilter(new ClassifierFilter(
+ DependencyUtil.cleanToBeTokenizedString(this.includeClassifiers),
+ DependencyUtil.cleanToBeTokenizedString(this.excludeClassifiers)));
- filter.addFilter( new GroupIdFilter( DependencyUtil.cleanToBeTokenizedString( this.includeGroupIds ),
- DependencyUtil.cleanToBeTokenizedString( this.excludeGroupIds ) ) );
+ filter.addFilter(new GroupIdFilter(
+ DependencyUtil.cleanToBeTokenizedString(this.includeGroupIds),
+ DependencyUtil.cleanToBeTokenizedString(this.excludeGroupIds)));
- filter.addFilter( new ArtifactIdFilter( DependencyUtil.cleanToBeTokenizedString( this.includeArtifactIds ),
- DependencyUtil.cleanToBeTokenizedString( this.excludeArtifactIds ) ) );
+ filter.addFilter(new ArtifactIdFilter(
+ DependencyUtil.cleanToBeTokenizedString(this.includeArtifactIds),
+ DependencyUtil.cleanToBeTokenizedString(this.excludeArtifactIds)));
// start with all artifacts.
Set artifacts = getProject().getArtifacts();
- if ( includeParents )
- {
+ if (includeParents) {
// add dependencies parents
- for ( Artifact dep : new ArrayList<>( artifacts ) )
- {
- addParentArtifacts( buildProjectFromArtifact( dep ), artifacts );
+ for (Artifact dep : new ArrayList<>(artifacts)) {
+ addParentArtifacts(buildProjectFromArtifact(dep), artifacts);
}
// add current project parent
- addParentArtifacts( getProject(), artifacts );
+ addParentArtifacts(getProject(), artifacts);
}
// perform filtering
- try
- {
- artifacts = filter.filter( artifacts );
- }
- catch ( ArtifactFilterException e )
- {
- throw new MojoExecutionException( e.getMessage(), e );
+ try {
+ artifacts = filter.filter(artifacts);
+ } catch (ArtifactFilterException e) {
+ throw new MojoExecutionException(e.getMessage(), e);
}
// transform artifacts if classifier is set
DependencyStatusSets status;
- if ( StringUtils.isNotEmpty( classifier ) )
- {
- status = getClassifierTranslatedDependencies( artifacts, stopOnFailure );
- }
- else
- {
- status = filterMarkedDependencies( artifacts );
+ if (StringUtils.isNotEmpty(classifier)) {
+ status = getClassifierTranslatedDependencies(artifacts, stopOnFailure);
+ } else {
+ status = filterMarkedDependencies(artifacts);
}
return status;
}
- private MavenProject buildProjectFromArtifact( Artifact artifact )
- throws MojoExecutionException
- {
- try
- {
- return projectBuilder.build( artifact, session.getProjectBuildingRequest() ).getProject();
- }
- catch ( ProjectBuildingException e )
- {
- throw new MojoExecutionException( e.getMessage(), e );
+ private MavenProject buildProjectFromArtifact(Artifact artifact) throws MojoExecutionException {
+ try {
+ return projectBuilder
+ .build(artifact, session.getProjectBuildingRequest())
+ .getProject();
+ } catch (ProjectBuildingException e) {
+ throw new MojoExecutionException(e.getMessage(), e);
}
}
- private void addParentArtifacts( MavenProject project, Set artifacts )
- throws MojoExecutionException
- {
- while ( project.hasParent() )
- {
+ private void addParentArtifacts(MavenProject project, Set artifacts) throws MojoExecutionException {
+ while (project.hasParent()) {
project = project.getParent();
- if ( artifacts.contains( project.getArtifact() ) )
- {
+ if (artifacts.contains(project.getArtifact())) {
// artifact already in the set
break;
}
- try
- {
+ try {
ProjectBuildingRequest buildingRequest = newResolveArtifactProjectBuildingRequest();
- Artifact resolvedArtifact =
- artifactResolver.resolveArtifact( buildingRequest, project.getArtifact() ).getArtifact();
+ Artifact resolvedArtifact = artifactResolver
+ .resolveArtifact(buildingRequest, project.getArtifact())
+ .getArtifact();
- artifacts.add( resolvedArtifact );
- }
- catch ( ArtifactResolverException e )
- {
- throw new MojoExecutionException( e.getMessage(), e );
+ artifacts.add(resolvedArtifact);
+ } catch (ArtifactResolverException e) {
+ throw new MojoExecutionException(e.getMessage(), e);
}
}
}
@@ -406,9 +385,8 @@ private void addParentArtifacts( MavenProject project, Set artifacts )
* @return DependencyStatusSets - Bean of TreeSets that contains information on the projects dependencies
* @throws MojoExecutionException in case of an error.
*/
- protected DependencyStatusSets getClassifierTranslatedDependencies( Set artifacts, boolean stopOnFailure )
- throws MojoExecutionException
- {
+ protected DependencyStatusSets getClassifierTranslatedDependencies(Set artifacts, boolean stopOnFailure)
+ throws MojoExecutionException {
Set unResolvedArtifacts = new LinkedHashSet<>();
Set resolvedArtifacts = artifacts;
DependencyStatusSets status = new DependencyStatusSets();
@@ -416,28 +394,27 @@ protected DependencyStatusSets getClassifierTranslatedDependencies( Set coordinates = translator.translate( artifacts, getLog() );
+ new ClassifierTypeTranslator(artifactHandlerManager, this.classifier, this.type);
+ Collection coordinates = translator.translate(artifacts, getLog());
- status = filterMarkedDependencies( artifacts );
+ status = filterMarkedDependencies(artifacts);
// the unskipped artifacts are in the resolved set.
artifacts = status.getResolvedDependencies();
// resolve the rest of the artifacts
- resolvedArtifacts = resolve( new LinkedHashSet<>( coordinates ), stopOnFailure );
+ resolvedArtifacts = resolve(new LinkedHashSet<>(coordinates), stopOnFailure);
// calculate the artifacts not resolved.
- unResolvedArtifacts.addAll( artifacts );
- unResolvedArtifacts.removeAll( resolvedArtifacts );
+ unResolvedArtifacts.addAll(artifacts);
+ unResolvedArtifacts.removeAll(resolvedArtifacts);
}
// return a bean of all 3 sets.
- status.setResolvedDependencies( resolvedArtifacts );
- status.setUnResolvedDependencies( unResolvedArtifacts );
+ status.setResolvedDependencies(resolvedArtifacts);
+ status.setUnResolvedDependencies(unResolvedArtifacts);
return status;
}
@@ -449,29 +426,24 @@ protected DependencyStatusSets getClassifierTranslatedDependencies( Set artifacts )
- throws MojoExecutionException
- {
+ protected DependencyStatusSets filterMarkedDependencies(Set artifacts) throws MojoExecutionException {
// remove files that have markers already
FilterArtifacts filter = new FilterArtifacts();
filter.clearFilters();
- filter.addFilter( getMarkedArtifactFilter() );
+ filter.addFilter(getMarkedArtifactFilter());
Set unMarkedArtifacts;
- try
- {
- unMarkedArtifacts = filter.filter( artifacts );
- }
- catch ( ArtifactFilterException e )
- {
- throw new MojoExecutionException( e.getMessage(), e );
+ try {
+ unMarkedArtifacts = filter.filter(artifacts);
+ } catch (ArtifactFilterException e) {
+ throw new MojoExecutionException(e.getMessage(), e);
}
// calculate the skipped artifacts
- Set skippedArtifacts = new LinkedHashSet<>( artifacts );
- skippedArtifacts.removeAll( unMarkedArtifacts );
+ Set skippedArtifacts = new LinkedHashSet<>(artifacts);
+ skippedArtifacts.removeAll(unMarkedArtifacts);
- return new DependencyStatusSets( unMarkedArtifacts, null, skippedArtifacts );
+ return new DependencyStatusSets(unMarkedArtifacts, null, skippedArtifacts);
}
/**
@@ -481,27 +453,23 @@ protected DependencyStatusSets filterMarkedDependencies( Set artifacts
* @return the resolved artifacts. {@link Artifact}.
* @throws MojoExecutionException in case of error.
*/
- protected Set resolve( Set coordinates, boolean stopOnFailure )
- throws MojoExecutionException
- {
+ protected Set resolve(Set coordinates, boolean stopOnFailure)
+ throws MojoExecutionException {
ProjectBuildingRequest buildingRequest = newResolveArtifactProjectBuildingRequest();
Set resolvedArtifacts = new LinkedHashSet<>();
- for ( ArtifactCoordinate coordinate : coordinates )
- {
- try
- {
- Artifact artifact = artifactResolver.resolveArtifact( buildingRequest, coordinate ).getArtifact();
- resolvedArtifacts.add( artifact );
- }
- catch ( ArtifactResolverException ex )
- {
+ for (ArtifactCoordinate coordinate : coordinates) {
+ try {
+ Artifact artifact = artifactResolver
+ .resolveArtifact(buildingRequest, coordinate)
+ .getArtifact();
+ resolvedArtifacts.add(artifact);
+ } catch (ArtifactResolverException ex) {
// an error occurred during resolution, log it an continue
- getLog().debug( "error resolving: " + coordinate );
- getLog().debug( ex );
- if ( stopOnFailure )
- {
- throw new MojoExecutionException( "error resolving: " + coordinate, ex );
+ getLog().debug("error resolving: " + coordinate);
+ getLog().debug(ex);
+ if (stopOnFailure) {
+ throw new MojoExecutionException("error resolving: " + coordinate, ex);
}
}
}
@@ -511,16 +479,14 @@ protected Set resolve( Set coordinates, boolean st
/**
* @return Returns the markersDirectory.
*/
- public File getMarkersDirectory()
- {
+ public File getMarkersDirectory() {
return this.markersDirectory;
}
/**
* @param theMarkersDirectory The markersDirectory to set.
*/
- public void setMarkersDirectory( File theMarkersDirectory )
- {
+ public void setMarkersDirectory(File theMarkersDirectory) {
this.markersDirectory = theMarkersDirectory;
}
@@ -529,40 +495,35 @@ public void setMarkersDirectory( File theMarkersDirectory )
/**
* @return true, if the groupId should be prepended to the filename.
*/
- public boolean isPrependGroupId()
- {
+ public boolean isPrependGroupId() {
return prependGroupId;
}
/**
* @param prependGroupId - true if the groupId must be prepended during the copy.
*/
- public void setPrependGroupId( boolean prependGroupId )
- {
+ public void setPrependGroupId(boolean prependGroupId) {
this.prependGroupId = prependGroupId;
}
/**
* @return {@link #artifactResolver}
*/
- protected final ArtifactResolver getArtifactResolver()
- {
+ protected final ArtifactResolver getArtifactResolver() {
return artifactResolver;
}
/**
* @return {@link #dependencyResolver}
*/
- protected final DependencyResolver getDependencyResolver()
- {
+ protected final DependencyResolver getDependencyResolver() {
return dependencyResolver;
}
/**
* @return {@link #repositoryManager}
*/
- protected final RepositoryManager getRepositoryManager()
- {
+ protected final RepositoryManager getRepositoryManager() {
return repositoryManager;
}
}
diff --git a/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/AbstractFromDependenciesMojo.java b/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/AbstractFromDependenciesMojo.java
index aad0cb635..1226c8ada 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/AbstractFromDependenciesMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/AbstractFromDependenciesMojo.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.dependency.fromDependencies;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
@@ -18,31 +16,29 @@
* specific language governing permissions and limitations
* under the License.
*/
-
-import org.apache.maven.plugins.annotations.Parameter;
+package org.apache.maven.plugins.dependency.fromDependencies;
import java.io.File;
+import org.apache.maven.plugins.annotations.Parameter;
/**
* Abstract Parent class used by mojos that get Artifact information from the project dependencies.
*
* @author Brian Fox
*/
-public abstract class AbstractFromDependenciesMojo
- extends AbstractDependencyFilterMojo
-{
+public abstract class AbstractFromDependenciesMojo extends AbstractDependencyFilterMojo {
/**
* Output location.
*
* @since 1.0
*/
- @Parameter( property = "outputDirectory", defaultValue = "${project.build.directory}/dependency" )
+ @Parameter(property = "outputDirectory", defaultValue = "${project.build.directory}/dependency")
protected File outputDirectory;
/**
* Strip artifact version during copy
*/
- @Parameter( property = "mdep.stripVersion", defaultValue = "false" )
+ @Parameter(property = "mdep.stripVersion", defaultValue = "false")
protected boolean stripVersion = false;
/**
@@ -50,13 +46,13 @@ public abstract class AbstractFromDependenciesMojo
*
* @since 3.4.0
*/
- @Parameter( property = "mdep.stripType", defaultValue = "false" )
+ @Parameter(property = "mdep.stripType", defaultValue = "false")
protected boolean stripType = false;
/**
* Strip artifact classifier during copy
*/
- @Parameter( property = "mdep.stripClassifier", defaultValue = "false" )
+ @Parameter(property = "mdep.stripClassifier", defaultValue = "false")
protected boolean stripClassifier = false;
/**
@@ -66,14 +62,14 @@ public abstract class AbstractFromDependenciesMojo
*
* example:
*
- *
+ *
*
* /outputDirectory/junit/junit/3.8.1/junit-3.8.1.jar
*
*
* @since 2.0-alpha-2
*/
- @Parameter( property = "mdep.useRepositoryLayout", defaultValue = "false" )
+ @Parameter(property = "mdep.useRepositoryLayout", defaultValue = "false")
protected boolean useRepositoryLayout;
/**
@@ -82,7 +78,7 @@ public abstract class AbstractFromDependenciesMojo
*
* @since 2.2
*/
- @Parameter( property = "mdep.useSubDirectoryPerScope", defaultValue = "false" )
+ @Parameter(property = "mdep.useSubDirectoryPerScope", defaultValue = "false")
protected boolean useSubDirectoryPerScope;
/**
@@ -90,7 +86,7 @@ public abstract class AbstractFromDependenciesMojo
*
* @since 2.0-alpha-1
*/
- @Parameter( property = "mdep.useSubDirectoryPerType", defaultValue = "false" )
+ @Parameter(property = "mdep.useSubDirectoryPerType", defaultValue = "false")
protected boolean useSubDirectoryPerType;
/**
@@ -98,7 +94,7 @@ public abstract class AbstractFromDependenciesMojo
*
* @since 2.0-alpha-1
*/
- @Parameter( property = "mdep.useSubDirectoryPerArtifact", defaultValue = "false" )
+ @Parameter(property = "mdep.useSubDirectoryPerArtifact", defaultValue = "false")
protected boolean useSubDirectoryPerArtifact;
/**
@@ -106,136 +102,118 @@ public abstract class AbstractFromDependenciesMojo
*
* @since 2.0-alpha-2
*/
- @Parameter( property = "mdep.failOnMissingClassifierArtifact", defaultValue = "false" )
+ @Parameter(property = "mdep.failOnMissingClassifierArtifact", defaultValue = "false")
protected boolean failOnMissingClassifierArtifact = true;
/**
* @return Returns the outputDirectory.
*/
- public File getOutputDirectory()
- {
+ public File getOutputDirectory() {
return this.outputDirectory;
}
/**
* @param theOutputDirectory The outputDirectory to set.
*/
- public void setOutputDirectory( File theOutputDirectory )
- {
+ public void setOutputDirectory(File theOutputDirectory) {
this.outputDirectory = theOutputDirectory;
}
/**
* @return Returns the useSubDirectoryPerArtifact.
*/
- public boolean isUseSubDirectoryPerArtifact()
- {
+ public boolean isUseSubDirectoryPerArtifact() {
return this.useSubDirectoryPerArtifact;
}
/**
* @param theUseSubDirectoryPerArtifact The useSubDirectoryPerArtifact to set.
*/
- public void setUseSubDirectoryPerArtifact( boolean theUseSubDirectoryPerArtifact )
- {
+ public void setUseSubDirectoryPerArtifact(boolean theUseSubDirectoryPerArtifact) {
this.useSubDirectoryPerArtifact = theUseSubDirectoryPerArtifact;
}
/**
* @return Returns the useSubDirectoryPerScope
*/
- public boolean isUseSubDirectoryPerScope()
- {
+ public boolean isUseSubDirectoryPerScope() {
return this.useSubDirectoryPerScope;
}
/**
* @param theUseSubDirectoryPerScope The useSubDirectoryPerScope to set.
*/
- public void setUseSubDirectoryPerScope( boolean theUseSubDirectoryPerScope )
- {
+ public void setUseSubDirectoryPerScope(boolean theUseSubDirectoryPerScope) {
this.useSubDirectoryPerScope = theUseSubDirectoryPerScope;
}
/**
* @return Returns the useSubDirectoryPerType.
*/
- public boolean isUseSubDirectoryPerType()
- {
+ public boolean isUseSubDirectoryPerType() {
return this.useSubDirectoryPerType;
}
/**
* @param theUseSubDirectoryPerType The useSubDirectoryPerType to set.
*/
- public void setUseSubDirectoryPerType( boolean theUseSubDirectoryPerType )
- {
+ public void setUseSubDirectoryPerType(boolean theUseSubDirectoryPerType) {
this.useSubDirectoryPerType = theUseSubDirectoryPerType;
}
/**
* @return {@link #failOnMissingClassifierArtifact}
*/
- public boolean isFailOnMissingClassifierArtifact()
- {
+ public boolean isFailOnMissingClassifierArtifact() {
return failOnMissingClassifierArtifact;
}
/**
* @param failOnMissingClassifierArtifact {@link #failOnMissingClassifierArtifact}
*/
- public void setFailOnMissingClassifierArtifact( boolean failOnMissingClassifierArtifact )
- {
+ public void setFailOnMissingClassifierArtifact(boolean failOnMissingClassifierArtifact) {
this.failOnMissingClassifierArtifact = failOnMissingClassifierArtifact;
}
/**
* @return {@link #stripVersion}
*/
- public boolean isStripVersion()
- {
+ public boolean isStripVersion() {
return stripVersion;
}
/**
* @param stripVersion {@link #stripVersion}
*/
- public void setStripVersion( boolean stripVersion )
- {
+ public void setStripVersion(boolean stripVersion) {
this.stripVersion = stripVersion;
}
-
/**
* @return {@link #stripType}
*/
- public boolean isStripType()
- {
+ public boolean isStripType() {
return stripType;
}
/**
* @param stripType {@link #stripType}
*/
- public void setStripType( boolean stripType )
- {
+ public void setStripType(boolean stripType) {
this.stripType = stripType;
}
-
/**
* @return true, if dependencies must be planted in a repository layout
*/
- public boolean isUseRepositoryLayout()
- {
+ public boolean isUseRepositoryLayout() {
return useRepositoryLayout;
}
/**
* @param useRepositoryLayout - true if dependencies must be planted in a repository layout
*/
- public void setUseRepositoryLayout( boolean useRepositoryLayout )
- {
+ public void setUseRepositoryLayout(boolean useRepositoryLayout) {
this.useRepositoryLayout = useRepositoryLayout;
}
}
diff --git a/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/BuildClasspathMojo.java b/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/BuildClasspathMojo.java
index 4a4176a91..8424f7084 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/BuildClasspathMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/BuildClasspathMojo.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.dependency.fromDependencies;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
@@ -18,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.dependency.fromDependencies;
import java.io.BufferedReader;
import java.io.BufferedWriter;
@@ -36,7 +35,6 @@
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Component;
@@ -58,51 +56,52 @@
* @since 2.0-alpha-2
*/
// CHECKSTYLE_OFF: LineLength
-@Mojo( name = "build-classpath", requiresDependencyResolution = ResolutionScope.TEST, defaultPhase = LifecyclePhase.GENERATE_SOURCES, threadSafe = true )
+@Mojo(
+ name = "build-classpath",
+ requiresDependencyResolution = ResolutionScope.TEST,
+ defaultPhase = LifecyclePhase.GENERATE_SOURCES,
+ threadSafe = true)
// CHECKSTYLE_ON: LineLength
-public class BuildClasspathMojo
- extends AbstractDependencyFilterMojo
- implements Comparator
-{
+public class BuildClasspathMojo extends AbstractDependencyFilterMojo implements Comparator {
- @Parameter( property = "outputEncoding", defaultValue = "${project.reporting.outputEncoding}" )
+ @Parameter(property = "outputEncoding", defaultValue = "${project.reporting.outputEncoding}")
private String outputEncoding;
-
+
/**
* Strip artifact version during copy (only works if prefix is set)
*/
- @Parameter( property = "mdep.stripVersion", defaultValue = "false" )
+ @Parameter(property = "mdep.stripVersion", defaultValue = "false")
private boolean stripVersion = false;
/**
* Strip artifact classifier during copy (only works if prefix is set)
*/
- @Parameter( property = "mdep.stripClassifier", defaultValue = "false" )
+ @Parameter(property = "mdep.stripClassifier", defaultValue = "false")
private boolean stripClassifier = false;
/**
* The prefix to prepend on each dependent artifact. If undefined, the paths refer to the actual files store in the
* local repository (the stripVersion parameter does nothing then).
*/
- @Parameter( property = "mdep.prefix" )
+ @Parameter(property = "mdep.prefix")
private String prefix;
/**
* A property to set to the content of the classpath string.
*/
- @Parameter( property = "mdep.outputProperty" )
+ @Parameter(property = "mdep.outputProperty")
private String outputProperty;
/**
* The file to write the classpath string. If undefined, it just prints the classpath as [INFO].
*/
- @Parameter( property = "mdep.outputFile" )
+ @Parameter(property = "mdep.outputFile")
private File outputFile;
/**
* If 'true', it skips the up-to-date-check, and always regenerates the classpath file.
*/
- @Parameter( property = "mdep.regenerateFile", defaultValue = "false" )
+ @Parameter(property = "mdep.regenerateFile", defaultValue = "false")
private boolean regenerateFile;
/**
@@ -112,7 +111,7 @@ public class BuildClasspathMojo
*
* @since 2.0
*/
- @Parameter( property = "mdep.fileSeparator", defaultValue = "" )
+ @Parameter(property = "mdep.fileSeparator", defaultValue = "")
private String fileSeparator;
/**
@@ -123,7 +122,7 @@ public class BuildClasspathMojo
*
* @since 2.0
*/
- @Parameter( property = "mdep.pathSeparator", defaultValue = "" )
+ @Parameter(property = "mdep.pathSeparator", defaultValue = "")
private String pathSeparator;
/**
@@ -132,7 +131,7 @@ public class BuildClasspathMojo
*
* @since 2.0
*/
- @Parameter( property = "mdep.localRepoProperty", defaultValue = "" )
+ @Parameter(property = "mdep.localRepoProperty", defaultValue = "")
private String localRepoProperty;
/**
@@ -140,7 +139,7 @@ public class BuildClasspathMojo
*
* @since 2.0
*/
- @Parameter( defaultValue = "false" )
+ @Parameter(defaultValue = "false")
private boolean attach;
/**
@@ -148,16 +147,16 @@ public class BuildClasspathMojo
*
* @since 2.0
*/
- @Parameter( property = "mdep.outputFilterFile", defaultValue = "false" )
+ @Parameter(property = "mdep.outputFilterFile", defaultValue = "false")
private boolean outputFilterFile;
/**
* Either append the artifact's baseVersion or uniqueVersion to the filename. Will only be used if
* {@link #isStripVersion()} is {@code false}.
- *
+ *
* @since 2.6
*/
- @Parameter( property = "mdep.useBaseVersion", defaultValue = "true" )
+ @Parameter(property = "mdep.useBaseVersion", defaultValue = "true")
private boolean useBaseVersion = true;
/**
@@ -176,39 +175,33 @@ public class BuildClasspathMojo
* @see #getResolvedDependencies(boolean)
*/
@Override
- protected void doExecute()
- throws MojoExecutionException
- {
+ protected void doExecute() throws MojoExecutionException {
// initialize the separators.
- boolean isFileSepSet = StringUtils.isNotEmpty( fileSeparator );
- boolean isPathSepSet = StringUtils.isNotEmpty( pathSeparator );
+ boolean isFileSepSet = StringUtils.isNotEmpty(fileSeparator);
+ boolean isPathSepSet = StringUtils.isNotEmpty(pathSeparator);
// don't allow them to have absolute paths when they attach.
- if ( attach && StringUtils.isEmpty( localRepoProperty ) )
- {
+ if (attach && StringUtils.isEmpty(localRepoProperty)) {
localRepoProperty = "${M2_REPO}";
}
- Set artifacts = getResolvedDependencies( true );
+ Set artifacts = getResolvedDependencies(true);
- if ( artifacts == null || artifacts.isEmpty() )
- {
- getLog().info( "No dependencies found." );
+ if (artifacts == null || artifacts.isEmpty()) {
+ getLog().info("No dependencies found.");
}
- List artList = new ArrayList<>( artifacts );
+ List artList = new ArrayList<>(artifacts);
StringBuilder sb = new StringBuilder();
Iterator i = artList.iterator();
- if ( i.hasNext() )
- {
- appendArtifactPath( i.next(), sb );
+ if (i.hasNext()) {
+ appendArtifactPath(i.next(), sb);
- while ( i.hasNext() )
- {
- sb.append( isPathSepSet ? this.pathSeparator : File.pathSeparator );
- appendArtifactPath( i.next(), sb );
+ while (i.hasNext()) {
+ sb.append(isPathSepSet ? this.pathSeparator : File.pathSeparator);
+ appendArtifactPath(i.next(), sb);
}
}
@@ -216,47 +209,36 @@ protected void doExecute()
// if file separator is set, I need to replace the default one from all
// the file paths that were pulled from the artifacts
- if ( isFileSepSet )
- {
+ if (isFileSepSet) {
// Escape file separators to be used as literal strings
- final String pattern = Pattern.quote( File.separator );
- final String replacement = Matcher.quoteReplacement( fileSeparator );
- cpString = cpString.replaceAll( pattern, replacement );
+ final String pattern = Pattern.quote(File.separator);
+ final String replacement = Matcher.quoteReplacement(fileSeparator);
+ cpString = cpString.replaceAll(pattern, replacement);
}
// make the string valid for filtering
- if ( outputFilterFile )
- {
+ if (outputFilterFile) {
cpString = "classpath=" + cpString;
}
- if ( outputProperty != null )
- {
- getProject().getProperties().setProperty( outputProperty, cpString );
- if ( getLog().isDebugEnabled() )
- {
- getLog().debug( outputProperty + " = " + cpString );
+ if (outputProperty != null) {
+ getProject().getProperties().setProperty(outputProperty, cpString);
+ if (getLog().isDebugEnabled()) {
+ getLog().debug(outputProperty + " = " + cpString);
}
}
- if ( outputFile == null )
- {
- getLog().info( "Dependencies classpath:" + System.lineSeparator() + cpString );
- }
- else
- {
- if ( regenerateFile || !isUpToDate( cpString ) )
- {
- storeClasspathFile( cpString, outputFile );
- }
- else
- {
- this.getLog().info( "Skipped writing classpath file '" + outputFile + "'. No changes found." );
+ if (outputFile == null) {
+ getLog().info("Dependencies classpath:" + System.lineSeparator() + cpString);
+ } else {
+ if (regenerateFile || !isUpToDate(cpString)) {
+ storeClasspathFile(cpString, outputFile);
+ } else {
+ this.getLog().info("Skipped writing classpath file '" + outputFile + "'. No changes found.");
}
}
- if ( attach )
- {
- attachFile( cpString );
+ if (attach) {
+ attachFile(cpString);
}
}
@@ -264,13 +246,11 @@ protected void doExecute()
* @param cpString The classpath.
* @throws MojoExecutionException in case of an error.
*/
- protected void attachFile( String cpString )
- throws MojoExecutionException
- {
- File attachedFile = new File( getProject().getBuild().getDirectory(), "classpath" );
- storeClasspathFile( cpString, attachedFile );
+ protected void attachFile(String cpString) throws MojoExecutionException {
+ File attachedFile = new File(getProject().getBuild().getDirectory(), "classpath");
+ storeClasspathFile(cpString, attachedFile);
- projectHelper.attachArtifact( getProject(), attachedFile, "classpath" );
+ projectHelper.attachArtifact(getProject(), attachedFile, "classpath");
}
/**
@@ -279,28 +259,23 @@ protected void attachFile( String cpString )
* @param art {@link Artifact}
* @param sb {@link StringBuilder}
*/
- protected void appendArtifactPath( Artifact art, StringBuilder sb )
- {
- if ( prefix == null )
- {
+ protected void appendArtifactPath(Artifact art, StringBuilder sb) {
+ if (prefix == null) {
String file = art.getFile().getPath();
// substitute the property for the local repo path to make the classpath file portable.
- if ( StringUtils.isNotEmpty( localRepoProperty ) )
- {
+ if (StringUtils.isNotEmpty(localRepoProperty)) {
ProjectBuildingRequest projectBuildingRequest = session.getProjectBuildingRequest();
- File localBasedir = repositoryManager.getLocalRepositoryBasedir( projectBuildingRequest );
+ File localBasedir = repositoryManager.getLocalRepositoryBasedir(projectBuildingRequest);
- file = StringUtils.replace( file, localBasedir.getAbsolutePath(), localRepoProperty );
+ file = StringUtils.replace(file, localBasedir.getAbsolutePath(), localRepoProperty);
}
- sb.append( file );
- }
- else
- {
+ sb.append(file);
+ } else {
// TODO: add param for prepending groupId and version.
- sb.append( prefix );
- sb.append( File.separator );
- sb.append( DependencyUtil.getFormattedFileName( art, this.stripVersion, this.prependGroupId,
- this.useBaseVersion, this.stripClassifier ) );
+ sb.append(prefix);
+ sb.append(File.separator);
+ sb.append(DependencyUtil.getFormattedFileName(
+ art, this.stripVersion, this.prependGroupId, this.useBaseVersion, this.stripClassifier));
}
}
@@ -310,17 +285,13 @@ protected void appendArtifactPath( Artifact art, StringBuilder sb )
* @return true if the specified classpath equals the one found inside the file, false otherwise (including when
* file does not exist but new classpath does).
*/
- private boolean isUpToDate( String cpString )
- {
- try
- {
+ private boolean isUpToDate(String cpString) {
+ try {
String oldCp = readClasspathFile();
- return Objects.equals( cpString, oldCp );
- }
- catch ( IOException ex )
- {
- this.getLog().warn( "Error while reading old classpath file '" + outputFile + "' for up-to-date check: "
- + ex );
+ return Objects.equals(cpString, oldCp);
+ } catch (IOException ex) {
+ this.getLog()
+ .warn("Error while reading old classpath file '" + outputFile + "' for up-to-date check: " + ex);
return false;
}
@@ -331,56 +302,42 @@ private boolean isUpToDate( String cpString )
*
* @param cpString the string to write into the file
*/
- private void storeClasspathFile( String cpString, File out )
- throws MojoExecutionException
- {
+ private void storeClasspathFile(String cpString, File out) throws MojoExecutionException {
// make sure the parent path exists.
out.getParentFile().mkdirs();
-
- String encoding = Objects.toString( outputEncoding, "UTF-8" );
-
- try ( Writer w =
- new BufferedWriter( new OutputStreamWriter( new FileOutputStream( out ), encoding ) ) )
- {
- w.write( cpString );
- getLog().info( "Wrote classpath file '" + out + "'." );
- }
- catch ( IOException ex )
- {
- throw new MojoExecutionException( "Error while writing to classpath file '" + out,
- ex );
+
+ String encoding = Objects.toString(outputEncoding, "UTF-8");
+
+ try (Writer w = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(out), encoding))) {
+ w.write(cpString);
+ getLog().info("Wrote classpath file '" + out + "'.");
+ } catch (IOException ex) {
+ throw new MojoExecutionException("Error while writing to classpath file '" + out, ex);
}
}
/**
* Reads the file specified by the mojo param 'outputFile' into a string. Assumes the field
* 'outputFile' is not null.
- *
+ *
* @return the string contained in the classpathFile, if it exists, or null otherwise
* @throws IOException in case of an error
*/
- protected String readClasspathFile()
- throws IOException
- {
- if ( outputFile == null )
- {
- throw new IllegalArgumentException( "The outputFile parameter "
- + "cannot be null if the file is intended to be read." );
+ protected String readClasspathFile() throws IOException {
+ if (outputFile == null) {
+ throw new IllegalArgumentException(
+ "The outputFile parameter " + "cannot be null if the file is intended to be read.");
}
- if ( !outputFile.isFile() )
- {
+ if (!outputFile.isFile()) {
return null;
}
StringBuilder sb = new StringBuilder();
- String encoding = Objects.toString( outputEncoding, "UTF-8" );
-
- try ( BufferedReader r =
- new BufferedReader( new InputStreamReader( new FileInputStream( outputFile ), encoding ) ) )
- {
- for ( String line = r.readLine(); line != null; line = r.readLine() )
- {
- sb.append( line );
+ String encoding = Objects.toString(outputEncoding, "UTF-8");
+
+ try (BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(outputFile), encoding))) {
+ for (String line = r.readLine(); line != null; line = r.readLine()) {
+ sb.append(line);
}
return sb.toString();
@@ -397,102 +354,86 @@ protected String readClasspathFile()
* 0
if this string is lexicographically greater than the string argument.
*/
@Override
- public int compare( Artifact art1, Artifact art2 )
- {
- if ( art1 == art2 )
- {
+ public int compare(Artifact art1, Artifact art2) {
+ if (art1 == art2) {
return 0;
- }
- else if ( art1 == null )
- {
+ } else if (art1 == null) {
return -1;
- }
- else if ( art2 == null )
- {
+ } else if (art2 == null) {
return +1;
}
String s1 = art1.getGroupId() + art1.getArtifactId() + art1.getVersion();
String s2 = art2.getGroupId() + art2.getArtifactId() + art2.getVersion();
- return s1.compareTo( s2 );
+ return s1.compareTo(s2);
}
@Override
- protected ArtifactsFilter getMarkedArtifactFilter()
- {
+ protected ArtifactsFilter getMarkedArtifactFilter() {
return null;
}
/**
* @param outputFile the outputFile to set
*/
- public void setOutputFile( File outputFile )
- {
+ public void setOutputFile(File outputFile) {
this.outputFile = outputFile;
}
/**
* @param theOutputProperty the outputProperty to set
*/
- public void setOutputProperty( String theOutputProperty )
- {
+ public void setOutputProperty(String theOutputProperty) {
this.outputProperty = theOutputProperty;
}
/**
* @param theFileSeparator the fileSeparator to set
*/
- public void setFileSeparator( String theFileSeparator )
- {
+ public void setFileSeparator(String theFileSeparator) {
this.fileSeparator = theFileSeparator;
}
/**
* @param thePathSeparator the pathSeparator to set
*/
- public void setPathSeparator( String thePathSeparator )
- {
+ public void setPathSeparator(String thePathSeparator) {
this.pathSeparator = thePathSeparator;
}
/**
* @param thePrefix the prefix to set
*/
- public void setPrefix( String thePrefix )
- {
+ public void setPrefix(String thePrefix) {
this.prefix = thePrefix;
}
/**
* @param theRegenerateFile the regenerateFile to set
*/
- public void setRegenerateFile( boolean theRegenerateFile )
- {
+ public void setRegenerateFile(boolean theRegenerateFile) {
this.regenerateFile = theRegenerateFile;
}
/**
* @return the stripVersion
*/
- public boolean isStripVersion()
- {
+ public boolean isStripVersion() {
return this.stripVersion;
}
/**
* @param theStripVersion the stripVersion to set
*/
- public void setStripVersion( boolean theStripVersion )
- {
+ public void setStripVersion(boolean theStripVersion) {
this.stripVersion = theStripVersion;
}
/**
* @param localRepoProperty {@link #localRepoProperty}
*/
- public void setLocalRepoProperty( String localRepoProperty )
- {
+ public void setLocalRepoProperty(String localRepoProperty) {
this.localRepoProperty = localRepoProperty;
}
}
diff --git a/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/CopyDependenciesMojo.java b/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/CopyDependenciesMojo.java
index fd2a60362..31d2477d7 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/CopyDependenciesMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/CopyDependenciesMojo.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.dependency.fromDependencies;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
@@ -18,12 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.dependency.fromDependencies;
import java.io.File;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
-
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.plugin.MojoExecutionException;
@@ -48,18 +46,20 @@
* @author Brian Fox
* @since 1.0
*/
-//CHECKSTYLE_OFF: LineLength
-@Mojo( name = "copy-dependencies", requiresDependencyResolution = ResolutionScope.TEST, defaultPhase = LifecyclePhase.PROCESS_SOURCES, threadSafe = true )
-//CHECKSTYLE_ON: LineLength
-public class CopyDependenciesMojo
- extends AbstractFromDependenciesMojo
-{
+// CHECKSTYLE_OFF: LineLength
+@Mojo(
+ name = "copy-dependencies",
+ requiresDependencyResolution = ResolutionScope.TEST,
+ defaultPhase = LifecyclePhase.PROCESS_SOURCES,
+ threadSafe = true)
+// CHECKSTYLE_ON: LineLength
+public class CopyDependenciesMojo extends AbstractFromDependenciesMojo {
/**
* Also copy the pom of each artifact.
*
* @since 2.0
*/
- @Parameter( property = "mdep.copyPom", defaultValue = "false" )
+ @Parameter(property = "mdep.copyPom", defaultValue = "false")
protected boolean copyPom = true;
/**
@@ -71,24 +71,24 @@ public class CopyDependenciesMojo
/**
*
*/
- @Component( role = ArtifactRepositoryLayout.class )
+ @Component(role = ArtifactRepositoryLayout.class)
private Map repositoryLayouts;
/**
* Either append the artifact's baseVersion or uniqueVersion to the filename. Will only be used if
* {@link #isStripVersion()} is {@code false}.
- *
+ *
* @since 2.6
*/
- @Parameter( property = "mdep.useBaseVersion", defaultValue = "true" )
+ @Parameter(property = "mdep.useBaseVersion", defaultValue = "true")
protected boolean useBaseVersion = true;
/**
* Add parent poms to the list of copied dependencies (both current project pom parents and dependencies parents).
- *
+ *
* @since 2.8
*/
- @Parameter( property = "mdep.addParentPoms", defaultValue = "false" )
+ @Parameter(property = "mdep.addParentPoms", defaultValue = "false")
protected boolean addParentPoms;
/**
@@ -111,89 +111,71 @@ public class CopyDependenciesMojo
* @see #copyArtifact(Artifact, boolean, boolean, boolean, boolean)
*/
@Override
- protected void doExecute()
- throws MojoExecutionException
- {
- DependencyStatusSets dss = getDependencySets( this.failOnMissingClassifierArtifact, addParentPoms );
+ protected void doExecute() throws MojoExecutionException {
+ DependencyStatusSets dss = getDependencySets(this.failOnMissingClassifierArtifact, addParentPoms);
Set artifacts = dss.getResolvedDependencies();
- if ( !useRepositoryLayout )
- {
- for ( Artifact artifact : artifacts )
- {
- copyArtifact( artifact, isStripVersion(), this.prependGroupId, this.useBaseVersion,
- this.stripClassifier );
+ if (!useRepositoryLayout) {
+ for (Artifact artifact : artifacts) {
+ copyArtifact(
+ artifact, isStripVersion(), this.prependGroupId, this.useBaseVersion, this.stripClassifier);
}
- }
- else
- {
- ProjectBuildingRequest buildingRequest =
- getRepositoryManager().setLocalRepositoryBasedir( session.getProjectBuildingRequest(),
- outputDirectory );
+ } else {
+ ProjectBuildingRequest buildingRequest = getRepositoryManager()
+ .setLocalRepositoryBasedir(session.getProjectBuildingRequest(), outputDirectory);
- artifacts.forEach( artifact -> installArtifact( artifact, buildingRequest ) );
+ artifacts.forEach(artifact -> installArtifact(artifact, buildingRequest));
}
Set skippedArtifacts = dss.getSkippedDependencies();
- for ( Artifact artifact : skippedArtifacts )
- {
- getLog().info( artifact.getId() + " already exists in destination." );
+ for (Artifact artifact : skippedArtifacts) {
+ getLog().info(artifact.getId() + " already exists in destination.");
}
- if ( isCopyPom() && !useRepositoryLayout )
- {
- copyPoms( getOutputDirectory(), artifacts, this.stripVersion );
- copyPoms( getOutputDirectory(), skippedArtifacts, this.stripVersion, this.stripClassifier ); // Artifacts
- // that already
- // exist may
- // not yet have
- // poms
+ if (isCopyPom() && !useRepositoryLayout) {
+ copyPoms(getOutputDirectory(), artifacts, this.stripVersion);
+ copyPoms(getOutputDirectory(), skippedArtifacts, this.stripVersion, this.stripClassifier); // Artifacts
+ // that already
+ // exist may
+ // not yet have
+ // poms
}
}
/**
* install the artifact and the corresponding pom if copyPoms=true
- *
+ *
* @param artifact
* @param buildingRequest
*/
- private void installArtifact( Artifact artifact, ProjectBuildingRequest buildingRequest )
- {
- try
- {
- installer.install( buildingRequest, Collections.singletonList( artifact ) );
- installBaseSnapshot( artifact, buildingRequest );
-
- if ( !"pom".equals( artifact.getType() ) && isCopyPom() )
- {
- Artifact pomArtifact = getResolvedPomArtifact( artifact );
- if ( pomArtifact != null && pomArtifact.getFile() != null && pomArtifact.getFile().exists() )
- {
- installer.install( buildingRequest, Collections.singletonList( pomArtifact ) );
- installBaseSnapshot( pomArtifact, buildingRequest );
+ private void installArtifact(Artifact artifact, ProjectBuildingRequest buildingRequest) {
+ try {
+ installer.install(buildingRequest, Collections.singletonList(artifact));
+ installBaseSnapshot(artifact, buildingRequest);
+
+ if (!"pom".equals(artifact.getType()) && isCopyPom()) {
+ Artifact pomArtifact = getResolvedPomArtifact(artifact);
+ if (pomArtifact != null
+ && pomArtifact.getFile() != null
+ && pomArtifact.getFile().exists()) {
+ installer.install(buildingRequest, Collections.singletonList(pomArtifact));
+ installBaseSnapshot(pomArtifact, buildingRequest);
}
}
- }
- catch ( ArtifactInstallerException e )
- {
- getLog().warn( "unable to install " + artifact, e );
+ } catch (ArtifactInstallerException e) {
+ getLog().warn("unable to install " + artifact, e);
}
}
- private void installBaseSnapshot( Artifact artifact, ProjectBuildingRequest buildingRequest )
- throws ArtifactInstallerException
- {
- if ( artifact.isSnapshot() && !artifact.getBaseVersion().equals( artifact.getVersion() ) )
- {
+ private void installBaseSnapshot(Artifact artifact, ProjectBuildingRequest buildingRequest)
+ throws ArtifactInstallerException {
+ if (artifact.isSnapshot() && !artifact.getBaseVersion().equals(artifact.getVersion())) {
String version = artifact.getVersion();
- try
- {
- artifact.setVersion( artifact.getBaseVersion() );
- installer.install( buildingRequest, Collections.singletonList( artifact ) );
- }
- finally
- {
- artifact.setVersion( version );
+ try {
+ artifact.setVersion(artifact.getBaseVersion());
+ installer.install(buildingRequest, Collections.singletonList(artifact));
+ } finally {
+ artifact.setVersion(version);
}
}
}
@@ -209,11 +191,10 @@ private void installBaseSnapshot( Artifact artifact, ProjectBuildingRequest buil
* @throws MojoExecutionException with a message if an error occurs.
* @see #copyArtifact(Artifact, boolean, boolean, boolean, boolean)
*/
- protected void copyArtifact( Artifact artifact, boolean removeVersion, boolean prependGroupId,
- boolean theUseBaseVersion )
- throws MojoExecutionException
- {
- copyArtifact( artifact, removeVersion, prependGroupId, theUseBaseVersion, false );
+ protected void copyArtifact(
+ Artifact artifact, boolean removeVersion, boolean prependGroupId, boolean theUseBaseVersion)
+ throws MojoExecutionException {
+ copyArtifact(artifact, removeVersion, prependGroupId, theUseBaseVersion, false);
}
/**
@@ -229,63 +210,69 @@ protected void copyArtifact( Artifact artifact, boolean removeVersion, boolean p
* @see #copyFile(File, File)
* @see DependencyUtil#getFormattedOutputDirectory(boolean, boolean, boolean, boolean, boolean, boolean, File, Artifact)
*/
- protected void copyArtifact( Artifact artifact, boolean removeVersion, boolean prependGroupId,
- boolean theUseBaseVersion, boolean removeClassifier )
- throws MojoExecutionException
- {
-
- String destFileName = DependencyUtil.getFormattedFileName( artifact, removeVersion, prependGroupId,
- theUseBaseVersion, removeClassifier );
-
- File destDir = DependencyUtil.getFormattedOutputDirectory( useSubDirectoryPerScope, useSubDirectoryPerType,
- useSubDirectoryPerArtifact, useRepositoryLayout,
- stripVersion, stripType, outputDirectory, artifact );
- File destFile = new File( destDir, destFileName );
-
- copyFile( artifact.getFile(), destFile );
+ protected void copyArtifact(
+ Artifact artifact,
+ boolean removeVersion,
+ boolean prependGroupId,
+ boolean theUseBaseVersion,
+ boolean removeClassifier)
+ throws MojoExecutionException {
+
+ String destFileName = DependencyUtil.getFormattedFileName(
+ artifact, removeVersion, prependGroupId, theUseBaseVersion, removeClassifier);
+
+ File destDir = DependencyUtil.getFormattedOutputDirectory(
+ useSubDirectoryPerScope,
+ useSubDirectoryPerType,
+ useSubDirectoryPerArtifact,
+ useRepositoryLayout,
+ stripVersion,
+ stripType,
+ outputDirectory,
+ artifact);
+ File destFile = new File(destDir, destFileName);
+
+ copyFile(artifact.getFile(), destFile);
}
/**
* Copy the pom files associated with the artifacts.
- *
+ *
* @param destDir The destination directory {@link File}.
* @param artifacts The artifacts {@link Artifact}.
* @param removeVersion remove version or not.
* @throws MojoExecutionException in case of errors.
*/
- public void copyPoms( File destDir, Set artifacts, boolean removeVersion )
- throws MojoExecutionException
+ public void copyPoms(File destDir, Set artifacts, boolean removeVersion) throws MojoExecutionException {
- {
- copyPoms( destDir, artifacts, removeVersion, false );
+ copyPoms(destDir, artifacts, removeVersion, false);
}
/**
* Copy the pom files associated with the artifacts.
- *
+ *
* @param destDir The destination directory {@link File}.
* @param artifacts The artifacts {@link Artifact}.
* @param removeVersion remove version or not.
* @param removeClassifier remove the classifier or not.
* @throws MojoExecutionException in case of errors.
*/
- public void copyPoms( File destDir, Set artifacts, boolean removeVersion, boolean removeClassifier )
- throws MojoExecutionException
+ public void copyPoms(File destDir, Set artifacts, boolean removeVersion, boolean removeClassifier)
+ throws MojoExecutionException {
- {
- for ( Artifact artifact : artifacts )
- {
- Artifact pomArtifact = getResolvedPomArtifact( artifact );
+ for (Artifact artifact : artifacts) {
+ Artifact pomArtifact = getResolvedPomArtifact(artifact);
// Copy the pom
- if ( pomArtifact != null && pomArtifact.getFile() != null && pomArtifact.getFile().exists() )
- {
- File pomDestFile =
- new File( destDir, DependencyUtil.getFormattedFileName( pomArtifact, removeVersion, prependGroupId,
- useBaseVersion, removeClassifier ) );
- if ( !pomDestFile.exists() )
- {
- copyFile( pomArtifact.getFile(), pomDestFile );
+ if (pomArtifact != null
+ && pomArtifact.getFile() != null
+ && pomArtifact.getFile().exists()) {
+ File pomDestFile = new File(
+ destDir,
+ DependencyUtil.getFormattedFileName(
+ pomArtifact, removeVersion, prependGroupId, useBaseVersion, removeClassifier));
+ if (!pomDestFile.exists()) {
+ copyFile(pomArtifact.getFile(), pomDestFile);
}
}
}
@@ -295,51 +282,54 @@ public void copyPoms( File destDir, Set artifacts, boolean removeVersi
* @param artifact {@link Artifact}
* @return {@link Artifact}
*/
- protected Artifact getResolvedPomArtifact( Artifact artifact )
- {
+ protected Artifact getResolvedPomArtifact(Artifact artifact) {
DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate();
- coordinate.setGroupId( artifact.getGroupId() );
- coordinate.setArtifactId( artifact.getArtifactId() );
- coordinate.setVersion( artifact.getVersion() );
- coordinate.setExtension( "pom" );
+ coordinate.setGroupId(artifact.getGroupId());
+ coordinate.setArtifactId(artifact.getArtifactId());
+ coordinate.setVersion(artifact.getVersion());
+ coordinate.setExtension("pom");
Artifact pomArtifact = null;
// Resolve the pom artifact using repos
- try
- {
+ try {
ProjectBuildingRequest buildingRequest = newResolveArtifactProjectBuildingRequest();
- pomArtifact = getArtifactResolver().resolveArtifact( buildingRequest, coordinate ).getArtifact();
- }
- catch ( ArtifactResolverException e )
- {
- getLog().info( e.getMessage() );
+ pomArtifact = getArtifactResolver()
+ .resolveArtifact(buildingRequest, coordinate)
+ .getArtifact();
+ } catch (ArtifactResolverException e) {
+ getLog().info(e.getMessage());
}
return pomArtifact;
}
@Override
- protected ArtifactsFilter getMarkedArtifactFilter()
- {
- return new DestFileFilter( this.overWriteReleases, this.overWriteSnapshots, this.overWriteIfNewer,
- this.useSubDirectoryPerArtifact, this.useSubDirectoryPerType,
- this.useSubDirectoryPerScope, this.useRepositoryLayout, this.stripVersion,
- this.prependGroupId, this.useBaseVersion, this.outputDirectory );
+ protected ArtifactsFilter getMarkedArtifactFilter() {
+ return new DestFileFilter(
+ this.overWriteReleases,
+ this.overWriteSnapshots,
+ this.overWriteIfNewer,
+ this.useSubDirectoryPerArtifact,
+ this.useSubDirectoryPerType,
+ this.useSubDirectoryPerScope,
+ this.useRepositoryLayout,
+ this.stripVersion,
+ this.prependGroupId,
+ this.useBaseVersion,
+ this.outputDirectory);
}
/**
* @return true, if the pom of each artifact must be copied
*/
- public boolean isCopyPom()
- {
+ public boolean isCopyPom() {
return this.copyPom;
}
/**
* @param copyPom - true if the pom of each artifact must be copied
*/
- public void setCopyPom( boolean copyPom )
- {
+ public void setCopyPom(boolean copyPom) {
this.copyPom = copyPom;
}
}
diff --git a/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/UnpackDependenciesMojo.java b/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/UnpackDependenciesMojo.java
index 12a574f9f..e7c812688 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/UnpackDependenciesMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/UnpackDependenciesMojo.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.dependency.fromDependencies;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
@@ -18,34 +16,36 @@
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.dependency.fromDependencies;
+import java.io.File;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugins.dependency.utils.DependencyStatusSets;
-import org.apache.maven.plugins.dependency.utils.DependencyUtil;
-import org.apache.maven.plugins.dependency.utils.filters.MarkerFileFilter;
-import org.apache.maven.plugins.dependency.utils.markers.DefaultFileMarkerHandler;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
+import org.apache.maven.plugins.dependency.utils.DependencyStatusSets;
+import org.apache.maven.plugins.dependency.utils.DependencyUtil;
+import org.apache.maven.plugins.dependency.utils.filters.MarkerFileFilter;
+import org.apache.maven.plugins.dependency.utils.markers.DefaultFileMarkerHandler;
import org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter;
import org.codehaus.plexus.components.io.filemappers.FileMapper;
-import java.io.File;
-
/**
* Goal that unpacks the project dependencies from the repository to a defined location.
*
* @author Brian Fox
* @since 1.0
*/
-//CHECKSTYLE_OFF: LineLength
-@Mojo( name = "unpack-dependencies", requiresDependencyResolution = ResolutionScope.TEST, defaultPhase = LifecyclePhase.PROCESS_SOURCES, threadSafe = true )
-//CHECKSTYLE_ON: LineLength
-public class UnpackDependenciesMojo
- extends AbstractFromDependenciesMojo
-{
+// CHECKSTYLE_OFF: LineLength
+@Mojo(
+ name = "unpack-dependencies",
+ requiresDependencyResolution = ResolutionScope.TEST,
+ defaultPhase = LifecyclePhase.PROCESS_SOURCES,
+ threadSafe = true)
+// CHECKSTYLE_ON: LineLength
+public class UnpackDependenciesMojo extends AbstractFromDependenciesMojo {
/**
* A comma separated list of file patterns to include when unpacking the artifact. i.e.
* **/*.xml,**/*.properties
NOTE: Excludes patterns override the includes. (component code =
@@ -53,7 +53,7 @@ public class UnpackDependenciesMojo
*
* @since 2.0
*/
- @Parameter( property = "mdep.unpack.includes" )
+ @Parameter(property = "mdep.unpack.includes")
private String includes;
/**
@@ -63,15 +63,15 @@ public class UnpackDependenciesMojo
*
* @since 2.0
*/
- @Parameter( property = "mdep.unpack.excludes" )
+ @Parameter(property = "mdep.unpack.excludes")
private String excludes;
/**
* Encoding of artifacts.
- *
+ *
* @since 3.0
*/
- @Parameter( property = "mdep.unpack.encoding" )
+ @Parameter(property = "mdep.unpack.encoding")
private String encoding;
/**
@@ -79,7 +79,7 @@ public class UnpackDependenciesMojo
*
* @since 3.1.2
*/
- @Parameter( property = "mdep.unpack.filemappers" )
+ @Parameter(property = "mdep.unpack.filemappers")
private FileMapper[] fileMappers;
/**
@@ -91,63 +91,63 @@ public class UnpackDependenciesMojo
* @see #unpack(Artifact, File, String, FileMapper[])
*/
@Override
- protected void doExecute()
- throws MojoExecutionException
- {
- DependencyStatusSets dss = getDependencySets( this.failOnMissingClassifierArtifact );
-
- for ( Artifact artifact : dss.getResolvedDependencies() )
- {
- File destDir = DependencyUtil.getFormattedOutputDirectory( useSubDirectoryPerScope, useSubDirectoryPerType,
- useSubDirectoryPerArtifact, useRepositoryLayout,
- stripVersion, stripType, outputDirectory, artifact );
- unpack( artifact, destDir, getIncludes(), getExcludes(), getEncoding(), getFileMappers() );
- DefaultFileMarkerHandler handler = new DefaultFileMarkerHandler( artifact, this.markersDirectory );
+ protected void doExecute() throws MojoExecutionException {
+ DependencyStatusSets dss = getDependencySets(this.failOnMissingClassifierArtifact);
+
+ for (Artifact artifact : dss.getResolvedDependencies()) {
+ File destDir = DependencyUtil.getFormattedOutputDirectory(
+ useSubDirectoryPerScope,
+ useSubDirectoryPerType,
+ useSubDirectoryPerArtifact,
+ useRepositoryLayout,
+ stripVersion,
+ stripType,
+ outputDirectory,
+ artifact);
+ unpack(artifact, destDir, getIncludes(), getExcludes(), getEncoding(), getFileMappers());
+ DefaultFileMarkerHandler handler = new DefaultFileMarkerHandler(artifact, this.markersDirectory);
handler.setMarker();
}
- for ( Artifact artifact : dss.getSkippedDependencies() )
- {
- getLog().info( artifact.getId() + " already exists in destination." );
+ for (Artifact artifact : dss.getSkippedDependencies()) {
+ getLog().info(artifact.getId() + " already exists in destination.");
}
}
@Override
- protected ArtifactsFilter getMarkedArtifactFilter()
- {
- return new MarkerFileFilter( this.overWriteReleases, this.overWriteSnapshots, this.overWriteIfNewer,
- new DefaultFileMarkerHandler( this.markersDirectory ) );
+ protected ArtifactsFilter getMarkedArtifactFilter() {
+ return new MarkerFileFilter(
+ this.overWriteReleases,
+ this.overWriteSnapshots,
+ this.overWriteIfNewer,
+ new DefaultFileMarkerHandler(this.markersDirectory));
}
/**
* @return Returns a comma separated list of excluded items
*/
- public String getExcludes()
- {
- return DependencyUtil.cleanToBeTokenizedString( this.excludes );
+ public String getExcludes() {
+ return DependencyUtil.cleanToBeTokenizedString(this.excludes);
}
/**
* @param excludes A comma separated list of items to exclude i.e. **\/*.xml, **\/*.properties
*/
- public void setExcludes( String excludes )
- {
+ public void setExcludes(String excludes) {
this.excludes = excludes;
}
/**
* @return Returns a comma separated list of included items
*/
- public String getIncludes()
- {
- return DependencyUtil.cleanToBeTokenizedString( this.includes );
+ public String getIncludes() {
+ return DependencyUtil.cleanToBeTokenizedString(this.includes);
}
/**
* @param includes A comma separated list of items to include i.e. **\/*.xml, **\/*.properties
*/
- public void setIncludes( String includes )
- {
+ public void setIncludes(String includes) {
this.includes = includes;
}
@@ -155,8 +155,7 @@ public void setIncludes( String includes )
* @param encoding The encoding to set.
* @since 3.0
*/
- public void setEncoding( String encoding )
- {
+ public void setEncoding(String encoding) {
this.encoding = encoding;
}
@@ -164,8 +163,7 @@ public void setEncoding( String encoding )
* @return Returns the encoding.
* @since 3.0
*/
- public String getEncoding()
- {
+ public String getEncoding() {
return this.encoding;
}
@@ -175,8 +173,7 @@ public String getEncoding()
*
* @since 3.1.2
*/
- public FileMapper[] getFileMappers()
- {
+ public FileMapper[] getFileMappers() {
return this.fileMappers;
}
@@ -186,8 +183,7 @@ public FileMapper[] getFileMappers()
*
* @since 3.1.2
*/
- public void setFileMappers( FileMapper[] fileMappers )
- {
+ public void setFileMappers(FileMapper[] fileMappers) {
this.fileMappers = fileMappers;
}
}
diff --git a/src/main/java/org/apache/maven/plugins/dependency/resolvers/AbstractResolveMojo.java b/src/main/java/org/apache/maven/plugins/dependency/resolvers/AbstractResolveMojo.java
index 3b65171d0..20f5a9b93 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/resolvers/AbstractResolveMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/resolvers/AbstractResolveMojo.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.dependency.resolvers;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
@@ -18,11 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.dependency.resolvers;
import java.io.File;
import java.util.LinkedHashSet;
import java.util.Set;
-
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.dependency.fromDependencies.AbstractDependencyFilterMojo;
@@ -41,16 +39,14 @@
/**
* @author Brian Fox
*/
-public abstract class AbstractResolveMojo
- extends AbstractDependencyFilterMojo
-{
+public abstract class AbstractResolveMojo extends AbstractDependencyFilterMojo {
/**
* If specified, this parameter causes the dependencies to be written to the path specified instead of
* the console.
*
* @since 2.0
*/
- @Parameter( property = "outputFile" )
+ @Parameter(property = "outputFile")
protected File outputFile;
/**
@@ -58,7 +54,7 @@ public abstract class AbstractResolveMojo
*
* @since 2.2
*/
- @Parameter( property = "appendOutput", defaultValue = "false" )
+ @Parameter(property = "appendOutput", defaultValue = "false")
protected boolean appendOutput;
/**
@@ -66,7 +62,7 @@ public abstract class AbstractResolveMojo
*
* @since 2.7
*/
- @Parameter( property = "excludeReactor", defaultValue = "true" )
+ @Parameter(property = "excludeReactor", defaultValue = "true")
protected boolean excludeReactor;
/**
@@ -84,31 +80,33 @@ public abstract class AbstractResolveMojo
/**
* @return {@link FilterArtifacts}
*/
- protected FilterArtifacts getArtifactsFilter()
- {
+ protected FilterArtifacts getArtifactsFilter() {
final FilterArtifacts filter = new FilterArtifacts();
- if ( excludeReactor )
- {
-
- filter.addFilter( new ExcludeReactorProjectsArtifactFilter( reactorProjects, getLog() ) );
+ if (excludeReactor) {
+ filter.addFilter(new ExcludeReactorProjectsArtifactFilter(reactorProjects, getLog()));
}
- filter.addFilter( new ScopeFilter( DependencyUtil.cleanToBeTokenizedString( this.includeScope ),
- DependencyUtil.cleanToBeTokenizedString( this.excludeScope ) ) );
+ filter.addFilter(new ScopeFilter(
+ DependencyUtil.cleanToBeTokenizedString(this.includeScope),
+ DependencyUtil.cleanToBeTokenizedString(this.excludeScope)));
- filter.addFilter( new TypeFilter( DependencyUtil.cleanToBeTokenizedString( this.includeTypes ),
- DependencyUtil.cleanToBeTokenizedString( this.excludeTypes ) ) );
+ filter.addFilter(new TypeFilter(
+ DependencyUtil.cleanToBeTokenizedString(this.includeTypes),
+ DependencyUtil.cleanToBeTokenizedString(this.excludeTypes)));
- filter.addFilter( new ClassifierFilter( DependencyUtil.cleanToBeTokenizedString( this.includeClassifiers ),
- DependencyUtil.cleanToBeTokenizedString( this.excludeClassifiers ) ) );
+ filter.addFilter(new ClassifierFilter(
+ DependencyUtil.cleanToBeTokenizedString(this.includeClassifiers),
+ DependencyUtil.cleanToBeTokenizedString(this.excludeClassifiers)));
- filter.addFilter( new GroupIdFilter( DependencyUtil.cleanToBeTokenizedString( this.includeGroupIds ),
- DependencyUtil.cleanToBeTokenizedString( this.excludeGroupIds ) ) );
+ filter.addFilter(new GroupIdFilter(
+ DependencyUtil.cleanToBeTokenizedString(this.includeGroupIds),
+ DependencyUtil.cleanToBeTokenizedString(this.excludeGroupIds)));
- filter.addFilter( new ArtifactIdFilter( DependencyUtil.cleanToBeTokenizedString( this.includeArtifactIds ),
- DependencyUtil.cleanToBeTokenizedString( this.excludeArtifactIds ) ) );
+ filter.addFilter(new ArtifactIdFilter(
+ DependencyUtil.cleanToBeTokenizedString(this.includeArtifactIds),
+ DependencyUtil.cleanToBeTokenizedString(this.excludeArtifactIds)));
return filter;
}
@@ -120,22 +118,19 @@ protected FilterArtifacts getArtifactsFilter()
* @return resolved set of dependencies
* @throws DependencyResolverException in case of error while resolving artifacts.
*/
- protected Set resolveArtifactDependencies( final DependableCoordinate artifact )
- throws DependencyResolverException
- {
+ protected Set resolveArtifactDependencies(final DependableCoordinate artifact)
+ throws DependencyResolverException {
ProjectBuildingRequest buildingRequest = newResolveArtifactProjectBuildingRequest();
Iterable artifactResults =
- getDependencyResolver().resolveDependencies( buildingRequest, artifact, null );
+ getDependencyResolver().resolveDependencies(buildingRequest, artifact, null);
Set artifacts = new LinkedHashSet<>();
- for ( final ArtifactResult artifactResult : artifactResults )
- {
- artifacts.add( artifactResult.getArtifact() );
+ for (final ArtifactResult artifactResult : artifactResults) {
+ artifacts.add(artifactResult.getArtifact());
}
return artifacts;
-
}
}
diff --git a/src/main/java/org/apache/maven/plugins/dependency/resolvers/CollectDependenciesMojo.java b/src/main/java/org/apache/maven/plugins/dependency/resolvers/CollectDependenciesMojo.java
index 98152a798..bc23a637d 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/resolvers/CollectDependenciesMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/resolvers/CollectDependenciesMojo.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.dependency.resolvers;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
@@ -18,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.dependency.resolvers;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
@@ -41,10 +40,11 @@
* @author Brian Fox
* @since 3.0
*/
-//CHECKSTYLE_OFF: LineLength
-@Mojo( name = "collect", requiresDependencyCollection = ResolutionScope.TEST, defaultPhase = LifecyclePhase.GENERATE_SOURCES, threadSafe = true )
-//CHECKSTYLE_ON: LineLength
-public class CollectDependenciesMojo
- extends ResolveDependenciesMojo
-{
-}
+// CHECKSTYLE_OFF: LineLength
+@Mojo(
+ name = "collect",
+ requiresDependencyCollection = ResolutionScope.TEST,
+ defaultPhase = LifecyclePhase.GENERATE_SOURCES,
+ threadSafe = true)
+// CHECKSTYLE_ON: LineLength
+public class CollectDependenciesMojo extends ResolveDependenciesMojo {}
diff --git a/src/main/java/org/apache/maven/plugins/dependency/resolvers/ExcludeReactorProjectsArtifactFilter.java b/src/main/java/org/apache/maven/plugins/dependency/resolvers/ExcludeReactorProjectsArtifactFilter.java
index 4c57ca50a..42e42fec3 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/resolvers/ExcludeReactorProjectsArtifactFilter.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/resolvers/ExcludeReactorProjectsArtifactFilter.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.dependency.resolvers;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
@@ -18,7 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.dependency.resolvers;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
@@ -27,49 +30,35 @@
import org.apache.maven.shared.artifact.filter.collection.AbstractArtifactsFilter;
import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.HashSet;
-import java.util.Set;
-
/**
* {@link ArtifactFilter} implementation that excludes artifacts found in the Reactor.
*
* @author Maarten Mulders
*/
-public class ExcludeReactorProjectsArtifactFilter extends AbstractArtifactsFilter
-{
+public class ExcludeReactorProjectsArtifactFilter extends AbstractArtifactsFilter {
private final Log log;
private final Set reactorArtifactKeys;
- public ExcludeReactorProjectsArtifactFilter( final List reactorProjects, final Log log )
- {
+ public ExcludeReactorProjectsArtifactFilter(final List reactorProjects, final Log log) {
this.log = log;
- this.reactorArtifactKeys = new HashSet<>( reactorProjects.size() );
- for ( final MavenProject project : reactorProjects )
- {
- this.reactorArtifactKeys.add( ArtifactUtils.key( project.getArtifact() ) );
+ this.reactorArtifactKeys = new HashSet<>(reactorProjects.size());
+ for (final MavenProject project : reactorProjects) {
+ this.reactorArtifactKeys.add(ArtifactUtils.key(project.getArtifact()));
}
}
@Override
- public Set filter( final Set artifacts ) throws ArtifactFilterException
- {
- final Set results = new LinkedHashSet<>( artifacts.size() );
+ public Set filter(final Set artifacts) throws ArtifactFilterException {
+ final Set results = new LinkedHashSet<>(artifacts.size());
- for ( final Artifact artifact : artifacts )
- {
- if ( !isArtifactInReactor( artifact ) )
- {
- results.add( artifact );
- }
- else
- {
- if ( log.isDebugEnabled() )
- {
- log.debug( "Skipped artifact "
- + ArtifactUtils.key( artifact )
- + " because it is present in the reactor" );
+ for (final Artifact artifact : artifacts) {
+ if (!isArtifactInReactor(artifact)) {
+ results.add(artifact);
+ } else {
+ if (log.isDebugEnabled()) {
+ log.debug("Skipped artifact "
+ + ArtifactUtils.key(artifact)
+ + " because it is present in the reactor");
}
}
}
@@ -77,15 +66,12 @@ public Set filter( final Set artifacts ) throws ArtifactFilt
return results;
}
- private boolean isArtifactInReactor( final Artifact artifact )
- {
- for ( final String reactorArtifactKey : this.reactorArtifactKeys )
- {
- final String artifactKey = ArtifactUtils.key( artifact );
+ private boolean isArtifactInReactor(final Artifact artifact) {
+ for (final String reactorArtifactKey : this.reactorArtifactKeys) {
+ final String artifactKey = ArtifactUtils.key(artifact);
// This check only includes GAV. Should we take a look at the types, too?
- if ( reactorArtifactKey.equals( artifactKey ) )
- {
+ if (reactorArtifactKey.equals(artifactKey)) {
return true;
}
}
diff --git a/src/main/java/org/apache/maven/plugins/dependency/resolvers/ExcludeReactorProjectsDependencyFilter.java b/src/main/java/org/apache/maven/plugins/dependency/resolvers/ExcludeReactorProjectsDependencyFilter.java
index b429a3eac..98a60bfda 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/resolvers/ExcludeReactorProjectsDependencyFilter.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/resolvers/ExcludeReactorProjectsDependencyFilter.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.dependency.resolvers;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
@@ -18,7 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.dependency.resolvers;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.model.Dependency;
import org.apache.maven.plugin.logging.Log;
@@ -27,44 +29,33 @@
import org.apache.maven.shared.artifact.filter.resolve.Node;
import org.apache.maven.shared.artifact.filter.resolve.TransformableFilter;
-import java.util.List;
-import java.util.Set;
-import java.util.stream.Collectors;
-
/**
* {@link TransformableFilter} implementation that excludes artifacts found in the Reactor.
*
* @author Maarten Mulders
*/
-public class ExcludeReactorProjectsDependencyFilter extends AbstractFilter
-{
+public class ExcludeReactorProjectsDependencyFilter extends AbstractFilter {
private final Log log;
private final Set reactorArtifactKeys;
- public ExcludeReactorProjectsDependencyFilter( final List reactorProjects, final Log log )
- {
+ public ExcludeReactorProjectsDependencyFilter(final List reactorProjects, final Log log) {
this.log = log;
this.reactorArtifactKeys = reactorProjects.stream()
- .map( project -> ArtifactUtils.key( project.getArtifact() ) )
- .collect( Collectors.toSet() );
+ .map(project -> ArtifactUtils.key(project.getArtifact()))
+ .collect(Collectors.toSet());
}
@Override
- public boolean accept( final Node node, final List parents )
- {
+ public boolean accept(final Node node, final List parents) {
final Dependency dependency = node.getDependency();
- if ( dependency != null )
- {
- final String dependencyArtifactKey = ArtifactUtils.key(
- dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion() );
+ if (dependency != null) {
+ final String dependencyArtifactKey =
+ ArtifactUtils.key(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion());
- final boolean result = isDependencyArtifactInReactor( dependencyArtifactKey );
+ final boolean result = isDependencyArtifactInReactor(dependencyArtifactKey);
- if ( log.isDebugEnabled() && result )
- {
- log.debug( "Skipped dependency "
- + dependencyArtifactKey
- + " because it is present in the reactor" );
+ if (log.isDebugEnabled() && result) {
+ log.debug("Skipped dependency " + dependencyArtifactKey + " because it is present in the reactor");
}
return !result;
@@ -72,13 +63,10 @@ public boolean accept( final Node node, final List parents )
return true;
}
- private boolean isDependencyArtifactInReactor( final String dependencyArtifactKey )
- {
- for ( final String reactorArtifactKey : this.reactorArtifactKeys )
- {
+ private boolean isDependencyArtifactInReactor(final String dependencyArtifactKey) {
+ for (final String reactorArtifactKey : this.reactorArtifactKeys) {
// This check only includes GAV. Should we take a look at the types, too?
- if ( reactorArtifactKey.equals( dependencyArtifactKey ) )
- {
+ if (reactorArtifactKey.equals(dependencyArtifactKey)) {
return true;
}
}
diff --git a/src/main/java/org/apache/maven/plugins/dependency/resolvers/GoOfflineMojo.java b/src/main/java/org/apache/maven/plugins/dependency/resolvers/GoOfflineMojo.java
index a91bd8978..a0f8e09ab 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/resolvers/GoOfflineMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/resolvers/GoOfflineMojo.java
@@ -1,6 +1,4 @@
-package org.apache.maven.plugins.dependency.resolvers;
-
-/*
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -9,22 +7,28 @@
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
- * under the License.
+ * under the License.
*/
+package org.apache.maven.plugins.dependency.resolvers;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.Set;
+import java.util.stream.Collectors;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.Dependency;
import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugins.dependency.utils.DependencyUtil;
import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.dependency.utils.DependencyUtil;
import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter;
import org.apache.maven.shared.artifact.filter.resolve.TransformableFilter;
@@ -33,12 +37,6 @@
import org.apache.maven.shared.transfer.dependencies.DependableCoordinate;
import org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolverException;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.LinkedHashSet;
-import java.util.Set;
-import java.util.stream.Collectors;
-
/**
* Goal that resolves all project dependencies, including plugins and reports and their dependencies.
*
@@ -46,10 +44,8 @@
* @author Maarten Mulders
* @since 2.0
*/
-@Mojo( name = "go-offline", threadSafe = true )
-public class GoOfflineMojo
- extends AbstractResolveMojo
-{
+@Mojo(name = "go-offline", threadSafe = true)
+public class GoOfflineMojo extends AbstractResolveMojo {
/**
* Main entry into mojo. Gets the list of dependencies, resolves all that are not in the Reactor, and iterates
* through displaying the resolved versions.
@@ -57,37 +53,26 @@ public class GoOfflineMojo
* @throws MojoExecutionException with a message if an error occurs.
*/
@Override
- protected void doExecute()
- throws MojoExecutionException
- {
+ protected void doExecute() throws MojoExecutionException {
- try
- {
+ try {
final Set plugins = resolvePluginArtifacts();
final Set dependencies = resolveDependencyArtifacts();
- if ( !isSilent() )
- {
- for ( Artifact artifact : plugins )
- {
- this.getLog().info( "Resolved plugin: "
- + DependencyUtil.getFormattedFileName( artifact, false ) );
+ if (!isSilent()) {
+ for (Artifact artifact : plugins) {
+ this.getLog().info("Resolved plugin: " + DependencyUtil.getFormattedFileName(artifact, false));
}
- for ( Artifact artifact : dependencies )
- {
- this.getLog().info( "Resolved dependency: "
- + DependencyUtil.getFormattedFileName( artifact, false ) );
+ for (Artifact artifact : dependencies) {
+ this.getLog().info("Resolved dependency: " + DependencyUtil.getFormattedFileName(artifact, false));
}
}
+ } catch (DependencyResolverException e) {
+ throw new MojoExecutionException(e.getMessage(), e);
}
- catch ( DependencyResolverException e )
- {
- throw new MojoExecutionException( e.getMessage(), e );
- }
-
}
/**
@@ -96,57 +81,48 @@ protected void doExecute()
* @return set of resolved dependency artifacts.
* @throws DependencyResolverException in case of an error while resolving the artifacts.
*/
- protected Set resolveDependencyArtifacts()
- throws DependencyResolverException
- {
+ protected Set resolveDependencyArtifacts() throws DependencyResolverException {
Collection dependencies = getProject().getDependencies();
Set dependableCoordinates = dependencies.stream()
- .map( this::createDependendableCoordinateFromDependency )
- .collect( Collectors.toSet() );
+ .map(this::createDependendableCoordinateFromDependency)
+ .collect(Collectors.toSet());
ProjectBuildingRequest buildingRequest = newResolveArtifactProjectBuildingRequest();
- return resolveDependableCoordinate( buildingRequest, dependableCoordinates, "dependencies" );
+ return resolveDependableCoordinate(buildingRequest, dependableCoordinates, "dependencies");
}
- private Set resolveDependableCoordinate( final ProjectBuildingRequest buildingRequest,
- final Collection dependableCoordinates,
- final String type )
- throws DependencyResolverException
- {
+ private Set resolveDependableCoordinate(
+ final ProjectBuildingRequest buildingRequest,
+ final Collection dependableCoordinates,
+ final String type)
+ throws DependencyResolverException {
final TransformableFilter filter = getTransformableFilter();
- this.getLog().debug( "Resolving '" + type + "' with following repositories:" );
- for ( ArtifactRepository repo : buildingRequest.getRemoteRepositories() )
- {
- getLog().debug( repo.getId() + " (" + repo.getUrl() + ")" );
+ this.getLog().debug("Resolving '" + type + "' with following repositories:");
+ for (ArtifactRepository repo : buildingRequest.getRemoteRepositories()) {
+ getLog().debug(repo.getId() + " (" + repo.getUrl() + ")");
}
final Set results = new HashSet<>();
- for ( DependableCoordinate dependableCoordinate : dependableCoordinates )
- {
- final Iterable artifactResults = getDependencyResolver().resolveDependencies(
- buildingRequest, dependableCoordinate, filter );
+ for (DependableCoordinate dependableCoordinate : dependableCoordinates) {
+ final Iterable artifactResults =
+ getDependencyResolver().resolveDependencies(buildingRequest, dependableCoordinate, filter);
- for ( final ArtifactResult artifactResult : artifactResults )
- {
- results.add( artifactResult.getArtifact() );
+ for (final ArtifactResult artifactResult : artifactResults) {
+ results.add(artifactResult.getArtifact());
}
}
return results;
}
- private TransformableFilter getTransformableFilter()
- {
- if ( this.excludeReactor )
- {
- return new ExcludeReactorProjectsDependencyFilter( this.reactorProjects, getLog() );
- }
- else
- {
+ private TransformableFilter getTransformableFilter() {
+ if (this.excludeReactor) {
+ return new ExcludeReactorProjectsDependencyFilter(this.reactorProjects, getLog());
+ } else {
return null;
}
}
@@ -157,54 +133,48 @@ private TransformableFilter getTransformableFilter()
* @return set of resolved plugin artifacts.
* @throws DependencyResolverException in case of an error while resolving the artifacts.
*/
- protected Set resolvePluginArtifacts()
- throws DependencyResolverException
- {
+ protected Set resolvePluginArtifacts() throws DependencyResolverException {
Set plugins = getProject().getPluginArtifacts();
Set reports = getProject().getReportArtifacts();
Set artifacts = new LinkedHashSet<>();
- artifacts.addAll( reports );
- artifacts.addAll( plugins );
+ artifacts.addAll(reports);
+ artifacts.addAll(plugins);
Set dependableCoordinates = artifacts.stream()
- .map( this::createDependendableCoordinateFromArtifact )
- .collect( Collectors.toSet() );
-
+ .map(this::createDependendableCoordinateFromArtifact)
+ .collect(Collectors.toSet());
ProjectBuildingRequest buildingRequest = newResolvePluginProjectBuildingRequest();
- return resolveDependableCoordinate( buildingRequest, dependableCoordinates, "plugins" );
+ return resolveDependableCoordinate(buildingRequest, dependableCoordinates, "plugins");
}
- private DependableCoordinate createDependendableCoordinateFromArtifact( final Artifact artifact )
- {
+ private DependableCoordinate createDependendableCoordinateFromArtifact(final Artifact artifact) {
final DefaultDependableCoordinate result = new DefaultDependableCoordinate();
- result.setGroupId( artifact.getGroupId() );
- result.setArtifactId( artifact.getArtifactId() );
- result.setVersion( artifact.getVersion() );
- result.setType( artifact.getType() );
- result.setClassifier( artifact.getClassifier() );
+ result.setGroupId(artifact.getGroupId());
+ result.setArtifactId(artifact.getArtifactId());
+ result.setVersion(artifact.getVersion());
+ result.setType(artifact.getType());
+ result.setClassifier(artifact.getClassifier());
return result;
}
- private DependableCoordinate createDependendableCoordinateFromDependency( final Dependency dependency )
- {
+ private DependableCoordinate createDependendableCoordinateFromDependency(final Dependency dependency) {
final DefaultDependableCoordinate result = new DefaultDependableCoordinate();
- result.setGroupId( dependency.getGroupId() );
- result.setArtifactId( dependency.getArtifactId() );
- result.setVersion( dependency.getVersion() );
- result.setType( dependency.getType() );
- result.setClassifier( dependency.getClassifier() );
+ result.setGroupId(dependency.getGroupId());
+ result.setArtifactId(dependency.getArtifactId());
+ result.setVersion(dependency.getVersion());
+ result.setType(dependency.getType());
+ result.setClassifier(dependency.getClassifier());
return result;
}
@Override
- protected ArtifactsFilter getMarkedArtifactFilter()
- {
+ protected ArtifactsFilter getMarkedArtifactFilter() {
return null;
}
}
diff --git a/src/main/java/org/apache/maven/plugins/dependency/resolvers/ListMojo.java b/src/main/java/org/apache/maven/plugins/dependency/resolvers/ListMojo.java
index c4bc2abda..54cb52c46 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/resolvers/ListMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/resolvers/ListMojo.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.dependency.resolvers;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,15 +7,16 @@
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
- * under the License.
+ * under the License.
*/
+package org.apache.maven.plugins.dependency.resolvers;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.ResolutionScope;
@@ -28,9 +27,7 @@
* @author Mark Hobson
* @since 2.0-alpha-5
*/
-@Mojo( name = "list", requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true )
-public class ListMojo
- extends ResolveDependenciesMojo
-{
+@Mojo(name = "list", requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true)
+public class ListMojo extends ResolveDependenciesMojo {
// alias for dependency:resolve
}
diff --git a/src/main/java/org/apache/maven/plugins/dependency/resolvers/ListRepositoriesMojo.java b/src/main/java/org/apache/maven/plugins/dependency/resolvers/ListRepositoriesMojo.java
index deed8d34d..59a785ce3 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/resolvers/ListRepositoriesMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/resolvers/ListRepositoriesMojo.java
@@ -1,76 +1,66 @@
-package org.apache.maven.plugins.dependency.resolvers;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugins.annotations.Component;
-import org.apache.maven.plugins.annotations.Mojo;
-import org.apache.maven.plugins.annotations.ResolutionScope;
-import org.apache.maven.plugins.dependency.AbstractDependencyMojo;
-import org.apache.maven.shared.transfer.dependencies.collect.CollectorResult;
-import org.apache.maven.shared.transfer.dependencies.collect.DependencyCollector;
-import org.apache.maven.shared.transfer.dependencies.collect.DependencyCollectorException;
-
-/**
- * Goal that resolves all project dependencies and then lists the repositories used by the build and by the transitive
- * dependencies
- *
- * @author Brian Fox
- * @since 2.2
- */
-@Mojo( name = "list-repositories", requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true )
-public class ListRepositoriesMojo
- extends AbstractDependencyMojo
-{
- /**
- * Dependency collector, needed to resolve dependencies.
- */
- @Component( role = DependencyCollector.class )
- private DependencyCollector dependencyCollector;
-
- /**
- * Displays a list of the repositories used by this build.
- *
- * @throws MojoExecutionException with a message if an error occurs.
- */
- @Override
- protected void doExecute()
- throws MojoExecutionException
- {
- try
- {
- CollectorResult collectResult =
- dependencyCollector.collectDependencies( session.getProjectBuildingRequest(), getProject().getModel() );
-
- this.getLog().info( "Repositories used by this build:" );
-
- for ( ArtifactRepository repo : collectResult.getRemoteRepositories() )
- {
- this.getLog().info( repo.toString() );
- }
- }
- catch ( DependencyCollectorException e )
- {
- throw new MojoExecutionException( "Unable to resolve artifacts", e );
- }
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugins.dependency.resolvers;
+
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugins.annotations.Component;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.ResolutionScope;
+import org.apache.maven.plugins.dependency.AbstractDependencyMojo;
+import org.apache.maven.shared.transfer.dependencies.collect.CollectorResult;
+import org.apache.maven.shared.transfer.dependencies.collect.DependencyCollector;
+import org.apache.maven.shared.transfer.dependencies.collect.DependencyCollectorException;
+
+/**
+ * Goal that resolves all project dependencies and then lists the repositories used by the build and by the transitive
+ * dependencies
+ *
+ * @author Brian Fox
+ * @since 2.2
+ */
+@Mojo(name = "list-repositories", requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true)
+public class ListRepositoriesMojo extends AbstractDependencyMojo {
+ /**
+ * Dependency collector, needed to resolve dependencies.
+ */
+ @Component(role = DependencyCollector.class)
+ private DependencyCollector dependencyCollector;
+
+ /**
+ * Displays a list of the repositories used by this build.
+ *
+ * @throws MojoExecutionException with a message if an error occurs.
+ */
+ @Override
+ protected void doExecute() throws MojoExecutionException {
+ try {
+ CollectorResult collectResult = dependencyCollector.collectDependencies(
+ session.getProjectBuildingRequest(), getProject().getModel());
+
+ this.getLog().info("Repositories used by this build:");
+
+ for (ArtifactRepository repo : collectResult.getRemoteRepositories()) {
+ this.getLog().info(repo.toString());
+ }
+ } catch (DependencyCollectorException e) {
+ throw new MojoExecutionException("Unable to resolve artifacts", e);
+ }
+ }
+}
diff --git a/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolveDependenciesMojo.java b/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolveDependenciesMojo.java
index c44535276..be09c9afb 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolveDependenciesMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolveDependenciesMojo.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.dependency.resolvers;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
@@ -18,21 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-
-import org.apache.maven.artifact.Artifact;
-
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugins.dependency.utils.DependencyStatusSets;
-import org.apache.maven.plugins.dependency.utils.DependencyUtil;
-import org.apache.maven.plugins.dependency.utils.filters.ResolveFileFilter;
-import org.apache.maven.plugins.dependency.utils.markers.SourcesFileMarkerHandler;
-import org.apache.maven.plugins.annotations.LifecyclePhase;
-import org.apache.maven.plugins.annotations.Mojo;
-import org.apache.maven.plugins.annotations.Parameter;
-import org.apache.maven.plugins.annotations.ResolutionScope;
-import org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter;
-import org.apache.maven.shared.utils.logging.MessageBuilder;
-import org.apache.maven.shared.utils.logging.MessageUtils;
+package org.apache.maven.plugins.dependency.resolvers;
import java.io.File;
import java.io.IOException;
@@ -46,6 +30,19 @@
import java.util.Set;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.plugins.annotations.ResolutionScope;
+import org.apache.maven.plugins.dependency.utils.DependencyStatusSets;
+import org.apache.maven.plugins.dependency.utils.DependencyUtil;
+import org.apache.maven.plugins.dependency.utils.filters.ResolveFileFilter;
+import org.apache.maven.plugins.dependency.utils.markers.SourcesFileMarkerHandler;
+import org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter;
+import org.apache.maven.shared.utils.logging.MessageBuilder;
+import org.apache.maven.shared.utils.logging.MessageUtils;
/**
* Goal that resolves the project dependencies from the repository. When using this goal while running on Java 9 the
@@ -54,14 +51,16 @@
* @author Brian Fox
* @since 2.0
*/
-//CHECKSTYLE_OFF: LineLength
-@Mojo( name = "resolve", requiresDependencyResolution = ResolutionScope.TEST, defaultPhase = LifecyclePhase.GENERATE_SOURCES, threadSafe = true )
-//CHECKSTYLE_ON: LineLength
-public class ResolveDependenciesMojo
- extends AbstractResolveMojo
-{
-
- @Parameter( property = "outputEncoding", defaultValue = "${project.reporting.outputEncoding}" )
+// CHECKSTYLE_OFF: LineLength
+@Mojo(
+ name = "resolve",
+ requiresDependencyResolution = ResolutionScope.TEST,
+ defaultPhase = LifecyclePhase.GENERATE_SOURCES,
+ threadSafe = true)
+// CHECKSTYLE_ON: LineLength
+public class ResolveDependenciesMojo extends AbstractResolveMojo {
+
+ @Parameter(property = "outputEncoding", defaultValue = "${project.reporting.outputEncoding}")
private String outputEncoding;
/**
@@ -69,7 +68,7 @@ public class ResolveDependenciesMojo
*
* @since 2.0-alpha-2
*/
- @Parameter( property = "mdep.outputScope", defaultValue = "true" )
+ @Parameter(property = "mdep.outputScope", defaultValue = "true")
protected boolean outputScope;
/**
@@ -79,18 +78,18 @@ public class ResolveDependenciesMojo
/**
* Sort the output list of resolved artifacts alphabetically. The default ordering matches the classpath order.
- *
+ *
* @since 2.8
*/
- @Parameter( property = "sort", defaultValue = "false" )
+ @Parameter(property = "sort", defaultValue = "false")
boolean sort;
/**
* Include parent poms in the dependency resolution list.
- *
+ *
* @since 2.8
*/
- @Parameter( property = "includeParents", defaultValue = "false" )
+ @Parameter(property = "includeParents", defaultValue = "false")
boolean includeParents;
/**
@@ -99,43 +98,33 @@ public class ResolveDependenciesMojo
* @throws MojoExecutionException with a message if an error occurs
*/
@Override
- protected void doExecute()
- throws MojoExecutionException
- {
+ protected void doExecute() throws MojoExecutionException {
// get sets of dependencies
- results = this.getDependencySets( false, includeParents );
-
- String output = getOutput( outputAbsoluteArtifactFilename, outputScope, sort );
- try
- {
- if ( outputFile == null )
- {
- DependencyUtil.log( output, getLog() );
+ results = this.getDependencySets(false, includeParents);
+
+ String output = getOutput(outputAbsoluteArtifactFilename, outputScope, sort);
+ try {
+ if (outputFile == null) {
+ DependencyUtil.log(output, getLog());
+ } else {
+ String encoding = Objects.toString(outputEncoding, "UTF-8");
+ DependencyUtil.write(output, outputFile, appendOutput, encoding);
}
- else
- {
- String encoding = Objects.toString( outputEncoding, "UTF-8" );
- DependencyUtil.write( output, outputFile, appendOutput, encoding );
- }
- }
- catch ( IOException e )
- {
- throw new MojoExecutionException( e.getMessage(), e );
+ } catch (IOException e) {
+ throw new MojoExecutionException(e.getMessage(), e);
}
}
/**
* @return returns the results
*/
- public DependencyStatusSets getResults()
- {
+ public DependencyStatusSets getResults() {
return this.results;
}
@Override
- protected ArtifactsFilter getMarkedArtifactFilter()
- {
- return new ResolveFileFilter( new SourcesFileMarkerHandler( this.markersDirectory ) );
+ protected ArtifactsFilter getMarkedArtifactFilter() {
+ return new ResolveFileFilter(new SourcesFileMarkerHandler(this.markersDirectory));
}
/**
@@ -144,201 +133,162 @@ protected ArtifactsFilter getMarkedArtifactFilter()
* @param theSort sort yes/no
* @return the output
*/
- public String getOutput( boolean outputAbsoluteArtifactFilename, boolean theOutputScope, boolean theSort )
- {
+ public String getOutput(boolean outputAbsoluteArtifactFilename, boolean theOutputScope, boolean theSort) {
StringBuilder sb = new StringBuilder();
- sb.append( System.lineSeparator() );
- sb.append( "The following files have been resolved:" );
- sb.append( System.lineSeparator() );
- if ( results.getResolvedDependencies() == null || results.getResolvedDependencies().isEmpty() )
- {
- sb.append( " none" );
- sb.append( System.lineSeparator() );
- }
- else
- {
- sb.append( buildArtifactListOutput( results.getResolvedDependencies(), outputAbsoluteArtifactFilename,
- theOutputScope, theSort ) );
+ sb.append(System.lineSeparator());
+ sb.append("The following files have been resolved:");
+ sb.append(System.lineSeparator());
+ if (results.getResolvedDependencies() == null
+ || results.getResolvedDependencies().isEmpty()) {
+ sb.append(" none");
+ sb.append(System.lineSeparator());
+ } else {
+ sb.append(buildArtifactListOutput(
+ results.getResolvedDependencies(), outputAbsoluteArtifactFilename, theOutputScope, theSort));
}
- if ( results.getSkippedDependencies() != null && !results.getSkippedDependencies().isEmpty() )
- {
- sb.append( System.lineSeparator() );
- sb.append( "The following files were skipped:" );
- sb.append( System.lineSeparator() );
- Set skippedDependencies = new LinkedHashSet<>( results.getSkippedDependencies() );
- sb.append( buildArtifactListOutput( skippedDependencies, outputAbsoluteArtifactFilename, theOutputScope,
- theSort ) );
+ if (results.getSkippedDependencies() != null
+ && !results.getSkippedDependencies().isEmpty()) {
+ sb.append(System.lineSeparator());
+ sb.append("The following files were skipped:");
+ sb.append(System.lineSeparator());
+ Set skippedDependencies = new LinkedHashSet<>(results.getSkippedDependencies());
+ sb.append(buildArtifactListOutput(
+ skippedDependencies, outputAbsoluteArtifactFilename, theOutputScope, theSort));
}
- if ( results.getUnResolvedDependencies() != null && !results.getUnResolvedDependencies().isEmpty() )
- {
- sb.append( System.lineSeparator() );
- sb.append( "The following files have NOT been resolved:" );
- sb.append( System.lineSeparator() );
- Set unResolvedDependencies = new LinkedHashSet<>( results.getUnResolvedDependencies() );
- sb.append( buildArtifactListOutput( unResolvedDependencies, outputAbsoluteArtifactFilename, theOutputScope,
- theSort ) );
+ if (results.getUnResolvedDependencies() != null
+ && !results.getUnResolvedDependencies().isEmpty()) {
+ sb.append(System.lineSeparator());
+ sb.append("The following files have NOT been resolved:");
+ sb.append(System.lineSeparator());
+ Set unResolvedDependencies = new LinkedHashSet<>(results.getUnResolvedDependencies());
+ sb.append(buildArtifactListOutput(
+ unResolvedDependencies, outputAbsoluteArtifactFilename, theOutputScope, theSort));
}
- sb.append( System.lineSeparator() );
+ sb.append(System.lineSeparator());
return sb.toString();
}
- private StringBuilder buildArtifactListOutput( Set artifacts, boolean outputAbsoluteArtifactFilename,
- boolean theOutputScope, boolean theSort )
- {
+ private StringBuilder buildArtifactListOutput(
+ Set artifacts, boolean outputAbsoluteArtifactFilename, boolean theOutputScope, boolean theSort) {
StringBuilder sb = new StringBuilder();
List artifactStringList = new ArrayList<>();
- for ( Artifact artifact : artifacts )
- {
+ for (Artifact artifact : artifacts) {
MessageBuilder messageBuilder = MessageUtils.buffer();
- messageBuilder.a( " " );
+ messageBuilder.a(" ");
- if ( theOutputScope )
- {
- messageBuilder.a( artifact.toString() );
- }
- else
- {
- messageBuilder.a( artifact.getId() );
+ if (theOutputScope) {
+ messageBuilder.a(artifact.toString());
+ } else {
+ messageBuilder.a(artifact.getId());
}
- if ( outputAbsoluteArtifactFilename )
- {
- try
- {
+ if (outputAbsoluteArtifactFilename) {
+ try {
// we want to print the absolute file name here
- String artifactFilename = artifact.getFile().getAbsoluteFile().getPath();
+ String artifactFilename =
+ artifact.getFile().getAbsoluteFile().getPath();
- messageBuilder.a( ':' ).a( artifactFilename );
- }
- catch ( NullPointerException e )
- {
+ messageBuilder.a(':').a(artifactFilename);
+ } catch (NullPointerException e) {
// ignore the null pointer, we'll output a null string
}
}
- if ( theOutputScope && artifact.isOptional() )
- {
- messageBuilder.a( " (optional)" );
+ if (theOutputScope && artifact.isOptional()) {
+ messageBuilder.a(" (optional)");
}
// dependencies:collect won't download jars
- if ( artifact.getFile() != null )
- {
- ModuleDescriptor moduleDescriptor = getModuleDescriptor( artifact.getFile() );
- if ( moduleDescriptor != null )
- {
- messageBuilder.project( " -- module " + moduleDescriptor.name );
-
- if ( moduleDescriptor.automatic )
- {
- if ( "MANIFEST".equals( moduleDescriptor.moduleNameSource ) )
- {
- messageBuilder.strong( " [auto]" );
- }
- else
- {
- messageBuilder.warning( " (auto)" );
+ if (artifact.getFile() != null) {
+ ModuleDescriptor moduleDescriptor = getModuleDescriptor(artifact.getFile());
+ if (moduleDescriptor != null) {
+ messageBuilder.project(" -- module " + moduleDescriptor.name);
+
+ if (moduleDescriptor.automatic) {
+ if ("MANIFEST".equals(moduleDescriptor.moduleNameSource)) {
+ messageBuilder.strong(" [auto]");
+ } else {
+ messageBuilder.warning(" (auto)");
}
}
}
}
- artifactStringList.add( messageBuilder + System.lineSeparator() );
+ artifactStringList.add(messageBuilder + System.lineSeparator());
}
- if ( theSort )
- {
- Collections.sort( artifactStringList );
+ if (theSort) {
+ Collections.sort(artifactStringList);
}
- for ( String artifactString : artifactStringList )
- {
- sb.append( artifactString );
+ for (String artifactString : artifactStringList) {
+ sb.append(artifactString);
}
return sb;
}
- private ModuleDescriptor getModuleDescriptor( File artifactFile )
- {
+ private ModuleDescriptor getModuleDescriptor(File artifactFile) {
ModuleDescriptor moduleDescriptor = null;
- try
- {
+ try {
// Use Java9 code to get moduleName, don't try to do it better with own implementation
- Class> moduleFinderClass = Class.forName( "java.lang.module.ModuleFinder" );
+ Class> moduleFinderClass = Class.forName("java.lang.module.ModuleFinder");
java.nio.file.Path path = artifactFile.toPath();
- Method ofMethod = moduleFinderClass.getMethod( "of", java.nio.file.Path[].class );
- Object moduleFinderInstance = ofMethod.invoke( null, new Object[] { new java.nio.file.Path[] { path } } );
+ Method ofMethod = moduleFinderClass.getMethod("of", java.nio.file.Path[].class);
+ Object moduleFinderInstance = ofMethod.invoke(null, new Object[] {new java.nio.file.Path[] {path}});
- Method findAllMethod = moduleFinderClass.getMethod( "findAll" );
- Set