mirror of https://github.com/apache/maven.git
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:
parent
3229076989
commit
6821063783
|
@ -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() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -78,18 +78,20 @@ public class ArtifactTransferEvent
|
||||||
|
|
||||||
private MavenArtifact artifact;
|
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 );
|
super( wagon );
|
||||||
|
|
||||||
setEventType( eventType );
|
setEventType( eventType );
|
||||||
|
|
||||||
setRequestType( requestType );
|
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;
|
this.exception = exception;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,14 @@ package org.apache.maven.repository;
|
||||||
|
|
||||||
public interface ArtifactTransferListener
|
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 );
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,45 @@
|
||||||
package org.apache.maven.repository;
|
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
|
public class MavenArtifact
|
||||||
{
|
{
|
||||||
public String getName()
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private long contentLength;
|
||||||
|
|
||||||
|
public MavenArtifact( String name, long contentLength )
|
||||||
{
|
{
|
||||||
return "";
|
this.name = name;
|
||||||
|
this.contentLength = contentLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getContentLength()
|
public String getName()
|
||||||
{
|
{
|
||||||
return 0;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getContentLength()
|
||||||
|
{
|
||||||
|
return contentLength;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
|
||||||
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
|
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
|
||||||
import org.apache.maven.artifact.resolver.MultipleArtifactsNotFoundException;
|
import org.apache.maven.artifact.resolver.MultipleArtifactsNotFoundException;
|
||||||
import org.apache.maven.artifact.resolver.ResolutionErrorHandler;
|
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.artifact.resolver.filter.CumulativeScopeArtifactFilter;
|
||||||
import org.apache.maven.execution.MavenSession;
|
import org.apache.maven.execution.MavenSession;
|
||||||
import org.apache.maven.project.MavenProject;
|
import org.apache.maven.project.MavenProject;
|
||||||
|
@ -135,7 +136,7 @@ public class DefaultProjectDependenciesResolver
|
||||||
.setOffline( session.isOffline() )
|
.setOffline( session.isOffline() )
|
||||||
.setForceUpdate( session.getRequest().isUpdateSnapshots() )
|
.setForceUpdate( session.getRequest().isUpdateSnapshots() )
|
||||||
.setCache( session.getRepositoryCache() );
|
.setCache( session.getRepositoryCache() );
|
||||||
// FIXME setTransferListener
|
request.setTransferListener( TransferListenerAdapter.newAdapter( session.getRequest().getTransferListener() ) );
|
||||||
|
|
||||||
Set<String> projectIds = null;
|
Set<String> projectIds = null;
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,11 @@ public abstract class AbstractMavenTransferListener
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void transferProgress( ArtifactTransferEvent transferEvent, byte[] buffer, int length )
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public void transferCompleted( ArtifactTransferEvent transferEvent )
|
public void transferCompleted( ArtifactTransferEvent transferEvent )
|
||||||
{
|
{
|
||||||
long contentLength = transferEvent.getResource().getContentLength();
|
long contentLength = transferEvent.getResource().getContentLength();
|
||||||
|
|
|
@ -36,6 +36,18 @@ public class ConsoleMavenTransferListener
|
||||||
super.transferInitiated( transferEvent );
|
super.transferInitiated( transferEvent );
|
||||||
|
|
||||||
complete = 0;
|
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 )
|
public void transferProgress( ArtifactTransferEvent transferEvent, byte[] buffer, int length )
|
||||||
|
|
Loading…
Reference in New Issue