Source Code Cross Referenced for InstallEngine.java in  » Code-Analyzer » apache-ivy » org » apache » ivy » core » install » 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.core.install 
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.core.install;
019:
020:        import java.io.File;
021:        import java.io.IOException;
022:        import java.util.Arrays;
023:        import java.util.Collection;
024:        import java.util.Date;
025:        import java.util.Iterator;
026:
027:        import org.apache.ivy.core.module.descriptor.Configuration;
028:        import org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor;
029:        import org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor;
030:        import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
031:        import org.apache.ivy.core.module.id.ModuleId;
032:        import org.apache.ivy.core.module.id.ModuleRevisionId;
033:        import org.apache.ivy.core.publish.PublishEngine;
034:        import org.apache.ivy.core.report.ArtifactDownloadReport;
035:        import org.apache.ivy.core.report.ResolveReport;
036:        import org.apache.ivy.core.resolve.DownloadOptions;
037:        import org.apache.ivy.core.resolve.IvyNode;
038:        import org.apache.ivy.core.resolve.ResolveEngine;
039:        import org.apache.ivy.core.resolve.ResolveOptions;
040:        import org.apache.ivy.core.search.SearchEngine;
041:        import org.apache.ivy.plugins.conflict.NoConflictManager;
042:        import org.apache.ivy.plugins.matcher.ExactPatternMatcher;
043:        import org.apache.ivy.plugins.matcher.MatcherHelper;
044:        import org.apache.ivy.plugins.matcher.PatternMatcher;
045:        import org.apache.ivy.plugins.resolver.DependencyResolver;
046:        import org.apache.ivy.util.Message;
047:        import org.apache.ivy.util.filter.Filter;
048:        import org.apache.ivy.util.filter.FilterHelper;
049:
050:        public class InstallEngine {
051:            private InstallEngineSettings settings;
052:
053:            private ResolveEngine resolveEngine;
054:
055:            private PublishEngine publishEngine;
056:
057:            private SearchEngine searchEngine;
058:
059:            public InstallEngine(InstallEngineSettings settings,
060:                    SearchEngine searchEngine, ResolveEngine resolveEngine,
061:                    PublishEngine publishEngine) {
062:                this .settings = settings;
063:                this .searchEngine = searchEngine;
064:                this .resolveEngine = resolveEngine;
065:                this .publishEngine = publishEngine;
066:            }
067:
068:            public ResolveReport install(ModuleRevisionId mrid, String from,
069:                    String to, boolean transitive, boolean validate,
070:                    boolean overwrite, Filter artifactFilter, String matcherName)
071:                    throws IOException {
072:                if (artifactFilter == null) {
073:                    artifactFilter = FilterHelper.NO_FILTER;
074:                }
075:                DependencyResolver fromResolver = settings.getResolver(from);
076:                DependencyResolver toResolver = settings.getResolver(to);
077:                if (fromResolver == null) {
078:                    throw new IllegalArgumentException("unknown resolver "
079:                            + from + ". Available resolvers are: "
080:                            + settings.getResolverNames());
081:                }
082:                if (toResolver == null) {
083:                    throw new IllegalArgumentException("unknown resolver " + to
084:                            + ". Available resolvers are: "
085:                            + settings.getResolverNames());
086:                }
087:                PatternMatcher matcher = settings.getMatcher(matcherName);
088:                if (matcher == null) {
089:                    throw new IllegalArgumentException("unknown matcher "
090:                            + matcherName + ". Available matchers are: "
091:                            + settings.getMatcherNames());
092:                }
093:
094:                // build module file declaring the dependency
095:                Message.info(":: installing " + mrid + " ::");
096:                DependencyResolver oldDicator = resolveEngine
097:                        .getDictatorResolver();
098:                boolean log = settings.logNotConvertedExclusionRule();
099:                try {
100:                    settings.setLogNotConvertedExclusionRule(true);
101:                    resolveEngine.setDictatorResolver(fromResolver);
102:
103:                    DefaultModuleDescriptor md = new DefaultModuleDescriptor(
104:                            ModuleRevisionId.newInstance("apache",
105:                                    "ivy-install", "1.0"), settings
106:                                    .getStatusManager().getDefaultStatus(),
107:                            new Date());
108:                    String resolveId = ResolveOptions.getDefaultResolveId(md);
109:                    md.addConfiguration(new Configuration("default"));
110:                    md.addConflictManager(new ModuleId(
111:                            ExactPatternMatcher.ANY_EXPRESSION,
112:                            ExactPatternMatcher.ANY_EXPRESSION),
113:                            ExactPatternMatcher.INSTANCE,
114:                            new NoConflictManager());
115:
116:                    if (MatcherHelper.isExact(matcher, mrid)) {
117:                        DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(
118:                                md, mrid, false, false, transitive);
119:                        dd.addDependencyConfiguration("default", "*");
120:                        md.addDependency(dd);
121:                    } else {
122:                        Collection mrids = searchEngine.findModuleRevisionIds(
123:                                fromResolver, mrid, matcher);
124:
125:                        for (Iterator iter = mrids.iterator(); iter.hasNext();) {
126:                            ModuleRevisionId foundMrid = (ModuleRevisionId) iter
127:                                    .next();
128:                            Message.info("\tfound " + foundMrid
129:                                    + " to install: adding to the list");
130:                            DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(
131:                                    md, foundMrid, false, false, transitive);
132:                            dd.addDependencyConfiguration("default", "*");
133:                            md.addDependency(dd);
134:                        }
135:                    }
136:
137:                    // resolve using appropriate resolver
138:                    ResolveReport report = new ResolveReport(md, resolveId);
139:
140:                    Message.info(":: resolving dependencies ::");
141:                    ResolveOptions options = new ResolveOptions().setResolveId(
142:                            resolveId).setConfs(new String[] { "default" })
143:                            .setValidate(validate);
144:                    IvyNode[] dependencies = resolveEngine.getDependencies(md,
145:                            options, report);
146:                    report.setDependencies(Arrays.asList(dependencies),
147:                            artifactFilter);
148:
149:                    Message.info(":: downloading artifacts to cache ::");
150:                    resolveEngine.downloadArtifacts(report, artifactFilter,
151:                            new DownloadOptions());
152:
153:                    // now that everything is in cache, we can publish all these modules
154:                    Message.info(":: installing in " + to + " ::");
155:                    for (int i = 0; i < dependencies.length; i++) {
156:                        ModuleDescriptor depmd = dependencies[i]
157:                                .getDescriptor();
158:                        if (depmd != null) {
159:                            ModuleRevisionId depMrid = depmd
160:                                    .getModuleRevisionId();
161:                            Message.verbose("installing " + depMrid);
162:                            boolean successfullyPublished = false;
163:                            try {
164:                                toResolver.beginPublishTransaction(depMrid,
165:                                        overwrite);
166:
167:                                // publish artifacts
168:                                ArtifactDownloadReport[] artifacts = report
169:                                        .getArtifactsReports(depMrid);
170:                                for (int j = 0; j < artifacts.length; j++) {
171:                                    if (artifacts[j].getLocalFile() != null) {
172:                                        toResolver.publish(artifacts[j]
173:                                                .getArtifact(), artifacts[j]
174:                                                .getLocalFile(), overwrite);
175:                                    }
176:                                }
177:
178:                                // publish metadata
179:                                File localIvyFile = dependencies[i]
180:                                        .getModuleRevision().getReport()
181:                                        .getLocalFile();
182:                                toResolver.publish(depmd.getMetadataArtifact(),
183:                                        localIvyFile, overwrite);
184:
185:                                // end module publish
186:                                toResolver.commitPublishTransaction();
187:                                successfullyPublished = true;
188:                            } finally {
189:                                if (!successfullyPublished) {
190:                                    toResolver.abortPublishTransaction();
191:                                }
192:                            }
193:                        }
194:                    }
195:
196:                    Message.info(":: install resolution report ::");
197:
198:                    // output report
199:                    resolveEngine.outputReport(report, settings
200:                            .getResolutionCacheManager(), options);
201:
202:                    return report;
203:                } finally {
204:                    resolveEngine.setDictatorResolver(oldDicator);
205:                    settings.setLogNotConvertedExclusionRule(log);
206:                }
207:            }
208:
209:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.