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 fa459fbaa5c2a0d2ae0cfd4299b2f751d2ff9877 Author: Karl Heinz Marbaise <khmarba...@apache.org> AuthorDate: Thu Dec 21 16:11:54 2017 +0100 [MSHARED-656] Make integration testing for different Maven versions possible o Added separate integration test projects to make IT's possible o Reformatted code * Added null checks for parameters in ProjectDeployer and ProjectInstaller included tests to check this. * Added working IT for ProjectInstaller. o Enhanced apache-rat-plugin configuration * Fixed missing copyright header. o Added Maven Project Deployer IT o Added argument checks. o Added DefaultDependencyCollectorTest --- .gitignore | 1 + pom.xml | 77 +++++++++++ src/it/maven-artifact-deployer-plugin/pom.xml | 130 +++++++++++++++++++ .../artifact/deployer/ArtifactDeployerMojo.java | 129 +++++++++++++++++++ .../artifact/deployer/ArtifactDeployerTest.java | 120 +++++++++++++++++ .../src/test/projects/example/pom.xml | 67 ++++++++++ src/it/maven-artifact-installer-plugin/pom.xml | 130 +++++++++++++++++++ .../artifact/installer/ArtifactInstallerMojo.java | 128 ++++++++++++++++++ .../artifact/installer/ArtifactInstallerTest.java | 127 ++++++++++++++++++ .../src/test/projects/example/pom.xml | 67 ++++++++++ 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 | 77 +++++++++++ src/it/maven-project-installer-plugin/pom.xml | 130 +++++++++++++++++++ .../project/install/ProjectInstallerMojo.java | 129 +++++++++++++++++++ .../project/install/ProjectInstallerTest.java | 129 +++++++++++++++++++ .../src/test/projects/example/pom.xml | 68 ++++++++++ src/it/settings.xml | 55 ++++++++ .../artifact/deploy/ArtifactDeployerException.java | 1 + .../shared/artifact/install/ArtifactInstaller.java | 10 +- .../install/internal/DefaultArtifactInstaller.java | 1 - .../install/internal/Maven31ArtifactInstaller.java | 1 - .../dependencies/collect/DependencyCollector.java | 6 + .../internal/DefaultDependencyCollector.java | 49 ++++++- .../shared/project/deploy/ProjectDeployer.java | 10 +- .../deploy/internal/DefaultProjectDeployer.java | 95 +++++++------- .../shared/project/install/ProjectInstaller.java | 14 +- .../install/internal/DefaultProjectInstaller.java | 3 +- .../{install-project.apt => deploy-project.apt} | 21 +-- src/site/apt/install-project.apt | 9 +- .../internal/DefaultArtifactDeployerTest.java | 12 +- .../internal/DefaultArtifactInstallerTest.java | 3 +- .../internal/DefaultDependencyCollectorTest.java | 115 +++++++++++++++++ .../DefaultDependencyCoordinateTest.java | 1 + .../internal/DefaultProjectDeployerTest.java | 82 ++++++++++++ .../internal/DefaultProjectInstallerTest.java | 27 ++-- 37 files changed, 2333 insertions(+), 100 deletions(-) diff --git a/.gitignore b/.gitignore index d0d7222..3578f45 100644 --- a/.gitignore +++ b/.gitignore @@ -12,5 +12,6 @@ out/ .DS_Store /bootstrap /dependencies.xml +/dependency-reduced-pom.xml .java-version dependency-reduced-pom.xml diff --git a/pom.xml b/pom.xml index 01719f6..961887f 100644 --- a/pom.xml +++ b/pom.xml @@ -56,6 +56,9 @@ </site> </distributionManagement> + <properties> + <javaVersion>7</javaVersion> + </properties> <build> <plugins> <plugin> @@ -106,6 +109,7 @@ <plugin> <groupId>org.apache.rat</groupId> <artifactId>apache-rat-plugin</artifactId> + <version>0.12</version> <configuration> <excludes combine.children="append"> <exclude>dependency-reduced-pom.xml</exclude> @@ -153,6 +157,7 @@ </execution> </executions> </plugin> + </plugins> </build> @@ -243,6 +248,7 @@ <version>4.11</version> <scope>test</scope> </dependency> + <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-core</artifactId> @@ -264,4 +270,75 @@ </pluginRepository> </pluginRepositories> + <profiles> + <profile> + <id>run-its</id> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-invoker-plugin</artifactId> + <version>3.0.1</version> + <dependencies> + <dependency> + <groupId>org.codehaus.groovy</groupId> + <artifactId>groovy</artifactId> + <version>2.4.10</version> + </dependency> + <dependency> + <groupId>org.codehaus.gmaven.runtime</groupId> + <artifactId>gmaven-runtime-2.0</artifactId> + <version>1.5</version> + </dependency> + </dependencies> + <configuration> + <addTestClassPath>true</addTestClassPath> + <debug>false</debug> + <localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath> + <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo> + <projectsDirectory>src/it</projectsDirectory> + <showVersion>false</showVersion> + <pomIncludes> + <pomInclude>*/pom.xml</pomInclude> + </pomIncludes> + <preBuildHookScript>setup</preBuildHookScript> + <postBuildHookScript>verify</postBuildHookScript> + <settingsFile>src/it/settings.xml</settingsFile> + <!-- Currently working with more than one thread does not work, cause + it is not guaranteed that the setup-config project is build at first. see + also http://jira.codehaus.org/browse/MINVOKER-147 --> + <parallelThreads>1</parallelThreads> + <filterProperties> + <repository.proxy.url>${repository.proxy.url}</repository.proxy.url> + <localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath> + </filterProperties> + <extraArtifacts> + <extraArtifact>org.apache.maven:apache-maven:3.0.5:tar.gz:bin</extraArtifact> + <extraArtifact>org.apache.maven:apache-maven:3.1.1:tar.gz:bin</extraArtifact> + <extraArtifact>org.apache.maven:apache-maven:3.2.5:tar.gz:bin</extraArtifact> + <extraArtifact>org.apache.maven:apache-maven:3.3.1:tar.gz:bin</extraArtifact> + <extraArtifact>org.apache.maven:apache-maven:3.3.9:tar.gz:bin</extraArtifact> + <extraArtifact>org.apache.maven:apache-maven:3.5.0:tar.gz:bin</extraArtifact> + </extraArtifacts> + </configuration> + <executions> + <execution> + <id>pre-integration-tests</id> + <goals> + <goal>install</goal> + </goals> + </execution> + <execution> + <id>integration-tests</id> + <goals> + <goal>run</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + + </build> + </profile> + </profiles> </project> diff --git a/src/it/maven-artifact-deployer-plugin/pom.xml b/src/it/maven-artifact-deployer-plugin/pom.xml new file mode 100644 index 0000000..9ebabc3 --- /dev/null +++ b/src/it/maven-artifact-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-artifact-deployer-plugin</artifactId> + <version>1.0.0</version> + <packaging>maven-plugin</packaging> + + <name>Apache Maven Artifact 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 ArtifactDeployer</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-artifact-deployer-plugin/src/main/java/org/apache/maven/plugin/artifact/deployer/ArtifactDeployerMojo.java b/src/it/maven-artifact-deployer-plugin/src/main/java/org/apache/maven/plugin/artifact/deployer/ArtifactDeployerMojo.java new file mode 100644 index 0000000..d5bf396 --- /dev/null +++ b/src/it/maven-artifact-deployer-plugin/src/main/java/org/apache/maven/plugin/artifact/deployer/ArtifactDeployerMojo.java @@ -0,0 +1,129 @@ +package org.apache.maven.plugin.artifact.deployer; + +/* + * 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.Collection; +import java.util.List; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.DefaultArtifact; +import org.apache.maven.artifact.handler.DefaultArtifactHandler; +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.ProjectBuildingRequest; +import org.apache.maven.shared.artifact.deploy.ArtifactDeployer; +import org.apache.maven.shared.artifact.deploy.ArtifactDeployerException; +import org.apache.maven.shared.repository.RepositoryManager; + +/** + * This mojo is implemented to test the ArtifactDeployer part of the maven-artifact-transfer shared component. + */ +@Mojo( name = "artifact-deployer", defaultPhase = LifecyclePhase.VERIFY, threadSafe = true ) +public class ArtifactDeployerMojo + 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 ArtifactDeployer deployer; + + public void execute() + throws MojoExecutionException, MojoFailureException + { + getLog().info( "Hello from artifact-deployer plugin" ); + deployerProject( session.getProjectBuildingRequest() ); + getLog().info( "Bye bye from artifact-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 deployerProject( ProjectBuildingRequest pbr ) + throws MojoFailureException, MojoExecutionException + { + try + { + DefaultArtifactHandler artifactHandler = new DefaultArtifactHandler(); + artifactHandler.setExtension( "EXTENSION" ); + + File artifactsDirectory = + new File( session.getCurrentProject().getBuild().getDirectory(), "tests/artifacts" ); + getLog().info( "Directory: '" + artifactsDirectory.getAbsolutePath() + "'" ); + artifactsDirectory.mkdirs(); + + File tmpFile = File.createTempFile( "test-deploy", ".jar", artifactsDirectory ); + createFileContent( tmpFile ); + + DefaultArtifact artifact = new DefaultArtifact( "ARTIFACT-DEPLOYER-GROUPID-" + mvnVersion, "ARTIFACTID", "VERSION", + "compile", "jar", null, artifactHandler ); + artifact.setFile( tmpFile ); + artifact.setRepository( session.getProjectBuildingRequest().getLocalRepository() ); + + DefaultArtifact artifactWithClassifier = + new DefaultArtifact( "ARTIFACT-DEPLOYER-GROUPID-" + mvnVersion, "ARTIFACTID", "VERSION", "compile", "jar", + "CLASSIFIER", artifactHandler ); + File tmpFileClassifier = File.createTempFile( "test-deploy-classifier", ".jar", artifactsDirectory ); + createFileContent( tmpFileClassifier ); + artifactWithClassifier.setFile( tmpFileClassifier ); + artifactWithClassifier.setRepository( session.getProjectBuildingRequest().getLocalRepository() ); + + Collection<Artifact> mavenArtifacts = Arrays.<Artifact>asList( artifact, artifactWithClassifier ); + + deployer.deploy( session.getProjectBuildingRequest(), mavenArtifacts ); + } + catch ( ArtifactDeployerException e ) + { + throw new MojoExecutionException( "ArtifactDeployerException", e ); + } + catch ( IOException e ) + { + throw new MojoExecutionException( "IOException", e ); + } + } + +} diff --git a/src/it/maven-artifact-deployer-plugin/src/test/java/org/apache/maven/plugin/artifact/deployer/ArtifactDeployerTest.java b/src/it/maven-artifact-deployer-plugin/src/test/java/org/apache/maven/plugin/artifact/deployer/ArtifactDeployerTest.java new file mode 100644 index 0000000..ca7b8fb --- /dev/null +++ b/src/it/maven-artifact-deployer-plugin/src/test/java/org/apache/maven/plugin/artifact/deployer/ArtifactDeployerTest.java @@ -0,0 +1,120 @@ +package org.apache.maven.plugin.artifact.deployer; + +/* + * 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 ArtifactInstaller 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-artifact-deployer-plugin</code> which uses the + * ArtifactInstaller 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" } ) +public class ArtifactDeployerTest +{ + + @Rule + public final TestResources resources = new TestResources(); + + public final MavenRuntime mavenRuntime; + + public ArtifactDeployerTest( 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" ) + .execute( "clean", "verify" ); + //@formatter:on + + result.assertErrorFreeLog(); + // Check that the current plugins has been called at least once. + result.assertLogText( "[INFO] --- maven-artifact-deployer-plugin:1.0.0:artifact-deployer (id-artifact-deployer) @ maven-artifact-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 + "'" ); + + File baseDirectoy = new File( localRepo, "ARTIFACT-DEPLOYER-GROUPID-" + mvnVersion + "/ARTIFACTID/VERSION/" ); + + checkForArtifactFile( baseDirectoy ); + checkForArtifactClassifierFile( baseDirectoy ); + + assertTrue( new File( localRepo, + "ARTIFACT-DEPLOYER-GROUPID-" + mvnVersion + "/ARTIFACTID/maven-metadata-local.xml" ).exists() ); // ?? + + } + + private void checkForArtifactClassifierFile( File baseDirectoy ) + { + File artifactClassifierFile = new File( baseDirectoy, "ARTIFACTID-VERSION-CLASSIFIER.EXTENSION" ); + assertTrue( "artifactClassifierFile '" + artifactClassifierFile.getAbsolutePath() + "'", + artifactClassifierFile.exists() ); + assertTrue( "artifactClassifierFile md5 not found.", + new File( artifactClassifierFile.getAbsolutePath() + ".md5" ).exists() ); + assertTrue( "artifactClassifierFile sha1 not found.", + new File( artifactClassifierFile.getAbsolutePath() + ".sha1" ).exists() ); + } + + private void checkForArtifactFile( File baseDirectoy ) + { + File artifactFile = new File( baseDirectoy, "ARTIFACTID-VERSION.EXTENSION" ); + assertTrue( "artifactFile '" + artifactFile.getAbsolutePath() + "'", artifactFile.exists() ); + assertTrue( "artifactFile md5 not found.", new File( artifactFile.getAbsolutePath() + ".md5" ).exists() ); + assertTrue( "artifactFile sha1 not found.", new File( artifactFile.getAbsolutePath() + ".sha1" ).exists() ); + } +} \ No newline at end of file diff --git a/src/it/maven-artifact-deployer-plugin/src/test/projects/example/pom.xml b/src/it/maven-artifact-deployer-plugin/src/test/projects/example/pom.xml new file mode 100644 index 0000000..f4f14c9 --- /dev/null +++ b/src/it/maven-artifact-deployer-plugin/src/test/projects/example/pom.xml @@ -0,0 +1,67 @@ +<?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> + + <artifactId>maven-artifact-deployer-plugin-it</artifactId> + <version>1.0.0-A</version> + + <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-artifact-deployer-plugin</artifactId> + <version>${it-plugin.version}</version> + <configuration> + <localRepositoryPath>${localRepositoryPath}</localRepositoryPath> + <mvnVersion>${mvnVersion}</mvnVersion> + </configuration> + <executions> + <execution> + <id>id-artifact-deployer</id> + <goals> + <goal>artifact-deployer</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> diff --git a/src/it/maven-artifact-installer-plugin/pom.xml b/src/it/maven-artifact-installer-plugin/pom.xml new file mode 100644 index 0000000..32e88fd --- /dev/null +++ b/src/it/maven-artifact-installer-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-artifact-installer-plugin</artifactId> + <version>1.0.0</version> + <packaging>maven-plugin</packaging> + + <name>Apache Maven Artifact Installer 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 ArtifactInstaller</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-artifact-installer-plugin/src/main/java/org/apache/maven/plugin/artifact/installer/ArtifactInstallerMojo.java b/src/it/maven-artifact-installer-plugin/src/main/java/org/apache/maven/plugin/artifact/installer/ArtifactInstallerMojo.java new file mode 100644 index 0000000..8bc83ad --- /dev/null +++ b/src/it/maven-artifact-installer-plugin/src/main/java/org/apache/maven/plugin/artifact/installer/ArtifactInstallerMojo.java @@ -0,0 +1,128 @@ +package org.apache.maven.plugin.artifact.installer; + +/* + * 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.Collection; +import java.util.List; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.DefaultArtifact; +import org.apache.maven.artifact.handler.DefaultArtifactHandler; +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.ProjectBuildingRequest; +import org.apache.maven.shared.artifact.install.ArtifactInstaller; +import org.apache.maven.shared.artifact.install.ArtifactInstallerException; +import org.apache.maven.shared.repository.RepositoryManager; + +/** + * This mojo is implemented to test the ArtifactInstaller part of the maven-artifact-transfer shared component. + */ +@Mojo( name = "artifact-installer", defaultPhase = LifecyclePhase.VERIFY, threadSafe = true ) +public class ArtifactInstallerMojo + 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 ArtifactInstaller installer; + + public void execute() + throws MojoExecutionException, MojoFailureException + { + getLog().info( "Hello from artifact-installer plugin" ); + installProject( session.getProjectBuildingRequest() ); + getLog().info( "Bye bye from artifact-installer 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 + { + DefaultArtifactHandler artifactHandler = new DefaultArtifactHandler(); + artifactHandler.setExtension( "EXTENSION" ); + + File artifactsDirectory = + new File( session.getCurrentProject().getBuild().getDirectory(), "tests/artifacts" ); + getLog().info( "Directory: '" + artifactsDirectory.getAbsolutePath() + "'" ); + artifactsDirectory.mkdirs(); + + File tmpFile = File.createTempFile( "test-install", ".jar", artifactsDirectory ); + createFileContent( tmpFile ); + + DefaultArtifact artifact = new DefaultArtifact( "ARTIFACT-INSTALLER-GROUPID-" + mvnVersion, "ARTIFACTID", "VERSION", "compile", + "jar", null, artifactHandler ); + artifact.setFile( tmpFile ); + DefaultArtifact artifactWithClassifier = + new DefaultArtifact( "ARTIFACT-INSTALLER-GROUPID-" + mvnVersion, "ARTIFACTID", "VERSION", "compile", "jar", "CLASSIFIER", + artifactHandler ); + + File tmpFileClassifier = File.createTempFile( "test-install-classifier", ".jar", artifactsDirectory ); + createFileContent( tmpFileClassifier ); + artifactWithClassifier.setFile( tmpFileClassifier ); + + Collection<Artifact> mavenArtifacts = Arrays.<Artifact>asList( artifact, artifactWithClassifier ); + + installer.install( session.getProjectBuildingRequest(), mavenArtifacts ); + } + catch ( ArtifactInstallerException e ) + { + throw new MojoExecutionException( "ArtifactInstallerException", e ); + } + catch ( IOException e ) + { + throw new MojoExecutionException( "IOException", e ); + } + + } + +} diff --git a/src/it/maven-artifact-installer-plugin/src/test/java/org/apache/maven/plugin/artifact/installer/ArtifactInstallerTest.java b/src/it/maven-artifact-installer-plugin/src/test/java/org/apache/maven/plugin/artifact/installer/ArtifactInstallerTest.java new file mode 100644 index 0000000..fc43dee --- /dev/null +++ b/src/it/maven-artifact-installer-plugin/src/test/java/org/apache/maven/plugin/artifact/installer/ArtifactInstallerTest.java @@ -0,0 +1,127 @@ +package org.apache.maven.plugin.artifact.installer; + +/* + * 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.assertFalse; +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 ArtifactInstaller 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-artifact-installer-plugin</code> which uses the + * ArtifactInstaller 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 ArtifactInstallerTest +{ + + @Rule + public final TestResources resources = new TestResources(); + + public final MavenRuntime mavenRuntime; + + public ArtifactInstallerTest( 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" ) + .execute( "clean", "verify" ); + //@formatter:on + + result.assertErrorFreeLog(); + // Check that the current plugins has been called at least once. + result.assertLogText( "[INFO] --- maven-artifact-installer-plugin:1.0.0:artifact-installer (id-artifact-installer) @ maven-artifact-installer-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 + "'" ); + + File baseDirectoy = new File( localRepo, "ARTIFACT-INSTALLER-GROUPID-" + mvnVersion + "/ARTIFACTID/VERSION/" ); + + // We don't have a pom file. + checkForNonExistingPomFile( baseDirectoy ); + checkForArtifact( baseDirectoy ); + checkForArtifactClassifier( baseDirectoy ); + } + + private void checkForArtifactClassifier( File baseDirectoy ) + { + File jarArtifactClassifierFile = new File( baseDirectoy, "ARTIFACTID-VERSION-CLASSIFIER.EXTENSION" ); + assertTrue( "jarClassifierFile '" + jarArtifactClassifierFile.getAbsolutePath() + "'", + jarArtifactClassifierFile.exists() ); + assertFalse( "jarClassifier md5 not found.", + new File( jarArtifactClassifierFile.getAbsolutePath() + ".md5" ).exists() ); + assertFalse( "jarClassifier sha1 not found.", + new File( jarArtifactClassifierFile.getAbsolutePath() + ".sha1" ).exists() ); + } + + private void checkForArtifact( File baseDirectoy ) + { + File artifactFile = new File( baseDirectoy, "ARTIFACTID-VERSION.EXTENSION" ); + assertTrue( "artifactFile '" + artifactFile.getAbsolutePath() + "'", artifactFile.exists() ); + assertFalse( "artifactFile md5 not found.", new File( artifactFile.getAbsolutePath() + ".md5" ).exists() ); + assertFalse( "artifactFile sha1 not found.", new File( artifactFile.getAbsolutePath() + ".sha1" ).exists() ); + } + + private void checkForNonExistingPomFile( File baseDirectoy ) + { + File pomFile = new File( baseDirectoy, "ARTIFACTID-VERSION.EXTENSION.pom" ); + assertFalse( "pomFile '" + pomFile.getAbsolutePath() + "'", pomFile.exists() ); + assertFalse( "pom md5 not found.", new File( pomFile.getAbsolutePath() + ".md5" ).exists() ); + assertFalse( "pom sha1 not found.", new File( pomFile.getAbsolutePath() + ".sha1" ).exists() ); + } +} \ No newline at end of file diff --git a/src/it/maven-artifact-installer-plugin/src/test/projects/example/pom.xml b/src/it/maven-artifact-installer-plugin/src/test/projects/example/pom.xml new file mode 100644 index 0000000..3332df5 --- /dev/null +++ b/src/it/maven-artifact-installer-plugin/src/test/projects/example/pom.xml @@ -0,0 +1,67 @@ +<?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> + + <artifactId>maven-artifact-installer-plugin-it</artifactId> + <version>1.0.0-A</version> + + <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-artifact-installer-plugin</artifactId> + <version>${it-plugin.version}</version> + <configuration> + <localRepositoryPath>${localRepositoryPath}</localRepositoryPath> + <mvnVersion>${mvnVersion}</mvnVersion> + </configuration> + <executions> + <execution> + <id>id-artifact-installer</id> + <goals> + <goal>artifact-installer</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> 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..b0913e1 --- /dev/null +++ b/src/it/maven-project-deployer-plugin/src/test/projects/example/pom.xml @@ -0,0 +1,77 @@ +<?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 simpler way to express this. + --> + <url>file:///${maven.repo.local}/../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> diff --git a/src/it/maven-project-installer-plugin/pom.xml b/src/it/maven-project-installer-plugin/pom.xml new file mode 100644 index 0000000..3d83a97 --- /dev/null +++ b/src/it/maven-project-installer-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-installer-plugin</artifactId> + <version>1.0.0</version> + <packaging>maven-plugin</packaging> + + <name>Apache Maven Project Installer 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 ProjectInstaller</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-installer-plugin/src/main/java/org/apache/maven/plugin/project/install/ProjectInstallerMojo.java b/src/it/maven-project-installer-plugin/src/main/java/org/apache/maven/plugin/project/install/ProjectInstallerMojo.java new file mode 100644 index 0000000..24a57be --- /dev/null +++ b/src/it/maven-project-installer-plugin/src/main/java/org/apache/maven/plugin/project/install/ProjectInstallerMojo.java @@ -0,0 +1,129 @@ +package org.apache.maven.plugin.project.install; + +/* + * 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.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.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; +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-installer", defaultPhase = LifecyclePhase.VERIFY, threadSafe = true ) +public class ProjectInstallerMojo + 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 ProjectInstaller installer; + + @Component + private MavenProjectHelper projectHelper; + + public void execute() + throws MojoExecutionException, MojoFailureException + { + getLog().info( "Hello from project-installer plugin" ); + installProject( session.getProjectBuildingRequest() ); + getLog().info( "Bye bye from project-installer 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-install", ".jar", artifactsDirectory ); + createFileContent( tmpFile ); + + File tmpFileClassifier = File.createTempFile( "project-install-classifier", ".jar", artifactsDirectory ); + createFileContent( tmpFileClassifier ); + + projectHelper.attachArtifact( session.getCurrentProject(), "jar", "classifier", tmpFileClassifier ); + session.getCurrentProject().getArtifact().setFile( tmpFile ); + + ProjectInstallerRequest pir = new ProjectInstallerRequest(); + pir.setCreateChecksum( true ); + pir.setProject( session.getCurrentProject()); + installer.install( pbr, pir ); + } + catch ( ArtifactInstallerException e ) + { + throw new MojoExecutionException( "ArtifactInstallerException", e ); + } + catch ( IOException e ) + { + throw new MojoExecutionException( "IOException", e ); + } + catch ( NoFileAssignedException e ) + { + throw new MojoExecutionException( "NoFileAssignedException", e ); + } + + } + +} diff --git a/src/it/maven-project-installer-plugin/src/test/java/org/apache/maven/plugin/project/install/ProjectInstallerTest.java b/src/it/maven-project-installer-plugin/src/test/java/org/apache/maven/plugin/project/install/ProjectInstallerTest.java new file mode 100644 index 0000000..ea79c29 --- /dev/null +++ b/src/it/maven-project-installer-plugin/src/test/java/org/apache/maven/plugin/project/install/ProjectInstallerTest.java @@ -0,0 +1,129 @@ +package org.apache.maven.plugin.project.install; + +/* + * 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 ProjectInstaller 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-installer-plugin</code> which uses the ProjectInstaller 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 ProjectInstallerTest +{ + + @Rule + public final TestResources resources = new TestResources(); + + public final MavenRuntime mavenRuntime; + + public ProjectInstallerTest( 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-installer-plugin:1.0.0:project-installer (id-project-installer) @ maven-project-installer-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 + "'" ); + + File baseDirectoy = + new File( localRepo, + "PROJECT-INSTALLER-GROUPID-" + mvnVersion + "maven-project-installer-plugin-it/1.0.0-A/" ); + + checkForPomFile( baseDirectoy ); + + checkForJarFile( baseDirectoy ); + + checkForJarClassifierFile( baseDirectoy ); + + } + + private void checkForJarClassifierFile( File baseDirectoy ) + { + File jarClassifierFile = new File( baseDirectoy, "maven-project-installer-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-installer-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-installer-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-installer-plugin/src/test/projects/example/pom.xml b/src/it/maven-project-installer-plugin/src/test/projects/example/pom.xml new file mode 100644 index 0000000..3cff491 --- /dev/null +++ b/src/it/maven-project-installer-plugin/src/test/projects/example/pom.xml @@ -0,0 +1,68 @@ +<?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-INSTALLER-GROUPID-${mvnVersion}</groupId> + <artifactId>maven-project-installer-plugin-it</artifactId> + <version>1.0.0-A</version> + + <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-installer-plugin</artifactId> + <version>${it-plugin.version}</version> + <configuration> + <localRepositoryPath>${localRepositoryPath}</localRepositoryPath> + <mvnVersion>${mvnVersion}</mvnVersion> + </configuration> + <executions> + <execution> + <id>id-project-installer</id> + <goals> + <goal>project-installer</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> diff --git a/src/it/settings.xml b/src/it/settings.xml new file mode 100644 index 0000000..c8f77f0 --- /dev/null +++ b/src/it/settings.xml @@ -0,0 +1,55 @@ +<?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. +--> + +<settings> + <profiles> + <profile> + <id>it-repo</id> + <activation> + <activeByDefault>true</activeByDefault> + </activation> + <repositories> + <repository> + <id>local.central</id> + <url>@localRepositoryUrl@</url> + <releases> + <enabled>true</enabled> + </releases> + <snapshots> + <enabled>true</enabled> + </snapshots> + </repository> + </repositories> + <pluginRepositories> + <pluginRepository> + <id>local.central</id> + <url>@localRepositoryUrl@</url> + <releases> + <enabled>true</enabled> + </releases> + <snapshots> + <enabled>true</enabled> + </snapshots> + </pluginRepository> + </pluginRepositories> + </profile> + </profiles> +</settings> diff --git a/src/main/java/org/apache/maven/shared/artifact/deploy/ArtifactDeployerException.java b/src/main/java/org/apache/maven/shared/artifact/deploy/ArtifactDeployerException.java index b0dac8d..a66f6f0 100644 --- a/src/main/java/org/apache/maven/shared/artifact/deploy/ArtifactDeployerException.java +++ b/src/main/java/org/apache/maven/shared/artifact/deploy/ArtifactDeployerException.java @@ -20,6 +20,7 @@ package org.apache.maven.shared.artifact.deploy; */ /** + * An artifact could not correctly being deployed. * */ public class ArtifactDeployerException diff --git a/src/main/java/org/apache/maven/shared/artifact/install/ArtifactInstaller.java b/src/main/java/org/apache/maven/shared/artifact/install/ArtifactInstaller.java index f9cadf2..92c2973 100644 --- a/src/main/java/org/apache/maven/shared/artifact/install/ArtifactInstaller.java +++ b/src/main/java/org/apache/maven/shared/artifact/install/ArtifactInstaller.java @@ -33,14 +33,14 @@ public interface ArtifactInstaller /** * @param request {@link ProjectBuildingRequest} - * @param mavenArtifacts {@link Artifact} + * @param mavenArtifacts {@link Artifact} (no null or empty collection allowed.) * @throws ArtifactInstallerException in case of an error. - * @throws IllegalArgumentException in case of parameter <code>request</code> is <code>null</code> or parameter - * <code>mavenArtifacts</code> is <code>null</code> or <code>mavenArtifacts.isEmpty()</code> is - * <code>true</code>. + * @throws IllegalArgumentException in case <code>request</code> is <code>null</code>, <code>mavenArtifacts</code> + * is <code>null</code> or <code>mavenArtifacts</code> is empty (<code>mavenArtifacts.isEmpty()</code> + * == <code>true</code>). */ void install( ProjectBuildingRequest request, Collection<Artifact> mavenArtifacts ) - throws ArtifactInstallerException; + throws ArtifactInstallerException, IllegalArgumentException; /** * @param request {@link ProjectBuildingRequest}. diff --git a/src/main/java/org/apache/maven/shared/artifact/install/internal/DefaultArtifactInstaller.java b/src/main/java/org/apache/maven/shared/artifact/install/internal/DefaultArtifactInstaller.java index 9072fea..06ba7a8 100644 --- a/src/main/java/org/apache/maven/shared/artifact/install/internal/DefaultArtifactInstaller.java +++ b/src/main/java/org/apache/maven/shared/artifact/install/internal/DefaultArtifactInstaller.java @@ -49,7 +49,6 @@ class DefaultArtifactInstaller throws ArtifactInstallerException, IllegalArgumentException { validateParameters( request, mavenArtifacts ); - try { String hint = isMaven31() ? "maven31" : "maven3"; diff --git a/src/main/java/org/apache/maven/shared/artifact/install/internal/Maven31ArtifactInstaller.java b/src/main/java/org/apache/maven/shared/artifact/install/internal/Maven31ArtifactInstaller.java index f683baf..090a8a6 100644 --- a/src/main/java/org/apache/maven/shared/artifact/install/internal/Maven31ArtifactInstaller.java +++ b/src/main/java/org/apache/maven/shared/artifact/install/internal/Maven31ArtifactInstaller.java @@ -46,7 +46,6 @@ import org.eclipse.aether.util.artifact.SubArtifact; class Maven31ArtifactInstaller implements ArtifactInstaller { - @Requirement private RepositorySystem repositorySystem; diff --git a/src/main/java/org/apache/maven/shared/dependencies/collect/DependencyCollector.java b/src/main/java/org/apache/maven/shared/dependencies/collect/DependencyCollector.java index c7d6783..ce996ed 100644 --- a/src/main/java/org/apache/maven/shared/dependencies/collect/DependencyCollector.java +++ b/src/main/java/org/apache/maven/shared/dependencies/collect/DependencyCollector.java @@ -40,6 +40,8 @@ public interface DependencyCollector * @param root {@link Dependency} * @return {@link CollectorResult} * @throws DependencyCollectorException in case of an error. + * @throws IllegalArgumentException in case of parameter <code>buildingRequest</code> is <code>null</code> or + * parameter <code>root</code> is <code>null</code>. */ CollectorResult collectDependencies( ProjectBuildingRequest buildingRequest, Dependency root ) throws DependencyCollectorException; @@ -50,6 +52,8 @@ public interface DependencyCollector * @return {@link CollectorResult} * @throws DependencyCollectorException in case of an error which can be a component lookup error or * an error while trying to look up the dependencies. + * @throws IllegalArgumentException in case of parameter <code>buildingRequest</code> is <code>null</code> or + * parameter <code>root</code> is <code>null</code>. */ CollectorResult collectDependencies( ProjectBuildingRequest buildingRequest, DependableCoordinate root ) throws DependencyCollectorException; @@ -60,6 +64,8 @@ public interface DependencyCollector * @return {@link CollectorResult} * @throws DependencyCollectorException in case of an error which can be a component lookup error or * an error while trying to look up the dependencies. + * @throws IllegalArgumentException in case of parameter <code>buildingRequest</code> is <code>null</code> or + * parameter <code>root</code> is <code>null</code>. */ CollectorResult collectDependencies( ProjectBuildingRequest buildingRequest, Model root ) throws DependencyCollectorException; diff --git a/src/main/java/org/apache/maven/shared/dependencies/collect/internal/DefaultDependencyCollector.java b/src/main/java/org/apache/maven/shared/dependencies/collect/internal/DefaultDependencyCollector.java index c1cb5b1..26c7010 100644 --- a/src/main/java/org/apache/maven/shared/dependencies/collect/internal/DefaultDependencyCollector.java +++ b/src/main/java/org/apache/maven/shared/dependencies/collect/internal/DefaultDependencyCollector.java @@ -36,18 +36,20 @@ import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; /** * This DependencyCollector passes the request to the proper Maven 3.x implementation - * + * * @author Robert Scholte */ @Component( role = DependencyCollector.class, hint = "default" ) class DefaultDependencyCollector implements DependencyCollector, Contextualizable { private PlexusContainer container; - + @Override public CollectorResult collectDependencies( ProjectBuildingRequest buildingRequest, Dependency root ) throws DependencyCollectorException { + validateParameters( buildingRequest, root ); + try { String hint = isMaven31() ? "maven31" : "maven3"; @@ -61,11 +63,13 @@ class DefaultDependencyCollector implements DependencyCollector, Contextualizabl throw new DependencyCollectorException( e.getMessage(), e ); } } - + @Override public CollectorResult collectDependencies( ProjectBuildingRequest buildingRequest, DependableCoordinate root ) throws DependencyCollectorException { + validateParameters( buildingRequest, root ); + try { String hint = isMaven31() ? "maven31" : "maven3"; @@ -79,11 +83,13 @@ class DefaultDependencyCollector implements DependencyCollector, Contextualizabl throw new DependencyCollectorException( e.getMessage(), e ); } } - + @Override public CollectorResult collectDependencies( ProjectBuildingRequest buildingRequest, Model root ) throws DependencyCollectorException { + validateParameters( buildingRequest, root ); + try { String hint = isMaven31() ? "maven31" : "maven3"; @@ -98,6 +104,41 @@ class DefaultDependencyCollector implements DependencyCollector, Contextualizabl } } + private void validateParameters( ProjectBuildingRequest buildingRequest, DependableCoordinate root ) + { + validateBuildingRequest( buildingRequest ); + if ( root == null ) + { + throw new IllegalArgumentException( "The parameter root is not allowed to be null." ); + } + } + + private void validateParameters( ProjectBuildingRequest buildingRequest, Dependency root ) + { + validateBuildingRequest( buildingRequest ); + if ( root == null ) + { + throw new IllegalArgumentException( "The parameter root is not allowed to be null." ); + } + } + + private void validateParameters( ProjectBuildingRequest buildingRequest, Model root ) + { + validateBuildingRequest( buildingRequest ); + if ( root == null ) + { + throw new IllegalArgumentException( "The parameter root is not allowed to be null." ); + } + } + + private void validateBuildingRequest( ProjectBuildingRequest buildingRequest ) + { + if ( buildingRequest == null ) + { + throw new IllegalArgumentException( "The parameter buildingRequest is not allowed to be null." ); + } + } + /** * @return true if the current Maven version is Maven 3.1. */ diff --git a/src/main/java/org/apache/maven/shared/project/deploy/ProjectDeployer.java b/src/main/java/org/apache/maven/shared/project/deploy/ProjectDeployer.java index 2c4519b..b09adeb 100644 --- a/src/main/java/org/apache/maven/shared/project/deploy/ProjectDeployer.java +++ b/src/main/java/org/apache/maven/shared/project/deploy/ProjectDeployer.java @@ -21,6 +21,7 @@ package org.apache.maven.shared.project.deploy; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.project.ProjectBuildingRequest; +import org.apache.maven.shared.artifact.deploy.ArtifactDeployerException; import org.apache.maven.shared.project.NoFileAssignedException; /** @@ -55,11 +56,12 @@ public interface ProjectDeployer * @param request {@link ProjectDeployerRequest} * @param artifactRepository {@link ArtifactRepository} * @throws NoFileAssignedException In case of missing file which has not been assigned to project. - * @throws IllegalArgumentException in case of artifact is not correctly assigned. + * @throws ArtifactDeployerException in case of artifact could not correctly deployed. + * @throws IllegalArgumentException in case <code>buildingRequest</code> is <code>null</code>, <code>request</code> + * is <code>null</code> or <code>artifactRepository</code> is <code>null</code>. */ void deploy( ProjectBuildingRequest buildingRequest, ProjectDeployerRequest request, - ArtifactRepository artifactRepository ) - throws NoFileAssignedException, IllegalArgumentException; - + ArtifactRepository artifactRepository ) + throws NoFileAssignedException, ArtifactDeployerException; } diff --git a/src/main/java/org/apache/maven/shared/project/deploy/internal/DefaultProjectDeployer.java b/src/main/java/org/apache/maven/shared/project/deploy/internal/DefaultProjectDeployer.java index f000ddc..74049be 100644 --- a/src/main/java/org/apache/maven/shared/project/deploy/internal/DefaultProjectDeployer.java +++ b/src/main/java/org/apache/maven/shared/project/deploy/internal/DefaultProjectDeployer.java @@ -54,24 +54,19 @@ class DefaultProjectDeployer 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 ProjectDeployerRequest} - * @param artifactRepository {@link ArtifactRepository} - * @throws IllegalArgumentException in case of artifact is not correctly assigned. - * @throws NoFileAssignedException In case no file has been assigned to main file. + * {@inheritDoc} */ - public void deploy( ProjectBuildingRequest buildingRequest, ProjectDeployerRequest request, + public void deploy( ProjectBuildingRequest buildingRequest, ProjectDeployerRequest projectDeployerRequest, ArtifactRepository artifactRepository ) - throws NoFileAssignedException, IllegalArgumentException + throws NoFileAssignedException, IllegalArgumentException, ArtifactDeployerException { + validateParameters( buildingRequest, projectDeployerRequest, artifactRepository ); - Artifact artifact = request.getProject().getArtifact(); - String packaging = request.getProject().getPackaging(); - File pomFile = request.getProject().getFile(); + Artifact artifact = projectDeployerRequest.getProject().getArtifact(); + String packaging = projectDeployerRequest.getProject().getPackaging(); + File pomFile = projectDeployerRequest.getProject().getFile(); - List<Artifact> attachedArtifacts = request.getProject().getAttachedArtifacts(); + List<Artifact> attachedArtifacts = projectDeployerRequest.getProject().getAttachedArtifacts(); // Deploy the POM boolean isPomArtifact = "pom".equals( packaging ); @@ -85,54 +80,68 @@ class DefaultProjectDeployer artifact.addMetadata( metadata ); } - if ( request.isUpdateReleaseInfo() ) + // FIXME: It does not make sense to set an artifact explicitly to a "Release" + // cause this should be choosen only by the not existing of "-SNAPSHOT" in the + // version. + if ( projectDeployerRequest.isUpdateReleaseInfo() ) { artifact.setRelease( true ); } artifact.setRepository( artifactRepository ); - int retryFailedDeploymentCount = request.getRetryFailedDeploymentCount(); + int retryFailedDeploymentCount = projectDeployerRequest.getRetryFailedDeploymentCount(); - try + List<Artifact> deployableArtifacts = new ArrayList<Artifact>(); + if ( isPomArtifact ) + { + deployableArtifacts.add( artifact ); + } + else { - List<Artifact> deployableArtifacts = new ArrayList<Artifact>(); - if ( isPomArtifact ) + File file = artifact.getFile(); + + if ( file != null && file.isFile() ) { deployableArtifacts.add( artifact ); } - else + else if ( !attachedArtifacts.isEmpty() ) { - File file = artifact.getFile(); - - if ( file != null && file.isFile() ) - { - deployableArtifacts.add( artifact ); - } - else if ( !attachedArtifacts.isEmpty() ) - { - // TODO: Reconsider this exception? Better Exception type? - throw new NoFileAssignedException( "The packaging plugin for this project did not assign " - + "a main file to the project but it has attachments. Change packaging to 'pom'." ); - } - else - { - // TODO: Reconsider this exception? Better Exception type? - throw new NoFileAssignedException( "The packaging for this project did not assign " - + "a file to the build artifact" ); - } + // TODO: Reconsider this exception? Better Exception type? + throw new NoFileAssignedException( "The packaging plugin for this project did not assign " + + "a main file to the project but it has attachments. Change packaging to 'pom'." ); } - - for ( Artifact attached : attachedArtifacts ) + else { - deployableArtifacts.add( attached ); + // TODO: Reconsider this exception? Better Exception type? + throw new NoFileAssignedException( "The packaging for this project did not assign " + + "a file to the build artifact" ); } + } + + for ( Artifact attached : attachedArtifacts ) + { + deployableArtifacts.add( attached ); + } - deploy( buildingRequest, deployableArtifacts, artifactRepository, retryFailedDeploymentCount ); + deploy( buildingRequest, deployableArtifacts, artifactRepository, retryFailedDeploymentCount ); + } + + private void validateParameters( ProjectBuildingRequest buildingRequest, + ProjectDeployerRequest projectDeployerRequest, + ArtifactRepository artifactRepository ) + { + if ( buildingRequest == null ) + { + throw new IllegalArgumentException( "The parameter buildingRequest is not allowed to be null." ); + } + if ( projectDeployerRequest == null ) + { + throw new IllegalArgumentException( "The parameter projectDeployerRequest is not allowed to be null." ); } - catch ( ArtifactDeployerException e ) + if ( artifactRepository == null ) { - throw new IllegalArgumentException( e.getMessage(), e ); + throw new IllegalArgumentException( "The parameter artifactRepository is not allowed to be null." ); } } diff --git a/src/main/java/org/apache/maven/shared/project/install/ProjectInstaller.java b/src/main/java/org/apache/maven/shared/project/install/ProjectInstaller.java index 0ddc46c..0fab22e 100644 --- a/src/main/java/org/apache/maven/shared/project/install/ProjectInstaller.java +++ b/src/main/java/org/apache/maven/shared/project/install/ProjectInstaller.java @@ -54,15 +54,15 @@ public interface ProjectInstaller * installer.install( session.getProjectBuildingRequest(), pir ); * </pre> * - * To set a different local repository than the current one in the Maven session, you can inject an instance of - * the <code>RepositoryManager</code> and set the path to the local repository, called - * <code>localRepositoryPath</code>, as such: + * To set a different local repository than the current one in the Maven session, you can inject an instance of the + * <code>RepositoryManager</code> and set the path to the local repository, called <code>localRepositoryPath</code>, + * as such: * * <pre class="java"> - * @Component - * private RepositoryManager repositoryManager; + * @Component + * private RepositoryManager repositoryManager; * - * buildingRequest = repositoryManager.setLocalRepositoryBasedir( buildingRequest, localRepositoryPath ); + * buildingRequest = repositoryManager.setLocalRepositoryBasedir( buildingRequest, localRepositoryPath ); * </pre> * * @param projectBuildingRequest {@link ProjectBuildingRequest} @@ -74,6 +74,6 @@ public interface ProjectInstaller * parameter <code>projectInstallerRequest</code> is <code>null</code>. */ void install( ProjectBuildingRequest projectBuildingRequest, ProjectInstallerRequest projectInstallerRequest ) - throws IOException, ArtifactInstallerException, NoFileAssignedException, IllegalArgumentException; + throws IOException, ArtifactInstallerException, NoFileAssignedException; } diff --git a/src/main/java/org/apache/maven/shared/project/install/internal/DefaultProjectInstaller.java b/src/main/java/org/apache/maven/shared/project/install/internal/DefaultProjectInstaller.java index 59664e3..8d643c3 100644 --- a/src/main/java/org/apache/maven/shared/project/install/internal/DefaultProjectInstaller.java +++ b/src/main/java/org/apache/maven/shared/project/install/internal/DefaultProjectInstaller.java @@ -71,7 +71,6 @@ class DefaultProjectInstaller public void install( ProjectBuildingRequest buildingRequest, ProjectInstallerRequest installerRequest ) throws IOException, ArtifactInstallerException, NoFileAssignedException, IllegalArgumentException { - validateParameters( buildingRequest, installerRequest ); MavenProject project = installerRequest.getProject(); boolean createChecksum = installerRequest.isCreateChecksum(); @@ -157,7 +156,7 @@ class DefaultProjectInstaller throw new IllegalArgumentException( "The parameter installerRequest is not allowed to be null." ); } } - + /** * Installs the checksums for the specified artifact if this has been enabled in the plugin configuration. This * method creates checksums for files that have already been installed to the local repo to account for on-the-fly diff --git a/src/site/apt/install-project.apt b/src/site/apt/deploy-project.apt similarity index 70% copy from src/site/apt/install-project.apt copy to src/site/apt/deploy-project.apt index eb07a08..eb3e81d 100644 --- a/src/site/apt/install-project.apt +++ b/src/site/apt/deploy-project.apt @@ -1,9 +1,9 @@ ----- - Install Project + Deploy Project ----- Karl Heinz Marbaise ----- - 2017-05-07 + 2017-08-20 ----- ~~ Licensed to the Apache Software Foundation (ASF) under one @@ -26,10 +26,10 @@ ~~ NOTE: For help with the syntax of this file, see: ~~ http://maven.apache.org/doxia/references/apt-format.html -Install a Project +Deploy a Project - If you are developing a maven plugin you need often to install artifacts - into the local repository which is a little bit cumbersome. This can be easily + If you are developing a maven plugin you need often to deploy a whole project + into a repository which is a little bit cumbersome. This can be easily done via the following code parts. +--- @@ -39,15 +39,16 @@ Install a Project private MavenProject project; @Component - private ProjectInstaller installer; + private ProjectDeployer deployer; ... public void execute() { - ProjectInstallerRequest pir = - new ProjectInstallerRequest() - .setProject( project ).setUpdateReleaseInfo( updateReleaseInfo ); + ProjectDeployerRequest pir = + new ProjectDeployerRequest() + //TODO: Think about setUpdateReleaseInfo().. + .setProject( project ).setUpdateReleaseInfo( true ); - installer.install( session.getProjectBuildingRequest(), pir ); + deployer.deploy( session.getProjectBuildingRequest(), pir ); ... } diff --git a/src/site/apt/install-project.apt b/src/site/apt/install-project.apt index eb07a08..3d02631 100644 --- a/src/site/apt/install-project.apt +++ b/src/site/apt/install-project.apt @@ -28,9 +28,9 @@ Install a Project - If you are developing a maven plugin you need often to install artifacts - into the local repository which is a little bit cumbersome. This can be easily - done via the following code parts. + If you are developing a maven plugin or other components related to Maven you need + often to install artifacts into the local repository which is a little bit cumbersome. + This can be easily done via the following code parts. +--- @Parameter ( defaultValue = "${session}", required = true, readonly = true) @@ -45,8 +45,9 @@ Install a Project ProjectInstallerRequest pir = new ProjectInstallerRequest() + //TODO: THink about setUpdateReleaseInfo().. .setProject( project ).setUpdateReleaseInfo( updateReleaseInfo ); - + installer.install( session.getProjectBuildingRequest(), pir ); ... } diff --git a/src/test/java/org/apache/maven/shared/artifact/deploy/internal/DefaultArtifactDeployerTest.java b/src/test/java/org/apache/maven/shared/artifact/deploy/internal/DefaultArtifactDeployerTest.java index cfd9587..5e17f60 100644 --- a/src/test/java/org/apache/maven/shared/artifact/deploy/internal/DefaultArtifactDeployerTest.java +++ b/src/test/java/org/apache/maven/shared/artifact/deploy/internal/DefaultArtifactDeployerTest.java @@ -64,9 +64,10 @@ public class DefaultArtifactDeployerTest public void deployShouldReturnIllegalArgumentExceptionForSecondParameterWithNull() throws ArtifactDeployerException { + ProjectBuildingRequest pbr = mock( ProjectBuildingRequest.class ); + thrown.expect( IllegalArgumentException.class ); thrown.expectMessage( "The parameter mavenArtifacts is not allowed to be null." ); - ProjectBuildingRequest pbr = mock( ProjectBuildingRequest.class ); dap.deploy( pbr, null ); } @@ -74,9 +75,10 @@ public class DefaultArtifactDeployerTest public void deployShouldReturnIllegalArgumentExceptionForSecondParameterWithEmpty() throws ArtifactDeployerException { + ProjectBuildingRequest pbr = mock( ProjectBuildingRequest.class ); + thrown.expect( IllegalArgumentException.class ); thrown.expectMessage( "The collection mavenArtifacts is not allowed to be empty." ); - ProjectBuildingRequest pbr = mock( ProjectBuildingRequest.class ); dap.deploy( pbr, Collections.<Artifact>emptyList() ); } @@ -94,9 +96,10 @@ public class DefaultArtifactDeployerTest public void deploy3ParametersShouldReturnIllegalArgumentExceptionForSecondParameterWithNull() throws ArtifactDeployerException { + ProjectBuildingRequest pbr = mock( ProjectBuildingRequest.class ); + thrown.expect( IllegalArgumentException.class ); thrown.expectMessage( "The parameter mavenArtifacts is not allowed to be null." ); - ProjectBuildingRequest pbr = mock( ProjectBuildingRequest.class ); dap.deploy( pbr, null, null ); } @@ -104,9 +107,10 @@ public class DefaultArtifactDeployerTest public void deploy3ParametersShouldReturnIllegalArgumentExceptionForSecondParameterWithEmpty() throws ArtifactDeployerException { + ProjectBuildingRequest pbr = mock( ProjectBuildingRequest.class ); + thrown.expect( IllegalArgumentException.class ); thrown.expectMessage( "The collection mavenArtifacts is not allowed to be empty." ); - ProjectBuildingRequest pbr = mock( ProjectBuildingRequest.class ); dap.deploy( pbr, null, Collections.<Artifact>emptyList() ); } diff --git a/src/test/java/org/apache/maven/shared/artifact/install/internal/DefaultArtifactInstallerTest.java b/src/test/java/org/apache/maven/shared/artifact/install/internal/DefaultArtifactInstallerTest.java index 144f33f..d26ed01 100644 --- a/src/test/java/org/apache/maven/shared/artifact/install/internal/DefaultArtifactInstallerTest.java +++ b/src/test/java/org/apache/maven/shared/artifact/install/internal/DefaultArtifactInstallerTest.java @@ -45,8 +45,7 @@ public class DefaultArtifactInstallerTest public ExpectedException thrown = ExpectedException.none(); @Test - public void installShouldReturnIllegalArgumentExceptionForFirstParameterWithNull() - throws ArtifactInstallerException + public void installShouldReturnIllegalArgumentExceptionForFirstParameterWithNull() throws IllegalArgumentException, ArtifactInstallerException { DefaultArtifactInstaller dai = new DefaultArtifactInstaller(); diff --git a/src/test/java/org/apache/maven/shared/dependencies/collect/internal/DefaultDependencyCollectorTest.java b/src/test/java/org/apache/maven/shared/dependencies/collect/internal/DefaultDependencyCollectorTest.java new file mode 100644 index 0000000..5e48299 --- /dev/null +++ b/src/test/java/org/apache/maven/shared/dependencies/collect/internal/DefaultDependencyCollectorTest.java @@ -0,0 +1,115 @@ +package org.apache.maven.shared.dependencies.collect.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 static org.mockito.Mockito.mock; + +import org.apache.maven.model.Dependency; +import org.apache.maven.model.Model; +import org.apache.maven.project.ProjectBuildingRequest; +import org.apache.maven.shared.artifact.deploy.ArtifactDeployerException; +import org.apache.maven.shared.artifact.resolve.ArtifactResolverException; +import org.apache.maven.shared.dependencies.DependableCoordinate; +import org.apache.maven.shared.dependencies.collect.DependencyCollector; +import org.apache.maven.shared.dependencies.collect.DependencyCollectorException; +import org.apache.maven.shared.dependencies.collect.internal.DefaultDependencyCollector; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +public class DefaultDependencyCollectorTest +{ + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + private DependencyCollector dc; + + @Before + public void setUp() + { + dc = new DefaultDependencyCollector(); + } + + @Test + public void collectDependenciesWithDependableCoordinatShouldFailWithIAEWhenParameterBuildingRequestIsNull() + throws ArtifactDeployerException, ArtifactResolverException, DependencyCollectorException + { + thrown.expect( IllegalArgumentException.class ); + thrown.expectMessage( "The parameter buildingRequest is not allowed to be null." ); + + dc.collectDependencies( null, (DependableCoordinate) null ); + } + + @Test + public void collectDependenciesWithDependableCoordinatShouldFailWithIAEWhenParameterRootIsNull() + throws ArtifactDeployerException, ArtifactResolverException, DependencyCollectorException + { + thrown.expect( IllegalArgumentException.class ); + thrown.expectMessage( "The parameter root is not allowed to be null." ); + + ProjectBuildingRequest request = mock( ProjectBuildingRequest.class ); + dc.collectDependencies( request, (DependableCoordinate) null ); + } + + @Test + public void collectDependenciesWithDependencyShouldFailWithIAEWhenParameterBuildingRequestIsNull() + throws ArtifactDeployerException, ArtifactResolverException, DependencyCollectorException + { + thrown.expect( IllegalArgumentException.class ); + thrown.expectMessage( "The parameter buildingRequest is not allowed to be null." ); + + dc.collectDependencies( null, (Dependency) null ); + } + + @Test + public void collectDependenciesWithDependencyShouldFailWithIAEWhenParameterRootIsNull() + throws ArtifactDeployerException, ArtifactResolverException, DependencyCollectorException + { + thrown.expect( IllegalArgumentException.class ); + thrown.expectMessage( "The parameter root is not allowed to be null." ); + + ProjectBuildingRequest request = mock( ProjectBuildingRequest.class ); + dc.collectDependencies( request, (Dependency) null ); + } + + @Test + public void collectDependenciesWithModelShouldFailWithIAEWhenParameterBuildingRequestIsNull() + throws ArtifactDeployerException, ArtifactResolverException, DependencyCollectorException + { + thrown.expect( IllegalArgumentException.class ); + thrown.expectMessage( "The parameter buildingRequest is not allowed to be null." ); + + dc.collectDependencies( null, (Model) null ); + } + + @Test + public void collectDependenciesWithModelShouldFailWithIAEWhenParameterRootIsNull() + throws ArtifactDeployerException, ArtifactResolverException, DependencyCollectorException + { + thrown.expect( IllegalArgumentException.class ); + thrown.expectMessage( "The parameter root is not allowed to be null." ); + + ProjectBuildingRequest request = mock( ProjectBuildingRequest.class ); + dc.collectDependencies( request, (Model) null ); + } + +} diff --git a/src/test/java/org/apache/maven/shared/dependency/DefaultDependencyCoordinateTest.java b/src/test/java/org/apache/maven/shared/dependency/DefaultDependencyCoordinateTest.java index a52d055..f3d00ea 100644 --- a/src/test/java/org/apache/maven/shared/dependency/DefaultDependencyCoordinateTest.java +++ b/src/test/java/org/apache/maven/shared/dependency/DefaultDependencyCoordinateTest.java @@ -18,6 +18,7 @@ package org.apache.maven.shared.dependency; * specific language governing permissions and limitations * under the License. */ + import static org.junit.Assert.assertEquals; import org.apache.maven.shared.dependencies.DefaultDependableCoordinate; diff --git a/src/test/java/org/apache/maven/shared/project/deploy/internal/DefaultProjectDeployerTest.java b/src/test/java/org/apache/maven/shared/project/deploy/internal/DefaultProjectDeployerTest.java new file mode 100644 index 0000000..2d54a24 --- /dev/null +++ b/src/test/java/org/apache/maven/shared/project/deploy/internal/DefaultProjectDeployerTest.java @@ -0,0 +1,82 @@ +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 static org.mockito.Mockito.mock; + +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.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +/** + * Check the parameter contracts which have been made based on the interface {@link ProjectDeployer}. + * + * @author Karl Heinz Marbaise <a href="mailto:khmarba...@apache.org">khmaba...@apache.org</a> + */ +public class DefaultProjectDeployerTest +{ + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + @Test + public void deployShouldFailWithIAEWhileBuildingRequestIsNull() + throws IllegalArgumentException, NoFileAssignedException, ArtifactDeployerException + { + ProjectDeployer dpi = new DefaultProjectDeployer(); + + expectedException.expect( IllegalArgumentException.class ); + expectedException.expectMessage( "The parameter buildingRequest is not allowed to be null." ); + + dpi.deploy( null, null, null ); + } + + @Test + public void deployShouldFailWithIAEWhileProjectDeployerRequestIsNull() + throws IllegalArgumentException, NoFileAssignedException, ArtifactDeployerException + { + ProjectDeployer dpi = new DefaultProjectDeployer(); + + expectedException.expect( IllegalArgumentException.class ); + expectedException.expectMessage( "The parameter projectDeployerRequest is not allowed to be null." ); + + ProjectBuildingRequest pbr = mock( ProjectBuildingRequest.class ); + dpi.deploy( pbr, null, null ); + } + + @Test + public void deployShouldFailWithIAEWhileArtifactRepositoryIsNull() + throws IllegalArgumentException, NoFileAssignedException, ArtifactDeployerException + { + ProjectDeployer dpi = new DefaultProjectDeployer(); + + expectedException.expect( IllegalArgumentException.class ); + expectedException.expectMessage( "The parameter artifactRepository is not allowed to be null." ); + + ProjectBuildingRequest pbr = mock( ProjectBuildingRequest.class ); + ProjectDeployerRequest pdr = mock( ProjectDeployerRequest.class ); + dpi.deploy( pbr, pdr, null ); + } + +} diff --git a/src/test/java/org/apache/maven/shared/project/install/internal/DefaultProjectInstallerTest.java b/src/test/java/org/apache/maven/shared/project/install/internal/DefaultProjectInstallerTest.java index 7d1cc8e..f5d65a3 100644 --- a/src/test/java/org/apache/maven/shared/project/install/internal/DefaultProjectInstallerTest.java +++ b/src/test/java/org/apache/maven/shared/project/install/internal/DefaultProjectInstallerTest.java @@ -38,32 +38,33 @@ import org.junit.rules.ExpectedException; */ public class DefaultProjectInstallerTest { + @Rule - public ExpectedException thrown = ExpectedException.none(); + public ExpectedException expectedException = ExpectedException.none(); @Test - public void installShouldReturnIllegalArgumentExceptionWhereBuildingRequestIsNull() + public void installShouldFailWithIAEWhileBuildingRequestIsNull() throws IOException, ArtifactInstallerException, NoFileAssignedException { - DefaultProjectInstaller dai = new DefaultProjectInstaller(); + ProjectInstaller dpi = new DefaultProjectInstaller(); + + expectedException.expect( IllegalArgumentException.class ); + expectedException.expectMessage( "The parameter buildingRequest is not allowed to be null." ); - thrown.expect( IllegalArgumentException.class ); - thrown.expectMessage( "The parameter buildingRequest is not allowed to be null." ); - dai.install( null, null ); + dpi.install( null, null ); } @Test - public void installShouldReturnIllegalArgumentExceptionWhereInstallerRequestIsNull() + public void installShouldFailWithIAEWhileProjectInstallerRequestIsNull() throws IOException, ArtifactInstallerException, NoFileAssignedException { - DefaultProjectInstaller dai = new DefaultProjectInstaller(); + ProjectInstaller dpi = new DefaultProjectInstaller(); - thrown.expect( IllegalArgumentException.class ); - thrown.expectMessage( "The parameter installerRequest is not allowed to be null." ); + expectedException.expect( IllegalArgumentException.class ); + expectedException.expectMessage( "The parameter installerRequest is not allowed to be null." ); ProjectBuildingRequest pbr = mock( ProjectBuildingRequest.class ); - dai.install( pbr, null ); - } - + dpi.install( pbr, null ); + } } -- To stop receiving notification emails like this one, please contact khmarba...@apache.org.