Skip to content

Commit

Permalink
Fix JENKINS-12208
Browse files Browse the repository at this point in the history
  • Loading branch information
gboissinot committed Jan 26, 2012
1 parent 81f2269 commit 5375d31
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 16 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
Expand Up @@ -8,6 +8,7 @@
import hudson.remoting.VirtualChannel;
import hudson.util.SequentialExecutionQueue;
import hudson.util.StreamTaskListener;
import org.apache.tools.ant.types.DirSet;
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.resources.FileResource;
import org.jenkinsci.lib.xtrigger.XTriggerException;
Expand Down Expand Up @@ -204,6 +205,21 @@ private Map<String, FileInfo> getFileInfo(String path, String includes, String e
if (includes == null) {
includes = "**/*.*, **/*";
}

//Process Directories
DirSet dirSet = new DirSet();
dirSet.setProject(new org.apache.tools.ant.Project());
dirSet.setDir(new File(path));
dirSet.setIncludes("*");
if (excludes != null) {
dirSet.setExcludes(excludes);
}
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();) {
FileResource fileResource = (FileResource) it.next();
Expand All @@ -212,6 +228,16 @@ private Map<String, FileInfo> getFileInfo(String path, String includes, String e
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()));
} else {
FileInfo fileInfo = new FileInfo(null, folderResource.getLastModified());
result.put(folderResource.getFile().getAbsolutePath(), fileInfo);
}
}

private void processFileResource(XTriggerLog log, Map<String, FileInfo> result, FileResource fileResource) throws XTriggerException {
if (!fileResource.isExists()) {
log.info(String.format("\nThe file '%s' doesn't exist anymore ", fileResource.getFile().getPath()));
Expand Down Expand Up @@ -329,13 +355,13 @@ private boolean computeEachFile(XTriggerLog log, Map<String, FileInfo> originMd5

//Checks if the file from the new compute has been modified
if (originFileInfo.getLastModified() != newFileInfo.getLastModified()) {
log.info(String.format("The '%s' last modification date has changed.", originFilePath));
log.info(String.format("The last modification date of '%s' has changed.", originFilePath));
return true;
}

//Checks it the content file from the new compute has been modified
if (!originFileInfo.getMd5().equals(newFileInfo.getMd5())) {
log.info(String.format("The '%s' content has changed.", originFilePath));
if (originFileInfo.getMd5() != null && !originFileInfo.getMd5().equals(newFileInfo.getMd5())) {
log.info(String.format("The content of '%s' has changed.", originFilePath));
return true;
}

Expand Down

0 comments on commit 5375d31

Please sign in to comment.