diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/TransferListenerAdapter.java b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/TransferListenerAdapter.java new file mode 100644 index 0000000000..179175b112 --- /dev/null +++ b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/TransferListenerAdapter.java @@ -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() ); + } + } + +} diff --git a/maven-compat/src/main/java/org/apache/maven/repository/ArtifactTransferEvent.java b/maven-compat/src/main/java/org/apache/maven/repository/ArtifactTransferEvent.java index 05525f1f58..6b5b6080eb 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/ArtifactTransferEvent.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/ArtifactTransferEvent.java @@ -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; } diff --git a/maven-compat/src/main/java/org/apache/maven/repository/ArtifactTransferListener.java b/maven-compat/src/main/java/org/apache/maven/repository/ArtifactTransferListener.java index 3e365b5fc4..45e063907e 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/ArtifactTransferListener.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/ArtifactTransferListener.java @@ -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 ); } diff --git a/maven-compat/src/main/java/org/apache/maven/repository/MavenArtifact.java b/maven-compat/src/main/java/org/apache/maven/repository/MavenArtifact.java index e9ae6e5d8c..0ded45b957 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/MavenArtifact.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/MavenArtifact.java @@ -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; + } + } diff --git a/maven-core/src/main/java/org/apache/maven/DefaultProjectDependenciesResolver.java b/maven-core/src/main/java/org/apache/maven/DefaultProjectDependenciesResolver.java index 50b6d5e1eb..2faa41cb87 100644 --- a/maven-core/src/main/java/org/apache/maven/DefaultProjectDependenciesResolver.java +++ b/maven-core/src/main/java/org/apache/maven/DefaultProjectDependenciesResolver.java @@ -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 projectIds = null; diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/AbstractMavenTransferListener.java b/maven-embedder/src/main/java/org/apache/maven/cli/AbstractMavenTransferListener.java index 622556cd80..93349cb577 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/AbstractMavenTransferListener.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/AbstractMavenTransferListener.java @@ -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(); diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/ConsoleMavenTransferListener.java b/maven-embedder/src/main/java/org/apache/maven/cli/ConsoleMavenTransferListener.java index a609715735..b2a1306041 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/ConsoleMavenTransferListener.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/ConsoleMavenTransferListener.java @@ -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 )