Exemplo n.º 1
0
 private void inicializaLabirinto() {
   salas = new Sala[50];
   salas[0] = new Sala();
   countSalas = 1;
   try {
     leLabirinto(new Scanner(new FileInputStream("labirinto.txt")));
   } catch (Exception e) {
     err.println(e.getMessage());
     exit(1);
   }
 }
    private void diagnoseFailedLoad(Exception cause) {
        Process proc = process.getProcess();

        try {
            int val = proc.exitValue();
            new RuntimeException("Jenkins died loading. Exit code " + val, cause);
        } catch (IllegalThreadStateException _) {
            // Process alive
        }

        // Try to get stacktrace
        Class<?> clazz;
        Field pidField;
        try {
            clazz = Class.forName("java.lang.UNIXProcess");
            pidField = clazz.getDeclaredField("pid");
            pidField.setAccessible(true);
        } catch (Exception e) {
            LinkageError x = new LinkageError();
            x.initCause(e);
            throw x;
        }

        if (clazz.isAssignableFrom(proc.getClass())) {
            int pid;
            try {
                pid = (int) pidField.get(proc);
            } catch (IllegalArgumentException | IllegalAccessException e) {
                throw new AssertionError(e);
            }

            try {
                Process jstack = new ProcessBuilder("jstack", String.valueOf(pid)).start();
                if (jstack.waitFor() == 0) {
                    StringWriter writer = new StringWriter();
                    IOUtils.copy(jstack.getInputStream(), writer);
                    RuntimeException ex = new RuntimeException(
                            cause.getMessage() + "\n\n" + writer.toString()
                    );
                    ex.setStackTrace(cause.getStackTrace());
                    throw ex;
                }
            } catch (IOException | InterruptedException e) {
                throw new AssertionError(e);
            }
        }

        throw new Error(cause);
    }
 @Override
 public void populateJenkinsHome(byte[] _template, boolean clean) throws IOException {
     try {
         if (clean && tempDir.isDirectory()) {
             FileUtils.cleanDirectory(tempDir);
         }
         if (!tempDir.isDirectory() && ! tempDir.mkdirs()) {
             throw new IOException("Could not create directory: " + tempDir);
         }
         File template = File.createTempFile("template", ".dat");
         try {
             FileUtils.writeByteArrayToFile(template, _template);
             Expand expand = new Expand();
             expand.setSrc(template);
             expand.setOverwrite(true);
             expand.setDest(tempDir);
             expand.execute();
         } finally {
             template.delete();
         }
     } catch (Exception e) {
         throw new IOException(e.getMessage(), e);
     }
 }