Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-23365] Draft SCM-Job rework.
  • Loading branch information
jglick committed Jun 10, 2014
1 parent 09438ec commit 6a633e0
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 67 deletions.
7 changes: 6 additions & 1 deletion pom.xml
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.509.4</version>
<version>1.568-SNAPSHOT</version>
</parent>
<artifactId>mercurial</artifactId>
<version>1.51-SNAPSHOT</version>
Expand Down Expand Up @@ -95,6 +95,11 @@
<artifactId>jsch</artifactId>
<version>0.1.50</version>
</dependency>
<dependency> <!-- TODO so long as we depend on a new core version, this is required to compile: -->
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>matrix-project</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>multiple-scms</artifactId>
Expand Down
19 changes: 14 additions & 5 deletions src/main/java/hudson/plugins/mercurial/ChangeComparator.java
Expand Up @@ -7,9 +7,11 @@
import hudson.ExtensionPoint;
import hudson.FilePath;
import hudson.Launcher;
import hudson.Util;
import hudson.model.TaskListener;
import hudson.model.AbstractProject;
import hudson.model.Hudson;
import hudson.model.Job;
import hudson.model.Node;
import hudson.scm.PollingResult;

Expand All @@ -29,10 +31,17 @@ public static ExtensionList<ChangeComparator> all() {
* Override to customize the compare functionality.
* @return either a class of change, or null if the standard comparison is wanted
*/
abstract public PollingResult.Change compare(MercurialSCM scm, Launcher launcher,
TaskListener listener, MercurialTagAction baseline,
PrintStream output, Node node, FilePath repository,
AbstractProject<?, ?> project)
throws IOException, InterruptedException;
public PollingResult.Change compare(MercurialSCM scm, Launcher launcher, TaskListener listener, MercurialTagAction baseline, PrintStream output, Node node, FilePath repository, Job<?, ?> project) throws IOException, InterruptedException {
if (Util.isOverridden(ChangeComparator.class, getClass(), "compare", MercurialSCM.class, Launcher.class, TaskListener.class, MercurialTagAction.class, PrintStream.class, Node.class, FilePath.class, AbstractProject.class) && project instanceof AbstractProject) {
return compare(scm, launcher, listener, baseline, output, node, repository, (AbstractProject) project);
} else {
throw new AbstractMethodError("you must override the new overload of compare");
}
}

@Deprecated
public PollingResult.Change compare(MercurialSCM scm, Launcher launcher, TaskListener listener, MercurialTagAction baseline, PrintStream output, Node node, FilePath repository, AbstractProject<?, ?> project) throws IOException, InterruptedException {
return compare(scm, launcher, listener, baseline, output, node, repository, (Job) project);
}

}
@@ -1,8 +1,9 @@
package hudson.plugins.mercurial;

import hudson.Util;
import hudson.model.AbstractBuild;
import hudson.model.Run;
import hudson.scm.ChangeLogParser;
import hudson.scm.RepositoryBrowser;
import hudson.util.Digester2;
import hudson.util.IOException2;

Expand Down Expand Up @@ -30,7 +31,7 @@ public MercurialChangeLogParser(Set<String> modules) {
this.modules = modules;
}

public MercurialChangeSetList parse(AbstractBuild build, File changelogFile)
@Override public MercurialChangeSetList parse(Run build, RepositoryBrowser<?> browser, File changelogFile)
throws IOException, SAXException {
Digester digester = new Digester2();
ArrayList<MercurialChangeSet> r = new ArrayList<MercurialChangeSet>();
Expand Down Expand Up @@ -91,7 +92,7 @@ public int compare(MercurialChangeSet o1, MercurialChangeSet o2) {
}
});

return new MercurialChangeSetList(build, r);
return new MercurialChangeSetList(build, browser, r);
}

}
@@ -1,7 +1,8 @@
package hudson.plugins.mercurial;

import hudson.scm.ChangeLogSet;
import hudson.model.AbstractBuild;
import hudson.model.Run;
import hudson.scm.RepositoryBrowser;

import java.util.List;
import java.util.Collections;
Expand All @@ -13,8 +14,8 @@
public class MercurialChangeSetList extends ChangeLogSet<MercurialChangeSet> {
private final List<MercurialChangeSet> changeSets;

/*package*/ MercurialChangeSetList(AbstractBuild build, List<MercurialChangeSet> logs) {
super(build);
/*package*/ MercurialChangeSetList(Run<?,?> build, RepositoryBrowser<?> browser, List<MercurialChangeSet> logs) {
super(build, browser);
Collections.reverse(logs); // put new things first
this.changeSets = Collections.unmodifiableList(logs);
for (MercurialChangeSet log : logs)
Expand Down
27 changes: 17 additions & 10 deletions src/main/java/hudson/plugins/mercurial/MercurialRevisionColumn.java
@@ -1,11 +1,11 @@
package hudson.plugins.mercurial;

import hudson.Extension;
import hudson.model.AbstractProject;
import hudson.model.Item;
import hudson.scm.SCM;
import hudson.views.ListViewColumn;
import hudson.views.ListViewColumnDescriptor;
import jenkins.triggers.SCMTriggerItem;
import org.kohsuke.stapler.DataBoundConstructor;

/**
Expand All @@ -22,15 +22,22 @@ public MercurialRevisionColumn() {
}

public String getMercurialRevision(final Item item) {
if (!AbstractProject.class.isAssignableFrom(item.getClass())) {
return "";
}
final SCM scm = ((AbstractProject) item).getScm();
if (scm == null || !MercurialSCM.class.isAssignableFrom(scm.getClass())) {
return "";
}

return ((MercurialSCM) scm).getRevision();
SCMTriggerItem s = SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(item);
if (s == null) {
return "";
}
String revision = null;
for (SCM scm : s.getSCMs()) {
if (!(scm instanceof MercurialSCM)) {
return "";
}
String _revision = ((MercurialSCM) scm).getRevision();
if (revision != null && !revision.equals(_revision)) {
return "";
}
revision = _revision;
}
return revision != null ? revision : "";
}

@Extension public static class DescriptorImpl extends ListViewColumnDescriptor {
Expand Down

0 comments on commit 6a633e0

Please sign in to comment.