--- old/src/share/tools/ProjectCreator/WinGammaPlatformVC7.java 2012-04-19 13:40:35.966024100 +0200 +++ new/src/share/tools/ProjectCreator/WinGammaPlatformVC7.java 2012-04-19 13:40:35.436993800 +0200 @@ -25,9 +25,7 @@ import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.TreeSet; +import java.nio.file.FileSystems; import java.util.Vector; public class WinGammaPlatformVC7 extends WinGammaPlatform { @@ -42,29 +40,25 @@ // write the .vcproj file printWriter = new PrintWriter(new FileWriter(projectFileName)); - printWriter.println(""); - startTag( - "VisualStudioProject", - new String[] { - "ProjectType", "Visual C++", - "Version", projectVersion(), - "Name", projectName, - "ProjectGUID", "{8822CB5C-1C41-41C2-8493-9F6E1994338B}", - "SccProjectName", "", - "SccLocalPath", "" - } - ); - startTag("Platforms"); - tag("Platform", new String[] {"Name", (String) BuildConfig.getField(null, "PlatformName")}); - endTag("Platforms"); + printWriter + .println(""); + startTag("VisualStudioProject", new String[] { "ProjectType", + "Visual C++", "Version", projectVersion(), "Name", projectName, + "ProjectGUID", "{8822CB5C-1C41-41C2-8493-9F6E1994338B}", + "SccProjectName", "", "SccLocalPath", "" }); + startTag("Platforms"); + tag("Platform", + new String[] { "Name", + (String) BuildConfig.getField(null, "PlatformName") }); + endTag(); startTag("Configurations"); - for (Iterator i = allConfigs.iterator(); i.hasNext(); ) { - writeConfiguration((BuildConfig)i.next()); - } + for (BuildConfig cfg : allConfigs) { + writeConfiguration(cfg); + } - endTag("Configurations"); + endTag(); tag("References"); @@ -72,550 +66,118 @@ tag("Globals"); - endTag("VisualStudioProject"); + endTag(); printWriter.close(); System.out.println(" Done."); } - - abstract class NameFilter { - protected String fname; - - abstract boolean match(FileInfo fi); - - String filterString() { return ""; } - String name() { return this.fname;} - - @Override - // eclipse auto-generated - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + getOuterType().hashCode(); - result = prime * result + ((fname == null) ? 0 : fname.hashCode()); - return result; - } - - @Override - // eclipse auto-generated - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - NameFilter other = (NameFilter) obj; - if (!getOuterType().equals(other.getOuterType())) - return false; - if (fname == null) { - if (other.fname != null) - return false; - } else if (!fname.equals(other.fname)) - return false; - return true; - } - - // eclipse auto-generated - private WinGammaPlatformVC7 getOuterType() { - return WinGammaPlatformVC7.this; - } - } - - class DirectoryFilter extends NameFilter { - String dir; - int baseLen, dirLen; - - DirectoryFilter(String dir, String sbase) { - this.dir = dir; - this.baseLen = sbase.length(); - this.dirLen = dir.length(); - this.fname = dir; - } - - DirectoryFilter(String fname, String dir, String sbase) { - this.dir = dir; - this.baseLen = sbase.length(); - this.dirLen = dir.length(); - this.fname = fname; - } - - - boolean match(FileInfo fi) { - int lastSlashIndex = fi.full.lastIndexOf('/'); - String fullDir = fi.full.substring(0, lastSlashIndex); - return fullDir.endsWith(dir); - } - - @Override - // eclipse auto-generated - public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + getOuterType().hashCode(); - result = prime * result + baseLen; - result = prime * result + ((dir == null) ? 0 : dir.hashCode()); - result = prime * result + dirLen; - return result; - } - - @Override - // eclipse auto-generated - public boolean equals(Object obj) { - if (this == obj) - return true; - if (!super.equals(obj)) - return false; - if (getClass() != obj.getClass()) - return false; - DirectoryFilter other = (DirectoryFilter) obj; - if (!getOuterType().equals(other.getOuterType())) - return false; - if (baseLen != other.baseLen) - return false; - if (dir == null) { - if (other.dir != null) - return false; - } else if (!dir.equals(other.dir)) - return false; - if (dirLen != other.dirLen) - return false; - return true; - } - - // eclipse auto-generated - private WinGammaPlatformVC7 getOuterType() { - return WinGammaPlatformVC7.this; - } - } - - class TerminatorFilter extends NameFilter { - TerminatorFilter(String fname) { - this.fname = fname; - - } - boolean match(FileInfo fi) { - return true; - } - - } - - class SpecificNameFilter extends NameFilter { - String pats[]; - - SpecificNameFilter(String fname, String[] pats) { - this.fname = fname; - this.pats = pats; - } - - boolean match(FileInfo fi) { - for (int i=0; i makeFilters(TreeSet files) { - Vector rv = new Vector(); - String sbase = Util.normalize(BuildConfig.getFieldString(null, "SourceBase")+"/src/"); - - String currentDir = ""; - DirectoryFilter container = null; - for(FileInfo fileInfo : files) { - - if (!fileInfo.full.startsWith(sbase)) { - continue; - } - - int lastSlash = fileInfo.full.lastIndexOf('/'); - String dir = fileInfo.full.substring(sbase.length(), lastSlash); - if(dir.equals("share/vm")) { - // skip files directly in share/vm - should only be precompiled.hpp which is handled below - continue; - } - if (!dir.equals(currentDir)) { - currentDir = dir; - if (container != null && !rv.contains(container)) { - rv.add(container); - } - - // remove "share/vm/" from names - String name = dir; - if (dir.startsWith("share/vm/")) { - name = dir.substring("share/vm/".length(), dir.length()); - } - DirectoryFilter newfilter = new DirectoryFilter(name, dir, sbase); - int i = rv.indexOf(newfilter); - if(i == -1) { - container = newfilter; - } else { - // if the filter already exists, reuse it - container = (DirectoryFilter) rv.get(i); - } - } - } - if (container != null && !rv.contains(container)) { - rv.add(container); - } - - ContainerFilter generated = new ContainerFilter("Generated"); - ContainerFilter c1Generated = new ContainerFilter("C1"); - c1Generated.add(new SpecificPathFilter("C++ Interpreter Generated", new String[] {".*compiler1/generated/jvmtifiles/bytecodeInterpreterWithChecks.+"})); - c1Generated.add(new SpecificPathFilter("jvmtifiles", new String[] {".*compiler1/generated/jvmtifiles/.*"})); - generated.add(c1Generated); - ContainerFilter c2Generated = new ContainerFilter("C2"); - c2Generated.add(new SpecificPathFilter("C++ Interpreter Generated", new String[] {".*compiler2/generated/jvmtifiles/bytecodeInterpreterWithChecks.+"})); - c2Generated.add(new SpecificPathFilter("adfiles", new String[] {".*compiler2/generated/adfiles/.*"})); - c2Generated.add(new SpecificPathFilter("jvmtifiles", new String[] {".*compiler2/generated/jvmtifiles/.*"})); - generated.add(c2Generated); - ContainerFilter coreGenerated = new ContainerFilter("Core"); - coreGenerated.add(new SpecificPathFilter("C++ Interpreter Generated", new String[] {".*core/generated/jvmtifiles/bytecodeInterpreterWithChecks.+"})); - coreGenerated.add(new SpecificPathFilter("jvmtifiles", new String[] {".*core/generated/jvmtifiles/.*"})); - generated.add(coreGenerated); - ContainerFilter tieredGenerated = new ContainerFilter("Tiered"); - tieredGenerated.add(new SpecificPathFilter("C++ Interpreter Generated", new String[] {".*tiered/generated/jvmtifiles/bytecodeInterpreterWithChecks.+"})); - tieredGenerated.add(new SpecificPathFilter("adfiles", new String[] {".*tiered/generated/adfiles/.*"})); - tieredGenerated.add(new SpecificPathFilter("jvmtifiles", new String[] {".*tiered/generated/jvmtifiles/.*"})); - generated.add(tieredGenerated); - ContainerFilter kernelGenerated = new ContainerFilter("Kernel"); - kernelGenerated.add(new SpecificPathFilter("C++ Interpreter Generated", new String[] {".*kernel/generated/jvmtifiles/bytecodeInterpreterWithChecks.+"})); - kernelGenerated.add(new SpecificPathFilter("jvmtifiles", new String[] {".*kernel/generated/jvmtifiles/.*"})); - generated.add(kernelGenerated); - rv.add(generated); - - rv.add(new SpecificNameFilter("Precompiled Header", new String[] {"precompiled.hpp"})); - - // this one is to catch files not caught by other filters - rv.add(new TerminatorFilter("Source Files")); - - return rv; - } - - void writeFiles(Vector allConfigs) { - - Hashtable allFiles = computeAttributedFiles(allConfigs); - - Vector allConfigNames = new Vector(); - for (Iterator i = allConfigs.iterator(); i.hasNext(); ) { - allConfigNames.add(((BuildConfig)i.next()).get("Name")); - } - - TreeSet sortedFiles = sortFiles(allFiles); - - startTag("Files"); - - for (Iterator i = makeFilters(sortedFiles).iterator(); i.hasNext(); ) { - doWriteFiles(sortedFiles, allConfigNames, (NameFilter)i.next()); - } - - - startTag("Filter", - new String[] { - "Name", "Resource Files", - "Filter", "ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe" - } - ); - endTag("Filter"); - - endTag("Files"); - } - - void doWriteFiles(TreeSet allFiles, Vector allConfigNames, NameFilter filter) { - startTag("Filter", - new String[] { - "Name", filter.name(), - "Filter", filter.filterString() - } - ); - - if (filter instanceof ContainerFilter) { - - Iterator i = ((ContainerFilter)filter).babies(); - while (i.hasNext()) { - doWriteFiles(allFiles, allConfigNames, (NameFilter)i.next()); - } - - } else { - - Iterator i = allFiles.iterator(); - while (i.hasNext()) { - FileInfo fi = (FileInfo)i.next(); - - if (!filter.match(fi)) { - continue; - } - - startTag("File", - new String[] { - "RelativePath", fi.full.replace('/', '\\') - } - ); - - FileAttribute a = fi.attr; - if (a.pchRoot) { - writeCustomToolConfig(allConfigNames, - new String[] { - "Name", "VCCLCompilerTool", - "UsePrecompiledHeader", "1" - }); - } - - if (a.noPch) { - writeCustomToolConfig(allConfigNames, - new String[] { - "Name", "VCCLCompilerTool", - "UsePrecompiledHeader", "0" - }); - } - - if (a.configs != null) { - for (Iterator j=allConfigNames.iterator(); j.hasNext();) { - String cfg = (String)j.next(); - if (!a.configs.contains(cfg)) { - startTag("FileConfiguration", - new String[] { - "Name", cfg, - "ExcludedFromBuild", "TRUE" - }); - endTag("FileConfiguration"); - - } - } - } - - endTag("File"); - - // we not gonna look at this file anymore - i.remove(); - } - } - - endTag("Filter"); - } - - - void writeConfiguration(BuildConfig cfg) { - startTag("Configuration", - new String[] { - "Name", cfg.get("Name"), - "OutputDirectory", cfg.get("OutputDir"), - "IntermediateDirectory", cfg.get("OutputDir"), - "ConfigurationType", "2", - "UseOfMFC", "0", - "ATLMinimizesCRunTimeLibraryUsage", "FALSE" - } - ); - - - - tagV("Tool", cfg.getV("CompilerFlags")); - - tag("Tool", - new String[] { - "Name", "VCCustomBuildTool" - } - ); - - tagV("Tool", cfg.getV("LinkerFlags")); - - tag("Tool", - new String[] { - "Name", "VCPostBuildEventTool", - "Description", BuildConfig.getFieldString(null, "PostbuildDescription"), - //Caution: String.replace(String,String) is available from JDK5 onwards only - "CommandLine", cfg.expandFormat(BuildConfig.getFieldString(null, "PostbuildCommand").replace - ("\t", " ")) - } - ); - - tag("Tool", - new String[] { - "Name", "VCPreBuildEventTool" - } - ); - - tag("Tool", - new String[] { - "Name", "VCPreLinkEventTool", - "Description", BuildConfig.getFieldString(null, "PrelinkDescription"), - //Caution: String.replace(String,String) is available from JDK5 onwards only - "CommandLine", cfg.expandFormat(BuildConfig.getFieldString(null, "PrelinkCommand").replace - ("\t", " ")) - } - ); - - tag("Tool", - new String[] { - "Name", "VCResourceCompilerTool", - // XXX??? - "PreprocessorDefinitions", "NDEBUG", - "Culture", "1033" - } - ); - - tag("Tool", - new String[] { - "Name", "VCMIDLTool", - "PreprocessorDefinitions", "NDEBUG", - "MkTypLibCompatible", "TRUE", - "SuppressStartupBanner", "TRUE", - "TargetEnvironment", "1", - "TypeLibraryName", cfg.get("OutputDir") + Util.sep + "vm.tlb", - "HeaderFileName", "" - } - ); - - endTag("Configuration"); - } - - int indent; - - private void startTagPrim(String name, - String[] attrs, - boolean close) { - startTagPrim(name, attrs, close, true); - } - - private void startTagPrim(String name, - String[] attrs, - boolean close, - boolean newline) { - doIndent(); - printWriter.print("<"+name); - indent++; - - if (attrs != null && attrs.length > 0) { - for (int i=0; i"); - } else { - printWriter.print(">"); - } - if(newline) { - printWriter.println(); - } - } - - void startTag(String name, String... attrs) { - startTagPrim(name, attrs, false); - } - - void startTagV(String name, Vector attrs) { - String s[] = new String [attrs.size()]; - for (int i=0; i configs, String[] customToolAttrs) { + for (BuildConfig cfg : configs) { + startTag("FileConfiguration", + new String[] { "Name", (String) cfg.get("Name") }); + tag("Tool", customToolAttrs); + + endTag(); + } + } + + void writeFiles(Vector allConfigs) { + + // This code assummes there are no config specific includes. + startTag("Files"); + String sourceBase = BuildConfig.getFieldString(null, "SourceBase"); + + // Use first config for all global absolute includes. + BuildConfig baseConfig = allConfigs.firstElement(); + Vector rv = new Vector(); + + // Then use first config for all relative includes + Vector ri = new Vector(); + baseConfig.collectRelevantVectors(ri, "RelativeSrcInclude"); + for (String f : ri) { + rv.add(sourceBase + Util.sep + f); + } + + baseConfig.collectRelevantVectors(rv, "AbsoluteSrcInclude"); + + handleIncludes(rv, allConfigs); + + startTag("Filter", new String[] { "Name", "Resource Files", "Filter", + "ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe" }); + endTag(); + + endTag(); + } + + // Will visit file tree for each include + private void handleIncludes(Vector includes, Vector allConfigs) { + for (String path : includes) { + FileTreeCreatorVC7 ftc = new FileTreeCreatorVC7(FileSystems.getDefault().getPath(path) , allConfigs, this); + try { + ftc.writeFileTree(); + } catch (IOException e) { + e.printStackTrace(); } - startTagPrim(name, s, false); - } + } + } - void endTag(String name) { - indent--; - doIndent(); - printWriter.println(""); - } - - void tag(String name, String... attrs) { - startTagPrim(name, attrs, true); - } - - void tagData(String name, String data) { - doIndent(); - printWriter.print("<"+name+">"); - printWriter.print(data); - printWriter.println(""); - } + void writeConfiguration(BuildConfig cfg) { + startTag("Configuration", new String[] { "Name", cfg.get("Name"), + "OutputDirectory", cfg.get("OutputDir"), + "IntermediateDirectory", cfg.get("OutputDir"), + "ConfigurationType", "2", "UseOfMFC", "0", + "ATLMinimizesCRunTimeLibraryUsage", "FALSE" }); + + tagV("Tool", cfg.getV("CompilerFlags")); + + tag("Tool", new String[] { "Name", "VCCustomBuildTool" }); + + tagV("Tool", cfg.getV("LinkerFlags")); + + tag("Tool", + new String[] { + "Name", + "VCPostBuildEventTool", + "Description", + BuildConfig + .getFieldString(null, "PostbuildDescription"), + // Caution: String.replace(String,String) is available + // from JDK5 onwards only + "CommandLine", + cfg.expandFormat(BuildConfig.getFieldString(null, + "PostbuildCommand").replace("\t", + " ")) }); + + tag("Tool", new String[] { "Name", "VCPreBuildEventTool" }); + + tag("Tool", + new String[] { + "Name", + "VCPreLinkEventTool", + "Description", + BuildConfig.getFieldString(null, "PrelinkDescription"), + // Caution: String.replace(String,String) is available + // from JDK5 onwards only + "CommandLine", + cfg.expandFormat(BuildConfig.getFieldString(null, + "PrelinkCommand").replace("\t", " ")) }); + + tag("Tool", new String[] { "Name", "VCResourceCompilerTool", + "PreprocessorDefinitions", "NDEBUG", "Culture", "1033" }); + + tag("Tool", new String[] { "Name", "VCMIDLTool", + "PreprocessorDefinitions", "NDEBUG", "MkTypLibCompatible", + "TRUE", "SuppressStartupBanner", "TRUE", "TargetEnvironment", + "1", "TypeLibraryName", + cfg.get("OutputDir") + Util.sep + "vm.tlb", "HeaderFileName", + "" }); - void tagData(String name, String data, String... attrs) { - startTagPrim(name, attrs, false, false); - printWriter.print(data); - printWriter.println(""); - indent--; - } + endTag(); + } - void tagV(String name, Vector attrs) { - String s[] = new String [attrs.size()]; - for (int i=0; i