From 43efc1be3f4e2dfd996bf0b7d7e98aba7a981de8 Mon Sep 17 00:00:00 2001 From: kohsuke Date: Mon, 1 Jan 2007 06:11:46 +0000 Subject: [PATCH] SCM code is moved from Project to AbstractProject. git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@1587 71c3de6d-444a-0410-be80-ed276b4c234a --- .../java/hudson/model/AbstractProject.java | 63 +++++++++++++++ core/src/main/java/hudson/model/Project.java | 76 +------------------ 2 files changed, 64 insertions(+), 75 deletions(-) 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 { - private SCM scm = new NullSCM(); - /** * List of all {@link Trigger}s for this project. */ @@ -106,14 +100,6 @@ public class Project extends AbstractProject { updateTransientActions(); } - public SCM getScm() { - return scm; - } - - public void setScm(SCM scm) { - this.scm = scm; - } - @Override public BallColor getIconColor() { if(isDisabled()) @@ -198,54 +184,6 @@ public class Project extends AbstractProject { return lastBuild; } - 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; - } - } - /** * Returns the root directory of the checked-out module. * @@ -318,18 +256,6 @@ public class Project extends AbstractProject { } } - /** - * Schedules the SCM polling. If a polling is already in progress - * or a build is in progress, polling will take place after that. - * Otherwise the polling will be started immediately on a separate thread. - * - *

- * 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 { req.setCharacterEncoding("UTF-8"); int scmidx = Integer.parseInt(req.getParameter("scm")); - scm = SCMS.SCMS.get(scmidx).newInstance(req); + setScm(SCMS.SCMS.get(scmidx).newInstance(req)); buildDescribable(req, BuildWrappers.WRAPPERS, buildWrappers, "wrapper"); buildDescribable(req, BuildStep.BUILDERS, builders, "builder");