1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugins.assembly.functions;
20
21 import java.util.List;
22 import java.util.Set;
23
24 import org.apache.maven.artifact.Artifact;
25 import org.apache.maven.artifact.ArtifactUtils;
26 import org.apache.maven.project.MavenProject;
27 import org.slf4j.Logger;
28
29
30
31
32 public class MavenProjects {
33 public static void without(Iterable<MavenProject> source, String packagingType, MavenProjectConsumer consumer) {
34 for (MavenProject project : source) {
35 if (!packagingType.equals(project.getPackaging())) {
36 consumer.accept(project);
37 }
38 }
39 }
40
41 public static void select(Iterable<MavenProject> source, String packagingType, MavenProjectConsumer consumer) {
42 for (MavenProject project : source) {
43 if (packagingType.equals(project.getPackaging())) {
44 consumer.accept(project);
45 }
46 }
47 }
48
49 public static void select(
50 Iterable<MavenProject> source,
51 String packagingType,
52 MavenProjectConsumer include,
53 MavenProjectConsumer excluded) {
54 for (MavenProject project : source) {
55 if (packagingType.equals(project.getPackaging())) {
56 include.accept(project);
57 } else {
58 excluded.accept(project);
59 }
60 }
61 }
62
63 public static Artifact findArtifactByClassifier(MavenProject mavenProject, String classifier) {
64 final List<Artifact> attachments = mavenProject.getAttachedArtifacts();
65 if ((attachments != null) && !attachments.isEmpty()) {
66 for (final Artifact attachment : attachments) {
67 if (classifier.equals(attachment.getClassifier())) {
68 return attachment;
69 }
70 }
71 }
72 return null;
73 }
74
75 public static MavenProjectConsumer log(final Logger logger) {
76 return new MavenProjectConsumer() {
77 @Override
78 public void accept(MavenProject project) {
79 final String projectId = ArtifactUtils.versionlessKey(project.getGroupId(), project.getArtifactId());
80
81 logger.debug("Excluding POM-packaging module: " + projectId);
82 }
83 };
84 }
85
86 public static MavenProjectConsumer addTo(final Set<MavenProject> set) {
87 return new MavenProjectConsumer() {
88 @Override
89 public void accept(MavenProject project) {
90 set.add(project);
91 }
92 };
93 }
94 }