diff --git a/maven-1.x-integration/README.txt b/maven-1.x-integration/README.txt new file mode 100644 index 0000000000..395314a542 --- /dev/null +++ b/maven-1.x-integration/README.txt @@ -0,0 +1,14 @@ +Maven 1.x Integration + +This component will internally spawn a complete Maven 1.x instance +that will run a project from within m2, using a specified version of +Maven 1.x. + +This will allow a mix of m2 and m1 projects in a single organization +with only one installation, aiding the transition. + +Work in progress, Brett Porter, 18/8/04 + + +Currently it does require an m1 installation to obtain the plugins installed. It could potentially use +the plugin descriptor file for this. diff --git a/maven-1.x-integration/pom.xml b/maven-1.x-integration/pom.xml new file mode 100644 index 0000000000..ebb451ceeb --- /dev/null +++ b/maven-1.x-integration/pom.xml @@ -0,0 +1,25 @@ + + + + 4.0.0 + + maven + maven-component + 2.0-SNAPSHOT + + maven + maven-1.x-integration + Maven 1.x Compatibility + 2.0-SNAPSHOT + 2004 + org.apache.maven.legacy + + + + + forehead + forehead + 1.0-beta-5 + + + diff --git a/maven-1.x-integration/src/main/java/org/apache/maven/legacy/DefaultMaven1xIntegration.java b/maven-1.x-integration/src/main/java/org/apache/maven/legacy/DefaultMaven1xIntegration.java new file mode 100644 index 0000000000..9dea5c071f --- /dev/null +++ b/maven-1.x-integration/src/main/java/org/apache/maven/legacy/DefaultMaven1xIntegration.java @@ -0,0 +1,117 @@ +package org.apache.maven.legacy; + +/* + * Copyright 2001-2004 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. + */ + +import com.werken.forehead.Forehead; +import com.werken.forehead.ForeheadClassLoader; + +import java.io.File; +import java.io.FileInputStream; +import java.util.Arrays; +import java.util.Date; +import java.util.Iterator; +import java.util.List; + +import java.lang.reflect.*; +import java.net.*; + +import org.codehaus.plexus.logging.AbstractLogEnabled; + +/** + * @author Brett Porter + * @version $Id$ + */ +public class DefaultMaven1xIntegration + extends AbstractLogEnabled + implements Maven1xIntegration +{ + private String mavenHome; + private String mavenHomeLocal; + + + // ---------------------------------------------------------------------- + // Execution + // ---------------------------------------------------------------------- + + // TODO: may want an executionresponse returned? If so, that may need to be part of another component + public void execute( File project, List goals ) + { + // TODO: need real integration + try + { + ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); + URL foreheadUrl = new File( mavenHome, "lib/forehead-1.0-beta-5.jar" ).toURL(); + File foreheadConf = new File( mavenHome, "bin/forehead.conf" ); + ClassLoader cl = URLClassLoader.newInstance( new URL[] { foreheadUrl } ); + Class c = Class.forName( "com.werken.forehead.Forehead", true, cl ); + Method m = c.getMethod( "getInstance", new Class[] {} ); + 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.invoke( forehead, new Object[] { new FileInputStream( foreheadConf ) } ); + + System.setProperty( "user.dir", project.getParentFile().getAbsolutePath() ); + /*m = c.getMethod( "getClassLoader", new Class[] { String.class } ); + cl = ( ClassLoader ) m.invoke( forehead, new Object[] { "root.maven" } ); + Thread.currentThread().setContextClassLoader( cl ); + c = Class.forName( "org.apache.maven.cli.App", true, cl ); + Object app = c.newInstance(); + m = c.getMethod( "initialize", new Class[] { String[].class } ); + m.invoke( app, new Object[] { (String[]) goals.toArray( new String[0] ) } ); + Object session = c.getDeclaredField( "mavenSession" ).get( app ); + m = session.getClass().getMethod( "initialize", new Class[0] ); + m.invoke( session, new Object[0] ); + m = session.getClass().getMethod( "getRootProject", new Class[0] ); + Object p = m.invoke( session, new Object[0] ); + m = session.getClass().getMethod( "attainGoals", new Class[] { p.getClass(), List.class } ); + m.invoke( session, new Object[] { p, goals } ); */ + + // TODO: this currently system.exit's + m = c.getMethod( "run", new Class[] { String[].class } ); + m.invoke( forehead, new Object[] { (String[]) goals.toArray( new String[0] ) } ); + Thread.currentThread().setContextClassLoader( oldClassLoader ); + } + catch ( Exception e ) + { + // TODO: handle this + e.printStackTrace(); + } + } + + public void setMavenHome( String mavenHome ) + { + this.mavenHome = mavenHome; + } + + public String getMavenHome() + { + return mavenHome; + } + + public void setMavenHomeLocal( String mavenHomeLocal ) + { + this.mavenHomeLocal = mavenHomeLocal; + } + + public String getMavenHomeLocal() + { + return mavenHomeLocal; + } + +} + diff --git a/maven-1.x-integration/src/main/java/org/apache/maven/legacy/Maven1xIntegration.java b/maven-1.x-integration/src/main/java/org/apache/maven/legacy/Maven1xIntegration.java new file mode 100644 index 0000000000..93bc9e5eaa --- /dev/null +++ b/maven-1.x-integration/src/main/java/org/apache/maven/legacy/Maven1xIntegration.java @@ -0,0 +1,54 @@ +package org.apache.maven.legacy; + +/* + * Copyright 2001-2004 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. + */ + +import java.io.File; +import java.util.List; + +/** + * @author Brett Porter + * @version $Id$ + */ +public interface Maven1xIntegration +{ + static String ROLE = Maven1xIntegration.class.getName(); + + // ---------------------------------------------------------------------- + // Execution + // ---------------------------------------------------------------------- + + void execute( File project, List goals ); + + // ---------------------------------------------------------------------- + // Reactor execution + // ---------------------------------------------------------------------- + + // TODO: perhaps? + // ExecutionResponse executeReactor( String goal, String includes, String excludes ); + + // ---------------------------------------------------------------------- + // Maven home + // ---------------------------------------------------------------------- + void setMavenHome( String mavenHome ); + + String getMavenHome(); + + void setMavenHomeLocal( String mavenHomeLocal ); + + String getMavenHomeLocal(); +} + diff --git a/maven-1.x-integration/src/main/resources/META-INF/plexus/components.xml b/maven-1.x-integration/src/main/resources/META-INF/plexus/components.xml new file mode 100644 index 0000000000..2c0087705a --- /dev/null +++ b/maven-1.x-integration/src/main/resources/META-INF/plexus/components.xml @@ -0,0 +1,16 @@ + + + + + + org.apache.maven.legacy.Maven1xIntegration + org.apache.maven.legacy.DefaultMaven1xIntegration + + + + +