Skip to Content.
Sympa Menu

notify-dpml - svn commit: r2932 - in development/main: . depot depot/console magic magic/core/src/main/net/dpml/magic metro transit/core transit/core/etc transit/core/handler/src/main/net/dpml/transit transit/core/handler/src/main/net/dpml/transit/artifact transit/core/handler/src/main/net/dpml/transit/link transit/core/handler/src/main/net/dpml/transit/model transit/core/handler/src/main/net/dpml/transit/runtime transit/core/handler/src/test/net/dpml/transit/test transit/core/tools/src/main/net/dpml/transit 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: r2932 - in development/main: . depot depot/console magic magic/core/src/main/net/dpml/magic metro transit/core transit/core/etc transit/core/handler/src/main/net/dpml/transit transit/core/handler/src/main/net/dpml/transit/artifact transit/core/handler/src/main/net/dpml/transit/link transit/core/handler/src/main/net/dpml/transit/model transit/core/handler/src/main/net/dpml/transit/runtime transit/core/handler/src/test/net/dpml/transit/test transit/core/tools/src/main/net/dpml/transit transit/core/tools/src/main/net/dpml/transit/tools
  • Date: Tue, 28 Jun 2005 13:26:08 -0400

Author: mcconnell AT dpml.net
Date: Tue Jun 28 13:26:08 2005
New Revision: 2932

Added:
development/main/transit/core/etc/project.module.link

development/main/transit/core/handler/src/main/net/dpml/transit/artifact/UnsupportedSchemeException.java

development/main/transit/core/tools/src/main/net/dpml/transit/tools/LinkTask.java
Modified:
development/main/depot/console/build.xml
development/main/depot/module.xml
development/main/magic/core/src/main/net/dpml/magic/AntFileIndex.java
development/main/magic/module.xml
development/main/metro/module.xml
development/main/module.properties
development/main/transit/core/build.xml

development/main/transit/core/handler/src/main/net/dpml/transit/SecuredTransitContext.java

development/main/transit/core/handler/src/main/net/dpml/transit/Transit.java

development/main/transit/core/handler/src/main/net/dpml/transit/artifact/Artifact.java

development/main/transit/core/handler/src/main/net/dpml/transit/link/ArtifactLinkManager.java

development/main/transit/core/handler/src/main/net/dpml/transit/link/Link.java

development/main/transit/core/handler/src/main/net/dpml/transit/link/LinkURLConnection.java

development/main/transit/core/handler/src/main/net/dpml/transit/model/TransitRegistryEvent.java

development/main/transit/core/handler/src/main/net/dpml/transit/runtime/ClassicLayout.java

development/main/transit/core/handler/src/main/net/dpml/transit/runtime/DefaultCacheHandler.java

development/main/transit/core/handler/src/main/net/dpml/transit/runtime/EclipseLayout.java

development/main/transit/core/handler/src/test/net/dpml/transit/test/LinkTestCase.java
development/main/transit/core/tools/src/main/net/dpml/transit/antlib.xml
Log:
Updates to Transit to support links and updating of the core products to
reference modules via links.

Modified: development/main/depot/console/build.xml
==============================================================================
--- development/main/depot/console/build.xml (original)
+++ development/main/depot/console/build.xml Tue Jun 28 13:26:08 2005
@@ -15,14 +15,10 @@
<filter token="TRANSIT-PATH" value="${transit.filename}"/>
<filter token="TRANSIT-MAIN-LIB" value="${transit.filename}" />
<filter token="DEPOT-MAIN-CLASS" value="net.dpml.depot.Main" />
- <x:property name="station.plugin" key="dpml-depot-station" feature="uri"
type="plugin"/>
- <filter token="STATION-PLUGIN-URI" value="${station.plugin}" />
- <x:property name="test.plugin" key="dpml-depot-test" feature="uri"
type="plugin"/>
- <filter token="TEST-PLUGIN-URI" value="${test.plugin}" />
- <x:property name="console.plugin" feature="uri" type="jar"/>
- <filter token="DEPOT-CONSOLE-URI" value="${console.plugin}" />
- <x:property name="prefs.plugin" key="dpml-depot-prefs" feature="uri"
type="plugin"/>
- <filter token="DEPOT-PREFS-URI" value="${prefs.plugin}" />
+ <x:filter token="STATION-PLUGIN-URI" key="dpml-depot-station"
feature="uri" type="plugin"/>
+ <x:filter token="TEST-PLUGIN-URI" key="dpml-depot-test" feature="uri"
type="plugin"/>
+ <x:filter token="DEPOT-CONSOLE-URI" feature="uri" type="jar"/>
+ <x:filter token="DEPOT-PREFS-URI" key="dpml-depot-prefs" feature="uri"
type="plugin"/>
</target>

<target name="build" depends="standard.build">

Modified: development/main/depot/module.xml
==============================================================================
--- development/main/depot/module.xml (original)
+++ development/main/depot/module.xml Tue Jun 28 13:26:08 2005
@@ -41,6 +41,11 @@
</x:javadoc>
</target>

+ <target name="install" depends="standard.install">
+ <x:property name="module.uri" feature="uri" type="module"/>
+ <transit:link target="${module.uri}"
uri="link:module:${project.group}/${project.name}"/>
+ </target>
+
<target name="test" depends="standard.test">
<mkdir dir="target/reports/junit"/>
<junitreport todir="target/reports/junit">

Modified:
development/main/magic/core/src/main/net/dpml/magic/AntFileIndex.java
==============================================================================
--- development/main/magic/core/src/main/net/dpml/magic/AntFileIndex.java
(original)
+++ development/main/magic/core/src/main/net/dpml/magic/AntFileIndex.java
Tue Jun 28 13:26:08 2005
@@ -37,6 +37,7 @@
import net.dpml.transit.NullArgumentException;
import net.dpml.transit.Transit;
import net.dpml.transit.TransitException;
+import net.dpml.transit.artifact.Artifact;
import net.dpml.transit.artifact.Handler;
import net.dpml.transit.repository.Repository;
import net.dpml.transit.repository.StandardLoader;
@@ -474,7 +475,11 @@
}
catch( Throwable e )
{
- throw new BuildException( e, new Location( source.toString() ) );
+ final String error =
+ "Unexpected error while building index list."
+ + "\nSource file: " + source
+ + "\nURI: " + uri;
+ throw new BuildException( error, e, new Location(
source.toString() ) );
}
}

@@ -502,9 +507,9 @@
}
}

- /* (non-Javadoc)
- * @see net.dpml.magic.Index#buildModule(java.io.File)
- */
+ /* (non-Javadoc)
+ * @see net.dpml.magic.Index#buildModule(java.io.File)
+ */
public Module buildModule( File source )
{
try
@@ -539,12 +544,13 @@
{
try
{
- URL artifact = new URL( null, uri, new Handler() );
- File local = (File) artifact.getContent( new Class[]{ File.class
} );
+ Artifact artifact = Artifact.createArtifact( uri );
+ URL url = artifact.toURL();
+ File local = (File) url.getContent( new Class[]{ File.class } );
final Element root = ElementHelper.getRootElement( local );
return buildModule( root, local );
}
- catch( IOException ioe )
+ catch( Exception ioe )
{
final String error =
"Failed to load module ["
@@ -719,7 +725,7 @@
final File index = AntFileIndexBuilder.getFile( anchor, filename
);
buildList( index, uri );
}
- else if(null == urn || "".equals(urn))
+ else if( null == urn || "".equals( urn ) )
{
final String error =
"Invalid import statement. No uri, index attribute.";
@@ -733,11 +739,12 @@
m_includes.add( urn );
try
{
- URL artifact = new URL( null, urn, new Handler() );
- File local = (File) artifact.getContent( new Class[]{
File.class } );
+ Artifact artifact = Artifact.createArtifact( urn );
+ URL url = artifact.toURL();
+ File local = (File) url.getContent( new Class[]{
File.class } );
buildList( local, urn );
}
- catch( IOException ioe )
+ catch( Exception ioe )
{
final String error =
"Failed to load module ["

Modified: development/main/magic/module.xml
==============================================================================
--- development/main/magic/module.xml (original)
+++ development/main/magic/module.xml Tue Jun 28 13:26:08 2005
@@ -46,6 +46,8 @@
</target>

<target name="install" depends="standard.install,junit-report,checkstyle">
+ <x:property name="module.uri" feature="uri" type="module"/>
+ <transit:link target="${module.uri}"
uri="link:module:${project.group}/${project.name}"/>
<echo>

#----------------------------------------------------------------------------------
# Updating DPML PREFS ${dpml.prefs}

Modified: development/main/metro/module.xml
==============================================================================
--- development/main/metro/module.xml (original)
+++ development/main/metro/module.xml Tue Jun 28 13:26:08 2005
@@ -39,6 +39,8 @@
</target>

<target name="install" depends="docs,standard.install">
+ <x:property name="module.uri" feature="uri" type="module"/>
+ <transit:link target="${module.uri}"
uri="link:module:${project.group}/${project.name}"/>
<echo>

#----------------------------------------------------------------------------------
# Updating DPML PREFS ${dpml.prefs}

Modified: development/main/module.properties
==============================================================================
--- development/main/module.properties (original)
+++ development/main/module.properties Tue Jun 28 13:26:08 2005
@@ -10,14 +10,19 @@
dpml.ant.version = 1.6.4

#dpml.transit.version = $1835M
+#dpml.transit.uri =
artifact:module:dpml/transit/dpml-transit#${dpml.transit.version}
+#dpml.magic.uri = artifact:module:dpml/magic/dpml-magic#${dpml.magic.version}
+#dpml.metro.uri = artifact:module:dpml/metro/dpml-metro#${dpml.metro.version}
+#dpml.depot.uri = artifact:module:dpml/depot/dpml-depot#${dpml.depot.version}
+
dpml.transit.version = ${dpml.build.signature}
-dpml.transit.uri =
artifact:module:dpml/transit/dpml-transit#${dpml.transit.version}
+dpml.transit.uri = link:module:dpml/transit/dpml-transit

dpml.magic.version = ${dpml.build.signature}
-dpml.magic.uri = artifact:module:dpml/magic/dpml-magic#${dpml.magic.version}
+dpml.magic.uri = link:module:dpml/magic/dpml-magic

dpml.metro.version = ${dpml.build.signature}
-dpml.metro.uri = artifact:module:dpml/metro/dpml-metro#${dpml.metro.version}
+dpml.metro.uri = link:module:dpml/metro/dpml-metro

dpml.depot.version = ${dpml.build.signature}
-dpml.depot.uri = artifact:module:dpml/depot/dpml-depot#${dpml.depot.version}
+dpml.depot.uri = link:module:dpml/depot/dpml-depot

Modified: development/main/transit/core/build.xml
==============================================================================
--- development/main/transit/core/build.xml (original)
+++ development/main/transit/core/build.xml Tue Jun 28 13:26:08 2005
@@ -49,6 +49,8 @@
tofile="${module.file}"/>
<checksum fileext=".md5" file="${module.file}"/>
<antcall target="module.asc"/>
+ <copy file="${basedir}/target/project.module.link"
+
tofile="${basedir}/target/deliverables/modules/dpml-transit.module.link"/>
</target>

<target name="module.asc" if="gpg.declared">

Added: development/main/transit/core/etc/project.module.link
==============================================================================
--- (empty file)
+++ development/main/transit/core/etc/project.module.link Tue Jun 28
13:26:08 2005
@@ -0,0 +1 @@
+artifact:module:dpml/transit/dpml-transit-@PROJECT-VERSION@
\ No newline at end of file

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/SecuredTransitContext.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/SecuredTransitContext.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/SecuredTransitContext.java
Tue Jun 28 13:26:08 2005
@@ -34,6 +34,7 @@
import java.util.Properties;

import net.dpml.transit.adapter.LoggingAdapter;
+import net.dpml.transit.link.ArtifactLinkManager;
import net.dpml.transit.link.FileLinkManager;
import net.dpml.transit.link.LinkManager;
import net.dpml.transit.model.Logger;
@@ -310,7 +311,8 @@
*/
protected void initialize() throws IOException
{
- m_linkManager = new FileLinkManager();
+ //m_linkManager = new FileLinkManager();
+ m_linkManager = new ArtifactLinkManager();
m_repository = new StandardLoader();
initializeCache();
initializeRegistry();

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/Transit.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/Transit.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/Transit.java
Tue Jun 28 13:26:08 2005
@@ -292,6 +292,16 @@
}

/**
+ * Return the Transit repository service.
+ * @return the repository service
+ * @exception IllegalStateException if Transit has not been initialized
+ */
+ public Repository getRepository()
+ {
+ return getTransitContext().getRepository();
+ }
+
+ /**
* Returns a reference to the repository monitor router. Client
application
* may use the router to add, remove or replace existing monitors.
* @return the repository monitor router
@@ -321,16 +331,6 @@
return m_networkMonitor;
}

- /**
- * Return the Transit repository service.
- * @return the repository service
- * @exception IllegalStateException if Transit has not been initialized
- */
- public Repository getRepository()
- {
- return getTransitContext().getRepository();
- }
-
/** Returns the LogWriter for the Transit system.
* This writer should only be used to report information that
* should not be output to the user in the course of normal

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/artifact/Artifact.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/artifact/Artifact.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/artifact/Artifact.java
Tue Jun 28 13:26:08 2005
@@ -28,6 +28,7 @@
import java.net.URL;

import net.dpml.transit.NullArgumentException;
+import net.dpml.transit.TransitRuntimeException;

/**
* An Artifact is a utility class the handles validation of
<code>artifact</code> uri
@@ -52,8 +53,9 @@
* <p>The following represent valid artifact uri examples:</p>
*
* <ul>
- * <li>artifact:jar:dpml/transit/dpml-transit-main#1.0.0</li>
+ * <li>artifact:jar:dpml/transit/dpml-transit-main#1234</li>
* <li>artifact:jar:dpml/transit/dpml-transit-main</li>
+ * <li>link:jar:dpml/transit/dpml-transit-main#1.0</li>
* </ul>
*
* <p>
@@ -71,21 +73,19 @@
* @return the new artifact
* @exception java.net.URISyntaxException if the supplied uri is not
valid.
* @throws IllegalArgumentException if the URI does not have "artifact"
- * as its <strong>scheme</strong>.
+ * or "link" as its <strong>scheme</strong>.
*/
public static final Artifact createArtifact( String uri )
throws URISyntaxException, IllegalArgumentException
{
- if( uri == null || !uri.startsWith( "artifact:" ) )
+ if( null == uri )
{
- final String error =
- "Supplied uri [" + uri + "] does not declare the 'artifact:'
protocol";
- throw new IllegalArgumentException( error );
+ throw new NullArgumentException( "uri" );
}
int asterix = uri.indexOf( "!" );
if( asterix == -1 )
{
- return new Artifact( new URI( uri ) );
+ return createArtifact( new URI( uri ) );
}
else
{
@@ -118,16 +118,21 @@
* @param uri the artifact uri
* @return the new artifact
* @throws IllegalArgumentException if the URI does not have "artifact"
- * as its <strong>scheme</strong>.
+ * or "link" as its <strong>scheme</strong>.
*/
public static final Artifact createArtifact( URI uri )
throws IllegalArgumentException
{
- if( !"artifact".equals( uri.getScheme() ) )
+ if( null == uri )
{
- final String error =
- "Supplied uri [" + uri + "] does not declare the 'artifact:'
protocol";
- throw new IllegalArgumentException( error );
+ throw new NullArgumentException( "uri" );
+ }
+ String scheme = uri.getScheme();
+ if( !scheme.equals( "artifact" ) && !scheme.equals( "link" ) )
+ {
+ final String error =
+ "URI contains a scheme that is not recognized: " + uri;
+ throw new UnsupportedSchemeException( error );
}
return new Artifact( uri );
}
@@ -163,10 +168,11 @@
{
URI uri = new URI( composite );
return new Artifact( uri );
- } catch( URISyntaxException e )
+ }
+ catch( URISyntaxException e )
{
// Can not happen.
- throw new InternalError( "An internal error has occurred. The
following URI could not be constructed: " + composite );
+ throw new TransitRuntimeException( "An internal error has
occurred. The following URI could not be constructed: " + composite );
}
}

@@ -290,6 +296,16 @@
//
------------------------------------------------------------------------

/**
+ * Return the protocol for the artifact.
+ *
+ * @return the protocol scheme
+ */
+ public final String getScheme()
+ {
+ return m_uri.getScheme();
+ }
+
+ /**
* Return the group identifier for the artifact. The group identifier
* is composed of a sequence of named separated by the '/' character.
*
@@ -349,14 +365,30 @@
*/
public URL toURL()
{
- try
+ String scheme = getScheme();
+ if( "artifact".equals( scheme ) )
{
- return toURL( new Handler() );
+ try
+ {
+ return toURL( new Handler() );
+ }
+ catch( Exception e )
+ {
+ final String error =
+ "Unexpected error while attempting to construct artifact
url."
+ + "\nURI: " + m_uri;
+ throw new TransitRuntimeException( error, e );
+ }
}
- catch( Throwable e )
+ else if( "link".equals( scheme ) )
{
- // Can not happen!
- throw new InternalError( "An Artifact URI could not be converted
to a URL: " + m_uri );
+ return toURL( new net.dpml.transit.link.Handler() );
+ }
+ else
+ {
+ final String error =
+ "URI scheme not recognized: " + m_uri;
+ throw new UnsupportedSchemeException( error );
}
}

@@ -369,12 +401,12 @@
{
try
{
- return new URL( null, m_uri.toString(), handler );
+ return new URL( null, m_uri.toASCIIString(), handler );
}
catch( MalformedURLException e )
{
// Can not happen!
- throw new InternalError( "An Artifact URI could not be converted
to a URL: " + m_uri );
+ throw new TransitRuntimeException( "An Artifact URI could not be
converted to a URL: " + m_uri );
}
}


Added:
development/main/transit/core/handler/src/main/net/dpml/transit/artifact/UnsupportedSchemeException.java
==============================================================================
--- (empty file)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/artifact/UnsupportedSchemeException.java
Tue Jun 28 13:26:08 2005
@@ -0,0 +1,43 @@
+/*
+ * 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.artifact;
+
+/**
+ * Exception to indicate that the scheme of a supplied uri is not recognized
+ * by Transit.
+ *
+ * @author <a href="http://www.dpml.net";>The Digital Product Meta Library</a>
+ */
+public class UnsupportedSchemeException extends IllegalArgumentException
+{
+ //
------------------------------------------------------------------------
+ // constructor
+ //
------------------------------------------------------------------------
+
+ /**
+ * Construct a new <code>UnsupportedSchemeException</code> instance.
+ *
+ * @param message The detail message for this exception.
+ */
+ public UnsupportedSchemeException( String message )
+ {
+ super( message );
+ }
+}
+

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/link/ArtifactLinkManager.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/link/ArtifactLinkManager.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/link/ArtifactLinkManager.java
Tue Jun 28 13:26:08 2005
@@ -1,5 +1,7 @@
/*
* Copyright 2005 Niclas Hedhman
+ * 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
@@ -30,16 +32,20 @@
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;

-/** The LinkManager is responsible for storing the mapping between a Link
- * instance and a URI.
+import net.dpml.transit.NullArgumentException;
+import net.dpml.transit.artifact.ArtifactNotFoundException;
+
+/**
+ * The LinkManager is responsible for storing the mapping between a Link
+ * instance and a URI.
* <p>
* Applications should never call the methods for the LinkManager directly,
* and it is likely that the LinkManager remains outside the reachability of
* applications.
* </p>
* <p>
- * This LinkManager stores all the link: to URI mappings in artifact:link:
- * cache objects.
+ * This LinkManager stores all the link: to URI mappings as artifacts with
+ * the file extension postfix ".link".
* </p>
*/
public class ArtifactLinkManager
@@ -61,29 +67,48 @@
public void setTargetURI( final URI linkUri, final URI targetUri )
throws IOException
{
- try
+ if( null == linkUri )
{
- AccessController.doPrivileged( new PrivilegedExceptionAction()
- {
+ throw new NullArgumentException( "linkUri" );
+ }

+ try
+ {
+ AccessController.doPrivileged(
+ new PrivilegedExceptionAction()
+ {
public Object run()
throws IOException
{
- String artifact = "artifact:" + linkUri.toString();
- URL store = new URL( artifact );
+ String artifact = linkUri.toASCIIString();
+ URL store = new URL( null, artifact, new
net.dpml.transit.artifact.Handler() );
OutputStream out =
store.openConnection().getOutputStream();
- byte[] array = targetUri.toString().getBytes(
"ISO8859-1" );
+ byte[] array = getByteArray( targetUri );
ByteArrayInputStream in = new ByteArrayInputStream(
array );
StreamUtils.copyStream( in, out, true );
return null; // nothing to return
}
- });
- } catch( PrivilegedActionException e )
+ }
+ );
+ }
+ catch( PrivilegedActionException e )
{
throw (IOException) e.getException();
}
}

+ private byte[] getByteArray( URI uri ) throws IOException
+ {
+ if( null != uri )
+ {
+ return uri.toString().getBytes( "ISO8859-1" );
+ }
+ else
+ {
+ return new byte[0];
+ }
+ }
+
/** Returns the URI that the provided link: URI instance is pointing to.
* @exception IOException if the mapping could not be retrieved, due to
* a IOException.
@@ -95,25 +120,36 @@
{
try
{
- URI result = (URI) AccessController.doPrivileged( new
PrivilegedExceptionAction()
- {
-
+ URI result = (URI) AccessController.doPrivileged(
+ new PrivilegedExceptionAction()
+ {
public Object run()
throws IOException
{
- String artifact = "artifact:" + linkUri.toString();
- URL store = new URL( artifact );
+ String artifact = linkUri.toASCIIString();
+ URL store = new URL( null, artifact, new
net.dpml.transit.artifact.Handler() );
ByteArrayOutputStream out = new ByteArrayOutputStream();
InputStream in = store.openConnection().getInputStream();
StreamUtils.copyStream( in, out, true );
String target = out.toString( "ISO8859-1" );
- return URI.create( target );
+ URI value = URI.create( target );
+ return value ;
}
- });
+ }
+ );
return result;
- } catch( PrivilegedActionException e )
+ }
+ catch( PrivilegedActionException e )
{
- throw (IOException) e.getException();
+ Exception exception = e.getException();
+ if( exception instanceof ArtifactNotFoundException )
+ {
+ return null;
+ }
+ else
+ {
+ throw (IOException) exception;
+ }
}
}
}

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/link/Link.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/link/Link.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/link/Link.java
Tue Jun 28 13:26:08 2005
@@ -1,5 +1,7 @@
/*
* Copyright 2005 Niclas Hedhman
+ * Copyright 2005 Stephen 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
@@ -21,37 +23,53 @@

import java.net.URI;

-/** The Link class represents the content of the link: URL and not the
content
+import net.dpml.transit.NullArgumentException;
+
+/**
+ * The Link class represents the content of the link: URL and not the
content
* of the target that the link: points to.
* It is not intended that the applications instantiates this class
directly,
* but obtains it as a object from the <code>URL.getContent()</code> method.
* Example;
* <pre><code>
- * URL url = new URL( "link:some/opague/pointer" );
+ * URL url = new URL( "link:blob:some/opague/pointer" );
* Class[] type = new Class[] { Link.class };
*
* // Get the Link object from the URL
* Link link = (Link) url.getContent( type );
*
* // Get the URI that this link is pointing to at the moment
- * URI uri = link.getURI();
+ * URI uri = link.getTargetURI();
*
* // Change the link to point somewhere else.
* URI newUri = new URI( "artifact:jar:abc/def/hoopla#3.1.2" );
- * link.setURI( newUri );
+ * link.setTargetURI( newUri );
* </code></pre>
*/
public class Link
{
- private LinkManager m_manager;
- private URI m_uri;
+ private final LinkManager m_manager;
+ private final URI m_uri;

- /** Constructor for the Link.
- */
- public Link( URI linkURI, LinkManager manager )
+ /**
+ * Constructor for the Link.
+ * @param uri the link physical uri
+ * @param manager the link manager
+ * @exception NullArgumentException if the link uri or manager is null
+ */
+ public Link( URI uri, LinkManager manager )
{
+ if( null == manager )
+ {
+ throw new NullArgumentException( "manager" );
+ }
+ if( null == uri )
+ {
+ throw new NullArgumentException( "uri" );
+ }
+
m_manager = manager;
- m_uri = linkURI;
+ m_uri = uri;
}

public URI getLinkURI()
@@ -59,21 +77,26 @@
return m_uri;
}

- /** Return the URI that is currently bound to the Link.
- * @return the current URI the link: is pointing to.
- */
+ /**
+ * Return the URI that is currently bound to the Link.
+ * @param defaultUri the default value
+ * @return the current URI the link: is pointing to.
+ */
public URI getTargetURI( URI defaultUri )
throws IOException
{
URI uri = m_manager.getTargetURI( m_uri );
if( uri == null )
+ {
return defaultUri;
+ }
return uri;
}

- /** Sets (and permanently remembers) the Link to point to a new URI.
- * @param uri the URI that this link: should be pointing to.
- */
+ /**
+ * Sets (and permanently remembers) the Link to point to a new URI.
+ * @param uri the URI that this link: should be pointing to.
+ */
public void setTargetURI( URI uri )
throws IOException
{

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/link/LinkURLConnection.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/link/LinkURLConnection.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/link/LinkURLConnection.java
Tue Jun 28 13:26:08 2005
@@ -1,5 +1,7 @@
/*
* Copyright 2005 Niclas Hedhman
+ * 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
@@ -31,6 +33,8 @@

import net.dpml.transit.Transit;
import net.dpml.transit.SecuredTransitContext;
+import net.dpml.transit.artifact.Artifact;
+import net.dpml.transit.artifact.UnsupportedSchemeException;
import net.dpml.transit.util.MimeTypeHandler;

/**
@@ -38,8 +42,6 @@
*/
public class LinkURLConnection extends URLConnection
{
- private LinkManager m_linkManager;
-
private boolean m_connected;
private URL m_targetURL;

@@ -65,32 +67,46 @@
throws IOException
{
if( m_connected )
+ {
return;
+ }
+
m_connected = true;

- m_linkManager = Transit.getInstance().getLinkManager();
-
try
{
AccessController.doPrivileged( new PrivilegedExceptionAction()
{
-
public Object run()
throws IOException
{
URI linkUri = URI.create( url.toExternalForm() );
- URI targetUri = m_linkManager.getTargetURI( linkUri );
+ LinkManager manager =
Transit.getInstance().getLinkManager();
+ URI targetUri = manager.getTargetURI( linkUri );
if( targetUri != null )
- m_targetURL = new URL( targetUri.toString() );
+ {
+ try
+ {
+ Artifact artifact = Artifact.createArtifact(
targetUri );
+ m_targetURL = artifact.toURL();
+ }
+ catch( UnsupportedSchemeException use )
+ {
+ m_targetURL = new URL( targetUri.toASCIIString()
);
+ }
+ }
else
+ {
m_targetURL = null;
+ }
return null; // nothing to return
}
});
- } catch( PrivilegedActionException e )
+ }
+ catch( PrivilegedActionException e )
{
throw (IOException) e.getException();
- }
+ }
}

/**
@@ -103,10 +119,15 @@
{
connect();
if( m_targetURL == null )
+ {
return null;
- URLConnection conn = m_targetURL.openConnection();
- InputStream in = conn.getInputStream();
- return in;
+ }
+ else
+ {
+ URLConnection conn = m_targetURL.openConnection();
+ InputStream in = conn.getInputStream();
+ return in;
+ }
}

/**
@@ -119,10 +140,15 @@
{
connect();
if( m_targetURL == null )
+ {
return null;
- URLConnection conn = m_targetURL.openConnection();
- OutputStream out = conn.getOutputStream();
- return out;
+ }
+ else
+ {
+ URLConnection conn = m_targetURL.openConnection();
+ OutputStream out = conn.getOutputStream();
+ return out;
+ }
}

/**
@@ -144,25 +170,11 @@
public Object getContent( final Class[] classes )
throws IOException
{
- try
- {
- Object content = super.getContent( classes );
- if( content != null )
- {
- return content;
- }
- }
- catch( UnknownServiceException use )
- {
- // Ignore
- }
+ final LinkManager manager = Transit.getInstance().getLinkManager();

- //
- // attempt to resolve this locally
- //
-
- Object result = AccessController.doPrivileged( new PrivilegedAction()
- {
+ Object result = AccessController.doPrivileged(
+ new PrivilegedAction()
+ {
public Object run()
{
for( int i=0; i < classes.length; i++ )
@@ -172,7 +184,7 @@
{
String extUri = getURL().toString();
URI uri = URI.create( extUri );
- Link link = new Link( uri, m_linkManager );
+ Link link = new Link( uri, manager );
return link;
}
if( c.equals( URI.class ) )
@@ -184,7 +196,24 @@
}
return null;
}
- });
- return result;
+ }
+ );
+
+ if( null != result )
+ {
+ return result;
+ }
+ else
+ {
+ connect();
+ if( null != m_targetURL )
+ {
+ return m_targetURL.getContent( classes );
+ }
+ else
+ {
+ return super.getContent( classes );
+ }
+ }
}
}

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/model/TransitRegistryEvent.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/model/TransitRegistryEvent.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/model/TransitRegistryEvent.java
Tue Jun 28 13:26:08 2005
@@ -33,7 +33,7 @@
* or removal of a transit model.
*
* @param registry the Transit model registry
- * @param resolver the layout resolver model that was added or removed
+ * @param model the model that was added or removed
*/
public TransitRegistryEvent( TransitRegistryModel registry, TransitModel
model )
{
@@ -43,7 +43,7 @@

/**
* Return the model initiating the event.
- * @return the layout model
+ * @return the transit registry model
*/
public TransitRegistryModel getTransitRegistryModel()
{
@@ -52,7 +52,7 @@

/**
* Return the resolver model that was added or removed.
- * @return the resolver model
+ * @return the transit model
*/
public TransitModel getTransitModel()
{

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/runtime/ClassicLayout.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/runtime/ClassicLayout.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/runtime/ClassicLayout.java
Tue Jun 28 13:26:08 2005
@@ -1,5 +1,5 @@
/*
- * 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");
@@ -20,6 +20,7 @@
package net.dpml.transit.runtime;

import net.dpml.transit.artifact.Artifact;
+import net.dpml.transit.TransitRuntimeException;

/** The ClassicLayout decodes artifacts into the Classic/Maven layout
* of artifacts on a file system or http server.
@@ -44,7 +45,7 @@
*/
public final String resolveBase( Artifact artifact )
{
- return artifact.getGroup() + "/" + artifact.getType() + "s";
+ return artifact.getGroup() + "/" + artifact.getType() + "s";
}

/**
@@ -72,6 +73,26 @@
*/
public String resolveFilename( Artifact artifact )
{
+ String scheme = artifact.getScheme();
+ String filename = resolveBaseFilename( artifact );
+ if( "artifact".equals( scheme ) )
+ {
+ return filename;
+ }
+ else if( "link".equals( scheme ) )
+ {
+ return filename + ".link";
+ }
+ else
+ {
+ final String error =
+ "Protocol not recognized: " + scheme;
+ throw new TransitRuntimeException( error );
+ }
+ }
+
+ public String resolveBaseFilename( Artifact artifact )
+ {
String ver = artifact.getVersion();
if( null == ver )
{
@@ -82,5 +103,4 @@
return artifact.getName() + "-" + ver + "." + artifact.getType();
}
}
-
}

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/runtime/DefaultCacheHandler.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/runtime/DefaultCacheHandler.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/runtime/DefaultCacheHandler.java
Tue Jun 28 13:26:08 2005
@@ -449,13 +449,14 @@
/** Creates an output stream to where the artifact content can be written
* to.
* <p>
- * If the artifact already exists, a
<code>ArtifactAlreadyExistsException</code>
+ * If the artifact already exists and the artifact is not a link a
+ * <code>ArtifactAlreadyExistsException</code>
* will be thrown. If the directory doesn't exists, it will be created.
* </p>
* @exception IOException if an IO error occurs.
* @exception NullArgumentException if the artifact argument is null.
* @exception ArtifactAlreadyExistsException if the artifact already
exists
- * in the cache.
+ * in the cache and the artifact is not a link.
*/
public OutputStream createOutputStream( Artifact artifact )
throws NullArgumentException, ArtifactAlreadyExistsException,
IOException
@@ -465,15 +466,23 @@
throw new NullArgumentException( "artifact" );
}
ResourceHost any = findAnyPresence( artifact );
- if( any != null )
+ String scheme = artifact.getScheme();
+ boolean flag = !"link".equals( scheme );
+ if( ( any != null ) && flag )
+ {
throw new ArtifactAlreadyExistsException( "Artifact found on
server.", artifact );
+ }
String path = m_resolver.resolvePath( artifact );
File destination = new File( m_cacheDir, path );
- if( destination.exists() )
+ if( destination.exists() && flag )
+ {
throw new ArtifactAlreadyExistsException( "Artifact found in
cache.", artifact );
+ }
File parentDir = destination.getParentFile();
if( !parentDir.exists() )
+ {
parentDir.mkdirs();
+ }
return new FileOutputStream( destination );
}


Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/runtime/EclipseLayout.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/runtime/EclipseLayout.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/runtime/EclipseLayout.java
Tue Jun 28 13:26:08 2005
@@ -1,5 +1,5 @@
/*
- * 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");
@@ -20,6 +20,7 @@
package net.dpml.transit.runtime;

import net.dpml.transit.artifact.Artifact;
+import net.dpml.transit.TransitRuntimeException;

/** The EclipseLayout decodes artifacts into the Eclipse specified layout
* of artifacts on a file system or http server.
@@ -66,6 +67,7 @@
return resolveBase( artifact ) + "/" + resolveFilename( artifact );
}

+
/**
* Return the expanded filename of the artifact.
* The filename is expressed as <code>[name].[type]</code>.
@@ -74,7 +76,32 @@
*/
public String resolveFilename( Artifact artifact )
{
- return artifact.getName() + "." + artifact.getType();
+ String scheme = artifact.getScheme();
+ String filename = resolveBaseFilename( artifact );
+ if( "artifact".equals( scheme ) )
+ {
+ return filename;
+ }
+ else if( "link".equals( scheme ) )
+ {
+ return filename + ".link";
+ }
+ else
+ {
+ final String error =
+ "Protocol not recognized: " + scheme;
+ throw new TransitRuntimeException( error );
+ }
}

+ /**
+ * Return the expanded filename of the artifact.
+ * The filename is expressed as <code>[name].[type]</code>.
+ *
+ * @return the artifact expanded filename
+ */
+ public String resolveBaseFilename( Artifact artifact )
+ {
+ return artifact.getName() + "." + artifact.getType();
+ }
}

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
Tue Jun 28 13:26:08 2005
@@ -74,7 +74,7 @@
public void testDefaultValue()
throws Exception
{
- URL url = new URL( "link:transit/test/aaa/bbb" );
+ URL url = new URL( "link:blob:transit/test/aaa/bbb" );
Class[] args = new Class[] { Link.class };
Link link = (Link) url.getContent( args );
URI defUri = URI.create( "artifact:bla:abc/def#142" );
@@ -85,7 +85,7 @@
public void testContentUri()
throws Exception
{
- URI orig = URI.create( "link:transit/test/aaa/bbb" );
+ URI orig = URI.create( "link:blob:transit/test/aaa/bbb" );
URL url = orig.toURL();
Class[] args = new Class[] { URI.class };
URI found = (URI) url.getContent( args );
@@ -95,13 +95,13 @@
public void testSetValue()
throws Exception
{
- URL url = new URL( "link:transit/test/aaa/ccc" );
+ URL url = new URL( "link:blob:transit/test/aaa/ccc" );
Class[] args = new Class[] { Link.class };
Link link = (Link) url.getContent( args );
URI newUri = URI.create( "artifact:testfile:dpml/test/abc#1.0.1" );
link.setTargetURI( newUri );

- url = new URL( "link:transit/test/aaa/ccc" );
+ url = new URL( "link:blob:transit/test/aaa/ccc" );
link = (Link) url.getContent( args );
URI defUri = URI.create( "artifact:bla:ccc/ddd#222" );
URI uri = link.getTargetURI( defUri );
@@ -109,16 +109,28 @@
assertEquals( "setting", newUri, uri );
}

+ public void testResetValue()
+ throws Exception
+ {
+ URL url = new URL( "link:blob:transit/test/example" );
+ Class[] args = new Class[] { Link.class };
+ Link link = (Link) url.getContent( args );
+ URI newUri = URI.create( "artifact:testfile:dpml/test/abc#1.0" );
+ link.setTargetURI( newUri );
+ URI newerUri = URI.create( "artifact:testfile:dpml/test/abc#2.0" );
+ link.setTargetURI( newerUri );
+ }
+
public void testGetValue()
throws Exception
{
- URL url = new URL( "link:transit/test/aaa/ccc" );
+ URL url = new URL( "link:blob:transit/test/aaa/xxx" );
Class[] args = new Class[] { Link.class };
Link link = (Link) url.getContent( args );
URI newUri = URI.create( "artifact:testfile:dpml/test/abc#1.0.1" );
link.setTargetURI( newUri );

- url = new URL( "link:transit/test/aaa/ccc" );
+ url = new URL( "link:blob:transit/test/aaa/xxx" );
URL original = newUri.toURL();
InputStream in1 = url.openConnection().getInputStream();
InputStream in2 = original.openConnection().getInputStream();
@@ -128,21 +140,19 @@
public void testIllegalArtifact()
throws Exception
{
- URL url = new URL( "link:transit/test/errors/aaa" );
+ URL url = new URL( "link:blob:transit/test/errors/aaa" );
Class[] args = new Class[] { Link.class };
- URI newUri = URI.create( "artifact:abc:aaa/bbb/def" );
-
- url = new URL( "link:transit/test/errors/aaa" );
+ URI newUri = URI.create( "artifact:abc:does/not/exist" );
try
{
Link link = (Link) url.getContent( args );
link.setTargetURI( newUri );
-
- link = (Link) url.getContent( args );
- fail( "No ArtifactNotFoundException" );
- } catch( ArtifactNotFoundException e )
+ url.getContent();
+ fail( "ArtifactNotFoundException was not thrown." );
+ }
+ catch( ArtifactNotFoundException e )
{
- // should throw an exception if we try to read a against a
+ // should throw an exception if we try to read against a
// non existent artifact.
}
}

Modified:
development/main/transit/core/tools/src/main/net/dpml/transit/antlib.xml
==============================================================================
--- development/main/transit/core/tools/src/main/net/dpml/transit/antlib.xml
(original)
+++ development/main/transit/core/tools/src/main/net/dpml/transit/antlib.xml
Tue Jun 28 13:26:08 2005
@@ -1,6 +1,7 @@
<?xml version="1.0"?>
<antlib xmlns:current="ant:current">
<taskdef name="init" classname="net.dpml.transit.tools.MainTask"/>
+ <taskdef name="link" classname="net.dpml.transit.tools.LinkTask"/>
<taskdef name="plugin" classname="net.dpml.transit.tools.PluginTask"/>
<taskdef name="import"
classname="net.dpml.transit.tools.ImportArtifactTask"/>
<taskdef name="get" classname="net.dpml.transit.tools.GetTask"/>

Added:
development/main/transit/core/tools/src/main/net/dpml/transit/tools/LinkTask.java
==============================================================================
--- (empty file)
+++
development/main/transit/core/tools/src/main/net/dpml/transit/tools/LinkTask.java
Tue Jun 28 13:26:08 2005
@@ -0,0 +1,89 @@
+/*
+ * 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.transit.tools;
+
+import java.net.URI;
+import java.net.URL;
+
+import org.apache.tools.ant.BuildException;
+
+import net.dpml.transit.artifact.Artifact;
+import net.dpml.transit.link.Link;
+
+/**
+ * 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 class LinkTask extends TransitTask
+{
+ private URI m_uri;
+ private URI m_target;
+
+ public void init()
+ {
+ setTaskName( "link" );
+ }
+
+ public void setURI( URI uri )
+ {
+ m_uri = uri;
+ }
+
+ public void setTarget( URI uri )
+ {
+ m_target = uri;
+ }
+
+ public void execute() throws BuildException
+ {
+ if( null == m_uri )
+ {
+ final String error =
+ "Required 'uri' attribute is missing.";
+ throw new BuildException( error );
+ }
+ if( null == m_target )
+ {
+ final String error =
+ "Required 'target' attribute is missing.";
+ throw new BuildException( error );
+ }
+ try
+ {
+ Artifact main = Artifact.createArtifact( m_uri );
+ Artifact target = Artifact.createArtifact( m_target );
+ URL url = main.toURL();
+ Class[] args = new Class[] { Link.class };
+ Link link = (Link) url.getContent( args );
+ link.setTargetURI( m_target );
+ log( "created link: " + main + " with target: " + target );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Link creation failure."
+ + "\nLink URI: " + m_uri
+ + "\nTarget URI: " + m_target;
+ throw new BuildException( error, e );
+ }
+ }
+}
+



  • svn commit: r2932 - in development/main: . depot depot/console magic magic/core/src/main/net/dpml/magic metro transit/core transit/core/etc transit/core/handler/src/main/net/dpml/transit transit/core/handler/src/main/net/dpml/transit/artifact transit/core/handler/src/main/net/dpml/transit/link transit/core/handler/src/main/net/dpml/transit/model transit/core/handler/src/main/net/dpml/transit/runtime transit/core/handler/src/test/net/dpml/transit/test transit/core/tools/src/main/net/dpml/transit transit/core/tools/src/main/net/dpml/transit/tools, mcconnell, 06/28/2005

Archive powered by MHonArc 2.6.24.

Top of Page