Skip to content

Commit c6f7b45

Browse files
authored
Never treat attached artifacts as content packages which don't have extension "zip" (#343)
This closes #342
1 parent 4ed92a4 commit c6f7b45

File tree

3 files changed

+42
-6
lines changed

3 files changed

+42
-6
lines changed

aemanalyser-maven-plugin/src/main/java/com/adobe/aem/analyser/mojos/AemAnalyseMojo.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public class AemAnalyseMojo extends AbstractAnalyseMojo {
8989
* Only analyze the package attached to the project with the given classifier.
9090
*/
9191
@Parameter(property = "aem.analyser.classifier")
92-
private String classifier;
92+
String classifier;
9393

9494
/**
9595
* Analyzes the given list of content package files.
@@ -98,7 +98,7 @@ public class AemAnalyseMojo extends AbstractAnalyseMojo {
9898
* The files must be located inside the Maven project directory (e.g. src or target folder).
9999
*/
100100
@Parameter
101-
private List<File> contentPackageFiles;
101+
List<File> contentPackageFiles;
102102

103103
/**
104104
* Additional content package artifacts to be considered in the analysis given as list of Maven coordinates/ids in format
@@ -185,7 +185,7 @@ void convertContentPackages(final List<String> additionalWarnings, final List<St
185185
* @return The list of artifacts (non empty)
186186
* @throws MojoExecutionException If anything goes wrong, for example no content packages are found
187187
*/
188-
private List<Artifact> getContentPackages() throws MojoExecutionException {
188+
List<Artifact> getContentPackages() throws MojoExecutionException {
189189
final List<Artifact> result = new ArrayList<>();
190190
if (!Constants.PACKAGING_AEM_ANALYSE.equals(project.getPackaging())) {
191191
if (contentPackageFiles != null && !contentPackageFiles.isEmpty()) {
@@ -197,20 +197,21 @@ private List<Artifact> getContentPackages() throws MojoExecutionException {
197197
} else if (classifier != null) {
198198
// look for attached artifact with given classifier
199199
for (Artifact artifact : project.getAttachedArtifacts()) {
200-
if (classifier.equals(artifact.getClassifier())) {
200+
if (classifier.equals(artifact.getClassifier()) && Constants.EXTENSION_CONTENT_PACKAGE.equalsIgnoreCase(artifact.getArtifactHandler().getExtension())) {
201201
getLog().info("Using attached artifact with classifier '" + classifier + "' as content package: " + project.getArtifact());
202202
result.add(artifact);
203+
break; // only one attached artifact with matching classifier and extension is expected
203204
}
204205
}
205206
if (result.isEmpty()) {
206-
throw new MojoExecutionException("No attached artifact with classifier " + classifier + " found for project.");
207+
throw new MojoExecutionException("No attached artifact with classifier \"" + classifier + "\" and extension \"" + Constants.EXTENSION_CONTENT_PACKAGE + "\" found for project.");
207208
}
208209
} else {
209210
// Use the current project artifact as the content package
210211
getLog().info("Using current project as content package: " + project.getArtifact());
211212
if (project.getArtifact().getFile() == null) {
212213
// in case of a standalone usage of the plugin, the project artifact file might not be set
213-
final File target = new File(project.getBuild().getDirectory(), project.getBuild().getFinalName() + "." + project.getArtifact().getArtifactHandler().getExtension());
214+
final File target = new File(project.getBuild().getDirectory(), project.getBuild().getFinalName() + "." + Constants.EXTENSION_CONTENT_PACKAGE);
214215
if ( !target.exists() ) {
215216
throw new MojoExecutionException("Project artifact file not found. Build the project first. Looking for: " + target.getName());
216217
}

aemanalyser-maven-plugin/src/main/java/com/adobe/aem/analyser/mojos/Constants.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ public abstract class Constants extends com.adobe.aem.analyser.Constants {
2525
/** Packaging for content packages */
2626
public static final String PACKAGING_CONTENT_PACKAGE = "content-package";
2727

28+
/** The extension for the content packages without the leading dot */
29+
public static final String EXTENSION_CONTENT_PACKAGE = "zip";
30+
2831
/** The directory for the content package converter */
2932
public static final String CONVERTER_DIRECTORY = "cp-conversion";
3033

aemanalyser-maven-plugin/src/test/java/com/adobe/aem/analyser/mojos/AemAnalyseMojoTest.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@
2424
import java.util.List;
2525

2626
import org.apache.maven.artifact.Artifact;
27+
import org.apache.maven.artifact.DefaultArtifact;
28+
import org.apache.maven.artifact.handler.ArtifactHandler;
29+
import org.apache.maven.artifact.handler.DefaultArtifactHandler;
2730
import org.apache.maven.model.Build;
31+
import org.apache.maven.plugin.MojoExecutionException;
2832
import org.apache.maven.project.MavenProject;
2933
import org.apache.sling.feature.ArtifactId;
3034
import org.apache.sling.feature.builder.ArtifactProvider;
@@ -131,6 +135,34 @@ public void testGetAnalyserTasksWithSkip() {
131135
assertEquals(ImmutableSet.of("utask2","utask3"), mojo.getAnalyserUserTasks());
132136
}
133137

138+
@Test
139+
public void testGetContentPackagesWithClassifier() throws MojoExecutionException {
140+
MavenProject prj = Mockito.mock(MavenProject.class);
141+
Artifact packageArtifact = new DefaultArtifact("group", "artifact", "1.0", null, Constants.PACKAGING_CONTENT_PACKAGE, "myclassifier", new ContentPackageArtifactHandler());
142+
Artifact signatureForPackageArtifact = new DefaultArtifact("group", "artifact", "1.0", null, Constants.PACKAGING_ZIP, "myclassifier", new DefaultArtifactHandler("zip.asc"));
143+
Mockito.when(prj.getAttachedArtifacts()).thenReturn(
144+
List.of(
145+
packageArtifact,
146+
signatureForPackageArtifact
147+
)
148+
);
149+
AemAnalyseMojo mojo = new TestAnalyseMojo(prj);
150+
mojo.classifier = "myclassifier";
151+
152+
assertEquals(List.of(packageArtifact), mojo.getContentPackages());
153+
}
154+
155+
// copied from https://github.com/apache/jackrabbit-filevault-package-maven-plugin/blob/filevault-package-maven-plugin-1.4.0/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/impl/extensions/ContentPackageArtifactHandler.java
156+
private static final class ContentPackageArtifactHandler extends DefaultArtifactHandler {
157+
public ContentPackageArtifactHandler() {
158+
super(Constants.PACKAGING_CONTENT_PACKAGE);
159+
setIncludesDependencies(true);
160+
setExtension("zip");
161+
setLanguage("java");
162+
setAddedToClasspath(true);
163+
}
164+
}
165+
134166
private static class TestAnalyseMojo extends AemAnalyseMojo {
135167
private TestAnalyseMojo(final MavenProject prj) {
136168
this.project = prj;

0 commit comments

Comments
 (0)