Source Code Cross Referenced for IvyExtractFromSources.java in  » Code-Analyzer » apache-ivy » org » apache » ivy » ant » 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 » Code Analyzer » apache ivy » org.apache.ivy.ant 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         *
017:         */
018:        package org.apache.ivy.ant;
019:
020:        import java.io.File;
021:        import java.io.FileNotFoundException;
022:        import java.io.FileOutputStream;
023:        import java.io.PrintWriter;
024:        import java.io.StringWriter;
025:        import java.io.Writer;
026:        import java.util.ArrayList;
027:        import java.util.Arrays;
028:        import java.util.HashMap;
029:        import java.util.HashSet;
030:        import java.util.Iterator;
031:        import java.util.List;
032:        import java.util.Map;
033:        import java.util.Set;
034:
035:        import org.apache.ivy.core.module.id.ModuleRevisionId;
036:        import org.apache.tools.ant.BuildException;
037:        import org.apache.tools.ant.Project;
038:        import org.apache.tools.ant.Task;
039:        import org.apache.tools.ant.filters.LineContainsRegExp;
040:        import org.apache.tools.ant.filters.TokenFilter;
041:        import org.apache.tools.ant.taskdefs.Concat;
042:        import org.apache.tools.ant.types.FileSet;
043:        import org.apache.tools.ant.types.FilterChain;
044:        import org.apache.tools.ant.types.RegularExpression;
045:
046:        /**
047:         * Extracts imports from a set of java sources and generate corresponding ivy file
048:         */
049:        public class IvyExtractFromSources extends Task {
050:            public static class Ignore {
051:                private String packageName;
052:
053:                public String getPackage() {
054:                    return packageName;
055:                }
056:
057:                public void setPackage(String package1) {
058:                    packageName = package1;
059:                }
060:            }
061:
062:            private String organisation;
063:
064:            private String module;
065:
066:            private String revision;
067:
068:            private String status;
069:
070:            private List ignoredPackaged = new ArrayList(); // List (String package)
071:
072:            private Map mapping = new HashMap(); // Map (String package -> ModuleRevisionId)
073:
074:            private Concat concat = new Concat();
075:
076:            private File to;
077:
078:            public void addConfiguredIgnore(Ignore ignore) {
079:                ignoredPackaged.add(ignore.getPackage());
080:            }
081:
082:            public File getTo() {
083:                return to;
084:            }
085:
086:            public void setTo(File to) {
087:                this .to = to;
088:            }
089:
090:            public String getModule() {
091:                return module;
092:            }
093:
094:            public void setModule(String module) {
095:                this .module = module;
096:            }
097:
098:            public String getOrganisation() {
099:                return organisation;
100:            }
101:
102:            public void setOrganisation(String organisation) {
103:                this .organisation = organisation;
104:            }
105:
106:            public String getRevision() {
107:                return revision;
108:            }
109:
110:            public void setRevision(String revision) {
111:                this .revision = revision;
112:            }
113:
114:            public String getStatus() {
115:                return status;
116:            }
117:
118:            public void setStatus(String status) {
119:                this .status = status;
120:            }
121:
122:            public void addConfiguredMapping(PackageMapping mapping) {
123:                this .mapping.put(mapping.getPackage(), mapping
124:                        .getModuleRevisionId());
125:            }
126:
127:            public void addFileSet(FileSet fileSet) {
128:                concat.addFileset(fileSet);
129:            }
130:
131:            public void execute() throws BuildException {
132:                configureConcat();
133:                Writer out = new StringWriter();
134:                concat.setWriter(out);
135:                concat.execute();
136:                Set importsSet = new HashSet(Arrays.asList(out.toString()
137:                        .split("\n")));
138:                Set dependencies = new HashSet();
139:                for (Iterator iter = importsSet.iterator(); iter.hasNext();) {
140:                    String pack = ((String) iter.next()).trim();
141:                    ModuleRevisionId mrid = getMapping(pack);
142:                    if (mrid != null) {
143:                        dependencies.add(mrid);
144:                    }
145:                }
146:                try {
147:                    PrintWriter writer = new PrintWriter(new FileOutputStream(
148:                            to));
149:                    writer.println("<ivy-module version=\"1.0\">");
150:                    writer.println("\t<info organisation=\"" + organisation
151:                            + "\"");
152:                    writer.println("\t       module=\"" + module + "\"");
153:                    if (revision != null) {
154:                        writer
155:                                .println("\t       revision=\"" + revision
156:                                        + "\"");
157:                    }
158:                    if (status != null) {
159:                        writer.println("\t       status=\"" + status + "\"");
160:                    } else {
161:                        writer.println("\t       status=\"integration\"");
162:                    }
163:                    writer.println("\t/>");
164:                    if (!dependencies.isEmpty()) {
165:                        writer.println("\t<dependencies>");
166:                        for (Iterator iter = dependencies.iterator(); iter
167:                                .hasNext();) {
168:                            ModuleRevisionId mrid = (ModuleRevisionId) iter
169:                                    .next();
170:                            writer.println("\t\t<dependency org=\""
171:                                    + mrid.getOrganisation() + "\" name=\""
172:                                    + mrid.getName() + "\" rev=\""
173:                                    + mrid.getRevision() + "\"/>");
174:                        }
175:                        writer.println("\t</dependencies>");
176:                    }
177:                    writer.println("</ivy-module>");
178:                    writer.close();
179:                    log(dependencies.size() + " dependencies put in " + to);
180:                } catch (FileNotFoundException e) {
181:                    throw new BuildException("impossible to create file " + to
182:                            + ": " + e, e);
183:                }
184:            }
185:
186:            /**
187:             * @param pack
188:             * @return
189:             */
190:            private ModuleRevisionId getMapping(String pack) {
191:                String askedPack = pack;
192:                ModuleRevisionId ret = null;
193:                while (ret == null && pack.length() > 0) {
194:                    if (ignoredPackaged.contains(pack)) {
195:                        return null;
196:                    }
197:                    ret = (ModuleRevisionId) mapping.get(pack);
198:                    int lastDotIndex = pack.lastIndexOf('.');
199:                    if (lastDotIndex != -1) {
200:                        pack = pack.substring(0, lastDotIndex);
201:                    } else {
202:                        break;
203:                    }
204:                }
205:                if (ret == null) {
206:                    log("no mapping found for " + askedPack,
207:                            Project.MSG_VERBOSE);
208:                }
209:                return ret;
210:            }
211:
212:            private void configureConcat() {
213:                concat.setProject(getProject());
214:                concat.setTaskName(getTaskName());
215:                FilterChain filterChain = new FilterChain();
216:                LineContainsRegExp lcre = new LineContainsRegExp();
217:                RegularExpression regexp = new RegularExpression();
218:                regexp.setPattern("^import .+;");
219:                lcre.addConfiguredRegexp(regexp);
220:                filterChain.add(lcre);
221:                TokenFilter tf = new TokenFilter();
222:                TokenFilter.ReplaceRegex rre = new TokenFilter.ReplaceRegex();
223:                rre.setPattern("import (.+);.*");
224:                rre.setReplace("\\1");
225:                tf.add(rre);
226:                filterChain.add(tf);
227:                concat.addFilterChain(filterChain);
228:            }
229:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.