Skip to Content.
Sympa Menu

notify-dpml - svn commit: r2927 - in development/main: depot/prefs/src/main/net/dpml/depot/prefs magic/core transit transit/core transit/core/handler transit/core/handler/src/main/net/dpml/transit/unit transit/core/handler/src/test/net/dpml/transit/manager transit/core/handler/src/test/net/dpml/transit/test transit/core/tools transit/core/tools/src/main/net/dpml/transit/tools

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: mcconnell AT dpml.net
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: svn commit: r2927 - in development/main: depot/prefs/src/main/net/dpml/depot/prefs magic/core transit transit/core transit/core/handler transit/core/handler/src/main/net/dpml/transit/unit transit/core/handler/src/test/net/dpml/transit/manager transit/core/handler/src/test/net/dpml/transit/test transit/core/tools transit/core/tools/src/main/net/dpml/transit/tools
  • Date: Mon, 27 Jun 2005 10:01:50 -0400

Author: mcconnell AT dpml.net
Date: Mon Jun 27 10:01:50 2005
New Revision: 2927

Added:

development/main/transit/core/tools/src/main/net/dpml/transit/tools/TransitTask.java
Removed:

development/main/transit/core/handler/src/test/net/dpml/transit/test/AuthorityTestCase.java
Modified:

development/main/depot/prefs/src/main/net/dpml/depot/prefs/GroupsListModel.java
development/main/magic/core/build.xml
development/main/transit/build.xml
development/main/transit/core/build.xml
development/main/transit/core/handler/build.xml

development/main/transit/core/handler/src/main/net/dpml/transit/unit/TransitStorageUnit.java

development/main/transit/core/handler/src/test/net/dpml/transit/manager/ProxyManagerTestCase.java

development/main/transit/core/handler/src/test/net/dpml/transit/manager/TransitManagerTestCase.java

development/main/transit/core/handler/src/test/net/dpml/transit/test/LinkTestCase.java
development/main/transit/core/tools/build.xml

development/main/transit/core/tools/src/main/net/dpml/transit/tools/GetTask.java

development/main/transit/core/tools/src/main/net/dpml/transit/tools/ImportArtifactTask.java

development/main/transit/core/tools/src/main/net/dpml/transit/tools/MainTask.java

development/main/transit/core/tools/src/main/net/dpml/transit/tools/PluginTask.java
Log:
Consolidate Transit configuration aspects across a number of Transit ant
tasks under a single class and improve the Transit build procedures
(including resolution of some missing resources).

Modified:
development/main/depot/prefs/src/main/net/dpml/depot/prefs/GroupsListModel.java
==============================================================================
---
development/main/depot/prefs/src/main/net/dpml/depot/prefs/GroupsListModel.java
(original)
+++
development/main/depot/prefs/src/main/net/dpml/depot/prefs/GroupsListModel.java
Mon Jun 27 10:01:50 2005
@@ -136,8 +136,7 @@

/**
* Returns the activation profile at the requested index.
- * @param row the row index
- * @param col the column index
+ * @param index the list index
* @return Object
*/
public Object getElementAt( int index )

Modified: development/main/magic/core/build.xml
==============================================================================
--- development/main/magic/core/build.xml (original)
+++ development/main/magic/core/build.xml Mon Jun 27 10:01:50 2005
@@ -46,7 +46,8 @@
</taskdef>
<echo>plugin:dpml/magic/dpml-magic-core#${dpml.build.signature}</echo>
<export>
- <antlib resource="net/dpml/magic/plugin.xml"
urn="plugin:dpml/magic/dpml-magic-core#${dpml.build.signature}"/>
+ <antlib resource="net/dpml/magic/plugin.xml"
+ urn="plugin:dpml/magic/dpml-magic-core#${dpml.build.signature}"/>
</export>
</target>


Modified: development/main/transit/build.xml
==============================================================================
--- development/main/transit/build.xml (original)
+++ development/main/transit/build.xml Mon Jun 27 10:01:50 2005
@@ -32,8 +32,6 @@
</target>

<target name="prepare" depends="standard.prepare">
- <ant dir="core/handler" inheritall="false"/>
- <ant dir="core/tools" inheritall="false"/>
<ant dir="core" inheritall="false"/>
</target>

@@ -48,7 +46,7 @@
</copy>
</target>

- <target name="build" depends="standard.build,transit.setup">
+ <target name="build" depends="standard.build">

<delete dir="${bundle}"/>

@@ -84,13 +82,14 @@

<!-- build the library -->
<mkdir dir="${local}/ant/jars"/>
- <get xmlns="antlib:net.dpml.transit" property="localJUnitPath"
uri="${junit.uri}"/>
- <copy file="${localJUnitPath}"
tofile="${local}/junit/jars/${junit.filename}"/>
- <get xmlns="antlib:net.dpml.transit" property="localAntJUnitPath"
uri="${ant.junit.uri}"/>
- <copy file="${localAntJUnitPath}"
tofile="${local}/ant/jars/${ant.junit.filename}"/>
- <get xmlns="antlib:net.dpml.transit" property="localAntPath"
uri="${ant.uri}"/>
- <copy file="${localAntPath}"
tofile="${local}/ant/jars/${transit-ant.filename}"/>
<mkdir dir="${local}/junit/jars"/>
+ <copy file="${dpml.cache}/junit/jars/${junit.filename}"
+ tofile="${local}/junit/jars/${junit.filename}"/>
+ <copy file="${dpml.cache}/ant/jars/${ant.junit.filename}"
+ tofile="${local}/junit/jars/${ant.junit.filename}"/>
+ <copy file="${dpml.cache}/ant/jars/${transit-ant.filename}"
+ tofile="${local}/junit/jars/${transit-ant.filename}"/>
+
<mkdir dir="${local}/dpml/transit"/>
<copy todir="${local}/dpml/transit">
<fileset dir="${basedir}/core/target/deliverables"/>
@@ -137,22 +136,6 @@
<include name="transit/**"/>
</fileset>
</copy>
- <echo>
-#----------------------------------------------------------------------------------
-# Updating Ant. ${user.dir}/.ant/lib
-#----------------------------------------------------------------------------------
- </echo>
- <delete verbose="true" failonerror="false">
- <fileset dir="${user.home}/.ant/lib">
- <include name="dpml-*.*"/>
- <exclude name="dpml-transit-main.jar"/>
- <exclude name="dpml-transit-tools.jar"/>
- </fileset>
- </delete>
- <copy tofile="${user.home}/.ant/lib/dpml-transit-main.jar"
-
file="${local}/dpml/transit/jars/dpml-transit-main-${project.version}.jar"/>
- <copy tofile="${user.home}/.ant/lib/dpml-transit-tools.jar"
-
file="${local}/dpml/transit/jars/dpml-transit-tools-${project.version}.jar"/>
</target>

<!-- internal utilities -->
@@ -209,15 +192,6 @@
</exec>
</target>

- <target name="transit.setup" depends="init">
- <taskdef uri="antlib:net.dpml.transit"
resource="net/dpml/transit/antlib.xml">
- <classpath>
- <pathelement
location="${dpml.cache}/dpml/transit/jars/dpml-transit-main-${project.version}.jar"/>
- <pathelement
location="${dpml.cache}/dpml/transit/jars/dpml-transit-tools-${project.version}.jar"/>
- </classpath>
- </taskdef>
- </target>
-
<target name="update" depends="install"/>

<target name="clean">

Modified: development/main/transit/core/build.xml
==============================================================================
--- development/main/transit/core/build.xml (original)
+++ development/main/transit/core/build.xml Mon Jun 27 10:01:50 2005
@@ -31,7 +31,17 @@
<filter token="COMMON-ANT-VERSION" value="${transit-ant.version}"/>
</target>

+ <target name="prepare" depends="standard.prepare">
+ <mkdir dir="${dpml.cache}/ant/jars"/>
+ <get src="${dpml.repository}/ant/jars/${transit-ant.filename}"
+ usetimestamp="true"
dest="${dpml.cache}/ant/jars/${transit-ant.filename}"/>
+ <get src="${dpml.repository}/ant/jars/${ant.junit.filename}"
+ usetimestamp="true"
dest="${dpml.cache}/ant/jars/${ant.junit.filename}"/>
+ </target>
+
<target name="package" depends="standard.package">
+ <ant dir="handler" inheritall="false"/>
+ <ant dir="tools" inheritall="false"/>
<mkdir dir="${basedir}/target/deliverables/modules"/>
<property name="module.file"

location="${basedir}/target/deliverables/modules/dpml-transit-${project.version}.module"/>
@@ -56,23 +66,13 @@
<target name="install" depends="standard.install,javadoc"/>

<target name="javadoc" depends="prepare">
-
- <taskdef uri="antlib:net.dpml.transit"
resource="net/dpml/transit/antlib.xml">
- <classpath>
- <pathelement
location="${dpml.cache}/dpml/transit/jars/dpml-transit-main-${project.version}.jar"/>
- <pathelement
location="${dpml.cache}/dpml/transit/jars/dpml-transit-tools-${project.version}.jar"/>
- </classpath>
- </taskdef>
-
- <get xmlns="antlib:net.dpml.transit" property="junit.path"
uri="${junit.uri}"/>
- <get xmlns="antlib:net.dpml.transit" property="ant.path"
uri="${ant.uri}"/>
-
+ <mkdir dir="${dpml.cache}/ant/jars"/>
<property name="api.dir" location="target/api"/>
-
<mkdir dir="${api.dir}"/>
<javadoc overview="overview.html" destdir="${api.dir}" use="true">
<classpath>
- <pathelement location="${ant.path}"/>
+ <pathelement
location="${dpml.cache}/ant/jars/${transit-ant.filename}"/>
+ <pathelement location="${dpml.cache}/junit/jars/${junit.filename}"/>
</classpath>
<doctitle><![CDATA[<h1>${project.name} API, Build
${project.version}</h1>]]></doctitle>
<packageset dir="handler/target/build/main"/>

Modified: development/main/transit/core/handler/build.xml
==============================================================================
--- development/main/transit/core/handler/build.xml (original)
+++ development/main/transit/core/handler/build.xml Mon Jun 27 10:01:50
2005
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
- Copyright 2004 Stephen J McConnell
+ Copyright 2004-2005 Stephen J McConnell
Copyright 2004 Niclas Hedhman

Licensed under the Apache License, Version 2.0 (the "License");
@@ -74,9 +74,6 @@
<jar destfile="${target.deliverables.jars.dir}/${project.filename}"
basedir="${target.classes.dir}"
includes="**/*.*" excludes="**/*.html">
- <manifest>
- <attribute name="Main-Class" value="${project.jar.main.class}"/>
- </manifest>
</jar>
<checksum fileext=".md5"
file="${target.deliverables.jars.dir}/${project.filename}"/>
<delete file="${target.deliverables.jars.dir}/${project.filename}.asc"/>
@@ -94,6 +91,20 @@
<include name="${project.filename}.asc"/>
</fileset>
</copy>
+ <echo>
+#----------------------------------------------------------------------------------
+# Updating Ant. ${user.dir}/.ant/lib
+#----------------------------------------------------------------------------------
+ </echo>
+ <delete verbose="true" failonerror="false">
+ <fileset dir="${user.home}/.ant/lib">
+ <include name="dpml-*.*"/>
+ <exclude name="dpml-transit-main.jar"/>
+ </fileset>
+ </delete>
+ <copy preservelastmodified="true" overwrite="true"
+ tofile="${user.home}/.ant/lib/dpml-transit-main.jar"
+
file="target/deliverables/jars/dpml-transit-main-${project.version}.jar"/>
</target>

</project>

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/unit/TransitStorageUnit.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/unit/TransitStorageUnit.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/unit/TransitStorageUnit.java
Mon Jun 27 10:01:50 2005
@@ -63,27 +63,13 @@

public TransitStorageUnit( String profile )
{
- this( Preferences.userNodeForPackage( Transit.class ).node(
"profiles" ).node( profile ) );
+ this( getTransitPreferences( profile ) );
}

public TransitStorageUnit( Preferences prefs )
{
super( prefs );

- URL authority = getAuthority();
- if( null != authority )
- {
- TransitPreferences.setupPreferences( prefs, authority );
- }
- else
- {
- long install = prefs.getLong( "installation", -1 );
- if( install < 0 )
- {
- TransitPreferences.setupFactoryPreferences( prefs );
- }
- }
-
try
{
Preferences proxy = getPreferences().node( "proxy" );
@@ -164,17 +150,32 @@
return m_repository;
}

- private static Preferences getPreferencesForProfile( String profile )
+ private static Preferences getTransitPreferences( String profile )
{
- return getRootPreferences().node( profile );
+ URL authority = getAuthority();
+ Preferences root = Preferences.userNodeForPackage( Transit.class );
+ Preferences prefs = root.node( "profiles" ).node( profile );
+ if( null != authority )
+ {
+ TransitPreferences.setupPreferences( prefs, authority );
+ }
+ else
+ {
+ long install = prefs.getLong( "installation", -1 );
+ if( install < 0 )
+ {
+ TransitPreferences.setupFactoryPreferences( prefs );
+ }
+ }
+ return prefs;
}

- private static Preferences getRootPreferences()
+ private static String getDefaultProfileName()
{
- return Preferences.userNodeForPackage( Transit.class ).node(
"profiles" );
+ return System.getProperty( PROFILE_KEY, DEFAULT_PROFILE_NAME );
}

- private URL getAuthority()
+ private static URL getAuthority()
{
String auth = System.getProperty( AUTHORITY_KEY, null );
if( null != auth )
@@ -202,11 +203,6 @@
}
}

- private static String getDefaultProfileName()
- {
- return System.getProperty( PROFILE_KEY, DEFAULT_PROFILE_NAME );
- }
-
private static final String DEFAULT_PROFILE_NAME = "default";
private static final String PROFILE_KEY = "dpml.transit.profile";
private static final String AUTHORITY_KEY = "dpml.transit.authority";

Modified:
development/main/transit/core/handler/src/test/net/dpml/transit/manager/ProxyManagerTestCase.java
==============================================================================
---
development/main/transit/core/handler/src/test/net/dpml/transit/manager/ProxyManagerTestCase.java
(original)
+++
development/main/transit/core/handler/src/test/net/dpml/transit/manager/ProxyManagerTestCase.java
Mon Jun 27 10:01:50 2005
@@ -45,11 +45,11 @@
{
static
{
- System.setProperty( "dpml.data", "target/test/data" );
System.setProperty(
"java.util.prefs.PreferencesFactory",
"net.dpml.transit.unit.LocalPreferencesFactory" );
System.setProperty( "dpml.transit.profile", "test-proxy" );
+ System.setProperty( "dpml.data", "target/test/data" );
}

private TransitModel m_model;

Modified:
development/main/transit/core/handler/src/test/net/dpml/transit/manager/TransitManagerTestCase.java
==============================================================================
---
development/main/transit/core/handler/src/test/net/dpml/transit/manager/TransitManagerTestCase.java
(original)
+++
development/main/transit/core/handler/src/test/net/dpml/transit/manager/TransitManagerTestCase.java
Mon Jun 27 10:01:50 2005
@@ -34,11 +34,11 @@
{
static
{
- System.setProperty( "dpml.data", "target/test/data" );
System.setProperty(
"java.util.prefs.PreferencesFactory",
"net.dpml.transit.unit.LocalPreferencesFactory" );
System.setProperty( "dpml.transit.profile", "test-cache" );
+ System.setProperty( "dpml.data", "target/test/data" );
}

private TransitModel m_model;

Modified:
development/main/transit/core/handler/src/test/net/dpml/transit/test/LinkTestCase.java
==============================================================================
---
development/main/transit/core/handler/src/test/net/dpml/transit/test/LinkTestCase.java
(original)
+++
development/main/transit/core/handler/src/test/net/dpml/transit/test/LinkTestCase.java
Mon Jun 27 10:01:50 2005
@@ -44,8 +44,8 @@
System.setProperty(
"java.util.prefs.PreferencesFactory",
"net.dpml.transit.unit.LocalPreferencesFactory" );
- System.setProperty( "java.protocol.handler.pkgs", "net.dpml.transit"
);
System.setProperty( "dpml.transit.profile", "test-link" );
+ System.setProperty( "java.protocol.handler.pkgs", "net.dpml.transit"
);
try
{
String authority = new File( "target/test" ).toURL().toString();

Modified: development/main/transit/core/tools/build.xml
==============================================================================
--- development/main/transit/core/tools/build.xml (original)
+++ development/main/transit/core/tools/build.xml Mon Jun 27 10:01:50
2005
@@ -30,4 +30,14 @@
</path>
</target>

+ <target name="install" depends="standard.install">
+ <echo>
+#----------------------------------------------------------------------------------
+# Updating Ant. ${user.dir}/.ant/lib
+#----------------------------------------------------------------------------------
+ </echo>
+ <copy tofile="${user.home}/.ant/lib/dpml-transit-tools.jar"
+
file="target/deliverables/jars/dpml-transit-tools-${project.version}.jar"/>
+ </target>
+
</project>

Modified:
development/main/transit/core/tools/src/main/net/dpml/transit/tools/GetTask.java
==============================================================================
---
development/main/transit/core/tools/src/main/net/dpml/transit/tools/GetTask.java
(original)
+++
development/main/transit/core/tools/src/main/net/dpml/transit/tools/GetTask.java
Mon Jun 27 10:01:50 2005
@@ -34,7 +34,7 @@
* @author <a href="http://www.dpml.net";>The Digital Product Meta Library</a>
* @version $Revision: 1.2 $ $Date: 2004/03/17 10:30:09 $
*/
-public class GetTask extends org.apache.tools.ant.Task
+public class GetTask extends TransitTask
{
/**
* The uri of the artifact to load.
@@ -46,6 +46,11 @@
*/
private String m_name;

+ public void setProject( Project project )
+ {
+ setTaskName( "get" );
+ super.setProject( project );
+ }

/**
* Set the artifact uri of the plugin from which the task is to be loaded.

Modified:
development/main/transit/core/tools/src/main/net/dpml/transit/tools/ImportArtifactTask.java
==============================================================================
---
development/main/transit/core/tools/src/main/net/dpml/transit/tools/ImportArtifactTask.java
(original)
+++
development/main/transit/core/tools/src/main/net/dpml/transit/tools/ImportArtifactTask.java
Mon Jun 27 10:01:50 2005
@@ -50,22 +50,7 @@
{
super.setProject( project );
setTaskName( "import" );
- try
- {
- Logger logger = new AntAdapter( this );
- TransitModel model = new DefaultTransitModel( logger );
- Transit.getInstance( model );
- }
- catch( TransitAlreadyInitializedException e )
- {
- // Transit is already initialized.
- }
- catch( Throwable e )
- {
- final String error =
- "Internal error while initializing Transit";
- throw new BuildException( error, e );
- }
+ TransitTask.initialize( this );
}

//
------------------------------------------------------------------------

Modified:
development/main/transit/core/tools/src/main/net/dpml/transit/tools/MainTask.java
==============================================================================
---
development/main/transit/core/tools/src/main/net/dpml/transit/tools/MainTask.java
(original)
+++
development/main/transit/core/tools/src/main/net/dpml/transit/tools/MainTask.java
Mon Jun 27 10:01:50 2005
@@ -67,18 +67,9 @@
*
* @author <a href="http://www.dpml.net";>The Digital Product Meta Library</a>
*/
-public class MainTask extends Task
+public class MainTask extends TransitTask
{
//
------------------------------------------------------------------------
- // static
- //
------------------------------------------------------------------------
-
- /**
- * The one-time initialized state of the transit system.
- */
- private static boolean m_INIT = false;
-
- //
------------------------------------------------------------------------
// state
//
------------------------------------------------------------------------

@@ -92,14 +83,6 @@
//
------------------------------------------------------------------------

/**
- * Task initialization.
- */
- public void init()
- {
- setTaskName( "transit" );
- }
-
- /**
* Create and return a new plugin definition.
* @return the plugin definition
*/
@@ -110,6 +93,12 @@
return map;
}

+ public void setProject( Project project )
+ {
+ setTaskName( "transit" );
+ super.setProject( project );
+ }
+
/**
* Updates properties on the current project and install any plugins
declared
* as children of the transit init tag.
@@ -119,92 +108,10 @@
public void execute() throws BuildException
{
Project project = getProject();
- checkProperties( project );
- if( !m_INIT )
- {
- setupMonitors( );
- log( "initialization in " + project.getName() );
- m_INIT = true;
- }
TransitComponentHelper.initialize( project );
ComponentHelper ch = ComponentHelper.getComponentHelper( project );
MapDataType[] maps = (MapDataType[]) m_mappings.toArray( new
MapDataType[0] );
TransitComponentHelper.register( maps );
}
-
- /**
- * Declares four properties into the current project covering the DPML
home directory,
- * template directory, doc and main cache directories.
- * @param project the current project
- * @exception BuildException if an execution error occurs
- */
- private void checkProperties( Project project ) throws BuildException
- {
- File home = Transit.DPML_HOME;
- File system = Transit.DPML_SYSTEM;
- File data = Transit.DPML_DATA;
- File prefs = Transit.DPML_PREFS;
-
- File docs = new File( data, "docs" );
- File cache = new File( data, "cache" ); // <--- FIX ME !!
- File dist = new File( data, "dist" );
- File logs = new File( data, "logs" );
-
- updateProperty( project, "dpml.home", home.getAbsolutePath() );
- updateProperty( project, "dpml.system", system.getAbsolutePath() );
- updateProperty( project, "dpml.data", data.getAbsolutePath() );
- updateProperty( project, "dpml.docs", docs.getAbsolutePath() );
- updateProperty( project, "dpml.cache", cache.getAbsolutePath() );
- updateProperty( project, "dpml.dist", dist.getAbsolutePath() );
- updateProperty( project, "dpml.logs", dist.getAbsolutePath() );
- updateProperty( project, "dpml.prefs", prefs.getAbsolutePath() );
- }
-
- /**
- * Setup the monitors.
- */
- private void setupMonitors()
- {
- try
- {
- Transit instance = Transit.getInstance();
- Adapter adapter = new AntAdapter( this );
- instance.getRepositoryMonitorRouter().addMonitor(
- new RepositoryMonitorAdapter( adapter ) );
- instance.getCacheMonitorRouter().addMonitor(
- new CacheMonitorAdapter( adapter ) );
- instance.getNetworkMonitorRouter().addMonitor(
- new NetworkMonitorAdapter( adapter ) );
- }
- catch( Throwable e )
- {
- final String error =
- "Failed to initialize Transit.";
- throw new BuildException( error, e );
- }
- }
-
- /**
- * Update a property. If the property is already defined, the
implementation
- * checks if the current value is the same as the supplied value and if
not the
- * property value is updated. If not property exists for the given key a
new
- * property will be created.
- *
- * @param project the ant project
- * @param key the property key
- * @param value the property value
- */
- private void updateProperty( Project project, String key, String value )
- {
- String v = project.getProperty( key );
- if( null == v )
- {
- project.setProperty( key, value );
- }
- else if( !v.equals( value ) )
- {
- project.setNewProperty( key, value );
- }
- }
}


Modified:
development/main/transit/core/tools/src/main/net/dpml/transit/tools/PluginTask.java
==============================================================================
---
development/main/transit/core/tools/src/main/net/dpml/transit/tools/PluginTask.java
(original)
+++
development/main/transit/core/tools/src/main/net/dpml/transit/tools/PluginTask.java
Mon Jun 27 10:01:50 2005
@@ -46,7 +46,7 @@
* @author <a href="http://www.dpml.net";>The Digital Product Meta Library</a>
* @version $Revision: 1.2 $ $Date: 2004/03/17 10:30:09 $
*/
-public class PluginTask extends org.apache.tools.ant.Task
+public class PluginTask extends TransitTask
{
private static Repository REPOSITORY;

@@ -80,6 +80,12 @@
*/
private boolean m_flag = false;

+ public void setProject( Project project )
+ {
+ setTaskName( "plugin" );
+ super.setProject( project );
+ }
+
/**
* Create and associate a new antlib urn entry with the plugin.
* @return the new antlib entry

Added:
development/main/transit/core/tools/src/main/net/dpml/transit/tools/TransitTask.java
==============================================================================
--- (empty file)
+++
development/main/transit/core/tools/src/main/net/dpml/transit/tools/TransitTask.java
Mon Jun 27 10:01:50 2005
@@ -0,0 +1,161 @@
+/*
+ * Copyright 2004-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.transit.tools;
+
+import java.io.File;
+import java.net.URL;
+
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+
+import net.dpml.transit.Transit;
+import net.dpml.transit.TransitAlreadyInitializedException;
+import net.dpml.transit.adapter.Adapter;
+import net.dpml.transit.artifact.Handler;
+import net.dpml.transit.monitors.Monitor;
+import net.dpml.transit.model.Logger;
+import net.dpml.transit.model.TransitModel;
+import net.dpml.transit.model.DefaultTransitModel;
+import net.dpml.transit.adapter.Adapter;
+import net.dpml.transit.adapter.RepositoryMonitorAdapter;
+import net.dpml.transit.adapter.CacheMonitorAdapter;
+import net.dpml.transit.adapter.NetworkMonitorAdapter;
+import net.dpml.transit.monitors.Monitor;
+
+/**
+ * Ant task that provides support for the import of build file templates
+ * via an artifact url.
+ *
+ * @author <a href="http://www.dpml.net";>The Digital Product Meta Library</a>
+ */
+public abstract class TransitTask extends Task
+{
+ static
+ {
+ System.setProperty(
+ "java.util.prefs.PreferencesFactory",
+ "net.dpml.transit.unit.LocalPreferencesFactory" );
+ System.setProperty( "java.protocol.handler.pkgs", "net.dpml.transit"
);
+ System.setProperty( "dpml.transit.authority",
"file:${dpml.prefs}/transit/authority" );
+ }
+
+ private static boolean m_INIT = false;
+
+ public void setProject( Project project )
+ {
+ super.setProject( project );
+ initialize( this );
+ }
+
+ public static void initialize( Task task ) throws BuildException
+ {
+ synchronized( TransitTask.class )
+ {
+ checkProperties( task.getProject() );
+ if( true == m_INIT )
+ {
+ return;
+ }
+ try
+ {
+ Adapter logger = new AntAdapter( task );
+ TransitModel model = new DefaultTransitModel( logger );
+ Transit transit = Transit.getInstance( model );
+ setupMonitors( transit, logger );
+ m_INIT = true;
+ }
+ catch( TransitAlreadyInitializedException e )
+ {
+ // Transit is already initialized.
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Internal error while initializing Transit";
+ throw new BuildException( error, e );
+ }
+ }
+ }
+
+ /**
+ * Declares four properties into the current project covering the DPML
home directory,
+ * template directory, doc and main cache directories.
+ * @param project the current project
+ * @exception BuildException if an execution error occurs
+ */
+ private static void checkProperties( Project project ) throws
BuildException
+ {
+ File home = Transit.DPML_HOME;
+ File system = Transit.DPML_SYSTEM;
+ File data = Transit.DPML_DATA;
+ File prefs = Transit.DPML_PREFS;
+
+ File docs = new File( data, "docs" );
+ File cache = new File( data, "cache" ); // <--- FIX ME !!
+ File dist = new File( data, "dist" );
+ File logs = new File( data, "logs" );
+
+ updateProperty( project, "dpml.home", home.getAbsolutePath() );
+ updateProperty( project, "dpml.system", system.getAbsolutePath() );
+ updateProperty( project, "dpml.data", data.getAbsolutePath() );
+ updateProperty( project, "dpml.docs", docs.getAbsolutePath() );
+ updateProperty( project, "dpml.cache", cache.getAbsolutePath() );
+ updateProperty( project, "dpml.dist", dist.getAbsolutePath() );
+ updateProperty( project, "dpml.logs", dist.getAbsolutePath() );
+ updateProperty( project, "dpml.prefs", prefs.getAbsolutePath() );
+ }
+
+ /**
+ * Update a property. If the property is already defined, the
implementation
+ * checks if the current value is the same as the supplied value and if
not the
+ * property value is updated. If not property exists for the given key a
new
+ * property will be created.
+ *
+ * @param project the ant project
+ * @param key the property key
+ * @param value the property value
+ */
+ private static void updateProperty( Project project, String key, String
value )
+ {
+ String v = project.getProperty( key );
+ if( null == v )
+ {
+ project.setProperty( key, value );
+ }
+ else if( !v.equals( value ) )
+ {
+ project.setNewProperty( key, value );
+ }
+ }
+
+ /**
+ * Setup the monitors.
+ */
+ private static void setupMonitors( Transit instance, Adapter adapter )
throws Exception
+ {
+ instance.getRepositoryMonitorRouter().addMonitor(
+ new RepositoryMonitorAdapter( adapter ) );
+ instance.getCacheMonitorRouter().addMonitor(
+ new CacheMonitorAdapter( adapter ) );
+ instance.getNetworkMonitorRouter().addMonitor(
+ new NetworkMonitorAdapter( adapter ) );
+ }
+}
+



  • svn commit: r2927 - in development/main: depot/prefs/src/main/net/dpml/depot/prefs magic/core transit transit/core transit/core/handler transit/core/handler/src/main/net/dpml/transit/unit transit/core/handler/src/test/net/dpml/transit/manager transit/core/handler/src/test/net/dpml/transit/test transit/core/tools transit/core/tools/src/main/net/dpml/transit/tools, mcconnell, 06/27/2005

Archive powered by MHonArc 2.6.24.

Top of Page