diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java index b08172bffa..41bcc74705 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java @@ -144,18 +144,10 @@ public class MavenCli } MavenEmbedder mavenEmbedder; - MavenEmbedderLogger logger; try { mavenEmbedder = new MavenEmbedder( configuration ); - - logger = mavenEmbedder.getLogger(); - - if ( mavenEmbedder.isOffline( request ) ) - { - logger.info( "You are working in offline mode." ); - } } catch ( MavenEmbedderException e ) { diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java b/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java index b74adec8e5..e7a4f42722 100644 --- a/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java +++ b/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java @@ -118,7 +118,7 @@ public class MavenEmbedder private Configuration configuration; - private MavenExecutionRequest request; + //private MavenExecutionRequest request; // ---------------------------------------------------------------------------- // Constructors @@ -130,10 +130,12 @@ public class MavenEmbedder start( embedderConfiguration ); } + /* public MavenExecutionRequest getDefaultRequest() { return request; } + */ // ---------------------------------------------------------------------- // Accessors @@ -144,6 +146,7 @@ public class MavenEmbedder return classWorld; } + /* public ArtifactRepository getLocalRepository() { return request.getLocalRepository(); @@ -153,6 +156,7 @@ public class MavenEmbedder { return request.getSettings(); } + */ public MavenEmbedderLogger getLogger() { @@ -261,65 +265,6 @@ public class MavenEmbedder } } - // ---------------------------------------------------------------------- - // Project - // ---------------------------------------------------------------------- - - public MavenProject readProject( File mavenProject ) - throws ProjectBuildingException, MavenExecutionException - { - return readProject( mavenProject, request ); - } - - private MavenProject readProject( File mavenProject, MavenExecutionRequest request ) - throws ProjectBuildingException, MissingModuleException - { - getLogger().debug( "Building MavenProject instance: " + mavenProject ); - - return projectBuilder.build( mavenProject, request.getProjectBuildingRequest() ); - } - - /** - * This method is used to grab the list of dependencies that belong to a project so that a UI - * can be populated. For example, a list of libraries that are used by an Eclipse, Netbeans, or - * IntelliJ project. - */ - - // currently in m2eclipse each project is read read a single project for dependencies - // Project - // Exceptions - // explicit for exceptions where coordinate are involved. - // m2eclipse is not using the topological sorting at all because it keeps track itself. - - public MavenExecutionResult readProjectWithDependencies( MavenExecutionRequest request ) - { - MavenExecutionResult result = new DefaultMavenExecutionResult(); - - try - { - request = populator.populateDefaults( request, configuration ); - } - catch ( MavenEmbedderException e ) - { - return result.addException( e ); - } - - try - { - MavenProjectBuildingResult projectBuildingResult = projectBuilder.buildProjectWithDependencies( request.getPom(), request.getProjectBuildingRequest() ); - - result.setProject( projectBuildingResult.getProject() ); - - result.setArtifactResolutionResult( projectBuildingResult.getArtifactResolutionResult() ); - - return result; - } - catch ( ProjectBuildingException e ) - { - return result.addException( e ); - } - } - // ---------------------------------------------------------------------- // Lifecycle // ---------------------------------------------------------------------- @@ -397,9 +342,9 @@ public class MavenEmbedder // This is temporary as we can probably cache a single request and use it for default values and // simply cascade values in from requests used for individual executions. - request = new DefaultMavenExecutionRequest(); - - populator.populateDefaults( request, configuration ); + //request = new DefaultMavenExecutionRequest(); + // + //populator.populateDefaults( request, configuration ); } catch ( ComponentLookupException e ) { @@ -496,18 +441,6 @@ public class MavenEmbedder return configuration; } - // ---------------------------------------------------------------------- - // Start of new embedder API - // ---------------------------------------------------------------------- - - public boolean isOffline( MavenExecutionRequest request ) - throws MavenEmbedderException - { - request = populator.populateDefaults( request, configuration ); - - return request.isOffline(); - } - public MavenExecutionResult execute( MavenExecutionRequest request ) { LoggerManager loggerManager = container.getLoggerManager(); @@ -520,7 +453,7 @@ public class MavenEmbedder try { - request = populator.populateDefaults( request, configuration ); + request = populator.populateDefaults( request ); } catch ( MavenEmbedderException e ) { diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestPopulator.java b/maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestPopulator.java index 92ff98623f..5993c2cd2a 100644 --- a/maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestPopulator.java +++ b/maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestPopulator.java @@ -23,7 +23,6 @@ import java.util.Set; import org.apache.maven.Maven; import org.apache.maven.artifact.InvalidRepositoryException; import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.embedder.Configuration; import org.apache.maven.embedder.MavenEmbedder; import org.apache.maven.embedder.MavenEmbedderException; import org.apache.maven.execution.MavenExecutionRequest; @@ -36,12 +35,10 @@ import org.apache.maven.settings.SettingsUtils; import org.apache.maven.toolchain.ToolchainsBuilder; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; -import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.util.StringUtils; @Component(role = MavenExecutionRequestPopulator.class) public class DefaultMavenExecutionRequestPopulator - extends AbstractLogEnabled implements MavenExecutionRequestPopulator { //TODO: this needs to be pushed up to the front-end @@ -54,45 +51,6 @@ public class DefaultMavenExecutionRequestPopulator @Requirement private ToolchainsBuilder toolchainsBuilder; - public MavenExecutionRequest populateDefaults( MavenExecutionRequest request, Configuration configuration ) - throws MavenEmbedderException - { - // copy configuration to request - if ( request.getSettings() == null ) - { - if ( configuration.getGlobalSettingsFile() != null ) - { - request.setGlobalSettingsFile( configuration.getGlobalSettingsFile() ); - } - - if ( configuration.getUserSettingsFile() != null ) - { - request.setUserSettingsFile( configuration.getUserSettingsFile() ); - } - } - - String localRepositoryPath = null; - - if ( request.getLocalRepositoryPath() != null ) - { - localRepositoryPath = request.getLocalRepositoryPath().getAbsolutePath(); - } - - if ( StringUtils.isEmpty( localRepositoryPath ) && ( configuration.getLocalRepository() != null ) ) - { - localRepositoryPath = configuration.getLocalRepository().getAbsolutePath(); - } - - if ( !StringUtils.isEmpty( localRepositoryPath ) ) - { - request.setLocalRepositoryPath( localRepositoryPath ); - } - - // populate the defaults - - return populateDefaults( request ); - } - private void pom( MavenExecutionRequest request ) { if ( request.getPom() != null && !request.getPom().isAbsolute() ) diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/execution/MavenExecutionRequestPopulator.java b/maven-embedder/src/main/java/org/apache/maven/embedder/execution/MavenExecutionRequestPopulator.java index 055e32293a..79742a5338 100644 --- a/maven-embedder/src/main/java/org/apache/maven/embedder/execution/MavenExecutionRequestPopulator.java +++ b/maven-embedder/src/main/java/org/apache/maven/embedder/execution/MavenExecutionRequestPopulator.java @@ -19,17 +19,11 @@ package org.apache.maven.embedder.execution; * under the License. */ -import org.apache.maven.embedder.Configuration; import org.apache.maven.embedder.MavenEmbedderException; import org.apache.maven.execution.MavenExecutionRequest; public interface MavenExecutionRequestPopulator { - String ROLE = MavenExecutionRequestPopulator.class.getName(); - - MavenExecutionRequest populateDefaults( MavenExecutionRequest request, Configuration configuration ) - throws MavenEmbedderException; - MavenExecutionRequest populateDefaults( MavenExecutionRequest request ) throws MavenEmbedderException; diff --git a/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderProjectWithExtensionReadingTest.java b/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderProjectWithExtensionReadingTest.java deleted file mode 100644 index a65d5790b9..0000000000 --- a/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderProjectWithExtensionReadingTest.java +++ /dev/null @@ -1,108 +0,0 @@ -package org.apache.maven.embedder; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.Map; - -import org.apache.maven.artifact.handler.ArtifactHandler; -import org.apache.maven.execution.DefaultMavenExecutionRequest; -import org.apache.maven.execution.MavenExecutionRequest; -import org.apache.maven.execution.MavenExecutionResult; -import org.apache.maven.model.Plugin; -import org.apache.maven.plugin.PluginManagerException; -import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.component.repository.ComponentDescriptor; -import org.codehaus.plexus.component.repository.exception.ComponentLookupException; -import org.codehaus.plexus.logging.Logger; - -/** @author Jason van Zyl */ -public class MavenEmbedderProjectWithExtensionReadingTest - extends MavenEmbedderTest -{ - public void testProjectWithExtensionsReading() - throws Exception - { - MavenExecutionRequest request = new DefaultMavenExecutionRequest().setShowErrors( true ) - .setPom( new File( basedir, "src/test/resources/pom2.xml" ) ) - // TODO: Remove this! - .setLoggingLevel( Logger.LEVEL_DEBUG ); - - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - - MavenEmbedder embedder = new ExtendableMavenEmbedder( classLoader ); - - // Here we take the artifact handler and programmatically place it into the container - - ComponentDescriptor cd = new ComponentDescriptor(); - - cd.setRole( ArtifactHandler.ROLE ); - - cd.setRoleHint( "mkleint" ); - - cd.setImplementation( MyArtifactHandler.class.getName() ); - - embedder.getPlexusContainer().addComponentDescriptor( cd ); - - // At this point the artifact handler will be inside the container and - // Maven internally will pick up the artifact handler and use it accordingly to - // create the classpath appropriately. - - MavenExecutionResult result = embedder.readProjectWithDependencies( request ); - - assertNoExceptions( result ); - - // sources, test sources, and the junit jar.. - - assertEquals( 3, result.getProject().getTestClasspathElements().size() ); - } - - private class ExtendableMavenEmbedder - extends MavenEmbedder - { - - public ExtendableMavenEmbedder( ClassLoader classLoader ) - throws MavenEmbedderException - { - super( new SimpleConfiguration().setClassLoader( classLoader ) ); - } - - protected Map getPluginExtensionComponents( Plugin plugin ) - throws PluginManagerException - { - try - { - return getPlexusContainer().lookupMap( ArtifactHandler.class ); - } - catch ( ComponentLookupException e ) - { - throw new PluginManagerException( plugin, null ); - } - - } - - protected void verifyPlugin( Plugin plugin, - MavenProject project ) - { - //ignore don't want to actually verify in test - } - } - -} diff --git a/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderTest.java b/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderTest.java index 12f17ce97d..7f2fde8962 100644 --- a/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderTest.java +++ b/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderTest.java @@ -23,10 +23,8 @@ import java.io.File; import java.io.IOException; import java.io.Reader; import java.io.Writer; -import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Set; import junit.framework.TestCase; @@ -57,7 +55,6 @@ public class MavenEmbedderTest protected MavenEmbedder mavenEmbedder; - protected void setUp() throws Exception { @@ -321,11 +318,13 @@ public class MavenEmbedderTest // Repository // ---------------------------------------------------------------------- + /* public void testLocalRepositoryRetrieval() throws Exception { assertNotNull( mavenEmbedder.getLocalRepository().getBasedir() ); } + */ // ---------------------------------------------------------------------- // Model Reading @@ -343,79 +342,6 @@ public class MavenEmbedderTest assertEquals( "org.apache.maven", model.getGroupId() ); } - public void testProjectReading() - throws Exception - { - MavenExecutionRequest request = new DefaultMavenExecutionRequest().setShowErrors( true ).setPom( getPomFile() ); - - MavenExecutionResult result = mavenEmbedder.readProjectWithDependencies( request ); - - assertNoExceptions( result ); - - assertEquals( "org.apache.maven", result.getProject().getGroupId() ); - - Set artifacts = result.getProject().getArtifacts(); - - assertEquals( 1, artifacts.size() ); - - artifacts.iterator().next(); - } - - public void testProjectReadingNoDependencies() - throws Exception - { - MavenExecutionRequest request = - new DefaultMavenExecutionRequest().setShowErrors( true ).setPom( - getPomFile( "pom-without-dependencies.xml" ) ); - - MavenExecutionResult result = mavenEmbedder.readProjectWithDependencies( request ); - - assertNoExceptions( result ); - - assertEquals( new ArrayList(), new ArrayList( result.getProject().getArtifacts() ) ); - } - - public void testProjectReading_FromChildLevel_ScmInheritanceCalculations() - throws Exception - { - File pomFile = new File( basedir, "src/test/projects/readProject-withScmInheritance/modules/child1/pom.xml" ); - - MavenProject project = mavenEmbedder.readProject( pomFile ); - assertNotNull(project.getScm()); - assertEquals( "http://host/viewer?path=/trunk/parent/modules/child1", project.getScm().getUrl() ); - assertEquals( "scm:svn:http://host/trunk/parent/modules/child1", project.getScm().getConnection() ); - assertEquals( "scm:svn:https://host/trunk/parent/modules/child1", project.getScm().getDeveloperConnection() ); - } - - public void testProjectReading_SkipMissingModuleSilently() - throws Exception - { - File pomFile = new File( basedir, - "src/test/projects/readProject-missingModuleIgnored/pom.xml" ); - - mavenEmbedder.readProject( pomFile ); - } - - public void testProjectReadingWithDistributionStatus() - throws Exception - { - File pom = new File( basedir, "src/test/resources/pom-with-distribution-status.xml" ); - MavenExecutionRequest request = new DefaultMavenExecutionRequest().setShowErrors( true ) - .setPom( pom ); - - MavenProject project = mavenEmbedder.readProject( pom ); - - assertEquals( "deployed", project.getDistributionManagement().getStatus() ); - - MavenExecutionResult result = mavenEmbedder.readProjectWithDependencies( request ); - - assertNoExceptions( result ); - - assertEquals( "org.apache.maven", result.getProject().getGroupId() ); - - assertEquals( "deployed", result.getProject().getDistributionManagement().getStatus() ); - } - // ---------------------------------------------------------------------------- // Model Writing // ---------------------------------------------------------------------------- diff --git a/maven-embedder/src/test/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestPopulatorTest.java b/maven-embedder/src/test/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestPopulatorTest.java deleted file mode 100644 index 9db04b9f3e..0000000000 --- a/maven-embedder/src/test/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestPopulatorTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.apache.maven.embedder.execution; - -import org.apache.maven.embedder.DefaultConfiguration; -import org.apache.maven.embedder.MavenEmbedderException; -import org.apache.maven.execution.DefaultMavenExecutionRequest; -import org.apache.maven.execution.MavenExecutionRequest; -import org.codehaus.plexus.PlexusTestCase; - -public class DefaultMavenExecutionRequestPopulatorTest - extends PlexusTestCase -{ - private MavenExecutionRequestPopulator populator; - - public void setUp() - throws Exception - { - super.setUp(); - - populator = (MavenExecutionRequestPopulator) lookup( MavenExecutionRequestPopulator.class ); - } - - @Override - protected void tearDown() throws Exception { - populator = null; - super.tearDown(); - } - - public void testWagonManagerOfflineFlagIsPopulatedFromSettings() - throws MavenEmbedderException - { - MavenExecutionRequest req = new DefaultMavenExecutionRequest().setOffline( true ); - - populator.populateDefaults( req, new DefaultConfiguration() ); - } -} diff --git a/maven-embedder/src/test/java/org/apache/maven/embedder/project/BadModuleNotRecursiveTest.java b/maven-embedder/src/test/java/org/apache/maven/embedder/project/BadModuleNotRecursiveTest.java deleted file mode 100644 index ec560891d9..0000000000 --- a/maven-embedder/src/test/java/org/apache/maven/embedder/project/BadModuleNotRecursiveTest.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.apache.maven.embedder.project; - -import java.io.File; - -import junit.framework.TestCase; - -import org.apache.maven.embedder.Configuration; -import org.apache.maven.embedder.MavenEmbedder; -import org.apache.maven.embedder.SimpleConfiguration; -import org.apache.maven.execution.DefaultMavenExecutionRequest; -import org.apache.maven.execution.MavenExecutionResult; -import org.apache.maven.project.MavenProject; - -public class BadModuleNotRecursiveTest - extends TestCase -{ - public void test() - throws Exception - { - Configuration configuration = new SimpleConfiguration(); - MavenEmbedder embedder = new MavenEmbedder( configuration ); - - File pom = new File( "src/test/projects/bad-module-non-recursive/pom.xml" ).getCanonicalFile(); - - System.out.println( pom.getCanonicalFile() ); - - DefaultMavenExecutionRequest request = new DefaultMavenExecutionRequest(); - request.setOffline( false ); - request.setUseReactor( false ); - request.setRecursive( false ); - //request.setLoggingLevel( Logger.LEVEL_DEBUG ); - request.setPom( pom ); - request.setBaseDirectory( pom.getParentFile() ); - MavenExecutionResult result = embedder.readProjectWithDependencies( request ); - MavenProject project = result.getProject(); - - if ( result.hasExceptions() ) - { - for ( Exception e : result.getExceptions() ) - { - e.printStackTrace(); - } - } - - assertNotNull( project ); - } -} diff --git a/maven-embedder/src/test/java/org/apache/maven/embedder/validation/MavenEmbedderCrappySettingsConfigurationTest.java b/maven-embedder/src/test/java/org/apache/maven/embedder/validation/MavenEmbedderCrappySettingsConfigurationTest.java index e62839464e..527e98683f 100644 --- a/maven-embedder/src/test/java/org/apache/maven/embedder/validation/MavenEmbedderCrappySettingsConfigurationTest.java +++ b/maven-embedder/src/test/java/org/apache/maven/embedder/validation/MavenEmbedderCrappySettingsConfigurationTest.java @@ -53,7 +53,7 @@ public class MavenEmbedderCrappySettingsConfigurationTest MavenEmbedder embedder = new MavenEmbedder( configuration ); - assertNotNull( embedder.getLocalRepository().getBasedir() ); + //assertNotNull( embedder.getLocalRepository().getBasedir() ); MavenExecutionRequest request = new DefaultMavenExecutionRequest() .setBaseDirectory( projectDirectory )