Search in sources :

Example 16 with IOException2

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);
        }
    }
}
Also used : HtmlImage(com.gargoylesoftware.htmlunit.html.HtmlImage) UserCause(hudson.model.Cause.UserCause) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) FreeStyleBuild(hudson.model.FreeStyleBuild) IOException(java.io.IOException) FreeStyleProject(hudson.model.FreeStyleProject) IOException2(hudson.util.IOException2)

Example 17 with IOException2

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);
    }
}
Also used : IOException2(hudson.util.IOException2) IOException(java.io.IOException) Plugin(hudson.Plugin)

Example 18 with IOException2

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);
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) UnbufferedBase64InputStream(hudson.util.UnbufferedBase64InputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInputStreamEx(hudson.remoting.ObjectInputStreamEx) DataInputStream(java.io.DataInputStream) IOException2(hudson.util.IOException2) ObjectInputStream(java.io.ObjectInputStream)

Example 19 with IOException2

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());
    }
}
Also used : FilePath(hudson.FilePath) Serializable(java.io.Serializable) Fingerprint(hudson.model.Fingerprint) AbstractBuild(hudson.model.AbstractBuild) FileSet(org.apache.tools.ant.types.FileSet) VirtualChannel(hudson.remoting.VirtualChannel) IOException(java.io.IOException) FingerprintMap(hudson.model.FingerprintMap) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) IOException2(hudson.util.IOException2)

Example 20 with IOException2

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);
    }
}
Also used : IOException(java.io.IOException) File(java.io.File) IOException2(hudson.util.IOException2)

Aggregations

IOException2 (hudson.util.IOException2)37 IOException (java.io.IOException)20 File (java.io.File)16 FileInputStream (java.io.FileInputStream)10 DocumentBuilder (javax.xml.parsers.DocumentBuilder)5 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)5 InputStream (java.io.InputStream)4 ObjectInputStream (java.io.ObjectInputStream)4 GZIPInputStream (java.util.zip.GZIPInputStream)4 TarInputStream (hudson.org.apache.tools.tar.TarInputStream)3 VirtualChannel (hudson.remoting.VirtualChannel)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3 Document (org.w3c.dom.Document)3 Element (org.w3c.dom.Element)3 NodeList (org.w3c.dom.NodeList)3 SAXException (org.xml.sax.SAXException)3 XmlPullParser (org.xmlpull.v1.XmlPullParser)3 XmlPullParserFactory (org.xmlpull.v1.XmlPullParserFactory)3 StreamException (com.thoughtworks.xstream.io.StreamException)2 ObjectInputStreamEx (hudson.remoting.ObjectInputStreamEx)2