Author: niclas Date: Wed Sep 1 08:02:07 2004 New Revision: 37342 Added: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/DeliverableHelper.java Modified: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/AbstractDeliverableTask.java avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/ArtifactTask.java avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/BarTask.java avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/BlockTask.java avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/DeclareTask.java avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/JarTask.java Log: addition of support for arbitary <configuration> elements within a component defintion (BlockTask) and refactoring of the implementation to enable cleaner support for MD5 and ASC file creation. Patch submitted by Stephen McConnell.
Modified: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/AbstractDeliverableTask.java ============================================================================== --- avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/AbstractDeliverableTask.java (original) +++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/AbstractDeliverableTask.java Wed Sep 1 08:02:07 2004 @@ -1,91 +0,0 @@ -/* - * Copyright 2004 Apache Software Foundation - * 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 org.apache.avalon.tools.tasks; - -import org.apache.tools.ant.Project; -import org.apache.tools.ant.taskdefs.Checksum; -import org.apache.tools.ant.taskdefs.ExecTask; - -import org.apache.avalon.tools.model.Home; - -import java.io.File; - - -/** - * Abstract task that provides utilites supporting the generation of MD5 - * and ASC artifacts. - * - * @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a> - * @version $Revision: 1.2 $ $Date: 2004/03/17 10:30:09 $ - */ -public class AbstractDeliverableTask extends SystemTask -{ - public static final String MD5_EXT = "md5"; - public static final String ASC_EXT = "asc"; - - public void checksum( final File file ) - { - log( "Creating md5 checksum" ); - - final File md5 = new File( file.toString() + "." + MD5_EXT ); - if( md5.exists() ) - { - md5.delete(); - } - - final Checksum checksum = (Checksum) getProject().createTask( "checksum" ); - checksum.setTaskName( getTaskName() ); - checksum.setFile( file ); - checksum.setFileext( "." + MD5_EXT ); - checksum.init(); - checksum.execute(); - } - - public void asc( final File file ) - { - - final String path = Project.translatePath( file.toString() ); - final File asc = new File( file.toString() + "." + ASC_EXT ); - if( asc.exists() ) - { - asc.delete(); - } - - final String gpg = getHome().getProperty( Home.GPG_EXE_KEY ); - - if(( null != gpg ) && !"".equals( gpg ) ) - { - log( "Creating asc signature using '" + gpg + "'." ); - final ExecTask execute = (ExecTask) getProject().createTask( "exec" ); - - execute.setExecutable( gpg ); - - execute.createArg().setValue( "-a" ); - execute.createArg().setValue( "-b" ); - execute.createArg().setValue( "-o" ); - execute.createArg().setValue( path + "." + ASC_EXT ); - execute.createArg().setValue( path ); - - execute.setDir( getProject().getBaseDir() ); - execute.setSpawn( false ); - execute.setAppend( false ); - execute.setTimeout( new Integer( 1000 ) ); - execute.execute(); - } - } -} Modified: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/ArtifactTask.java ============================================================================== --- avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/ArtifactTask.java (original) +++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/ArtifactTask.java Wed Sep 1 08:02:07 2004 @@ -100,6 +100,8 @@ { closeStream( output ); } + DeliverableHelper.checksum( this, file ); + DeliverableHelper.asc( getHome(), this, file ); } catch( Throwable e ) { Modified: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/BarTask.java ============================================================================== --- avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/BarTask.java (original) +++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/BarTask.java Wed Sep 1 08:02:07 2004 @@ -32,7 +32,7 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a> * @version $Revision: 1.2 $ $Date: 2004/03/17 10:30:09 $ */ -public class BarTask extends AbstractDeliverableTask +public class BarTask extends SystemTask { public static final String BAR_EXT = "bar"; @@ -70,8 +70,8 @@ final boolean modified = bar( def, deliverables, bar ); if( modified ) { - checksum( bar ); - asc( bar ); + DeliverableHelper.checksum( this, bar ); + DeliverableHelper.asc( getHome(), this, bar ); } } } Modified: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/BlockTask.java ============================================================================== --- avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/BlockTask.java (original) +++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/BlockTask.java Wed Sep 1 08:02:07 2004 @@ -18,6 +18,8 @@ package org.apache.avalon.tools.tasks; import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.DynamicAttributeNS; +import org.apache.tools.ant.DynamicConfiguratorNS; import org.apache.avalon.tools.model.Definition; @@ -26,6 +28,10 @@ import java.io.Writer; import java.util.List; import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Hashtable; /** * Create meta-data for a block. @@ -35,25 +41,44 @@ */ public class BlockTask extends DeclareTask { + //-------------------------------------------------------------------------- + // static + //-------------------------------------------------------------------------- + private static final String BLOCK = "block"; private static final String MAIN = "main"; private static final String TEST = "test"; + /** + * An classes exposing a name attribute setter and getter. Used as a + * supertype to a number of the block meta-data classes. + */ public static class Identifiable { private String m_name; + /** + * Set the name of the identifiable to the supplied value. + * @param name the identifying name + */ public void setName( final String name ) { m_name = name; } + /** + * Return the name assigned to the identifiable. + * @return the identifying name + */ public String getName() { return m_name; } } + /** + * A class representing a nested component within a block. + */ public static class Component extends Identifiable { private String m_classname; @@ -65,36 +90,65 @@ private boolean m_activation = true; private ArrayList m_children = new ArrayList(); + /** + * Set the classname of the component. + * @param classname the component classname + */ public void setClass( final String classname ) { m_classname = classname; } + /** + * Set the component activation on startup flag. + * @param flag the component activation policy + */ public void setActivation( final boolean flag ) { m_activation = flag ; } + /** + * Declaration of the assignment of a packaged profile to the component + * directive. + * @param profile the packaged profile name to use for this component directive + */ public void setProfile( final String profile ) { m_profile = profile; } + /** + * Get the activation policy. + * @return the activation policy + */ public boolean getActivation() { return m_activation; } + /** + * Return the classname of the component type. + * @return the classname + */ public String getClassname() { return m_classname; } + /** + * Return the profile name (possibly null) + * @return the profile name + */ public String getProfile() { return m_profile; } + /** + * Add a context to this compoent. + * @return the context directive + */ public Context createContext() { if( !m_context ) @@ -112,6 +166,10 @@ } } + /** + * Add a configuration to this component. + * @return the configuration directive + */ public Configuration createConfiguration() { if( !m_configured ) @@ -129,6 +187,10 @@ } } + /** + * Add a parameters to this component. + * @return the parameters directive + */ public Parameters createParameters() { if( !m_parameters ) @@ -146,6 +208,10 @@ } } + /** + * Add a dependencies override directive to this component. + * @return the depednencies directive + */ public Dependencies createDependencies() { if( !m_dependencies ) @@ -163,75 +229,140 @@ } } + /** + * Return the set of child directives within the component. + * @return the nested directive + */ public Object[] getChildren() { return m_children.toArray(); } - - public Dependency createDependency() - { - final Dependency dep = new Dependency(); - m_children.add( dep ); - return dep; - } } + /** + * Definition of an include directive. + */ public static class Include extends Identifiable { private String m_artifact; + private List m_targets = new LinkedList(); + /** + * Set the artifact uri. + * @param the artifact uri + */ public void setArtifact( final String spec ) { m_artifact = spec; } + /** + * Return the artifact url + * @return the artifact uri value + */ public String getArtifact() { return m_artifact; } + + /** + * Create, add and return a new target directive to the include directive. + * @return a new target directive + */ + public Target createTarget() + { + final Target target = new Target(); + m_targets.add( target ); + return target; + } + + /** + * Return all of the target directives within the include directive. + * @return the set of target directives + */ + public Target[] getTargets() + { + return (Target[]) m_targets.toArray( new Target[0] ); + } } + /** + * Declaration of a service export by a container. + */ public static class Service { private String m_type; private String m_source; + /** + * Set the interface type that is to be exported. + * @param type the interface classname + */ public void setType( final String type ) { m_type = type; } + /** + * Return the interface classname assigned to the service export directive + * @return the service interface classname + */ public String getType() { return m_type; } + /** + * Set the name of the component within the container providing the + * exported service. + * @param the source component address + */ public void setSource( final String source ) { m_source = source; } + /** + * Return the name of the component within the container providing the + * exported service. + * @return the source component address + */ public String getSource() { return m_source; } } + /** + * A context directive class. + */ public static class Context { private String m_class; private List m_entries = new ArrayList(); + /** + * Declare a custom context implementation classname. + * @param classname the classname of an optional context implementation class + */ public void setClass( final String classname ) { m_class = classname ; } + /** + * Return the optional context implementation classname. + * @return the classname + */ public String getClassname() { return m_class; } + /** + * Create, add and return a new entry directive to the context. + * @return a new context entry directive + */ public Entry createEntry() { final Entry entry = new Entry(); @@ -239,53 +370,91 @@ return entry; } + /** + * Return all of the context entries within the context directive. + * @return the set of context entries + */ public Entry[] getEntries() { return (Entry[]) m_entries.toArray( new Entry[0] ); } } + /** + * Defintion of a context entry directive. + */ public static class Entry extends Param { private String m_key; + /** + * Set the context enty key that this directive qualifies. + * @param key the context entry key + */ public void setKey( final String key ) { m_key = key ; } + /** + * Return the context entry key. + * @return the entry key + */ public String getKey() { return m_key; } } + /** + * Defintion of a context entry parameter directive. + */ public static class Param { private String m_classname; private String m_value; private List m_params = new ArrayList(); + /** + * Set the context entry classname. + * @param classname the context entry classname + */ public void setClass( final String classname ) { m_classname = classname; } + /** + * Return the context entry parameter classname. + * @return the classname + */ public String getClassname() { return m_classname; } + /** + * Set the value of the context entry parameter. + * @param the param value + */ public void setValue( final String value ) { m_value = value; } + /** + * Return the value of the context entry param. + * @return the value + */ public String getValue() { return m_value; } + /** + * Create, assign anfd return a new nested entry constructor parameter. + * @return the new context entry param + */ public Param createParam() { final Param param = new Param(); @@ -293,43 +462,72 @@ return param; } + /** + * Return the set of nested param directives. + * @return the params + */ public Param[] getParams() { return (Param[]) m_params.toArray( new Param[0] ); } } + /** + * A dependency directive. + */ public static class Dependency { private String m_source; private String m_key; + /** + * Set the key that this depedency directive qualifies. + * @param key the dependency key + */ public void setKey( final String key ) { m_key = key; } + /** + * Get the dependency directive key. + */ public String getKey() { return m_key; } + /** + * Set the address of the source component to fulofill the dependency. + * @param the source component address + */ public void setSource( final String source ) { m_source = source; } + /** + * Return the address of the source component to use to fulfill this dependency. + * @return the source component address + */ public String getSource() { return m_source; } } + /** + * A dependencies directive. + */ public static class Dependencies { private List m_dependencies = new ArrayList(); + /** + * Create, assiciate and return a new dependency within this set of dependencies. + * @return the new dependnecy directive + */ public Dependency createDependency() { final Dependency dep = new Dependency(); @@ -337,31 +535,53 @@ return dep; } + /** + * Return the setr of dependency directives withi this dependencies directive. + * @return the dependency directives + */ public Dependency[] getDependencies() { return (Dependency[]) m_dependencies.toArray( new Dependency[0] ); } } + /** + * A parameter directive. + */ public static class Parameter extends Identifiable { private String m_value; + /** + * Set the value assigned to the named parameter. + * @param value the parameter value + */ public void setValue( final String value ) { m_value = value; } + /** + * Return the value assigned to the parameter. + * @return the parameter value + */ public String getValue() { return m_value; } } + /** + * A parameters directive declares a set of n parameters. + */ public static class Parameters { private List m_parameters = new ArrayList(); + /** + * Create, allocate and return a new parameter with this set of parameters. + * @return a new parameter directive + */ public Parameter createParameter() { final Parameter parameter = new Parameter(); @@ -369,33 +589,219 @@ return parameter; } + /** + * Return the set of parameter directives declarared within this parameters directives. + * @return the set of parameter directives + */ public Parameter[] getParameters() { return (Parameter[]) m_parameters.toArray( new Parameter[0] ); } } - public static class Configuration + /** + * A configuration directive. + */ + public static class Configuration implements DynamicConfiguratorNS { - private File m_file; + private String m_value; + private Map m_attributes = new Hashtable(); + private List m_children = new LinkedList(); + private String m_name; + + /** + * Creation of a root configuration directive. + */ + public Configuration() + { + this( "configuration" ); + } - public void setFile( final File file ) + /** + * Creation of a named configuration element. + * @param name the element name + */ + public Configuration( String name ) { - m_file = file; + m_name = name; } - public File getFile() + /** + * Add nested text. + * @param value the test value + */ + public void addText(String value ) + { + String s = value.trim(); + if( s.length() > 0 ) + { + m_value = s; + } + } + + /** + * Set a named attribute to the given value + * + * @param uri The namespace uri for this attribute, "" is + * used if there is no namespace uri. + * @param localName The localname of this attribute. + * @param qName The qualified name for this attribute + * @param value The value of this attribute. + * @throws BuildException when any error occurs + */ + public void setDynamicAttribute( + String uri, String localName, String qName, String value) + throws BuildException + { + m_attributes.put( qName, value ); + } + + + /** + * Create an element with the given name + * + * @param name the element nbame + * @throws BuildException when any error occurs + * @return the element created + */ + public Object createDynamicElement( + String uri, String localName, String qName) throws BuildException + { + Configuration conf = new Configuration( qName ); + m_children.add( conf ); + return conf; + } + + /** + * Return the name of the configuration element. + * @return the node name + */ + public String getName() { - return m_file; + return m_name; + } + + /** + * Return a value associated with the element. + * @return the assigned value + */ + public String getValue() + { + return m_value; + } + + /** + * Return the map of the assigned attributes. + * @return the attribute name value map + */ + public Map getAttributes() + { + return m_attributes; + } + + /** + * Return he set of nest child configuration directives. + * @return the configuration directives within this directive + */ + public Configuration[] getChildren() + { + return (Configuration[]) m_children.toArray( new Configuration[0] ); + } + } + + /** + * A target directive. + */ + public static class Target + { + private String m_path; + private Configuration m_configuration; + private Parameters m_parameters; + + /** + * Set the path that this target is overriding. + */ + public void setPath( String path ) + { + m_path = path; + } + + /** + * Return the target path. + * @return the target that this override is overriding. + * @exception BuildException if the target is not declared + */ + public String getPath() + { + if( null == m_path ) + { + final String error = + "Required path attribute has not been declared."; + throw new BuildException( error ); + } + else + { + return m_path; + } + } + + /** + * Create a configuration directive. + * @return the configuration directive + */ + public Configuration createConfiguration() + { + if( null == m_configuration ) + { + m_configuration = new Configuration(); + return m_configuration; + } + else + { + final String error = + "Configuration entry already set!"; + throw new BuildException( error ); + } + } + + /** + * Reurn the configuration directive. + * @return the configuration directive (possibly null) + */ + public Configuration getConfiguration() + { + return m_configuration; + } + + + /** + * Return the parameters assigned this target override (possibly null). + * @return the parameters directive + */ + public Parameters getParameters() + { + return m_parameters; } } + //-------------------------------------------------------------------------- + // state + //-------------------------------------------------------------------------- + private String m_target; private String m_container; private List m_content = new ArrayList(); private boolean m_standalone = true; private Service m_service; + //-------------------------------------------------------------------------- + // features + //-------------------------------------------------------------------------- + + /** + * Set the name of the block. + * @param name the block name + */ public void setName( final String name ) { m_container = name; @@ -427,51 +833,18 @@ /** * Optional attribute indicating that the block is to be generated * as a standalone block. + * + * @param flag the standalone flag */ public void setStandalone( final boolean flag ) { m_standalone = flag; } - - private String getName( Definition def ) - { - if( null == m_container ) - { - return def.getInfo().getName(); - } - else - { - return m_container; - } - } - - protected File getPluginFile() - { - if( null == m_target ) - { - return super.getPluginFile(); - } - else - { - File root = getEmbeddedRoot( m_target ); - File blockinf = new File( root, "BLOCK-INF" ); - return new File( blockinf, "block.xml" ); - } - } - - private File getEmbeddedRoot( String target ) - { - if( MAIN.equals( target ) ) - { - return getContext().getClassesDirectory(); - } - else - { - return getContext().getTestClassesDirectory(); - } - } - + /** + * Create and add a component directive to this block. + * @return the new component directive + */ public Component createComponent() { final Component component = new Component(); @@ -479,6 +852,10 @@ return component; } + /** + * Create and add a new block include directive to the block. + * @return the include directive + */ public Include createInclude() { final Include include = new Include(); @@ -486,6 +863,10 @@ return include; } + /** + * Create and add a single service export directive to the block. + * @return the service export directive + */ public Service createService() { if( null == m_service ) @@ -501,12 +882,18 @@ } } + /** + * Initialize the task. + */ public void init() { super.init(); super.setType( BLOCK ); } + /** + * Execute the task. + */ public void execute() { if( null != m_target ) @@ -520,6 +907,48 @@ } } + //-------------------------------------------------------------------------- + // implementation + //-------------------------------------------------------------------------- + + private String getName( Definition def ) + { + if( null == m_container ) + { + return def.getInfo().getName(); + } + else + { + return m_container; + } + } + + protected File getPluginFile() + { + if( null == m_target ) + { + return super.getPluginFile(); + } + else + { + File root = getEmbeddedRoot( m_target ); + File blockinf = new File( root, "BLOCK-INF" ); + return new File( blockinf, "block.xml" ); + } + } + + private File getEmbeddedRoot( String target ) + { + if( MAIN.equals( target ) ) + { + return getContext().getClassesDirectory(); + } + else + { + return getContext().getTestClassesDirectory(); + } + } + protected void writePlugin( final Writer writer, final Definition def ) throws IOException { @@ -618,33 +1047,35 @@ private void writeConfiguration( final String pad, final Writer writer, final Configuration config ) throws IOException { - File file = config.getFile(); - if( null == file ) + String name = config.getName(); + writer.write( "\n" + pad + "<" + name ); + Map attributes = config.getAttributes(); + if( attributes.size() > 0 ) { - final String error = - "Missing file attribute in configuration declaration."; - throw new BuildException( error ); + Map.Entry[] values = (Map.Entry[]) attributes.entrySet().toArray( new Map.Entry[0] ); + for( int i=0; i<values.length; i++ ) + { + Map.Entry entry = values[i]; + writer.write( " " + entry.getKey() + "=\"" + entry.getValue() + "\"" ); + } } - if( !file.exists() ) + + Configuration[] children = config.getChildren(); + if( children.length > 0 ) { - final String error = - "Missing configuration file [" - + file - + "] does not exist."; - throw new BuildException( error ); + writer.write( ">" ); + for( int i=0; i<children.length; i++ ) + { + writeConfiguration( pad + " ", writer, children[i] ); + } + writer.write( "\n" + pad + "</" + name + ">" ); } - if( file.isDirectory() ) + else { - final String error = - "Configuration file [" - + file - + "] referes to a directory."; - throw new BuildException( error ); + writer.write( "/>" ); } - writer.write( "\n" + pad + "<configuration/>" ); } - private void writeContext( final String pad, final Writer writer, final Context context ) throws IOException { @@ -665,7 +1096,7 @@ { writeEntry( pad + " ", writer, entries[i] ); } - writer.write( "\n </context>" ); + writer.write( "\n" + pad + "</context>" ); } } @@ -708,8 +1139,41 @@ { writer.write( "\n\n" + pad + "<include name=\"" - + include.getName() + "\" artifact=\"" - + include.getArtifact() + "\"/>" ); + + include.getName() + "\" artifact=\"" + include.getArtifact() + "\"" ); + Target[] targets = include.getTargets(); + if( targets.length > 0 ) + { + writer.write( ">" ); + for( int i=0; i<targets.length; i++ ) + { + writeTarget( pad + " ", writer, targets[i] ); + } + writer.write( "\n" + pad + "</include>" ); + } + else + { + writer.write( "/>" ); + } + } + + private void writeTarget( final String pad, final Writer writer, final Target target ) + throws IOException + { + String path = target.getPath(); + writer.write( + "\n" + pad + "<target path=\"" + path + "\">" ); + Configuration config = target.getConfiguration(); + if( null != config ) + { + writeConfiguration( pad + " ", writer, config ); + } + Parameters parameters = target.getParameters(); + if( null != parameters ) + { + writeParameters( pad + " ", writer, parameters ); + } + writer.write( + "\n" + pad + "</target>" ); } private void writeService( final String pad, final Writer writer, final Service service ) Modified: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/DeclareTask.java ============================================================================== --- avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/DeclareTask.java (original) +++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/DeclareTask.java Wed Sep 1 08:02:07 2004 @@ -71,6 +71,10 @@ { closeStream( output ); } + + DeliverableHelper.checksum( this, file ); + DeliverableHelper.asc( getHome(), this, file ); + } catch( Throwable e ) { Added: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/DeliverableHelper.java ============================================================================== --- (empty file) +++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/DeliverableHelper.java Wed Sep 1 08:02:07 2004 @@ -0,0 +1,107 @@ +/* + * Copyright 2004 Apache Software Foundation + * 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 org.apache.avalon.tools.tasks; + +import org.apache.tools.ant.Task; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.Checksum; +import org.apache.tools.ant.taskdefs.ExecTask; + +import org.apache.avalon.tools.model.Home; + +import java.io.File; + +/** + * Utilites supporting the generation of MD5 and ASC artifacts. + * + * @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a> + * @version $Revision: 1.2 $ $Date: 2004/03/17 10:30:09 $ + */ +public class DeliverableHelper +{ + public static final String MD5_EXT = "md5"; + public static final String ASC_EXT = "asc"; + + /** + * Create an MD5 checksum file relative to the supplied file. + * If an [filename].md5 file exists it will be deleted and a new + * MD5 created. + * + * @param task the task controlling file generation + * @param file the file from which a checksum signature will be generated + */ + public static void checksum( final Task task, final File file ) + { + task.log( "Creating md5 checksum" ); + + final File md5 = new File( file.toString() + "." + MD5_EXT ); + if( md5.exists() ) + { + md5.delete(); + } + + final Checksum checksum = (Checksum) task.getProject().createTask( "checksum" ); + checksum.setTaskName( task.getTaskName() ); + checksum.setFile( file ); + checksum.setFileext( "." + MD5_EXT ); + checksum.init(); + checksum.execute(); + } + + /** + * Creation of an ASC signature relative to a supplied file. If a [filename].asc + * exists it will be deleted and recreated relative to the supplied file content. + * The ASC signature will be generated using the executable assigned to the property + * Home.GPG_EXE_KEY. + * + * @param home the magic home + * @param task the task creating the file + * @param file the file to sign + */ + public static void asc( final Home home, final Task task, final File file ) + { + final String path = Project.translatePath( file.toString() ); + final File asc = new File( file.toString() + "." + ASC_EXT ); + if( asc.exists() ) + { + asc.delete(); + } + + final String gpg = home.getProperty( Home.GPG_EXE_KEY ); + + if(( null != gpg ) && !"".equals( gpg ) ) + { + task.log( "Creating asc signature using '" + gpg + "'." ); + final ExecTask execute = (ExecTask) task.getProject().createTask( "exec" ); + + execute.setExecutable( gpg ); + + execute.createArg().setValue( "-a" ); + execute.createArg().setValue( "-b" ); + execute.createArg().setValue( "-o" ); + execute.createArg().setValue( path + "." + ASC_EXT ); + execute.createArg().setValue( path ); + + execute.setDir( task.getProject().getBaseDir() ); + execute.setSpawn( false ); + execute.setAppend( false ); + execute.setTimeout( new Integer( 1000 ) ); + execute.execute(); + } + } +} Modified: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/JarTask.java ============================================================================== --- avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/JarTask.java (original) +++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/tasks/JarTask.java Wed Sep 1 08:02:07 2004 @@ -31,7 +31,7 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a> * @version $Revision: 1.2 $ $Date: 2004/03/17 10:30:09 $ */ -public class JarTask extends AbstractDeliverableTask +public class JarTask extends SystemTask { public static final String JAR_EXT = "jar"; public static final String JAR_MAIN_KEY = "project.jar.main.class"; @@ -51,8 +51,8 @@ final boolean modified = jar( def, classes, jarFile ); if( modified ) { - checksum( jarFile ); - asc( jarFile ); + DeliverableHelper.checksum( this, jarFile ); + DeliverableHelper.asc( getHome(), this, jarFile ); } } getContext().setBuildPath( "jar", jarFile.toString() ); --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]