use of hudson.FilePath in project hudson-2.x by hudson.
the class AbstractBuild method getEnvironment.
@Override
public EnvVars getEnvironment(TaskListener log) throws IOException, InterruptedException {
EnvVars env = super.getEnvironment(log);
FilePath ws = getWorkspace();
if (// if this is done very early on in the build, workspace may not be decided yet. see HUDSON-3997
ws != null)
env.put("WORKSPACE", ws.getRemote());
// servlet container may have set CLASSPATH in its launch script,
// so don't let that inherit to the new child process.
// see http://www.nabble.com/Run-Job-with-JDK-1.4.2-tf4468601.html
env.put("CLASSPATH", "");
JDK jdk = project.getJDK();
if (jdk != null) {
Computer computer = Computer.currentComputer();
if (computer != null) {
// just in case were not in a build
jdk = jdk.forNode(computer.getNode(), log);
}
jdk.buildEnvVars(env);
}
project.getScm().buildEnvVars(this, env);
if (buildEnvironments != null)
for (Environment e : buildEnvironments) e.buildEnvVars(env);
for (EnvironmentContributingAction a : Util.filter(getActions(), EnvironmentContributingAction.class)) a.buildEnvVars(this, env);
EnvVars.resolve(env);
return env;
}
use of hudson.FilePath in project hudson-2.x by hudson.
the class WindowsServiceLifecycle method updateHudsonExeIfNeeded.
/**
* If <tt>hudson.exe</tt> is old compared to our copy,
* schedule an overwrite (except that since it's currently running,
* we can only do it when Hudson restarts next time.)
*/
private void updateHudsonExeIfNeeded() {
try {
File rootDir = Hudson.getInstance().getRootDir();
URL exe = getClass().getResource("/windows-service/hudson.exe");
String ourCopy = Util.getDigestOf(exe.openStream());
File currentCopy = new File(rootDir, "hudson.exe");
if (!currentCopy.exists())
return;
String curCopy = new FilePath(currentCopy).digest();
if (ourCopy.equals(curCopy))
// identical
return;
File stage = new File(rootDir, "hudson.exe.new");
FileUtils.copyURLToFile(exe, stage);
Kernel32.INSTANCE.MoveFileExA(stage.getAbsolutePath(), currentCopy.getAbsolutePath(), MOVEFILE_DELAY_UNTIL_REBOOT | MOVEFILE_REPLACE_EXISTING);
LOGGER.info("Scheduled a replacement of hudson.exe");
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Failed to replace hudson.exe", e);
} catch (InterruptedException e) {
LOGGER.log(Level.SEVERE, "Failed to replace hudson.exe", e);
}
}
use of hudson.FilePath in project hudson-2.x by hudson.
the class FileParameterDefinition method createValue.
@Override
public ParameterValue createValue(CLICommand command, String value) throws IOException, InterruptedException {
// capture the file to the server
FilePath src = new FilePath(command.channel, value);
File local = File.createTempFile("hudson", "parameter");
src.copyTo(new FilePath(local));
FileParameterValue p = new FileParameterValue(getName(), local, src.getName());
p.setDescription(getDescription());
p.setLocation(getName());
return p;
}
use of hudson.FilePath in project hudson-2.x by hudson.
the class CommandInterpreter method perform.
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, TaskListener listener) throws InterruptedException {
FilePath ws = build.getWorkspace();
FilePath script = null;
try {
try {
script = createScriptFile(ws);
} catch (IOException e) {
Util.displayIOException(e, listener);
e.printStackTrace(listener.fatalError(Messages.CommandInterpreter_UnableToProduceScript()));
return false;
}
int r;
try {
EnvVars envVars = build.getEnvironment(listener);
// convert variables to all upper cases.
for (Map.Entry<String, String> e : build.getBuildVariables().entrySet()) envVars.put(e.getKey(), e.getValue());
r = launcher.launch().cmds(buildCommandLine(script)).envs(envVars).stdout(listener).pwd(ws).join();
} catch (IOException e) {
Util.displayIOException(e, listener);
e.printStackTrace(listener.fatalError(Messages.CommandInterpreter_CommandFailed()));
r = -1;
}
return r == 0;
} finally {
try {
if (script != null)
script.delete();
} catch (IOException e) {
Util.displayIOException(e, listener);
e.printStackTrace(listener.fatalError(Messages.CommandInterpreter_UnableToDelete(script)));
}
}
}
use of hudson.FilePath in project hudson-2.x by hudson.
the class Fingerprinter method record.
private void record(AbstractBuild<?, ?> build, BuildListener listener, Map<String, String> record, final String targets) throws IOException, InterruptedException {
final class Record implements Serializable {
final boolean produced;
final String relativePath;
final String fileName;
final String md5sum;
public Record(boolean produced, String relativePath, String fileName, String md5sum) {
this.produced = produced;
this.relativePath = relativePath;
this.fileName = fileName;
this.md5sum = md5sum;
}
Fingerprint addRecord(AbstractBuild build) throws IOException {
FingerprintMap map = Hudson.getInstance().getFingerprintMap();
return map.getOrCreate(produced ? build : null, fileName, md5sum);
}
private static final long serialVersionUID = 1L;
}
final long buildTimestamp = build.getTimeInMillis();
FilePath ws = build.getWorkspace();
if (ws == null) {
listener.error(Messages.Fingerprinter_NoWorkspace());
build.setResult(Result.FAILURE);
return;
}
List<Record> records = ws.act(new FileCallable<List<Record>>() {
public List<Record> invoke(File baseDir, VirtualChannel channel) throws IOException {
List<Record> results = new ArrayList<Record>();
FileSet src = Util.createFileSet(baseDir, targets);
DirectoryScanner ds = src.getDirectoryScanner();
for (String f : ds.getIncludedFiles()) {
File file = new File(baseDir, f);
// consider the file to be produced by this build only if the timestamp
// is newer than when the build has started.
// 2000ms is an error margin since since VFAT only retains timestamp at 2sec precision
boolean produced = buildTimestamp <= file.lastModified() + 2000;
try {
results.add(new Record(produced, f, file.getName(), new FilePath(file).digest()));
} catch (IOException e) {
throw new IOException2(Messages.Fingerprinter_DigestFailed(file), e);
} catch (InterruptedException e) {
throw new IOException2(Messages.Fingerprinter_Aborted(), e);
}
}
return results;
}
});
for (Record r : records) {
Fingerprint fp = r.addRecord(build);
if (fp == null) {
listener.error(Messages.Fingerprinter_FailedFor(r.relativePath));
continue;
}
fp.add(build);
record.put(r.relativePath, fp.getHashString());
}
}
Aggregations