Skip to content

Commit

Permalink
Remove baked in packaging from plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
cstamas committed Jan 12, 2024
1 parent 6d136a7 commit 5353d54
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.artifact.ProjectArtifact;
import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.deployment.DeployRequest;
import org.eclipse.aether.repository.RemoteRepository;
import org.eclipse.aether.util.artifact.ArtifactIdUtils;

/**
* Deploys an artifact to remote repository.
Expand Down Expand Up @@ -285,17 +287,32 @@ private boolean hasExecution(Plugin plugin) {
}

private void processProject(final MavenProject project, DeployRequest request) throws MojoExecutionException {
// always exists, as project exists
Artifact pomArtifact = RepositoryUtils.toArtifact(new ProjectArtifact(project));
// always exists, but at "init" is w/o file (packaging plugin assigns file to this when packaged)
Artifact projectArtifact = RepositoryUtils.toArtifact(project.getArtifact());

// pom project: pomArtifact and projectArtifact are SAME
// jar project: pomArtifact and projectArtifact are DIFFERENT
// incomplete project: is not pom project and projectArtifact has no file

// we must compare coordinates ONLY (as projectArtifact may not have file, and Artifact.equals factors it in)
boolean pomArtifactIsMainArtifact = ArtifactIdUtils.equalsId(pomArtifact, projectArtifact);
if (pomArtifactIsMainArtifact) {
projectArtifact = null;
}
// is not packaged, is "incomplete"
boolean isIncomplete = projectArtifact != null && !isFile(projectArtifact.getFile());

if (isFile(project.getFile())) {
request.addArtifact(RepositoryUtils.toArtifact(new ProjectArtifact(project)));
if (isFile(pomArtifact.getFile())) {
request.addArtifact(pomArtifact);
} else {
throw new MojoExecutionException("The project POM could not be attached");
}

if (!"pom".equals(project.getPackaging())) {
org.apache.maven.artifact.Artifact mavenMainArtifact = project.getArtifact();
if (isFile(mavenMainArtifact.getFile())) {
request.addArtifact(RepositoryUtils.toArtifact(mavenMainArtifact));
if (projectArtifact != null) {
if (!isIncomplete) {
request.addArtifact(projectArtifact);
} else if (!project.getAttachedArtifacts().isEmpty()) {
if (allowIncompleteProjects) {
getLog().warn("");
Expand Down

0 comments on commit 5353d54

Please sign in to comment.