Package ch.mtSystems.gcjStubber.model

Examples of ch.mtSystems.gcjStubber.model.CommandExecutor


      cmd.add("-w");
      cmd.add("-O2");
      cmd.add("-C");
      for(File f : listFiles(tmpDir)) cmd.add(f.toString());
 
      CommandExecutor commandExecutor = new CommandExecutor(cmd.toArray(new String[0]), tmpDir);
      commandExecutor.execute();
      if(commandExecutor.getOutput().length > 0 || commandExecutor.getError().length > 0)
      {
        StringBuffer sb = new StringBuffer("Compiling java source files failed:\n");
        for(String s : commandExecutor.getOutput()) { sb.append("   [stdout] "); sb.append(s); sb.append("\n"); }
        for(String s : commandExecutor.getError()) { sb.append("   [stderr] "); sb.append(s); sb.append("\n"); }
        throw new Exception(sb.toString());
      }
 
      // create a jar from the .class files
      ZipOutputStream outputStream = new ZipOutputStream(new FileOutputStream(jar));
      byte[] buffer = new byte[2048];
 
      for(File f : listFiles(tmpDir))
      {
        if(!f.getName().endsWith(".class")) continue;
 
        String entryName = f.toString().substring(tmpDir.toString().length()+1).replaceAll("\\\\", "/");
        ZipEntry zipEntry = new ZipEntry(entryName);
        outputStream.putNextEntry(zipEntry);
 
        InputStream inputStream = new FileInputStream(f);
        while(true)
        {
          int len = inputStream.read(buffer);
          if(len < 0) break;
          outputStream.write(buffer, 0, len);
        }
        inputStream.close();
 
        outputStream.closeEntry();
      }
      outputStream.flush();
      outputStream.close();
     
      // compile the jar to an object
      cmd.clear();
      cmd.add(cmdGcj.toString());
      cmd.add("-s");
      cmd.add("-O2");
      cmd.add("-c");
      cmd.add(jar.toString());
      cmd.add("-o");
      cmd.add(object.toString());
 
      commandExecutor = new CommandExecutor(cmd.toArray(new String[0]), tmpDir);
      commandExecutor.execute();
      if(commandExecutor.getOutput().length > 0 || commandExecutor.getError().length > 0)
      {
        StringBuffer sb = new StringBuffer("Compiling the jar failed:\n");
        for(String s : commandExecutor.getOutput()) { sb.append("   [stdout] "); sb.append(s); sb.append("\n"); }
        for(String s : commandExecutor.getError()) { sb.append("   [stderr] "); sb.append(s); sb.append("\n"); }
        throw new Exception(sb.toString());
      }
    } finally
    {
      // clean up tmp dir
View Full Code Here

TOP

Related Classes of ch.mtSystems.gcjStubber.model.CommandExecutor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.