1 import static java.nio.file.FileVisitResult.CONTINUE; 2 3 import java.io.IOException; 4 import java.nio.file.FileVisitResult; 5 import java.nio.file.Files; 6 import java.nio.file.Path; 7 import java.nio.file.attribute.BasicFileAttributes; 8 import java.util.Vector; 9 10 public class FileTreeCreatorVC7 extends FileTreeCreator { 11 12 public FileTreeCreatorVC7(Path startDir, Vector<BuildConfig> allConfigs, 13 WinGammaPlatform wg) { 14 super(startDir, allConfigs, null); 15 } 16 17 @Override 18 public FileVisitResult visitFile(Path file, BasicFileAttributes attr) { 19 DirAttributes currentFileAttr = attributes.peek().clone(); 20 boolean usePch = false; 21 boolean disablePch = false; 22 boolean useIgnore = false; 23 String fileName = file.getFileName().toString(); 24 25 // usePch applies to all configs for a file. 26 if (fileName.equals(BuildConfig.getFieldString(null, "UseToGeneratePch"))) { 27 usePch = true; 28 } 29 30 for (BuildConfig cfg : allConfigs) { 31 if (cfg.lookupHashFieldInContext("IgnoreFile", fileName) != null) { 32 useIgnore = true; 33 currentFileAttr.setIgnore(cfg); 34 } else if (cfg.matchesIgnoredPath(file.toAbsolutePath().toString())) { 35 useIgnore = true; 36 currentFileAttr.setIgnore(cfg); 37 } 38 39 if (cfg.lookupHashFieldInContext("DisablePch", fileName) != null) { 40 disablePch = true; 41 currentFileAttr.setDisablePch(cfg); 42 } 43 44 Vector<String> rv = new Vector<String>(); 45 cfg.collectRelevantVectors(rv, "AdditionalFile"); 46 for (String addFile : rv) { 47 if (addFile.equals(fileName)) { 48 // supress any ignore 49 currentFileAttr.removeFromIgnored(cfg); 50 } 51 } 52 } 53 54 if (!useIgnore && !disablePch && !usePch) { 55 wg.tag("File", new String[] { "RelativePath", 56 vcProjLocation.relativize(file).toString() }); 57 } else { 58 wg.startTag("File", new String[] { "RelativePath", 59 vcProjLocation.relativize(file).toString() }); 60 61 for (BuildConfig cfg : allConfigs) { 62 boolean ignore = currentFileAttr.hasIgnore(cfg); 63 String[] fileConfAttr; 64 65 if (ignore) { 66 fileConfAttr = new String[] { "Name", cfg.get("Name"), 67 "ExcludedFromBuild", "TRUE" }; 68 } else { 69 fileConfAttr = new String[] { "Name", cfg.get("Name") }; 70 } 71 72 if (!disablePch && !usePch && !ignore) { 73 continue; 74 } else if (!disablePch && !usePch) { 75 wg.tag("FileConfiguration", fileConfAttr); 76 } else { 77 wg.startTag("FileConfiguration", fileConfAttr); 78 if (usePch) { 79 // usePch always applies to all configs, might not always be 80 // so. 81 wg.tag("Tool", new String[] { "Name", "VCCLCompilerTool", 82 "UsePrecompiledHeader", "1" }); 83 assert (!disablePch); 84 } 85 if (disablePch) { 86 if (currentFileAttr.hasDisablePch(cfg)) { 87 wg.tag("Tool", new String[] { "Name", "VCCLCompilerTool", 88 "UsePrecompiledHeader", "0" }); 89 } 90 assert (!usePch); 91 } 92 wg.endTag(); 93 } 94 } 95 wg.endTag(); 96 } 97 98 return CONTINUE; 99 } 100 101 @Override 102 public FileVisitResult preVisitDirectory(Path path, BasicFileAttributes attrs) 103 throws IOException { 104 Boolean hide = false; 105 DirAttributes newAttr = attributes.peek().clone(); 106 107 String rPath; 108 if (path.toAbsolutePath().toString() 109 .equals(this.startDir.toAbsolutePath().toString())) { 110 rPath = startDir.toString(); 111 } else { 112 rPath = path.getFileName().toString(); 113 } 114 115 // check per config ignorePaths! 116 for (BuildConfig cfg : allConfigs) { 117 if (cfg.matchesIgnoredPath(path.toAbsolutePath().toString())) { 118 newAttr.setIgnore(cfg); 119 } 120 121 // Hide is always on all configs. And additional files are never 122 // hiddden 123 if (cfg.matchesHidePath(path.toAbsolutePath().toString())) { 124 hide = true; 125 break; 126 } 127 } 128 129 if (!hide) { 130 wg.startTag("Filter", new String[] { "Name", rPath }); 131 132 attributes.push(newAttr); 133 return super.preVisitDirectory(path, attrs); 134 } else { 135 return FileVisitResult.SKIP_SUBTREE; 136 } 137 } 138 139 @Override 140 public FileVisitResult postVisitDirectory(Path dir, IOException exc) { 141 // end matching attributes set by ignorepath 142 wg.endTag(); 143 attributes.pop(); 144 145 return CONTINUE; 146 } 147 148 @Override 149 public FileVisitResult visitFileFailed(Path file, IOException exc) { 150 return CONTINUE; 151 } 152 153 public void writeFileTree() throws IOException { 154 Files.walkFileTree(this.startDir, this); 155 } 156 }