Skip to content

Commit

Permalink
Allow triggering on new prerelease versions (#3)
Browse files Browse the repository at this point in the history
[FIXED JENKINS-34420] Allow triggering on new prerelease versions
  • Loading branch information
Greybird committed Apr 25, 2016
1 parent 482f73c commit 91478ba
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 24 deletions.
Expand Up @@ -14,6 +14,7 @@
abstract class NugetCommandBase {

static final String NON_INTERACTIVE = "-NonInteractive";
static final String PRE_RELEASE = "-Prerelease";

int retryCount = 1;
protected TaskListener listener;
Expand Down
Expand Up @@ -17,20 +17,25 @@ class NugetGetLatestPackageVersionCommand extends NugetCommandBase {

private ForkingOutputStream fork;
private final String packageName;
private final boolean checkPrerelease;
private final XTriggerLog log;
private String version;

NugetGetLatestPackageVersionCommand(XTriggerLog log, NugetGlobalConfiguration configuration, FilePath workDir, String packageName) {
NugetGetLatestPackageVersionCommand(XTriggerLog log, NugetGlobalConfiguration configuration, FilePath workDir, String packageName, boolean checkPrerelease) {
super(log.getListener(), configuration, workDir);
this.log = log;
this.packageName = packageName;
this.checkPrerelease = checkPrerelease;
this.retryCount = 3;
}

@Override
protected void enrichArguments(ArgumentListBuilder builder) {
builder.add("list");
builder.add(packageName);
if (checkPrerelease) {
builder.add(PRE_RELEASE);
}
builder.add(NON_INTERACTIVE);
}

Expand Down
Expand Up @@ -27,6 +27,7 @@ class NugetPackageCheckerVisitor extends SimpleFileVisitor<Path> {

private final Map<String, String> latestPackageVersions = Maps.newHashMap();
private final XTriggerLog log;
private final boolean preReleaseChecked;
private final FilePath workspaceRoot;
private final DocumentBuilder builder;
private final NugetGlobalConfiguration configuration;
Expand All @@ -36,9 +37,10 @@ boolean isUpdated() {
return updated;
}

NugetPackageCheckerVisitor(XTriggerLog log, NugetGlobalConfiguration configuration, FilePath workspaceRoot) throws ParserConfigurationException {
NugetPackageCheckerVisitor(XTriggerLog log, NugetGlobalConfiguration configuration, boolean preReleaseChecked, FilePath workspaceRoot) throws ParserConfigurationException {
this.log = log;
this.configuration = configuration;
this.preReleaseChecked = preReleaseChecked;
this.workspaceRoot = workspaceRoot;
builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
}
Expand Down Expand Up @@ -90,7 +92,7 @@ private String getPackageVersion(FilePath workspaceRoot, String packageName) thr
if (latestPackageVersions.containsKey(packageName)) {
return latestPackageVersions.get(packageName);
}
NugetGetLatestPackageVersionCommand command = new NugetGetLatestPackageVersionCommand(log, configuration, workspaceRoot, packageName);
NugetGetLatestPackageVersionCommand command = new NugetGetLatestPackageVersionCommand(log, configuration, workspaceRoot, packageName, preReleaseChecked);
command.execute();
return command.getVersion();
}
Expand Down
Expand Up @@ -5,6 +5,7 @@
import jenkins.MasterToSlaveFileCallable;
import org.jenkinsci.lib.xtrigger.XTriggerLog;
import org.jenkinsci.plugins.nuget.NugetGlobalConfiguration;
import org.jenkinsci.plugins.nuget.triggers.NugetTrigger;

import javax.xml.parsers.ParserConfigurationException;
import java.io.File;
Expand All @@ -16,18 +17,20 @@
* @author Arnaud TAMAILLON
*/
class NugetPackagesCheckerCallable extends MasterToSlaveFileCallable<Boolean> {
private XTriggerLog log;
private NugetGlobalConfiguration configuration;
private final boolean preReleaseChecked;
private final XTriggerLog log;
private final NugetGlobalConfiguration configuration;

NugetPackagesCheckerCallable(NugetGlobalConfiguration configuration, XTriggerLog log) {
NugetPackagesCheckerCallable(NugetGlobalConfiguration configuration, boolean preReleaseChecked, XTriggerLog log) {
this.configuration = configuration;
this.preReleaseChecked = preReleaseChecked;
this.log = log;
}

public Boolean invoke(File file, VirtualChannel vc) throws IOException, InterruptedException {
try {
FilePath filePath = new FilePath(file);
NugetPackageCheckerVisitor visitor = new NugetPackageCheckerVisitor(log, configuration, filePath);
NugetPackageCheckerVisitor visitor = new NugetPackageCheckerVisitor(log, configuration, preReleaseChecked, filePath);
Files.walkFileTree(Paths.get(file.getPath()), visitor);
return visitor.isUpdated();
} catch (ParserConfigurationException ex) {
Expand Down
Expand Up @@ -11,14 +11,14 @@
* @author bgregg
*/
public class NugetUpdater {
private FilePath solutionDir;
private NugetPackagesCheckerCallable nugetPackagesCheckerCallable;
private XTriggerLog log;
private final FilePath solutionDir;
private final NugetPackagesCheckerCallable nugetPackagesCheckerCallable;
private final XTriggerLog log;

public NugetUpdater(FilePath solutionDir, NugetGlobalConfiguration configuration, XTriggerLog log) {
public NugetUpdater(FilePath solutionDir, NugetGlobalConfiguration configuration, boolean checkPrerelease, XTriggerLog log) {
this.solutionDir = solutionDir;
this.log = log;
this.nugetPackagesCheckerCallable = new NugetPackagesCheckerCallable(configuration, log);
this.nugetPackagesCheckerCallable = new NugetPackagesCheckerCallable(configuration, checkPrerelease, log);
}

public boolean performUpdate() {
Expand Down
@@ -1,6 +1,5 @@
package org.jenkinsci.plugins.nuget.triggers;
import antlr.ANTLRException;
import hudson.FilePath;
import hudson.XmlFile;
import hudson.model.Items;
import jenkins.model.GlobalConfiguration;
Expand Down Expand Up @@ -28,11 +27,19 @@
* @author bgregg
*/
public class NugetTrigger extends AbstractTrigger {

private boolean checkPrerelease;

@DataBoundConstructor
public NugetTrigger(String cronTabSpec) throws ANTLRException {
public NugetTrigger(String cronTabSpec, boolean checkPrerelease) throws ANTLRException {
super(cronTabSpec);
this.checkPrerelease = checkPrerelease;
}

public boolean getCheckPrerelease() {
return checkPrerelease;
}

@Override
protected File getLogFile() {
return new File(job.getRootDir(), "nuget-polling.log");
Expand Down Expand Up @@ -60,15 +67,15 @@ protected boolean checkIfModified(Node node, XTriggerLog xtl) throws XTriggerExc
}
AbstractProject project = (AbstractProject) job;
NugetGlobalConfiguration configuration = GlobalConfiguration.all().get(NugetGlobalConfiguration.class);
NugetUpdater updater = new NugetUpdater(project.getSomeWorkspace(), configuration, xtl);
NugetUpdater updater = new NugetUpdater(project.getSomeWorkspace(), configuration, checkPrerelease, xtl);
return updater.performUpdate();
}

@Override
protected String getCause() {
return Messages.NugetCause_Cause();
}

@Override
public NugetTriggerDescriptor getDescriptor() {
return (NugetTriggerDescriptor)super.getDescriptor();
Expand All @@ -81,7 +88,7 @@ public Collection<? extends Action> getProjectActions() {
}
return Collections.singleton(new NugetTriggerAction(job, getLogFile()));
}

@Extension(ordinal=1000)
public static final class NugetTriggerDescriptor extends XTriggerDescriptor {
private String nugetExe;
Expand All @@ -90,7 +97,7 @@ public NugetTriggerDescriptor() {
super();
load();
}

@Override
public String getDisplayName() {
return Messages.NugetTrigger_DiplayName();
Expand Down
@@ -1,8 +1,12 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:i="jelly:fmt" xmlns:l="/lib/layout" xmlns:f="/lib/form">
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:i="jelly:fmt" xmlns:l="/lib/layout"
xmlns:f="/lib/form">
<f:entry title="${%Schedule}" help="/descriptor/hudson.triggers.TimerTrigger/help/spec">
<f:textarea name="cronTabSpec"
checkUrl="'${rootURL}/trigger/TimerTrigger/check?value='+encodeURIComponent(this.value)"
value="${instance.spec}"/>
</f:entry>
<f:textarea name="cronTabSpec"
checkUrl="'${rootURL}/trigger/TimerTrigger/check?value='+encodeURIComponent(this.value)"
value="${instance.spec}"/>
</f:entry>
<f:entry title="${%Prerelease}">
<f:checkbox name="checkPrerelease" checked="${instance.checkPrerelease}"/>
</f:entry>
</j:jelly>
@@ -0,0 +1 @@
Prerelease=Allow prerelease
@@ -0,0 +1 @@
Prerelease=Accepter les versions préliminaires

0 comments on commit 91478ba

Please sign in to comment.