Permalink
Browse files

BuildChooser extension point (mimic git-plugin)

  • Loading branch information...
ndeloof committed Oct 25, 2011
1 parent a257c4d commit 63e91a82ecbe415681054b7c6364d11a6466ae56
@@ -1,25 +0,0 @@
-package hudson.plugins.mercurial.build;
-
-/**
- * Capture the status of a Jenkins build vs a Mercurial commit ID
- * @author <a href="mailto:nicolas.deloof@cloudbees.com">Nicolas De loof</a>
- */
-public class Build {
-
- public int buildNumber;
-
- public String changesetID;
-
- public String branch;
-
- public Build(int buildNumber, String branch, String sha) {
- this.buildNumber = buildNumber;
- this.branch = branch;
- this.changesetID = sha;
- }
-
- @Override
- public String toString() {
- return "Build #" + buildNumber + " of " + changesetID + " on " + branch;
- }
-}
@@ -0,0 +1,42 @@
+package hudson.plugins.mercurial.build;
+
+import hudson.DescriptorExtensionList;
+import hudson.ExtensionPoint;
+import hudson.model.Describable;
+import hudson.model.Hudson;
+import hudson.plugins.mercurial.MercurialSCM;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.Collection;
+
+/**
+ * Extension point to identify the revision (commit ID) to be built
+ *
+ * @author <a href="mailto:nicolas.deloof@cloudbees.com">Nicolas De loof</a>
+ */
+public abstract class BuildChooser implements ExtensionPoint, Describable<BuildChooser>, Serializable {
+
+ /**
+ * Get a list of revisions (commit IDs or branch names) that are candidates to be built.
+ * @param branchSpec the branch specification, may be a specific branch name or a pattern to monitor multiple branches
+ * @return candidate revisions, may be an empty collection but not null
+ */
+ public abstract Collection<String> getCandidateRevisions(String branchSpec) throws IOException;
+
+ /**
+ * Refers back to the {@link MercurialSCM} that owns this build chooser.
+ */
+ public transient MercurialSCM scm;
+
+ public BuildChooserDescriptor getDescriptor() {
+ return (BuildChooserDescriptor)Hudson.getInstance().getDescriptorOrDie(getClass());
+ }
+
+ public static DescriptorExtensionList<BuildChooser,BuildChooserDescriptor> all() {
+ return Hudson.getInstance().<BuildChooser,BuildChooserDescriptor>getDescriptorList(BuildChooser.class);
+ }
+
+ private static final long serialVersionUID = 1L;
+
+}
@@ -0,0 +1,9 @@
+package hudson.plugins.mercurial.build;
+
+import hudson.model.Descriptor;
+
+/**
+ * @author <a href="mailto:nicolas.deloof@cloudbees.com">Nicolas De loof</a>
+ */
+public abstract class BuildChooserDescriptor extends Descriptor<BuildChooser> {
+}
@@ -2,13 +2,20 @@
import static hudson.Util.fixNull;
+<<<<<<< HEAD
import hudson.model.AbstractBuild;
import hudson.model.Action;
import hudson.plugins.mercurial.MercurialTagAction;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
+=======
+import hudson.model.Action;
+
+import java.io.Serializable;
+import java.util.HashMap;
+>>>>>>> 386bffe... BuildChooser extension point (mimic git-plugin)
import java.util.Map;
/**
@@ -21,6 +28,7 @@
/**
* Map of branch name -> build (Branch name to last built SHA1).
*/
+<<<<<<< HEAD
Map<String,MercurialTagAction> buildsByBranchName = new HashMap<String,MercurialTagAction>();
public final String scm;
@@ -31,19 +39,34 @@ public BuildData(String scm) {
public void saveBuild(MercurialTagAction build) {
buildsByBranchName.put(build.getBranch(), build);
+=======
+ Map<String,Build> buildsByBranchName = new HashMap<String,Build>();
+
+ public void saveBuild(Build build) {
+ buildsByBranchName.put(build.branch, build);
+>>>>>>> 386bffe... BuildChooser extension point (mimic git-plugin)
}
/**
* @return true if the changesetID has already been built in the past
*/
public boolean hasBeenBuilt(String changesetID) {
+<<<<<<< HEAD
for (MercurialTagAction b : buildsByBranchName.values()) {
if (b.getId().equals(changesetID)) return true;
+=======
+ for (Build b : buildsByBranchName.values()) {
+ if (b.changesetID.equals(changesetID)) return true;
+>>>>>>> 386bffe... BuildChooser extension point (mimic git-plugin)
}
return false;
}
+<<<<<<< HEAD
public MercurialTagAction getLastBuildOfBranch(String branch) {
+=======
+ public Build getLastBuildOfBranch(String branch) {
+>>>>>>> 386bffe... BuildChooser extension point (mimic git-plugin)
return buildsByBranchName.get(branch);
}
@@ -58,6 +81,7 @@ public String getIconFileName() {
public String getUrlName() {
return "mercurial";
}
+<<<<<<< HEAD
public static BuildData getBuildData(String scm, AbstractBuild<?,?> build) {
BuildData buildData = null;
@@ -77,4 +101,6 @@ public static BuildData getBuildData(String scm, AbstractBuild<?,?> build) {
return (buildData != null ? buildData : new BuildData(scm));
}
+=======
+>>>>>>> 386bffe... BuildChooser extension point (mimic git-plugin)
}
@@ -0,0 +1,26 @@
+package hudson.plugins.mercurial.build;
+
+import hudson.Extension;
+
+import java.io.IOException;
+import java.util.Collection;
+
+/**
+ * @author <a href="mailto:nicolas.deloof@cloudbees.com">Nicolas De loof</a>
+ */
+public class DefaultBuildChooser extends BuildChooser {
+
+ @Override
+ public Collection<String> getCandidateRevisions(String branchSpec) throws IOException {
+
+ return null;
+ }
+
+ @Extension
+ public static final class DescriptorImpl extends BuildChooserDescriptor {
+ @Override
+ public String getDisplayName() {
+ return "Default";
+ }
+ }
+}

0 comments on commit 63e91a8

Please sign in to comment.