mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-11 19:16:42 +00:00
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
This commit is contained in:
1 parent
577d707f03
commit
43efc1be3f
2 files changed
+64
-75
No files matched your search
@@ -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<P extends AbstractProject<P,R>,R extends AbstractBuild<P,R>> extends Job<P,R> {
|
||||
|
||||
private SCM scm = new NullSCM();
|
||||
|
||||
/**
|
||||
* All the builds keyed by their build number.
|
||||
*/
|
||||
@@ -190,6 +197,62 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,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.
|
||||
*
|
||||
* <p>
|
||||
* 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
|
||||
|
||||
@@ -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<Project,Build> {
|
||||
|
||||
private SCM scm = new NullSCM();
|
||||
|
||||
/**
|
||||
* List of all {@link Trigger}s for this project.
|
||||
*/
|
||||
@@ -106,14 +100,6 @@ public class Project extends AbstractProject<Project,Build> {
|
||||
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<Project,Build> {
|
||||
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.
|
||||
*
|
||||
* <p>
|
||||
* 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<Project,Build> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* <p>
|
||||
* 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<Project,Build> {
|
||||
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");
|
||||
|
||||
Reference in new issue
Block a user