Resending with .txt attachment.
> -----Original Message----- > From: Stephen McConnell [mailto:[EMAIL PROTECTED] > Sent: 27 August 2004 07:47 > To: Avalon Developers List > Subject: [patch] magic md5 and asc enhancements > > > The attached multi-file patch refactors the asc and md5 generation > within magic. This functionality was provided in an abstract task and > this patch moves that functionality into a static helper class. This > change enables easier reuse of the asc and md5 functionality from tasks > that cannot directly extend from an abstract base.The patch also > includes revision of the artifact and block generation tasks to enable > asc and md5 generation of the respective artifacts. > > Stephen. > >
Index: tools/magic/src/main/org/apache/avalon/tools/tasks/JarTask.java =================================================================== --- tools/magic/src/main/org/apache/avalon/tools/tasks/JarTask.java (revision 37110) +++ tools/magic/src/main/org/apache/avalon/tools/tasks/JarTask.java (working copy) @@ -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() ); Index: tools/magic/src/main/org/apache/avalon/tools/tasks/DeliverableHelper.java =================================================================== --- tools/magic/src/main/org/apache/avalon/tools/tasks/DeliverableHelper.java (revision 0) +++ tools/magic/src/main/org/apache/avalon/tools/tasks/DeliverableHelper.java (revision 0) @@ -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(); + } + } +} Index: tools/magic/src/main/org/apache/avalon/tools/tasks/ArtifactTask.java =================================================================== --- tools/magic/src/main/org/apache/avalon/tools/tasks/ArtifactTask.java (revision 37110) +++ tools/magic/src/main/org/apache/avalon/tools/tasks/ArtifactTask.java (working copy) @@ -100,6 +100,8 @@ { closeStream( output ); } + DeliverableHelper.checksum( this, file ); + DeliverableHelper.asc( getHome(), this, file ); } catch( Throwable e ) { Index: tools/magic/src/main/org/apache/avalon/tools/tasks/DeclareTask.java =================================================================== --- tools/magic/src/main/org/apache/avalon/tools/tasks/DeclareTask.java (revision 37110) +++ tools/magic/src/main/org/apache/avalon/tools/tasks/DeclareTask.java (working copy) @@ -71,6 +71,10 @@ { closeStream( output ); } + + DeliverableHelper.checksum( this, file ); + DeliverableHelper.asc( getHome(), this, file ); + } catch( Throwable e ) { Index: tools/magic/src/main/org/apache/avalon/tools/tasks/AbstractDeliverableTask.java =================================================================== --- tools/magic/src/main/org/apache/avalon/tools/tasks/AbstractDeliverableTask.java (revision 37103) +++ tools/magic/src/main/org/apache/avalon/tools/tasks/AbstractDeliverableTask.java (working copy) @@ -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(); - } - } -} Index: tools/magic/src/main/org/apache/avalon/tools/tasks/BarTask.java =================================================================== --- tools/magic/src/main/org/apache/avalon/tools/tasks/BarTask.java (revision 37110) +++ tools/magic/src/main/org/apache/avalon/tools/tasks/BarTask.java (working copy) @@ -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 ); } } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]