You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by mc...@apache.org on 2003/04/29 16:24:37 UTC
cvs commit: avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/engine/model/impl DefaultClasspath.java EngineConfigurationHelper.java Resources.properties package.html
mcconnell 2003/04/29 07:24:37
Added: merlin/assembly/src/java/org/apache/avalon/assembly/engine/impl
DefaultClasspath.java
EngineConfigurationHelper.java
Removed: merlin/assembly/src/java/org/apache/avalon/assembly/engine/model/impl
DefaultClasspath.java
EngineConfigurationHelper.java Resources.properties
package.html
Log:
consolidating enging impl classes
Revision Changes Path
1.1 avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/engine/impl/DefaultClasspath.java
Index: DefaultClasspath.java
===================================================================
/* ====================================================================
* 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 "Jakarta", "Avalon", and "Apache Software Foundation"
* 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",
* 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/>.
*/
package org.apache.avalon.assembly.engine.impl;
import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import org.apache.avalon.assembly.engine.model.Classpath;
import org.apache.avalon.assembly.engine.model.ClasspathDescriptor;
import org.apache.avalon.assembly.engine.model.FilesetDescriptor;
import org.apache.avalon.assembly.engine.model.IncludeDescriptor;
import org.apache.avalon.assembly.engine.model.ResourceDescriptor;
import org.apache.avalon.assembly.engine.model.ClasspathRuntimeException;
import org.apache.avalon.assembly.repository.Repository;
import org.apache.avalon.assembly.repository.RepositoryException;
/**
* <p>A classpath directive that describes a scoped set of jar files and
* a relative base directory.
*
* @see ClasspathDescriptor
* @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
* @version $Revision: 1.1 $ $Date: 2003/04/29 14:24:37 $
*/
public class DefaultClasspath implements Classpath
{
/**
* The classpath descriptor.
*/
private final ClasspathDescriptor m_classpath;
/**
* Create a new Classpath instance.
* @param classpath the classpath descriptor
*/
public DefaultClasspath( ClasspathDescriptor classpath )
throws IllegalArgumentException
{
m_classpath = classpath;
}
/**
* Expand a classpath to an array of URLS.
* @param system the parent directory of the system repository
* @param base the base directory from which relative classpath entries
* will be resolved.
*/
public URL[] expand( File system, File base )
{
if( base == null )
{
throw new NullPointerException( "base" );
}
List list = new ArrayList();
expand( base, list );
if( system != null )
{
expandResources( system, list );
}
return (URL[]) list.toArray( new URL[0] );
}
/**
* Expand a classpath to an array of URLS.
* @param repository the system repository
* @param base the base directory from which relative classpath entries
* will be resolved.
*/
public URL[] expand( Repository repository, File base )
throws RepositoryException
{
if( base == null )
{
throw new NullPointerException( "base" );
}
List list = new ArrayList();
expand( base, list );
expand( repository, list );
return (URL[]) list.toArray( new URL[0] );
}
/**
* Expand a classpath to an array of URLS.
* @param system the parent directory of the system repository
* @param base the base directory from which relative classpath entries
* will be resolved.
*/
private void expand( File base, List list )
{
FilesetDescriptor[] dirs = m_classpath.getFilesetDescriptors();
for( int i = 0; i < dirs.length; i++ )
{
FilesetDescriptor descriptor = dirs[i];
File anchor = new File( base, descriptor.getBaseDirectory() );
if( !anchor.exists() )
{
final String error =
"Fileset base directory does not exist: "
+ anchor;
throw new ClasspathRuntimeException( error );
}
IncludeDescriptor[] includes = descriptor.getIncludeDescriptors();
for( int j = 0; j < includes.length; j++ )
{
String inc = includes[j].getFile();
try
{
URL url = new File( anchor, inc ).getCanonicalFile().toURL();
list.add( url );
} catch( Throwable e )
{
final String error =
"Error processing a classpath include: "
+ inc;
throw new ClasspathRuntimeException( error, e );
}
}
}
}
/**
* Expand any resource declarations and add them to the supplied list.
*/
private void expand( Repository repository, List list ) throws RepositoryException
{
ResourceDescriptor[] resources = m_classpath.getResourceDescriptors();
if(( repository == null ) && resources.length > 0 )
{
throw new IllegalStateException( "repository" );
}
for( int i = 0; i < resources.length; i++ )
{
final ResourceDescriptor resource = resources[i];
final String group = resource.getGroupID();
final String name = resource.getName();
final String version = resource.getVersion();
list.add( repository.getArtifact( group, name, version, "jar" ) );
}
}
/**
* Return the classpath descriptor.
*
* @return the classpath descriptor
*/
public ClasspathDescriptor getClasspathDescriptor()
{
return m_classpath;
}
/**
* Expand any resource declarations and add them to the supplied list.
*/
private void expandResources( File system, List list )
{
ResourceDescriptor[] resources = m_classpath.getResourceDescriptors();
for( int i = 0; i < resources.length; i++ )
{
final ResourceDescriptor resource = resources[i];
final String group = resource.getGroupID();
final String name = resource.getName();
final String version = resource.getVersion();
File repository = new File( system, "repository" );
File jars = new File( new File( repository, group ), "jars" );
File target = new File( jars, name + "-" + version + ".jar" );
if( target.exists() )
{
try
{
final URL url = target.toURL();
list.add( url );
} catch( Throwable e )
{
final String error =
"Malformed URL error while attempting add resource: " + resource;
throw new IllegalArgumentException( error );
}
} else
{
final String error =
"Supplied resource declaration unresolvable: " + resource;
throw new IllegalArgumentException( error );
}
}
}
/**
* Resolves a supplied URL to a directory.
* @param url the url to resolve
* @return the base directory file
* @exception IllegalArgumentException if the supplied URL
* cannot be resolved to a directory
*/
private static File getBaseDirectory( final URL url )
{
File base = null;
if( url.getProtocol().equals( "file" ) )
{
File file = new File( url.toString().substring( 5 ) );
if( file.isFile() )
{
base = file.getParentFile();
} else
{
base = file;
}
if( base.isDirectory() )
{
return base;
}
}
final String error =
"Cannot resolve base directory from supplied URL: " + url;
throw new IllegalArgumentException( error );
}
}
1.1 avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/engine/impl/EngineConfigurationHelper.java
Index: EngineConfigurationHelper.java
===================================================================
/* ====================================================================
* 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 "Jakarta", "Avalon", and "Apache Software Foundation"
* 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",
* 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/>.
*/
package org.apache.avalon.assembly.engine.impl;
import java.util.ArrayList;
import org.apache.avalon.assembly.engine.model.ClasspathDescriptor;
import org.apache.avalon.assembly.engine.model.FilesetDescriptor;
import org.apache.avalon.assembly.engine.model.IncludeDescriptor;
import org.apache.avalon.assembly.engine.model.LibraryDescriptor;
import org.apache.avalon.assembly.engine.model.ResourceDescriptor;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.meta.model.Profile;
/**
* Handles internalization of an XML based description of a {@link Profile}
* from a Configuration object. The format for Configuration object
* is specified in the <a href="package-summary.html#external">package summary</a>.
*
* @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
* @version $Revision: 1.1 $ $Date: 2003/04/29 14:24:37 $
*/
public class EngineConfigurationHelper
{
/**
* Utility method to create a new classpath descriptor from a
* configuration instance.
* @param config a configuration defining the classpath
* @return the classpath descriptor
* @exception ConfigurationException if the configuration is
* incomplete
*/
public static ClasspathDescriptor createClasspathDescriptor( Configuration config )
throws ConfigurationException
{
ArrayList list = new ArrayList();
Configuration[] configs = config.getChildren( "fileset" );
for( int i = 0; i < configs.length; i++ )
{
Configuration c = configs[i];
list.add( createFilesetDescriptor( c ) );
}
FilesetDescriptor[] filesets =
(FilesetDescriptor[]) list.toArray( new FilesetDescriptor[0] );
//
// the the repository resource descriptors
//
ArrayList res = new ArrayList();
Configuration repository = config.getChild( "repository" );
Configuration[] resources = repository.getChildren( "resource" );
for( int i = 0; i < resources.length; i++ )
{
Configuration resource = resources[i];
String id = resource.getAttribute( "id" );
String version = resource.getAttribute( "version" );
res.add( new ResourceDescriptor( id, version ) );
}
ResourceDescriptor[] descriptors =
(ResourceDescriptor[]) res.toArray( new ResourceDescriptor[0] );
return new ClasspathDescriptor( filesets, descriptors );
}
/**
* Utility method to create a new fileset descriptor from a
* configuration instance.
* @param config a configuration defining the fileset
* @return the fileset descriptor
* @exception ConfigurationException if the configuration is
* incomplete
*/
public static FilesetDescriptor createFilesetDescriptor( Configuration config )
throws ConfigurationException
{
String base = config.getAttribute( "dir", "." );
ArrayList list = new ArrayList();
Configuration[] includeConfigs = config.getChildren( "include" );
for( int i = 0; i < includeConfigs.length; i++ )
{
Configuration includeConfig = includeConfigs[i];
list.add( createIncludeDescriptor( includeConfig ) );
}
IncludeDescriptor[] includes =
(IncludeDescriptor[]) list.toArray( new IncludeDescriptor[0] );
return new FilesetDescriptor( base, includes );
}
/**
* Utility method to create a new include descriptor from a
* configuration instance.
* @param config a configuration defining the include descriptor
* @return the include descriptor
* @exception ConfigurationException if the configuration is
* incomplete
*/
public static IncludeDescriptor createIncludeDescriptor( Configuration config )
throws ConfigurationException
{
String filename = config.getAttribute( "name" );
return new IncludeDescriptor( filename );
}
/**
* Utility method to create a new jar file extension library
* descriptor from a configuration instance.
* @param config a configuration defining the library descriptor
* @return the library descriptor
* @exception ConfigurationException if the configuration is
* incomplete
*/
public static LibraryDescriptor createLibraryDescriptor( Configuration config )
throws ConfigurationException
{
if( config == null )
{
return new LibraryDescriptor();
}
String base = config.getAttribute( "dir", "." );
String scope = config.getAttribute( "scope", "home" );
ArrayList list = new ArrayList();
Configuration[] configs = config.getChildren( "include" );
for( int i = 0; i < configs.length; i++ )
{
Configuration c = configs[i];
list.add( createIncludeDescriptor( c ) );
}
IncludeDescriptor[] dirs =
(IncludeDescriptor[]) list.toArray( new IncludeDescriptor[0] );
return new LibraryDescriptor( scope, base, dirs );
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org