diff options
Diffstat (limited to 'src/main/java/net')
6 files changed, 141 insertions, 95 deletions
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/CUtil.java b/src/main/java/net/sf/antcontrib/cpptasks/CUtil.java index 4681e95..c41c99e 100644 --- a/src/main/java/net/sf/antcontrib/cpptasks/CUtil.java +++ b/src/main/java/net/sf/antcontrib/cpptasks/CUtil.java @@ -493,7 +493,31 @@ public class CUtil { 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"; + } + } diff --git a/src/main/java/net/sf/antcontrib/cpptasks/apple/PropertyListSerialization.java b/src/main/java/net/sf/antcontrib/cpptasks/apple/PropertyListSerialization.java index 207d52f..c3a6807 100644 --- a/src/main/java/net/sf/antcontrib/cpptasks/apple/PropertyListSerialization.java +++ b/src/main/java/net/sf/antcontrib/cpptasks/apple/PropertyListSerialization.java @@ -50,10 +50,12 @@ public final class PropertyListSerialization { * 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 @@ public final class PropertyListSerialization { 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); diff --git a/src/main/java/net/sf/antcontrib/cpptasks/apple/XcodeProjectWriter.java b/src/main/java/net/sf/antcontrib/cpptasks/apple/XcodeProjectWriter.java index 1d77c29..fbab766 100644 --- a/src/main/java/net/sf/antcontrib/cpptasks/apple/XcodeProjectWriter.java +++ b/src/main/java/net/sf/antcontrib/cpptasks/apple/XcodeProjectWriter.java @@ -88,6 +88,12 @@ public final class XcodeProjectWriter "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 @@ public final class XcodeProjectWriter createPBXGroup("Source", sourceTree, sourceGroupChildren); objects.put(sourceGroup.getID(), sourceGroup.getProperties()); + + + // // add product to property list // @@ -141,6 +150,13 @@ public final class XcodeProjectWriter 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 @@ public final class XcodeProjectWriter addProjectConfigurationList(objects, basePath, compilerConfig, - (CommandLineLinkerConfiguration) - linkTarget.getConfiguration()); + linkerConfig); String projectDirPath = ""; List projectTargets = new ArrayList(); @@ -173,7 +188,8 @@ public final class XcodeProjectWriter // 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 @@ public final class XcodeProjectWriter // 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 @@ public final class XcodeProjectWriter */ private PBXObjectRef addNativeTargetConfigurationList(final Map objects, final String projectName) { + // // Create a configuration list with // two stock configurations: Debug and Release @@ -334,12 +352,13 @@ public final class XcodeProjectWriter 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 @@ public final class XcodeProjectWriter 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 @@ public final class XcodeProjectWriter 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 @@ public final class XcodeProjectWriter 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 @@ public final class XcodeProjectWriter 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 @@ public final class XcodeProjectWriter 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); } 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 d70ad23..475005d 100644 --- a/src/main/java/net/sf/antcontrib/cpptasks/devstudio/DevStudioProjectWriter.java +++ b/src/main/java/net/sf/antcontrib/cpptasks/devstudio/DevStudioProjectWriter.java @@ -25,9 +25,8 @@ 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 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.Comparator; 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 @@ 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());
-
+ + writeComments(writer, projectDef.getComments()); + String outputType = task.getOuttype(); String subsystem = task.getSubsystem(); String configName = projectName; @@ -333,9 +331,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());
-
+ + writeComments(writer, project.getComments()); + List dependencies = project.getDependencies(); List projectDeps = new ArrayList(); @@ -557,18 +555,6 @@ public final class DevStudioProjectWriter - /** - * 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 @@ public final class DevStudioProjectWriter // 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 @@ 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;
- }
- }
- }
+ } + + 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 3115640..0afeebc 100644 --- a/src/main/java/net/sf/antcontrib/cpptasks/devstudio/VisualStudioNETProjectWriter.java +++ b/src/main/java/net/sf/antcontrib/cpptasks/devstudio/VisualStudioNETProjectWriter.java @@ -26,8 +26,8 @@ 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.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 @@ public final class VisualStudioNETProjectWriter 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 @@ public final class VisualStudioNETProjectWriter return targtype; } + /** * Get output directory. * @param basePath path to parent of project file. @@ -238,19 +227,17 @@ public final class VisualStudioNETProjectWriter * @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 @@ public final class VisualStudioNETProjectWriter // 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]); } // diff --git a/src/main/java/net/sf/antcontrib/cpptasks/ide/CommentDef.java b/src/main/java/net/sf/antcontrib/cpptasks/ide/CommentDef.java index c87261a..2221aba 100644 --- a/src/main/java/net/sf/antcontrib/cpptasks/ide/CommentDef.java +++ b/src/main/java/net/sf/antcontrib/cpptasks/ide/CommentDef.java @@ -34,10 +34,14 @@ public final class CommentDef { } - 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; + } } |