mirror of https://github.com/apache/maven.git
Re-enable offline flag from the settings.xml.
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@629161 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
fb4092ba17
commit
4bc04c413b
|
@ -523,6 +523,10 @@ public class DefaultMavenExecutionRequestPopulator
|
||||||
{
|
{
|
||||||
wagonManager.setOnline( false );
|
wagonManager.setOnline( false );
|
||||||
}
|
}
|
||||||
|
else if ( ( request.getSettings() != null ) && request.getSettings().isOffline() )
|
||||||
|
{
|
||||||
|
wagonManager.setOnline( false );
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
wagonManager.findAndRegisterWagons( container );
|
wagonManager.findAndRegisterWagons( container );
|
||||||
|
|
|
@ -44,4 +44,11 @@ under the License.
|
||||||
</properties>
|
</properties>
|
||||||
</profile>
|
</profile>
|
||||||
</profiles>
|
</profiles>
|
||||||
|
|
||||||
|
<distributionManagement>
|
||||||
|
<repository>
|
||||||
|
<id>test-deploy-location</id>
|
||||||
|
<url>file:${java.io.tmpdir}/test-deploy-repository</url>
|
||||||
|
</repository>
|
||||||
|
</distributionManagement>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
package org.apache.maven.embedder.execution;
|
||||||
|
|
||||||
|
import org.apache.maven.artifact.manager.WagonManager;
|
||||||
|
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.apache.maven.settings.Settings;
|
||||||
|
import org.codehaus.plexus.PlexusTestCase;
|
||||||
|
|
||||||
|
public class DefaultMavenExecutionRequestPopulatorTest
|
||||||
|
extends PlexusTestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
private MavenExecutionRequestPopulator populator;
|
||||||
|
|
||||||
|
private WagonManager wagonManager;
|
||||||
|
|
||||||
|
public void setUp()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
super.setUp();
|
||||||
|
|
||||||
|
populator = (MavenExecutionRequestPopulator) lookup( MavenExecutionRequestPopulator.class );
|
||||||
|
wagonManager = (WagonManager) lookup( WagonManager.class );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testWagonManagerOfflineFlagIsPopulatedFromSettings()
|
||||||
|
throws MavenEmbedderException
|
||||||
|
{
|
||||||
|
Settings settings = new Settings();
|
||||||
|
settings.setOffline( true );
|
||||||
|
|
||||||
|
MavenExecutionRequest req = new DefaultMavenExecutionRequest().setSettings( settings );
|
||||||
|
|
||||||
|
assertTrue( wagonManager.isOnline() );
|
||||||
|
|
||||||
|
populator.populateDefaults( req, new DefaultConfiguration() );
|
||||||
|
|
||||||
|
assertFalse( wagonManager.isOnline() );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,97 @@
|
||||||
|
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.execution.DefaultMavenExecutionRequest;
|
||||||
|
import org.apache.maven.execution.MavenExecutionRequest;
|
||||||
|
import org.apache.maven.execution.MavenExecutionResult;
|
||||||
|
import org.apache.maven.lifecycle.LifecycleExecutionException;
|
||||||
|
import org.apache.maven.settings.Settings;
|
||||||
|
import org.codehaus.plexus.util.FileUtils;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import edu.emory.mathcs.backport.java.util.Collections;
|
||||||
|
|
||||||
|
/** @author Jason van Zyl */
|
||||||
|
public class EmbedderOfflineTest
|
||||||
|
extends AbstractEmbedderExecutionTestCase
|
||||||
|
{
|
||||||
|
private File tempRepo = new File( System.getProperty( "java.io.tmpdir" ), "test-deploy-repository" );
|
||||||
|
|
||||||
|
public void tearDown()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
if ( tempRepo.exists() && tempRepo.isDirectory() )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
FileUtils.deleteDirectory( tempRepo );
|
||||||
|
}
|
||||||
|
catch ( IOException e )
|
||||||
|
{
|
||||||
|
// ignore, we've done our best.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
super.tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getId()
|
||||||
|
{
|
||||||
|
return "offline-from-embedder";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testShouldFailToDeployWhenOfflineFromSettings()
|
||||||
|
throws IOException
|
||||||
|
{
|
||||||
|
File testDirectory = new File( getBasedir(), "src/test/embedder-test-project" );
|
||||||
|
|
||||||
|
File targetDirectory = new File( getBasedir(), "target/offline-from-settings-deploy" );
|
||||||
|
|
||||||
|
FileUtils.copyDirectoryStructure( testDirectory, targetDirectory );
|
||||||
|
|
||||||
|
Settings settings = new Settings();
|
||||||
|
settings.setOffline( true );
|
||||||
|
|
||||||
|
MavenExecutionRequest request = new DefaultMavenExecutionRequest()
|
||||||
|
.setSettings( settings )
|
||||||
|
.setShowErrors( true )
|
||||||
|
.setBaseDirectory( targetDirectory )
|
||||||
|
.setGoals( Collections.singletonList( "deploy" ) );
|
||||||
|
|
||||||
|
MavenExecutionResult result = maven.execute( request );
|
||||||
|
|
||||||
|
assertTrue( result.hasExceptions() );
|
||||||
|
|
||||||
|
List exceptions = result.getExceptions();
|
||||||
|
assertEquals( 1, exceptions.size() );
|
||||||
|
|
||||||
|
assertTrue( exceptions.get( 0 ) instanceof LifecycleExecutionException );
|
||||||
|
|
||||||
|
LifecycleExecutionException top = (LifecycleExecutionException) exceptions.get( 0 );
|
||||||
|
|
||||||
|
assertNotNull( top.getCause().getCause() );
|
||||||
|
assertTrue( top.getCause().getCause().getMessage().indexOf( "System is offline" ) > -1 );
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue