Source Code Cross Referenced for AptTask.java in  » J2EE » Pustefix » de » schlund » pfixcore » generator » iwrpgen » 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 » J2EE » Pustefix » de.schlund.pfixcore.generator.iwrpgen 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * This file is part of PFIXCORE.
003:         *
004:         * PFIXCORE is free software; you can redistribute it and/or modify
005:         * it under the terms of the GNU Lesser General Public License as published by
006:         * the Free Software Foundation; either version 2 of the License, or
007:         * (at your option) any later version.
008:         *
009:         * PFIXCORE is distributed in the hope that it will be useful,
010:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012:         * GNU Lesser General Public License for more details.
013:         *
014:         * You should have received a copy of the GNU Lesser General Public License
015:         * along with PFIXCORE; if not, write to the Free Software
016:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
017:         *
018:         */
019:
020:        package de.schlund.pfixcore.generator.iwrpgen;
021:
022:        import java.io.File;
023:        import java.io.FileWriter;
024:        import java.io.IOException;
025:        import java.io.PrintWriter;
026:        import java.util.ArrayList;
027:        import java.util.List;
028:
029:        import org.apache.tools.ant.BuildException;
030:        import org.apache.tools.ant.Project;
031:        import org.apache.tools.ant.taskdefs.Execute;
032:        import org.apache.tools.ant.taskdefs.LogStreamHandler;
033:        import org.apache.tools.ant.taskdefs.MatchingTask;
034:        import org.apache.tools.ant.types.Commandline;
035:        import org.apache.tools.ant.types.Path;
036:        import org.apache.tools.ant.types.Reference;
037:
038:        /**
039:         * 
040:         * @author mleidig@schlund.de
041:         * 
042:         */
043:        public class AptTask extends MatchingTask {
044:
045:            private File lastAptRunFile = new File("build/.lastaptrun");
046:            private Path srcDir;
047:            private File destDir;
048:            private File preprocessDir;
049:            private String factory;
050:            private Path classPath;
051:            private String encoding;
052:
053:            @Override
054:            public void execute() throws BuildException {
055:                long lastAptRun = lastAptRunFile.lastModified();
056:                List<File> modList = getModifiedFiles(lastAptRun);
057:                if (modList.size() > 0) {
058:                    log("Processing " + modList.size() + " source file"
059:                            + (modList.size() > 1 ? "s" : ""));
060:                    Commandline cmd = new Commandline();
061:                    cmd.setExecutable("apt");
062:                    cmd.createArgument().setValue("-J-Xmx512m");
063:                    cmd.createArgument().setValue("-classpath");
064:                    classPath.addExisting(classPath.concatSystemClasspath());
065:                    cmd.createArgument().setPath(classPath);
066:                    cmd.createArgument().setValue("-sourcepath");
067:                    cmd.createArgument().setPath(srcDir);
068:                    cmd.createArgument().setValue("-nocompile");
069:                    cmd.createArgument().setValue("-encoding");
070:                    cmd.createArgument().setValue(encoding);
071:                    cmd.createArgument().setValue("-factory");
072:                    cmd.createArgument().setValue(factory);
073:                    cmd.createArgument().setValue("-s");
074:                    cmd.createArgument().setFile(preprocessDir);
075:                    int firstFileIndex = cmd.size();
076:                    for (File file : modList)
077:                        cmd.createArgument().setValue(file.getAbsolutePath());
078:                    log(cmd.toString(), Project.MSG_DEBUG);
079:                    callApt(cmd.getCommandline(), firstFileIndex);
080:                }
081:                lastAptRunFile.delete();
082:                try {
083:                    lastAptRunFile.createNewFile();
084:                } catch (IOException x) {
085:                }
086:            }
087:
088:            private List<File> getModifiedFiles(long lastAptRun)
089:                    throws BuildException {
090:                IWrapperFileScanner fileScanner = new IWrapperFileScanner();
091:                List<File> modList = new ArrayList<File>();
092:                String[] dirs = srcDir.list();
093:                for (int i = 0; i < dirs.length; i++) {
094:                    File dir = getProject().resolveFile(dirs[i]);
095:                    if (!dir.exists())
096:                        throw new BuildException(
097:                                "Source directory doesn't exist: "
098:                                        + dir.getAbsolutePath(), getLocation());
099:                    List<File> newFiles = fileScanner.getChangedFiles(dir,
100:                            destDir, lastAptRun);
101:                    modList.addAll(newFiles);
102:                }
103:                if (fileScanner.getScanCount() > 0)
104:                    System.out.println(fileScanner.printStatistics());
105:                return modList;
106:            }
107:
108:            private void callApt(String[] args, int firstFileIndex) {
109:                File tmpFile = null;
110:                try {
111:                    String[] commandArray = null;
112:                    if (Commandline.toString(args).length() > 4096
113:                            && firstFileIndex >= 0) {
114:                        PrintWriter out = null;
115:                        try {
116:                            tmpFile = File.createTempFile("pfx-aptfiles-",
117:                                    ".tmp", null);
118:                            log("Commandline too long, using temporary file '"
119:                                    + tmpFile.getAbsolutePath() + "'.",
120:                                    Project.MSG_DEBUG);
121:                            tmpFile.deleteOnExit();
122:                            out = new PrintWriter(new FileWriter(tmpFile));
123:                            for (int i = firstFileIndex; i < args.length; i++) {
124:                                if (args[i].indexOf(" ") > -1) {
125:                                    args[i] = args[i].replace(
126:                                            File.separatorChar, '/');
127:                                    out.println("\"" + args[i] + "\"");
128:                                } else
129:                                    out.println(args[i]);
130:                            }
131:                            out.flush();
132:                            commandArray = new String[firstFileIndex + 1];
133:                            System.arraycopy(args, 0, commandArray, 0,
134:                                    firstFileIndex);
135:                            commandArray[firstFileIndex] = "@" + tmpFile;
136:                        } catch (IOException x) {
137:                            throw new BuildException(
138:                                    "Error creating temporary file", x,
139:                                    getLocation());
140:                        } finally {
141:                            out.close();
142:                        }
143:                    } else {
144:                        commandArray = args;
145:                    }
146:                    try {
147:                        Execute exec = new Execute(new LogStreamHandler(this ,
148:                                Project.MSG_INFO, Project.MSG_WARN));
149:                        exec.setAntRun(getProject());
150:                        exec.setWorkingDirectory(getProject().getBaseDir());
151:                        exec.setCommandline(commandArray);
152:                        int ret = exec.execute();
153:                        if (ret != 0)
154:                            throw new BuildException(
155:                                    "Error while executing apt (exit value: "
156:                                            + ret + ").");
157:                    } catch (IOException x) {
158:                        throw new BuildException("Error invoking apt", x,
159:                                getLocation());
160:                    }
161:                } finally {
162:                    if (tmpFile != null && tmpFile.exists())
163:                        tmpFile.delete();
164:                }
165:            }
166:
167:            public void setSrcdir(Path srcDir) {
168:                this .srcDir = srcDir;
169:            }
170:
171:            public void setDestdir(File destDir) {
172:                this .destDir = destDir;
173:            }
174:
175:            public void setPreprocessdir(File preprocessDir) {
176:                this .preprocessDir = preprocessDir;
177:            }
178:
179:            public void setFactory(String factory) {
180:                this .factory = factory;
181:            }
182:
183:            public void setClasspathRef(Reference ref) {
184:                classPath = new Path(getProject());
185:                classPath.createPath().setRefid(ref);
186:            }
187:
188:            public void setEncoding(String encoding) {
189:                this.encoding = encoding;
190:            }
191:
192:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.