Author: mcconnell
Date: Tue Jun 29 03:29:49 2004
New Revision: 22266
Modified:
avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/FilterTask.java
Log:
Update the filter task to generate a nice platform specific classpath using the new magic path task.
Modified: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/FilterTask.java
==============================================================================
--- avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/FilterTask.java (original)
+++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/FilterTask.java Tue Jun 29 03:29:49 2004
@@ -17,12 +17,20 @@
package org.apache.avalon.tools.tasks;
+import java.io.File;
+
import org.apache.avalon.tools.model.Definition;
import org.apache.avalon.tools.model.Policy;
import org.apache.avalon.tools.model.Resource;
import org.apache.avalon.tools.model.ResourceRef;
+import org.apache.avalon.tools.model.MagicPath;
+
+import org.apache.tools.ant.Project;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.taskdefs.Filter;
+import org.apache.tools.ant.types.Path;
+
+
/**
* Build a set of projects taking into account dependencies within the
@@ -36,6 +44,9 @@
private String m_key;
private String m_feature;
private String m_token;
+ private String m_prefix;
+ private boolean m_windows = true;
+ private boolean m_flag = false; // os not set
public void init()
{
@@ -60,6 +71,24 @@
m_token = token;
}
+ public void setPrefix( final String prefix )
+ {
+ m_prefix = prefix;
+ }
+
+ public void setPlatform( final String os )
+ {
+ m_flag = true;
+ if( "windows".equalsIgnoreCase( os ) )
+ {
+ m_windows = true;
+ }
+ else if( "unix".equalsIgnoreCase( os ) )
+ {
+ m_windows = false;
+ }
+ }
+
public void execute() throws BuildException
{
if( null == m_key )
@@ -114,76 +143,94 @@
{
return resource.getInfo().getURI();
}
+ else if( m_feature.equals( "path" ) )
+ {
+ return convertString( resource.getInfo().getPath() );
+ }
else if( resource instanceof Definition )
{
final Definition def = (Definition) resource;
- if( m_feature.equals( "system-classpath-for-windows" ) )
- {
- return getPath( def, true );
- }
- else if( m_feature.equals( "system-classpath-for-unix" ) )
+ if( m_feature.equals( "classpath" ) )
{
- return getPath( def, false );
+ return getPath( def );
}
}
return null;
}
- private String getPath( final Definition def, final boolean windows )
+ private String getPath( final Definition def )
{
- final StringBuffer buffer = new StringBuffer();
- final ResourceRef[] refs =
- def.getResourceRefs( Policy.RUNTIME, ResourceRef.ANY, true );
- for( int i=0; i<refs.length; i++ )
+ if( null == m_prefix )
{
- if( i>0 )
- {
- buffer.append( ";" );
- }
-
- final ResourceRef ref = refs[i];
- final Resource resource = getHome().getResource( ref );
- final String path = getNativePath( windows, resource );
- buffer.append( path );
+ final String error =
+ "Filter attribute 'prefix' is not declared.";
+ throw new BuildException( error );
}
-
- if( refs.length > 0 )
+ if( !m_flag )
{
- buffer.append( ";" );
+ final String error =
+ "Filter attribute 'platform' is not declared.";
+ throw new BuildException( error );
}
- buffer.append( getNativePath( windows, def ) );
- return buffer.toString();
- }
+ File cache = getHome().getRepository().getCacheDirectory();
+ String root = cache.toString();
+ MagicPath path = new MagicPath( getProject() );
+ path.setMode( "RUNTIME" );
+ String sequence = path.toString();
+ String[] translation = Path.translatePath( getProject(), sequence );
- private String getNativePath( final boolean windows, final Resource resource )
- {
- final String symbol = getPlatformCacheSymbol( windows );
- final StringBuffer buffer = new StringBuffer( symbol );
- final String path = resource.getInfo().getPath();
- if( windows )
+ //
+ // substitute the cache directory with the prefix symbol
+ //
+
+ for( int i=0; i<translation.length; i++ )
{
- buffer.append( "\\" );
- buffer.append( path.replace( '/', '\\' ) );
+ String trans = translation[i];
+ if( trans.startsWith( root ) )
+ {
+ String relativeFilename = trans.substring( root.length() );
+ log( relativeFilename, Project.MSG_VERBOSE );
+ translation[i] = m_prefix + relativeFilename;
+ }
}
- else
+
+ //
+ // do platform convertion
+ //
+
+ StringBuffer buffer = new StringBuffer();
+ for( int i=0; i<translation.length; i++ )
{
- buffer.append( "/" );
- buffer.append( path );
+ String trans = convertString( translation[i] );
+ if( i>0 )
+ {
+ if( m_windows )
+ {
+ buffer.append( ";" );
+ }
+ else
+ {
+ buffer.append( ":" );
+ }
+ }
+ buffer.append( trans );
}
+
return buffer.toString();
}
- private String getPlatformCacheSymbol( final boolean windows )
+ private String convertString( String value )
{
- if( windows )
+ if( !m_flag ) return value;
+ if( m_windows )
{
- return "%MAGIC_SCD%";
+ return value.replace( '/', '\\' );
}
else
{
- return "$MAGIC_SCD";
- }
+ return value.replace( '\\', '/' );
+ }
}
public static class Attribute
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.