use of hudson.FilePath in project hudson-2.x by hudson.
the class JavadocArchiver method perform.
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
listener.getLogger().println(Messages.JavadocArchiver_Publishing());
EnvVars env = build.getEnvironment(listener);
FilePath javadoc = build.getWorkspace().child(env.expand(javadocDir));
FilePath target = new FilePath(keepAll ? getJavadocDir(build) : getJavadocDir(build.getProject()));
try {
if (javadoc.copyRecursiveTo("**/*", target) == 0) {
if (build.getResult().isBetterOrEqualTo(Result.UNSTABLE)) {
// If the build failed, don't complain that there was no javadoc.
// The build probably didn't even get to the point where it produces javadoc.
listener.error(Messages.JavadocArchiver_NoMatchFound(javadoc, javadoc.validateAntFileMask("**/*")));
}
build.setResult(Result.FAILURE);
return true;
}
} catch (IOException e) {
Util.displayIOException(e, listener);
e.printStackTrace(listener.fatalError(Messages.JavadocArchiver_UnableToCopy(javadoc, target)));
build.setResult(Result.FAILURE);
return true;
}
// add build action, if javadoc is recorded for each build
if (keepAll)
build.addAction(new JavadocBuildAction(build));
return true;
}
use of hudson.FilePath in project hudson-2.x by hudson.
the class SlaveComputer method setChannel.
/**
* Creates a {@link Channel} from the given stream and sets that to this slave.
*
* @param in
* Stream connected to the remote "slave.jar". It's the caller's responsibility to do
* buffering on this stream, if that's necessary.
* @param out
* Stream connected to the remote peer. It's the caller's responsibility to do
* buffering on this stream, if that's necessary.
* @param launchLog
* If non-null, receive the portion of data in <tt>is</tt> before
* the data goes into the "binary mode". This is useful
* when the established communication channel might include some data that might
* be useful for debugging/trouble-shooting.
* @param listener
* Gets a notification when the channel closes, to perform clean up. Can be null.
* By the time this method is called, the cause of the termination is reported to the user,
* so the implementation of the listener doesn't need to do that again.
*/
public void setChannel(InputStream in, OutputStream out, OutputStream launchLog, Channel.Listener listener) throws IOException, InterruptedException {
if (this.channel != null)
throw new IllegalStateException("Already connected");
final TaskListener taskListener = new StreamTaskListener(launchLog);
PrintStream log = taskListener.getLogger();
Channel channel = new Channel(nodeName, threadPoolForRemoting, Channel.Mode.NEGOTIATE, in, out, launchLog);
channel.addListener(new Channel.Listener() {
@Override
public void onClosed(Channel c, IOException cause) {
SlaveComputer.this.channel = null;
// Orderly shutdown will have null exception
if (cause != null) {
offlineCause = new ChannelTermination(cause);
cause.printStackTrace(taskListener.error("Connection terminated"));
} else {
taskListener.getLogger().println("Connection terminated");
}
launcher.afterDisconnect(SlaveComputer.this, taskListener);
}
});
if (listener != null)
channel.addListener(listener);
String slaveVersion = channel.call(new SlaveVersion());
log.println("Slave.jar version: " + slaveVersion);
boolean _isUnix = channel.call(new DetectOS());
log.println(_isUnix ? hudson.model.Messages.Slave_UnixSlave() : hudson.model.Messages.Slave_WindowsSlave());
String defaultCharsetName = channel.call(new DetectDefaultCharset());
String remoteFs = getNode().getRemoteFS();
if (_isUnix && !remoteFs.contains("/") && remoteFs.contains("\\"))
log.println("WARNING: " + remoteFs + " looks suspiciously like Windows path. Maybe you meant " + remoteFs.replace('\\', '/') + "?");
FilePath root = new FilePath(channel, getNode().getRemoteFS());
channel.call(new SlaveInitializer());
channel.call(new WindowsSlaveInstaller(remoteFs));
for (ComputerListener cl : ComputerListener.all()) cl.preOnline(this, channel, root, taskListener);
offlineCause = null;
// update the data structure atomically to prevent others from seeing a channel that's not properly initialized yet
synchronized (channelLock) {
if (this.channel != null) {
// check again. we used to have this entire method in a big sycnhronization block,
// but Channel constructor blocks for an external process to do the connection
// if CommandLauncher is used, and that cannot be interrupted because it blocks at InputStream.
// so if the process hangs, it hangs the thread in a lock, and since Hudson will try to relaunch,
// we'll end up queuing the lot of threads in a pseudo deadlock.
// This implementation prevents that by avoiding a lock. HUDSON-1705 is likely a manifestation of this.
channel.close();
throw new IllegalStateException("Already connected");
}
isUnix = _isUnix;
numRetryAttempt = 0;
this.channel = channel;
defaultCharset = Charset.forName(defaultCharsetName);
}
for (ComputerListener cl : ComputerListener.all()) cl.onOnline(this, taskListener);
log.println("Slave successfully connected and online");
Hudson.getInstance().getQueue().scheduleMaintenance();
}
use of hudson.FilePath in project hudson-2.x by hudson.
the class DownloadFromUrlInstaller method performInstallation.
public FilePath performInstallation(ToolInstallation tool, Node node, TaskListener log) throws IOException, InterruptedException {
FilePath expected = preferredLocation(tool, node);
Installable inst = getInstallable();
if (inst == null) {
log.getLogger().println("Invalid tool ID " + id);
return expected;
}
if (isUpToDate(expected, inst))
return expected;
if (expected.installIfNecessaryFrom(new URL(inst.url), log, "Unpacking " + inst.url + " to " + expected + " on " + node.getDisplayName())) {
// we don't use the timestamp
expected.child(".timestamp").delete();
FilePath base = findPullUpDirectory(expected);
if (base != null && base != expected)
base.moveAllChildrenTo(expected);
// leave a record for the next up-to-date check
expected.child(".installedFrom").write(inst.url, "UTF-8");
expected.act(new ZipExtractionInstaller.ChmodRecAPlusX());
}
return expected;
}
use of hudson.FilePath in project hudson-2.x by hudson.
the class JDKInstaller method install.
/**
* Performs the JDK installation to a system, provided that the bundle was already downloaded.
*
* @param launcher
* Used to launch processes on the system.
* @param p
* Platform of the system. This determines how the bundle is installed.
* @param fs
* Abstraction of the file system manipulation on this system.
* @param log
* Where the output from the installation will be written.
* @param expectedLocation
* Path to install JDK to. Must be absolute and in the native file system notation.
* @param jdkBundle
* Path to the installed JDK bundle. (The bundle to download can be determined by {@link #locate(TaskListener, Platform, CPU)} call.)
*/
public void install(Launcher launcher, Platform p, FileSystem fs, TaskListener log, String expectedLocation, String jdkBundle) throws IOException, InterruptedException {
PrintStream out = log.getLogger();
out.println("Installing " + jdkBundle);
switch(p) {
case LINUX:
case SOLARIS:
fs.chmod(jdkBundle, 0755);
int exit = launcher.launch().cmds(jdkBundle, "-noregister").stdin(new ByteArrayInputStream("yes".getBytes())).stdout(out).pwd(new FilePath(launcher.getChannel(), expectedLocation)).join();
if (exit != 0)
throw new AbortException(Messages.JDKInstaller_FailedToInstallJDK(exit));
// JDK creates its own sub-directory, so pull them up
List<String> paths = fs.listSubDirectories(expectedLocation);
for (Iterator<String> itr = paths.iterator(); itr.hasNext(); ) {
String s = itr.next();
if (!s.matches("j(2s)?dk.*"))
itr.remove();
}
if (paths.size() != 1)
throw new AbortException("Failed to find the extracted JDKs: " + paths);
// remove the intermediate directory
fs.pullUp(expectedLocation + '/' + paths.get(0), expectedLocation);
break;
case WINDOWS:
/*
Windows silent installation is full of bad know-how.
On Windows, command line argument to a process at the OS level is a single string,
not a string array like POSIX. When we pass arguments as string array, JRE eventually
turn it into a single string with adding quotes to "the right place". Unfortunately,
with the strange argument layout of InstallShield (like /v/qn" INSTALLDIR=foobar"),
it appears that the escaping done by JRE gets in the way, and prevents the installation.
Presumably because of this, my attempt to use /q/vn" INSTALLDIR=foo" didn't work with JDK5.
I tried to locate exactly how InstallShield parses the arguments (and why it uses
awkward option like /qn, but couldn't find any. Instead, experiments revealed that
"/q/vn ARG ARG ARG" works just as well. This is presumably due to the Visual C++ runtime library
(which does single string -> string array conversion to invoke the main method in most Win32 process),
and this consistently worked on JDK5 and JDK4.
Some of the official documentations are available at
- http://java.sun.com/j2se/1.5.0/sdksilent.html
- http://java.sun.com/j2se/1.4.2/docs/guide/plugin/developer_guide/silent.html
*/
String logFile = jdkBundle + ".install.log";
ArgumentListBuilder args = new ArgumentListBuilder();
args.add(jdkBundle);
args.add("/s");
// according to http://community.acresso.com/showthread.php?t=83301, \" is the trick to quote values with whitespaces.
// Oh Windows, oh windows, why do you have to be so difficult?
args.add("/v/qn REBOOT=Suppress INSTALLDIR=\\\"" + expectedLocation + "\\\" /L \\\"" + logFile + "\\\"");
int r = launcher.launch().cmds(args).stdout(out).pwd(new FilePath(launcher.getChannel(), expectedLocation)).join();
if (r != 0) {
out.println(Messages.JDKInstaller_FailedToInstallJDK(r));
// log file is in UTF-16
InputStreamReader in = new InputStreamReader(fs.read(logFile), "UTF-16");
try {
IOUtils.copy(in, new OutputStreamWriter(out));
} finally {
in.close();
}
throw new AbortException();
}
fs.delete(logFile);
break;
}
}
use of hudson.FilePath in project hudson-2.x by hudson.
the class WorkspaceCleanupThread method process.
private void process(Hudson h) throws IOException, InterruptedException {
File jobs = new File(h.getRootDir(), "jobs");
File[] dirs = jobs.listFiles(DIR_FILTER);
if (dirs == null)
return;
for (File dir : dirs) {
FilePath ws = new FilePath(new File(dir, "workspace"));
if (shouldBeDeleted(dir.getName(), ws, h)) {
delete(ws);
}
}
}
Aggregations