You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sj...@apache.org on 2023/01/21 15:53:12 UTC
[maven-deploy-plugin] 02/02: [MDEPLOY-302] Upgrade maven-plugin parent to 39 - reformat
This is an automated email from the ASF dual-hosted git repository.
sjaranowski pushed a commit to branch MDEPLOY-302
in repository https://gitbox.apache.org/repos/asf/maven-deploy-plugin.git
commit bf01bf5fd777ffafb703a2a8af38d9e309c3e56a
Author: Slawomir Jaranowski <s....@gmail.com>
AuthorDate: Sat Jan 21 16:52:39 2023 +0100
[MDEPLOY-302] Upgrade maven-plugin parent to 39 - reformat
---
pom.xml | 22 +-
.../maven/plugins/deploy/AbstractDeployMojo.java | 120 +--
.../maven/plugins/deploy/DeployFileMojo.java | 529 ++++------
.../apache/maven/plugins/deploy/DeployMojo.java | 352 +++----
.../maven/plugins/deploy/DeployFileMojoTest.java | 325 +++----
.../plugins/deploy/DeployFileMojoUnitTest.java | 128 ++-
.../maven/plugins/deploy/DeployMojoTest.java | 1011 ++++++++++----------
.../org/apache/maven/plugins/deploy/Utils.java | 27 +-
.../deploy/stubs/ArtifactRepositoryStub.java | 145 ++-
.../deploy/stubs/ArtifactRepositoryStub2.java | 46 +-
.../plugins/deploy/stubs/AttachedArtifactStub.java | 26 +-
.../plugins/deploy/stubs/DeployArtifactStub.java | 97 +-
.../plugins/deploy/stubs/MavenProjectStub.java | 13 +-
13 files changed, 1255 insertions(+), 1586 deletions(-)
diff --git a/pom.xml b/pom.xml
index b261827..5c30c55 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,5 +1,4 @@
-<?xml version='1.0' encoding='UTF-8'?>
-
+<?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
@@ -18,7 +17,6 @@ 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>
@@ -37,6 +35,13 @@ under the License.
<description>Uploads the project artifacts to the internal remote repository.</description>
<inceptionYear>2004</inceptionYear>
+ <contributors>
+ <!-- alphabetic order -->
+ <contributor>
+ <name>Hermann Josef Hill</name>
+ </contributor>
+ </contributors>
+
<prerequisites>
<maven>${mavenVersion}</maven>
</prerequisites>
@@ -44,8 +49,8 @@ under the License.
<scm>
<connection>scm:git:https://gitbox.apache.org/repos/asf/maven-deploy-plugin.git</connection>
<developerConnection>scm:git:https://gitbox.apache.org/repos/asf/maven-deploy-plugin.git</developerConnection>
- <url>https://github.com/apache/maven-deploy-plugin/tree/${project.scm.tag}</url>
<tag>HEAD</tag>
+ <url>https://github.com/apache/maven-deploy-plugin/tree/${project.scm.tag}</url>
</scm>
<issueManagement>
<system>JIRA</system>
@@ -185,15 +190,8 @@ under the License.
<version>${slf4jVersion}</version>
<scope>test</scope>
</dependency>
-
- </dependencies>
- <contributors>
- <!-- alphabetic order -->
- <contributor>
- <name>Hermann Josef Hill</name>
- </contributor>
- </contributors>
+ </dependencies>
<profiles>
<profile>
diff --git a/src/main/java/org/apache/maven/plugins/deploy/AbstractDeployMojo.java b/src/main/java/org/apache/maven/plugins/deploy/AbstractDeployMojo.java
index 4a66ecd..33ecad0 100644
--- a/src/main/java/org/apache/maven/plugins/deploy/AbstractDeployMojo.java
+++ b/src/main/java/org/apache/maven/plugins/deploy/AbstractDeployMojo.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.deploy;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@ package org.apache.maven.plugins.deploy;
* "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
+ * 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
@@ -18,6 +16,7 @@ package org.apache.maven.plugins.deploy;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.deploy;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
@@ -38,13 +37,11 @@ import org.eclipse.aether.version.Version;
/**
* Abstract class for Deploy mojo's.
*/
-public abstract class AbstractDeployMojo
- extends AbstractMojo
-{
+public abstract class AbstractDeployMojo extends AbstractMojo {
/**
* Flag whether Maven is currently in online/offline mode.
*/
- @Parameter( defaultValue = "${settings.offline}", readonly = true )
+ @Parameter(defaultValue = "${settings.offline}", readonly = true)
private boolean offline;
/**
@@ -53,13 +50,13 @@ public abstract class AbstractDeployMojo
*
* @since 2.7
*/
- @Parameter( property = "retryFailedDeploymentCount", defaultValue = "1" )
+ @Parameter(property = "retryFailedDeploymentCount", defaultValue = "1")
private int retryFailedDeploymentCount;
@Component
private RuntimeInformation runtimeInformation;
- @Parameter( defaultValue = "${session}", readonly = true, required = true )
+ @Parameter(defaultValue = "${session}", readonly = true, required = true)
protected MavenSession session;
@Component
@@ -71,38 +68,29 @@ public abstract class AbstractDeployMojo
/* Setters and Getters */
- void failIfOffline()
- throws MojoFailureException
- {
- if ( offline )
- {
- throw new MojoFailureException( "Cannot deploy artifacts when Maven is in offline mode" );
+ void failIfOffline() throws MojoFailureException {
+ if (offline) {
+ throw new MojoFailureException("Cannot deploy artifacts when Maven is in offline mode");
}
}
/**
* If this plugin used in pre-3.9.0 Maven, the packaging {@code maven-plugin} will not deploy G level metadata.
*/
- protected void warnIfAffectedPackagingAndMaven( final String packaging )
- {
- if ( AFFECTED_MAVEN_PACKAGING.equals( packaging ) )
- {
- try
- {
+ protected void warnIfAffectedPackagingAndMaven(final String packaging) {
+ if (AFFECTED_MAVEN_PACKAGING.equals(packaging)) {
+ try {
GenericVersionScheme versionScheme = new GenericVersionScheme();
- Version fixedMavenVersion = versionScheme.parseVersion( FIXED_MAVEN_VERSION );
- Version currentMavenVersion = versionScheme.parseVersion( runtimeInformation.getMavenVersion() );
- if ( fixedMavenVersion.compareTo( currentMavenVersion ) > 0 )
- {
- getLog().warn( "" );
- getLog().warn( "You are about to deploy a maven-plugin using Maven " + currentMavenVersion + "." );
- getLog().warn( "This plugin should be used ONLY with Maven 3.9.0 and newer, as MNG-7055" );
- getLog().warn( "is fixed in those versions of Maven only!" );
- getLog().warn( "" );
+ Version fixedMavenVersion = versionScheme.parseVersion(FIXED_MAVEN_VERSION);
+ Version currentMavenVersion = versionScheme.parseVersion(runtimeInformation.getMavenVersion());
+ if (fixedMavenVersion.compareTo(currentMavenVersion) > 0) {
+ getLog().warn("");
+ getLog().warn("You are about to deploy a maven-plugin using Maven " + currentMavenVersion + ".");
+ getLog().warn("This plugin should be used ONLY with Maven 3.9.0 and newer, as MNG-7055");
+ getLog().warn("is fixed in those versions of Maven only!");
+ getLog().warn("");
}
- }
- catch ( InvalidVersionSpecificationException e )
- {
+ } catch (InvalidVersionSpecificationException e) {
// skip it: Generic does not throw, only API contains this exception
}
}
@@ -111,23 +99,21 @@ public abstract class AbstractDeployMojo
/**
* Creates resolver {@link RemoteRepository} equipped with needed whistles and bells.
*/
- protected RemoteRepository getRemoteRepository( final String repositoryId, final String url )
- {
- RemoteRepository result = new RemoteRepository.Builder( repositoryId, "default", url ).build();
-
- if ( result.getAuthentication() == null || result.getProxy() == null )
- {
- RemoteRepository.Builder builder = new RemoteRepository.Builder( result );
-
- if ( result.getAuthentication() == null )
- {
- builder.setAuthentication( session.getRepositorySession().getAuthenticationSelector()
- .getAuthentication( result ) );
+ protected RemoteRepository getRemoteRepository(final String repositoryId, final String url) {
+ RemoteRepository result = new RemoteRepository.Builder(repositoryId, "default", url).build();
+
+ if (result.getAuthentication() == null || result.getProxy() == null) {
+ RemoteRepository.Builder builder = new RemoteRepository.Builder(result);
+
+ if (result.getAuthentication() == null) {
+ builder.setAuthentication(session.getRepositorySession()
+ .getAuthenticationSelector()
+ .getAuthentication(result));
}
- if ( result.getProxy() == null )
- {
- builder.setProxy( session.getRepositorySession().getProxySelector().getProxy( result ) );
+ if (result.getProxy() == null) {
+ builder.setProxy(
+ session.getRepositorySession().getProxySelector().getProxy(result));
}
result = builder.build();
@@ -139,40 +125,30 @@ public abstract class AbstractDeployMojo
/**
* Handles high level retries (this was buried into MAT).
*/
- protected void deploy( RepositorySystemSession session, DeployRequest deployRequest ) throws MojoExecutionException
- {
- int retryFailedDeploymentCounter = Math.max( 1, Math.min( 10, retryFailedDeploymentCount ) );
+ protected void deploy(RepositorySystemSession session, DeployRequest deployRequest) throws MojoExecutionException {
+ int retryFailedDeploymentCounter = Math.max(1, Math.min(10, retryFailedDeploymentCount));
DeploymentException exception = null;
- for ( int count = 0; count < retryFailedDeploymentCounter; count++ )
- {
- try
- {
- if ( count > 0 )
- {
- getLog().info( "Retrying deployment attempt " + ( count + 1 ) + " of "
- + retryFailedDeploymentCounter );
+ for (int count = 0; count < retryFailedDeploymentCounter; count++) {
+ try {
+ if (count > 0) {
+ getLog().info("Retrying deployment attempt " + (count + 1) + " of " + retryFailedDeploymentCounter);
}
- repositorySystem.deploy( session, deployRequest );
+ repositorySystem.deploy(session, deployRequest);
exception = null;
break;
- }
- catch ( DeploymentException e )
- {
- if ( count + 1 < retryFailedDeploymentCounter )
- {
- getLog().warn( "Encountered issue during deployment: " + e.getLocalizedMessage() );
- getLog().debug( e );
+ } catch (DeploymentException e) {
+ if (count + 1 < retryFailedDeploymentCounter) {
+ getLog().warn("Encountered issue during deployment: " + e.getLocalizedMessage());
+ getLog().debug(e);
}
- if ( exception == null )
- {
+ if (exception == null) {
exception = e;
}
}
}
- if ( exception != null )
- {
- throw new MojoExecutionException( exception.getMessage(), exception );
+ if (exception != null) {
+ throw new MojoExecutionException(exception.getMessage(), exception);
}
}
}
diff --git a/src/main/java/org/apache/maven/plugins/deploy/DeployFileMojo.java b/src/main/java/org/apache/maven/plugins/deploy/DeployFileMojo.java
index 7f27f39..c6c875b 100644
--- a/src/main/java/org/apache/maven/plugins/deploy/DeployFileMojo.java
+++ b/src/main/java/org/apache/maven/plugins/deploy/DeployFileMojo.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.deploy;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@ package org.apache.maven.plugins.deploy;
* "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
+ * 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
@@ -18,6 +16,7 @@ package org.apache.maven.plugins.deploy;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.deploy;
import java.io.File;
import java.io.FileNotFoundException;
@@ -59,29 +58,27 @@ import org.eclipse.aether.util.artifact.SubArtifact;
/**
* Installs the artifact in the remote repository.
- *
+ *
* @author <a href="mailto:aramirez@apache.org">Allan Ramirez</a>
*/
-@Mojo( name = "deploy-file", requiresProject = false, threadSafe = true )
-public class DeployFileMojo
- extends AbstractDeployMojo
-{
+@Mojo(name = "deploy-file", requiresProject = false, threadSafe = true)
+public class DeployFileMojo extends AbstractDeployMojo {
/**
* GroupId of the artifact to be deployed. Retrieved from POM file if specified.
*/
- @Parameter( property = "groupId" )
+ @Parameter(property = "groupId")
private String groupId;
/**
* ArtifactId of the artifact to be deployed. Retrieved from POM file if specified.
*/
- @Parameter( property = "artifactId" )
+ @Parameter(property = "artifactId")
private String artifactId;
/**
* Version of the artifact to be deployed. Retrieved from POM file if specified.
*/
- @Parameter( property = "version" )
+ @Parameter(property = "version")
private String version;
/**
@@ -90,88 +87,88 @@ public class DeployFileMojo
* Maven uses two terms to refer to this datum: the <packaging> element for the entire POM, and the
* <type> element in a dependency specification.
*/
- @Parameter( property = "packaging" )
+ @Parameter(property = "packaging")
private String packaging;
/**
* Description passed to a generated POM file (in case of generatePom=true)
*/
- @Parameter( property = "generatePom.description" )
+ @Parameter(property = "generatePom.description")
private String description;
/**
* File to be deployed.
*/
- @Parameter( property = "file", required = true )
+ @Parameter(property = "file", required = true)
private File file;
/**
* The bundled API docs for the artifact.
- *
+ *
* @since 2.6
*/
- @Parameter( property = "javadoc" )
+ @Parameter(property = "javadoc")
private File javadoc;
/**
* The bundled sources for the artifact.
- *
+ *
* @since 2.6
*/
- @Parameter( property = "sources" )
+ @Parameter(property = "sources")
private File sources;
/**
* Server Id to map on the <id> under <server> section of settings.xml In most cases, this parameter
* will be required for authentication.
*/
- @Parameter( property = "repositoryId", defaultValue = "remote-repository", required = true )
+ @Parameter(property = "repositoryId", defaultValue = "remote-repository", required = true)
private String repositoryId;
/**
* URL where the artifact will be deployed. <br/>
* ie ( file:///C:/m2-repo or scp://host.com/path/to/repo )
*/
- @Parameter( property = "url", required = true )
+ @Parameter(property = "url", required = true)
private String url;
/**
* Location of an existing POM file to be deployed alongside the main artifact, given by the ${file} parameter.
*/
- @Parameter( property = "pomFile" )
+ @Parameter(property = "pomFile")
private File pomFile;
/**
* Upload a POM for this artifact. Will generate a default POM if none is supplied with the pomFile argument.
*/
- @Parameter( property = "generatePom", defaultValue = "true" )
+ @Parameter(property = "generatePom", defaultValue = "true")
private boolean generatePom;
/**
* Add classifier to the artifact
*/
- @Parameter( property = "classifier" )
+ @Parameter(property = "classifier")
private String classifier;
/**
* A comma separated list of types for each of the extra side artifacts to deploy. If there is a mis-match in the
* number of entries in {@link #files} or {@link #classifiers}, then an error will be raised.
*/
- @Parameter( property = "types" )
+ @Parameter(property = "types")
private String types;
/**
* A comma separated list of classifiers for each of the extra side artifacts to deploy. If there is a mis-match in
* the number of entries in {@link #files} or {@link #types}, then an error will be raised.
*/
- @Parameter( property = "classifiers" )
+ @Parameter(property = "classifiers")
private String classifiers;
/**
* A comma separated list of files for each of the extra side artifacts to deploy. If there is a mis-match in the
* number of entries in {@link #types} or {@link #classifiers}, then an error will be raised.
*/
- @Parameter( property = "files" )
+ @Parameter(property = "files")
private String files;
/**
@@ -185,265 +182,202 @@ public class DeployFileMojo
* </ul>
* @since 3.1.0
*/
- @Parameter( property = "maven.deploy.file.skip", defaultValue = "false" )
+ @Parameter(property = "maven.deploy.file.skip", defaultValue = "false")
private String skip = Boolean.FALSE.toString();
- void initProperties()
- throws MojoExecutionException
- {
- if ( pomFile == null )
- {
+ void initProperties() throws MojoExecutionException {
+ if (pomFile == null) {
boolean foundPom = false;
- try ( JarFile jarFile = new JarFile( file ) )
- {
- Pattern pomEntry = Pattern.compile( "META-INF/maven/.*/pom\\.xml" );
+ try (JarFile jarFile = new JarFile(file)) {
+ Pattern pomEntry = Pattern.compile("META-INF/maven/.*/pom\\.xml");
Enumeration<JarEntry> jarEntries = jarFile.entries();
- while ( jarEntries.hasMoreElements() )
- {
+ while (jarEntries.hasMoreElements()) {
JarEntry entry = jarEntries.nextElement();
- if ( pomEntry.matcher( entry.getName() ).matches() )
- {
- getLog().debug( "Using " + entry.getName() + " as pomFile" );
+ if (pomEntry.matcher(entry.getName()).matches()) {
+ getLog().debug("Using " + entry.getName() + " as pomFile");
foundPom = true;
String base = file.getName();
- if ( base.indexOf( '.' ) > 0 )
- {
- base = base.substring( 0, base.lastIndexOf( '.' ) );
+ if (base.indexOf('.') > 0) {
+ base = base.substring(0, base.lastIndexOf('.'));
}
- pomFile = new File( file.getParentFile(), base + ".pom" );
+ pomFile = new File(file.getParentFile(), base + ".pom");
- try ( InputStream pomInputStream = jarFile.getInputStream( entry ) )
- {
- try ( OutputStream pomOutputStream = Files.newOutputStream( pomFile.toPath() ) )
- {
- IOUtil.copy( pomInputStream, pomOutputStream );
+ try (InputStream pomInputStream = jarFile.getInputStream(entry)) {
+ try (OutputStream pomOutputStream = Files.newOutputStream(pomFile.toPath())) {
+ IOUtil.copy(pomInputStream, pomOutputStream);
}
- processModel( readModel( pomFile ) );
+ processModel(readModel(pomFile));
break;
}
}
}
- if ( !foundPom )
- {
- getLog().info( "pom.xml not found in " + file.getName() );
+ if (!foundPom) {
+ getLog().info("pom.xml not found in " + file.getName());
}
- }
- catch ( IOException e )
- {
+ } catch (IOException e) {
// ignore, artifact not packaged by Maven
}
- }
- else
- {
- processModel( readModel( pomFile ) );
+ } else {
+ processModel(readModel(pomFile));
}
- if ( packaging == null && file != null )
- {
- packaging = getExtension( file );
+ if (packaging == null && file != null) {
+ packaging = getExtension(file);
}
}
- public void execute()
- throws MojoExecutionException, MojoFailureException
- {
- if ( Boolean.parseBoolean( skip )
- || ( "releases".equals( skip ) && !ArtifactUtils.isSnapshot( version ) )
- || ( "snapshots".equals( skip ) && ArtifactUtils.isSnapshot( version ) )
- )
- {
- getLog().info( "Skipping artifact deployment" );
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ if (Boolean.parseBoolean(skip)
+ || ("releases".equals(skip) && !ArtifactUtils.isSnapshot(version))
+ || ("snapshots".equals(skip) && ArtifactUtils.isSnapshot(version))) {
+ getLog().info("Skipping artifact deployment");
return;
}
- if ( !file.exists() )
- {
- throw new MojoExecutionException( file.getPath() + " not found." );
+ if (!file.exists()) {
+ throw new MojoExecutionException(file.getPath() + " not found.");
}
initProperties();
- RemoteRepository remoteRepository = getRemoteRepository( repositoryId, url );
+ RemoteRepository remoteRepository = getRemoteRepository(repositoryId, url);
- if ( StringUtils.isEmpty( remoteRepository.getProtocol() ) )
- {
- throw new MojoExecutionException( "No transfer protocol found." );
+ if (StringUtils.isEmpty(remoteRepository.getProtocol())) {
+ throw new MojoExecutionException("No transfer protocol found.");
}
- if ( groupId == null || artifactId == null || version == null || packaging == null )
- {
- throw new MojoExecutionException( "The artifact information is incomplete: 'groupId', 'artifactId', "
- + "'version' and 'packaging' are required." );
+ if (groupId == null || artifactId == null || version == null || packaging == null) {
+ throw new MojoExecutionException("The artifact information is incomplete: 'groupId', 'artifactId', "
+ + "'version' and 'packaging' are required.");
}
- if ( !isValidId( groupId )
- || !isValidId( artifactId )
- || !isValidVersion( version ) )
- {
- throw new MojoExecutionException( "The artifact information is not valid: uses invalid characters." );
+ if (!isValidId(groupId) || !isValidId(artifactId) || !isValidVersion(version)) {
+ throw new MojoExecutionException("The artifact information is not valid: uses invalid characters.");
}
failIfOffline();
- warnIfAffectedPackagingAndMaven( packaging );
+ warnIfAffectedPackagingAndMaven(packaging);
DeployRequest deployRequest = new DeployRequest();
- deployRequest.setRepository( remoteRepository );
-
- boolean isFilePom = classifier == null && "pom".equals( packaging );
- if ( !isFilePom )
- {
- ArtifactType artifactType = session.getRepositorySession().getArtifactTypeRegistry().get( packaging );
- if ( artifactType != null
- && StringUtils.isEmpty( classifier )
- && !StringUtils.isEmpty( artifactType.getClassifier() ) )
- {
+ deployRequest.setRepository(remoteRepository);
+
+ boolean isFilePom = classifier == null && "pom".equals(packaging);
+ if (!isFilePom) {
+ ArtifactType artifactType =
+ session.getRepositorySession().getArtifactTypeRegistry().get(packaging);
+ if (artifactType != null
+ && StringUtils.isEmpty(classifier)
+ && !StringUtils.isEmpty(artifactType.getClassifier())) {
classifier = artifactType.getClassifier();
}
}
Artifact mainArtifact = new DefaultArtifact(
- groupId,
- artifactId,
- classifier,
- isFilePom ? "pom" : getExtension( file ),
- version
- ).setFile( file );
- deployRequest.addArtifact( mainArtifact );
-
- File artifactLocalFile = getLocalRepositoryFile( session.getRepositorySession(), mainArtifact );
-
- if ( file.equals( artifactLocalFile ) )
- {
- throw new MojoFailureException( "Cannot deploy artifact from the local repository: " + file );
+ groupId, artifactId, classifier, isFilePom ? "pom" : getExtension(file), version)
+ .setFile(file);
+ deployRequest.addArtifact(mainArtifact);
+
+ File artifactLocalFile = getLocalRepositoryFile(session.getRepositorySession(), mainArtifact);
+
+ if (file.equals(artifactLocalFile)) {
+ throw new MojoFailureException("Cannot deploy artifact from the local repository: " + file);
}
File temporaryPom = null;
- if ( !"pom".equals( packaging ) )
- {
- if ( pomFile != null )
- {
- deployRequest.addArtifact( new SubArtifact( mainArtifact, "", "pom", pomFile ) );
- }
- else if ( generatePom )
- {
+ if (!"pom".equals(packaging)) {
+ if (pomFile != null) {
+ deployRequest.addArtifact(new SubArtifact(mainArtifact, "", "pom", pomFile));
+ } else if (generatePom) {
temporaryPom = generatePomFile();
- getLog().debug( "Deploying generated POM" );
- deployRequest.addArtifact( new SubArtifact( mainArtifact, "", "pom", temporaryPom ) );
- }
- else
- {
- getLog().debug( "Skipping deploying POM" );
+ getLog().debug("Deploying generated POM");
+ deployRequest.addArtifact(new SubArtifact(mainArtifact, "", "pom", temporaryPom));
+ } else {
+ getLog().debug("Skipping deploying POM");
}
}
- if ( sources != null )
- {
- deployRequest.addArtifact( new SubArtifact( mainArtifact, "sources", "jar", sources ) );
+ if (sources != null) {
+ deployRequest.addArtifact(new SubArtifact(mainArtifact, "sources", "jar", sources));
}
- if ( javadoc != null )
- {
- deployRequest.addArtifact( new SubArtifact( mainArtifact, "javadoc", "jar", javadoc ) );
+ if (javadoc != null) {
+ deployRequest.addArtifact(new SubArtifact(mainArtifact, "javadoc", "jar", javadoc));
}
- if ( files != null )
- {
- if ( types == null )
- {
- throw new MojoExecutionException( "You must specify 'types' if you specify 'files'" );
+ if (files != null) {
+ if (types == null) {
+ throw new MojoExecutionException("You must specify 'types' if you specify 'files'");
}
- if ( classifiers == null )
- {
- throw new MojoExecutionException( "You must specify 'classifiers' if you specify 'files'" );
+ if (classifiers == null) {
+ throw new MojoExecutionException("You must specify 'classifiers' if you specify 'files'");
}
- int filesLength = StringUtils.countMatches( files, "," );
- int typesLength = StringUtils.countMatches( types, "," );
- int classifiersLength = StringUtils.countMatches( classifiers, "," );
- if ( typesLength != filesLength )
- {
- throw new MojoExecutionException( "You must specify the same number of entries in 'files' and "
- + "'types' (respectively " + filesLength + " and " + typesLength + " entries )" );
+ int filesLength = StringUtils.countMatches(files, ",");
+ int typesLength = StringUtils.countMatches(types, ",");
+ int classifiersLength = StringUtils.countMatches(classifiers, ",");
+ if (typesLength != filesLength) {
+ throw new MojoExecutionException("You must specify the same number of entries in 'files' and "
+ + "'types' (respectively " + filesLength + " and " + typesLength + " entries )");
}
- if ( classifiersLength != filesLength )
- {
- throw new MojoExecutionException( "You must specify the same number of entries in 'files' and "
- + "'classifiers' (respectively " + filesLength + " and " + classifiersLength + " entries )" );
+ if (classifiersLength != filesLength) {
+ throw new MojoExecutionException("You must specify the same number of entries in 'files' and "
+ + "'classifiers' (respectively " + filesLength + " and " + classifiersLength + " entries )");
}
int fi = 0;
int ti = 0;
int ci = 0;
- for ( int i = 0; i <= filesLength; i++ )
- {
- int nfi = files.indexOf( ',', fi );
- if ( nfi == -1 )
- {
+ for (int i = 0; i <= filesLength; i++) {
+ int nfi = files.indexOf(',', fi);
+ if (nfi == -1) {
nfi = files.length();
}
- int nti = types.indexOf( ',', ti );
- if ( nti == -1 )
- {
+ int nti = types.indexOf(',', ti);
+ if (nti == -1) {
nti = types.length();
}
- int nci = classifiers.indexOf( ',', ci );
- if ( nci == -1 )
- {
+ int nci = classifiers.indexOf(',', ci);
+ if (nci == -1) {
nci = classifiers.length();
}
- File file = new File( files.substring( fi, nfi ) );
- if ( !file.isFile() )
- {
+ File file = new File(files.substring(fi, nfi));
+ if (!file.isFile()) {
// try relative to the project basedir just in case
- file = new File( files.substring( fi, nfi ) );
+ file = new File(files.substring(fi, nfi));
}
- if ( file.isFile() )
- {
- String extension = getExtension( file );
- ArtifactType artifactType = session.getRepositorySession().getArtifactTypeRegistry()
- .get( types.substring( ti, nti ).trim() );
- if ( artifactType != null && !Objects.equals( extension, artifactType.getExtension() ) )
- {
+ if (file.isFile()) {
+ String extension = getExtension(file);
+ ArtifactType artifactType = session.getRepositorySession()
+ .getArtifactTypeRegistry()
+ .get(types.substring(ti, nti).trim());
+ if (artifactType != null && !Objects.equals(extension, artifactType.getExtension())) {
extension = artifactType.getExtension();
}
- deployRequest.addArtifact(
- new SubArtifact( mainArtifact, classifiers.substring( ci, nci ).trim(), extension, file )
- );
- }
- else
- {
- throw new MojoExecutionException( "Specified side artifact " + file + " does not exist" );
+ deployRequest.addArtifact(new SubArtifact(
+ mainArtifact, classifiers.substring(ci, nci).trim(), extension, file));
+ } else {
+ throw new MojoExecutionException("Specified side artifact " + file + " does not exist");
}
fi = nfi + 1;
ti = nti + 1;
ci = nci + 1;
}
- }
- else
- {
- if ( types != null )
- {
- throw new MojoExecutionException( "You must specify 'files' if you specify 'types'" );
+ } else {
+ if (types != null) {
+ throw new MojoExecutionException("You must specify 'files' if you specify 'types'");
}
- if ( classifiers != null )
- {
- throw new MojoExecutionException( "You must specify 'files' if you specify 'classifiers'" );
+ if (classifiers != null) {
+ throw new MojoExecutionException("You must specify 'files' if you specify 'classifiers'");
}
}
- try
- {
- repositorySystem.deploy( session.getRepositorySession(), deployRequest );
- }
- catch ( DeploymentException e )
- {
- throw new MojoExecutionException( e.getMessage(), e );
- }
- finally
- {
- if ( temporaryPom != null )
- {
+ try {
+ repositorySystem.deploy(session.getRepositorySession(), deployRequest);
+ } catch (DeploymentException e) {
+ throw new MojoExecutionException(e.getMessage(), e);
+ } finally {
+ if (temporaryPom != null) {
// noinspection ResultOfMethodCallIgnored
temporaryPom.delete();
}
@@ -454,198 +388,159 @@ public class DeployFileMojo
* Gets the path of the specified artifact within the local repository. Note that the returned path need not exist
* (yet).
*/
- private File getLocalRepositoryFile( RepositorySystemSession session, Artifact artifact )
- {
- String path = session.getLocalRepositoryManager().getPathForLocalArtifact( artifact );
- return new File( session.getLocalRepository().getBasedir(), path );
+ private File getLocalRepositoryFile(RepositorySystemSession session, Artifact artifact) {
+ String path = session.getLocalRepositoryManager().getPathForLocalArtifact(artifact);
+ return new File(session.getLocalRepository().getBasedir(), path);
}
/**
* Process the supplied pomFile to get groupId, artifactId, version, and packaging
- *
+ *
* @param model The POM to extract missing artifact coordinates from, must not be <code>null</code>.
*/
- private void processModel( Model model )
- {
+ private void processModel(Model model) {
Parent parent = model.getParent();
- if ( this.groupId == null )
- {
+ if (this.groupId == null) {
this.groupId = model.getGroupId();
- if ( this.groupId == null && parent != null )
- {
+ if (this.groupId == null && parent != null) {
this.groupId = parent.getGroupId();
}
}
- if ( this.artifactId == null )
- {
+ if (this.artifactId == null) {
this.artifactId = model.getArtifactId();
}
- if ( this.version == null )
- {
+ if (this.version == null) {
this.version = model.getVersion();
- if ( this.version == null && parent != null )
- {
+ if (this.version == null && parent != null) {
this.version = parent.getVersion();
}
}
- if ( this.packaging == null )
- {
+ if (this.packaging == null) {
this.packaging = model.getPackaging();
}
}
/**
* Extract the model from the specified POM file.
- *
+ *
* @param pomFile The path of the POM file to parse, must not be <code>null</code>.
* @return The model from the POM file, never <code>null</code>.
* @throws MojoExecutionException If the file doesn't exist of cannot be read.
*/
- Model readModel( File pomFile )
- throws MojoExecutionException
- {
+ Model readModel(File pomFile) throws MojoExecutionException {
Reader reader = null;
- try
- {
- reader = ReaderFactory.newXmlReader( pomFile );
- final Model model = new MavenXpp3Reader().read( reader );
+ try {
+ reader = ReaderFactory.newXmlReader(pomFile);
+ final Model model = new MavenXpp3Reader().read(reader);
reader.close();
reader = null;
return model;
- }
- catch ( FileNotFoundException e )
- {
- throw new MojoExecutionException( "POM not found " + pomFile, e );
- }
- catch ( IOException e )
- {
- throw new MojoExecutionException( "Error reading POM " + pomFile, e );
- }
- catch ( XmlPullParserException e )
- {
- throw new MojoExecutionException( "Error parsing POM " + pomFile, e );
- }
- finally
- {
- IOUtil.close( reader );
+ } catch (FileNotFoundException e) {
+ throw new MojoExecutionException("POM not found " + pomFile, e);
+ } catch (IOException e) {
+ throw new MojoExecutionException("Error reading POM " + pomFile, e);
+ } catch (XmlPullParserException e) {
+ throw new MojoExecutionException("Error parsing POM " + pomFile, e);
+ } finally {
+ IOUtil.close(reader);
}
}
/**
* Generates a minimal POM from the user-supplied artifact information.
- *
+ *
* @return The path to the generated POM file, never <code>null</code>.
* @throws MojoExecutionException If the generation failed.
*/
- private File generatePomFile()
- throws MojoExecutionException
- {
+ private File generatePomFile() throws MojoExecutionException {
Model model = generateModel();
Writer fw = null;
- try
- {
- File tempFile = File.createTempFile( "mvndeploy", ".pom" );
+ try {
+ File tempFile = File.createTempFile("mvndeploy", ".pom");
tempFile.deleteOnExit();
- fw = WriterFactory.newXmlWriter( tempFile );
+ fw = WriterFactory.newXmlWriter(tempFile);
- new MavenXpp3Writer().write( fw, model );
+ new MavenXpp3Writer().write(fw, model);
fw.close();
fw = null;
return tempFile;
- }
- catch ( IOException e )
- {
- throw new MojoExecutionException( "Error writing temporary pom file: " + e.getMessage(), e );
- }
- finally
- {
- IOUtil.close( fw );
+ } catch (IOException e) {
+ throw new MojoExecutionException("Error writing temporary pom file: " + e.getMessage(), e);
+ } finally {
+ IOUtil.close(fw);
}
}
/**
* Generates a minimal model from the user-supplied artifact information.
- *
+ *
* @return The generated model, never <code>null</code>.
*/
- private Model generateModel()
- {
+ private Model generateModel() {
Model model = new Model();
- model.setModelVersion( "4.0.0" );
+ model.setModelVersion("4.0.0");
- model.setGroupId( groupId );
- model.setArtifactId( artifactId );
- model.setVersion( version );
- model.setPackaging( packaging );
+ model.setGroupId(groupId);
+ model.setArtifactId(artifactId);
+ model.setVersion(version);
+ model.setPackaging(packaging);
- model.setDescription( description );
+ model.setDescription(description);
return model;
}
- void setGroupId( String groupId )
- {
+ void setGroupId(String groupId) {
this.groupId = groupId;
}
- void setArtifactId( String artifactId )
- {
+ void setArtifactId(String artifactId) {
this.artifactId = artifactId;
}
- void setVersion( String version )
- {
+ void setVersion(String version) {
this.version = version;
}
- void setPackaging( String packaging )
- {
+ void setPackaging(String packaging) {
this.packaging = packaging;
}
- void setPomFile( File pomFile )
- {
+ void setPomFile(File pomFile) {
this.pomFile = pomFile;
}
- String getGroupId()
- {
+ String getGroupId() {
return groupId;
}
- String getArtifactId()
- {
+ String getArtifactId() {
return artifactId;
}
- String getVersion()
- {
+ String getVersion() {
return version;
}
- String getPackaging()
- {
+ String getPackaging() {
return packaging;
}
- File getFile()
- {
+ File getFile() {
return file;
}
- String getClassifier()
- {
+ String getClassifier() {
return classifier;
}
- void setClassifier( String classifier )
- {
+ void setClassifier(String classifier) {
this.classifier = classifier;
}
@@ -654,34 +549,30 @@ public class DeployFileMojo
/**
* Specialization of {@link FileUtils#getExtension(String)} that honors various {@code tar.xxx} combinations.
*/
- private String getExtension( final File file )
- {
+ private String getExtension(final File file) {
String filename = file.getName();
- if ( filename.contains( ".tar." ) )
- {
- return "tar." + FileUtils.getExtension( filename );
- }
- else
- {
- return FileUtils.getExtension( filename );
+ if (filename.contains(".tar.")) {
+ return "tar." + FileUtils.getExtension(filename);
+ } else {
+ return FileUtils.getExtension(filename);
}
}
/**
* Returns {@code true} if passed in string is "valid Maven ID" (groupId or artifactId).
*/
- private boolean isValidId( String id )
- {
- if ( id == null )
- {
+ private boolean isValidId(String id) {
+ if (id == null) {
return false;
}
- for ( int i = 0; i < id.length(); i++ )
- {
- char c = id.charAt( i );
- if ( !( c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z'
- || c >= '0' && c <= '9' || c == '-' || c == '_' || c == '.' ) )
- {
+ for (int i = 0; i < id.length(); i++) {
+ char c = id.charAt(i);
+ if (!(c >= 'a' && c <= 'z'
+ || c >= 'A' && c <= 'Z'
+ || c >= '0' && c <= '9'
+ || c == '-'
+ || c == '_'
+ || c == '.')) {
return false;
}
}
@@ -693,16 +584,12 @@ public class DeployFileMojo
/**
* Returns {@code true} if passed in string is "valid Maven (simple. non range, expression, etc) version".
*/
- private boolean isValidVersion( String version )
- {
- if ( version == null )
- {
+ private boolean isValidVersion(String version) {
+ if (version == null) {
return false;
}
- for ( int i = version.length() - 1; i >= 0; i-- )
- {
- if ( ILLEGAL_VERSION_CHARS.indexOf( version.charAt( i ) ) >= 0 )
- {
+ for (int i = version.length() - 1; i >= 0; i--) {
+ if (ILLEGAL_VERSION_CHARS.indexOf(version.charAt(i)) >= 0) {
return false;
}
}
diff --git a/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java b/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java
index d169ab8..0921417 100644
--- a/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java
+++ b/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.deploy;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@ package org.apache.maven.plugins.deploy;
* "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
+ * 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
@@ -18,6 +16,7 @@ package org.apache.maven.plugins.deploy;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.deploy;
import java.io.File;
import java.util.List;
@@ -42,35 +41,33 @@ import org.eclipse.aether.util.artifact.SubArtifact;
/**
* Deploys an artifact to remote repository.
- *
+ *
* @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
* @author <a href="mailto:jdcasey@apache.org">John Casey (refactoring only)</a>
*/
-@Mojo( name = "deploy", defaultPhase = LifecyclePhase.DEPLOY, threadSafe = true )
-public class DeployMojo
- extends AbstractDeployMojo
-{
- private static final Pattern ALT_LEGACY_REPO_SYNTAX_PATTERN = Pattern.compile( "(.+?)::(.+?)::(.+)" );
+@Mojo(name = "deploy", defaultPhase = LifecyclePhase.DEPLOY, threadSafe = true)
+public class DeployMojo extends AbstractDeployMojo {
+ private static final Pattern ALT_LEGACY_REPO_SYNTAX_PATTERN = Pattern.compile("(.+?)::(.+?)::(.+)");
- private static final Pattern ALT_REPO_SYNTAX_PATTERN = Pattern.compile( "(.+?)::(.+)" );
+ private static final Pattern ALT_REPO_SYNTAX_PATTERN = Pattern.compile("(.+?)::(.+)");
- @Parameter( defaultValue = "${project}", readonly = true, required = true )
+ @Parameter(defaultValue = "${project}", readonly = true, required = true)
private MavenProject project;
- @Parameter( defaultValue = "${reactorProjects}", required = true, readonly = true )
+ @Parameter(defaultValue = "${reactorProjects}", required = true, readonly = true)
private List<MavenProject> reactorProjects;
- @Parameter( defaultValue = "${plugin}", required = true, readonly = true )
+ @Parameter(defaultValue = "${plugin}", required = true, readonly = true)
private PluginDescriptor pluginDescriptor;
/**
* Whether every project should be deployed during its own deploy-phase or at the end of the multimodule build. If
* set to {@code true} and the build fails, none of the reactor projects is deployed.
* <strong>(experimental)</strong>
- *
+ *
* @since 2.8
*/
- @Parameter( defaultValue = "false", property = "deployAtEnd" )
+ @Parameter(defaultValue = "false", property = "deployAtEnd")
private boolean deployAtEnd;
/**
@@ -87,7 +84,7 @@ public class DeployMojo
* could be <code>default</code> (ie. Maven 2) or <code>legacy</code> (ie. Maven 1), but since 3.0.0 the layout part
* has been removed because Maven 3 only supports Maven 2 repository layout.
*/
- @Parameter( property = "altDeploymentRepository" )
+ @Parameter(property = "altDeploymentRepository")
private String altDeploymentRepository;
/**
@@ -99,7 +96,7 @@ public class DeployMojo
* @since 2.8
* @see DeployMojo#altDeploymentRepository
*/
- @Parameter( property = "altSnapshotDeploymentRepository" )
+ @Parameter(property = "altSnapshotDeploymentRepository")
private String altSnapshotDeploymentRepository;
/**
@@ -111,7 +108,7 @@ public class DeployMojo
* @since 2.8
* @see DeployMojo#altDeploymentRepository
*/
- @Parameter( property = "altReleaseDeploymentRepository" )
+ @Parameter(property = "altReleaseDeploymentRepository")
private String altReleaseDeploymentRepository;
/**
@@ -125,191 +122,163 @@ public class DeployMojo
* </ul>
* @since 2.4
*/
- @Parameter( property = "maven.deploy.skip", defaultValue = "false" )
+ @Parameter(property = "maven.deploy.skip", defaultValue = "false")
private String skip = Boolean.FALSE.toString();
- private enum State
- {
- SKIPPED, DEPLOYED, TO_BE_DEPLOYED
+ private enum State {
+ SKIPPED,
+ DEPLOYED,
+ TO_BE_DEPLOYED
}
private static final String DEPLOY_PROCESSED_MARKER = DeployMojo.class.getName() + ".processed";
private static final String DEPLOY_ALT_RELEASE_DEPLOYMENT_REPOSITORY =
- DeployMojo.class.getName() + ".altReleaseDeploymentRepository";
+ DeployMojo.class.getName() + ".altReleaseDeploymentRepository";
private static final String DEPLOY_ALT_SNAPSHOT_DEPLOYMENT_REPOSITORY =
- DeployMojo.class.getName() + ".altSnapshotDeploymentRepository";
+ DeployMojo.class.getName() + ".altSnapshotDeploymentRepository";
private static final String DEPLOY_ALT_DEPLOYMENT_REPOSITORY =
- DeployMojo.class.getName() + ".altDeploymentRepository";
+ DeployMojo.class.getName() + ".altDeploymentRepository";
- private void putState( State state )
- {
- getPluginContext().put( DEPLOY_PROCESSED_MARKER, state.name() );
+ private void putState(State state) {
+ getPluginContext().put(DEPLOY_PROCESSED_MARKER, state.name());
}
- private void putPluginContextValue( String key, String value )
- {
- if ( value != null )
- {
- getPluginContext().put( key, value );
+ private void putPluginContextValue(String key, String value) {
+ if (value != null) {
+ getPluginContext().put(key, value);
}
}
- private String getPluginContextValue( Map<String, Object> pluginContext, String key )
- {
- return (String) pluginContext.get( key );
+ private String getPluginContextValue(Map<String, Object> pluginContext, String key) {
+ return (String) pluginContext.get(key);
}
- private State getState( Map<String, Object> pluginContext )
- {
- return State.valueOf( getPluginContextValue( pluginContext, DEPLOY_PROCESSED_MARKER ) );
+ private State getState(Map<String, Object> pluginContext) {
+ return State.valueOf(getPluginContextValue(pluginContext, DEPLOY_PROCESSED_MARKER));
}
- private boolean hasState( MavenProject project )
- {
- Map<String, Object> pluginContext = session.getPluginContext( pluginDescriptor, project );
- return pluginContext.containsKey( DEPLOY_PROCESSED_MARKER );
+ private boolean hasState(MavenProject project) {
+ Map<String, Object> pluginContext = session.getPluginContext(pluginDescriptor, project);
+ return pluginContext.containsKey(DEPLOY_PROCESSED_MARKER);
}
- public void execute()
- throws MojoExecutionException, MojoFailureException
- {
- if ( Boolean.parseBoolean( skip )
- || ( "releases".equals( skip ) && !ArtifactUtils.isSnapshot( project.getVersion() ) )
- || ( "snapshots".equals( skip ) && ArtifactUtils.isSnapshot( project.getVersion() ) )
- )
- {
- getLog().info( "Skipping artifact deployment" );
- putState( State.SKIPPED );
- }
- else
- {
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ if (Boolean.parseBoolean(skip)
+ || ("releases".equals(skip) && !ArtifactUtils.isSnapshot(project.getVersion()))
+ || ("snapshots".equals(skip) && ArtifactUtils.isSnapshot(project.getVersion()))) {
+ getLog().info("Skipping artifact deployment");
+ putState(State.SKIPPED);
+ } else {
failIfOffline();
- warnIfAffectedPackagingAndMaven( project.getPackaging() );
-
- if ( !deployAtEnd )
- {
- deploy( session.getRepositorySession(),
- processProject( project,
- altSnapshotDeploymentRepository, altReleaseDeploymentRepository, altDeploymentRepository ) );
- putState( State.DEPLOYED );
- }
- else
- {
- putPluginContextValue( DEPLOY_ALT_RELEASE_DEPLOYMENT_REPOSITORY, altReleaseDeploymentRepository );
- putPluginContextValue( DEPLOY_ALT_SNAPSHOT_DEPLOYMENT_REPOSITORY, altSnapshotDeploymentRepository );
- putPluginContextValue( DEPLOY_ALT_DEPLOYMENT_REPOSITORY, altDeploymentRepository );
- putState( State.TO_BE_DEPLOYED );
- getLog().info( "Deferring deploy for " + project.getGroupId()
- + ":" + project.getArtifactId() + ":" + project.getVersion() + " at end" );
+ warnIfAffectedPackagingAndMaven(project.getPackaging());
+
+ if (!deployAtEnd) {
+ deploy(
+ session.getRepositorySession(),
+ processProject(
+ project,
+ altSnapshotDeploymentRepository,
+ altReleaseDeploymentRepository,
+ altDeploymentRepository));
+ putState(State.DEPLOYED);
+ } else {
+ putPluginContextValue(DEPLOY_ALT_RELEASE_DEPLOYMENT_REPOSITORY, altReleaseDeploymentRepository);
+ putPluginContextValue(DEPLOY_ALT_SNAPSHOT_DEPLOYMENT_REPOSITORY, altSnapshotDeploymentRepository);
+ putPluginContextValue(DEPLOY_ALT_DEPLOYMENT_REPOSITORY, altDeploymentRepository);
+ putState(State.TO_BE_DEPLOYED);
+ getLog().info("Deferring deploy for " + project.getGroupId() + ":" + project.getArtifactId() + ":"
+ + project.getVersion() + " at end");
}
}
- if ( allProjectsMarked() )
- {
- for ( MavenProject reactorProject : reactorProjects )
- {
- Map<String, Object> pluginContext = session.getPluginContext( pluginDescriptor, reactorProject );
- State state = getState( pluginContext );
- if ( state == State.TO_BE_DEPLOYED )
- {
+ if (allProjectsMarked()) {
+ for (MavenProject reactorProject : reactorProjects) {
+ Map<String, Object> pluginContext = session.getPluginContext(pluginDescriptor, reactorProject);
+ State state = getState(pluginContext);
+ if (state == State.TO_BE_DEPLOYED) {
String altReleaseDeploymentRepository =
- getPluginContextValue( pluginContext, DEPLOY_ALT_RELEASE_DEPLOYMENT_REPOSITORY );
+ getPluginContextValue(pluginContext, DEPLOY_ALT_RELEASE_DEPLOYMENT_REPOSITORY);
String altSnapshotDeploymentRepository =
- getPluginContextValue( pluginContext, DEPLOY_ALT_SNAPSHOT_DEPLOYMENT_REPOSITORY );
+ getPluginContextValue(pluginContext, DEPLOY_ALT_SNAPSHOT_DEPLOYMENT_REPOSITORY);
String altDeploymentRepository =
- getPluginContextValue( pluginContext, DEPLOY_ALT_DEPLOYMENT_REPOSITORY );
-
- deploy( session.getRepositorySession(),
- processProject( reactorProject,
- altSnapshotDeploymentRepository, altReleaseDeploymentRepository, altDeploymentRepository )
- );
+ getPluginContextValue(pluginContext, DEPLOY_ALT_DEPLOYMENT_REPOSITORY);
+
+ deploy(
+ session.getRepositorySession(),
+ processProject(
+ reactorProject,
+ altSnapshotDeploymentRepository,
+ altReleaseDeploymentRepository,
+ altDeploymentRepository));
}
}
}
}
- private boolean allProjectsMarked()
- {
- for ( MavenProject reactorProject : reactorProjects )
- {
- if ( !hasState( reactorProject ) )
- {
+ private boolean allProjectsMarked() {
+ for (MavenProject reactorProject : reactorProjects) {
+ if (!hasState(reactorProject)) {
return false;
}
}
return true;
}
- private DeployRequest processProject( final MavenProject project,
- final String altSnapshotDeploymentRepository,
- final String altReleaseDeploymentRepository,
- final String altDeploymentRepository )
- throws MojoExecutionException, MojoFailureException
- {
+ private DeployRequest processProject(
+ final MavenProject project,
+ final String altSnapshotDeploymentRepository,
+ final String altReleaseDeploymentRepository,
+ final String altDeploymentRepository)
+ throws MojoExecutionException, MojoFailureException {
DeployRequest request = new DeployRequest();
- request.setRepository( getDeploymentRepository( project,
- altSnapshotDeploymentRepository, altReleaseDeploymentRepository, altDeploymentRepository ) );
+ request.setRepository(getDeploymentRepository(
+ project, altSnapshotDeploymentRepository, altReleaseDeploymentRepository, altDeploymentRepository));
org.apache.maven.artifact.Artifact mavenMainArtifact = project.getArtifact();
String packaging = project.getPackaging();
File pomFile = project.getFile();
- boolean isPomArtifact = "pom".equals( packaging );
+ boolean isPomArtifact = "pom".equals(packaging);
boolean pomArtifactAttached = false;
- if ( pomFile != null )
- {
- request.addArtifact( RepositoryUtils.toArtifact( new ProjectArtifact( project ) ) );
+ if (pomFile != null) {
+ request.addArtifact(RepositoryUtils.toArtifact(new ProjectArtifact(project)));
pomArtifactAttached = true;
}
- if ( !isPomArtifact )
- {
+ if (!isPomArtifact) {
File file = mavenMainArtifact.getFile();
- if ( file != null && file.isFile() )
- {
- org.eclipse.aether.artifact.Artifact mainArtifact = RepositoryUtils.toArtifact( mavenMainArtifact );
- request.addArtifact( mainArtifact );
-
- if ( !pomArtifactAttached )
- {
- for ( Object metadata : mavenMainArtifact.getMetadataList() )
- {
- if ( metadata instanceof ProjectArtifactMetadata )
- {
- request.addArtifact( new SubArtifact(
- mainArtifact,
- "",
- "pom"
- ).setFile( ( (ProjectArtifactMetadata) metadata ).getFile() ) );
+ if (file != null && file.isFile()) {
+ org.eclipse.aether.artifact.Artifact mainArtifact = RepositoryUtils.toArtifact(mavenMainArtifact);
+ request.addArtifact(mainArtifact);
+
+ if (!pomArtifactAttached) {
+ for (Object metadata : mavenMainArtifact.getMetadataList()) {
+ if (metadata instanceof ProjectArtifactMetadata) {
+ request.addArtifact(new SubArtifact(mainArtifact, "", "pom")
+ .setFile(((ProjectArtifactMetadata) metadata).getFile()));
pomArtifactAttached = true;
}
}
}
- }
- else if ( !project.getAttachedArtifacts().isEmpty() )
- {
- throw new MojoExecutionException( "The packaging plugin for this project did not assign "
- + "a main file to the project but it has attachments. Change packaging to 'pom'." );
- }
- else
- {
- throw new MojoExecutionException( "The packaging for this project did not assign "
- + "a file to the build artifact" );
+ } else if (!project.getAttachedArtifacts().isEmpty()) {
+ throw new MojoExecutionException("The packaging plugin for this project did not assign "
+ + "a main file to the project but it has attachments. Change packaging to 'pom'.");
+ } else {
+ throw new MojoExecutionException(
+ "The packaging for this project did not assign " + "a file to the build artifact");
}
}
- if ( !pomArtifactAttached )
- {
- throw new MojoExecutionException( "The POM could not be attached" );
+ if (!pomArtifactAttached) {
+ throw new MojoExecutionException("The POM could not be attached");
}
- for ( org.apache.maven.artifact.Artifact attached : project.getAttachedArtifacts() )
- {
- getLog().debug( "Attaching for install: " + attached.getId() );
- request.addArtifact( RepositoryUtils.toArtifact( attached ) );
+ for (org.apache.maven.artifact.Artifact attached : project.getAttachedArtifacts()) {
+ getLog().debug("Attaching for install: " + attached.getId());
+ request.addArtifact(RepositoryUtils.toArtifact(attached));
}
return request;
@@ -318,91 +287,72 @@ public class DeployMojo
/**
* Visible for testing.
*/
- RemoteRepository getDeploymentRepository( final MavenProject project,
- final String altSnapshotDeploymentRepository,
- final String altReleaseDeploymentRepository,
- final String altDeploymentRepository )
-
- throws MojoExecutionException, MojoFailureException
- {
+ RemoteRepository getDeploymentRepository(
+ final MavenProject project,
+ final String altSnapshotDeploymentRepository,
+ final String altReleaseDeploymentRepository,
+ final String altDeploymentRepository)
+ throws MojoExecutionException, MojoFailureException {
RemoteRepository repo = null;
String altDeploymentRepo;
- if ( ArtifactUtils.isSnapshot( project.getVersion() ) && altSnapshotDeploymentRepository != null )
- {
+ if (ArtifactUtils.isSnapshot(project.getVersion()) && altSnapshotDeploymentRepository != null) {
altDeploymentRepo = altSnapshotDeploymentRepository;
- }
- else if ( !ArtifactUtils.isSnapshot( project.getVersion() ) && altReleaseDeploymentRepository != null )
- {
+ } else if (!ArtifactUtils.isSnapshot(project.getVersion()) && altReleaseDeploymentRepository != null) {
altDeploymentRepo = altReleaseDeploymentRepository;
- }
- else
- {
+ } else {
altDeploymentRepo = altDeploymentRepository;
}
- if ( altDeploymentRepo != null )
- {
- getLog().info( "Using alternate deployment repository " + altDeploymentRepo );
+ if (altDeploymentRepo != null) {
+ getLog().info("Using alternate deployment repository " + altDeploymentRepo);
- Matcher matcher = ALT_LEGACY_REPO_SYNTAX_PATTERN.matcher( altDeploymentRepo );
+ Matcher matcher = ALT_LEGACY_REPO_SYNTAX_PATTERN.matcher(altDeploymentRepo);
- if ( matcher.matches() )
- {
- String id = matcher.group( 1 ).trim();
- String layout = matcher.group( 2 ).trim();
- String url = matcher.group( 3 ).trim();
+ if (matcher.matches()) {
+ String id = matcher.group(1).trim();
+ String layout = matcher.group(2).trim();
+ String url = matcher.group(3).trim();
- if ( "default".equals( layout ) )
- {
- getLog().warn( "Using legacy syntax for alternative repository. "
- + "Use \"" + id + "::" + url + "\" instead." );
- repo = getRemoteRepository( id, url );
- }
- else
- {
- throw new MojoFailureException( altDeploymentRepo,
+ if ("default".equals(layout)) {
+ getLog().warn("Using legacy syntax for alternative repository. " + "Use \"" + id + "::" + url
+ + "\" instead.");
+ repo = getRemoteRepository(id, url);
+ } else {
+ throw new MojoFailureException(
+ altDeploymentRepo,
"Invalid legacy syntax and layout for repository.",
- "Invalid legacy syntax and layout for alternative repository. Use \""
- + id + "::" + url + "\" instead, and only default layout is supported."
- );
+ "Invalid legacy syntax and layout for alternative repository. Use \"" + id + "::" + url
+ + "\" instead, and only default layout is supported.");
}
- }
- else
- {
- matcher = ALT_REPO_SYNTAX_PATTERN.matcher( altDeploymentRepo );
+ } else {
+ matcher = ALT_REPO_SYNTAX_PATTERN.matcher(altDeploymentRepo);
- if ( !matcher.matches() )
- {
- throw new MojoFailureException( altDeploymentRepo,
+ if (!matcher.matches()) {
+ throw new MojoFailureException(
+ altDeploymentRepo,
"Invalid syntax for repository.",
- "Invalid syntax for alternative repository. Use \"id::url\"."
- );
- }
- else
- {
- String id = matcher.group( 1 ).trim();
- String url = matcher.group( 2 ).trim();
+ "Invalid syntax for alternative repository. Use \"id::url\".");
+ } else {
+ String id = matcher.group(1).trim();
+ String url = matcher.group(2).trim();
- repo = getRemoteRepository( id, url );
+ repo = getRemoteRepository(id, url);
}
}
}
- if ( repo == null )
- {
- repo = RepositoryUtils.toRepo( project.getDistributionManagementArtifactRepository() );
+ if (repo == null) {
+ repo = RepositoryUtils.toRepo(project.getDistributionManagementArtifactRepository());
}
- if ( repo == null )
- {
+ if (repo == null) {
String msg = "Deployment failed: repository element was not specified in the POM inside"
- + " distributionManagement element or in -DaltDeploymentRepository=id::url parameter";
+ + " distributionManagement element or in -DaltDeploymentRepository=id::url parameter";
- throw new MojoExecutionException( msg );
+ throw new MojoExecutionException(msg);
}
return repo;
}
-
}
diff --git a/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoTest.java b/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoTest.java
index deb9fa3..f36e689 100644
--- a/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoTest.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.deploy;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@ package org.apache.maven.plugins.deploy;
* "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
+ * 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
@@ -18,9 +16,7 @@ package org.apache.maven.plugins.deploy;
* specific language governing permissions and limitations
* under the License.
*/
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
+package org.apache.maven.plugins.deploy;
import java.io.File;
import java.util.ArrayList;
@@ -32,20 +28,21 @@ import org.apache.maven.model.Model;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.apache.maven.project.ProjectBuildingRequest;
import org.eclipse.aether.DefaultRepositorySystemSession;
+import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
import org.eclipse.aether.repository.LocalRepository;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
/**
* @author <a href="mailto:aramirez@apache.org">Allan Ramirez</a>
*/
-public class DeployFileMojoTest
- extends AbstractMojoTestCase
-{
+public class DeployFileMojoTest extends AbstractMojoTestCase {
private final String LOCAL_REPO = getBasedir() + "/target/local-repo";
-
+
private List<String> expectedFiles;
private List<String> fileList;
@@ -54,263 +51,253 @@ public class DeployFileMojoTest
@Mock
private MavenSession session;
-
+
@InjectMocks
private DeployFileMojo mojo;
-
- public void setUp()
- throws Exception
- {
+
+ public void setUp() throws Exception {
super.setUp();
- remoteRepo = new File( getBasedir(), "target/remote-repo" );
+ remoteRepo = new File(getBasedir(), "target/remote-repo");
- if ( !remoteRepo.exists() )
- {
+ if (!remoteRepo.exists()) {
remoteRepo.mkdirs();
}
}
- public void testDeployTestEnvironment()
- throws Exception
- {
- File testPom = new File( getBasedir(), "target/test-classes/unit/deploy-file-test/plugin-config.xml" );
+ public void testDeployTestEnvironment() throws Exception {
+ File testPom = new File(getBasedir(), "target/test-classes/unit/deploy-file-test/plugin-config.xml");
- AbstractDeployMojo mojo = (AbstractDeployMojo) lookupMojo( "deploy-file", testPom );
+ AbstractDeployMojo mojo = (AbstractDeployMojo) lookupMojo("deploy-file", testPom);
- assertNotNull( mojo );
+ assertNotNull(mojo);
}
- public void testBasicDeployFile()
- throws Exception
- {
- File testPom = new File( getBasedir(), "target/test-classes/unit/deploy-file-test/plugin-config.xml" );
+ public void testBasicDeployFile() throws Exception {
+ File testPom = new File(getBasedir(), "target/test-classes/unit/deploy-file-test/plugin-config.xml");
+
+ mojo = (DeployFileMojo) lookupMojo("deploy-file", testPom);
+
+ MockitoAnnotations.initMocks(this);
- mojo = (DeployFileMojo) lookupMojo( "deploy-file", testPom );
+ assertNotNull(mojo);
- MockitoAnnotations.initMocks( this );
-
- assertNotNull( mojo );
-
- ProjectBuildingRequest buildingRequest = mock ( ProjectBuildingRequest.class );
- when( buildingRequest.getRepositoryMerging() ).thenReturn( ProjectBuildingRequest.RepositoryMerging.POM_DOMINANT );
- when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
+ ProjectBuildingRequest buildingRequest = mock(ProjectBuildingRequest.class);
+ when(buildingRequest.getRepositoryMerging()).thenReturn(ProjectBuildingRequest.RepositoryMerging.POM_DOMINANT);
+ when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
- repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManagerFactory().newInstance( repositorySession, new LocalRepository( LOCAL_REPO ) ) );
- when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );
- when( session.getRepositorySession() ).thenReturn( repositorySession );
+ repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory()
+ .newInstance(repositorySession, new LocalRepository(LOCAL_REPO)));
+ when(buildingRequest.getRepositorySession()).thenReturn(repositorySession);
+ when(session.getRepositorySession()).thenReturn(repositorySession);
- String groupId = (String) getVariableValueFromObject( mojo, "groupId" );
+ String groupId = (String) getVariableValueFromObject(mojo, "groupId");
- String artifactId = (String) getVariableValueFromObject( mojo, "artifactId" );
+ String artifactId = (String) getVariableValueFromObject(mojo, "artifactId");
- String version = (String) getVariableValueFromObject( mojo, "version" );
+ String version = (String) getVariableValueFromObject(mojo, "version");
- String packaging = (String) getVariableValueFromObject( mojo, "packaging" );
+ String packaging = (String) getVariableValueFromObject(mojo, "packaging");
- File file = (File) getVariableValueFromObject( mojo, "file" );
+ File file = (File) getVariableValueFromObject(mojo, "file");
- String repositoryId = (String) getVariableValueFromObject( mojo, "repositoryId" );
+ String repositoryId = (String) getVariableValueFromObject(mojo, "repositoryId");
- String url = (String) getVariableValueFromObject( mojo, "url" );
+ String url = (String) getVariableValueFromObject(mojo, "url");
- String skip = (String) getVariableValueFromObject( mojo, "skip" );
+ String skip = (String) getVariableValueFromObject(mojo, "skip");
- assertEquals( "org.apache.maven.test", groupId );
+ assertEquals("org.apache.maven.test", groupId);
- assertEquals( "maven-deploy-file-test", artifactId );
+ assertEquals("maven-deploy-file-test", artifactId);
- assertEquals( "1.0", version );
+ assertEquals("1.0", version);
- assertEquals( "jar", packaging );
+ assertEquals("jar", packaging);
- assertEquals( "snapshots", skip );
+ assertEquals("snapshots", skip);
- assertTrue( file.exists() );
+ assertTrue(file.exists());
- assertEquals( "deploy-test", repositoryId );
+ assertEquals("deploy-test", repositoryId);
+
+ assertEquals("file://" + getBasedir() + "/target/remote-repo/deploy-file-test", url);
- assertEquals( "file://" + getBasedir() + "/target/remote-repo/deploy-file-test", url );
-
mojo.execute();
- //check the generated pom
- File pom = new File( remoteRepo, "deploy-file-test/" + groupId.replace( '.', '/' ) +
- "/" + artifactId + "/" + version + "/" + artifactId +
- "-" + version + ".pom" );
+ // check the generated pom
+ File pom = new File(
+ remoteRepo,
+ "deploy-file-test/" + groupId.replace('.', '/') + "/"
+ + artifactId + "/" + version + "/" + artifactId + "-"
+ + version + ".pom");
- assertTrue( pom.exists() );
+ assertTrue(pom.exists());
- Model model = mojo.readModel( pom );
+ Model model = mojo.readModel(pom);
- assertEquals( "4.0.0", model.getModelVersion() );
+ assertEquals("4.0.0", model.getModelVersion());
- assertEquals( groupId, model.getGroupId() );
+ assertEquals(groupId, model.getGroupId());
- assertEquals( artifactId, model.getArtifactId() );
+ assertEquals(artifactId, model.getArtifactId());
- assertEquals( version, model.getVersion() );
+ assertEquals(version, model.getVersion());
- assertEquals( packaging, model.getPackaging() );
+ assertEquals(packaging, model.getPackaging());
- assertEquals( "POM was created from deploy:deploy-file", model.getDescription() );
+ assertEquals("POM was created from deploy:deploy-file", model.getDescription());
- //check the remote-repo
+ // check the remote-repo
expectedFiles = new ArrayList<>();
fileList = new ArrayList<>();
- File repo = new File( remoteRepo, "deploy-file-test" );
+ File repo = new File(remoteRepo, "deploy-file-test");
File[] files = repo.listFiles();
- for (File file1 : Objects.requireNonNull( files ) ) {
+ for (File file1 : Objects.requireNonNull(files)) {
addFileToList(file1, fileList);
}
- expectedFiles.add( "org" );
- expectedFiles.add( "apache" );
- expectedFiles.add( "maven" );
- expectedFiles.add( "test" );
- expectedFiles.add( "maven-deploy-file-test" );
- expectedFiles.add( "1.0" );
- expectedFiles.add( "maven-metadata.xml" );
- expectedFiles.add( "maven-metadata.xml.md5" );
- expectedFiles.add( "maven-metadata.xml.sha1" );
- expectedFiles.add( "maven-deploy-file-test-1.0.jar" );
- expectedFiles.add( "maven-deploy-file-test-1.0.jar.md5" );
- expectedFiles.add( "maven-deploy-file-test-1.0.jar.sha1" );
- expectedFiles.add( "maven-deploy-file-test-1.0.pom" );
- expectedFiles.add( "maven-deploy-file-test-1.0.pom.md5" );
- expectedFiles.add( "maven-deploy-file-test-1.0.pom.sha1" );
-
- assertEquals( expectedFiles.size(), fileList.size() );
-
- assertEquals( 0, getSizeOfExpectedFiles( fileList, expectedFiles ) );
+ expectedFiles.add("org");
+ expectedFiles.add("apache");
+ expectedFiles.add("maven");
+ expectedFiles.add("test");
+ expectedFiles.add("maven-deploy-file-test");
+ expectedFiles.add("1.0");
+ expectedFiles.add("maven-metadata.xml");
+ expectedFiles.add("maven-metadata.xml.md5");
+ expectedFiles.add("maven-metadata.xml.sha1");
+ expectedFiles.add("maven-deploy-file-test-1.0.jar");
+ expectedFiles.add("maven-deploy-file-test-1.0.jar.md5");
+ expectedFiles.add("maven-deploy-file-test-1.0.jar.sha1");
+ expectedFiles.add("maven-deploy-file-test-1.0.pom");
+ expectedFiles.add("maven-deploy-file-test-1.0.pom.md5");
+ expectedFiles.add("maven-deploy-file-test-1.0.pom.sha1");
+
+ assertEquals(expectedFiles.size(), fileList.size());
+
+ assertEquals(0, getSizeOfExpectedFiles(fileList, expectedFiles));
}
- public void testDeployIfClassifierIsSet()
- throws Exception
- {
- File testPom = new File( getBasedir(), "target/test-classes/unit/deploy-file-classifier/plugin-config.xml" );
+ public void testDeployIfClassifierIsSet() throws Exception {
+ File testPom = new File(getBasedir(), "target/test-classes/unit/deploy-file-classifier/plugin-config.xml");
+
+ mojo = (DeployFileMojo) lookupMojo("deploy-file", testPom);
+
+ MockitoAnnotations.initMocks(this);
- mojo = (DeployFileMojo) lookupMojo( "deploy-file", testPom );
+ assertNotNull(mojo);
- MockitoAnnotations.initMocks( this );
-
- assertNotNull( mojo );
-
- ProjectBuildingRequest buildingRequest = mock ( ProjectBuildingRequest.class );
- when( buildingRequest.getRepositoryMerging() ).thenReturn( ProjectBuildingRequest.RepositoryMerging.POM_DOMINANT );
- when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
+ ProjectBuildingRequest buildingRequest = mock(ProjectBuildingRequest.class);
+ when(buildingRequest.getRepositoryMerging()).thenReturn(ProjectBuildingRequest.RepositoryMerging.POM_DOMINANT);
+ when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
- repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManagerFactory().newInstance( repositorySession, new LocalRepository( LOCAL_REPO ) ) );
- when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );
- when( session.getRepositorySession() ).thenReturn( repositorySession );
+ repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory()
+ .newInstance(repositorySession, new LocalRepository(LOCAL_REPO)));
+ when(buildingRequest.getRepositorySession()).thenReturn(repositorySession);
+ when(session.getRepositorySession()).thenReturn(repositorySession);
- String classifier = ( String ) getVariableValueFromObject( mojo, "classifier" );
+ String classifier = (String) getVariableValueFromObject(mojo, "classifier");
- String groupId = ( String ) getVariableValueFromObject( mojo, "groupId" );
+ String groupId = (String) getVariableValueFromObject(mojo, "groupId");
- String artifactId = ( String ) getVariableValueFromObject( mojo, "artifactId" );
+ String artifactId = (String) getVariableValueFromObject(mojo, "artifactId");
- String version = ( String ) getVariableValueFromObject( mojo, "version" );
+ String version = (String) getVariableValueFromObject(mojo, "version");
- assertEquals( "bin", classifier );
+ assertEquals("bin", classifier);
mojo.execute();
- File deployedArtifact = new File( remoteRepo, "deploy-file-classifier/" + groupId.replace( '.', '/' ) +
- "/" + artifactId + "/" + version + "/" + artifactId +
- "-" + version + "-" + classifier + ".jar");
+ File deployedArtifact = new File(
+ remoteRepo,
+ "deploy-file-classifier/" + groupId.replace('.', '/') + "/"
+ + artifactId + "/" + version + "/" + artifactId + "-"
+ + version + "-" + classifier + ".jar");
- assertTrue( deployedArtifact.exists() );
+ assertTrue(deployedArtifact.exists());
- mojo.setClassifier( "prod" );
+ mojo.setClassifier("prod");
- assertEquals( "prod", mojo.getClassifier() );
+ assertEquals("prod", mojo.getClassifier());
mojo.execute();
- File prodDeployedArtifact = new File( remoteRepo, "deploy-file-classifier/" + groupId.replace( '.', '/' ) +
- "/" + artifactId + "/" + version + "/" + artifactId +
- "-" + version + "-" + mojo.getClassifier() + ".jar");
+ File prodDeployedArtifact = new File(
+ remoteRepo,
+ "deploy-file-classifier/" + groupId.replace('.', '/') + "/"
+ + artifactId + "/" + version + "/" + artifactId + "-"
+ + version + "-" + mojo.getClassifier() + ".jar");
- assertTrue( prodDeployedArtifact.exists() );
+ assertTrue(prodDeployedArtifact.exists());
}
- public void testDeployIfArtifactIsNotJar()
- throws Exception
- {
- File testPom = new File( getBasedir(), "target/test-classes/unit/deploy-file-artifact-not-jar/plugin-config.xml" );
+ public void testDeployIfArtifactIsNotJar() throws Exception {
+ File testPom =
+ new File(getBasedir(), "target/test-classes/unit/deploy-file-artifact-not-jar/plugin-config.xml");
- mojo = (DeployFileMojo) lookupMojo( "deploy-file", testPom );
+ mojo = (DeployFileMojo) lookupMojo("deploy-file", testPom);
- MockitoAnnotations.initMocks( this );
-
- assertNotNull( mojo );
-
- ProjectBuildingRequest buildingRequest = mock ( ProjectBuildingRequest.class );
- when( buildingRequest.getRepositoryMerging() ).thenReturn( ProjectBuildingRequest.RepositoryMerging.POM_DOMINANT );
- when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
+ MockitoAnnotations.initMocks(this);
+
+ assertNotNull(mojo);
+
+ ProjectBuildingRequest buildingRequest = mock(ProjectBuildingRequest.class);
+ when(buildingRequest.getRepositoryMerging()).thenReturn(ProjectBuildingRequest.RepositoryMerging.POM_DOMINANT);
+ when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
- repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManagerFactory().newInstance( repositorySession, new LocalRepository( LOCAL_REPO ) ) );
- when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );
- when( session.getRepositorySession() ).thenReturn( repositorySession );
+ repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory()
+ .newInstance(repositorySession, new LocalRepository(LOCAL_REPO)));
+ when(buildingRequest.getRepositorySession()).thenReturn(repositorySession);
+ when(session.getRepositorySession()).thenReturn(repositorySession);
- String groupId = (String) getVariableValueFromObject( mojo, "groupId" );
+ String groupId = (String) getVariableValueFromObject(mojo, "groupId");
- String artifactId = (String) getVariableValueFromObject( mojo, "artifactId" );
+ String artifactId = (String) getVariableValueFromObject(mojo, "artifactId");
- String version = (String) getVariableValueFromObject( mojo, "version" );
+ String version = (String) getVariableValueFromObject(mojo, "version");
- assertEquals( "org.apache.maven.test", groupId );
+ assertEquals("org.apache.maven.test", groupId);
- assertEquals( "maven-deploy-file-test", artifactId );
+ assertEquals("maven-deploy-file-test", artifactId);
- assertEquals( "1.0", version );
+ assertEquals("1.0", version);
mojo.execute();
- File file = new File( remoteRepo, "deploy-file-artifact-not-jar/" + groupId.replace( '.', '/' ) +
- "/" + artifactId + "/" + version + "/" + artifactId +
- "-" + version + ".zip");
+ File file = new File(
+ remoteRepo,
+ "deploy-file-artifact-not-jar/" + groupId.replace('.', '/') + "/"
+ + artifactId + "/" + version + "/" + artifactId + "-"
+ + version + ".zip");
- assertTrue( file.exists() );
+ assertTrue(file.exists());
}
- private void addFileToList( File file, List<String> fileList )
- {
- if ( !file.isDirectory() )
- {
- fileList.add( file.getName() );
- }
- else
- {
- fileList.add( file.getName() );
+ private void addFileToList(File file, List<String> fileList) {
+ if (!file.isDirectory()) {
+ fileList.add(file.getName());
+ } else {
+ fileList.add(file.getName());
File[] files = file.listFiles();
- for (File file1 : Objects.requireNonNull( files ) ) {
+ for (File file1 : Objects.requireNonNull(files)) {
addFileToList(file1, fileList);
}
}
}
- private int getSizeOfExpectedFiles( List<String> fileList, List<String> expectedFiles )
- {
- for ( String fileName : fileList )
- {
- if ( expectedFiles.contains( fileName ) )
- {
- expectedFiles.remove( fileName );
- }
- else
- {
- fail( fileName + " is not included in the expected files" );
+ private int getSizeOfExpectedFiles(List<String> fileList, List<String> expectedFiles) {
+ for (String fileName : fileList) {
+ if (expectedFiles.contains(fileName)) {
+ expectedFiles.remove(fileName);
+ } else {
+ fail(fileName + " is not included in the expected files");
}
}
return expectedFiles.size();
}
-
}
-
diff --git a/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoUnitTest.java b/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoUnitTest.java
index 0edf72f..c368b36 100644
--- a/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoUnitTest.java
+++ b/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoUnitTest.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.deploy;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@ package org.apache.maven.plugins.deploy;
* "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
+ * 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
@@ -18,6 +16,9 @@ package org.apache.maven.plugins.deploy;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.deploy;
+
+import java.io.File;
import org.apache.maven.model.Model;
import org.apache.maven.model.Parent;
@@ -26,36 +27,31 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import java.io.File;
-
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* @author <a href="jerome@coffeebreaks.org">Jerome Lacoste</a>
*/
-public class DeployFileMojoUnitTest
-{
+public class DeployFileMojoUnitTest {
MockDeployFileMojo mojo;
Parent parent;
@Before
- public void setUp()
- {
+ public void setUp() {
Model pomModel = new Model();
- pomModel.setPackaging( null );
+ pomModel.setPackaging(null);
parent = new Parent();
- parent.setGroupId( "parentGroup" );
- parent.setArtifactId( "parentArtifact" );
- parent.setVersion( "parentVersion" );
+ parent.setGroupId("parentGroup");
+ parent.setArtifactId("parentArtifact");
+ parent.setVersion("parentVersion");
- mojo = new MockDeployFileMojo( pomModel );
+ mojo = new MockDeployFileMojo(pomModel);
}
@After
- public void tearDown()
- {
+ public void tearDown() {
mojo = null;
}
@@ -70,64 +66,58 @@ public class DeployFileMojoUnitTest
this.model = model;
}
- protected Model readModel(File pomFile)
- {
+ protected Model readModel(File pomFile) {
return model;
}
}
@Test
- public void testProcessPomFromPomFileWithParent1()
- {
- mojo.setPomFile( new File( "foo.bar" ) );
+ public void testProcessPomFromPomFileWithParent1() {
+ mojo.setPomFile(new File("foo.bar"));
- setMojoModel( mojo.model, null, null, null, null, parent );
+ setMojoModel(mojo.model, null, null, null, null, parent);
try {
mojo.initProperties();
} catch (MojoExecutionException expected) {
- assertTrue( true ); // missing artifactId and packaging
+ assertTrue(true); // missing artifactId and packaging
}
checkMojoProperties("parentGroup", null, "parentVersion", null);
}
@Test
- public void testProcessPomFromPomFileWithParent2()
- {
- mojo.setPomFile( new File( "foo.bar" ) );
- setMojoModel( mojo.model, null, "artifact", null, null, parent );
+ public void testProcessPomFromPomFileWithParent2() {
+ mojo.setPomFile(new File("foo.bar"));
+ setMojoModel(mojo.model, null, "artifact", null, null, parent);
try {
mojo.initProperties();
} catch (MojoExecutionException expected) {
- assertTrue( true ); // missing packaging
+ assertTrue(true); // missing packaging
}
- checkMojoProperties("parentGroup", "artifact", "parentVersion", null );
-
+ checkMojoProperties("parentGroup", "artifact", "parentVersion", null);
}
@Test
- public void testProcessPomFromPomFileWithParent3()
- {
- mojo.setPomFile( new File( "foo.bar" ) );
- setMojoModel( mojo.model, null, "artifact", "version", null, parent );
+ public void testProcessPomFromPomFileWithParent3() {
+ mojo.setPomFile(new File("foo.bar"));
+ setMojoModel(mojo.model, null, "artifact", "version", null, parent);
try {
mojo.initProperties();
} catch (MojoExecutionException expected) {
- assertTrue( true ); // missing version and packaging
+ assertTrue(true); // missing version and packaging
}
- checkMojoProperties( "parentGroup", "artifact", "version", null );
+ checkMojoProperties("parentGroup", "artifact", "version", null);
}
@Test
- public void testProcessPomFromPomFileWithParent4() throws MojoExecutionException
- {
- mojo.setPomFile( new File( "foo.bar" ) );
- setMojoModel( mojo.model, null, "artifact", "version", "packaging", parent );
+ public void testProcessPomFromPomFileWithParent4() throws MojoExecutionException {
+ mojo.setPomFile(new File("foo.bar"));
+ setMojoModel(mojo.model, null, "artifact", "version", "packaging", parent);
mojo.initProperties();
@@ -135,10 +125,9 @@ public class DeployFileMojoUnitTest
}
@Test
- public void testProcessPomFromPomFileWithParent5() throws MojoExecutionException
- {
- mojo.setPomFile( new File( "foo.bar" ) );
- setMojoModel( mojo.model, "group", "artifact", "version", "packaging", parent );
+ public void testProcessPomFromPomFileWithParent5() throws MojoExecutionException {
+ mojo.setPomFile(new File("foo.bar"));
+ setMojoModel(mojo.model, "group", "artifact", "version", "packaging", parent);
mojo.initProperties();
@@ -146,46 +135,47 @@ public class DeployFileMojoUnitTest
}
@Test
- public void testProcessPomFromPomFileWithParent6() throws MojoExecutionException
- {
- mojo.setPomFile( new File( "foo.bar" ) );
- setMojoModel( mojo.model, "group", "artifact", "version", "packaging", null );
+ public void testProcessPomFromPomFileWithParent6() throws MojoExecutionException {
+ mojo.setPomFile(new File("foo.bar"));
+ setMojoModel(mojo.model, "group", "artifact", "version", "packaging", null);
mojo.initProperties();
checkMojoProperties("group", "artifact", "version", "packaging");
-
}
@Test
- public void testProcessPomFromPomFileWithOverrides() throws MojoExecutionException
- {
- mojo.setPomFile( new File( "foo.bar" ) );
- setMojoModel( mojo.model, "group", "artifact", "version", "packaging", null );
+ public void testProcessPomFromPomFileWithOverrides() throws MojoExecutionException {
+ mojo.setPomFile(new File("foo.bar"));
+ setMojoModel(mojo.model, "group", "artifact", "version", "packaging", null);
- mojo.setGroupId( "groupO" );
- mojo.setArtifactId( "artifactO" );
- mojo.setVersion( "versionO" );
- mojo.setPackaging( "packagingO" );
+ mojo.setGroupId("groupO");
+ mojo.setArtifactId("artifactO");
+ mojo.setVersion("versionO");
+ mojo.setPackaging("packagingO");
mojo.initProperties();
checkMojoProperties("groupO", "artifactO", "versionO", "packagingO");
}
- private void checkMojoProperties(final String expectedGroup, final String expectedArtifact, final String expectedVersion, final String expectedPackaging) {
- assertEquals( expectedGroup, mojo.getGroupId() );
- assertEquals( expectedArtifact, mojo.getArtifactId() );
- assertEquals( expectedVersion, mojo.getVersion() );
- assertEquals( expectedPackaging, mojo.getPackaging() );
+ private void checkMojoProperties(
+ final String expectedGroup,
+ final String expectedArtifact,
+ final String expectedVersion,
+ final String expectedPackaging) {
+ assertEquals(expectedGroup, mojo.getGroupId());
+ assertEquals(expectedArtifact, mojo.getArtifactId());
+ assertEquals(expectedVersion, mojo.getVersion());
+ assertEquals(expectedPackaging, mojo.getPackaging());
}
- private void setMojoModel(Model model, String group, String artifact, String version, String packaging, Parent parent ) {
- model.setGroupId( group );
- model.setArtifactId( artifact );
- model.setVersion( version );
- model.setPackaging( packaging );
- model.setParent( parent );
+ private void setMojoModel(
+ Model model, String group, String artifact, String version, String packaging, Parent parent) {
+ model.setGroupId(group);
+ model.setArtifactId(artifact);
+ model.setVersion(version);
+ model.setPackaging(packaging);
+ model.setParent(parent);
}
-
}
diff --git a/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java b/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java
index 54bc16f..b99d717 100644
--- a/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.deploy;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@ package org.apache.maven.plugins.deploy;
* "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
+ * 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
@@ -18,12 +16,7 @@ package org.apache.maven.plugins.deploy;
* specific language governing permissions and limitations
* under the License.
*/
-
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
+package org.apache.maven.plugins.deploy;
import java.io.File;
import java.util.ArrayList;
@@ -46,707 +39,671 @@ import org.apache.maven.project.ProjectBuildingRequest;
import org.codehaus.plexus.util.FileUtils;
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositorySystem;
+import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
import org.eclipse.aether.repository.LocalRepository;
import org.eclipse.aether.repository.RemoteRepository;
import org.junit.Ignore;
import org.mockito.InjectMocks;
import org.mockito.MockitoAnnotations;
-import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
/**
* @author <a href="mailto:aramirez@apache.org">Allan Ramirez</a>
*/
-public class DeployMojoTest
- extends AbstractMojoTestCase
-{
+public class DeployMojoTest extends AbstractMojoTestCase {
private File remoteRepo;
-
+
private File localRepo;
-
+
private final String LOCAL_REPO = getBasedir() + "/target/local-repo";
-
+
private final String REMOTE_REPO = getBasedir() + "/target/remote-repo";
-
+
DeployArtifactStub artifact;
-
+
final MavenProjectStub project = new MavenProjectStub();
private MavenSession session;
-
+
@InjectMocks
private DeployMojo mojo;
- public void setUp()
- throws Exception
- {
+ public void setUp() throws Exception {
super.setUp();
- session = mock( MavenSession.class );
- when( session.getPluginContext(any(PluginDescriptor.class), any(MavenProject.class)))
- .thenReturn( new ConcurrentHashMap<String, Object>() );
+ session = mock(MavenSession.class);
+ when(session.getPluginContext(any(PluginDescriptor.class), any(MavenProject.class)))
+ .thenReturn(new ConcurrentHashMap<String, Object>());
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
- repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManagerFactory().newInstance( repositorySession, new LocalRepository( LOCAL_REPO ) ) );
- when( session.getRepositorySession() ).thenReturn( repositorySession );
-
- remoteRepo = new File( REMOTE_REPO );
-
- remoteRepo.mkdirs();
-
- localRepo = new File( LOCAL_REPO );
-
- if ( localRepo.exists() )
- {
- FileUtils.deleteDirectory( localRepo );
+ repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory()
+ .newInstance(repositorySession, new LocalRepository(LOCAL_REPO)));
+ when(session.getRepositorySession()).thenReturn(repositorySession);
+
+ remoteRepo = new File(REMOTE_REPO);
+
+ remoteRepo.mkdirs();
+
+ localRepo = new File(LOCAL_REPO);
+
+ if (localRepo.exists()) {
+ FileUtils.deleteDirectory(localRepo);
}
- if ( remoteRepo.exists() )
- {
- FileUtils.deleteDirectory( remoteRepo );
+ if (remoteRepo.exists()) {
+ FileUtils.deleteDirectory(remoteRepo);
}
}
- public void tearDown()
- throws Exception
- {
+ public void tearDown() throws Exception {
super.tearDown();
-
- if( remoteRepo.exists() )
- {
- //FileUtils.deleteDirectory( remoteRepo );
+
+ if (remoteRepo.exists()) {
+ // FileUtils.deleteDirectory( remoteRepo );
}
}
-
- public void testDeployTestEnvironment()
- throws Exception
- {
- File testPom = new File( getBasedir(),
- "target/test-classes/unit/basic-deploy-test/plugin-config.xml" );
-
- DeployMojo mojo = ( DeployMojo ) lookupMojo( "deploy", testPom );
-
- assertNotNull( mojo );
+
+ public void testDeployTestEnvironment() throws Exception {
+ File testPom = new File(getBasedir(), "target/test-classes/unit/basic-deploy-test/plugin-config.xml");
+
+ DeployMojo mojo = (DeployMojo) lookupMojo("deploy", testPom);
+
+ assertNotNull(mojo);
}
-
- public void testBasicDeploy()
- throws Exception
- {
- File testPom = new File( getBasedir(), "target/test-classes/unit/basic-deploy-test/plugin-config.xml" );
-
- mojo = ( DeployMojo ) lookupMojo( "deploy", testPom );
-
- MockitoAnnotations.initMocks( this );
-
- assertNotNull( mojo );
-
- ProjectBuildingRequest buildingRequest = mock ( ProjectBuildingRequest.class );
- when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
+
+ public void testBasicDeploy() throws Exception {
+ File testPom = new File(getBasedir(), "target/test-classes/unit/basic-deploy-test/plugin-config.xml");
+
+ mojo = (DeployMojo) lookupMojo("deploy", testPom);
+
+ MockitoAnnotations.initMocks(this);
+
+ assertNotNull(mojo);
+
+ ProjectBuildingRequest buildingRequest = mock(ProjectBuildingRequest.class);
+ when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
- repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManagerFactory().newInstance( repositorySession, new LocalRepository( LOCAL_REPO ) ) );
- when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );
- when( session.getRepositorySession() ).thenReturn( repositorySession );
+ repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory()
+ .newInstance(repositorySession, new LocalRepository(LOCAL_REPO)));
+ when(buildingRequest.getRepositorySession()).thenReturn(repositorySession);
+ when(session.getRepositorySession()).thenReturn(repositorySession);
- File file = new File( getBasedir(),
- "target/test-classes/unit/basic-deploy-test/target/" +
- "deploy-test-file-1.0-SNAPSHOT.jar" );
+ File file = new File(
+ getBasedir(),
+ "target/test-classes/unit/basic-deploy-test/target/" + "deploy-test-file-1.0-SNAPSHOT.jar");
- assertTrue( file.exists() );
+ assertTrue(file.exists());
- MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" );
- project.setGroupId( "org.apache.maven.test" );
- project.setArtifactId( "maven-deploy-test" );
- project.setVersion( "1.0-SNAPSHOT" );
+ MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
+ project.setGroupId("org.apache.maven.test");
+ project.setArtifactId("maven-deploy-test");
+ project.setVersion("1.0-SNAPSHOT");
- setVariableValueToObject( mojo, "pluginContext", new ConcurrentHashMap<>() );
- setVariableValueToObject( mojo, "reactorProjects", Collections.singletonList( project ) );
-
- artifact = ( DeployArtifactStub ) project.getArtifact();
+ setVariableValueToObject(mojo, "pluginContext", new ConcurrentHashMap<>());
+ setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project));
+
+ artifact = (DeployArtifactStub) project.getArtifact();
String packaging = project.getPackaging();
-
- assertEquals( "jar", packaging );
-
- artifact.setFile( file );
-
- ArtifactRepositoryStub repo = getRepoStub( mojo );
-
- assertNotNull( repo );
-
- repo.setAppendToUrl( "basic-deploy-test" );
-
- assertEquals( "deploy-test", repo.getId() );
- assertEquals( "deploy-test", repo.getKey() );
- assertEquals( "file", repo.getProtocol() );
- assertEquals( "file://" + getBasedir() + "/target/remote-repo/basic-deploy-test", repo.getUrl() );
-
+
+ assertEquals("jar", packaging);
+
+ artifact.setFile(file);
+
+ ArtifactRepositoryStub repo = getRepoStub(mojo);
+
+ assertNotNull(repo);
+
+ repo.setAppendToUrl("basic-deploy-test");
+
+ assertEquals("deploy-test", repo.getId());
+ assertEquals("deploy-test", repo.getKey());
+ assertEquals("file", repo.getProtocol());
+ assertEquals("file://" + getBasedir() + "/target/remote-repo/basic-deploy-test", repo.getUrl());
+
mojo.execute();
- //check the artifact in local repository
+ // check the artifact in local repository
List<String> expectedFiles = new ArrayList<>();
List<String> fileList = new ArrayList<>();
-
- expectedFiles.add( "org" );
- expectedFiles.add( "apache" );
- expectedFiles.add( "maven" );
- expectedFiles.add( "test" );
- expectedFiles.add( "maven-deploy-test" );
- expectedFiles.add( "1.0-SNAPSHOT" );
- expectedFiles.add( "maven-metadata-deploy-test.xml" );
+
+ expectedFiles.add("org");
+ expectedFiles.add("apache");
+ expectedFiles.add("maven");
+ expectedFiles.add("test");
+ expectedFiles.add("maven-deploy-test");
+ expectedFiles.add("1.0-SNAPSHOT");
+ expectedFiles.add("maven-metadata-deploy-test.xml");
// expectedFiles.add( "maven-deploy-test-1.0-SNAPSHOT.jar" );
// expectedFiles.add( "maven-deploy-test-1.0-SNAPSHOT.pom" );
// as we are in SNAPSHOT the file is here twice
- expectedFiles.add( "maven-metadata-deploy-test.xml" );
+ expectedFiles.add("maven-metadata-deploy-test.xml");
// extra Aether files
- expectedFiles.add( "resolver-status.properties" );
- expectedFiles.add( "resolver-status.properties" );
-
- File localRepo = new File( LOCAL_REPO, "" );
-
+ expectedFiles.add("resolver-status.properties");
+ expectedFiles.add("resolver-status.properties");
+
+ File localRepo = new File(LOCAL_REPO, "");
+
File[] files = localRepo.listFiles();
- for (File file2 : Objects.requireNonNull( files ) ) {
+ for (File file2 : Objects.requireNonNull(files)) {
addFileToList(file2, fileList);
}
-
- assertEquals( expectedFiles.size(), fileList.size() );
- assertEquals( 0, getSizeOfExpectedFiles( fileList, expectedFiles ) );
-
- //check the artifact in remote repository
+ assertEquals(expectedFiles.size(), fileList.size());
+
+ assertEquals(0, getSizeOfExpectedFiles(fileList, expectedFiles));
+
+ // check the artifact in remote repository
expectedFiles = new ArrayList<>();
fileList = new ArrayList<>();
-
- expectedFiles.add( "org" );
- expectedFiles.add( "apache" );
- expectedFiles.add( "maven" );
- expectedFiles.add( "test" );
- expectedFiles.add( "maven-deploy-test" );
- expectedFiles.add( "1.0-SNAPSHOT" );
- expectedFiles.add( "maven-metadata.xml" );
- expectedFiles.add( "maven-metadata.xml.md5" );
- expectedFiles.add( "maven-metadata.xml.sha1" );
- expectedFiles.add( "maven-deploy-test-1.0-SNAPSHOT.jar" );
- expectedFiles.add( "maven-deploy-test-1.0-SNAPSHOT.jar.md5" );
- expectedFiles.add( "maven-deploy-test-1.0-SNAPSHOT.jar.sha1" );
- expectedFiles.add( "maven-deploy-test-1.0-SNAPSHOT.pom" );
- expectedFiles.add( "maven-deploy-test-1.0-SNAPSHOT.pom.md5" );
- expectedFiles.add( "maven-deploy-test-1.0-SNAPSHOT.pom.sha1" );
+
+ expectedFiles.add("org");
+ expectedFiles.add("apache");
+ expectedFiles.add("maven");
+ expectedFiles.add("test");
+ expectedFiles.add("maven-deploy-test");
+ expectedFiles.add("1.0-SNAPSHOT");
+ expectedFiles.add("maven-metadata.xml");
+ expectedFiles.add("maven-metadata.xml.md5");
+ expectedFiles.add("maven-metadata.xml.sha1");
+ expectedFiles.add("maven-deploy-test-1.0-SNAPSHOT.jar");
+ expectedFiles.add("maven-deploy-test-1.0-SNAPSHOT.jar.md5");
+ expectedFiles.add("maven-deploy-test-1.0-SNAPSHOT.jar.sha1");
+ expectedFiles.add("maven-deploy-test-1.0-SNAPSHOT.pom");
+ expectedFiles.add("maven-deploy-test-1.0-SNAPSHOT.pom.md5");
+ expectedFiles.add("maven-deploy-test-1.0-SNAPSHOT.pom.sha1");
// as we are in SNAPSHOT the file is here twice
- expectedFiles.add( "maven-metadata.xml" );
- expectedFiles.add( "maven-metadata.xml.md5" );
- expectedFiles.add( "maven-metadata.xml.sha1" );
-
- remoteRepo = new File( remoteRepo, "basic-deploy-test" );
-
+ expectedFiles.add("maven-metadata.xml");
+ expectedFiles.add("maven-metadata.xml.md5");
+ expectedFiles.add("maven-metadata.xml.sha1");
+
+ remoteRepo = new File(remoteRepo, "basic-deploy-test");
+
files = remoteRepo.listFiles();
- for (File file1 : Objects.requireNonNull( files ) ) {
+ for (File file1 : Objects.requireNonNull(files)) {
addFileToList(file1, fileList);
}
-
- assertEquals( expectedFiles.size(), fileList.size() );
- assertEquals( 0, getSizeOfExpectedFiles( fileList, expectedFiles ) );
+ assertEquals(expectedFiles.size(), fileList.size());
+
+ assertEquals(0, getSizeOfExpectedFiles(fileList, expectedFiles));
}
- public void testSkippingDeploy()
- throws Exception
- {
- File testPom = new File( getBasedir(), "target/test-classes/unit/basic-deploy-test/plugin-config.xml" );
+ public void testSkippingDeploy() throws Exception {
+ File testPom = new File(getBasedir(), "target/test-classes/unit/basic-deploy-test/plugin-config.xml");
- DeployMojo mojo = (DeployMojo) lookupMojo( "deploy", testPom );
+ DeployMojo mojo = (DeployMojo) lookupMojo("deploy", testPom);
- assertNotNull( mojo );
+ assertNotNull(mojo);
- File file = new File( getBasedir(), "target/test-classes/unit/basic-deploy-test/target/"
- + "deploy-test-file-1.0-SNAPSHOT.jar" );
+ File file = new File(
+ getBasedir(),
+ "target/test-classes/unit/basic-deploy-test/target/" + "deploy-test-file-1.0-SNAPSHOT.jar");
- assertTrue( file.exists() );
+ assertTrue(file.exists());
- MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" );
+ MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
- setVariableValueToObject( mojo, "pluginDescriptor", new PluginDescriptor() );
- setVariableValueToObject( mojo, "pluginContext", new ConcurrentHashMap<>() );
- setVariableValueToObject( mojo, "reactorProjects", Collections.singletonList( project ) );
- setVariableValueToObject( mojo, "session", session );
+ setVariableValueToObject(mojo, "pluginDescriptor", new PluginDescriptor());
+ setVariableValueToObject(mojo, "pluginContext", new ConcurrentHashMap<>());
+ setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project));
+ setVariableValueToObject(mojo, "session", session);
artifact = (DeployArtifactStub) project.getArtifact();
String packaging = project.getPackaging();
- assertEquals( "jar", packaging );
+ assertEquals("jar", packaging);
+
+ artifact.setFile(file);
- artifact.setFile( file );
+ ArtifactRepositoryStub repo = getRepoStub(mojo);
- ArtifactRepositoryStub repo = getRepoStub( mojo );
+ assertNotNull(repo);
- assertNotNull( repo );
+ repo.setAppendToUrl("basic-deploy-test");
- repo.setAppendToUrl( "basic-deploy-test" );
+ assertEquals("deploy-test", repo.getId());
+ assertEquals("deploy-test", repo.getKey());
+ assertEquals("file", repo.getProtocol());
+ assertEquals("file://" + getBasedir() + "/target/remote-repo/basic-deploy-test", repo.getUrl());
- assertEquals( "deploy-test", repo.getId() );
- assertEquals( "deploy-test", repo.getKey() );
- assertEquals( "file", repo.getProtocol() );
- assertEquals( "file://" + getBasedir() + "/target/remote-repo/basic-deploy-test", repo.getUrl() );
+ setVariableValueToObject(mojo, "skip", Boolean.TRUE.toString());
- setVariableValueToObject( mojo, "skip", Boolean.TRUE.toString() );
-
mojo.execute();
- File localRepo = new File( LOCAL_REPO, "" );
+ File localRepo = new File(LOCAL_REPO, "");
File[] files = localRepo.listFiles();
- assertNull( files );
-
- remoteRepo = new File( remoteRepo, "basic-deploy-test" );
+ assertNull(files);
+
+ remoteRepo = new File(remoteRepo, "basic-deploy-test");
files = remoteRepo.listFiles();
- assertNull( files );
- }
-
- public void testBasicDeployWithPackagingAsPom()
- throws Exception
- {
- File testPom = new File( getBasedir(),
- "target/test-classes/unit/basic-deploy-pom/plugin-config.xml" );
-
- mojo = ( DeployMojo ) lookupMojo( "deploy", testPom );
-
- MockitoAnnotations.initMocks( this );
-
- assertNotNull( mojo );
-
- ProjectBuildingRequest buildingRequest = mock ( ProjectBuildingRequest.class );
- when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
+ assertNull(files);
+ }
+
+ public void testBasicDeployWithPackagingAsPom() throws Exception {
+ File testPom = new File(getBasedir(), "target/test-classes/unit/basic-deploy-pom/plugin-config.xml");
+
+ mojo = (DeployMojo) lookupMojo("deploy", testPom);
+
+ MockitoAnnotations.initMocks(this);
+
+ assertNotNull(mojo);
+
+ ProjectBuildingRequest buildingRequest = mock(ProjectBuildingRequest.class);
+ when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
- repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManagerFactory().newInstance( repositorySession, new LocalRepository( LOCAL_REPO ) ) );
- when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );
- when( session.getRepositorySession() ).thenReturn( repositorySession );
-
- File pomFile = new File( getBasedir(),
- "target/test-classes/unit/basic-deploy-pom/target/" +
- "deploy-test-file-1.0-SNAPSHOT.pom" );
-
- assertTrue( pomFile.exists() );
-
- MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" );
- project.setGroupId( "org.apache.maven.test" );
- project.setArtifactId( "maven-deploy-test" );
- project.setVersion( "1.0-SNAPSHOT" );
-
- setVariableValueToObject( mojo, "pluginContext", new ConcurrentHashMap<>() );
- setVariableValueToObject( mojo, "reactorProjects", Collections.singletonList( project ) );
+ repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory()
+ .newInstance(repositorySession, new LocalRepository(LOCAL_REPO)));
+ when(buildingRequest.getRepositorySession()).thenReturn(repositorySession);
+ when(session.getRepositorySession()).thenReturn(repositorySession);
+
+ File pomFile = new File(
+ getBasedir(),
+ "target/test-classes/unit/basic-deploy-pom/target/" + "deploy-test-file-1.0-SNAPSHOT.pom");
+
+ assertTrue(pomFile.exists());
+
+ MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
+ project.setGroupId("org.apache.maven.test");
+ project.setArtifactId("maven-deploy-test");
+ project.setVersion("1.0-SNAPSHOT");
+
+ setVariableValueToObject(mojo, "pluginContext", new ConcurrentHashMap<>());
+ setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project));
artifact = (DeployArtifactStub) project.getArtifact();
-
- artifact.setArtifactHandlerExtension( project.getPackaging() );
-
- artifact.setFile( pomFile );
-
- ArtifactRepositoryStub repo = getRepoStub( mojo );
-
- repo.setAppendToUrl( "basic-deploy-pom" );
-
+
+ artifact.setArtifactHandlerExtension(project.getPackaging());
+
+ artifact.setFile(pomFile);
+
+ ArtifactRepositoryStub repo = getRepoStub(mojo);
+
+ repo.setAppendToUrl("basic-deploy-pom");
+
mojo.execute();
-
+
List<String> expectedFiles = new ArrayList<>();
List<String> fileList = new ArrayList<>();
-
- expectedFiles.add( "org" );
- expectedFiles.add( "apache" );
- expectedFiles.add( "maven" );
- expectedFiles.add( "test" );
- expectedFiles.add( "maven-deploy-test" );
- expectedFiles.add( "1.0-SNAPSHOT" );
- expectedFiles.add( "maven-metadata.xml" );
- expectedFiles.add( "maven-metadata.xml.md5" );
- expectedFiles.add( "maven-metadata.xml.sha1" );
- expectedFiles.add( "maven-deploy-test-1.0-SNAPSHOT.pom" );
- expectedFiles.add( "maven-deploy-test-1.0-SNAPSHOT.pom.md5" );
- expectedFiles.add( "maven-deploy-test-1.0-SNAPSHOT.pom.sha1" );
+
+ expectedFiles.add("org");
+ expectedFiles.add("apache");
+ expectedFiles.add("maven");
+ expectedFiles.add("test");
+ expectedFiles.add("maven-deploy-test");
+ expectedFiles.add("1.0-SNAPSHOT");
+ expectedFiles.add("maven-metadata.xml");
+ expectedFiles.add("maven-metadata.xml.md5");
+ expectedFiles.add("maven-metadata.xml.sha1");
+ expectedFiles.add("maven-deploy-test-1.0-SNAPSHOT.pom");
+ expectedFiles.add("maven-deploy-test-1.0-SNAPSHOT.pom.md5");
+ expectedFiles.add("maven-deploy-test-1.0-SNAPSHOT.pom.sha1");
// as we are in SNAPSHOT the file is here twice
- expectedFiles.add( "maven-metadata.xml" );
- expectedFiles.add( "maven-metadata.xml.md5" );
- expectedFiles.add( "maven-metadata.xml.sha1" );
- remoteRepo = new File( remoteRepo, "basic-deploy-pom" );
-
+ expectedFiles.add("maven-metadata.xml");
+ expectedFiles.add("maven-metadata.xml.md5");
+ expectedFiles.add("maven-metadata.xml.sha1");
+ remoteRepo = new File(remoteRepo, "basic-deploy-pom");
+
File[] files = remoteRepo.listFiles();
- for (File file : Objects.requireNonNull( files ) ) {
+ for (File file : Objects.requireNonNull(files)) {
addFileToList(file, fileList);
}
-
- assertEquals( expectedFiles.size(), fileList.size() );
- assertEquals( 0, getSizeOfExpectedFiles( fileList, expectedFiles ) );
+ assertEquals(expectedFiles.size(), fileList.size());
+
+ assertEquals(0, getSizeOfExpectedFiles(fileList, expectedFiles));
}
- public void testDeployIfArtifactFileIsNull()
- throws Exception
- {
- File testPom = new File( getBasedir(),
- "target/test-classes/unit/basic-deploy-test/plugin-config.xml" );
-
- DeployMojo mojo = ( DeployMojo ) lookupMojo( "deploy", testPom );
-
- MockitoAnnotations.initMocks( this );
-
- ProjectBuildingRequest buildingRequest = mock ( ProjectBuildingRequest.class );
- when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
-
- setVariableValueToObject( mojo, "session", session );
-
- assertNotNull( mojo );
-
- MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" );
- project.setGroupId( "org.apache.maven.test" );
- project.setArtifactId( "maven-deploy-test" );
- project.setVersion( "1.0-SNAPSHOT" );
-
- setVariableValueToObject( mojo, "pluginContext", new ConcurrentHashMap<>() );
- setVariableValueToObject( mojo, "reactorProjects", Collections.singletonList( project ) );
+ public void testDeployIfArtifactFileIsNull() throws Exception {
+ File testPom = new File(getBasedir(), "target/test-classes/unit/basic-deploy-test/plugin-config.xml");
+
+ DeployMojo mojo = (DeployMojo) lookupMojo("deploy", testPom);
+
+ MockitoAnnotations.initMocks(this);
+
+ ProjectBuildingRequest buildingRequest = mock(ProjectBuildingRequest.class);
+ when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
+
+ setVariableValueToObject(mojo, "session", session);
+
+ assertNotNull(mojo);
+
+ MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
+ project.setGroupId("org.apache.maven.test");
+ project.setArtifactId("maven-deploy-test");
+ project.setVersion("1.0-SNAPSHOT");
+
+ setVariableValueToObject(mojo, "pluginContext", new ConcurrentHashMap<>());
+ setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project));
artifact = (DeployArtifactStub) project.getArtifact();
-
- artifact.setFile( null );
-
- assertNull( artifact.getFile() );
-
- try
- {
+
+ artifact.setFile(null);
+
+ assertNull(artifact.getFile());
+
+ try {
mojo.execute();
- fail( "Did not throw mojo execution exception" );
- }
- catch( MojoExecutionException e )
- {
- //expected
+ fail("Did not throw mojo execution exception");
+ } catch (MojoExecutionException e) {
+ // expected
}
}
-
- public void testDeployWithAttachedArtifacts()
- throws Exception
- {
- File testPom = new File( getBasedir(),
- "target/test-classes/unit/basic-deploy-with-attached-artifacts/" +
- "plugin-config.xml" );
-
- mojo = ( DeployMojo ) lookupMojo( "deploy", testPom );
-
- MockitoAnnotations.initMocks( this );
-
- assertNotNull( mojo );
-
- ProjectBuildingRequest buildingRequest = mock ( ProjectBuildingRequest.class );
- when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
+
+ public void testDeployWithAttachedArtifacts() throws Exception {
+ File testPom = new File(
+ getBasedir(), "target/test-classes/unit/basic-deploy-with-attached-artifacts/" + "plugin-config.xml");
+
+ mojo = (DeployMojo) lookupMojo("deploy", testPom);
+
+ MockitoAnnotations.initMocks(this);
+
+ assertNotNull(mojo);
+
+ ProjectBuildingRequest buildingRequest = mock(ProjectBuildingRequest.class);
+ when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
- repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManagerFactory().newInstance( repositorySession, new LocalRepository( LOCAL_REPO ) ) );
- when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );
- when( session.getRepositorySession() ).thenReturn( repositorySession );
+ repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory()
+ .newInstance(repositorySession, new LocalRepository(LOCAL_REPO)));
+ when(buildingRequest.getRepositorySession()).thenReturn(repositorySession);
+ when(session.getRepositorySession()).thenReturn(repositorySession);
- MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" );
- project.setGroupId( "org.apache.maven.test" );
- project.setArtifactId( "maven-deploy-test" );
- project.setVersion( "1.0-SNAPSHOT" );
+ MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
+ project.setGroupId("org.apache.maven.test");
+ project.setArtifactId("maven-deploy-test");
+ project.setVersion("1.0-SNAPSHOT");
- setVariableValueToObject( mojo, "pluginContext", new ConcurrentHashMap<>() );
- setVariableValueToObject( mojo, "reactorProjects", Collections.singletonList( project ) );
+ setVariableValueToObject(mojo, "pluginContext", new ConcurrentHashMap<>());
+ setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project));
artifact = (DeployArtifactStub) project.getArtifact();
-
- File file = new File( getBasedir(),
- "target/test-classes/unit/basic-deploy-with-attached-artifacts/target/" +
- "deploy-test-file-1.0-SNAPSHOT.jar" );
-
- artifact.setFile( file );
-
- ArtifactRepositoryStub repo = getRepoStub( mojo );
-
- repo.setAppendToUrl( "basic-deploy-with-attached-artifacts" );
-
+
+ File file = new File(
+ getBasedir(),
+ "target/test-classes/unit/basic-deploy-with-attached-artifacts/target/"
+ + "deploy-test-file-1.0-SNAPSHOT.jar");
+
+ artifact.setFile(file);
+
+ ArtifactRepositoryStub repo = getRepoStub(mojo);
+
+ repo.setAppendToUrl("basic-deploy-with-attached-artifacts");
+
mojo.execute();
- //check the artifacts in remote repository
+ // check the artifacts in remote repository
List<String> expectedFiles = new ArrayList<>();
List<String> fileList = new ArrayList<>();
-
- expectedFiles.add( "org" );
- expectedFiles.add( "apache" );
- expectedFiles.add( "maven" );
- expectedFiles.add( "test" );
- expectedFiles.add( "maven-deploy-test" );
- expectedFiles.add( "1.0-SNAPSHOT" );
- expectedFiles.add( "maven-metadata.xml" );
- expectedFiles.add( "maven-metadata.xml.md5" );
- expectedFiles.add( "maven-metadata.xml.sha1" );
- expectedFiles.add( "maven-deploy-test-1.0-SNAPSHOT.jar" );
- expectedFiles.add( "maven-deploy-test-1.0-SNAPSHOT.jar.md5" );
- expectedFiles.add( "maven-deploy-test-1.0-SNAPSHOT.jar.sha1" );
- expectedFiles.add( "maven-deploy-test-1.0-SNAPSHOT.pom" );
- expectedFiles.add( "maven-deploy-test-1.0-SNAPSHOT.pom.md5" );
- expectedFiles.add( "maven-deploy-test-1.0-SNAPSHOT.pom.sha1" );
+
+ expectedFiles.add("org");
+ expectedFiles.add("apache");
+ expectedFiles.add("maven");
+ expectedFiles.add("test");
+ expectedFiles.add("maven-deploy-test");
+ expectedFiles.add("1.0-SNAPSHOT");
+ expectedFiles.add("maven-metadata.xml");
+ expectedFiles.add("maven-metadata.xml.md5");
+ expectedFiles.add("maven-metadata.xml.sha1");
+ expectedFiles.add("maven-deploy-test-1.0-SNAPSHOT.jar");
+ expectedFiles.add("maven-deploy-test-1.0-SNAPSHOT.jar.md5");
+ expectedFiles.add("maven-deploy-test-1.0-SNAPSHOT.jar.sha1");
+ expectedFiles.add("maven-deploy-test-1.0-SNAPSHOT.pom");
+ expectedFiles.add("maven-deploy-test-1.0-SNAPSHOT.pom.md5");
+ expectedFiles.add("maven-deploy-test-1.0-SNAPSHOT.pom.sha1");
// as we are in SNAPSHOT the file is here twice
- expectedFiles.add( "maven-metadata.xml" );
- expectedFiles.add( "maven-metadata.xml.md5" );
- expectedFiles.add( "maven-metadata.xml.sha1" );
- expectedFiles.add( "attached-artifact-test-0" );
- expectedFiles.add( "1.0-SNAPSHOT" );
- expectedFiles.add( "maven-metadata.xml" );
- expectedFiles.add( "maven-metadata.xml.md5" );
- expectedFiles.add( "maven-metadata.xml.sha1" );
- expectedFiles.add( "attached-artifact-test-0-1.0-SNAPSHOT.jar" );
- expectedFiles.add( "attached-artifact-test-0-1.0-SNAPSHOT.jar.md5" );
- expectedFiles.add( "attached-artifact-test-0-1.0-SNAPSHOT.jar.sha1" );
+ expectedFiles.add("maven-metadata.xml");
+ expectedFiles.add("maven-metadata.xml.md5");
+ expectedFiles.add("maven-metadata.xml.sha1");
+ expectedFiles.add("attached-artifact-test-0");
+ expectedFiles.add("1.0-SNAPSHOT");
+ expectedFiles.add("maven-metadata.xml");
+ expectedFiles.add("maven-metadata.xml.md5");
+ expectedFiles.add("maven-metadata.xml.sha1");
+ expectedFiles.add("attached-artifact-test-0-1.0-SNAPSHOT.jar");
+ expectedFiles.add("attached-artifact-test-0-1.0-SNAPSHOT.jar.md5");
+ expectedFiles.add("attached-artifact-test-0-1.0-SNAPSHOT.jar.sha1");
// as we are in SNAPSHOT the file is here twice
- expectedFiles.add( "maven-metadata.xml" );
- expectedFiles.add( "maven-metadata.xml.md5" );
- expectedFiles.add( "maven-metadata.xml.sha1" );
-
- remoteRepo = new File( remoteRepo, "basic-deploy-with-attached-artifacts" );
-
+ expectedFiles.add("maven-metadata.xml");
+ expectedFiles.add("maven-metadata.xml.md5");
+ expectedFiles.add("maven-metadata.xml.sha1");
+
+ remoteRepo = new File(remoteRepo, "basic-deploy-with-attached-artifacts");
+
File[] files = remoteRepo.listFiles();
- for (File file1 : Objects.requireNonNull( files ) ) {
+ for (File file1 : Objects.requireNonNull(files)) {
addFileToList(file1, fileList);
}
-
- assertEquals( expectedFiles.size(), fileList.size() );
- assertEquals( 0, getSizeOfExpectedFiles( fileList, expectedFiles ) );
+ assertEquals(expectedFiles.size(), fileList.size());
+
+ assertEquals(0, getSizeOfExpectedFiles(fileList, expectedFiles));
}
-
- @Ignore( "SCP is not part of Maven3 distribution. Aether handles transport extensions." )
- public void _testBasicDeployWithScpAsProtocol()
- throws Exception
- {
- String originalUserHome = System.getProperty( "user.home" );
-
+
+ @Ignore("SCP is not part of Maven3 distribution. Aether handles transport extensions.")
+ public void _testBasicDeployWithScpAsProtocol() throws Exception {
+ String originalUserHome = System.getProperty("user.home");
+
// FIX THE DAMN user.home BEFORE YOU DELETE IT!!!
- File altHome = new File( getBasedir(), "target/ssh-user-home" );
+ File altHome = new File(getBasedir(), "target/ssh-user-home");
altHome.mkdirs();
-
- System.out.println( "Testing user.home value for .ssh dir: " + altHome.getCanonicalPath() );
-
+
+ System.out.println("Testing user.home value for .ssh dir: " + altHome.getCanonicalPath());
+
Properties props = System.getProperties();
- props.setProperty( "user.home", altHome.getCanonicalPath() );
-
- System.setProperties( props );
-
- File testPom = new File( getBasedir(),
- "target/test-classes/unit/basic-deploy-scp/plugin-config.xml" );
-
- mojo = ( DeployMojo ) lookupMojo( "deploy", testPom );
-
- assertNotNull( mojo );
-
- RepositorySystem repositorySystem = mock( RepositorySystem.class );
-
- setVariableValueToObject( mojo, "repositorySystem", repositorySystem );
-
- File file = new File( getBasedir(),
- "target/test-classes/unit/basic-deploy-scp/target/" +
- "deploy-test-file-1.0-SNAPSHOT.jar" );
-
- assertTrue( file.exists() );
-
- MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" );
-
- setVariableValueToObject( mojo, "pluginContext", new ConcurrentHashMap<>() );
- setVariableValueToObject( mojo, "reactorProjects", Collections.singletonList( project ) );
+ props.setProperty("user.home", altHome.getCanonicalPath());
+
+ System.setProperties(props);
+
+ File testPom = new File(getBasedir(), "target/test-classes/unit/basic-deploy-scp/plugin-config.xml");
+
+ mojo = (DeployMojo) lookupMojo("deploy", testPom);
+
+ assertNotNull(mojo);
+
+ RepositorySystem repositorySystem = mock(RepositorySystem.class);
+
+ setVariableValueToObject(mojo, "repositorySystem", repositorySystem);
+
+ File file = new File(
+ getBasedir(),
+ "target/test-classes/unit/basic-deploy-scp/target/" + "deploy-test-file-1.0-SNAPSHOT.jar");
+
+ assertTrue(file.exists());
+
+ MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
+
+ setVariableValueToObject(mojo, "pluginContext", new ConcurrentHashMap<>());
+ setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project));
artifact = (DeployArtifactStub) project.getArtifact();
-
- artifact.setFile( file );
-
- String altUserHome = System.getProperty( "user.home" );
-
- if ( altUserHome.equals( originalUserHome ) )
- {
+
+ artifact.setFile(file);
+
+ String altUserHome = System.getProperty("user.home");
+
+ if (altUserHome.equals(originalUserHome)) {
// this is *very* bad!
- throw new IllegalStateException( "Setting 'user.home' system property to alternate value did NOT work. Aborting test." );
+ throw new IllegalStateException(
+ "Setting 'user.home' system property to alternate value did NOT work. Aborting test.");
}
-
- File sshFile = new File( altUserHome, ".ssh" );
-
- System.out.println( "Testing .ssh dir: " + sshFile.getCanonicalPath() );
-
- //delete first the .ssh folder if existing before executing the mojo
- if( sshFile.exists() )
- {
- FileUtils.deleteDirectory( sshFile );
+
+ File sshFile = new File(altUserHome, ".ssh");
+
+ System.out.println("Testing .ssh dir: " + sshFile.getCanonicalPath());
+
+ // delete first the .ssh folder if existing before executing the mojo
+ if (sshFile.exists()) {
+ FileUtils.deleteDirectory(sshFile);
}
mojo.execute();
-
- assertTrue( sshFile.exists() );
-
- FileUtils.deleteDirectory( sshFile );
+
+ assertTrue(sshFile.exists());
+
+ FileUtils.deleteDirectory(sshFile);
}
- public void testLegacyAltDeploymentRepositoryWithDefaultLayout()
- throws Exception
- {
+ public void testLegacyAltDeploymentRepositoryWithDefaultLayout() throws Exception {
DeployMojo mojo = new DeployMojo();
- setVariableValueToObject( mojo, "project", project );
- setVariableValueToObject( mojo, "session", session );
- setVariableValueToObject( mojo, "altDeploymentRepository", "altDeploymentRepository::default::http://localhost" );
-
- project.setVersion( "1.0-SNAPSHOT" );
+ setVariableValueToObject(mojo, "project", project);
+ setVariableValueToObject(mojo, "session", session);
+ setVariableValueToObject(mojo, "altDeploymentRepository", "altDeploymentRepository::default::http://localhost");
- assertEquals( new RemoteRepository.Builder( "altDeploymentRepository", "default", "http://localhost" ).build(),
- mojo.getDeploymentRepository( project, null, null, "altDeploymentRepository::default::http://localhost") );
+ project.setVersion("1.0-SNAPSHOT");
+ assertEquals(
+ new RemoteRepository.Builder("altDeploymentRepository", "default", "http://localhost").build(),
+ mojo.getDeploymentRepository(
+ project, null, null, "altDeploymentRepository::default::http://localhost"));
}
- public void testLegacyAltDeploymentRepositoryWithLegacyLayout()
- throws Exception
- {
+ public void testLegacyAltDeploymentRepositoryWithLegacyLayout() throws Exception {
DeployMojo mojo = new DeployMojo();
- setVariableValueToObject( mojo, "project", project );
- setVariableValueToObject( mojo, "session", session );
- setVariableValueToObject( mojo, "altDeploymentRepository", "altDeploymentRepository::legacy::http://localhost" );
-
- project.setVersion( "1.0-SNAPSHOT" );
- try
- {
- mojo.getDeploymentRepository( project, null, null, "altDeploymentRepository::legacy::http://localhost" );
- fail( "Should throw: Invalid legacy syntax and layout for repository." );
- }
- catch( MojoFailureException e )
- {
- assertEquals( e.getMessage(), "Invalid legacy syntax and layout for repository.");
- assertEquals( e.getLongMessage(), "Invalid legacy syntax and layout for alternative repository. Use \"altDeploymentRepository::http://localhost\" instead, and only default layout is supported.");
+ setVariableValueToObject(mojo, "project", project);
+ setVariableValueToObject(mojo, "session", session);
+ setVariableValueToObject(mojo, "altDeploymentRepository", "altDeploymentRepository::legacy::http://localhost");
+
+ project.setVersion("1.0-SNAPSHOT");
+ try {
+ mojo.getDeploymentRepository(project, null, null, "altDeploymentRepository::legacy::http://localhost");
+ fail("Should throw: Invalid legacy syntax and layout for repository.");
+ } catch (MojoFailureException e) {
+ assertEquals(e.getMessage(), "Invalid legacy syntax and layout for repository.");
+ assertEquals(
+ e.getLongMessage(),
+ "Invalid legacy syntax and layout for alternative repository. Use \"altDeploymentRepository::http://localhost\" instead, and only default layout is supported.");
}
}
- public void testInsaneAltDeploymentRepository()
- throws Exception
- {
+ public void testInsaneAltDeploymentRepository() throws Exception {
DeployMojo mojo = new DeployMojo();
- setVariableValueToObject( mojo, "project", project );
- setVariableValueToObject( mojo, "session", session );
- setVariableValueToObject( mojo, "altDeploymentRepository", "altDeploymentRepository::hey::wow::foo::http://localhost" );
-
- project.setVersion( "1.0-SNAPSHOT" );
- try
- {
- mojo.getDeploymentRepository( project, null, null, "altDeploymentRepository::hey::wow::foo::http://localhost" );
- fail( "Should throw: Invalid legacy syntax and layout for repository." );
- }
- catch( MojoFailureException e )
- {
- assertEquals( e.getMessage(), "Invalid legacy syntax and layout for repository.");
- assertEquals( e.getLongMessage(), "Invalid legacy syntax and layout for alternative repository. Use \"altDeploymentRepository::wow::foo::http://localhost\" instead, and only default layout is supported.");
+ setVariableValueToObject(mojo, "project", project);
+ setVariableValueToObject(mojo, "session", session);
+ setVariableValueToObject(
+ mojo, "altDeploymentRepository", "altDeploymentRepository::hey::wow::foo::http://localhost");
+
+ project.setVersion("1.0-SNAPSHOT");
+ try {
+ mojo.getDeploymentRepository(
+ project, null, null, "altDeploymentRepository::hey::wow::foo::http://localhost");
+ fail("Should throw: Invalid legacy syntax and layout for repository.");
+ } catch (MojoFailureException e) {
+ assertEquals(e.getMessage(), "Invalid legacy syntax and layout for repository.");
+ assertEquals(
+ e.getLongMessage(),
+ "Invalid legacy syntax and layout for alternative repository. Use \"altDeploymentRepository::wow::foo::http://localhost\" instead, and only default layout is supported.");
}
}
- public void testDefaultScmSvnAltDeploymentRepository()
- throws Exception
- {
+ public void testDefaultScmSvnAltDeploymentRepository() throws Exception {
DeployMojo mojo = new DeployMojo();
- setVariableValueToObject( mojo, "project", project );
- setVariableValueToObject( mojo, "session", session );
- setVariableValueToObject( mojo, "altDeploymentRepository", "altDeploymentRepository::default::scm:svn:http://localhost" );
+ setVariableValueToObject(mojo, "project", project);
+ setVariableValueToObject(mojo, "session", session);
+ setVariableValueToObject(
+ mojo, "altDeploymentRepository", "altDeploymentRepository::default::scm:svn:http://localhost");
- project.setVersion( "1.0-SNAPSHOT" );
+ project.setVersion("1.0-SNAPSHOT");
- assertEquals( new RemoteRepository.Builder( "altDeploymentRepository", "default", "scm:svn:http://localhost" ).build(),
- mojo.getDeploymentRepository( project, null, null, "altDeploymentRepository::default::scm:svn:http://localhost" ) );
+ assertEquals(
+ new RemoteRepository.Builder("altDeploymentRepository", "default", "scm:svn:http://localhost").build(),
+ mojo.getDeploymentRepository(
+ project, null, null, "altDeploymentRepository::default::scm:svn:http://localhost"));
}
- public void testLegacyScmSvnAltDeploymentRepository()
- throws Exception
- {
- DeployMojo mojo = new DeployMojo();
- setVariableValueToObject( mojo, "project", project );
- setVariableValueToObject( mojo, "altDeploymentRepository", "altDeploymentRepository::legacy::scm:svn:http://localhost" );
+ public void testLegacyScmSvnAltDeploymentRepository() throws Exception {
+ DeployMojo mojo = new DeployMojo();
- project.setVersion( "1.0-SNAPSHOT" );
- try
- {
- mojo.getDeploymentRepository( project, null, null, "altDeploymentRepository::legacy::scm:svn:http://localhost" );
- fail( "Should throw: Invalid legacy syntax and layout for repository." );
- }
- catch( MojoFailureException e )
- {
- assertEquals( e.getMessage(), "Invalid legacy syntax and layout for repository.");
- assertEquals( e.getLongMessage(), "Invalid legacy syntax and layout for alternative repository. Use \"altDeploymentRepository::scm:svn:http://localhost\" instead, and only default layout is supported.");
+ setVariableValueToObject(mojo, "project", project);
+ setVariableValueToObject(
+ mojo, "altDeploymentRepository", "altDeploymentRepository::legacy::scm:svn:http://localhost");
+
+ project.setVersion("1.0-SNAPSHOT");
+ try {
+ mojo.getDeploymentRepository(
+ project, null, null, "altDeploymentRepository::legacy::scm:svn:http://localhost");
+ fail("Should throw: Invalid legacy syntax and layout for repository.");
+ } catch (MojoFailureException e) {
+ assertEquals(e.getMessage(), "Invalid legacy syntax and layout for repository.");
+ assertEquals(
+ e.getLongMessage(),
+ "Invalid legacy syntax and layout for alternative repository. Use \"altDeploymentRepository::scm:svn:http://localhost\" instead, and only default layout is supported.");
}
}
- public void testAltSnapshotDeploymentRepository()
- throws Exception
- {
+ public void testAltSnapshotDeploymentRepository() throws Exception {
DeployMojo mojo = new DeployMojo();
- setVariableValueToObject( mojo, "project", project );
- setVariableValueToObject( mojo, "session", session );
- setVariableValueToObject( mojo, "altSnapshotDeploymentRepository", "altSnapshotDeploymentRepository::http://localhost" );
+ setVariableValueToObject(mojo, "project", project);
+ setVariableValueToObject(mojo, "session", session);
+ setVariableValueToObject(
+ mojo, "altSnapshotDeploymentRepository", "altSnapshotDeploymentRepository::http://localhost");
- project.setVersion( "1.0-SNAPSHOT" );
+ project.setVersion("1.0-SNAPSHOT");
- assertEquals( new RemoteRepository.Builder( "altSnapshotDeploymentRepository", "default", "http://localhost" ).build(),
- mojo.getDeploymentRepository( project, "altSnapshotDeploymentRepository::http://localhost", null, null ));
+ assertEquals(
+ new RemoteRepository.Builder("altSnapshotDeploymentRepository", "default", "http://localhost").build(),
+ mojo.getDeploymentRepository(project, "altSnapshotDeploymentRepository::http://localhost", null, null));
}
- public void testAltReleaseDeploymentRepository()
- throws Exception
- {
+ public void testAltReleaseDeploymentRepository() throws Exception {
DeployMojo mojo = new DeployMojo();
- setVariableValueToObject( mojo, "project", project );
- setVariableValueToObject( mojo, "session", session );
- setVariableValueToObject( mojo, "altReleaseDeploymentRepository", "altReleaseDeploymentRepository::http://localhost" );
+ setVariableValueToObject(mojo, "project", project);
+ setVariableValueToObject(mojo, "session", session);
+ setVariableValueToObject(
+ mojo, "altReleaseDeploymentRepository", "altReleaseDeploymentRepository::http://localhost");
- project.setVersion( "1.0" );
+ project.setVersion("1.0");
- assertEquals( new RemoteRepository.Builder("altReleaseDeploymentRepository", "default", "http://localhost").build(),
- mojo.getDeploymentRepository( project, null, "altReleaseDeploymentRepository::http://localhost", null ));
+ assertEquals(
+ new RemoteRepository.Builder("altReleaseDeploymentRepository", "default", "http://localhost").build(),
+ mojo.getDeploymentRepository(project, null, "altReleaseDeploymentRepository::http://localhost", null));
}
-
- private void addFileToList( File file, List<String> fileList )
- {
- if( !file.isDirectory() )
- {
- fileList.add( file.getName() );
- }
- else
- {
- fileList.add( file.getName() );
+
+ private void addFileToList(File file, List<String> fileList) {
+ if (!file.isDirectory()) {
+ fileList.add(file.getName());
+ } else {
+ fileList.add(file.getName());
File[] files = file.listFiles();
- for (File file1 : Objects.requireNonNull( files ) ) {
+ for (File file1 : Objects.requireNonNull(files)) {
addFileToList(file1, fileList);
}
}
- }
-
- private int getSizeOfExpectedFiles( List<String> fileList, List<String> expectedFiles )
- {
- for( String fileName : fileList )
- {
- // translate uniqueVersion to -SNAPSHOT
- fileName = fileName.replaceFirst( "-\\d{8}\\.\\d{6}-\\d+", "-SNAPSHOT" );
-
- if( !expectedFiles.remove( fileName ) )
- {
- fail( fileName + " is not included in the expected files" );
+ }
+
+ private int getSizeOfExpectedFiles(List<String> fileList, List<String> expectedFiles) {
+ for (String fileName : fileList) {
+ // translate uniqueVersion to -SNAPSHOT
+ fileName = fileName.replaceFirst("-\\d{8}\\.\\d{6}-\\d+", "-SNAPSHOT");
+
+ if (!expectedFiles.remove(fileName)) {
+ fail(fileName + " is not included in the expected files");
}
}
return expectedFiles.size();
- }
+ }
- private ArtifactRepositoryStub getRepoStub( Object mojo )
- throws Exception
- {
- MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" );
+ private ArtifactRepositoryStub getRepoStub(Object mojo) throws Exception {
+ MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
return (ArtifactRepositoryStub) project.getDistributionManagementArtifactRepository();
}
-
}
diff --git a/src/test/java/org/apache/maven/plugins/deploy/Utils.java b/src/test/java/org/apache/maven/plugins/deploy/Utils.java
index be96342..8fc876a 100644
--- a/src/test/java/org/apache/maven/plugins/deploy/Utils.java
+++ b/src/test/java/org/apache/maven/plugins/deploy/Utils.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.deploy;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,6 +16,7 @@ package org.apache.maven.plugins.deploy;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.deploy;
import java.io.File;
import java.io.IOException;
@@ -34,10 +33,9 @@ import org.eclipse.aether.util.ChecksumUtils;
*
* @author Benjamin Bentmann
*/
-public class Utils
-{
+public class Utils {
- public static final List<String> CHECKSUM_ALGORITHMS = Arrays.asList( "MD5", "SHA-1" );
+ public static final List<String> CHECKSUM_ALGORITHMS = Arrays.asList("MD5", "SHA-1");
/**
* Verifies the checksum files in the local repo for the given file.
@@ -46,19 +44,14 @@ public class Utils
* @throws MojoExecutionException In case the checksums were incorrect.
* @throws IOException If the files couldn't be read.
*/
- public static void verifyChecksum( File file )
- throws MojoExecutionException, IOException
- {
- Map<String, Object> checksums = ChecksumUtils.calc( file, CHECKSUM_ALGORITHMS );
- for ( Map.Entry<String, Object> entry : checksums.entrySet() )
- {
- File cksumFile = new File( file + "." + entry.getKey().toLowerCase().replace( "-", "" ) );
- String actualChecksum = ChecksumUtils.read( cksumFile );
- if ( !actualChecksum.equals( entry.getValue() ) )
- {
- throw new MojoExecutionException( "Incorrect " + entry.getKey() + " checksum for file: " + file );
+ public static void verifyChecksum(File file) throws MojoExecutionException, IOException {
+ Map<String, Object> checksums = ChecksumUtils.calc(file, CHECKSUM_ALGORITHMS);
+ for (Map.Entry<String, Object> entry : checksums.entrySet()) {
+ File cksumFile = new File(file + "." + entry.getKey().toLowerCase().replace("-", ""));
+ String actualChecksum = ChecksumUtils.read(cksumFile);
+ if (!actualChecksum.equals(entry.getValue())) {
+ throw new MojoExecutionException("Incorrect " + entry.getKey() + " checksum for file: " + file);
}
}
}
-
}
diff --git a/src/test/java/org/apache/maven/plugins/deploy/stubs/ArtifactRepositoryStub.java b/src/test/java/org/apache/maven/plugins/deploy/stubs/ArtifactRepositoryStub.java
index 238c5f7..9dd9540 100644
--- a/src/test/java/org/apache/maven/plugins/deploy/stubs/ArtifactRepositoryStub.java
+++ b/src/test/java/org/apache/maven/plugins/deploy/stubs/ArtifactRepositoryStub.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.deploy.stubs;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@ package org.apache.maven.plugins.deploy.stubs;
* "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
+ * 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
@@ -18,6 +16,7 @@ package org.apache.maven.plugins.deploy.stubs;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.deploy.stubs;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
@@ -27,120 +26,94 @@ import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
import org.apache.maven.plugin.testing.stubs.StubArtifactRepository;
-public class ArtifactRepositoryStub
- extends StubArtifactRepository
-{
+public class ArtifactRepositoryStub extends StubArtifactRepository {
private boolean blacklisted;
-
+
private ArtifactRepositoryLayout layout;
-
+
private String url;
-
- private final String basedir = System.getProperty( "basedir" );
-
- public ArtifactRepositoryStub()
- {
- super( null );
- }
-
- public ArtifactRepositoryStub( String dir )
- {
- super( dir );
- }
-
- public String pathOf( Artifact artifact )
- {
- return getLayout().pathOf( artifact );
- }
-
- public String pathOfRemoteRepositoryMetadata( ArtifactMetadata artifactMetadata )
- {
- return getLayout().pathOfRemoteRepositoryMetadata( artifactMetadata );
- }
-
- public String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, ArtifactRepository repository )
- {
- return getLayout().pathOfLocalRepositoryMetadata( metadata, repository );
- }
-
- public String getUrl()
- {
+
+ private final String basedir = System.getProperty("basedir");
+
+ public ArtifactRepositoryStub() {
+ super(null);
+ }
+
+ public ArtifactRepositoryStub(String dir) {
+ super(dir);
+ }
+
+ public String pathOf(Artifact artifact) {
+ return getLayout().pathOf(artifact);
+ }
+
+ public String pathOfRemoteRepositoryMetadata(ArtifactMetadata artifactMetadata) {
+ return getLayout().pathOfRemoteRepositoryMetadata(artifactMetadata);
+ }
+
+ public String pathOfLocalRepositoryMetadata(ArtifactMetadata metadata, ArtifactRepository repository) {
+ return getLayout().pathOfLocalRepositoryMetadata(metadata, repository);
+ }
+
+ public String getUrl() {
return url;
}
-
- public void setAppendToUrl( String dir )
- {
+
+ public void setAppendToUrl(String dir) {
this.url = "file://" + basedir + "/target/remote-repo/" + dir;
}
-
- public String getBasedir()
- {
+
+ public String getBasedir() {
return basedir;
}
-
- public String getProtocol()
- {
+
+ public String getProtocol() {
return "file";
}
-
- public String getId()
- {
+
+ public String getId() {
return "deploy-test";
}
-
- public ArtifactRepositoryPolicy getSnapshots()
- {
- return new ArtifactRepositoryPolicy( true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS,
- ArtifactRepositoryPolicy.CHECKSUM_POLICY_IGNORE );
- }
-
- public ArtifactRepositoryPolicy getReleases()
- {
- return new ArtifactRepositoryPolicy( true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS,
- ArtifactRepositoryPolicy.CHECKSUM_POLICY_IGNORE );
- }
-
- public ArtifactRepositoryLayout getLayout()
- {
- if( layout != null )
- {
+
+ public ArtifactRepositoryPolicy getSnapshots() {
+ return new ArtifactRepositoryPolicy(
+ true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, ArtifactRepositoryPolicy.CHECKSUM_POLICY_IGNORE);
+ }
+
+ public ArtifactRepositoryPolicy getReleases() {
+ return new ArtifactRepositoryPolicy(
+ true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, ArtifactRepositoryPolicy.CHECKSUM_POLICY_IGNORE);
+ }
+
+ public ArtifactRepositoryLayout getLayout() {
+ if (layout != null) {
return layout;
- }
- else
- {
+ } else {
return new DefaultRepositoryLayout();
}
}
-
- public String getKey()
- {
+
+ public String getKey() {
return getId();
}
- public boolean isUniqueVersion()
- {
+ public boolean isUniqueVersion() {
return false;
}
-
- public void setBlacklisted( boolean blackListed )
- {
+
+ public void setBlacklisted(boolean blackListed) {
this.blacklisted = blackListed;
}
- public boolean isBlacklisted()
- {
+ public boolean isBlacklisted() {
return blacklisted;
}
// @Override
- public boolean isBlocked()
- {
+ public boolean isBlocked() {
return false;
}
// @Override
- public void setBlocked( boolean b )
- {
-
- }
+ public void setBlocked(boolean b) {}
}
diff --git a/src/test/java/org/apache/maven/plugins/deploy/stubs/ArtifactRepositoryStub2.java b/src/test/java/org/apache/maven/plugins/deploy/stubs/ArtifactRepositoryStub2.java
index 0e3338f..96d43bb 100644
--- a/src/test/java/org/apache/maven/plugins/deploy/stubs/ArtifactRepositoryStub2.java
+++ b/src/test/java/org/apache/maven/plugins/deploy/stubs/ArtifactRepositoryStub2.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.deploy.stubs;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@ package org.apache.maven.plugins.deploy.stubs;
* "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
+ * 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
@@ -18,43 +16,35 @@ package org.apache.maven.plugins.deploy.stubs;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.deploy.stubs;
-public class ArtifactRepositoryStub2
- extends ArtifactRepositoryStub
-{
+public class ArtifactRepositoryStub2 extends ArtifactRepositoryStub {
private String protocol;
-
- public ArtifactRepositoryStub2()
- {
+
+ public ArtifactRepositoryStub2() {
super();
}
-
- public ArtifactRepositoryStub2( String dir )
- {
- super( dir );
+
+ public ArtifactRepositoryStub2(String dir) {
+ super(dir);
}
- public String getUrl()
- {
- return "file://" + System.getProperty( "basedir" ) + "/target/remote-repo/basic-deploy-scp";
+ public String getUrl() {
+ return "file://" + System.getProperty("basedir") + "/target/remote-repo/basic-deploy-scp";
}
-
- public String getBasedir()
- {
- return System.getProperty( "basedir" );
+
+ public String getBasedir() {
+ return System.getProperty("basedir");
}
-
- public String getProtocol()
- {
- if( this.protocol == null || this.protocol.equals("") )
- {
+
+ public String getProtocol() {
+ if (this.protocol == null || this.protocol.equals("")) {
this.protocol = "scp";
}
return this.protocol;
}
-
- public void setProtocol( String protocol )
- {
+
+ public void setProtocol(String protocol) {
this.protocol = protocol;
}
}
diff --git a/src/test/java/org/apache/maven/plugins/deploy/stubs/AttachedArtifactStub.java b/src/test/java/org/apache/maven/plugins/deploy/stubs/AttachedArtifactStub.java
index 0419a85..9226bdc 100644
--- a/src/test/java/org/apache/maven/plugins/deploy/stubs/AttachedArtifactStub.java
+++ b/src/test/java/org/apache/maven/plugins/deploy/stubs/AttachedArtifactStub.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.deploy.stubs;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@ package org.apache.maven.plugins.deploy.stubs;
* "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
+ * 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
@@ -18,21 +16,19 @@ package org.apache.maven.plugins.deploy.stubs;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.deploy.stubs;
import java.io.File;
-public class AttachedArtifactStub
- extends DeployArtifactStub
-{
- public String getArtifactId()
- {
+public class AttachedArtifactStub extends DeployArtifactStub {
+ public String getArtifactId() {
return "attached-artifact-test-0";
}
-
- public File getFile()
- {
- return new File( System.getProperty( "basedir" ),
- "target/test-classes/unit/basic-deploy-with-attached-artifacts/" +
- "target/deploy-test-file-1.0-SNAPSHOT.jar" );
- }
+
+ public File getFile() {
+ return new File(
+ System.getProperty("basedir"),
+ "target/test-classes/unit/basic-deploy-with-attached-artifacts/"
+ + "target/deploy-test-file-1.0-SNAPSHOT.jar");
+ }
}
diff --git a/src/test/java/org/apache/maven/plugins/deploy/stubs/DeployArtifactStub.java b/src/test/java/org/apache/maven/plugins/deploy/stubs/DeployArtifactStub.java
index 8993ed9..7218fdf 100644
--- a/src/test/java/org/apache/maven/plugins/deploy/stubs/DeployArtifactStub.java
+++ b/src/test/java/org/apache/maven/plugins/deploy/stubs/DeployArtifactStub.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.deploy.stubs;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@ package org.apache.maven.plugins.deploy.stubs;
* "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
+ * 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
@@ -18,6 +16,7 @@ package org.apache.maven.plugins.deploy.stubs;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.deploy.stubs;
import java.io.File;
import java.util.Collection;
@@ -30,103 +29,81 @@ import org.apache.maven.artifact.handler.DefaultArtifactHandler;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.plugin.testing.stubs.ArtifactStub;
-public class DeployArtifactStub
- extends ArtifactStub
-{
+public class DeployArtifactStub extends ArtifactStub {
private Map<Object, ArtifactMetadata> metadataMap;
-
+
private File file;
-
+
private boolean release;
-
+
private String extension;
-
- public String getArtifactId()
- {
+
+ public String getArtifactId() {
return "maven-deploy-test";
}
- public String getGroupId()
- {
+ public String getGroupId() {
return "org.apache.maven.test";
}
- public String getVersion()
- {
+ public String getVersion() {
return "1.0-SNAPSHOT";
}
-
- public String getBaseVersion()
- {
+
+ public String getBaseVersion() {
return getVersion();
}
-
+
@Override
- public String getType()
- {
+ public String getType() {
return "jar";
}
-
- public void setFile( File file )
- {
+
+ public void setFile(File file) {
this.file = file;
}
-
- public File getFile()
- {
+
+ public File getFile() {
return file;
}
-
- public ArtifactHandler getArtifactHandler()
- {
- return new DefaultArtifactHandler()
- {
- public String getExtension()
- {
- if( extension == null )
- {
+
+ public ArtifactHandler getArtifactHandler() {
+ return new DefaultArtifactHandler() {
+ public String getExtension() {
+ if (extension == null) {
extension = "jar";
}
return extension;
}
};
}
-
- public void setArtifactHandlerExtension( String extension )
- {
+
+ public void setArtifactHandlerExtension(String extension) {
this.extension = extension;
}
-
- public void addMetadata( ArtifactMetadata metadata )
- {
- if ( metadataMap == null )
- {
+
+ public void addMetadata(ArtifactMetadata metadata) {
+ if (metadataMap == null) {
metadataMap = new HashMap<>();
}
- ArtifactMetadata m = metadataMap.get( metadata.getKey() );
- if ( m != null )
- {
- m.merge( metadata );
- }
- else
- {
- metadataMap.put( metadata.getKey(), metadata );
+ ArtifactMetadata m = metadataMap.get(metadata.getKey());
+ if (m != null) {
+ m.merge(metadata);
+ } else {
+ metadataMap.put(metadata.getKey(), metadata);
}
}
-
- public Collection<ArtifactMetadata> getMetadataList()
- {
+
+ public Collection<ArtifactMetadata> getMetadataList() {
return metadataMap == null ? Collections.emptyList() : metadataMap.values();
}
- public boolean isRelease()
- {
+ public boolean isRelease() {
return release;
}
- public void setRelease( boolean release )
- {
+ public void setRelease(boolean release) {
this.release = release;
}
diff --git a/src/test/java/org/apache/maven/plugins/deploy/stubs/MavenProjectStub.java b/src/test/java/org/apache/maven/plugins/deploy/stubs/MavenProjectStub.java
index 91709a3..ff97f91 100644
--- a/src/test/java/org/apache/maven/plugins/deploy/stubs/MavenProjectStub.java
+++ b/src/test/java/org/apache/maven/plugins/deploy/stubs/MavenProjectStub.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.deploy.stubs;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@ package org.apache.maven.plugins.deploy.stubs;
* "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
+ * 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
@@ -18,18 +16,15 @@ package org.apache.maven.plugins.deploy.stubs;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.deploy.stubs;
import org.apache.maven.artifact.repository.ArtifactRepository;
-public class MavenProjectStub
- extends org.apache.maven.plugin.testing.stubs.MavenProjectStub
-{
+public class MavenProjectStub extends org.apache.maven.plugin.testing.stubs.MavenProjectStub {
private ArtifactRepositoryStub deploymentRepository;
- public ArtifactRepository getDistributionManagementArtifactRepository()
- {
+ public ArtifactRepository getDistributionManagementArtifactRepository() {
return deploymentRepository;
}
-
}