o another pass at removing wagon from the core.

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@823064 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2009-10-08 06:32:35 +00:00
parent 0f3d4d243f
commit b6c70ca1f9
32 changed files with 559 additions and 713 deletions

View File

@ -169,13 +169,11 @@ private void resolve( Artifact artifact, RepositoryRequest request, TransferList
if ( artifact.getRepository() != null )
{
// the transformations discovered the artifact - so use it exclusively
wagonManager.getArtifact( artifact, artifact.getRepository(), downloadMonitor,
request.isForceUpdate() );
wagonManager.getArtifact( artifact, artifact.getRepository(), downloadMonitor, request.isForceUpdate() );
}
else
{
wagonManager.getArtifact( artifact, remoteRepositories, downloadMonitor,
request.isForceUpdate() );
wagonManager.getArtifact( artifact, remoteRepositories, downloadMonitor, request.isForceUpdate() );
}
}
catch ( ResourceDoesNotExistException e )

View File

@ -1,4 +1,4 @@
package org.apache.maven.cli;
package org.apache.maven.repository;
/*
* Licensed to the Apache Software Foundation (ASF) under one
@ -9,7 +9,7 @@
* "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
* 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
@ -19,18 +19,16 @@
* under the License.
*/
/**
* Test for {@link BatchModeDownloadMonitor}
*
* @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
* @version $Id$
*/
public class BatchModeDownloadMonitorTest
extends AbstractConsoleDownloadMonitorTest
public class ArtifactDoesNotExistException
extends Exception
{
protected void setUp()
throws Exception
public ArtifactDoesNotExistException( final String message )
{
monitor = new BatchModeDownloadMonitor();
super( message );
}
public ArtifactDoesNotExistException( final String message, final Throwable cause )
{
super( message, cause );
}
}

View File

@ -0,0 +1,292 @@
package org.apache.maven.repository;
/*
* 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.EventObject;
/**
* TransferEvent is used to notify TransferListeners about progress
* in transfer of resources form/to the repository
*
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
* @version $Id$
*/
public class ArtifactTransferEvent
extends EventObject
{
/**
* A transfer was attempted, but has not yet commenced.
*/
public static final int TRANSFER_INITIATED = 0;
/**
* A transfer was started.
*/
public static final int TRANSFER_STARTED = 1;
/**
* A transfer is completed.
*/
public static final int TRANSFER_COMPLETED = 2;
/**
* A transfer is in progress.
*/
public static final int TRANSFER_PROGRESS = 3;
/**
* An error occurred during transfer
*/
public static final int TRANSFER_ERROR = 4;
/**
* Indicates GET transfer (from the repository)
*/
public static final int REQUEST_GET = 5;
/**
* Indicates PUT transfer (to the repository)
*/
public static final int REQUEST_PUT = 6;
private int eventType;
private int requestType;
private Exception exception;
private File localFile;
private MavenArtifact artifact;
public ArtifactTransferEvent( String wagon, final int eventType, final int requestType )
{
super( wagon );
setEventType( eventType );
setRequestType( requestType );
}
public ArtifactTransferEvent( String wagon, final Exception exception, final int requestType )
{
this( wagon, TRANSFER_ERROR, requestType );
this.exception = exception;
}
public MavenArtifact getResource()
{
return artifact;
}
/**
* @return Returns the exception.
*/
public Exception getException()
{
return exception;
}
/**
* Returns the request type.
*
* @return Returns the request type. The Request type is one of
* <code>TransferEvent.REQUEST_GET<code> or <code>TransferEvent.REQUEST_PUT<code>
*/
public int getRequestType()
{
return requestType;
}
/**
* Sets the request type
*
* @param requestType The requestType to set.
* The Request type value should be either
* <code>TransferEvent.REQUEST_GET<code> or <code>TransferEvent.REQUEST_PUT<code>.
* @throws IllegalArgumentException when
*/
public void setRequestType( final int requestType )
{
switch ( requestType )
{
case REQUEST_PUT:
break;
case REQUEST_GET:
break;
default :
throw new IllegalArgumentException( "Illegal request type: " + requestType );
}
this.requestType = requestType;
}
/**
* @return Returns the eventType.
*/
public int getEventType()
{
return eventType;
}
/**
* @param eventType The eventType to set.
*/
public void setEventType( final int eventType )
{
switch ( eventType )
{
case TRANSFER_INITIATED:
break;
case TRANSFER_STARTED:
break;
case TRANSFER_COMPLETED:
break;
case TRANSFER_PROGRESS:
break;
case TRANSFER_ERROR:
break;
default :
throw new IllegalArgumentException( "Illegal event type: " + eventType );
}
this.eventType = eventType;
}
/**
* @return Returns the local file.
*/
public File getLocalFile()
{
return localFile;
}
/**
* @param localFile The local file to set.
*/
public void setLocalFile( File localFile )
{
this.localFile = localFile;
}
public String toString()
{
StringBuffer sb = new StringBuffer();
sb.append( "TransferEvent[" );
switch ( this.getRequestType() )
{
case REQUEST_GET:
sb.append( "GET" );
break;
case REQUEST_PUT:
sb.append( "PUT" );
break;
default:
sb.append( this.getRequestType() );
break;
}
sb.append( "|" );
switch ( this.getEventType() )
{
case TRANSFER_COMPLETED:
sb.append( "COMPLETED" );
break;
case TRANSFER_ERROR:
sb.append( "ERROR" );
break;
case TRANSFER_INITIATED:
sb.append( "INITIATED" );
break;
case TRANSFER_PROGRESS:
sb.append( "PROGRESS" );
break;
case TRANSFER_STARTED:
sb.append( "STARTED" );
break;
default:
sb.append( this.getEventType() );
break;
}
sb.append( "|" );
sb.append( this.getLocalFile() ).append( "|" );
sb.append( "]" );
return sb.toString();
}
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + eventType;
result = prime * result + ( ( exception == null ) ? 0 : exception.hashCode() );
result = prime * result + ( ( localFile == null ) ? 0 : localFile.hashCode() );
result = prime * result + requestType;
return result;
}
public boolean equals( Object obj )
{
if ( this == obj )
{
return true;
}
if ( ( obj == null ) || ( getClass() != obj.getClass() ) )
{
return false;
}
final ArtifactTransferEvent other = (ArtifactTransferEvent) obj;
if ( eventType != other.eventType )
{
return false;
}
if ( exception == null )
{
if ( other.exception != null )
{
return false;
}
}
else if ( !exception.getClass().equals( other.exception.getClass() ) )
{
return false;
}
if ( requestType != other.requestType )
{
return false;
}
else if ( !source.equals( other.source ) )
{
return false;
}
return true;
}
}

View File

@ -0,0 +1,35 @@
package org.apache.maven.repository;
/*
* 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.
*/
public class ArtifactTransferFailedException
extends Exception
{
public ArtifactTransferFailedException( final String message )
{
super( message );
}
public ArtifactTransferFailedException( final String message, final Throwable cause )
{
super( message, cause );
}
}

View File

@ -1,4 +1,4 @@
package org.apache.maven;
package org.apache.maven.repository;
/*
* Licensed to the Apache Software Foundation (ASF) under one
@ -19,14 +19,7 @@
* under the License.
*/
import org.apache.maven.wagon.events.TransferListener;
/**
* @author Jason van Zyl
* @version $Revision$
*/
public interface MavenTransferListener
extends TransferListener
public interface ArtifactTransferListener
{
public boolean isShowChecksumEvents();

View File

@ -0,0 +1,14 @@
package org.apache.maven.repository;
public class MavenArtifact
{
public String getName()
{
return "";
}
public int getContentLength()
{
return 0;
}
}

View File

@ -34,9 +34,6 @@
import org.apache.maven.model.Repository;
import org.apache.maven.settings.Mirror;
import org.apache.maven.settings.Server;
import org.apache.maven.wagon.ResourceDoesNotExistException;
import org.apache.maven.wagon.TransferFailedException;
import org.apache.maven.wagon.events.TransferListener;
/**
* @author Jason van Zyl
@ -147,10 +144,10 @@ ArtifactRepository createLocalRepository( File localRepository )
//
// Raw file transfers
//
void publish( ArtifactRepository repository, File source, String remotePath, TransferListener downloadMonitor )
throws TransferFailedException;
void publish( ArtifactRepository repository, File source, String remotePath, ArtifactTransferListener transferListener )
throws ArtifactTransferFailedException;
void retrieve( ArtifactRepository repository, File destination, String remotePath, TransferListener downloadMonitor )
throws TransferFailedException, ResourceDoesNotExistException;
void retrieve( ArtifactRepository repository, File destination, String remotePath, ArtifactTransferListener transferListener )
throws ArtifactTransferFailedException, ArtifactDoesNotExistException;
}

View File

@ -1,4 +1,4 @@
package org.apache.maven.repository;
package org.apache.maven.repository.legacy;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license
@ -45,15 +45,16 @@
import org.apache.maven.model.RepositoryPolicy;
import org.apache.maven.repository.DelegatingLocalArtifactRepository;
import org.apache.maven.repository.LocalArtifactRepository;
import org.apache.maven.repository.ArtifactTransferListener;
import org.apache.maven.repository.MetadataResolutionRequest;
import org.apache.maven.repository.MetadataResolutionResult;
import org.apache.maven.repository.MirrorSelector;
import org.apache.maven.repository.Proxy;
import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.repository.legacy.WagonManager;
import org.apache.maven.repository.ArtifactDoesNotExistException;
import org.apache.maven.repository.ArtifactTransferFailedException;
import org.apache.maven.settings.Mirror;
import org.apache.maven.settings.Server;
import org.apache.maven.wagon.ResourceDoesNotExistException;
import org.apache.maven.wagon.TransferFailedException;
import org.apache.maven.wagon.events.TransferListener;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
@ -577,21 +578,39 @@ public MetadataResolutionResult resolveMetadata( MetadataResolutionRequest reque
// ArtifactFilter filter,
// List<ResolutionListener> listeners,
// List<ConflictResolver> conflictResolvers )
// ArtifactResolutionResult result = artifactCollector.
// ArtifactResolutionResult result = artifactCollector.
return null;
}
public void retrieve( ArtifactRepository repository, File destination, String remotePath, TransferListener downloadMonitor )
throws TransferFailedException, ResourceDoesNotExistException
public void retrieve( ArtifactRepository repository, File destination, String remotePath, ArtifactTransferListener transferListener )
throws ArtifactTransferFailedException, ArtifactDoesNotExistException
{
wagonManager.getRemoteFile( repository, destination, remotePath, downloadMonitor, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN, true );
try
{
wagonManager.getRemoteFile( repository, destination, remotePath, new TransferListenerAdapter( transferListener ), ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN, true );
}
catch ( org.apache.maven.wagon.TransferFailedException e )
{
throw new ArtifactTransferFailedException( "Error transferring artifact.", e );
}
catch ( org.apache.maven.wagon.ResourceDoesNotExistException e )
{
throw new ArtifactDoesNotExistException( "Requested artifact does not exist.", e );
}
}
public void publish( ArtifactRepository repository, File source, String remotePath, TransferListener downloadMonitor )
throws TransferFailedException
public void publish( ArtifactRepository repository, File source, String remotePath, ArtifactTransferListener transferListener )
throws ArtifactTransferFailedException
{
wagonManager.putRemoteFile( repository, source, remotePath, downloadMonitor );
try
{
wagonManager.putRemoteFile( repository, source, remotePath, new TransferListenerAdapter( transferListener ) );
}
catch ( org.apache.maven.wagon.TransferFailedException e )
{
throw new ArtifactTransferFailedException( "Error transferring artifact.", e );
}
}
//

View File

@ -0,0 +1,40 @@
package org.apache.maven.repository.legacy;
import org.apache.maven.repository.ArtifactTransferListener;
import org.apache.maven.wagon.events.TransferEvent;
import org.apache.maven.wagon.events.TransferListener;
public class TransferListenerAdapter
implements TransferListener
{
private ArtifactTransferListener transferListener;
public TransferListenerAdapter( ArtifactTransferListener transferListener )
{
this.transferListener = transferListener;
}
public void debug( String arg0 )
{
}
public void transferCompleted( TransferEvent arg0 )
{
}
public void transferError( TransferEvent arg0 )
{
}
public void transferInitiated( TransferEvent arg0 )
{
}
public void transferProgress( TransferEvent arg0, byte[] arg1, int arg2 )
{
}
public void transferStarted( TransferEvent arg0 )
{
}
}

View File

@ -21,6 +21,7 @@
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.repository.ArtifactTransferListener;
import org.apache.maven.wagon.ResourceDoesNotExistException;
import org.apache.maven.wagon.TransferFailedException;
import org.apache.maven.wagon.UnsupportedProtocolException;

View File

@ -20,7 +20,6 @@
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.Authentication;
import org.apache.maven.repository.LegacyRepositorySystem;
import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.settings.Server;
import org.codehaus.plexus.PlexusTestCase;

View File

@ -80,20 +80,6 @@
<artifactId>commons-jxpath</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-provider-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-file</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-http-lightweight</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<resources>

View File

@ -30,10 +30,10 @@
import org.apache.maven.model.Profile;
import org.apache.maven.project.DefaultProjectBuildingRequest;
import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.repository.ArtifactTransferListener;
import org.apache.maven.settings.Mirror;
import org.apache.maven.settings.Proxy;
import org.apache.maven.settings.Server;
import org.apache.maven.wagon.events.TransferListener;
/**
* @author Jason van Zyl
@ -112,7 +112,7 @@ public class DefaultMavenExecutionRequest
private List<String> inactiveProfiles;
private TransferListener transferListener;
private ArtifactTransferListener transferListener;
private int loggingLevel = LOGGING_LEVEL_INFO;
@ -348,7 +348,7 @@ public List<String> getInactiveProfiles()
return inactiveProfiles;
}
public TransferListener getTransferListener()
public ArtifactTransferListener getTransferListener()
{
return transferListener;
}
@ -585,7 +585,7 @@ public MavenExecutionRequest setInteractiveMode( boolean interactive )
return this;
}
public MavenExecutionRequest setTransferListener( TransferListener transferListener )
public MavenExecutionRequest setTransferListener( ArtifactTransferListener transferListener )
{
this.transferListener = transferListener;

View File

@ -29,10 +29,10 @@
import org.apache.maven.artifact.repository.RepositoryCache;
import org.apache.maven.model.Profile;
import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.repository.ArtifactTransferListener;
import org.apache.maven.settings.Mirror;
import org.apache.maven.settings.Proxy;
import org.apache.maven.settings.Server;
import org.apache.maven.wagon.events.TransferListener;
import org.codehaus.plexus.logging.Logger;
/**
@ -164,8 +164,8 @@ public interface MavenExecutionRequest
boolean isShowErrors();
// Transfer listeners
MavenExecutionRequest setTransferListener( TransferListener transferListener );
TransferListener getTransferListener();
MavenExecutionRequest setTransferListener( ArtifactTransferListener transferListener );
ArtifactTransferListener getTransferListener();
// Logging
MavenExecutionRequest setLoggingLevel( int loggingLevel );

View File

@ -37,8 +37,8 @@
import org.apache.maven.plugin.prefix.PluginPrefixResolver;
import org.apache.maven.plugin.prefix.PluginPrefixResult;
import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.wagon.ResourceDoesNotExistException;
import org.apache.maven.wagon.TransferFailedException;
import org.apache.maven.repository.ArtifactDoesNotExistException;
import org.apache.maven.repository.ArtifactTransferFailedException;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.Logger;
@ -173,7 +173,7 @@ private PluginPrefixResult resolveFromRepository( PluginPrefixRequest request )
{
repositorySystem.retrieve( repository, destination, remotePath, null );
}
catch ( TransferFailedException e )
catch ( ArtifactTransferFailedException e )
{
if ( logger.isDebugEnabled() )
{
@ -186,7 +186,7 @@ private PluginPrefixResult resolveFromRepository( PluginPrefixRequest request )
continue;
}
catch ( ResourceDoesNotExistException e )
catch ( ArtifactDoesNotExistException e )
{
continue;
}

View File

@ -32,8 +32,8 @@
import org.apache.maven.plugin.version.PluginVersionResolver;
import org.apache.maven.plugin.version.PluginVersionResult;
import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.wagon.ResourceDoesNotExistException;
import org.apache.maven.wagon.TransferFailedException;
import org.apache.maven.repository.ArtifactDoesNotExistException;
import org.apache.maven.repository.ArtifactTransferFailedException;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.Logger;
@ -86,7 +86,7 @@ public PluginVersionResult resolve( PluginVersionRequest request )
{
repositorySystem.retrieve( repository, artifactMetadataFile, remotePath, null );
}
catch ( TransferFailedException e )
catch ( ArtifactTransferFailedException e )
{
if ( logger.isDebugEnabled() )
{
@ -99,7 +99,7 @@ public PluginVersionResult resolve( PluginVersionRequest request )
continue;
}
catch ( ResourceDoesNotExistException e )
catch ( ArtifactDoesNotExistException e )
{
continue;
}

View File

@ -1,8 +1,8 @@
package org.apache.maven.project;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.repository.LegacyRepositorySystem;
import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.repository.legacy.LegacyRepositorySystem;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;

View File

@ -27,8 +27,8 @@
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.artifact.resolver.ResolutionErrorHandler;
import org.apache.maven.model.Dependency;
import org.apache.maven.repository.LegacyRepositorySystem;
import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.repository.legacy.LegacyRepositorySystem;
import org.codehaus.plexus.PlexusTestCase;
/**

View File

@ -18,11 +18,8 @@
<artifactId>maven</artifactId>
<version>3.0-SNAPSHOT</version>
</parent>
<artifactId>maven-embedder</artifactId>
<name>Maven Embedder</name>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
@ -67,26 +64,7 @@
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-provider-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-http-lightweight</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-file</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>easymock</groupId>
<artifactId>easymock</artifactId>
</dependency>
</dependencies>
<build>
<resources>
<resource>

View File

@ -1,128 +0,0 @@
package org.apache.maven.cli;
/*
* 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.MavenTransferListener;
import org.apache.maven.wagon.WagonConstants;
import org.apache.maven.wagon.events.TransferEvent;
import org.codehaus.plexus.logging.AbstractLogEnabled;
/**
* Abstract console download progress meter.
*
* @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
* @version $Id$
* @since 2.0.5
*/
public abstract class AbstractConsoleDownloadMonitor
extends AbstractLogEnabled
implements MavenTransferListener
{
private boolean showChecksumEvents = false;
protected boolean showEvent( TransferEvent event )
{
if ( event.getResource() == null )
{
return true;
}
String resource = event.getResource().getName();
if ( resource == null || resource.trim().length() == 0 )
{
return true;
}
if ( resource.endsWith( ".sha1" ) || resource.endsWith( ".md5" ) )
{
return showChecksumEvents;
}
return true;
}
public void transferInitiated( TransferEvent transferEvent )
{
if ( !showEvent( transferEvent ) )
{
return;
}
String message = transferEvent.getRequestType() == TransferEvent.REQUEST_PUT ? "Uploading" : "Downloading";
String url = transferEvent.getWagon().getRepository().getUrl();
// TODO: can't use getLogger() because this isn't currently instantiated as a component
System.out.println( message + ": " + url + "/" + transferEvent.getResource().getName() );
}
/**
* Do nothing
*/
public void transferStarted( TransferEvent transferEvent )
{
// This space left intentionally blank
}
/**
* Do nothing
*/
public void transferProgress( TransferEvent transferEvent, byte[] buffer, int length )
{
// This space left intentionally blank
}
public void transferCompleted( TransferEvent transferEvent )
{
long contentLength = transferEvent.getResource().getContentLength();
if ( contentLength != WagonConstants.UNKNOWN_LENGTH )
{
String type = ( transferEvent.getRequestType() == TransferEvent.REQUEST_PUT ? "uploaded" : "downloaded" );
String l = contentLength >= 1024 ? ( contentLength / 1024 ) + "K" : contentLength + "b";
System.out.println( l + " " + type );
}
}
public void transferError( TransferEvent transferEvent )
{
// TODO: can't use getLogger() because this isn't currently instantiated as a component
// transferEvent.getException().printStackTrace();
}
/**
* Do nothing
*/
public void debug( String message )
{
// TODO: can't use getLogger() because this isn't currently instantiated as a component
// getLogger().debug( message );
}
public boolean isShowChecksumEvents()
{
return showChecksumEvents;
}
public void setShowChecksumEvents( boolean showChecksumEvents )
{
this.showChecksumEvents = showChecksumEvents;
}
}

View File

@ -0,0 +1,80 @@
package org.apache.maven.cli;
/*
* 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.repository.ArtifactTransferEvent;
import org.apache.maven.repository.ArtifactTransferListener;
public abstract class AbstractMavenTransferListener
implements ArtifactTransferListener
{
private boolean showChecksumEvents = false;
protected boolean showEvent( ArtifactTransferEvent event )
{
if ( event.getResource() == null )
{
return true;
}
String resource = event.getResource().getName();
if ( resource == null || resource.trim().length() == 0 )
{
return true;
}
if ( resource.endsWith( ".sha1" ) || resource.endsWith( ".md5" ) )
{
return showChecksumEvents;
}
return true;
}
public void transferInitiated( ArtifactTransferEvent transferEvent )
{
if ( !showEvent( transferEvent ) )
{
return;
}
}
public void transferCompleted( ArtifactTransferEvent transferEvent )
{
long contentLength = transferEvent.getResource().getContentLength();
if ( contentLength != -1 )
{
String type = ( transferEvent.getRequestType() == ArtifactTransferEvent.REQUEST_PUT ? "uploaded" : "downloaded" );
String l = contentLength >= 1024 ? ( contentLength / 1024 ) + "K" : contentLength + "b";
System.out.println( l + " " + type );
}
}
public boolean isShowChecksumEvents()
{
return showChecksumEvents;
}
public void setShowChecksumEvents( boolean showChecksumEvents )
{
this.showChecksumEvents = showChecksumEvents;
}
}

View File

@ -1,48 +0,0 @@
package org.apache.maven.cli;
/*
* 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.wagon.events.TransferEvent;
/**
* Console download progress meter.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
*/
public class BatchModeDownloadMonitor
extends AbstractConsoleDownloadMonitor
{
public void transferInitiated( TransferEvent transferEvent )
{
if ( !showEvent( transferEvent ) )
{
return;
}
String message = transferEvent.getRequestType() == TransferEvent.REQUEST_PUT ? "Uploading" : "Downloading";
String url = transferEvent.getWagon().getRepository().getUrl();
System.out.println( "url = " + url );
// TODO: can't use getLogger() because this isn't currently instantiated as a component
System.out.println( message + ": " + url + "/" + transferEvent.getResource().getName() );
}
}

View File

@ -19,18 +19,16 @@
* under the License.
*/
/**
* Test for {@link ConsoleDownloadMonitor}
*
* @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
* @version $Id$
*/
public class ConsoleDownloadMonitorTest
extends AbstractConsoleDownloadMonitorTest
import org.apache.maven.repository.ArtifactTransferEvent;
public class BatchModeMavenTransferListener
extends AbstractMavenTransferListener
{
protected void setUp()
throws Exception
public void transferInitiated( ArtifactTransferEvent transferEvent )
{
monitor = new ConsoleDownloadMonitor();
if ( !showEvent( transferEvent ) )
{
return;
}
}
}

View File

@ -30,8 +30,8 @@
import org.apache.commons.cli.CommandLine;
import org.apache.maven.Maven;
import org.apache.maven.MavenTransferListener;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.repository.ArtifactTransferListener;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.cli.CommandLineUtils;
@ -175,15 +175,15 @@ else if ( profileAction.startsWith( "+" ) )
}
}
MavenTransferListener transferListener;
ArtifactTransferListener transferListener;
if ( request.isInteractiveMode() )
{
transferListener = new ConsoleDownloadMonitor();
transferListener = new ConsoleMavenTransferListener();
}
else
{
transferListener = new BatchModeDownloadMonitor();
transferListener = new BatchModeMavenTransferListener();
}
transferListener.setShowChecksumEvents( false );

View File

@ -27,84 +27,13 @@
import org.codehaus.plexus.classworlds.ClassWorld;
import org.codehaus.plexus.logging.Logger;
/**
* Configuration of embedder, used when starting up.
*
* @author mkleint
* @author Jason van Zyl
*/
public interface Configuration
{
// ----------------------------------------------------------------------------
// Settings
// ----------------------------------------------------------------------------
/** Set location of the userSettingsFile settings file to use for the embedder. */
Configuration setUserSettingsFile( File userSettingsFile );
File getUserSettingsFile();
/** Set location of the globalSettingsFiles settings file to use for the embedder. */
Configuration setGlobalSettingsFile( File globalSettingsFiles );
File getGlobalSettingsFile();
// ----------------------------------------------------------------------------
// Logger
// ----------------------------------------------------------------------------
Configuration setMavenEmbedderLogger( Logger logger );
Logger getMavenEmbedderLogger();
// ----------------------------------------------------------------------------
// ClassWorld/ClassLoader
// ----------------------------------------------------------------------------
ClassWorld getClassWorld();
Configuration setClassWorld( ClassWorld classWorld );
Configuration setClassLoader( ClassLoader loader );
PlexusContainer getParentContainer();
Configuration setParentContainer( PlexusContainer parentContainer );
// ----------------------------------------------------------------------------
// Profiles
// ----------------------------------------------------------------------------
/** Add profile to activate. */
Configuration addActiveProfile( String profile );
/** Add profile to inactivate. */
Configuration addInactiveProfile( String profile );
/** Add a list of String instances with names of profiles to activate. */
Configuration addActiveProfiles( List<String> profiles );
/** Add a list of String instances with names of profiles to inactivate. */
Configuration addInactiveProfiles( List<String> profiles );
/** set the system properties to be used during the lifecycle of the embedder. Excluding the time when executing the project, then the properties from MavenExecutionRequestare used. */
Configuration setSystemProperties( Properties properties );
List<String> getActiveProfiles();
List<String> getInactiveProfiles();
// ----------------------------------------------------------------------------
// System Properties
// ----------------------------------------------------------------------------
Properties getSystemProperties();
// ----------------------------------------------------------------------------
// Extensions
// ----------------------------------------------------------------------------
void addExtension( URL url );
List<URL> getExtensions();
}

View File

@ -53,49 +53,4 @@ public interface ConfigurationValidationResult
* Any exception that happened during parsing global settings, or null if there were no errors.
*/
Exception getGlobalSettingsException();
/**
* @deprecated
*/
boolean isUserSettingsFilePresent();
/**
* @deprecated
*/
void setUserSettingsFilePresent( boolean userSettingsFilePresent );
/**
* @deprecated
*/
boolean isUserSettingsFileParses();
/**
* @deprecated
*/
void setUserSettingsFileParses( boolean userSettingsFileParses );
/**
* @deprecated
*/
boolean isGlobalSettingsFilePresent();
/**
* @deprecated
*/
void setGlobalSettingsFilePresent( boolean globalSettingsFilePresent );
/**
* @deprecated
*/
boolean isGlobalSettingsFileParses();
/**
* @deprecated
*/
void setGlobalSettingsFileParses( boolean globalSettingsFileParses );
/**
* @deprecated
*/
void display();
}

View File

@ -19,27 +19,26 @@
* under the License.
*/
import org.apache.maven.wagon.WagonConstants;
import org.apache.maven.wagon.events.TransferEvent;
import org.apache.maven.repository.ArtifactTransferEvent;
/**
* Console download progress meter.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
*/
public class ConsoleDownloadMonitor
extends AbstractConsoleDownloadMonitor
public class ConsoleMavenTransferListener
extends AbstractMavenTransferListener
{
private long complete;
public void transferInitiated( TransferEvent transferEvent )
public void transferInitiated( ArtifactTransferEvent transferEvent )
{
super.transferInitiated( transferEvent );
complete = 0;
}
public void transferProgress( TransferEvent transferEvent, byte[] buffer, int length )
public void transferProgress( ArtifactTransferEvent transferEvent, byte[] buffer, int length )
{
long total = transferEvent.getResource().getContentLength();
complete += length;
@ -53,12 +52,12 @@ public void transferProgress( TransferEvent transferEvent, byte[] buffer, int le
if ( total >= 1024 )
{
System.out.print(
( complete / 1024 ) + "/" + ( total == WagonConstants.UNKNOWN_LENGTH ? "?" : ( total / 1024 ) + "K" )
( complete / 1024 ) + "/" + ( total == -1 ? "?" : ( total / 1024 ) + "K" )
+ "\r" );
}
else
{
System.out.print( complete + "/" + ( total == WagonConstants.UNKNOWN_LENGTH ? "?" : total + "b" ) + "\r" );
System.out.print( complete + "/" + ( total == -1 ? "?" : total + "b" ) + "\r" );
}
}
}

View File

@ -19,92 +19,14 @@
*/
import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.classworlds.ClassWorld;
import org.codehaus.plexus.logging.Logger;
/**
* Default implementation of Configuration intefrace.
*
* @author mkleint
*/
public class DefaultConfiguration
implements Configuration
{
private List<String> inactives;
private List<String> actives;
private File userSettings;
private File globalSettings;
private Properties systemProperties;
private List<URL> extensions = new ArrayList<URL>();
private Logger logger;
private ClassWorld classWorld;
private PlexusContainer parentContainer;
/** Creates a new instance of DefaultConfiguration */
public DefaultConfiguration()
{
}
public Configuration addActiveProfile( String profile )
{
getActiveProfiles().add( profile );
return this;
}
public Configuration addInactiveProfile( String profile )
{
getInactiveProfiles().add( profile );
return this;
}
public Configuration addActiveProfiles( List<String> profiles )
{
getActiveProfiles().addAll( profiles );
return this;
}
public Configuration addInactiveProfiles( List<String> profiles )
{
getInactiveProfiles().addAll( profiles );
return this;
}
public List<String> getActiveProfiles()
{
if ( actives == null )
{
actives = new ArrayList<String>();
}
return actives;
}
public List<String> getInactiveProfiles()
{
if ( inactives == null )
{
inactives = new ArrayList<String>();
}
return inactives;
}
public Configuration setUserSettingsFile( File user )
{
userSettings = user;
@ -126,66 +48,4 @@ public File getGlobalSettingsFile()
{
return globalSettings;
}
public Configuration setSystemProperties( Properties properties )
{
systemProperties = properties;
return this;
}
public Properties getSystemProperties()
{
return systemProperties != null ? systemProperties : System.getProperties();
}
public void addExtension( URL url )
{
extensions.add( url );
}
public List<URL> getExtensions()
{
return extensions;
}
public Configuration setMavenEmbedderLogger( Logger logger )
{
this.logger = logger;
return this;
}
public Logger getMavenEmbedderLogger()
{
return logger;
}
public ClassWorld getClassWorld()
{
return classWorld;
}
public Configuration setClassWorld( ClassWorld classWorld )
{
this.classWorld = classWorld;
return this;
}
public Configuration setClassLoader( ClassLoader loader )
{
classWorld = new ClassWorld( "plexus.core", loader );
return this;
}
public PlexusContainer getParentContainer()
{
return parentContainer;
}
public Configuration setParentContainer( PlexusContainer parentContainer )
{
this.parentContainer = parentContainer;
return this;
}
}

View File

@ -100,31 +100,6 @@ public boolean isUserSettingsFilePresent()
return isSettingsFilePresent( getUserSettings(), getUserSettingsException() );
}
public void setGlobalSettingsFileParses( boolean globalSettingsFileParses )
{
// ignored
}
public void setGlobalSettingsFilePresent( boolean globalSettingsFilePresent )
{
// ignored
}
public void setUserSettingsFileParses( boolean userSettingsFileParses )
{
// ignored
}
public void setUserSettingsFilePresent( boolean userSettingsFilePresent )
{
// ignored
}
public void display()
{
// ignored
}
private boolean isSettingsFilePresent( Settings settings, Throwable e )
{
return ( settings != null ) || ( ( e != null ) && !( e instanceof FileNotFoundException ) );

View File

@ -288,22 +288,6 @@ else if ( MavenExecutionRequest.CHECKSUM_POLICY_FAIL.equals( request.getGlobalCh
logger.info( "Enabling strict checksum verification on all artifact downloads." );
}
ConfigurationValidationResult cvr = validateConfiguration( configuration );
if ( cvr.isUserSettingsFilePresent() && !cvr.isUserSettingsFileParses() )
{
CLIReportingUtils.showError( logger, "Error reading user settings: ", cvr.getUserSettingsException(), showErrors );
return 1;
}
if ( cvr.isGlobalSettingsFilePresent() && !cvr.isGlobalSettingsFileParses() )
{
CLIReportingUtils.showError( logger, "Error reading global settings: ", cvr.getGlobalSettingsException(), showErrors );
return 1;
}
if ( configuration.getGlobalSettingsFile() != null )
{
request.setGlobalSettingsFile( configuration.getGlobalSettingsFile() );
@ -452,18 +436,9 @@ private Configuration buildEmbedderConfiguration( CommandLine commandLine )
globalSettingsFile = DEFAULT_GLOBAL_SETTINGS_FILE;
}
Configuration configuration = new DefaultConfiguration().setUserSettingsFile( userSettingsFile ).setGlobalSettingsFile( globalSettingsFile );
if ( commandLine.hasOption( CLIManager.LOG_FILE ) )
{
File logFile = new File( commandLine.getOptionValue( CLIManager.LOG_FILE ) ).getAbsoluteFile();
configuration.setMavenEmbedderLogger( new FileLogger( logFile ) );
}
else
{
configuration.setMavenEmbedderLogger( new ConsoleLogger( Logger.LEVEL_ERROR, Maven.class.getName()) );
}
Configuration configuration = new DefaultConfiguration()
.setUserSettingsFile( userSettingsFile )
.setGlobalSettingsFile( globalSettingsFile );
return configuration;
}

View File

@ -1,105 +0,0 @@
package org.apache.maven.cli;
/*
* 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 junit.framework.TestCase;
import org.apache.maven.wagon.ConnectionException;
import org.apache.maven.wagon.authentication.AuthenticationException;
import org.apache.maven.wagon.events.TransferEvent;
import org.apache.maven.wagon.providers.file.FileWagon;
import org.apache.maven.wagon.repository.Repository;
import org.apache.maven.wagon.resource.Resource;
/**
* Test for {@link AbstractConsoleDownloadMonitor}
*
* @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
* @version $Id$
*/
public abstract class AbstractConsoleDownloadMonitorTest
extends TestCase
{
protected AbstractConsoleDownloadMonitor monitor;
public AbstractConsoleDownloadMonitor getMonitor()
{
return monitor;
}
public void testTransferInitiated()
throws Exception
{
monitor.transferInitiated( new TransferEventMock() );
}
public void testTransferStarted()
throws Exception
{
monitor.transferStarted( new TransferEventMock() );
}
public void testTransferProgress()
throws Exception
{
byte[] buffer = new byte[1000];
monitor.transferProgress( new TransferEventMock(), buffer, 1000 );
}
public void testTransferCompleted()
throws Exception
{
monitor.transferCompleted( new TransferEventMock() );
}
public void testTransferError()
throws Exception
{
monitor.transferError( new TransferEventMock( new RuntimeException() ) );
}
public void testDebug()
throws Exception
{
monitor.debug( "msg" );
}
private class TransferEventMock
extends TransferEvent
{
public TransferEventMock()
throws ConnectionException, AuthenticationException
{
super( new FileWagon(), new Resource(), TransferEvent.TRANSFER_INITIATED, TransferEvent.REQUEST_GET );
getResource().setContentLength( 100000 );
Repository repository = new Repository();
getWagon().connect( repository );
}
public TransferEventMock( Exception exception )
throws ConnectionException, AuthenticationException
{
super( new FileWagon(), new Resource(), exception, TransferEvent.REQUEST_GET );
getResource().setContentLength( 100000 );
Repository repository = new Repository();
getWagon().connect( repository );
}
}
}

View File

@ -37,6 +37,12 @@ under the License.
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-compat</artifactId>
<exclusions>
<exclusion>
<artifactId>wagon-provider-api</artifactId>
<groupId>org.apache.maven.wagon</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>