Skip to content

Commit

Permalink
Fix for JENKINS-16541
Browse files Browse the repository at this point in the history
  • Loading branch information
inky84 committed Jan 30, 2013
1 parent 880a125 commit 78c3120
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
40 changes: 35 additions & 5 deletions src/main/java/net/praqma/hudson/nametemplates/FileTemplate.java
@@ -1,7 +1,10 @@
package net.praqma.hudson.nametemplates;

import hudson.FilePath;
import hudson.remoting.VirtualChannel;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.praqma.hudson.CCUCMBuildAction;

Expand All @@ -12,13 +15,40 @@ public class FileTemplate extends Template {
@Override
public String parse( CCUCMBuildAction action, String filename ) {
try {
FilePath file = new FilePath(new File(action.getWorkspace() + System.getProperty("file.separator") + filename) );
logger.fine( String.format( "Full path to the remote %s", file.absolutize() ) );
logger.fine( String.format( "FILE: %s", file ) );
return file.readToString().trim();
} catch( Exception e ) {
logger.fine(String.format("[FileTemplate] Parsing FileTemplate"));
String res = action.getBuild().getExecutor().getCurrentWorkspace().act(new FileFoundable(filename));
logger.fine(String.format("[FileTemplate] Parse result: %s",res));
return res;
} catch( Exception e ) {
logger.logp(Level.SEVERE, this.getClass().getName(), "parse", "[FileTemplate] Caught exception", e);
logger.fine( "E: " + e.getMessage() );
return "?";
}
}

public class FileFoundable implements FilePath.FileCallable<String> {
public final String filename;

public FileFoundable(final String filename) {
logger.fine("[FileTemplate] FileFoundable created");
this.filename = filename;
}

@Override
public String invoke(File f, VirtualChannel channel) throws IOException, InterruptedException {
FilePath path = null;
logger.fine(String.format("In invoke. Operating on slave with workspace path: %s",f.getAbsolutePath()));
try {
path = new FilePath(new FilePath(f), filename);
String readFile = path.readToString().trim();
logger.fine(String.format("[FileTemplate] This file was read on the slave: %s", readFile));
return readFile;
} catch (IOException ex) {
logger.fine(String.format("[FileTemplate] Using this file on remote: %s",path.absolutize().getRemote()));
logger.fine(String.format("[FileTemplate] Invoke caught exception with message %s", ex.getMessage()));
throw ex;
}
}

}
}
3 changes: 2 additions & 1 deletion src/main/java/net/praqma/hudson/nametemplates/Template.java
@@ -1,8 +1,9 @@
package net.praqma.hudson.nametemplates;

import java.io.Serializable;
import net.praqma.hudson.CCUCMBuildAction;
import net.praqma.hudson.exception.TemplateException;

public abstract class Template {
public abstract class Template implements Serializable {
public abstract String parse( CCUCMBuildAction action, String args ) throws TemplateException;
}

0 comments on commit 78c3120

Please sign in to comment.