Return-Path: Delivered-To: apmail-jakarta-ant-dev-archive@apache.org Received: (qmail 79976 invoked from network); 6 Feb 2002 12:44:42 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 6 Feb 2002 12:44:42 -0000 Received: (qmail 4197 invoked by uid 97); 6 Feb 2002 12:44:37 -0000 Delivered-To: qmlist-jakarta-archive-ant-dev@jakarta.apache.org Received: (qmail 4181 invoked by uid 97); 6 Feb 2002 12:44:37 -0000 Mailing-List: contact ant-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Ant Developers List" Reply-To: "Ant Developers List" Delivered-To: mailing list ant-dev@jakarta.apache.org Received: (qmail 4170 invoked by uid 97); 6 Feb 2002 12:44:36 -0000 Date: 6 Feb 2002 12:44:36 -0000 Message-ID: <20020206124436.65523.qmail@icarus.apache.org> From: donaldp@apache.org To: jakarta-ant-cvs@apache.org Subject: cvs commit: jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs Patch.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N donaldp 02/02/06 04:44:36 Added: proposal/myrmidon/src/java/org/apache/antlib/build Patch.java Removed: proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs Patch.java Log: Move patch task into a type library Revision Changes Path 1.1 jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/build/Patch.java Index: Patch.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.antlib.build; import java.io.File; import java.io.IOException; import org.apache.myrmidon.api.AbstractTask; import org.apache.myrmidon.api.TaskException; import org.apache.tools.ant.taskdefs.exec.Execute2; import org.apache.tools.ant.types.Commandline; import org.apache.aut.nativelib.ExecManager; /** * Task as a layer on top of patch. Patch applies a diff file to an original. * * @author Stefan Bodewig * @author Peter Donald */ public class Patch extends AbstractTask { private File m_originalFile; private File m_patchFile; private boolean m_backups; private boolean m_ignorewhitespace; private boolean m_reverse; private boolean m_quiet; private Integer m_strip; /** * Shall patch write backups. * * @param backups The new Backups value */ public void setBackups( final boolean backups ) { m_backups = backups; } /** * Ignore whitespace differences. * * @param ignore The new Ignorewhitespace value */ public void setIgnorewhitespace( final boolean ignorewhitespace ) { m_ignorewhitespace = ignorewhitespace; } /** * The file to patch. * * @param file The new Originalfile value */ public void setOriginalfile( final File originalFile ) { m_originalFile = originalFile; } /** * The file containing the diff output. * * @param file The new Patchfile value */ public void setPatchfile( final File patchFile ) { m_patchFile = patchFile; } /** * Work silently unless an error occurs. * * @param q The new Quiet value */ public void setQuiet( final boolean quiet ) { m_quiet = quiet; } /** * Assume patch was created with old and new files swapped. * * @param r The new Reverse value */ public void setReverse( final boolean reverse ) { m_reverse = reverse; } /** * Strip the smallest prefix containing num leading slashes from * filenames.

* * patch's -p option. * * @param strip The new Strip value */ public void setStrip( final Integer strip ) { m_strip = strip; } public void execute() throws TaskException { validate(); final ExecManager execManager = (ExecManager)getService( ExecManager.class ); final Execute2 exe = new Execute2( execManager ); setupLogger( exe ); final Commandline cmd = buildCommand(); exe.setCommandline( cmd ); try { exe.execute(); } catch( IOException e ) { throw new TaskException( "Error", e ); } } private void validate() throws TaskException { if( null == m_patchFile ) { final String message = "patchfile argument is required"; throw new TaskException( message ); } if( !m_patchFile.exists() ) { final String message = "patchfile " + m_patchFile + " doesn\'t exist"; throw new TaskException( message ); } if( null != m_strip && m_strip.intValue() < 0 ) { throw new TaskException( "strip has to be >= 0" ); } } private Commandline buildCommand() { final Commandline cmd = new Commandline(); cmd.setExecutable( "patch" ); if( m_backups ) { cmd.addArgument( "-b" ); } if( null != m_strip ) { cmd.addArgument( "-p" + m_strip.intValue() ); } if( m_quiet ) { cmd.addArgument( "-s" ); } if( m_reverse ) { cmd.addArgument( "-R" ); } cmd.addArgument( "-i" ); cmd.addArgument( m_patchFile ); if( m_ignorewhitespace ) { cmd.addArgument( "-l" ); } if( null != m_originalFile ) { cmd.addArgument( m_originalFile ); } return cmd; } } -- To unsubscribe, e-mail: For additional commands, e-mail: