notify-dpml AT lists.ibiblio.org
Subject: DPML Notify
List archive
r1171 - in trunk/main/depot: . build build/etc/bin build/src/main/net/dpml/library/console core core/console core/console/etc/bin install library library/common library/etc library/etc/test library/etc/test/ant library/etc/test/commons-cli library/etc/test/dpml library/etc/test/jgoodies library/etc/test/junit library/etc/test/samples library/etc/test/xstream library/src/main/net/dpml/library library/src/main/net/dpml/library/impl library/src/main/net/dpml/library/info library/src/main/net/dpml/library/model library/src/test/net/dpml/library/impl library/src/test/net/dpml/library/info tools/builder tools/builder/etc/deliverables tools/builder/etc/deliverables/parts tools/builder/etc/prefs/xmls tools/builder/src/main/net/dpml/tools/impl tools/builder/src/main/net/dpml/tools/info tools/builder/src/main/net/dpml/tools/model tools/builder/src/main/net/dpml/tools/process tools/builder/src/main/net/dpml/tools/tasks
- From: mcconnell at BerliOS <mcconnell AT mail.berlios.de>
- To: notify-dpml AT lists.ibiblio.org
- Subject: r1171 - in trunk/main/depot: . build build/etc/bin build/src/main/net/dpml/library/console core core/console core/console/etc/bin install library library/common library/etc library/etc/test library/etc/test/ant library/etc/test/commons-cli library/etc/test/dpml library/etc/test/jgoodies library/etc/test/junit library/etc/test/samples library/etc/test/xstream library/src/main/net/dpml/library library/src/main/net/dpml/library/impl library/src/main/net/dpml/library/info library/src/main/net/dpml/library/model library/src/test/net/dpml/library/impl library/src/test/net/dpml/library/info tools/builder tools/builder/etc/deliverables tools/builder/etc/deliverables/parts tools/builder/etc/prefs/xmls tools/builder/src/main/net/dpml/tools/impl tools/builder/src/main/net/dpml/tools/info tools/builder/src/main/net/dpml/tools/model tools/builder/src/main/net/dpml/tools/process tools/builder/src/main/net/dpml/tools/tasks
- Date: Tue, 14 Mar 2006 17:03:35 +0100
Author: mcconnell
Date: 2006-03-14 17:03:20 +0100 (Tue, 14 Mar 2006)
New Revision: 1171
Added:
trunk/main/depot/build/
trunk/main/depot/install/
trunk/main/depot/library/build.properties
trunk/main/depot/library/build.xml
trunk/main/depot/library/etc/
trunk/main/depot/library/etc/test/samples/
trunk/main/depot/library/etc/test/samples/anonymous.xml
trunk/main/depot/library/etc/test/samples/example-1.xml
trunk/main/depot/library/etc/test/samples/example-2.xml
trunk/main/depot/library/etc/test/samples/example-3.xml
trunk/main/depot/library/etc/test/samples/example-4.xml
trunk/main/depot/library/etc/test/samples/example-5.xml
trunk/main/depot/library/etc/test/samples/example-6.xml
trunk/main/depot/library/etc/test/samples/example-7.xml
trunk/main/depot/library/etc/test/samples/example-8.xml
trunk/main/depot/library/etc/test/samples/widget.xml
trunk/main/depot/library/src/
trunk/main/depot/library/src/main/net/dpml/library/TypeBuilder.java
trunk/main/depot/library/src/main/net/dpml/library/impl/DefaultTypeBuilder.java
trunk/main/depot/library/src/main/net/dpml/library/impl/LibraryBuilder.java
trunk/main/depot/library/src/test/net/dpml/library/impl/XMLTestCase.java
trunk/main/depot/tools/builder/etc/deliverables/parts/
trunk/main/depot/tools/builder/etc/deliverables/parts/builder.link
trunk/main/depot/tools/builder/etc/deliverables/parts/builder.xml
trunk/main/depot/tools/builder/src/main/net/dpml/tools/tasks/PartTask.java
Removed:
trunk/main/depot/core/install/
trunk/main/depot/library/common/build.properties
trunk/main/depot/library/common/build.xml
trunk/main/depot/library/common/etc/
trunk/main/depot/library/common/src/
trunk/main/depot/library/console/
trunk/main/depot/library/etc/main/
trunk/main/depot/library/etc/test/test.xml
trunk/main/depot/library/src/main/net/dpml/library/impl/LibraryDirectiveBuilder.java
trunk/main/depot/library/src/main/net/dpml/library/impl/ModuleBuilder.java
trunk/main/depot/tools/builder/etc/deliverables/plugins/
Modified:
trunk/main/depot/build/build.xml
trunk/main/depot/build/etc/bin/build.lap
trunk/main/depot/build/src/main/net/dpml/library/console/BuilderPlugin.java
trunk/main/depot/core/console/build.xml
trunk/main/depot/core/console/etc/bin/depot
trunk/main/depot/core/console/etc/bin/depot-cygwin.sh
trunk/main/depot/core/console/etc/bin/depot-unix.sh
trunk/main/depot/core/console/etc/bin/depot.lap
trunk/main/depot/install/build.xml
trunk/main/depot/library/
trunk/main/depot/library/etc/test/ant/module.xml
trunk/main/depot/library/etc/test/commons-cli/module.xml
trunk/main/depot/library/etc/test/dpml/module.xml
trunk/main/depot/library/etc/test/jgoodies/module.xml
trunk/main/depot/library/etc/test/junit/module.xml
trunk/main/depot/library/etc/test/library.xml
trunk/main/depot/library/etc/test/xstream/module.xml
trunk/main/depot/library/src/main/net/dpml/library/impl/DefaultLibrary.java
trunk/main/depot/library/src/main/net/dpml/library/impl/DefaultModule.java
trunk/main/depot/library/src/main/net/dpml/library/impl/DefaultResource.java
trunk/main/depot/library/src/main/net/dpml/library/impl/DefaultType.java
trunk/main/depot/library/src/main/net/dpml/library/info/ResourceDirective.java
trunk/main/depot/library/src/main/net/dpml/library/info/TypeDirective.java
trunk/main/depot/library/src/main/net/dpml/library/model/Resource.java
trunk/main/depot/library/src/test/net/dpml/library/impl/AbstractTestCase.java
trunk/main/depot/library/src/test/net/dpml/library/impl/AnonymousTestCase.java
trunk/main/depot/library/src/test/net/dpml/library/impl/DefaultLibraryTestCase.java
trunk/main/depot/library/src/test/net/dpml/library/impl/DefaultResourceTestCase.java
trunk/main/depot/library/src/test/net/dpml/library/impl/ExportTestCase.java
trunk/main/depot/library/src/test/net/dpml/library/info/ModuleDirectiveTestCase.java
trunk/main/depot/library/src/test/net/dpml/library/info/ResourceDirectiveTestCase.java
trunk/main/depot/library/src/test/net/dpml/library/info/TypeDirectiveTestCase.java
trunk/main/depot/module.xml
trunk/main/depot/tools/builder/build.xml
trunk/main/depot/tools/builder/etc/prefs/xmls/builder.xml
trunk/main/depot/tools/builder/src/main/net/dpml/tools/impl/DefaultContext.java
trunk/main/depot/tools/builder/src/main/net/dpml/tools/impl/DefaultWorkbench.java
trunk/main/depot/tools/builder/src/main/net/dpml/tools/info/BuilderDirectiveHelper.java
trunk/main/depot/tools/builder/src/main/net/dpml/tools/model/Context.java
trunk/main/depot/tools/builder/src/main/net/dpml/tools/process/PluginProcess.java
trunk/main/depot/tools/builder/src/main/net/dpml/tools/tasks/FeatureTask.java
trunk/main/depot/tools/builder/src/main/net/dpml/tools/tasks/InstallTask.java
trunk/main/depot/tools/builder/src/main/net/dpml/tools/tasks/JUnitTestTask.java
trunk/main/depot/tools/builder/src/main/net/dpml/tools/tasks/JarTask.java
trunk/main/depot/tools/builder/src/main/net/dpml/tools/tasks/ModuleTask.java
trunk/main/depot/tools/builder/src/main/net/dpml/tools/tasks/ReplicateTask.java
Log:
include support for full XML schema in the library definition and synchronize
with transit to support generic parts
Copied: trunk/main/depot/build (from rev 1167,
trunk/main/depot/library/console)
Modified: trunk/main/depot/build/build.xml
===================================================================
--- trunk/main/depot/library/console/build.xml 2006-03-05 11:48:22 UTC (rev
1167)
+++ trunk/main/depot/build/build.xml 2006-03-14 16:03:20 UTC (rev 1171)
@@ -9,7 +9,7 @@
<available property="builder.exe.available"
file="${dpml.system}/bin/build.exe"/>
<target name="init" depends="standard.init">
- <x:filter token="ANT-BUILDER-URI" ref="dpml/depot/dpml-tools-builder"
feature="uri" type="plugin"/>
+ <x:filter token="ANT-BUILDER-URI" ref="dpml/depot/dpml-tools-builder"
feature="uri" type="part"/>
</target>
<target name="install" depends="bin,standard.install">
Modified: trunk/main/depot/build/etc/bin/build.lap
===================================================================
--- trunk/main/depot/library/console/etc/bin/build.lap 2006-03-05 11:48:22
UTC (rev 1167)
+++ trunk/main/depot/build/etc/bin/build.lap 2006-03-14 16:03:20 UTC (rev
1171)
@@ -5,6 +5,7 @@
-Ddpml.transit.include.tools=true
-Djava.system.class.loader=net.dpml.transit.SystemClassLoader
-Djava.security.policy=${env.DPML_HOME}\share\bin\security.policy
+-Djava.endorsed.dirs=${env.DPML_HOME}\share\lib\endorsed
-Ddpml.depot.application=dpml.builder
-Djava.protocol.handler.pkgs=net.dpml.transit
janel.main.class=net.dpml.depot.Main
Modified:
trunk/main/depot/build/src/main/net/dpml/library/console/BuilderPlugin.java
===================================================================
---
trunk/main/depot/library/console/src/main/net/dpml/library/console/BuilderPlugin.java
2006-03-05 11:48:22 UTC (rev 1167)
+++
trunk/main/depot/build/src/main/net/dpml/library/console/BuilderPlugin.java
2006-03-14 16:03:20 UTC (rev 1171)
@@ -33,8 +33,9 @@
import net.dpml.library.model.Module;
import net.dpml.library.model.Resource;
import net.dpml.library.model.Builder;
-import net.dpml.library.model.Type;
+import net.dpml.lang.Type;
+
import net.dpml.library.impl.DefaultLibrary;
import net.dpml.cli.Option;
@@ -429,7 +430,7 @@
print( pad + "types: (" + types.length + ")" );
for( int i=0; i<types.length; i++ )
{
- print( p + types[i].getName() );
+ print( p + types[i].getID() );
}
}
Resource[] resources = resource.getProviders( Scope.BUILD, true,
true );
Modified: trunk/main/depot/core/console/build.xml
===================================================================
--- trunk/main/depot/core/console/build.xml 2006-03-14 15:59:54 UTC (rev
1170)
+++ trunk/main/depot/core/console/build.xml 2006-03-14 16:03:20 UTC (rev
1171)
@@ -16,12 +16,11 @@
<filter token="DEPOT-CLASSLOADER-CLASS"
value="net.dpml.transit.SystemClassLoader" />
<x:filter token="TRANSIT-CORE-URI" ref="dpml/transit/dpml-transit-main"
feature="uri" type="jar"/>
<x:filter token="DEPOT-CONSOLE-URI" feature="uri" type="jar"/>
- <x:filter token="DEPOT-EXEC-URI" ref="dpml/metro/dpml-metro-exec"
feature="uri" type="plugin"/>
- <x:filter token="DEPOT-BUILDER-URI"
ref="dpml/depot/dpml-library-console" feature="uri" type="plugin"/>
- <x:filter token="DEPOT-STATION-URI"
ref="dpml/metro/dpml-station-console" feature="uri" type="plugin"/>
- <x:filter token="DEPOT-STATION-SERVER-URI"
ref="dpml/metro/dpml-station-server" feature="uri" type="plugin"/>
- <x:filter token="TRANSIT-CONSOLE-URI"
ref="dpml/transit/dpml-transit-console" feature="uri" type="plugin"/>
- <!--<x:filter token="DEPOT-INSTALL-URI" key="dpml-depot-install"
feature="uri" type="plugin"/>-->
+ <x:filter token="DEPOT-EXEC-URI" ref="dpml/metro/dpml-metro-exec"
feature="uri" type="part"/>
+ <x:filter token="DEPOT-BUILDER-URI" ref="dpml/depot/dpml-library-build"
feature="uri" type="part"/>
+ <x:filter token="DEPOT-STATION-URI"
ref="dpml/metro/dpml-station-console" feature="uri" type="part"/>
+ <x:filter token="DEPOT-STATION-SERVER-URI"
ref="dpml/metro/dpml-station-server" feature="uri" type="part"/>
+ <x:filter token="TRANSIT-CONSOLE-URI"
ref="dpml/transit/dpml-transit-console" feature="uri" type="part"/>
</target>
<!--
@@ -34,7 +33,7 @@
<available property="depot.exe.available"
file="${dpml.system}/bin/depot.exe"/>
- <target name="bootstrap" depends="install,bin">
+ <target name="install" depends="standard.install,bin">
<property name="local" location="${dpml.system}/local"/>
<echo>
#----------------------------------------------------------------------------------
@@ -43,10 +42,10 @@
</echo>
<x:replicate self="true" verbose="false" layout="modern"
todir="${local}" >
<include ref="dpml/depot/dpml-tools-builder"/>
- <include ref="dpml/depot/dpml-library-main"/>
+ <include ref="dpml/depot/dpml-library"/>
+ <include ref="dpml/lang/dpml-common"/>
+ <include ref="dpml/lang/dpml-part"/>
</x:replicate>
- <property name="work" location="${dpml.data}/work"/>
- <mkdir dir="${work}"/>
<echo>
#----------------------------------------------------------------------------------
# Updating ${dpml.system}/lib
@@ -65,6 +64,20 @@
file="${basedir}/target/deliverables/jars/${depot.long.filename}"/>
<echo>
#----------------------------------------------------------------------------------
+# Updating ${dpml.system}/lib/endorsed
+#----------------------------------------------------------------------------------
+ </echo>
+ <transit:get uri="artifact:jar:org/apache/xml/xerces#2.8.0"
property="xerces.path"/>
+ <transit:get uri="artifact:jar:org/apache/xml/xml-apis#2.8.0"
property="xml-apis.path"/>
+ <transit:get uri="artifact:jar:org/apache/xml/xalan#2.7.0"
property="xalan.path"/>
+ <transit:get uri="artifact:jar:org/apache/xml/xalan-serializer#2.7.0"
property="serializer.path"/>
+ <mkdir dir="${lib}/endorsed"/>
+ <copy toDir="${lib}/endorsed" file="${xml-apis.path}"/>
+ <copy toDir="${lib}/endorsed" file="${xerces.path}"/>
+ <copy toDir="${lib}/endorsed" file="${xalan.path}"/>
+ <copy toDir="${lib}/endorsed" file="${serializer.path}"/>
+ <echo>
+#----------------------------------------------------------------------------------
# Updating ${dpml.system}/bin
#----------------------------------------------------------------------------------
</echo>
@@ -80,6 +93,8 @@
<include name="**/depot"/>
</fileset>
</chmod>
+ <property name="work" location="${dpml.data}/work"/>
+ <mkdir dir="${work}"/>
</target>
<target name="bin" depends="prepare" unless="depot.exe.available">
Modified: trunk/main/depot/core/console/etc/bin/depot
===================================================================
--- trunk/main/depot/core/console/etc/bin/depot 2006-03-14 15:59:54 UTC (rev
1170)
+++ trunk/main/depot/core/console/etc/bin/depot 2006-03-14 16:03:20 UTC (rev
1171)
@@ -58,6 +58,11 @@
fi
export DEPOT_SECURITY_POLICY
+if [ "$DEPOT_ENDORSED_DIRECTORY" = "" ] ; then
+ DEPOT_ENDORSED_DIRECTORY=$DPML_SYSTEM/lib/endorsed
+fi
+export DEPOT_ENDORSED_DIRECTORY
+
DEPOT_BASE_JVM_OPTS="-Djava.system.class.loader=@DEPOT-CLASSLOADER-CLASS@
-Djava.rmi.server.randomIDs=true
-Djava.rmi.server.RMIClassLoaderSpi=net.dpml.depot.DepotRMIClassLoaderSpi
-Djava.protocol.handler.pkgs=net.dpml.transit"
if [ "$DEPOT_JVM_OPTS" = "" ] ; then
Modified: trunk/main/depot/core/console/etc/bin/depot-cygwin.sh
===================================================================
--- trunk/main/depot/core/console/etc/bin/depot-cygwin.sh 2006-03-14
15:59:54 UTC (rev 1170)
+++ trunk/main/depot/core/console/etc/bin/depot-cygwin.sh 2006-03-14
16:03:20 UTC (rev 1171)
@@ -25,10 +25,11 @@
DPML_HOME=`cygpath --windows "$DPML_HOME"`
DPML_SYSTEM=`cygpath --windows "$DPML_SYSTEM"`
DEPOT_SECURITY_POLICY=`cygpath --windows "$DEPOT_SECURITY_POLICY"`
+DEPOT_ENDORSED_DIRECTORY=`cygpath --windows "$DEPOT_ENDORSED_DIRECTORY"`
DEPOT_CLASSPATH=`cygpath --path --windows "$DEPOT_CLASSPATH"`
[ -n "$CLASSPATH" ] && CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
-DEPOT_JVM_OPTS="\"-Djava.security.policy=$DEPOT_SECURITY_POLICY\"
$DEPOT_JVM_OPTS"
+DEPOT_JVM_OPTS="\"-Djava.security.policy=$DEPOT_SECURITY_POLICY\"
\"-Djava.endorsed.dirs=$DEPOT_ENDORSED_DIRECTORY\" $DEPOT_JVM_OPTS"
if [ "$DEPOT_DEBUG" = "true" ]; then
TITLE="Starting Depot $DEPOT_VERSION."
@@ -39,6 +40,7 @@
echo " DPML System: $DPML_SYSTEM"
echo " DPML Home: $DPML_HOME"
echo " Security Policy: $DEPOT_SECURITY_POLICY"
+ echo " Security Policy: $DEPOT_SECURITY_POLICY"
echo " JVM Options: $DEPOT_JVM_OPTS"
echo " Classpath: $DEPOT_CLASSPATH"
echo " Depot Arguments: $DEPOT_ARGS"
Modified: trunk/main/depot/core/console/etc/bin/depot-unix.sh
===================================================================
--- trunk/main/depot/core/console/etc/bin/depot-unix.sh 2006-03-14 15:59:54
UTC (rev 1170)
+++ trunk/main/depot/core/console/etc/bin/depot-unix.sh 2006-03-14 16:03:20
UTC (rev 1171)
@@ -17,7 +17,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-DEPOT_JVM_OPTS="\"-Djava.security.policy=$DEPOT_SECURITY_POLICY\"
$DEPOT_JVM_OPTS"
+DEPOT_JVM_OPTS="\"-Djava.security.policy=$DEPOT_SECURITY_POLICY\"
-Djava.endorsed.dirs=$DEPOT_ENDORSED_DIRECTORY $DEPOT_JVM_OPTS"
if [ "$DEPOT_DEBUG" = "true" ]; then
TITLE="Starting Depot $DEPOT_VERSION."
@@ -28,6 +28,7 @@
echo " DPML System: $DPML_SYSTEM"
echo " DPML Home: $DPML_HOME"
echo " Security Policy: $DEPOT_SECURITY_POLICY"
+ echo " Endorced Directory: $DEPOT_ENDORSED_DIRECTORY"
echo " JVM Options: $DEPOT_JVM_OPTS"
echo " Classpath: $DEPOT_CLASSPATH"
echo " Depot Arguments: $DEPOT_ARGS"
Modified: trunk/main/depot/core/console/etc/bin/depot.lap
===================================================================
--- trunk/main/depot/core/console/etc/bin/depot.lap 2006-03-14 15:59:54
UTC (rev 1170)
+++ trunk/main/depot/core/console/etc/bin/depot.lap 2006-03-14 16:03:20
UTC (rev 1171)
@@ -22,6 +22,7 @@
-Djava.protocol.handler.pkgs=net.dpml.transit
-Djava.system.class.loader=net.dpml.transit.SystemClassLoader
-Djava.security.policy=${env.DPML_HOME}\share\bin\security.policy
+-Djava.endorsed.dirs=${env.DPML_HOME}\share\lib\endorsed
-Djava.rmi.server.randomIDs=true
janel.main.class=net.dpml.depot.Main
janel.min.java.version=1.4.0
Copied: trunk/main/depot/install (from rev 1168,
trunk/main/depot/core/install)
Modified: trunk/main/depot/install/build.xml
===================================================================
--- trunk/main/depot/core/install/build.xml 2006-03-08 10:17:16 UTC (rev
1168)
+++ trunk/main/depot/install/build.xml 2006-03-14 16:03:20 UTC (rev 1171)
@@ -12,7 +12,7 @@
<x:filter token="VERSION" feature="version" />
<x:filter token="METRO_BUNDLE_URI" ref="dpml/metro" feature="uri"
type="zip"/>
<x:filter token="DEPOT_BUNDLE_URI" ref="dpml/depot" feature="uri"
type="zip"/>
- <x:filter token="DEPOT-STATION-PLUGIN-URI" key="dpml-station-server"
feature="uri" type="plugin"/>
+ <x:filter token="DEPOT-STATION-PLUGIN-URI" key="dpml-station-server"
feature="uri" type="part"/>
</target>
<target name="build" depends="standard.build">
Property changes on: trunk/main/depot/library
___________________________________________________________________
Name: svn:ignore
+ target
Copied: trunk/main/depot/library/build.properties (from rev 1167,
trunk/main/depot/library/common/build.properties)
===================================================================
--- trunk/main/depot/library/common/build.properties 2006-03-05 11:48:22
UTC (rev 1167)
+++ trunk/main/depot/library/build.properties 2006-03-14 16:03:20 UTC (rev
1171)
@@ -0,0 +1,7 @@
+
+project.group = dpml/depot
+project.name = dpml-library
+project.test.fork = true
+junit.version = 3.8.1
+junit.filename = junit-${junit.version}.jar
+junit.uri = artifact:jar:junit/junit#${junit.version}
Copied: trunk/main/depot/library/build.xml (from rev 1167,
trunk/main/depot/library/common/build.xml)
===================================================================
--- trunk/main/depot/library/common/build.xml 2006-03-05 11:48:22 UTC (rev
1167)
+++ trunk/main/depot/library/build.xml 2006-03-14 16:03:20 UTC (rev 1171)
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<project name="dpml-library" default="install" basedir="."
+ xmlns:transit="antlib:net.dpml.transit" >
+
+ <property file="${basedir}/build.properties"/>
+ <transit:import
file="${dpml.prefs}/dpml/transit/templates/bootstrap.template"/>
+
+ <target name="init" depends="bootstrap.init">
+ <property name="project.xsd.version" value="${project.version}"/>
+ <filter token="MODULE-XSD-URI"
value="artifact:xsd:dpml/lang/dpml-module#1.0"/>
+ <filter token="COMMON-XSD-URI"
value="artifact:xsd:dpml/lang/dpml-common#1.0"/>
+ <filter token="PART-XSD-URI"
value="artifact:xsd:dpml/lang/dpml-part#1.0"/>
+ <filter value="${junit.version}" token="JUNIT_VERSION"/>
+ <filter value="${project.version}" token="PROJECT-VERSION"/>
+ <filter
value="artifact:plugin:dpml/tools/dpml-tools-ant#${project.version}"
token="ANT-BUILDER-URI"/>
+ </target>
+
+ <target name="setup-path" depends="bootstrap.setup-path">
+ <transit:get property="junit.path" uri="${junit.uri}"/>
+ <transit:get property="transit.path"
uri="artifact:jar:dpml/transit/dpml-transit-main#${project.version}"/>
+ <path id="project.main.path">
+ <pathelement
location="${dpml.local.cache}/dpml/transit/jars/dpml-transit-main-${dpml.transit.version}.jar"/>
+ <pathelement location="${target.classes.dir}"/>
+ </path>
+ <path id="project.test.path">
+ <pathelement location="${junit.path}"/>
+ <pathelement location="${transit.path}"/>
+ <pathelement
location="${target.deliverables.jars.dir}/${project.filename}"/>
+ </path>
+ </target>
+
+</project>
+
Deleted: trunk/main/depot/library/common/build.properties
===================================================================
--- trunk/main/depot/library/common/build.properties 2006-03-14 15:59:54
UTC (rev 1170)
+++ trunk/main/depot/library/common/build.properties 2006-03-14 16:03:20
UTC (rev 1171)
@@ -1,6 +0,0 @@
-
-project.group = dpml/depot
-project.name = dpml-library-main
-junit.version = 3.8.1
-junit.filename = junit-${junit.version}.jar
-junit.uri = artifact:jar:junit/junit#${junit.version}
Deleted: trunk/main/depot/library/common/build.xml
===================================================================
--- trunk/main/depot/library/common/build.xml 2006-03-14 15:59:54 UTC (rev
1170)
+++ trunk/main/depot/library/common/build.xml 2006-03-14 16:03:20 UTC (rev
1171)
@@ -1,30 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-
-<project name="dpml-library-main" default="install" basedir="."
- xmlns:transit="antlib:net.dpml.transit" >
-
- <property file="${basedir}/build.properties"/>
- <transit:import
file="${dpml.prefs}/dpml/transit/templates/bootstrap.template"/>
-
- <target name="init" depends="bootstrap.init">
- <filter value="${junit.version}" token="JUNIT_VERSION"/>
- <filter value="${project.version}" token="PROJECT-VERSION"/>
- <filter
value="artifact:plugin:dpml/tools/dpml-tools-ant#${project.version}"
token="ANT-BUILDER-URI"/>
- </target>
-
- <target name="setup-path" depends="bootstrap.setup-path">
- <transit:get property="junit.path" uri="${junit.uri}"/>
- <transit:get property="transit.path"
uri="artifact:jar:dpml/transit/dpml-transit-main#${project.version}"/>
- <path id="project.main.path">
- <pathelement
location="${dpml.local.cache}/dpml/transit/jars/dpml-transit-main-${dpml.transit.version}.jar"/>
- <pathelement location="${target.classes.dir}"/>
- </path>
- <path id="project.test.path">
- <pathelement location="${junit.path}"/>
- <pathelement location="${transit.path}"/>
- <pathelement
location="${target.deliverables.jars.dir}/${project.filename}"/>
- </path>
- </target>
-
-</project>
-
Copied: trunk/main/depot/library/etc (from rev 1167,
trunk/main/depot/library/common/etc)
Modified: trunk/main/depot/library/etc/test/ant/module.xml
===================================================================
--- trunk/main/depot/library/common/etc/test/ant/module.xml 2006-03-05
11:48:22 UTC (rev 1167)
+++ trunk/main/depot/library/etc/test/ant/module.xml 2006-03-14 16:03:20
UTC (rev 1171)
@@ -1,9 +1,6 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
-<!DOCTYPE module PUBLIC "-//DPML//DTD Library 1.0//EN"
"http://download.dpml.net/dtds/library_1_0.dtd" >
+<module name="ant" version="1.6.5" xmlns="@MODULE-XSD-URI@">
-<module name="ant" version="1.6.5">
-
-
<resource name="ant">
<types>
<type id="jar"/>
@@ -29,5 +26,4 @@
</types>
</resource>
-
</module>
Modified: trunk/main/depot/library/etc/test/commons-cli/module.xml
===================================================================
--- trunk/main/depot/library/common/etc/test/commons-cli/module.xml
2006-03-05 11:48:22 UTC (rev 1167)
+++ trunk/main/depot/library/etc/test/commons-cli/module.xml 2006-03-14
16:03:20 UTC (rev 1171)
@@ -1,8 +1,6 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
-<!DOCTYPE module PUBLIC "-//DPML//DTD Library 1.0//EN"
"http://download.dpml.net/dtds/library_1_0.dtd" >
+<module name="commons-cli" version="1.0" xmlns="@MODULE-XSD-URI@">
-<module name="commons-cli" version="1.0">
-
<resource name="commons-cli">
<types>
<type id="jar"/>
Modified: trunk/main/depot/library/etc/test/dpml/module.xml
===================================================================
--- trunk/main/depot/library/common/etc/test/dpml/module.xml 2006-03-05
11:48:22 UTC (rev 1167)
+++ trunk/main/depot/library/etc/test/dpml/module.xml 2006-03-14 16:03:20
UTC (rev 1171)
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
-<!DOCTYPE module PUBLIC "-//DPML//DTD Library 1.0//EN"
"http://download.dpml.net/dtds/library_1_0.dtd" >
+<module xmlns="@MODULE-XSD-URI@"
+ xmlns:part="@PART-XSD-URI@"
+ name="dpml" basedir=".." >
-<module name="dpml" basedir="..">
-
<properties>
<property name="project.publisher.name" value="Digital Product Meta
Library"/>
<property name="project.specification.vendor"
value="${project.publisher.name}"/>
@@ -88,7 +88,7 @@
<types>
<type id="jar"/>
</types>
- <dependencies scope="TEST">
+ <dependencies scope="test">
<include ref="ant/ant-junit"/>
</dependencies>
</project>
@@ -100,11 +100,11 @@
<types>
<type id="jar"/>
</types>
- <dependencies scope="RUNTIME">
+ <dependencies scope="runtime">
<include key="dpml-transit-main"/>
<include ref="ant/ant"/>
</dependencies>
- <dependencies scope="TEST">
+ <dependencies scope="test">
<include ref="ant/ant-junit"/>
</dependencies>
</project>
@@ -143,10 +143,7 @@
<property name="project.template" value="${basedir}/builder.xml"/>
</properties>
<types>
- <type id="plugin" alias="true">
- <property name="project.plugin.class"
- value="net.dpml.part.PartManager"/>
- </type>
+ <part:plugin alias="true" class="net.dpml.part.PartManager"/>
<type id="jar"/>
</types>
<dependencies>
@@ -200,10 +197,7 @@
</properties>
<types>
<type id="jar"/>
- <type id="plugin">
- <property name="project.plugin.class"
- value="net.dpml.metro.runtime.edit.CompositionEditorFactory"/>
- </type>
+ <part:plugin
class="net.dpml.metro.runtime.edit.CompositionEditorFactory"/>
</types>
<dependencies>
<include key="dpml-component-control" tag="public"/>
@@ -217,10 +211,7 @@
</properties>
<types>
<type id="jar"/>
- <type id="plugin">
- <property name="project.plugin.class"
- value="net.dpml.metro.runtime.CompositionController"/>
- </type>
+ <part:plugin alias="true"
class="net.dpml.metro.runtime.CompositionController"/>
</types>
<dependencies>
<include ref="dpml/util/dpml-logging-api" tag="public"/>
@@ -238,12 +229,7 @@
</properties>
<types>
<type id="jar"/>
- <type id="plugin">
- <property name="project.plugin.resource"
- value="net/dpml/composition/tools/antlib.xml"/>
- <property name="project.plugin.urn"
- value="dpml:metro"/>
- </type>
+ <part:resource urn="dpml:metro"
path="net/dpml/composition/tools/antlib.xml"/>
</types>
<dependencies>
<include ref="dpml/tools/dpml-tools-ant"/>
@@ -305,10 +291,7 @@
</properties>
<types>
<type id="jar"/>
- <type id="plugin" alias="true">
- <property name="project.plugin.class"
- value="net.dpml.library.impl.BuildPlugin"/>
- </type>
+ <part:plugin alias="true"
class="net.dpml.library.impl.BuildPlugin"/>
</types>
<dependencies>
<include key="dpml-tools-model"/>
@@ -325,10 +308,7 @@
</properties>
<types>
<type id="jar"/>
- <type id="plugin" alias="true">
- <property name="project.plugin.class"
- value="net.dpml.tools.impl.StandardBuilder"/>
- </type>
+ <part:plugin alias="true"
class="net.dpml.tools.impl.StandardBuilder"/>
</types>
<dependencies>
<include key="dpml-tools-control"/>
Modified: trunk/main/depot/library/etc/test/jgoodies/module.xml
===================================================================
--- trunk/main/depot/library/common/etc/test/jgoodies/module.xml
2006-03-05 11:48:22 UTC (rev 1167)
+++ trunk/main/depot/library/etc/test/jgoodies/module.xml 2006-03-14
16:03:20 UTC (rev 1171)
@@ -1,8 +1,6 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
-<!DOCTYPE module PUBLIC "-//DPML//DTD Library 1.0//EN"
"http://download.dpml.net/dtds/library_1_0.dtd" >
+<module xmlns="@MODULE-XSD-URI@" name="jgoodies">
-<module name="jgoodies">
-
<resource name="looks" version="1.1">
<types>
<type id="jar"/>
Modified: trunk/main/depot/library/etc/test/junit/module.xml
===================================================================
--- trunk/main/depot/library/common/etc/test/junit/module.xml 2006-03-05
11:48:22 UTC (rev 1167)
+++ trunk/main/depot/library/etc/test/junit/module.xml 2006-03-14 16:03:20
UTC (rev 1171)
@@ -1,8 +1,6 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
-<!DOCTYPE module PUBLIC "-//DPML//DTD Library 1.0//EN"
"http://download.dpml.net/dtds/library_1_0.dtd" >
+<module xmlns="@MODULE-XSD-URI@" name="junit" version="3.8.1">
-<module name="junit" version="3.8.1">
-
<resource name="junit">
<types>
<type id="jar"/>
Modified: trunk/main/depot/library/etc/test/library.xml
===================================================================
--- trunk/main/depot/library/common/etc/test/library.xml 2006-03-05
11:48:22 UTC (rev 1167)
+++ trunk/main/depot/library/etc/test/library.xml 2006-03-14 16:03:20
UTC (rev 1171)
@@ -1,8 +1,6 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
-<!DOCTYPE library PUBLIC "-//DPML//DTD Library 1.0//EN"
"http://download.dpml.net/dtds/library_1_0.dtd" >
+<library xmlns="@MODULE-XSD-URI@"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
-<library>
-
<properties>
<property name="project.builder.uri"
value="link:plugin:dpml/tools/dpml-tools-builder"/>
<property name="project.standard.template"
value="local:template:dpml/tools/standard"/>
@@ -10,12 +8,12 @@
</properties>
<modules>
- <module file="junit/module.xml"/>
- <module file="commons-cli/module.xml"/>
- <module file="xstream/module.xml"/>
- <module file="jgoodies/module.xml"/>
- <module file="dpml/module.xml"/>
- <module file="ant/module.xml"/>
+ <import file="junit/module.xml"/>
+ <import file="commons-cli/module.xml"/>
+ <import file="xstream/module.xml"/>
+ <import file="jgoodies/module.xml"/>
+ <import file="dpml/module.xml"/>
+ <import file="ant/module.xml"/>
</modules>
</library>
Added: trunk/main/depot/library/etc/test/samples/anonymous.xml
===================================================================
--- trunk/main/depot/library/common/etc/test/samples/anonymous.xml
2006-03-05 11:48:22 UTC (rev 1167)
+++ trunk/main/depot/library/etc/test/samples/anonymous.xml 2006-03-14
16:03:20 UTC (rev 1171)
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<library xmlns="@MODULE-XSD-URI@"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+ <properties>
+ <property name="project.builder.uri"
value="link:plugin:dpml/tools/dpml-tools-builder"/>
+ <property name="project.standard.template"
value="local:template:dpml/tools/standard"/>
+ <property name="project.template" value="${project.standard.template}"/>
+ </properties>
+
+ <modules>
+ <module name="demo" basedir=".">
+ <project name="example" basedir="example">
+ <types>
+ <type id="jar"/>
+ </types>
+ <dependencies>
+ <include
urn="artifact:jar:commons-collections/commons-collections#3.0"/>
+ </dependencies>
+ </project>
+ </module>
+ </modules>
+
+</library>
Added: trunk/main/depot/library/etc/test/samples/example-1.xml
===================================================================
--- trunk/main/depot/library/common/etc/test/samples/example-1.xml
2006-03-05 11:48:22 UTC (rev 1167)
+++ trunk/main/depot/library/etc/test/samples/example-1.xml 2006-03-14
16:03:20 UTC (rev 1171)
@@ -0,0 +1,4 @@
+<?xml version="1.0"?>
+<library xmlns="@MODULE-XSD-URI@"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+</library>
Added: trunk/main/depot/library/etc/test/samples/example-2.xml
===================================================================
--- trunk/main/depot/library/common/etc/test/samples/example-2.xml
2006-03-05 11:48:22 UTC (rev 1167)
+++ trunk/main/depot/library/etc/test/samples/example-2.xml 2006-03-14
16:03:20 UTC (rev 1171)
@@ -0,0 +1,9 @@
+<?xml version="1.0"?>
+<library xmlns="@MODULE-XSD-URI@"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+ <properties>
+ <property name="foo" value="bar"/>
+ <property name="ping" value="pong"/>
+ </properties>
+
+</library>
Added: trunk/main/depot/library/etc/test/samples/example-3.xml
===================================================================
--- trunk/main/depot/library/common/etc/test/samples/example-3.xml
2006-03-05 11:48:22 UTC (rev 1167)
+++ trunk/main/depot/library/etc/test/samples/example-3.xml 2006-03-14
16:03:20 UTC (rev 1171)
@@ -0,0 +1,9 @@
+<?xml version="1.0"?>
+<library xmlns="@MODULE-XSD-URI@"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+ <imports>
+ <import uri="link:xml:abc/def/import-1#1.0"/>
+ <import uri="foo:bar"/>
+ </imports>
+
+</library>
Added: trunk/main/depot/library/etc/test/samples/example-4.xml
===================================================================
--- trunk/main/depot/library/common/etc/test/samples/example-4.xml
2006-03-05 11:48:22 UTC (rev 1167)
+++ trunk/main/depot/library/etc/test/samples/example-4.xml 2006-03-14
16:03:20 UTC (rev 1171)
@@ -0,0 +1,17 @@
+<?xml version="1.0"?>
+<library xmlns="@MODULE-XSD-URI@"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+ <imports>
+ <import uri="link:module:junit"/>
+ <import uri="link:module:ant"/>
+ </imports>
+
+ <modules>
+ <module name="acme" basedir=".">
+ <module name="widget"/>
+ </module>
+ <module name="foo"/>
+ <module name="bar"/>
+ </modules>
+
+</library>
Added: trunk/main/depot/library/etc/test/samples/example-5.xml
===================================================================
--- trunk/main/depot/library/common/etc/test/samples/example-5.xml
2006-03-05 11:48:22 UTC (rev 1167)
+++ trunk/main/depot/library/etc/test/samples/example-5.xml 2006-03-14
16:03:20 UTC (rev 1171)
@@ -0,0 +1,19 @@
+<?xml version="1.0"?>
+<library xmlns="@MODULE-XSD-URI@"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+ <imports>
+ <import uri="link:module:junit"/>
+ <import uri="link:module:ant"/>
+ </imports>
+
+ <modules>
+ <module name="acme" basedir=".">
+ <properties>
+ <property name="fred" value="wilma"/>
+ <property name="foo" value="bar"/>
+ <property name="widget" value="gizmo"/>
+ </properties>
+ </module>
+ </modules>
+
+</library>
Added: trunk/main/depot/library/etc/test/samples/example-6.xml
===================================================================
--- trunk/main/depot/library/common/etc/test/samples/example-6.xml
2006-03-05 11:48:22 UTC (rev 1167)
+++ trunk/main/depot/library/etc/test/samples/example-6.xml 2006-03-14
16:03:20 UTC (rev 1171)
@@ -0,0 +1,13 @@
+<?xml version="1.0"?>
+<library xmlns="@MODULE-XSD-URI@"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+ <imports>
+ <import uri="link:module:junit"/>
+ <import uri="link:module:ant"/>
+ </imports>
+
+ <modules>
+ <import file="widget.xml"/>
+ </modules>
+
+</library>
Added: trunk/main/depot/library/etc/test/samples/example-7.xml
===================================================================
--- trunk/main/depot/library/common/etc/test/samples/example-7.xml
2006-03-05 11:48:22 UTC (rev 1167)
+++ trunk/main/depot/library/etc/test/samples/example-7.xml 2006-03-14
16:03:20 UTC (rev 1171)
@@ -0,0 +1,15 @@
+<?xml version="1.0"?>
+<library xmlns="@MODULE-XSD-URI@"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+ <imports>
+ <import uri="link:module:junit"/>
+ <import uri="link:module:ant"/>
+ </imports>
+
+ <modules>
+ <module name="acme">
+ <import file="widget.xml"/>
+ </module>
+ </modules>
+
+</library>
Added: trunk/main/depot/library/etc/test/samples/example-8.xml
===================================================================
--- trunk/main/depot/library/common/etc/test/samples/example-8.xml
2006-03-05 11:48:22 UTC (rev 1167)
+++ trunk/main/depot/library/etc/test/samples/example-8.xml 2006-03-14
16:03:20 UTC (rev 1171)
@@ -0,0 +1,25 @@
+<?xml version="1.0"?>
+<library xmlns="@MODULE-XSD-URI@"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:part="artifact:xsd:dpml/lang/dpml-part#1.0">
+
+ <imports>
+ <import uri="link:module:junit"/>
+ <import uri="link:module:ant"/>
+ </imports>
+
+ <modules>
+ <module name="acme">
+ <resource name="widget">
+ <types>
+ <type id="foo">
+ <property name="pink" value="floyd"/>
+ <property name="alice" value="cooper"/>
+ </type>
+ <part:plugin class="Widget"/>
+ </types>
+ </resource>
+ </module>
+ </modules>
+
+</library>
Added: trunk/main/depot/library/etc/test/samples/widget.xml
===================================================================
--- trunk/main/depot/library/common/etc/test/samples/widget.xml 2006-03-05
11:48:22 UTC (rev 1167)
+++ trunk/main/depot/library/etc/test/samples/widget.xml 2006-03-14
16:03:20 UTC (rev 1171)
@@ -0,0 +1,2 @@
+<?xml version="1.0"?>
+<module xmlns="@MODULE-XSD-URI@" name="abc"/>
Deleted: trunk/main/depot/library/etc/test/test.xml
===================================================================
--- trunk/main/depot/library/common/etc/test/test.xml 2006-03-05 11:48:22
UTC (rev 1167)
+++ trunk/main/depot/library/etc/test/test.xml 2006-03-14 16:03:20 UTC (rev
1171)
@@ -1,25 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<!DOCTYPE library PUBLIC "-//DPML//DTD Library 1.0//EN"
"http://download.dpml.net/dtds/library_1_0.dtd" >
-
-<library>
-
- <properties>
- <property name="project.builder.uri"
value="link:plugin:dpml/tools/dpml-tools-builder"/>
- <property name="project.standard.template"
value="local:template:dpml/tools/standard"/>
- <property name="project.template" value="${project.standard.template}"/>
- </properties>
-
- <modules>
- <module name="demo" basedir=".">
- <project name="example" basedir="example">
- <types>
- <type id="jar"/>
- </types>
- <dependencies>
- <include
urn="artifact:jar:commons-collections/commons-collections#3.0"/>
- </dependencies>
- </project>
- </module>
- </modules>
-
-</library>
Modified: trunk/main/depot/library/etc/test/xstream/module.xml
===================================================================
--- trunk/main/depot/library/common/etc/test/xstream/module.xml 2006-03-05
11:48:22 UTC (rev 1167)
+++ trunk/main/depot/library/etc/test/xstream/module.xml 2006-03-14
16:03:20 UTC (rev 1171)
@@ -1,8 +1,6 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
-<!DOCTYPE module PUBLIC "-//DPML//DTD Library 1.0//EN"
"http://download.dpml.net/dtds/library_1_0.dtd" >
+<module xmlns="@MODULE-XSD-URI@" name="xstream" version="1.1">
-<module name="xstream" version="1.1">
-
<resource name="xstream">
<types>
<type id="jar"/>
Copied: trunk/main/depot/library/src (from rev 1167,
trunk/main/depot/library/common/src)
Added: trunk/main/depot/library/src/main/net/dpml/library/TypeBuilder.java
===================================================================
---
trunk/main/depot/library/common/src/main/net/dpml/library/TypeBuilder.java
2006-03-05 11:48:22 UTC (rev 1167)
+++ trunk/main/depot/library/src/main/net/dpml/library/TypeBuilder.java
2006-03-14 16:03:20 UTC (rev 1171)
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2006 Stephen J. McConnell.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.library;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import org.w3c.dom.Element;
+
+import net.dpml.lang.Type;
+import net.dpml.lang.Builder;
+
+import net.dpml.library.info.TypeDirective;
+
+/**
+ * Construct an Strategy instance from a DOM Element.
+ */
+public interface TypeBuilder //extends Builder
+{
+ String getID();
+
+ Type buildType( ClassLoader classoader, TypeDirective type ) throws
Exception;
+
+ //void write( Writer writer, TypeDirective type ) throws IOException;
+}
Modified:
trunk/main/depot/library/src/main/net/dpml/library/impl/DefaultLibrary.java
===================================================================
---
trunk/main/depot/library/common/src/main/net/dpml/library/impl/DefaultLibrary.java
2006-03-05 11:48:22 UTC (rev 1167)
+++
trunk/main/depot/library/src/main/net/dpml/library/impl/DefaultLibrary.java
2006-03-14 16:03:20 UTC (rev 1171)
@@ -51,7 +51,7 @@
*/
public final class DefaultLibrary extends DefaultDictionary implements
Library
{
- private static final ModuleBuilder BUILDER = new ModuleBuilder();
+ private static final LibraryBuilder BUILDER = new LibraryBuilder();
private final LibraryDirective m_directive;
private final DefaultModule m_module;
@@ -60,6 +60,12 @@
private final Logger m_logger;
private final Hashtable m_anonymous = new Hashtable();
+ private static LibraryDirective buildLibraryDirective( File source )
throws Exception
+ {
+ LibraryBuilder builder = new LibraryBuilder();
+ return builder.build( source );
+ }
+
/**
* Creation of a new library. The definition of the library will
* be resolved by search up the file system for a file named library.xml.
@@ -79,7 +85,7 @@
*/
public DefaultLibrary( Logger logger, File source ) throws Exception
{
- super( null, LibraryDirectiveBuilder.build( source ) );
+ super( null, buildLibraryDirective( source ) );
if( null == logger )
{
@@ -103,18 +109,14 @@
ImportDirective.Mode mode = include.getMode();
if( ImportDirective.Mode.FILE.equals( mode ) )
{
- String path = include.getValue();
- File file = new File( m_root, path );
- getLogger().debug( "loading local import: " + file );
- importModuleDirectives[i] =
LibraryDirectiveBuilder.buildModuleDirective( m_root, path );
+ throw new UnsupportedOperationException( "file" );
}
else
{
String path = include.getValue();
URI uri = new URI( path );
getLogger().debug( "loading external import: " + uri );
- URL url = Artifact.createArtifact( uri ).toURL();
- importModuleDirectives[i] = BUILDER.load( url );
+ importModuleDirectives[i] = BUILDER.buildModule( uri );
//InputStream input = url.openStream();
//importModuleDirectives[i] =
LibraryDirectiveBuilder.buildModuleDirective( input );
@@ -417,59 +419,6 @@
return m_root;
}
- /*
- DefaultProcessor getDefaultProcessor( String id ) throws
InvalidProcessorNameException
- {
- for( int i=0; i<m_processes.length; i++ )
- {
- DefaultProcessor processor = m_processes[i];
- String name = processor.getName();
- if( name.equals( id ) )
- {
- return processor;
- }
- }
- throw new InvalidProcessorNameException( id );
- }
-
- DefaultProcessor[] getDefaultProcessorSequence( Type[] types )
- {
- String[] names = getProcessorNames( types );
- DefaultProcessor[] processors = new DefaultProcessor[ names.length ];
- for( int i=0; i<names.length; i++ )
- {
- String name = names[i];
- processors[i] = getDefaultProcessor( name );
- }
- return processors;
- }
-
- String[] getProcessorNames( Type[] types )
- {
- String[] names = getTypeNames( types );
- ProcessorDescriptor[] descriptors = getProcessorDescriptors( names );
- ProcessorDescriptor[] sorted = sortProcessorDescriptors( descriptors
);
- String[] processors = new String[ sorted.length ];
- for( int i=0; i<sorted.length; i++ )
- {
- ProcessorDescriptor descriptor = sorted[i];
- processors[i] = descriptor.getName();
- }
- return processors;
- }
-
- String[] getTypeNames( Type[] types )
- {
- String[] names = new String[ types.length ];
- for( int i=0; i<types.length; i++ )
- {
- Type type = types[i];
- names[i] = type.getName();
- }
- return names;
- }
- */
-
/**
* Return the array of top-level modules.
* @return the top-level module array
@@ -523,81 +472,6 @@
}
//----------------------------------------------------------------------------
- // internal ProcessorDescriptor sorting
-
//----------------------------------------------------------------------------
-
- /*
- private ProcessorDescriptor[] getProcessorDescriptors( String[] names )
- {
- ArrayList list = new ArrayList();
- for( int i=0; i<names.length; i++ )
- {
- String name = names[i];
- try
- {
- ProcessorDescriptor descriptor = getProcessorDescriptor(
name );
- list.add( descriptor );
- }
- catch( InvalidProcessorNameException e )
- {
- }
- }
- return (ProcessorDescriptor[]) list.toArray( new
ProcessorDescriptor[0] );
- }
-
- private ProcessorDescriptor getProcessorDescriptor( String name ) throws
InvalidProcessorNameException
- {
- ProcessorDescriptor[] processes =
m_directive.getProcessorDescriptors();
- for( int i=0; i<processes.length; i++ )
- {
- ProcessorDescriptor process = processes[i];
- if( process.getName().equals( name ) )
- {
- return process;
- }
- }
- throw new InvalidProcessorNameException( name );
- }
-
- private ProcessorDescriptor[] getProcessorDescriptors()
- {
- return m_directive.getProcessorDescriptors();
- }
-
- private ProcessorDescriptor[] sortProcessorDescriptors(
ProcessorDescriptor[] descriptors )
- {
- ArrayList visited = new ArrayList();
- ArrayList stack = new ArrayList();
- for( int i=0; i<descriptors.length; i++ )
- {
- ProcessorDescriptor descriptor = descriptors[i];
- processProcessorDescriptor( visited, stack, descriptor );
- }
- return (ProcessorDescriptor[]) stack.toArray( new
ProcessorDescriptor[0] );
- }
-
- private void processProcessorDescriptor(
- List visited, List stack, ProcessorDescriptor descriptor )
- {
- if( visited.contains( descriptor ) )
- {
- return;
- }
- else
- {
- visited.add( descriptor );
- String[] deps = descriptor.getDependencies();
- ProcessorDescriptor[] providers = getProcessorDescriptors( deps
);
- for( int i=0; i<providers.length; i++ )
- {
- processProcessorDescriptor( visited, stack, providers[i] );
- }
- stack.add( descriptor );
- }
- }
- */
-
-
//----------------------------------------------------------------------------
// other internals
//----------------------------------------------------------------------------
Modified:
trunk/main/depot/library/src/main/net/dpml/library/impl/DefaultModule.java
===================================================================
---
trunk/main/depot/library/common/src/main/net/dpml/library/impl/DefaultModule.java
2006-03-05 11:48:22 UTC (rev 1167)
+++
trunk/main/depot/library/src/main/net/dpml/library/impl/DefaultModule.java
2006-03-14 16:03:20 UTC (rev 1171)
@@ -39,6 +39,7 @@
import net.dpml.lang.Category;
+import net.dpml.lang.Type;
/**
* A Module is a collection of resources. It serves to establish a
@@ -273,9 +274,10 @@
String version = getVersion();
String basedir = null;
TypeDirective[] types = m_directive.getTypeDirectives();
+ TypeDirective[] exportedTypes = createExportedTypes( types );
return new ModuleDirective(
name, version, Classifier.EXTERNAL, basedir,
- types, new DependencyDirective[0], directives, null );
+ exportedTypes, new DependencyDirective[0], directives, null );
}
//----------------------------------------------------------------------------
Modified:
trunk/main/depot/library/src/main/net/dpml/library/impl/DefaultResource.java
===================================================================
---
trunk/main/depot/library/common/src/main/net/dpml/library/impl/DefaultResource.java
2006-03-05 11:48:22 UTC (rev 1167)
+++
trunk/main/depot/library/src/main/net/dpml/library/impl/DefaultResource.java
2006-03-14 16:03:20 UTC (rev 1171)
@@ -30,7 +30,6 @@
import java.util.Properties;
import net.dpml.library.model.Resource;
-import net.dpml.library.model.Type;
import net.dpml.library.model.Module;
import net.dpml.library.info.TypeDirective;
import net.dpml.library.info.ResourceDirective;
@@ -44,6 +43,8 @@
import net.dpml.transit.Artifact;
import net.dpml.lang.Category;
+import net.dpml.lang.Type;
+
/**
* Implementation of a resource.
*
@@ -65,7 +66,7 @@
private final DefaultLibrary m_library;
private final ResourceDirective m_directive;
private final DefaultModule m_parent;
- private final DefaultType[] m_types;
+ private final Type[] m_types;
private final String[] m_typeNames;
private final String m_path;
private final File m_basedir;
@@ -77,7 +78,7 @@
m_library = library;
m_directive = null;
m_parent = null;
- m_types = new DefaultType[0];
+ m_types = new Type[0];
m_typeNames = new String[0];
m_path = "";
m_basedir = null;
@@ -103,13 +104,13 @@
{
m_path = module.getResourcePath() + "/" + directive.getName();
}
-
- m_types = resolveTypes( directive );
+
+ m_types = buildTypes( directive.getTypeDirectives() );
m_typeNames = new String[ m_types.length ];
for( int i=0; i<m_types.length; i++ )
{
Type type = m_types[i];
- m_typeNames[i] = type.getName();
+ m_typeNames[i] = type.getID();
}
File anchor = getAnchor();
@@ -156,6 +157,17 @@
}
}
+ private Type[] buildTypes( TypeDirective[] directives )
+ {
+ Type[] types = new Type[ directives.length ];
+ for( int i=0; i<directives.length; i++ )
+ {
+ TypeDirective directive = directives[i];
+ types[i] = new DefaultType( this, directive );
+ }
+ return types;
+ }
+
//----------------------------------------------------------------------------
// Resource
//----------------------------------------------------------------------------
@@ -263,7 +275,7 @@
for( int i=0; i<m_types.length; i++ )
{
Type someType = m_types[i];
- String name = someType.getName();
+ String name = someType.getID();
if( name.equals( type ) )
{
return true;
@@ -284,7 +296,7 @@
for( int i=0; i<m_types.length; i++ )
{
Type type = m_types[i];
- if( type.getName().equals( id ) )
+ if( type.getID().equals( id ) )
{
return type;
}
@@ -487,13 +499,27 @@
String version = getVersion();
String basedir = null;
TypeDirective[] types = m_directive.getTypeDirectives();
+ TypeDirective[] exportedTypes = createExportedTypes( types );
DependencyDirective[] dependencies = createDeps( module );
Properties properties = getExportProperties();
return new ResourceDirective(
name, version, Classifier.EXTERNAL, basedir,
- types, dependencies, properties );
+ exportedTypes, dependencies, properties );
}
+ TypeDirective[] createExportedTypes( TypeDirective[] types )
+ {
+ TypeDirective[] export = new TypeDirective[ types.length ];
+ for( int i=0; i<export.length; i++ )
+ {
+ TypeDirective type = types[i];
+ String id = type.getID();
+ boolean alias = type.getAlias();
+ export[i] = new TypeDirective( id, alias );
+ }
+ return export;
+ }
+
private DependencyDirective[] createDeps( DefaultModule module )
{
ArrayList list = new ArrayList();
@@ -565,7 +591,7 @@
for( int j=0; j<types.length; j++ )
{
Type type = types[j];
- String label = type.getName();
+ String label = type.getID();
Artifact artifact = provider.getArtifact( label );
String urn = artifact.toString();
IncludeDirective include =
@@ -711,7 +737,7 @@
list.add( resource );
}
}
- else if( resource.isa( Type.JAR ) )
+ else if( resource.isa( "jar" ) )
{
if( !list.contains( resource ) )
{
@@ -1052,22 +1078,6 @@
}
//----------------------------------------------------------------------------
- // type utilities
-
//----------------------------------------------------------------------------
-
- private DefaultType[] resolveTypes( ResourceDirective directive )
- {
- TypeDirective[] directives = directive.getTypeDirectives();
- DefaultType[] types = new DefaultType[ directives.length ];
- for( int i=0; i<directives.length; i++ )
- {
- TypeDirective type = directives[i];
- types[i] = new DefaultType( this, type );
- }
- return types;
- }
-
-
//----------------------------------------------------------------------------
// version utilities
//----------------------------------------------------------------------------
Modified:
trunk/main/depot/library/src/main/net/dpml/library/impl/DefaultType.java
===================================================================
---
trunk/main/depot/library/common/src/main/net/dpml/library/impl/DefaultType.java
2006-03-05 11:48:22 UTC (rev 1167)
+++ trunk/main/depot/library/src/main/net/dpml/library/impl/DefaultType.java
2006-03-14 16:03:20 UTC (rev 1171)
@@ -18,45 +18,90 @@
package net.dpml.library.impl;
-import net.dpml.library.model.Type;
+import java.net.URI;
+import java.util.Map;
+import java.util.Hashtable;
+
import net.dpml.library.info.TypeDirective;
+import net.dpml.lang.Type;
+import net.dpml.lang.Builder;
+import net.dpml.lang.BuilderException;
+import net.dpml.part.AbstractBuilder;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.TypeInfo;
+
/**
- * Utility class used for construction of a module model from an XML source.
+ * Internal exception throw to indicate a bad name reference.
*
* @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
* @version @PROJECT-VERSION@
*/
-public final class DefaultType extends DefaultDictionary implements Type
+public class DefaultType extends DefaultDictionary implements Type
{
+ private final DefaultResource m_resource;
private final TypeDirective m_directive;
- DefaultType( DefaultDictionary parent, TypeDirective directive )
+ /**
+ * Creation of a new DefaultType.
+ * @param message the exception message
+ */
+ DefaultType( DefaultResource resource, TypeDirective directive )
{
- super( parent, directive );
+ super( resource, directive );
+
+ m_resource = resource;
m_directive = directive;
}
-
-
//----------------------------------------------------------------------------
- // Type
-
//----------------------------------------------------------------------------
-
- /**
- * Return the name of the type.
- * @return the name of the type
- */
- public String getName()
+
+ public String getID()
{
- return m_directive.getName();
+ return m_directive.getID();
}
- /**
- * Return the alias association policy.
- * @return true if alias production is required
- */
public boolean getAlias()
{
return m_directive.getAlias();
}
+
+ public Object getData()
+ {
+ Element element = m_directive.getElement();
+ if( null == element )
+ {
+ return null;
+ }
+ try
+ {
+ TypeInfo info = element.getSchemaTypeInfo();
+ String namespace = info.getTypeNamespace();
+ String builderURI = m_resource.getProperty(
"project.xsd.builder." + namespace );
+ Map map = new Hashtable();
+ if( null != builderURI )
+ {
+ try
+ {
+ map.put( namespace, new URI( builderURI ) );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Bad builder uri [" + builderURI + "].";
+ throw new IllegalStateException( error );
+ }
+ }
+ AbstractBuilder factory = new AbstractBuilder( map );
+ Builder builder = factory.getBuilder( element );
+ return builder.build( getClass().getClassLoader(), element );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Unexpected error while attempting to load foreign builder.";
+ throw new BuilderException( element, error, e );
+ }
+ }
+
}
Added:
trunk/main/depot/library/src/main/net/dpml/library/impl/DefaultTypeBuilder.java
===================================================================
---
trunk/main/depot/library/common/src/main/net/dpml/library/impl/DefaultTypeBuilder.java
2006-03-05 11:48:22 UTC (rev 1167)
+++
trunk/main/depot/library/src/main/net/dpml/library/impl/DefaultTypeBuilder.java
2006-03-14 16:03:20 UTC (rev 1171)
@@ -0,0 +1,185 @@
+/*
+ * Copyright 2006 Stephen J. McConnell.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.library.impl;
+
+import java.io.Writer;
+import java.io.IOException;
+import java.io.Serializable;
+import java.net.URI;
+import java.util.Properties;
+import java.util.Map;
+
+import net.dpml.lang.Type;
+import net.dpml.library.TypeBuilder;
+import net.dpml.library.info.TypeDirective;
+
+import net.dpml.transit.util.ElementHelper;
+
+import net.dpml.part.AbstractBuilder;
+import net.dpml.lang.Builder;
+import net.dpml.part.Strategy;
+import net.dpml.lang.BuilderException;
+import net.dpml.part.PartStrategyBuilder;
+
+import org.w3c.dom.TypeInfo;
+import org.w3c.dom.Element;
+
+/**
+ * Utility used to build a type defintion from a DOM element.
+ *
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
+ */
+public class DefaultTypeBuilder extends AbstractBuilder implements
TypeBuilder
+{
+ private static final String PART_XSD_URI = "@PART-XSD-URI@";
+ private static final String MODULE_XSD_URI = "@MODULE-XSD-URI@";
+ private static final String COMMON_XSD_URI = "@COMMON-XSD-URI@";
+
+ DefaultTypeBuilder( Map map )
+ {
+ super( map );
+ }
+
+ public String getID()
+ {
+ throw new UnsupportedOperationException( "getID" );
+ }
+
+ //public Object build( ClassLoader classloader, Element element ) throws
Exception
+ //{
+ // return buildType( classloader, element );
+ //}
+
+ public Type buildType( ClassLoader classloader, TypeDirective type )
throws Exception
+ {
+ throw new UnsupportedOperationException( "buildType" );
+ }
+
+ /*
+ public TypeDirective buildType( ClassLoader classloader, TypeDirective
type ) throws Exception
+ {
+ Element element = type.getElement();
+ TypeInfo info = element.getSchemaTypeInfo();
+ String namespace = info.getTypeNamespace();
+ if( null == namespace )
+ {
+ throw new NullPointerException( "namespace" );
+ }
+ String typeName = info.getTypeName();
+ if( info.isDerivedFrom( COMMON_XSD_URI, "AbstractType",
TypeInfo.DERIVATION_EXTENSION ) )
+ {
+ final boolean alias = getAliasFlag( element );
+ if( MODULE_XSD_URI.equals( namespace ) )
+ {
+ if( "GenericType".equals( typeName ) )
+ {
+ final String id = getID( element );
+ final Properties properties = getProperties( element );
+ return new TypeDirective( id, alias, properties );
+ }
+ else
+ {
+ System.out.println( "# UNRECOGNIZED MODULE TYPE" );
+ final String error =
+ "Element namespace is recognized as within the module
definition "
+ + " however the type identifier is not recognized."
+ + "\nNamespace: "
+ + namespace
+ + "\nType Name: "
+ + info.getTypeName();
+ throw new BuilderException( element, error );
+ }
+ }
+ else if( info.isDerivedFrom( PART_XSD_URI, "StrategyType",
TypeInfo.DERIVATION_EXTENSION ) )
+ {
+ return new TypeDirective( "part", alias, element );
+ }
+ else
+ {
+ System.out.println( "# UNRECOGNIZED TYPE" );
+ final String error =
+ "Element is recognized as an AbstractType however the type
id is not resolvable."
+ + "\nNamespace: "
+ + namespace
+ + "\nElement Name (from Schema Info): "
+ + info.getTypeName();
+ throw new BuilderException( element, error );
+ }
+ }
+ else
+ {
+ System.out.println( "# INVALID ELEMENT" );
+ final String error =
+ "Element is not derivived from AbstractType defined under the
common namespace."
+ + "\nNamespace: " + namespace
+ + "\nElement Name (from Schema Info): " + info.getTypeName();
+ throw new BuilderException( element, error );
+ }
+ }
+ */
+
+ protected String getID( Element element )
+ {
+ final String id = ElementHelper.getAttribute( element, "id" );
+ if( null == id )
+ {
+ final String error =
+ "Missing type 'id'.";
+ throw new IllegalArgumentException( error );
+ }
+ else
+ {
+ return id;
+ }
+ }
+
+ protected boolean getAliasFlag( Element element )
+ {
+ return ElementHelper.getBooleanAttribute( element, "alias", false );
+ }
+
+ protected Properties getProperties( Element element )
+ {
+ Properties properties = new Properties();
+ Element[] children = ElementHelper.getChildren( element );
+ for( int i=0; i<children.length; i++ )
+ {
+ Element child = children[i];
+ String tag = child.getTagName();
+ if( "property".equals( tag ) )
+ {
+ String key = ElementHelper.getAttribute( child, "name", null
);
+ if( null == key )
+ {
+ final String error =
+ "Property declaration does not contain a 'name'
attribute.";
+ throw new IllegalArgumentException( error );
+ }
+ else
+ {
+ String value = ElementHelper.getAttribute( child,
"value", null );
+ properties.setProperty( key, value );
+ }
+ }
+ }
+ return properties;
+ }
+
+}
Added:
trunk/main/depot/library/src/main/net/dpml/library/impl/LibraryBuilder.java
===================================================================
---
trunk/main/depot/library/common/src/main/net/dpml/library/impl/LibraryBuilder.java
2006-03-05 11:48:22 UTC (rev 1167)
+++
trunk/main/depot/library/src/main/net/dpml/library/impl/LibraryBuilder.java
2006-03-14 16:03:20 UTC (rev 1171)
@@ -0,0 +1,1150 @@
+/*
+ * Copyright 2005 Stephen J. McConnell
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.library.impl;
+
+import java.io.File;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.IOException;
+import java.io.FileNotFoundException;
+import java.io.FileInputStream;
+import java.io.BufferedInputStream;
+import java.io.Writer;
+import java.io.OutputStreamWriter;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Properties;
+import java.util.Hashtable;
+import java.util.Map;
+import java.beans.XMLDecoder;
+
+import javax.xml.XMLConstants;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import net.dpml.lang.Type;
+
+import net.dpml.library.info.LibraryDirective;
+import net.dpml.library.info.ImportDirective;
+import net.dpml.library.info.IncludeDirective;
+import net.dpml.library.info.IncludeDirective.Mode;
+import net.dpml.library.info.ModuleDirective;
+import net.dpml.library.info.ResourceDirective;
+import net.dpml.library.info.ResourceDirective.Classifier;
+import net.dpml.library.info.DependencyDirective;
+import net.dpml.library.info.TypeDirective;
+import net.dpml.library.info.Scope;
+
+import net.dpml.library.TypeBuilder;
+
+import net.dpml.part.PartStrategyBuilder;
+import net.dpml.part.PartBuilder;
+import net.dpml.part.AbstractBuilder;
+
+import net.dpml.transit.Artifact;
+import net.dpml.transit.Repository;
+import net.dpml.transit.Transit;
+import net.dpml.transit.util.ElementHelper;
+import net.dpml.transit.util.ExceptionHelper;
+
+import net.dpml.lang.Category;
+import net.dpml.lang.BuilderException;
+
+import net.dpml.part.DOM3DocumentBuilder;
+
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.Document;
+import org.w3c.dom.DocumentType;
+import org.w3c.dom.TypeInfo;
+
+/**
+ * Utility class used for construction of a module model from an XML source.
+ *
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
+ */
+public final class LibraryBuilder extends AbstractBuilder
+{
+ private static final String PART_XSD_URI = "@PART-XSD-URI@";
+ private static final String MODULE_XSD_URI = "@MODULE-XSD-URI@";
+ private static final String COMMON_XSD_URI = "@COMMON-XSD-URI@";
+
+ public static final String XML_HEADER =
+ "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
+
+ private static final String LIBRARY_ELEMENT_NAME = "library";
+ private static final String IMPORTS_ELEMENT_NAME = "imports";
+ private static final String IMPORT_ELEMENT_NAME = "import";
+ private static final String MODULE_ELEMENT_NAME = "module";
+ private static final String MODULES_ELEMENT_NAME = "modules";
+ private static final String DEPENDENCIES_ELEMENT_NAME = "dependencies";
+ private static final String INCLUDE_ELEMENT_NAME = "include";
+ private static final String RESOURCE_ELEMENT_NAME = "resource";
+ private static final String TYPES_ELEMENT_NAME = "types";
+ private static final String TYPE_ELEMENT_NAME = "type";
+ private static final String PROJECT_ELEMENT_NAME = "project";
+ private static final String PROPERTIES_ELEMENT_NAME = "properties";
+
+ private DOM3DocumentBuilder m_builder = new DOM3DocumentBuilder();
+
+ public LibraryBuilder()
+ {
+ this( null );
+ }
+
+ public LibraryBuilder( Map map )
+ {
+ super( map );
+ }
+
+ /**
+ * Construct a library directive from XML source.
+ * @param source the XML source file
+ * @return the library directive
+ * @exception IOException if an IO exception occurs
+ */
+ public LibraryDirective build( File source ) throws IOException
+ {
+ if( null == source )
+ {
+ throw new NullPointerException( "source" );
+ }
+ if( !source.exists() )
+ {
+ throw new FileNotFoundException( source.toString() );
+ }
+ if( source.isDirectory() )
+ {
+ final String error =
+ "File ["
+ + source
+ + "] references a directory.";
+ throw new IllegalArgumentException( error );
+ }
+ try
+ {
+ final Element root = getRootElement( source );
+ File base = source.getParentFile();
+ return buildLibraryDirective( base, root );
+ }
+ catch( IOException e )
+ {
+ throw e;
+ }
+ catch( Exception e )
+ {
+ final String error =
+ "Unexpected error while attempting to load library."
+ + "File: '" + source + "'";
+ IOException ioe = new IOException( error );
+ ioe.initCause( e );
+ throw ioe;
+ }
+ }
+
+ public ModuleDirective buildModule( URI uri ) throws IOException
+ {
+ try
+ {
+ final Document document = m_builder.parse( uri );
+ Element root = document.getDocumentElement();
+ return buildModuleDirectiveFromElement( null, root, null );
+ }
+ catch( IOException e )
+ {
+ throw e;
+ }
+ catch( Exception e )
+ {
+ final String error =
+ "Unexpected error while attempting to load module."
+ + "URI: '" + uri + "'";
+ IOException ioe = new IOException( error );
+ ioe.initCause( e );
+ throw ioe;
+ }
+ }
+
+ /**
+ * Write a module directive to an output stream as a portable XML
definition.
+ * During export dependencies are limited to runtime concerns
(eliminating
+ * build and test scoped dependencies). Artifact production is strippped
down
+ * to a generic type declaration. The resulting XML file is suitable for
+ * publication and usage by external projects.
+ *
+ * @param module the moudle directive to externalize
+ * @param output the output stream
+ * @exception Exception if an error occurs during module externalization
+ */
+ public void export( final ModuleDirective module, final OutputStream
output ) throws IOException
+ {
+ final Writer writer = new OutputStreamWriter( output );
+ try
+ {
+ writer.write( XML_HEADER );
+ writer.write( "\n" );
+
+ String name = module.getName();
+ String version = module.getVersion();
+
+ if( null != name )
+ {
+ writer.write( "<module name=\"" + name + "\"" );
+ }
+ if( null != version )
+ {
+ writer.write( " version=\"" + version + "\"" );
+ }
+
+ writer.write(
+ "\n xmlns=\""
+ + MODULE_XSD_URI
+ + "\""
+ + "\n xmlns:xsi=\""
+ + XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI
+ + "\""
+ + "\n xmlns:common=\""
+ + COMMON_XSD_URI
+ + "\">" );
+
+ Properties properties = module.getProperties();
+ String basedir = module.getBasedir();
+ TypeDirective[] types = module.getTypeDirectives();
+ DependencyDirective[] dependencies =
module.getDependencyDirectives();
+ ResourceDirective[] resources = module.getResourceDirectives();
+ if( properties.size() > 0 )
+ {
+ writer.write( "\n" );
+ writeProperties( writer, properties, " ", true );
+ }
+ if( types.length > 0 )
+ {
+ writer.write( "\n" );
+ writeTypes( writer, types, " " );
+ }
+ if( dependencies.length > 0 )
+ {
+ writer.write( "\n" );
+ writeDependencies( writer, dependencies, " " );
+ }
+ if( resources.length > 0 )
+ {
+ writeResources( writer, resources, " " );
+ }
+ writer.write( "\n\n</module>" );
+ writer.write( "\n" );
+ }
+ finally
+ {
+ writer.flush();
+ writer.close();
+ }
+ }
+
+ private Element getRootElement( File source ) throws IOException
+ {
+ File file = source.getCanonicalFile();
+ final Document document = m_builder.parse( file.toURI() );
+ return document.getDocumentElement();
+ }
+
+ /**
+ * Build a module using an XML element.
+ * @param base the base directory
+ * @param element the module element
+ * @return the library directive
+ * @exception IOException if an IO exception occurs
+ */
+ private LibraryDirective buildLibraryDirective( File base, Element
element ) throws Exception
+ {
+ final String elementName = element.getTagName();
+ if( !LIBRARY_ELEMENT_NAME.equals( elementName ) )
+ {
+ final String error =
+ "Element is not a library.";
+ throw new IllegalArgumentException( error );
+ }
+
+ // get type descriptors, modules and properties
+
+ Properties properties = null;
+ ImportDirective[] imports = new ImportDirective[0];
+ ModuleDirective[] modules = new ModuleDirective[0];
+ Element[] children = ElementHelper.getChildren( element );
+ for( int i=0; i<children.length; i++ )
+ {
+ Element child = children[i];
+ final String tag = child.getTagName();
+ if( PROPERTIES_ELEMENT_NAME.equals( tag ) )
+ {
+ properties = buildProperties( child );
+ }
+ else if( IMPORTS_ELEMENT_NAME.equals( tag ) )
+ {
+ imports = buildImportDirectives( child );
+ }
+ else if( MODULES_ELEMENT_NAME.equals( tag ) )
+ {
+ modules = buildModuleDirectivesFromElement( base, child );
+ }
+ else
+ {
+ final String error =
+ "Illegal element name [" + tag + "] within 'library'
element.";
+ throw new IllegalArgumentException( error );
+ }
+ }
+ return new LibraryDirective( imports, modules, properties );
+ }
+
+ /**
+ * Construct a module directive relative to the supplied base directory
+ * using the supplied DOM element.
+ * @param base the basedire of the enclosing library or module
+ * @param element the element definting the module
+ */
+ private ModuleDirective[] buildModuleDirectivesFromElement(
+ File base, Element element ) throws Exception
+ {
+ String tag = element.getTagName();
+ if( !"modules".equals( element.getTagName() ) )
+ {
+ final String error =
+ "Unsupported library element name [" + tag + "].";
+ throw new IllegalArgumentException( error );
+ }
+ Element[] children = ElementHelper.getChildren( element );
+ ModuleDirective[] modules = new ModuleDirective[ children.length ];
+ for( int i=0; i<children.length; i++ )
+ {
+ Element child = children[i];
+ modules[i] = buildModuleDirectiveFromElement( base, child, null
);
+ }
+ return modules;
+ }
+
+ /**
+ * Build a module directive an XML file.
+ * @param source the XML source
+ * @param path the relative path
+ * @return the module directive
+ * @exception IOException if an IO exception occurs
+ */
+ public ModuleDirective buildModuleDirective( File source, String path )
throws IOException
+ {
+ if( null == source )
+ {
+ throw new NullPointerException( "source" );
+ }
+ if( !source.exists() )
+ {
+ throw new FileNotFoundException( source.toString() );
+ }
+ if( source.isDirectory() )
+ {
+ final String error =
+ "File ["
+ + source
+ + "] references a directory.";
+ throw new IllegalArgumentException( error );
+ }
+ try
+ {
+ final Element root = getRootElement( source );
+ final File parent = source.getParentFile();
+ final String basedir = path;
+ return buildModuleDirectiveFromElement( parent, root, basedir );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "An error occured while attempting to build a module directive
from the source: "
+ + source;
+ IOException ioe = new IOException( error );
+ ioe.initCause( e );
+ throw ioe;
+ }
+ }
+
+
+ /**
+ * Build a module using an XML element.
+ * @param base the base directory
+ * @param element the module element
+ * @param offset the imported file directory offset
+ */
+ private ModuleDirective buildModuleDirectiveFromElement(
+ File base, Element element, String offset ) throws Exception
+ {
+ final String elementName = element.getTagName();
+ if( "import".equals( elementName ) )
+ {
+ String path = ElementHelper.getAttribute( element, "file" );
+ File file = new File( base, path );
+ File dir = file.getParentFile();
+ String spec = getRelativePath( base, dir );
+ File source = file.getCanonicalFile();
+ if( !source.exists() )
+ {
+ final String error =
+ "Cannot include module ["
+ + source
+ + "] because the file does not exist.";
+ throw new FileNotFoundException( error );
+ }
+ else
+ {
+ return buildModuleDirective( source, spec );
+ }
+ }
+ else if( MODULE_ELEMENT_NAME.equals( elementName ) )
+ {
+ ResourceDirective resource = buildResourceDirective( element,
offset );
+ ArrayList list = new ArrayList();
+ Element[] children = ElementHelper.getChildren( element );
+ for( int i=0; i<children.length; i++ )
+ {
+ Element child = children[i];
+ final String tag = child.getTagName();
+ if( PROPERTIES_ELEMENT_NAME.equals( tag ) )
+ {
+ boolean ok = true; // already processed
+ }
+ else if( DEPENDENCIES_ELEMENT_NAME.equals( tag ) )
+ {
+ boolean ok = true; // already processed
+ }
+ else if( TYPES_ELEMENT_NAME.equals( tag ) )
+ {
+ boolean ok = true; // already processed
+ }
+ else if( MODULE_ELEMENT_NAME.equals( tag ) )
+ {
+ ModuleDirective directive =
+ buildModuleDirectiveFromElement( base, child, null );
+ list.add( directive );
+ }
+ else if( IMPORT_ELEMENT_NAME.equals( tag ) )
+ {
+ ModuleDirective directive =
+ buildModuleDirectiveFromElement( base, child, null );
+ list.add( directive );
+ }
+ else if( PROJECT_ELEMENT_NAME.equals( tag ) )
+ {
+ ResourceDirective directive =
+ buildResourceDirective( child );
+ list.add( directive );
+ }
+ else if( RESOURCE_ELEMENT_NAME.equals( tag ) )
+ {
+ ResourceDirective directive =
+ buildResourceDirective( child );
+ list.add( directive );
+ }
+ else
+ {
+ final String error =
+ "Illegal element name [" + tag + "] within 'module'
element.";
+ throw new IllegalArgumentException( error );
+ }
+ }
+ ResourceDirective[] resources = (ResourceDirective[])
list.toArray( new ResourceDirective[0] );
+ return new ModuleDirective( resource, resources );
+ }
+ else
+ {
+ final String error =
+ "Element ["
+ + elementName
+ + "] is not a module.";
+ throw new IllegalArgumentException( error );
+ }
+ }
+
+ private String getRelativePath( File base, File dir ) throws IOException
+ {
+ String baseSpec = base.getCanonicalPath();
+ String dirSpec = dir.getCanonicalPath();
+ if( dirSpec.equals( baseSpec ) )
+ {
+ return ".";
+ }
+ if( dirSpec.startsWith( baseSpec ) )
+ {
+ return dirSpec.substring( baseSpec.length() + 1 );
+ }
+ else
+ {
+ final String error =
+ "Supplied dir [" + dirSpec + "] is not with base [" + baseSpec
+ "].";
+ throw new IllegalArgumentException( error );
+ }
+ }
+
+ /**
+ * Build an array of include directives contained within the supplied
enclosing element.
+ * @param element the enclosing element
+ * @return the array of includes
+ */
+ private ImportDirective[] buildImportDirectives( Element element )
+ {
+ Element[] children = ElementHelper.getChildren( element );
+ ImportDirective[] includes = new ImportDirective[ children.length ];
+ for( int i=0; i<children.length; i++ )
+ {
+ Element child = children[i];
+ includes[i] = buildImportDirective( child );
+ }
+ return includes;
+ }
+
+ private ImportDirective buildImportDirective( Element element )
+ {
+ final String tag = element.getTagName();
+ final Properties properties = buildProperties( element );
+ if( IMPORT_ELEMENT_NAME.equals( tag ) )
+ {
+ if( element.hasAttribute( "file" ) )
+ {
+ final String value = ElementHelper.getAttribute( element,
"file", null );
+ return new ImportDirective( ImportDirective.FILE, value,
properties );
+ }
+ else if( element.hasAttribute( "uri" ) )
+ {
+ final String value = ElementHelper.getAttribute( element,
"uri", null );
+ return new ImportDirective( ImportDirective.URI, value,
properties );
+ }
+ else
+ {
+ final String error =
+ "Import element does not declare a 'file' or 'uri'
attribute.\n"
+ + element.toString();
+ throw new IllegalArgumentException( error );
+ }
+ }
+ else
+ {
+ final String error =
+ "Invalid include element name ["
+ + tag
+ + "].";
+ throw new IllegalArgumentException( error );
+ }
+ }
+
+ private DependencyDirective buildDependencyDirective( Element element )
+ {
+ final String tag = element.getTagName();
+ if( DEPENDENCIES_ELEMENT_NAME.equals( tag ) )
+ {
+ final String spec = ElementHelper.getAttribute( element,
"scope", "runtime" );
+ Scope scope = Scope.parse( spec );
+ Element[] children = ElementHelper.getChildren( element );
+ IncludeDirective[] includes = new IncludeDirective[
children.length ];
+ for( int i=0; i<children.length; i++ )
+ {
+ Element child = children[i];
+ includes[i] = buildIncludeDirective( child );
+ }
+ return new DependencyDirective( scope, includes );
+ }
+ else
+ {
+ final String error =
+ "Invalid dependency element name ["
+ + tag
+ + "].";
+ throw new IllegalArgumentException( error );
+ }
+ }
+
+ /**
+ * Build an array of include directives contained within the supplied
enclosing element.
+ * @param element the enclosing element
+ * @return the array of includes
+ */
+ private IncludeDirective[] buildIncludeDirectives( Element element )
+ {
+ Element[] children = ElementHelper.getChildren( element );
+ IncludeDirective[] includes = new IncludeDirective[ children.length
];
+ for( int i=0; i<children.length; i++ )
+ {
+ Element child = children[i];
+ includes[i] = buildIncludeDirective( child );
+ }
+ return includes;
+ }
+
+ private IncludeDirective buildIncludeDirective( Element element )
+ {
+ final String tag = element.getTagName();
+ final Properties properties = buildProperties( element );
+ if( INCLUDE_ELEMENT_NAME.equals( tag ) )
+ {
+
+ final String tagValue = ElementHelper.getAttribute( element,
"tag", "private" );
+ Category category = Category.parse( tagValue );
+ if( element.hasAttribute( "key" ) )
+ {
+ final String value = ElementHelper.getAttribute( element,
"key", null );
+ return new IncludeDirective( IncludeDirective.KEY, category,
value, properties );
+ }
+ else if( element.hasAttribute( "ref" ) )
+ {
+ final String value = ElementHelper.getAttribute( element,
"ref", null );
+ return new IncludeDirective( IncludeDirective.REF, category,
value, properties );
+ }
+ else if( element.hasAttribute( "urn" ) )
+ {
+ final String value = ElementHelper.getAttribute( element,
"urn", null );
+ return new IncludeDirective( IncludeDirective.URN, category,
value, properties );
+ }
+ else
+ {
+ final String error =
+ "Include directive does not declare a 'urn', 'key' or
'ref' attribute.\n"
+ + element.toString();
+ throw new IllegalArgumentException( error );
+ }
+ }
+ else
+ {
+ final String error =
+ "Invalid include element name ["
+ + tag
+ + "].";
+ throw new IllegalArgumentException( error );
+ }
+ }
+
+ private ResourceDirective buildResourceDirective( Element element )
throws Exception
+ {
+ return buildResourceDirective( element, null );
+ }
+
+ private ResourceDirective buildResourceDirective( Element element,
String path ) throws Exception
+ {
+ Classifier classifier = null;
+ final String tag = element.getTagName();
+ if( RESOURCE_ELEMENT_NAME.equals( tag ) ||
PROJECT_ELEMENT_NAME.equals( tag )
+ || MODULE_ELEMENT_NAME.equals( tag ) )
+ {
+ final String name = ElementHelper.getAttribute( element, "name",
null );
+ final String version = ElementHelper.getAttribute( element,
"version", null );
+ String basedir = ElementHelper.getAttribute( element, "basedir",
null );
+ if( path != null )
+ {
+ if( basedir == null )
+ {
+ basedir = path;
+ }
+ else
+ {
+ basedir = path + "/" + basedir;
+ }
+ }
+
+ if( PROJECT_ELEMENT_NAME.equals( tag ) )
+ {
+ classifier = Classifier.LOCAL;
+ if( null == basedir )
+ {
+ final String error =
+ "Missing basedir attribute on project ["
+ + name
+ + "].";
+ throw new IllegalArgumentException( error );
+ }
+ }
+ else if( MODULE_ELEMENT_NAME.equals( tag ) )
+ {
+ if( null != basedir )
+ {
+ classifier = Classifier.LOCAL;
+ }
+ else
+ {
+ classifier = Classifier.EXTERNAL;
+ }
+ }
+ else
+ {
+ classifier = Classifier.EXTERNAL;
+ }
+
+ ArrayList dependencies = new ArrayList();
+ TypeDirective[] types = new TypeDirective[0];
+ Element[] children = ElementHelper.getChildren( element );
+ Properties properties = null;
+ for( int i=0; i<children.length; i++ )
+ {
+ Element child = children[i];
+ final String childTag = child.getTagName();
+ if( TYPES_ELEMENT_NAME.equals( childTag ) )
+ {
+ types = buildTypes( child );
+ }
+ else if( DEPENDENCIES_ELEMENT_NAME.equals( childTag ) )
+ {
+ DependencyDirective dependency =
buildDependencyDirective( child );
+ dependencies.add( dependency );
+ }
+ else if( PROPERTIES_ELEMENT_NAME.equals( childTag ) )
+ {
+ properties = buildProperties( child );
+ }
+ }
+ DependencyDirective[] deps = (DependencyDirective[])
dependencies.toArray( new DependencyDirective[0] );
+ return new ResourceDirective( name, version, classifier,
basedir, types, deps, properties );
+ }
+ else
+ {
+ final String error =
+ "Invalid element name ["
+ + tag
+ + "].";
+ throw new IllegalArgumentException( error );
+ }
+ }
+
+ private TypeDirective[] buildTypes( Element element ) throws Exception
+ {
+ Element[] children = ElementHelper.getChildren( element );
+ TypeDirective[] types = new TypeDirective[ children.length ];
+ for( int i=0; i<children.length; i++ )
+ {
+ Element child = children[i];
+ types[i] = buildType( child );
+ }
+ return types;
+ }
+
+ private TypeDirective buildType( Element element ) throws Exception
+ {
+ TypeInfo info = element.getSchemaTypeInfo();
+ String namespace = info.getTypeNamespace();
+ if( null == namespace )
+ {
+ throw new NullPointerException( "namespace" );
+ }
+ String typeName = info.getTypeName();
+ if( info.isDerivedFrom( COMMON_XSD_URI, "AbstractType",
TypeInfo.DERIVATION_EXTENSION ) )
+ {
+ final boolean alias = getAliasFlag( element );
+ if( MODULE_XSD_URI.equals( namespace ) )
+ {
+ if( "GenericType".equals( typeName ) )
+ {
+ final String id = getID( element );
+ final Properties properties = getProperties( element );
+ return new TypeDirective( id, alias, properties );
+ }
+ else
+ {
+ System.out.println( "# UNRECOGNIZED MODULE TYPE" );
+ final String error =
+ "Element namespace is recognized as within the module
definition "
+ + " however the type identifier is not recognized."
+ + "\nNamespace: "
+ + namespace
+ + "\nType Name: "
+ + info.getTypeName();
+ throw new BuilderException( element, error );
+ }
+ }
+ else if( info.isDerivedFrom( PART_XSD_URI, "StrategyType",
TypeInfo.DERIVATION_EXTENSION ) )
+ {
+ return new TypeDirective( "part", alias, element );
+ }
+ else
+ {
+ System.out.println( "# UNRECOGNIZED TYPE" );
+ final String error =
+ "Element is recognized as an AbstractType however the type
id is not resolvable."
+ + "\nNamespace: "
+ + namespace
+ + "\nElement Name (from Schema Info): "
+ + info.getTypeName();
+ throw new BuilderException( element, error );
+ }
+ }
+ else
+ {
+ System.out.println( "# INVALID ELEMENT" );
+ final String error =
+ "Element is not derivived from AbstractType defined under the
common namespace."
+ + "\nNamespace: " + namespace
+ + "\nElement Name (from Schema Info): " + info.getTypeName();
+ throw new BuilderException( element, error );
+ }
+ }
+
+ private Properties buildProperties( Element element )
+ {
+ Properties properties = new Properties();
+ Element[] children = ElementHelper.getChildren( element );
+ for( int i=0; i<children.length; i++ )
+ {
+ Element child = children[i];
+ String tag = child.getTagName();
+ if( "property".equals( tag ) )
+ {
+ String key = ElementHelper.getAttribute( child, "name", null
);
+ if( null == key )
+ {
+ final String error =
+ "Property declaration does not contain a 'name'
attribute.";
+ throw new IllegalArgumentException( error );
+ }
+ else
+ {
+ String value = ElementHelper.getAttribute( child,
"value", null );
+ properties.setProperty( key, value );
+ }
+ }
+ }
+ return properties;
+ }
+
+ private URI getURIFromSpec( String spec )
+ {
+ if( null == spec )
+ {
+ return null;
+ }
+ else
+ {
+ try
+ {
+ return new URI( spec );
+ }
+ catch( URISyntaxException e )
+ {
+ final String error =
+ "Type descriptor uri ["
+ + spec
+ + "] could not be converted to a URI value.";
+ throw new IllegalArgumentException( error );
+ }
+ }
+ }
+
+ private TypeBuilder loadTypeBuilder( URI uri ) throws Exception
+ {
+ ClassLoader classloader = TypeBuilder.class.getClassLoader();
+ Repository repository = Transit.getInstance().getRepository();
+ Object[] args = new Object[0];
+ Object handler = repository.getPlugin( classloader, uri, args );
+ if( handler instanceof TypeBuilder )
+ {
+ return (TypeBuilder) handler;
+ }
+ else
+ {
+ final String error =
+ "Plugin ["
+ + uri
+ + "] does not implement the "
+ + TypeBuilder.class.getName()
+ + " interface.";
+ throw new IllegalArgumentException( error );
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ // internal utilities supporting ModuleDirective to XML creation
+ //-----------------------------------------------------------------------
+
+ private void writeModule( Writer writer, ModuleDirective module, String
lead ) throws IOException
+ {
+ String name = module.getName();
+ String version = module.getVersion();
+
+ Properties properties = module.getProperties();
+ String basedir = module.getBasedir();
+ TypeDirective[] types = module.getTypeDirectives();
+ DependencyDirective[] dependencies =
module.getDependencyDirectives();
+ ResourceDirective[] resources = module.getResourceDirectives();
+
+ writer.write( "\n" + lead + "<module" );
+ if( null != name )
+ {
+ writer.write( " name=\"" + name + "\"" );
+ }
+ if( null != version )
+ {
+ writer.write( " version=\"" + version + "\"" );
+ }
+ writer.write( ">" );
+
+ if( properties.size() > 0 )
+ {
+ writer.write( "\n" );
+ writeProperties( writer, properties, lead + " ", true );
+ }
+
+ if( types.length > 0 )
+ {
+ writer.write( "\n" );
+ writeTypes( writer, types, lead + " " );
+ }
+
+ if( dependencies.length > 0 )
+ {
+ writer.write( "\n" );
+ writeDependencies( writer, dependencies, lead + " " );
+ }
+
+ if( resources.length > 0 )
+ {
+ writeResources( writer, resources, lead + " " );
+ }
+ writer.write( "\n\n" + lead + "</module>" );
+ }
+
+ private void writeResource( Writer writer, ResourceDirective resource,
String lead ) throws IOException
+ {
+ String name = resource.getName();
+ String version = resource.getVersion();
+
+ Properties properties = resource.getProperties();
+ String basedir = resource.getBasedir();
+ TypeDirective[] types = resource.getTypeDirectives();
+ DependencyDirective[] dependencies =
resource.getDependencyDirectives();
+
+ writer.write( "\n" + lead + "<resource" );
+ if( null != name )
+ {
+ writer.write( " name=\"" + name + "\"" );
+ }
+ if( null != version )
+ {
+ writer.write( " version=\"" + version + "\"" );
+ }
+ writer.write( ">" );
+
+ if( properties.size() > 0 )
+ {
+ writeProperties( writer, properties, lead + " ", true );
+ }
+ if( types.length > 0 )
+ {
+ writeTypes( writer, types, lead + " " );
+ }
+ if( dependencies.length > 0 )
+ {
+ writeDependencies( writer, dependencies, lead + " " );
+ }
+ writer.write( "\n" + lead + "</resource>" );
+ }
+
+ private void writeProperties(
+ Writer writer, Properties properties, String lead, boolean flag )
throws IOException
+ {
+ if( properties.size() > 0 )
+ {
+ if( flag )
+ {
+ writer.write( "\n" + lead + "<properties>" );
+ }
+ String[] names = (String[]) properties.keySet().toArray( new
String[0] );
+ for( int i=0; i<names.length; i++ )
+ {
+ String name = names[i];
+ String value = properties.getProperty( name );
+ writer.write( "\n" + lead );
+ if( flag )
+ {
+ writer.write( " " );
+ }
+ writer.write( "<property name=\"" + name + "\" value=\"" +
value + "\"/>" );
+ }
+ if( flag )
+ {
+ writer.write( "\n" + lead + "</properties>" );
+ }
+ }
+ }
+
+ private void writeTypes( Writer writer, TypeDirective[] types, String
lead ) throws IOException
+ {
+ if( types.length > 0 )
+ {
+ writer.write( "\n" + lead + "<types>" );
+ for( int i=0; i<types.length; i++ )
+ {
+ TypeDirective type = types[i];
+ writeType( writer, type, lead + " " );
+ }
+ writer.write( "\n" + lead + "</types>" );
+ }
+ }
+
+ private void writeType( Writer writer, TypeDirective type, String lead )
throws IOException
+ {
+ String id = type.getID();
+ boolean alias = type.getAlias();
+ writer.write( "\n" + lead + " <type id=\"" + id + "\"" );
+ if( alias )
+ {
+ writer.write( " alias=\"true\"" );
+ }
+ writer.write( "/>" );
+ }
+
+ private void writeDependencies(
+ Writer writer, DependencyDirective[] dependencies, String lead )
throws IOException
+ {
+ if( dependencies.length > 0 )
+ {
+ for( int i=0; i<dependencies.length; i++ )
+ {
+ DependencyDirective dependency = dependencies[i];
+ IncludeDirective[] includes =
dependency.getIncludeDirectives();
+ if( includes.length > 0 )
+ {
+ Scope scope = dependency.getScope();
+ if( Scope.RUNTIME.equals( scope ) )
+ {
+ writer.write( "\n" + lead + "<dependencies>" );
+ }
+ else
+ {
+ writer.write( "\n" + lead + "<dependencies scope=\""
+ scope + "\">" );
+ }
+
+ for( int j=0; j<includes.length; j++ )
+ {
+ IncludeDirective include = includes[j];
+ Mode mode = include.getMode();
+ String value = include.getValue();
+ writer.write( "\n" + lead + " <include" );
+ if( Mode.KEY.equals( mode ) )
+ {
+ writer.write( " key=\"" + value + "\"" );
+ }
+ else if( Mode.REF.equals( mode ) )
+ {
+ writer.write( " ref=\"" + value + "\"" );
+ }
+ else if( Mode.URN.equals( mode ) )
+ {
+ writer.write( " urn=\"" + value + "\"" );
+ }
+
+ if( Scope.RUNTIME.equals( scope ) )
+ {
+ Category category = include.getCategory();
+ if( !Category.PRIVATE.equals( category ) )
+ {
+ String label =
category.getName().toLowerCase();
+ writer.write( " tag=\"" + label + "\"" );
+ }
+ }
+
+ Properties props = include.getProperties();
+ if( props.size() > 0 )
+ {
+ writer.write( ">" );
+ writeProperties( writer, props, lead + " ",
false );
+ writer.write( "\n" + lead + " </include>");
+ }
+ else
+ {
+ writer.write( "/>" );
+ }
+ }
+ writer.write( "\n" + lead + "</dependencies>" );
+ }
+ }
+ }
+ }
+
+ private void writeResources( Writer writer, ResourceDirective[]
resources, String lead ) throws IOException
+ {
+ for( int i=0; i<resources.length; i++ )
+ {
+ ResourceDirective resource = resources[i];
+ if( resource instanceof ModuleDirective )
+ {
+ writer.write( "\n" );
+ ModuleDirective module = (ModuleDirective) resource;
+ writeModule( writer, module, lead );
+ }
+ else
+ {
+ writer.write( "\n" );
+ writeResource( writer, resource, lead );
+ }
+ }
+ }
+
+ protected String getID( Element element )
+ {
+ final String id = ElementHelper.getAttribute( element, "id" );
+ if( null == id )
+ {
+ final String error =
+ "Missing type 'id'.";
+ throw new IllegalArgumentException( error );
+ }
+ else
+ {
+ return id;
+ }
+ }
+
+ protected boolean getAliasFlag( Element element )
+ {
+ return ElementHelper.getBooleanAttribute( element, "alias", false );
+ }
+
+ protected Properties getProperties( Element element )
+ {
+ Properties properties = new Properties();
+ Element[] children = ElementHelper.getChildren( element );
+ for( int i=0; i<children.length; i++ )
+ {
+ Element child = children[i];
+ String tag = child.getTagName();
+ if( "property".equals( tag ) )
+ {
+ String key = ElementHelper.getAttribute( child, "name", null
);
+ if( null == key )
+ {
+ final String error =
+ "Property declaration does not contain a 'name'
attribute.";
+ throw new IllegalArgumentException( error );
+ }
+ else
+ {
+ String value = ElementHelper.getAttribute( child,
"value", null );
+ properties.setProperty( key, value );
+ }
+ }
+ }
+ return properties;
+ }
+}
Deleted:
trunk/main/depot/library/src/main/net/dpml/library/impl/LibraryDirectiveBuilder.java
===================================================================
---
trunk/main/depot/library/common/src/main/net/dpml/library/impl/LibraryDirectiveBuilder.java
2006-03-05 11:48:22 UTC (rev 1167)
+++
trunk/main/depot/library/src/main/net/dpml/library/impl/LibraryDirectiveBuilder.java
2006-03-14 16:03:20 UTC (rev 1171)
@@ -1,771 +0,0 @@
-/*
- * Copyright 2005 Stephen J. McConnell
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- * implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package net.dpml.library.impl;
-
-import java.io.File;
-import java.io.InputStream;
-import java.io.IOException;
-import java.io.FileNotFoundException;
-import java.io.FileInputStream;
-import java.io.BufferedInputStream;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.ArrayList;
-import java.util.Properties;
-import java.beans.XMLDecoder;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-
-import net.dpml.library.info.LibraryDirective;
-import net.dpml.library.info.ImportDirective;
-import net.dpml.library.info.IncludeDirective;
-import net.dpml.library.info.ModuleDirective;
-import net.dpml.library.info.ResourceDirective;
-import net.dpml.library.info.ResourceDirective.Classifier;
-import net.dpml.library.info.TypeDirective;
-import net.dpml.library.info.DependencyDirective;
-import net.dpml.library.info.Scope;
-
-import net.dpml.lang.DTD;
-import net.dpml.lang.DTDResolver;
-
-import net.dpml.transit.util.ElementHelper;
-import net.dpml.transit.util.ExceptionHelper;
-import net.dpml.lang.Category;
-
-import org.xml.sax.ErrorHandler;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
-
-import org.w3c.dom.Element;
-import org.w3c.dom.Document;
-import org.w3c.dom.DocumentType;
-
-/**
- * Utility class used for construction of a module model from an XML source.
- *
- * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
- * @version @PROJECT-VERSION@
- */
-public final class LibraryDirectiveBuilder
-{
- private static final DTD[] DTDS = new DTD[]
- {
- new DTD(
- ModuleBuilder.PUBLIC_ID,
- ModuleBuilder.SYSTEM_ID,
- ModuleBuilder.RESOURCE, null )
- };
-
- private static final DTDResolver DTD_RESOLVER =
- new DTDResolver( DTDS,
LibraryDirectiveBuilder.class.getClassLoader() );
-
- private static final String LIBRARY_ELEMENT_NAME = "library";
- private static final String IMPORTS_ELEMENT_NAME = "imports";
- private static final String IMPORT_ELEMENT_NAME = "import";
- private static final String MODULE_ELEMENT_NAME = "module";
- private static final String MODULES_ELEMENT_NAME = "modules";
- private static final String DEPENDENCIES_ELEMENT_NAME = "dependencies";
- private static final String INCLUDE_ELEMENT_NAME = "include";
- private static final String RESOURCE_ELEMENT_NAME = "resource";
- private static final String TYPES_ELEMENT_NAME = "types";
- private static final String TYPE_ELEMENT_NAME = "type";
- private static final String PROJECT_ELEMENT_NAME = "project";
- private static final String PROPERTIES_ELEMENT_NAME = "properties";
-
- private LibraryDirectiveBuilder()
- {
- }
-
- /**
- * Construct a library directive from XML source.
- * @param source the XML source file
- * @return the library directive
- * @exception IOException if an IO exception occurs
- */
- public static LibraryDirective build( File source ) throws IOException
- {
- if( null == source )
- {
- throw new NullPointerException( "source" );
- }
- if( !source.exists() )
- {
- throw new FileNotFoundException( source.toString() );
- }
- if( source.isDirectory() )
- {
- final String error =
- "File ["
- + source
- + "] references a directory.";
- throw new IllegalArgumentException( error );
- }
- try
- {
- final Element root = getRootElement( source );
- File base = source.getParentFile();
- return buildLibraryDirective( base, root );
- }
- catch( Throwable e )
- {
- System.out.println( "# ERROR: " + e.toString() );
- String message = ExceptionHelper.packException( e, true );
- System.out.println( message );
-
- final String error =
- "An error occured while attempting to build a library
directive from the source: "
- + source;
- IOException ioe = new IOException( error );
- ioe.initCause( e );
- throw ioe;
-
- }
- }
-
- private static Element getRootElement( File source ) throws IOException
- {
- FileInputStream input = new FileInputStream( source );
- try
- {
- final DocumentBuilderFactory factory =
- DocumentBuilderFactory.newInstance();
- factory.setValidating( true );
- factory.setNamespaceAware( true );
- factory.setExpandEntityReferences( true );
- DocumentBuilder builder = factory.newDocumentBuilder();
- builder.setEntityResolver( DTD_RESOLVER );
- builder.setErrorHandler( new InternalErrorHandler( source ) );
-
- final Document document = builder.parse( input );
- return document.getDocumentElement();
- }
- catch( IOException e )
- {
- throw e;
- }
- catch( Throwable e )
- {
- System.out.println( "# ERROR: " + e.toString() );
- String message = ExceptionHelper.packException( e, true );
- System.out.println( message );
-
- final String error =
- "An unexpected error occured while attempting to load library
or module source.";
- IOException ioe = new IOException( error );
- ioe.initCause( e );
- throw ioe;
- }
- finally
- {
- input.close();
- }
- }
-
- /**
- * Build a module using an XML element.
- * @param base the base directory
- * @param element the module element
- * @return the library directive
- * @exception IOException if an IO exception occurs
- */
- private static LibraryDirective buildLibraryDirective( File base,
Element element ) throws IOException
- {
- final String elementName = element.getTagName();
- if( !LIBRARY_ELEMENT_NAME.equals( elementName ) )
- {
- final String error =
- "Element is not a library.";
- throw new IllegalArgumentException( error );
- }
-
- // get type descriptors, modules and properties
-
- Properties properties = null;
- ImportDirective[] imports = new ImportDirective[0];
- ModuleDirective[] modules = new ModuleDirective[0];
- Element[] children = ElementHelper.getChildren( element );
- for( int i=0; i<children.length; i++ )
- {
- Element child = children[i];
- final String tag = child.getTagName();
- if( PROPERTIES_ELEMENT_NAME.equals( tag ) )
- {
- properties = buildProperties( child );
- }
- else if( IMPORTS_ELEMENT_NAME.equals( tag ) )
- {
- imports = buildImportDirectives( child );
- }
- else if( MODULES_ELEMENT_NAME.equals( tag ) )
- {
- modules = buildModuleDirectivesFromElement( base, child );
- }
- else
- {
- final String error =
- "Illegal element name [" + tag + "] within 'library'
element.";
- throw new IllegalArgumentException( error );
- }
- }
- return new LibraryDirective( imports, modules, properties );
- }
-
- private static ModuleDirective[] buildModuleDirectivesFromElement(
- File base, Element element ) throws IOException
- {
- Element[] children = ElementHelper.getChildren( element );
- ModuleDirective[] modules = new ModuleDirective[ children.length ];
- for( int i=0; i<children.length; i++ )
- {
- Element child = children[i];
- modules[i] = buildModuleDirectiveFromElement( base, child, null
);
- }
- return modules;
- }
-
- /**
- * Build a module directive an XML file.
- * @param source the XML source
- * @param path the relative path
- * @return the module directive
- * @exception IOException if an IO exception occurs
- */
- public static ModuleDirective buildModuleDirective( File source, String
path ) throws IOException
- {
- if( null == source )
- {
- throw new NullPointerException( "source" );
- }
- if( !source.exists() )
- {
- throw new FileNotFoundException( source.toString() );
- }
- if( source.isDirectory() )
- {
- final String error =
- "File ["
- + source
- + "] references a directory.";
- throw new IllegalArgumentException( error );
- }
- try
- {
- final Element root = getRootElement( source );
- final File parent = source.getParentFile();
- final String basedir = path;
- return buildModuleDirectiveFromElement( parent, root, basedir );
- }
- catch( Throwable e )
- {
- final String error =
- "An error occured while attempting to build a module directive
from the source: "
- + source;
- IOException ioe = new IOException( error );
- ioe.initCause( e );
- throw ioe;
- }
- }
-
- /**
- * Build a module directive from an input stream.
- * @param input the input stream
- * @return the module directive
- * @exception Exception if an exception occurs
- */
- /*
- public static ModuleDirective buildModuleDirective( InputStream input )
throws Exception
- {
- final ClassLoader loader =
Thread.currentThread().getContextClassLoader();
- try
- {
- ClassLoader context = ModuleDirective.class.getClassLoader();
- Thread.currentThread().setContextClassLoader( context );
- XMLDecoder decoder = new XMLDecoder( new BufferedInputStream(
input ) );
- return (ModuleDirective) decoder.readObject();
- }
- catch( Throwable e )
- {
- final String error =
- "An error occured while attempting to build a module directive
from an input stream.";
- IOException ioe = new IOException( error );
- ioe.initCause( e );
- throw ioe;
- }
- finally
- {
- Thread.currentThread().setContextClassLoader( loader );
- input.close();
- }
- }
- */
-
- /**
- * Build a module using an XML element.
- * @param base the base directory
- * @param element the module element
- */
- private static ModuleDirective buildModuleDirectiveFromElement(
- File base, Element element, String basedir ) throws IOException
- {
- final String elementName = element.getTagName();
- if( !MODULE_ELEMENT_NAME.equals( elementName ) )
- {
- final String error =
- "Element ["
- + elementName
- + "] is not a module.";
- throw new IllegalArgumentException( error );
- }
-
- String path = ElementHelper.getAttribute( element, "file" );
- if( null != path )
- {
- File file = new File( base, path );
- File dir = file.getParentFile();
- String spec = getRelativePath( base, dir );
-
- if( !dir.exists() )
- {
- final String error =
- "Cannot include module.xml from the dir ["
- + dir
- + "] because the directory does not exist.";
- throw new FileNotFoundException( error );
- }
- File source = file.getCanonicalFile();
- if( !source.exists() )
- {
- final String error =
- "Cannot include module ["
- + source
- + "] because the file does not exist.";
- throw new FileNotFoundException( error );
- }
- else
- {
- return buildModuleDirective( source, spec );
- }
- }
-
- ResourceDirective resource = buildResourceDirective( element,
basedir );
- ArrayList list = new ArrayList();
- Element[] children = ElementHelper.getChildren( element );
- for( int i=0; i<children.length; i++ )
- {
- Element child = children[i];
- final String tag = child.getTagName();
- if( PROPERTIES_ELEMENT_NAME.equals( tag ) )
- {
- boolean ok = true; // already processed
- }
- else if( DEPENDENCIES_ELEMENT_NAME.equals( tag ) )
- {
- boolean ok = true; // already processed
- }
- else if( TYPES_ELEMENT_NAME.equals( tag ) )
- {
- boolean ok = true; // already processed
- }
- else if( MODULE_ELEMENT_NAME.equals( tag ) )
- {
- ModuleDirective directive =
- buildModuleDirectiveFromElement( base, child, null );
- list.add( directive );
- }
- else if( PROJECT_ELEMENT_NAME.equals( tag ) )
- {
- ResourceDirective directive =
- buildResourceDirective( child );
- list.add( directive );
- }
- else if( RESOURCE_ELEMENT_NAME.equals( tag ) )
- {
- ResourceDirective directive =
- buildResourceDirective( child );
- list.add( directive );
- }
- else
- {
- final String error =
- "Illegal element name [" + tag + "] within 'module'
element.";
- throw new IllegalArgumentException( error );
- }
- }
- ResourceDirective[] resources = (ResourceDirective[]) list.toArray(
new ResourceDirective[0] );
- return new ModuleDirective( resource, resources );
- }
-
- private static String getRelativePath( File base, File dir ) throws
IOException
- {
- String baseSpec = base.getCanonicalPath();
- String dirSpec = dir.getCanonicalPath();
- if( dirSpec.startsWith( baseSpec ) )
- {
- return dirSpec.substring( baseSpec.length() + 1 );
- }
- else
- {
- final String error =
- "Supplied dir [" + dirSpec + "] is not with base [" + baseSpec
+ "].";
- throw new IllegalArgumentException( error );
- }
- }
-
- /**
- * Build an array of include directives contained within the supplied
enclosing element.
- * @param element the enclosing element
- * @return the array of includes
- */
- private static ImportDirective[] buildImportDirectives( Element element )
- {
- Element[] children = ElementHelper.getChildren( element );
- ImportDirective[] includes = new ImportDirective[ children.length ];
- for( int i=0; i<children.length; i++ )
- {
- Element child = children[i];
- includes[i] = buildImportDirective( child );
- }
- return includes;
- }
-
- private static ImportDirective buildImportDirective( Element element )
- {
- final String tag = element.getTagName();
- final Properties properties = buildProperties( element );
- if( IMPORT_ELEMENT_NAME.equals( tag ) )
- {
- if( element.hasAttribute( "file" ) )
- {
- final String value = ElementHelper.getAttribute( element,
"file", null );
- return new ImportDirective( ImportDirective.FILE, value,
properties );
- }
- else if( element.hasAttribute( "uri" ) )
- {
- final String value = ElementHelper.getAttribute( element,
"uri", null );
- return new ImportDirective( ImportDirective.URI, value,
properties );
- }
- else
- {
- final String error =
- "Import element does not declare a 'file' or 'uri'
attribute.\n"
- + element.toString();
- throw new IllegalArgumentException( error );
- }
- }
- else
- {
- final String error =
- "Invalid include element name ["
- + tag
- + "].";
- throw new IllegalArgumentException( error );
- }
- }
-
- private static DependencyDirective buildDependencyDirective( Element
element )
- {
- final String tag = element.getTagName();
- if( DEPENDENCIES_ELEMENT_NAME.equals( tag ) )
- {
- final String spec = ElementHelper.getAttribute( element,
"scope", "runtime" );
- Scope scope = Scope.parse( spec );
- Element[] children = ElementHelper.getChildren( element );
- IncludeDirective[] includes = new IncludeDirective[
children.length ];
- for( int i=0; i<children.length; i++ )
- {
- Element child = children[i];
- includes[i] = buildIncludeDirective( child );
- }
- return new DependencyDirective( scope, includes );
- }
- else
- {
- final String error =
- "Invalid dependency element name ["
- + tag
- + "].";
- throw new IllegalArgumentException( error );
- }
- }
-
- /**
- * Build an array of include directives contained within the supplied
enclosing element.
- * @param element the enclosing element
- * @return the array of includes
- */
- private static IncludeDirective[] buildIncludeDirectives( Element
element )
- {
- Element[] children = ElementHelper.getChildren( element );
- IncludeDirective[] includes = new IncludeDirective[ children.length
];
- for( int i=0; i<children.length; i++ )
- {
- Element child = children[i];
- includes[i] = buildIncludeDirective( child );
- }
- return includes;
- }
-
- private static IncludeDirective buildIncludeDirective( Element element )
- {
- final String tag = element.getTagName();
- final Properties properties = buildProperties( element );
- if( INCLUDE_ELEMENT_NAME.equals( tag ) )
- {
-
- final String tagValue = ElementHelper.getAttribute( element,
"tag", "private" );
- Category category = Category.parse( tagValue );
- if( element.hasAttribute( "key" ) )
- {
- final String value = ElementHelper.getAttribute( element,
"key", null );
- return new IncludeDirective( IncludeDirective.KEY, category,
value, properties );
- }
- else if( element.hasAttribute( "ref" ) )
- {
- final String value = ElementHelper.getAttribute( element,
"ref", null );
- return new IncludeDirective( IncludeDirective.REF, category,
value, properties );
- }
- else if( element.hasAttribute( "urn" ) )
- {
- final String value = ElementHelper.getAttribute( element,
"urn", null );
- return new IncludeDirective( IncludeDirective.URN, category,
value, properties );
- }
- else
- {
- final String error =
- "Include directive does not declare a 'urn', 'key' or
'ref' attribute.\n"
- + element.toString();
- throw new IllegalArgumentException( error );
- }
- }
- else
- {
- final String error =
- "Invalid include element name ["
- + tag
- + "].";
- throw new IllegalArgumentException( error );
- }
- }
-
- private static ResourceDirective buildResourceDirective( Element element
)
- {
- return buildResourceDirective( element, null );
- }
-
- private static ResourceDirective buildResourceDirective( Element
element, String path )
- {
- Classifier classifier = null;
- final String tag = element.getTagName();
- if( RESOURCE_ELEMENT_NAME.equals( tag ) ||
PROJECT_ELEMENT_NAME.equals( tag )
- || MODULE_ELEMENT_NAME.equals( tag ) )
- {
- final String name = ElementHelper.getAttribute( element, "name",
null );
- final String version = ElementHelper.getAttribute( element,
"version", null );
- String basedir = ElementHelper.getAttribute( element, "basedir",
null );
- if( path != null )
- {
- if( basedir == null )
- {
- basedir = path;
- }
- else
- {
- basedir = path + "/" + basedir;
- }
- }
-
- if( PROJECT_ELEMENT_NAME.equals( tag ) )
- {
- classifier = Classifier.LOCAL;
- if( null == basedir )
- {
- final String error =
- "Missing basedir attribute on project ["
- + name
- + "].";
- throw new IllegalArgumentException( error );
- }
- }
- else if( MODULE_ELEMENT_NAME.equals( tag ) )
- {
- if( null != basedir )
- {
- classifier = Classifier.LOCAL;
- }
- else
- {
- classifier = Classifier.EXTERNAL;
- }
- }
- else
- {
- classifier = Classifier.EXTERNAL;
- }
-
- ArrayList dependencies = new ArrayList();
- TypeDirective[] types = new TypeDirective[0];
- Element[] children = ElementHelper.getChildren( element );
- Properties properties = null;
- for( int i=0; i<children.length; i++ )
- {
- Element child = children[i];
- final String childTag = child.getTagName();
- if( TYPES_ELEMENT_NAME.equals( childTag ) )
- {
- types = buildTypeDirectives( child );
- }
- else if( DEPENDENCIES_ELEMENT_NAME.equals( childTag ) )
- {
- DependencyDirective dependency =
buildDependencyDirective( child );
- dependencies.add( dependency );
- }
- else if( PROPERTIES_ELEMENT_NAME.equals( childTag ) )
- {
- properties = buildProperties( child );
- }
- }
- DependencyDirective[] deps = (DependencyDirective[])
dependencies.toArray( new DependencyDirective[0] );
- return new ResourceDirective( name, version, classifier,
basedir, types, deps, properties );
- }
- else
- {
- final String error =
- "Invalid element name ["
- + tag
- + "].";
- throw new IllegalArgumentException( error );
- }
- }
-
- private static TypeDirective[] buildTypeDirectives( Element element )
- {
- Element[] children = ElementHelper.getChildren( element );
- TypeDirective[] types = new TypeDirective[ children.length ];
- for( int i=0; i<children.length; i++ )
- {
- Element child = children[i];
- types[i] = buildTypeDirective( child );
- }
- return types;
- }
-
- private static TypeDirective buildTypeDirective( Element element )
- {
- final String tag = element.getTagName();
- if( TYPE_ELEMENT_NAME.equals( tag ) )
- {
- final String name = ElementHelper.getAttribute( element, "id",
null );
- final boolean alias = ElementHelper.getBooleanAttribute(
element, "alias", false );
- final Properties properties = buildProperties( element );
- return new TypeDirective( name, alias, properties );
- }
- else
- {
- final String error =
- "Invalid resource element name ["
- + tag
- + "].";
- throw new IllegalArgumentException( error );
- }
- }
-
- private static Properties buildProperties( Element element )
- {
- Properties properties = new Properties();
- Element[] children = ElementHelper.getChildren( element );
- for( int i=0; i<children.length; i++ )
- {
- Element child = children[i];
- String tag = child.getTagName();
- if( "property".equals( tag ) )
- {
- String key = ElementHelper.getAttribute( child, "name", null
);
- if( null == key )
- {
- final String error =
- "Property declaration does not contain a 'name'
attribute.";
- throw new IllegalArgumentException( error );
- }
- else
- {
- String value = ElementHelper.getAttribute( child,
"value", null );
- properties.setProperty( key, value );
- }
- }
- }
- return properties;
- }
-
- private static URI getURIFromSpec( String spec )
- {
- if( null == spec )
- {
- return null;
- }
- else
- {
- try
- {
- return new URI( spec );
- }
- catch( URISyntaxException e )
- {
- final String error =
- "Type descriptor uri ["
- + spec
- + "] could not be converted to a URI value.";
- throw new IllegalArgumentException( error );
- }
- }
- }
-
- private static final class InternalErrorHandler implements ErrorHandler
- {
- private final File m_file;
-
- InternalErrorHandler( File file )
- {
- m_file = file;
- }
-
- public void error( SAXParseException e ) throws SAXException
- {
- System.out.println( "ERROR: "
- + e.getMessage()
- + "\nFile: " + m_file
- + "\nLine " + e.getLineNumber() + " Column: " +
e.getColumnNumber() );
- }
- public void fatalError( SAXParseException e ) throws SAXException
- {
- System.out.println( "FATAL: "
- + e.getMessage()
- + "\nFile: " + m_file
- + "\nLine " + e.getLineNumber() + " Column: " +
e.getColumnNumber() );
- }
- public void warning( SAXParseException e ) throws SAXException
- {
- System.out.println( "WARNING: "
- + e.getMessage()
- + "\nFile: " + m_file
- + "\nLine " + e.getLineNumber() + " Column: " +
e.getColumnNumber() );
- }
- }
-}
Deleted:
trunk/main/depot/library/src/main/net/dpml/library/impl/ModuleBuilder.java
===================================================================
---
trunk/main/depot/library/common/src/main/net/dpml/library/impl/ModuleBuilder.java
2006-03-05 11:48:22 UTC (rev 1167)
+++
trunk/main/depot/library/src/main/net/dpml/library/impl/ModuleBuilder.java
2006-03-14 16:03:20 UTC (rev 1171)
@@ -1,697 +0,0 @@
-/*
- * Copyright 2005 Stephen J. McConnell
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- * implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package net.dpml.library.impl;
-
-import java.io.File;
-import java.io.InputStream;
-import java.io.IOException;
-import java.io.FileNotFoundException;
-import java.io.FileInputStream;
-import java.io.BufferedInputStream;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.Writer;
-import java.net.URLConnection;
-import java.net.URI;
-import java.net.URL;
-import java.net.URISyntaxException;
-import java.util.ArrayList;
-import java.util.Properties;
-import java.beans.XMLDecoder;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-
-import net.dpml.library.info.LibraryDirective;
-import net.dpml.library.info.ImportDirective;
-import net.dpml.library.info.IncludeDirective;
-import net.dpml.library.info.IncludeDirective.Mode;
-import net.dpml.library.info.ModuleDirective;
-import net.dpml.library.info.ResourceDirective;
-import net.dpml.library.info.ResourceDirective.Classifier;
-import net.dpml.library.info.TypeDirective;
-import net.dpml.library.info.DependencyDirective;
-import net.dpml.library.info.Scope;
-
-import net.dpml.lang.DTD;
-import net.dpml.lang.DTDResolver;
-
-import net.dpml.transit.util.ElementHelper;
-import net.dpml.lang.Category;
-
-import org.xml.sax.ErrorHandler;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
-
-import org.w3c.dom.Element;
-import org.w3c.dom.Document;
-import org.w3c.dom.DocumentType;
-
-/**
- * Utility class used for construction of a module model from an XML source.
- *
- * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
- * @version @PROJECT-VERSION@
- */
-public final class ModuleBuilder
-{
- public static final String XML_HEADER =
- "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
-
- public static final String NAME = "module";
-
- public static final String PUBLIC_ID =
- "-//DPML//DTD Library 1.0//EN";
-
- public static final String SYSTEM_ID =
- "http://download.dpml.net/dtds/library_1_0.dtd";
-
- public static final String RESOURCE =
- "net/dpml/library/library_1_0.dtd";
-
- private static final String DOCTYPE =
- "\n<!DOCTYPE "
- + NAME
- + " PUBLIC \""
- + PUBLIC_ID
- + "\" \""
- + SYSTEM_ID
- + "\" >";
-
- static final DTD[] DTDS = new DTD[]
- {
- new DTD(
- PUBLIC_ID,
- SYSTEM_ID,
- RESOURCE, null )
- };
-
- static final DTDResolver DTD_RESOLVER =
- new DTDResolver( DTDS, ModuleBuilder.class.getClassLoader() );
-
- static final ErrorHandler ERROR_HANDLER =
- new InternalErrorHandler();
-
- private static final String MODULE_ELEMENT_NAME = "module";
- private static final String MODULES_ELEMENT_NAME = "modules";
- private static final String DEPENDENCIES_ELEMENT_NAME = "dependencies";
- private static final String INCLUDE_ELEMENT_NAME = "include";
- private static final String RESOURCE_ELEMENT_NAME = "resource";
- private static final String TYPES_ELEMENT_NAME = "types";
- private static final String TYPE_ELEMENT_NAME = "type";
- private static final String PROJECT_ELEMENT_NAME = "project";
- private static final String PROPERTIES_ELEMENT_NAME = "properties";
-
- /**
- * Construct a module from a supplied url.
- * @param url the module url
- * @return the module datastructure
- * @exception Exception if an error occurs during module loading
- */
- public ModuleDirective load( final URL url ) throws Exception
- {
- URLConnection connection = url.openConnection();
- InputStream input = connection.getInputStream();
-
- final DocumentBuilderFactory factory =
- DocumentBuilderFactory.newInstance();
- factory.setValidating( true );
- factory.setNamespaceAware( true );
- factory.setExpandEntityReferences( true );
- DocumentBuilder builder = factory.newDocumentBuilder();
- builder.setEntityResolver( DTD_RESOLVER );
- builder.setErrorHandler( ERROR_HANDLER );
-
- final Document document = builder.parse( input );
- final DocumentType docType = document.getDoctype();
- final Element root = document.getDocumentElement();
- return build( root );
- }
-
- /**
- * Write a module directive to an output stream as a portable XML
definition.
- * @param module the moudle directive to externalize
- * @param output the output stream
- * @exception Exception if an error occurs during module externalization
- */
- public void write( final ModuleDirective module, final OutputStream
output ) throws Exception
- {
- final Writer writer = new OutputStreamWriter( output );
- try
- {
- writer.write( XML_HEADER );
- writer.write( DOCTYPE );
- writer.write( "\n" );
- writeModule( writer, module, "" );
- writer.write( "\n" );
- }
- finally
- {
- writer.flush();
- writer.close();
- }
- }
-
- //-----------------------------------------------------------------------
- // internal utilities supporting ModuleDirective to XML creation
- //-----------------------------------------------------------------------
-
- private void writeModule( Writer writer, ModuleDirective module, String
lead ) throws IOException
- {
- String name = module.getName();
- String version = module.getVersion();
-
- Properties properties = module.getProperties();
- String basedir = module.getBasedir();
- TypeDirective[] types = module.getTypeDirectives();
- DependencyDirective[] dependencies =
module.getDependencyDirectives();
- ResourceDirective[] resources = module.getResourceDirectives();
-
- writer.write( "\n" + lead + "<" + NAME );
- if( null != name )
- {
- writer.write( " name=\"" + name + "\"" );
- }
- if( null != version )
- {
- writer.write( " version=\"" + version + "\"" );
- }
- writer.write( ">" );
-
- if( properties.size() > 0 )
- {
- writer.write( "\n" );
- writeProperties( writer, properties, lead + " ", true );
- }
-
- if( types.length > 0 )
- {
- writer.write( "\n" );
- writeTypes( writer, types, lead + " " );
- }
-
- if( dependencies.length > 0 )
- {
- writer.write( "\n" );
- writeDependencies( writer, dependencies, lead + " " );
- }
-
- if( resources.length > 0 )
- {
- writeResources( writer, resources, lead + " " );
- }
- writer.write( "\n\n" + lead + "</" + NAME + ">" );
- }
-
- private void writeResource( Writer writer, ResourceDirective resource,
String lead ) throws IOException
- {
- String name = resource.getName();
- String version = resource.getVersion();
-
- Properties properties = resource.getProperties();
- String basedir = resource.getBasedir();
- TypeDirective[] types = resource.getTypeDirectives();
- DependencyDirective[] dependencies =
resource.getDependencyDirectives();
-
- writer.write( "\n" + lead + "<resource" );
- if( null != name )
- {
- writer.write( " name=\"" + name + "\"" );
- }
- if( null != version )
- {
- writer.write( " version=\"" + version + "\"" );
- }
- writer.write( ">" );
-
- if( properties.size() > 0 )
- {
- writeProperties( writer, properties, lead + " ", true );
- }
- if( types.length > 0 )
- {
- writeTypes( writer, types, lead + " " );
- }
- if( dependencies.length > 0 )
- {
- writeDependencies( writer, dependencies, lead + " " );
- }
- writer.write( "\n" + lead + "</resource>" );
- }
-
- private void writeProperties( Writer writer, Properties properties,
String lead, boolean flag ) throws IOException
- {
- if( properties.size() > 0 )
- {
- if( flag )
- {
- writer.write( "\n" + lead + "<properties>" );
- }
- String[] names = (String[]) properties.keySet().toArray( new
String[0] );
- for( int i=0; i<names.length; i++ )
- {
- String name = names[i];
- String value = properties.getProperty( name );
- writer.write( "\n" + lead );
- if( flag )
- {
- writer.write( " " );
- }
- writer.write( "<property name=\"" + name + "\" value=\"" +
value + "\"/>" );
- }
- if( flag )
- {
- writer.write( "\n" + lead + "</properties>" );
- }
- }
- }
-
- private void writeTypes( Writer writer, TypeDirective[] types, String
lead ) throws IOException
- {
- if( types.length > 0 )
- {
- writer.write( "\n" + lead + "<types>" );
- for( int i=0; i<types.length; i++ )
- {
- TypeDirective type = types[i];
- String id = type.getName();
- boolean alias = type.getAlias();
- writer.write( "\n" + lead + " <type id=\"" + id + "\"" );
- if( alias )
- {
- writer.write( " alias=\"true\"" );
- }
- Properties properties = type.getProperties();
- if( properties.size() > 0 )
- {
- writer.write( ">" );
- writeProperties( writer, properties, lead + " ",
false );
- writer.write( "\n" + lead + " </type>" );
- }
- else
- {
- writer.write( "/>" );
- }
- }
- writer.write( "\n" + lead + "</types>" );
- }
- }
-
- private void writeDependencies( Writer writer, DependencyDirective[]
dependencies, String lead ) throws IOException
- {
- if( dependencies.length > 0 )
- {
- for( int i=0; i<dependencies.length; i++ )
- {
- DependencyDirective dependency = dependencies[i];
- IncludeDirective[] includes =
dependency.getIncludeDirectives();
- if( includes.length > 0 )
- {
- Scope scope = dependency.getScope();
- if( Scope.RUNTIME.equals( scope ) )
- {
- writer.write( "\n" + lead + "<dependencies>" );
- }
- else
- {
- writer.write( "\n" + lead + "<dependencies scope=\""
+ scope + "\">" );
- }
-
- for( int j=0; j<includes.length; j++ )
- {
- IncludeDirective include = includes[j];
- Mode mode = include.getMode();
- String value = include.getValue();
- writer.write( "\n" + lead + " <include" );
- if( Mode.KEY.equals( mode ) )
- {
- writer.write( " key=\"" + value + "\"" );
- }
- else if( Mode.REF.equals( mode ) )
- {
- writer.write( " ref=\"" + value + "\"" );
- }
- else if( Mode.URN.equals( mode ) )
- {
- writer.write( " urn=\"" + value + "\"" );
- }
-
- if( Scope.RUNTIME.equals( scope ) )
- {
- Category category = include.getCategory();
- if( !Category.PRIVATE.equals( category ) )
- {
- writer.write( " tag=\"" + category + "\"" );
- }
- }
-
- Properties props = include.getProperties();
- if( props.size() > 0 )
- {
- writer.write( ">" );
- writeProperties( writer, props, lead + " ",
false );
- writer.write( "\n" + lead + " </include>");
- }
- else
- {
- writer.write( "/>" );
- }
- }
- writer.write( "\n" + lead + "</dependencies>" );
- }
- }
- }
- }
-
- private void writeResources( Writer writer, ResourceDirective[]
resources, String lead ) throws IOException
- {
- for( int i=0; i<resources.length; i++ )
- {
- ResourceDirective resource = resources[i];
- if( resource instanceof ModuleDirective )
- {
- writer.write( "\n" );
- ModuleDirective module = (ModuleDirective) resource;
- writeModule( writer, module, lead );
- }
- else
- {
- writer.write( "\n" );
- writeResource( writer, resource, lead );
- }
- }
- }
-
- //-----------------------------------------------------------------------
- // internal utilities supporting XML to ModuleDirective creation
- //-----------------------------------------------------------------------
-
- private ModuleDirective build( Element element )
- {
- final String elementName = element.getTagName();
- if( !MODULE_ELEMENT_NAME.equals( elementName ) )
- {
- final String error =
- "Element ["
- + elementName
- + "] is not a module.";
- throw new IllegalArgumentException( error );
- }
-
- ResourceDirective resource = buildResourceDirective( element );
- ArrayList list = new ArrayList();
- Element[] children = ElementHelper.getChildren( element );
- for( int i=0; i<children.length; i++ )
- {
- Element child = children[i];
- final String tag = child.getTagName();
- if( PROPERTIES_ELEMENT_NAME.equals( tag ) )
- {
- boolean ok = true; // already processed
- }
- else if( DEPENDENCIES_ELEMENT_NAME.equals( tag ) )
- {
- boolean ok = true; // already processed
- }
- else if( TYPES_ELEMENT_NAME.equals( tag ) )
- {
- boolean ok = true; // already processed
- }
- else if( MODULE_ELEMENT_NAME.equals( tag ) )
- {
- ModuleDirective directive = build( child );
- list.add( directive );
- }
- else if( PROJECT_ELEMENT_NAME.equals( tag ) )
- {
- ResourceDirective directive = buildResourceDirective( child
);
- list.add( directive );
- }
- else if( RESOURCE_ELEMENT_NAME.equals( tag ) )
- {
- ResourceDirective directive = buildResourceDirective( child
);
- list.add( directive );
- }
- else
- {
- final String error =
- "Illegal element name ["
- + tag
- + "] within 'module' element.";
- throw new IllegalArgumentException( error );
- }
- }
- ResourceDirective[] resources = (ResourceDirective[]) list.toArray(
new ResourceDirective[0] );
- return new ModuleDirective( resource, resources );
- }
-
- private DependencyDirective buildDependencyDirective( Element element )
- {
- final String tag = element.getTagName();
- if( DEPENDENCIES_ELEMENT_NAME.equals( tag ) )
- {
- final String spec = ElementHelper.getAttribute( element,
"scope", "runtime" );
- Scope scope = Scope.parse( spec );
- Element[] children = ElementHelper.getChildren( element );
- IncludeDirective[] includes = new IncludeDirective[
children.length ];
- for( int i=0; i<children.length; i++ )
- {
- Element child = children[i];
- includes[i] = buildIncludeDirective( child );
- }
- return new DependencyDirective( scope, includes );
- }
- else
- {
- final String error =
- "Invalid dependency element name ["
- + tag
- + "].";
- throw new IllegalArgumentException( error );
- }
- }
-
- /**
- * Build an array of include directives contained within the supplied
enclosing element.
- * @param element the enclosing element
- * @return the array of includes
- */
- private IncludeDirective[] buildIncludeDirectives( Element element )
- {
- Element[] children = ElementHelper.getChildren( element );
- IncludeDirective[] includes = new IncludeDirective[ children.length
];
- for( int i=0; i<children.length; i++ )
- {
- Element child = children[i];
- includes[i] = buildIncludeDirective( child );
- }
- return includes;
- }
-
- private IncludeDirective buildIncludeDirective( Element element )
- {
- final String tag = element.getTagName();
- final Properties properties = buildProperties( element );
- if( INCLUDE_ELEMENT_NAME.equals( tag ) )
- {
-
- final String tagValue = ElementHelper.getAttribute( element,
"tag", "private" );
- Category category = Category.parse( tagValue );
- if( element.hasAttribute( "key" ) )
- {
- final String value = ElementHelper.getAttribute( element,
"key", null );
- return new IncludeDirective( IncludeDirective.KEY, category,
value, properties );
- }
- else if( element.hasAttribute( "ref" ) )
- {
- final String value = ElementHelper.getAttribute( element,
"ref", null );
- return new IncludeDirective( IncludeDirective.REF, category,
value, properties );
- }
- else if( element.hasAttribute( "urn" ) )
- {
- final String value = ElementHelper.getAttribute( element,
"urn", null );
- return new IncludeDirective( IncludeDirective.URN, category,
value, properties );
- }
- else
- {
- final String error =
- "Include directive does not declare a 'urn', 'key' or
'ref' attribute.\n"
- + element.toString();
- throw new IllegalArgumentException( error );
- }
- }
- else
- {
- final String error =
- "Invalid include element name ["
- + tag
- + "].";
- throw new IllegalArgumentException( error );
- }
- }
-
- private ResourceDirective buildResourceDirective( Element element )
- {
- Classifier classifier = null;
- final String tag = element.getTagName();
- if( RESOURCE_ELEMENT_NAME.equals( tag ) ||
PROJECT_ELEMENT_NAME.equals( tag )
- || MODULE_ELEMENT_NAME.equals( tag ) )
- {
- final String name = ElementHelper.getAttribute( element, "name"
);
- final String version = ElementHelper.getAttribute( element,
"version" );
- final String basedir = ElementHelper.getAttribute( element,
"basedir" );
-
- if( PROJECT_ELEMENT_NAME.equals( tag ) )
- {
- classifier = Classifier.LOCAL;
- if( null == basedir )
- {
- final String error =
- "Missing basedir attribute on project ["
- + name
- + "].";
- throw new IllegalArgumentException( error );
- }
- }
- else if( MODULE_ELEMENT_NAME.equals( tag ) )
- {
- if( null != basedir )
- {
- classifier = Classifier.LOCAL;
- }
- else
- {
- classifier = Classifier.EXTERNAL;
- }
- }
- else
- {
- classifier = Classifier.EXTERNAL;
- }
-
- ArrayList dependencies = new ArrayList();
- TypeDirective[] types = new TypeDirective[0];
- Element[] children = ElementHelper.getChildren( element );
- Properties properties = null;
- for( int i=0; i<children.length; i++ )
- {
- Element child = children[i];
- final String childTag = child.getTagName();
- if( TYPES_ELEMENT_NAME.equals( childTag ) )
- {
- types = buildTypeDirectives( child );
- }
- else if( DEPENDENCIES_ELEMENT_NAME.equals( childTag ) )
- {
- DependencyDirective dependency =
buildDependencyDirective( child );
- dependencies.add( dependency );
- }
- else if( PROPERTIES_ELEMENT_NAME.equals( childTag ) )
- {
- properties = buildProperties( child );
- }
- }
- DependencyDirective[] deps = (DependencyDirective[])
dependencies.toArray( new DependencyDirective[0] );
- return new ResourceDirective( name, version, classifier,
basedir, types, deps, properties );
- }
- else
- {
- final String error =
- "Invalid element name ["
- + tag
- + "].";
- throw new IllegalArgumentException( error );
- }
- }
-
- private TypeDirective[] buildTypeDirectives( Element element )
- {
- Element[] children = ElementHelper.getChildren( element );
- TypeDirective[] types = new TypeDirective[ children.length ];
- for( int i=0; i<children.length; i++ )
- {
- Element child = children[i];
- types[i] = buildTypeDirective( child );
- }
- return types;
- }
-
- private TypeDirective buildTypeDirective( Element element )
- {
- final String tag = element.getTagName();
- if( TYPE_ELEMENT_NAME.equals( tag ) )
- {
- final String name = ElementHelper.getAttribute( element, "id",
null );
- final boolean alias = ElementHelper.getBooleanAttribute(
element, "alias", false );
- final Properties properties = buildProperties( element );
- return new TypeDirective( name, alias, properties );
- }
- else
- {
- final String error =
- "Invalid resource element name ["
- + tag
- + "].";
- throw new IllegalArgumentException( error );
- }
- }
-
- private Properties buildProperties( Element element )
- {
- Properties properties = new Properties();
- Element[] children = ElementHelper.getChildren( element );
- for( int i=0; i<children.length; i++ )
- {
- Element child = children[i];
- String tag = child.getTagName();
- if( "property".equals( tag ) )
- {
- String key = ElementHelper.getAttribute( child, "name", null
);
- if( null == key )
- {
- final String error =
- "Property declaration does not contain a 'name'
attribute.";
- throw new IllegalArgumentException( error );
- }
- else
- {
- String value = ElementHelper.getAttribute( child,
"value", null );
- properties.setProperty( key, value );
- }
- }
- }
- return properties;
- }
-
- private static final class InternalErrorHandler implements ErrorHandler
- {
- public void error( SAXParseException e ) throws SAXException
- {
- System.out.println( "ERROR: " + e.getMessage() );
- }
- public void fatalError( SAXParseException e ) throws SAXException
- {
- System.out.println( "FATAL: " + e.getMessage() );
- }
- public void warning( SAXParseException e ) throws SAXException
- {
- System.out.println( "WARN: " + e.getMessage() );
- }
- }
-}
Modified:
trunk/main/depot/library/src/main/net/dpml/library/info/ResourceDirective.java
===================================================================
---
trunk/main/depot/library/common/src/main/net/dpml/library/info/ResourceDirective.java
2006-03-05 11:48:22 UTC (rev 1167)
+++
trunk/main/depot/library/src/main/net/dpml/library/info/ResourceDirective.java
2006-03-14 16:03:20 UTC (rev 1171)
@@ -71,7 +71,7 @@
{
this(
name, version, Classifier.ANONYMOUS, null,
- new TypeDirective[]{new TypeDirective( type )},
+ new TypeDirective[]{ new TypeDirective( type ) },
new DependencyDirective[0],
properties );
}
@@ -171,7 +171,7 @@
}
/**
- * Return an array of type directives representing artifacts associated
+ * Return an array of types representing artifacts associated
* with the resource.
* @return the type directives
*/
@@ -192,7 +192,7 @@
for( int i=0; i<m_types.length; i++ )
{
TypeDirective type = m_types[i];
- if( name.equals( type.getName() ) )
+ if( name.equals( type.getID() ) )
{
return type;
}
Modified:
trunk/main/depot/library/src/main/net/dpml/library/info/TypeDirective.java
===================================================================
---
trunk/main/depot/library/common/src/main/net/dpml/library/info/TypeDirective.java
2006-03-05 11:48:22 UTC (rev 1167)
+++
trunk/main/depot/library/src/main/net/dpml/library/info/TypeDirective.java
2006-03-14 16:03:20 UTC (rev 1171)
@@ -20,24 +20,33 @@
import java.util.Properties;
+import org.w3c.dom.Element;
+
+import net.dpml.lang.Type;
+
+import net.dpml.lang.Builder;
+import net.dpml.part.AbstractBuilder;
+import net.dpml.lang.BuilderException;
+
/**
* The ModuleDirective class describes a module data-structure.
*
* @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
* @version @PROJECT-VERSION@
*/
-public final class TypeDirective extends AbstractDirective
+public final class TypeDirective extends AbstractDirective
{
private final String m_name;
private final boolean m_alias;
-
+ private final Element m_element;
+
/**
* Creation of a new type directive.
* @param name the name
*/
public TypeDirective( String name )
{
- this( name, false, null );
+ this( name, false );
}
/**
@@ -47,7 +56,7 @@
*/
public TypeDirective( String name, boolean alias )
{
- this( name, alias, null );
+ this( name, alias, (Properties) null );
}
/**
@@ -65,13 +74,32 @@
}
m_name = name;
m_alias = alias;
+ m_element = null;
}
/**
+ * Creation of a new type directive.
+ * @param name the name
+ * @param alias alias production policy
+ * @param properties supplimentary properties
+ */
+ public TypeDirective( String name, boolean alias, Element element )
+ {
+ super( null );
+ if( null == name )
+ {
+ throw new NullPointerException( "name" );
+ }
+ m_name = name;
+ m_alias = alias;
+ m_element = element;
+ }
+
+ /**
* Return the type name.
* @return the name
*/
- public String getName()
+ public String getID()
{
return m_name;
}
@@ -86,6 +114,15 @@
}
/**
+ * Return the underlying custom element.
+ * @return the DOM element
+ */
+ public Element getElement()
+ {
+ return m_element;
+ }
+
+ /**
* Compare this object with another for equality.
* @param other the other object
* @return true if equal
@@ -95,7 +132,7 @@
if( super.equals( other ) && ( other instanceof TypeDirective ) )
{
TypeDirective object = (TypeDirective) other;
- if( !equals( m_name, object.m_name ) )
+ if( !m_name.equals( object.m_name ) )
{
return false;
}
@@ -121,7 +158,7 @@
{
hash ^= 1298657;
}
- hash ^= super.hashValue( m_name );
+ hash ^= m_name.hashCode();
return hash;
}
@@ -131,6 +168,6 @@
*/
public String toString()
{
- return "type-desc:" + m_name;
+ return "type:" + m_name;
}
}
Modified:
trunk/main/depot/library/src/main/net/dpml/library/model/Resource.java
===================================================================
---
trunk/main/depot/library/common/src/main/net/dpml/library/model/Resource.java
2006-03-05 11:48:22 UTC (rev 1167)
+++ trunk/main/depot/library/src/main/net/dpml/library/model/Resource.java
2006-03-14 16:03:20 UTC (rev 1171)
@@ -20,6 +20,7 @@
import java.io.File;
+import net.dpml.lang.Type;
import net.dpml.library.info.Scope;
import net.dpml.library.info.ResourceDirective.Classifier;
Modified:
trunk/main/depot/library/src/test/net/dpml/library/impl/AbstractTestCase.java
===================================================================
---
trunk/main/depot/library/common/src/test/net/dpml/library/impl/AbstractTestCase.java
2006-03-05 11:48:22 UTC (rev 1167)
+++
trunk/main/depot/library/src/test/net/dpml/library/impl/AbstractTestCase.java
2006-03-14 16:03:20 UTC (rev 1171)
@@ -77,7 +77,7 @@
{
String testPath = System.getProperty( "project.test.dir" );
File test = new File( testPath );
- File example = new File( test, path );
+ File example = new File( test, path ).getCanonicalFile();
m_library = new DefaultLibrary( m_logger, example );
}
@@ -223,9 +223,6 @@
static
{
System.setProperty(
- "java.util.prefs.PreferencesFactory",
- "net.dpml.transit.store.LocalPreferencesFactory" );
- System.setProperty(
"java.util.logging.config.class",
System.getProperty(
"java.util.logging.config.class",
Modified:
trunk/main/depot/library/src/test/net/dpml/library/impl/AnonymousTestCase.java
===================================================================
---
trunk/main/depot/library/common/src/test/net/dpml/library/impl/AnonymousTestCase.java
2006-03-05 11:48:22 UTC (rev 1167)
+++
trunk/main/depot/library/src/test/net/dpml/library/impl/AnonymousTestCase.java
2006-03-14 16:03:20 UTC (rev 1171)
@@ -36,7 +36,7 @@
*/
public void setUp() throws Exception
{
- setUp( "test.xml" );
+ setUp( "samples/anonymous.xml" );
}
/**
Modified:
trunk/main/depot/library/src/test/net/dpml/library/impl/DefaultLibraryTestCase.java
===================================================================
---
trunk/main/depot/library/common/src/test/net/dpml/library/impl/DefaultLibraryTestCase.java
2006-03-05 11:48:22 UTC (rev 1167)
+++
trunk/main/depot/library/src/test/net/dpml/library/impl/DefaultLibraryTestCase.java
2006-03-14 16:03:20 UTC (rev 1171)
@@ -20,8 +20,9 @@
import net.dpml.library.model.Module;
import net.dpml.library.model.Resource;
-import net.dpml.library.model.Type;
+import net.dpml.lang.Type;
+
/**
* Test DefaultLibrary implementation.
*
@@ -144,7 +145,7 @@
* Return the type name.
* @return the name
*/
- public String getName()
+ public String getID()
{
return m_name;
}
@@ -157,44 +158,14 @@
{
return m_alias;
}
-
+
/**
- * Return the type property names.
- * @return the names
+ * Return the type datastructure.
+ * @return the data
*/
- public String[] getPropertyNames()
+ public Object getData()
{
- return new String[0];
- }
-
- /**
- * Return the type local property names.
- * @return the names
- */
- public String[] getLocalPropertyNames()
- {
- return new String[0];
- }
-
- /**
- * Return a named property value.
- * @param key the property key (ignored)
- * @return the value (allays returns null in mock)
- */
- public String getProperty( String key )
- {
return null;
}
-
- /**
- * Return a named property value.
- * @param key the property key (ignored)
- * @param value the default value (ignored)
- * @return the value (allays returns null in mock)
- */
- public String getProperty( String key, String value )
- {
- return value;
- }
}
}
Modified:
trunk/main/depot/library/src/test/net/dpml/library/impl/DefaultResourceTestCase.java
===================================================================
---
trunk/main/depot/library/common/src/test/net/dpml/library/impl/DefaultResourceTestCase.java
2006-03-05 11:48:22 UTC (rev 1167)
+++
trunk/main/depot/library/src/test/net/dpml/library/impl/DefaultResourceTestCase.java
2006-03-14 16:03:20 UTC (rev 1171)
@@ -21,9 +21,10 @@
import java.io.File;
import net.dpml.library.model.Resource;
-import net.dpml.library.model.Type;
import net.dpml.library.info.Scope;
+import net.dpml.lang.Type;
+
import net.dpml.transit.Artifact;
import net.dpml.lang.Category;
@@ -132,10 +133,10 @@
Resource resource = getLibrary().getResource( path );
Type[] types = resource.getTypes();
Type jar = types[0];
- Type plugin = types[1];
+ Type part = types[1];
assertEquals( "types-length", 2, types.length );
- assertEquals( "jar-type", "jar", jar.getName() );
- assertEquals( "plugin-type", "plugin", plugin.getName() );
+ assertEquals( "jar-type", "jar", jar.getID() );
+ assertEquals( "part-type", "part", part.getID() );
}
/**
@@ -147,7 +148,7 @@
String path = "dpml/tools/dpml-tools-ant";
Resource resource = getLibrary().getResource( path );
assertTrue( "isa-jar", resource.isa( "jar" ) );
- assertTrue( "isa-plugin", resource.isa( "plugin" ) );
+ assertTrue( "isa-plugin", resource.isa( "part" ) );
assertFalse( "isa-rabbit", resource.isa( "rabbit" ) );
}
@@ -163,10 +164,10 @@
for( int i=0; i<types.length; i++ )
{
Type type = types[i];
- Artifact artifact = resource.getArtifact( type.getName() );
+ Artifact artifact = resource.getArtifact( type.getID() );
String urn =
"artifact:"
- + type.getName()
+ + type.getID()
+ ":"
+ resource.getResourcePath()
+ "#"
Modified:
trunk/main/depot/library/src/test/net/dpml/library/impl/ExportTestCase.java
===================================================================
---
trunk/main/depot/library/common/src/test/net/dpml/library/impl/ExportTestCase.java
2006-03-05 11:48:22 UTC (rev 1167)
+++
trunk/main/depot/library/src/test/net/dpml/library/impl/ExportTestCase.java
2006-03-14 16:03:20 UTC (rev 1171)
@@ -20,13 +20,17 @@
import java.io.File;
import java.io.FileOutputStream;
+import java.util.Arrays;
import net.dpml.library.model.Module;
import net.dpml.library.model.Resource;
-import net.dpml.library.model.Type;
import net.dpml.library.info.ModuleDirective;
import net.dpml.library.info.ResourceDirective;
+import net.dpml.library.info.DependencyDirective;
+import net.dpml.library.info.TypeDirective;
+import net.dpml.lang.Type;
+
/**
* Test DefaultLibrary implementation.
*
@@ -43,62 +47,119 @@
String spec = "dpml";
Module module = getLibrary().getModule( spec );
ModuleDirective directive = module.export();
- ModuleBuilder builder = new ModuleBuilder();
+ LibraryBuilder builder = new LibraryBuilder();
String testPath = System.getProperty( "project.test.dir" );
File test = new File( testPath );
File export = new File( test, "export.xml" );
- builder.write( directive, new FileOutputStream( export ) );
- ModuleDirective result = builder.load( export.toURL() );
+ builder.export( directive, new FileOutputStream( export ) );
+ ModuleDirective result = builder.buildModule( export.toURI() );
+ compareResourceDirective( directive, result );
assertEquals( "export", directive, result );
}
- /*
+ private void compareResourceDirective( ResourceDirective a,
ResourceDirective b )
+ {
+ if( equals( a, b ) )
+ {
+ return;
+ }
+
+ System.out.println( "exported resource: " + a.getName() + " is not
equals to constructed resource." );
+
+ if( !a.getName().equals( b.getName() ) )
+ {
+ System.out.println( "# different names" );
+ }
+ if( !a.getVersion().equals( b.getVersion() ) )
+ {
+ System.out.println( "# different versions" );
+ }
+ if( !equals( a.getBasedir(), b.getBasedir() ) )
+ {
+ System.out.println( "# different basedirs" );
+ }
+ if( !Arrays.equals( a.getTypeDirectives(), b.getTypeDirectives() ) )
+ {
+ System.out.println( "# different types" );
+ compareTypes( a.getTypeDirectives(), b.getTypeDirectives() );
+ }
+ if( !Arrays.equals( a.getDependencyDirectives(),
b.getDependencyDirectives() ) )
+ {
+ System.out.println( "# different dependencies" );
+ }
+ if( !a.getClassifier().equals( b.getClassifier() ) )
+ {
+ System.out.println( "# different classifiers" );
+ }
+ if( a instanceof ModuleDirective )
+ {
+ compareModuleDirective( (ModuleDirective) a, (ModuleDirective) b
);
+ }
+ }
+
private void compareModuleDirective( ModuleDirective a, ModuleDirective
b )
{
ResourceDirective[] ar = a.getResourceDirectives();
ResourceDirective[] br = b.getResourceDirectives();
- for( int i=0; i<ar.length; i++ )
+ if( ar.length != br.length )
{
- ResourceDirective r = ar[i];
- ResourceDirective rx = br[i];
- boolean equal = r.equals( rx );
- if( !equal )
+ System.out.println( "# different subsidiary resource count" );
+ }
+ else
+ {
+ for( int i=0; i<ar.length; i++ )
{
- compareResourceDirective( r, rx );
+ ResourceDirective r = ar[i];
+ ResourceDirective rx = br[i];
+ if( !r.equals( rx ) )
+ {
+ compareResourceDirective( r, rx );
+ }
}
}
}
- private void compareResourceDirective( ResourceDirective a,
ResourceDirective b )
+ private boolean equals( Object a, Object b )
{
- System.out.println( a.getName() + " is not equal" );
- if( a instanceof ModuleDirective )
+ if( null == a )
{
- compareModuleDirective( (ModuleDirective) a, (ModuleDirective) b
);
+ return ( null == b );
}
-
- if( !a.getName().equals( b.getName() ) )
+ else
{
- System.out.println( "different names" );
+ return a.equals( b );
}
- if( !a.getVersion().equals( b.getVersion() ) )
+ }
+
+ private void compareTypes( TypeDirective[] a, TypeDirective[] b )
+ {
+ if( a.length != b.length )
{
- System.out.println( "different versions" );
+ System.out.println( "# different type count" );
}
- if( !a.getClassifier().equals( b.getClassifier() ) )
+ else
{
- System.out.println( "different classifiers" );
+ for( int i=0; i<a.length; i++ )
+ {
+ compareType( a[i], b[i] );
+ }
}
- if( a.getTypeDirectives().length != b.getTypeDirectives().length )
+ }
+
+ private void compareType( TypeDirective a, TypeDirective b )
+ {
+ if( !a.equals( b ) )
{
- System.out.println( "different types length" );
+ if( !a.getID().equals( b.getID() ) )
+ {
+ System.out.println( "# different type ids: " + a.getID() +
", " + b.getID() );
+ }
+ else
+ {
+ System.out.println( "# different types for id: " + a.getID()
);
+ System.out.println( "# A: " + a );
+ System.out.println( "# B: " + b );
+ }
}
- if( a.getDependencyDirectives().length !=
b.getDependencyDirectives().length )
- {
- System.out.println( "different dependency length in " +
a.getName() );
- System.out.println( "A: " + a.getDependencyDirectives().length );
- System.out.println( "B: " + b.getDependencyDirectives().length );
- }
}
- */
}
Added:
trunk/main/depot/library/src/test/net/dpml/library/impl/XMLTestCase.java
===================================================================
---
trunk/main/depot/library/common/src/test/net/dpml/library/impl/XMLTestCase.java
2006-03-05 11:48:22 UTC (rev 1167)
+++ trunk/main/depot/library/src/test/net/dpml/library/impl/XMLTestCase.java
2006-03-14 16:03:20 UTC (rev 1171)
@@ -0,0 +1,191 @@
+/*
+ * Copyright 2004-2006 Stephen J. McConnell.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.library.impl;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.net.URI;
+import java.net.URL;
+import java.util.Map;
+import java.util.Hashtable;
+
+import net.dpml.library.impl.LibraryBuilder;
+import net.dpml.library.info.LibraryDirective;
+import net.dpml.library.info.ModuleDirective;
+import net.dpml.library.info.ResourceDirective;
+import net.dpml.library.info.TypeDirective;
+
+import net.dpml.lang.Type;
+
+import junit.framework.TestCase;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.DocumentType;
+
+
+/**
+ * Library XML test case.
+ *
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
+ */
+public class XMLTestCase extends TestCase
+{
+ static
+ {
+ System.setProperty( "java.protocol.handler.pkgs", "net.dpml.transit"
);
+ }
+
+ private LibraryBuilder m_builder;
+
+ /**
+ * Setup the library directive builder.
+ */
+ public void setUp() throws Exception
+ {
+ m_builder = new LibraryBuilder();
+ }
+
+ /**
+ * Test an empty library definition.
+ */
+ public void testEmptyLibrary() throws Exception
+ {
+ LibraryDirective library = getDirective( "samples/example-1.xml" );
+ assertEquals( "imports", 0, library.getImportDirectives().length );
+ assertEquals( "modules", 0, library.getModuleDirectives().length );
+ assertEquals( "properties", 0,
library.getProperties().keySet().size() );
+ }
+
+ /**
+ * Test a library definition containing just properties.
+ */
+ public void testLibraryWithProperties() throws Exception
+ {
+ LibraryDirective library = getDirective( "samples/example-2.xml" );
+ assertEquals( "imports", 0, library.getImportDirectives().length );
+ assertEquals( "modules", 0, library.getModuleDirectives().length );
+ assertEquals( "properties", 2,
library.getProperties().keySet().size() );
+ }
+
+ /**
+ * Test a library definition containing just a few imports.
+ */
+ public void testLibraryWithImports() throws Exception
+ {
+ LibraryDirective library = getDirective( "samples/example-3.xml" );
+ assertEquals( "imports", 2, library.getImportDirectives().length );
+ assertEquals( "modules", 0, library.getModuleDirectives().length );
+ assertEquals( "properties", 0,
library.getProperties().keySet().size() );
+ }
+
+ /**
+ * Test a library definition containing just a modules imports.
+ */
+ public void testLibraryWithModules() throws Exception
+ {
+ LibraryDirective library = getDirective( "samples/example-4.xml" );
+ assertEquals( "imports", 2, library.getImportDirectives().length );
+ assertEquals( "modules", 3, library.getModuleDirectives().length );
+ assertEquals( "properties", 0,
library.getProperties().keySet().size() );
+ }
+
+ /**
+ * Test a direct module name.
+ */
+ public void testModuleName() throws Exception
+ {
+ LibraryDirective library = getDirective( "samples/example-5.xml" );
+ ModuleDirective[] modules = library.getModuleDirectives();
+ ModuleDirective module = modules[0];
+ String name = module.getName();
+ assertEquals( "name", "acme", name );
+ }
+
+ /**
+ * Test a direct module basedir.
+ */
+ public void testModuleBasedir() throws Exception
+ {
+ LibraryDirective library = getDirective( "samples/example-5.xml" );
+ ModuleDirective[] modules = library.getModuleDirectives();
+ ModuleDirective module = modules[0];
+ String basedir = module.getBasedir();
+ assertEquals( "basedir", ".", basedir );
+ }
+
+ /**
+ * Test the properties within a module.
+ */
+ public void testModuleProperties() throws Exception
+ {
+ LibraryDirective library = getDirective( "samples/example-5.xml" );
+ ModuleDirective[] modules = library.getModuleDirectives();
+ ModuleDirective module = modules[0];
+ assertEquals( "properties", 3,
module.getProperties().keySet().size() );
+ }
+
+ /**
+ * Test the import of a module into the <modules> element.
+ */
+ public void testModuleImport() throws Exception
+ {
+ LibraryDirective library = getDirective( "samples/example-6.xml" );
+ ModuleDirective[] modules = library.getModuleDirectives();
+ assertEquals( "modules", 1, modules.length );
+ }
+
+ /**
+ * Test the import of a module into the <modules> element.
+ */
+ public void testNestedModuleImport() throws Exception
+ {
+ LibraryDirective library = getDirective( "samples/example-7.xml" );
+ ModuleDirective[] modules = library.getModuleDirectives();
+ assertEquals( "modules", 1, modules.length );
+ ModuleDirective module = modules[0];
+ ResourceDirective[] resources = module.getResourceDirectives();
+ assertEquals( "resources", 1, resources.length );
+ }
+
+ /**
+ * Test the import of a module into the <modules> element.
+ */
+ public void testResourceStatement() throws Exception
+ {
+ LibraryDirective library = getDirective( "samples/example-8.xml" );
+ ModuleDirective[] modules = library.getModuleDirectives();
+ assertEquals( "modules", 1, modules.length );
+ ModuleDirective module = modules[0];
+ ResourceDirective[] resources = module.getResourceDirectives();
+ assertEquals( "resources", 1, resources.length );
+ ResourceDirective resource = resources[0];
+ TypeDirective[] types = resource.getTypeDirectives();
+ assertEquals( "types", 2, types.length );
+ }
+
+ private LibraryDirective getDirective( String path ) throws Exception
+ {
+ String base = System.getProperty( "project.test.dir" );
+ File test = new File( base );
+ File file = new File( test, path );
+ return m_builder.build( file );
+ }
+}
Modified:
trunk/main/depot/library/src/test/net/dpml/library/info/ModuleDirectiveTestCase.java
===================================================================
---
trunk/main/depot/library/common/src/test/net/dpml/library/info/ModuleDirectiveTestCase.java
2006-03-05 11:48:22 UTC (rev 1167)
+++
trunk/main/depot/library/src/test/net/dpml/library/info/ModuleDirectiveTestCase.java
2006-03-14 16:03:20 UTC (rev 1171)
@@ -19,7 +19,10 @@
package net.dpml.library.info;
import net.dpml.library.info.ResourceDirective.Classifier;
+import net.dpml.library.info.TypeDirective;
+import net.dpml.lang.Type;
+
/**
* The ModuleDirective class describes a module data-structure.
*
Modified:
trunk/main/depot/library/src/test/net/dpml/library/info/ResourceDirectiveTestCase.java
===================================================================
---
trunk/main/depot/library/common/src/test/net/dpml/library/info/ResourceDirectiveTestCase.java
2006-03-05 11:48:22 UTC (rev 1167)
+++
trunk/main/depot/library/src/test/net/dpml/library/info/ResourceDirectiveTestCase.java
2006-03-14 16:03:20 UTC (rev 1171)
@@ -19,7 +19,9 @@
package net.dpml.library.info;
import net.dpml.library.info.ResourceDirective.Classifier;
+import net.dpml.library.info.TypeDirective;
+import net.dpml.lang.Type;
/**
* The ModuleDirective class describes a module data-structure.
Modified:
trunk/main/depot/library/src/test/net/dpml/library/info/TypeDirectiveTestCase.java
===================================================================
---
trunk/main/depot/library/common/src/test/net/dpml/library/info/TypeDirectiveTestCase.java
2006-03-05 11:48:22 UTC (rev 1167)
+++
trunk/main/depot/library/src/test/net/dpml/library/info/TypeDirectiveTestCase.java
2006-03-14 16:03:20 UTC (rev 1171)
@@ -18,6 +18,8 @@
package net.dpml.library.info;
+import net.dpml.library.info.TypeDirective;
+
/**
* The ModuleDirective class describes a module data-structure.
*
@@ -57,7 +59,7 @@
public void testTypeName()
{
TypeDirective type = new TypeDirective( "abc", true, PROPERTIES );
- assertEquals( "type", "abc", type.getName() );
+ assertEquals( "type", "abc", type.getID() );
}
/**
Modified: trunk/main/depot/module.xml
===================================================================
--- trunk/main/depot/module.xml 2006-03-14 15:59:54 UTC (rev 1170)
+++ trunk/main/depot/module.xml 2006-03-14 16:03:20 UTC (rev 1171)
@@ -1,35 +1,40 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
-<!DOCTYPE module PUBLIC "-//DPML//DTD Library 1.0//EN"
"http://download.dpml.net/dtds/library_1_0.dtd" >
+<module name="depot"
+ xmlns="artifact:xsd:dpml/lang/dpml-module#1.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:part="artifact:xsd:dpml/lang/dpml-part#1.0">
-<module name="depot">
-
- <project name="dpml-library-console" basedir="library/console">
+ <resource name="dpml-library">
<types>
<type id="jar"/>
- <type id="plugin" alias="true">
- <property name="project.plugin.class"
- value="net.dpml.library.console.BuilderPlugin"/>
- </type>
</types>
<dependencies>
+ <include ref="dpml/transit/dpml-transit-main"/>
+ </dependencies>
+ <dependencies scope="test">
+ <include ref="ant/ant-junit"/>
+ </dependencies>
+ </resource>
+
+ <project name="dpml-library-build" basedir="build">
+ <types>
+ <type id="jar"/>
+ <part:plugin alias="true"
class="net.dpml.library.console.BuilderPlugin"/>
+ </types>
+ <dependencies>
+ <include ref="dpml/depot/dpml-library"/>
<include ref="dpml/util/dpml-util-cli"/>
<include ref="dpml/transit/dpml-transit-main"/>
- <include ref="dpml/depot/dpml-library-main"/>
</dependencies>
<dependencies scope="test">
<include ref="ant/ant-junit"/>
</dependencies>
</project>
-
+
<project name="dpml-depot-checkstyle" basedir="tools/checkstyle">
<types>
<type id="jar"/>
- <type id="plugin" alias="true">
- <property name="project.plugin.resource"
- value="net/dpml/tools/checkstyle/antlib.xml"/>
- <property name="project.plugin.urn"
- value="dpml:checkstyle"/>
- </type>
+ <part:resource alias="true" urn="dpml:checkstyle"
path="net/dpml/tools/checkstyle/antlib.xml"/>
</types>
<dependencies>
<include ref="dpml/depot/dpml-tools-builder"/>
@@ -48,12 +53,7 @@
<project name="dpml-depot-convert" basedir="tools/convert">
<types>
<type id="jar"/>
- <type id="plugin" alias="true">
- <property name="project.plugin.resource"
- value="net/dpml/tools/convert/antlib.xml"/>
- <property name="project.plugin.urn"
- value="dpml:convert"/>
- </type>
+ <part:resource alias="true" urn="dpml:convert"
path="net/dpml/tools/convert/antlib.xml"/>
</types>
<dependencies>
<include urn="artifact:jar:java2html/java2html#4.2"/>
@@ -76,46 +76,13 @@
</dependencies>
</project>
- <!--
- <project name="dpml-depot-install" basedir="core/install">
+ <resource name="dpml-tools-builder">
<types>
<type id="jar"/>
- <type id="plugin">
- <property name="project.plugin.class"
- value="net.dpml.depot.install.PackageInstaller"/>
- </type>
+ <part:plugin alias="true" class="net.dpml.tools.impl.StandardBuilder"/>
</types>
<dependencies>
- <include key="dpml-depot-console"/>
- <include ref="dpml/transit/dpml-transit-main"/>
- <include key="dpml-station-api"/>
- <include key="dpml-station-server"/>
- </dependencies>
- </project>
- -->
-
- <resource name="dpml-library-main" basedir="library/common">
- <types>
- <type id="jar"/>
- </types>
- <dependencies>
- <include ref="dpml/transit/dpml-transit-main"/>
- </dependencies>
- <dependencies scope="test">
- <include ref="ant/ant-junit"/>
- </dependencies>
- </resource>
-
- <resource name="dpml-tools-builder" basedir="tools/builder">
- <types>
- <type id="jar"/>
- <type id="plugin" alias="true">
- <property name="project.plugin.class"
- value="net.dpml.tools.impl.StandardBuilder"/>
- </type>
- </types>
- <dependencies>
- <include key="dpml-library-main"/>
+ <include ref="dpml/depot/dpml-library"/>
<include ref="dpml/transit/dpml-transit-tools"/>
<include ref="ant/ant-junit" tag="system"/>
<include ref="ant/ant" tag="system"/>
Modified: trunk/main/depot/tools/builder/build.xml
===================================================================
--- trunk/main/depot/tools/builder/build.xml 2006-03-14 15:59:54 UTC (rev
1170)
+++ trunk/main/depot/tools/builder/build.xml 2006-03-14 16:03:20 UTC (rev
1171)
@@ -4,24 +4,26 @@
xmlns:transit="antlib:net.dpml.transit">
<property file="${basedir}/build.properties"/>
+ <property file="../../../bootstrap.properties"/>
<transit:import
file="${dpml.prefs}/dpml/transit/templates/bootstrap.template"/>
<target name="init" depends="bootstrap.init">
- <filter
value="artifact:plugin:${project.group}/${project.name}#${project.version}"
token="PROJECT-URI"/>
- <filter value="${project.name}" token="PROJECT-NAME"/>
- <filter value="${project.group}" token="PROJECT-GROUP"/>
- <filter value="${project.version}" token="PROJECT-VERSION"/>
- <filter value="${tools.ant.version}" token="ANT-VERSION"/>
- <filter value="${junit.version}" token="JUNIT-VERSION"/>
- <filter value="net.dpml.tools.impl.StandardBuilder"
token="PLUGIN-CLASS"/>
- <filter
value="artifact:plugin:${project.group}/dpml-depot-checkstyle#${project.version}"
- token="DEPOT-CHECKSTYLE-PLUGIN-URI"/>
+ <filter token="PART-XSD-URI"
value="artifact:xsd:dpml/lang/dpml-part#${dpml.xsd.version}"/>
+ <filter token="PROJECT-URI"
value="artifact:part:${project.group}/${project.name}#${project.version}" />
+ <filter token="PROJECT-NAME" value="${project.name}" />
+ <filter token="PROJECT-GROUP" value="${project.group}"/>
+ <filter token="PROJECT-VERSION" value="${project.version}"/>
+ <filter token="ANT-VERSION" value="${tools.ant.version}"/>
+ <filter token="JUNIT-VERSION" value="${junit.version}"/>
+ <filter token="PLUGIN-CLASS"
value="net.dpml.tools.impl.StandardBuilder"/>
+ <filter token="DEPOT-CHECKSTYLE-PLUGIN-URI"
+
value="artifact:plugin:${project.group}/dpml-depot-checkstyle#${project.version}"/>
</target>
<target name="setup-path" depends="bootstrap.setup-path">
<transit:get property="junit.path" uri="${junit.uri}"/>
<transit:get property="library.path"
- uri="artifact:jar:dpml/depot/dpml-library-main#${project.version}"/>
+ uri="artifact:jar:dpml/depot/dpml-library#${project.version}"/>
<transit:get property="transit.path"
uri="artifact:jar:dpml/transit/dpml-transit-main#${project.version}"/>
<path id="project.main.path">
@@ -39,10 +41,10 @@
</target>
<target name="package" depends="bootstrap.package">
- <move file="${target.deliverables.dir}/plugins/project.plugin"
-
toFile="${target.deliverables.dir}/plugins/${project.name}-${project.version}.plugin"/>
- <move file="${target.deliverables.dir}/plugins/project.plugin.link"
-
toFile="${target.deliverables.dir}/plugins/${project.name}.plugin.link"/>
+ <move file="${target.deliverables.dir}/parts/builder.xml"
+
toFile="${target.deliverables.dir}/parts/${project.name}-${project.version}.part"/>
+ <move file="${target.deliverables.dir}/parts/builder.link"
+ toFile="${target.deliverables.dir}/parts/${project.name}.part.link"/>
</target>
<target name="install" depends="bootstrap.install">
Added: trunk/main/depot/tools/builder/etc/deliverables/parts/builder.link
===================================================================
--- trunk/main/depot/tools/builder/etc/deliverables/parts/builder.link
2006-03-14 15:59:54 UTC (rev 1170)
+++ trunk/main/depot/tools/builder/etc/deliverables/parts/builder.link
2006-03-14 16:03:20 UTC (rev 1171)
@@ -0,0 +1 @@
+artifact:part:@PROJECT-GROUP@/@PROJECT-NAME@#@PROJECT-VERSION@
\ No newline at end of file
Added: trunk/main/depot/tools/builder/etc/deliverables/parts/builder.xml
===================================================================
--- trunk/main/depot/tools/builder/etc/deliverables/parts/builder.xml
2006-03-14 15:59:54 UTC (rev 1170)
+++ trunk/main/depot/tools/builder/etc/deliverables/parts/builder.xml
2006-03-14 16:03:20 UTC (rev 1171)
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<part xmlns="@PART-XSD-URI@"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+ <info title="Depot Builder">
+ <description>
+ Ant project builder for Depot.
+ </description>
+ </info>
+
+ <strategy xsi:type="plugin" class="@PLUGIN-CLASS@"/>
+
+ <classpath>
+ <system>
+ <uri>artifact:jar:ant/ant-launcher#@ANT-VERSION@</uri>
+ <uri>artifact:jar:ant/ant#@ANT-VERSION@</uri>
+ <uri>artifact:jar:junit/junit#@JUNIT-VERSION@</uri>
+ <uri>artifact:jar:ant/ant-junit#@ANT-VERSION@</uri>
+ <uri>artifact:jar:ant/ant-xslp#@ANT-VERSION@</uri>
+ <uri>artifact:jar:ant/ant-trax#@ANT-VERSION@</uri>
+ </system>
+ <private>
+
<uri>artifact:jar:dpml/transit/dpml-transit-main#@PROJECT-VERSION@</uri>
+
<uri>artifact:jar:dpml/transit/dpml-transit-tools#@PROJECT-VERSION@</uri>
+ <uri>artifact:jar:dpml/depot/dpml-library#@PROJECT-VERSION@</uri>
+
<uri>artifact:jar:@PROJECT-GROUP@/@PROJECT-NAME@#@PROJECT-VERSION@</uri>
+ </private>
+ </classpath>
+
+</part>
Modified: trunk/main/depot/tools/builder/etc/prefs/xmls/builder.xml
===================================================================
--- trunk/main/depot/tools/builder/etc/prefs/xmls/builder.xml 2006-03-14
15:59:54 UTC (rev 1170)
+++ trunk/main/depot/tools/builder/etc/prefs/xmls/builder.xml 2006-03-14
16:03:20 UTC (rev 1171)
@@ -11,7 +11,7 @@
<listeners>
<listener name="jar" class="net.dpml.tools.process.JarProcess"/>
- <listener name="plugin" class="net.dpml.tools.process.PluginProcess"
depends="jar"/>
+ <listener name="part" class="net.dpml.tools.process.PluginProcess"
depends="jar"/>
<listener name="module" class="net.dpml.tools.process.ModuleProcess"/>
</listeners>
Modified:
trunk/main/depot/tools/builder/src/main/net/dpml/tools/impl/DefaultContext.java
===================================================================
---
trunk/main/depot/tools/builder/src/main/net/dpml/tools/impl/DefaultContext.java
2006-03-14 15:59:54 UTC (rev 1170)
+++
trunk/main/depot/tools/builder/src/main/net/dpml/tools/impl/DefaultContext.java
2006-03-14 16:03:20 UTC (rev 1171)
@@ -25,8 +25,9 @@
import net.dpml.library.info.Scope;
import net.dpml.library.model.Library;
import net.dpml.library.model.Resource;
-import net.dpml.library.model.Type;
+import net.dpml.lang.Type;
+
import net.dpml.tools.model.Context;
import net.dpml.transit.Artifact;
@@ -187,6 +188,7 @@
* @param value the default value
* @return the property value or null if undefined
*/
+ /*
public String getProperty( Type type, String key, String value )
{
if( null == type )
@@ -206,6 +208,7 @@
}
}
}
+ */
/**
* Return an Ant path suitable for comile or runtime usage. If the
supplied scope is
@@ -542,7 +545,7 @@
Type[] types = resource.getTypes();
for( int j=0; j<types.length; j++ )
{
- Artifact artifact = resource.getArtifact(
types[j].getName() );
+ Artifact artifact = resource.getArtifact(
types[j].getID() );
addToPath( cache, path, artifact, resolve );
}
}
Modified:
trunk/main/depot/tools/builder/src/main/net/dpml/tools/impl/DefaultWorkbench.java
===================================================================
---
trunk/main/depot/tools/builder/src/main/net/dpml/tools/impl/DefaultWorkbench.java
2006-03-14 15:59:54 UTC (rev 1170)
+++
trunk/main/depot/tools/builder/src/main/net/dpml/tools/impl/DefaultWorkbench.java
2006-03-14 16:03:20 UTC (rev 1171)
@@ -23,8 +23,9 @@
import net.dpml.library.model.Library;
import net.dpml.library.model.Resource;
-import net.dpml.library.model.Type;
+import net.dpml.lang.Type;
+
import net.dpml.tools.info.BuilderDirective;
import net.dpml.tools.info.BuilderDirectiveHelper;
import net.dpml.tools.info.ListenerDirective;
@@ -159,7 +160,7 @@
for( int i=0; i<types.length; i++ )
{
Type type = types[i];
- names[i] = type.getName();
+ names[i] = type.getID();
}
return names;
}
Modified:
trunk/main/depot/tools/builder/src/main/net/dpml/tools/info/BuilderDirectiveHelper.java
===================================================================
---
trunk/main/depot/tools/builder/src/main/net/dpml/tools/info/BuilderDirectiveHelper.java
2006-03-14 15:59:54 UTC (rev 1170)
+++
trunk/main/depot/tools/builder/src/main/net/dpml/tools/info/BuilderDirectiveHelper.java
2006-03-14 16:03:20 UTC (rev 1171)
@@ -137,7 +137,7 @@
null );
listeners[1] =
new ListenerDirective(
- "plugin",
+ "part",
(URI) null,
PluginProcess.class.getName(),
true,
Modified:
trunk/main/depot/tools/builder/src/main/net/dpml/tools/model/Context.java
===================================================================
--- trunk/main/depot/tools/builder/src/main/net/dpml/tools/model/Context.java
2006-03-14 15:59:54 UTC (rev 1170)
+++ trunk/main/depot/tools/builder/src/main/net/dpml/tools/model/Context.java
2006-03-14 16:03:20 UTC (rev 1171)
@@ -23,8 +23,9 @@
import net.dpml.library.info.Scope;
import net.dpml.library.model.Library;
import net.dpml.library.model.Resource;
-import net.dpml.library.model.Type;
+import net.dpml.lang.Type;
+
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.Path;
@@ -70,7 +71,7 @@
* @param value the default value
* @return the property value or null if undefined
*/
- String getProperty( Type type, String key, String value );
+ //String getProperty( Type type, String key, String value );
/**
* Return an Ant path suitable for compile or runtime usage. If the
supplied scope is
Modified:
trunk/main/depot/tools/builder/src/main/net/dpml/tools/process/PluginProcess.java
===================================================================
---
trunk/main/depot/tools/builder/src/main/net/dpml/tools/process/PluginProcess.java
2006-03-14 15:59:54 UTC (rev 1170)
+++
trunk/main/depot/tools/builder/src/main/net/dpml/tools/process/PluginProcess.java
2006-03-14 16:03:20 UTC (rev 1171)
@@ -27,24 +27,24 @@
import java.util.ArrayList;
import java.util.List;
-import net.dpml.lang.Plugin;
-import net.dpml.lang.PluginFactory;
-import net.dpml.lang.Strategy;
import net.dpml.lang.Classpath;
import net.dpml.lang.Category;
import net.dpml.transit.Artifact;
import net.dpml.transit.Transit;
import net.dpml.transit.Logger;
-import net.dpml.transit.StandardHandler;
-import net.dpml.transit.DefaultPluginFactory;
-import net.dpml.transit.DefaultStrategy;
+import net.dpml.transit.util.ExceptionHelper;
+import net.dpml.part.Part;
+import net.dpml.part.Strategy;
+import net.dpml.part.Info;
+import net.dpml.part.PartBuilder;
+
+import net.dpml.lang.Type;
import net.dpml.library.info.Scope;
import net.dpml.library.model.Resource;
-import net.dpml.library.model.Type;
-import net.dpml.tools.tasks.GenericTask;
+import net.dpml.tools.tasks.PartTask;
import net.dpml.tools.model.Context;
import org.apache.tools.ant.Project;
@@ -60,33 +60,6 @@
*/
public class PluginProcess extends AbstractBuildListener
{
- /**
- * Constant artifact type for a plugin.
- */
- public static final String TYPE = "plugin";
-
- /**
- * Property key used to identify the plugin title.
- */
- public static final String PLUGIN_TITLE_KEY = "project.plugin.title";
-
- /**
- * Property key used to identify the plugin description.
- */
- public static final String PLUGIN_DESCRIPTION_KEY =
"project.plugin.description";
-
- /**
- * Property key used to identify a custom plugin handler classname.
- */
- public static final String PLUGIN_HANDLER_KEY = "project.plugin.handler";
-
- /**
- * Default runtime plugin handler classname.
- */
- public static final String STANDARD_PLUGIN_HANDLER =
StandardHandler.class.getName();
-
- private static final PluginFactory FACTORY = new DefaultPluginFactory();
-
/**
* Signals that a target is finished.
*
@@ -95,225 +68,32 @@
*
* @see BuildEvent#getTarget()
*/
- public void targetFinished( BuildEvent event )
+ public void targetStarted( BuildEvent event )
{
Target target = event.getTarget();
String name = target.getName();
- if( "build".equals( name ) )
+ if( "package".equals( name ) )
{
try
{
+ PartTask task = new PartTask();
Project project = event.getProject();
- final Context context = getContext( project );
- Resource resource = context.getResource();
- Plugin plugin = build( resource );
-
- // extenalize the plugin to XML
-
- final String path = context.getLayoutPath( TYPE );
- final File deliverables =
context.getTargetDeliverablesDirectory();
- final File plugins = new File( deliverables, "plugins" );
- final File file = new File( plugins, path );
- plugins.mkdirs();
- file.createNewFile();
- final OutputStream output = new FileOutputStream( file );
-
- try
- {
- plugin.write( output );
- }
- finally
- {
- try
- {
- output.close();
- }
- catch( IOException e )
- {
- e.printStackTrace();
- }
- }
-
- // md5 and asc
-
- GenericTask task = new GenericTask();
task.setProject( project );
task.init();
- task.checksum( file );
- task.asc( file );
-
+ task.execute();
}
- catch( Exception e )
+ catch( BuildException e )
{
- final String error =
- "An error occured during the creation of the plugin
descriptor.";
- throw new BuildException( error, e );
+ throw e;
}
- }
- }
-
- /**
- * Build the plugin definition.
- * @exception exception if a build related error occurs
- */
- private Plugin build( Resource resource ) throws Exception
- {
- URI uri = getPluginURI( resource );
- String title = getTitle( resource );
- String description = getDescription( resource );
- Strategy strategy = getStrategy( resource );
- Classpath classpath = getClasspath( resource );
- Type type = resource.getType( TYPE );
- String spec = type.getProperty( "project.plugin.factory" );
- PluginFactory factory = getPluginFactory( spec );
- return factory.newPlugin( title, description, uri, strategy,
classpath );
- }
-
-
- private URI getPluginURI( Resource resource ) throws Exception
- {
- Artifact artifact = resource.getArtifact( TYPE );
- return artifact.toURI();
- }
-
- private String getTitle( Resource resource )
- {
- Type type = resource.getType( TYPE );
- return type.getProperty( PLUGIN_TITLE_KEY );
- }
-
- private String getDescription( Resource resource )
- {
- Type type = resource.getType( TYPE );
- return type.getProperty( PLUGIN_DESCRIPTION_KEY );
- }
-
- protected Strategy getStrategy( Resource resource )
- {
- Type type = resource.getType( TYPE );
- Properties properties = getProperties( type );
- String handler = type.getProperty(
- PLUGIN_HANDLER_KEY,
- STANDARD_PLUGIN_HANDLER );
- return new DefaultStrategy( handler, properties );
- }
-
- private Properties getProperties( Type type )
- {
- Properties properties = new Properties();
- String[] keys = type.getLocalPropertyNames();
- for( int i=0; i<keys.length; i++ )
- {
- String key = keys[i];
- if( !PLUGIN_HANDLER_KEY.equals( key ) )
+ catch( Throwable e )
{
- String value = type.getProperty( key );
- properties.setProperty( key, value );
+ final String message =
+ "Unexpected failure during plugin generation.";
+ final String error =
+ ExceptionHelper.packException( message, e, true );
+ throw new BuildException( error, e );
}
}
- return properties;
}
-
- protected Classpath getClasspath( Resource resource ) throws IOException
- {
- URI[] sysUris = getURIs( resource, Category.SYSTEM );
- URI[] publicUris = getURIs( resource, Category.PUBLIC );
- URI[] protectedUris = getURIs( resource, Category.PROTECTED );
- URI[] privateUris = getURIs( resource, Category.PRIVATE, true );
- return new Classpath( sysUris, publicUris, protectedUris,
privateUris );
- }
-
- private URI[] getURIs( Resource resource, Category category ) throws
IOException
- {
- return getURIs( resource, category, false );
- }
-
- private URI[] getURIs( Resource resource, Category category, boolean
self ) throws IOException
- {
- Resource[] resources = resource.getClasspathProviders( category );
- ArrayList list = new ArrayList();
- for( int i=0; i<resources.length; i++ )
- {
- Resource r = resources[i];
- addURI( list, r );
- }
- if( self )
- {
- addURI( list, resource );
- }
- URI[] uris = (URI[]) list.toArray( new URI[0] );
- return uris;
- }
-
- private void addURI( List list, Resource resource ) throws IOException
- {
- if( resource.isa( "jar" ) )
- {
- try
- {
- Artifact artifact = resource.getArtifact( "jar" );
- URI uri = artifact.toURI();
- list.add( uri );
- }
- catch( Exception e )
- {
- final String error =
- "Unexpected error while attempting to resolve resource.";
- IOException ioe = new IOException( error );
- ioe.initCause( e );
- throw ioe;
- }
- }
- }
-
- private PluginFactory getPluginFactory( String spec ) throws Exception
- {
- if( null == spec )
- {
- return FACTORY;
- }
- else
- {
- URI uri = new URI( spec );
- ClassLoader classloader = Plugin.class.getClassLoader();
- Object[] args = new Object[0];
- Object instance =
- Transit.getInstance().getRepository().getPlugin( classloader,
uri, args );
- if( instance instanceof PluginFactory )
- {
- return (PluginFactory) instance;
- }
- else
- {
- final String error =
- "Plugin factory artifact argument ["
- + spec
- + "] established an instance of ["
- + instance.getClass().getName()
- + "] which is not assignable to "
- + PluginFactory.class.getName()
- + ".";
- throw new IllegalArgumentException( error );
- }
- }
- }
-
- /**
- * Get the project definition.
- * @param project the project
- * @return the build context
- */
- protected Context getContext( Project project )
- {
- Context context = (Context) project.getReference( "project.context"
);
- if( null == context )
- {
- final String error =
- "Missing project context reference.";
- throw new BuildException( error );
- }
- context.getPath( Scope.TEST ); // triggers path initialization
- return context;
- }
-
}
Modified:
trunk/main/depot/tools/builder/src/main/net/dpml/tools/tasks/FeatureTask.java
===================================================================
---
trunk/main/depot/tools/builder/src/main/net/dpml/tools/tasks/FeatureTask.java
2006-03-14 15:59:54 UTC (rev 1170)
+++
trunk/main/depot/tools/builder/src/main/net/dpml/tools/tasks/FeatureTask.java
2006-03-14 16:03:20 UTC (rev 1171)
@@ -43,6 +43,7 @@
private boolean m_windows = true;
private boolean m_flag = false; // os not set
private String m_type; // optional - used to select type when resolving
uris
+ private boolean m_alias = false; // used when resolving filenames
/**
* Set the key of the target project or resource description from which
features will be
@@ -56,6 +57,18 @@
}
/**
+ * Set filename resolution switch. If true the filename feature will
+ * return an alias path.
+ *
+ * @param flag the alias switch
+ */
+ public void setAlias( final boolean flag )
+ {
+ m_alias = flag;
+ }
+
+
+ /**
* Set the ref of the target project or resource description from which
features will be
* resolved from.
*
@@ -137,6 +150,18 @@
String ref = getRef();
Resource resource = getResource( ref );
+
+ if( null != m_type && !resource.isa( m_type ) )
+ {
+ final String error =
+ "The feature request for the type ["
+ + m_type
+ + "] from the resource ["
+ + resource
+ + "] cannot be fullfilled because the resource does not
declare "
+ + "production of the requested type.";
+ throw new BuildException( error, getLocation() );
+ }
if( m_feature.equals( "name" ) )
{
Modified:
trunk/main/depot/tools/builder/src/main/net/dpml/tools/tasks/InstallTask.java
===================================================================
---
trunk/main/depot/tools/builder/src/main/net/dpml/tools/tasks/InstallTask.java
2006-03-14 15:59:54 UTC (rev 1170)
+++
trunk/main/depot/tools/builder/src/main/net/dpml/tools/tasks/InstallTask.java
2006-03-14 16:03:20 UTC (rev 1171)
@@ -26,7 +26,9 @@
import net.dpml.library.model.Module;
import net.dpml.library.model.Resource;
-import net.dpml.library.model.Type;
+
+import net.dpml.lang.Type;
+
import net.dpml.transit.Artifact;
import org.apache.tools.ant.BuildException;
@@ -70,7 +72,7 @@
// type that it declares
//
- String name = type.getName();
+ String name = type.getID();
String filename = getContext().getLayoutPath( name );
File group = new File( deliverables, name + "s" );
File target = new File( group, filename );
@@ -96,7 +98,7 @@
{
try
{
- Artifact artifact = resource.getArtifact( type.getName()
);
+ Artifact artifact = resource.getArtifact( type.getID() );
String uri = artifact.toURI().toASCIIString();
String link = resource.getName() + "." + name + ".link";
log( link.toString() );
Modified:
trunk/main/depot/tools/builder/src/main/net/dpml/tools/tasks/JUnitTestTask.java
===================================================================
---
trunk/main/depot/tools/builder/src/main/net/dpml/tools/tasks/JUnitTestTask.java
2006-03-14 15:59:54 UTC (rev 1170)
+++
trunk/main/depot/tools/builder/src/main/net/dpml/tools/tasks/JUnitTestTask.java
2006-03-14 16:03:20 UTC (rev 1171)
@@ -25,6 +25,8 @@
import net.dpml.tools.model.Context;
+import net.dpml.transit.Transit;
+
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.Exit;
@@ -244,7 +246,7 @@
final JUnitTask junit = (JUnitTask) getProject().createTask( "junit"
);
junit.init();
-
+
final JUnitTask.SummaryAttribute summary = new
JUnitTask.SummaryAttribute();
summary.setValue( "on" );
junit.setPrintsummary( summary );
@@ -313,6 +315,11 @@
junit.addConfiguredSysproperty( security );
}
+ final Environment.Variable endorsed = new Environment.Variable();
+ endorsed.setKey( "java.endorsed.dirs" );
+ endorsed.setValue( new File( Transit.DPML_SYSTEM, "lib/endorsed"
).getAbsolutePath() );
+ junit.addConfiguredSysproperty( endorsed );
+
junit.setErrorProperty( ERROR_KEY );
junit.setFailureProperty( FAILURE_KEY );
junit.setTaskName( getTaskName() );
Modified:
trunk/main/depot/tools/builder/src/main/net/dpml/tools/tasks/JarTask.java
===================================================================
--- trunk/main/depot/tools/builder/src/main/net/dpml/tools/tasks/JarTask.java
2006-03-14 15:59:54 UTC (rev 1170)
+++ trunk/main/depot/tools/builder/src/main/net/dpml/tools/tasks/JarTask.java
2006-03-14 16:03:20 UTC (rev 1171)
@@ -26,8 +26,9 @@
import org.apache.tools.ant.taskdefs.ManifestException;
import net.dpml.library.model.Resource;
-import net.dpml.library.model.Type;
+import net.dpml.lang.Type;
+
/**
* Execute all plugins relative to the current build phase.
*
@@ -168,10 +169,13 @@
try
{
Type type = getType();
+ Resource resource = getResource();
+
final Manifest manifest = new Manifest();
final Manifest.Section main = manifest.getMainSection();
- String publisher = getContext().getProperty( type,
"project.publisher.name", null );
+ String publisher = resource.getProperty(
"project.publisher.name" );
+ //String publisher = getContext().getProperty( type,
"project.publisher.name", null );
if( null != publisher )
{
addAttribute( main, "Created-By", publisher );
@@ -183,38 +187,45 @@
{
addAttribute( main, "Class-Path", classpath );
}
- final String mainClass = getContext().getProperty( type,
JAR_MAIN_KEY, null );
+
+ //final String mainClass = getContext().getProperty( type,
JAR_MAIN_KEY, null );
+ final String mainClass = resource.getProperty( JAR_MAIN_KEY );
if( null != mainClass )
{
addAttribute( main, "Main-Class", mainClass );
}
addAttribute( main, "Extension-Name",
getResource().getResourcePath() );
- String specificationVendor = getContext().getProperty( type,
"project.specification.vendor", null );
+ //String specificationVendor = getContext().getProperty( type,
"project.specification.vendor", null );
+ String specificationVendor = resource.getProperty(
"project.specification.vendor" );
if( null != specificationVendor )
{
addAttribute( main, "Specification-Vendor",
specificationVendor );
}
- String version = getContext().getProperty( type,
"project.specification.version", null );
+ //String version = getContext().getProperty( type,
"project.specification.version", null );
+ String version = resource.getProperty(
"project.specification.version" );
if( null != version )
{
addAttribute( main, "Specification-Version", version );
}
- String implementationVendor = getContext().getProperty( type,
"project.implementation.vendor", null );
+ //String implementationVendor = getContext().getProperty( type,
"project.implementation.vendor", null );
+ String implementationVendor = resource.getProperty(
"project.implementation.vendor" );
if( null != implementationVendor )
{
addAttribute( main, "Implementation-Vendor",
implementationVendor );
}
- String implementationVendorID = getContext().getProperty( type,
"project.implementation.vendor-id", null );
+ //String implementationVendorID =
+ // getContext().getProperty( type,
"project.implementation.vendor-id", null );
+ String implementationVendorID = resource.getProperty(
"project.implementation.vendor-id" );
if( null != implementationVendorID )
{
addAttribute( main, "Implementation-Vendor-Id",
implementationVendorID );
}
- final String implementationVersion = getResource().getVersion();
+ final String implementationVersion = resource.getVersion();
addAttribute( main, "Implementation-Version",
implementationVersion );
jar.addConfiguredManifest( manifest );
Modified:
trunk/main/depot/tools/builder/src/main/net/dpml/tools/tasks/ModuleTask.java
===================================================================
---
trunk/main/depot/tools/builder/src/main/net/dpml/tools/tasks/ModuleTask.java
2006-03-14 15:59:54 UTC (rev 1170)
+++
trunk/main/depot/tools/builder/src/main/net/dpml/tools/tasks/ModuleTask.java
2006-03-14 16:03:20 UTC (rev 1171)
@@ -30,7 +30,7 @@
import net.dpml.library.model.Module;
import net.dpml.library.info.Scope;
import net.dpml.library.info.ModuleDirective;
-import net.dpml.library.impl.ModuleBuilder;
+import net.dpml.library.impl.LibraryBuilder;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.BuildException;
@@ -89,30 +89,14 @@
private void writeModuleDirective( ModuleDirective directive, File file )
{
- //ClassLoader current =
Thread.currentThread().getContextClassLoader();
- //Thread.currentThread().setContextClassLoader(
ModuleDirective.class.getClassLoader() );
FileOutputStream output = null;
try
{
log( "Exporting module to: " + file );
- ModuleBuilder builder = new ModuleBuilder();
+ LibraryBuilder builder = new LibraryBuilder();
file.getParentFile().mkdirs();
output = new FileOutputStream( file );
- builder.write( directive, output );
-
- //final BufferedOutputStream buffer = new BufferedOutputStream(
output );
- //XMLEncoder encoder = new XMLEncoder( buffer );
- //encoder.setExceptionListener( new ModuleEncoderListener() );
- //try
- //{
- // encoder.writeObject( directive );
- checksum( file );
- asc( file );
- //}
- //finally
- //{
- // encoder.close();
- //}
+ builder.export( directive, output );
}
catch( Exception e )
{
@@ -122,7 +106,6 @@
}
finally
{
- //Thread.currentThread().setContextClassLoader( current );
if( null != output )
{
try
Added:
trunk/main/depot/tools/builder/src/main/net/dpml/tools/tasks/PartTask.java
===================================================================
---
trunk/main/depot/tools/builder/src/main/net/dpml/tools/tasks/PartTask.java
2006-03-14 15:59:54 UTC (rev 1170)
+++
trunk/main/depot/tools/builder/src/main/net/dpml/tools/tasks/PartTask.java
2006-03-14 16:03:20 UTC (rev 1171)
@@ -0,0 +1,385 @@
+/*
+ * Copyright 2005 Stephen J. McConnell
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.tools.tasks;
+
+import java.io.File;
+import java.io.OutputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.URI;
+import java.util.Properties;
+import java.util.ArrayList;
+import java.util.List;
+
+import net.dpml.lang.Classpath;
+import net.dpml.lang.Category;
+
+import net.dpml.transit.Artifact;
+import net.dpml.transit.Transit;
+import net.dpml.transit.Logger;
+
+import net.dpml.part.Part;
+import net.dpml.part.Strategy;
+import net.dpml.part.Info;
+import net.dpml.part.PartBuilder;
+
+import net.dpml.lang.Type;
+
+import net.dpml.library.info.Scope;
+import net.dpml.library.model.Resource;
+
+import net.dpml.tools.model.Context;
+
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Target;
+import org.apache.tools.ant.BuildEvent;
+import org.apache.tools.ant.BuildException;
+
+/**
+ * Execute all plugins relative to the current build phase.
+ *
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
+ */
+public class PartTask extends GenericTask
+{
+ /**
+ * Constant artifact type for a plugin.
+ */
+ public static final String TYPE = "part";
+
+ /**
+ * Property key used to identify the plugin title.
+ */
+ public static final String PLUGIN_TITLE_KEY = "project.plugin.title";
+
+ /**
+ * Property key used to identify the plugin description.
+ */
+ public static final String PLUGIN_DESCRIPTION_KEY =
"project.plugin.description";
+
+ /**
+ * Property key used to identify a custom plugin handler classname.
+ */
+ public static final String PLUGIN_HANDLER_KEY = "project.plugin.handler";
+
+ private boolean m_test = false;
+
+ private File m_output;
+
+ private Strategy m_strategy;
+
+ public void setStrategy( Strategy strategy )
+ {
+ m_strategy = strategy;
+ }
+
+ /**
+ * Set the test build policy. The default is to include
+ * the project artifact in the classpath of a created part, however - in
a
+ * test scenario we don't want to do this. Setting test to true will
result
+ * in the association of a local file uri to the project resource.
+ *
+ * @param test true if this is a local test part
+ */
+ public void setTest( boolean test )
+ {
+ m_test = test;
+ }
+
+ /**
+ * Override the default output destination.
+ *
+ * @param file the overriding destination
+ */
+ public void setDest( File file )
+ {
+ m_output = file;
+ }
+
+ public void execute()
+ {
+ Resource resource = getResource();
+ Strategy strategy = getStrategy( resource );
+ Part part = buildPart( resource, strategy );
+ writePart( part );
+ }
+
+ public Part buildPart( Resource resource, Strategy strategy )
+ {
+ try
+ {
+ Info info = getInfo( resource );
+ Classpath classpath = getClasspath( resource );
+ return new Part( info, strategy, classpath );
+ }
+ catch( Exception e )
+ {
+ final String error =
+ "Part construction error.";
+ throw new BuildException( error, e );
+ }
+ }
+
+ public void writePart( Part part )
+ {
+ File file = getOutputFile();
+ try
+ {
+ Object data = part.getStrategy().getDeploymentData();
+ ClassLoader classloader = data.getClass().getClassLoader();
+ ClassLoader loader =
Thread.currentThread().getContextClassLoader();
+ file.createNewFile();
+ final OutputStream output = new FileOutputStream( file );
+ try
+ {
+ Thread.currentThread().setContextClassLoader( classloader );
+ PartBuilder builder = new PartBuilder();
+ builder.writePart( part, output, "" );
+ checksum( file );
+ asc( file );
+ }
+ finally
+ {
+ Thread.currentThread().setContextClassLoader( loader );
+ try
+ {
+ output.close();
+ }
+ catch( IOException e )
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+ catch( Exception e )
+ {
+ final String error =
+ "Part externalization error.";
+ throw new BuildException( error, e );
+ }
+ }
+
+ private File getOutputFile()
+ {
+ if( null != m_output )
+ {
+ return m_output;
+ }
+ else
+ {
+ Context context = getContext();
+ final String path = context.getLayoutPath( TYPE );
+ final File deliverables =
context.getTargetDeliverablesDirectory();
+ final File parts = new File( deliverables, TYPE + "s" );
+ final File file = new File( parts, path );
+ parts.mkdirs();
+ return file;
+ }
+ }
+
+ /**
+ * Build the plugin definition.
+ * @exception exception if a build related error occurs
+ */
+ private Part build( Resource resource ) throws Exception
+ {
+ Info info = getInfo( resource );
+ Strategy strategy = getStrategy( resource );
+ Classpath classpath = getClasspath( resource );
+ return new Part( info, strategy, classpath );
+ }
+
+ private Info getInfo( Resource resource )
+ {
+ String title = getTitle( resource );
+ String description = getDescription( resource );
+ return new Info( title, description );
+ }
+
+ private String getTitle( Resource resource )
+ {
+ return resource.getProperty( PLUGIN_TITLE_KEY );
+ }
+
+ private String getDescription( Resource resource )
+ {
+ return resource.getProperty( PLUGIN_DESCRIPTION_KEY );
+ }
+
+ protected Strategy getStrategy( Resource resource )
+ {
+ if( null == m_strategy )
+ {
+ Type type = resource.getType( TYPE );
+ if( type instanceof Strategy )
+ {
+ return (Strategy) type;
+ }
+ else
+ {
+ Object data = type.getData();
+ if( null != data )
+ {
+ if( data instanceof Strategy )
+ {
+ return (Strategy) data;
+ }
+ else
+ {
+ final String error =
+ "Datatype associated as the 'part' datastructure
is not an instance of "
+ + Strategy.class.getName() + "."
+ + "\nClass " + type.getClass().getName();
+ throw new BuildException( error, getLocation() );
+ }
+ }
+ else
+ {
+ final String error =
+ "No data associated with part declaration."
+ + "\nResource: " + resource
+ + "\nType: " + TYPE;
+ throw new BuildException( error, getLocation() );
+ }
+ }
+ }
+ else
+ {
+ return m_strategy;
+ }
+ }
+
+ protected Classpath getClasspath( Resource resource ) throws IOException
+ {
+ URI[] sysUris = getURIs( resource, Category.SYSTEM );
+ URI[] publicUris = getURIs( resource, Category.PUBLIC );
+ URI[] protectedUris = getURIs( resource, Category.PROTECTED );
+ URI[] privateUris = getURIs( resource, Category.PRIVATE, true );
+ return new Classpath( sysUris, publicUris, protectedUris,
privateUris );
+ }
+
+ private URI[] getURIs( Resource resource, Category category ) throws
IOException
+ {
+ return getURIs( resource, category, false );
+ }
+
+ private URI[] getURIs( Resource resource, Category category, boolean
self ) throws IOException
+ {
+ Resource[] resources = resource.getClasspathProviders( category );
+ ArrayList list = new ArrayList();
+ for( int i=0; i<resources.length; i++ )
+ {
+ Resource r = resources[i];
+ addURI( list, r );
+ }
+ if( self )
+ {
+ addURI( list, resource );
+ }
+ URI[] uris = (URI[]) list.toArray( new URI[0] );
+ return uris;
+ }
+
+ private void addURI( List list, Resource resource ) throws IOException
+ {
+ if( resource.isa( "jar" ) )
+ {
+ try
+ {
+ URI uri = toURI( resource );
+ list.add( uri );
+ }
+ catch( Exception e )
+ {
+ final String error =
+ "Unexpected error while attempting to resolve resource.";
+ IOException ioe = new IOException( error );
+ ioe.initCause( e );
+ throw ioe;
+ }
+ }
+ }
+
+ private URI toURI( Resource resource ) throws Exception
+ {
+ if( m_test && resource.equals( getResource() ) )
+ {
+ File local = getContext().getTargetDeliverable( "jar" );
+ return local.toURI();
+ }
+ else
+ {
+ return resource.getArtifact( "jar" ).toURI();
+ }
+ }
+
+ /*
+ private PluginFactory getPluginFactory( String spec ) throws Exception
+ {
+ if( null == spec )
+ {
+ return FACTORY;
+ }
+ else
+ {
+ URI uri = new URI( spec );
+ ClassLoader classloader = Plugin.class.getClassLoader();
+ Object[] args = new Object[0];
+ Object instance =
+ Transit.getInstance().getRepository().getPlugin( classloader,
uri, args );
+ if( instance instanceof PluginFactory )
+ {
+ return (PluginFactory) instance;
+ }
+ else
+ {
+ final String error =
+ "Plugin factory artifact argument ["
+ + spec
+ + "] established an instance of ["
+ + instance.getClass().getName()
+ + "] which is not assignable to "
+ + PluginFactory.class.getName()
+ + ".";
+ throw new IllegalArgumentException( error );
+ }
+ }
+ }
+ */
+
+ /**
+ * Get the project definition.
+ * @param project the project
+ * @return the build context
+ */
+ protected Context getContext( Project project )
+ {
+ Context context = (Context) project.getReference( "project.context"
);
+ if( null == context )
+ {
+ final String error =
+ "Missing project context reference.";
+ throw new BuildException( error );
+ }
+ context.getPath( Scope.TEST ); // triggers path initialization
+ return context;
+ }
+
+}
Modified:
trunk/main/depot/tools/builder/src/main/net/dpml/tools/tasks/ReplicateTask.java
===================================================================
---
trunk/main/depot/tools/builder/src/main/net/dpml/tools/tasks/ReplicateTask.java
2006-03-14 15:59:54 UTC (rev 1170)
+++
trunk/main/depot/tools/builder/src/main/net/dpml/tools/tasks/ReplicateTask.java
2006-03-14 16:03:20 UTC (rev 1171)
@@ -25,8 +25,9 @@
import net.dpml.library.info.Scope;
import net.dpml.library.model.Resource;
import net.dpml.library.model.ResourceNotFoundException;
-import net.dpml.library.model.Type;
+import net.dpml.lang.Type;
+
import net.dpml.transit.Artifact;
import net.dpml.transit.Transit;
import net.dpml.transit.Layout;
@@ -181,7 +182,7 @@
for( int j=0; j<types.length; j++ )
{
Type type = types[j];
- String id = type.getName();
+ String id = type.getID();
Artifact artifact = resource.getArtifact( id );
copyArtifact( artifact, cache, destination, layout );
- r1171 - in trunk/main/depot: . build build/etc/bin build/src/main/net/dpml/library/console core core/console core/console/etc/bin install library library/common library/etc library/etc/test library/etc/test/ant library/etc/test/commons-cli library/etc/test/dpml library/etc/test/jgoodies library/etc/test/junit library/etc/test/samples library/etc/test/xstream library/src/main/net/dpml/library library/src/main/net/dpml/library/impl library/src/main/net/dpml/library/info library/src/main/net/dpml/library/model library/src/test/net/dpml/library/impl library/src/test/net/dpml/library/info tools/builder tools/builder/etc/deliverables tools/builder/etc/deliverables/parts tools/builder/etc/prefs/xmls tools/builder/src/main/net/dpml/tools/impl tools/builder/src/main/net/dpml/tools/info tools/builder/src/main/net/dpml/tools/model tools/builder/src/main/net/dpml/tools/process tools/builder/src/main/net/dpml/tools/tasks, mcconnell at BerliOS, 03/14/2006
Archive powered by MHonArc 2.6.24.