use of hudson.util.IOException2 in project promoted-builds-plugin by jenkinsci.
the class PromotedBuildActionTest method testDeletedPromotionProcess.
public void testDeletedPromotionProcess() throws Exception {
FreeStyleProject p = createFreeStyleProject();
JobPropertyImpl base = new JobPropertyImpl(p);
p.addProperty(base);
PromotionProcess foo = base.addProcess("foo");
// promote a build
FreeStyleBuild b1 = assertBuildStatusSuccess(p.scheduleBuild2(0));
foo.promote(b1, new UserCause(), new ManualPromotionBadge());
// now delete the promotion process
p.removeProperty(base);
p.addProperty(base = new JobPropertyImpl(p));
assertTrue(base.getActiveItems().isEmpty());
// make sure that the page renders OK without any error
HtmlPage page = createWebClient().getPage(p);
List<?> candidates = page.getByXPath("//IMG");
for (Object candidate : candidates) {
if (!(candidate instanceof HtmlImage)) {
continue;
}
HtmlImage img = (HtmlImage) candidate;
try {
img.getHeight();
} catch (IOException e) {
throw new IOException2("Failed to load " + img.getSrcAttribute(), e);
}
}
}
use of hudson.util.IOException2 in project hudson-2.x by hudson.
the class SmoothiePluginStrategy method load.
/**
* Loads the optional {@link hudson.Plugin} instance, configures and starts it.
*/
public void load(final PluginWrapper plugin) throws IOException {
checkNotNull(plugin);
if (log.isDebugEnabled()) {
log.debug("Configuring plugin: {}", plugin.getShortName());
}
container.register(plugin);
ClassLoader old = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(plugin.classLoader);
try {
Plugin instance;
// Load the plugin instance, if one has been configured.
if (plugin.getPluginClass() == null) {
instance = new Plugin.DummyImpl();
} else {
try {
// Ask the container to construct the instance
Class<? extends Plugin> type = loadPluginClass(plugin);
instance = container.injector(plugin).getInstance(type);
log.trace("Plugin instance: {}", instance);
} catch (Throwable e) {
throw new IOException2("Failed to load plugin instance for: " + plugin.getShortName(), e);
}
}
plugin.setPlugin(instance);
try {
start(plugin);
} catch (Exception e) {
throw new IOException2("Failed to start plugin: " + plugin.getShortName(), e);
}
} finally {
Thread.currentThread().setContextClassLoader(old);
}
}
use of hudson.util.IOException2 in project hudson-2.x by hudson.
the class ConsoleNote method readFrom.
/**
* Reads a note back from {@linkplain #encodeTo(OutputStream) its encoded form}.
*
* @param in
* Must point to the beginning of a preamble.
*
* @return null if the encoded form is malformed.
*/
public static ConsoleNote readFrom(DataInputStream in) throws IOException, ClassNotFoundException {
try {
byte[] preamble = new byte[PREAMBLE.length];
in.readFully(preamble);
if (!Arrays.equals(preamble, PREAMBLE))
// not a valid preamble
return null;
DataInputStream decoded = new DataInputStream(new UnbufferedBase64InputStream(in));
int sz = decoded.readInt();
//Size should be greater than Zero. See http://issues.hudson-ci.org/browse/HUDSON-6558
if (sz < 0) {
return null;
}
byte[] buf = new byte[sz];
decoded.readFully(buf);
byte[] postamble = new byte[POSTAMBLE.length];
in.readFully(postamble);
if (!Arrays.equals(postamble, POSTAMBLE))
// not a valid postamble
return null;
ObjectInputStream ois = new ObjectInputStreamEx(new GZIPInputStream(new ByteArrayInputStream(buf)), Hudson.getInstance().pluginManager.uberClassLoader);
return (ConsoleNote) ois.readObject();
} catch (Error e) {
// package that up as IOException so that the caller won't fatally die.
throw new IOException2(e);
}
}
use of hudson.util.IOException2 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());
}
}
use of hudson.util.IOException2 in project hudson-2.x by hudson.
the class TemporaryDirectoryAllocator method allocate.
/**
* Allocates a new empty temporary directory and returns it.
*
* This directory will be wiped out when {@link TemporaryDirectoryAllocator} gets disposed.
* When this method returns, the directory already exists.
*/
public synchronized File allocate() throws IOException {
try {
File f = File.createTempFile("hudson", "test", base);
f.delete();
f.mkdirs();
tmpDirectories.add(f);
return f;
} catch (IOException e) {
throw new IOException2("Failed to create a temporary directory in " + base, e);
}
}
Aggregations