diff --git a/src/main/java/hudson/plugins/repo/RepoScm.java b/src/main/java/hudson/plugins/repo/RepoScm.java index 4e13898..bce8951 100644 --- a/src/main/java/hudson/plugins/repo/RepoScm.java +++ b/src/main/java/hudson/plugins/repo/RepoScm.java @@ -30,7 +30,11 @@ import java.io.Serializable; import java.net.URL; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.LinkedHashSet; import java.util.List; +import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; @@ -97,6 +101,7 @@ public class RepoScm extends SCM implements Serializable { @CheckForNull private boolean trace; @CheckForNull private boolean showAllChanges; @CheckForNull private boolean noTags; + @CheckForNull private Set ignoreProjects; /** * Returns the manifest repository URL. @@ -221,6 +226,14 @@ public String getDestinationDir() { return destinationDir; } + /** + * returns list of ignore projects. + */ + @Exported + public String getIgnoreProjects() { + return StringUtils.join(ignoreProjects, '\n'); + } + /** * Returns the value of currentBranch. */ @@ -300,6 +313,7 @@ public boolean isForceSync() { * executing "repo init" and "repo sync". * @param showAllChanges If this value is true, add the "--first-parent" option to * "git log" when determining changesets. + * */ @Deprecated public RepoScm(final String manifestRepositoryUrl, @@ -328,6 +342,7 @@ public RepoScm(final String manifestRepositoryUrl, setTrace(trace); setShowAllChanges(showAllChanges); setRepoUrl(repoUrl); + ignoreProjects = Collections.emptySet(); } /** @@ -355,6 +370,7 @@ public RepoScm(final String manifestRepositoryUrl) { trace = false; showAllChanges = false; noTags = false; + ignoreProjects = Collections.emptySet(); } /** @@ -553,6 +569,23 @@ public final void setNoTags(final boolean noTags) { this.noTags = noTags; } + /** + * Sets list of projects which changes will be ignored when + * calculating whether job needs to be rebuild. This field corresponds + * to serverpath i.e. "name" section of the manifest. + * @param ignoreProjects + * String representing project names separated by " ". + */ + @DataBoundSetter + public final void setIgnoreProjects(final String ignoreProjects) { + if (ignoreProjects == null) { + this.ignoreProjects = Collections.emptySet(); + return; + } + this.ignoreProjects = new LinkedHashSet( + Arrays.asList(ignoreProjects.split("\\s+"))); + } + @Override public SCMRevisionState calcRevisionsFromBuild( @Nonnull final Run build, @Nullable final FilePath workspace, @@ -565,6 +598,26 @@ public SCMRevisionState calcRevisionsFromBuild( return null; } + private boolean shouldIgnoreChanges(final RevisionState current, final RevisionState baseline) { + List changedProjects = current.whatChanged(baseline); + if ((changedProjects == null) || (ignoreProjects == null)) { + return false; + } + if (ignoreProjects.isEmpty()) { + return false; + } + + + // Check for every changed item if it is not contained in the + // ignored setting .. project must be rebuilt + for (ProjectState changed : changedProjects) { + if (!ignoreProjects.contains(changed.getServerPath())) { + return false; + } + } + return true; + } + @Override public PollingResult compareRemoteRevisionWith( @Nonnull final Job job, @Nullable final Launcher launcher, @@ -605,11 +658,16 @@ public PollingResult compareRemoteRevisionWith( getStaticManifest(launcher, repoDir, listener.getLogger()), getManifestRevision(launcher, repoDir, listener.getLogger()), expandedManifestBranch, listener.getLogger()); + final Change change; if (currentState.equals(myBaseline)) { change = Change.NONE; } else { - change = Change.SIGNIFICANT; + if (shouldIgnoreChanges(currentState, (RevisionState) myBaseline)) { + change = Change.NONE; + } else { + change = Change.SIGNIFICANT; + } } return new PollingResult(myBaseline, currentState, change); } diff --git a/src/main/resources/hudson/plugins/repo/RepoScm/config.jelly b/src/main/resources/hudson/plugins/repo/RepoScm/config.jelly index f09d440..a866851 100644 --- a/src/main/resources/hudson/plugins/repo/RepoScm/config.jelly +++ b/src/main/resources/hudson/plugins/repo/RepoScm/config.jelly @@ -23,6 +23,10 @@ + + + + diff --git a/src/main/webapp/help-ignoreChanges.html b/src/main/webapp/help-ignoreChanges.html new file mode 100644 index 0000000..f358ce9 --- /dev/null +++ b/src/main/webapp/help-ignoreChanges.html @@ -0,0 +1,6 @@ +
+

+ Specify projects changes in which would not be considered a change that requires project rebuild when polling scm. + Project should be specified as the name in the name section of the project declaration in manifest separated by spaces. +

+
diff --git a/src/test/java/hudson/plugins/repo/TestRepoScm.java b/src/test/java/hudson/plugins/repo/TestRepoScm.java new file mode 100644 index 0000000..6342651 --- /dev/null +++ b/src/test/java/hudson/plugins/repo/TestRepoScm.java @@ -0,0 +1,53 @@ +/* + * The MIT License + * + * Copyright (c) 2011, Brad Larson + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package hudson.plugins.repo; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; + +import junit.framework.TestCase; + +/** + * Test cases for the {@link RevisionState} class. + */ +public class TestRepoScm extends TestCase { + + + public void testSetIgnoredProjects() { + RepoScm scm = new RepoScm("http://manifesturl"); + scm.setIgnoreProjects(""); + assertEquals("", scm.getIgnoreProjects()); + + } + + public void testSetIgnoredProjectsKeepsOrder() { + RepoScm scm = new RepoScm("http://manifesturl"); + scm.setIgnoreProjects("projecta projectb"); + assertEquals("projecta\nprojectb", scm.getIgnoreProjects()); + scm.setIgnoreProjects("projectb projecta"); + assertEquals("projectb\nprojecta", scm.getIgnoreProjects()); + } +}