1 package org.apache.maven;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 import java.util.Iterator;
22
23 import org.apache.maven.project.Dependency;
24 import org.apache.maven.project.Project;
25 import org.apache.maven.repository.Artifact;
26
27 /**
28 * Take a valid MavenJellyContext which contains references to the POM, ant
29 * project, and all defined properties and create the dependency classpath based
30 * on dependencies listed in the POM. We also push the individual paths of each
31 * of the dependencies back into the POM so that they can later be referenced in
32 * maven.xml files and plugin.jelly files.
33 *
34 * @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
35 * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
36 *
37 * @version $Id: DependencyClasspathBuilder.java 517014 2007-03-11 21:15:50Z ltheussl $
38 */
39 public class DependencyClasspathBuilder
40 {
41 /** path separator for the classpath */
42 private static final String cps = System.getProperty( "path.separator" );
43
44
45
46
47
48 /**
49 * @return the dependency classpath for the given project.
50 * @param project the project to create the classpath for.
51 */
52 public static String build( Project project )
53 {
54 StringBuffer classpath = new StringBuffer();
55
56 for ( Iterator i = project.getArtifacts().iterator(); i.hasNext(); )
57 {
58 Artifact artifact = (Artifact) i.next();
59 Dependency d = artifact.getDependency();
60
61
62 if ( d.isAddedToClasspath() )
63 {
64 classpath.append( artifact.getPath() ).append( cps );
65 }
66 project.setDependencyPath( d.getKey(), artifact.getPath() );
67 }
68
69 return classpath.toString();
70 }
71 }