From 25f3aedef1de94ab8a83f3f8d19c4903fb14c0f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20St=C3=B6r?= Date: Tue, 24 Sep 2019 16:03:01 +0200 Subject: [PATCH] Allow to ignore certain files from the Git repo change detection This includes refactoring those methods that accept a ton of mojo configuration parameters. There is now a single class that wraps all of those. Fixes #77 --- pom.xml | 6 +- .../mavenplugins/release/BaseMojo.java | 72 +++++++++++++++- .../mavenplugins/release/NextMojo.java | 4 +- .../mavenplugins/release/Reactor.java | 21 ++--- .../mavenplugins/release/ReleaseMojo.java | 4 +- .../mavenplugins/release/ResolverWrapper.java | 36 ++------ .../release/TreeWalkingDiffDetector.java | 47 ++++++++-- src/site/markdown/changelog.md | 4 + ....java => TreeWalkingDiffDetectorTest.java} | 85 ++++++++++++++++--- src/test/java/scaffolding/TestProject.java | 8 +- 10 files changed, 219 insertions(+), 68 deletions(-) rename src/test/java/com/github/danielflower/mavenplugins/release/{DiffDetectorTest.java => TreeWalkingDiffDetectorTest.java} (50%) diff --git a/pom.xml b/pom.xml index 4fdaf3e9..86d693c1 100644 --- a/pom.xml +++ b/pom.xml @@ -1,12 +1,10 @@ - + 4.0.0 com.github.danielflower.mavenplugins multi-module-maven-release-plugin - 3.3-SNAPSHOT + 3.4-SNAPSHOT The Multi Module Maven Release Plugin A maven release plugin built for multi-maven-module git repositories allowing continuous deployment diff --git a/src/main/java/com/github/danielflower/mavenplugins/release/BaseMojo.java b/src/main/java/com/github/danielflower/mavenplugins/release/BaseMojo.java index 750ae55c..e0a58b58 100644 --- a/src/main/java/com/github/danielflower/mavenplugins/release/BaseMojo.java +++ b/src/main/java/com/github/danielflower/mavenplugins/release/BaseMojo.java @@ -7,7 +7,6 @@ import org.apache.maven.model.Scm; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.logging.Log; import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Parameter; @@ -19,15 +18,17 @@ import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider; import java.util.List; +import java.util.Set; import static java.lang.String.format; -import static java.util.Arrays.asList; /** * @author Roland Hauser sourcepond@gmail.com * */ public abstract class BaseMojo extends AbstractMojo { + private PluginConfiguration pluginConfiguration; + /** * The Maven Project. */ @@ -185,6 +186,23 @@ public void setBuildNumber(String buildNumber) { @Parameter(property = "arguments") public String arguments; + /** + *

List of relative file system paths to ignore when detecting changes in the project(s).

+ *

The primarily purpose is to skip creating new releases if only "infrastructure" files such as + * .gitignore, .editorconfig and the like changed. Very basic wild cards are supported as + * follows: + *

    + *
  • foo.txt - matches foo.txt in the root of the top-level project
  • + *
  • bar/foo.txt - matches foo.txt in the root of the bar directory
  • + *
  • bar - matches the foo directory and ignores everything below
  • + *
  • **.txt - matches all paths ending in .txt (suffix match)
  • + *
  • **.editorconfig - matches all .editorconfig files in all (sub)directories; a special case of suffix matching
  • + *
      + *

      + */ + @Parameter(property = "ignoredPaths") + Set ignoredPaths; + final void setSettings(final Settings settings) { this.settings = settings; } @@ -275,4 +293,54 @@ protected static String getRemoteUrlOrNullIfNoneSet(Scm originalScm, Scm actualS } return GitHelper.scmUrlToRemote(remote); } + + PluginConfiguration getPluginConfiguration() { + if (pluginConfiguration == null) { + pluginConfiguration = new PluginConfiguration(project, projects, buildNumber, versionNamer, + modulesToRelease, modulesToForceRelease, noChangesAction, factory, artifactResolver, remoteRepositories, + localRepository, settings, pullTags, arguments, ignoredPaths); + } + return pluginConfiguration; + } + + static class PluginConfiguration { + final MavenProject rootProject; + final List projects; + final String buildNumber; + final VersionNamer versionNamer; + final List modulesToRelease; + final List modulesToForceRelease; + final NoChangesAction noChangesAction; + final ArtifactFactory factory; + final ArtifactResolver artifactResolver; + final List remoteRepositories; + final ArtifactRepository localRepository; + final Settings settings; + final boolean pullTags; + final String arguments; + final Set ignoredPaths; + + PluginConfiguration(MavenProject rootProject, List projects, String buildNumber, + VersionNamer versionNamer, List modulesToRelease, + List modulesToForceRelease, NoChangesAction noChangesAction, + ArtifactFactory factory, ArtifactResolver artifactResolver, List remoteRepositories, + ArtifactRepository localRepository, Settings settings, boolean pullTags, String arguments, + Set ignoredPaths) { + this.rootProject = rootProject; + this.projects = projects; + this.buildNumber = buildNumber; + this.versionNamer = versionNamer; + this.modulesToRelease = modulesToRelease; + this.modulesToForceRelease = modulesToForceRelease; + this.noChangesAction = noChangesAction; + this.factory = factory; + this.artifactResolver = artifactResolver; + this.remoteRepositories = remoteRepositories; + this.localRepository = localRepository; + this.settings = settings; + this.pullTags = pullTags; + this.arguments = arguments; + this.ignoredPaths = ignoredPaths; + } + } } diff --git a/src/main/java/com/github/danielflower/mavenplugins/release/NextMojo.java b/src/main/java/com/github/danielflower/mavenplugins/release/NextMojo.java index de41f73f..94de4c7a 100644 --- a/src/main/java/com/github/danielflower/mavenplugins/release/NextMojo.java +++ b/src/main/java/com/github/danielflower/mavenplugins/release/NextMojo.java @@ -45,8 +45,8 @@ public void execute() throws MojoExecutionException, MojoFailureException { project.getModel().getScm())) .credentialsProvider(getCredentialsProvider(log)) .buildFromCurrentDir(); - ResolverWrapper resolverWrapper = new ResolverWrapper(factory, artifactResolver, remoteRepositories, localRepository); - Reactor reactor = Reactor.fromProjects(log, repo, project, projects, buildNumber, modulesToForceRelease, noChangesAction, resolverWrapper, versionNamer); + ResolverWrapper resolverWrapper = new ResolverWrapper(getPluginConfiguration()); + Reactor reactor = Reactor.fromProjects(repo, getPluginConfiguration(), resolverWrapper, noChangesAction, log); if (reactor == null) { return; } diff --git a/src/main/java/com/github/danielflower/mavenplugins/release/Reactor.java b/src/main/java/com/github/danielflower/mavenplugins/release/Reactor.java index a9926204..669e98af 100644 --- a/src/main/java/com/github/danielflower/mavenplugins/release/Reactor.java +++ b/src/main/java/com/github/danielflower/mavenplugins/release/Reactor.java @@ -29,15 +29,16 @@ public List getModulesInBuildOrder() { return modulesInBuildOrder; } - public static Reactor fromProjects(Log log, LocalGitRepo gitRepo, MavenProject rootProject, List projects, String buildNumber, List modulesToForceRelease, NoChangesAction actionWhenNoChangesDetected, ResolverWrapper resolverWrapper, VersionNamer versionNamer) throws ValidationException, GitAPIException, MojoExecutionException { - DiffDetector detector = new TreeWalkingDiffDetector(gitRepo.git.getRepository()); - List modules = new ArrayList(); + static Reactor fromProjects(LocalGitRepo gitRepo, BaseMojo.PluginConfiguration pluginConfiguration, ResolverWrapper resolverWrapper, NoChangesAction noChangesAction, Log log) throws ValidationException, GitAPIException, MojoExecutionException { + DiffDetector detector = new TreeWalkingDiffDetector(gitRepo.git.getRepository(), pluginConfiguration.ignoredPaths); + List modules = new ArrayList<>(); - resolveVersionsDefinedThroughProperties(projects); + resolveVersionsDefinedThroughProperties(pluginConfiguration.projects); + VersionNamer versionNamer = pluginConfiguration.versionNamer; AnnotatedTagFinder annotatedTagFinder = new AnnotatedTagFinder(versionNamer); - for (MavenProject project : projects) { - String relativePathToModule = calculateModulePath(rootProject, project); + for (MavenProject project : pluginConfiguration.projects) { + String relativePathToModule = calculateModulePath(pluginConfiguration.rootProject, project); String artifactId = project.getArtifactId(); String versionWithoutBuildNumber = project.getVersion().replace("-SNAPSHOT", ""); List previousTagsForThisModule = annotatedTagFinder.tagsForVersion(gitRepo.git, artifactId, versionWithoutBuildNumber); @@ -53,7 +54,7 @@ public static Reactor fromProjects(Log log, LocalGitRepo gitRepo, MavenProject r Collection remoteBuildNumbers = getRemoteBuildNumbers(gitRepo, artifactId, versionWithoutBuildNumber, versionNamer); previousBuildNumbers.addAll(remoteBuildNumbers); - VersionName newVersion = versionNamer.name(project.getVersion(), buildNumber, previousBuildNumbers); + VersionName newVersion = versionNamer.name(project.getVersion(), pluginConfiguration.buildNumber, previousBuildNumbers); boolean oneOfTheDependenciesHasChanged = false; String changedDependency = null; @@ -90,7 +91,7 @@ public static Reactor fromProjects(Log log, LocalGitRepo gitRepo, MavenProject r String equivalentVersion = null; - if(modulesToForceRelease != null && modulesToForceRelease.contains(artifactId)) { + if(pluginConfiguration.modulesToForceRelease != null && pluginConfiguration.modulesToForceRelease.contains(artifactId)) { log.info("Releasing " + artifactId + " " + newVersion.releaseVersion() + " as we was asked to forced release."); } else if (oneOfTheDependenciesHasChanged) { log.info("Releasing " + artifactId + " " + newVersion.releaseVersion() + " as " + changedDependency + " has changed."); @@ -114,7 +115,7 @@ public static Reactor fromProjects(Log log, LocalGitRepo gitRepo, MavenProject r } if (!atLeastOneBeingReleased(modules)) { - switch (actionWhenNoChangesDetected) { + switch (noChangesAction) { case ReleaseNone: log.warn("No changes have been detected in any modules so will not perform release"); return null; @@ -122,7 +123,7 @@ public static Reactor fromProjects(Log log, LocalGitRepo gitRepo, MavenProject r throw new MojoExecutionException("No module changes have been detected"); default: log.warn("No changes have been detected in any modules so will re-release them all"); - List newList = new ArrayList(); + List newList = new ArrayList<>(); for (ReleasableModule module : modules) { newList.add(module.createReleasableVersion()); } diff --git a/src/main/java/com/github/danielflower/mavenplugins/release/ReleaseMojo.java b/src/main/java/com/github/danielflower/mavenplugins/release/ReleaseMojo.java index 5ded4f14..18d070e6 100644 --- a/src/main/java/com/github/danielflower/mavenplugins/release/ReleaseMojo.java +++ b/src/main/java/com/github/danielflower/mavenplugins/release/ReleaseMojo.java @@ -123,8 +123,8 @@ public void execute() throws MojoExecutionException, MojoFailureException { .buildFromCurrentDir(); repo.errorIfNotClean(); - ResolverWrapper resolverWrapper = new ResolverWrapper(factory, artifactResolver, remoteRepositories, localRepository); - Reactor reactor = Reactor.fromProjects(log, repo, project, projects, buildNumber, modulesToForceRelease, noChangesAction, resolverWrapper, versionNamer); + ResolverWrapper resolverWrapper = new ResolverWrapper(getPluginConfiguration()); + Reactor reactor = Reactor.fromProjects(repo, getPluginConfiguration(), resolverWrapper, noChangesAction, log); if (reactor == null) { return; } diff --git a/src/main/java/com/github/danielflower/mavenplugins/release/ResolverWrapper.java b/src/main/java/com/github/danielflower/mavenplugins/release/ResolverWrapper.java index 347e9d41..0656f7ea 100644 --- a/src/main/java/com/github/danielflower/mavenplugins/release/ResolverWrapper.java +++ b/src/main/java/com/github/danielflower/mavenplugins/release/ResolverWrapper.java @@ -10,43 +10,21 @@ import java.util.List; -/** - * - */ -public class ResolverWrapper { +class ResolverWrapper { private final ArtifactFactory factory; - private final ArtifactResolver artifactResolver; - private final List remoteRepositories; - private final ArtifactRepository localRepository; - public ResolverWrapper(ArtifactFactory factory, ArtifactResolver artifactResolver, List remoteRepositories, ArtifactRepository localRepository) { - this.factory = factory; - this.artifactResolver = artifactResolver; - this.remoteRepositories = remoteRepositories; - this.localRepository = localRepository; - } - - public ArtifactFactory getFactory() { - return factory; - } - - public ArtifactResolver getArtifactResolver() { - return artifactResolver; - } - - public List getRemoteRepositories() { - return remoteRepositories; - } - - public ArtifactRepository getLocalRepository() { - return localRepository; + ResolverWrapper(BaseMojo.PluginConfiguration pluginConfiguration) { + this.factory = pluginConfiguration.factory; + this.artifactResolver = pluginConfiguration.artifactResolver; + this.remoteRepositories = pluginConfiguration.remoteRepositories; + this.localRepository = pluginConfiguration.localRepository; } - public boolean isResolvable(String groupId, String artifactId, String version, String type, Log log) { + boolean isResolvable(String groupId, String artifactId, String version, String type, Log log) { try { Artifact pomArtifact = this.factory.createArtifact(groupId, artifactId, version, "", type); artifactResolver.resolve(pomArtifact, remoteRepositories, localRepository); diff --git a/src/main/java/com/github/danielflower/mavenplugins/release/TreeWalkingDiffDetector.java b/src/main/java/com/github/danielflower/mavenplugins/release/TreeWalkingDiffDetector.java index 81fd260c..6586e769 100644 --- a/src/main/java/com/github/danielflower/mavenplugins/release/TreeWalkingDiffDetector.java +++ b/src/main/java/com/github/danielflower/mavenplugins/release/TreeWalkingDiffDetector.java @@ -1,39 +1,75 @@ package com.github.danielflower.mavenplugins.release; +import org.codehaus.plexus.util.CollectionUtils; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.treewalk.filter.AndTreeFilter; import org.eclipse.jgit.treewalk.filter.PathFilter; +import org.eclipse.jgit.treewalk.filter.PathSuffixFilter; import org.eclipse.jgit.treewalk.filter.TreeFilter; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; public class TreeWalkingDiffDetector implements DiffDetector { private final Repository repo; + private final Set ignoredPaths; - public TreeWalkingDiffDetector(Repository repo) { + TreeWalkingDiffDetector(Repository repo, Set ignoredPaths) { this.repo = repo; + this.ignoredPaths = ignoredPaths; } - public boolean hasChangedSince(String modulePath, java.util.List childModules, Collection tags) throws IOException { + TreeWalkingDiffDetector(Repository repository) { + this(repository, Collections.emptySet()); + } + + public boolean hasChangedSince(String modulePath, List childModules, Collection tags) throws IOException { RevWalk walk = new RevWalk(repo); try { walk.setRetainBody(false); walk.markStart(walk.parseCommit(repo.getRefDatabase().findRef("HEAD").getObjectId())); - filterOutOtherModulesChanges(modulePath, childModules, walk); + + List treeFilters = createTreeFiltersForOtherModulesChanges(modulePath, childModules); + treeFilters.addAll(createTreeFiltersForIgnoredPaths()); + walk.setTreeFilter(treeFilters.size() == 1 ? treeFilters.get(0) : AndTreeFilter.create(treeFilters)); stopWalkingWhenTheTagsAreHit(tags, walk); + return walk.iterator().hasNext(); } finally { walk.dispose(); } } + private Collection createTreeFiltersForIgnoredPaths() { + List treeFilters = new ArrayList<>(); + if (ignoredPaths != null) { + treeFilters.addAll( + ignoredPaths.stream() + // To differentiate path suffix filters from path filters in the configuration there is the special + // "**" prefix. + // foo.txt -> path filter that matches foo.txt in the root of the top-level project + // bar/foo.txt -> path filter that matches foo.txt in the root of the bar directory + // bar -> path filter that matches everything in/under the bar directory + // **.txt -> path suffix filter that matches all paths ending in .txt (suffix match) + // **.editorconfig -> path suffix filter that matches all .editorconfig files in all (sub)directories; a special case of suffix matching + .map(p -> p.startsWith("**") ? PathSuffixFilter.create(p.substring(2)): PathFilter.create(p)) + // tree filters define what to include, yet the users define what to IGNORE -> negate the filter + .map(TreeFilter::negate) + .collect(Collectors.toList()) + ); + } + return treeFilters; + } + private static void stopWalkingWhenTheTagsAreHit(Collection tags, RevWalk walk) throws IOException { for (AnnotatedTag tag : tags) { ObjectId commitId = tag.ref().getTarget().getObjectId(); @@ -42,7 +78,7 @@ private static void stopWalkingWhenTheTagsAreHit(Collection tags, } } - private void filterOutOtherModulesChanges(String modulePath, List childModules, RevWalk walk) { + private List createTreeFiltersForOtherModulesChanges(String modulePath, List childModules) { boolean isRootModule = ".".equals(modulePath); boolean isMultiModuleProject = !isRootModule || !childModules.isEmpty(); List treeFilters = new ArrayList<>(); @@ -60,7 +96,6 @@ private void filterOutOtherModulesChanges(String modulePath, List childM } } - TreeFilter treeFilter = treeFilters.size() == 1 ? treeFilters.get(0) : AndTreeFilter.create(treeFilters); - walk.setTreeFilter(treeFilter); + return treeFilters; } } diff --git a/src/site/markdown/changelog.md b/src/site/markdown/changelog.md index b0d59c26..4293e3e8 100644 --- a/src/site/markdown/changelog.md +++ b/src/site/markdown/changelog.md @@ -1,6 +1,10 @@ Changelog --------- +### 3.4.0 + +* Allow to define paths which should be ignored when detecting changes (`.gitignore` et.al.), #77 + ### 3.3.0 * Allow build numbers to be arbitrary strings or null, #75 diff --git a/src/test/java/com/github/danielflower/mavenplugins/release/DiffDetectorTest.java b/src/test/java/com/github/danielflower/mavenplugins/release/TreeWalkingDiffDetectorTest.java similarity index 50% rename from src/test/java/com/github/danielflower/mavenplugins/release/DiffDetectorTest.java rename to src/test/java/com/github/danielflower/mavenplugins/release/TreeWalkingDiffDetectorTest.java index 1570c27e..141a4f9f 100644 --- a/src/test/java/com/github/danielflower/mavenplugins/release/DiffDetectorTest.java +++ b/src/test/java/com/github/danielflower/mavenplugins/release/TreeWalkingDiffDetectorTest.java @@ -1,18 +1,30 @@ package com.github.danielflower.mavenplugins.release; import org.eclipse.jgit.api.errors.GitAPIException; +import org.junit.BeforeClass; import org.junit.Test; +import org.junit.experimental.runners.Enclosed; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameter; +import org.junit.runners.Parameterized.Parameters; import scaffolding.TestProject; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Set; import static com.github.danielflower.mavenplugins.release.AnnotatedTagFinderTest.saveFileInModule; import static java.util.Arrays.asList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; -public class DiffDetectorTest { +@RunWith(Enclosed.class) +public class TreeWalkingDiffDetectorTest { @Test public void canDetectIfFilesHaveBeenChangedForAModuleSinceSomeSpecificTag() throws Exception { @@ -24,9 +36,10 @@ public void canDetectIfFilesHaveBeenChangedForAModuleSinceSomeSpecificTag() thro DiffDetector detector = new TreeWalkingDiffDetector(project.local.getRepository()); - assertThat(detector.hasChangedSince("core-utils", noChildModules(), asList(tag2)), is(false)); - assertThat(detector.hasChangedSince("console-app", noChildModules(), asList(tag2)), is(true)); - assertThat(detector.hasChangedSince("console-app", noChildModules(), asList(tag3)), is(false)); + assertThat(detector.hasChangedSince("core-utils", noChildModules(), singletonListOf(tag1)), is(true)); + assertThat(detector.hasChangedSince("core-utils", noChildModules(), singletonListOf(tag2)), is(false)); + assertThat(detector.hasChangedSince("console-app", noChildModules(), singletonListOf(tag2)), is(true)); + assertThat(detector.hasChangedSince("console-app", noChildModules(), singletonListOf(tag3)), is(false)); } @Test @@ -35,10 +48,10 @@ public void canDetectThingsInTheRoot() throws IOException, GitAPIException { AnnotatedTag tag1 = saveFileInModule(simple, ".", "1.0", "1"); simple.commitRandomFile("."); DiffDetector detector = new TreeWalkingDiffDetector(simple.local.getRepository()); - assertThat(detector.hasChangedSince(".", noChildModules(), asList(tag1)), is(true)); + assertThat(detector.hasChangedSince(".", noChildModules(), singletonListOf(tag1)), is(true)); AnnotatedTag tag2 = saveFileInModule(simple, ".", "1.0", "2"); - assertThat(detector.hasChangedSince(".", noChildModules(), asList(tag2)), is(false)); + assertThat(detector.hasChangedSince(".", noChildModules(), singletonListOf(tag2)), is(false)); } @Test @@ -51,7 +64,7 @@ public void canDetectChangesAfterTheLastTag() throws IOException, GitAPIExceptio project.commitRandomFile("console-app"); DiffDetector detector = new TreeWalkingDiffDetector(project.local.getRepository()); - assertThat(detector.hasChangedSince("console-app", noChildModules(), asList(tag3)), is(true)); + assertThat(detector.hasChangedSince("console-app", noChildModules(), singletonListOf(tag3)), is(true)); } @Test @@ -63,7 +76,7 @@ public void canIgnoreChangesInModuleFolders() throws IOException, GitAPIExceptio DiffDetector detector = new TreeWalkingDiffDetector(project.local.getRepository()); assertThat(detector.hasChangedSince("server-modules", asList("server-module-a", "server-module-b"), - asList(tag1)), is(false)); + singletonListOf(tag1)), is(false)); } @Test @@ -75,11 +88,61 @@ public void canDetectLocalChangesWithModuleFolders() throws IOException, GitAPIE DiffDetector detector = new TreeWalkingDiffDetector(project.local.getRepository()); assertThat(detector.hasChangedSince("server-modules", asList("server-module-a", "server-module-b"), - asList(tag1)), is(true)); + singletonListOf(tag1)), is(true)); } + @RunWith(Parameterized.class) + public static class IgnorePaths { + private static TestProject project; + private static AnnotatedTag tag; + + @Parameter + public String ignoredPathsPattern; + + @Parameter(1) + public boolean changeExpected; + + @BeforeClass + public static void setup() throws IOException, GitAPIException { + project = TestProject.nestedProject(); + // create & commit a random file, then create a tag at that revision + tag = saveFileInModule(project, "server-modules", "1.0", "0"); + // create & commit three more files but do NOT create a tag at that revision + // -> changes in the project (-> signal for the plugin to release those) + project.commitFile("server-modules", "paul.txt"); + project.commitFile("core-utils", "muller.txt"); + project.commitFile(".", "4711.txt"); + } + + @Parameters(name = "{0} -> has changes: {1}") + public static Collection data() { + return Arrays.asList( + new Object[]{"**.txt", false}, // all .txt are ignored -> no (other) changes + new Object[]{"core-utils", true}, // only 1 directory ignored -> there are (other) changes + new Object[]{"core-utils/muller.txt", true}, // only 1 file in 1 directory ignored -> there are (other) changes + new Object[]{"4711.txt", true} // only 1 file ignored -> there are (other) changes + ); + } + + @Test + public void shouldConsiderIgnoredPathsWhenDetectingChanges() throws IOException { + // given the test project in setup() @BeforeClass + Set ignoredPaths = Collections.singleton(ignoredPathsPattern); + DiffDetector detector = new TreeWalkingDiffDetector(project.local.getRepository(), ignoredPaths); + + // when + boolean hasChangedSince = detector.hasChangedSince(".", Collections.emptyList(), singletonListOf(tag)); + + // then + assertThat(hasChangedSince, is(changeExpected)); + } + } + + private static Collection singletonListOf(AnnotatedTag tag) { + return Collections.singletonList(tag); + } - private static java.util.List noChildModules() { - return new ArrayList(); + private static List noChildModules() { + return new ArrayList<>(); } } diff --git a/src/test/java/scaffolding/TestProject.java b/src/test/java/scaffolding/TestProject.java index e01442bf..744884e0 100644 --- a/src/test/java/scaffolding/TestProject.java +++ b/src/test/java/scaffolding/TestProject.java @@ -19,7 +19,7 @@ public class TestProject { private static final MvnRunner defaultRunner = new MvnRunner(null); - private static final String PLUGIN_VERSION_FOR_TESTS = "3.3-SNAPSHOT"; + private static final String PLUGIN_VERSION_FOR_TESTS = "3.4-SNAPSHOT"; private static final String RELEASE_TARGET = "releaser:release"; private static final String NEXT_TARGET = "releaser:next"; @@ -73,11 +73,15 @@ public List mvnReleaserNext(String buildNumber, String...arguments) { } public TestProject commitRandomFile(String module) throws IOException, GitAPIException { + return commitFile(module, UUID.randomUUID() + ".txt"); + } + + public TestProject commitFile(String module, String fileNameAndSuffix) throws IOException, GitAPIException { File moduleDir = new File(localDir, module); if (!moduleDir.isDirectory()) { throw new RuntimeException("Could not find " + moduleDir.getCanonicalPath()); } - File random = new File(moduleDir, UUID.randomUUID() + ".txt"); + File random = new File(moduleDir, fileNameAndSuffix); random.createNewFile(); String modulePath = module.equals(".") ? "" : module + "/"; local.add().addFilepattern(modulePath + random.getName()).call();