You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by do...@apache.org on 2001/12/23 00:38:37 UTC
cvs commit: jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/unix Chmod.java Rpm.java
donaldp 01/12/22 15:38:37
Added: proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/unix
Chmod.java Rpm.java
Removed: proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs
Chmod.java
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional
Rpm.java
Log:
Move unix type tasks into new package
Revision Changes Path
1.1 jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/unix/Chmod.java
Index: Chmod.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 file.
*/
package org.apache.tools.ant.taskdefs.unix;
import java.io.File;
import java.io.IOException;
import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.framework.Os;
import org.apache.tools.ant.taskdefs.exec.Execute;
import org.apache.tools.ant.taskdefs.ExecuteOn;
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.PatternSet;
/**
* Chmod equivalent for unix-like environments.
*
* @author costin@eng.sun.com
* @author Mariusz Nowostawski (Marni) <a
* href="mailto:mnowostawski@infoscience.otago.ac.nz">
* mnowostawski@infoscience.otago.ac.nz</a>
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
*/
public class Chmod extends ExecuteOn
{
private FileSet defaultSet = new FileSet();
private boolean defaultSetDefined = false;
private boolean havePerm = false;
public Chmod()
throws TaskException
{
super.setExecutable( "chmod" );
super.setParallel( true );
super.setSkipEmptyFilesets( true );
}
/**
* Sets whether default exclusions should be used or not.
*
* @param useDefaultExcludes "true"|"on"|"yes" when default exclusions
* should be used, "false"|"off"|"no" when they shouldn't be used.
*/
public void setDefaultexcludes( boolean useDefaultExcludes )
throws TaskException
{
defaultSetDefined = true;
defaultSet.setDefaultexcludes( useDefaultExcludes );
}
public void setDir( File src )
throws TaskException
{
defaultSet.setDir( src );
}
/**
* Sets the set of exclude patterns. Patterns may be separated by a comma or
* a space.
*
* @param excludes the string containing the exclude patterns
*/
public void setExcludes( String excludes )
throws TaskException
{
defaultSetDefined = true;
defaultSet.setExcludes( excludes );
}
public void setExecutable( String e )
throws TaskException
{
throw new TaskException( getName() + " doesn\'t support the executable attribute" );
}
public void setFile( File src )
throws TaskException
{
FileSet fs = new FileSet();
fs.setDir( new File( src.getParent() ) );
fs.createInclude().setName( src.getName() );
addFileset( fs );
}
/**
* Sets the set of include patterns. Patterns may be separated by a comma or
* a space.
*
* @param includes the string containing the include patterns
*/
public void setIncludes( String includes )
throws TaskException
{
defaultSetDefined = true;
defaultSet.setIncludes( includes );
}
public void setPerm( String perm )
{
createArg().setValue( perm );
havePerm = true;
}
public void setSkipEmptyFilesets( boolean skip )
throws TaskException
{
throw new TaskException( getName() + " doesn\'t support the skipemptyfileset attribute" );
}
/**
* add a name entry on the exclude list
*
* @return Description of the Returned Value
*/
public PatternSet.NameEntry createExclude()
throws TaskException
{
defaultSetDefined = true;
return defaultSet.createExclude();
}
/**
* add a name entry on the include list
*
* @return Description of the Returned Value
*/
public PatternSet.NameEntry createInclude()
throws TaskException
{
defaultSetDefined = true;
return defaultSet.createInclude();
}
/**
* add a set of patterns
*
* @return Description of the Returned Value
*/
public PatternSet createPatternSet()
throws TaskException
{
defaultSetDefined = true;
return defaultSet.createPatternSet();
}
public void execute()
throws TaskException
{
if( defaultSetDefined || defaultSet.getDir( getProject() ) == null )
{
super.execute();
}
else if( isValidOs() )
{
// we are chmodding the given directory
createArg().setValue( defaultSet.getDir( getProject() ).getPath() );
Execute execute = prepareExec();
try
{
execute.setCommandline( cmdl.getCommandline() );
runExecute( execute );
}
catch( IOException e )
{
throw new TaskException( "Execute failed: " + e, e );
}
finally
{
// close the output file if required
logFlush();
}
}
}
protected boolean isValidOs()
{
return Os.isFamily( "unix" ) && super.isValidOs();
}
protected void checkConfiguration()
throws TaskException
{
if( !havePerm )
{
throw new TaskException( "Required attribute perm not set in chmod" );
}
if( defaultSetDefined && defaultSet.getDir( getProject() ) != null )
{
addFileset( defaultSet );
}
super.checkConfiguration();
}
}
1.1 jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/unix/Rpm.java
Index: Rpm.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 file.
*/
package org.apache.tools.ant.taskdefs.unix;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import org.apache.myrmidon.api.TaskException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.taskdefs.exec.Execute;
import org.apache.tools.ant.taskdefs.exec.ExecuteStreamHandler;
import org.apache.tools.ant.taskdefs.exec.LogOutputStream;
import org.apache.tools.ant.taskdefs.exec.LogStreamHandler;
import org.apache.tools.ant.taskdefs.exec.PumpStreamHandler;
import org.apache.tools.ant.types.Commandline;
/**
* @author lucas@collab.net
*/
public class Rpm extends Task
{
/**
* the rpm command to use
*/
private String command = "-bb";
/**
* clean BUILD directory
*/
private boolean cleanBuildDir = false;
/**
* remove spec file
*/
private boolean removeSpec = false;
/**
* remove sources
*/
private boolean removeSource = false;
/**
* the file to direct standard error from the command
*/
private File error;
/**
* the file to direct standard output from the command
*/
private File output;
/**
* the spec file
*/
private String specFile;
/**
* the rpm top dir
*/
private File topDir;
public void setCleanBuildDir( boolean cbd )
{
cleanBuildDir = cbd;
}
public void setCommand( String c )
{
this.command = c;
}
public void setError( File error )
{
this.error = error;
}
public void setOutput( File output )
{
this.output = output;
}
public void setRemoveSource( boolean rs )
{
removeSource = rs;
}
public void setRemoveSpec( boolean rs )
{
removeSpec = rs;
}
public void setSpecFile( String sf )
throws TaskException
{
if( ( sf == null ) || ( sf.trim().equals( "" ) ) )
{
throw new TaskException( "You must specify a spec file" );
}
this.specFile = sf;
}
public void setTopDir( File td )
{
this.topDir = td;
}
public void execute()
throws TaskException
{
Commandline toExecute = new Commandline();
toExecute.setExecutable( "rpm" );
if( topDir != null )
{
toExecute.createArgument().setValue( "--define" );
toExecute.createArgument().setValue( "_topdir" + topDir );
}
toExecute.createArgument().setLine( command );
if( cleanBuildDir )
{
toExecute.createArgument().setValue( "--clean" );
}
if( removeSpec )
{
toExecute.createArgument().setValue( "--rmspec" );
}
if( removeSource )
{
toExecute.createArgument().setValue( "--rmsource" );
}
toExecute.createArgument().setValue( "SPECS/" + specFile );
ExecuteStreamHandler streamhandler = null;
OutputStream outputstream = null;
OutputStream errorstream = null;
if( error == null && output == null )
{
streamhandler = new LogStreamHandler( this, Project.MSG_INFO,
Project.MSG_WARN );
}
else
{
if( output != null )
{
try
{
outputstream = new PrintStream( new BufferedOutputStream( new FileOutputStream( output ) ) );
}
catch( IOException e )
{
throw new TaskException( "Error", e );
}
}
else
{
outputstream = new LogOutputStream( this, Project.MSG_INFO );
}
if( error != null )
{
try
{
errorstream = new PrintStream( new BufferedOutputStream( new FileOutputStream( error ) ) );
}
catch( IOException e )
{
throw new TaskException( "Error", e );
}
}
else
{
errorstream = new LogOutputStream( this, Project.MSG_WARN );
}
streamhandler = new PumpStreamHandler( outputstream, errorstream );
}
Execute exe = new Execute( streamhandler );
if( topDir == null ) topDir = getBaseDirectory();
exe.setWorkingDirectory( topDir );
exe.setCommandline( toExecute.getCommandline() );
try
{
exe.execute();
getLogger().info( "Building the RPM based on the " + specFile + " file" );
}
catch( IOException e )
{
throw new TaskException( "Error", e );
}
finally
{
if( output != null )
{
try
{
outputstream.close();
}
catch( IOException e )
{
}
}
if( error != null )
{
try
{
errorstream.close();
}
catch( IOException e )
{
}
}
}
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>