+++ /dev/null
-/*\r
- * \r
- * Copyright 2002-2006 The Ant-Contrib project\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package net.sf.antcontrib.cpptasks.userdefine;\r
-\r
-import java.io.BufferedReader;\r
-import java.io.File;\r
-import java.io.FileReader;\r
-import java.util.Iterator;\r
-import java.util.LinkedHashSet;\r
-import java.util.Set;\r
-import java.util.Vector;\r
-\r
-import org.apache.tools.ant.BuildException;\r
-import org.apache.tools.ant.Project;\r
-\r
-import net.sf.antcontrib.cpptasks.ProcessorDef;\r
-import net.sf.antcontrib.cpptasks.types.ConditionalPath;\r
-import net.sf.antcontrib.cpptasks.types.IncludePath;\r
-import net.sf.antcontrib.cpptasks.types.LibrarySet;\r
-\r
-/**\r
- * A userdefinedef definition. userdefine elements may be placed either as\r
- * children of a cc element or the project element. A userdefine element with an\r
- * id attribute may be referenced by userdefine elements with refid or extends\r
- * attributes.\r
- * \r
- */\r
-public class UserDefineDef extends ProcessorDef {\r
-\r
- public UserDefineDef () {\r
- }\r
-\r
- private String type = "CC";\r
-\r
- private String family = "MSFT";\r
-\r
- private String cmd;\r
-\r
- private String includePathDelimiter;\r
-\r
- private String outputDelimiter;\r
-\r
- private File workdir;\r
-\r
- private Vector includePaths = new Vector();\r
-\r
- private String outputFile;\r
-\r
- private Vector allLibraries = new Vector();\r
- \r
- private String dpath = null;\r
- \r
- private String libpath = null;\r
- \r
- private String include = null;\r
-\r
- public void addLibset(LibrarySet libset) {\r
- if (isReference()) {\r
- throw noChildrenAllowed();\r
- }\r
- if (libset == null) {\r
- throw new NullPointerException("libset");\r
- }\r
-\r
- allLibraries.add(libset);\r
- }\r
-\r
- public void execute() throws org.apache.tools.ant.BuildException {\r
- throw new org.apache.tools.ant.BuildException(\r
- "Not an actual task, but looks like one for documentation purposes");\r
- }\r
-\r
- public void addConfiguredArgument(UserDefineArgument arg) {\r
- if (isReference()) {\r
- throw noChildrenAllowed();\r
- }\r
- addConfiguredProcessorArg(arg);\r
- }\r
-\r
- /**\r
- * Creates an include path.\r
- */\r
- public IncludePath createIncludePath() {\r
- Project p = getProject();\r
- if (isReference()) {\r
- throw noChildrenAllowed();\r
- }\r
- IncludePath path = new IncludePath(p);\r
- includePaths.addElement(path);\r
- return path;\r
- }\r
-\r
- /**\r
- * Add a <includepath> if specify the file attribute\r
- * \r
- * @param activePath\r
- * Active Path Vector\r
- * @param file\r
- * File with multiple path\r
- * @throws BuildException\r
- * if the specify file not exist\r
- */\r
- protected void loadFile(Vector activePath, File file) throws BuildException {\r
- FileReader fileReader;\r
- BufferedReader in;\r
- String str;\r
- if (!file.exists()) {\r
- throw new BuildException("The file " + file + " is not existed");\r
- }\r
- try {\r
- fileReader = new FileReader(file);\r
- in = new BufferedReader(fileReader);\r
- while ((str = in.readLine()) != null) {\r
- if (str.trim().endsWith("")) {\r
- continue;\r
- }\r
- str = getProject().replaceProperties(str);\r
- activePath.addElement(str.trim());\r
- }\r
- } catch (Exception e) {\r
- throw new BuildException(e.getMessage());\r
- }\r
- }\r
-\r
- /**\r
- * Returns the specific include path.\r
- * \r
- * @return All active include paths\r
- */\r
- public String[] getActiveIncludePaths() {\r
- if (isReference()) {\r
- return ((UserDefineDef) getCheckedRef(UserDefineDef.class,\r
- "UserDefineDef")).getActiveIncludePaths();\r
- }\r
- return getActivePaths(includePaths);\r
- }\r
-\r
- private String[] getActivePaths(Vector paths) {\r
- Project p = getProject();\r
- Vector activePaths = new Vector(paths.size());\r
- int length = paths.size();\r
- for (int i = 0; i < length; i++) {\r
- ConditionalPath path = (ConditionalPath) paths.elementAt(i);\r
- if (path.isActive(p)) {\r
- if (path.getFile() == null) {\r
- String[] pathEntries = path.list();\r
- for (int j = 0; j < pathEntries.length; j++) {\r
- activePaths.addElement(pathEntries[j]);\r
- }\r
- } else {\r
- loadFile(activePaths, path.getFile());\r
- }\r
- }\r
- }\r
- String[] pathNames = new String[activePaths.size()];\r
- activePaths.copyInto(pathNames);\r
- return pathNames;\r
- }\r
-\r
- /**\r
- * Get include path delimiter.\r
- * \r
- * @return Include Path Delimiter\r
- */\r
- public String getIncludePathDelimiter() {\r
- if (isReference()) {\r
- return ((UserDefineDef) getCheckedRef(UserDefineDef.class,\r
- "UserDefineDef")).getIncludePathDelimiter();\r
- }\r
- return includePathDelimiter;\r
- }\r
-\r
- /**\r
- * Set include path delimiter.\r
- * \r
- * @param includePathDelimiter\r
- * include path delimiter\r
- */\r
- public void setIncludePathDelimiter(String includePathDelimiter) {\r
- if (isReference()) {\r
- throw tooManyAttributes();\r
- }\r
- this.includePathDelimiter = includePathDelimiter;\r
- }\r
-\r
- /**\r
- * Get type.\r
- * \r
- * @return type\r
- */\r
- public String getType() {\r
- if (isReference()) {\r
- return ((UserDefineDef) getCheckedRef(UserDefineDef.class,\r
- "UserDefineDef")).getType();\r
- }\r
- return type;\r
- }\r
-\r
- /**\r
- * Set type.\r
- * \r
- * @param type\r
- * Type\r
- */\r
- public void setType(String type) {\r
- if (isReference()) {\r
- throw tooManyAttributes();\r
- }\r
- this.type = type;\r
- }\r
-\r
- public String getCmd() {\r
- return cmd;\r
- }\r
-\r
- public void setCmd(String cmd) {\r
- if (isReference()) {\r
- throw tooManyAttributes();\r
- }\r
- if (cmd == null || cmd.trim().length() == 0) {\r
- throw new BuildException("cmd attribute is empty!");\r
- }\r
- File cmdProgram = new File(cmd);\r
- if (cmdProgram.isDirectory()) {\r
- throw new BuildException(cmd + " is not valid or executable!");\r
- }\r
- this.cmd = cmd;\r
- }\r
-\r
- public String getFamily() {\r
- return family;\r
- }\r
-\r
- public void setFamily(String family) {\r
- if (isReference()) {\r
- throw tooManyAttributes();\r
- }\r
- this.family = family;\r
- }\r
-\r
- public String getOutputFile() {\r
- return outputFile;\r
- }\r
-\r
- public void setOutputFile(String outputFile) {\r
- if (isReference()) {\r
- throw tooManyAttributes();\r
- }\r
- this.outputFile = outputFile;\r
- }\r
-\r
- public File getWorkdir() {\r
- return workdir;\r
- }\r
-\r
- public void setWorkdir(File workdir) {\r
- if (isReference()) {\r
- throw tooManyAttributes();\r
- }\r
- this.workdir = workdir;\r
- }\r
-\r
- public String[] getLibset() {\r
- Set libs = new LinkedHashSet();\r
- Iterator iter = allLibraries.iterator();\r
- while (iter.hasNext()) {\r
- LibrarySet librarySet = (LibrarySet) iter.next();\r
- File basedir = librarySet.getDir(getProject());\r
- String[] libStrArray = librarySet.getLibs();\r
- for (int i = 0; i < libStrArray.length; i++) {\r
- if (basedir != null) {\r
- File libFile = new File(libStrArray[i]);\r
- if (libFile.isAbsolute()) {\r
- libs.add(libFile.getPath());\r
- } else {\r
- libs.add(basedir.getPath() + File.separatorChar\r
- + libFile.getPath());\r
- }\r
- } else {\r
- libs.add(libStrArray[i]);\r
- }\r
- }\r
- }\r
- return (String[]) libs.toArray(new String[libs.size()]);\r
- }\r
-\r
- public String getOutputDelimiter() {\r
- return outputDelimiter;\r
- }\r
-\r
- public void setOutputDelimiter(String outputDelimiter) {\r
- this.outputDelimiter = outputDelimiter;\r
- }\r
-\r
- public String getDpath() {\r
- return dpath;\r
- }\r
-\r
- public void setDpath(String dpath) {\r
- this.dpath = dpath;\r
- }\r
-\r
- public String getLibpath() {\r
- return libpath;\r
- }\r
-\r
- public void setLibpath(String libpath) {\r
- this.libpath = libpath;\r
- }\r
-\r
- public String getInclude() {\r
- return include;\r
- }\r
-\r
- public void setInclude(String include) {\r
- this.include = include;\r
- }\r
-\r
-}\r