mirror of https://github.com/apache/maven.git
o Re-added support for offline mode
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@803093 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
24bd8d772f
commit
217c82d26d
|
@ -31,12 +31,26 @@ public class DefaultRepositoryRequest
|
|||
implements RepositoryRequest
|
||||
{
|
||||
|
||||
private boolean offline;
|
||||
|
||||
private ArtifactRepository localRepository;
|
||||
|
||||
private List<ArtifactRepository> remoteRepositories;
|
||||
|
||||
private RepositoryCache cache;
|
||||
|
||||
public boolean isOffline()
|
||||
{
|
||||
return offline;
|
||||
}
|
||||
|
||||
public DefaultRepositoryRequest setOffline( boolean offline )
|
||||
{
|
||||
this.offline = offline;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArtifactRepository getLocalRepository()
|
||||
{
|
||||
return localRepository;
|
||||
|
|
|
@ -29,16 +29,64 @@ import java.util.List;
|
|||
public interface RepositoryRequest
|
||||
{
|
||||
|
||||
/**
|
||||
* Indicates whether network access to remote repositories has been disabled.
|
||||
*
|
||||
* @return {@code true} if remote access has been disabled, {@code false} otherwise.
|
||||
*/
|
||||
boolean isOffline();
|
||||
|
||||
/**
|
||||
* Enables/disables network access to remote repositories.
|
||||
*
|
||||
* @param offline {@code true} to disable remote access, {@code false} to allow network access.
|
||||
* @return This request, never {@code null}.
|
||||
*/
|
||||
RepositoryRequest setOffline( boolean offline );
|
||||
|
||||
/**
|
||||
* Gets the local repository to use.
|
||||
*
|
||||
* @return The local repository to use or {@code null} if not set.
|
||||
*/
|
||||
ArtifactRepository getLocalRepository();
|
||||
|
||||
/**
|
||||
* Sets the local repository to use.
|
||||
*
|
||||
* @param localRepository The local repository to use.
|
||||
* @return This request, never {@code null}.
|
||||
*/
|
||||
RepositoryRequest setLocalRepository( ArtifactRepository localRepository );
|
||||
|
||||
/**
|
||||
* Gets the remote repositories to use.
|
||||
*
|
||||
* @return The remote repositories to use, never {@code null}.
|
||||
*/
|
||||
List<ArtifactRepository> getRemoteRepositories();
|
||||
|
||||
/**
|
||||
* Sets the remote repositories to use.
|
||||
*
|
||||
* @param remoteRepositories The remote repositories to use.
|
||||
* @return This request, never {@code null}.
|
||||
*/
|
||||
RepositoryRequest setRemoteRepositories( List<ArtifactRepository> remoteRepositories );
|
||||
|
||||
/**
|
||||
* Gets the repository cache to use.
|
||||
*
|
||||
* @return The repository cache to use or {@code null} if none.
|
||||
*/
|
||||
RepositoryCache getCache();
|
||||
|
||||
/**
|
||||
* Sets the repository cache to use.
|
||||
*
|
||||
* @param cache The repository cache to use, may be {@code null}.
|
||||
* @return This request, never {@code null}.
|
||||
*/
|
||||
RepositoryRequest setCache( RepositoryCache cache );
|
||||
|
||||
}
|
||||
|
|
|
@ -106,11 +106,16 @@ public class DefaultRepositoryMetadataManager
|
|||
ArtifactRepository localRepository = request.getLocalRepository();
|
||||
List<ArtifactRepository> remoteRepositories = request.getRemoteRepositories();
|
||||
|
||||
if ( !request.isOffline() )
|
||||
{
|
||||
for ( ArtifactRepository repository : remoteRepositories )
|
||||
{
|
||||
ArtifactRepositoryPolicy policy = metadata.isSnapshot() ? repository.getSnapshots() : repository.getReleases();
|
||||
ArtifactRepositoryPolicy policy =
|
||||
metadata.isSnapshot() ? repository.getSnapshots() : repository.getReleases();
|
||||
|
||||
File file = new File( localRepository.getBasedir(), localRepository.pathOfLocalRepositoryMetadata( metadata, repository ) );
|
||||
File file =
|
||||
new File( localRepository.getBasedir(), localRepository.pathOfLocalRepositoryMetadata( metadata,
|
||||
repository ) );
|
||||
|
||||
if ( updateCheckManager.isUpdateRequired( metadata, repository, file ) )
|
||||
{
|
||||
|
@ -131,7 +136,8 @@ public class DefaultRepositoryMetadataManager
|
|||
}
|
||||
catch ( TransferFailedException e )
|
||||
{
|
||||
getLogger().warn( metadata + " could not be retrieved from repository: " + repository.getId() + " due to an error: " + e.getMessage() );
|
||||
getLogger().warn( metadata + " could not be retrieved from repository: " + repository.getId()
|
||||
+ " due to an error: " + e.getMessage() );
|
||||
getLogger().debug( "Exception", e );
|
||||
}
|
||||
finally
|
||||
|
@ -141,7 +147,8 @@ public class DefaultRepositoryMetadataManager
|
|||
}
|
||||
else
|
||||
{
|
||||
getLogger().debug( "Skipping metadata update of " + metadata.getKey() + " from " + repository.getId() );
|
||||
getLogger().debug( "Skipping metadata update of " + metadata.getKey() + " from "
|
||||
+ repository.getId() );
|
||||
}
|
||||
|
||||
// TODO: should this be inside the above check?
|
||||
|
@ -151,6 +158,7 @@ public class DefaultRepositoryMetadataManager
|
|||
file.setLastModified( System.currentTimeMillis() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
|
|
|
@ -68,6 +68,8 @@ public class ArtifactResolutionRequest
|
|||
|
||||
private boolean resolveTransitively = false;
|
||||
|
||||
private boolean offline;
|
||||
|
||||
public ArtifactResolutionRequest()
|
||||
{
|
||||
// nothing here
|
||||
|
@ -78,6 +80,7 @@ public class ArtifactResolutionRequest
|
|||
setLocalRepository( request.getLocalRepository() );
|
||||
setRemoteRepositories( request.getRemoteRepositories() );
|
||||
setCache( request.getCache() );
|
||||
setOffline( request.isOffline() );
|
||||
}
|
||||
|
||||
public Artifact getArtifact()
|
||||
|
@ -230,4 +233,16 @@ public class ArtifactResolutionRequest
|
|||
return this;
|
||||
}
|
||||
|
||||
public boolean isOffline()
|
||||
{
|
||||
return offline;
|
||||
}
|
||||
|
||||
public ArtifactResolutionRequest setOffline( boolean offline )
|
||||
{
|
||||
this.offline = offline;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -162,7 +162,7 @@ public class DefaultArtifactResolver
|
|||
|
||||
destination = artifact.getFile();
|
||||
|
||||
if ( force || !destination.exists() || ( artifact.isSnapshot() && !localCopy ) )
|
||||
if ( ( force || !destination.exists() || ( artifact.isSnapshot() && !localCopy ) ) && !request.isOffline() )
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -175,12 +175,6 @@ public class DefaultArtifactResolver
|
|||
{
|
||||
wagonManager.getArtifact( artifact, remoteRepositories, downloadMonitor );
|
||||
}
|
||||
|
||||
if ( !artifact.isResolved() && !destination.exists() )
|
||||
{
|
||||
throw new ArtifactResolutionException( "Failed to resolve artifact, possibly due to a repository list that is not appropriately equipped for this artifact's metadata.",
|
||||
artifact, remoteRepositories );
|
||||
}
|
||||
}
|
||||
catch ( ResourceDoesNotExistException e )
|
||||
{
|
||||
|
@ -196,6 +190,20 @@ public class DefaultArtifactResolver
|
|||
{
|
||||
artifact.setResolved( true );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( request.isOffline() )
|
||||
{
|
||||
throw new ArtifactResolutionException( "The repository system is offline"
|
||||
+ " and the requested artifact is not locally available", artifact, remoteRepositories );
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArtifactResolutionException( "Failed to resolve artifact, possibly due to a "
|
||||
+ "repository list that is not appropriately equipped for this artifact's metadata.", artifact,
|
||||
remoteRepositories );
|
||||
}
|
||||
}
|
||||
|
||||
// 1.0-SNAPSHOT
|
||||
//
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.apache.maven.repository.legacy.metadata;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
|
@ -45,6 +46,8 @@ public class DefaultMetadataResolutionRequest
|
|||
|
||||
private boolean resolveManagedVersions;
|
||||
|
||||
private boolean offline;
|
||||
|
||||
public DefaultMetadataResolutionRequest()
|
||||
{
|
||||
// does nothing
|
||||
|
@ -55,6 +58,7 @@ public class DefaultMetadataResolutionRequest
|
|||
setLocalRepository( request.getLocalRepository() );
|
||||
setRemoteRepositories( request.getRemoteRepositories() );
|
||||
setCache( request.getCache() );
|
||||
setOffline( request.isOffline() );
|
||||
}
|
||||
|
||||
public Artifact getArtifact()
|
||||
|
@ -83,6 +87,11 @@ public class DefaultMetadataResolutionRequest
|
|||
|
||||
public List<ArtifactRepository> getRemoteRepositories()
|
||||
{
|
||||
if ( remoteRepositories == null )
|
||||
{
|
||||
remoteRepositories = new ArrayList<ArtifactRepository>();
|
||||
}
|
||||
|
||||
return remoteRepositories;
|
||||
}
|
||||
|
||||
|
@ -98,9 +107,10 @@ public class DefaultMetadataResolutionRequest
|
|||
return resolveManagedVersions;
|
||||
}
|
||||
|
||||
public MetadataResolutionRequest setResolveManagedVersions( boolean resolveManagedVersions )
|
||||
public DefaultMetadataResolutionRequest setResolveManagedVersions( boolean resolveManagedVersions )
|
||||
{
|
||||
this.resolveManagedVersions = resolveManagedVersions;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -109,11 +119,23 @@ public class DefaultMetadataResolutionRequest
|
|||
return cache;
|
||||
}
|
||||
|
||||
public MetadataResolutionRequest setCache( RepositoryCache cache )
|
||||
public DefaultMetadataResolutionRequest setCache( RepositoryCache cache )
|
||||
{
|
||||
this.cache = cache;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isOffline()
|
||||
{
|
||||
return offline;
|
||||
}
|
||||
|
||||
public DefaultMetadataResolutionRequest setOffline( boolean offline )
|
||||
{
|
||||
this.offline = offline;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.util.List;
|
|||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.repository.RepositoryCache;
|
||||
import org.apache.maven.artifact.repository.RepositoryRequest;
|
||||
|
||||
/**
|
||||
|
@ -34,6 +35,21 @@ public interface MetadataResolutionRequest
|
|||
extends RepositoryRequest
|
||||
{
|
||||
|
||||
/**
|
||||
* Indicates whether network access to remote repositories has been disabled.
|
||||
*
|
||||
* @return {@code true} if remote access has been disabled, {@code false} otherwise.
|
||||
*/
|
||||
boolean isOffline();
|
||||
|
||||
/**
|
||||
* Enables/disables network access to remote repositories.
|
||||
*
|
||||
* @param offline {@code true} to disable remote access, {@code false} to allow network access.
|
||||
* @return This request, never {@code null}.
|
||||
*/
|
||||
MetadataResolutionRequest setOffline( boolean offline );
|
||||
|
||||
/**
|
||||
* Gets the artifact to resolve metadata for.
|
||||
*
|
||||
|
@ -67,18 +83,33 @@ public interface MetadataResolutionRequest
|
|||
/**
|
||||
* Gets the remote repositories to use for the resolution.
|
||||
*
|
||||
* @return The remote repositories to use for the resolution or {@code null} if not set.
|
||||
* @return The remote repositories to use for the resolution, never {@code null}.
|
||||
*/
|
||||
List<ArtifactRepository> getRemoteRepositories();
|
||||
|
||||
/**
|
||||
* Sets the remote repository to use for the resolution.
|
||||
* Sets the remote repositories to use for the resolution.
|
||||
*
|
||||
* @param remoteRepositories The remote repository to use for the resolution.
|
||||
* @param remoteRepositories The remote repositories to use for the resolution.
|
||||
* @return This request, never {@code null}.
|
||||
*/
|
||||
MetadataResolutionRequest setRemoteRepositories( List<ArtifactRepository> remoteRepositories );
|
||||
|
||||
/**
|
||||
* Gets the repository cache to use.
|
||||
*
|
||||
* @return The repository cache to use or {@code null} if none.
|
||||
*/
|
||||
RepositoryCache getCache();
|
||||
|
||||
/**
|
||||
* Sets the repository cache to use.
|
||||
*
|
||||
* @param cache The repository cache to use, may be {@code null}.
|
||||
* @return This request, never {@code null}.
|
||||
*/
|
||||
MetadataResolutionRequest setCache( RepositoryCache cache );
|
||||
|
||||
/**
|
||||
* Determines whether the managed version information should be retrieved.
|
||||
*
|
||||
|
|
|
@ -898,6 +898,7 @@ public class DefaultMavenExecutionRequest
|
|||
projectBuildingRequest.setRemoteRepositories( getRemoteRepositories() );
|
||||
projectBuildingRequest.setPluginArtifactRepositories( getPluginArtifactRepositories() );
|
||||
projectBuildingRequest.setRepositoryCache( getRepositoryCache() );
|
||||
projectBuildingRequest.setOffline( isOffline() );
|
||||
projectBuildingRequest.setActiveProfileIds( getActiveProfiles() );
|
||||
projectBuildingRequest.setInactiveProfileIds( getInactiveProfiles() );
|
||||
projectBuildingRequest.setProfiles( getProfiles() );
|
||||
|
|
|
@ -156,9 +156,7 @@ public class DefaultLifecycleExecutor
|
|||
|
||||
MavenExecutionResult result = session.getResult();
|
||||
|
||||
RepositoryRequest repositoryRequest = new DefaultRepositoryRequest();
|
||||
repositoryRequest.setLocalRepository( session.getLocalRepository() );
|
||||
repositoryRequest.setCache( session.getRepositoryCache() );
|
||||
RepositoryRequest repositoryRequest = getRepositoryRequest( session, null );
|
||||
|
||||
for ( MavenProject currentProject : session.getProjects() )
|
||||
{
|
||||
|
@ -366,7 +364,11 @@ public class DefaultLifecycleExecutor
|
|||
|
||||
request.setCache( session.getRepositoryCache() );
|
||||
request.setLocalRepository( session.getLocalRepository() );
|
||||
if ( project != null )
|
||||
{
|
||||
request.setRemoteRepositories( project.getPluginArtifactRepositories() );
|
||||
}
|
||||
request.setOffline( session.isOffline() );
|
||||
|
||||
return request;
|
||||
}
|
||||
|
|
|
@ -422,6 +422,7 @@ public class DefaultPluginManager
|
|||
request.setLocalRepository( localRepository );
|
||||
request.setRemoteRepositories( remoteRepositories );
|
||||
request.setCache( session.getRepositoryCache() );
|
||||
request.setOffline( session.isOffline() );
|
||||
pluginArtifacts = getPluginArtifacts( pluginArtifact, plugin, request );
|
||||
}
|
||||
catch ( ArtifactNotFoundException e )
|
||||
|
|
|
@ -167,6 +167,7 @@ public class DefaultProjectBuilder
|
|||
RepositoryRequest repositoryRequest = new DefaultRepositoryRequest();
|
||||
repositoryRequest.setCache( configuration.getRepositoryCache() );
|
||||
repositoryRequest.setLocalRepository( configuration.getLocalRepository() );
|
||||
repositoryRequest.setOffline( configuration.isOffline() );
|
||||
|
||||
ModelResolver resolver =
|
||||
new RepositoryModelResolver( repositorySystem, resolutionErrorHandler, repositoryRequest,
|
||||
|
@ -504,6 +505,7 @@ public class DefaultProjectBuilder
|
|||
repositoryRequest.setLocalRepository( configuration.getLocalRepository() );
|
||||
repositoryRequest.setRemoteRepositories( project.getPluginArtifactRepositories() );
|
||||
repositoryRequest.setCache( configuration.getRepositoryCache() );
|
||||
repositoryRequest.setOffline( configuration.isOffline() );
|
||||
|
||||
lifecycle.populateDefaultConfigurationForPlugins( model.getBuild().getPlugins(), repositoryRequest );
|
||||
}
|
||||
|
|
|
@ -34,6 +34,8 @@ public class DefaultProjectBuildingRequest
|
|||
implements ProjectBuildingRequest
|
||||
{
|
||||
|
||||
private boolean offline;
|
||||
|
||||
private RepositoryCache repositoryCache;
|
||||
|
||||
private ArtifactRepository localRepository;
|
||||
|
@ -84,6 +86,18 @@ public class DefaultProjectBuildingRequest
|
|||
this.topProject = mavenProject;
|
||||
}
|
||||
|
||||
public DefaultProjectBuildingRequest setOffline( boolean offline )
|
||||
{
|
||||
this.offline = offline;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isOffline()
|
||||
{
|
||||
return offline;
|
||||
}
|
||||
|
||||
public ProjectBuildingRequest setRepositoryCache( RepositoryCache repositoryCache )
|
||||
{
|
||||
this.repositoryCache = repositoryCache;
|
||||
|
|
|
@ -33,6 +33,10 @@ import org.apache.maven.wagon.events.TransferListener;
|
|||
public interface ProjectBuildingRequest
|
||||
{
|
||||
|
||||
ProjectBuildingRequest setOffline( boolean offline );
|
||||
|
||||
boolean isOffline();
|
||||
|
||||
ProjectBuildingRequest setRepositoryCache( RepositoryCache repositoryCache );
|
||||
|
||||
RepositoryCache getRepositoryCache();
|
||||
|
|
|
@ -469,6 +469,7 @@ public class MavenMetadataSource
|
|||
configuration.setRepositoryCache( repositoryRequest.getCache() );
|
||||
configuration.setLocalRepository( repositoryRequest.getLocalRepository() );
|
||||
configuration.setRemoteRepositories( repositoryRequest.getRemoteRepositories() );
|
||||
configuration.setOffline( repositoryRequest.isOffline() );
|
||||
configuration.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL );
|
||||
configuration.setProcessPlugins( false );
|
||||
configuration.setSystemProperties( System.getProperties() );
|
||||
|
|
Loading…
Reference in New Issue