summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorcarnold <[email protected]>2008-02-06 18:20:58 +0000
committercarnold <[email protected]>2008-02-06 18:20:58 +0000
commit77601bd19b2aa119c0ba42e7452f16297fc9a5fd (patch)
tree8df387639eb3aaec922f4ce570f56d1075eefe9f /src
parentf3766103c1d4635d42f9947457f6cd4a6584d339 (diff)
Bug 980130: Add comments to generated project files
git-svn-id: file:///home/sven/projects/JOGL/temp/ant-contrib/svn/ant-contrib-code/cpptasks/trunk@150 32d7a393-a5a9-423c-abd3-5d954feb1f2f
Diffstat (limited to 'src')
-rw-r--r--src/main/java/net/sf/antcontrib/cpptasks/devstudio/DevStudioProjectWriter.java23
-rw-r--r--src/main/java/net/sf/antcontrib/cpptasks/devstudio/VisualStudioNETProjectWriter.java9
-rw-r--r--src/main/java/net/sf/antcontrib/cpptasks/ide/CommentDef.java43
-rw-r--r--src/main/java/net/sf/antcontrib/cpptasks/ide/ProjectDef.java25
4 files changed, 95 insertions, 5 deletions
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/devstudio/DevStudioProjectWriter.java b/src/main/java/net/sf/antcontrib/cpptasks/devstudio/DevStudioProjectWriter.java
index d55e42f..d70ad23 100644
--- a/src/main/java/net/sf/antcontrib/cpptasks/devstudio/DevStudioProjectWriter.java
+++ b/src/main/java/net/sf/antcontrib/cpptasks/devstudio/DevStudioProjectWriter.java
@@ -25,6 +25,7 @@ import net.sf.antcontrib.cpptasks.compiler.ProcessorConfiguration;
import net.sf.antcontrib.cpptasks.ide.DependencyDef;
import net.sf.antcontrib.cpptasks.ide.ProjectDef;
import net.sf.antcontrib.cpptasks.ide.ProjectWriter;
+import net.sf.antcontrib.cpptasks.ide.CommentDef;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.util.StringUtils;
@@ -140,6 +141,9 @@ public final class DevStudioProjectWriter
writer.write(this.version);
writer.write("\r\n");
writer.write("# ** DO NOT EDIT **\r\n\r\n");
+
+ writeComments(writer, projectDef.getComments());
+
String outputType = task.getOuttype();
String subsystem = task.getSubsystem();
String configName = projectName;
@@ -329,6 +333,9 @@ public final class DevStudioProjectWriter
writer.write("\r\n");
writer.write("# WARNING: DO NOT EDIT OR DELETE");
writer.write(" THIS WORKSPACE FILE!\r\n\r\n");
+
+ writeComments(writer, project.getComments());
+
List dependencies = project.getDependencies();
List projectDeps = new ArrayList();
@@ -633,5 +640,21 @@ public final class DevStudioProjectWriter
options.append("\r\n");
writer.write(baseOptions.toString());
writer.write(options.toString());
+ }
+
+ private static void writeComments(final Writer writer,
+ final List comments) throws IOException {
+ for(Iterator iter = comments.iterator();iter.hasNext();) {
+ String comment = ((CommentDef) iter.next()).getText();
+ if (comment != null) {
+ int start = 0;
+ for(int end = comment.indexOf('\n');
+ end != -1;
+ end = comment.indexOf('\n', start)) {
+ writer.write("#" + comment.substring(start, end) + "\r\n");
+ start = end + 1;
+ }
+ }
+ }
}
}
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/devstudio/VisualStudioNETProjectWriter.java b/src/main/java/net/sf/antcontrib/cpptasks/devstudio/VisualStudioNETProjectWriter.java
index 868a0f9..3115640 100644
--- a/src/main/java/net/sf/antcontrib/cpptasks/devstudio/VisualStudioNETProjectWriter.java
+++ b/src/main/java/net/sf/antcontrib/cpptasks/devstudio/VisualStudioNETProjectWriter.java
@@ -23,6 +23,7 @@ import net.sf.antcontrib.cpptasks.compiler.CommandLineCompilerConfiguration;
import net.sf.antcontrib.cpptasks.compiler.ProcessorConfiguration;
import net.sf.antcontrib.cpptasks.compiler.CommandLineLinkerConfiguration;
import net.sf.antcontrib.cpptasks.ide.ProjectDef;
+import net.sf.antcontrib.cpptasks.ide.CommentDef;
import net.sf.antcontrib.cpptasks.ide.ProjectWriter;
import org.apache.tools.ant.BuildException;
import org.apache.xml.serialize.OutputFormat;
@@ -690,10 +691,16 @@ public final class VisualStudioNETProjectWriter
OutputStream outStream = new FileOutputStream(fileName + ".vcproj");
OutputFormat format = new OutputFormat("xml", "UTF-8", true);
- Serializer serializer = new XMLSerializer(outStream, format);
+ XMLSerializer serializer = new XMLSerializer(outStream, format);
ContentHandler content = serializer.asContentHandler();
String basePath = fileName.getParentFile().getAbsolutePath();
content.startDocument();
+
+ for(Iterator iter = projectDef.getComments().iterator(); iter.hasNext(); ) {
+ String comment = ((CommentDef) iter.next()).getText();
+ serializer.comment(comment);
+ }
+
AttributesImpl emptyAttrs = new AttributesImpl();
AttributesImpl attributes = new AttributesImpl();
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/ide/CommentDef.java b/src/main/java/net/sf/antcontrib/cpptasks/ide/CommentDef.java
new file mode 100644
index 0000000..c87261a
--- /dev/null
+++ b/src/main/java/net/sf/antcontrib/cpptasks/ide/CommentDef.java
@@ -0,0 +1,43 @@
+/*
+ *
+ * Copyright 2008 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 org.apache.tools.ant.util.StringUtils;
+
+import java.io.File;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Defines a comment to place in the generated project files.
+ *
+ */
+public final class CommentDef {
+ private String text;
+
+ public CommentDef() {
+ text = "";
+ }
+
+
+ public String getText() {
+ return text;
+ }
+ public void addText(final String newText) {
+ text += newText;
+ }
+}
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/ide/ProjectDef.java b/src/main/java/net/sf/antcontrib/cpptasks/ide/ProjectDef.java
index 77c0cb3..2942134 100644
--- a/src/main/java/net/sf/antcontrib/cpptasks/ide/ProjectDef.java
+++ b/src/main/java/net/sf/antcontrib/cpptasks/ide/ProjectDef.java
@@ -87,7 +87,12 @@ public final class ProjectDef
/**
* List of dependency definitions.
*/
- private List dependencies = new ArrayList();
+ private List dependencies = new ArrayList();
+
+ /**
+ * List of comments.
+ */
+ private List comments = new ArrayList();
/**
* Constructor.
@@ -330,9 +335,8 @@ public final class ProjectDef
}
/**
- * FileSet containing project files that should be imported
- * as dependencies
- * @param dependency dependency.
+ * Add a dependency definition to the project.
+ * @param dependency dependency.
*/
public void addDependency(final DependencyDef dependency) {
dependencies.add(dependency);
@@ -343,6 +347,19 @@ public final class ProjectDef
return new ArrayList(dependencies);
}
+
+ /**
+ * Add comment for the generated project file.
+ * @param comment comment, may not be null.
+ */
+ public void addComment(final CommentDef comment) {
+ comments.add(comment);
+
+ }
+
+ public List getComments() {
+ return new ArrayList(comments);
+ }
/**
* Required by documentation generator.