SF.net SVN: ant-contrib: [158] cpptasks/trunk/src/main/java/net/sf/ antcontrib/cpptasks/apple/XcodeProjectWriter.java

[email protected] Fri, 22 Feb 2008 08:48:35 -0800
Newsgroups gmane.comp.java.ant-contrib.devel
Message-ID <[email protected]>
Revision: 158
          http://ant-contrib.svn.sourceforge.net/ant-contrib/?rev=158&view=rev
Author:   carnold
Date:     2008-02-22 08:48:34 -0800 (Fri, 22 Feb 2008)

Log Message:
-----------
Fix outtype detection for Xcode gen on non-Mac platforms

Modified Paths:
--------------
    cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/apple/XcodeProjectWriter.java

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-22 06:45:56 UTC (rev 157)
+++ cpptasks/trunk/src/main/java/net/sf/antcontrib/cpptasks/apple/XcodeProjectWriter.java	2008-02-22 16:48:34 UTC (rev 158)
@@ -317,12 +317,7 @@
                 linkTarget.getOutput());
         Map executableProperties = executable.getProperties();
 
-        String fileType = "compiled.mach-o.executable";
-        if (isStaticLibrary(linkTarget)) {
-            fileType = "archive.ar";
-        } else if (isDylibLibrary(linkTarget)) {
-            fileType = "compiled.mach-o.dylib";
-        }
+        String fileType = getFileType(linkTarget);
         executableProperties.put("explicitFileType", fileType);
         executableProperties.put("includeInIndex", "0");
         objects.put(executable.getID(), executableProperties);
@@ -615,12 +610,7 @@
 
         String productInstallPath = "$(HOME)/bin";
 
-        String productType = "com.apple.product-type.tool";
-        if (isStaticLibrary(linkTarget)) {
-            productType = "com.apple.product-type.library.static";
-        } else if (isDylibLibrary(linkTarget)) {
-            productType = "com.apple.product-type.library.dynamic";            
-        }
+        String productType = getProductType(linkTarget);
 
         PBXObjectRef nativeTarget = createPBXNativeTarget(projectName,
                 buildConfigurations, buildPhases, buildRules, dependencies,
@@ -630,27 +620,46 @@
         return nativeTarget;
     }
 
-    /**
-     * Determines if linked target is a static library.
-     * @param linkTarget link target
-     * @return true if a static library
-     */
-    private static boolean isStaticLibrary(final TargetInfo linkTarget) {
+    private int getProductTypeIndex(final TargetInfo linkTarget) {
         String outPath = linkTarget.getOutput().getPath();
-        return (outPath.lastIndexOf(".a") == outPath.length() - 2);
+        String outExtension = null;
+        int lastDot = outPath.lastIndexOf('.');
+        if (lastDot != -1) {
+            outExtension = outPath.substring(lastDot);
+        }
+        if (".a".equalsIgnoreCase(outExtension) || ".lib".equalsIgnoreCase(outExtension)) {
+            return 1;
+        } else if (".dylib".equalsIgnoreCase(outExtension) ||
+                   ".so".equalsIgnoreCase(outExtension) ||
+                   ".dll".equalsIgnoreCase(outExtension)) {
+            return 2;
+        }
+        return 0;
     }
 
-    /**
-     * Determines if linked target is a static library.
-     * @param linkTarget link target
-     * @return true if a static library
-     */
-    private static boolean isDylibLibrary(final TargetInfo linkTarget) {
-        String outPath = linkTarget.getOutput().getPath();
-        return (outPath.lastIndexOf(".dylib") == outPath.length() - 6 &&
-            outPath.length() > 6);
+    private String getProductType(final TargetInfo linkTarget) {
+        switch(getProductTypeIndex(linkTarget)) {
+            case 1:
+                return "com.apple.product-type.library.static";
+            case 2:
+                return "com.apple.product-type.library.dynamic";
+            default:
+                return "com.apple.product-type.tool";
+        }
     }
 
+    private String getFileType(final TargetInfo linkTarget) {
+        switch(getProductTypeIndex(linkTarget)) {
+            case 1:
+                return "archive.ar";
+            case 2:
+                return "compiled.mach-o.dylib";
+            default:
+                return "compiled.mach-o.executable";
+        }
+    }
+
+
     /**
      * Create PBXFileReference.
      * @param sourceTree source tree.


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/