SF.net SVN: ant-contrib: [151] cpptasks/trunk

[email protected] Tue, 12 Feb 2008 08:16:47 -0800
Newsgroups gmane.comp.java.ant-contrib.devel
Message-ID <[email protected]>
Revision: 151
          http://ant-contrib.svn.sourceforge.net/ant-contrib/?rev=151&view=rev
Author:   carnold
Date:     2008-02-12 08:16:47 -0800 (Tue, 12 Feb 2008)

Log Message:
-----------
Bug 980130: Improvements to generated IDE files, more to come

Modified Paths:
--------------
    cpptasks/trunk/pom.xml
    cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/CUtil.java
    cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/apple/PropertyListSerialization.java
    cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/apple/XcodeProjectWriter.java
    cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/devstudio/DevStudioProjectWriter.java
    cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/devstudio/VisualStudioNETProjectWriter.java
    cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/ide/CommentDef.java
    cpptasks/trunk/src/test/java/net/sf/antcontrib/cpptasks/TestTargetHistoryTable.java

Modified: cpptasks/trunk/pom.xml
===================================================================
--- cpptasks/trunk/pom.xml	2008-02-06 18:20:58 UTC (rev 150)
+++ cpptasks/trunk/pom.xml	2008-02-12 16:16:47 UTC (rev 151)
@@ -68,11 +68,13 @@
     <plugins>
       <plugin>
         <artifactId>maven-surefire-plugin</artifactId>
+        <version>2.4.1</version>
         <configuration>
           <reportFormat>plain</reportFormat>
           <excludes>
               <exclude>**/TestInstalledDevStudioLinker.java</exclude>
-              <exclude>**/TestMetaObjectCompiler.java</exclude> 
+              <exclude>**/TestMetaObjectCompiler.java</exclude>
+              <exclude>**/TestAbstract*.java</exclude> 
           </excludes>
         </configuration>
       </plugin>

Modified: cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/CUtil.java
===================================================================
--- cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/CUtil.java	2008-02-06 18:20:58 UTC (rev 150)
+++ cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/CUtil.java	2008-02-12 16:16:47 UTC (rev 151)
@@ -493,7 +493,31 @@
           return StringUtils.replace(path, File.separator, "\\");
       }
       return path;
-  }
+    }
     
+    public static String toUnixPath(final String path) {
+      if (File.separatorChar != '/' && path.indexOf(File.separatorChar) != -1) {
+          return StringUtils.replace(path, File.separator, "/");
+      }
+      return path;
+    }
 
+    /**
+     *  Determines if source file has a system path,
+     *    that is part of the compiler or platform.
+     *   @param source source, may not be null.
+     *   @return true is source file appears to be system library
+     *         and its path should be discarded.
+     */
+     public static boolean isSystemPath(final File source) {
+         String lcPath = source.getAbsolutePath().toLowerCase(java.util.Locale.US);
+         return lcPath.indexOf("platformsdk") != -1
+             || lcPath.indexOf("microsoft") != -1 ||
+                lcPath == "/usr/include" ||
+                lcPath == "/usr/lib" ||
+                lcPath == "/usr/local/include" ||
+                lcPath == "/usr/local/lib";
+     }
+
+
 }

Modified: cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/apple/PropertyListSerialization.java
===================================================================
--- cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/apple/PropertyListSerialization.java	2008-02-06 18:20:58 UTC (rev 150)
+++ cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/apple/PropertyListSerialization.java	2008-02-12 16:16:47 UTC (rev 151)
@@ -50,10 +50,12 @@
      * Serializes a property list into a Cocoa XML Property List document.
      * @param propertyList property list.
      * @param file destination.
+     * @param comments comments to insert into document.
      * @throws SAXException if exception during serialization.
      * @throws TransformerConfigurationException if exception creating serializer.
      */
     public static void serialize(final Map propertyList,
+                                 final List comments,
                                  final File file)
            throws IOException, SAXException,
                TransformerConfigurationException {
@@ -66,6 +68,10 @@
         handler.setResult(result);
 
         handler.startDocument();
+        for(Iterator iter = comments.iterator(); iter.hasNext();) {
+            char[] comment = String.valueOf(iter.next()).toCharArray();
+            handler.comment(comment, 0, comment.length);
+        }
         AttributesImpl attributes = new AttributesImpl();
         handler.startElement(null, "plist", "plist", attributes);
         serializeMap(propertyList, handler);

Modified: cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/apple/XcodeProjectWriter.java
===================================================================
--- cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/apple/XcodeProjectWriter.java	2008-02-06 18:20:58 UTC (rev 150)
+++ cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/apple/XcodeProjectWriter.java	2008-02-12 16:16:47 UTC (rev 151)
@@ -88,6 +88,12 @@
                     "Unable to find compilation target using GNU C++ compiler");
         }
 
+
+        CommandLineLinkerConfiguration linkerConfig = null;
+        if (linkTarget.getConfiguration() instanceof CommandLineLinkerConfiguration) {
+            linkerConfig = (CommandLineLinkerConfiguration) linkTarget.getConfiguration();
+        }
+
         String projectName = projectDef.getName();
         if (projectName == null) {
             projectName = fileName.getName();
@@ -118,6 +124,9 @@
                 createPBXGroup("Source", sourceTree, sourceGroupChildren);
         objects.put(sourceGroup.getID(), sourceGroup.getProperties());
 
+
+
+
         //
         //    add product to property list
         //
@@ -141,6 +150,13 @@
         groups.add(documentationGroup);
         groups.add(productsGroup);
         PBXObjectRef mainGroup = createPBXGroup(projectName, sourceTree, groups);
+        StringBuffer comments = new StringBuffer();
+        for(Iterator iter = projectDef.getComments().iterator(); iter.hasNext();) {
+            comments.append(iter.next());
+        }
+        if (comments.length() > 0) {
+            mainGroup.getProperties().put("comments", comments.toString());
+        }
         objects.put(mainGroup.getID(), mainGroup.getProperties());
 
         //
@@ -150,8 +166,7 @@
                 addProjectConfigurationList(objects,
                         basePath,
                         compilerConfig,
-                        (CommandLineLinkerConfiguration)
-                                linkTarget.getConfiguration());
+                        linkerConfig);
 
         String projectDirPath = "";
         List projectTargets = new ArrayList();
@@ -173,7 +188,8 @@
         //   Calculate path (typically several ../..) of the root directory
         //        (where build.xml lives) relative to the XCode project directory.
         //         XCode 3.0 will now prompt user to supply the value if not specified.
-        String projectRoot = CUtil.getRelativePath(basePath, projectDef.getProject().getBaseDir());
+        String projectRoot = CUtil.toUnixPath(
+                CUtil.getRelativePath(basePath, projectDef.getProject().getBaseDir()));
         PBXObjectRef project = createPBXProject(compilerConfigurations, mainGroup,
                 projectDirPath, projectRoot, projectTargets);
         objects.put(project.getID(), project.getProperties());
@@ -190,7 +206,8 @@
         //    write property list out to XML file
         //
         try {
-            PropertyListSerialization.serialize(propertyList, xcodeProj);
+            PropertyListSerialization.serialize(propertyList,
+                    projectDef.getComments(), xcodeProj);
         } catch (TransformerConfigurationException ex) {
             throw new IOException(ex.toString());
         } catch (SAXException ex) {
@@ -296,6 +313,7 @@
      */
     private PBXObjectRef addNativeTargetConfigurationList(final Map objects,
                                                        final String projectName) {
+
         //
         //   Create a configuration list with
         //     two stock configurations: Debug and Release
@@ -334,12 +352,13 @@
         return configurationList;
     }
 
+
+
     /**
      * Add project configuration list.
      * @param objects map of objects.
      * @param baseDir base directory.
      * @param compilerConfig compiler configuration.
-     * @param linkerConfig linker configuration.
      * @return project configuration object.
      */
     private PBXObjectRef addProjectConfigurationList(final Map objects,
@@ -356,6 +375,8 @@
         debugSettings.put("GCC_WARN_UNUSED_VARIABLE", "YES");
         debugSettings.put("PREBINDING", "NO");
         debugSettings.put("SDKROOT", "/Developer/SDKs/MacOSX10.4u.sdk");
+
+
         PBXObjectRef debugConfig = createXCBuildConfiguration("Debug", debugSettings);
         objects.put(debugConfig.getID(), debugConfig.getProperties());
         configurations.add(debugConfig);
@@ -381,12 +402,20 @@
         File[] includeDirs = compilerConfig.getIncludePath();
         if (includeDirs.length > 0) {
             ArrayList includePaths = new ArrayList();
+            Map includePathMap = new HashMap();
             for (int i = 0; i < includeDirs.length; i++) {
-                String relPath = CUtil.getRelativePath(baseDir, includeDirs[i]);
-                if (relPath.startsWith("..")) {
-                    includePaths.add(includeDirs[i].getPath());
-                } else {
-                    includePaths.add(relPath);
+                if(!CUtil.isSystemPath(includeDirs[i])) {
+                    String absPath = includeDirs[i].getAbsolutePath();
+                    if (!includePathMap.containsKey(absPath)) {
+                        if(absPath.startsWith("/usr/")) {
+                            includePaths.add(CUtil.toUnixPath(absPath));
+                        } else {
+                            String relPath = CUtil.toUnixPath(
+                                CUtil.getRelativePath(baseDir, includeDirs[i]));
+                            includePaths.add(relPath);
+                        }
+                        includePathMap.put(absPath, absPath);
+                    }
                 }
             }
             includePaths.add("${inherited)");
@@ -411,26 +440,33 @@
             releaseSettings.put("GCC_PREPROCESSOR_DEFINITIONS", defines);
         }
 
-        String[] linkerArgs = linkerConfig.getPreArguments();
-        List librarySearchPaths = new ArrayList();
-        List libNames = new ArrayList();
-        for (int i = 0; i < linkerArgs.length; i++) {
-            if (linkerArgs[i].startsWith("-L")) {
-                 librarySearchPaths.add(linkerArgs[i].substring(2));
-            } else if (linkerArgs[i].startsWith("-l")) {
-                 libNames.add(linkerArgs[i]);
+
+        if (linkerConfig != null) {
+            Map librarySearchMap = new HashMap();
+            List librarySearchPaths = new ArrayList();
+            List otherLdFlags = new ArrayList();
+            String[] linkerArgs = linkerConfig.getEndArguments();
+            for (int i = 0; i < linkerArgs.length; i++) {
+                 if (linkerArgs[i].startsWith("-L")) {
+                     String libName = linkerArgs[i].substring(2);
+                     if (!librarySearchMap.containsKey(libName)) {
+                         if (!libName.equals("/usr/lib")) {
+                            librarySearchPaths.add(libName);
+                         }
+                         librarySearchMap.put(libName, libName);
+
+                     }
+                } else if (linkerArgs[i].startsWith("-l")) {
+                     otherLdFlags.add(linkerArgs[i]);
+                }
             }
-        }
-        if (librarySearchPaths.size() > 0) {
-            librarySearchPaths.add("\"$(inherited)\"");
+
+
             debugSettings.put("LIBRARY_SEARCH_PATHS", librarySearchPaths);
+            debugSettings.put("OTHER_LDFLAGS", otherLdFlags);
             releaseSettings.put("LIBRARY_SEARCH_PATHS", librarySearchPaths);
-        }
-        if (libNames.size() > 0) {
-            libNames.add("$(inherited)");
-            debugSettings.put("OTHER_LDFLAGS", libNames);
-            releaseSettings.put("OTHER_LDFLAGS", libNames);
-        }
+            releaseSettings.put("OTHER_LDFLAGS", otherLdFlags);
+        }        
         return configurationList;
     }
 
@@ -473,9 +509,11 @@
         buildPhases.add(sourcesBuildPhase);
 
 
+        List frameworkBuildFiles = new ArrayList();
+        buildActionMask = 8;
         PBXObjectRef frameworksBuildPhase =
                 createPBXFrameworksBuildPhase(buildActionMask,
-                new ArrayList(), false);
+                frameworkBuildFiles, false);
         objects.put(frameworksBuildPhase.getID(), frameworksBuildPhase.getProperties());
         buildPhases.add(frameworksBuildPhase);
 
@@ -539,8 +577,9 @@
         Map map = new HashMap();
         map.put("isa", "PBXFileReference");
 
-        String relPath = CUtil.getRelativePath(baseDir, file);
+        String relPath = CUtil.toUnixPath(CUtil.getRelativePath(baseDir, file));
         map.put("path", relPath);
+        map.put("name", file.getName());
         map.put("sourceTree", sourceTree);
         return new PBXObjectRef(map);
     }

Modified: cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/devstudio/DevStudioProjectWriter.java
===================================================================
--- cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/devstudio/DevStudioProjectWriter.java	2008-02-06 18:20:58 UTC (rev 150)
+++ cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/devstudio/DevStudioProjectWriter.java	2008-02-12 16:16:47 UTC (rev 151)
@@ -25,9 +25,8 @@
 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 net.sf.antcontrib.cpptasks.ide.CommentDef;
 import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.util.StringUtils;
 
 import java.io.BufferedWriter;
 import java.io.File;
@@ -40,7 +39,6 @@
 import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Vector;
 
 /**
  * Writes a Microsoft Visual Studio 97 or Visual Studio 6 project file.
@@ -141,9 +139,9 @@
     writer.write(this.version);
     writer.write("\r\n");
     writer.write("# ** DO NOT EDIT **\r\n\r\n");
-
-	writeComments(writer, projectDef.getComments());
-
+
+	writeComments(writer, projectDef.getComments());
+
     String outputType = task.getOuttype();
     String subsystem = task.getSubsystem();
     String configName = projectName;
@@ -333,10 +331,10 @@
       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());
-
 
+	  writeComments(writer, project.getComments());
+
+
       List dependencies = project.getDependencies();
       List projectDeps = new ArrayList();
       String basePath = dspFile.getParent();
@@ -557,18 +555,6 @@
 
 
 
- /**
-  *  Determines if source file has a system path,
-  *    that is part of the compiler or platform.
-  *   @param source source, may not be null.
-  *   @return true is source file appears to be system library
-  *         and its path should be discarded.
-  */
-  private static boolean isSystemPath(final File source) {
-	  String lcPath = source.toString().toLowerCase(java.util.Locale.US);
-	  return lcPath.indexOf("platformsdk") != -1
-	      || lcPath.indexOf("microsoft") != -1;
-  }
 
   /**
    * Writes link options.
@@ -605,7 +591,7 @@
           //      otherwise construct a relative path.
           //
           String relPath = linkSources[i].getName();
-          if (!isSystemPath(linkSources[i])) {
+          if (!CUtil.isSystemPath(linkSources[i])) {
               relPath = CUtil.getRelativePath(basePath, linkSources[i]);
           }
           //
@@ -640,21 +626,21 @@
     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;
-				}
-			}	
-		}
   }
+
+  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;
+				}
+			}	
+		}
+  }
 }

Modified: cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/devstudio/VisualStudioNETProjectWriter.java
===================================================================
--- cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/devstudio/VisualStudioNETProjectWriter.java	2008-02-06 18:20:58 UTC (rev 150)
+++ cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/devstudio/VisualStudioNETProjectWriter.java	2008-02-12 16:16:47 UTC (rev 151)
@@ -26,8 +26,8 @@
 import net.sf.antcontrib.cpptasks.ide.CommentDef;
 import net.sf.antcontrib.cpptasks.ide.ProjectWriter;
 import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.util.StringUtils;
 import org.apache.xml.serialize.OutputFormat;
-import org.apache.xml.serialize.Serializer;
 import org.apache.xml.serialize.XMLSerializer;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.SAXException;
@@ -90,18 +90,6 @@
         this.falseLiteral = falseArg;
     }
     
- /**
-  *  Determines if source file has a system path,
-  *    that is part of the compiler or platform.
-  *   @param source source, may not be null.
-  *   @return true is source file appears to be system library
-  *         and its path should be discarded.
-  */
-  private static boolean isSystemPath(final File source) {
-	  String lcPath = source.toString().toLowerCase(java.util.Locale.US);
-	  return lcPath.indexOf("platformsdk") != -1
-	      || lcPath.indexOf("microsoft") != -1;
-  }
 
     /**
      * Get configuration name.
@@ -132,6 +120,7 @@
         return targtype;
     }
 
+
     /**
      * Get output directory.
      * @param basePath path to parent of project file.
@@ -238,19 +227,17 @@
      * @return value of AdditionalIncludeDirectories property.
      */
     private String getAdditionalIncludeDirectories(
-            final String basePath,
+            final String baseDir,
             final CommandLineCompilerConfiguration compilerConfig) {
+        File[] includePath = compilerConfig.getIncludePath();
         StringBuffer includeDirs = new StringBuffer();
-        String[] args = compilerConfig.getPreArguments();
-        for (int i = 0; i < args.length; i++) {
-            if (args[i].startsWith("/I")) {
-                includeDirs.append(CUtil.toWindowsPath(
-                    CUtil.getRelativePath(basePath, 
-                        new File(args[i].substring(2)))));
-                includeDirs.append(';');
-            }
+        for (int i = 0; i < includePath.length; i++) {
+          String relPath = CUtil.getRelativePath(baseDir, includePath[i]);
+          includeDirs.append(CUtil.toWindowsPath(relPath));
+          includeDirs.append(';');
         }
 
+
         if (includeDirs.length() > 0) {
             includeDirs.setLength(includeDirs.length() - 1);
         }
@@ -583,7 +570,7 @@
             //      otherwise construct a relative path.
             //
             String relPath = linkSources[i].getName();
-            if (!isSystemPath(linkSources[i])) {
+            if (!CUtil.isSystemPath(linkSources[i])) {
                 relPath = CUtil.getRelativePath(basePath, linkSources[i]);
             }
             //

Modified: cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/ide/CommentDef.java
===================================================================
--- cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/ide/CommentDef.java	2008-02-06 18:20:58 UTC (rev 150)
+++ cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/ide/CommentDef.java	2008-02-12 16:16:47 UTC (rev 151)
@@ -34,10 +34,14 @@
     }
 
 
-    public String getText() {
+    public String getText() {
 		return text;
-    }
-	public void addText(final String newText) {
-		text += newText;
+    }
+	public void addText(final String newText) {
+		text += newText;
 	}
+
+    public String toString() {
+        return text;
+    }
 }

Modified: cpptasks/trunk/src/test/java/net/sf/antcontrib/cpptasks/TestTargetHistoryTable.java
===================================================================
--- cpptasks/trunk/src/test/java/net/sf/antcontrib/cpptasks/TestTargetHistoryTable.java	2008-02-06 18:20:58 UTC (rev 150)
+++ cpptasks/trunk/src/test/java/net/sf/antcontrib/cpptasks/TestTargetHistoryTable.java	2008-02-12 16:16:47 UTC (rev 151)
@@ -27,7 +27,7 @@
  * @author CurtA
  */
 public class TestTargetHistoryTable extends TestXMLConsumer {
-    private static class MockProcessorConfiguration
+    public static class MockProcessorConfiguration
             implements
                 ProcessorConfiguration {
         public MockProcessorConfiguration() {


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/