From 8ce69da93850d0e2414aadd7b122db422b55cf06 Mon Sep 17 00:00:00 2001 From: Jason van Zyl Date: Sun, 2 Sep 2007 00:01:02 +0000 Subject: [PATCH] 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 --- .../apache/maven/embedder/MavenEmbedder.java | 15 +- ...avenExecutionRequestDefaultsPopulator.java | 221 ------------------ ...DefaultMavenExecutionRequestPopulator.java | 23 ++ ...avenExecutionRequestDefaultsPopulator.java | 32 --- .../resources/META-INF/plexus/components.xml | 4 +- .../AbstractEmbedderExecutionTestCase.java | 132 ----------- .../EmbedderUsingEclipsePluginTest.java | 42 ---- .../embedder/EmbedderUsingScmPluginTest.java | 47 ---- ...bedderCrappySettingsConfigurationTest.java | 71 ------ .../embedder/ValidateConfigurationTest.java | 100 -------- ...venEmbedderProjectNotInRepositoryTest.java | 81 +++++++ 11 files changed, 113 insertions(+), 655 deletions(-) delete mode 100644 maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestDefaultsPopulator.java delete mode 100644 maven-embedder/src/main/java/org/apache/maven/embedder/execution/MavenExecutionRequestDefaultsPopulator.java delete mode 100644 maven-embedder/src/test/java/org/apache/maven/embedder/AbstractEmbedderExecutionTestCase.java delete mode 100644 maven-embedder/src/test/java/org/apache/maven/embedder/EmbedderUsingEclipsePluginTest.java delete mode 100644 maven-embedder/src/test/java/org/apache/maven/embedder/EmbedderUsingScmPluginTest.java delete mode 100644 maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderCrappySettingsConfigurationTest.java delete mode 100644 maven-embedder/src/test/java/org/apache/maven/embedder/ValidateConfigurationTest.java create mode 100644 maven-embedder/src/test/java/org/apache/maven/embedder/project/MavenEmbedderProjectNotInRepositoryTest.java 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 391f5cc60f..60d216d51b 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 @@ -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 ) { diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestDefaultsPopulator.java b/maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestDefaultsPopulator.java deleted file mode 100644 index e75c8c4f67..0000000000 --- a/maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestDefaultsPopulator.java +++ /dev/null @@ -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 ); - } -} 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 5068c7c04b..7844bb73f2 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 @@ -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 // ---------------------------------------------------------------------------- diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/execution/MavenExecutionRequestDefaultsPopulator.java b/maven-embedder/src/main/java/org/apache/maven/embedder/execution/MavenExecutionRequestDefaultsPopulator.java deleted file mode 100644 index bebf432225..0000000000 --- a/maven-embedder/src/main/java/org/apache/maven/embedder/execution/MavenExecutionRequestDefaultsPopulator.java +++ /dev/null @@ -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; -} diff --git a/maven-embedder/src/main/resources/META-INF/plexus/components.xml b/maven-embedder/src/main/resources/META-INF/plexus/components.xml index 639fe417ea..db7b47ad0a 100644 --- a/maven-embedder/src/main/resources/META-INF/plexus/components.xml +++ b/maven-embedder/src/main/resources/META-INF/plexus/components.xml @@ -20,8 +20,8 @@ under the License. - org.apache.maven.embedder.execution.MavenExecutionRequestDefaultsPopulator - org.apache.maven.embedder.execution.DefaultMavenExecutionRequestDefaultsPopulator + org.apache.maven.embedder.execution.MavenExecutionRequestPopulator + org.apache.maven.embedder.execution.DefaultMavenExecutionRequestPopulator org.apache.maven.artifact.manager.WagonManager diff --git a/maven-embedder/src/test/java/org/apache/maven/embedder/AbstractEmbedderExecutionTestCase.java b/maven-embedder/src/test/java/org/apache/maven/embedder/AbstractEmbedderExecutionTestCase.java deleted file mode 100644 index e05d767d3c..0000000000 --- a/maven-embedder/src/test/java/org/apache/maven/embedder/AbstractEmbedderExecutionTestCase.java +++ /dev/null @@ -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." ); - } - } -} diff --git a/maven-embedder/src/test/java/org/apache/maven/embedder/EmbedderUsingEclipsePluginTest.java b/maven-embedder/src/test/java/org/apache/maven/embedder/EmbedderUsingEclipsePluginTest.java deleted file mode 100644 index 4fec6ed76c..0000000000 --- a/maven-embedder/src/test/java/org/apache/maven/embedder/EmbedderUsingEclipsePluginTest.java +++ /dev/null @@ -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" ) ); - } -} diff --git a/maven-embedder/src/test/java/org/apache/maven/embedder/EmbedderUsingScmPluginTest.java b/maven-embedder/src/test/java/org/apache/maven/embedder/EmbedderUsingScmPluginTest.java deleted file mode 100644 index 4baf432b2e..0000000000 --- a/maven-embedder/src/test/java/org/apache/maven/embedder/EmbedderUsingScmPluginTest.java +++ /dev/null @@ -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 ); - } -} diff --git a/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderCrappySettingsConfigurationTest.java b/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderCrappySettingsConfigurationTest.java deleted file mode 100644 index f0904f5a1b..0000000000 --- a/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderCrappySettingsConfigurationTest.java +++ /dev/null @@ -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 - } -} diff --git a/maven-embedder/src/test/java/org/apache/maven/embedder/ValidateConfigurationTest.java b/maven-embedder/src/test/java/org/apache/maven/embedder/ValidateConfigurationTest.java deleted file mode 100644 index 63fcd4e4d7..0000000000 --- a/maven-embedder/src/test/java/org/apache/maven/embedder/ValidateConfigurationTest.java +++ /dev/null @@ -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() ); - } -} diff --git a/maven-embedder/src/test/java/org/apache/maven/embedder/project/MavenEmbedderProjectNotInRepositoryTest.java b/maven-embedder/src/test/java/org/apache/maven/embedder/project/MavenEmbedderProjectNotInRepositoryTest.java new file mode 100644 index 0000000000..567917c192 --- /dev/null +++ b/maven-embedder/src/test/java/org/apache/maven/embedder/project/MavenEmbedderProjectNotInRepositoryTest.java @@ -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 ); + } + */ + } +} \ No newline at end of file