Skip to content

Commit

Permalink
Merge pull request #38 from captdestrukto/workflow-fix
Browse files Browse the repository at this point in the history
Update to work with the workflow plugin
  • Loading branch information
mc1arke committed Apr 2, 2015
2 parents 5bc5af1 + 6eff635 commit 9f2a393
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 28 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.520</version>
<version>1.607</version>
</parent>

<artifactId>cvs</artifactId>
Expand Down
52 changes: 44 additions & 8 deletions src/main/java/hudson/scm/AbstractCvs.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@
import hudson.Util;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Run;
import hudson.model.BuildListener;
import hudson.model.TaskListener;
import hudson.remoting.VirtualChannel;
import hudson.scm.cvstagging.CvsTagAction;
import hudson.util.Secret;

import jenkins.scm.cvs.QuietPeriodCompleted;

import org.apache.commons.io.output.DeferredFileOutputStream;
import org.jenkinsci.remoting.RoleChecker;
import org.netbeans.lib.cvsclient.CVSRoot;
import org.netbeans.lib.cvsclient.Client;
import org.netbeans.lib.cvsclient.admin.AdminHandler;
Expand Down Expand Up @@ -80,6 +82,10 @@
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public abstract class AbstractCvs extends SCM implements ICvs {

protected static final DateFormat DATE_FORMATTER = new SimpleDateFormat("dd MMM yyyy HH:mm:ss Z", Locale.UK);
Expand All @@ -94,8 +100,8 @@ public boolean isCheckoutCurrentTimestamp() {
}

protected boolean checkout(CvsRepository[] repositories, boolean isFlatten, FilePath workspace, boolean canUseUpdate,
AbstractBuild<?, ?> build, String dateStamp, boolean pruneEmptyDirectories,
boolean cleanOnFailedUpdate, BuildListener listener) throws IOException, InterruptedException {
Run<?, ?> build, String dateStamp, boolean pruneEmptyDirectories,
boolean cleanOnFailedUpdate, TaskListener listener) throws IOException, InterruptedException {

final EnvVars envVars = build.getEnvironment(listener);

Expand Down Expand Up @@ -300,6 +306,12 @@ public Boolean invoke(final File workspace, final VirtualChannel channel) throws
}
}
}

@Override
public void checkRoles(RoleChecker checker)
throws SecurityException {
// Do nothing
}
})) {
listener.error("Cvs task failed");
return false;
Expand Down Expand Up @@ -468,6 +480,12 @@ public SCMRevisionState calcRevisionsFromBuild(final AbstractBuild<?, ?> build,
return build.getAction(CvsRevisionState.class);
}

@Override
public @CheckForNull SCMRevisionState calcRevisionsFromBuild(@Nonnull Run<?,?> build, @Nullable FilePath workspace,
@Nullable Launcher launcher, @Nonnull TaskListener listener)
throws IOException, InterruptedException {
return build.getAction(CvsRevisionState.class);
}

protected PollingResult compareRemoteRevisionWith(final AbstractProject<?, ?> project, final Launcher launcher,
final FilePath workspace, final TaskListener listener,
Expand Down Expand Up @@ -677,6 +695,12 @@ private CvsChangeSet getRemoteLogForModule(final CvsRepository repository, final
public CvsChangeSet invoke(File file, VirtualChannel virtualChannel) throws IOException, InterruptedException {
return executeRlog(cvsClient, rlogCommand, listener, encoding, globalOptions, repository, envVars, item.getLocation());
}

@Override
public void checkRoles(RoleChecker checker)
throws SecurityException {
// Do nothing
}
});
}

Expand Down Expand Up @@ -797,11 +821,11 @@ protected List<CVSChangeLogSet.CVSChangeLog> calculateChangeLog(final Date start
return changes;
}

protected void postCheckout(AbstractBuild<?, ?> build, File changelogFile, CvsRepository[] repositories,
FilePath workspace, final BuildListener listener, boolean flatten, EnvVars envVars)
protected void postCheckout(Run<?, ?> build, File changelogFile, CvsRepository[] repositories,
FilePath workspace, final TaskListener listener, boolean flatten, EnvVars envVars)
throws IOException, InterruptedException {
// build change log
final AbstractBuild<?, ?> lastCompleteBuild = build.getPreviousBuiltBuild();
final Run<?, ?> lastCompleteBuild = build.getPreviousBuiltBuild();

if (lastCompleteBuild != null && !isSkipChangeLog()) {
final Date lastCompleteTimestamp = getCheckoutDate(lastCompleteBuild);
Expand All @@ -812,7 +836,7 @@ protected void postCheckout(AbstractBuild<?, ?> build, File changelogFile, CvsRe
changes.addAll(calculateChangeLog(lastCompleteTimestamp, checkoutDate, location,
listener, build.getEnvironment(listener), workspace));
}
new CVSChangeLogSet(build,changes).toFile(changelogFile);
new CVSChangeLogSet(build, getBrowser(), changes).toFile(changelogFile);
} else {
createEmptyChangeLog(changelogFile, listener, "changelog");
}
Expand All @@ -838,6 +862,12 @@ public Void invoke(File module, VirtualChannel virtualChannel) throws IOExceptio
return null;
}

@Override
public void checkRoles(RoleChecker checker)
throws SecurityException {
// Do nothing
}

private void cleanup(File directory, AdminHandler adminHandler) throws IOException {
for (File file : adminHandler.getAllFiles(directory)) {
Entry entry = adminHandler.getEntry(file);
Expand Down Expand Up @@ -876,7 +906,7 @@ private void cleanup(File directory, AdminHandler adminHandler) throws IOExcepti
}
}

protected Date getCheckoutDate(AbstractBuild<?, ?> build) {
protected Date getCheckoutDate(Run<?, ?> build) {
QuietPeriodCompleted quietPeriodCompleted;
Date checkoutDate;
quietPeriodCompleted = build.getAction(QuietPeriodCompleted.class);
Expand Down Expand Up @@ -960,6 +990,12 @@ public List<CvsFile> invoke(final File moduleLocation, final VirtualChannel chan
return buildFileList(moduleLocation, envVars.expand(module.getRemoteName()));
}

@Override
public void checkRoles(RoleChecker checker)
throws SecurityException {
// Do nothing
}

public List<CvsFile> buildFileList(final File moduleLocation, final String prefix) throws IOException {
AdminHandler adminHandler = new StandardAdminHandler();
List<CvsFile> fileList = new ArrayList<CvsFile>();
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/hudson/scm/CVSChangeLogParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
package hudson.scm;

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

import java.io.File;
import java.io.IOException;
Expand All @@ -42,4 +44,9 @@ public CVSChangeLogSet parse(
final File changelogFile) throws IOException, SAXException {
return CVSChangeLogSet.parse(build, changelogFile);
}

@Override
public ChangeLogSet<? extends Entry> parse(Run build, RepositoryBrowser<?> browser, File changelogFile) throws IOException, SAXException {
return CVSChangeLogSet.parse(build, browser, changelogFile);
}
}
33 changes: 29 additions & 4 deletions src/main/java/hudson/scm/CVSChangeLogSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package hudson.scm;

import hudson.model.AbstractBuild;
import hudson.model.Run;
import hudson.model.User;
import hudson.scm.CVSChangeLogSet.CVSChangeLog;
import hudson.util.Digester2;
Expand All @@ -46,6 +47,7 @@
import java.util.List;

import jenkins.model.Jenkins;

import org.apache.commons.digester.Digester;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;
Expand All @@ -70,6 +72,15 @@ public CVSChangeLogSet(final AbstractBuild<?, ?> build,
}
}

public CVSChangeLogSet(final Run<?, ?> build, RepositoryBrowser<?> browser,
final List<CVSChangeLog> logs) {
super(build, browser);
this.logs = Collections.unmodifiableList(logs);
for (CVSChangeLog log : logs) {
log.setParent(this);
}
}

/**
* Returns the read-only list of changes.
*/
Expand All @@ -94,7 +105,21 @@ public String getKind() {

public static CVSChangeLogSet parse(final AbstractBuild<?, ?> build,
final java.io.File f) throws IOException, SAXException {
Digester digester = new Digester2();
ArrayList<CVSChangeLog> r = parseFile(f);

return new CVSChangeLogSet(build, r);
}

public static CVSChangeLogSet parse(final Run<?, ?> build, RepositoryBrowser<?> browser,
final java.io.File f) throws IOException, SAXException {
ArrayList<CVSChangeLog> r = parseFile(f);

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

private static ArrayList<CVSChangeLog> parseFile(final java.io.File f)
throws IOException2 {
Digester digester = new Digester2();
ArrayList<CVSChangeLog> r = new ArrayList<CVSChangeLog>();
digester.push(r);

Expand Down Expand Up @@ -143,9 +168,9 @@ public static CVSChangeLogSet parse(final AbstractBuild<?, ?> build,
r.remove(log);
}
}

return new CVSChangeLogSet(build, r);
}
return r;
}

/**
* In-memory representation of CVS Changelog.
Expand Down
28 changes: 21 additions & 7 deletions src/main/java/hudson/scm/CVSSCM.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package hudson.scm;

import hudson.AbortException;
import hudson.Extension;
import hudson.FilePath;
import hudson.Launcher;
Expand All @@ -33,6 +34,7 @@
import hudson.util.Secret;
import jenkins.scm.cvs.QuietPeriodCompleted;
import net.sf.json.JSONObject;

import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;
Expand All @@ -52,6 +54,9 @@
import java.util.Set;
import java.util.TreeSet;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

import static hudson.Util.fixEmptyAndTrim;

/**
Expand Down Expand Up @@ -356,6 +361,20 @@ private String getBranchName() {
@Override
public boolean checkout(final AbstractBuild<?, ?> build, final Launcher launcher, final FilePath workspace,
final BuildListener listener, final File changelogFile) throws IOException, InterruptedException {
try {
checkout(build, launcher, workspace, listener, changelogFile, null);
}
catch (AbortException e) {
return false;
}

return true;
}

@Override
public void checkout(final @Nonnull Run<?,?> build, final @Nonnull Launcher launcher, final @Nonnull FilePath workspace,
final @Nonnull TaskListener listener, final @CheckForNull File changelogFile,
final @CheckForNull SCMRevisionState baseline) throws IOException, InterruptedException {
if (!canUseUpdate) {
workspace.deleteContents();
}
Expand All @@ -370,18 +389,13 @@ public boolean checkout(final AbstractBuild<?, ?> build, final Launcher launcher

if (!checkout(repositories, flatten, workspace, canUseUpdate,
build, dateStamp, pruneEmptyDirectories, cleanOnFailedUpdate, listener)) {
return false;
throw new AbortException();
}

postCheckout(build, changelogFile, getRepositories(), workspace, listener, isFlatten(), build.getEnvironment(listener));

return true;
}





@Override
public DescriptorImpl getDescriptor() {
return (DescriptorImpl) super.getDescriptor();
Expand Down Expand Up @@ -592,7 +606,7 @@ public final class TagAction extends AbstractScmTagAction implements Describable

private String tagName;

public TagAction(final AbstractBuild<?, ?> build) {
public TagAction(final Run<?, ?> build) {
super(build);
}

Expand Down
29 changes: 23 additions & 6 deletions src/main/java/hudson/scm/CvsProjectset.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
*/
package hudson.scm;

import hudson.AbortException;
import hudson.Extension;
import hudson.FilePath;
import hudson.Launcher;
import hudson.Util;
import hudson.model.*;
import hudson.scm.cvs.Messages;
import hudson.util.Secret;

import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.export.Exported;

Expand All @@ -42,6 +44,9 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;


public class CvsProjectset extends AbstractCvs {

Expand Down Expand Up @@ -109,6 +114,21 @@ protected PollingResult compareRemoteRevisionWith(AbstractProject<?, ?> project,
@Override
public boolean checkout(AbstractBuild<?, ?> build, Launcher launcher, FilePath workspace, BuildListener listener,
File changelogFile) throws IOException, InterruptedException {
try {
checkout(build, launcher, workspace, listener, changelogFile, null);
}
catch (AbortException e) {
return false;
}

return true;
}


@Override
public void checkout(final @Nonnull Run<?,?> build, final @Nonnull Launcher launcher, final @Nonnull FilePath workspace,
final @Nonnull TaskListener listener, final @CheckForNull File changelogFile,
final @CheckForNull SCMRevisionState baseline) throws IOException, InterruptedException {
if (!isCanUseUpdate()) {
workspace.deleteContents();
}
Expand All @@ -121,20 +141,17 @@ public boolean checkout(AbstractBuild<?, ?> build, Launcher launcher, FilePath w

if (!checkout(getRepositories(), false, workspace, isCanUseUpdate(),
build, dateStamp, isPruneEmptyDirectories(), isCleanOnFailedUpdate(), listener)) {
return false;
throw new AbortException();
}

if (!checkout(getInnerRepositories(workspace), false, workspace, isCanUseUpdate(),
build, dateStamp, isPruneEmptyDirectories(), isCleanOnFailedUpdate(), listener)) {
return false;
throw new AbortException();
}

postCheckout(build, changelogFile, getAllRepositories(workspace), workspace, listener, isFlatten(), build.getEnvironment(listener));

return true;
}



private CvsRepository[] getInnerRepositories(FilePath workspace) throws IOException, InterruptedException {
List<CvsRepository> psfList = new ArrayList<CvsRepository>();
for (CvsRepository repository : getRepositories()) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/hudson/scm/cvstagging/CvsTagAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class CvsTagAction extends AbstractScmTagAction implements Describable<Cv
private transient CVSSCM parent;


public CvsTagAction(final AbstractBuild<?, ?> build, final AbstractCvs parent) {
public CvsTagAction(final Run<?, ?> build, final AbstractCvs parent) {
super(build);
this.parentScm = parent;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/hudson/scm/cvstagging/LegacyTagAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class LegacyTagAction extends AbstractScmTagAction implements
private volatile String tagName;
private CVSSCM parent;

public LegacyTagAction(final AbstractBuild<?, ?> build,
public LegacyTagAction(final Run<?, ?> build,
final CVSSCM parent) {
super(build);
this.parent = parent;
Expand Down

0 comments on commit 9f2a393

Please sign in to comment.