another pass at integration, not ready.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@289142 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-09-15 04:26:09 +00:00
parent d31da596ee
commit 9149ba0904
4 changed files with 124 additions and 40 deletions

View File

@ -1,5 +1,5 @@
<model xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <model xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent> <parent>
<artifactId>maven</artifactId> <artifactId>maven</artifactId>
<groupId>org.apache.maven</groupId> <groupId>org.apache.maven</groupId>
@ -12,12 +12,18 @@
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>plexus</groupId> <groupId>plexus</groupId>
<artifactId>plexus-container-default</artifactId> <artifactId>plexus-utils</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>forehead</groupId> <groupId>plexus</groupId>
<artifactId>forehead</artifactId> <artifactId>plexus-container-default</artifactId>
<version>1.0-beta-5</version>
</dependency> </dependency>
<!--
<dependency>
<groupId>forehead</groupId>
<artifactId>forehead</artifactId>
<version>1.0-beta-5</version>
</dependency>
-->
</dependencies> </dependencies>
</model> </model>

View File

@ -16,21 +16,17 @@ package org.apache.maven.legacy;
* limitations under the License. * limitations under the License.
*/ */
import com.werken.forehead.Forehead; import org.codehaus.plexus.logging.AbstractLogEnabled;
import com.werken.forehead.ForeheadClassLoader; import org.codehaus.plexus.util.cli.CommandLineException;
import org.codehaus.plexus.util.cli.CommandLineUtils;
import org.codehaus.plexus.util.cli.Commandline;
import org.codehaus.plexus.util.cli.DefaultConsumer;
import org.codehaus.plexus.util.cli.StreamConsumer;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.util.Arrays;
import java.util.Date;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.lang.reflect.*;
import java.net.*;
import org.codehaus.plexus.logging.AbstractLogEnabled;
/** /**
* @author <a href="mailto:brett@apache.org">Brett Porter</a> * @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id$ * @version $Id$
@ -40,8 +36,8 @@ public class DefaultMaven1xIntegration
implements Maven1xIntegration implements Maven1xIntegration
{ {
private String mavenHome; private String mavenHome;
private String mavenHomeLocal;
private String mavenHomeLocal;
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// Execution // Execution
@ -49,47 +45,98 @@ public class DefaultMaven1xIntegration
// TODO: may want an executionresponse returned? If so, that may need to be part of another component // TODO: may want an executionresponse returned? If so, that may need to be part of another component
public void execute( File project, List goals ) public void execute( File project, List goals )
throws Maven1xIntegrationException
{ {
// TODO: need real integration Commandline cl = new Commandline();
String exec = "maven";
if ( mavenHome != null )
{
exec = mavenHome + "/bin/" + exec;
cl.createArgument().setValue( "-Dmaven.home=" + mavenHome );
}
if ( mavenHomeLocal != null )
{
cl.createArgument().setValue( "-Dmaven.home.local=" + mavenHomeLocal );
}
cl.setExecutable( exec );
cl.setWorkingDirectory( project.getParentFile().getAbsolutePath() );
for ( Iterator i = goals.iterator(); i.hasNext(); )
{
cl.createArgument().setValue( (String) i.next() );
}
StreamConsumer consumer = new DefaultConsumer();
try try
{ {
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); int exitCode = CommandLineUtils.executeCommandLine( cl, consumer, consumer );
URL foreheadUrl = new File( mavenHome, "lib/forehead-1.0-beta-5.jar" ).toURL(); if ( exitCode != 0 )
{
throw new Maven1xIntegrationException( "Received exit code " + exitCode + " from Maven" );
}
}
catch ( CommandLineException e )
{
throw new Maven1xIntegrationException( "Can't run goals " + goals, e );
}
// TODO: need better integration, requires changes in Maven 1.1 - also want to avoid a dep on forehead in m2/lib
try
{
/*
File foreheadConf = new File( mavenHome, "bin/forehead.conf" ); File foreheadConf = new File( mavenHome, "bin/forehead.conf" );
System.setProperty( "tools.jar", "file:" + System.getProperty( "java.home" ) + "/lib/tools.jar" );
System.setProperty( "maven.home", mavenHome );
System.setProperty( "maven.home.local", mavenHome );
Forehead.getInstance().config( new FileReader( foreheadConf ) );
// TODO: this currently System.exit()s
Forehead.getInstance().run( (String[]) goals.toArray( EMPTY_STRING_ARRAY ) );
*/
/*
URL foreheadUrl = new File( mavenHome, "lib/forehead-1.0-beta-5.jar" ).toURL();
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
ClassLoader cl = URLClassLoader.newInstance( new URL[] { foreheadUrl } ); ClassLoader cl = URLClassLoader.newInstance( new URL[] { foreheadUrl } );
Class c = Class.forName( "com.werken.forehead.Forehead", true, cl ); Class c = Class.forName( "com.werken.forehead.Forehead", true, cl );
Method m = c.getMethod( "getInstance", new Class[] {} ); Method m = c.getMethod( "getInstance", new Class[] {} );
Object forehead = m.invoke( null, new Object[] {} ); Object forehead = m.invoke( null, new Object[] {} );
System.setProperty( "maven.home", mavenHome );
System.setProperty( "tools.jar", "file:" + System.getProperty( "java.home" ) + "/lib/tools.jar" );
m = c.getMethod( "config", new Class[] { java.io.InputStream.class } ); m = c.getMethod( "config", new Class[] { java.io.InputStream.class } );
m.invoke( forehead, new Object[] { new FileInputStream( foreheadConf ) } ); m.invoke( forehead, new Object[] { new FileInputStream( foreheadConf ) } );
System.setProperty( "user.dir", project.getParentFile().getAbsolutePath() ); System.setProperty( "user.dir", project.getParentFile().getAbsolutePath() );
/*m = c.getMethod( "getClassLoader", new Class[] { String.class } ); */
cl = ( ClassLoader ) m.invoke( forehead, new Object[] { "root.maven" } );
/*
m = c.getMethod( "getClassLoader", new Class[]{String.class} );
cl = (ClassLoader) m.invoke( forehead, new Object[]{"root.maven"} );
Thread.currentThread().setContextClassLoader( cl ); Thread.currentThread().setContextClassLoader( cl );
c = Class.forName( "org.apache.maven.cli.App", true, cl ); c = Class.forName( "org.apache.maven.cli.App", true, cl );
Object app = c.newInstance(); Object app = c.newInstance();
m = c.getMethod( "initialize", new Class[] { String[].class } ); m = c.getMethod( "initialize", new Class[]{String[].class} );
m.invoke( app, new Object[] { (String[]) goals.toArray( new String[0] ) } ); m.invoke( app, new Object[]{(String[]) goals.toArray( new String[0] )} );
Object session = c.getDeclaredField( "mavenSession" ).get( app ); Object session = c.getDeclaredField( "mavenSession" ).get( app );
m = session.getClass().getMethod( "initialize", new Class[0] ); m = session.getClass().getMethod( "initialize", new Class[0] );
m.invoke( session, new Object[0] ); m.invoke( session, new Object[0] );
m = session.getClass().getMethod( "getRootProject", new Class[0] ); m = session.getClass().getMethod( "getRootProject", new Class[0] );
Object p = m.invoke( session, new Object[0] ); Object p = m.invoke( session, new Object[0] );
m = session.getClass().getMethod( "attainGoals", new Class[] { p.getClass(), List.class } ); m = session.getClass().getMethod( "attainGoals", new Class[]{p.getClass(), List.class} );
m.invoke( session, new Object[] { p, goals } ); */ m.invoke( session, new Object[]{p, goals} );
*/
/*
// TODO: this currently system.exit's // TODO: this currently system.exit's
m = c.getMethod( "run", new Class[] { String[].class } ); m = c.getMethod( "run", new Class[]{String[].class} );
m.invoke( forehead, new Object[] { (String[]) goals.toArray( new String[0] ) } ); m.invoke( forehead, new Object[]{(String[]) goals.toArray( new String[0] )} );
Thread.currentThread().setContextClassLoader( oldClassLoader ); Thread.currentThread().setContextClassLoader( oldClassLoader );
*/
} }
catch ( Exception e ) catch ( Exception e )
{ {
// TODO: handle this throw new Maven1xIntegrationException( "Error executing Maven 1.x", e );
e.printStackTrace();
} }
} }

View File

@ -31,14 +31,8 @@ public interface Maven1xIntegration
// Execution // Execution
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
void execute( File project, List goals ); void execute( File project, List args, List goals )
throws Maven1xIntegrationException;
// ----------------------------------------------------------------------
// Reactor execution
// ----------------------------------------------------------------------
// TODO: perhaps?
// ExecutionResponse executeReactor( String goal, String includes, String excludes );
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// Maven home // Maven home

View File

@ -0,0 +1,37 @@
package org.apache.maven.legacy;
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Exception in the Maven 1.x integration.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id$
*/
public class Maven1xIntegrationException
extends Exception
{
public Maven1xIntegrationException( String message )
{
super( message );
}
public Maven1xIntegrationException( String msg, Exception e )
{
super( msg, e );
}
}