[Git][java-team/maven-install-plugin][master] 3 commits: New upstream version 3.1.1
Emmanuel Bourg (@ebourg)
gitlab at salsa.debian.org
Sat Jun 17 10:54:31 BST 2023
Emmanuel Bourg pushed to branch master at Debian Java Maintainers / maven-install-plugin
Commits:
446e2679 by Emmanuel Bourg at 2023-06-17T11:15:38+02:00
New upstream version 3.1.1
- - - - -
36eeeed7 by Emmanuel Bourg at 2023-06-17T11:15:38+02:00
Update upstream source from tag 'upstream/3.1.1'
Update to upstream version '3.1.1'
with Debian dir ea35ce86c9a20b5a34232a444ad874307544a743
- - - - -
51704d7d by Emmanuel Bourg at 2023-06-17T11:52:21+02:00
New upstream release (3.1.1)
- - - - -
13 changed files:
- .asf.yaml
- .gitignore
- debian/changelog
- pom.xml
- src/main/java/org/apache/maven/plugins/install/InstallFileMojo.java
- src/main/java/org/apache/maven/plugins/install/InstallMojo.java
- src/test/java/org/apache/maven/plugins/install/InstallFileMojoTest.java
- src/test/java/org/apache/maven/plugins/install/InstallMojoTest.java
- src/test/java/org/apache/maven/plugins/install/stubs/AttachedArtifactStub0.java
- src/test/java/org/apache/maven/plugins/install/stubs/AttachedArtifactStub1.java
- src/test/java/org/apache/maven/plugins/install/stubs/InstallArtifactStub.java
- + src/test/resources/unit/install-file-from-local-repository-test/plugin-config.xml
- + src/test/resources/unit/install-file-from-local-repository-test/target/org/apache/maven/test/maven-install-test/1.0-SNAPSHOT/maven-install-test-1.0-SNAPSHOT.jar
Changes:
=====================================
.asf.yaml
=====================================
@@ -24,3 +24,9 @@ github:
- maven-plugins
- maven-install-plugin
- maven
+ enabled_merge_buttons:
+ squash: true
+ merge: false
+ rebase: true
+ autolink_jira:
+ - MINSTALL
\ No newline at end of file
=====================================
.gitignore
=====================================
@@ -1,4 +1,5 @@
target/
+!src/test/resources/unit/*/target
.project
.classpath
.settings/
=====================================
debian/changelog
=====================================
@@ -1,3 +1,10 @@
+maven-install-plugin (3.1.1-1) unstable; urgency=medium
+
+ * Team upload.
+ * New upstream release
+
+ -- Emmanuel Bourg <ebourg at apache.org> Sat, 17 Jun 2023 11:51:56 +0200
+
maven-install-plugin (3.1.0-1) unstable; urgency=medium
* Team upload.
=====================================
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,25 +17,34 @@
specific language governing permissions and limitations
under the License.
-->
-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugins</artifactId>
- <version>37</version>
+ <version>39</version>
<relativePath />
</parent>
<artifactId>maven-install-plugin</artifactId>
- <version>3.1.0</version>
+ <version>3.1.1</version>
<packaging>maven-plugin</packaging>
<name>Apache Maven Install Plugin</name>
<description>Copies the project artifacts to the user's local repository.</description>
<inceptionYear>2004</inceptionYear>
+ <contributors>
+ <!-- alphabetic order -->
+ <contributor>
+ <name>Hermann Josef Hill</name>
+ </contributor>
+ <contributor>
+ <name>Ludwig Magnusson</name>
+ </contributor>
+ </contributors>
+
<prerequisites>
<maven>${mavenVersion}</maven>
</prerequisites>
@@ -44,8 +52,8 @@
<scm>
<connection>scm:git:https://gitbox.apache.org/repos/asf/maven-install-plugin.git</connection>
<developerConnection>scm:git:https://gitbox.apache.org/repos/asf/maven-install-plugin.git</developerConnection>
+ <tag>maven-install-plugin-3.1.1</tag>
<url>https://github.com/apache/maven-install-plugin/tree/${project.scm.tag}</url>
- <tag>maven-install-plugin-3.1.0</tag>
</scm>
<issueManagement>
<system>jira</system>
@@ -65,8 +73,10 @@
<properties>
<javaVersion>8</javaVersion>
<mavenVersion>3.2.5</mavenVersion>
- <aetherVersion>1.0.0.v20140518</aetherVersion> <!-- Maven bound -->
- <slf4jVersion>1.7.5</slf4jVersion> <!-- Maven bound -->
+ <!-- Maven bound -->
+ <aetherVersion>1.0.0.v20140518</aetherVersion>
+ <!-- Maven bound -->
+ <slf4jVersion>1.7.5</slf4jVersion>
<!-- plugin versions used in IT tests -->
<mavenAntrunPluginVersion>3.1.0</mavenAntrunPluginVersion>
@@ -78,7 +88,7 @@
<mavenSourcePluginVersion>3.2.1</mavenSourcePluginVersion>
<mavenSurefirePluginVersion>3.0.0-M7</mavenSurefirePluginVersion>
- <project.build.outputTimestamp>2022-11-13T22:11:59Z</project.build.outputTimestamp>
+ <project.build.outputTimestamp>2023-03-21T14:30:42Z</project.build.outputTimestamp>
</properties>
<dependencies>
@@ -117,7 +127,8 @@
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-util</artifactId>
<version>${aetherVersion}</version>
- <scope>compile</scope> <!-- To work in Maven versions older than 3.9.0 -->
+ <!-- To work in Maven versions older than 3.9.0 -->
+ <scope>compile</scope>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
@@ -143,7 +154,8 @@
<version>3.3.0</version>
<scope>test</scope>
</dependency>
- <dependency> <!-- used by maven-plugin-testing-harness, don't give it compile scope! -->
+ <dependency>
+ <!-- used by maven-plugin-testing-harness, don't give it compile scope! -->
<groupId>org.apache.maven</groupId>
<artifactId>maven-compat</artifactId>
<version>${mavenVersion}</version>
@@ -175,16 +187,6 @@
</dependency>
</dependencies>
- <contributors>
- <!-- alphabetic order -->
- <contributor>
- <name>Hermann Josef Hill</name>
- </contributor>
- <contributor>
- <name>Ludwig Magnusson</name>
- </contributor>
- </contributors>
-
<profiles>
<profile>
<id>run-its</id>
=====================================
src/main/java/org/apache/maven/plugins/install/InstallFileMojo.java
=====================================
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.install;
-
/*
* 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.install;
* "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.install;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.install;
import java.io.File;
import java.io.FileNotFoundException;
@@ -64,287 +63,245 @@ import org.eclipse.aether.util.artifact.SubArtifact;
/**
* Installs a file in the local repository.
- *
+ *
* @author <a href="mailto:brett at apache.org">Brett Porter</a>
*/
- at Mojo( name = "install-file", requiresProject = false, aggregator = true, threadSafe = true )
-public class InstallFileMojo
- extends AbstractMojo
-{
- private static final String LS = System.getProperty( "line.separator" );
+ at Mojo(name = "install-file", requiresProject = false, aggregator = true, threadSafe = true)
+public class InstallFileMojo extends AbstractMojo {
+ private static final String LS = System.getProperty("line.separator");
@Component
private RepositorySystem repositorySystem;
- @Parameter( defaultValue = "${session}", required = true, readonly = true )
+ @Parameter(defaultValue = "${session}", required = true, readonly = true)
private MavenSession session;
/**
* GroupId of the artifact to be installed. Retrieved from POM file if one is specified or extracted from
* {@code pom.xml} in jar if available.
*/
- @Parameter( property = "groupId" )
+ @Parameter(property = "groupId")
private String groupId;
/**
* ArtifactId of the artifact to be installed. Retrieved from POM file if one is specified or extracted from
* {@code pom.xml} in jar if available.
*/
- @Parameter( property = "artifactId" )
+ @Parameter(property = "artifactId")
private String artifactId;
/**
* Version of the artifact to be installed. Retrieved from POM file if one is specified or extracted from
* {@code pom.xml} in jar if available.
*/
- @Parameter( property = "version" )
+ @Parameter(property = "version")
private String version;
/**
* Packaging type of the artifact to be installed. Retrieved from POM file if one is specified or extracted from
* {@code pom.xml} in jar if available.
*/
- @Parameter( property = "packaging" )
+ @Parameter(property = "packaging")
private String packaging;
/**
* Classifier type of the artifact to be installed. For example, "sources" or "javadoc". Defaults to none which
* means this is the project's main artifact.
- *
+ *
* @since 2.2
*/
- @Parameter( property = "classifier" )
+ @Parameter(property = "classifier")
private String classifier;
/**
* The file to be installed in the local repository.
*/
- @Parameter( property = "file", required = true )
+ @Parameter(property = "file", required = true)
private File file;
/**
* The bundled API docs for the artifact.
- *
+ *
* @since 2.3
*/
- @Parameter( property = "javadoc" )
+ @Parameter(property = "javadoc")
private File javadoc;
/**
* The bundled sources for the artifact.
- *
+ *
* @since 2.3
*/
- @Parameter( property = "sources" )
+ @Parameter(property = "sources")
private File sources;
/**
* Location of an existing POM file to be installed alongside the main artifact, given by the {@link #file}
* parameter.
- *
+ *
* @since 2.1
*/
- @Parameter( property = "pomFile" )
+ @Parameter(property = "pomFile")
private File pomFile;
/**
* Generate a minimal POM for the artifact if none is supplied via the parameter {@link #pomFile}. Defaults to
* <code>true</code> if there is no existing POM in the local repository yet.
- *
+ *
* @since 2.1
*/
- @Parameter( property = "generatePom" )
+ @Parameter(property = "generatePom")
private Boolean generatePom;
/**
* The path for a specific local repository directory. If not specified the local repository path configured in the
* Maven settings will be used.
- *
+ *
* @since 2.2
*/
- @Parameter( property = "localRepositoryPath" )
+ @Parameter(property = "localRepositoryPath")
private File localRepositoryPath;
@Override
- public void execute()
- throws MojoExecutionException, MojoFailureException
- {
- if ( !file.exists() )
- {
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ if (!file.exists()) {
String message = "The specified file '" + file.getPath() + "' does not exist";
- getLog().error( message );
- throw new MojoFailureException( message );
+ getLog().error(message);
+ throw new MojoFailureException(message);
}
RepositorySystemSession repositorySystemSession = session.getRepositorySession();
- if ( localRepositoryPath != null )
- {
+ if (localRepositoryPath != null) {
// "clone" repository session and replace localRepository
- DefaultRepositorySystemSession newSession = new DefaultRepositorySystemSession(
- session.getRepositorySession() );
+ DefaultRepositorySystemSession newSession =
+ new DefaultRepositorySystemSession(session.getRepositorySession());
// Clear cache, since we're using a new local repository
- newSession.setCache( new DefaultRepositoryCache() );
+ newSession.setCache(new DefaultRepositoryCache());
// keep same repositoryType
String contentType = newSession.getLocalRepository().getContentType();
- if ( "enhanced".equals( contentType ) )
- {
+ if ("enhanced".equals(contentType)) {
contentType = "default";
}
- LocalRepositoryManager localRepositoryManager = repositorySystem.newLocalRepositoryManager( newSession,
- new LocalRepository( localRepositoryPath, contentType ) );
- newSession.setLocalRepositoryManager( localRepositoryManager );
+ LocalRepositoryManager localRepositoryManager = repositorySystem.newLocalRepositoryManager(
+ newSession, new LocalRepository(localRepositoryPath, contentType));
+ newSession.setLocalRepositoryManager(localRepositoryManager);
repositorySystemSession = newSession;
- getLog().debug( "localRepoPath: " + localRepositoryManager.getRepository().getBasedir() );
+ getLog().debug("localRepoPath: "
+ + localRepositoryManager.getRepository().getBasedir());
}
File temporaryPom = null;
- if ( pomFile != null )
- {
- processModel( readModel( pomFile ) );
- }
- else
- {
+ if (pomFile != null) {
+ processModel(readModel(pomFile));
+ } else {
temporaryPom = readingPomFromJarFile();
- if ( !Boolean.TRUE.equals( generatePom ) )
- {
+ if (!Boolean.TRUE.equals(generatePom)) {
pomFile = temporaryPom;
- getLog().debug( "Using JAR embedded POM as pomFile" );
+ getLog().debug("Using JAR embedded POM as pomFile");
}
}
- 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.");
}
InstallRequest installRequest = new InstallRequest();
- boolean isFilePom = classifier == null && "pom".equals( packaging );
- if ( !isFilePom )
- {
- ArtifactType artifactType = repositorySystemSession.getArtifactTypeRegistry().get( packaging );
- if ( artifactType != null
- && StringUtils.isEmpty( classifier )
- && !StringUtils.isEmpty( artifactType.getClassifier() ) )
- {
+ boolean isFilePom = classifier == null && "pom".equals(packaging);
+ if (!isFilePom) {
+ ArtifactType artifactType =
+ repositorySystemSession.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 );
- installRequest.addArtifact( mainArtifact );
-
- File artifactLocalFile = getLocalRepositoryFile( session.getRepositorySession(), mainArtifact );
- File pomLocalFile = getPomLocalRepositoryFile( session.getRepositorySession(), mainArtifact );
-
- if ( file.equals( artifactLocalFile ) )
- {
- throw new MojoFailureException( "Cannot install artifact. "
- + "Artifact is already in the local repository." + LS + LS + "File in question is: " + file + LS );
+ groupId, artifactId, classifier, isFilePom ? "pom" : getExtension(file), version)
+ .setFile(file);
+ installRequest.addArtifact(mainArtifact);
+
+ File artifactLocalFile = getLocalRepositoryFile(repositorySystemSession, mainArtifact);
+ File pomLocalFile = getPomLocalRepositoryFile(repositorySystemSession, mainArtifact);
+
+ if (file.equals(artifactLocalFile)) {
+ throw new MojoFailureException("Cannot install artifact. " + "Artifact is already in the local repository."
+ + LS + LS + "File in question is: " + file + LS);
}
- if ( !"pom".equals( packaging ) )
- {
- if ( pomFile != null )
- {
- installRequest.addArtifact( new SubArtifact( mainArtifact, "", "pom", pomFile ) );
- }
- else
- {
- if ( Boolean.TRUE.equals( generatePom ) || ( generatePom == null && !pomLocalFile.exists() ) )
- {
+ if (!"pom".equals(packaging)) {
+ if (pomFile != null) {
+ installRequest.addArtifact(new SubArtifact(mainArtifact, "", "pom", pomFile));
+ } else {
+ if (Boolean.TRUE.equals(generatePom) || (generatePom == null && !pomLocalFile.exists())) {
temporaryPom = generatePomFile();
- getLog().debug( "Installing generated POM" );
- installRequest.addArtifact( new SubArtifact( mainArtifact, "", "pom", temporaryPom ) );
- }
- else if ( generatePom == null )
- {
- getLog().debug( "Skipping installation of generated POM, already present in local repository" );
+ getLog().debug("Installing generated POM");
+ installRequest.addArtifact(new SubArtifact(mainArtifact, "", "pom", temporaryPom));
+ } else if (generatePom == null) {
+ getLog().debug("Skipping installation of generated POM, already present in local repository");
}
}
}
- if ( sources != null )
- {
- installRequest.addArtifact( new SubArtifact( mainArtifact, "sources", "jar", sources ) );
+ if (sources != null) {
+ installRequest.addArtifact(new SubArtifact(mainArtifact, "sources", "jar", sources));
}
- if ( javadoc != null )
- {
- installRequest.addArtifact( new SubArtifact( mainArtifact, "javadoc", "jar", javadoc ) );
+ if (javadoc != null) {
+ installRequest.addArtifact(new SubArtifact(mainArtifact, "javadoc", "jar", javadoc));
}
- try
- {
- repositorySystem.install( repositorySystemSession, installRequest );
- }
- catch ( InstallationException e )
- {
- throw new MojoExecutionException( e.getMessage(), e );
- }
- finally
- {
- if ( temporaryPom != null )
- {
+ try {
+ repositorySystem.install(repositorySystemSession, installRequest);
+ } catch (InstallationException e) {
+ throw new MojoExecutionException(e.getMessage(), e);
+ } finally {
+ if (temporaryPom != null) {
// noinspection ResultOfMethodCallIgnored
temporaryPom.delete();
}
}
}
- private File readingPomFromJarFile()
- throws MojoExecutionException
- {
+ private File readingPomFromJarFile() throws MojoExecutionException {
File pomFile = null;
JarFile jarFile = null;
- try
- {
- Pattern pomEntry = Pattern.compile( "META-INF/maven/.*/pom\\.xml" );
+ try {
+ Pattern pomEntry = Pattern.compile("META-INF/maven/.*/pom\\.xml");
- jarFile = new JarFile( file );
+ jarFile = new JarFile(file);
Enumeration<JarEntry> jarEntries = jarFile.entries();
- while ( jarEntries.hasMoreElements() )
- {
+ while (jarEntries.hasMoreElements()) {
JarEntry entry = jarEntries.nextElement();
- if ( pomEntry.matcher( entry.getName() ).matches() )
- {
- getLog().debug( "Loading " + entry.getName() );
+ if (pomEntry.matcher(entry.getName()).matches()) {
+ getLog().debug("Loading " + entry.getName());
InputStream pomInputStream = null;
OutputStream pomOutputStream = null;
- try
- {
- pomInputStream = jarFile.getInputStream( entry );
+ try {
+ pomInputStream = jarFile.getInputStream(entry);
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 = File.createTempFile( base, ".pom" );
+ pomFile = File.createTempFile(base, ".pom");
- pomOutputStream = Files.newOutputStream( pomFile.toPath() );
+ pomOutputStream = Files.newOutputStream(pomFile.toPath());
- IOUtil.copy( pomInputStream, pomOutputStream );
+ IOUtil.copy(pomInputStream, pomOutputStream);
pomOutputStream.close();
pomOutputStream = null;
@@ -352,37 +309,26 @@ public class InstallFileMojo
pomInputStream.close();
pomInputStream = null;
- processModel( readModel( pomFile ) );
+ processModel(readModel(pomFile));
break;
- }
- finally
- {
- IOUtil.close( pomInputStream );
- IOUtil.close( pomOutputStream );
+ } finally {
+ IOUtil.close(pomInputStream);
+ IOUtil.close(pomOutputStream);
}
}
}
- if ( pomFile == null )
- {
- getLog().info( "pom.xml not found in " + file.getName() );
+ if (pomFile == null) {
+ getLog().info("pom.xml not found in " + file.getName());
}
- }
- catch ( IOException e )
- {
+ } catch (IOException e) {
// ignore, artifact not packaged by Maven
- }
- finally
- {
- if ( jarFile != null )
- {
- try
- {
+ } finally {
+ if (jarFile != null) {
+ try {
jarFile.close();
- }
- catch ( IOException e )
- {
+ } catch (IOException e) {
// we did our best
}
}
@@ -392,93 +338,74 @@ public class InstallFileMojo
/**
* Parses a POM.
- *
+ *
* @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 POM could not be parsed.
*/
- private Model readModel( File pomFile )
- throws MojoExecutionException
- {
+ private Model readModel(File pomFile) throws MojoExecutionException {
Reader reader = null;
- try
- {
- reader = new XmlStreamReader( pomFile );
- final Model model = new MavenXpp3Reader().read( reader );
+ try {
+ reader = new XmlStreamReader(pomFile);
+ final Model model = new MavenXpp3Reader().read(reader);
reader.close();
reader = null;
return model;
- }
- catch ( FileNotFoundException e )
- {
- throw new MojoExecutionException( "File 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("File 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);
}
}
/**
* Populates missing mojo parameters from the specified POM.
- *
+ *
* @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();
}
}
/**
* 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( "POM was created from install:install-file" );
+ model.setDescription("POM was created from install:install-file");
return model;
}
@@ -486,34 +413,27 @@ public class InstallFileMojo
/**
* Generates a (temporary) POM file from the plugin configuration. It's the responsibility of the caller to delete
* the generated file when no longer needed.
- *
+ *
* @return The path to the generated POM file, never <code>null</code>.
* @throws MojoExecutionException If the POM file could not be generated.
*/
- private File generatePomFile()
- throws MojoExecutionException
- {
+ private File generatePomFile() throws MojoExecutionException {
Model model = generateModel();
Writer writer = null;
- try
- {
- File pomFile = File.createTempFile( "mvninstall", ".pom" );
+ try {
+ File pomFile = File.createTempFile("mvninstall", ".pom");
- writer = new XmlStreamWriter( pomFile );
- new MavenXpp3Writer().write( writer, model );
+ writer = new XmlStreamWriter(pomFile);
+ new MavenXpp3Writer().write(writer, model);
writer.close();
writer = null;
return pomFile;
- }
- catch ( IOException e )
- {
- throw new MojoExecutionException( "Error writing temporary POM file: " + e.getMessage(), e );
- }
- finally
- {
- IOUtil.close( writer );
+ } catch (IOException e) {
+ throw new MojoExecutionException("Error writing temporary POM file: " + e.getMessage(), e);
+ } finally {
+ IOUtil.close(writer);
}
}
@@ -521,21 +441,19 @@ public class InstallFileMojo
* 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);
}
/**
* Gets the path of the specified artifact POM within the local repository. Note that the returned path need
* not exist (yet).
*/
- private File getPomLocalRepositoryFile( RepositorySystemSession session, Artifact artifact )
- {
- SubArtifact pomArtifact = new SubArtifact( artifact, "", "pom" );
- String path = session.getLocalRepositoryManager().getPathForLocalArtifact( pomArtifact );
- return new File( session.getLocalRepository().getBasedir(), path );
+ private File getPomLocalRepositoryFile(RepositorySystemSession session, Artifact artifact) {
+ SubArtifact pomArtifact = new SubArtifact(artifact, "", "pom");
+ String path = session.getLocalRepositoryManager().getPathForLocalArtifact(pomArtifact);
+ return new File(session.getLocalRepository().getBasedir(), path);
}
// these below should be shared (duplicated in m-install-p, m-deploy-p)
@@ -543,34 +461,30 @@ public class InstallFileMojo
/**
* 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;
}
}
@@ -582,20 +496,15 @@ public class InstallFileMojo
/**
* 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;
}
}
return true;
}
-
}
=====================================
src/main/java/org/apache/maven/plugins/install/InstallMojo.java
=====================================
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.install;
-
/*
* 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.install;
* "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.install;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.install;
import java.io.File;
import java.util.ArrayList;
@@ -47,23 +46,21 @@ import org.eclipse.aether.installation.InstallationException;
*
* @author <a href="mailto:evenisse at apache.org">Emmanuel Venisse</a>
*/
- at Mojo( name = "install", defaultPhase = LifecyclePhase.INSTALL, threadSafe = true )
-public class InstallMojo
- extends AbstractMojo
-{
+ at Mojo(name = "install", defaultPhase = LifecyclePhase.INSTALL, threadSafe = true)
+public class InstallMojo extends AbstractMojo {
@Component
private RepositorySystem repositorySystem;
- @Parameter( defaultValue = "${session}", required = true, readonly = true )
+ @Parameter(defaultValue = "${session}", required = true, readonly = true)
private MavenSession session;
- @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;
/**
@@ -73,7 +70,7 @@ public class InstallMojo
*
* @since 2.5
*/
- @Parameter( defaultValue = "false", property = "installAtEnd" )
+ @Parameter(defaultValue = "false", property = "installAtEnd")
private boolean installAtEnd;
/**
@@ -82,127 +79,112 @@ public class InstallMojo
*
* @since 2.4
*/
- @Parameter( property = "maven.install.skip", defaultValue = "false" )
+ @Parameter(property = "maven.install.skip", defaultValue = "false")
private boolean skip;
- private enum State
- {
- SKIPPED, INSTALLED, TO_BE_INSTALLED
+ /**
+ * Set this to <code>true</code> to allow incomplete project processing. By default, such projects are forbidden
+ * and Mojo will fail to process them. Incomplete project is a Maven Project that has any other packaging than
+ * "pom" and has no main artifact packaged. In the majority of cases, what user really wants here is a project
+ * with "pom" packaging and some classified artifact attached (typical example is some assembly being packaged
+ * and attached with classifier).
+ *
+ * @since 3.1.1
+ */
+ @Parameter(defaultValue = "false", property = "allowIncompleteProjects")
+ private boolean allowIncompleteProjects;
+
+ private enum State {
+ SKIPPED,
+ INSTALLED,
+ TO_BE_INSTALLED
}
private static final String INSTALL_PROCESSED_MARKER = InstallMojo.class.getName() + ".processed";
- private void putState( State state )
- {
- getPluginContext().put( INSTALL_PROCESSED_MARKER, state.name() );
+ private void putState(State state) {
+ getPluginContext().put(INSTALL_PROCESSED_MARKER, state.name());
}
- private State getState( MavenProject project )
- {
- Map<String, Object> pluginContext = session.getPluginContext( pluginDescriptor, project );
- return State.valueOf( (String) pluginContext.get( INSTALL_PROCESSED_MARKER ) );
+ private State getState(MavenProject project) {
+ Map<String, Object> pluginContext = session.getPluginContext(pluginDescriptor, project);
+ return State.valueOf((String) pluginContext.get(INSTALL_PROCESSED_MARKER));
}
- private boolean hasState( MavenProject project )
- {
- Map<String, Object> pluginContext = session.getPluginContext( pluginDescriptor, project );
- return pluginContext.containsKey( INSTALL_PROCESSED_MARKER );
+ private boolean hasState(MavenProject project) {
+ Map<String, Object> pluginContext = session.getPluginContext(pluginDescriptor, project);
+ return pluginContext.containsKey(INSTALL_PROCESSED_MARKER);
}
@Override
- public void execute()
- throws MojoExecutionException
- {
- if ( skip )
- {
- getLog().info( "Skipping artifact installation" );
- putState( State.SKIPPED );
- }
- else
- {
- if ( !installAtEnd )
- {
+ public void execute() throws MojoExecutionException {
+ if (skip) {
+ getLog().info("Skipping artifact installation");
+ putState(State.SKIPPED);
+ } else {
+ if (!installAtEnd) {
InstallRequest request = new InstallRequest();
- processProject( project, request );
- installProject( request );
- putState( State.INSTALLED );
- }
- else
- {
- getLog().info( "Deferring install for " + project.getGroupId()
- + ":" + project.getArtifactId() + ":" + project.getVersion() + " at end" );
- putState( State.TO_BE_INSTALLED );
+ processProject(project, request);
+ installProject(request);
+ putState(State.INSTALLED);
+ } else {
+ getLog().info("Deferring install for " + project.getGroupId() + ":" + project.getArtifactId() + ":"
+ + project.getVersion() + " at end");
+ putState(State.TO_BE_INSTALLED);
}
}
List<MavenProject> allProjectsUsingPlugin = getAllProjectsUsingPlugin();
- if ( allProjectsMarked( allProjectsUsingPlugin ) )
- {
+ if (allProjectsMarked(allProjectsUsingPlugin)) {
InstallRequest request = new InstallRequest();
- for ( MavenProject reactorProject : allProjectsUsingPlugin )
- {
- State state = getState( reactorProject );
- if ( state == State.TO_BE_INSTALLED )
- {
- processProject( reactorProject, request );
+ for (MavenProject reactorProject : allProjectsUsingPlugin) {
+ State state = getState(reactorProject);
+ if (state == State.TO_BE_INSTALLED) {
+ processProject(reactorProject, request);
}
}
- installProject( request );
+ installProject(request);
}
}
- private boolean allProjectsMarked( List<MavenProject> allProjectsUsingPlugin )
- {
- for ( MavenProject reactorProject : allProjectsUsingPlugin )
- {
- if ( !hasState( reactorProject ) )
- {
+ private boolean allProjectsMarked(List<MavenProject> allProjectsUsingPlugin) {
+ for (MavenProject reactorProject : allProjectsUsingPlugin) {
+ if (!hasState(reactorProject)) {
return false;
}
}
return true;
}
- private List<MavenProject> getAllProjectsUsingPlugin()
- {
+ private List<MavenProject> getAllProjectsUsingPlugin() {
ArrayList<MavenProject> result = new ArrayList<>();
- for ( MavenProject reactorProject : reactorProjects )
- {
- if ( hasExecution( reactorProject.getPlugin( "org.apache.maven.plugins:maven-install-plugin" ) ) )
- {
- result.add( reactorProject );
+ for (MavenProject reactorProject : reactorProjects) {
+ if (hasExecution(reactorProject.getPlugin("org.apache.maven.plugins:maven-install-plugin"))) {
+ result.add(reactorProject);
}
}
return result;
}
- private boolean hasExecution( Plugin plugin )
- {
- if ( plugin == null )
- {
+ private boolean hasExecution(Plugin plugin) {
+ if (plugin == null) {
return false;
}
- for ( PluginExecution execution : plugin.getExecutions() )
- {
- if ( !execution.getGoals().isEmpty() && !"none".equalsIgnoreCase( execution.getPhase() ) )
- {
+ for (PluginExecution execution : plugin.getExecutions()) {
+ if (!execution.getGoals().isEmpty() && !"none".equalsIgnoreCase(execution.getPhase())) {
return true;
}
}
return false;
}
- private void installProject( InstallRequest request ) throws MojoExecutionException
- {
- try
- {
- repositorySystem.install( session.getRepositorySession(), request );
- }
- catch ( InstallationException e )
- {
- throw new MojoExecutionException( e.getMessage(), e );
+ private void installProject(InstallRequest request) throws MojoExecutionException {
+ try {
+ repositorySystem.install(session.getRepositorySession(), request);
+ } catch (InstallationException e) {
+ throw new MojoExecutionException(e.getMessage(), e);
}
}
@@ -211,46 +193,42 @@ public class InstallMojo
*
* @throws MojoExecutionException if project is badly set up.
*/
- private void processProject( MavenProject project, InstallRequest request ) throws MojoExecutionException
- {
- if ( isFile( project.getFile() ) )
- {
- request.addArtifact( RepositoryUtils.toArtifact( new ProjectArtifact( project ) ) );
- }
- else
- {
- throw new MojoExecutionException( "The project POM could not be attached" );
+ private void processProject(MavenProject project, InstallRequest request) throws MojoExecutionException {
+ if (isFile(project.getFile())) {
+ request.addArtifact(RepositoryUtils.toArtifact(new ProjectArtifact(project)));
+ } else {
+ throw new MojoExecutionException("The project POM could not be attached");
}
- if ( !"pom".equals( project.getPackaging() ) )
- {
+ if (!"pom".equals(project.getPackaging())) {
org.apache.maven.artifact.Artifact mavenMainArtifact = project.getArtifact();
- if ( isFile( mavenMainArtifact.getFile() ) )
- {
- request.addArtifact( RepositoryUtils.toArtifact( mavenMainArtifact ) );
- }
- 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 (isFile(mavenMainArtifact.getFile())) {
+ request.addArtifact(RepositoryUtils.toArtifact(mavenMainArtifact));
+ } else if (!project.getAttachedArtifacts().isEmpty()) {
+ if (allowIncompleteProjects) {
+ getLog().warn("");
+ getLog().warn("The packaging plugin for this project did not assign");
+ getLog().warn("a main file to the project but it has attachments. Change packaging to 'pom'.");
+ getLog().warn("");
+ getLog().warn("Incomplete projects like this will fail in future Maven versions!");
+ getLog().warn("");
+ } else {
+ 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");
}
}
-
- 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));
}
}
- private boolean isFile( File file )
- {
+ private boolean isFile(File file) {
return file != null && file.isFile();
}
}
=====================================
src/test/java/org/apache/maven/plugins/install/InstallFileMojoTest.java
=====================================
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.install;
-
/*
* 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.install;
* "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.install;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.install;
import java.io.File;
import java.io.Reader;
@@ -41,9 +40,7 @@ import static org.mockito.Mockito.when;
/**
* @author <a href="mailto:aramirez at apache.org">Allan Ramirez</a>
*/
-public class InstallFileMojoTest
- extends AbstractMojoTestCase
-{
+public class InstallFileMojoTest extends AbstractMojoTestCase {
private String groupId;
private String artifactId;
@@ -58,237 +55,298 @@ public class InstallFileMojoTest
private final String LOCAL_REPO = "target/local-repo/";
- public void setUp()
- throws Exception
- {
+ private final String SPECIFIC_LOCAL_REPO = "target/specific-local-repo/";
+
+ public void setUp() throws Exception {
super.setUp();
- FileUtils.deleteDirectory( new File( getBasedir() + "/" + LOCAL_REPO ) );
+ FileUtils.deleteDirectory(new File(getBasedir() + "/" + LOCAL_REPO));
+ FileUtils.deleteDirectory(new File(getBasedir() + "/" + SPECIFIC_LOCAL_REPO));
+ }
+
+ public void testInstallFileFromLocalRepositoryToLocalRepositoryPath() throws Exception {
+ File localRepository =
+ new File(getBasedir(), "target/test-classes/unit/install-file-from-local-repository-test/target");
+
+ File testPom = new File(localRepository.getParentFile(), "plugin-config.xml");
+
+ InstallFileMojo mojo = (InstallFileMojo) lookupMojo("install-file", testPom);
+
+ assertNotNull(mojo);
+
+ setVariableValueToObject(mojo, "session", createMavenSession(localRepository.getAbsolutePath()));
+
+ File specificLocalRepositoryPath = new File(getBasedir() + "/" + SPECIFIC_LOCAL_REPO);
+
+ setVariableValueToObject(mojo, "localRepositoryPath", specificLocalRepositoryPath);
+
+ assignValuesForParameter(mojo);
+
+ mojo.execute();
+
+ String localPath = getBasedir() + "/" + SPECIFIC_LOCAL_REPO + groupId + "/" + artifactId + "/" + version + "/"
+ + artifactId + "-" + version;
+
+ File installedArtifact = new File(localPath + "." + "jar");
+
+ assertTrue(installedArtifact.exists());
+
+ assertEquals(
+ FileUtils.getFiles(new File(SPECIFIC_LOCAL_REPO), null, null).toString(),
+ 5,
+ FileUtils.getFiles(new File(SPECIFIC_LOCAL_REPO), null, null).size());
+ }
+
+ public void testInstallFileWithLocalRepositoryPath() throws Exception {
+ File testPom =
+ new File(getBasedir(), "target/test-classes/unit/install-file-with-checksum/" + "plugin-config.xml");
+
+ InstallFileMojo mojo = (InstallFileMojo) lookupMojo("install-file", testPom);
+
+ assertNotNull(mojo);
+
+ setVariableValueToObject(mojo, "session", createMavenSession(LOCAL_REPO));
+
+ File specificLocalRepositoryPath = new File(getBasedir() + "/" + SPECIFIC_LOCAL_REPO);
+
+ setVariableValueToObject(mojo, "localRepositoryPath", specificLocalRepositoryPath);
+
+ assignValuesForParameter(mojo);
+
+ mojo.execute();
+
+ String localPath = getBasedir() + "/" + SPECIFIC_LOCAL_REPO + groupId + "/" + artifactId + "/" + version + "/"
+ + artifactId + "-" + version;
+
+ File installedArtifact = new File(localPath + "." + "jar");
+
+ assertTrue(installedArtifact.exists());
+
+ assertEquals(
+ FileUtils.getFiles(new File(SPECIFIC_LOCAL_REPO), null, null).toString(),
+ 5,
+ FileUtils.getFiles(new File(SPECIFIC_LOCAL_REPO), null, null).size());
}
- public void testInstallFileTestEnvironment()
- throws Exception
- {
- File testPom = new File( getBasedir(), "target/test-classes/unit/install-file-basic-test/plugin-config.xml" );
+ public void testInstallFileTestEnvironment() throws Exception {
+ File testPom = new File(getBasedir(), "target/test-classes/unit/install-file-basic-test/plugin-config.xml");
+
+ InstallFileMojo mojo = (InstallFileMojo) lookupMojo("install-file", testPom);
- InstallFileMojo mojo = (InstallFileMojo) lookupMojo( "install-file", testPom );
-
- setVariableValueToObject( mojo, "session", createMavenSession() );
+ setVariableValueToObject(mojo, "session", createMavenSession(LOCAL_REPO));
- assertNotNull( mojo );
+ assertNotNull(mojo);
}
- public void testBasicInstallFile()
- throws Exception
- {
- File testPom = new File( getBasedir(), "target/test-classes/unit/install-file-basic-test/plugin-config.xml" );
+ public void testBasicInstallFile() throws Exception {
+ File testPom = new File(getBasedir(), "target/test-classes/unit/install-file-basic-test/plugin-config.xml");
- InstallFileMojo mojo = (InstallFileMojo) lookupMojo( "install-file", testPom );
+ InstallFileMojo mojo = (InstallFileMojo) lookupMojo("install-file", testPom);
- assertNotNull( mojo );
-
- setVariableValueToObject( mojo, "session", createMavenSession() );
+ assertNotNull(mojo);
- assignValuesForParameter( mojo );
+ setVariableValueToObject(mojo, "session", createMavenSession(LOCAL_REPO));
+
+ assignValuesForParameter(mojo);
mojo.execute();
- File installedArtifact = new File( getBasedir(), LOCAL_REPO + groupId + "/" + artifactId + "/" + version + "/" +
- artifactId + "-" + version + "." + packaging );
+ File installedArtifact = new File(
+ getBasedir(),
+ LOCAL_REPO + groupId + "/" + artifactId + "/" + version + "/" + artifactId + "-" + version + "."
+ + packaging);
+
+ assertTrue(installedArtifact.exists());
- assertTrue( installedArtifact.exists() );
-
- assertEquals( 5, FileUtils.getFiles( new File( LOCAL_REPO ), null, null ).size() );
+ assertEquals(5, FileUtils.getFiles(new File(LOCAL_REPO), null, null).size());
}
- public void testInstallFileWithClassifier()
- throws Exception
- {
+ public void testInstallFileWithClassifier() throws Exception {
File testPom =
- new File( getBasedir(), "target/test-classes/unit/install-file-with-classifier/plugin-config.xml" );
+ new File(getBasedir(), "target/test-classes/unit/install-file-with-classifier/plugin-config.xml");
+
+ InstallFileMojo mojo = (InstallFileMojo) lookupMojo("install-file", testPom);
- InstallFileMojo mojo = (InstallFileMojo) lookupMojo( "install-file", testPom );
+ assertNotNull(mojo);
- assertNotNull( mojo );
-
- setVariableValueToObject( mojo, "session", createMavenSession() );
+ setVariableValueToObject(mojo, "session", createMavenSession(LOCAL_REPO));
- assignValuesForParameter( mojo );
+ assignValuesForParameter(mojo);
- assertNotNull( classifier );
+ assertNotNull(classifier);
mojo.execute();
- File installedArtifact = new File( getBasedir(), LOCAL_REPO + groupId + "/" + artifactId + "/" + version + "/" +
- artifactId + "-" + version + "-" + classifier + "." + packaging );
+ File installedArtifact = new File(
+ getBasedir(),
+ LOCAL_REPO + groupId + "/" + artifactId + "/" + version + "/" + artifactId + "-" + version + "-"
+ + classifier + "." + packaging);
- assertTrue( installedArtifact.exists() );
-
- assertEquals( 5, FileUtils.getFiles( new File( LOCAL_REPO ), null, null ).size() );
+ assertTrue(installedArtifact.exists());
+
+ assertEquals(5, FileUtils.getFiles(new File(LOCAL_REPO), null, null).size());
}
- public void testInstallFileWithGeneratePom()
- throws Exception
- {
+ public void testInstallFileWithGeneratePom() throws Exception {
File testPom =
- new File( getBasedir(), "target/test-classes/unit/install-file-test-generatePom/plugin-config.xml" );
+ new File(getBasedir(), "target/test-classes/unit/install-file-test-generatePom/plugin-config.xml");
+
+ InstallFileMojo mojo = (InstallFileMojo) lookupMojo("install-file", testPom);
- InstallFileMojo mojo = (InstallFileMojo) lookupMojo( "install-file", testPom );
+ assertNotNull(mojo);
- assertNotNull( mojo );
-
- setVariableValueToObject( mojo, "session", createMavenSession() );
+ setVariableValueToObject(mojo, "session", createMavenSession(LOCAL_REPO));
- assignValuesForParameter( mojo );
+ assignValuesForParameter(mojo);
mojo.execute();
- File installedArtifact = new File( getBasedir(), LOCAL_REPO + groupId + "/" + artifactId + "/" + version + "/" +
- artifactId + "-" + version + "." + packaging );
+ File installedArtifact = new File(
+ getBasedir(),
+ LOCAL_REPO + groupId + "/" + artifactId + "/" + version + "/" + artifactId + "-" + version + "."
+ + packaging);
+
+ assertTrue((Boolean) getVariableValueFromObject(mojo, "generatePom"));
- assertTrue( (Boolean) getVariableValueFromObject( mojo, "generatePom" ) );
+ assertTrue(installedArtifact.exists());
- assertTrue( installedArtifact.exists() );
+ File installedPom = new File(
+ getBasedir(),
+ LOCAL_REPO + groupId + "/" + artifactId + "/" + version + "/" + artifactId + "-" + version + "."
+ + "pom");
- File installedPom = new File( getBasedir(), LOCAL_REPO + groupId + "/" + artifactId + "/" + version + "/" +
- artifactId + "-" + version + "." + "pom" );
+ try (Reader reader = new XmlStreamReader(installedPom)) {
+ Model model = new MavenXpp3Reader().read(reader);
- try ( Reader reader = new XmlStreamReader( installedPom ) ) {
- Model model = new MavenXpp3Reader().read( reader );
+ assertEquals("4.0.0", model.getModelVersion());
- assertEquals( "4.0.0", model.getModelVersion() );
-
- assertEquals( (String) getVariableValueFromObject( mojo, "groupId" ), model.getGroupId() );
-
- assertEquals( artifactId, model.getArtifactId() );
-
- assertEquals( version, model.getVersion() );
+ assertEquals((String) getVariableValueFromObject(mojo, "groupId"), model.getGroupId());
+
+ assertEquals(artifactId, model.getArtifactId());
+
+ assertEquals(version, model.getVersion());
}
- assertEquals( 5, FileUtils.getFiles( new File( LOCAL_REPO ), null, null ).size() );
+ assertEquals(5, FileUtils.getFiles(new File(LOCAL_REPO), null, null).size());
}
- public void testInstallFileWithPomFile()
- throws Exception
- {
+ public void testInstallFileWithPomFile() throws Exception {
File testPom =
- new File( getBasedir(), "target/test-classes/unit/install-file-with-pomFile-test/plugin-config.xml" );
+ new File(getBasedir(), "target/test-classes/unit/install-file-with-pomFile-test/plugin-config.xml");
+
+ InstallFileMojo mojo = (InstallFileMojo) lookupMojo("install-file", testPom);
- InstallFileMojo mojo = (InstallFileMojo) lookupMojo( "install-file", testPom );
+ assertNotNull(mojo);
- assertNotNull( mojo );
-
- setVariableValueToObject( mojo, "session", createMavenSession() );
+ setVariableValueToObject(mojo, "session", createMavenSession(LOCAL_REPO));
- assignValuesForParameter( mojo );
+ assignValuesForParameter(mojo);
mojo.execute();
- File pomFile = (File) getVariableValueFromObject( mojo, "pomFile" );
+ File pomFile = (File) getVariableValueFromObject(mojo, "pomFile");
- assertTrue( pomFile.exists() );
+ assertTrue(pomFile.exists());
- File installedArtifact = new File( getBasedir(), LOCAL_REPO + groupId + "/" + artifactId + "/" + version + "/" +
- artifactId + "-" + version + "." + packaging );
+ File installedArtifact = new File(
+ getBasedir(),
+ LOCAL_REPO + groupId + "/" + artifactId + "/" + version + "/" + artifactId + "-" + version + "."
+ + packaging);
- assertTrue( installedArtifact.exists() );
+ assertTrue(installedArtifact.exists());
- File installedPom = new File( getBasedir(), LOCAL_REPO + groupId + "/" + artifactId + "/" + version + "/" +
- artifactId + "-" + version + "." + "pom" );
+ File installedPom = new File(
+ getBasedir(),
+ LOCAL_REPO + groupId + "/" + artifactId + "/" + version + "/" + artifactId + "-" + version + "."
+ + "pom");
- assertTrue( installedPom.exists() );
-
- assertEquals( 5, FileUtils.getFiles( new File( LOCAL_REPO ), null, null ).size() );
+ assertTrue(installedPom.exists());
+
+ assertEquals(5, FileUtils.getFiles(new File(LOCAL_REPO), null, null).size());
}
- public void testInstallFileWithPomAsPackaging()
- throws Exception
- {
- File testPom = new File( getBasedir(),
- "target/test-classes/unit/install-file-with-pom-as-packaging/" + "plugin-config.xml" );
+ public void testInstallFileWithPomAsPackaging() throws Exception {
+ File testPom = new File(
+ getBasedir(), "target/test-classes/unit/install-file-with-pom-as-packaging/" + "plugin-config.xml");
+
+ InstallFileMojo mojo = (InstallFileMojo) lookupMojo("install-file", testPom);
- InstallFileMojo mojo = (InstallFileMojo) lookupMojo( "install-file", testPom );
+ assertNotNull(mojo);
- assertNotNull( mojo );
-
- setVariableValueToObject( mojo, "session", createMavenSession() );
+ setVariableValueToObject(mojo, "session", createMavenSession(LOCAL_REPO));
- assignValuesForParameter( mojo );
+ assignValuesForParameter(mojo);
- assertTrue( file.exists() );
+ assertTrue(file.exists());
- assertEquals( "pom", packaging );
+ assertEquals("pom", packaging);
mojo.execute();
- File installedPom = new File( getBasedir(), LOCAL_REPO + groupId + "/" + artifactId + "/" + version + "/" +
- artifactId + "-" + version + "." + "pom" );
+ File installedPom = new File(
+ getBasedir(),
+ LOCAL_REPO + groupId + "/" + artifactId + "/" + version + "/" + artifactId + "-" + version + "."
+ + "pom");
- assertTrue( installedPom.exists() );
+ assertTrue(installedPom.exists());
- assertEquals( 4, FileUtils.getFiles( new File( LOCAL_REPO ), null, null ).size() );
+ assertEquals(4, FileUtils.getFiles(new File(LOCAL_REPO), null, null).size());
}
- public void testInstallFile()
- throws Exception
- {
+ public void testInstallFile() throws Exception {
File testPom =
- new File( getBasedir(), "target/test-classes/unit/install-file-with-checksum/" + "plugin-config.xml" );
+ new File(getBasedir(), "target/test-classes/unit/install-file-with-checksum/" + "plugin-config.xml");
+
+ InstallFileMojo mojo = (InstallFileMojo) lookupMojo("install-file", testPom);
- InstallFileMojo mojo = (InstallFileMojo) lookupMojo( "install-file", testPom );
+ assertNotNull(mojo);
- assertNotNull( mojo );
-
- setVariableValueToObject( mojo, "session", createMavenSession() );
+ setVariableValueToObject(mojo, "session", createMavenSession(LOCAL_REPO));
- assignValuesForParameter( mojo );
+ assignValuesForParameter(mojo);
mojo.execute();
- String localPath = getBasedir() + "/" + LOCAL_REPO + groupId + "/" + artifactId + "/" + version + "/" +
- artifactId + "-" + version;
-
- File installedArtifact = new File( localPath + "." + "jar" );
-
- assertTrue( installedArtifact.exists() );
-
- assertEquals( FileUtils.getFiles( new File( LOCAL_REPO ), null, null ).toString(), 5, FileUtils.getFiles( new File( LOCAL_REPO ), null, null ).size() );
+ String localPath = getBasedir() + "/" + LOCAL_REPO + groupId + "/" + artifactId + "/" + version + "/"
+ + artifactId + "-" + version;
+
+ File installedArtifact = new File(localPath + "." + "jar");
+
+ assertTrue(installedArtifact.exists());
+
+ assertEquals(
+ FileUtils.getFiles(new File(LOCAL_REPO), null, null).toString(),
+ 5,
+ FileUtils.getFiles(new File(LOCAL_REPO), null, null).size());
}
- private void assignValuesForParameter( Object obj )
- throws Exception
- {
- this.groupId = dotToSlashReplacer( (String) getVariableValueFromObject( obj, "groupId" ) );
+ private void assignValuesForParameter(Object obj) throws Exception {
+ this.groupId = dotToSlashReplacer((String) getVariableValueFromObject(obj, "groupId"));
- this.artifactId = (String) getVariableValueFromObject( obj, "artifactId" );
+ this.artifactId = (String) getVariableValueFromObject(obj, "artifactId");
- this.version = (String) getVariableValueFromObject( obj, "version" );
+ this.version = (String) getVariableValueFromObject(obj, "version");
- this.packaging = (String) getVariableValueFromObject( obj, "packaging" );
+ this.packaging = (String) getVariableValueFromObject(obj, "packaging");
- this.classifier = (String) getVariableValueFromObject( obj, "classifier" );
+ this.classifier = (String) getVariableValueFromObject(obj, "classifier");
- this.file = (File) getVariableValueFromObject( obj, "file" );
+ this.file = (File) getVariableValueFromObject(obj, "file");
}
- private String dotToSlashReplacer( String parameter )
- {
- return parameter.replace( '.', '/' );
+ private String dotToSlashReplacer(String parameter) {
+ return parameter.replace('.', '/');
}
- private MavenSession createMavenSession() throws NoLocalRepositoryManagerException
- {
- MavenSession session = mock( MavenSession.class );
- DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
- repositorySession.setLocalRepositoryManager(
- new EnhancedLocalRepositoryManagerFactory().newInstance(
- repositorySession, new LocalRepository( LOCAL_REPO )
- )
- );
+ private MavenSession createMavenSession(String localRepositoryBaseDir) throws NoLocalRepositoryManagerException {
+ MavenSession session = mock(MavenSession.class);
+ DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
+ repositorySession.setLocalRepositoryManager(new EnhancedLocalRepositoryManagerFactory()
+ .newInstance(repositorySession, new LocalRepository(localRepositoryBaseDir)));
ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest();
- buildingRequest.setRepositorySession( repositorySession );
- when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
- when( session.getRepositorySession() ).thenReturn( repositorySession );
+ buildingRequest.setRepositorySession(repositorySession);
+ when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
+ when(session.getRepositorySession()).thenReturn(repositorySession);
return session;
}
}
=====================================
src/test/java/org/apache/maven/plugins/install/InstallMojoTest.java
=====================================
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.install;
-
/*
* 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.install;
* "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.install;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.install;
import java.io.File;
import java.util.Collections;
@@ -51,85 +50,80 @@ import static org.mockito.Mockito.when;
/**
* @author <a href="mailto:aramirez at apache.org">Allan Ramirez</a>
*/
-public class InstallMojoTest
- extends AbstractMojoTestCase
-{
+public class InstallMojoTest extends AbstractMojoTestCase {
InstallArtifactStub artifact;
private final String LOCAL_REPO = "target/local-repo/";
- public void setUp()
- throws Exception
- {
+ public void setUp() throws Exception {
super.setUp();
- FileUtils.deleteDirectory( new File( getBasedir() + "/" + LOCAL_REPO ) );
+ FileUtils.deleteDirectory(new File(getBasedir() + "/" + LOCAL_REPO));
}
- public void testInstallTestEnvironment()
- throws Exception
- {
- File testPom = new File( getBasedir(), "target/test-classes/unit/basic-install-test/plugin-config.xml" );
+ public void testInstallTestEnvironment() throws Exception {
+ File testPom = new File(getBasedir(), "target/test-classes/unit/basic-install-test/plugin-config.xml");
- AbstractMojo mojo = (AbstractMojo) lookupMojo( "install", testPom );
+ AbstractMojo mojo = (AbstractMojo) lookupMojo("install", testPom);
- assertNotNull( mojo );
+ assertNotNull(mojo);
}
- public void testBasicInstall()
- throws Exception
- {
- File testPom = new File( getBasedir(), "target/test-classes/unit/basic-install-test/plugin-config.xml" );
+ public void testBasicInstall() throws Exception {
+ File testPom = new File(getBasedir(), "target/test-classes/unit/basic-install-test/plugin-config.xml");
- AbstractMojo mojo = (AbstractMojo) lookupMojo( "install", testPom );
+ AbstractMojo mojo = (AbstractMojo) lookupMojo("install", testPom);
- assertNotNull( mojo );
+ assertNotNull(mojo);
- File file = new File( getBasedir(), "target/test-classes/unit/basic-install-test/target/"
- + "maven-install-test-1.0-SNAPSHOT.jar" );
+ File file = new File(
+ getBasedir(),
+ "target/test-classes/unit/basic-install-test/target/" + "maven-install-test-1.0-SNAPSHOT.jar");
- MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" );
- updateMavenProject( project );
+ MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
+ updateMavenProject(project);
- setVariableValueToObject( mojo, "pluginContext", new ConcurrentHashMap<>() );
- setVariableValueToObject( mojo, "pluginDescriptor", new PluginDescriptor() );
- setVariableValueToObject( mojo, "reactorProjects", Collections.singletonList( project ) );
- setVariableValueToObject( mojo, "session", createMavenSession() );
+ setVariableValueToObject(mojo, "pluginContext", new ConcurrentHashMap<>());
+ setVariableValueToObject(mojo, "pluginDescriptor", new PluginDescriptor());
+ setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project));
+ setVariableValueToObject(mojo, "session", createMavenSession());
artifact = (InstallArtifactStub) project.getArtifact();
- artifact.setFile( file );
+ artifact.setFile(file);
mojo.execute();
- String groupId = dotToSlashReplacer( artifact.getGroupId() );
+ String groupId = dotToSlashReplacer(artifact.getGroupId());
+
+ File installedArtifact = new File(
+ getBasedir(),
+ LOCAL_REPO + groupId + "/" + artifact.getArtifactId() + "/" + artifact.getVersion() + "/"
+ + artifact.getArtifactId() + "-" + artifact.getVersion() + "."
+ + artifact.getArtifactHandler().getExtension());
- File installedArtifact = new File( getBasedir(), LOCAL_REPO + groupId + "/" + artifact.getArtifactId() + "/" +
- artifact.getVersion() + "/" + artifact.getArtifactId() + "-" + artifact.getVersion() + "." + artifact.getArtifactHandler().getExtension() );
+ assertTrue(installedArtifact.exists());
- assertTrue( installedArtifact.exists() );
-
- assertEquals( 5, FileUtils.getFiles( new File( LOCAL_REPO ), null, null ).size() );
+ assertEquals(5, FileUtils.getFiles(new File(LOCAL_REPO), null, null).size());
}
- public void testBasicInstallWithAttachedArtifacts()
- throws Exception
- {
- File testPom = new File( getBasedir(), "target/test-classes/unit/basic-install-test-with-attached-artifacts/"
- + "plugin-config.xml" );
+ public void testBasicInstallWithAttachedArtifacts() throws Exception {
+ File testPom = new File(
+ getBasedir(),
+ "target/test-classes/unit/basic-install-test-with-attached-artifacts/" + "plugin-config.xml");
- AbstractMojo mojo = (AbstractMojo) lookupMojo( "install", testPom );
+ AbstractMojo mojo = (AbstractMojo) lookupMojo("install", testPom);
- assertNotNull( mojo );
+ assertNotNull(mojo);
- MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" );
- updateMavenProject( project );
+ MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
+ updateMavenProject(project);
- setVariableValueToObject( mojo, "pluginContext", new ConcurrentHashMap<>() );
- setVariableValueToObject( mojo, "pluginDescriptor", new PluginDescriptor() );
- setVariableValueToObject( mojo, "reactorProjects", Collections.singletonList( project ) );
- setVariableValueToObject( mojo, "session", createMavenSession() );
+ setVariableValueToObject(mojo, "pluginContext", new ConcurrentHashMap<>());
+ setVariableValueToObject(mojo, "pluginDescriptor", new PluginDescriptor());
+ setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project));
+ setVariableValueToObject(mojo, "session", createMavenSession());
List<Artifact> attachedArtifacts = project.getAttachedArtifacts();
@@ -139,241 +133,233 @@ public class InstallMojoTest
String groupId;
- for ( Object attachedArtifact1 : attachedArtifacts )
- {
+ for (Object attachedArtifact1 : attachedArtifacts) {
AttachedArtifactStub0 attachedArtifact = (AttachedArtifactStub0) attachedArtifact1;
- groupId = dotToSlashReplacer( attachedArtifact.getGroupId() );
+ groupId = dotToSlashReplacer(attachedArtifact.getGroupId());
- File installedArtifact = new File( getBasedir(), LOCAL_REPO + groupId + "/" +
- attachedArtifact.getArtifactId() + "/" + attachedArtifact.getVersion() + "/" +
- attachedArtifact.getArtifactId() + "-" + attachedArtifact.getVersion() + "." + packaging );
+ File installedArtifact = new File(
+ getBasedir(),
+ LOCAL_REPO + groupId + "/" + attachedArtifact.getArtifactId()
+ + "/" + attachedArtifact.getVersion() + "/" + attachedArtifact.getArtifactId()
+ + "-" + attachedArtifact.getVersion() + "." + packaging);
- assertTrue( installedArtifact.getPath() + " does not exist", installedArtifact.exists() );
+ assertTrue(installedArtifact.getPath() + " does not exist", installedArtifact.exists());
}
-
- assertEquals( 13, FileUtils.getFiles( new File( LOCAL_REPO ), null, null ).size() );
+
+ assertEquals(13, FileUtils.getFiles(new File(LOCAL_REPO), null, null).size());
}
- public void testUpdateReleaseParamSetToTrue()
- throws Exception
- {
- File testPom = new File( getBasedir(), "target/test-classes/unit/configured-install-test/plugin-config.xml" );
+ public void testUpdateReleaseParamSetToTrue() throws Exception {
+ File testPom = new File(getBasedir(), "target/test-classes/unit/configured-install-test/plugin-config.xml");
- AbstractMojo mojo = (AbstractMojo) lookupMojo( "install", testPom );
+ AbstractMojo mojo = (AbstractMojo) lookupMojo("install", testPom);
- assertNotNull( mojo );
+ assertNotNull(mojo);
- File file = new File( getBasedir(), "target/test-classes/unit/configured-install-test/target/"
- + "maven-install-test-1.0-SNAPSHOT.jar" );
+ File file = new File(
+ getBasedir(),
+ "target/test-classes/unit/configured-install-test/target/" + "maven-install-test-1.0-SNAPSHOT.jar");
- MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" );
- updateMavenProject( project );
+ MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
+ updateMavenProject(project);
- setVariableValueToObject( mojo, "pluginContext", new ConcurrentHashMap<>() );
- setVariableValueToObject( mojo, "pluginDescriptor", new PluginDescriptor() );
- setVariableValueToObject( mojo, "reactorProjects", Collections.singletonList( project ) );
- setVariableValueToObject( mojo, "session", createMavenSession() );
+ setVariableValueToObject(mojo, "pluginContext", new ConcurrentHashMap<>());
+ setVariableValueToObject(mojo, "pluginDescriptor", new PluginDescriptor());
+ setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project));
+ setVariableValueToObject(mojo, "session", createMavenSession());
artifact = (InstallArtifactStub) project.getArtifact();
- artifact.setFile( file );
+ artifact.setFile(file);
mojo.execute();
-// assertTrue( artifact.isRelease() );
-
- assertEquals( 5, FileUtils.getFiles( new File( LOCAL_REPO ), null, null ).size() );
+ // assertTrue( artifact.isRelease() );
+
+ assertEquals(5, FileUtils.getFiles(new File(LOCAL_REPO), null, null).size());
}
- public void testInstallIfArtifactFileIsNull()
- throws Exception
- {
- File testPom = new File( getBasedir(), "target/test-classes/unit/basic-install-test/plugin-config.xml" );
+ public void testInstallIfArtifactFileIsNull() throws Exception {
+ File testPom = new File(getBasedir(), "target/test-classes/unit/basic-install-test/plugin-config.xml");
- AbstractMojo mojo = (AbstractMojo) lookupMojo( "install", testPom );
+ AbstractMojo mojo = (AbstractMojo) lookupMojo("install", testPom);
- assertNotNull( mojo );
+ assertNotNull(mojo);
- MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" );
- updateMavenProject( project );
+ MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
+ updateMavenProject(project);
- setVariableValueToObject( mojo, "pluginContext", new ConcurrentHashMap<>() );
- setVariableValueToObject( mojo, "pluginDescriptor", new PluginDescriptor() );
- setVariableValueToObject( mojo, "reactorProjects", Collections.singletonList( project ) );
- setVariableValueToObject( mojo, "session", createMavenSession() );
+ setVariableValueToObject(mojo, "pluginContext", new ConcurrentHashMap<>());
+ setVariableValueToObject(mojo, "pluginDescriptor", new PluginDescriptor());
+ setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project));
+ setVariableValueToObject(mojo, "session", createMavenSession());
artifact = (InstallArtifactStub) project.getArtifact();
- artifact.setFile( null );
+ artifact.setFile(null);
- assertNull( artifact.getFile() );
+ assertNull(artifact.getFile());
- try
- {
+ try {
mojo.execute();
- fail( "Did not throw mojo execution exception" );
+ fail("Did not throw mojo execution exception");
+ } catch (MojoExecutionException e) {
+ // expected
}
- catch ( MojoExecutionException e )
- {
- //expected
- }
-
- assertFalse( new File( LOCAL_REPO ).exists() );
+
+ assertFalse(new File(LOCAL_REPO).exists());
}
- public void testInstallIfPackagingIsPom()
- throws Exception
- {
- File testPom = new File( getBasedir(),
- "target/test-classes/unit/basic-install-test-packaging-pom/" + "plugin-config.xml" );
+ public void testInstallIfPackagingIsPom() throws Exception {
+ File testPom = new File(
+ getBasedir(), "target/test-classes/unit/basic-install-test-packaging-pom/" + "plugin-config.xml");
- AbstractMojo mojo = (AbstractMojo) lookupMojo( "install", testPom );
+ AbstractMojo mojo = (AbstractMojo) lookupMojo("install", testPom);
- assertNotNull( mojo );
+ assertNotNull(mojo);
- MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" );
- updateMavenProject( project );
+ MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
+ updateMavenProject(project);
- setVariableValueToObject( mojo, "pluginContext", new ConcurrentHashMap<>() );
- setVariableValueToObject( mojo, "pluginDescriptor", new PluginDescriptor() );
- setVariableValueToObject( mojo, "reactorProjects", Collections.singletonList( project ) );
- setVariableValueToObject( mojo, "session", createMavenSession() );
+ setVariableValueToObject(mojo, "pluginContext", new ConcurrentHashMap<>());
+ setVariableValueToObject(mojo, "pluginDescriptor", new PluginDescriptor());
+ setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project));
+ setVariableValueToObject(mojo, "session", createMavenSession());
String packaging = project.getPackaging();
- assertEquals( "pom", packaging );
+ assertEquals("pom", packaging);
artifact = (InstallArtifactStub) project.getArtifact();
mojo.execute();
- String groupId = dotToSlashReplacer( artifact.getGroupId() );
+ String groupId = dotToSlashReplacer(artifact.getGroupId());
- File installedArtifact = new File( getBasedir(), LOCAL_REPO + groupId + "/" + artifact.getArtifactId() + "/" +
- artifact.getVersion() + "/" + artifact.getArtifactId() + "-" + artifact.getVersion() + "." + "pom" );
+ File installedArtifact = new File(
+ getBasedir(),
+ LOCAL_REPO + groupId + "/" + artifact.getArtifactId() + "/" + artifact.getVersion() + "/"
+ + artifact.getArtifactId() + "-" + artifact.getVersion() + "." + "pom");
- assertTrue( installedArtifact.exists() );
-
- assertEquals( 4, FileUtils.getFiles( new File( LOCAL_REPO ), null, null ).size() );
+ assertTrue(installedArtifact.exists());
+
+ assertEquals(4, FileUtils.getFiles(new File(LOCAL_REPO), null, null).size());
}
- public void testBasicInstallAndCreate()
- throws Exception
- {
- File testPom = new File( getBasedir(), "target/test-classes/unit/basic-install-checksum/plugin-config.xml" );
+ public void testBasicInstallAndCreate() throws Exception {
+ File testPom = new File(getBasedir(), "target/test-classes/unit/basic-install-checksum/plugin-config.xml");
- AbstractMojo mojo = (AbstractMojo) lookupMojo( "install", testPom );
+ AbstractMojo mojo = (AbstractMojo) lookupMojo("install", testPom);
- assertNotNull( mojo );
+ assertNotNull(mojo);
- File file = new File( getBasedir(), "target/test-classes/unit/basic-install-checksum/" + "maven-test-jar.jar" );
+ File file = new File(getBasedir(), "target/test-classes/unit/basic-install-checksum/" + "maven-test-jar.jar");
- MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" );
+ MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
MavenSession mavenSession = createMavenSession();
- updateMavenProject( project );
+ updateMavenProject(project);
- setVariableValueToObject( mojo, "pluginContext", new ConcurrentHashMap<>() );
- setVariableValueToObject( mojo, "pluginDescriptor", new PluginDescriptor() );
- setVariableValueToObject( mojo, "reactorProjects", Collections.singletonList( project ) );
- setVariableValueToObject( mojo, "session", mavenSession );
+ setVariableValueToObject(mojo, "pluginContext", new ConcurrentHashMap<>());
+ setVariableValueToObject(mojo, "pluginDescriptor", new PluginDescriptor());
+ setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project));
+ setVariableValueToObject(mojo, "session", mavenSession);
artifact = (InstallArtifactStub) project.getArtifact();
- artifact.setFile( file );
+ artifact.setFile(file);
mojo.execute();
- File pom = new File( new File( LOCAL_REPO ), mavenSession.getRepositorySession().getLocalRepositoryManager().getPathForLocalArtifact( new DefaultArtifact( artifact.getGroupId(), artifact.getArtifactId(), "pom", artifact.getVersion() ) ) );
+ File pom = new File(
+ new File(LOCAL_REPO),
+ mavenSession
+ .getRepositorySession()
+ .getLocalRepositoryManager()
+ .getPathForLocalArtifact(new DefaultArtifact(
+ artifact.getGroupId(), artifact.getArtifactId(), "pom", artifact.getVersion())));
- assertTrue( pom.exists() );
+ assertTrue(pom.exists());
- String groupId = dotToSlashReplacer( artifact.getGroupId() );
+ String groupId = dotToSlashReplacer(artifact.getGroupId());
String packaging = project.getPackaging();
- String localPath = getBasedir() + "/" + LOCAL_REPO + groupId + "/" + artifact.getArtifactId() + "/" +
- artifact.getVersion() + "/" + artifact.getArtifactId() + "-" + artifact.getVersion();
-
+ String localPath = getBasedir() + "/" + LOCAL_REPO + groupId + "/" + artifact.getArtifactId() + "/"
+ + artifact.getVersion() + "/" + artifact.getArtifactId() + "-" + artifact.getVersion();
+
+ File installedArtifact = new File(localPath + "." + packaging);
- File installedArtifact = new File( localPath + "." + packaging );
+ assertTrue(installedArtifact.exists());
- assertTrue( installedArtifact.exists() );
-
- assertEquals( 5, FileUtils.getFiles( new File( LOCAL_REPO ), null, null ).size() );
+ assertEquals(5, FileUtils.getFiles(new File(LOCAL_REPO), null, null).size());
}
- public void testSkip()
- throws Exception
- {
- File testPom = new File( getBasedir(), "target/test-classes/unit/basic-install-test/plugin-config.xml" );
+ public void testSkip() throws Exception {
+ File testPom = new File(getBasedir(), "target/test-classes/unit/basic-install-test/plugin-config.xml");
- InstallMojo mojo = (InstallMojo) lookupMojo( "install", testPom );
+ InstallMojo mojo = (InstallMojo) lookupMojo("install", testPom);
- assertNotNull( mojo );
+ assertNotNull(mojo);
- File file = new File( getBasedir(), "target/test-classes/unit/basic-install-test/target/"
- + "maven-install-test-1.0-SNAPSHOT.jar" );
+ File file = new File(
+ getBasedir(),
+ "target/test-classes/unit/basic-install-test/target/" + "maven-install-test-1.0-SNAPSHOT.jar");
- MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" );
- updateMavenProject( project );
+ MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
+ updateMavenProject(project);
- setVariableValueToObject( mojo, "pluginContext", new ConcurrentHashMap<>() );
- setVariableValueToObject( mojo, "pluginDescriptor", new PluginDescriptor() );
- setVariableValueToObject( mojo, "reactorProjects", Collections.singletonList( project ) );
- setVariableValueToObject( mojo, "session", createMavenSession() );
- setVariableValueToObject( mojo, "skip", Boolean.TRUE );
+ setVariableValueToObject(mojo, "pluginContext", new ConcurrentHashMap<>());
+ setVariableValueToObject(mojo, "pluginDescriptor", new PluginDescriptor());
+ setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project));
+ setVariableValueToObject(mojo, "session", createMavenSession());
+ setVariableValueToObject(mojo, "skip", Boolean.TRUE);
artifact = (InstallArtifactStub) project.getArtifact();
- artifact.setFile( file );
+ artifact.setFile(file);
mojo.execute();
- String groupId = dotToSlashReplacer( artifact.getGroupId() );
+ String groupId = dotToSlashReplacer(artifact.getGroupId());
String packaging = project.getPackaging();
- File installedArtifact = new File( getBasedir(), LOCAL_REPO + groupId + "/" + artifact.getArtifactId() + "/" +
- artifact.getVersion() + "/" + artifact.getArtifactId() + "-" + artifact.getVersion() + "." + packaging );
+ File installedArtifact = new File(
+ getBasedir(),
+ LOCAL_REPO + groupId + "/" + artifact.getArtifactId() + "/" + artifact.getVersion() + "/"
+ + artifact.getArtifactId() + "-" + artifact.getVersion() + "." + packaging);
- assertFalse( installedArtifact.exists() );
-
- assertFalse( new File( LOCAL_REPO ).exists() );
- }
+ assertFalse(installedArtifact.exists());
+ assertFalse(new File(LOCAL_REPO).exists());
+ }
- private String dotToSlashReplacer( String parameter )
- {
- return parameter.replace( '.', '/' );
+ private String dotToSlashReplacer(String parameter) {
+ return parameter.replace('.', '/');
}
-
- private MavenSession createMavenSession() throws NoLocalRepositoryManagerException
- {
- MavenSession session = mock( MavenSession.class );
- DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
- repositorySession.setLocalRepositoryManager(
- new EnhancedLocalRepositoryManagerFactory().newInstance(
- repositorySession, new LocalRepository( LOCAL_REPO )
- )
- );
+
+ private MavenSession createMavenSession() throws NoLocalRepositoryManagerException {
+ MavenSession session = mock(MavenSession.class);
+ DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
+ repositorySession.setLocalRepositoryManager(new EnhancedLocalRepositoryManagerFactory()
+ .newInstance(repositorySession, new LocalRepository(LOCAL_REPO)));
ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest();
- buildingRequest.setRepositorySession( repositorySession );
- when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
- when( session.getRepositorySession() ).thenReturn( repositorySession );
- when( session.getPluginContext(any(PluginDescriptor.class), any(MavenProject.class)))
- .thenReturn( new ConcurrentHashMap<String, Object>() );
+ buildingRequest.setRepositorySession(repositorySession);
+ when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
+ when(session.getRepositorySession()).thenReturn(repositorySession);
+ when(session.getPluginContext(any(PluginDescriptor.class), any(MavenProject.class)))
+ .thenReturn(new ConcurrentHashMap<String, Object>());
return session;
}
-
- private void updateMavenProject( MavenProject project )
- {
- project.setGroupId( project.getArtifact().getGroupId() );
- project.setArtifactId( project.getArtifact().getArtifactId() );
- project.setVersion( project.getArtifact().getVersion() );
-
- Plugin plugin = new Plugin();
- plugin.setArtifactId( "maven-install-plugin" );
- project.setBuild( new Build() );
- project.getBuild().addPlugin( plugin );
+
+ private void updateMavenProject(MavenProject project) {
+ project.setGroupId(project.getArtifact().getGroupId());
+ project.setArtifactId(project.getArtifact().getArtifactId());
+ project.setVersion(project.getArtifact().getVersion());
+
+ Plugin plugin = new Plugin();
+ plugin.setArtifactId("maven-install-plugin");
+ project.setBuild(new Build());
+ project.getBuild().addPlugin(plugin);
}
}
=====================================
src/test/java/org/apache/maven/plugins/install/stubs/AttachedArtifactStub0.java
=====================================
@@ -1,7 +1,3 @@
-package org.apache.maven.plugins.install.stubs;
-
-import java.io.File;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -11,7 +7,7 @@ import java.io.File;
* "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
@@ -20,19 +16,19 @@ import java.io.File;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.install.stubs;
+
+import java.io.File;
-public class AttachedArtifactStub0
- extends InstallArtifactStub
-{
- public String getArtifactId()
- {
+public class AttachedArtifactStub0 extends InstallArtifactStub {
+ public String getArtifactId() {
return "attached-artifact-test-0";
}
- public File getFile()
- {
- return new File( System.getProperty( "basedir" ),
- "target/test-classes/unit/basic-install-test-with-attached-artifacts/"
- + "target/maven-install-test-1.0-SNAPSHOT.jar" );
+ public File getFile() {
+ return new File(
+ System.getProperty("basedir"),
+ "target/test-classes/unit/basic-install-test-with-attached-artifacts/"
+ + "target/maven-install-test-1.0-SNAPSHOT.jar");
}
}
=====================================
src/test/java/org/apache/maven/plugins/install/stubs/AttachedArtifactStub1.java
=====================================
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.install.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.install.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,12 +16,10 @@ package org.apache.maven.plugins.install.stubs;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.install.stubs;
-public class AttachedArtifactStub1
- extends AttachedArtifactStub0
-{
- public String getArtifactId()
- {
+public class AttachedArtifactStub1 extends AttachedArtifactStub0 {
+ public String getArtifactId() {
return "attached-artifact-test-1";
}
}
=====================================
src/test/java/org/apache/maven/plugins/install/stubs/InstallArtifactStub.java
=====================================
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.install.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.install.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,11 +16,7 @@ package org.apache.maven.plugins.install.stubs;
* specific language governing permissions and limitations
* under the License.
*/
-
-import org.apache.maven.artifact.handler.ArtifactHandler;
-import org.apache.maven.artifact.handler.DefaultArtifactHandler;
-import org.apache.maven.artifact.metadata.ArtifactMetadata;
-import org.apache.maven.plugin.testing.stubs.ArtifactStub;
+package org.apache.maven.plugins.install.stubs;
import java.io.File;
import java.util.Collection;
@@ -30,92 +24,76 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+import org.apache.maven.artifact.handler.ArtifactHandler;
+import org.apache.maven.artifact.handler.DefaultArtifactHandler;
+import org.apache.maven.artifact.metadata.ArtifactMetadata;
+import org.apache.maven.plugin.testing.stubs.ArtifactStub;
-public class InstallArtifactStub
- extends ArtifactStub
-{
+public class InstallArtifactStub extends ArtifactStub {
private Map<Object, ArtifactMetadata> metadataMap;
private File file;
private boolean release;
- public String getArtifactId()
- {
+ public String getArtifactId() {
return "maven-install-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();
}
- public void setFile( File file )
- {
+ public void setFile(File file) {
this.file = file;
}
- public File getFile()
- {
+ public File getFile() {
return file;
}
- public String getType()
- {
+ public String getType() {
return "jar";
}
-
- public ArtifactHandler getArtifactHandler()
- {
- return new DefaultArtifactHandler()
- {
- public String getExtension()
- {
+
+ public ArtifactHandler getArtifactHandler() {
+ return new DefaultArtifactHandler() {
+ public String getExtension() {
return "jar";
}
};
}
- public void addMetadata( ArtifactMetadata metadata )
- {
- if ( metadataMap == null )
- {
+ public void addMetadata(ArtifactMetadata metadata) {
+ if (metadataMap == null) {
metadataMap = new HashMap<Object, ArtifactMetadata>();
}
- 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 getMetadataList()
- {
+ public Collection getMetadataList() {
return metadataMap == null ? Collections.EMPTY_LIST : metadataMap.values();
}
- public boolean isRelease()
- {
+ public boolean isRelease() {
return release;
}
- public void setRelease( boolean release )
- {
+ public void setRelease(boolean release) {
this.release = release;
}
}
=====================================
src/test/resources/unit/install-file-from-local-repository-test/plugin-config.xml
=====================================
@@ -0,0 +1,35 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<project>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-install-plugin</artifactId>
+ <configuration>
+ <groupId>org.apache.maven.test</groupId>
+ <artifactId>maven-install-test</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+ <file>${basedir}/target/test-classes/unit/install-file-from-local-repository-test/target/org/apache/maven/test/maven-install-test/1.0-SNAPSHOT/maven-install-test-1.0-SNAPSHOT.jar
+ </file>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
=====================================
src/test/resources/unit/install-file-from-local-repository-test/target/org/apache/maven/test/maven-install-test/1.0-SNAPSHOT/maven-install-test-1.0-SNAPSHOT.jar
=====================================
Binary files /dev/null and b/src/test/resources/unit/install-file-from-local-repository-test/target/org/apache/maven/test/maven-install-test/1.0-SNAPSHOT/maven-install-test-1.0-SNAPSHOT.jar differ
View it on GitLab: https://salsa.debian.org/java-team/maven-install-plugin/-/compare/6373bfbf336d7278642d1a40f203784bf2940493...51704d7ddbe0b2bcc09e817f8e3366f81c27ec27
--
View it on GitLab: https://salsa.debian.org/java-team/maven-install-plugin/-/compare/6373bfbf336d7278642d1a40f203784bf2940493...51704d7ddbe0b2bcc09e817f8e3366f81c27ec27
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-java-commits/attachments/20230617/7d8dbd20/attachment.htm>
More information about the pkg-java-commits
mailing list