maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From khmarba...@apache.org
Subject svn commit: r1760196 - in /maven/shared/trunk/maven-artifact-transfer: ./ src/main/java/org/apache/maven/shared/project/deploy/ src/main/java/org/apache/maven/shared/project/deploy/internal/
Date Sat, 10 Sep 2016 16:58:28 GMT
Author: khmarbaise
Date: Sat Sep 10 16:58:28 2016
New Revision: 1760196

URL: http://svn.apache.org/viewvc?rev=1760196&view=rev
Log:
[MSHARED-591] Add interface to deploy a Maven Project

Added:
    maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/project/deploy/
    maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/project/deploy/DeployProject.java
    maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/project/deploy/ProjectDeployRequest.java
    maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/project/deploy/internal/
    maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/project/deploy/internal/DefaultDeployProject.java
Modified:
    maven/shared/trunk/maven-artifact-transfer/pom.xml

Modified: maven/shared/trunk/maven-artifact-transfer/pom.xml
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-artifact-transfer/pom.xml?rev=1760196&r1=1760195&r2=1760196&view=diff
==============================================================================
--- maven/shared/trunk/maven-artifact-transfer/pom.xml (original)
+++ maven/shared/trunk/maven-artifact-transfer/pom.xml Sat Sep 10 16:58:28 2016
@@ -209,6 +209,13 @@
       <scope>provided</scope>
     </dependency>
 
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+      <version>1.7.5</version>
+      <scope>provided</scope>
+    </dependency>
+
     <!-- TEST -->
     <dependency>
       <groupId>junit</groupId>

Added: maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/project/deploy/DeployProject.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/project/deploy/DeployProject.java?rev=1760196&view=auto
==============================================================================
--- maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/project/deploy/DeployProject.java
(added)
+++ maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/project/deploy/DeployProject.java
Sat Sep 10 16:58:28 2016
@@ -0,0 +1,42 @@
+package org.apache.maven.shared.project.deploy;
+
+/*
+ * 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.project.ProjectBuildingRequest;
+
+/**
+ * This defines the interface to deploy a single Maven Project.
+ * 
+ * @author Karl Heinz Marbaise <a href="mailto:khmarbaise@apache.org">khmarbaise@apache.org</a>
+ */
+public interface DeployProject
+{
+    /**
+     * This will deploy a single project which may contain several artifacts. Those artifacts
will be deployed into the
+     * appropriate remote repository.
+     * 
+     * @param buildingRequest {@link ProjectBuildingRequest}
+     * @param request {@link ProjectDeployRequest}
+     * @param artifactRepository {@link ArtifactRepository}
+     */
+    void deployProject( ProjectBuildingRequest buildingRequest, ProjectDeployRequest request,
+                        ArtifactRepository artifactRepository );
+}

Added: maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/project/deploy/ProjectDeployRequest.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/project/deploy/ProjectDeployRequest.java?rev=1760196&view=auto
==============================================================================
--- maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/project/deploy/ProjectDeployRequest.java
(added)
+++ maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/project/deploy/ProjectDeployRequest.java
Sat Sep 10 16:58:28 2016
@@ -0,0 +1,148 @@
+package org.apache.maven.shared.project.deploy;
+
+/*
+ * 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.project.MavenProject;
+
+/**
+ * 
+ * @author Robert Scholte
+ */
+public class ProjectDeployRequest
+{
+
+    // From AbstractDeployMojo
+
+    private boolean updateReleaseInfo;
+
+    private int retryFailedDeploymentCount;
+
+    // From DeployMojo
+
+    private MavenProject project;
+
+    private String altDeploymentRepository;
+
+    private String altSnapshotDeploymentRepository;
+
+    private String altReleaseDeploymentRepository;
+
+    /**
+     * @return the updateReleaseInfo
+     */
+    public boolean isUpdateReleaseInfo()
+    {
+        return updateReleaseInfo;
+    }
+
+    /**
+     * @param updateReleaseInfo the updateReleaseInfo to set
+     */
+    public ProjectDeployRequest setUpdateReleaseInfo( boolean updateReleaseInfo )
+    {
+        this.updateReleaseInfo = updateReleaseInfo;
+        return this;
+    }
+
+    /**
+     * @return the retryFailedDeploymentCount
+     */
+    public int getRetryFailedDeploymentCount()
+    {
+        return retryFailedDeploymentCount;
+    }
+
+    /**
+     * @param retryFailedDeploymentCount the retryFailedDeploymentCount to set
+     */
+    public ProjectDeployRequest setRetryFailedDeploymentCount( int retryFailedDeploymentCount
)
+    {
+        this.retryFailedDeploymentCount = retryFailedDeploymentCount;
+        return this;
+    }
+
+    /**
+     * @return the project
+     */
+    public MavenProject getProject()
+    {
+        return project;
+    }
+
+    /**
+     * @param project the project to set
+     */
+    public ProjectDeployRequest setProject( MavenProject project )
+    {
+        this.project = project;
+        return this;
+    }
+
+    /**
+     * @return the altDeploymentRepository
+     */
+    public String getAltDeploymentRepository()
+    {
+        return altDeploymentRepository;
+    }
+
+    /**
+     * @param altDeploymentRepository the altDeploymentRepository to set
+     */
+    public ProjectDeployRequest setAltDeploymentRepository( String altDeploymentRepository
)
+    {
+        this.altDeploymentRepository = altDeploymentRepository;
+        return this;
+    }
+
+    /**
+     * @return the altSnapshotDeploymentRepository
+     */
+    public String getAltSnapshotDeploymentRepository()
+    {
+        return altSnapshotDeploymentRepository;
+    }
+
+    /**
+     * @param altSnapshotDeploymentRepository the altSnapshotDeploymentRepository to set
+     */
+    public ProjectDeployRequest setAltSnapshotDeploymentRepository( String altSnapshotDeploymentRepository
)
+    {
+        this.altSnapshotDeploymentRepository = altSnapshotDeploymentRepository;
+        return this;
+    }
+
+    /**
+     * @return the altReleaseDeploymentRepository
+     */
+    public String getAltReleaseDeploymentRepository()
+    {
+        return altReleaseDeploymentRepository;
+    }
+
+    /**
+     * @param altReleaseDeploymentRepository the altReleaseDeploymentRepository to set
+     */
+    public ProjectDeployRequest setAltReleaseDeploymentRepository( String altReleaseDeploymentRepository
)
+    {
+        this.altReleaseDeploymentRepository = altReleaseDeploymentRepository;
+        return this;
+    }
+}

Added: maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/project/deploy/internal/DefaultDeployProject.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/project/deploy/internal/DefaultDeployProject.java?rev=1760196&view=auto
==============================================================================
--- maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/project/deploy/internal/DefaultDeployProject.java
(added)
+++ maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/project/deploy/internal/DefaultDeployProject.java
Sat Sep 10 16:58:28 2016
@@ -0,0 +1,188 @@
+package org.apache.maven.shared.project.deploy.internal;
+
+/*
+ * 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 java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import javax.inject.Inject;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.project.ProjectBuildingRequest;
+import org.apache.maven.project.artifact.ProjectArtifactMetadata;
+import org.apache.maven.shared.artifact.deploy.ArtifactDeployer;
+import org.apache.maven.shared.artifact.deploy.ArtifactDeployerException;
+import org.apache.maven.shared.project.deploy.DeployProject;
+import org.apache.maven.shared.project.deploy.ProjectDeployRequest;
+import org.codehaus.plexus.component.annotations.Component;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This will deploy a whole project into the appropriate remote repository.
+ * 
+ * @author Karl Heinz Marbaise <a href="mailto:khmarbaise@apache.org">khmarbaise@apache.org</a>
+ *
+ * Most of the code is taken from maven-dependency-plugin.
+ * 
+ */
+@Component( role = DeployProject.class )
+public class DefaultDeployProject implements DeployProject
+{
+    private static final Logger LOGGER = LoggerFactory.getLogger( DefaultDeployProject.class
);
+
+    @Inject
+    private ArtifactDeployer deployer;
+
+    /**
+     * This will deploy a single project which may contain several artifacts
+     * into the appropriate remote repository.
+     * 
+     * @param buildingRequest {@link ProjectBuildingRequest}
+     * @param request {@link ProjectDeployRequest}
+     * @param artifactRepository {@link ArtifactRepository}
+     */
+    public void deployProject( ProjectBuildingRequest buildingRequest, ProjectDeployRequest
request,
+                               ArtifactRepository artifactRepository )
+    {
+        List<Artifact> deployableArtifacts = new ArrayList<Artifact>();
+
+        Artifact artifact = request.getProject().getArtifact();
+        String packaging = request.getProject().getPackaging();
+        File pomFile = request.getProject().getFile();
+
+        List<Artifact> attachedArtifacts = request.getProject().getAttachedArtifacts();
+
+        // Deploy the POM
+        boolean isPomArtifact = "pom".equals( packaging );
+        if ( !isPomArtifact )
+        {
+            ProjectArtifactMetadata metadata = new ProjectArtifactMetadata( artifact, pomFile
);
+            artifact.addMetadata( metadata );
+        }
+        else
+        {
+            artifact.setFile( pomFile );
+        }
+
+        if ( request.isUpdateReleaseInfo() )
+        {
+            artifact.setRelease( true );
+        }
+
+        artifact.setRepository( artifactRepository );
+
+        int retryFailedDeploymentCount = request.getRetryFailedDeploymentCount();
+
+        try
+        {
+            if ( isPomArtifact )
+            {
+                deployableArtifacts.add( artifact );
+            }
+            else
+            {
+                File file = artifact.getFile();
+
+                if ( file != null && file.isFile() )
+                {
+                    deployableArtifacts.add( artifact );
+                }
+                else if ( !attachedArtifacts.isEmpty() )
+                {
+                    throw new IllegalArgumentException( "The packaging plugin for this project
did not assign "
+                        + "a main file to the project but it has attachments. Change packaging
to 'pom'." );
+                }
+                else
+                {
+                    throw new IllegalArgumentException( "The packaging for this project did
not assign "
+                        + "a file to the build artifact" );
+                }
+            }
+
+            for ( Artifact attached : attachedArtifacts )
+            {
+                // This is here when AttachedArtifact is used, like m-sources-plugin:2.0.4
+                try
+                {
+                    attached.setRepository( artifactRepository );
+                }
+                catch ( UnsupportedOperationException e )
+                {
+                    LOGGER.warn( attached.getId() + " has been attached with deprecated code,
"
+                        + "try to upgrade the responsible plugin" );
+                }
+
+                deployableArtifacts.add( attached );
+            }
+
+            deploy( buildingRequest, deployableArtifacts, artifactRepository, retryFailedDeploymentCount
);
+        }
+        catch ( ArtifactDeployerException e )
+        {
+            throw new IllegalArgumentException( e.getMessage(), e );
+        }
+    }
+
+    private void deploy( ProjectBuildingRequest request, Collection<Artifact> artifacts,
+                         ArtifactRepository deploymentRepository, int retryFailedDeploymentCount
)
+        throws ArtifactDeployerException
+    {
+
+        // for now retry means redeploy the complete artifacts collection
+        int retryFailedDeploymentCounter = Math.max( 1, Math.min( 10, retryFailedDeploymentCount
) );
+        ArtifactDeployerException exception = null;
+        for ( int count = 0; count < retryFailedDeploymentCounter; count++ )
+        {
+            try
+            {
+                if ( count > 0 )
+                {
+                    LOGGER.info( "Retrying deployment attempt " + ( count + 1 ) + " of "
+                        + retryFailedDeploymentCounter );
+                }
+
+                deployer.deploy( request, deploymentRepository, artifacts );
+                exception = null;
+                break;
+            }
+            catch ( ArtifactDeployerException e )
+            {
+                if ( count + 1 < retryFailedDeploymentCounter )
+                {
+                    LOGGER.warn( "Encountered issue during deployment: " + e.getLocalizedMessage()
);
+                    LOGGER.debug( e.getMessage() );
+                }
+                if ( exception == null )
+                {
+                    exception = e;
+                }
+            }
+        }
+        if ( exception != null )
+        {
+            throw exception;
+        }
+    }
+
+}



Mime
View raw message