o separate out the embedder tests into packages by concern

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@571902 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2007-09-02 00:01:02 +00:00
parent e72f6758be
commit 8ce69da938
11 changed files with 113 additions and 655 deletions

View File

@ -34,7 +34,7 @@ import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.context.BuildContextManager;
import org.apache.maven.embedder.execution.MavenExecutionRequestDefaultsPopulator;
import org.apache.maven.embedder.execution.MavenExecutionRequestPopulator;
import org.apache.maven.embedder.writer.WriterUtils;
import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.DefaultMavenExecutionResult;
@ -95,7 +95,6 @@ import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.net.URL;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@ -159,7 +158,7 @@ public class MavenEmbedder
private MavenSettingsBuilder settingsBuilder;
private MavenExecutionRequestDefaultsPopulator defaultsPopulator;
private MavenExecutionRequestPopulator populator;
// ----------------------------------------------------------------------
// Configuration
@ -426,7 +425,7 @@ public class MavenEmbedder
try
{
request = defaultsPopulator.populateDefaults( request, this );
request = populator.populateDefaults( request, this );
//mkleint: copied from DefaultLifecycleExecutor
project = readProject( new File( request.getPomFile() ) );
@ -458,7 +457,7 @@ public class MavenEmbedder
}
catch ( ProjectBuildingException e )
{
result.addException( e );
}
result.setProject( r.getProject() );
@ -645,8 +644,8 @@ public class MavenEmbedder
defaultArtifactRepositoryLayout =
(ArtifactRepositoryLayout) container.lookup( ArtifactRepositoryLayout.ROLE, DEFAULT_LAYOUT_ID );
defaultsPopulator = (MavenExecutionRequestDefaultsPopulator) container.lookup(
MavenExecutionRequestDefaultsPopulator.ROLE );
populator = (MavenExecutionRequestPopulator) container.lookup(
MavenExecutionRequestPopulator.ROLE );
artifactHandlerManager = (ArtifactHandlerManager) container.lookup( ArtifactHandlerManager.ROLE );
@ -925,7 +924,7 @@ public class MavenEmbedder
try
{
request = defaultsPopulator.populateDefaults( request, this );
request = populator.populateDefaults( request, this );
}
catch ( MavenEmbedderException e )
{

View File

@ -1,221 +0,0 @@
package org.apache.maven.embedder.execution;
/*
* 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 org.apache.maven.SettingsConfigurationException;
import org.apache.maven.wagon.repository.RepositoryPermissions;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.embedder.MavenEmbedder;
import org.apache.maven.embedder.MavenEmbedderException;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.monitor.event.DefaultEventMonitor;
import org.apache.maven.plugin.Mojo;
import org.apache.maven.settings.Mirror;
import org.apache.maven.settings.Proxy;
import org.apache.maven.settings.Server;
import org.apache.maven.settings.Settings;
import org.apache.maven.usability.SystemWarnings;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.context.Context;
import org.codehaus.plexus.context.ContextException;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import java.io.File;
import java.util.Iterator;
/**
* DefaultMavenExecutionRequestDefaultsPopulator
*
* @version $Id$
*/
public class DefaultMavenExecutionRequestDefaultsPopulator
extends AbstractLogEnabled
implements MavenExecutionRequestDefaultsPopulator, Contextualizable
{
private ArtifactRepositoryFactory artifactRepositoryFactory;
private ArtifactRepositoryLayout defaultArtifactRepositoryLayout;
private PlexusContainer container;
private WagonManager wagonManager;
public MavenExecutionRequest populateDefaults( MavenExecutionRequest request,
MavenEmbedder embedder )
throws MavenEmbedderException
{
if ( request.getSettings() == null )
{
request.setSettings( embedder.getSettings() );
}
if ( request.getLocalRepository() == null )
{
request.setLocalRepository( embedder.getLocalRepository() );
}
// Repository update policies
boolean snapshotPolicySet = false;
if ( request.isOffline() )
{
snapshotPolicySet = true;
}
if ( !snapshotPolicySet )
{
if ( request.isUpdateSnapshots() )
{
artifactRepositoryFactory.setGlobalUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS );
}
else if ( request.isNoSnapshotUpdates() )
{
getLogger().info( "+ Supressing SNAPSHOT updates." );
artifactRepositoryFactory.setGlobalUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER );
}
}
artifactRepositoryFactory.setGlobalChecksumPolicy( request.getGlobalChecksumPolicy() );
// Wagon
if ( request.isOffline() )
{
getLogger().info( SystemWarnings.getOfflineWarning() );
wagonManager.setOnline( false );
}
else
{
wagonManager.findAndRegisterWagons( container );
wagonManager.setInteractive( request.isInteractiveMode() );
wagonManager.setDownloadMonitor( request.getTransferListener() );
wagonManager.setOnline( true );
}
try
{
resolveParameters( request.getSettings() );
}
catch ( Exception e )
{
throw new MavenEmbedderException( "Unable to configure Maven for execution", e );
}
// BaseDirectory in MavenExecutionRequest
if ( request.getPomFile() != null && request.getBaseDirectory() == null )
{
request.setBaseDirectory( new File( request.getPomFile() ) );
}
// EventMonitor/Logger
Logger logger = container.getLoggerManager().getLoggerForComponent( Mojo.ROLE );
if ( request.getEventMonitors() == null )
{
request.addEventMonitor( new DefaultEventMonitor( logger ) );
}
container.getLoggerManager().setThreshold( request.getLoggingLevel() );
return request;
}
private void resolveParameters( Settings settings )
throws ComponentLookupException, ComponentLifecycleException, SettingsConfigurationException
{
WagonManager wagonManager = (WagonManager) container.lookup( WagonManager.ROLE );
try
{
Proxy proxy = settings.getActiveProxy();
if ( proxy != null )
{
if ( proxy.getHost() == null )
{
throw new SettingsConfigurationException( "Proxy in settings.xml has no host" );
}
wagonManager.addProxy( proxy.getProtocol(), proxy.getHost(), proxy.getPort(), proxy.getUsername(),
proxy.getPassword(), proxy.getNonProxyHosts() );
}
for ( Iterator i = settings.getServers().iterator(); i.hasNext(); )
{
Server server = (Server) i.next();
wagonManager.addAuthenticationInfo( server.getId(), server.getUsername(), server.getPassword(),
server.getPrivateKey(), server.getPassphrase() );
wagonManager.addPermissionInfo( server.getId(), server.getFilePermissions(), server.getDirectoryPermissions() );
if ( server.getConfiguration() != null )
{
wagonManager.addConfiguration( server.getId(), (Xpp3Dom) server.getConfiguration() );
}
}
RepositoryPermissions defaultPermissions = new RepositoryPermissions();
defaultPermissions.setDirectoryMode( "775" );
defaultPermissions.setFileMode( "664" );
wagonManager.setDefaultRepositoryPermissions( defaultPermissions );
for ( Iterator i = settings.getMirrors().iterator(); i.hasNext(); )
{
Mirror mirror = (Mirror) i.next();
wagonManager.addMirror( mirror.getId(), mirror.getMirrorOf(), mirror.getUrl() );
}
}
finally
{
container.release( wagonManager );
}
}
// ----------------------------------------------------------------------------
// LegacyLifecycle
// ----------------------------------------------------------------------------
public void contextualize( Context context )
throws ContextException
{
container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
}
}

View File

@ -29,6 +29,8 @@ import org.apache.maven.embedder.MavenEmbedderException;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.monitor.event.DefaultEventMonitor;
import org.apache.maven.plugin.Mojo;
import org.apache.maven.profiles.ProfileManager;
import org.apache.maven.profiles.DefaultProfileManager;
import org.apache.maven.settings.Mirror;
import org.apache.maven.settings.Proxy;
import org.apache.maven.settings.Server;
@ -150,6 +152,10 @@ public class DefaultMavenExecutionRequestPopulator
container.getLoggerManager().setThreshold( request.getLoggingLevel() );
// Create the standard profile manager
request.setProfileManager( createProfileManager( request ) );
return request;
}
@ -209,6 +215,23 @@ public class DefaultMavenExecutionRequestPopulator
}
}
// ------------------------------------------------------------------------
// Profile Manager
// ------------------------------------------------------------------------
public ProfileManager createProfileManager( MavenExecutionRequest request )
{
ProfileManager globalProfileManager = new DefaultProfileManager( container, request.getProperties() );
globalProfileManager.loadSettingsProfiles( request.getSettings() );
globalProfileManager.explicitlyActivate( request.getActiveProfiles() );
globalProfileManager.explicitlyDeactivate( request.getInactiveProfiles() );
return globalProfileManager;
}
// ----------------------------------------------------------------------------
// LegacyLifecycle
// ----------------------------------------------------------------------------

View File

@ -1,32 +0,0 @@
package org.apache.maven.embedder.execution;
/*
* 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 org.apache.maven.embedder.MavenEmbedder;
import org.apache.maven.embedder.MavenEmbedderException;
import org.apache.maven.execution.MavenExecutionRequest;
public interface MavenExecutionRequestDefaultsPopulator
{
String ROLE = MavenExecutionRequestDefaultsPopulator.class.getName();
MavenExecutionRequest populateDefaults( MavenExecutionRequest request, MavenEmbedder embedder )
throws MavenEmbedderException;
}

View File

@ -20,8 +20,8 @@ under the License.
<component-set>
<components>
<component>
<role>org.apache.maven.embedder.execution.MavenExecutionRequestDefaultsPopulator</role>
<implementation>org.apache.maven.embedder.execution.DefaultMavenExecutionRequestDefaultsPopulator</implementation>
<role>org.apache.maven.embedder.execution.MavenExecutionRequestPopulator</role>
<implementation>org.apache.maven.embedder.execution.DefaultMavenExecutionRequestPopulator</implementation>
<requirements>
<requirement>
<role>org.apache.maven.artifact.manager.WagonManager</role>

View File

@ -1,132 +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 org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResult;
import org.codehaus.plexus.util.FileUtils;
import java.io.File;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
public abstract class AbstractEmbedderExecutionTestCase
extends AbstractEmbedderTestCase
{
protected File runWithProject( String goal )
throws Exception
{
return runWithProject( Collections.singletonList( goal ), null );
}
protected File runWithProject( String goal,
Properties properties )
throws Exception
{
return runWithProject( Collections.singletonList( goal ), properties );
}
protected File runWithProject( String[] goals )
throws Exception
{
return runWithProject( Arrays.asList( goals ), null );
}
protected File runWithProject( String[] goals,
Properties properties )
throws Exception
{
return runWithProject( Arrays.asList( goals ), properties );
}
protected File runWithProject( List goals )
throws Exception
{
return runWithProject( goals, null );
}
protected File runWithProject( List goals,
Properties properties )
throws Exception
{
/*
if ( request.getBaseDirectory() == null || !new File( request.getBaseDirectory() ).exists() )
{
throw new IllegalStateException( "You must specify a valid base directory in your execution request for this test." );
}
*/
File testDirectory = new File( getBasedir(), "src/test/embedder-test-project" );
File targetDirectory = new File( getBasedir(), "target/" + getId() );
FileUtils.copyDirectoryStructure( testDirectory, targetDirectory );
MavenExecutionRequest request = new DefaultMavenExecutionRequest()
.setShowErrors( true )
.setLoggingLevel( MavenExecutionRequest.LOGGING_LEVEL_DEBUG )
.setBaseDirectory( targetDirectory )
.setGoals( goals );
System.out.println( "properties = " + properties );
if ( properties != null )
{
request.setProperties( properties );
}
MavenExecutionResult result = maven.execute( request );
assertNoExceptions( result );
return targetDirectory;
}
protected abstract String getId();
protected void assertNoExceptions( MavenExecutionResult result )
{
if ( !result.hasExceptions() )
{
return;
}
for ( Iterator i = result.getExceptions().iterator(); i.hasNext(); )
{
Exception exception = (Exception) i.next();
exception.printStackTrace( System.err );
}
fail( "Encountered Exceptions in MavenExecutionResult during " + getName() );
}
protected void assertFileExists( File file )
{
if ( !file.exists() )
{
fail( "The specified file '" + file + "' does not exist." );
}
}
}

View File

@ -1,42 +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;
/** @author Jason van Zyl */
public class EmbedderUsingEclipsePluginTest
extends AbstractEmbedderExecutionTestCase
{
protected String getId()
{
return "eclipse-from-embedder";
}
public void testRunningEclipsePlugin()
throws Exception
{
File basedir = runWithProject( "eclipse:eclipse" );
assertFileExists( new File( basedir, ".classpath" ) );
assertFileExists( new File( basedir, ".project" ) );
}
}

View File

@ -1,47 +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.Properties;
/** @author Jason van Zyl */
public class EmbedderUsingScmPluginTest
extends AbstractEmbedderExecutionTestCase
{
protected String getId()
{
return "scm-plugin-from-embedder";
}
public void testRunningScmPlugin()
throws Exception
{
Properties p = new Properties();
File outputDirectory = new File( getBasedir(), "target/scm.diff" );
p.setProperty( "outputDirectory", outputDirectory.getCanonicalPath() );
p.setProperty( "connectionUrl", "scm:svn:http://svn.apache.org/repos/asf/maven/components/trunk/maven-embedder" );
File basedir = runWithProject( "scm:diff", p );
}
}

View File

@ -1,71 +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 org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResult;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.PlexusTestCase;
import java.io.File;
import java.util.Arrays;
public class MavenEmbedderCrappySettingsConfigurationTest
extends PlexusTestCase
{
public void testEmbedderWillStillStartupWhenTheSettingsConfigurationIsCrap()
throws Exception
{
// START SNIPPET: simple-embedder-example
File projectDirectory = new File( getBasedir(), "src/examples/simple-project" );
File user = new File( projectDirectory, "invalid-settings.xml" );
Configuration configuration = new DefaultConfiguration()
.setUserSettingsFile( user )
.setClassLoader( Thread.currentThread().getContextClassLoader() );
ConfigurationValidationResult validationResult = MavenEmbedder.validateConfiguration( configuration );
assertFalse( validationResult.isValid() );
MavenEmbedder embedder = new MavenEmbedder( configuration );
assertNotNull( embedder.getLocalRepository().getBasedir() );
MavenExecutionRequest request = new DefaultMavenExecutionRequest()
.setBaseDirectory( projectDirectory )
.setGoals( Arrays.asList( new String[]{"clean", "install"} ) );
MavenExecutionResult result = embedder.execute( request );
assertNotNull( result.getProject() );
MavenProject project = result.getProject();
String environment = project.getProperties().getProperty( "environment" );
assertEquals( "development", environment );
// END SNIPPET: simple-embedder-example
}
}

View File

@ -1,100 +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 org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.File;
/** @author Jason van Zyl */
public class ValidateConfigurationTest
extends PlexusTestCase
{
public void testConfigurationOnlyUserSettingsAreActiveAndItIsValid()
{
File user = new File( getBasedir(), "src/test/resources/settings/valid-settings.xml" );
Configuration configuration = new DefaultConfiguration()
.setUserSettingsFile( user );
ConfigurationValidationResult result = MavenEmbedder.validateConfiguration( configuration );
assertTrue( result.isUserSettingsFilePresent() );
assertTrue( result.isUserSettingsFileParses() );
assertNotNull( result.getUserSettings() );
assertNull( result.getUserSettingsException() );
assertNull( result.getGlobalSettings() );
assertNull( result.getGlobalSettingsException() );
}
public void testConfigurationOnlyUserSettingsAreActiveAndItIsInvalid()
{
File user = new File( getBasedir(), "src/test/resources/settings/invalid-settings.xml" );
Configuration configuration = new DefaultConfiguration()
.setUserSettingsFile( user );
ConfigurationValidationResult result = MavenEmbedder.validateConfiguration( configuration );
assertTrue( result.isUserSettingsFilePresent() );
assertFalse( result.isUserSettingsFileParses() );
assertNull( result.getUserSettings() );
assertNotNull( result.getUserSettingsException() );
assertTrue( result.getUserSettingsException() instanceof XmlPullParserException );
assertNull( result.getGlobalSettings() );
assertNull( result.getGlobalSettingsException() );
}
public void testConfigurationOnlyGlobalSettingsAreActiveAndItIsValid()
{
File global = new File( getBasedir(), "src/test/resources/settings/valid-settings.xml" );
Configuration configuration = new DefaultConfiguration()
.setGlobalSettingsFile( global );
ConfigurationValidationResult result = MavenEmbedder.validateConfiguration( configuration );
assertTrue( result.isGlobalSettingsFilePresent() );
assertTrue( result.isGlobalSettingsFileParses() );
assertNotNull( result.getGlobalSettings() );
assertNull( result.getGlobalSettingsException() );
assertNull( result.getUserSettings() );
assertNull( result.getUserSettingsException() );
}
public void testConfigurationOnlyGlobalSettingsAreActiveAndItIsInvalid()
{
File global = new File( getBasedir(), "src/test/resources/settings/invalid-settings.xml" );
Configuration configuration = new DefaultConfiguration()
.setGlobalSettingsFile( global );
ConfigurationValidationResult result = MavenEmbedder.validateConfiguration( configuration );
assertTrue( result.isGlobalSettingsFilePresent() );
assertFalse( result.isGlobalSettingsFileParses() );
assertNull( result.getGlobalSettings() );
assertNotNull( result.getGlobalSettingsException() );
assertTrue( result.getGlobalSettingsException() instanceof XmlPullParserException );
assertNull( result.getUserSettings() );
assertNull( result.getUserSettingsException() );
}
}

View File

@ -0,0 +1,81 @@
package org.apache.maven.embedder.project;
/*
* 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 org.apache.maven.embedder.AbstractEmbedderTestCase;
import org.apache.maven.embedder.Configuration;
import org.apache.maven.embedder.ConfigurationValidationResult;
import org.apache.maven.embedder.DefaultConfiguration;
import org.apache.maven.embedder.MavenEmbedder;
import org.apache.maven.embedder.MavenEmbedderConsoleLogger;
import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResult;
import org.apache.maven.project.MavenProject;
import java.io.File;
import java.util.Iterator;
import java.util.List;
/**
* We want to make sure when projects are newly created and have dependencies between them that
* projects will still resolve and allow good IDE integration. Currently if you have newly
* created projects that have interdependencies and you have not run "mvn install" then
* none of the dependencies will be resolved for projects with interdependencies.
*
* @author Jason van Zyl
*/
public class MavenEmbedderProjectNotInRepositoryTest
extends AbstractEmbedderTestCase
{
public void testThatNewlyCreatedProjectsWithInterdependenciesStillResolveCorrectly()
throws Exception
{
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
Configuration configuration = new DefaultConfiguration()
.setClassLoader( classLoader )
.setMavenEmbedderLogger( new MavenEmbedderConsoleLogger() );
ConfigurationValidationResult cr = MavenEmbedder.validateConfiguration( configuration );
assertTrue( cr.isValid() );
MavenEmbedder embedder = new MavenEmbedder( configuration );
File projectDirectory = new File( getBasedir(), "src/test/projects/no-artifact-in-repository-test" );
MavenExecutionRequest request = new DefaultMavenExecutionRequest()
.setBaseDirectory( projectDirectory );
MavenExecutionResult result = embedder.readProjectWithDependencies( request );
List projects = result.getTopologicallySortedProjects();
/*
for ( Iterator i = projects.iterator(); i.hasNext(); )
{
MavenProject project = (MavenProject) i.next();
System.out.println( "project = " + project );
}
*/
}
}