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 2018/02/14 20:04:40 UTC
[maven-artifact-transfer] 04/07: Added Maven Project Deployer IT
This is an automated email from the ASF dual-hosted git repository.
khmarbaise pushed a commit to branch MSHARED-656
in repository https://gitbox.apache.org/repos/asf/maven-artifact-transfer.git
commit e221d7f231bc14fd102b1b15e952cee053e696a3
Author: Karl Heinz Marbaise <kh...@apache.org>
AuthorDate: Sun Jan 28 19:48:04 2018 +0100
Added Maven Project Deployer IT
---
src/it/maven-project-deployer-plugin/pom.xml | 130 +++++++++++++++++++
.../plugin/project/deploy/ProjectDeployerMojo.java | 136 ++++++++++++++++++++
.../plugin/project/deploy/ProjectDeployerTest.java | 143 +++++++++++++++++++++
.../src/test/projects/example/pom.xml | 78 +++++++++++
4 files changed, 487 insertions(+)
diff --git a/src/it/maven-project-deployer-plugin/pom.xml b/src/it/maven-project-deployer-plugin/pom.xml
new file mode 100644
index 0000000..0f49542
--- /dev/null
+++ b/src/it/maven-project-deployer-plugin/pom.xml
@@ -0,0 +1,130 @@
+<?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.plugins</groupId>
+ <artifactId>maven-plugins</artifactId>
+ <version>30</version>
+ <relativePath />
+ </parent>
+
+ <artifactId>maven-project-deployer-plugin</artifactId>
+ <version>1.0.0</version>
+ <packaging>maven-plugin</packaging>
+
+ <name>Apache Maven Project Deployer Plugin</name>
+ <description>The plugin is only intended as a real testing environment for parts
+ of the maven-artifact-transfer component. In this test we check the ProjectDeployer</description>
+ <prerequisites>
+ <maven>${mavenVersion}</maven>
+ </prerequisites>
+
+ <properties>
+ <mavenVersion>3.0</mavenVersion>
+ <javaVersion>8</javaVersion>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>${mavenVersion}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-artifact</artifactId>
+ <version>${mavenVersion}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>maven-artifact-transfer</artifactId>
+<!-- <version>@project.version@</version> -->
+ <version>0.9.2-SNAPSHOT</version>
+ </dependency>
+
+ <!-- dependencies to annotations -->
+ <dependency>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-annotations</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>io.takari.maven.plugins</groupId>
+ <artifactId>takari-plugin-integration-testing</artifactId>
+ <version>2.9.1</version>
+ <type>pom</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>io.takari.maven.plugins</groupId>
+ <artifactId>takari-plugin-testing</artifactId>
+ <version>2.9.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <systemProperties>
+ <maven.local.repo>${maven.local.repo}</maven.local.repo>
+ <localRepositoryPath>${localRepositoryPath}</localRepositoryPath>
+ <mvnVersion>${mvnVersion}</mvnVersion>
+ </systemProperties>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>io.takari.maven.plugins</groupId>
+ <artifactId>takari-lifecycle-plugin</artifactId>
+ <version>1.13.1</version>
+ <executions>
+ <execution>
+ <?m2e ignore ?>
+ <id>testProperties</id>
+ <phase>process-test-resources</phase>
+ <goals>
+ <goal>testProperties</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+
+ </build>
+</project>
diff --git a/src/it/maven-project-deployer-plugin/src/main/java/org/apache/maven/plugin/project/deploy/ProjectDeployerMojo.java b/src/it/maven-project-deployer-plugin/src/main/java/org/apache/maven/plugin/project/deploy/ProjectDeployerMojo.java
new file mode 100644
index 0000000..17c0934
--- /dev/null
+++ b/src/it/maven-project-deployer-plugin/src/main/java/org/apache/maven/plugin/project/deploy/ProjectDeployerMojo.java
@@ -0,0 +1,136 @@
+package org.apache.maven.plugin.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 java.io.File;
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.plugin.AbstractMojo;
+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.MavenProjectHelper;
+import org.apache.maven.project.ProjectBuildingRequest;
+import org.apache.maven.shared.artifact.deploy.ArtifactDeployerException;
+import org.apache.maven.shared.project.NoFileAssignedException;
+import org.apache.maven.shared.project.deploy.ProjectDeployer;
+import org.apache.maven.shared.project.deploy.ProjectDeployerRequest;
+import org.apache.maven.shared.project.install.ProjectInstaller;
+import org.apache.maven.shared.repository.RepositoryManager;
+
+/**
+ * This mojo is implemented to test the {@link ProjectInstaller} part of the maven-artifact-transfer shared component.
+ */
+@Mojo( name = "project-deployer", defaultPhase = LifecyclePhase.VERIFY, threadSafe = true )
+public class ProjectDeployerMojo
+ extends AbstractMojo
+{
+
+ /**
+ * Parameter to have different locations for each Maven version we are testing with.
+ */
+ @Parameter
+ private String mvnVersion;
+
+ @Component
+ protected RepositoryManager repositoryManager;
+
+ @Parameter( defaultValue = "${session}", required = true, readonly = true )
+ protected MavenSession session;
+
+ @Component
+ private ProjectDeployer deployer;
+
+ @Component
+ private MavenProjectHelper projectHelper;
+
+ public void execute()
+ throws MojoExecutionException, MojoFailureException
+ {
+ getLog().info( "Hello from project-deployer plugin" );
+ installProject( session.getProjectBuildingRequest() );
+ getLog().info( "Bye bye from project-deployer plugin" );
+ }
+
+ private void createFileContent( File outputFile )
+ throws IOException
+ {
+ Path file = outputFile.toPath();
+ List<String> asList = Arrays.asList( "Line 1", "Line 2" );
+ Files.write( file, asList, Charset.forName( "UTF-8" ) );
+ }
+
+ private void installProject( ProjectBuildingRequest pbr )
+ throws MojoFailureException, MojoExecutionException
+ {
+ try
+ {
+
+ File artifactsDirectory =
+ new File( session.getCurrentProject().getBuild().getDirectory(), "tests/artifacts" );
+ artifactsDirectory.mkdirs();
+
+ getLog().info( "Directory: '" + artifactsDirectory.getAbsolutePath() + "'" );
+
+ File tmpFile = File.createTempFile( "project-deploy", ".jar", artifactsDirectory );
+ createFileContent( tmpFile );
+
+ File tmpFileClassifier = File.createTempFile( "project-deploy-classifier", ".jar", artifactsDirectory );
+ createFileContent( tmpFileClassifier );
+
+ projectHelper.attachArtifact( session.getCurrentProject(), "jar", "classifier", tmpFileClassifier );
+ session.getCurrentProject().getArtifact().setFile( tmpFile );
+
+ ProjectDeployerRequest pdr = new ProjectDeployerRequest();
+ pdr.setProject( session.getCurrentProject());
+
+ ArtifactRepository repo = session.getCurrentProject().getDistributionManagementArtifactRepository();
+ deployer.deploy( session.getProjectBuildingRequest(), pdr, repo );
+ }
+ catch ( IOException e )
+ {
+ throw new MojoExecutionException( "IOException", e );
+ }
+ catch ( NoFileAssignedException e )
+ {
+ throw new MojoExecutionException( "NoFileAssignedException", e );
+ }
+ catch ( IllegalArgumentException e )
+ {
+ throw new MojoExecutionException( "IllegalArgumentException", e );
+ }
+ catch ( ArtifactDeployerException e )
+ {
+ throw new MojoExecutionException( "ArtifactDeployerException", e );
+ }
+
+ }
+
+}
diff --git a/src/it/maven-project-deployer-plugin/src/test/java/org/apache/maven/plugin/project/deploy/ProjectDeployerTest.java b/src/it/maven-project-deployer-plugin/src/test/java/org/apache/maven/plugin/project/deploy/ProjectDeployerTest.java
new file mode 100644
index 0000000..e8f97c9
--- /dev/null
+++ b/src/it/maven-project-deployer-plugin/src/test/java/org/apache/maven/plugin/project/deploy/ProjectDeployerTest.java
@@ -0,0 +1,143 @@
+package org.apache.maven.plugin.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 static org.junit.Assert.assertTrue;
+
+import java.io.File;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import io.takari.maven.testing.TestResources;
+import io.takari.maven.testing.executor.MavenExecutionResult;
+import io.takari.maven.testing.executor.MavenRuntime;
+import io.takari.maven.testing.executor.MavenRuntime.MavenRuntimeBuilder;
+import io.takari.maven.testing.executor.MavenVersions;
+import io.takari.maven.testing.executor.junit.MavenJUnitTestRunner;
+
+/**
+ * This will check if the ProjectDeployer works for all Maven versions 3.0.5, 3.1.1, 3.2.5, 3.3.1, 3.3.9, 3.5.0, 3.5.2
+ * This is done by using the test plugin <code>maven-project-deployer-plugin</code> which uses the ProjectDeplyoer as
+ * component. By using this way we get a real runtime environment which supports all Maven versions.
+ *
+ * @author Karl Heinz Marbaise
+ */
+@RunWith( MavenJUnitTestRunner.class )
+@MavenVersions( { "3.0.5", "3.1.1", "3.2.5", "3.3.1", "3.3.9", "3.5.0", "3.5.2" } )
+public class ProjectDeployerTest
+{
+
+ @Rule
+ public final TestResources resources = new TestResources();
+
+ public final MavenRuntime mavenRuntime;
+
+ public ProjectDeployerTest( MavenRuntimeBuilder builder )
+ throws Exception
+ {
+ this.mavenRuntime = builder.build();
+ }
+
+ @Test
+ public void buildExample()
+ throws Exception
+ {
+ File basedir = resources.getBasedir( "example" );
+ //@formatter:off
+ MavenExecutionResult result =
+ mavenRuntime
+ .forProject( basedir )
+ .withCliOption( "-DmvnVersion=" + mavenRuntime.getMavenVersion() ) // Might be superfluous
+ .withCliOption( "-B" )
+ .withCliOption( "-V" )
+ // We use verify to prevent running maven-install-plugin.
+ .execute( "clean", "verify" );
+ //@formatter:on
+
+ result.assertErrorFreeLog();
+
+ // Check that the current plugins has been called at least once.
+ result.assertLogText( "[INFO] --- maven-project-deployer-plugin:1.0.0:project-deployer (id-project-deployer) @ maven-project-deployer-plugin-it ---" );
+
+ String mvnVersion = mavenRuntime.getMavenVersion() + "/";
+ // The "." will be replaced by "/" in the running of the artifact-installer-plugin so I need to do the same
+ // here.
+ // Maybe there is a more elegant way to do that?
+ mvnVersion = mvnVersion.replaceAll( "\\.", "/" );
+
+ String mavenRepoLocal = System.getProperty( "maven.repo.local" );
+ File localRepo = new File( mavenRepoLocal );
+
+ System.out.println( "localRepo='" + localRepo.getAbsolutePath() + "'" );
+ System.out.println( "mvnVersion='" + mvnVersion + "'" );
+
+ // Thats needed cause the transfer of other variables seemed to be not working (Or I do something wrong).
+ File repositoryBase = new File( localRepo.getParent(), "dist" );
+
+ File baseDirectoy =
+ new File( repositoryBase, "PROJECT-DEPLOYER-GROUPID-" + mvnVersion + "maven-project-deployer-plugin-it/" );
+
+ checkForMetadata( baseDirectoy );
+
+ baseDirectoy = new File( baseDirectoy, "1.0.0-A" );
+
+ checkForPomFile( baseDirectoy );
+
+ checkForJarFile( baseDirectoy );
+
+ checkForJarClassifierFile( baseDirectoy );
+
+ }
+
+ private void checkForMetadata( File baseDirectoy )
+ {
+ File metadataFile = new File( baseDirectoy, "maven-metadata.xml" );
+ assertTrue( "metadataFile '" + metadataFile.getAbsolutePath() + "'", metadataFile.exists() );
+ assertTrue( "metadataFile md5 not found.", new File( metadataFile.getAbsolutePath() + ".md5" ).exists() );
+ assertTrue( "metadataFile sha1 not found.", new File( metadataFile.getAbsolutePath() + ".sha1" ).exists() );
+ }
+
+ private void checkForJarClassifierFile( File baseDirectoy )
+ {
+ File jarClassifierFile = new File( baseDirectoy, "maven-project-deployer-plugin-it-1.0.0-A-classifier.jar" );
+ assertTrue( "jarClassifierFile '" + jarClassifierFile.getAbsolutePath() + "'", jarClassifierFile.exists() );
+ assertTrue( "jarClassifier md5 not found.", new File( jarClassifierFile.getAbsolutePath() + ".md5" ).exists() );
+ assertTrue( "jarClassifier sha1 not found.",
+ new File( jarClassifierFile.getAbsolutePath() + ".sha1" ).exists() );
+ }
+
+ private void checkForJarFile( File baseDirectoy )
+ {
+ File jarFile = new File( baseDirectoy, "maven-project-deployer-plugin-it-1.0.0-A.jar" );
+ assertTrue( "jarFile '" + jarFile.getAbsolutePath() + "'", jarFile.exists() );
+ assertTrue( "jar md5 not found.", new File( jarFile.getAbsolutePath() + ".md5" ).exists() );
+ assertTrue( "jar sha1 not found.", new File( jarFile.getAbsolutePath() + ".sha1" ).exists() );
+ }
+
+ private void checkForPomFile( File baseDirectoy )
+ {
+ File pomFile = new File( baseDirectoy, "maven-project-deployer-plugin-it-1.0.0-A.pom" );
+ assertTrue( "pomFile '" + pomFile.getAbsolutePath() + "'", pomFile.exists() );
+ assertTrue( "pom md5 not found.", new File( pomFile.getAbsolutePath() + ".md5" ).exists() );
+ assertTrue( "pom sha1 not found.", new File( pomFile.getAbsolutePath() + ".sha1" ).exists() );
+ }
+}
\ No newline at end of file
diff --git a/src/it/maven-project-deployer-plugin/src/test/projects/example/pom.xml b/src/it/maven-project-deployer-plugin/src/test/projects/example/pom.xml
new file mode 100644
index 0000000..bc63091
--- /dev/null
+++ b/src/it/maven-project-deployer-plugin/src/test/projects/example/pom.xml
@@ -0,0 +1,78 @@
+<?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.shared</groupId>
+ <artifactId>maven-shared-components</artifactId>
+ <version>30</version>
+ <relativePath />
+ </parent>
+
+ <groupId>PROJECT-DEPLOYER-GROUPID-${mvnVersion}</groupId>
+ <artifactId>maven-project-deployer-plugin-it</artifactId>
+ <version>1.0.0-A</version>
+
+ <distributionManagement>
+ <repository>
+ <id>distribution-repo</id>
+ <!--
+ ! Need to find a better way to express this.
+ -->
+ <url>file:///${maven.repo.local}/../dist</url>
+<!-- <url>file:///${project.basedir}/../../../../../dist</url> -->
+ </repository>
+ </distributionManagement>
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-project-deployer-plugin</artifactId>
+ <version>${it-plugin.version}</version>
+ <configuration>
+ <localRepositoryPath>${localRepositoryPath}</localRepositoryPath>
+ <mvnVersion>${mvnVersion}</mvnVersion>
+ </configuration>
+ <executions>
+ <execution>
+ <id>id-project-deployer</id>
+ <goals>
+ <goal>project-deployer</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
--
To stop receiving notification emails like this one, please contact
khmarbaise@apache.org.