plexus-ant-factory-1.0~alpha2.1/0000755000175000017500000000000011224730071016477 5ustar twernertwernerplexus-ant-factory-1.0~alpha2.1/src/0000755000175000017500000000000011224730070017265 5ustar twernertwernerplexus-ant-factory-1.0~alpha2.1/src/test/0000755000175000017500000000000011224730070020244 5ustar twernertwernerplexus-ant-factory-1.0~alpha2.1/src/test/resources/0000755000175000017500000000000011224730070022256 5ustar twernertwernerplexus-ant-factory-1.0~alpha2.1/src/test/resources/test-scripts/0000755000175000017500000000000011224730070024722 5ustar twernertwernerplexus-ant-factory-1.0~alpha2.1/src/test/resources/test-scripts/AntScriptInvoker-build.xml0000644000175000017500000000012311144421674032012 0ustar twernertwerner ${testDir} plexus-ant-factory-1.0~alpha2.1/src/test/java/0000755000175000017500000000000011224730070021165 5ustar twernertwernerplexus-ant-factory-1.0~alpha2.1/src/test/java/org/0000755000175000017500000000000011224730070021754 5ustar twernertwernerplexus-ant-factory-1.0~alpha2.1/src/test/java/org/codehaus/0000755000175000017500000000000011224730070023547 5ustar twernertwernerplexus-ant-factory-1.0~alpha2.1/src/test/java/org/codehaus/plexus/0000755000175000017500000000000011224730070025067 5ustar twernertwernerplexus-ant-factory-1.0~alpha2.1/src/test/java/org/codehaus/plexus/component/0000755000175000017500000000000011224730070027071 5ustar twernertwernerplexus-ant-factory-1.0~alpha2.1/src/test/java/org/codehaus/plexus/component/factory/0000755000175000017500000000000011224730070030540 5ustar twernertwernerplexus-ant-factory-1.0~alpha2.1/src/test/java/org/codehaus/plexus/component/factory/ant/0000755000175000017500000000000011224730070031322 5ustar twernertwerner././@LongLink0000000000000000000000000000016200000000000011564 Lustar rootrootplexus-ant-factory-1.0~alpha2.1/src/test/java/org/codehaus/plexus/component/factory/ant/AntScriptInvokerTest.javaplexus-ant-factory-1.0~alpha2.1/src/test/java/org/codehaus/plexus/component/factory/ant/AntScriptInv0000644000175000017500000001437211144421674033650 0ustar twernertwernerpackage org.codehaus.plexus.component.factory.ant; import org.apache.tools.ant.BuildEvent; import org.apache.tools.ant.BuildListener; import org.codehaus.plexus.component.configurator.ComponentConfigurationException; import org.codehaus.plexus.component.factory.ComponentInstantiationException; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.component.repository.ComponentRequirement; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import junit.framework.TestCase; public class AntScriptInvokerTest extends TestCase { private static final String SCRIPT_RESOURCE = "test-scripts/AntScriptInvoker-build.xml"; public void testInit_UsingResourceAndTarget() throws IOException, ComponentInstantiationException { String target = "test"; AntScriptInvoker invoker = newInvoker( SCRIPT_RESOURCE, target ); assertEquals( SCRIPT_RESOURCE, invoker.getScriptResource() ); assertEquals( target, invoker.getTarget() ); } private AntScriptInvoker newInvoker( String resource, String target ) throws IOException, ComponentInstantiationException { String impl = resource + ( ( target == null ) ? "" : ( ":" + target ) ); ComponentDescriptor cd = new ComponentDescriptor(); cd.setRole( "invoker" ); cd.setRoleHint( "test" ); cd.setImplementation( impl ); return new AntScriptInvoker( cd, Thread.currentThread().getContextClassLoader() ); } public void testInit_UsingResource_NoTarget() throws IOException, ComponentInstantiationException { AntScriptInvoker invoker = newInvoker( SCRIPT_RESOURCE, null ); assertEquals( SCRIPT_RESOURCE, invoker.getScriptResource() ); assertNull( invoker.getTarget() ); } public void testAddComponentRequirement_ShouldBePresentInReferences() throws IOException, ComponentInstantiationException, ComponentConfigurationException { Object component = new Object(); String role = "role"; String hint = "hint"; ComponentRequirement cr = new ComponentRequirement(); cr.setRole( role ); cr.setRoleHint( hint ); AntScriptInvoker invoker = newInvoker( SCRIPT_RESOURCE, null ); invoker.getDescriptor().addRequirement( cr ); invoker.addComponentRequirement( cr, component ); Map references = invoker.getReferences(); assertTrue( references.containsKey( role + "_" + hint ) ); } public void testSetComponentConfiguration_StringToStringMappingGoesIntoProperties() throws IOException, ComponentInstantiationException, ComponentConfigurationException { AntScriptInvoker invoker = newInvoker( SCRIPT_RESOURCE, null ); Map config = new HashMap(); config.put( "basedir", new File( "." ).getAbsolutePath() ); config.put( "key", "value" ); invoker.setComponentConfiguration( config ); assertEquals( "value", invoker.getProperties().get( "key" ) ); } public void testSetComponentConfiguration_StringToNonStringMappingGoesIntoReferences() throws IOException, ComponentInstantiationException, ComponentConfigurationException { AntScriptInvoker invoker = newInvoker( SCRIPT_RESOURCE, null ); Map config = new HashMap(); config.put( "basedir", new File( "." ).getAbsolutePath() ); Object value = new Object(); config.put( "key", value ); invoker.setComponentConfiguration( config ); assertSame( value, invoker.getReferences().get( "key" ) ); } public void testProjectInstanceConstructedWhenConfigurationIsSet() throws IOException, ComponentInstantiationException, ComponentConfigurationException { AntScriptInvoker invoker = newInvoker( SCRIPT_RESOURCE, null ); Map config = new HashMap(); String basedir = new File( "." ).getAbsolutePath(); config.put( "basedir", basedir ); invoker.setComponentConfiguration( config ); assertNotNull( invoker.getProject() ); assertEquals( new File( basedir ).getCanonicalFile(), invoker.getProject().getBaseDir() ); } public void testExecute() throws IOException, ComponentInstantiationException, ComponentConfigurationException, AntComponentExecutionException { AntScriptInvoker invoker = newInvoker( SCRIPT_RESOURCE, "test" ); Map config = new HashMap(); String basedir = new File( "." ).getAbsolutePath(); File testdir = File.createTempFile( "AntScriptInvoker.", ".dir.tmp" ); testdir.delete(); testdir.mkdirs(); testdir.deleteOnExit(); String testDir = testdir.getCanonicalPath(); config.put( "basedir", basedir ); config.put( "testDir", testDir ); config.put( "messageLevel", "info" ); invoker.setComponentConfiguration( config ); final List messages = new ArrayList(); BuildListener listener = new BuildListener() { public void buildFinished( BuildEvent arg0 ) { } public void buildStarted( BuildEvent arg0 ) { } public void messageLogged( BuildEvent event ) { messages.add( event.getMessage() ); } public void targetFinished( BuildEvent arg0 ) { } public void targetStarted( BuildEvent arg0 ) { } public void taskFinished( BuildEvent arg0 ) { } public void taskStarted( BuildEvent arg0 ) { } }; invoker.getProject().addBuildListener( listener ); invoker.invoke(); boolean found = false; for ( Iterator it = messages.iterator(); it.hasNext(); ) { String message = (String) it.next(); if ( message.indexOf( testDir ) > -1 ) { found = true; break; } } assertTrue( found ); } } plexus-ant-factory-1.0~alpha2.1/src/main/0000755000175000017500000000000011224730071020212 5ustar twernertwernerplexus-ant-factory-1.0~alpha2.1/src/main/resources/0000755000175000017500000000000011224730071022224 5ustar twernertwernerplexus-ant-factory-1.0~alpha2.1/src/main/resources/META-INF/0000755000175000017500000000000011224730071023364 5ustar twernertwernerplexus-ant-factory-1.0~alpha2.1/src/main/resources/META-INF/plexus/0000755000175000017500000000000011224730071024704 5ustar twernertwernerplexus-ant-factory-1.0~alpha2.1/src/main/resources/META-INF/plexus/components.xml0000644000175000017500000000046110315536031027614 0ustar twernertwerner org.codehaus.plexus.component.factory.ComponentFactory org.codehaus.plexus.component.factory.ant.AntComponentFactory ant plexus-ant-factory-1.0~alpha2.1/src/main/java/0000755000175000017500000000000011224730070021132 5ustar twernertwernerplexus-ant-factory-1.0~alpha2.1/src/main/java/org/0000755000175000017500000000000011224730070021721 5ustar twernertwernerplexus-ant-factory-1.0~alpha2.1/src/main/java/org/codehaus/0000755000175000017500000000000011224730070023514 5ustar twernertwernerplexus-ant-factory-1.0~alpha2.1/src/main/java/org/codehaus/plexus/0000755000175000017500000000000011224730070025034 5ustar twernertwernerplexus-ant-factory-1.0~alpha2.1/src/main/java/org/codehaus/plexus/component/0000755000175000017500000000000011224730071027037 5ustar twernertwernerplexus-ant-factory-1.0~alpha2.1/src/main/java/org/codehaus/plexus/component/factory/0000755000175000017500000000000011224730071030506 5ustar twernertwernerplexus-ant-factory-1.0~alpha2.1/src/main/java/org/codehaus/plexus/component/factory/ant/0000755000175000017500000000000011224730071031270 5ustar twernertwerner././@LongLink0000000000000000000000000000015600000000000011567 Lustar rootrootplexus-ant-factory-1.0~alpha2.1/src/main/java/org/codehaus/plexus/component/factory/ant/AntScriptInvoker.javaplexus-ant-factory-1.0~alpha2.1/src/main/java/org/codehaus/plexus/component/factory/ant/AntScriptInv0000644000175000017500000002461611147341104033607 0ustar twernertwernerpackage org.codehaus.plexus.component.factory.ant; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.DefaultLogger; import org.apache.tools.ant.DemuxInputStream; import org.apache.tools.ant.DemuxOutputStream; import org.apache.tools.ant.Main; import org.apache.tools.ant.Project; import org.apache.tools.ant.ProjectHelper; import org.apache.tools.ant.helper.ProjectHelper2; import org.codehaus.plexus.component.MapOrientedComponent; import org.codehaus.plexus.component.configurator.ComponentConfigurationException; import org.codehaus.plexus.component.factory.ComponentInstantiationException; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.component.repository.ComponentRequirement; import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.util.IOUtil; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintStream; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Properties; public class AntScriptInvoker extends AbstractLogEnabled implements MapOrientedComponent { public static final String BASEDIR_PARAMETER = "basedir"; public static final String MESSAGE_LEVEL_PARAMETER = "messageLevel"; private final ComponentDescriptor descriptor; private final File script; private final String scriptResource; private String target; private Map references = new HashMap(); private Properties properties = new Properties(); private Project project; private File basedir; private String messageLevel; public AntScriptInvoker( ComponentDescriptor descriptor, ClassLoader loader ) throws IOException, ComponentInstantiationException { this.descriptor = descriptor; String impl = descriptor.getImplementation(); int colon = impl.indexOf( ":" ); String resourceName; if ( colon > -1 ) { resourceName = impl.substring( 0, colon ); target = impl.substring( colon + 1 ); } else { resourceName = impl; } scriptResource = resourceName; InputStream input = null; OutputStream output = null; try { input = loader.getResourceAsStream( resourceName ); if ( input == null ) { throw new ComponentInstantiationException( "Cannot find Ant script resource: '" + resourceName + "' in classpath of: " + loader ); } script = File.createTempFile( "plexus-ant-component", ".build.xml" ); script.deleteOnExit(); output = new FileOutputStream( script ); IOUtil.copy( input, output ); } finally { IOUtil.close( input ); IOUtil.close( output ); } } public static String[] getImplicitRequiredParameters() { return new String[] { BASEDIR_PARAMETER }; } public static String[] getImplicitOptionalParameters() { return new String[] { MESSAGE_LEVEL_PARAMETER }; } public void addComponentRequirement( ComponentRequirement rd, Object rv ) throws ComponentConfigurationException { if ( !descriptor.getRequirements().contains( rd ) ) { throw new ComponentConfigurationException( "Requirement: " + rd.getHumanReadableKey() + " is not listed in this component's descriptor." ); } references.put( rd.getRole() + "_" + rd.getRoleHint(), rv ); } public void setComponentConfiguration( Map componentConfiguration ) throws ComponentConfigurationException { for ( Iterator it = componentConfiguration.entrySet().iterator(); it.hasNext(); ) { Map.Entry entry = (Map.Entry) it.next(); Object key = entry.getKey(); Object val = entry.getValue(); if ( ( key instanceof String ) && ( val instanceof String ) ) { properties.setProperty( (String) key, (String) val ); } else { references.put( key, val ); } } Object basedirInput = componentConfiguration.get( BASEDIR_PARAMETER ); if ( basedirInput instanceof File ) { this.basedir = (File) basedirInput; } else if ( basedirInput != null ) { this.basedir = new File( String.valueOf( basedirInput ) ); } else { throw new ComponentConfigurationException( "\'" + BASEDIR_PARAMETER + "\' parameter is missing." ); } Object messageLevelInput = componentConfiguration.get( MESSAGE_LEVEL_PARAMETER ); if ( messageLevelInput != null ) { this.messageLevel = String.valueOf( messageLevelInput ); } // ---------------------------------------------------------------------------- // We need things like the basedir in order to initialize the ant project and // we need to initialize the project here so that it can be augmented with // classpath references and other properties before the ant task execution. // This is a little brittle as we're relying on a call for configuration // to signal ant project initialization ... jvz. // ---------------------------------------------------------------------------- initializeProject(); } public void invoke() throws AntComponentExecutionException { InputStream oldSysIn = System.in; PrintStream oldSysOut = System.out; PrintStream oldSysErr = System.err; try { project.setDefaultInputStream( System.in ); System.setIn( new DemuxInputStream( project ) ); System.setOut( new PrintStream( new DemuxOutputStream( project, false ) ) ); System.setErr( new PrintStream( new DemuxOutputStream( project, true ) ) ); project.fireBuildStarted(); Throwable error = null; try { try { ProjectHelper helper = new ProjectHelper2(); project.addReference( "ant.projectHelper", helper ); helper.parse( project, script ); } catch ( BuildException ex ) { error = ex; throw new AntComponentExecutionException( scriptResource, target, "Failed to parse.", ex ); } try { project.executeTarget( target ); } catch ( BuildException e ) { error = e; throw new AntComponentExecutionException( scriptResource, target, "Failed to execute.", e ); } } finally { project.fireSubBuildFinished( error ); } } finally { // help the gc project = null; System.setIn( oldSysIn ); System.setOut( oldSysOut ); System.setErr( oldSysErr ); } } private void initializeProject() { this.project = new Project(); project.init(); project.setUserProperty( "ant.version", Main.getAntVersion() ); project.setProperty( "ant.file", script.toString() ); DefaultLogger antLogger = new DefaultLogger(); antLogger.setOutputPrintStream( System.out ); antLogger.setErrorPrintStream( System.err ); int level = convertMsgLevel( messageLevel ); Logger logger = getLogger(); if ( logger != null ) { logger.debug( "Ant message level is set to: " + messageLevel + "(" + level + ")" ); } antLogger.setMessageOutputLevel( level ); project.addBuildListener( antLogger ); project.setBaseDir( basedir ); for ( Iterator it = references.entrySet().iterator(); it.hasNext(); ) { Map.Entry entry = (Map.Entry) it.next(); String key = (String) entry.getKey(); project.addReference( key, entry.getValue() ); } for ( Iterator it = properties.entrySet().iterator(); it.hasNext(); ) { Map.Entry entry = (Map.Entry) it.next(); String key = (String) entry.getKey(); project.setUserProperty( key, properties.getProperty( key ) ); } } protected int convertMsgLevel( String msgLevel ) { int level; if ( msgLevel == null ) { return Project.MSG_ERR; } msgLevel = msgLevel.toLowerCase(); if ( msgLevel.equals( "error" ) ) { level = Project.MSG_ERR; } else if ( msgLevel.equals( "warning" ) || msgLevel.equals( "warn" ) ) { level = Project.MSG_WARN; } else if ( msgLevel.equals( "information" ) || msgLevel.equals( "info" ) ) { level = Project.MSG_INFO; } else if ( msgLevel.equals( "debug" ) ) { level = Project.MSG_DEBUG; } else if ( msgLevel.equals( "verbose" ) ) { level = Project.MSG_VERBOSE; } else { Logger logger = getLogger(); if ( logger != null ) { logger.info( "Unknown Ant Message Level (" + msgLevel + ") -- using \"error\" instead" ); } level = Project.MSG_ERR; } return level; } public Project getProject() { return project; } public ComponentDescriptor getDescriptor() { return descriptor; } public File getScript() { return script; } public String getScriptResource() { return scriptResource; } public String getTarget() { return target; } public Map getReferences() { return references; } public Properties getProperties() { return properties; } public File getBasedir() { return basedir; } public String getMessageLevel() { return messageLevel; } } ././@LongLink0000000000000000000000000000016100000000000011563 Lustar rootrootplexus-ant-factory-1.0~alpha2.1/src/main/java/org/codehaus/plexus/component/factory/ant/AntComponentFactory.javaplexus-ant-factory-1.0~alpha2.1/src/main/java/org/codehaus/plexus/component/factory/ant/AntComponent0000644000175000017500000000202311147341104033614 0ustar twernertwernerpackage org.codehaus.plexus.component.factory.ant; import org.codehaus.classworlds.ClassRealm; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.component.factory.AbstractComponentFactory; import org.codehaus.plexus.component.factory.ComponentInstantiationException; import org.codehaus.plexus.component.repository.ComponentDescriptor; import java.io.IOException; public class AntComponentFactory extends AbstractComponentFactory { public Object newInstance( ComponentDescriptor componentDescriptor, ClassRealm classRealm, PlexusContainer container ) throws ComponentInstantiationException { try { return new AntScriptInvoker( componentDescriptor, new RealmDelegatingClassLoader( classRealm ) ); } catch ( IOException e ) { throw new ComponentInstantiationException( "Failed to extract Ant script for: " + componentDescriptor.getHumanReadableKey(), e ); } } public String getId() { return "ant"; } } ././@LongLink0000000000000000000000000000017400000000000011567 Lustar rootrootplexus-ant-factory-1.0~alpha2.1/src/main/java/org/codehaus/plexus/component/factory/ant/AntComponentExecutionException.javaplexus-ant-factory-1.0~alpha2.1/src/main/java/org/codehaus/plexus/component/factory/ant/AntComponent0000644000175000017500000000233510325337134033627 0ustar twernertwernerpackage org.codehaus.plexus.component.factory.ant; public class AntComponentExecutionException extends Exception { static final long serialVersionUID = 1; private final String script; private final String target; private final String originalMessage; public AntComponentExecutionException( String script, String target, String message, Throwable cause ) { super( "Executing Ant script: " + script + " [" + ( ( target == null ) ? ( "default-target" ) : ( target ) ) + "]: " + message, cause ); this.script = script; this.target = target; this.originalMessage = message; } public AntComponentExecutionException( String script, String target, String message ) { super( "Executing Ant script: " + script + " [" + ( ( target == null ) ? ( "default-target" ) : ( target ) ) + "]: " + message ); this.script = script; this.target = target; this.originalMessage = message; } public final String getOriginalMessage() { return originalMessage; } public final String getScript() { return script; } public final String getTarget() { return target; } } ././@LongLink0000000000000000000000000000017000000000000011563 Lustar rootrootplexus-ant-factory-1.0~alpha2.1/src/main/java/org/codehaus/plexus/component/factory/ant/RealmDelegatingClassLoader.javaplexus-ant-factory-1.0~alpha2.1/src/main/java/org/codehaus/plexus/component/factory/ant/RealmDelegat0000644000175000017500000000164110325337134033547 0ustar twernertwernerpackage org.codehaus.plexus.component.factory.ant; import org.codehaus.classworlds.ClassRealm; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.util.Enumeration; /** * @author jdcasey */ public class RealmDelegatingClassLoader extends ClassLoader { private final ClassRealm realm; public RealmDelegatingClassLoader(ClassRealm realm) { this.realm = realm; } protected Enumeration findResources( String name ) throws IOException { return realm.findResources( name ); } public URL getResource( String name ) { return realm.getResource( name ); } public InputStream getResourceAsStream( String name ) { return realm.getResourceAsStream( name ); } public Class loadClass( String name ) throws ClassNotFoundException { return realm.loadClass( name ); } } plexus-ant-factory-1.0~alpha2.1/pom.xml0000644000175000017500000000270011147341104020012 0ustar twernertwerner plexus-component-factories org.codehaus.plexus 1.0-alpha-8 4.0.0 plexus-ant-factory Plexus Ant Factory 1.0-alpha-2.1 org.apache.ant ant-launcher 1.7.1 org.apache.ant ant 1.7.1 org.codehaus.plexus plexus-utils 1.0.5 org.codehaus.plexus plexus-container-default 1.0-alpha-9-stable-1 scm:svn:http://svn.codehaus.org/plexus/tags/plexus-ant-factory-1.0-alpha-2.1 scm:svn:https://svn.codehaus.org/plexus/tags/plexus-ant-factory-1.0-alpha-2.1