Skip to Content.
Sympa Menu

notify-dpml - svn commit: r1533 - in development/main/magic: bootstrap core/src/main/net/dpml/magic core/src/main/net/dpml/magic/model core/src/main/net/dpml/magic/tasks spells/bar spells/checkstyle spells/doc/task spells/doc/themes/modern spells/eclipse spells/publish spells/style spells/upload test

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: mcconnell AT netcompartner.com
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: svn commit: r1533 - in development/main/magic: bootstrap core/src/main/net/dpml/magic core/src/main/net/dpml/magic/model core/src/main/net/dpml/magic/tasks spells/bar spells/checkstyle spells/doc/task spells/doc/themes/modern spells/eclipse spells/publish spells/style spells/upload test
  • Date: Wed, 19 Jan 2005 16:00:09 +0100

Author: mcconnell
Date: Wed Jan 19 16:00:07 2005
New Revision: 1533

Modified:
development/main/magic/bootstrap/ (props changed)
development/main/magic/core/src/main/net/dpml/magic/Index.java
development/main/magic/core/src/main/net/dpml/magic/model/Module.java
development/main/magic/core/src/main/net/dpml/magic/tasks/ModuleTask.java
development/main/magic/spells/bar/ (props changed)
development/main/magic/spells/checkstyle/ (props changed)
development/main/magic/spells/doc/task/ (props changed)
development/main/magic/spells/doc/themes/modern/ (props changed)
development/main/magic/spells/eclipse/ (props changed)
development/main/magic/spells/publish/ (props changed)
development/main/magic/spells/style/ (props changed)
development/main/magic/spells/upload/ (props changed)
development/main/magic/test/ (props changed)
Log:

As part of the process of finalizing the Transit release I'm taking care of
some long overdue functionality concerning module management and in turn
using this to get the build procedures to create well packaged modules as
part of the release process.

Revision 1533 represents an enhancement to the Index and Module class to
provide support for the creation of Module data models. This is a first step
in moving the index towards a virtual Module. The current implementation
maintains a flat index and the Module is modelled as a type of Resource with
references to dependent resources and contained resources. Changes seem to
be taking things in the direction of the index.xml file serving as the source
file for a module which implies that we should be moving module header
definition content out of the build files and up into the respective index
files.


Modified: development/main/magic/core/src/main/net/dpml/magic/Index.java
==============================================================================
--- development/main/magic/core/src/main/net/dpml/magic/Index.java
(original)
+++ development/main/magic/core/src/main/net/dpml/magic/Index.java Wed
Jan 19 16:00:07 2005
@@ -35,6 +35,7 @@
import net.dpml.magic.model.Definition;
import net.dpml.magic.model.Resource;
import net.dpml.magic.model.ResourceRef;
+import net.dpml.magic.model.Module;
import net.dpml.magic.model.Info;

import net.dpml.transit.Transit;
@@ -479,7 +480,7 @@
}
else if( "module".equals( rootElementName ) )
{
- buildModule( root, source, uri );
+ buildModule( root, source );
}
else
{
@@ -518,7 +519,57 @@
}
}

- private void buildModule( Element root, File source, String uri )
+ public Module buildModule( File source )
+ {
+ try
+ {
+ final Element root = ElementHelper.getRootElement( source );
+ final String rootElementName = root.getTagName();
+ if( "module".equals( rootElementName ) )
+ {
+ return buildModule( root, source );
+ }
+ else
+ {
+ final String error =
+ "Unexpected root module element name ["
+ + rootElementName
+ + "] while reading source ["
+ + source + "].";
+ throw new BuildException( error );
+ }
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Module construction failure using source ["
+ + source
+ + "]";
+ throw new BuildException( error, e );
+ }
+ }
+
+ private Module buildModule( String uri )
+ {
+ try
+ {
+ URL artifact = new URL( null, uri, new Handler() );
+ File local = (File) artifact.getContent( new Class[]{ File.class
} );
+ final Element root = ElementHelper.getRootElement( local );
+ return buildModule( root, local );
+ }
+ catch( IOException ioe )
+ {
+ final String error =
+ "Failed to load module ["
+ + uri
+ + "]."
+ + ioe.toString();
+ throw new BuildException( error, ioe );
+ }
+ }
+
+ private Module buildModule( Element root, File source )
{
//
// its a module definition so we need to add the module as an
available
@@ -529,36 +580,61 @@
if( "".equals( moduleUri ) || ( null == moduleUri ) )
{
String mess =
- "Modules must contain a \"uri\" attribute in the root module
element: " + source;
+ "Modules must contain a \"uri\" attribute in the root module
element: "
+ + source;
throw new BuildException( mess );
}

Info info = Info.create( moduleUri );
String key = info.getName();
- Resource resource = new Resource( this, key, info, new
ResourceRef[0], null );

- if( !m_resources.containsKey( key ) )
+ if( m_resources.containsKey( key ) )
{
- m_resources.put( key, resource );
- log( "resource: " + resource, Project.MSG_VERBOSE );
- }
- else
- {
- Resource r = (Resource) m_resources.get( key );
- if( ! r.equals( resource ) )
+ Resource resource = getResource( key );
+ if( resource instanceof Module )
{
- final String error =
- "WARNING: Ignoring duplicate module key reference ["
- + key
- + "].";
- log( error, Project.MSG_WARN );
+ return (Module) resource;
+ }
+ else
+ {
+ final String error =
+ "Source index or module [" + source + "] declartes the key
[" + key + "] that is already bound.";
+ throw new BuildException( error );
}
}

+ Module.Header header = Module.Header.create( root );
+ String[] imports = Module.createImports( root );
+ ResourceRef[] refs = new ResourceRef[ imports.length ];
+ for( int i=0; i < imports.length; i++ )
+ {
+ String spec = imports[i];
+ Module link = buildModule( spec );
+ refs[i] = new ResourceRef( link.getKey() );
+ }
+
final Element resources = ElementHelper.getChild( root, "resources"
);
final Element[] elements = ElementHelper.getChildren( resources );
final File anchor = source.getParentFile();
- buildLocalList( anchor, elements, uri );
+ final ResourceRef[] children = new ResourceRef[ elements.length ];
+ for( int i=0; i < elements.length; i++ )
+ {
+ final Resource resource = createResource( elements[i], anchor,
moduleUri );
+ final String k = resource.getKey();
+ if( !m_resources.containsKey( k ) )
+ {
+ m_resources.put( k, resource );
+ log( "resource: " + resource, Project.MSG_VERBOSE );
+ }
+ }
+
+ Module module = new Module( this, key, info, refs, "key:NULL",
header, children );
+ m_resources.put( key, module );
+ log( "resource: " + module, Project.MSG_VERBOSE );
+
+ return module;
+
+ //buildLocalList( anchor, elements, uri );
}

private File resolveIndex( File file )

Modified:
development/main/magic/core/src/main/net/dpml/magic/model/Module.java
==============================================================================
--- development/main/magic/core/src/main/net/dpml/magic/model/Module.java
(original)
+++ development/main/magic/core/src/main/net/dpml/magic/model/Module.java
Wed Jan 19 16:00:07 2005
@@ -18,9 +18,14 @@
package net.dpml.magic.model;

import net.dpml.magic.Index;
+import net.dpml.magic.builder.ElementHelper;

import java.net.URL;

+import org.apache.tools.ant.BuildException;
+
+import org.w3c.dom.Element;
+
/**
* A module represent a collection of resources associated with
* a publisher, a source repository, a home site and api documentation, a
set of package
@@ -32,14 +37,36 @@
*/
public class Module extends Resource
{
+ public static String[] createImports( Element element )
+ {
+ Element resources = ElementHelper.getChild( element, "resources" );
+ if( null == resources )
+ {
+ return new String[0];
+ }
+ else
+ {
+ Element[] links = ElementHelper.getChildren( resources, "import"
);
+ String[] list = new String[ links.length ];
+ for( int i=0; i<links.length; i++ )
+ {
+ Element link = links[i];
+ list[i] = ElementHelper.getAttribute( link, "uri" );
+ }
+ return list;
+ }
+ }
+
private Header m_header;
+ private ResourceRef[] m_entries;

public Module(
final Index index, final String key, final Info info, final
ResourceRef[] resources,
- String uri, Header header )
+ String uri, Header header, ResourceRef[] entries )
{
super( index, key, info, resources, uri );
m_header = header;
+ m_entries = entries;
}

public Header getHeader()
@@ -47,8 +74,89 @@
return m_header;
}

+ public ResourceRef[] getEntries()
+ {
+ return m_entries;
+ }
+
public static class Header
{
+ public static Header create( Element element )
+ {
+ try
+ {
+ Element header = ElementHelper.getChild( element, "header" );
+ String publisher = createPublisher( header );
+ URL home = createHref( header, "home" );
+ URL docs = createHref( header, "docs" );
+ URL svn = createHref( header, "svn" );
+ URL repository = createHref( header, "repository" );
+ Legal legal = createLegal( header );
+ return new Header( publisher, legal, home, svn, new
String[0], repository, docs );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Unexpected error while attempting to construct module.";
+ throw new BuildException( error, e );
+ }
+ }
+
+ private static String createPublisher( Element header )
+ {
+ if( null == header )
+ {
+ return null;
+ }
+ else
+ {
+ Element publisher = ElementHelper.getChild( header,
"publisher" );
+ if( null == publisher )
+ {
+ return null;
+ }
+ else
+ {
+ return ElementHelper.getAttribute( publisher, "name",
null );
+ }
+ }
+ }
+
+ private static URL createHref( Element element, String name ) throws
Exception
+ {
+ if( null == element )
+ {
+ return null;
+ }
+ else
+ {
+ Element child = ElementHelper.getChild( element, name );
+ if( null == child )
+ {
+ return null;
+ }
+ else
+ {
+ return new URL( ElementHelper.getAttribute( child,
"href" ) );
+ }
+ }
+ }
+
+ private static Legal createLegal( Element header ) throws Exception
+ {
+ if( null == header )
+ {
+ return new Legal( null, null );
+ }
+ else
+ {
+ Element legal = ElementHelper.getChild( header, "legal" );
+ URL license = createHref( legal, "license" );
+ URL notice = createHref( legal, "notice" );
+ return new Legal( license, notice );
+ }
+ }
+
private final String m_publisher;
private final Legal m_legal;
private final URL m_home;

Modified:
development/main/magic/core/src/main/net/dpml/magic/tasks/ModuleTask.java
==============================================================================
--- development/main/magic/core/src/main/net/dpml/magic/tasks/ModuleTask.java
(original)
+++ development/main/magic/core/src/main/net/dpml/magic/tasks/ModuleTask.java
Wed Jan 19 16:00:07 2005
@@ -25,6 +25,7 @@
import net.dpml.magic.model.ResourceRef;
import net.dpml.magic.project.Context;
import net.dpml.magic.project.DeliverableHelper;
+
import org.apache.tools.ant.BuildException;

import java.io.File;
@@ -177,16 +178,23 @@
{
Definition[] definitions =
getPrivateIndex().getSubsidiaryDefinitions( definition );

- List includes = new ArrayList();
+ List external = new ArrayList();
List modules = new ArrayList();
for( int i=0; i<definitions.length; i++ )
{
Definition def = definitions[i];
- expand( definition, def, includes, modules );
+ expand( definition, def, external, modules );
}

writer.write( "\n <resources>" );

+ //
+ // after scanning all of the contained projects within the scope of
this
+ // module, we scan all of the depedencies, we grab the list of
module uris
+ // implied by the dependencies. This establishes the runtime
imports
+ // (module dependencies that this module has with other moudlues)
+ //
+
String[] uris = (String[]) modules.toArray( new String[0] );
if( uris.length > 0 )
{
@@ -197,6 +205,10 @@
}
}

+ //
+ // parts will be dropped shortly
+ //
+
ResourceRef[] parts = definition.getPartRefs();
if( parts.length > 0 )
{
@@ -212,6 +224,11 @@
}
}

+ //
+ // write out the list of projects (in the form of <resource>
statements
+ // for all projects that are within the scope of the module
+ //
+
writer.write( "\n\n <!-- module resources -->" );
for( int i=0; i<definitions.length; i++ )
{
@@ -219,7 +236,14 @@
writeResource( writer, def );
}

- Resource[] resources = (Resource[]) includes.toArray( new
Resource[0] );
+ //
+ // write out the list of any externally referenced resources that
+ // are not part of the module but required by the module to fullfill
+ // project runtime depedencies (this impl needs to be updated to
+ // crosscheck with resources available under imported modules)
+ //
+
+ Resource[] resources = (Resource[]) external.toArray( new
Resource[0] );
if( resources.length > 0 )
{
writer.write( "\n\n <!-- referenced resources -->" );
@@ -229,6 +253,7 @@
writeResource( writer, resource );
}
}
+
writer.write( "\n\n </resources>" );
}

@@ -236,11 +261,12 @@
* Add the resource referenced by the ref to the list and for all of the
* runtime dependencies of the resource, axpand them into the list.
*
- * @param def the resource reference to expand
- * @param list the expansion list
- * @param modules
+ * @param definition the current module definition
+ * @param def the project defintion to be expanded
+ * @param list the list of external resources to be populated
+ * @param modules the list of module uri names to be populated
*/
- private void expand( Definition definition, Definition def, List list,
List modules )
+ private void expand( final Definition definition, final Definition def,
final List list, final List modules )
{
ResourceRef[] refs = def.getResourceRefs();
for( int i=0; i<refs.length; i++ )
@@ -254,6 +280,7 @@
* Add the resource referenced by the ref to the list and for all of the
* runtime dependencies of the resource, axpand them into the list.
*
+ * @param definition the current module definition
* @param reference the resource reference to expand
* @param list the expansion list
* @param modules



  • svn commit: r1533 - in development/main/magic: bootstrap core/src/main/net/dpml/magic core/src/main/net/dpml/magic/model core/src/main/net/dpml/magic/tasks spells/bar spells/checkstyle spells/doc/task spells/doc/themes/modern spells/eclipse spells/publish spells/style spells/upload test, mcconnell, 01/19/2005

Archive powered by MHonArc 2.6.24.

Top of Page