Slightly updated diff that corrects reference to plugin uri.
SJM
> -----Original Message-----
> From: Stephen McConnell [mailto:[EMAIL PROTECTED]
> Sent: 17 September 2004 06:23
> To: Avalon Developers List
> Subject: [patch] magic update
>
>
> The attached diff corrects a bug in the PluginTask that was resulting
in
> a IndexOutOfBoundsException when dealing with artifacts without a
> version. In addition I've added a name setter to the task to make the
> process of handling plugs that wrap a single class easier to use.
>
> For example, you can now do something like:
>
> <x:plugin name="checkstyle"
> uri="plugin:avalon/tools/magic-checkstyle-plugin"/>
> <checkstyle config="whatever.xml">
> ...
> </checkstyle>
>
> I've also updated the standard.xml template to reference checkstyle
> using the above model so that we do not force checkstyle dependencies
on
> core magic. There is a separate checkstyle plugin directory which
I'll
> zip and send though to Niclas.
>
> Steve.
Index: magic/src/main/org/apache/avalon/tools/tasks/PluginTask.java
===================================================================
--- magic/src/main/org/apache/avalon/tools/tasks/PluginTask.java (revision
46227)
+++ magic/src/main/org/apache/avalon/tools/tasks/PluginTask.java (working copy)
@@ -46,9 +46,15 @@
public class PluginTask extends SystemTask
{
private String m_id;
+ private String m_name;
- public void setArtifact( final String id )
+ public void setName( final String name )
{
+ m_name = name;
+ }
+
+ public void setUri( final String id )
+ {
m_id = id;
}
@@ -89,7 +95,8 @@
final AntClassLoader classloader = project.createClassLoader(
data.getPath() );
final String spec = data.getInfo().getSpec();
- final String uri = "plugin:" + spec.substring( 0, spec.indexOf( "#" ) );
+ final String uri = getURI( spec );
+
log( "Install \"" + uri + "\"" );
//
@@ -99,14 +106,24 @@
final ComponentHelper helper =
ComponentHelper.getComponentHelper( project );
final TaskDef[] defs = data.getTaskDefs();
- for( int i=0; i<defs.length; i++ )
+ if(( defs.length == 1 ) && ( null != m_name ))
{
- final TaskDef def = defs[i];
+ final TaskDef def = defs[0];
final Class taskClass = classloader.loadClass( def.getClassname() );
- final String name = uri + ":" + def.getName();
- helper.addTaskDefinition( name, taskClass );
- log( "Task \"" + name + "\"" );
+ helper.addTaskDefinition( m_name, taskClass );
+ log( "Task \"" + m_name + "\"" );
}
+ else
+ {
+ for( int i=0; i<defs.length; i++ )
+ {
+ final TaskDef def = defs[i];
+ final Class taskClass = classloader.loadClass( def.getClassname()
);
+ final String name = uri + ":" + def.getName();
+ helper.addTaskDefinition( name, taskClass );
+ log( "Task \"" + name + "\"" );
+ }
+ }
//
// register plugins that declare themselves as build listeners
@@ -127,6 +144,18 @@
}
}
+ private String getURI( String spec )
+ {
+ if( spec.indexOf( "#" ) > -1 )
+ {
+ return "plugin:" + spec.substring( 0, spec.indexOf( "#" ) );
+ }
+ else
+ {
+ return "plugin:" + spec;
+ }
+ }
+
/**
* Create a build listerer using a supplied class. The implementation
* checks the first available constructor arguments and builds a set of
Index: magic/src/main/org/apache/avalon/tools/tasks/InitializeTask.java
===================================================================
--- magic/src/main/org/apache/avalon/tools/tasks/InitializeTask.java (revision
46227)
+++ magic/src/main/org/apache/avalon/tools/tasks/InitializeTask.java (working copy)
@@ -69,7 +69,7 @@
final PluginTask task = new PluginTask();
task.setTaskName( "plugin" );
task.setProject( project );
- task.setArtifact( path );
+ task.setUri( path );
task.init();
task.execute();
}
Index: magic/etc/deliverables/templates/standard.xml
===================================================================
--- magic/etc/deliverables/templates/standard.xml (revision 46227)
+++ magic/etc/deliverables/templates/standard.xml (working copy)
@@ -30,25 +30,6 @@
<x:clean/>
</target>
- <target name="checkstyle" depends="info" unless="project.checkstyle.disable" >
- <taskdef resource="checkstyletask.properties" >
- <classpath>
- <x:path key="checkstyle" resolve="true" />
- </classpath>
- </taskdef>
-
- <mkdir dir="target/checkstyle-errors/"/>
- <mkdir dir="target/checkstyle-reports/"/>
- <checkstyle config="${magic.templates}/checkstyle/metro-checkstyle.xml">
- <fileset dir="${project.src}/${project.src.main}" includes="**/*.java"/>
- <formatter type="xml" toFile="target/checkstyle/checkstyle_errors.xml"/>
- </checkstyle>
- <style in="target/checkstyle-errors/checkstyle_errors.xml"
- out="target/checkstyle-reports/checkstyle_report.html"
- style="${magic.templates}/checkstyle/checkstyle-frames.xsl"
- />
- </target>
-
<target name="prepare" depends="init">
<x:prepare/>
</target>
@@ -81,5 +62,18 @@
<target name="dist" depends="checkstyle,install,site"/>
+ <target name="checkstyle" depends="info" unless="project.checkstyle.disable" >
+ <x:plugin name="checkstyle" uri="plugin:avalon/tools/magic-checkstyle-plugin"/>
+ <mkdir dir="target/checkstyle/"/>
+ <mkdir dir="target/reports/checkstyle"/>
+ <checkstyle config="${magic.templates}/checkstyle/metro-checkstyle.xml">
+ <fileset dir="${project.src}/${project.src.main}" includes="**/*.java"/>
+ <formatter type="xml" toFile="target/checkstyle/checkstyle_errors.xml"/>
+ </checkstyle>
+ <style in="target/checkstyle/checkstyle_errors.xml"
+ out="target/reports/checkstyle/checkstyle_report.html"
+ style="${magic.templates}/checkstyle/checkstyle-frames.xsl"/>
+ </target>
+
</project>
Index: index.xml
===================================================================
--- index.xml (revision 46227)
+++ index.xml (working copy)
@@ -117,6 +117,18 @@
</info>
</resource>
+ <resource>
+ <info>
+ <group>junit</group>
+ <name>junit</name>
+ <version>3.8.1</version>
+ <type>jar</type>
+ </info>
+ <gump>
+ <classpath/>
+ </gump>
+ </resource>
+
<!--
Avalon Tools.
-->
@@ -132,7 +144,6 @@
<include key="junit"/>
<include key="ant-junit"/>
<include key="ant-nodeps"/>
- <include key="checkstyle"/>
</dependencies>
</project>
@@ -147,17 +158,19 @@
</dependencies>
</project>
- <resource>
+ <plugin basedir="spells/checkstyle">
<info>
- <group>junit</group>
- <name>junit</name>
- <version>3.8.1</version>
- <type>jar</type>
+ <group>avalon/tools</group>
+ <name>magic-checkstyle-plugin</name>
+ <type>plugin</type>
</info>
- <gump>
- <classpath/>
- </gump>
- </resource>
+ <dependencies>
+ <include key="checkstyle"/>
+ </dependencies>
+ <tasks>
+ <taskdef name="checkstyle"
class="com.puppycrawl.tools.checkstyle.CheckStyleTask"/>
+ </tasks>
+ </plugin>
<!--
Avalon eXternal Supplemental.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]