Source Code Cross Referenced for JaxxcAntTask.java in  » XML-UI » JAXX » jaxx » 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 » XML UI » JAXX » jaxx 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2006 Ethan Nicholas. All rights reserved.
003:         * Use is subject to license terms.
004:         */
005:        package jaxx;
006:
007:        import java.io.*;
008:        import java.lang.reflect.*;
009:        import java.net.*;
010:        import java.util.*;
011:        import org.apache.tools.ant.*;
012:        import org.apache.tools.ant.taskdefs.*;
013:        import org.apache.tools.ant.util.*;
014:
015:        import jaxx.compiler.*;
016:
017:        public class JaxxcAntTask extends MatchingTask {
018:            private File srcDir;
019:            private File destDir;
020:            private String classPath;
021:            private boolean keepJavaFiles;
022:            private boolean optimize;
023:            private boolean runJavac = true;
024:            private String javacOpts;
025:            protected File[] compileList = new File[0];
026:
027:            // add dt.jar to the system class path so Introspector will find the JAXXBeanInfos
028:            public void init() {
029:                URL resourceURL = JaxxcAntTask.class.getClassLoader()
030:                        .getResource("javax/swing/JButtonBeanInfo.class");
031:                String resourceString = resourceURL != null ? resourceURL
032:                        .toString() : null;
033:                if (resourceURL == null || !resourceString.startsWith("jar:"))
034:                    throw new BuildException(
035:                            "could not find dt.jar on classpath");
036:                try {
037:                    URL jarURL = new URL(resourceString.substring("jar:"
038:                            .length(), resourceString.indexOf("!")));
039:                    URLClassLoader classLoader = (URLClassLoader) ClassLoader
040:                            .getSystemClassLoader();
041:                    Method addURL = URLClassLoader.class.getDeclaredMethod(
042:                            "addURL", new Class[] { URL.class });
043:                    addURL.setAccessible(true);
044:                    addURL.invoke(classLoader, new Object[] { jarURL });
045:                } catch (Exception e) {
046:                    throw new BuildException(e);
047:                }
048:            }
049:
050:            public void execute() {
051:                checkParameters();
052:                resetFileLists();
053:                DirectoryScanner ds = getDirectoryScanner(srcDir);
054:                String[] files = ds.getIncludedFiles();
055:                scanDir(srcDir, destDir != null ? destDir : srcDir, files);
056:                if (compileList.length > 0) {
057:                    log("Compiling " + compileList.length + " source file"
058:                            + (compileList.length == 1 ? "" : "s")
059:                            + (destDir != null ? " to " + destDir : ""));
060:                    compile();
061:                }
062:            }
063:
064:            private void checkParameters() {
065:                if (srcDir == null) {
066:                    throw new BuildException("srcdir attribute must be set!",
067:                            getLocation());
068:                }
069:
070:                if (!srcDir.isDirectory()) {
071:                    throw new BuildException("source directory \"" + srcDir
072:                            + "\" does not exist " + "or is not a directory",
073:                            getLocation());
074:                }
075:
076:                if (destDir != null && !destDir.isDirectory()) {
077:                    throw new BuildException("destination directory \""
078:                            + destDir + "\" does not exist "
079:                            + "or is not a directory", getLocation());
080:                }
081:            }
082:
083:            private void compile() {
084:                CompilerOptions options = new CompilerOptions();
085:                if (classPath == null)
086:                    classPath = srcDir.getPath();
087:                else
088:                    classPath = srcDir + File.pathSeparator + classPath;
089:                options.setClassPath(classPath);
090:                options.setTargetDirectory(destDir);
091:                options.setKeepJavaFiles(keepJavaFiles);
092:                options.setOptimize(optimize);
093:                options.setRunJavac(runJavac);
094:                options.setJavacOpts(javacOpts);
095:                String[] files = new String[compileList.length];
096:                for (int i = 0; i < compileList.length; i++)
097:                    if (compileList[i].getPath().startsWith(srcDir.getPath())) {
098:                        files[i] = compileList[i].getPath().substring(
099:                                srcDir.getPath().length());
100:                        if (files[i].startsWith(File.separator))
101:                            files[i] = files[i].substring(1);
102:                    } else
103:                        files[i] = compileList[i].getPath();
104:                if (!JAXXCompiler.compile(srcDir, files, options))
105:                    throw new BuildException(
106:                            "Aborting due to errors reported by jaxxc");
107:            }
108:
109:            public void setSrcDir(File srcDir) {
110:                this .srcDir = srcDir;
111:            }
112:
113:            public void setDestDir(File destDir) {
114:                this .destDir = destDir;
115:            }
116:
117:            public void setClassPath(String classPath) {
118:                this .classPath = classPath;
119:            }
120:
121:            public void setKeepJavaFiles(boolean keepJavaFiles) {
122:                this .keepJavaFiles = keepJavaFiles;
123:            }
124:
125:            public void setOptimize(boolean optimize) {
126:                this .optimize = optimize;
127:            }
128:
129:            public void setRunJavac(boolean runJavac) {
130:                this .runJavac = runJavac;
131:            }
132:
133:            public void setJavacOptions(String javacOpts) {
134:                this .javacOpts = javacOpts;
135:            }
136:
137:            /**
138:             * Clear the list of files to be compiled and copied..
139:             */
140:            protected void resetFileLists() {
141:                compileList = new File[0];
142:            }
143:
144:            /**
145:             * Scans the directory looking for source files to be compiled.
146:             * The results are returned in the class variable compileList
147:             *
148:             * @param srcDir   The source directory
149:             * @param destDir  The destination directory
150:             * @param files    An array of filenames
151:             */
152:            protected void scanDir(File srcDir, File destDir, String[] files) {
153:                GlobPatternMapper m = new GlobPatternMapper();
154:                m.setFrom("*.jaxx");
155:                m.setTo("*.class");
156:                SourceFileScanner sfs = new SourceFileScanner(this );
157:                File[] jaxxFiles = sfs.restrictAsFiles(files, srcDir, destDir,
158:                        m);
159:                m.setFrom("*.css");
160:                File[] cssFiles = sfs
161:                        .restrictAsFiles(files, srcDir, destDir, m);
162:                m.setFrom("*.script");
163:                File[] scriptFiles = sfs.restrictAsFiles(files, srcDir,
164:                        destDir, m);
165:
166:                Set/*<File>*/newFiles = new HashSet/*<File>*/(Arrays
167:                        .asList(jaxxFiles));
168:                // if we find an updated .css or .script file, check for a corresponding .jaxx file
169:                for (int i = 0; i < cssFiles.length; i++) {
170:                    String path = cssFiles[i].getPath();
171:                    File jaxxFile = new File(path.substring(0, path.length()
172:                            - ".css".length())
173:                            + ".jaxx");
174:                    if (jaxxFile.exists())
175:                        newFiles.add(jaxxFile);
176:                }
177:                for (int i = 0; i < scriptFiles.length; i++) {
178:                    String path = scriptFiles[i].getPath();
179:                    File jaxxFile = new File(path.substring(0, path.length()
180:                            - ".script".length())
181:                            + ".jaxx");
182:                    if (jaxxFile.exists())
183:                        newFiles.add(jaxxFile);
184:                }
185:
186:                if (newFiles.size() > 0) {
187:                    File[] newCompileList = new File[compileList.length
188:                            + newFiles.size()];
189:                    System.arraycopy(compileList, 0, newCompileList, 0,
190:                            compileList.length);
191:                    System.arraycopy(newFiles.toArray(), 0, newCompileList,
192:                            compileList.length, newFiles.size());
193:                    compileList = newCompileList;
194:                }
195:            }
196:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.