⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 compilerprocess.java

📁 gcc的组建
💻 JAVA
字号:
/*  Copyright (c) 2001, 2003 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version. GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING.  If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library.  Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule.  An independent module is a module which is not derived fromor based on this library.  If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so.  If you do not wish to do so, delete thisexception statement from your version. */package gnu.java.rmi.rmic;import java.io.InputStream;/** * Subclass of Compiler that can be subclassed to invoke a process to * do its work. */public abstract class CompilerProcess extends Compiler{  /** This is used to compute the command line for the process.  */  public abstract String[] computeArguments (String filename);   /**    * This is used to compute the command line for the process.    * Most compilers typically arrange their arguments as in    * <compiler name and arguments> <optional destination> <filename>.    * This method builds an argument array out that. It should be used    * to define computeArguments for those compilers that follow the    * argument convention described above.    */   public static String[] computeTypicalArguments(String[] compilerArgs,	String destination, String filename)   {     /* length of compiler specific arguments */     final int len = compilerArgs.length;     /* length of returned array of arguments */     final int arglen = len + (destination == null ? 0 : 2) + 1;     /* Allocate String array for computed arguments. */     String [] args = new String[arglen];     /* Fill in compiler arguments. */     System.arraycopy(compilerArgs, 0, args, 0, len);     /* Fill in destination argument if necessary. */     if (destination != null)      {	args[len] = "-d";	args[len + 1] = destination;      }     /* Fill in filename */     args[arglen - 1] = filename;     return args;   }  public void compile (String name) throws Exception  {    String[] args = computeArguments (name);    Process p = Runtime.getRuntime ().exec (args);    /* Print compiler output to System.out.  Do this asynchronously so       that the compiler never blocks writing to its stdout.  */    {      final InputStream procin = p.getInputStream();      final Thread copier = new Thread() 	{	  public void run()	  {	    try	      {		for (int ch = procin.read(); ch != -1; ch = procin.read())		  System.out.print((char) ch);	      }	    catch (java.io.IOException _)	      {	      }	  }	};      copier.start();    }    /* Collect compiler error output in a buffer.     * If compilation fails, it will be used for an error message.     */    StringBuffer stderr = new StringBuffer();    InputStream procerr = p.getErrorStream();    for (int ch = procerr.read(); ch != -1; ch = procerr.read())      stderr.append((char) ch);    int result;    while (true)      {	try	  {	    result = p.waitFor ();	    break;	  }	catch (InterruptedException _)	  {	  }      }    if (result != 0)      {	// FIXME: wrong exception class.	throw new Exception ("compiler exited with status: " + result,			     new RMICException(stderr.toString()));      }  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -