Author: mcconnell
Date: Mon Jun 28 00:06:55 2004
New Revision: 22230
Modified:
avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/Definition.java
avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/ElementHelper.java
avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/Home.java
avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/Resource.java
avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/XMLDefinitionBuilder.java
avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/InstallTask.java
avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/JavadocTask.java
avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/ReactorTask.java
Log:
Updates to the Resource and Defintion classes to enable improvements to the handling of transative dependencies when dealing with imported resources
Modified: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/Definition.java
==============================================================================
--- avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/Definition.java (original)
+++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/Definition.java Mon Jun 28 00:06:55 2004
@@ -18,11 +18,8 @@
package org.apache.avalon.tools.model;
import org.apache.tools.ant.Project;
-import org.apache.tools.ant.types.Path;
import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
/**
* Defintion of a project.
@@ -32,7 +29,6 @@
*/
public class Definition extends Resource
{
- private ResourceRef[] m_resources;
private ResourceRef[] m_plugins;
private File m_basedir;
@@ -40,94 +36,22 @@
final Home home, final String key, final File basedir, final Info info,
final ResourceRef[] resources, final ResourceRef[] plugins )
{
- super( home, key, info );
+ super( home, key, info, resources );
m_basedir = basedir;
- m_resources = resources;
m_plugins = plugins;
}
- public File getBasedir()
+ public File getBaseDir()
{
return m_basedir;
}
- public ResourceRef[] getResourceRefs()
- {
- return m_resources;
- }
-
- public ResourceRef[] getResourceRefs( final int mode, final int tag, final boolean flag )
- {
- final ArrayList list = new ArrayList();
- getResourceRefs( list, mode, tag, flag );
- return (ResourceRef[]) list.toArray( new ResourceRef[0] );
- }
-
- protected void getResourceRefs( final List list, final int mode, final int tag, final boolean flag )
- {
- final ResourceRef[] refs = getResourceRefs();
- for( int i=0; i<refs.length; i++ )
- {
- final ResourceRef ref = refs[i];
- if( !list.contains( ref ) )
- {
- final Policy policy = ref.getPolicy();
- if( policy.matches( mode ) && ref.matches( tag ) )
- {
- list.add( ref );
- if( flag && getHome().isaDefinition( ref ) )
- {
- final Definition def = getHome().getDefinition( ref );
- def.getResourceRefs( list, mode, ResourceRef.ANY, flag );
- }
- }
- }
- }
- }
-
public ResourceRef[] getPluginRefs()
{
return m_plugins;
}
- public Path getPath( final Project project, final int mode )
- {
- if( null == project )
- {
- throw new NullPointerException( "project" );
- }
-
- final Path path = new Path( project );
- final ResourceRef[] refs = getResourceRefs( mode, ResourceRef.ANY, true );
- for( int i=0; i<refs.length; i++ )
- {
- final ResourceRef ref = refs[i];
- final Resource resource = getHome().getResource( ref );
- final File file = resource.getArtifact( project );
- path.createPathElement().setLocation( file );
- }
-
- return path;
- }
-
- public ResourceRef[] getQualifiedRefs( final List visited, final int category )
- {
- final ArrayList list = new ArrayList();
- final ResourceRef[] refs =
- getResourceRefs( Policy.RUNTIME, category, true );
- for( int i=0; i<refs.length; i++ )
- {
- final ResourceRef ref = refs[i];
- if( !visited.contains( ref ) )
- {
- list.add( ref );
- visited.add( ref );
- }
- }
- return (ResourceRef[]) list.toArray( new ResourceRef[0] );
- }
-
public File getDocDirectory()
{
final File cache = getHome().getDocsRepository().getCacheDirectory();
@@ -145,12 +69,6 @@
if( super.equals( other ) && ( other instanceof Definition ))
{
final Definition def = (Definition) other;
- final ResourceRef[] refs = getResourceRefs();
- final ResourceRef[] references = def.getResourceRefs();
- for( int i=0; i<refs.length; i++ )
- {
- if( !refs[i].equals( references[i] ) ) return false;
- }
final ResourceRef[] plugins = getPluginRefs();
final ResourceRef[] plugins2 = def.getPluginRefs();
Modified: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/ElementHelper.java
==============================================================================
--- avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/ElementHelper.java (original)
+++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/ElementHelper.java Mon Jun 28 00:06:55 2004
@@ -29,6 +29,7 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.io.InputStream;
import java.util.ArrayList;
/**
@@ -74,6 +75,31 @@
throw new BuildException( sxe.getException() );
}
throw new BuildException( sxe );
+ }
+ catch( ParserConfigurationException pce )
+ {
+ // Parser with specified options can't be built
+ throw new BuildException( pce );
+ }
+ catch( IOException ioe )
+ {
+ // I/O error
+ throw new BuildException(ioe);
+ }
+ }
+
+ public static Element getRootElement( final InputStream input )
+ throws Exception
+ {
+ try
+ {
+ final DocumentBuilderFactory factory =
+ DocumentBuilderFactory.newInstance();
+ factory.setValidating( false );
+ factory.setNamespaceAware( false );
+ final Document document =
+ factory.newDocumentBuilder().parse( input );
+ return document.getDocumentElement();
}
catch( ParserConfigurationException pce )
{
Modified: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/Home.java
==============================================================================
--- avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/Home.java (original)
+++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/Home.java Mon Jun 28 00:06:55 2004
@@ -20,14 +20,20 @@
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.BuildListener;
import org.apache.tools.ant.Task;
+import org.apache.tools.ant.Location;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.Get;
import org.apache.tools.ant.taskdefs.Property;
import org.apache.tools.ant.types.DataType;
import org.w3c.dom.Element;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
import java.io.File;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.FileNotFoundException;
+import java.io.FileInputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Hashtable;
@@ -71,7 +77,7 @@
project.log( "index: " + index );
m_index = index;
m_system = system;
- buildList( index, false );
+ buildList( index );
}
//-------------------------------------------------------------
@@ -193,6 +199,194 @@
// internal
//-------------------------------------------------------------
+ private void buildList( final File index )
+ {
+ if( null == index )
+ {
+ throw new NullPointerException( "index" );
+ }
+
+ if( !index.exists() )
+ {
+ throw new BuildException(
+ new FileNotFoundException( index.toString() ) );
+ }
+
+ File source = resolveIndex( index );
+
+ try
+ {
+ final Element root = ElementHelper.getRootElement( source );
+ final Element[] elements = ElementHelper.getChildren( root );
+ final File anchor = source.getParentFile();
+ buildLocalList( anchor, elements );
+ }
+ catch( Throwable e )
+ {
+ throw new BuildException( e, new Location( index.toString() ) );
+ }
+ }
+
+ private File resolveIndex( File file )
+ {
+ if( file.isDirectory() )
+ {
+ return new File( file, "index.xml" );
+ }
+ else
+ {
+ return file;
+ }
+ }
+
+ private void buildLocalList(
+ final File anchor, final Element[] children )
+ {
+ log( "entries: " + children.length, Project.MSG_VERBOSE );
+ for( int i=0; i<children.length; i++ )
+ {
+ final Element element = children[i];
+ final String tag = element.getTagName();
+ if( isaResource( tag ) )
+ {
+ final Resource resource = createResource( element, anchor );
+ final String key = resource.getKey();
+ m_resources.put( key, resource );
+ log(
+ "resource: " + resource
+ + " key=" + key, Project.MSG_VERBOSE );
+ }
+ else if( "import".equals( element.getTagName() ) )
+ {
+ final String filename = element.getAttribute( "index" );
+ final String path = element.getAttribute( "href" );
+
+ if(( null != filename ) && ( !"".equals( filename )))
+ {
+ final File index = Context.getFile( anchor, filename );
+ if( !m_includes.contains( index.toString() ) )
+ {
+ m_includes.add( index );
+ log( "import: " + index );
+ buildList( index );
+ }
+ }
+ else if(( null != path ) && ( !"".equals( path )))
+ {
+ // switch to remote
+ if( !m_includes.contains( path ) )
+ {
+ m_includes.add( path );
+ buildRemoteList( path );
+ }
+ }
+ else
+ {
+ final String error =
+ "Invalid import statement. No href or index attribute.";
+ throw new BuildException( error );
+ }
+ }
+ else
+ {
+ final String error =
+ "Unrecognized element type \"" + tag + "\" found in index.";
+ throw new BuildException( error );
+ }
+ }
+ }
+
+ private void buildRemoteList( String path )
+ {
+ log( "import: " + path );
+ final URL url = createURL( path );
+ InputStream input = null;
+ try
+ {
+ input = url.openStream();
+ final Element root = ElementHelper.getRootElement( input );
+ final Element[] elements = ElementHelper.getChildren( root );
+ buildRemoteList( path, elements );
+ }
+ catch( SAXParseException e )
+ {
+ int line = e.getLineNumber();
+ int column = e.getColumnNumber();
+ throw new BuildException( e, new Location( path, line, column ) );
+ }
+ catch( SAXException e )
+ {
+ if( e.getException() != null)
+ {
+ throw new BuildException(
+ e.getException(), new Location( path ) );
+ }
+ throw new BuildException( e, new Location( path ) );
+ }
+ catch( Throwable e )
+ {
+ throw new BuildException( e, new Location( path ) );
+ }
+ finally
+ {
+ if( null != input )
+ {
+ try
+ {
+ input.close();
+ }
+ catch( IOException ioe )
+ {
+ // ignore
+ }
+ }
+ }
+ }
+
+ private void buildRemoteList( final String source, final Element[] children )
+ {
+ log( "entries: " + children.length, Project.MSG_VERBOSE );
+ for( int i=0; i<children.length; i++ )
+ {
+ final Element element = children[i];
+ final String tag = element.getTagName();
+ if( isaResource( tag ) )
+ {
+ final Resource resource = createResource( element );
+ final String key = resource.getKey();
+ m_resources.put( key, resource );
+ log(
+ "resource: " + resource
+ + " key=" + key, Project.MSG_VERBOSE );
+ }
+ else if( "import".equals( element.getTagName() ) )
+ {
+ final String path = element.getAttribute( "href" );
+ if(( null != path ) && ( !"".equals( path )))
+ {
+ if( !m_includes.contains( path ) )
+ {
+ m_includes.add( path );
+ buildRemoteList( path );
+ }
+ }
+ else
+ {
+ final String error =
+ "Import statement in remote index does not contain an 'href' attribute.";
+ throw new BuildException( error, new Location( source ) );
+ }
+ }
+ else
+ {
+ final String error =
+ "Unrecognized element type \"" + tag + "\" found in remote index.";
+ throw new BuildException( error, new Location( source ) );
+ }
+ }
+ }
+
+ /*
private void buildList( final File index, final boolean remote )
{
final Element root = ElementHelper.getRootElement( index );
@@ -200,7 +394,9 @@
final File system = index.getParentFile();
buildList( system, elements, remote );
}
+ */
+ /*
private void buildList(
final File system, final Element[] children, final boolean remote )
{
@@ -222,6 +418,10 @@
}
else if( "import".equals( element.getTagName() ) )
{
+ //
+ // things get interesting
+ //
+
final String path = element.getAttribute( "href" );
if(( null != path ) && ( !"".equals( path ) ))
{
@@ -281,6 +481,7 @@
}
}
}
+ */
private URL createURL( String path )
{
@@ -307,16 +508,14 @@
}
private Resource createResource(
- final Element element, final File system, final boolean remote )
+ final Element element, final File anchor )
{
- if( remote )
- {
- return XMLDefinitionBuilder.createResource( this, element );
- }
- else
- {
- return XMLDefinitionBuilder.createResource( this, element, system );
- }
+ return XMLDefinitionBuilder.createResource( this, element, anchor );
+ }
+
+ private Resource createResource( final Element element )
+ {
+ return XMLDefinitionBuilder.createResource( this, element );
}
private boolean isaResource( final String tag )
Modified: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/Resource.java
==============================================================================
--- avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/Resource.java (original)
+++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/Resource.java Mon Jun 28 00:06:55 2004
@@ -20,10 +20,13 @@
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.Get;
+import org.apache.tools.ant.types.Path;
import java.io.File;
import java.io.FileNotFoundException;
import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
/**
* Defintion of a resource.
@@ -33,19 +36,24 @@
*/
public class Resource
{
+ private static final ResourceRef[] EMPTY_REFS = new ResourceRef[0];
+
private final String m_key;
private Info m_info;
+ private ResourceRef[] m_resources;
private Home m_home;
public Resource( final Home home, final Info info )
{
- this( home, null, info );
+ this( home, null, info, EMPTY_REFS );
}
- public Resource( final Home home, final String key, final Info info )
+ public Resource(
+ final Home home, final String key, final Info info, final ResourceRef[] resources )
{
m_key = key;
m_info = info;
+ m_resources = resources;
m_home = home;
}
@@ -59,18 +67,91 @@
return m_info;
}
+ public ResourceRef[] getResourceRefs()
+ {
+ return m_resources;
+ }
+
protected Home getHome()
{
return m_home;
}
- public File getArtifact( final Project project )
+ public ResourceRef[] getResourceRefs( final int mode, final int tag, final boolean flag )
+ {
+ final ArrayList list = new ArrayList();
+ getResourceRefs( list, mode, tag, flag );
+ return (ResourceRef[]) list.toArray( new ResourceRef[0] );
+ }
+
+ protected void getResourceRefs(
+ final List list, final int mode, final int tag, final boolean flag )
+ {
+ final ResourceRef[] refs = getResourceRefs();
+ for( int i=0; i<refs.length; i++ )
+ {
+ final ResourceRef ref = refs[i];
+ if( !list.contains( ref ) )
+ {
+ final Policy policy = ref.getPolicy();
+ if( policy.matches( mode ) && ref.matches( tag ) )
+ {
+ list.add( ref );
+ if( flag )
+ {
+ final Resource def = getHome().getResource( ref );
+ def.getResourceRefs( list, mode, ResourceRef.ANY, flag );
+ }
+ }
+ }
+ }
+ }
+
+ public Path getPath( final Project project, final int mode )
+ {
+ if( null == project )
+ {
+ throw new NullPointerException( "project" );
+ }
+
+ final ArrayList visited = new ArrayList();
+ final Path path = new Path( project );
+ final ResourceRef[] refs = getResourceRefs( mode, ResourceRef.ANY, true );
+ for( int i=0; i<refs.length; i++ )
+ {
+ final ResourceRef ref = refs[i];
+ if( !visited.contains( ref ) )
+ {
+ final Resource resource = getHome().getResource( ref );
+ final File file = resource.getArtifact( project );
+ path.createPathElement().setLocation( file );
+ visited.add( ref );
+ }
+ }
+
+ return path;
+ }
+
+ public ResourceRef[] getQualifiedRefs( final List visited, final int category )
{
- //
- // TODO: add support for snapshot semantics
- // based on a resource feature
- //
+ final ArrayList list = new ArrayList();
+ final ResourceRef[] refs =
+ getResourceRefs( Policy.RUNTIME, category, true );
+ for( int i=0; i<refs.length; i++ )
+ {
+ final ResourceRef ref = refs[i];
+ if( !visited.contains( ref ) )
+ {
+ list.add( ref );
+ visited.add( ref );
+ }
+ }
+ return (ResourceRef[]) list.toArray( new ResourceRef[0] );
+ }
+
+ public File getArtifact( final Project project )
+ {
final String path = getInfo().getPath();
final File cache = getHome().getRepository().getCacheDirectory();
final File target = new File( cache, path );
@@ -99,7 +180,7 @@
final Get get = (Get) project.createTask( "get" );
get.setSrc( source );
get.setDest( target );
- get.setIgnoreErrors( true );
+ get.setIgnoreErrors( false );
get.setUseTimestamp( true );
get.setVerbose( false );
get.execute();
@@ -132,7 +213,6 @@
}
}
-
public String toString()
{
return "[" + getInfo().toString() + "]";
@@ -144,6 +224,14 @@
{
final Resource def = (Resource) other;
if( !getInfo().equals( def.getInfo() ) ) return false;
+
+ final ResourceRef[] refs = getResourceRefs();
+ final ResourceRef[] references = def.getResourceRefs();
+ for( int i=0; i<refs.length; i++ )
+ {
+ if( !refs[i].equals( references[i] ) ) return false;
+ }
+
return true;
}
return false;
Modified: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/XMLDefinitionBuilder.java
==============================================================================
--- avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/XMLDefinitionBuilder.java (original)
+++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/XMLDefinitionBuilder.java Mon Jun 28 00:06:55 2004
@@ -86,7 +86,12 @@
final Info info =
createInfo( ElementHelper.getChild( element, "info" ) );
final String key = getDefinitionKey( element, info );
- return new Resource( home, key, info );
+
+ final ResourceRef[] resources =
+ createResourceRefs(
+ ElementHelper.getChild( element, "dependencies" ) );
+
+ return new Resource( home, key, info, resources );
}
public static Definition createDefinition( final Home home, final Element element, final File anchor )
Modified: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/InstallTask.java
==============================================================================
--- avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/InstallTask.java (original)
+++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/InstallTask.java Mon Jun 28 00:06:55 2004
@@ -62,7 +62,7 @@
private void installDeliverables( final Definition definition )
{
- final File basedir = definition.getBasedir();
+ final File basedir = definition.getBaseDir();
final File target = new File( basedir, Context.TARGET );
final File deliverables = new File( target, Context.DELIVERABLES );
if( deliverables.exists() )
Modified: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/JavadocTask.java
==============================================================================
--- avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/JavadocTask.java (original)
+++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/JavadocTask.java Mon Jun 28 00:06:55 2004
@@ -255,7 +255,7 @@
if( resource instanceof Definition )
{
final Definition def = (Definition) resource;
- final File base = def.getBasedir();
+ final File base = def.getBaseDir();
final File src = Context.getFile( base, "target/build/main" );
if( src.exists() )
{
@@ -275,7 +275,7 @@
if( flag )
{
- final File basedir = definition.getBasedir();
+ final File basedir = definition.getBaseDir();
final File local = new File( basedir, "target/build/main" );
if( local.exists() )
{
Modified: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/ReactorTask.java
==============================================================================
--- avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/ReactorTask.java (original)
+++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/ReactorTask.java Mon Jun 28 00:06:55 2004
@@ -129,7 +129,7 @@
public void execute( final Definition definition, final String target )
{
final Ant ant = (Ant) getProject().createTask( "ant" );
- ant.setDir( definition.getBasedir() );
+ ant.setDir( definition.getBaseDir() );
ant.setInheritRefs( false );
ant.setInheritAll( false );
if( null != target )
@@ -233,7 +233,7 @@
for( int i=0; i<defs.length; i++ )
{
final Definition def = defs[i];
- final String base = def.getBasedir().getCanonicalPath();
+ final String base = def.getBaseDir().getCanonicalPath();
if( base.startsWith( path ) )
{
list.add( def );
@@ -276,7 +276,7 @@
{
log( "Skipping dir: "
+ dir
- + "due to missing build.properties file" );
+ + " as it does not exist." );
}
}
return list;
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.