diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractMapVersionsPhase.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractMapVersionsPhase.java index 57605bfd..dae2b705 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractMapVersionsPhase.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractMapVersionsPhase.java @@ -18,8 +18,12 @@ */ package org.apache.maven.shared.release.phase; +import java.nio.file.FileSystems; +import java.nio.file.Paths; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import org.apache.maven.artifact.ArtifactUtils; import org.apache.maven.project.MavenProject; @@ -97,6 +101,8 @@ public abstract class AbstractMapVersionsPhase extends AbstractReleasePhase { */ private final boolean convertToBranch; + private final Set exclusionPatterns = new HashSet<>(); + public AbstractMapVersionsPhase( ScmRepositoryConfigurator scmRepositoryConfigurator, Prompter prompter, @@ -118,6 +124,12 @@ public ReleaseResult execute( throws ReleaseExecutionException { ReleaseResult result = new ReleaseResult(); + List additionalExcludes = releaseDescriptor.getCheckModificationExcludes(); + + if (additionalExcludes != null) { + exclusionPatterns.addAll(additionalExcludes); + } + MavenProject rootProject = ReleaseUtil.getRootProject(reactorProjects); if (releaseDescriptor.isAutoVersionSubmodules() && ArtifactUtils.isSnapshot(rootProject.getVersion())) { @@ -165,17 +177,31 @@ public ReleaseResult execute( } } } else { + for (MavenProject project : reactorProjects) { String projectId = ArtifactUtils.versionlessKey(project.getGroupId(), project.getArtifactId()); String nextVersion = resolveNextVersion(project, projectId, releaseDescriptor, releaseEnvironment); - if (!convertToSnapshot) { - releaseDescriptor.addReleaseVersion(projectId, nextVersion); - } else if (releaseDescriptor.isBranchCreation() && convertToBranch) { - releaseDescriptor.addReleaseVersion(projectId, nextVersion); - } else { - releaseDescriptor.addDevelopmentVersion(projectId, nextVersion); + final String path = project.getFile().getPath(); + + boolean isExcludedPathFound = false; + for (String exclusionPattern : exclusionPatterns) { + if (FileSystems.getDefault() + .getPathMatcher("glob:" + exclusionPattern) + .matches(Paths.get(path))) { + isExcludedPathFound = true; + break; + } + } + if (!isExcludedPathFound) { + if (!convertToSnapshot) { + releaseDescriptor.addReleaseVersion(projectId, nextVersion); + } else if (releaseDescriptor.isBranchCreation() && convertToBranch) { + releaseDescriptor.addReleaseVersion(projectId, nextVersion); + } else { + releaseDescriptor.addDevelopmentVersion(projectId, nextVersion); + } } } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractRewritePomsPhase.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractRewritePomsPhase.java index 76747c56..d4a07f90 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractRewritePomsPhase.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractRewritePomsPhase.java @@ -19,16 +19,19 @@ package org.apache.maven.shared.release.phase; import java.io.File; -import java.net.URI; +import java.nio.file.FileSystems; +import java.nio.file.Paths; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Date; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Properties; +import java.util.Set; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -106,6 +109,8 @@ public abstract class AbstractRewritePomsPhase extends AbstractReleasePhase impl private long startTime = -1 * 1000; + private final Set exclusionPatterns = new HashSet<>(); + protected AbstractRewritePomsPhase( ScmRepositoryConfigurator scmRepositoryConfigurator, Map modelETLFactories, @@ -157,6 +162,12 @@ public ReleaseResult execute( throws ReleaseExecutionException, ReleaseFailureException { ReleaseResult result = new ReleaseResult(); + List additionalExcludes = releaseDescriptor.getCheckModificationExcludes(); + + if (additionalExcludes != null) { + exclusionPatterns.addAll(additionalExcludes); + } + transform(releaseDescriptor, releaseEnvironment, reactorProjects, false, result); result.setResultCode(ReleaseResult.SUCCESS); @@ -210,17 +221,19 @@ private void transform( throws ReleaseExecutionException, ReleaseFailureException { result.setStartTime((startTime >= 0) ? startTime : System.currentTimeMillis()); - URI root = ReleaseUtil.getRootProject(reactorProjects).getBasedir().toURI(); - for (MavenProject project : reactorProjects) { - URI pom = project.getFile().toURI(); - logInfo( - result, - "Transforming " + root.relativize(pom).getPath() + ' ' - + buffer().project(project.getArtifactId()) + " '" + project.getName() + "'" - + (simulate ? " with ." + getPomSuffix() + " suffix" : "") + "..."); + final String path = project.getFile().getPath(); + if (exclusionPatterns.stream().noneMatch(exclusionPattern -> FileSystems.getDefault() + .getPathMatcher("glob:" + exclusionPattern) + .matches(Paths.get(path)))) { + logDebug( + result, + "Transforming " + path + ' ' + + buffer().project(project.getArtifactId()) + " '" + project.getName() + "'" + + (simulate ? " with ." + getPomSuffix() + " suffix" : "") + "..."); - transformProject(project, releaseDescriptor, releaseEnvironment, simulate, result); + transformProject(project, releaseDescriptor, releaseEnvironment, simulate, result); + } } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractScmCommitPhase.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractScmCommitPhase.java index a479cbb9..c1ae801e 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractScmCommitPhase.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractScmCommitPhase.java @@ -19,9 +19,13 @@ package org.apache.maven.shared.release.phase; import java.io.File; +import java.nio.file.FileSystems; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collection; +import java.util.HashSet; import java.util.List; +import java.util.Set; import org.apache.maven.project.MavenProject; import org.apache.maven.scm.ScmException; @@ -61,6 +65,8 @@ public abstract class AbstractScmCommitPhase extends AbstractReleasePhase { */ protected final String descriptorCommentGetter; + private final Set exclusionPatterns = new HashSet<>(); + protected AbstractScmCommitPhase( ScmRepositoryConfigurator scmRepositoryConfigurator, String descriptorCommentGetter) { this.scmRepositoryConfigurator = requireNonNull(scmRepositoryConfigurator); @@ -77,6 +83,12 @@ public ReleaseResult execute( validateConfiguration(releaseDescriptor); + List additionalExcludes = releaseDescriptor.getCheckModificationExcludes(); + + if (additionalExcludes != null) { + exclusionPatterns.addAll(additionalExcludes); + } + runLogic(releaseDescriptor, releaseEnvironment, reactorProjects, relResult, false); relResult.setResultCode(ReleaseResult.SUCCESS); @@ -166,9 +178,12 @@ protected void performCheckins( } } else { List pomFiles = createPomFiles(releaseDescriptor, reactorProjects); - ScmFileSet fileSet = new ScmFileSet(new File(releaseDescriptor.getWorkingDirectory()), pomFiles); - checkin(provider, repository, fileSet, releaseDescriptor, message); + if (!pomFiles.isEmpty()) { + ScmFileSet fileSet = new ScmFileSet(new File(releaseDescriptor.getWorkingDirectory()), pomFiles); + + checkin(provider, repository, fileSet, releaseDescriptor, message); + } } } @@ -288,11 +303,25 @@ protected static List createPomFiles(ReleaseDescriptor releaseDescriptor, * @param reactorProjects a {@link java.util.List} object * @return a {@link java.util.List} object */ - protected static List createPomFiles( - ReleaseDescriptor releaseDescriptor, List reactorProjects) { + protected List createPomFiles(ReleaseDescriptor releaseDescriptor, List reactorProjects) { + List pomFiles = new ArrayList<>(); for (MavenProject project : reactorProjects) { - pomFiles.addAll(createPomFiles(releaseDescriptor, project)); + + final String path = project.getFile().getPath(); + + boolean isExcludedPathFound = false; + for (String exclusionPattern : exclusionPatterns) { + if (FileSystems.getDefault() + .getPathMatcher("glob:" + exclusionPattern) + .matches(Paths.get(path))) { + isExcludedPathFound = true; + break; + } + } + if (!isExcludedPathFound) { + pomFiles.addAll(createPomFiles(releaseDescriptor, project)); + } } return pomFiles; } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/MapDevelopmentVersionPhaseIT.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/MapDevelopmentVersionPhaseIT.java index 6088a9b8..d4f830c2 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/MapDevelopmentVersionPhaseIT.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/MapDevelopmentVersionPhaseIT.java @@ -18,6 +18,7 @@ */ package org.apache.maven.shared.release.phase; +import java.io.File; import java.util.Collections; import java.util.List; @@ -46,7 +47,10 @@ private static MavenProject createProject(String artifactId, String version) { model.setGroupId("groupId"); model.setArtifactId(artifactId); model.setVersion(version); - return new MavenProject(model); + + MavenProject mavenProject = new MavenProject(model); + mavenProject.setFile(new File("src/test/resources/pomfinder/pom1.xml")); + return mavenProject; } @Test diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/MapVersionsPhaseTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/MapVersionsPhaseTest.java index 36baf5df..cee4dbc7 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/MapVersionsPhaseTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/MapVersionsPhaseTest.java @@ -18,6 +18,7 @@ */ package org.apache.maven.shared.release.phase; +import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -2452,6 +2453,9 @@ private static MavenProject createProject(String artifactId, String version) { model.setGroupId("groupId"); model.setArtifactId(artifactId); model.setVersion(version); - return new MavenProject(model); + + MavenProject mavenProject = new MavenProject(model); + mavenProject.setFile(new File("src/test/resources/pomfinder/pom1.xml")); + return mavenProject; } }