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 2002/05/02 10:43:33 UTC
cvs commit: jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/project TypeLibTask.java TargetTask.java Resources.properties
donaldp 02/05/02 01:43:33
Added: antlib/src/java/org/apache/antlib/project TypeLibTask.java
TargetTask.java Resources.properties
Log:
Start to create tasks that can represent a Project.
Revision Changes Path
1.1 jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/project/TypeLibTask.java
Index: TypeLibTask.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.project;
import java.io.File;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.myrmidon.api.AbstractTask;
import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.interfaces.deployer.Deployer;
import org.apache.myrmidon.interfaces.deployer.DeploymentException;
import org.apache.myrmidon.interfaces.deployer.TypeLibraryDeployer;
/**
* Task to import a typeLib.
*
* @author <a href="mailto:peter@apache.org">Peter Donald</a>
* @ant.task name="typelib"
*/
public class TypeLibTask
extends AbstractTask
{
private static final Resources REZ =
ResourceManager.getPackageResources( TypeLibTask.class );
private String m_library;
private String m_name;
private String m_role;
public void setLibrary( final String library )
{
m_library = library;
}
public void setName( final String name )
{
m_name = name;
}
public void setRole( final String role )
{
m_role = role;
}
public void execute()
throws TaskException
{
validate();
deployTypeLib();
}
/**
* Make sure valid parameters are passed to task.
*
* @throws TaskException if invalid parameters passed to task
*/
private void validate()
throws TaskException
{
if( null == m_library )
{
final String message =
REZ.getString( "typelib.missing-library.error" );
throw new TaskException( message );
}
if( null == m_name && null == m_role )
{
return;
}
else if( null == m_name )
{
final String message =
REZ.getString( "typelib.missing-name.error", m_role );
throw new TaskException( message );
}
else if( null == m_role )
{
final String message =
REZ.getString( "typelib.missing-role.error", m_name );
throw new TaskException( message );
}
}
/**
* Actually do work of deploying type library.
*
* @throws TaskException if error occured deploying library
*/
private void deployTypeLib()
throws TaskException
{
final File file = findTypeLib();
try
{
final Deployer deployer = (Deployer)getService( Deployer.class );
final TypeLibraryDeployer typeDeployer = deployer.createDeployer( file );
if( null == m_role )
{
// Deploy everything in the typelib
typeDeployer.deployAll();
}
else
{
// Deploy the specified type
typeDeployer.deployType( m_role, m_name );
}
}
catch( final DeploymentException de )
{
final String message =
REZ.getString( "no-deploy.error",
m_library,
file );
throw new TaskException( message, de );
}
}
/**
* Find the physical file location of library.
*
* @return the File representing library
* @throws TaskException if can not find library
* matching name
* @todo In future this will be expanded to allow
* users to specify search path or automagically
* add entries to lib path (like user specific or
* workspace specific)
*/
private File findTypeLib()
throws TaskException
{
final String name = m_library.replace( '/', File.separatorChar ) + ".atl";
final File[] extPath =
(File[])getContext().getProperty( "myrmidon.antlib.path" );
for( int i = 0; i < extPath.length; i++ )
{
final File extDir = extPath[ i ];
final File file = new File( extDir, name );
if( file.exists() )
{
if( !file.canRead() )
{
final String message =
REZ.getString( "typelib.no-read.error",
file,
m_library );
throw new TaskException( message );
}
else
{
return file;
}
}
}
final String message =
REZ.getString( "typelib.no-file.error", m_library );
throw new TaskException( message );
}
}
1.1 jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/project/TargetTask.java
Index: TargetTask.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.project;
import java.util.ArrayList;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.api.metadata.ModelElement;
import org.apache.myrmidon.framework.AbstractContainerTask;
import org.apache.myrmidon.interfaces.executor.ExecutionFrame;
/**
* A simple task to task to execute a group of tasks.
*
* @author <a href="mailto:peter@apache.org">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2002/05/02 08:43:33 $
* @ant.task name="target"
*/
public class TargetTask
extends AbstractContainerTask
{
private static final Resources REZ =
ResourceManager.getPackageResources( TargetTask.class );
/**
* The array of ordered tasks which are contained
* withing Target.
*/
private final ArrayList m_tasks = new ArrayList();
/**
* The name of the target.
*/
private String m_name;
/**
* The frame in which the tasks in target execute.
*/
private ExecutionFrame m_frame;
/**
* Specify the name of target.
*
* @param name the name of the target
* @see #m_name
*/
public void setName( final String name )
{
m_name = name;
}
/**
* Add a task to the target.
*
* @param task a model representing a task
* @see #m_tasks
*/
public void add( final ModelElement task )
{
m_tasks.add( task );
}
public void execute()
throws TaskException
{
if( null == m_name )
{
final String message =
REZ.getString( "target.no-name.error" );
throw new TaskException( message );
}
if( getContext().isInfoEnabled() )
{
final String message =
REZ.getString( "target.exec.notice", m_name );
getContext().info( message );
}
final ExecutionFrame parentFrame = super.getExecutionFrame();
m_frame = parentFrame.createChildFrame( m_name, null, false );
final ModelElement[] tasks =
(ModelElement[])m_tasks.toArray( new ModelElement[ m_tasks.size() ] );
for( int i = 0; i < tasks.length; i++ )
{
final ModelElement task = tasks[ i ];
if( getContext().isInfoEnabled() )
{
final String message =
REZ.getString( "target.task-exec.notice",
task.getName() );
getContext().info( message );
}
executeTask( task );
}
}
/**
* Return a different frame for target.
*
* @return the targets frame
*/
protected ExecutionFrame getExecutionFrame()
{
return m_frame;
}
public String toString()
{
return "Target['" + m_name + "]";
}
}
1.1 jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/project/Resources.properties
Index: Resources.properties
===================================================================
target.no-name.error=Target does not specify the name attribute.
target.exec.notice=Executing target: "{0}".
target.task-exec.notice=Executing task: "{0}".
typelib.missing-library.error=Missing library attribute from typelib statement.
typelib.missing-name.error=Specified role ("{0}") but missing name from typelib statement.
typelib.missing-role.error=Specified name ("{0}") but missing role from typelib statement.
typelib.no-read.error=Unable to read file "{0}" to load library "{1}".
typelib.no-file.error=No file can be found when searching for library "{0}".
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>