Source Code Cross Referenced for Config.java in  » Testing » KeY » de » uka » ilkd » key » util » make » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Testing » KeY » de.uka.ilkd.key.util.make 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // This file is part of KeY - Integrated Deductive Software Design
002:        // Copyright (C) 2001-2007 Universitaet Karlsruhe, Germany
003:        //                         Universitaet Koblenz-Landau, Germany
004:        //                         Chalmers University of Technology, Sweden
005:        //
006:        // The KeY system is protected by the GNU General Public License. 
007:        // See LICENSE.TXT for details.
008:        //
009:        //
010:
011:        /** this class parses in a config file that has to use the following grammar:
012:         *  S -> (IDENTIFIER ':'  (alles ausser ';')* ';')* 
013:         *  then it creates files that can refer to the first IDENTIFIER by using
014:         *  @IDENTIFIER@ that will be replaced by the expression after the ':'
015:         *  and before ';'
016:         */package de.uka.ilkd.key.util.make;
017:
018:        import java.io.*;
019:        import java.net.URL;
020:        import java.util.HashMap;
021:        import java.util.Properties;
022:
023:        public class Config {
024:
025:            private Config() {
026:            }
027:
028:            private static final Config unique = new Config();
029:
030:            //these two can't be made local to, say, GFinterface because of 
031:            //static loading
032:            public static File GF_PATH_FILE = new File(
033:                    de.uka.ilkd.key.gui.configuration.PathConfig.KEY_CONFIG_DIR
034:                            + File.separator + "gf-path.props");
035:
036:            public static final String GF_PATH_KEY = "[GFPath]";
037:
038:            public static File SIMPLIFY_PATH_FILE = new File(
039:                    de.uka.ilkd.key.gui.configuration.PathConfig.KEY_CONFIG_DIR
040:                            + File.separator + "simplify-path.props");
041:
042:            public static final String SIMPLIFY_PATH_KEY = "[SimplifyPath]";
043:
044:            static HashMap map = new HashMap();
045:
046:            /** loads a resource and returns its URL 
047:             * @param cl the Class used to determine the resource 
048:             * @param resourcename the String that contains the name of the resource
049:             * @return the URL of the resource
050:             */
051:            public static URL getResourceFile(Class cl, String resourcename) {
052:                URL resourceURL = cl.getResource(resourcename);
053:                if (resourceURL == null && cl.getSuperclass() != null) {
054:                    return getResourceFile(cl.getSuperclass(), resourcename);
055:                } else if (resourceURL == null && cl.getSuperclass() == null) {
056:                    return null;
057:                }
058:                return resourceURL;
059:            }
060:
061:            /** loads a resource and returns its URL 
062:             * @param o the Object used to determine the resource 
063:             * @param resourcename the String that contains the name of the resource
064:             * @return the URL of the resource
065:             */
066:            private static URL getResourceFile(Object o, String resourcename) {
067:                return getResourceFile(o.getClass(), resourcename);
068:            }
069:
070:            /** reads until character char is found and return alls read signs without
071:             * character last */
072:            private static StringBuffer readUntil(InputStreamReader fr,
073:                    char last) {
074:                StringBuffer result = new StringBuffer();
075:                try {
076:                    int chr = fr.read();
077:                    while (chr != -1 && ((char) chr) != last) {
078:                        if (((char) chr) != '\n' && ((char) chr) != '\r'
079:                                && ((char) chr) != '\t') { //&& ((char)chr)!=' '
080:                            result.append((char) chr);
081:                        }
082:                        chr = fr.read();
083:                    }
084:                } catch (IOException io) {
085:                    System.err
086:                            .println("Error occured while reading config file.");
087:                    System.err.println(io);
088:                    System.exit(-1);
089:                }
090:                return result;
091:            }
092:
093:            private static int readIdentifier(FileReader fr) {
094:                StringBuffer identifier = new StringBuffer();
095:                identifier = readUntil(fr, '[');
096:                if (identifier.length() == 0)
097:                    return -1;
098:                if (identifier.length() == 0) {
099:                    throw new RuntimeException("IDENTIFIER EXPECTED.");
100:                }
101:                StringBuffer path = new StringBuffer();
102:                path = readUntil(fr, ']');
103:
104:                StringBuffer result = (StringBuffer) map.get(identifier);
105:                if (map.get(identifier.toString()) == null) {
106:                    map.put(identifier.toString(), path);
107:                } else {
108:                    result.append(File.pathSeparator + path);
109:                }
110:                return 0;
111:            }
112:
113:            private static void createFile(String filename, String template) {
114:                InputStreamReader fr = null;
115:                FileWriter fw = null;
116:                try {
117:                    fr = new InputStreamReader(
118:                            getResourceFile(unique, template).openStream());
119:                    fw = new FileWriter(filename);
120:                    int chr = fr.read();
121:                    while (chr != -1) {
122:                        if (((char) chr) != '@') {
123:                            fw.write(chr);
124:                        } else {
125:                            StringBuffer res = readUntil(fr, '@');
126:                            if (map.get(res.toString()) == null) {
127:                                System.err.println("Identifier " + res
128:                                        + " not defined");
129:                                System.exit(-1);
130:                            }
131:                            String repl = map.get(res.toString()).toString();
132:                            fw.write(repl, 0, repl.length());
133:                        }
134:                        chr = fr.read();
135:                    }
136:                    fr.close();
137:                    fw.close();
138:                } catch (IOException io) {
139:                    System.err.println("File " + filename
140:                            + " can not be written.\n" + io);
141:                    System.exit(-1);
142:                }
143:            }
144:
145:            private static void writeToKeYConfig(File file, String header,
146:                    String key, String prop) {
147:                if (!file.exists()) {
148:                    new File(
149:                            de.uka.ilkd.key.gui.configuration.PathConfig.KEY_CONFIG_DIR
150:                                    + File.separator).mkdir();
151:                }
152:                try {
153:                    FileOutputStream out = new FileOutputStream(file);
154:                    Properties props = new Properties();
155:                    props.setProperty(key, prop);
156:                    props.store(out, header);
157:                } catch (Exception e) {
158:                    System.err
159:                            .println("Could not write property to config file "
160:                                    + file);
161:                }
162:            }
163:
164:            /** args[0] contains the file with the config infromation
165:             * args[1] if dev use development templates else dist templates
166:             */
167:            public static void main(String args[]) {
168:                FileReader fr = null;
169:                try {
170:                    fr = new FileReader(args[0]);
171:                    map = new HashMap();
172:                    while (readIdentifier(fr) != -1) {
173:                    }
174:                    fr.close();
175:                } catch (IOException io) {
176:                    System.err.println("File " + args[0] + " not found");
177:                    System.exit(-1);
178:                }
179:                if ("dev".equals(args[1])) {
180:                    createFile("install_dev.key", "install_dev.template");
181:                    createFile("Makefile.mk", "config.template");
182:                    createFile("runTests", "runTests.template");
183:                    createFile("runProver", "runProver.template");
184:                    createFile("runJava", "runJava.template");
185:                    createFile("miscConfigExtension",
186:                            "miscConfigExtension_dev.template");
187:                    if ("50".equals(args[2])) {
188:                        createFile("startkey", "startkey_dev_50.template");
189:                    } else if ("55".equals(args[2])) {
190:                        createFile("startkey", "startkey_dev_55.template");
191:                    } else {
192:                        createFile("startkey", "startkey_dev_60.template");
193:                        createFile("startkey.bat", "startkey_60_bat.template");
194:                    }
195:                } else if ("dist".equals(args[1])) {
196:                    createFile("install.key", "install.template");
197:                    createFile("miscConfigExtension",
198:                            "miscConfigExtension.template");
199:                    if ("50".equals(args[2])) {
200:                        createFile("startkey", "startkey_50.template");
201:                    } else if ("55".equals(args[2])) {
202:                        createFile("startkey", "startkey_55.template");
203:                    } else {
204:                        createFile("startkey", "startkey_60.template");
205:                        createFile("startkey.bat", "startkey_60_bat.template");
206:                    }
207:                }
208:                createFile("configDefaultSnapShot",
209:                        "configDefaultSnapShot.template");
210:                if (args.length > 3 && args[3] != null && !("".equals(args[3]))) {
211:                    writeToKeYConfig(GF_PATH_FILE, "GF-Path-File", GF_PATH_KEY,
212:                            args[3]);
213:                }
214:                if (args.length > 4 && args[4] != null && !("".equals(args[4]))) {
215:                    writeToKeYConfig(SIMPLIFY_PATH_FILE, "Simplify-Path-File",
216:                            SIMPLIFY_PATH_KEY, args[4]);
217:                }
218:            }
219:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.