Skip to content
Permalink
Browse files

Merge pull request #86 from jglick/SCM-Job

[JENKINS-23365] Work in a general Job
  • Loading branch information
jglick committed Jun 16, 2014
2 parents c0f3ef4 + 5c4c1de commit e87e989537edc5eaabb2cd22f786f7778a24948e
@@ -28,7 +28,7 @@ THE SOFTWARE.
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.509</version>
<version>1.568</version>
</parent>

<artifactId>subversion</artifactId>
@@ -37,5 +37,9 @@
// return false;
// }

@Override public String toString() {
return "SVNRevisionState" + revisions;
}

private static final long serialVersionUID = 1L;
}
@@ -31,6 +31,8 @@
import hudson.util.IOException2;
import hudson.remoting.VirtualChannel;
import hudson.FilePath.FileCallable;
import hudson.model.Run;
import hudson.model.TaskListener;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.tmatesoft.svn.core.SVNException;
@@ -55,6 +57,7 @@
import java.io.Serializable;
import java.util.Map;
import java.util.Collection;
import javax.annotation.Nonnull;

/**
* Builds <tt>changelog.xml</tt> for {@link SubversionSCM}.
@@ -71,27 +74,29 @@
*/
private final Map<String,Long> thisRevisions;

private final BuildListener listener;
private final TaskListener listener;
private final SubversionSCM scm;
private final AbstractBuild<?,?> build;
private final Run<?,?> build;
private final FilePath workspace;
private final EnvVars env;

/**
* @deprecated 1.34
*/
public SubversionChangeLogBuilder(AbstractBuild<?,?> build, BuildListener listener, SubversionSCM scm) throws IOException {
this(build, null,listener, scm);
this(build, build.getWorkspace(), build.getPreviousBuild().getAction(SVNRevisionState.class), null, listener, scm);
}

/**
* @since 1.34
*/
public SubversionChangeLogBuilder(AbstractBuild<?,?> build, EnvVars env, BuildListener listener, SubversionSCM scm) throws IOException {
previousRevisions = scm.parseSvnRevisionFile(build.getPreviousBuild());
public SubversionChangeLogBuilder(Run<?,?> build, FilePath workspace, @Nonnull SVNRevisionState baseline, EnvVars env, TaskListener listener, SubversionSCM scm) throws IOException {
previousRevisions = baseline.revisions;
thisRevisions = scm.parseSvnRevisionFile(build);
this.listener = listener;
this.scm = scm;
this.build = build;
this.workspace = workspace;
this.env = env;
}

@@ -109,11 +114,11 @@ public boolean run(Collection<SubversionSCM.External> externals, Result changeLo
for (ModuleLocation l : scm.getLocations(env, build)) {
ISVNAuthenticationProvider authProvider =
CredentialsSVNAuthenticationProviderImpl
.createAuthenticationProvider(build.getProject(), scm, l);
.createAuthenticationProvider(build.getParent(), scm, l);
final SVNClientManager manager = SubversionSCM.createClientManager(authProvider).getCore();
try {
SVNLogClient svnlc = manager.getLogClient();
PathContext context = getUrlForPath(build.getWorkspace().child(l.getLocalDir()), authProvider);
PathContext context = getUrlForPath(workspace.child(l.getLocalDir()), authProvider);
context.moduleWorkspacePath = l.getLocalDir();
changelogFileCreated |= buildModule(context, svnlc, logHandler);
} finally {
@@ -122,12 +127,12 @@ public boolean run(Collection<SubversionSCM.External> externals, Result changeLo
}
ISVNAuthenticationProvider authProvider =
CredentialsSVNAuthenticationProviderImpl
.createAuthenticationProvider(build.getProject(), scm, null);
.createAuthenticationProvider(build.getParent(), scm, null);
final SVNClientManager manager = SubversionSCM.createClientManager(authProvider).getCore();
try {
SVNLogClient svnlc = manager.getLogClient();
for(SubversionSCM.External ext : externals) {
PathContext context = getUrlForPath(build.getWorkspace().child(ext.path), authProvider);
PathContext context = getUrlForPath(workspace.child(ext.path), authProvider);
context.moduleWorkspacePath = ext.path;
changelogFileCreated |= buildModule(context, svnlc, logHandler);
}
@@ -23,7 +23,7 @@
*/
package hudson.scm;

import hudson.model.AbstractBuild;
import hudson.model.Run;
import hudson.scm.SubversionChangeLogSet.LogEntry;
import hudson.scm.SubversionChangeLogSet.Path;
import hudson.util.Digester2;
@@ -53,7 +53,7 @@ public SubversionChangeLogParser(boolean ignoreDirPropChanges) {
this.ignoreDirPropChanges = ignoreDirPropChanges;
}

public SubversionChangeLogSet parse(@SuppressWarnings("rawtypes") AbstractBuild build, File changelogFile) throws IOException, SAXException {
@Override public SubversionChangeLogSet parse(@SuppressWarnings("rawtypes") Run build, RepositoryBrowser<?> browser, File changelogFile) throws IOException, SAXException {
// http://svn.apache.org/repos/asf/subversion/trunk/subversion/svn/schema/log.rnc

Digester digester = new Digester2();
@@ -83,7 +83,7 @@ public SubversionChangeLogSet parse(@SuppressWarnings("rawtypes") AbstractBuild
for (LogEntry e : r) {
e.finish();
}
return new SubversionChangeLogSet(build,r, ignoreDirPropChanges);
return new SubversionChangeLogSet(build, browser, r, ignoreDirPropChanges);
}

}
@@ -25,6 +25,8 @@

import hudson.Util;
import hudson.model.AbstractBuild;
import hudson.model.Job;
import hudson.model.Run;
import hudson.model.User;
import hudson.scm.SubversionChangeLogSet.LogEntry;
import hudson.scm.SubversionSCM.ModuleLocation;
@@ -41,6 +43,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import jenkins.triggers.SCMTriggerItem;

import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
@@ -65,11 +68,11 @@

@Deprecated
/*package*/ SubversionChangeLogSet(AbstractBuild<?,?> build, List<LogEntry> logs) {
this(build, logs, false);
this(build, build.getProject().getScm().getEffectiveBrowser(), logs, false);
}

/*package*/ SubversionChangeLogSet(AbstractBuild<?,?> build, List<LogEntry> logs, boolean ignoreDirPropChanges) {
super(build);
/*package*/ SubversionChangeLogSet(Run<?,?> build, RepositoryBrowser<?> browser, List<LogEntry> logs, boolean ignoreDirPropChanges) {
super(build, browser);
this.ignoreDirPropChanges = ignoreDirPropChanges;
this.logs = prepareChangeLogEntries(logs);
}
@@ -230,8 +233,15 @@ public int size() {
}

private String preparePath(String path) {
SCM scm = getParent().build.getProject().getScm();
if (!(scm instanceof SubversionSCM)) return path;
Job job = getParent().getRun().getParent();
SCMTriggerItem s = SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(job);
if (s == null) {
return path;
}
for (SCM scm : s.getSCMs()) {
if (!(scm instanceof SubversionSCM)) {
continue;
}
ModuleLocation[] locations = ((SubversionSCM)scm).getLocations();
for (int i = 0; i < locations.length; i++) {
String commonPart = findCommonPart(locations[i].remote, path);
@@ -246,6 +256,7 @@ private String preparePath(String path) {
return newPath;
}
}
}
return path;
}

@@ -9,7 +9,7 @@
import hudson.ExtensionPoint;
import hudson.model.AbstractModelObject;
import hudson.model.AbstractProject;
import hudson.model.Hudson;
import hudson.model.Job;
import hudson.scm.SubversionSCM.ModuleLocation;
import hudson.scm.SubversionSCM.SvnInfo;
import hudson.triggers.SCMTrigger;
@@ -31,6 +31,7 @@
import javax.servlet.ServletException;

import jenkins.model.Jenkins;
import jenkins.triggers.SCMTriggerItem;
import org.apache.commons.io.IOUtils;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
@@ -63,7 +64,7 @@ public String getSearchUrl() {

static interface JobProvider {
@SuppressWarnings("rawtypes")
List<AbstractProject> getAllJobs();
List<Job> getAllJobs();
}

/**
@@ -150,8 +151,8 @@ public void doNotifyCommit(StaplerRequest req, StaplerResponse rsp) throws Servl

private JobProvider jobProvider = new JobProvider() {
@SuppressWarnings("rawtypes")
public List<AbstractProject> getAllJobs() {
return Hudson.getInstance().getAllItems(AbstractProject.class);
public List<Job> getAllJobs() {
return Jenkins.getInstance().getAllItems(Job.class);
}
};

@@ -165,13 +166,19 @@ public boolean onNotify(UUID uuid, long rev, Set<String> affectedPath) {
boolean scmFound = false, triggerFound = false, uuidFound = false, pathFound = false;
Map<String, UUID> remoteUUIDCache = new HashMap<String, UUID>();
LOGGER.fine("Starting subversion locations checks for all jobs");
for (AbstractProject<?,?> p : this.jobProvider.getAllJobs()) {
if(p.isDisabled()) continue;
for (Job p : this.jobProvider.getAllJobs()) {
SCMTriggerItem scmTriggerItem = SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(p);
if (scmTriggerItem == null) {
continue;
}
if (p instanceof AbstractProject && ((AbstractProject) p).isDisabled()) {
continue;
}
try {
SCM scm = p.getScm();
SCMS: for (SCM scm : scmTriggerItem.getSCMs()) {
if (scm instanceof SubversionSCM) scmFound = true; else continue;

SCMTrigger trigger = p.getTrigger(SCMTrigger.class);
SCMTrigger trigger = scmTriggerItem.getSCMTrigger();
if (trigger!=null && !doesIgnorePostCommitHooks(trigger)) triggerFound = true; else continue;

SubversionSCM sscm = (SubversionSCM) scm;
@@ -199,8 +206,8 @@ public boolean onNotify(UUID uuid, long rev, Set<String> affectedPath) {
if (LOGGER.isLoggable(FINER)) {
LOGGER.finer("Could not find " + loc.getURL() + " in " + remoteUUIDCache.keySet().toString());
}
remoteUUID = loc.getUUID(p);
SVNURL repositoryRoot = loc.getRepositoryRoot(p);
remoteUUID = loc.getUUID(p, scm);
SVNURL repositoryRoot = loc.getRepositoryRoot(p, scm);
repositoryRootPath = repositoryRoot.getPath();
remoteUUIDCache.put(repositoryRoot.toString(), remoteUUID);
}
@@ -242,6 +249,8 @@ public boolean onNotify(UUID uuid, long rev, Set<String> affectedPath) {
}

trigger.run(actions);
break SCMS;
}
}

} catch (SVNException e) {

0 comments on commit e87e989

Please sign in to comment.
You can’t perform that action at this time.