Added in a sample config file and a sample factory aswell. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270866 13f79535-47bb-0310-9956-ffa450edef68master
@@ -0,0 +1,62 @@ | |||||
/* | |||||
* 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.myrmidon.framework.factorys; | |||||
import java.io.File; | |||||
import org.apache.aut.nativelib.ExecException; | |||||
import org.apache.aut.nativelib.impl.DefaultExecManager; | |||||
import org.apache.avalon.excalibur.i18n.ResourceManager; | |||||
import org.apache.avalon.excalibur.i18n.Resources; | |||||
import org.apache.myrmidon.services.ServiceException; | |||||
import org.apache.myrmidon.services.ServiceFactory; | |||||
/** | |||||
* A Factory responsible for creating the ExecManager service. | |||||
* | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public class ExecManagerFactory | |||||
implements ServiceFactory | |||||
{ | |||||
private static final Resources REZ = | |||||
ResourceManager.getPackageResources( ExecManagerFactory.class ); | |||||
/** | |||||
* Create the ExecManager Service. | |||||
*/ | |||||
public Object createService() | |||||
throws ServiceException | |||||
{ | |||||
final File home = getHomeDirectory(); | |||||
try | |||||
{ | |||||
return new DefaultExecManager( home ); | |||||
} | |||||
catch( final ExecException ee ) | |||||
{ | |||||
throw new ServiceException( ee.getMessage(), ee ); | |||||
} | |||||
} | |||||
/** | |||||
* Utility method to retrieve home directory. | |||||
*/ | |||||
private static File getHomeDirectory() | |||||
throws ServiceException | |||||
{ | |||||
final String home = System.getProperty( "myrmidon.home" ); | |||||
if( null == home ) | |||||
{ | |||||
final String message = REZ.getString( "missing-home-dir.error" ); | |||||
throw new ServiceException( message ); | |||||
} | |||||
return new File( home ); | |||||
} | |||||
} |
@@ -0,0 +1 @@ | |||||
missing-home-dir.error=Cannot locate antRun scripts: Property 'myrmidon.home' not specified |
@@ -0,0 +1,50 @@ | |||||
/* | |||||
* 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.myrmidon.services; | |||||
import org.apache.avalon.framework.CascadingException; | |||||
/** | |||||
* ServiceException thrown when a service can not be created for | |||||
* some reason. | |||||
* | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | |||||
*/ | |||||
public class ServiceException | |||||
extends CascadingException | |||||
{ | |||||
/** | |||||
* Basic constructor for exception that does not specify a message | |||||
*/ | |||||
public ServiceException() | |||||
{ | |||||
this( "", null ); | |||||
} | |||||
/** | |||||
* Basic constructor with a message | |||||
* | |||||
* @param message the message | |||||
*/ | |||||
public ServiceException( final String message ) | |||||
{ | |||||
this( message, null ); | |||||
} | |||||
/** | |||||
* Constructor that builds cascade so that other exception information can be retained. | |||||
* | |||||
* @param message the message | |||||
* @param throwable the throwable | |||||
*/ | |||||
public ServiceException( final String message, final Throwable throwable ) | |||||
{ | |||||
super( message, throwable ); | |||||
} | |||||
} | |||||
@@ -0,0 +1,27 @@ | |||||
/* | |||||
* 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.myrmidon.services; | |||||
/** | |||||
* A ServiceFactory is used to create a service for use in the | |||||
* Myrmidon runtime. The factory is responsible for creating and | |||||
* preparing the service for use. | |||||
* | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public interface ServiceFactory | |||||
{ | |||||
/** | |||||
* Create a service that coresponds to this factory. | |||||
* This method is usually called after the factory has been | |||||
* prepared and configured as appropriate. | |||||
*/ | |||||
Object createService() | |||||
throws ServiceException; | |||||
} |
@@ -0,0 +1,4 @@ | |||||
<services> | |||||
<service role="org.apache.aut.nativelib.ExecManager" | |||||
factory="org.apache.myrmidon.framework.factorys.ExecManagerFactory"/> | |||||
</services> |