View Javadoc

1   package org.apache.maven;
2   
3   /* ====================================================================
4    *   Licensed to the Apache Software Foundation (ASF) under one or more
5    *   contributor license agreements.  See the NOTICE file distributed with
6    *   this work for additional information regarding copyright ownership.
7    *   The ASF licenses this file to You under the Apache License, Version 2.0
8    *   (the "License"); you may not use this file except in compliance with
9    *   the License.  You may obtain a copy of the License at
10   *
11   *       http://www.apache.org/licenses/LICENSE-2.0
12   *
13   *   Unless required by applicable law or agreed to in writing, software
14   *   distributed under the License is distributed on an "AS IS" BASIS,
15   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   *   See the License for the specific language governing permissions and
17   *   limitations under the License.
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      // I M P L E M E N T A T I O N
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              // Only add jar or ejb (MAVEN-512) dependencies to the classpath
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  }