Skip to Content.
Sympa Menu

notify-dpml - r1058 - in trunk/main: depot/tools/builder/src/main/net/dpml/tools/tasks transit/core/src/main/net/dpml/transit

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: mcconnell at BerliOS <mcconnell AT mail.berlios.de>
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: r1058 - in trunk/main: depot/tools/builder/src/main/net/dpml/tools/tasks transit/core/src/main/net/dpml/transit
  • Date: Wed, 8 Feb 2006 17:11:48 +0100

Author: mcconnell
Date: 2006-02-08 17:11:46 +0100 (Wed, 08 Feb 2006)
New Revision: 1058

Modified:

trunk/main/depot/tools/builder/src/main/net/dpml/tools/tasks/PluginExportTask.java
trunk/main/transit/core/src/main/net/dpml/transit/Category.java
trunk/main/transit/core/src/main/net/dpml/transit/Plugin.java
trunk/main/transit/core/src/main/net/dpml/transit/PropertiesPlugin.java
trunk/main/transit/core/src/main/net/dpml/transit/StandardLoader.java
Log:
add support for native library loading within the plugin handler

Modified:
trunk/main/depot/tools/builder/src/main/net/dpml/tools/tasks/PluginExportTask.java
===================================================================
---
trunk/main/depot/tools/builder/src/main/net/dpml/tools/tasks/PluginExportTask.java
2006-02-08 15:02:06 UTC (rev 1057)
+++
trunk/main/depot/tools/builder/src/main/net/dpml/tools/tasks/PluginExportTask.java
2006-02-08 16:11:46 UTC (rev 1058)
@@ -121,7 +121,16 @@
*/
public static final String ARTIFACT_PRIVATE = "dpml.artifact.dependency";

+ /**
+ * The constant artifact native w32 dependencies.
+ */
+ public static final String ARTIFACT_NATIVE_W32 =
"dpml.artifact.native.w32";

+ /**
+ * The constant artifact native nix dependencies.
+ */
+ public static final String ARTIFACT_NATIVE_NIX =
"dpml.artifact.native.nix";
+
//
------------------------------------------------------------------------
// state
//
------------------------------------------------------------------------
@@ -240,6 +249,7 @@
// return;
//}
//else
+
if( !file.exists() )
{
log( "Creating plugin directive" );
@@ -330,10 +340,26 @@
final Date created = new Date( file.lastModified() );
return getSignature( created );
}
-
+
private void writeClasspath( final Writer writer )
throws Exception
{
+ Resource[] w32Resources = getResource().getClasspathProviders(
Category.W32 );
+ if( w32Resources.length > 0 )
+ {
+ final String label = "Native W32 dependencies.";
+ final String lead = ARTIFACT_NATIVE_W32;
+ writeRefs( writer, w32Resources, lead, label );
+ }
+
+ Resource[] nixResources = getResource().getClasspathProviders(
Category.NIX );
+ if( nixResources.length > 0 )
+ {
+ final String label = "Native NIX dependencies.";
+ final String lead = ARTIFACT_NATIVE_NIX;
+ writeRefs( writer, nixResources, lead, label );
+ }
+
Resource[] systemResources = getResource().getClasspathProviders(
Category.SYSTEM );
if( systemResources.length > 0 )
{
@@ -394,19 +420,53 @@
writer.write( lead );
writer.write( "." + i );
writer.write( " = " );
- try
+ if( resource.isa( "jar" ) )
{
- Artifact artifact = resource.getArtifact( "jar" );
- String uri = artifact.toURI().toString();
- writer.write( uri );
+ try
+ {
+ Artifact artifact = resource.getArtifact( "jar" );
+ String uri = artifact.toURI().toString();
+ writer.write( uri );
+ }
+ catch( Exception e )
+ {
+ final String error =
+ "Unexpected error while attempting to write resource.";
+ IOException ioe = new IOException( error );
+ ioe.initCause( e );
+ throw ioe;
+ }
}
- catch( Exception e )
+ else
{
- final String error =
- "Unexpected error while attempting to write resource.";
- IOException ioe = new IOException( error );
- ioe.initCause( e );
- throw ioe;
+ if( resource.getTypes().length == 1 )
+ {
+ String type = resource.getTypes()[0].getName();
+ try
+ {
+ Artifact artifact = resource.getArtifact( type );
+ String uri = artifact.toURI().toString();
+ writer.write( uri );
+ }
+ catch( Exception e )
+ {
+ final String error =
+ "Unexpected error while attempting to write resource."
+ + "\nResource: " + resource;
+ IOException ioe = new IOException( error );
+ ioe.initCause( e );
+ throw ioe;
+ }
+ }
+ else
+ {
+ final String error =
+ "Ambiguity in resource selection - the resource ["
+ + resource
+ + "] declares multiple types.";
+ throw new IOException( error );
+
+ }
}
}


Modified: trunk/main/transit/core/src/main/net/dpml/transit/Category.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/transit/Category.java
2006-02-08 15:02:06 UTC (rev 1057)
+++ trunk/main/transit/core/src/main/net/dpml/transit/Category.java
2006-02-08 16:11:46 UTC (rev 1058)
@@ -50,9 +50,20 @@
public static final Category PRIVATE = new Category( "private", 3 );

/**
+ * Native category.
+ */
+ public static final Category W32 = new Category( "w32", 4 );
+
+ /**
+ * Native category.
+ */
+ public static final Category NIX = new Category( "nix", 5 );
+
+ /**
* Array of scope enumeration values.
*/
- private static final Category[] ENUM_VALUES = new Category[]{SYSTEM,
PUBLIC, PROTECTED, PRIVATE};
+ private static final Category[] ENUM_VALUES =
+ new Category[]{SYSTEM, PUBLIC, PROTECTED, PRIVATE, W32, NIX};

/**
* Returns an array of activation enum values.
@@ -107,6 +118,14 @@
{
return PRIVATE;
}
+ else if( value.equalsIgnoreCase( "w32" ) )
+ {
+ return W32;
+ }
+ else if( value.equalsIgnoreCase( "nix" ) )
+ {
+ return NIX;
+ }
else
{
final String error =

Modified: trunk/main/transit/core/src/main/net/dpml/transit/Plugin.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/transit/Plugin.java
2006-02-08 15:02:06 UTC (rev 1057)
+++ trunk/main/transit/core/src/main/net/dpml/transit/Plugin.java
2006-02-08 16:11:46 UTC (rev 1058)
@@ -63,13 +63,20 @@
/**
* Return the implementation dependencies
*
- * @param key SYSTEM, PRIVATE, PROTECTED or PUBLIC constants.
+ * @param key NATIVE, SYSTEM, PRIVATE, PROTECTED or PUBLIC constants.
*
* @return the uris matching the key
*/
URI[] getDependencies( Category key );

/**
+ * Return the native dependencies
+ *
+ * @return the uris to native libraries
+ */
+ URI[] getNativeDependencies();
+
+ /**
* Return the aggregated set of dependency uris.
*
* @return the dependency artifacts

Modified:
trunk/main/transit/core/src/main/net/dpml/transit/PropertiesPlugin.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/transit/PropertiesPlugin.java
2006-02-08 15:02:06 UTC (rev 1057)
+++ trunk/main/transit/core/src/main/net/dpml/transit/PropertiesPlugin.java
2006-02-08 16:11:46 UTC (rev 1058)
@@ -73,6 +73,16 @@
static final String PP_IMP_KEY = "dpml.artifact.dependency";

/**
+ * key to designate w32 native libraries
+ */
+ static final String PP_NATIVE_W32_KEY = "dpml.artifact.native.w32";
+
+ /**
+ * key to designate nix native libraries
+ */
+ static final String PP_NATIVE_NIX_KEY = "dpml.artifact.native.nix";
+
+ /**
* key to designate the plugin classname.
*/
static final String PP_FACTORY_KEY = "dpml.plugin.class";
@@ -142,6 +152,16 @@
private final URI[] m_imp;

/**
+ * The set of uris representing the native w32 libraries.
+ */
+ private final URI[] m_w32;
+
+ /**
+ * The set of uris representing the native nix libraries.
+ */
+ private final URI[] m_nix;
+
+ /**
* Plugin group.
*/
private final String m_group;
@@ -220,6 +240,8 @@

m_uri = Artifact.createArtifact( m_group, m_name, m_version,
"plugin" ).toURI();

+ m_w32 = buildDependents( attributes, PP_NATIVE_W32_KEY );
+ m_nix = buildDependents( attributes, PP_NATIVE_NIX_KEY );
m_sys = buildDependents( attributes, PP_SYS_KEY );
m_api = buildDependents( attributes, PP_API_KEY );
m_spi = buildDependents( attributes, PP_SPI_KEY );
@@ -382,8 +404,25 @@
throw new IllegalArgumentException( error );
}
}
-
+
/**
+ * Return the native dependencies
+ *
+ * @return the uris to native libraries
+ */
+ public URI[] getNativeDependencies()
+ {
+ if( Environment.isUnix() )
+ {
+ return m_nix;
+ }
+ else
+ {
+ return m_w32;
+ }
+ }
+
+ /**
* Return all dependencies
* @return the set of URIs
*/
@@ -456,4 +495,5 @@
result.toArray( dependencies );
return dependencies;
}
+
}

Modified:
trunk/main/transit/core/src/main/net/dpml/transit/StandardLoader.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/transit/StandardLoader.java
2006-02-08 15:02:06 UTC (rev 1057)
+++ trunk/main/transit/core/src/main/net/dpml/transit/StandardLoader.java
2006-02-08 16:11:46 UTC (rev 1058)
@@ -21,6 +21,7 @@

import java.io.IOException;
import java.io.InputStream;
+import java.io.File;
import java.beans.Expression;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
@@ -602,6 +603,18 @@
{
throw new NullArgumentException( "base" );
}
+
+ // load any native libraries declared by the plugin
+
+ URI[] libraries = descriptor.getNativeDependencies();
+ for( int i=0; i<libraries.length; i++ )
+ {
+ URI library = libraries[i];
+ File source = (File) library.toURL().getContent( new
Class[]{File.class} );
+ String path = source.getAbsolutePath();
+ getMonitor().sequenceInfo( "loading: " + path );
+ System.load( path );
+ }

URI plugin = descriptor.getURI();





  • r1058 - in trunk/main: depot/tools/builder/src/main/net/dpml/tools/tasks transit/core/src/main/net/dpml/transit, mcconnell at BerliOS, 02/08/2006

Archive powered by MHonArc 2.6.24.

Top of Page