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 FileTreeCreatorVC10 extends FileTreeCreator { 11 12 public FileTreeCreatorVC10(Path startDir, Vector<BuildConfig> allConfigs, 13 WinGammaPlatformVC10 wg) { 14 super(startDir, allConfigs, wg); 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 String fileLoc = vcProjLocation.relativize(file).toString(); 25 String fullPath = file.toAbsolutePath().toString(); 26 27 // usePch applies to all configs for a file. 28 if (fileName.equals(BuildConfig.getFieldString(null, "UseToGeneratePch"))) { 29 usePch = true; 30 } 31 32 for (BuildConfig cfg : allConfigs) { 33 if (cfg.lookupHashFieldInContext("IgnoreFile", fileName) != null) { 34 useIgnore = true; 35 currentFileAttr.setIgnore(cfg); 36 } else if (cfg.matchesIgnoredPath(fullPath)) { 37 useIgnore = true; 38 currentFileAttr.setIgnore(cfg); 39 } 40 41 if (cfg.lookupHashFieldInContext("DisablePch", fileName) != null) { 42 disablePch = true; 43 currentFileAttr.setDisablePch(cfg); 44 } 45 46 Vector<String> rv = new Vector<String>(); 47 cfg.collectRelevantVectors(rv, "AdditionalFile"); 48 for (String addFile : rv) { 49 if (addFile.equals(fullPath)) { 50 // supress any ignore 51 currentFileAttr.removeFromIgnored(cfg); 52 } 53 } 54 } 55 56 String tagName = wg.getFileTagFromSuffix(fileName); 57 58 if (!useIgnore && !disablePch && !usePch) { 59 wg.tag(tagName, new String[] { "Include", fileLoc }); 60 } else { 61 wg.startTag(tagName, new String[] { "Include", fileLoc }); 62 63 for (BuildConfig cfg : allConfigs) { 64 boolean ignore = currentFileAttr.hasIgnore(cfg); 65 if (ignore) { 66 wg.tagData("ExcludedFromBuild", "true", "Condition", 67 "'$(Configuration)|$(Platform)'=='" + cfg.get("Name") 68 + "'"); 69 } 70 if (usePch) { 71 wg.tagData("PrecompiledHeader", "Create", "Condition", 72 "'$(Configuration)|$(Platform)'=='" + cfg.get("Name") 73 + "'"); 74 } 75 if (disablePch) { 76 wg.tag("PrecompiledHeader", "Condition", 77 "'$(Configuration)|$(Platform)'=='" + cfg.get("Name") 78 + "'"); 79 } 80 } 81 wg.endTag(); 82 } 83 84 String filter = startDir.relativize(file.getParent().toAbsolutePath()) 85 .toString(); 86 wg.addFilterDependency(fileLoc, filter); 87 88 return CONTINUE; 89 } 90 91 @Override 92 public FileVisitResult preVisitDirectory(Path path, BasicFileAttributes attrs) 93 throws IOException { 94 Boolean hide = false; 95 // TODO remove attrs, if path is matched in this dir, then it is too in 96 // every subdir. And we will check anyway 97 DirAttributes newAttr = attributes.peek().clone(); 98 99 // check per config ignorePaths! 100 for (BuildConfig cfg : allConfigs) { 101 if (cfg.matchesIgnoredPath(path.toAbsolutePath().toString())) { 102 newAttr.setIgnore(cfg); 103 } 104 105 // Hide is always on all configs. And additional files are never 106 // hiddden 107 if (cfg.matchesHidePath(path.toAbsolutePath().toString())) { 108 hide = true; 109 break; 110 } 111 } 112 113 if (!hide) { 114 String name = startDir.relativize(path.toAbsolutePath()).toString(); 115 if (!"".equals(name)) { 116 wg.addFilter(name); 117 } 118 119 attributes.push(newAttr); 120 return super.preVisitDirectory(path, attrs); 121 } else { 122 return FileVisitResult.SKIP_SUBTREE; 123 } 124 } 125 126 @Override 127 public FileVisitResult postVisitDirectory(Path dir, IOException exc) { 128 // end matching attributes set by ignorepath 129 attributes.pop(); 130 return CONTINUE; 131 } 132 133 @Override 134 public FileVisitResult visitFileFailed(Path file, IOException exc) { 135 return CONTINUE; 136 } 137 138 public void writeFileTree() throws IOException { 139 Files.walkFileTree(this.startDir, this); 140 } 141 }