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);
    }
  public String runCommand(String com) {
    StringBuffer output = new StringBuffer();
    Process p;
    String line = "";

    try {
      p = Runtime.getRuntime().exec(com);
      p.waitFor();
      BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
      while ((reader.readLine()) != null) {
        output.append(line = reader.readLine() + "\n");
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    return output.toString();
  }
 @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);
     }
 }