summaryrefslogtreecommitdiff
path: root/src/main/java/net/sf/antcontrib/cpptasks/types
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/net/sf/antcontrib/cpptasks/types')
-rw-r--r--src/main/java/net/sf/antcontrib/cpptasks/types/CommandLineArgument.java104
-rw-r--r--src/main/java/net/sf/antcontrib/cpptasks/types/CompilerArgument.java28
-rw-r--r--src/main/java/net/sf/antcontrib/cpptasks/types/ConditionalFileSet.java84
-rw-r--r--src/main/java/net/sf/antcontrib/cpptasks/types/ConditionalPath.java75
-rw-r--r--src/main/java/net/sf/antcontrib/cpptasks/types/DefineArgument.java38
-rw-r--r--src/main/java/net/sf/antcontrib/cpptasks/types/DefineSet.java199
-rw-r--r--src/main/java/net/sf/antcontrib/cpptasks/types/FlexLong.java59
-rw-r--r--src/main/java/net/sf/antcontrib/cpptasks/types/IncludePath.java38
-rw-r--r--src/main/java/net/sf/antcontrib/cpptasks/types/LibrarySet.java347
-rw-r--r--src/main/java/net/sf/antcontrib/cpptasks/types/LibraryTypeEnum.java48
-rw-r--r--src/main/java/net/sf/antcontrib/cpptasks/types/LinkerArgument.java28
-rw-r--r--src/main/java/net/sf/antcontrib/cpptasks/types/SystemIncludePath.java45
-rw-r--r--src/main/java/net/sf/antcontrib/cpptasks/types/SystemLibrarySet.java37
-rw-r--r--src/main/java/net/sf/antcontrib/cpptasks/types/UndefineArgument.java153
14 files changed, 1283 insertions, 0 deletions
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/types/CommandLineArgument.java b/src/main/java/net/sf/antcontrib/cpptasks/types/CommandLineArgument.java
new file mode 100644
index 0000000..e428469
--- /dev/null
+++ b/src/main/java/net/sf/antcontrib/cpptasks/types/CommandLineArgument.java
@@ -0,0 +1,104 @@
+/*
+ *
+ * Copyright 2001-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.types;
+import org.apache.tools.ant.types.EnumeratedAttribute;
+/**
+ * An compiler/linker command line flag.
+ */
+public class CommandLineArgument {
+ /**
+ * Enumerated attribute with the values "start", "mid" and "end",
+ */
+ public static class LocationEnum extends EnumeratedAttribute {
+ public String[] getValues() {
+ return new String[]{"start", "mid", "end"};
+ }
+ }
+ private String ifCond;
+ private int location;
+ private String unlessCond;
+ private String value;
+ public CommandLineArgument() {
+ }
+ public int getLocation() {
+ return location;
+ }
+ public String getValue() {
+ return value;
+ }
+ /**
+ * Returns true if the define's if and unless conditions (if any) are
+ * satisfied.
+ */
+ public boolean isActive(org.apache.tools.ant.Project p) {
+ if (value == null) {
+ return false;
+ }
+ if (ifCond != null && p.getProperty(ifCond) == null) {
+ return false;
+ } else if (unlessCond != null && p.getProperty(unlessCond) != null) {
+ return false;
+ }
+ return true;
+ }
+ /**
+ * Sets the property name for the 'if' condition.
+ *
+ * The argument will be ignored unless the property is defined.
+ *
+ * The value of the property is insignificant, but values that would imply
+ * misinterpretation ("false", "no") will throw an exception when
+ * evaluated.
+ */
+ public void setIf(String propName) {
+ ifCond = propName;
+ }
+ /**
+ * Specifies relative location of argument on command line. "start" will
+ * place argument at start of command line, "mid" will place argument after
+ * all "start" arguments but before filenames, "end" will place argument
+ * after filenames.
+ *
+ */
+ public void setLocation(LocationEnum location) {
+ this.location = location.getIndex();
+ }
+ /**
+ * Set the property name for the 'unless' condition.
+ *
+ * If named property is set, the argument will be ignored.
+ *
+ * The value of the property is insignificant, but values that would imply
+ * misinterpretation ("false", "no") of the behavior will throw an
+ * exception when evaluated.
+ *
+ * @param propName
+ * name of property
+ */
+ public void setUnless(String propName) {
+ unlessCond = propName;
+ }
+ /**
+ * Specifies the string that should appear on the command line. The
+ * argument will be quoted if it contains embedded blanks. Use multiple
+ * arguments to avoid quoting.
+ *
+ */
+ public void setValue(String value) {
+ this.value = value;
+ }
+}
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/types/CompilerArgument.java b/src/main/java/net/sf/antcontrib/cpptasks/types/CompilerArgument.java
new file mode 100644
index 0000000..2137186
--- /dev/null
+++ b/src/main/java/net/sf/antcontrib/cpptasks/types/CompilerArgument.java
@@ -0,0 +1,28 @@
+/*
+ *
+ * Copyright 2001-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.types;
+/**
+ * A compiler command line argument.
+ */
+public class CompilerArgument extends CommandLineArgument {
+ public CompilerArgument() {
+ }
+ public void execute() throws org.apache.tools.ant.BuildException {
+ throw new org.apache.tools.ant.BuildException(
+ "Not an actual task, but looks like one for documentation purposes");
+ }
+}
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/types/ConditionalFileSet.java b/src/main/java/net/sf/antcontrib/cpptasks/types/ConditionalFileSet.java
new file mode 100644
index 0000000..7bc22ee
--- /dev/null
+++ b/src/main/java/net/sf/antcontrib/cpptasks/types/ConditionalFileSet.java
@@ -0,0 +1,84 @@
+/*
+ *
+ * Copyright 2001-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.types;
+import net.sf.antcontrib.cpptasks.CUtil;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.types.AbstractFileSet;
+import org.apache.tools.ant.types.FileSet;
+/**
+ * An Ant FileSet object augmented with if and unless conditions.
+ *
+ * @author Curt Arnold
+ */
+public class ConditionalFileSet extends FileSet {
+ private String ifCond;
+ private String unlessCond;
+ public ConditionalFileSet() {
+ }
+ public void execute() throws org.apache.tools.ant.BuildException {
+ throw new org.apache.tools.ant.BuildException(
+ "Not an actual task, but looks like one for documentation purposes");
+ }
+ /**
+ * overrides FileSet's implementation which would throw an exception since
+ * the referenced object isn't this type.
+ */
+ protected AbstractFileSet getRef(Project p) {
+ return (AbstractFileSet) ref.getReferencedObject(p);
+ }
+ /**
+ * Returns true if the Path's if and unless conditions (if any) are
+ * satisfied.
+ */
+ public boolean isActive() throws BuildException {
+ Project p = getProject();
+ if (p == null) {
+ throw new java.lang.IllegalStateException(
+ "setProject() should have been called");
+ }
+ return CUtil.isActive(p, ifCond, unlessCond);
+ }
+ /**
+ * Sets the property name for the 'if' condition.
+ *
+ * The fileset will be ignored unless the property is defined.
+ *
+ * The value of the property is insignificant, but values that would imply
+ * misinterpretation ("false", "no") will throw an exception when
+ * evaluated.
+ */
+ public void setIf(String propName) {
+ ifCond = propName;
+ }
+ /**
+ * Set the property name for the 'unless' condition.
+ *
+ * If named property is set, the fileset will be ignored.
+ *
+ * The value of the property is insignificant, but values that would imply
+ * misinterpretation ("false", "no") of the behavior will throw an
+ * exception when evaluated.
+ *
+ * @param propName
+ * name of property
+ */
+ public void setUnless(String propName) {
+ unlessCond = propName;
+ }
+}
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/types/ConditionalPath.java b/src/main/java/net/sf/antcontrib/cpptasks/types/ConditionalPath.java
new file mode 100644
index 0000000..ae45eaa
--- /dev/null
+++ b/src/main/java/net/sf/antcontrib/cpptasks/types/ConditionalPath.java
@@ -0,0 +1,75 @@
+/*
+ *
+ * Copyright 2001-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.types;
+import net.sf.antcontrib.cpptasks.CUtil;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.types.Path;
+/**
+ * An Ant Path object augmented with if and unless conditionals
+ *
+ * @author Curt Arnold
+ */
+public class ConditionalPath extends Path {
+ private String ifCond;
+ private String unlessCond;
+ public ConditionalPath(Project project) {
+ super(project);
+ }
+ public ConditionalPath(Project p, String path) {
+ super(p, path);
+ }
+ /**
+ * Returns true if the Path's if and unless conditions (if any) are
+ * satisfied.
+ */
+ public boolean isActive(org.apache.tools.ant.Project p)
+ throws BuildException {
+ return CUtil.isActive(p, ifCond, unlessCond);
+ }
+ /**
+ * Sets the property name for the 'if' condition.
+ *
+ * The path will be ignored unless the property is defined.
+ *
+ * The value of the property is insignificant, but values that would imply
+ * misinterpretation ("false", "no") will throw an exception when
+ * evaluated.
+ *
+ * @param propName
+ * property name
+ */
+ public void setIf(String propName) {
+ ifCond = propName;
+ }
+ /**
+ * Set the property name for the 'unless' condition.
+ *
+ * If named property is set, the path will be ignored.
+ *
+ * The value of the property is insignificant, but values that would imply
+ * misinterpretation ("false", "no") of the behavior will throw an
+ * exception when evaluated.
+ *
+ * @param propName
+ * name of property
+ */
+ public void setUnless(String propName) {
+ unlessCond = propName;
+ }
+}
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/types/DefineArgument.java b/src/main/java/net/sf/antcontrib/cpptasks/types/DefineArgument.java
new file mode 100644
index 0000000..5118e79
--- /dev/null
+++ b/src/main/java/net/sf/antcontrib/cpptasks/types/DefineArgument.java
@@ -0,0 +1,38 @@
+/*
+ *
+ * Copyright 2001-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.types;
+/**
+ * Preprocessor macro definition.
+ *
+ * @author Mark A Russell <a
+ * href="mailto:mark_russell@csgsystems.com">mark_russell@csg_systems.com
+ * </a>
+ */
+public class DefineArgument extends UndefineArgument {
+ private String value;
+ public DefineArgument() {
+ super(true);
+ }
+ /** Returns the value of the define */
+ public final String getValue() {
+ return value;
+ }
+ /** Set the value attribute */
+ public final void setValue(String value) {
+ this.value = value;
+ }
+}
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/types/DefineSet.java b/src/main/java/net/sf/antcontrib/cpptasks/types/DefineSet.java
new file mode 100644
index 0000000..f3ab44b
--- /dev/null
+++ b/src/main/java/net/sf/antcontrib/cpptasks/types/DefineSet.java
@@ -0,0 +1,199 @@
+/*
+ *
+ * Copyright 2001-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.types;
+import java.util.Vector;
+
+import net.sf.antcontrib.cpptasks.CUtil;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.types.DataType;
+import org.apache.tools.ant.types.Reference;
+/**
+ * Set of preprocessor macro defines and undefines.
+ *
+ * @author Mark A Russell <a
+ * href="mailto:mark_russell@csgsystems.com">mark_russell@csg_systems.com
+ * </a>
+ * @author Adam Murdoch
+ */
+public class DefineSet extends DataType {
+ private Vector defineList = new Vector();
+ private String ifCond = null;
+ private String unlessCond = null;
+ /**
+ *
+ * Adds a define element.
+ *
+ * @throws BuildException
+ * if reference
+ */
+ public void addDefine(DefineArgument arg) throws BuildException {
+ if (isReference()) {
+ throw noChildrenAllowed();
+ }
+ defineList.addElement(arg);
+ }
+ /** Adds defines/undefines. */
+ private void addDefines(String[] defs, boolean isDefine) {
+ for (int i = 0; i < defs.length; i++) {
+ UndefineArgument def;
+ if (isDefine) {
+ def = new DefineArgument();
+ } else {
+ def = new UndefineArgument();
+ }
+ def.setName(defs[i]);
+ defineList.addElement(def);
+ }
+ }
+ /**
+ *
+ * Adds an undefine element.
+ *
+ * @throws BuildException
+ * if reference
+ */
+ public void addUndefine(UndefineArgument arg) throws BuildException {
+ if (isReference()) {
+ throw noChildrenAllowed();
+ }
+ defineList.addElement(arg);
+ }
+ public void execute() throws org.apache.tools.ant.BuildException {
+ throw new org.apache.tools.ant.BuildException(
+ "Not an actual task, but looks like one for documentation purposes");
+ }
+ /** Returns the defines and undefines in this set. */
+ public UndefineArgument[] getDefines() throws BuildException {
+ if (isReference()) {
+ DefineSet defset = (DefineSet) getCheckedRef(DefineSet.class,
+ "DefineSet");
+ return defset.getDefines();
+ } else {
+ if (isActive()) {
+ UndefineArgument[] defs = new UndefineArgument[defineList
+ .size()];
+ defineList.copyInto(defs);
+ return defs;
+ } else {
+ return new UndefineArgument[0];
+ }
+ }
+ }
+ /**
+ * Returns true if the define's if and unless conditions (if any) are
+ * satisfied.
+ *
+ * @exception BuildException
+ * throws build exception if name is not set
+ */
+ public final boolean isActive() throws BuildException {
+ return CUtil.isActive(getProject(), ifCond, unlessCond);
+ }
+ /**
+ * A comma-separated list of preprocessor macros to define. Use nested
+ * define elements to define macro values.
+ *
+ * @param defList
+ * comma-separated list of preprocessor macros
+ * @throws BuildException
+ * throw if defineset is a reference
+ */
+ public void setDefine(CUtil.StringArrayBuilder defList)
+ throws BuildException {
+ if (isReference()) {
+ throw tooManyAttributes();
+ }
+ addDefines(defList.getValue(), true);
+ }
+ /**
+ * Sets a description of the current data type.
+ */
+ public void setDescription(String desc) {
+ super.setDescription(desc);
+ }
+ /**
+ * Sets an id that can be used to reference this element.
+ *
+ * @param id
+ * id
+ */
+ public void setId(String id) {
+ //
+ // this is actually accomplished by a different
+ // mechanism, but we can document it
+ //
+ }
+ /**
+ * Sets the property name for the 'if' condition.
+ *
+ * The define will be ignored unless the property is defined.
+ *
+ * The value of the property is insignificant, but values that would imply
+ * misinterpretation ("false", "no") will throw an exception when
+ * evaluated.
+ *
+ * @param propName
+ * property name
+ */
+ public final void setIf(String propName) {
+ ifCond = propName;
+ }
+ /**
+ * Specifies that this element should behave as if the content of the
+ * element with the matching id attribute was inserted at this location. If
+ * specified, no other attributes or child content should be specified,
+ * other than "description".
+ *
+ */
+ public void setRefid(Reference r) throws BuildException {
+ if (!defineList.isEmpty()) {
+ throw tooManyAttributes();
+ }
+ super.setRefid(r);
+ }
+ /**
+ * A comma-separated list of preprocessor macros to undefine.
+ *
+ * @param undefList
+ * comma-separated list of preprocessor macros
+ * @throws BuildException
+ * throw if defineset is a reference
+ */
+ public void setUndefine(CUtil.StringArrayBuilder undefList)
+ throws BuildException {
+ if (isReference()) {
+ throw tooManyAttributes();
+ }
+ addDefines(undefList.getValue(), false);
+ }
+ /**
+ * Set the property name for the 'unless' condition.
+ *
+ * If named property is set, the define will be ignored.
+ *
+ * The value of the property is insignificant, but values that would imply
+ * misinterpretation ("false", "no") of the behavior will throw an
+ * exception when evaluated.
+ *
+ * @param propName
+ * name of property
+ */
+ public final void setUnless(String propName) {
+ unlessCond = propName;
+ }
+}
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/types/FlexLong.java b/src/main/java/net/sf/antcontrib/cpptasks/types/FlexLong.java
new file mode 100644
index 0000000..f710aa3
--- /dev/null
+++ b/src/main/java/net/sf/antcontrib/cpptasks/types/FlexLong.java
@@ -0,0 +1,59 @@
+/*
+ *
+ * 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.types;
+import java.lang.reflect.Method;
+
+/**
+ * Helper class which can be used for Ant task attribute setter methods to
+ * allow the build file to specify a long in either decimal, octal, or
+ * hexadecimal format.
+ * // FlexInteger author
+ * @author Erik Hatcher
+ * @see org.apache.tools.ant.types.FlexInteger
+ */
+public class FlexLong {
+ private Long value;
+ /**
+ * Constructor used by Ant's introspection mechanism for attribute
+ * population
+ */
+ public FlexLong(String value) {
+ // Java 1.1 did not support Long.decode().. so we call it by
+ // reflection.
+ try {
+ Method m = Long.class
+ .getMethod("decode", new Class[]{String.class});
+ Object rc = m.invoke(null, new Object[]{value});
+ this.value = (Long) rc;
+ } catch (Exception e) {
+ // Try it the old fashioned way, we must be on a 1.1 jre
+ this.value = new Long(value);
+ }
+ }
+ /**
+ * Returns the decimal integer value
+ */
+ public long longValue() {
+ return value.longValue();
+ }
+ /**
+ * Overridden method to return the decimal value for display
+ */
+ public String toString() {
+ return value.toString();
+ }
+}
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/types/IncludePath.java b/src/main/java/net/sf/antcontrib/cpptasks/types/IncludePath.java
new file mode 100644
index 0000000..e4c8414
--- /dev/null
+++ b/src/main/java/net/sf/antcontrib/cpptasks/types/IncludePath.java
@@ -0,0 +1,38 @@
+/*
+ *
+ * Copyright 2001-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.types;
+import org.apache.tools.ant.Project;
+/**
+ * An include path.
+ *
+ * Works like other paths in Ant with with the addition of "if" and "unless"
+ * conditions.
+ *
+ * @author Curt Arnold
+ */
+public class IncludePath extends ConditionalPath {
+ public IncludePath(Project project) {
+ super(project);
+ }
+ public IncludePath(Project p, String path) {
+ super(p, path);
+ }
+ public void execute() throws org.apache.tools.ant.BuildException {
+ throw new org.apache.tools.ant.BuildException(
+ "Not an actual task, but looks like one for documentation purposes");
+ }
+}
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/types/LibrarySet.java b/src/main/java/net/sf/antcontrib/cpptasks/types/LibrarySet.java
new file mode 100644
index 0000000..acac911
--- /dev/null
+++ b/src/main/java/net/sf/antcontrib/cpptasks/types/LibrarySet.java
@@ -0,0 +1,347 @@
+/*
+ *
+ * Copyright 2001-2006 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.types;
+import java.io.File;
+
+import net.sf.antcontrib.cpptasks.CUtil;
+import net.sf.antcontrib.cpptasks.FileVisitor;
+import net.sf.antcontrib.cpptasks.compiler.Linker;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.DirectoryScanner;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.types.DataType;
+import org.apache.tools.ant.types.FileSet;
+import org.apache.tools.ant.types.PatternSet;
+/**
+ * A set of library names. Libraries can also be added to a link by specifying
+ * them in a fileset.
+ *
+ * For most Unix-like compilers, libset will result in a series of -l and -L
+ * linker arguments. For Windows compilers, the library names will be used to
+ * locate the appropriate library files which will be added to the linkers
+ * input file list as if they had been specified in a fileset.
+ *
+ * @author Mark A Russell <a
+ * href="mailto:mark_russell@csgsystems.com">mark_russell@csg_systems.com
+ * </a>
+ * @author Adam Murdoch
+ * @author Curt Arnold
+ */
+public class LibrarySet extends DataType {
+ private String dataset;
+ private boolean explicitCaseSensitive;
+ private String ifCond;
+ private String[] libnames;
+ private final FileSet set = new FileSet();
+ private String unlessCond;
+ private LibraryTypeEnum libraryType;
+ public LibrarySet() {
+ libnames = new String[0];
+ }
+ public void execute() throws org.apache.tools.ant.BuildException {
+ throw new org.apache.tools.ant.BuildException(
+ "Not an actual task, but looks like one for documentation purposes");
+ }
+ /**
+ * Gets the dataset. Used on OS390 if the libs are in a dataset.
+ *
+ * @return Returns a String
+ */
+ public String getDataset() {
+ if (isReference()) {
+ LibrarySet master = ((LibrarySet) getCheckedRef(LibrarySet.class, "LibrarySet"));
+ return master.getDataset();
+ }
+ return dataset;
+ }
+ public File getDir(final Project project) {
+ if (isReference()) {
+ LibrarySet master = ((LibrarySet) getCheckedRef(LibrarySet.class, "LibrarySet"));
+ return master.getDir(project);
+ }
+ return set.getDir(project);
+ }
+ protected FileSet getFileSet() {
+ if (isReference()) {
+ LibrarySet master = ((LibrarySet) getCheckedRef(LibrarySet.class, "LibrarySet"));
+ return master.getFileSet();
+ }
+ return set;
+ }
+ public String[] getLibs() {
+ if (isReference()) {
+ LibrarySet master = ((LibrarySet) getCheckedRef(LibrarySet.class, "LibrarySet"));
+ return master.getLibs();
+ }
+ String[] retval = (String[]) libnames.clone();
+ return retval;
+ }
+
+ /**
+ * Gets preferred library type
+ *
+ * @return library type, may be null.
+ */
+ public LibraryTypeEnum getType() {
+ if (isReference()) {
+ LibrarySet master = ((LibrarySet) getCheckedRef(LibrarySet.class, "LibrarySet"));
+ return master.getType();
+ }
+ return libraryType;
+ }
+ /**
+ * Returns true if the define's if and unless conditions (if any) are
+ * satisfied.
+ */
+ public boolean isActive(final org.apache.tools.ant.Project p) {
+ if (p == null) {
+ throw new NullPointerException("p");
+ }
+ if (ifCond != null) {
+ String ifValue = p.getProperty(ifCond);
+ if (ifValue != null) {
+ if (ifValue.equals("no") || ifValue.equals("false")) {
+ throw new BuildException(
+ "property "
+ + ifCond
+ + " used as if condition has value "
+ + ifValue
+ + " which suggests a misunderstanding of if attributes");
+ }
+ } else {
+ return false;
+ }
+ }
+ if (unlessCond != null) {
+ String unlessValue = p.getProperty(unlessCond);
+ if (unlessValue != null) {
+ if (unlessValue.equals("no") || unlessValue.equals("false")) {
+ throw new BuildException(
+ "property "
+ + unlessCond
+ + " used as unless condition has value "
+ + unlessValue
+ + " which suggests a misunderstanding of unless attributes");
+ }
+ return false;
+ }
+ }
+ if (isReference()) {
+ LibrarySet master = ((LibrarySet) getCheckedRef(LibrarySet.class, "LibrarySet"));
+ return master.isActive(project);
+ }
+ if (libnames.length == 0) {
+ p.log("libnames not specified or empty.", Project.MSG_WARN);
+ return false;
+ }
+ return true;
+ }
+ /**
+ * Sets case sensitivity of the file system. If not set, will default to
+ * the linker's case sensitivity.
+ *
+ * @param isCaseSensitive
+ * "true"|"on"|"yes" if file system is case sensitive,
+ * "false"|"off"|"no" when not.
+ */
+ public void setCaseSensitive(final boolean isCaseSensitive) {
+ if (isReference()) {
+ throw tooManyAttributes();
+ }
+ explicitCaseSensitive = true;
+ set.setCaseSensitive(isCaseSensitive);
+ }
+ /**
+ * Sets the dataset. Used on OS390 if the libs are in a dataset.
+ *
+ * @param dataset
+ * The dataset to set
+ */
+ public void setDataset(final String dataset) {
+ if (isReference()) {
+ throw tooManyAttributes();
+ }
+ this.dataset = dataset;
+ }
+ /**
+ * Library directory.
+ *
+ * @param dir
+ * library directory
+ *
+ */
+ public void setDir(final File dir) throws BuildException {
+ if (isReference()) {
+ throw tooManyAttributes();
+ }
+ set.setDir(dir);
+ }
+ /**
+ * Sets the property name for the 'if' condition.
+ *
+ * The library set will be ignored unless the property is defined.
+ *
+ * The value of the property is insignificant, but values that would imply
+ * misinterpretation ("false", "no") will throw an exception when
+ * evaluated.
+ *
+ * @param propName
+ * property name
+ */
+ public void setIf(String propName) {
+ ifCond = propName;
+ }
+ /**
+ * Comma-separated list of library names without leading prefixes, such as
+ * "lib", or extensions, such as ".so" or ".a".
+ *
+ */
+ public void setLibs(final CUtil.StringArrayBuilder libs) throws BuildException {
+ if (isReference()) {
+ throw tooManyAttributes();
+ }
+ libnames = libs.getValue();
+ //
+ // earlier implementations would warn of suspicious library names
+ // (like libpthread for pthread or kernel.lib for kernel).
+ // visitLibraries now provides better feedback and ld type linkers
+ // should provide adequate feedback so the check here is not necessary.
+ }
+ public void setProject(final Project project) {
+ set.setProject(project);
+ super.setProject(project);
+ }
+ /**
+ * Set the property name for the 'unless' condition.
+ *
+ * If named property is set, the library set will be ignored.
+ *
+ * The value of the property is insignificant, but values that would imply
+ * misinterpretation ("false", "no") of the behavior will throw an
+ * exception when evaluated.
+ *
+ * @param propName
+ * name of property
+ */
+ public void setUnless(String propName) {
+ unlessCond = propName;
+ }
+
+ /**
+ * Sets the preferred library type. Supported values "shared", "static", and
+ * "framework". "framework" is equivalent to "shared" on non-Darwin platforms.
+ */
+ public void setType(final LibraryTypeEnum type) {
+ if (isReference()) {
+ throw tooManyAttributes();
+ }
+ this.libraryType = type;
+ }
+
+ public void visitLibraries(final Project project,
+ final Linker linker,
+ final File[] libpath,
+ final FileVisitor visitor) throws BuildException {
+ if (isReference()) {
+ LibrarySet master = ((LibrarySet) getCheckedRef(LibrarySet.class, "LibrarySet"));
+ master.visitLibraries(project, linker, libpath, visitor);
+ }
+ //
+ // if there was a libs attribute then
+ // add the corresponding patterns to the FileSet
+ //
+ if (libnames != null) {
+ for (int i = 0; i < libnames.length; i++) {
+ String[] patterns = linker.getLibraryPatterns(new String[] { libnames[i] }, libraryType);
+ if (patterns.length > 0) {
+ FileSet localSet = (FileSet) set.clone();
+ //
+ // unless explicitly set
+ // will default to the linker case sensitivity
+ //
+ if (!explicitCaseSensitive) {
+ boolean linkerCaseSensitive = linker.isCaseSensitive();
+ localSet.setCaseSensitive(linkerCaseSensitive);
+ }
+ //
+ // add all the patterns for this libname
+ //
+ for (int j = 0; j < patterns.length; j++) {
+ PatternSet.NameEntry entry = localSet.createInclude();
+ entry.setName(patterns[j]);
+ }
+ int matches = 0;
+ //
+ // if there was no specified directory then
+ // run through the libpath backwards
+ //
+ if (localSet.getDir(project) == null) {
+ //
+ // scan libpath in reverse order
+ // to give earlier entries priority
+ //
+ for (int j = libpath.length - 1; j >= 0; j--) {
+ FileSet clone = (FileSet) localSet.clone();
+ clone.setDir(libpath[j]);
+ DirectoryScanner scanner = clone.getDirectoryScanner(project);
+ File basedir = scanner.getBasedir();
+ String[] files = scanner.getIncludedFiles();
+ matches += files.length;
+ for (int k = 0; k < files.length; k++) {
+ visitor.visit(basedir, files[k]);
+ }
+ }
+ } else {
+ DirectoryScanner scanner = localSet.getDirectoryScanner(project);
+ File basedir = scanner.getBasedir();
+ String[] files = scanner.getIncludedFiles();
+ matches += files.length;
+ for (int k = 0; k < files.length; k++) {
+ visitor.visit(basedir, files[k]);
+ }
+ }
+ //
+ // TODO: following section works well for Windows
+ // style linkers but unnecessary fails
+ // Unix style linkers. Will need to revisit.
+ //
+ if (matches == 0 && false) {
+ StringBuffer msg = new StringBuffer("No file matching ");
+ if (patterns.length == 1) {
+ msg.append("pattern (");
+ msg.append(patterns[0]);
+ msg.append(")");
+ } else {
+ msg.append("patterns (\"");
+ msg.append(patterns[0]);
+ for (int k = 1; k < patterns.length; k++) {
+ msg.append(", ");
+ msg.append(patterns[k]);
+ }
+ msg.append(")");
+ }
+ msg.append(" for library name \"");
+ msg.append(libnames[i]);
+ msg.append("\" was found.");
+ throw new BuildException(msg.toString());
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/types/LibraryTypeEnum.java b/src/main/java/net/sf/antcontrib/cpptasks/types/LibraryTypeEnum.java
new file mode 100644
index 0000000..c0af5f8
--- /dev/null
+++ b/src/main/java/net/sf/antcontrib/cpptasks/types/LibraryTypeEnum.java
@@ -0,0 +1,48 @@
+/*
+ *
+ * Copyright 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.types;
+import org.apache.tools.ant.types.EnumeratedAttribute;
+/**
+ * Enumeration of library types for LibrarySet
+ *
+ * @author Curt Arnold
+ *
+ */
+public class LibraryTypeEnum extends EnumeratedAttribute {
+ /**
+ * Constructor
+ *
+ * Set by default to "shared"
+ *
+ * @see java.lang.Object#Object()
+ */
+ public LibraryTypeEnum() {
+ setValue("shared");
+ }
+ /**
+ * Gets list of acceptable values
+ *
+ * @see org.apache.tools.ant.types.EnumeratedAttribute#getValues()
+ */
+ public String[] getValues() {
+ return new String[]{"shared", // prefer shared libraries
+ "static", // prefer static libraries
+ "framework" // framework libraries (Mac OS/X)
+ // equiv to shared on other platforms
+ };
+ }
+}
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/types/LinkerArgument.java b/src/main/java/net/sf/antcontrib/cpptasks/types/LinkerArgument.java
new file mode 100644
index 0000000..bee15cf
--- /dev/null
+++ b/src/main/java/net/sf/antcontrib/cpptasks/types/LinkerArgument.java
@@ -0,0 +1,28 @@
+/*
+ *
+ * Copyright 2001-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.types;
+/**
+ * A linker command line argument.
+ */
+public class LinkerArgument extends CommandLineArgument {
+ public LinkerArgument() {
+ }
+ public void execute() throws org.apache.tools.ant.BuildException {
+ throw new org.apache.tools.ant.BuildException(
+ "Not an actual task, but looks like one for documentation purposes");
+ }
+}
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/types/SystemIncludePath.java b/src/main/java/net/sf/antcontrib/cpptasks/types/SystemIncludePath.java
new file mode 100644
index 0000000..37a3e28
--- /dev/null
+++ b/src/main/java/net/sf/antcontrib/cpptasks/types/SystemIncludePath.java
@@ -0,0 +1,45 @@
+/*
+ *
+ * Copyright 2001-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.types;
+import org.apache.tools.ant.Project;
+/**
+ * A system include path.
+ *
+ * Files located using a system include path will not participate in dependency
+ * analysis.
+ *
+ * Standard include paths for a compiler should not be specified since these
+ * should be determined from environment variables or configuration files by
+ * the compiler adapter.
+ *
+ * Works like other paths in Ant with with the addition of "if" and "unless"
+ * conditions.
+ *
+ * @author Curt Arnold
+ */
+public class SystemIncludePath extends ConditionalPath {
+ public SystemIncludePath(Project project) {
+ super(project);
+ }
+ public SystemIncludePath(Project p, String path) {
+ super(p, path);
+ }
+ public void execute() throws org.apache.tools.ant.BuildException {
+ throw new org.apache.tools.ant.BuildException(
+ "Not an actual task, but looks like one for documentation purposes");
+ }
+}
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/types/SystemLibrarySet.java b/src/main/java/net/sf/antcontrib/cpptasks/types/SystemLibrarySet.java
new file mode 100644
index 0000000..97c4fa2
--- /dev/null
+++ b/src/main/java/net/sf/antcontrib/cpptasks/types/SystemLibrarySet.java
@@ -0,0 +1,37 @@
+/*
+ *
+ * Copyright 2001-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.types;
+/**
+ * A set of system library names. Timestamp or location of system libraries are
+ * not considered in dependency analysis.
+ *
+ * Libraries can also be added to a link by specifying them in a fileset.
+ *
+ * For most Unix-like compilers, syslibset will result in a series of -l and -L
+ * linker arguments. For Windows compilers, the library names will be used to
+ * locate the appropriate library files which will be added to the linkers
+ * input file list as if they had been specified in a fileset.
+ */
+public class SystemLibrarySet extends LibrarySet {
+ public SystemLibrarySet() {
+ super();
+ }
+ public void execute() throws org.apache.tools.ant.BuildException {
+ throw new org.apache.tools.ant.BuildException(
+ "Not an actual task, but looks like one for documentation purposes");
+ }
+}
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/types/UndefineArgument.java b/src/main/java/net/sf/antcontrib/cpptasks/types/UndefineArgument.java
new file mode 100644
index 0000000..aa958ef
--- /dev/null
+++ b/src/main/java/net/sf/antcontrib/cpptasks/types/UndefineArgument.java
@@ -0,0 +1,153 @@
+/*
+ *
+ * Copyright 2001-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.types;
+import java.util.Vector;
+
+import net.sf.antcontrib.cpptasks.CUtil;
+
+import org.apache.tools.ant.BuildException;
+/**
+ * Preprocessor macro undefinition.
+ *
+ * @author Mark A Russell <a
+ * href="mailto:mark_russell@csgsystems.com">mark_russell@csg_systems.com
+ * </a>
+ */
+public class UndefineArgument {
+ /**
+ * This method returns an array of UndefineArgument and DefineArgument's by
+ * merging a base list with an override list.
+ *
+ * Any define in the base list with a name that appears in the override
+ * list is suppressed. All entries in the override list are preserved
+ *
+ */
+ public static UndefineArgument[] merge(UndefineArgument[] base,
+ UndefineArgument[] override) {
+ if (base.length == 0) {
+ UndefineArgument[] overrideClone = (UndefineArgument[]) override
+ .clone();
+ return overrideClone;
+ }
+ if (override.length == 0) {
+ UndefineArgument[] baseClone = (UndefineArgument[]) base.clone();
+ return baseClone;
+ }
+ Vector unduplicated = new Vector(base.length);
+ for (int i = 0; i < base.length; i++) {
+ UndefineArgument current = base[i];
+ String currentName = current.getName();
+ boolean match = false;
+ if (currentName == null) {
+ match = true;
+ } else {
+ for (int j = 0; j < override.length; j++) {
+ UndefineArgument over = override[j];
+ String overName = over.getName();
+ if (overName != null && overName.equals(currentName)) {
+ match = true;
+ break;
+ }
+ }
+ }
+ if (!match) {
+ unduplicated.addElement(current);
+ }
+ }
+ UndefineArgument[] combined = new UndefineArgument[unduplicated.size()
+ + override.length];
+ unduplicated.copyInto(combined);
+ int offset = unduplicated.size();
+ for (int i = 0; i < override.length; i++) {
+ combined[offset + i] = override[i];
+ }
+ return combined;
+ }
+ private boolean define = false;
+ private String ifCond;
+ private String name;
+ private String unlessCond;
+ public UndefineArgument() {
+ }
+ protected UndefineArgument(boolean isDefine) {
+ this.define = isDefine;
+ }
+ public void execute() throws org.apache.tools.ant.BuildException {
+ throw new org.apache.tools.ant.BuildException(
+ "Not an actual task, but looks like one for documentation purposes");
+ }
+ /** Returns the name of the define */
+ public final String getName() {
+ return name;
+ }
+ /** Returns the value of the define */
+ public String getValue() {
+ return null;
+ }
+ /**
+ * Returns true if the define's if and unless conditions (if any) are
+ * satisfied.
+ *
+ * @exception BuildException
+ * throws build exception if name is not set
+ */
+ public final boolean isActive(org.apache.tools.ant.Project p)
+ throws BuildException {
+ if (name == null) {
+ throw new BuildException("<define> is missing name attribute");
+ }
+ return CUtil.isActive(p, ifCond, unlessCond);
+ }
+ /** Returns true if this is a define, false if an undefine. */
+ public final boolean isDefine() {
+ return define;
+ }
+ /**
+ * Sets the property name for the 'if' condition.
+ *
+ * The define will be ignored unless the property is defined.
+ *
+ * The value of the property is insignificant, but values that would imply
+ * misinterpretation ("false", "no") will throw an exception when
+ * evaluated.
+ *
+ * @param propName
+ * property name
+ */
+ public final void setIf(String propName) {
+ ifCond = propName;
+ }
+ /** Set the name attribute */
+ public final void setName(String name) {
+ this.name = name;
+ }
+ /**
+ * Set the property name for the 'unless' condition.
+ *
+ * If named property is set, the define will be ignored.
+ *
+ * The value of the property is insignificant, but values that would imply
+ * misinterpretation ("false", "no") of the behavior will throw an
+ * exception when evaluated.
+ *
+ * @param propName
+ * name of property
+ */
+ public final void setUnless(String propName) {
+ unlessCond = propName;
+ }
+}