-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MINSTALL-175] Drop MAT #31
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,14 +21,22 @@ | |
|
||
import java.io.File; | ||
|
||
import org.apache.maven.RepositoryUtils; | ||
import org.apache.maven.artifact.Artifact; | ||
import org.apache.maven.execution.MavenSession; | ||
import org.apache.maven.plugin.AbstractMojo; | ||
import org.apache.maven.plugin.MojoExecutionException; | ||
import org.apache.maven.plugin.MojoFailureException; | ||
import org.apache.maven.plugins.annotations.Component; | ||
import org.apache.maven.plugins.annotations.Parameter; | ||
import org.apache.maven.project.ProjectBuildingRequest; | ||
import org.apache.maven.project.MavenProject; | ||
import org.apache.maven.project.artifact.ProjectArtifact; | ||
import org.apache.maven.project.artifact.ProjectArtifactMetadata; | ||
import org.apache.maven.shared.transfer.repository.RepositoryManager; | ||
import org.eclipse.aether.RepositorySystem; | ||
import org.eclipse.aether.artifact.DefaultArtifact; | ||
import org.eclipse.aether.installation.InstallRequest; | ||
import org.eclipse.aether.installation.InstallationException; | ||
import org.eclipse.aether.util.artifact.SubArtifact; | ||
|
||
/** | ||
* Common fields for installation mojos. | ||
|
@@ -38,9 +46,8 @@ | |
public abstract class AbstractInstallMojo | ||
extends AbstractMojo | ||
{ | ||
|
||
@Component | ||
protected RepositoryManager repositoryManager; | ||
protected RepositorySystem repositorySystem; | ||
|
||
@Parameter( defaultValue = "${session}", required = true, readonly = true ) | ||
protected MavenSession session; | ||
|
@@ -49,28 +56,98 @@ public abstract class AbstractInstallMojo | |
* Gets the path of the specified artifact within the local repository. Note that the returned path need not exist | ||
* (yet). | ||
* | ||
* @param buildingRequest {@link ProjectBuildingRequest}. | ||
* @param artifact The artifact whose local repo path should be determined, must not be <code>null</code>. | ||
* @return The absolute path to the artifact when installed, never <code>null</code>. | ||
*/ | ||
protected File getLocalRepoFile( ProjectBuildingRequest buildingRequest, Artifact artifact ) | ||
protected File getLocalRepoFile( Artifact artifact ) | ||
{ | ||
String path = repositoryManager.getPathForLocalArtifact( buildingRequest, artifact ); | ||
return new File( repositoryManager.getLocalRepositoryBasedir( buildingRequest ), path ); | ||
String path = session.getRepositorySession().getLocalRepositoryManager() | ||
.getPathForLocalArtifact( RepositoryUtils.toArtifact( artifact ) ); | ||
return new File( session.getRepositorySession().getLocalRepository().getBasedir(), path ); | ||
} | ||
|
||
/** | ||
* Gets the path of the specified artifact metadata within the local repository. Note that the returned path need | ||
* not exist (yet). | ||
* | ||
* @param buildingRequest {@link ProjectBuildingRequest}. | ||
* @param metadata The artifact metadata whose local repo path should be determined, must not be <code>null</code>. | ||
* @return The absolute path to the artifact metadata when installed, never <code>null</code>. | ||
*/ | ||
protected File getLocalRepoFile( ProjectBuildingRequest buildingRequest, ProjectArtifactMetadata metadata ) | ||
protected File getLocalRepoFile( ProjectArtifactMetadata metadata ) | ||
{ | ||
String path = repositoryManager.getPathForLocalMetadata( buildingRequest, metadata ); | ||
return new File( repositoryManager.getLocalRepositoryBasedir( buildingRequest ), path ); | ||
DefaultArtifact pomArtifact = new DefaultArtifact( | ||
metadata.getGroupId(), | ||
metadata.getArtifactId(), | ||
"", | ||
"pom", | ||
metadata.getBaseVersion() ); | ||
|
||
String path = session.getRepositorySession().getLocalRepositoryManager().getPathForLocalArtifact( | ||
pomArtifact ); | ||
return new File( session.getRepositorySession().getLocalRepository().getBasedir(), path ); | ||
} | ||
|
||
protected void installProject( MavenProject project ) | ||
throws MojoFailureException, MojoExecutionException | ||
{ | ||
try | ||
{ | ||
InstallRequest request = new InstallRequest(); | ||
Artifact artifact = project.getArtifact(); | ||
String packaging = project.getPackaging(); | ||
File pomFile = project.getFile(); | ||
boolean isPomArtifact = "pom".equals( packaging ); | ||
|
||
if ( pomFile != null ) | ||
{ | ||
request.addArtifact( RepositoryUtils.toArtifact( new ProjectArtifact( project ) ) ); | ||
} | ||
|
||
if ( !isPomArtifact ) | ||
{ | ||
File file = artifact.getFile(); | ||
|
||
// Here, we have a temporary solution to MINSTALL-3 (isDirectory() is true if it went through compile | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks odd. We build against Maven 3.2.5 (see pom.xml) but this comment suggests a "proper solution" will be in place with Maven 2.1? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I lifted the relevant MAT code here, so this PR does not change "logic", it merely moves it into this plugin (that was before in MAT). So, just like in #15 "minimal change" is in place, that will subsequent PRs refine. |
||
// but not package). We are designing in a proper solution for Maven 2.1 | ||
if ( file != null && file.isFile() ) | ||
{ | ||
org.eclipse.aether.artifact.Artifact mainArtifact = RepositoryUtils.toArtifact( artifact ); | ||
request.addArtifact( mainArtifact ); | ||
|
||
for ( Object metadata : artifact.getMetadataList() ) | ||
{ | ||
if ( metadata instanceof ProjectArtifactMetadata ) | ||
{ | ||
org.eclipse.aether.artifact.Artifact pomArtifact = | ||
new SubArtifact( mainArtifact, "", "pom" ); | ||
pomArtifact = pomArtifact.setFile( ( (ProjectArtifactMetadata) metadata ).getFile() ); | ||
request.addArtifact( pomArtifact ); | ||
} | ||
} | ||
} | ||
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" ); | ||
} | ||
} | ||
|
||
for ( Artifact attached : project.getAttachedArtifacts() ) | ||
{ | ||
getLog().debug( "Attaching for install: " + attached.getId() ); | ||
request.addArtifact( RepositoryUtils.toArtifact( attached ) ); | ||
} | ||
|
||
repositorySystem.install( session.getRepositorySession(), request ); | ||
} | ||
catch ( InstallationException e ) | ||
{ | ||
throw new MojoExecutionException( e.getMessage(), e ); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is effectively a downgrade? From 1.1.0 to 1.0.0.v20140518?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, because it aligns with the Aether version from Maven 3.2.5.