-
Notifications
You must be signed in to change notification settings - Fork 65
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
[MDEPLOY-295] Drop MAT #25
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,16 +19,28 @@ | |
* under the License. | ||
*/ | ||
|
||
import java.util.List; | ||
|
||
import org.apache.maven.RepositoryUtils; | ||
import org.apache.maven.artifact.Artifact; | ||
import org.apache.maven.artifact.metadata.ArtifactMetadata; | ||
import org.apache.maven.artifact.repository.ArtifactRepository; | ||
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; | ||
import org.apache.maven.artifact.repository.MavenArtifactRepository; | ||
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; | ||
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.artifact.ProjectArtifactMetadata; | ||
import org.apache.maven.rtinfo.RuntimeInformation; | ||
import org.eclipse.aether.RepositorySystem; | ||
import org.eclipse.aether.deployment.DeployRequest; | ||
import org.eclipse.aether.deployment.DeploymentException; | ||
import org.eclipse.aether.repository.RemoteRepository; | ||
import org.eclipse.aether.util.artifact.SubArtifact; | ||
import org.eclipse.aether.util.version.GenericVersionScheme; | ||
import org.eclipse.aether.version.InvalidVersionSpecificationException; | ||
import org.eclipse.aether.version.Version; | ||
|
@@ -37,9 +49,8 @@ | |
* Abstract class for Deploy mojo's. | ||
*/ | ||
public abstract class AbstractDeployMojo | ||
extends AbstractMojo | ||
extends AbstractMojo | ||
{ | ||
|
||
/** | ||
* Flag whether Maven is currently in online/offline mode. | ||
*/ | ||
|
@@ -49,17 +60,20 @@ public abstract class AbstractDeployMojo | |
/** | ||
* Parameter used to control how many times a failed deployment will be retried before giving up and failing. If a | ||
* value outside the range 1-10 is specified it will be pulled to the nearest value within the range 1-10. | ||
* | ||
* | ||
* @since 2.7 | ||
*/ | ||
@Parameter( property = "retryFailedDeploymentCount", defaultValue = "1" ) | ||
private int retryFailedDeploymentCount; | ||
|
||
@Component | ||
private RuntimeInformation runtimeInformation; | ||
|
||
@Parameter( defaultValue = "${session}", readonly = true, required = true ) | ||
private MavenSession session; | ||
protected MavenSession session; | ||
|
||
@Component | ||
private RuntimeInformation runtimeInformation; | ||
protected RepositorySystem repositorySystem; | ||
|
||
private static final String AFFECTED_MAVEN_PACKAGING = "maven-plugin"; | ||
|
||
|
@@ -68,28 +82,18 @@ public abstract class AbstractDeployMojo | |
/* Setters and Getters */ | ||
|
||
void failIfOffline() | ||
throws MojoFailureException | ||
throws MojoFailureException | ||
{ | ||
if ( offline ) | ||
{ | ||
throw new MojoFailureException( "Cannot deploy artifacts when Maven is in offline mode" ); | ||
} | ||
} | ||
|
||
int getRetryFailedDeploymentCount() | ||
{ | ||
return retryFailedDeploymentCount; | ||
} | ||
|
||
protected ArtifactRepository createDeploymentArtifactRepository( String id, String url ) | ||
{ | ||
return new MavenArtifactRepository( id, url, new DefaultRepositoryLayout(), new ArtifactRepositoryPolicy(), | ||
new ArtifactRepositoryPolicy() ); | ||
} | ||
|
||
protected final MavenSession getSession() | ||
{ | ||
return session; | ||
new ArtifactRepositoryPolicy() ); | ||
} | ||
|
||
protected void warnIfAffectedPackagingAndMaven( final String packaging ) | ||
|
@@ -116,4 +120,88 @@ protected void warnIfAffectedPackagingAndMaven( final String packaging ) | |
} | ||
} | ||
} | ||
|
||
private RemoteRepository getRemoteRepository( ArtifactRepository remoteRepository ) | ||
{ | ||
RemoteRepository aetherRepo = RepositoryUtils.toRepo( remoteRepository ); | ||
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. Should we still use the old term |
||
|
||
if ( aetherRepo.getAuthentication() == null || aetherRepo.getProxy() == null ) | ||
{ | ||
RemoteRepository.Builder builder = new RemoteRepository.Builder( aetherRepo ); | ||
|
||
if ( aetherRepo.getAuthentication() == null ) | ||
{ | ||
builder.setAuthentication( session.getRepositorySession().getAuthenticationSelector() | ||
.getAuthentication( aetherRepo ) ); | ||
} | ||
|
||
if ( aetherRepo.getProxy() == null ) | ||
{ | ||
builder.setProxy( session.getRepositorySession().getProxySelector().getProxy( aetherRepo ) ); | ||
} | ||
|
||
aetherRepo = builder.build(); | ||
} | ||
|
||
return aetherRepo; | ||
} | ||
|
||
protected DeployRequest deployRequest( ArtifactRepository repository, List<Artifact> artifacts ) | ||
{ | ||
DeployRequest deployRequest = new DeployRequest(); | ||
deployRequest.setRepository( getRemoteRepository( repository ) ); | ||
for ( Artifact artifact : artifacts ) | ||
{ | ||
org.eclipse.aether.artifact.Artifact aetherArtifact = RepositoryUtils.toArtifact( artifact ); | ||
deployRequest.addArtifact( aetherArtifact ); | ||
|
||
for ( ArtifactMetadata metadata : artifact.getMetadataList() ) | ||
{ | ||
if ( metadata instanceof ProjectArtifactMetadata ) | ||
{ | ||
org.eclipse.aether.artifact.Artifact pomArtifact = new SubArtifact( aetherArtifact, "", "pom" ); | ||
pomArtifact = pomArtifact.setFile( ( (ProjectArtifactMetadata) metadata ).getFile() ); | ||
deployRequest.addArtifact( pomArtifact ); | ||
} | ||
} | ||
} | ||
return deployRequest; | ||
} | ||
|
||
protected void deploy( DeployRequest deployRequest ) throws MojoExecutionException | ||
{ | ||
int retryFailedDeploymentCounter = Math.max( 1, Math.min( 10, retryFailedDeploymentCount ) ); | ||
DeploymentException exception = null; | ||
for ( int count = 0; count < retryFailedDeploymentCounter; count++ ) | ||
{ | ||
try | ||
{ | ||
if ( count > 0 ) | ||
{ | ||
getLog().info( "Retrying deployment attempt " + ( count + 1 ) + " of " | ||
+ retryFailedDeploymentCounter ); | ||
} | ||
|
||
repositorySystem.deploy( session.getRepositorySession(), deployRequest ); | ||
exception = null; | ||
break; | ||
} | ||
catch ( DeploymentException e ) | ||
{ | ||
if ( count + 1 < retryFailedDeploymentCounter ) | ||
{ | ||
getLog().warn( "Encountered issue during deployment: " + e.getLocalizedMessage() ); | ||
getLog().debug( e.getMessage() ); | ||
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. Honestly, just use warn with |
||
} | ||
if ( exception == null ) | ||
{ | ||
exception = e; | ||
} | ||
} | ||
} | ||
if ( exception != null ) | ||
{ | ||
throw new MojoExecutionException( exception.getMessage(), exception ); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
and soon we will change to org.apache.maven package... ?
maybe think in the other way… why we have not yet change package from maven-resolver?
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.
Unsure what you talk about: