Search in sources :

Example 1 with IgnoreJRERequirement

use of org.jvnet.animal_sniffer.IgnoreJRERequirement in project hudson-2.x by hudson.

the class Util method makeWritable.

/**
     * Makes the given file writable by any means possible.
     */
@IgnoreJRERequirement
private static void makeWritable(File f) {
    // try chmod. this becomes no-op if this is not Unix.
    try {
        Chmod chmod = new Chmod();
        chmod.setProject(new Project());
        chmod.setFile(f);
        chmod.setPerm("u+w");
        chmod.execute();
    } catch (BuildException e) {
        LOGGER.log(Level.INFO, "Failed to chmod " + f, e);
    }
    // also try JDK6-way of doing it.
    try {
        f.setWritable(true);
    } catch (NoSuchMethodError e) {
    // not JDK6
    }
    try {
        // try libc chmod
        POSIX posix = PosixAPI.get();
        String path = f.getAbsolutePath();
        FileStat stat = posix.stat(path);
        // u+w
        posix.chmod(path, stat.mode() | 0200);
    } catch (Throwable t) {
        LOGGER.log(Level.FINE, "Failed to chmod(2) " + f, t);
    }
}
Also used : Project(org.apache.tools.ant.Project) FileStat(org.jruby.ext.posix.FileStat) BuildException(org.apache.tools.ant.BuildException) Chmod(org.apache.tools.ant.taskdefs.Chmod) POSIX(org.jruby.ext.posix.POSIX) IgnoreJRERequirement(org.jvnet.animal_sniffer.IgnoreJRERequirement)

Example 2 with IgnoreJRERequirement

use of org.jvnet.animal_sniffer.IgnoreJRERequirement in project hudson-2.x by hudson.

the class Functions method dumpThreadInfo.

// ThreadInfo.toString() truncates the stack trace by first 8, so needed my own version
@IgnoreJRERequirement
public static String dumpThreadInfo(ThreadInfo ti, ThreadGroupMap map) {
    String grp = map.getThreadGroup(ti);
    StringBuilder sb = new StringBuilder("\"" + ti.getThreadName() + "\"" + " Id=" + ti.getThreadId() + " Group=" + (grp != null ? grp : "?") + " " + ti.getThreadState());
    if (ti.getLockName() != null) {
        sb.append(" on " + ti.getLockName());
    }
    if (ti.getLockOwnerName() != null) {
        sb.append(" owned by \"" + ti.getLockOwnerName() + "\" Id=" + ti.getLockOwnerId());
    }
    if (ti.isSuspended()) {
        sb.append(" (suspended)");
    }
    if (ti.isInNative()) {
        sb.append(" (in native)");
    }
    sb.append('\n');
    StackTraceElement[] stackTrace = ti.getStackTrace();
    for (int i = 0; i < stackTrace.length; i++) {
        StackTraceElement ste = stackTrace[i];
        sb.append("\tat " + ste.toString());
        sb.append('\n');
        if (i == 0 && ti.getLockInfo() != null) {
            Thread.State ts = ti.getThreadState();
            switch(ts) {
                case BLOCKED:
                    sb.append("\t-  blocked on " + ti.getLockInfo());
                    sb.append('\n');
                    break;
                case WAITING:
                    sb.append("\t-  waiting on " + ti.getLockInfo());
                    sb.append('\n');
                    break;
                case TIMED_WAITING:
                    sb.append("\t-  waiting on " + ti.getLockInfo());
                    sb.append('\n');
                    break;
                default:
            }
        }
        for (MonitorInfo mi : ti.getLockedMonitors()) {
            if (mi.getLockedStackDepth() == i) {
                sb.append("\t-  locked " + mi);
                sb.append('\n');
            }
        }
    }
    LockInfo[] locks = ti.getLockedSynchronizers();
    if (locks.length > 0) {
        sb.append("\n\tNumber of locked synchronizers = " + locks.length);
        sb.append('\n');
        for (LockInfo li : locks) {
            sb.append("\t- " + li);
            sb.append('\n');
        }
    }
    sb.append('\n');
    return sb.toString();
}
Also used : MonitorInfo(java.lang.management.MonitorInfo) LockInfo(java.lang.management.LockInfo) IgnoreJRERequirement(org.jvnet.animal_sniffer.IgnoreJRERequirement)

Example 3 with IgnoreJRERequirement

use of org.jvnet.animal_sniffer.IgnoreJRERequirement in project hudson-2.x by hudson.

the class ExternalRun method acceptRemoteSubmission.

/**
     * Instead of performing a build, accept the log and the return code
     * from a remote machine.
     *
     * <p>
     * The format of the XML is:
     *
     * <pre><xmp>
     * <run>
     *  <log>...console output...</log>
     *  <result>exit code</result>
     * </run>
     * </xmp></pre>
     */
@SuppressWarnings({ "Since15" })
@IgnoreJRERequirement
public void acceptRemoteSubmission(final Reader in) throws IOException {
    final long[] duration = new long[1];
    run(new Runner() {

        private String elementText(XMLStreamReader r) throws XMLStreamException {
            StringBuilder buf = new StringBuilder();
            while (true) {
                int type = r.next();
                if (type == CHARACTERS || type == CDATA)
                    buf.append(r.getTextCharacters(), r.getTextStart(), r.getTextLength());
                else
                    return buf.toString();
            }
        }

        public Result run(BuildListener listener) throws Exception {
            PrintStream logger = new PrintStream(new DecodingStream(listener.getLogger()));
            XMLInputFactory xif = XMLInputFactory.newInstance();
            XMLStreamReader p = xif.createXMLStreamReader(in);
            // get to the <run>
            p.nextTag();
            // get to the <log>
            p.nextTag();
            charset = p.getAttributeValue(null, "content-encoding");
            while (p.next() != END_ELEMENT) {
                int type = p.getEventType();
                if (type == CHARACTERS || type == CDATA)
                    logger.print(p.getText());
            }
            // get to <result>
            p.nextTag();
            Result r = Integer.parseInt(elementText(p)) == 0 ? Result.SUCCESS : Result.FAILURE;
            // get to <duration> (optional)
            p.nextTag();
            if (p.getEventType() == START_ELEMENT && p.getLocalName().equals("duration")) {
                duration[0] = Long.parseLong(elementText(p));
            }
            return r;
        }

        public void post(BuildListener listener) {
        // do nothing
        }

        public void cleanUp(BuildListener listener) {
        // do nothing
        }
    });
    if (duration[0] != 0) {
        super.duration = duration[0];
        // save the updated duration
        save();
    }
}
Also used : PrintStream(java.io.PrintStream) XMLStreamReader(javax.xml.stream.XMLStreamReader) XMLStreamException(javax.xml.stream.XMLStreamException) DecodingStream(hudson.util.DecodingStream) XMLStreamException(javax.xml.stream.XMLStreamException) IOException(java.io.IOException) XMLInputFactory(javax.xml.stream.XMLInputFactory) IgnoreJRERequirement(org.jvnet.animal_sniffer.IgnoreJRERequirement)

Aggregations

IgnoreJRERequirement (org.jvnet.animal_sniffer.IgnoreJRERequirement)3 DecodingStream (hudson.util.DecodingStream)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 LockInfo (java.lang.management.LockInfo)1 MonitorInfo (java.lang.management.MonitorInfo)1 XMLInputFactory (javax.xml.stream.XMLInputFactory)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1 BuildException (org.apache.tools.ant.BuildException)1 Project (org.apache.tools.ant.Project)1 Chmod (org.apache.tools.ant.taskdefs.Chmod)1 FileStat (org.jruby.ext.posix.FileStat)1 POSIX (org.jruby.ext.posix.POSIX)1