📄 dotnetcompile.java
字号:
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * *//* * build notes * -The reference CD to listen to while editing this file is * nap:Cream+Live+2001+CD+2 */// place in the optional ant tasks package// but in its own dotnet grouppackage org.apache.tools.ant.taskdefs.optional.dotnet;// importsimport java.io.File;import java.util.Vector;import java.util.Enumeration;import java.util.Hashtable;import org.apache.tools.ant.BuildException;import org.apache.tools.ant.Project;import org.apache.tools.ant.types.Commandline;import org.apache.tools.ant.types.Path;import org.apache.tools.ant.types.FileSet;import org.apache.tools.ant.types.EnumeratedAttribute;/** * Abstract superclass for dotnet compiler tasks. * * History * <table> * <tr> * <td> * 0.1 * </td> * <td> * First creation * </td> * <td> * Most of the code here was copied verbatim from v0.3 of * Steve Loughran's CSharp optional task. Abstracted functionality * to allow subclassing of other dotnet compiler types. * </td> * </tr> * * </table> * * * @version 0.1 */public abstract class DotnetCompile extends DotnetBaseMatchingTask { private static final int DEFAULT_WARN_LEVEL = 3; /** * list of reference classes. (pretty much a classpath equivalent) */ private String references; /** * flag to enable automatic reference inclusion */ private boolean includeDefaultReferences = true; /** * icon for incorporation into apps */ private File win32icon; /** * icon for incorporation into apps */ private File win32res; /** * flag to control action on execution trouble */ private boolean failOnError; /** * using the path approach didn't work as it could not handle the implicit * execution path. Perhaps that could be extracted from the runtime and * then the path approach would be viable */ private Path referenceFiles; /** * optimise flag */ private boolean optimize; // CheckStyle:VisibilityModifier OFF - bc /** * a list of definitions to support; */ protected Vector definitionList = new Vector(); /** * our resources */ protected Vector resources = new Vector(); /** * executable */ protected String executable; protected static final String REFERENCE_OPTION = "/reference:"; /** * debug flag. Controls generation of debug information. */ protected boolean debug; /** * warning level: 0-4, with 4 being most verbose */ private int warnLevel; /** * main class (or null for automatic choice) */ protected String mainClass; /** * any extra command options? */ protected String extraOptions; /** * type of target. Should be one of exe|library|module|winexe|(null) * default is exe; the actual value (if not null) is fed to the command * line. <br> * See /target */ protected String targetType; /** * utf out flag */ protected boolean utf8output = false; /** * list of extra modules to refer to */ protected String additionalModules; /** * filesets of references */ protected Vector referenceFilesets = new Vector(); /** * flag to set to to use @file based command cache */ private boolean useResponseFile = false; private static final int AUTOMATIC_RESPONSE_FILE_THRESHOLD = 64; // CheckStyle:VisibilityModifier ON /** * constructor inits everything and set up the search pattern */ public DotnetCompile() { clear(); setIncludes(getFilePattern()); } /** * reset all contents. */ public void clear() { targetType = null; win32icon = null; srcDir = null; mainClass = null; warnLevel = DEFAULT_WARN_LEVEL; optimize = false; debug = true; references = null; failOnError = true; additionalModules = null; includeDefaultReferences = true; extraOptions = null; } /** * Semicolon separated list of DLLs to refer to. * *@param s The new References value */ public void setReferences(String s) { references = s; } /** * get the reference string or null for no argument needed * *@return The References Parameter to CSC */ protected String getReferencesParameter() { //bail on no references if (notEmpty(references)) { if (isWindows) { return '\"' + REFERENCE_OPTION + references + '\"'; } else { return REFERENCE_OPTION + references; } } else { return null; } } /** * Path of references to include. * Wildcards should work. * *@param path another path to append */ public void setReferenceFiles(Path path) { //demand create pathlist if (referenceFiles == null) { referenceFiles = new Path(this.getProject()); } referenceFiles.append(path); } /** * add a new reference fileset to the compilation * @param reference the files to use. */ public void addReference(FileSet reference) { referenceFilesets.add(reference); } /** * turn the path list into a list of files and a /references argument * *@return null or a string of references. */ protected String getReferenceFilesParameter() { //bail on no references if (references == null) { return null; } //iterate through the ref list & generate an entry for each //or just rely on the fact that the toString operator does this, but //noting that the separator is ';' on windows, ':' on unix //bail on no references listed if (references.length() == 0) { return null; } StringBuffer s = new StringBuffer(REFERENCE_OPTION); if (isWindows) { s.append('\"'); } s.append(references); if (isWindows) { s.append('\"'); } return s.toString(); } /** * If true, automatically includes the common assemblies * in dotnet, and tells the compiler to link in mscore.dll. * * set the automatic reference inclusion flag on or off this flag controls * the /nostdlib option in CSC * *@param f on/off flag */ public void setIncludeDefaultReferences(boolean f) { includeDefaultReferences = f; } /** * query automatic reference inclusion flag * *@return true if flag is turned on */ public boolean getIncludeDefaultReferences() { return includeDefaultReferences; } /** * get the include default references flag or null for no argument needed * *@return The Parameter to CSC */ protected String getIncludeDefaultReferencesParameter() { return "/nostdlib" + (includeDefaultReferences ? "-" : "+"); } /** * If true, enables optimization flag. * *@param f on/off flag */ public void setOptimize(boolean f) { optimize = f; } /** * query the optimise flag * *@return true if optimise is turned on */ public boolean getOptimize() { return optimize; } /** * get the optimise flag or null for no argument needed * *@return The Optimize Parameter to CSC */ protected String getOptimizeParameter() { return "/optimize" + (optimize ? "+" : "-"); } /** * set the debug flag on or off. * *@param f on/off flag */ public void setDebug(boolean f) { debug = f; } /** * query the debug flag * *@return true if debug is turned on */ public boolean getDebug() { return debug; } /** * get the debug switch argument * *@return The Debug Parameter to CSC */ protected String getDebugParameter() { return "/debug" + (debug ? "+" : "-"); } /** * Level of warning currently between 1 and 4 * with 4 being the strictest. * *@param warnLevel warn level -see .net docs for valid range (probably * 0-4) */ public void setWarnLevel(int warnLevel) { this.warnLevel = warnLevel; } /** * query warn level * *@return current value */ public int getWarnLevel() { return warnLevel; } /** * get the warn level switch * *@return The WarnLevel Parameter to CSC */ protected String getWarnLevelParameter() { return "/warn:" + warnLevel; } /** * Sets the name of main class for executables. * *@param mainClass The new MainClass value */ public void setMainClass(String mainClass) { this.mainClass = mainClass; } /** * Gets the MainClass attribute * *@return The MainClass value */ public String getMainClass() { return this.mainClass; } /** * get the /main argument or null for no argument needed * *@return The MainClass Parameter to CSC */ protected String getMainClassParameter() { if (mainClass != null && mainClass.length() != 0) { return "/main:" + mainClass; } else { return null; } } /** * Any extra options which are not explicitly supported * by this task. * *@param extraOptions The new ExtraOptions value */ public void setExtraOptions(String extraOptions) { this.extraOptions = extraOptions; } /** * Gets the ExtraOptions attribute * *@return The ExtraOptions value */ public String getExtraOptions() { return this.extraOptions; } /** * get any extra options or null for no argument needed * *@return The ExtraOptions Parameter to CSC */ protected String getExtraOptionsParameter() { if (extraOptions != null && extraOptions.length() != 0) { return extraOptions; } else { return null; } } /** * get any extra options or null for no argument needed, split * them if they represent multiple options. * * @return The ExtraOptions Parameter to CSC */ protected String[] getExtraOptionsParameters() { String extra = getExtraOptionsParameter(); return extra == null ? null : Commandline.translateCommandline(extra); } /**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -