package org.apache.maven;
/* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
import java.util.Iterator;
import org.apache.maven.project.Dependency;
import org.apache.maven.project.Project;
import org.apache.maven.repository.Artifact;
/**
* Take a valid MavenJellyContext which contains references to the POM, ant
* project, and all defined properties and create the dependency classpath based
* on dependencies listed in the POM. We also push the individual paths of each
* of the dependencies back into the POM so that they can later be referenced in
* maven.xml files and plugin.jelly files.
*
* @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
* @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
*
* @version $Id: DependencyClasspathBuilder.java 517014 2007-03-11 21:15:50Z ltheussl $
*/
public class DependencyClasspathBuilder
{
/** path separator for the classpath */
private static final String cps = System.getProperty( "path.separator" );
// --------------------------------------------------------------
// I M P L E M E N T A T I O N
// --------------------------------------------------------------
/**
* @return the dependency classpath for the given project.
* @param project the project to create the classpath for.
*/
public static String build( Project project )
{
StringBuffer classpath = new StringBuffer();
for ( Iterator i = project.getArtifacts().iterator(); i.hasNext(); )
{
Artifact artifact = (Artifact) i.next();
Dependency d = artifact.getDependency();
// Only add jar or ejb (MAVEN-512) dependencies to the classpath
if ( d.isAddedToClasspath() )
{
classpath.append( artifact.getPath() ).append( cps );
}
project.setDependencyPath( d.getKey(), artifact.getPath() );
}
return classpath.toString();
}
}