Source Code Cross Referenced for RuntimeDependencyResolver.java in  » Sevlet-Container » jetty-modules » org » mortbay » jetty » plugin » 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 » Sevlet Container » jetty modules » org.mortbay.jetty.plugin 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        //========================================================================
002:        //$Id: RuntimeDependencyResolver.java 397 2006-03-23 18:44:41Z janb $
003:        //Copyright 2000-2004 Mort Bay Consulting Pty. Ltd.
004:        //------------------------------------------------------------------------
005:        //Licensed under the Apache License, Version 2.0 (the "License");
006:        //you may not use this file except in compliance with the License.
007:        //You may obtain a copy of the License at 
008:        //http://www.apache.org/licenses/LICENSE-2.0
009:        //Unless required by applicable law or agreed to in writing, software
010:        //distributed under the License is distributed on an "AS IS" BASIS,
011:        //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012:        //See the License for the specific language governing permissions and
013:        //limitations under the License.
014:        //========================================================================
015:
016:        package org.mortbay.jetty.plugin;
017:
018:        import java.net.MalformedURLException;
019:        import java.util.ArrayList;
020:        import java.util.Collections;
021:        import java.util.Iterator;
022:        import java.util.List;
023:        import java.util.Set;
024:
025:        import org.apache.maven.artifact.Artifact;
026:        import org.apache.maven.artifact.factory.ArtifactFactory;
027:        import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
028:        import org.apache.maven.artifact.repository.ArtifactRepository;
029:        import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
030:        import org.apache.maven.artifact.resolver.ArtifactResolutionException;
031:        import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
032:        import org.apache.maven.artifact.resolver.ArtifactResolver;
033:        import org.apache.maven.artifact.resolver.ResolutionListener;
034:        import org.apache.maven.artifact.versioning.VersionRange;
035:        import org.apache.maven.project.MavenProject;
036:        import org.apache.maven.project.MavenProjectBuilder;
037:        import org.apache.maven.project.ProjectBuildingException;
038:        import org.apache.maven.project.artifact.InvalidDependencyVersionException;
039:        import org.apache.maven.project.artifact.MavenMetadataSource;
040:        import org.mortbay.jetty.plugin.util.PluginLog;
041:
042:        /**
043:         * RuntimeDependencyResolver
044:         * 
045:         * This class is able to pull down a remote pom, find all of it's
046:         * dependencies and transitively resolve them.
047:         * 
048:         *
049:         */
050:        public class RuntimeDependencyResolver {
051:            private ArtifactFactory artifactFactory;
052:            private ArtifactResolver artifactResolver;
053:            private ArtifactMetadataSource metadataSource;
054:            private ArtifactRepository localRepository;
055:            private List remoteRepositories;
056:
057:            /**
058:             * RuntimeResolutionListener
059:             * 
060:             * Just for debug printing of transitive resolution steps
061:             *
062:             */
063:            class RuntimeResolutionListener implements  ResolutionListener {
064:                public void testArtifact(Artifact arg0) {
065:                    PluginLog.getLog().debug("TESTING ARTIFACT " + arg0);
066:                }
067:
068:                public void startProcessChildren(Artifact arg0) {
069:                    PluginLog.getLog().debug("STARTING CHILDREN " + arg0);
070:                }
071:
072:                public void endProcessChildren(Artifact arg0) {
073:                    PluginLog.getLog().debug("ENDING CHILDREN " + arg0);
074:                }
075:
076:                public void includeArtifact(Artifact arg0) {
077:                    PluginLog.getLog().debug("INCLUDE ARTIFACT " + arg0);
078:                }
079:
080:                public void omitForNearer(Artifact arg0, Artifact arg1) {
081:                    PluginLog.getLog().debug(
082:                            "OMITTING " + arg0 + " for NEARER " + arg1);
083:                }
084:
085:                public void updateScope(Artifact arg0, String arg1) {
086:                    PluginLog.getLog().debug(
087:                            "UPDATE of SCOPE " + arg0 + "=" + arg1);
088:                }
089:
090:                public void manageArtifact(Artifact arg0, Artifact arg1) {
091:                    PluginLog.getLog().debug(
092:                            "MANAGE ARTIFACT " + arg0 + " and " + arg1);
093:                }
094:
095:                public void omitForCycle(Artifact arg0) {
096:                    PluginLog.getLog().debug("OMIT FOR CYCLE " + arg0);
097:                }
098:
099:                public void updateScopeCurrentPom(Artifact arg0, String arg1) {
100:                    PluginLog.getLog().debug(
101:                            "UPDATE SCOPE CURRENT POM " + arg0 + "=" + arg1);
102:                }
103:
104:                public void selectVersionFromRange(Artifact arg0) {
105:                    PluginLog.getLog().debug(
106:                            "SELECT VERSION FROM RANGE " + arg0);
107:                }
108:
109:                public void restrictRange(Artifact arg0, Artifact arg1,
110:                        VersionRange arg2) {
111:                    PluginLog.getLog().debug(
112:                            "RESTRICT RANGE " + arg0 + " " + arg1 + " range="
113:                                    + arg2);
114:                }
115:
116:            }
117:
118:            public RuntimeDependencyResolver(ArtifactFactory artifactFactory,
119:                    ArtifactResolver artifactResolver,
120:                    ArtifactMetadataSource metadataSource,
121:                    ArtifactRepository localRepository, List remoteRepositories) {
122:                this .artifactFactory = artifactFactory;
123:                this .artifactResolver = artifactResolver;
124:                this .metadataSource = metadataSource;
125:                this .localRepository = localRepository;
126:                this .remoteRepositories = new ArrayList(remoteRepositories);
127:            }
128:
129:            /**
130:             * Download (if necessary) a pom, and load it as a MavenProject, transitively resolving any
131:             * dependencies therein.
132:             * 
133:             * @param projectBuilder
134:             * @param groupId
135:             * @param artifactId
136:             * @param versionId
137:             * @return a Set of Artifacts representing the transitively resolved dependencies.
138:             * 
139:             * @throws MalformedURLException
140:             * @throws ProjectBuildingException
141:             * @throws InvalidDependencyVersionException
142:             * @throws ArtifactResolutionException
143:             * @throws ArtifactNotFoundException
144:             */
145:            public Set transitivelyResolvePomDependencies(
146:                    MavenProjectBuilder projectBuilder, String groupId,
147:                    String artifactId, String versionId,
148:                    boolean resolveProjectArtifact)
149:                    throws MalformedURLException, ProjectBuildingException,
150:                    InvalidDependencyVersionException,
151:                    ArtifactResolutionException, ArtifactNotFoundException {
152:
153:                Artifact pomArtifact = getPomArtifact(groupId, artifactId,
154:                        versionId);
155:                MavenProject project = loadPomAsProject(projectBuilder,
156:                        pomArtifact);
157:                List dependencies = project.getDependencies();
158:
159:                Set dependencyArtifacts = MavenMetadataSource.createArtifacts(
160:                        artifactFactory, dependencies, null, null, null);
161:                dependencyArtifacts.add(project.getArtifact());
162:
163:                List listeners = Collections.EMPTY_LIST;
164:
165:                if (PluginLog.getLog().isDebugEnabled()) {
166:                    listeners = new ArrayList();
167:                    listeners.add(new RuntimeResolutionListener());
168:                }
169:
170:                ArtifactResolutionResult result = artifactResolver
171:                        .resolveTransitively(dependencyArtifacts, pomArtifact,
172:                                Collections.EMPTY_MAP, localRepository,
173:                                remoteRepositories, metadataSource, null,
174:                                listeners);
175:
176:                Set artifacts = result.getArtifacts();
177:
178:                if (PluginLog.getLog().isDebugEnabled()) {
179:                    PluginLog.getLog().debug(
180:                            "RESOLVED " + artifacts.size() + " ARTIFACTS");
181:                    Iterator itor = artifacts.iterator();
182:                    while (itor.hasNext()) {
183:                        Artifact a = (Artifact) itor.next();
184:                        PluginLog.getLog()
185:                                .debug(a.getFile().toURL().toString());
186:                    }
187:                }
188:                return artifacts;
189:            }
190:
191:            public MavenProject loadPomAsProject(
192:                    MavenProjectBuilder projectBuilder, Artifact pomArtifact)
193:                    throws ProjectBuildingException {
194:                return projectBuilder.buildFromRepository(pomArtifact,
195:                        remoteRepositories, localRepository);
196:            }
197:
198:            public Artifact getArtifact(String groupId, String artifactId,
199:                    String versionId, String type) {
200:                return this .artifactFactory.createBuildArtifact(groupId,
201:                        artifactId, versionId, type);
202:            }
203:
204:            public Artifact getPomArtifact(String groupId, String artifactId,
205:                    String versionId) {
206:                return this .artifactFactory.createBuildArtifact(groupId,
207:                        artifactId, versionId, "pom");
208:            }
209:
210:            public void removeDependency(Set artifacts, String groupId,
211:                    String artifactId, String versionId, String type) {
212:                if ((artifacts == null) || artifacts.isEmpty())
213:                    return;
214:
215:                Iterator itor = artifacts.iterator();
216:                while (itor.hasNext()) {
217:                    Artifact a = (Artifact) itor.next();
218:                    if (a.getGroupId().equals(groupId)
219:                            && a.getArtifactId().equals(artifactId)
220:                            && a.getType().equals(type)) {
221:                        //remove if the versions match, or there was no version specified
222:                        if (versionId == null)
223:                            itor.remove();
224:                        else if (a.getVersion().equals(versionId))
225:                            itor.remove();
226:                    }
227:                }
228:            }
229:
230:            public void addDependency(Set artifacts, String groupId,
231:                    String artifactId, String versionId, String type)
232:                    throws ArtifactResolutionException,
233:                    ArtifactNotFoundException {
234:                Artifact a = getArtifact(groupId, artifactId, versionId, type);
235:                artifactResolver
236:                        .resolve(a, remoteRepositories, localRepository);
237:                artifacts.add(a);
238:            }
239:
240:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.