use of hudson.util.IOException2 in project hudson-2.x by hudson.
the class FilePath method createTextTempFile.
/**
* Creates a temporary file in this directory and set the contents by the
* given text (encoded in the platform default encoding)
*/
public FilePath createTextTempFile(final String prefix, final String suffix, final String contents, final boolean inThisDirectory) throws IOException, InterruptedException {
try {
return new FilePath(channel, act(new FileCallable<String>() {
public String invoke(File dir, VirtualChannel channel) throws IOException {
if (!inThisDirectory)
dir = new File(System.getProperty("java.io.tmpdir"));
else
dir.mkdirs();
File f;
try {
f = File.createTempFile(prefix, suffix, dir);
} catch (IOException e) {
throw new IOException2("Failed to create a temporary directory in " + dir, e);
}
Writer w = new FileWriter(f);
w.write(contents);
w.close();
return f.getAbsolutePath();
}
}));
} catch (IOException e) {
throw new IOException2("Failed to create a temp file on " + remote, e);
}
}
use of hudson.util.IOException2 in project hudson-2.x by hudson.
the class FilePath method createTempDir.
/**
* Creates a temporary directory inside the directory represented by 'this'
* @since 1.311
*/
public FilePath createTempDir(final String prefix, final String suffix) throws IOException, InterruptedException {
try {
return new FilePath(this, act(new FileCallable<String>() {
public String invoke(File dir, VirtualChannel channel) throws IOException {
File f = File.createTempFile(prefix, suffix, dir);
f.delete();
f.mkdir();
return f.getName();
}
}));
} catch (IOException e) {
throw new IOException2("Failed to create a temp directory on " + remote, e);
}
}
use of hudson.util.IOException2 in project hudson-2.x by hudson.
the class AnnotatedLargeText method createAnnotator.
private ConsoleAnnotator createAnnotator(StaplerRequest req) throws IOException {
try {
String base64 = req != null ? req.getHeader("X-ConsoleAnnotator") : null;
if (base64 != null) {
Cipher sym = Secret.getCipher("AES");
sym.init(Cipher.DECRYPT_MODE, Hudson.getInstance().getSecretKeyAsAES128());
ObjectInputStream ois = new ObjectInputStreamEx(new GZIPInputStream(new CipherInputStream(new ByteArrayInputStream(Base64.decode(base64.toCharArray())), sym)), Hudson.getInstance().pluginManager.uberClassLoader);
long timestamp = ois.readLong();
if (TimeUnit2.HOURS.toMillis(1) > abs(System.currentTimeMillis() - timestamp))
// don't deserialize something too old to prevent a replay attack
return (ConsoleAnnotator) ois.readObject();
}
} catch (GeneralSecurityException e) {
throw new IOException2(e);
} catch (ClassNotFoundException e) {
throw new IOException2(e);
}
// start from scratch
return ConsoleAnnotator.initial(context == null ? null : context.getClass());
}
use of hudson.util.IOException2 in project hudson-2.x by hudson.
the class ClassicPluginStrategy method load.
public void load(PluginWrapper wrapper) throws IOException {
// override the context classloader so that XStream activity in plugin.start()
// will be able to resolve classes in this plugin
ClassLoader old = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(wrapper.classLoader);
try {
String className = wrapper.getPluginClass();
if (className == null) {
// use the default dummy instance
wrapper.setPlugin(new DummyImpl());
} else {
try {
Class clazz = wrapper.classLoader.loadClass(className);
Object o = clazz.newInstance();
if (!(o instanceof Plugin)) {
throw new IOException(className + " doesn't extend from hudson.Plugin");
}
wrapper.setPlugin((Plugin) o);
} catch (LinkageError e) {
throw new IOException2("Unable to load " + className + " from " + wrapper.getShortName(), e);
} catch (ClassNotFoundException e) {
throw new IOException2("Unable to load " + className + " from " + wrapper.getShortName(), e);
} catch (IllegalAccessException e) {
throw new IOException2("Unable to create instance of " + className + " from " + wrapper.getShortName(), e);
} catch (InstantiationException e) {
throw new IOException2("Unable to create instance of " + className + " from " + wrapper.getShortName(), e);
}
}
// initialize plugin
try {
Plugin plugin = wrapper.getPlugin();
plugin.setServletContext(pluginManager.context);
startPlugin(wrapper);
} catch (Throwable t) {
// gracefully handle any error in plugin.
throw new IOException2("Failed to initialize", t);
}
} finally {
Thread.currentThread().setContextClassLoader(old);
}
}
use of hudson.util.IOException2 in project hudson-2.x by hudson.
the class ClassicPluginStrategy method explode.
/**
* Explodes the plugin into a directory, if necessary.
*/
private static void explode(File archive, File destDir) throws IOException {
if (!destDir.exists())
destDir.mkdirs();
// timestamp check
File explodeTime = new File(destDir, ".timestamp");
if (explodeTime.exists() && explodeTime.lastModified() == archive.lastModified())
// no need to expand
return;
// delete the contents so that old files won't interfere with new files
Util.deleteContentsRecursive(destDir);
try {
Expand e = new Expand();
e.setProject(new Project());
e.setTaskType("unzip");
e.setSrc(archive);
e.setDest(destDir);
e.execute();
} catch (BuildException x) {
throw new IOException2("Failed to expand " + archive, x);
}
try {
new FilePath(explodeTime).touch(archive.lastModified());
} catch (InterruptedException e) {
// impossible
throw new AssertionError(e);
}
}
Aggregations