Source Code Cross Referenced for AntSchemaFix.java in  » Issue-Tracking » scarab-0.21 » org » tigris » scarab » util » build » 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 » Issue Tracking » scarab 0.21 » org.tigris.scarab.util.build 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.tigris.scarab.util.build;
002:
003:        /* ================================================================
004:         * Copyright (c) 2000-2002 CollabNet.  All rights reserved.
005:         * 
006:         * Redistribution and use in source and binary forms, with or without
007:         * modification, are permitted provided that the following conditions are
008:         * met:
009:         * 
010:         * 1. Redistributions of source code must retain the above copyright
011:         * notice, this list of conditions and the following disclaimer.
012:         * 
013:         * 2. Redistributions in binary form must reproduce the above copyright
014:         * notice, this list of conditions and the following disclaimer in the
015:         * documentation and/or other materials provided with the distribution.
016:         * 
017:         * 3. The end-user documentation included with the redistribution, if
018:         * any, must include the following acknowlegement: "This product includes
019:         * software developed by Collab.Net <http://www.Collab.Net/>."
020:         * Alternately, this acknowlegement may appear in the software itself, if
021:         * and wherever such third-party acknowlegements normally appear.
022:         * 
023:         * 4. The hosted project names must not be used to endorse or promote
024:         * products derived from this software without prior written
025:         * permission. For written permission, please contact info@collab.net.
026:         * 
027:         * 5. Products derived from this software may not use the "Tigris" or 
028:         * "Scarab" names nor may "Tigris" or "Scarab" appear in their names without 
029:         * prior written permission of Collab.Net.
030:         * 
031:         * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
032:         * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
033:         * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
034:         * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
035:         * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
036:         * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
037:         * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
038:         * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
039:         * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
040:         * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
041:         * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
042:         *
043:         * ====================================================================
044:         * 
045:         * This software consists of voluntary contributions made by many
046:         * individuals on behalf of Collab.Net.
047:         */
048:
049:        import java.io.File;
050:        import java.io.FileWriter;
051:
052:        import org.apache.oro.text.regex.MalformedPatternException;
053:        import org.apache.tools.ant.BuildException;
054:        import org.apache.tools.ant.Task;
055:        import org.tigris.scarab.util.RegexProcessor;
056:
057:        /**
058:         * This class is used as ant task backend for the generation
059:         * of a property file by use of a template file.
060:         *
061:         * @author <a href="mailto:dabbous@saxess.com">Hussayn Dabbous</a>
062:         * @version $Id: AntPropertyFileGenerator.java 9421 2005-02-20 22:32:38Z jorgeuriarte $
063:         */
064:
065:        public class AntSchemaFix extends Task implements  PropertyGetter {
066:            File sourceFile;
067:            File targetFile;
068:            String dbtype;
069:
070:            /**
071:             * Source schema file to be fixed.
072:             * @param theSourceFileName
073:             */
074:            public void setSource(String theSourceFileName) {
075:                sourceFile = new File(adjust(theSourceFileName));
076:                if (!sourceFile.exists()) {
077:                    System.out.println("wd=[" + System.getProperty("user.dir")
078:                            + "]");
079:                    System.out.println("bd=[" + this .getProject().getBaseDir()
080:                            + "]");
081:                    throw new BuildException("the source file ["
082:                            + theSourceFileName + "] does not exist.");
083:                }
084:
085:                if (!sourceFile.canWrite()) {
086:                    throw new BuildException("the source file["
087:                            + theSourceFileName + "] is not writable.");
088:                }
089:
090:            }
091:
092:            /**
093:             * @param theFileName
094:             * @return
095:             */
096:            private String adjust(String theFileName) {
097:                String baseDir = this .getProject().getBaseDir()
098:                        .getAbsolutePath();
099:                System.setProperty("user.dir", baseDir);
100:
101:                String result = theFileName;
102:                if (!theFileName.startsWith("/") // this is for unix
103:                        && !theFileName.startsWith("\\") // this is for windows
104:                        && theFileName.charAt(1) != (':') // this is for windows
105:                ) {
106:                    result = baseDir + File.separator + theFileName;
107:                }
108:
109:                return result;
110:            }
111:
112:            /**
113:             * target schema file to be created.
114:             * @param theTargetFileName
115:             */
116:            public void setTarget(String theTargetFileName) {
117:
118:                targetFile = new File(adjust(theTargetFileName));
119:                if (targetFile.exists()) {
120:                    targetFile.delete();
121:                }
122:
123:            }
124:
125:            /**
126:             * database type for which to run the fix.
127:             * currently only hypersonic needs a fix.
128:             * @param theDbtype
129:             */
130:            public void setDbtype(String theDbtype) {
131:                dbtype = theDbtype;
132:            }
133:
134:            /**
135:             * fix schema-file if dbtype is hypersonic.
136:             * due to an error in the hypersonic-torque generator.
137:             */
138:            public void execute() {
139:                if (dbtype.equals("hypersonic")) {
140:                    System.out.println("dbtype \"" + dbtype
141:                            + "\" needs fixes ...");
142:                    fixHsqlSchema();
143:                } else {
144:                    System.out.println("dbtype \"" + dbtype + "\" is clean.");
145:                }
146:            }
147:
148:            /**
149:             * replace "integer(...)" by "integer"
150:             * replace "DELETED ... ," by "DELETED integer DEFAULT 0,"
151:             * @param sourceFile
152:             * @param targetFile
153:             */
154:            private void fixHsqlSchema() {
155:                try {
156:
157:                    boolean modifySelf = false;
158:
159:                    if (targetFile == null) {
160:                        String targetFileName = sourceFile.getPath() + "tmp";
161:                        setTarget(targetFileName);
162:                        modifySelf = true;
163:                    }
164:
165:                    java.io.BufferedReader rdr = new java.io.BufferedReader(
166:                            new java.io.FileReader(sourceFile));
167:                    FileWriter fw = new java.io.FileWriter(targetFile);
168:                    java.io.BufferedWriter wrtr = new java.io.BufferedWriter(fw);
169:
170:                    String str;
171:                    RegexProcessor processor = new RegexProcessor();
172:                    while ((str = rdr.readLine()) != null) {
173:
174:                        String fstr = processor.process(str,
175:                                "integer \\(\\d+\\)", "integer");
176:                        fstr = processor.process(fstr,
177:                                "DELETED\\s+integer[^,]*,",
178:                                "DELETED integer DEFAULT 0,");
179:
180:                        //if(!fstr.equals(str))
181:                        //{
182:                        //    System.out.println("old: "+str);
183:                        //    System.out.println("new: "+fstr);
184:                        //}
185:
186:                        wrtr.write(fstr);
187:                        wrtr.newLine();
188:                    }
189:                    rdr.close();
190:                    wrtr.close();
191:
192:                    if (modifySelf) {
193:                        sourceFile.delete();
194:                        targetFile.renameTo(sourceFile);
195:                        System.out.println("replaced [" + sourceFile.getPath()
196:                                + "]...");
197:                    } else {
198:                        System.out.println("created [" + targetFile.getPath()
199:                                + "]...");
200:                    }
201:
202:                }
203:
204:                catch (java.io.IOException e1) {
205:                    throw new BuildException(
206:                            "IOException while processing Hsql-schema.["
207:                                    + e1.getMessage() + "]");
208:                }
209:
210:                catch (MalformedPatternException e2) {
211:                    throw new BuildException(
212:                            "Regex Error while processing Hsql-schema.["
213:                                    + e2.getMessage() + "]");
214:                }
215:
216:            }
217:
218:            /**
219:             * dummy method. Not used.
220:             * @param name
221:             * @return
222:             */
223:            public Object getProperty(String name, Object def) {
224:                throw new BuildException(
225:                        "Tried to getProperty() from non implemented method.");
226:            }
227:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.