Skip to content

Commit

Permalink
[MDEPLOY-305] Improvement in DeployAtEnd
Browse files Browse the repository at this point in the history
- Fix when module does not use m-deploy-p
- Don't use metadata from main artifact to fetch pom.xml
- Deploy all artifacts in one request
  • Loading branch information
slawekjaranowski committed Jan 26, 2023
1 parent 6c2ce48 commit 33d89b1
Show file tree
Hide file tree
Showing 12 changed files with 332 additions and 76 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@ under the License.
<postBuildHookScript>verify</postBuildHookScript>
<localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
<settingsFile>src/it/settings.xml</settingsFile>
<scriptVariables>
<remoteRepo>${project.build.directory}/remote-repo</remoteRepo>
</scriptVariables>
<filterProperties>
<remoteRepo>${project.build.directory}/remote-repo</remoteRepo>
</filterProperties>
<goals>
<goal>deploy</goal>
</goals>
Expand Down
39 changes: 39 additions & 0 deletions src/it/deploy-at-end-pass/module2/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?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 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. -->

<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>
<groupId>org.apache.maven.its.deploy.dae.pass</groupId>
<artifactId>dae</artifactId>
<version>1.0</version>
</parent>
<artifactId>module2</artifactId>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<executions>
<execution>
<id>default-deploy</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
25 changes: 25 additions & 0 deletions src/it/deploy-at-end-pass/module3/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?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 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. -->

<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>
<groupId>org.apache.maven.its.deploy.dae.pass</groupId>
<artifactId>dae</artifactId>
<version>1.0</version>
</parent>
<artifactId>module3</artifactId>

</project>
38 changes: 38 additions & 0 deletions src/it/deploy-at-end-pass/module4/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?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 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. -->

<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>
<groupId>org.apache.maven.its.deploy.dae.pass</groupId>
<artifactId>dae</artifactId>
<version>1.0</version>
</parent>
<artifactId>module4</artifactId>

<!-- packaging without deploy plugin -->
<packaging>without-deploy</packaging>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.its.deploy.mock</groupId>
<artifactId>mock-phase-maven-plugin</artifactId>
<version>1.0</version>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
</project>
5 changes: 4 additions & 1 deletion src/it/deploy-at-end-pass/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ under the License.
<distributionManagement>
<repository>
<id>it</id>
<url>file:///${basedir}/target/repo</url>
<url>file:///@remoteRepo@/deploy-at-end-pass</url>
</repository>
</distributionManagement>

Expand Down Expand Up @@ -95,5 +95,8 @@ under the License.

<modules>
<module>module1</module>
<module>module2</module>
<module>module3</module>
<module>module4</module>
</modules>
</project>
9 changes: 7 additions & 2 deletions src/it/deploy-at-end-pass/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@
* under the License.
*/

assert new File( basedir, "target/repo/org/apache/maven/its/deploy/dae/pass/dae/1.0/dae-1.0.pom" ).exists()
assert new File( basedir, "module1/target/repo/org/apache/maven/its/deploy/dae/pass/module1/1.0/module1-1.0.pom" ).exists()
assert new File( remoteRepo, "deploy-at-end-pass/org/apache/maven/its/deploy/dae/pass/dae/1.0/dae-1.0.pom" ).exists()
assert new File( remoteRepo, "deploy-at-end-pass/org/apache/maven/its/deploy/dae/pass/module1/1.0/module1-1.0.pom" ).exists()
assert new File( remoteRepo, "deploy-at-end-pass/org/apache/maven/its/deploy/dae/pass/module1/1.0/module1-1.0.jar" ).exists()
assert new File( remoteRepo, "deploy-at-end-pass/org/apache/maven/its/deploy/dae/pass/module3/1.0/module3-1.0.pom" ).exists()
assert new File( remoteRepo, "deploy-at-end-pass/org/apache/maven/its/deploy/dae/pass/module3/1.0/module3-1.0.jar" ).exists()

File buildLog = new File( basedir, 'build.log' )
assert buildLog.exists()
assert buildLog.text.contains( "[INFO] Deferring deploy for org.apache.maven.its.deploy.dae.pass:dae:1.0 at end" )
assert buildLog.text.contains( "[INFO] Deferring deploy for org.apache.maven.its.deploy.dae.pass:module1:1.0 at end" )
assert buildLog.text.contains( "[INFO] Deferring deploy for org.apache.maven.its.deploy.dae.pass:module3:1.0 at end" )

18 changes: 18 additions & 0 deletions src/it/setup-mock-phase-maven-plugin/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# 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.

invoker.goals = install
57 changes: 57 additions & 0 deletions src/it/setup-mock-phase-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?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
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.
-->

<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>

<groupId>org.apache.maven.its.deploy.mock</groupId>
<artifactId>mock-phase-maven-plugin</artifactId>
<version>1.0</version>
<packaging>maven-plugin</packaging>

<prerequisites>
<maven>@mavenVersion@</maven>
</prerequisites>

<description>plugin with Maven phase without m-deploy-p</description>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>@mavenInstallPluginVersion@</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>@mavenPluginToolsVersion@</version>
<configuration>
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?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
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.
-->

<component-set>
<components>
<component>
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
<role-hint>without-deploy</role-hint>
<implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation>
<configuration>
<lifecycles>
<lifecycle>
<id>default</id>
<phases>
<process-resources>org.apache.maven.plugins:maven-resources-plugin:resources</process-resources>
</phases>
</lifecycle>
</lifecycles>
</configuration>
</component>
</components>
</component-set>
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.rtinfo.RuntimeInformation;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.deployment.DeployRequest;
import org.eclipse.aether.deployment.DeploymentException;
import org.eclipse.aether.repository.RemoteRepository;
Expand Down Expand Up @@ -122,10 +121,13 @@ protected RemoteRepository getRemoteRepository(final String repositoryId, final
return result;
}

/**
* Handles high level retries (this was buried into MAT).
*/
protected void deploy(RepositorySystemSession session, DeployRequest deployRequest) throws MojoExecutionException {
// I'm not sure if retries will work with deploying on client level ...
// Most repository managers block a duplicate artifacts.

// Eg, when we have an artifact list, even simple pom and jar in one request with released version,
// next try can fail due to duplicate.

protected void deploy(DeployRequest deployRequest) throws MojoExecutionException {
int retryFailedDeploymentCounter = Math.max(1, Math.min(10, retryFailedDeploymentCount));
DeploymentException exception = null;
for (int count = 0; count < retryFailedDeploymentCounter; count++) {
Expand All @@ -134,7 +136,7 @@ protected void deploy(RepositorySystemSession session, DeployRequest deployReque
getLog().info("Retrying deployment attempt " + (count + 1) + " of " + retryFailedDeploymentCounter);
}

repositorySystem.deploy(session, deployRequest);
repositorySystem.deploy(session.getRepositorySession(), deployRequest);
exception = null;
break;
} catch (DeploymentException e) {
Expand Down
Loading

0 comments on commit 33d89b1

Please sign in to comment.