Skip to content

Commit

Permalink
Merge pull request #21 from TomasHofman/fixes
Browse files Browse the repository at this point in the history
Fixes related to ignoring project modules
  • Loading branch information
TomasHofman authored Nov 26, 2024
2 parents f43e97f + ddba48f commit 42355d4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -69,8 +70,11 @@ public class CreateManifestMojo extends AbstractMojo {
@Parameter(name="manifestLogicalVersion", property = "manifestLogicalVersion")
private String manifestLogicalVersion;

@Inject
private MavenProject project;
/**
* Comma separated list of module G:As that should not be processed.
*/
@Parameter(property = "ignoreModules")
List<String> ignoreModules;

@Inject
private MavenProjectHelper projectHelper;
Expand All @@ -79,11 +83,17 @@ public class CreateManifestMojo extends AbstractMojo {
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
final Set<Artifact> artifacts = new HashSet<>();
artifacts.addAll(mavenProject.getArtifacts());
artifacts.add(mavenProject.getArtifact());
if (!isIgnoredModule(mavenProject.getGroupId(), mavenProject.getArtifactId())) {
artifacts.addAll(mavenProject.getArtifacts());
artifacts.add(mavenProject.getArtifact());
}

// include children modules
for (MavenProject project : mavenProject.getCollectedProjects()) {
if (isIgnoredModule(project.getGroupId(), project.getArtifactId())) {
getLog().info(String.format("Skipping module %s:%s", project.getGroupId(), project.getArtifact()));
continue;
}
if (getLog().isDebugEnabled()) {
getLog().debug("Including child module: " + project.getId());
}
Expand Down Expand Up @@ -137,17 +147,23 @@ public void execute() throws MojoExecutionException, MojoFailureException {
try {
final String yaml = ChannelManifestMapper.toYaml(channelManifest);
final String manifestFileName = String.format("%s-%s-%s.%s",
project.getArtifactId(), project.getVersion(),
mavenProject.getArtifactId(), mavenProject.getVersion(),
ChannelManifest.CLASSIFIER, ChannelManifest.EXTENSION);
final Path outputDirectory = Path.of(project.getBuild().getDirectory());
final Path outputDirectory = Path.of(mavenProject.getBuild().getDirectory());
if (!Files.exists(outputDirectory)) {
Files.createDirectory(outputDirectory);
}
final Path outputPath = Path.of(project.getBuild().getDirectory(), manifestFileName);
final Path outputPath = Path.of(mavenProject.getBuild().getDirectory(), manifestFileName);
Files.writeString(outputPath, yaml, StandardCharsets.UTF_8);
projectHelper.attachArtifact(project, ChannelManifest.EXTENSION, ChannelManifest.CLASSIFIER, outputPath.toFile());
projectHelper.attachArtifact(mavenProject, ChannelManifest.EXTENSION, ChannelManifest.CLASSIFIER, outputPath.toFile());
} catch (IOException e) {
throw new MojoExecutionException("Unable to serialize manifest", e);
}
}

private boolean isIgnoredModule(String groupId, String artifactId) {
return ignoreModules.contains(groupId + ":" + artifactId)
|| (groupId.equals(mavenProject.getGroupId()) && ignoreModules.contains(":" + artifactId));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ public class UpgradeComponentsMojo extends AbstractChannelMojo {

private final List<ProjectRef> ignoredStreams = new ArrayList<>();
private final List<ProjectRef> unignoredStreams = new ArrayList<>();
private final List<ProjectRef> ignoredModules = new ArrayList<>();
private Set<ProjectVersionRef> projectGavs;
private final HashMap<Pair<String, String>, PomManipulator> manipulators = new HashMap<>();
private PomManipulator rootManipulator;
Expand All @@ -178,7 +177,6 @@ private void init() throws MojoExecutionException {

ignoreStreams.forEach(ga -> ignoredStreams.add(SimpleProjectRef.parse(ga)));
dontIgnoreStreams.forEach(ga -> unignoredStreams.add(SimpleProjectRef.parse(ga)));
ignoreModules.forEach(ga -> ignoredModules.add(SimpleProjectRef.parse(ga)));
}

/**
Expand Down Expand Up @@ -215,8 +213,7 @@ public void execute() throws MojoExecutionException {

// process project modules
for (Project project: pmeProjects) {
ProjectRef moduleGA = project.getKey().asProjectRef();
if (ignoredModules.contains(moduleGA)) {
if (isIgnoredModule(project.getGroupId(), project.getArtifactId())) {
getLog().info(String.format("Skipping module %s:%s", project.getGroupId(), project.getArtifactId()));
continue;
}
Expand Down Expand Up @@ -536,7 +533,10 @@ private void injectTransitiveDependencies() throws DependencyGraphBuilderExcepti
Map<ArtifactRef, Collection<ProjectRef>> dependenciesToInject = new HashMap<>();
ArrayList<MavenProject> projects = new ArrayList<>();
projects.add(mavenProject);
projects.addAll(mavenProject.getCollectedProjects());
List<MavenProject> collectedProjects = mavenProject.getCollectedProjects().stream()
.filter(p -> !isIgnoredModule(p.getGroupId(), p.getArtifactId()))
.collect(Collectors.toList());
projects.addAll(collectedProjects);
for (MavenProject module: projects) {

// Collect exclusions from the effective POM
Expand Down Expand Up @@ -616,6 +616,11 @@ private void injectTransitiveDependencies() throws DependencyGraphBuilderExcepti

}

private boolean isIgnoredModule(String groupId, String artifactId) {
return ignoreModules.contains(groupId + ":" + artifactId)
|| (groupId.equals(mavenProject.getGroupId()) && ignoreModules.contains(":" + artifactId));
}

/**
* If a property references another property (possibly recursively), this method returns the final referenced
* property name and the module where the property is defined.
Expand Down

0 comments on commit 42355d4

Please sign in to comment.