From 89770b70fe1cc567b9a938123a4e803aa6d57072 Mon Sep 17 00:00:00 2001 From: Peter Donald Date: Thu, 14 Feb 2002 10:47:23 +0000 Subject: [PATCH] Make follow myrmidon designs anbd make sure it is not two things (task and condition). If need condition then move common funcitonality into helper class. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271335 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/antlib/build/Checksum.java | 89 +++---------------- 1 file changed, 11 insertions(+), 78 deletions(-) diff --git a/proposal/myrmidon/src/java/org/apache/antlib/build/Checksum.java b/proposal/myrmidon/src/java/org/apache/antlib/build/Checksum.java index cfc183d88..72a425646 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/build/Checksum.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/build/Checksum.java @@ -7,13 +7,11 @@ */ package org.apache.antlib.build; -import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; -import java.io.InputStreamReader; import java.security.DigestInputStream; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; @@ -23,8 +21,7 @@ import java.util.Enumeration; import java.util.Hashtable; import org.apache.avalon.excalibur.io.IOUtil; import org.apache.myrmidon.api.TaskException; -import org.apache.tools.ant.taskdefs.condition.Condition; -import org.apache.tools.ant.taskdefs.MatchingTask; +import org.apache.myrmidon.framework.AbstractMatchingTask; import org.apache.tools.ant.types.DirectoryScanner; import org.apache.tools.ant.types.FileSet; import org.apache.tools.ant.types.ScannerUtil; @@ -36,8 +33,7 @@ import org.apache.tools.ant.types.ScannerUtil; * @author Magesh Umasankar */ public class Checksum - extends MatchingTask - implements Condition + extends AbstractMatchingTask { /** * File for which checksum is to be calculated. @@ -74,11 +70,6 @@ public class Checksum */ private boolean m_forceOverwrite; - /** - * is this task being used as a nested condition element? - */ - private boolean m_isCondition; - /** * Message Digest instance */ @@ -178,19 +169,6 @@ public class Checksum m_filesets.add( set ); } - /** - * Calculate the checksum(s) - * - * @return Returns true if the checksum verification test passed, false - * otherwise. - */ - public boolean eval() - throws TaskException - { - m_isCondition = true; - return validateAndExecute(); - } - /** * Calculate the checksum(s). * @@ -224,7 +202,7 @@ public class Checksum if( m_property == null ) { final File dest = new File( file.getParent(), file.getName() + m_fileext ); - if( m_forceOverwrite || m_isCondition || + if( m_forceOverwrite || ( file.lastModified() > dest.lastModified() ) ) { m_includeFileMap.put( file, dest ); @@ -262,11 +240,8 @@ public class Checksum while( includes.hasMoreElements() ) { final File src = (File)includes.nextElement(); - if( !m_isCondition ) - { - final String message = "Calculating " + m_algorithm + " checksum for " + src; - getLogger().info( message ); - } + final String message = "Calculating " + m_algorithm + " checksum for " + src; + getLogger().info( message ); checksumMatches = z( src, checksumMatches ); } @@ -301,47 +276,16 @@ public class Checksum if( destination instanceof String ) { final String prop = (String)destination; - if( m_isCondition ) - { - checksumMatches = checksum.equals( m_property ); - } - else - { - final Object value = checksum; - getContext().setProperty( prop, value ); - } + checksumMatches = checksum.equals( m_property ); + getContext().setProperty( prop, checksum ); } else if( destination instanceof File ) { final File file = (File)destination; - if( m_isCondition ) - { - if( file.exists() && - file.length() == checksum.length() ) - { - fis = new FileInputStream( file ); - InputStreamReader isr = new InputStreamReader( fis ); - BufferedReader br = new BufferedReader( isr ); - String suppliedChecksum = br.readLine(); - fis.close(); - fis = null; - br.close(); - isr.close(); - checksumMatches = - checksum.equals( suppliedChecksum ); - } - else - { - checksumMatches = false; - } - } - else - { - fos = new FileOutputStream( file ); - fos.write( checksum.getBytes() ); - fos.close(); - fos = null; - } + fos = new FileOutputStream( file ); + fos.write( checksum.getBytes() ); + fos.close(); + fos = null; } } catch( final Exception e ) @@ -425,23 +369,12 @@ public class Checksum } } - if( m_verifyProperty != null ) - { - m_isCondition = true; - } - if( m_verifyProperty != null && m_forceOverwrite ) { final String message = "VerifyProperty and ForceOverwrite cannot co-exist."; throw new TaskException( message ); } - if( m_isCondition && m_forceOverwrite ) - { - final String message = "ForceOverwrite cannot be used when conditions are being used."; - throw new TaskException( message ); - } - if( m_fileext == null ) { m_fileext = "." + m_algorithm;