Skip to content

Commit

Permalink
Fix JENKINS-18658
Browse files Browse the repository at this point in the history
  • Loading branch information
gboissinot committed Aug 1, 2013
1 parent 3289d10 commit a8a6844
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 126 deletions.
@@ -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.

Expand Up @@ -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)
Expand Down
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -201,6 +197,7 @@ public Map<String, FileInfo> invoke(File node, VirtualChannel channel) throws IO
} catch (InterruptedException e) {
throw new XTriggerException(e);
}

return result;
}

Expand Down Expand Up @@ -230,21 +227,20 @@ private Map<String, FileInfo> getFileInfo(String path, String includes, String e
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()));
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -322,6 +317,7 @@ public Boolean invoke(File slavePath, VirtualChannel channel) throws IOException
} catch (InterruptedException ie) {
throw new XTriggerException(ie);
}

return isTriggering;
}

Expand Down Expand Up @@ -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 {
Expand Down
Expand Up @@ -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}" />
Expand Down

0 comments on commit a8a6844

Please sign in to comment.