You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by kh...@apache.org on 2016/09/18 17:26:28 UTC
svn commit: r1761346 - in /maven/plugins/trunk/maven-install-plugin: ./
src/main/java/org/apache/maven/plugin/install/
src/test/java/org/apache/maven/plugin/install/
Author: khmarbaise
Date: Sun Sep 18 17:26:28 2016
New Revision: 1761346
URL: http://svn.apache.org/viewvc?rev=1761346&view=rev
Log:
Improved usage of maven-artifact-transfer component:
o pom.xml
o Remove maven-model dependency.
o Added slf4j-api (provided), slf4j-nop in test scope.
o InstallMojo
Using ProjectInstaller and using ProjectInstallerRequest instead
of InstallRequest.
Removed:
maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/InstallRequest.java
Modified:
maven/plugins/trunk/maven-install-plugin/pom.xml
maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/InstallMojo.java
maven/plugins/trunk/maven-install-plugin/src/test/java/org/apache/maven/plugin/install/InstallMojoTest.java
Modified: maven/plugins/trunk/maven-install-plugin/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-install-plugin/pom.xml?rev=1761346&r1=1761345&r2=1761346&view=diff
==============================================================================
--- maven/plugins/trunk/maven-install-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-install-plugin/pom.xml Sun Sep 18 17:26:28 2016
@@ -1,25 +1,26 @@
<?xml version='1.0' encoding='UTF-8'?>
<!--
-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
+ 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.
+ 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.
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
@@ -68,11 +69,11 @@ under the License.
<artifactId>maven-plugin-api</artifactId>
<version>${mavenVersion}</version>
</dependency>
- <dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-model</artifactId>
- <version>${mavenVersion}</version>
- </dependency>
+ <!-- <dependency> -->
+ <!-- <groupId>org.apache.maven</groupId> -->
+ <!-- <artifactId>maven-model</artifactId> -->
+ <!-- <version>${mavenVersion}</version> -->
+ <!-- </dependency> -->
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
@@ -128,7 +129,19 @@ under the License.
<version>1.9.5</version>
<scope>test</scope>
</dependency>
-
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.7.5</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-nop</artifactId>
+ <version>1.7.5</version>
+ <scope>test</scope>
+ </dependency>
+
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
Modified: maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/InstallMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/InstallMojo.java?rev=1761346&r1=1761345&r2=1761346&view=diff
==============================================================================
--- maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/InstallMojo.java (original)
+++ maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/InstallMojo.java Sun Sep 18 17:26:28 2016
@@ -19,23 +19,24 @@ package org.apache.maven.plugin.install;
* under the License.
*/
-import java.io.File;
+import java.io.IOException;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.Collections;
-import java.util.LinkedHashSet;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
-import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugins.annotations.Component;
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.project.MavenProject;
-import org.apache.maven.project.artifact.ProjectArtifact;
-import org.apache.maven.project.artifact.ProjectArtifactMetadata;
+import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.shared.artifact.install.ArtifactInstallerException;
+import org.apache.maven.shared.project.NoFileAssignedException;
+import org.apache.maven.shared.project.install.ProjectInstaller;
+import org.apache.maven.shared.project.install.ProjectInstallerRequest;
/**
* Installs the project's main artifact, and any other artifacts attached by other plugins in the lifecycle, to the
@@ -55,8 +56,8 @@ public class InstallMojo
*/
private static final AtomicInteger READYPROJECTSCOUTNER = new AtomicInteger();
- private static final List<InstallRequest> INSTALLREQUESTS =
- Collections.synchronizedList( new ArrayList<InstallRequest>() );
+ private static final List<ProjectInstallerRequest> INSTALLREQUESTS =
+ Collections.synchronizedList( new ArrayList<ProjectInstallerRequest>() );
/**
*/
@@ -65,7 +66,7 @@ public class InstallMojo
@Parameter( defaultValue = "${reactorProjects}", required = true, readonly = true )
private List<MavenProject> reactorProjects;
-
+
/**
* Whether every project should be installed during its own install-phase or at the end of the multimodule build. If
* set to {@code true} and the build fails, none of the reactor projects is installed.
@@ -85,8 +86,11 @@ public class InstallMojo
@Parameter( property = "maven.install.skip", defaultValue = "false" )
private boolean skip;
+ @Component
+ private ProjectInstaller installer;
+
public void execute()
- throws MojoExecutionException
+ throws MojoExecutionException, MojoFailureException
{
boolean addedInstallRequest = false;
if ( skip )
@@ -96,17 +100,17 @@ public class InstallMojo
else
{
// CHECKSTYLE_OFF: LineLength
- InstallRequest currentExecutionInstallRequest =
- new InstallRequest().setProject( project ).setCreateChecksum( createChecksum ).setUpdateReleaseInfo( updateReleaseInfo );
+ ProjectInstallerRequest projectInstallerRequest =
+ new ProjectInstallerRequest().setProject( project ).setCreateChecksum( createChecksum ).setUpdateReleaseInfo( updateReleaseInfo );
// CHECKSTYLE_ON: LineLength
if ( !installAtEnd )
{
- installProject( currentExecutionInstallRequest );
+ installProject( session.getProjectBuildingRequest(), projectInstallerRequest );
}
else
{
- INSTALLREQUESTS.add( currentExecutionInstallRequest );
+ INSTALLREQUESTS.add( projectInstallerRequest );
addedInstallRequest = true;
}
}
@@ -118,96 +122,38 @@ public class InstallMojo
{
while ( !INSTALLREQUESTS.isEmpty() )
{
- installProject( INSTALLREQUESTS.remove( 0 ) );
+ installProject( session.getProjectBuildingRequest(), INSTALLREQUESTS.remove( 0 ) );
}
}
}
else if ( addedInstallRequest )
{
getLog().info( "Installing " + project.getGroupId() + ":" + project.getArtifactId() + ":"
- + project.getVersion() + " at end" );
+ + project.getVersion() + " at end" );
}
}
- private void installProject( InstallRequest request )
- throws MojoExecutionException
+ private void installProject( ProjectBuildingRequest pbr, ProjectInstallerRequest pir )
+ throws MojoFailureException, MojoExecutionException
{
- MavenProject project = request.getProject();
- boolean createChecksum = request.isCreateChecksum();
- boolean updateReleaseInfo = request.isUpdateReleaseInfo();
-
- Artifact artifact = project.getArtifact();
- String packaging = project.getPackaging();
- File pomFile = project.getFile();
-
- List<Artifact> attachedArtifacts = project.getAttachedArtifacts();
-
- // TODO: push into transformation
- boolean isPomArtifact = "pom".equals( packaging );
-
- ProjectArtifactMetadata metadata;
-
- if ( updateReleaseInfo )
+ try
{
- artifact.setRelease( true );
+ installer.installProject( session.getProjectBuildingRequest(), pir,
+ localRepository );
}
-
- try
+ catch ( IOException e )
{
- Collection<File> metadataFiles = new LinkedHashSet<File>();
-
- if ( isPomArtifact )
- {
-// installer.install( pomFile, artifact, localRepository );
- installer.install( session.getProjectBuildingRequest(),
- Collections.<Artifact>singletonList( new ProjectArtifact( project ) ) );
- installChecksums( artifact, createChecksum );
- addMetaDataFilesForArtifact( artifact, metadataFiles, createChecksum );
- }
- else
- {
- metadata = new ProjectArtifactMetadata( artifact, pomFile );
- artifact.addMetadata( metadata );
-
- File file = artifact.getFile();
-
- // Here, we have a temporary solution to MINSTALL-3 (isDirectory() is true if it went through compile
- // but not package). We are designing in a proper solution for Maven 2.1
- if ( file != null && file.isFile() )
- {
-// installer.install( file, artifact, localRepository );
- installer.install( session.getProjectBuildingRequest(), Collections.singletonList( artifact ) );
- installChecksums( artifact, createChecksum );
- addMetaDataFilesForArtifact( artifact, metadataFiles, createChecksum );
- }
- else if ( !attachedArtifacts.isEmpty() )
- {
- throw new MojoExecutionException( "The packaging plugin for this project did not assign "
- + "a main file to the project but it has attachments. Change packaging to 'pom'." );
- }
- else
- {
- // CHECKSTYLE_OFF: LineLength
- throw new MojoExecutionException(
- "The packaging for this project did not assign a file to the build artifact" );
- // CHECKSTYLE_ON: LineLength
- }
- }
-
- for ( Artifact attached : attachedArtifacts )
- {
-// installer.install( attached.getFile(), attached, localRepository );
- installer.install( session.getProjectBuildingRequest(), Collections.singletonList( attached ) );
- installChecksums( attached, createChecksum );
- addMetaDataFilesForArtifact( attached, metadataFiles, createChecksum );
- }
-
- installChecksums( metadataFiles );
+ throw new MojoFailureException( "IOException", e );
}
catch ( ArtifactInstallerException e )
{
- throw new MojoExecutionException( e.getMessage(), e );
+ throw new MojoExecutionException( "ArtifactInstallerException", e );
}
+ catch ( NoFileAssignedException e )
+ {
+ throw new MojoExecutionException( "NoFileAssignedException", e );
+ }
+
}
public void setSkip( boolean skip )
Modified: maven/plugins/trunk/maven-install-plugin/src/test/java/org/apache/maven/plugin/install/InstallMojoTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-install-plugin/src/test/java/org/apache/maven/plugin/install/InstallMojoTest.java?rev=1761346&r1=1761345&r2=1761346&view=diff
==============================================================================
--- maven/plugins/trunk/maven-install-plugin/src/test/java/org/apache/maven/plugin/install/InstallMojoTest.java (original)
+++ maven/plugins/trunk/maven-install-plugin/src/test/java/org/apache/maven/plugin/install/InstallMojoTest.java Sun Sep 18 17:26:28 2016
@@ -26,6 +26,7 @@ import java.io.File;
import java.util.Collections;
import java.util.List;
+import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.execution.MavenSession;
@@ -127,7 +128,7 @@ public class InstallMojoTest
setVariableValueToObject( mojo, "reactorProjects", Collections.singletonList( project ) );
setVariableValueToObject( mojo, "session", createMavenSession() );
- List attachedArtifacts = project.getAttachedArtifacts();
+ List<Artifact> attachedArtifacts = project.getAttachedArtifacts();
mojo.execute();