annotate src/share/tools/ProjectCreator/MacroDefinitions.java @ 2184:5d801e6b9a80

Imported build system changes from other repository.
author Thomas Wuerthinger <thomas.wuerthinger@gmail.com>
date Mon, 21 Feb 2011 19:17:10 +0100
parents f95d63e2154a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
2 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 import java.io.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
26 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28 public class MacroDefinitions {
a61af66fc99e Initial load
duke
parents:
diff changeset
29 private Vector macros;
a61af66fc99e Initial load
duke
parents:
diff changeset
30
a61af66fc99e Initial load
duke
parents:
diff changeset
31 public MacroDefinitions() {
a61af66fc99e Initial load
duke
parents:
diff changeset
32 macros = new Vector();
a61af66fc99e Initial load
duke
parents:
diff changeset
33 }
a61af66fc99e Initial load
duke
parents:
diff changeset
34
a61af66fc99e Initial load
duke
parents:
diff changeset
35 public void addMacro(String name, String contents) {
a61af66fc99e Initial load
duke
parents:
diff changeset
36 Macro macro = new Macro();
a61af66fc99e Initial load
duke
parents:
diff changeset
37 macro.name = name;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 macro.contents = contents;
a61af66fc99e Initial load
duke
parents:
diff changeset
39 macros.add(macro);
a61af66fc99e Initial load
duke
parents:
diff changeset
40 }
a61af66fc99e Initial load
duke
parents:
diff changeset
41
a61af66fc99e Initial load
duke
parents:
diff changeset
42 private boolean lineIsEmpty(String s) {
a61af66fc99e Initial load
duke
parents:
diff changeset
43 for (int i = 0; i < s.length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
44 if (!Character.isWhitespace(s.charAt(i))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
45 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
46 }
a61af66fc99e Initial load
duke
parents:
diff changeset
47 }
a61af66fc99e Initial load
duke
parents:
diff changeset
48 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
49 }
a61af66fc99e Initial load
duke
parents:
diff changeset
50
a61af66fc99e Initial load
duke
parents:
diff changeset
51 public void readFrom(String fileName, boolean missingOk)
a61af66fc99e Initial load
duke
parents:
diff changeset
52 throws FileNotFoundException, FileFormatException, IOException {
a61af66fc99e Initial load
duke
parents:
diff changeset
53 BufferedReader reader = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
54 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
55 reader = new BufferedReader(new FileReader(fileName));
a61af66fc99e Initial load
duke
parents:
diff changeset
56 } catch (FileNotFoundException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
57 if (missingOk) {
a61af66fc99e Initial load
duke
parents:
diff changeset
58 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
59 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
60 throw(e);
a61af66fc99e Initial load
duke
parents:
diff changeset
61 }
a61af66fc99e Initial load
duke
parents:
diff changeset
62 }
a61af66fc99e Initial load
duke
parents:
diff changeset
63 String line;
a61af66fc99e Initial load
duke
parents:
diff changeset
64 do {
a61af66fc99e Initial load
duke
parents:
diff changeset
65 line = reader.readLine();
a61af66fc99e Initial load
duke
parents:
diff changeset
66 if (line != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
67 // This had to be rewritten (compare to Database.java)
a61af66fc99e Initial load
duke
parents:
diff changeset
68 // because the Solaris platform file has been
a61af66fc99e Initial load
duke
parents:
diff changeset
69 // repurposed and now contains "macros" with spaces in
a61af66fc99e Initial load
duke
parents:
diff changeset
70 // them.
a61af66fc99e Initial load
duke
parents:
diff changeset
71
a61af66fc99e Initial load
duke
parents:
diff changeset
72 if ((!line.startsWith("//")) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
73 (!lineIsEmpty(line))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
74 int nameBegin = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
75 int nameEnd = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
76 boolean gotEquals = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
77 int contentsBegin = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
78 int contentsEnd = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
79
a61af66fc99e Initial load
duke
parents:
diff changeset
80 int i = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
81 // Scan forward for beginning of name
a61af66fc99e Initial load
duke
parents:
diff changeset
82 while (i < line.length()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
83 if (!Character.isWhitespace(line.charAt(i))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
84 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
85 }
a61af66fc99e Initial load
duke
parents:
diff changeset
86 i++;
a61af66fc99e Initial load
duke
parents:
diff changeset
87 }
a61af66fc99e Initial load
duke
parents:
diff changeset
88 nameBegin = i;
a61af66fc99e Initial load
duke
parents:
diff changeset
89
a61af66fc99e Initial load
duke
parents:
diff changeset
90 // Scan forward for end of name
a61af66fc99e Initial load
duke
parents:
diff changeset
91 while (i < line.length()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
92 if (Character.isWhitespace(line.charAt(i))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
93 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
94 }
a61af66fc99e Initial load
duke
parents:
diff changeset
95 i++;
a61af66fc99e Initial load
duke
parents:
diff changeset
96 }
a61af66fc99e Initial load
duke
parents:
diff changeset
97 nameEnd = i;
a61af66fc99e Initial load
duke
parents:
diff changeset
98
a61af66fc99e Initial load
duke
parents:
diff changeset
99 // Scan forward for equals sign
a61af66fc99e Initial load
duke
parents:
diff changeset
100 while (i < line.length()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
101 if (line.charAt(i) == '=') {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 gotEquals = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
103 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
104 }
a61af66fc99e Initial load
duke
parents:
diff changeset
105 i++;
a61af66fc99e Initial load
duke
parents:
diff changeset
106 }
a61af66fc99e Initial load
duke
parents:
diff changeset
107
a61af66fc99e Initial load
duke
parents:
diff changeset
108 // Scan forward for start of contents
a61af66fc99e Initial load
duke
parents:
diff changeset
109 i++;
a61af66fc99e Initial load
duke
parents:
diff changeset
110 while (i < line.length()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
111 if (!Character.isWhitespace(line.charAt(i))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
112 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
113 }
a61af66fc99e Initial load
duke
parents:
diff changeset
114 i++;
a61af66fc99e Initial load
duke
parents:
diff changeset
115 }
a61af66fc99e Initial load
duke
parents:
diff changeset
116 contentsBegin = i;
a61af66fc99e Initial load
duke
parents:
diff changeset
117
a61af66fc99e Initial load
duke
parents:
diff changeset
118 // Scan *backward* for end of contents
a61af66fc99e Initial load
duke
parents:
diff changeset
119 i = line.length() - 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
120 while (i >= 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
121 if (!Character.isWhitespace(line.charAt(i))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
122 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
123 }
a61af66fc99e Initial load
duke
parents:
diff changeset
124 }
a61af66fc99e Initial load
duke
parents:
diff changeset
125 contentsEnd = i+1;
a61af66fc99e Initial load
duke
parents:
diff changeset
126
a61af66fc99e Initial load
duke
parents:
diff changeset
127 // Now do consistency check
a61af66fc99e Initial load
duke
parents:
diff changeset
128 if (!((nameBegin < nameEnd) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
129 (nameEnd < contentsBegin) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
130 (contentsBegin < contentsEnd) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
131 (gotEquals == true))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
132 throw new FileFormatException(
a61af66fc99e Initial load
duke
parents:
diff changeset
133 "Expected \"macroname = value\", " +
a61af66fc99e Initial load
duke
parents:
diff changeset
134 "but found: " + line
a61af66fc99e Initial load
duke
parents:
diff changeset
135 );
a61af66fc99e Initial load
duke
parents:
diff changeset
136 }
a61af66fc99e Initial load
duke
parents:
diff changeset
137
a61af66fc99e Initial load
duke
parents:
diff changeset
138 String name = line.substring(nameBegin, nameEnd);
a61af66fc99e Initial load
duke
parents:
diff changeset
139 String contents = line.substring(contentsBegin,
a61af66fc99e Initial load
duke
parents:
diff changeset
140 contentsEnd);
a61af66fc99e Initial load
duke
parents:
diff changeset
141 addMacro(name, contents);
a61af66fc99e Initial load
duke
parents:
diff changeset
142 }
a61af66fc99e Initial load
duke
parents:
diff changeset
143 }
a61af66fc99e Initial load
duke
parents:
diff changeset
144 } while (line != null);
a61af66fc99e Initial load
duke
parents:
diff changeset
145 reader.close();
a61af66fc99e Initial load
duke
parents:
diff changeset
146 }
a61af66fc99e Initial load
duke
parents:
diff changeset
147
a61af66fc99e Initial load
duke
parents:
diff changeset
148 /** This returns an Iterator of Macros. You should not mutate the
a61af66fc99e Initial load
duke
parents:
diff changeset
149 returned Macro objects or use the Iterator to remove
a61af66fc99e Initial load
duke
parents:
diff changeset
150 macros. */
a61af66fc99e Initial load
duke
parents:
diff changeset
151 public Iterator getMacros() {
a61af66fc99e Initial load
duke
parents:
diff changeset
152 return macros.iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
153 }
a61af66fc99e Initial load
duke
parents:
diff changeset
154 }