diff --git a/core/src/main/java/hudson/model/AbstractProject.java b/core/src/main/java/hudson/model/AbstractProject.java index b782571fc8..ac07236788 100644 --- a/core/src/main/java/hudson/model/AbstractProject.java +++ b/core/src/main/java/hudson/model/AbstractProject.java @@ -2,6 +2,10 @@ package hudson.model; import hudson.maven.MavenJob; import hudson.FilePath; +import hudson.Launcher; +import hudson.Launcher.LocalLauncher; +import hudson.scm.SCM; +import hudson.scm.NullSCM; import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.StaplerResponse; @@ -19,6 +23,9 @@ import java.util.SortedMap; * @see AbstractBuild */ public abstract class AbstractProject
,R extends AbstractBuild
> extends Job
{ + + private SCM scm = new NullSCM(); + /** * All the builds keyed by their build number. */ @@ -190,6 +197,62 @@ public abstract class AbstractProject
,R extends A return b.getBuiltOn(); } + public boolean checkout(Build build, Launcher launcher, BuildListener listener, File changelogFile) throws IOException { + if(scm==null) + return true; // no SCM + + try { + FilePath workspace = getWorkspace(); + workspace.mkdirs(); + + return scm.checkout(build, launcher, workspace, listener, changelogFile); + } catch (InterruptedException e) { + e.printStackTrace(listener.fatalError("SCM check out aborted")); + return false; + } + } + + /** + * Checks if there's any update in SCM, and returns true if any is found. + * + *
+ * The caller is responsible for coordinating the mutual exclusion between
+ * a build and polling, as both touches the workspace.
+ */
+ public boolean pollSCMChanges( TaskListener listener ) {
+ if(scm==null) {
+ listener.getLogger().println("No SCM");
+ return false; // no SCM
+ }
+
+ try {
+ FilePath workspace = getWorkspace();
+ if(!workspace.exists()) {
+ // no workspace. build now, or nothing will ever be built
+ listener.getLogger().println("No workspace is available, so can't check for updates.");
+ listener.getLogger().println("Scheduling a new build to get a workspace.");
+ return true;
+ }
+
+ // TODO: do this by using the right slave
+ return scm.pollChanges(this, new LocalLauncher(listener), workspace, listener );
+ } catch (IOException e) {
+ e.printStackTrace(listener.fatalError(e.getMessage()));
+ return false;
+ } catch (InterruptedException e) {
+ e.printStackTrace(listener.fatalError("SCM polling aborted"));
+ return false;
+ }
+ }
+
+ public SCM getScm() {
+ return scm;
+ }
+
+ public void setScm(SCM scm) {
+ this.scm = scm;
+ }
+
//
//
// actions
diff --git a/core/src/main/java/hudson/model/Project.java b/core/src/main/java/hudson/model/Project.java
index 661cafb624..3eb569d191 100644
--- a/core/src/main/java/hudson/model/Project.java
+++ b/core/src/main/java/hudson/model/Project.java
@@ -1,13 +1,9 @@
package hudson.model;
import hudson.FilePath;
-import hudson.Launcher;
-import hudson.Launcher.LocalLauncher;
import hudson.model.Descriptor.FormException;
import hudson.model.Fingerprint.RangeSet;
import hudson.model.RunMap.Constructor;
-import hudson.scm.NullSCM;
-import hudson.scm.SCM;
import hudson.scm.SCMS;
import hudson.tasks.BuildStep;
import hudson.tasks.BuildTrigger;
@@ -45,8 +41,6 @@ import java.util.Vector;
*/
public class Project extends AbstractProject
- * The caller is responsible for coordinating the mutual exclusion between
- * a build and polling, as both touches the workspace.
- */
- public boolean pollSCMChanges( TaskListener listener ) {
- if(scm==null) {
- listener.getLogger().println("No SCM");
- return false; // no SCM
- }
-
- try {
- FilePath workspace = getWorkspace();
- if(!workspace.exists()) {
- // no workspace. build now, or nothing will ever be built
- listener.getLogger().println("No workspace is available, so can't check for updates.");
- listener.getLogger().println("Scheduling a new build to get a workspace.");
- return true;
- }
-
- // TODO: do this by using the right slave
- return scm.pollChanges(this, new LocalLauncher(listener), workspace, listener );
- } catch (IOException e) {
- e.printStackTrace(listener.fatalError(e.getMessage()));
- return false;
- } catch (InterruptedException e) {
- e.printStackTrace(listener.fatalError("SCM polling aborted"));
- return false;
- }
- }
-
/**
* Returns the root directory of the checked-out module.
*
@@ -318,18 +256,6 @@ public class Project extends AbstractProject
- * In any case this method returns immediately.
- */
- public void scheduleSCMPolling() {
- // TODO
- }
-
/**
* Returns true if the fingerprint record is configured in this project.
*/
@@ -365,7 +291,7 @@ public class Project extends AbstractProject