Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix JENKINS-12208
  • Loading branch information
Florence.Chabanois committed Jan 23, 2012
1 parent 81f2269 commit 47141d8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
Expand Up @@ -53,10 +53,10 @@ public FilePath computedFile(AbstractProject project, FileNameTriggerInfo fileIn

private FilePath computeFileOnMaster(FileNameTriggerInfo fileInfo, AbstractProject project, XTriggerLog log) throws XTriggerException {
Map<String, String> envVars = new XTriggerEnvVarsResolver().getEnvVars(project, Hudson.getInstance(), log);
log.info("Polling on the master");
log.info("Polling on the master.");
File file = new FSTriggerFileNameGetFileService(fileInfo, log, envVars).call();
if (file != null) {
log.info(String.format("\nMonitoring the file pattern '%s'", file.getPath()));
log.info(String.format("\nInspecting the file '%s'.", file.getPath()));
return new FilePath(Hudson.MasterComputer.localChannel, file.getPath());
} else {
return null;
Expand All @@ -76,25 +76,25 @@ private FilePath computeFileLabel(Label label, FileNameTriggerInfo fileInfo, Abs
File file = computeFileNode(node, fileInfo, project, log);
//We stop when the file exists on the slave
if (file != null) {
log.info(String.format("\nMonitoring the file pattern '%s'", file.getPath()));
log.info(String.format("\nChecking the file '%s'.", file.getPath()));
return new FilePath(node.getChannel(), file.getPath());
}
}

log.info(String.format("The file doesn't exist for the slaves with the label '%s'", label));
log.info(String.format("The file doesn't exist for the slaves with the label '%s'.", label));
return null;
}

private File computeFileNode(Node node, final FileNameTriggerInfo fileInfo, final AbstractProject project, final XTriggerLog log) throws XTriggerException {
try {
FilePath nodePath = node.getRootPath();
log.info(String.format("Polling on the node '%s'", node.getNodeName()));
log.info(String.format("Polling on the node '%s'.", node.getNodeName()));
// Is null if the slave is offline
if (nodePath != null) {
Map<String, String> envVars = new XTriggerEnvVarsResolver().getEnvVars(project, node, log);
return nodePath.act(new FSTriggerFileNameGetFileService(fileInfo, log, envVars));
} else {
log.info(String.format("The node '%s' is offline", node.getNodeName()));
log.info(String.format("The node '%s' is offline.", node.getNodeName()));
}
} catch (IOException e) {
throw new XTriggerException(e);
Expand Down
Expand Up @@ -6,6 +6,8 @@
import org.jenkinsci.plugins.fstrigger.triggers.FileNameTriggerInfo;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
* @author Gregory Boissinot
Expand All @@ -18,7 +20,7 @@ public class FSTriggerFileNameCheckedModifiedService {

private File resolvedFile;

private long lastModifiedDate;
private long lastModifiedDateTime;

private File newResolvedFile;

Expand All @@ -39,7 +41,7 @@ public FSTriggerFileNameCheckedModifiedService(XTriggerLog log, FileNameTriggerI
} else {
this.resolvedFile = new File(resolvedFilePath);
}
this.lastModifiedDate = resolvedFileLastModified;
this.lastModifiedDateTime = resolvedFileLastModified;
this.newResolvedFile = newResolvedFile;
}

Expand All @@ -62,8 +64,13 @@ public Boolean checkFileName() throws XTriggerException {
return true;
}

if (!fileInfo.isDoNotCheckLastModificationDate() && (newResolvedFile.lastModified() != lastModifiedDate)) {
log.info("The last modification date of the file '" + newResolvedFile + "' has changed.");
if (!fileInfo.isDoNotCheckLastModificationDate() && (newResolvedFile.lastModified() != lastModifiedDateTime)) {
log.info("The last modification date of the file '" + newResolvedFile + "' has changed.\n");
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MMM dd HH:mm:ss");
Date lastModifiedDate = new Date(lastModifiedDateTime);
Date newResolvedFileDate = new Date(newResolvedFile.lastModified());
log.info("The last date/time was " + simpleDateFormat.format(lastModifiedDate));
log.info("The current date/time is " + simpleDateFormat.format(newResolvedFileDate));
return true;
}

Expand Down
Expand Up @@ -63,13 +63,13 @@ public File call() throws XTriggerException {
//Computes all the files
FileSet fileSet = Util.createFileSet(folderPathFile, fileName);
if (fileSet.size() == 0) {
log.info(String.format("There is no matching files in the folder '%s' for the fileName '%s'", folder, fileName));
log.info(String.format("There is no matching files in the folder '%s' for the fileName '%s'.", folder, fileName));
return null;
}

if (fileSet.size() == 1) {
File file = ((FileResource) fileSet.iterator().next()).getFile();
log.info(String.format("Inspecting the file '%s'", file));
log.info(String.format("Checking one file: '%s'.", file));
return file;
}

Expand All @@ -94,7 +94,7 @@ public File call() throws XTriggerException {
}

if (lastModifiedFile != null) {
log.info("The selected file for polling is '" + lastModifiedFile.getPath() + "'");
log.info(String.format("The selected file to poll is '%s'.", lastModifiedFile.getPath()));
return lastModifiedFile;
}

Expand Down

0 comments on commit 47141d8

Please sign in to comment.