Skip to content
Permalink
Browse files

Fix JENKINS-18658

  • Loading branch information...
gboissinot committed Aug 1, 2013
1 parent 3289d10 commit a8a6844f2142021eb8fa5ab94efe00333bf7a731
@@ -1,64 +1,11 @@
package org.jenkinsci.plugins.fstrigger.core;

import hudson.Util;
import hudson.console.AnnotatedLargeText;
import hudson.model.AbstractProject;
import hudson.model.Action;
import org.apache.commons.jelly.XMLOutput;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;

/**
* Marked class for its matching jelly file
*
* @author Gregory Boissinot
*/
public class FSTriggerAction implements Action {

private transient AbstractProject<?, ?> job;

private transient File logFile;

private transient String actionTitle;

public FSTriggerAction(AbstractProject<?, ?> job, File logFile, String actionTitle) {
this.job = job;
this.logFile = logFile;
this.actionTitle = actionTitle;
}

public AbstractProject<?, ?> getOwner() {
return job;
}

@SuppressWarnings("unused")
public String getActionTitle() {
return actionTitle;
}

public String getIconFileName() {
return "clipboard.gif";
}

public String getDisplayName() {
return "FSTrigger Log";
}

public String getUrlName() {
return "triggerPollLog";
}

@SuppressWarnings("unused")
public String getLog() throws IOException {
return Util.loadFile(getLogFile());
}

public File getLogFile() {
return logFile;
}

@SuppressWarnings("unused")
public void writeLogTo(XMLOutput out) throws IOException {
new AnnotatedLargeText<FSTriggerAction>(getLogFile(), Charset.defaultCharset(), true, this).writeHtmlTo(0, out.asWriter());
}
public abstract class FSTriggerAction implements Action {
}

This file was deleted.

This file was deleted.

@@ -85,7 +85,7 @@ public File getFile() throws XTriggerException {
if (FileNameTrigger.STRATEGY_LATEST.equals(fileInfo.getStrategy())) {
log.info("According to the checked strategy, the latest modified file has been selected for the polling.");
File lastModifiedFile = null;
for (Iterator it = fileSet.iterator(); it.hasNext();) {
for (Iterator it = fileSet.iterator(); it.hasNext(); ) {
FileResource fileResource = (FileResource) it.next();
File curFile = fileResource.getFile();
if ((lastModifiedFile == null)
@@ -5,6 +5,7 @@
import hudson.Extension;
import hudson.FilePath;
import hudson.Util;
import hudson.console.AnnotatedLargeText;
import hudson.model.*;
import hudson.remoting.VirtualChannel;
import hudson.util.FormValidation;
@@ -14,12 +15,13 @@
import net.sf.json.JSONArray;
import net.sf.json.JSONException;
import net.sf.json.JSONObject;
import org.apache.commons.jelly.XMLOutput;
import org.jenkinsci.lib.xtrigger.AbstractTrigger;
import org.jenkinsci.lib.xtrigger.XTriggerDescriptor;
import org.jenkinsci.lib.xtrigger.XTriggerException;
import org.jenkinsci.lib.xtrigger.XTriggerLog;
import org.jenkinsci.plugins.fstrigger.core.FSTriggerAction;
import org.jenkinsci.plugins.fstrigger.core.FSTriggerContentFileType;
import org.jenkinsci.plugins.fstrigger.core.FSTriggerFilesAction;
import org.jenkinsci.plugins.fstrigger.service.FSTriggerComputeFileService;
import org.jenkinsci.plugins.fstrigger.service.FSTriggerFileNameCheckedModifiedService;
import org.kohsuke.stapler.QueryParameter;
@@ -28,6 +30,7 @@
import java.io.File;
import java.io.IOException;
import java.io.ObjectStreamException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -284,14 +287,53 @@ public String getCause() {

@Override
public Collection<? extends Action> getProjectActions() {
return Collections.singleton(new FSTriggerFilesAction((AbstractProject) job, getLogFile(), this.getDescriptor().getDisplayName()));
return Collections.singleton(new FSTriggerFilesAction(this.getDescriptor().getDisplayName()));
}

@Override
public FileNameTriggerDescriptor getDescriptor() {
return (FileNameTriggerDescriptor) Hudson.getInstance().getDescriptorOrDie(getClass());
}

public final class FSTriggerFilesAction extends FSTriggerAction {

private transient String actionTitle;

public FSTriggerFilesAction(String actionTitle) {
this.actionTitle = actionTitle;
}

@Override
public String getDisplayName() {
return "FSTrigger Files Log";
}

@Override
public String getUrlName() {
return "triggerPollLogFiles";
}

@Override
public String getIconFileName() {
return "clipboard.gif";
}

@SuppressWarnings("unused")
public String getActionTitle() {
return actionTitle;
}

@SuppressWarnings("unused")
public String getLog() throws IOException {
return Util.loadFile(getLogFile());
}

@SuppressWarnings("unused")
public void writeLogTo(XMLOutput out) throws IOException {
new AnnotatedLargeText<FSTriggerFilesAction>(getLogFile(), Charset.defaultCharset(), true, this).writeHtmlTo(0, out.asWriter());
}
}

@Extension
@SuppressWarnings("unused")
public static class FileNameTriggerDescriptor extends XTriggerDescriptor {
@@ -4,9 +4,11 @@
import hudson.Extension;
import hudson.FilePath;
import hudson.Util;
import hudson.console.AnnotatedLargeText;
import hudson.model.*;
import hudson.remoting.VirtualChannel;
import hudson.util.SequentialExecutionQueue;
import org.apache.commons.jelly.XMLOutput;
import org.apache.tools.ant.types.DirSet;
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.resources.FileResource;
@@ -16,10 +18,11 @@
import org.jenkinsci.lib.xtrigger.XTriggerDescriptor;
import org.jenkinsci.lib.xtrigger.XTriggerException;
import org.jenkinsci.lib.xtrigger.XTriggerLog;
import org.jenkinsci.plugins.fstrigger.core.FSTriggerFolderAction;
import org.jenkinsci.plugins.fstrigger.core.FSTriggerAction;
import org.kohsuke.stapler.DataBoundConstructor;

import java.io.*;
import java.nio.charset.Charset;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -133,7 +136,7 @@ public long getLastModified() {
protected synchronized boolean checkIfModified(Node pollingNode, final XTriggerLog log) throws XTriggerException {

EnvVarsResolver varsRetriever = new EnvVarsResolver();
Map<String, String> envVars = null;
Map<String, String> envVars;
try {
envVars = varsRetriever.getPollingEnvVars((AbstractProject) job, pollingNode);
} catch (EnvInjectException e) {
@@ -163,13 +166,6 @@ private void refreshMemoryInfo(Map<String, FileInfo> newMd5Map) throws XTriggerE
md5Map = newMd5Map;
}

/**
* Computes and gets the file information of the folder
*
* @param log
* @return the file of the folder information
* @throws XTriggerException
*/
private Map<String, FileInfo> getMd5Map(Node launcherNode, final String path, final String includes, final String excludes, final XTriggerLog log) throws XTriggerException {

if (path == null) {
@@ -201,6 +197,7 @@ private void refreshMemoryInfo(Map<String, FileInfo> newMd5Map) throws XTriggerE
} catch (InterruptedException e) {
throw new XTriggerException(e);
}

return result;
}

@@ -230,21 +227,20 @@ private void refreshMemoryInfo(Map<String, FileInfo> newMd5Map) throws XTriggerE
if (excludes != null) {
dirSet.setExcludes(excludes);
}
for (Iterator it = dirSet.iterator(); it.hasNext();) {
for (Iterator it = dirSet.iterator(); it.hasNext(); ) {
FileResource fileResource = (FileResource) it.next();
processDirectoryResource(log, result, fileResource);
}

//Process files
FileSet fileSet = Util.createFileSet(new File(path), includes, excludes);
for (Iterator it = fileSet.iterator(); it.hasNext();) {
for (Iterator it = fileSet.iterator(); it.hasNext(); ) {
FileResource fileResource = (FileResource) it.next();
processFileResource(log, result, fileResource);
}
return result;
}


private void processDirectoryResource(XTriggerLog log, Map<String, FileInfo> result, FileResource folderResource) throws XTriggerException {
if (!folderResource.isExists()) {
log.info(String.format("\nThe folder '%s' doesn't exist anymore ", folderResource.getFile().getPath()));
@@ -278,7 +274,6 @@ public String getCause() {
return CAUSE;
}


private boolean checkIfModified(Node launcherNode, String path, final XTriggerLog log, final Map<String, FileInfo> newMd5Map) throws XTriggerException {

assert launcherNode != null;
@@ -322,6 +317,7 @@ public Boolean invoke(File slavePath, VirtualChannel channel) throws IOException
} catch (InterruptedException ie) {
throw new XTriggerException(ie);
}

return isTriggering;
}

@@ -397,14 +393,53 @@ protected String getName() {

@Override
public Collection<? extends Action> getProjectActions() {
return Collections.singleton(new FSTriggerFolderAction((AbstractProject) job, getLogFile(), this.getDescriptor().getDisplayName()));
return Collections.singleton(new FSTriggerFolderAction(this.getDescriptor().getDisplayName()));
}

@Override
public FolderContentTriggerDescriptor getDescriptor() {
return (FolderContentTriggerDescriptor) Hudson.getInstance().getDescriptorOrDie(getClass());
}

public final class FSTriggerFolderAction extends FSTriggerAction {

private transient String actionTitle;

public FSTriggerFolderAction(String actionTitle) {
this.actionTitle = actionTitle;
}

@Override
public String getDisplayName() {
return "FSTrigger Folder Log";
}

@Override
public String getUrlName() {
return "triggerPollLogFolder";
}

@Override
public String getIconFileName() {
return "clipboard.gif";
}

@SuppressWarnings("unused")
public String getActionTitle() {
return actionTitle;
}

@SuppressWarnings("unused")
public String getLog() throws IOException {
return Util.loadFile(getLogFile());
}

@SuppressWarnings("unused")
public void writeLogTo(XMLOutput out) throws IOException {
new AnnotatedLargeText<FSTriggerFolderAction>(getLogFile(), Charset.defaultCharset(), true, this).writeHtmlTo(0, out.asWriter());
}
}

@Extension
@SuppressWarnings("unused")
public static class FolderContentTriggerDescriptor extends XTriggerDescriptor {
@@ -22,9 +22,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->

<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:l="/lib/layout">
<l:layout>
<st:include it="${it.owner}" page="sidepanel.jelly" />
<st:include it="${it.owner}" page="sidepanel.jelly" optional="true"/>
<l:main-panel>
<h1>${it.actionTitle}</h1>
<j:set var="log" value="${it.log}" />

0 comments on commit a8a6844

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