o Made embedder tests respect maven.repo.local

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@793342 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-07-12 12:59:21 +00:00
parent 67e6a9553a
commit 0ba6f79521
8 changed files with 71 additions and 57 deletions

View File

@ -46,10 +46,7 @@ protected void setUp()
{
super.setUp();
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
Configuration configuration = new DefaultConfiguration().setClassLoader( classLoader ).setMavenEmbedderLogger( new MavenEmbedderConsoleLogger() );
configuration.setUserSettingsFile( MavenEmbedder.DEFAULT_USER_SETTINGS_FILE );
Configuration configuration = new SimpleConfiguration();
maven = new MavenEmbedder( configuration );

View File

@ -21,7 +21,6 @@
import java.io.File;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import junit.framework.TestCase;
@ -52,12 +51,7 @@ protected void setUp()
basedir = new File( "." ).getCanonicalPath();
}
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
Configuration configuration = new DefaultConfiguration()
.setClassLoader( classLoader )
.setMavenEmbedderLogger( new MavenEmbedderConsoleLogger() );
configuration.setUserSettingsFile( MavenEmbedder.DEFAULT_USER_SETTINGS_FILE );
Configuration configuration = new SimpleConfiguration();
mavenEmbedder = new MavenEmbedder( configuration );
}
@ -70,7 +64,7 @@ protected void tearDown()
protected void assertNoExceptions( MavenExecutionResult result )
{
List exceptions = result.getExceptions();
List<Exception> exceptions = result.getExceptions();
if ( ( exceptions == null ) || exceptions.isEmpty() )
{
// everything is a-ok.
@ -78,10 +72,8 @@ protected void assertNoExceptions( MavenExecutionResult result )
}
System.err.println( "Encountered " + exceptions.size() + " exception(s)." );
Iterator it = exceptions.iterator();
while ( it.hasNext() )
for ( Exception exception : exceptions )
{
Exception exception = (Exception) it.next();
exception.printStackTrace( System.err );
}

View File

@ -81,9 +81,7 @@ private class ExtendableMavenEmbedder
public ExtendableMavenEmbedder( ClassLoader classLoader )
throws MavenEmbedderException
{
super( new DefaultConfiguration()
.setClassLoader( classLoader )
.setMavenEmbedderLogger( new MavenEmbedderConsoleLogger() ) );
super( new SimpleConfiguration().setClassLoader( classLoader ) );
}
protected Map<String, ArtifactHandler> getPluginExtensionComponents( Plugin plugin )

View File

@ -25,7 +25,6 @@
import java.io.Writer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
@ -71,12 +70,7 @@ protected void setUp()
basedir = new File( "." ).getCanonicalPath();
}
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
Configuration configuration = new DefaultConfiguration()
.setClassLoader( classLoader )
.setMavenEmbedderLogger( new MavenEmbedderConsoleLogger() );
configuration.setUserSettingsFile( MavenEmbedder.DEFAULT_USER_SETTINGS_FILE );
Configuration configuration = new SimpleConfiguration();
mavenEmbedder = new MavenEmbedder( configuration );
@ -92,7 +86,7 @@ protected void tearDown()
protected void assertNoExceptions( MavenExecutionResult result )
{
List exceptions = result.getExceptions();
List<Exception> exceptions = result.getExceptions();
if ( ( exceptions == null ) || exceptions.isEmpty() )
{
// everything is a-ok.
@ -100,10 +94,8 @@ protected void assertNoExceptions( MavenExecutionResult result )
}
System.err.println( "Encountered " + exceptions.size() + " exception(s)." );
Iterator it = exceptions.iterator();
while ( it.hasNext() )
for (Exception exception : exceptions)
{
Exception exception = (Exception) it.next();
exception.printStackTrace( System.err );
}
@ -181,11 +173,10 @@ public void testWithInvalidGoal()
.setGoals( Arrays.asList( new String[]{"validate"} ) );
MavenExecutionResult result = mavenEmbedder.execute( request );
List exceptions = result.getExceptions();
List<Exception> exceptions = result.getExceptions();
assertEquals("Incorrect number of exceptions", 1, exceptions.size());
Iterator it = exceptions.iterator();
if( (it.next() instanceof NullPointerException))
if ( ( exceptions.get( 0 ) instanceof NullPointerException ) )
{
fail("Null Pointer on Exception");
}
@ -306,7 +297,7 @@ public void testTwoExecutionsDoNotCacheChangedData()
MavenProject project = result.getProject();
Artifact p = (Artifact) project.getPluginArtifactMap().get( plugin.getKey() );
Artifact p = project.getPluginArtifactMap().get( plugin.getKey() );
assertEquals( "2.4.2", p.getVersion() );
/* Add the surefire plugin 2.3 to the pom */
@ -324,7 +315,7 @@ public void testTwoExecutionsDoNotCacheChangedData()
project = result.getProject();
p = (Artifact) project.getPluginArtifactMap().get( plugin.getKey() );
p = project.getPluginArtifactMap().get( plugin.getKey() );
assertEquals( "2.4.3", p.getVersion() );
}
@ -365,7 +356,7 @@ public void testProjectReading()
assertEquals( "org.apache.maven", result.getProject().getGroupId() );
Set artifacts = result.getProject().getArtifacts();
Set<Artifact> artifacts = result.getProject().getArtifacts();
assertEquals( 1, artifacts.size() );

View File

@ -0,0 +1,49 @@
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;
/**
* A configuration to be used for unit testing of the embedder. This basically sets some default values.
*
* @author Benjamin Bentmann
*/
public class SimpleConfiguration
extends DefaultConfiguration
{
public SimpleConfiguration()
{
String localRepo = System.getProperty( "maven.repo.local", "" );
if ( localRepo.length() > 0 )
{
setLocalRepository( new File( localRepo ).getAbsoluteFile() );
}
setClassLoader( Thread.currentThread().getContextClassLoader() );
setMavenEmbedderLogger( new MavenEmbedderConsoleLogger() );
setUserSettingsFile( MavenEmbedder.DEFAULT_USER_SETTINGS_FILE );
}
}

View File

@ -37,13 +37,7 @@ public class TestComponentOverride
protected void setUp()
throws Exception
{
ClassLoader loader = Thread.currentThread().getContextClassLoader();
Configuration request = new DefaultConfiguration();
request.setClassLoader( loader );
request.setMavenEmbedderLogger( new MavenEmbedderConsoleLogger() );
Configuration request = new SimpleConfiguration();
File extensions = new File( getBasedir(), "src/test/extensions" );

View File

@ -1,14 +1,12 @@
package org.apache.maven.embedder.project;
import java.io.File;
import java.util.Iterator;
import junit.framework.TestCase;
import org.apache.maven.embedder.Configuration;
import org.apache.maven.embedder.DefaultConfiguration;
import org.apache.maven.embedder.MavenEmbedder;
import org.apache.maven.embedder.MavenEmbedderConsoleLogger;
import org.apache.maven.embedder.SimpleConfiguration;
import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResult;
import org.apache.maven.project.MavenProject;
@ -19,8 +17,7 @@ public class BadModuleNotRecursiveTest
public void test()
throws Exception
{
Configuration configuration = new DefaultConfiguration();
configuration.setMavenEmbedderLogger( new MavenEmbedderConsoleLogger() );
Configuration configuration = new SimpleConfiguration();
MavenEmbedder embedder = new MavenEmbedder( configuration );
File pom = new File( "src/test/projects/bad-module-non-recursive/pom.xml" ).getCanonicalFile();
@ -39,10 +36,9 @@ public void test()
if ( result.hasExceptions() )
{
for ( Iterator it = result.getExceptions().iterator(); it.hasNext(); )
for ( Exception e : result.getExceptions() )
{
Exception ex = (Exception) it.next();
ex.printStackTrace();
e.printStackTrace();
}
}

View File

@ -21,12 +21,11 @@
import java.io.File;
import java.util.Arrays;
import java.util.Iterator;
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.SimpleConfiguration;
import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResult;
@ -45,9 +44,8 @@ public void testEmbedderWillStillStartupWhenTheSettingsConfigurationIsCrap()
File user = new File( projectDirectory, "invalid-settings.xml" );
Configuration configuration = new DefaultConfiguration()
.setUserSettingsFile( user )
.setClassLoader( Thread.currentThread().getContextClassLoader() );
Configuration configuration = new SimpleConfiguration()
.setUserSettingsFile( user );
ConfigurationValidationResult validationResult = MavenEmbedder.validateConfiguration( configuration );
@ -63,9 +61,8 @@ public void testEmbedderWillStillStartupWhenTheSettingsConfigurationIsCrap()
MavenExecutionResult result = embedder.execute( request );
for ( Iterator i = result.getExceptions().iterator(); i.hasNext(); )
for ( Exception e : result.getExceptions() )
{
Exception e = (Exception) i.next();
e.printStackTrace();
}