216 } |
217 } |
217 |
218 |
218 return false; |
219 return false; |
219 } |
220 } |
220 |
221 |
221 /* This returns a String containing the full path to the passed |
|
222 file name, or null if an error occurred. If the file was not |
|
223 found or was a duplicate and couldn't be resolved using the |
|
224 preferred paths, the file name is added to the appropriate |
|
225 Vector of Strings. */ |
|
226 private String findFileInDirectory(String fileName, |
|
227 DirectoryTree directory, |
|
228 Vector preferredPaths, |
|
229 Vector filesNotFound, |
|
230 Vector filesDuplicate) { |
|
231 List locationsInTree = directory.findFile(fileName); |
|
232 int rootNameLength = directory.getRootNodeName().length(); |
|
233 String name = null; |
|
234 if ((locationsInTree == null) || |
|
235 (locationsInTree.size() == 0)) { |
|
236 filesNotFound.add(fileName); |
|
237 } else if (locationsInTree.size() > 1) { |
|
238 // Iterate through them, trying to find one with a |
|
239 // preferred path |
|
240 search: |
|
241 { |
|
242 for (Iterator locIter = locationsInTree.iterator(); |
|
243 locIter.hasNext(); ) { |
|
244 DirectoryTreeNode node = |
|
245 (DirectoryTreeNode) locIter.next(); |
|
246 String tmpName = node.getName(); |
|
247 for (Iterator prefIter = preferredPaths.iterator(); |
|
248 prefIter.hasNext(); ) { |
|
249 // We need to make sure the preferred path is |
|
250 // found from the file path not including the root node name. |
|
251 if (tmpName.indexOf((String)prefIter.next(), |
|
252 rootNameLength) != -1) { |
|
253 name = tmpName; |
|
254 break search; |
|
255 } |
|
256 } |
|
257 } |
|
258 } |
|
259 |
|
260 if (name == null) { |
|
261 filesDuplicate.add(fileName); |
|
262 } |
|
263 } else { |
|
264 name = ((DirectoryTreeNode) locationsInTree.get(0)).getName(); |
|
265 } |
|
266 |
|
267 return name; |
|
268 } |
|
269 |
|
270 protected String envVarPrefixedFileName(String fileName, |
|
271 int sourceBaseLen, |
|
272 DirectoryTree tree, |
|
273 Vector preferredPaths, |
|
274 Vector filesNotFound, |
|
275 Vector filesDuplicate) { |
|
276 String fullName = findFileInDirectory(fileName, |
|
277 tree, |
|
278 preferredPaths, |
|
279 filesNotFound, |
|
280 filesDuplicate); |
|
281 return fullName; |
|
282 } |
|
283 |
|
284 String getProjectName(String fullPath, String extension) |
222 String getProjectName(String fullPath, String extension) |
285 throws IllegalArgumentException, IOException { |
223 throws IllegalArgumentException, IOException { |
286 File file = new File(fullPath).getCanonicalFile(); |
224 File file = new File(fullPath).getCanonicalFile(); |
287 fullPath = file.getCanonicalPath(); |
225 fullPath = file.getCanonicalPath(); |
288 String parent = file.getParent(); |
226 String parent = file.getParent(); |
609 } |
571 } |
610 |
572 |
611 return allConfigs; |
573 return allConfigs; |
612 } |
574 } |
613 |
575 |
614 class FileAttribute { |
|
615 int numConfigs; |
|
616 Vector configs; |
|
617 String shortName; |
|
618 boolean noPch, pchRoot; |
|
619 |
|
620 FileAttribute(String shortName, BuildConfig cfg, int numConfigs) { |
|
621 this.shortName = shortName; |
|
622 this.noPch = (cfg.lookupHashFieldInContext("DisablePch", shortName) != null); |
|
623 this.pchRoot = shortName.equals(BuildConfig.getFieldString(null, "UseToGeneratePch")); |
|
624 this.numConfigs = numConfigs; |
|
625 |
|
626 configs = new Vector(); |
|
627 add(cfg.get("Name")); |
|
628 } |
|
629 |
|
630 void add(String confName) { |
|
631 configs.add(confName); |
|
632 |
|
633 // if presented in all configs |
|
634 if (configs.size() == numConfigs) { |
|
635 configs = null; |
|
636 } |
|
637 } |
|
638 } |
|
639 |
|
640 class FileInfo implements Comparable { |
|
641 String full; |
|
642 FileAttribute attr; |
|
643 |
|
644 FileInfo(String full, FileAttribute attr) { |
|
645 this.full = full; |
|
646 this.attr = attr; |
|
647 } |
|
648 |
|
649 public int compareTo(Object o) { |
|
650 FileInfo oo = (FileInfo)o; |
|
651 return full.compareTo(oo.full); |
|
652 } |
|
653 |
|
654 boolean isHeader() { |
|
655 return attr.shortName.endsWith(".h") || attr.shortName.endsWith(".hpp"); |
|
656 } |
|
657 |
|
658 boolean isCpp() { |
|
659 return attr.shortName.endsWith(".cpp"); |
|
660 } |
|
661 } |
|
662 |
|
663 |
|
664 TreeSet sortFiles(Hashtable allFiles) { |
|
665 TreeSet rv = new TreeSet(); |
|
666 Enumeration e = allFiles.keys(); |
|
667 while (e.hasMoreElements()) { |
|
668 String fullPath = (String)e.nextElement(); |
|
669 rv.add(new FileInfo(fullPath, (FileAttribute)allFiles.get(fullPath))); |
|
670 } |
|
671 return rv; |
|
672 } |
|
673 |
|
674 Hashtable computeAttributedFiles(Vector allConfigs) { |
|
675 Hashtable ht = new Hashtable(); |
|
676 int numConfigs = allConfigs.size(); |
|
677 |
|
678 for (Iterator i = allConfigs.iterator(); i.hasNext(); ) { |
|
679 BuildConfig bc = (BuildConfig)i.next(); |
|
680 Hashtable confFiles = (Hashtable)bc.getSpecificField("AllFilesHash"); |
|
681 String confName = bc.get("Name"); |
|
682 |
|
683 for (Enumeration e=confFiles.keys(); e.hasMoreElements(); ) { |
|
684 String filePath = (String)e.nextElement(); |
|
685 FileAttribute fa = (FileAttribute)ht.get(filePath); |
|
686 |
|
687 if (fa == null) { |
|
688 fa = new FileAttribute((String)confFiles.get(filePath), bc, numConfigs); |
|
689 ht.put(filePath, fa); |
|
690 } else { |
|
691 fa.add(confName); |
|
692 } |
|
693 } |
|
694 } |
|
695 |
|
696 return ht; |
|
697 } |
|
698 |
|
699 Hashtable computeAttributedFiles(BuildConfig bc) { |
|
700 Hashtable ht = new Hashtable(); |
|
701 Hashtable confFiles = (Hashtable)bc.getSpecificField("AllFilesHash"); |
|
702 |
|
703 for (Enumeration e = confFiles.keys(); e.hasMoreElements(); ) { |
|
704 String filePath = (String)e.nextElement(); |
|
705 ht.put(filePath, new FileAttribute((String)confFiles.get(filePath), bc, 1)); |
|
706 } |
|
707 |
|
708 return ht; |
|
709 } |
|
710 |
|
711 PrintWriter printWriter; |
576 PrintWriter printWriter; |
712 |
577 |
713 public void writeProjectFile(String projectFileName, String projectName, |
578 public void writeProjectFile(String projectFileName, String projectName, |
714 Vector<BuildConfig> allConfigs) throws IOException { |
579 Vector<BuildConfig> allConfigs) throws IOException { |
715 throw new RuntimeException("use compiler version specific version"); |
580 throw new RuntimeException("use compiler version specific version"); |
716 } |
581 } |
|
582 |
|
583 int indent; |
|
584 private Stack<String> tagStack = new Stack<String>(); |
|
585 |
|
586 private void startTagPrim(String name, String[] attrs, boolean close) { |
|
587 startTagPrim(name, attrs, close, true); |
|
588 } |
|
589 |
|
590 private void startTagPrim(String name, String[] attrs, boolean close, |
|
591 boolean newline) { |
|
592 doIndent(); |
|
593 printWriter.print("<" + name); |
|
594 indent++; |
|
595 |
|
596 if (attrs != null && attrs.length > 0) { |
|
597 for (int i = 0; i < attrs.length; i += 2) { |
|
598 printWriter.print(" " + attrs[i] + "=\"" + attrs[i + 1] + "\""); |
|
599 if (i < attrs.length - 2) { |
|
600 } |
|
601 } |
|
602 } |
|
603 |
|
604 if (close) { |
|
605 indent--; |
|
606 printWriter.print(" />"); |
|
607 } else { |
|
608 // TODO push tag name, and change endTag to pop and print. |
|
609 tagStack.push(name); |
|
610 printWriter.print(">"); |
|
611 } |
|
612 if (newline) { |
|
613 printWriter.println(); |
|
614 } |
|
615 } |
|
616 |
|
617 void startTag(String name, String... attrs) { |
|
618 startTagPrim(name, attrs, false); |
|
619 } |
|
620 |
|
621 void startTagV(String name, Vector attrs) { |
|
622 String s[] = new String[attrs.size()]; |
|
623 for (int i = 0; i < attrs.size(); i++) { |
|
624 s[i] = (String) attrs.elementAt(i); |
|
625 } |
|
626 startTagPrim(name, s, false); |
|
627 } |
|
628 |
|
629 void endTag() { |
|
630 String name = tagStack.pop(); |
|
631 indent--; |
|
632 doIndent(); |
|
633 printWriter.println("</" + name + ">"); |
|
634 } |
|
635 |
|
636 private void endTagNoIndent() { |
|
637 String name = tagStack.pop(); |
|
638 indent--; |
|
639 printWriter.println("</" + name + ">"); |
|
640 } |
|
641 |
|
642 void tag(String name, String... attrs) { |
|
643 startTagPrim(name, attrs, true); |
|
644 } |
|
645 |
|
646 void tagData(String name, String data) { |
|
647 startTagPrim(name, null, false, false); |
|
648 printWriter.print(data); |
|
649 endTagNoIndent(); |
|
650 } |
|
651 |
|
652 void tagData(String name, String data, String... attrs) { |
|
653 startTagPrim(name, attrs, false, false); |
|
654 printWriter.print(data); |
|
655 endTagNoIndent(); |
|
656 } |
|
657 |
|
658 void tagV(String name, Vector attrs) { |
|
659 String s[] = new String[attrs.size()]; |
|
660 for (int i = 0; i < attrs.size(); i++) { |
|
661 s[i] = (String) attrs.elementAt(i); |
|
662 } |
|
663 startTagPrim(name, s, true); |
|
664 } |
|
665 |
|
666 void doIndent() { |
|
667 for (int i = 0; i < indent; i++) { |
|
668 printWriter.print(" "); |
|
669 } |
|
670 } |
|
671 |
|
672 |
717 } |
673 } |