diff options
author | mattinger <[email protected]> | 2006-11-07 21:16:39 +0000 |
---|---|---|
committer | mattinger <[email protected]> | 2006-11-07 21:16:39 +0000 |
commit | c8da7ec534c959db815f272819dafaf61e49a9bd (patch) | |
tree | 16dfe231dadf33c0829ca23efe8a0021502d99eb /src/net/sf/antcontrib/cpptasks/compiler/AbstractProcessor.java | |
parent | 93d3419f7217a29d266acf2884c6327f1953cb3f (diff) |
Initial import of cpptasks code
git-svn-id: file:///home/sven/projects/JOGL/temp/ant-contrib/svn/ant-contrib-code/trunk/cpptasks@62 32d7a393-a5a9-423c-abd3-5d954feb1f2f
Diffstat (limited to 'src/net/sf/antcontrib/cpptasks/compiler/AbstractProcessor.java')
-rw-r--r-- | src/net/sf/antcontrib/cpptasks/compiler/AbstractProcessor.java | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/src/net/sf/antcontrib/cpptasks/compiler/AbstractProcessor.java b/src/net/sf/antcontrib/cpptasks/compiler/AbstractProcessor.java new file mode 100644 index 0000000..d0cd77b --- /dev/null +++ b/src/net/sf/antcontrib/cpptasks/compiler/AbstractProcessor.java @@ -0,0 +1,129 @@ +/* + * + * Copyright 2002-2004 The Ant-Contrib project + * + * Licensed 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. + */ +package net.sf.antcontrib.cpptasks.compiler; +import org.apache.tools.ant.types.Environment; +/** + * An abstract processor (compiler/linker) implementation. + * + * @author Curt Arnold + */ +public abstract class AbstractProcessor implements Processor, Cloneable { + /** + * default bid for a file name that the processor recognizes but does not + * process and does not want to fall through to the linker + */ + public final static int DEFAULT_DISCARD_BID = 1; + /** + * default bid for a file name that the processor desires to process + */ + public final static int DEFAULT_PROCESS_BID = 100; + /** + * Determines the identification of a command line processor by capture the + * first line of its output for a specific command. + * + * @param command + * array of command line arguments starting with executable + * name. For example, { "cl" } + * @param fallback + * start of identifier if there is an error in executing the + * command + * @return identifier for the processor + */ + protected static String getIdentifier(String[] command, String fallback) { + String identifier = fallback; + try { + String[] cmdout = CaptureStreamHandler.run(command); + if (cmdout.length > 0) { + identifier = cmdout[0]; + } + } catch (Throwable ex) { + identifier = fallback + ":" + ex.toString(); + } + return identifier; + } + private final String[] headerExtensions; + private final String[] sourceExtensions; + protected AbstractProcessor(String[] sourceExtensions, + String[] headerExtensions) { + this.sourceExtensions = (String[]) sourceExtensions.clone(); + this.headerExtensions = (String[]) headerExtensions.clone(); + } + /** + * Returns the bid of the processor for the file. + * + * @param inputFile + * filename of input file + * @return bid for the file, 0 indicates no interest, 1 indicates that the + * processor recognizes the file but doesn't process it (header + * files, for example), 100 indicates strong interest + */ + public int bid(String inputFile) { + String lower = inputFile.toLowerCase(); + for (int i = 0; i < sourceExtensions.length; i++) { + if (lower.endsWith(sourceExtensions[i])) { + return DEFAULT_PROCESS_BID; + } + } + for (int i = 0; i < headerExtensions.length; i++) { + if (lower.endsWith(headerExtensions[i])) { + return DEFAULT_DISCARD_BID; + } + } + return 0; + } + public Processor changeEnvironment(boolean newEnvironment, Environment env) { + return this; + } + protected Object clone() throws CloneNotSupportedException { + return super.clone(); + } + public String[] getHeaderExtensions() { + return (String[]) this.headerExtensions.clone(); + } + abstract public String getIdentifier(); + /** + * Gets the target operating system architecture + * + * @return String target operating system architecture + */ + protected String getOSArch() { + return System.getProperty("os.arch"); + } + /** + * Gets the target operating system name + * + * @return String target operating system name + */ + protected String getOSName() { + return System.getProperty("os.name"); + } + public String[] getSourceExtensions() { + return (String[]) this.sourceExtensions.clone(); + } + /** + * Returns true if the target operating system is Mac OS X or Darwin. + * + * @return boolean + */ + protected boolean isDarwin() { + String osName = getOSName(); + return "Mac OS X".equals(osName); + } + public final String toString() { + return getIdentifier(); + } +} |