o Added transfer listener for project dependency downloads

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@825289 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-10-14 21:22:35 +00:00
parent 3229076989
commit 6821063783
7 changed files with 183 additions and 11 deletions

View File

@ -0,0 +1,114 @@
package org.apache.maven.artifact.resolver;
/*
* 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;
import org.apache.maven.repository.MavenArtifact;
import org.apache.maven.wagon.events.TransferEvent;
import org.apache.maven.wagon.events.TransferListener;
import org.apache.maven.wagon.resource.Resource;
public class TransferListenerAdapter
implements TransferListener
{
private ArtifactTransferListener listener;
public static TransferListener newAdapter( ArtifactTransferListener listener )
{
if ( listener == null )
{
return null;
}
else
{
return new TransferListenerAdapter( listener );
}
}
private TransferListenerAdapter( ArtifactTransferListener listener )
{
this.listener = listener;
}
public void debug( String message )
{
}
public void transferCompleted( TransferEvent transferEvent )
{
listener.transferCompleted( wrap( transferEvent ) );
}
public void transferError( TransferEvent transferEvent )
{
}
public void transferInitiated( TransferEvent transferEvent )
{
listener.transferInitiated( wrap( transferEvent ) );
}
public void transferProgress( TransferEvent transferEvent, byte[] buffer, int length )
{
listener.transferProgress( wrap( transferEvent ), buffer, length );
}
public void transferStarted( TransferEvent transferEvent )
{
}
private ArtifactTransferEvent wrap( TransferEvent event )
{
if ( event == null )
{
return null;
}
else
{
String wagon = event.getWagon().getRepository().getUrl();
MavenArtifact artifact = wrap( event.getResource() );
if ( event.getException() != null )
{
return new ArtifactTransferEvent( wagon, event.getException(), event.getRequestType(), artifact );
}
else
{
return new ArtifactTransferEvent( wagon, event.getEventType(), event.getRequestType(), artifact );
}
}
}
private MavenArtifact wrap( Resource resource )
{
if ( resource == null )
{
return null;
}
else
{
return new MavenArtifact( resource.getName(), resource.getContentLength() );
}
}
}

View File

@ -78,18 +78,20 @@ public class ArtifactTransferEvent
private MavenArtifact artifact;
public ArtifactTransferEvent( String wagon, final int eventType, final int requestType )
public ArtifactTransferEvent( String wagon, final int eventType, final int requestType, MavenArtifact artifact )
{
super( wagon );
setEventType( eventType );
setRequestType( requestType );
this.artifact = artifact;
}
public ArtifactTransferEvent( String wagon, final Exception exception, final int requestType )
public ArtifactTransferEvent( String wagon, final Exception exception, final int requestType, MavenArtifact artifact )
{
this( wagon, TRANSFER_ERROR, requestType );
this( wagon, TRANSFER_ERROR, requestType, artifact );
this.exception = exception;
}

View File

@ -21,7 +21,14 @@ package org.apache.maven.repository;
public interface ArtifactTransferListener
{
public boolean isShowChecksumEvents();
boolean isShowChecksumEvents();
void setShowChecksumEvents( boolean showChecksumEvents );
void transferInitiated( ArtifactTransferEvent transferEvent );
void transferProgress( ArtifactTransferEvent transferEvent, byte[] buffer, int length );
void transferCompleted( ArtifactTransferEvent transferEvent );
public void setShowChecksumEvents( boolean showChecksumEvents );
}

View File

@ -1,14 +1,45 @@
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 MavenArtifact
{
private String name;
private long contentLength;
public MavenArtifact( String name, long contentLength )
{
this.name = name;
this.contentLength = contentLength;
}
public String getName()
{
return "";
return name;
}
public int getContentLength()
public long getContentLength()
{
return 0;
}
return contentLength;
}
}

View File

@ -34,6 +34,7 @@ import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.artifact.resolver.MultipleArtifactsNotFoundException;
import org.apache.maven.artifact.resolver.ResolutionErrorHandler;
import org.apache.maven.artifact.resolver.TransferListenerAdapter;
import org.apache.maven.artifact.resolver.filter.CumulativeScopeArtifactFilter;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.project.MavenProject;
@ -135,7 +136,7 @@ public class DefaultProjectDependenciesResolver
.setOffline( session.isOffline() )
.setForceUpdate( session.getRequest().isUpdateSnapshots() )
.setCache( session.getRepositoryCache() );
// FIXME setTransferListener
request.setTransferListener( TransferListenerAdapter.newAdapter( session.getRequest().getTransferListener() ) );
Set<String> projectIds = null;

View File

@ -57,6 +57,11 @@ public abstract class AbstractMavenTransferListener
}
}
public void transferProgress( ArtifactTransferEvent transferEvent, byte[] buffer, int length )
{
}
public void transferCompleted( ArtifactTransferEvent transferEvent )
{
long contentLength = transferEvent.getResource().getContentLength();

View File

@ -36,6 +36,18 @@ public class ConsoleMavenTransferListener
super.transferInitiated( transferEvent );
complete = 0;
if ( !showEvent( transferEvent ) )
{
return;
}
String message =
transferEvent.getRequestType() == ArtifactTransferEvent.REQUEST_PUT ? "Uploading" : "Downloading";
String url = transferEvent.getSource().toString();
System.out.println( message + ": " + url + "/" + transferEvent.getResource().getName() );
}
public void transferProgress( ArtifactTransferEvent transferEvent, byte[] buffer, int length )