You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by mi...@apache.org on 2003/12/28 21:13:18 UTC
cvs commit: maven-components/maven-artifact-factory/src/main/java/org/apache/maven/artifact/layout DefaultRepositoryLayout.java RepositoryLayout.java
michal 2003/12/28 12:13:18
Added: maven-artifact-factory/src/main/conf layout_unix.properties
layout_windows.properties layout.properties
maven-artifact-factory/src/main/java/org/apache/maven/artifact
Artifact.java
maven-artifact-factory/src/main/java/org/apache/maven/artifact/factory
DefaultArtifact.java DefaultArtifactFactory.java
ArtifactFactory.java
maven-artifact-factory/src/main/java/org/apache/maven/artifact/layout
DefaultRepositoryLayout.java RepositoryLayout.java
Log:
Due to the fact that I am IDEA neophyte I managed to commit just test source tree :(. I hope that this time it's OK
Revision Changes Path
1.1 maven-components/maven-artifact-factory/src/main/conf/layout_unix.properties
Index: layout_unix.properties
===================================================================
native=${groupId}/native/${artifactId}-${version}.so
1.1 maven-components/maven-artifact-factory/src/main/conf/layout_windows.properties
Index: layout_windows.properties
===================================================================
native=${groupId}/native/${artifactId}-${version}.dll
1.1 maven-components/maven-artifact-factory/src/main/conf/layout.properties
Index: layout.properties
===================================================================
# For denoting artifact layout in repository 4 variables are
# accessible:
# ${version} --- (maps to)-> artifact.version
# ${artifactId} --------------> artifact.artifactId == dependency.artifactId
# ${groupId} --------------> artifact.groupId == dependency.groupId
# ${type} --------------> artifact.type == dependency.type
#
# DEFAULT
default=${groupId}/${type}s/${artifactId}-${version}.${type}
# this is for case when user requests to use particular file name
nameless=${groupId}/${type}s/
# EJB
ejb=${groupId}/ejbs/${artifactId}-${version}.jar
#
# Example of another possible use case:
#
# JAVADOC
#javadoc=${artifactId}/${groupId}/javadocs/${artifactId}_apidocs-${version}.jar
#
# for testing purpose
mock=${groupId}/jars/${artifactId}-${version}.jar
1.1 maven-components/maven-artifact-factory/src/main/java/org/apache/maven/artifact/Artifact.java
Index: Artifact.java
===================================================================
package org.apache.maven.artifact;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache MavenSession" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache MavenSession", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
import org.apache.maven.model.Dependency;
import java.io.File;
/**
* The interface defining an artifact (which probably lives in the
* repository).
*
* @author <a href="jason@zenplex.com">Jason van Zyl</a>
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
* @version $Id: Artifact.java,v 1.1 2003/12/28 20:13:18 michal Exp $
*/
public interface Artifact
{
/**
* Get the dependency.
*
* @return The dependency this artifact is based on.
*/
Dependency getDependency();
/**
* Get the artifact
*
* @return artifact for the artifact
*/
String getArtifact();
/**
* Return a path that is platform agnostic.
*
* @return URL of the artifact.
*/
String getPath();
/**
* Return a path that is platform agnostic.
* <p/>
* Path is relataive to repsository root
*
* @param path URL of the artifact.
*/
void setPath( String path );
/**
* Get the location of the artifact in the local file system.
*
* @return The location of the artifact in the local file system.
*/
File getFile();
/**
* Set the path to the artifact. The maven jar override facilty
* can be used to change the path to the artifact if the user
* specifies the use of a specific version.
*
* @param file the artifact file.
*/
void setFile( String file );
/**
* Sets the flag which indicates
* if file override mechanism was applied to this artifact
*/
void setFileOveridden( boolean fileOverriden );
/**
* Gets the flag is artifact's file has been overriden
*
* @return
*/
boolean isFileOverridden();
/**
* Sets the version
* This is used only when
* version override mechanism was applied to this artifact. So
* dependecy version and artifact version are different
*/
void setOverriddenVersion( String version );
/**
* Gets the artifact's version if the dependecy' version has been overriden
*
* @return Overriden version or <code>null</code>
*/
String getOverriddenVersion();
/**
* Gets the artifact's version
*
* @return Overriden version if one was provided , otherwise dependecy version
*/
String getVersion();
/**
* Return an URL path that is platform agnostic.
*
* @return URL of the artifact.
*/
String getUrlPath();
/**
* Return the url to the checksum file for this artifact.
*
* @return URL of the checksum file for this artifact.
*/
String getChecksumUrl();
/**
* Boolean flag indicating whether this artifact is a snapshot.
*
* @return Flag indicating whether this artifact is a snapshot.
*/
boolean isSnapshot();
/**
* Boolean flag indicating whether this artifact exists.
*
* @return Flag indicating the existance of the artifact in the
* local repository.
*/
boolean exists();
}
1.1 maven-components/maven-artifact-factory/src/main/java/org/apache/maven/artifact/factory/DefaultArtifact.java
Index: DefaultArtifact.java
===================================================================
package org.apache.maven.artifact.factory;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache MavenSession" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache MavenSession", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
import org.apache.maven.MavenConstants;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.model.Dependency;
import java.io.File;
/**
* The default implemenation of {@link Artifact} interface.
*
* @author <a href="jason@zenplex.com">Jason van Zyl</a>
* @version $Id: DefaultArtifact.java,v 1.1 2003/12/28 20:13:18 michal Exp $
*/
class DefaultArtifact implements Artifact
{
/** Platform specific file separator used for file system operations. */
protected final static String PATH_SEPARATOR = File.separator;
/** The artifact path */
private String path;
/** The artifact file. */
private File file;
/** Associated dependency */
private org.apache.maven.model.Dependency dependency = null;
/** Flag indicating that this artifact has been overidden */
private boolean fileOverriden;
/** Overidden version */
private String overriddenVersion;
/**
* Create artifacts from supplied dependecy
*
* @param dependency
*/
public DefaultArtifact( final Dependency dependency )
{
this.dependency = dependency;
}
/**
* @see org.apache.maven.artifact.Artifact#getArtifact()()
*/
public String getArtifact()
{
return getFile().getName();
}
/**
* @see org.apache.maven.artifact.Artifact#setPath(java.lang.String)
*/
public void setPath( final String path )
{
this.path = path;
}
/**
* @see org.apache.maven.artifact.Artifact#getPath()
*/
public String getPath()
{
return path;
}
/**
* @see org.apache.maven.artifact.Artifact#getUrlPath()
*/
public String getUrlPath()
{
return "/" + path;
}
/**
* @see org.apache.maven.artifact.Artifact#getChecksumUrl()
*/
public String getChecksumUrl()
{
return getUrlPath() + ".md5";
}
/**
* @see org.apache.maven.artifact.Artifact#isSnapshot()
*/
public boolean isSnapshot()
{
final String version = getDependency().getVersion();
if ( version == null )
{
return false;
}
return version.equalsIgnoreCase( MavenConstants.SNAPSHOT_SIGNIFIER );
}
/**
* @see org.apache.maven.artifact.Artifact#exists()
*/
public boolean exists()
{
if ( getFile().exists() )
{
return true;
}
else
{
return false;
}
}
/**
* @see org.apache.maven.artifact.Artifact#getFile()
*/
public File getFile()
{
if ( file == null )
{
setFile( path );
}
return file;
}
/**
* @see org.apache.maven.artifact.Artifact#setFile(java.lang.String)
*/
public void setFile( final String fileStr )
{
if ( fileStr != null )
{
setFile( new File( fileStr ) );
}
else
{
file = null;
}
}
/**
* @ see org.apache.maven.artifact.Artifact # setFile(java.lang.String)
*/
public void setFile( final File file )
{
this.file = file;
}
/**
* @see org.apache.maven.artifact.Artifact#getDependency()
*/
public Dependency getDependency()
{
return dependency;
}
/**
* @see org.apache.maven.artifact.Artifact#setFileOveridden(boolean)
*/
public void setFileOveridden( final boolean fileOverriden )
{
this.fileOverriden = fileOverriden;
}
/**
* @see org.apache.maven.artifact.Artifact#isFileOverridden()
*/
public boolean isFileOverridden()
{
return fileOverriden;
}
/**
* @see org.apache.maven.artifact.Artifact#setOverriddenVersion(String)
*/
public void setOverriddenVersion( final String overriddenVersion )
{
this.overriddenVersion = overriddenVersion;
}
/**
* @see org.apache.maven.artifact.Artifact#getOverriddenVersion()
*/
public String getOverriddenVersion()
{
return overriddenVersion;
}
/**
*
*/
public String toString()
{
return "Artifact:[" + dependency.getId() + ":"
+ getVersion() + "]";
}
/**
* @return
*/
public String getVersion()
{
if ( overriddenVersion != null)
{
return overriddenVersion;
}
return dependency.getVersion();
}
public String getArtifactDir()
{
return getFile().getParent();
}
}
1.1 maven-components/maven-artifact-factory/src/main/java/org/apache/maven/artifact/factory/DefaultArtifactFactory.java
Index: DefaultArtifactFactory.java
===================================================================
package org.apache.maven.artifact.factory;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
import org.apache.maven.MavenConstants;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.layout.RepositoryLayout;
import org.apache.maven.model.Dependency;
import org.apache.maven.project.Project;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.util.StringUtils;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
/**
* Simple factory for creating Artifact implementations based on a dependency
* type.
*
* @author <a href="mailto:michal.maczka@dimatics.com">Michal Maczka</a>
* @version $Id: DefaultArtifactFactory.java,v 1.1 2003/12/28 20:13:18 michal Exp $
*/
public class DefaultArtifactFactory extends AbstractLogEnabled implements Serviceable, ArtifactFactory
{
private RepositoryLayout repositoryLayout;
/**
* Return the list of artifact for given project
* type. The same list is set in the project
*
* @param project The base dependency.
* @param mavenRepoLocal Path to maven local repository. If it's null it's set via
* repository layout service
*
* @return The appropriate artifact based on the dependency type.
*/
public List createArtifacts( final Project project, String mavenRepoLocal )
throws Exception
{
final boolean hasDependencies = ( project.getDependencies() != null )
&& ( project.getDependencies().size() > 0 );
if ( !hasDependencies )
{
return Collections.EMPTY_LIST;
}
if ( mavenRepoLocal == null )
{
mavenRepoLocal = repositoryLayout.getMavenRepoLocal( project );
}
getLogger().info( "mavenRepoLocal: " + mavenRepoLocal );
if ( mavenRepoLocal == null )
{
throw new IllegalStateException(
"The artifact factory cannot function without a valid setting for the local maven repository." );
}
final List dependencies = project.getDependencies();
final List artifacts = new ArrayList();
for ( Iterator iter = dependencies.iterator(); iter.hasNext(); )
{
final Dependency dependency = ( Dependency ) iter.next();
final Artifact artifact = createArtifact( dependency, project,
mavenRepoLocal );
artifacts.add( artifact );
}
return artifacts;
}
public Artifact createArtifact( final String groupId, final String artifactId,
final String type, final String version, final Project project, final String mavenRepoLocal )
throws Exception
{
final Dependency dependency = new Dependency();
dependency.setGroupId( groupId );
dependency.setArtifactId( artifactId );
dependency.setType( type );
dependency.setVersion( version );
return createArtifact( dependency, project, mavenRepoLocal );
}
/**
* @todo We can check if such artifact is alredy "known"
*/
public Artifact createArtifact( final Dependency dependency, final Project project,
final String mavenRepoLocal )
throws Exception
{
boolean override = false;
if ( project != null )
{
final String jarOverrideProperty = project.getProperty( "maven.jar.override" );
final String artifactOverrideProperty = project.getProperty( "maven.artifact.override" );
override = isTrue( jarOverrideProperty ) || isTrue( artifactOverrideProperty );
}
final Artifact artifact = new DefaultArtifact( dependency );
if ( override )
{
final String file = getOverriddenArtifact( dependency, project );
if ( file != null )
{
artifact.setFile( file );
artifact.setFileOveridden( true );
}
else
{
final String version = getOverriddenVersion( dependency, project );
if ( version != null )
{
artifact.setOverriddenVersion( version );
}
}
}
if ( !artifact.isFileOverridden() )
{
final String path = generatePath( artifact );
artifact.setPath( path );
String file = null;
if ( mavenRepoLocal != null )
{
file = new File( mavenRepoLocal, path ).getAbsolutePath();
}
else
{
file = new File( repositoryLayout.getMavenRepoLocal( project ),
path ).getAbsolutePath();
}
artifact.setFile( file );
}
return artifact;
}
/**
* @param artifactOverrideProperty
* @return
*/
private boolean isTrue( final String property )
{
boolean retValue = false;
if ( property != null )
{
if ( "true".equalsIgnoreCase( property )
|| "on".equalsIgnoreCase( property )
|| "1".equals( property ) )
{
retValue = true;
}
}
return retValue;
}
/**
* @param groupId
* @param artifactId
* @param type
* @param version
*
* @return
*/
public Artifact createArtifactOfType( final Dependency dependency, final String type,
final Project project, final String mavenRepoLocal )
throws Exception
{
final Dependency newDependency = new Dependency();
newDependency.setGroupId( dependency.getGroupId() );
newDependency.setArtifactId( dependency.getArtifactId() );
newDependency.setType( type );
newDependency.setVersion( dependency.getVersion() );
return createArtifact( newDependency, project, mavenRepoLocal );
}
/**
* @param dependency
* @param type
*
* @return
*/
public Artifact createArtifactOfVersion( final Dependency dependency,
final String version, final Project project, final String mavenRepoLocal )
throws Exception
{
final Dependency newDependency = new Dependency();
newDependency.setGroupId( dependency.getGroupId() );
newDependency.setArtifactId( dependency.getArtifactId() );
newDependency.setType( dependency.getType() );
newDependency.setVersion( version );
return createArtifact( newDependency, project, mavenRepoLocal );
}
public Artifact createPomArtifact( final Artifact artifact ) throws Exception
{
Artifact pomArtifact = null;
System.out.println( "path:" + artifact.getPath() );
final File file = new File( artifact.getPath() );
final int index = artifact.getFile().getAbsolutePath().indexOf( file.getPath() );
final String mavenLocalRepo = artifact.getFile().getAbsolutePath().substring( 0, index - 1 );
final Dependency dependency = artifact.getDependency();
pomArtifact = createArtifactOfType( dependency, "pom", null, mavenLocalRepo );
return pomArtifact;
}
/**
* Get the maven jar override value for a particular dependency.
* <p/>
* This is "a copy/paste" from old Project class
*
* @param id Id of the project to override.
*
* @return MavenSession jar override value for a particular dependency.
*
* @deprecated this is purly for backward compatibility
*/
public String getMavenJarOverride( final String id, final Project project )
{
String retValue = ( String ) project.getProperties().get( "maven.jar." + id );
if ( retValue != null)
{
retValue = retValue.trim();
}
getLogger().info( "override: " + "maven.jar." + id + "=" + retValue);
return retValue;
}
/**
* Get the maven jar override value for a particular dependency.
*
* @param id Id of the project to override.
*
* @return MavenSession jar override value for a particular dependency.
*/
public String getOverriddenArtifact( final Dependency dependency, final Project project )
{
//XXX start of the block, which exists only for backward compatibility
// this should be removed somewhere in the future
String artifact = null;
artifact = getMavenJarOverride( dependency.getArtifactId(), project );
if ( artifact != null )
{
boolean isVersion = Character.isDigit( artifact.charAt( 0 ) );
getLogger().info ( "artifact: " + artifact + " isDigit: " + isVersion ) ;
if ( !isVersion )
{
return artifact;
}
else
{
return null;
}
}
// end of block
final String key = MavenConstants.ARTIFACT_OVERRIDE_PROPERTY
+ dependency.getGroupId() + "." + dependency.getArtifactId()
+ "." + dependency.getType();
artifact = ( String ) project.getProperties().get( key );
return artifact;
}
/**
* Get the maven jar override value for a particular dependency.
*
* @param id Id of the project to override.
*
* @return MavenSession jar override value for a particular dependency.
*/
public String getOverriddenVersion( final Dependency dependency, final Project project )
{
//XXX start of the block, which exists only for backward compatibility
// this should be removed somewhere in the future
String version = null;
version = getMavenJarOverride( dependency.getArtifactId(), project );
if ( version != null )
{
boolean isVersion = Character.isDigit( version.charAt( 0 ) );
getLogger().info ( "version: " + version + " isDigit: " + isVersion ) ;
if ( isVersion )
{
return version;
}
else
{
return null;
}
}
// end of block
final String key = MavenConstants.VERSION_OVERRIDE_PROPERTY
+ dependency.getGroupId() + "." + dependency.getArtifactId()
+ "." + dependency.getType();
version = ( String ) project.getProperties().get( key );
return version;
}
/**
* @param artifact
*
* @return
*/
private String generatePath( final Artifact artifact )
throws Exception
{
// take into account the fact that artifact version could be overriden
return repositoryLayout.generatePathWithVersion( artifact.getDependency(), artifact.getVersion() );
}
/**
* @see org.apache.maven.artifact.factory.ArtifactFactory#getMavenRepoLocal(org.apache.maven.project.Project)
*/
public String getMavenRepoLocal( final Project project )
{
return repositoryLayout.getMavenRepoLocal( project );
}
/**
* @param string
*/
public void setMavenRepoLocal( final String mavenRepoLocal )
{
repositoryLayout.setMavenRepoLocal( mavenRepoLocal );
}
// ----------------------------------------------------------------------
// Lifecycle Management
// ----------------------------------------------------------------------
/**
* @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
*/
public void service( final ServiceManager serviceManager )
throws ServiceException
{
repositoryLayout = ( RepositoryLayout ) serviceManager.lookup( RepositoryLayout.ROLE );
}
}
1.1 maven-components/maven-artifact-factory/src/main/java/org/apache/maven/artifact/factory/ArtifactFactory.java
Index: ArtifactFactory.java
===================================================================
package org.apache.maven.artifact.factory;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache MavenSession" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache MavenSession", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.model.Dependency;
import org.apache.maven.project.Project;
import java.util.List;
/**
* Class resposible for converting information kept
* in {@link org.apache.maven.project.Project}
* (list of dependicies) into the list of artifacts.
* <p/>
* For the moment there a general assumption that there
* is one to one relation between
* {@link org.apache.maven.project.Dependency} and {@link org.apache.maven.artifact.Artifact}
* and currently for each dependecy one artifact will
* created.
* <p/>
* Once (if ever) the agreement on meaning of terms like
* <b>transitive dependecy</b>, <b>group dependecy<b>
* will be found it can happend that there will be exceptions
* from this rule. That's why this interface has such form
* and leaves the doors open for such changes.
*
* @author <a href="mailto:michal.maczka@dimatics.com">Michal Maczka</a>
* @version $Id: ArtifactFactory.java,v 1.1 2003/12/28 20:13:18 michal Exp $
* @todo Exception handling
*/
public interface ArtifactFactory
{
/** Component role name */
String ROLE = ArtifactFactory.class.getName();
/**
* Returns the list of artifacts which is
* constructed basing on the information kept in the given
* Project.
* <br/>
*
* @param project The project for which the artifact list will be resolved
* @param mavenRepoLocal Path to maven local repository. If it's null it's set via
* repository layout service
*
* @return The list contating resolved artifacts.
*/
List createArtifacts( Project project, String mavenRepoLocal )
throws Exception;
Artifact createArtifact( String groupId, String artifactId,
String type, String version, Project project, String mavenRepoLocal )
throws Exception;
/**
* Either project or mavenRepoLocal should be not null.
* If mavenRepoLocal is not null it is used in the first place
*
* @param dependency
* @param project
* @param mavenRepoLocal Path to maven local repository. If it's null it's set via
* repository layout service
*
* @return
*
* @throws Exception
*/
Artifact createArtifact( Dependency dependency, Project project, String mavenRepoLocal )
throws Exception;
Artifact createArtifactOfType( Dependency dependency, String type,
Project project, String mavenRepoLocal ) throws Exception;
Artifact createArtifactOfVersion( Dependency dependency,
String version, Project project, String mavenRepoLocal )
throws Exception;
Artifact createPomArtifact( Artifact artifact ) throws Exception;
String getMavenRepoLocal( Project project );
void setMavenRepoLocal( String string );
}
1.1 maven-components/maven-artifact-factory/src/main/java/org/apache/maven/artifact/layout/DefaultRepositoryLayout.java
Index: DefaultRepositoryLayout.java
===================================================================
package org.apache.maven.artifact.layout;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache MavenSession" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache MavenSession", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
import org.apache.maven.model.Dependency;
import org.apache.maven.project.Project;
import org.codehaus.plexus.util.StringUtils;
import java.io.File;
import java.io.InputStream;
import java.util.Properties;
/**
* The standard {@link org.apache.maven.repository.RepositoryLayout}
* implementation.
*
* @author <a href="jason@zenplex.com">Jason van Zyl</a>
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
* @author <a href="pete-apache-dev@kazmier.com">Pete Kazmier</a>
* @version $Id: DefaultRepositoryLayout.java,v 1.1 2003/12/28 20:13:18 michal Exp $
* @todo Choose approprtiate Exception
*/
public class DefaultRepositoryLayout implements Initializable, Serviceable,
RepositoryLayout
{
/**
* The property key used to reference the default layout in the
* layout property file.
*/
private final static String DEFAULT_LAYOUT_KEY = "default";
/**
* If no default layout was specified in the layout property file,
* then this layout is used as a last ditch effort.
*/
private final static String DEFAULT_LAYOUT = "${groupId}/${type}s/${artifactId}-${version}.${type}";
/** List of cachedGlobalLayouts. */
private Properties layouts = null;
private String mavenRepoLocal;
/**
* see org.apache.maven.artifact.RepositoryLayout#generatePath(Artifact)
*/
public String generatePath( final Dependency dependency )
throws Exception
{
final String type = dependency.getType();
return generatePathWithType( dependency, type );
}
/**
* see org.apache.maven.artifact.RepositoryLayout#generatePath(Artifact)
*/
public String generatePathWithType( final Dependency dependency, final String type )
throws Exception
{
final String layout = getLayout( type );
final String groupId = dependency.getGroupId();
final String artifactId = dependency.getArtifactId();
final String version = dependency.getVersion();
final String artifact = dependency.getArtifact();
System.out.println( "artifact_+_)+: " + artifact );
String retValue = interpolateLayout( groupId, artifactId, type, version, layout );
// it means that user is requesting to use a given artifact name
// so path is: "{group directories}/{type}s/[user provided artifact]"
if ( artifact != null )
{
final int i = retValue.lastIndexOf( "/" ) + 1;
retValue = retValue.substring( 0, i ) + artifact;
}
return retValue;
}
/**
* see org.apache.maven.artifact.RepositoryLayout#generatePath(Artifact)
*/
public String generatePathWithVersion( final Dependency dependency, final String version )
throws Exception
{
final String groupId = dependency.getGroupId();
final String artifactId = dependency.getArtifactId();
final String type = dependency.getType();
final String artifact = dependency.getArtifact();
System.out.println( "artifact_+_)+: " + artifact );
final String layout = getLayout( type );
String retValue = interpolateLayout( groupId, artifactId, type, version, layout );
// it means that user is requesting to use a given artifact name
// so path is: "{group directories}/{type}s/[user provided artifact]"
if ( artifact != null )
{
final int i = retValue.lastIndexOf( "/" ) + 1;
retValue = retValue.substring( 0, i ) + artifact;
}
return retValue;
}
/**
* @see org.apache.maven.artifact.layout.RepositoryLayout#generatePath(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
*/
public String generatePath( final String groupId, final String artifactId, final String type,
final String version ) throws Exception
{
final String layout = getLayout( type );
return interpolateLayout( groupId, artifactId, type, version, layout );
}
/**
* @param groupId
* @param artifactId
* @param type
* @param version
* @param layout
*
* @return
*/
private String interpolateLayout( final String groupId, final String artifactId,
final String type, final String version, String layout )
{
layout = StringUtils.replace( layout, "${groupId}", groupId );
layout = StringUtils.replace( layout, "${artifactId}", artifactId );
layout = StringUtils.replace( layout, "${type}", type );
layout = StringUtils.replace( layout, "${version}", version );
return layout;
}
/**
* Gets the layout associated with an artifact type. If the
* type's layout is not specified in the property file, use the
* default layout specified in the same file; otherwise, use the
* hard-coded layout.
*
* @param type Determine the layout for this type of artifact.
*
* @return The layout for the specified artifact type.
*/
private String getLayout( final String type )
{
String layout = ( String ) layouts.get( type );
if ( layout == null )
{
layout = ( String ) layouts.get( DEFAULT_LAYOUT_KEY );
if ( layout == null )
{
layout = DEFAULT_LAYOUT;
}
layouts.put( type, layout );
}
return layout;
}
/**
* @param project
*
* @return
*/
public String getMavenRepoLocal( final Project project )
{
// We want the whole artifact processing to work as a separate tool chain
// so we need to be able to get the location of maven local repository in
// a flexible way.
//
// 1) We will attempt to use a value that has been directly set.
//
// 2) While reading in a project by default the project builder
// tries to read the standard properties files so we will search there
//.
// 3) We can attempt to use a system properties which could be
// set by client code.
if ( mavenRepoLocal == null )
{
if ( System.getProperty( "maven.repo.local" ) != null )
{
mavenRepoLocal = System.getProperty( "maven.repo.local" );
}
else if ( project.getProperties().get( "maven.repo.local" ) != null )
{
mavenRepoLocal = ( String ) project.getProperties().get( "maven.repo.local" );
}
}
if ( mavenRepoLocal != null )
{
final File repo = new File( mavenRepoLocal );
return repo.getAbsolutePath();
}
return mavenRepoLocal;
}
/**
* @param mavenRepoLocal
*/
public void setMavenRepoLocal( final String mavenRepoLocal )
{
this.mavenRepoLocal = mavenRepoLocal;
}
// ----------------------------------------------------------------------
// Lifecycle Management
// ----------------------------------------------------------------------
/**
* @todo is special things for MAX OS needed?
* @see org.apache.avalon.framework.activity.Initializable#initialize()
*/
public void initialize()
throws Exception
{
layouts = loadLayout( "/layout.properties" );
final String osName = System.getProperty( "os.name" );
String suffix = null;
if ( osName.toLowerCase().startsWith( "windows" ) )
{
suffix = "windows";
}
else
{
suffix = "unix";
}
layouts.putAll( loadLayout( "/layout_" + suffix + ".properties" ) );
}
/* (non-Javadoc)
* @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
*/
public void service( final ServiceManager serviceManager )
throws ServiceException
{
//i18n = ( I18N ) serviceManager.lookup( I18N.ROLE );
}
/**
* Load layouts from given properties file
*
* @param filename
*
* @return
*
* @throws MavenException
*/
private Properties loadLayout( final String filename )
throws Exception
{
System.out.println( "Loading: " + filename );
InputStream inputStream = null;
try
{
inputStream = DefaultRepositoryLayout.class.getResourceAsStream( filename );
final Properties properties = new Properties();
properties.load( inputStream );
return properties;
}
catch ( Exception e )
{
final String message = "Cannot read 'layout.properties' file";
throw new Exception( message, e );
}
finally
{
if ( inputStream != null )
{
try
{
inputStream.close();
}
catch ( Exception e )
{
}
}
}
}
}
1.1 maven-components/maven-artifact-factory/src/main/java/org/apache/maven/artifact/layout/RepositoryLayout.java
Index: RepositoryLayout.java
===================================================================
package org.apache.maven.artifact.layout;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache MavenSession" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache MavenSession", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
import org.apache.maven.model.Dependency;
import org.apache.maven.project.Project;
/**
* <code>RepositoryLayout</code> describes how artifacts are to
* be arranged in a user's local repository.
* <br/>
* The layout is type-senstive and for the different
* types of artifacts the layout can be arranged differently.
*
* @author <a href="jason@zenplex.com">Jason van Zyl</a>
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
* @version $Id: RepositoryLayout.java,v 1.1 2003/12/28 20:13:18 michal Exp $
*/
public interface RepositoryLayout
{
/** The role played in Avalon container */
String ROLE = RepositoryLayout.class.getName();
/**
* Returns the relative path for an artifact in local repository.
*
* @param dependency the Artifact for which the path will be built
*
* @return the path
*/
String generatePath( Dependency dependency ) throws Exception;
/**
* Returns the relative path for an artifact in local repository.
*/
String generatePathWithType( Dependency dependency, String type ) throws Exception;
/**
* Returns the relative path for an artifact in local repository.
*/
String generatePathWithVersion( Dependency dependency, String version ) throws Exception;
/**
* Returns the relative path for an artifact in local repository.
*
* @return the path
*/
String generatePath( String groupId, String artifactId, String type, String version )
throws Exception;
String getMavenRepoLocal( Project project );
void setMavenRepoLocal( String mavenRepoLocal );
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org