From 254c4886d58979eebd0e352f4d16e391736f2a33 Mon Sep 17 00:00:00 2001 From: Mark Donszelmann Date: Thu, 5 Nov 2009 23:27:33 +0100 Subject: Reorganized source directories in line with cpptasks-1.0b5, for easier tracking --- .../net/sf/antcontrib/cpptasks/ide/DebugDef.java | 127 ++++++++ .../net/sf/antcontrib/cpptasks/ide/ProjectDef.java | 330 +++++++++++++++++++++ .../sf/antcontrib/cpptasks/ide/ProjectWriter.java | 53 ++++ .../antcontrib/cpptasks/ide/ProjectWriterEnum.java | 100 +++++++ .../net/sf/antcontrib/cpptasks/ide/package.html | 27 ++ 5 files changed, 637 insertions(+) create mode 100644 src/main/java/net/sf/antcontrib/cpptasks/ide/DebugDef.java create mode 100644 src/main/java/net/sf/antcontrib/cpptasks/ide/ProjectDef.java create mode 100644 src/main/java/net/sf/antcontrib/cpptasks/ide/ProjectWriter.java create mode 100644 src/main/java/net/sf/antcontrib/cpptasks/ide/ProjectWriterEnum.java create mode 100644 src/main/java/net/sf/antcontrib/cpptasks/ide/package.html (limited to 'src/main/java/net/sf/antcontrib/cpptasks/ide') diff --git a/src/main/java/net/sf/antcontrib/cpptasks/ide/DebugDef.java b/src/main/java/net/sf/antcontrib/cpptasks/ide/DebugDef.java new file mode 100644 index 0000000..8ddd04e --- /dev/null +++ b/src/main/java/net/sf/antcontrib/cpptasks/ide/DebugDef.java @@ -0,0 +1,127 @@ +/* +* +* Copyright 2004-2005 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.ide; + +import java.io.File; + +import org.apache.tools.ant.types.Commandline; +import org.apache.tools.ant.types.Environment; +import org.apache.tools.ant.types.DataType; + + +/** +* Specifies a debugging configuration for a project. +* +* @author Curt Arnold +*/ +public final class DebugDef + extends DataType { + + /** + * Working directory for debug runs. + */ + private File dir; + /** + * Name of executable. + */ + private String executable; + /** + * Environment used to hold environment variables. + */ + private Environment env = new Environment(); + /** + * Command line used to hold command line arguments. + */ + private Commandline cmdl = new Commandline(); + + /** + * Constructor. + * + */ + public DebugDef() { + } + + + /** + * Set the name of the executable program. + * @param value the name of the executable program + */ + public void setExecutable(final String value) { + this.executable = value; + } + + /** + * Get the name of the executable program. + * @return the name of the executable program, may be null. + */ + public String getExecutable() { + return executable; + } + + /** + * Set the working directory of the process. + * @param d the working directory of the process + */ + public void setDir(final File d) { + this.dir = d; + } + + /** + * Get the working directory of the process. + * @return the working directory of the process, may be null. + */ + public File getDir() { + return dir; + } + + /** + * Add an environment variable. + * + * @param var new environment variable + */ + public void addEnv(final Environment.Variable var) { + env.addVariable(var); + } + + /** + * Get the variable list as an array. + * @return array of key=value assignment strings + */ + public String[] getVariables() { + return env.getVariables(); + } + + + /** + * Adds a command-line argument. + * + * @return new command line argument created + */ + public Commandline.Argument createArg() { + return cmdl.createArgument(); + } + + /** + * Returns all arguments defined by addLine, + * addValue or the argument object. + * @return array of command line arguments, may be zero-length. + */ + public String[] getArguments() { + return cmdl.getArguments(); + } + +} diff --git a/src/main/java/net/sf/antcontrib/cpptasks/ide/ProjectDef.java b/src/main/java/net/sf/antcontrib/cpptasks/ide/ProjectDef.java new file mode 100644 index 0000000..df0177c --- /dev/null +++ b/src/main/java/net/sf/antcontrib/cpptasks/ide/ProjectDef.java @@ -0,0 +1,330 @@ +/* + * + * Copyright 2004-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.ide; + +import net.sf.antcontrib.cpptasks.CCTask; +import net.sf.antcontrib.cpptasks.CUtil; +import net.sf.antcontrib.cpptasks.TargetInfo; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.types.DataType; + +import java.io.File; +import java.lang.reflect.Method; +import java.util.Hashtable; +import java.util.List; + +/** + * Requests the creation of an IDE project file. Experimental. + * + * Implementation status: msdev5, msdev6 and cbuilderx + * generate reasonable project files for simple projects, + * xcode and msdev7 and msdev71 capture source file lists and + * a few settings. + * + * @author Curt Arnold + */ +public final class ProjectDef + extends DataType { + /** + * Name of property that must be present or definition will be ignored. May + * be null. + */ + private String ifProp; + + /** + * Name of property that must be absent or definition will be ignored. May + * be null. + */ + private String unlessProp; + + /** + * Project file name. + */ + private File outFile; + + /** + * Project name. + */ + private String name; + + /** + * Fail on error. + */ + private boolean failOnError = true; + + /** + * Overwrite existing project file. + */ + private boolean overwrite = true; + + /** + * Project writer. + */ + private ProjectWriter projectWriter; + + /** + * Object directory. + * + */ + private File objDir; + + /** + * Constructor. + * + */ + public ProjectDef() { + } + + /** + * Set project type. + * + * + * Supported project formats + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
cbuilderxBorland C++BuilderX
msvc5Microsoft Visual C++ 97
msvc6Microsoft Visual C++ 6
msvc7Microsoft Visual C++.NET
msvc71Microsoft Visual C++.NET 2003
msvc8Microsoft Visual C++ 2005
xcodeApple Xcode
+ * + * @param value new value + */ + public void setType(final ProjectWriterEnum value) { + projectWriter = value.getProjectWriter(); + } + + /** + * Sets the name for the generated project file. + * + * @param outfile + * output file name + */ + public void setOutfile(final File outfile) { + // + // if file name was empty, skip link step + // + if (outfile == null || outfile.toString().length() > 0) { + outFile = outfile; + } + } + + /** + * Sets whether a failure to write the project file should cause the + * task to fail. Default is true. + * + * @param value new value + */ + public void setFailonerror(final boolean value) { + failOnError = value; + } + + /** + * Sets whether an existing project file should be overwritten, + * default is true. If false and the project file exists, + * the value of failonerror will determine if the task fails. + * + * @param value new value + */ + public void setOverwrite(final boolean value) { + overwrite = value; + } + + /** + * Gets whether an existing project file should be overwritten, + * default is true. If false and the project file exists, + * the value of failonerror will determine if the task fails. + * + * @return value + */ + public boolean getOverwrite() { + return overwrite; + } + + /** + * Determine if this def should be used. + * + * Definition will be active if the "if" variable (if specified) is set and + * the "unless" variable (if specified) is not set and that all reference + * or extended definitions are active + * + * @return true if processor is active + */ + public boolean isActive() { + Project project = getProject(); + if (!CUtil.isActive(project, ifProp, unlessProp)) { + return false; + } + return true; + } + + /** + * Class name for a user-supplied project writer. Use the "type" + * attribute to specify built-in project writer implementations. + * + * @param className + * full class name + * + */ + public void setClassname(final String className) { + Object proc = null; + try { + Class implClass = ProjectDef.class.getClassLoader().loadClass( + className); + try { + Method getInstance = implClass.getMethod("getInstance", + new Class[0]); + proc = getInstance.invoke(null, new Object[0]); + } catch (Exception ex) { + proc = implClass.newInstance(); + } + } catch (Exception ex) { + throw new BuildException(ex); + } + projectWriter = (ProjectWriter) proc; + } + + /** + * Sets the property name for the 'if' condition. + * + * The configuration 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 + * name of property + */ + public void setIf(final String propName) { + ifProp = propName; + } + + /** + * Set the property name for the 'unless' condition. + * + * If named property is set, the configuration 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(final String propName) { + unlessProp = propName; + } + + /** + * Get name. + * @return String name + */ + public String getName() { + return name; + } + + /** + * Set name. + * @param value String name + */ + public void setName(final String value) { + name = value; + } + + /** + * Executes the task. Compiles the given files. + * + * @param task cc task + * @param sources source files (includes headers) + * @param targets compilation targets + * @param linkTarget link target + */ + public void execute(final CCTask task, + final List sources, + final Hashtable targets, + final TargetInfo linkTarget) { + try { + projectWriter.writeProject(outFile, + task, + this, + sources, + targets, + linkTarget); + } catch (BuildException ex) { + if (failOnError) { + throw ex; + } else { + task.log(ex.toString()); + } + } catch (Exception ex) { + if (failOnError) { + throw new BuildException(ex); + } else { + task.log(ex.toString()); + } + } + } + + /** + * Gets the object files directory. + * @return directory, may be null. + */ + public File getObjdir() { + return objDir; + } + /** + * Sets the directory used for object files. If not specified, + * the object files directory from cc task will be used. + * @param oDir object file directory. + */ + public void getObjdir(final File oDir) { + this.objDir = oDir; + } + + /** + * Required by documentation generator. + */ + public void execute() { + 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/ide/ProjectWriter.java b/src/main/java/net/sf/antcontrib/cpptasks/ide/ProjectWriter.java new file mode 100644 index 0000000..c4c144d --- /dev/null +++ b/src/main/java/net/sf/antcontrib/cpptasks/ide/ProjectWriter.java @@ -0,0 +1,53 @@ +/* + * + * 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.ide; + +import java.io.File; +import java.io.IOException; +import java.util.Hashtable; +import java.util.List; + +import net.sf.antcontrib.cpptasks.CCTask; +import net.sf.antcontrib.cpptasks.TargetInfo; +import org.xml.sax.SAXException; + +/** + * Project writer interface. + * + * @author curta + * + */ +public interface ProjectWriter { + /** + * Write project definition file. + * @param baseName File name base, writer may append appropriate extension + * @param task task + * @param projectDef project element + * @param files source and header files + * @param targets compilation targets + * @param linkTarget link target + * @throws IOException if I/O error is encountered + * @throws SAXException if I/O error during XML serialization + */ + void writeProject(final File baseName, + final CCTask task, + final ProjectDef projectDef, + final List files, + final Hashtable targets, + final TargetInfo linkTarget) + throws IOException, SAXException; +} diff --git a/src/main/java/net/sf/antcontrib/cpptasks/ide/ProjectWriterEnum.java b/src/main/java/net/sf/antcontrib/cpptasks/ide/ProjectWriterEnum.java new file mode 100644 index 0000000..e100dbc --- /dev/null +++ b/src/main/java/net/sf/antcontrib/cpptasks/ide/ProjectWriterEnum.java @@ -0,0 +1,100 @@ +/* + * + * Copyright 2004-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.ide; + +import net.sf.antcontrib.cpptasks.apple.XcodeProjectWriter; +import net.sf.antcontrib.cpptasks.borland.CBuilderXProjectWriter; +import net.sf.antcontrib.cpptasks.devstudio.DevStudioProjectWriter; +import net.sf.antcontrib.cpptasks.devstudio.VisualStudioNETProjectWriter; +import org.apache.tools.ant.types.EnumeratedAttribute; + +/** + * Enumeration of supported project file generators. + * + * Supported project generators + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
cbuilderxBorland C++BuilderX
msvc5Microsoft Visual C++ 97
msvc6Microsoft Visual C++ 6
msvc7Microsoft Visual C++.NET
msvc71Microsoft Visual C++.NET 2003
msvc8Microsoft Visual C++ 2005
xcodeApple Xcode
+ * + * @author Curt Arnold + * + */ +public final class ProjectWriterEnum + extends EnumeratedAttribute { + /** + * Enumeration values. + */ + private static String[] values = new String[] { + "cbuilderx", "msvc5", + "msvc6", "msvc7", "msvc71", "msvc8", "xcode"}; + + /** + * Project writers associated with enumeration values. + */ + private static ProjectWriter[] writers = new ProjectWriter[] { + new CBuilderXProjectWriter(), new DevStudioProjectWriter("5.00"), + new DevStudioProjectWriter("6.00"), + new VisualStudioNETProjectWriter("7.00", "TRUE", "FALSE"), + new VisualStudioNETProjectWriter("7.10", "TRUE", "FALSE"), + new VisualStudioNETProjectWriter("8.00", "true", "false"), + new XcodeProjectWriter()}; + + /** + * Gets ProjectWriter associated with enumeration value. + * + * @return project writer + */ + public ProjectWriter getProjectWriter() { + return writers[this.getIndex()]; + } + + /** + * Gets acceptible values for enumeration. + * + * @return acceptible values + */ + public String[] getValues() { + return (String[]) values.clone(); + } +} + diff --git a/src/main/java/net/sf/antcontrib/cpptasks/ide/package.html b/src/main/java/net/sf/antcontrib/cpptasks/ide/package.html new file mode 100644 index 0000000..ed0de56 --- /dev/null +++ b/src/main/java/net/sf/antcontrib/cpptasks/ide/package.html @@ -0,0 +1,27 @@ + + + + + + + +IDE project file generation. + + + -- cgit v1.2.3