Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvladt2011-03-31 19:48:30 +0000
committervladt2011-03-31 19:48:30 +0000
commit3c2a9f942399b0e0e85d7f5beb21e65f7d35e923 (patch)
tree96a6a2f1a61eebeb9a1b3fd8148ed614bbb7a6ae
parentcc33e91bb09b843f922618db8232af8379e0c9e8 (diff)
downloadm2e-core-3c2a9f942399b0e0e85d7f5beb21e65f7d35e923.tar.gz
m2e-core-3c2a9f942399b0e0e85d7f5beb21e65f7d35e923.tar.xz
m2e-core-3c2a9f942399b0e0e85d7f5beb21e65f7d35e923.zip
341531: The downloads that use the ahc connector cannot be canceled
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/AbstractTransferListenerAdapter.java2
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/ArtifactTransferListenerAdapter.java10
-rw-r--r--org.eclipse.m2e.maven.runtime/.classpath1
-rw-r--r--org.eclipse.m2e.maven.runtime/build.properties1
-rw-r--r--org.eclipse.m2e.maven.runtime/src/README5
-rw-r--r--org.eclipse.m2e.maven.runtime/src/aether-1.12/org/sonatype/aether/connector/async/CompletionHandler.java388
6 files changed, 403 insertions, 4 deletions
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/AbstractTransferListenerAdapter.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/AbstractTransferListenerAdapter.java
index 8da15a24..a73cf816 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/AbstractTransferListenerAdapter.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/AbstractTransferListenerAdapter.java
@@ -68,7 +68,7 @@ abstract class AbstractTransferListenerAdapter {
monitor.subTask(Messages.AbstractTransferListenerAdapter_4 + artifactUrl);
}
- protected void transferProgress(String artifactUrl, long total, int length) {
+ protected void transferProgress(String artifactUrl, long total, int length) throws OperationCanceledException {
if(monitor.isCanceled()) {
throw new OperationCanceledException(Messages.AbstractTransferListenerAdapter_cancelled);
}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/ArtifactTransferListenerAdapter.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/ArtifactTransferListenerAdapter.java
index 7cc144b2..5f8467cf 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/ArtifactTransferListenerAdapter.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/ArtifactTransferListenerAdapter.java
@@ -12,7 +12,9 @@
package org.eclipse.m2e.core.internal.embedder;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.sonatype.aether.transfer.TransferCancelledException;
import org.sonatype.aether.transfer.TransferEvent;
import org.sonatype.aether.transfer.TransferListener;
@@ -32,11 +34,15 @@ public class ArtifactTransferListenerAdapter extends AbstractTransferListenerAda
transferInitiated(event.getResource().getRepositoryUrl() + event.getResource().getResourceName());
}
- public void transferProgressed(TransferEvent event) {
+ public void transferProgressed(TransferEvent event) throws TransferCancelledException {
long total = event.getResource().getContentLength();
String artifactUrl = event.getResource().getRepositoryUrl() + event.getResource().getResourceName();
- transferProgress(artifactUrl, total, event.getDataBuffer().remaining());
+ try {
+ transferProgress(artifactUrl, total, event.getDataBuffer().remaining());
+ } catch(OperationCanceledException e) {
+ throw new TransferCancelledException();
+ }
}
public void transferStarted(TransferEvent event) {
diff --git a/org.eclipse.m2e.maven.runtime/.classpath b/org.eclipse.m2e.maven.runtime/.classpath
index 5d9ff70b..1e696db0 100644
--- a/org.eclipse.m2e.maven.runtime/.classpath
+++ b/org.eclipse.m2e.maven.runtime/.classpath
@@ -3,6 +3,7 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src/maven-3.0.3"/>
+ <classpathentry kind="src" path="src/aether-1.12"/>
<classpathentry exported="true" kind="lib" path="jars/maven-embedder-3.0.2.jar"/>
<classpathentry exported="true" kind="lib" path="jars/maven-settings-3.0.2.jar"/>
<classpathentry exported="true" kind="lib" path="jars/maven-plugin-api-3.0.2.jar"/>
diff --git a/org.eclipse.m2e.maven.runtime/build.properties b/org.eclipse.m2e.maven.runtime/build.properties
index 451f3237..aa9ca638 100644
--- a/org.eclipse.m2e.maven.runtime/build.properties
+++ b/org.eclipse.m2e.maven.runtime/build.properties
@@ -16,4 +16,5 @@ jars.compile.order = local-patches.jar
source.local-patches.jar = src/main/java/
output.local-patches.jar = target/classes
source.local-patches.jar = src/maven-3.0.3/
+source.local-patches.jar = src/aether-1.12/
diff --git a/org.eclipse.m2e.maven.runtime/src/README b/org.eclipse.m2e.maven.runtime/src/README
index 964d6db8..4ef4415d 100644
--- a/org.eclipse.m2e.maven.runtime/src/README
+++ b/org.eclipse.m2e.maven.runtime/src/README
@@ -2,4 +2,7 @@ The following changes were cherry-picked
maven-3.0.3 (SNAPSHOT)
MNG-4988 API to calculate execution plan without full mojo execution configuration
-MNG-5003 populate mojo descriptor with cached plugin realm \ No newline at end of file
+MNG-5003 populate mojo descriptor with cached plugin realm
+
+aether-1.12
+AETHER-92 TransferCancelledException must interrupt the current download.
diff --git a/org.eclipse.m2e.maven.runtime/src/aether-1.12/org/sonatype/aether/connector/async/CompletionHandler.java b/org.eclipse.m2e.maven.runtime/src/aether-1.12/org/sonatype/aether/connector/async/CompletionHandler.java
new file mode 100644
index 00000000..8b13300d
--- /dev/null
+++ b/org.eclipse.m2e.maven.runtime/src/aether-1.12/org/sonatype/aether/connector/async/CompletionHandler.java
@@ -0,0 +1,388 @@
+package org.sonatype.aether.connector.async;
+
+/*******************************************************************************
+ * Copyright (c) 2010-2011 Sonatype, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Apache License v2.0 which accompanies this distribution.
+ * The Eclipse Public License is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * The Apache License v2.0 is available at
+ * http://www.apache.org/licenses/LICENSE-2.0.html
+ * You may elect to redistribute this code under either of these licenses.
+ *******************************************************************************/
+
+import com.ning.http.client.AsyncHandler;
+import com.ning.http.client.AsyncHttpClient;
+import com.ning.http.client.HttpResponseBodyPart;
+import com.ning.http.client.HttpResponseHeaders;
+import com.ning.http.client.HttpResponseStatus;
+import com.ning.http.client.ProgressAsyncHandler;
+import com.ning.http.client.Response;
+import org.sonatype.aether.spi.log.Logger;
+import org.sonatype.aether.transfer.TransferCancelledException;
+import org.sonatype.aether.transfer.TransferEvent;
+import org.sonatype.aether.transfer.TransferListener;
+import org.sonatype.aether.transfer.TransferResource;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.nio.ByteBuffer;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.concurrent.atomic.AtomicReference;
+
+/**
+ * An {@link AsyncHandler} for handling asynchronous download an upload.
+ *
+ * @author Jeanfrancois Arcand
+ */
+class CompletionHandler
+ implements ProgressAsyncHandler<Response>
+{
+ private final Logger logger;
+
+ private HttpResponseStatus status;
+
+ private HttpResponseHeaders headers;
+
+ private final ConcurrentLinkedQueue<TransferListener> listeners = new ConcurrentLinkedQueue<TransferListener>();
+
+ private final AsyncHttpClient httpClient;
+
+ private final AtomicLong byteTransfered = new AtomicLong();
+
+ private final AtomicReference<Throwable> exception = new AtomicReference<Throwable>();
+
+ private final TransferResource transferResource;
+
+ private final TransferEvent.RequestType requestType;
+
+ public CompletionHandler( TransferResource transferResource, AsyncHttpClient httpClient, Logger logger,
+ TransferEvent.RequestType requestType )
+ {
+ this.httpClient = httpClient;
+ this.transferResource = transferResource;
+ this.logger = logger;
+ this.requestType = requestType;
+ }
+
+ public STATE onHeaderWriteCompleted()
+ {
+ if ( TransferEvent.RequestType.PUT.equals( requestType ) )
+ {
+ byteTransfered.set( 0 );
+ try
+ {
+ fireTransferStarted();
+ }
+ catch ( TransferCancelledException e )
+ {
+ return STATE.ABORT;
+ }
+ }
+ return STATE.CONTINUE;
+ }
+
+ public STATE onContentWriteCompleted()
+ {
+ return STATE.CONTINUE;
+ }
+
+ public STATE onContentWriteProgress( long amount, long current, long total )
+ {
+ return STATE.CONTINUE;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ /* @Override */
+ public STATE onBodyPartReceived( final HttpResponseBodyPart content )
+ throws Exception
+ {
+ try
+ {
+ fireTransferProgressed( content.getBodyPartBytes() );
+ }
+ catch ( TransferCancelledException e )
+ {
+ return STATE.ABORT;
+ }
+ catch ( Exception ex )
+ {
+ if ( logger.isDebugEnabled() )
+ {
+ logger.debug( "", ex );
+ }
+ }
+ return STATE.CONTINUE;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ /* @Override */
+ public STATE onStatusReceived( final HttpResponseStatus status )
+ throws Exception
+ {
+ this.status = status;
+
+ if ( !TransferEvent.RequestType.PUT.equals( requestType ) )
+ {
+ if ( status.getStatusCode() >= 200 && status.getStatusCode() < 300 )
+ {
+ try
+ {
+ fireTransferStarted();
+ }
+ catch ( TransferCancelledException e )
+ {
+ return STATE.ABORT;
+ }
+ }
+ }
+
+ return ( status.getStatusCode() == HttpURLConnection.HTTP_NOT_FOUND ? STATE.ABORT : STATE.CONTINUE );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ /* @Override */
+ public STATE onHeadersReceived( final HttpResponseHeaders headers )
+ throws Exception
+ {
+ this.headers = headers;
+ return STATE.CONTINUE;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ /* @Override */
+ public final Response onCompleted()
+ throws Exception
+ {
+ // The connection has timed out
+ if ( status == null )
+ {
+ throw new TransferException( "Invalid AHC State. Response will possibly gets corrupted." );
+ }
+ return onCompleted( httpClient.getProvider().prepareResponse( status, headers,
+ Collections.<HttpResponseBodyPart> emptyList() ) );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ /* @Override */
+ public void onThrowable( Throwable t )
+ {
+ exception.set( t );
+ }
+
+ /**
+ * Invoked once the HTTP response has been fully read.
+ *
+ * @param response The {@link com.ning.http.client.Response}
+ * @return Type of the value that will be returned by the associated {@link java.util.concurrent.Future}
+ */
+ public Response onCompleted( Response response )
+ throws Exception
+ {
+ if ( response != null && response.hasResponseStatus() && response.getStatusCode() >= HttpURLConnection.HTTP_OK
+ && response.getStatusCode() <= HttpURLConnection.HTTP_CREATED )
+ {
+ fireTransferSucceeded( response );
+ }
+ return response;
+ }
+
+ void fireTransferProgressed( final byte[] buffer )
+ throws TransferCancelledException
+ {
+ fireTransferProgressed( ByteBuffer.wrap( buffer ) );
+ }
+
+ void fireTransferProgressed( final ByteBuffer buffer )
+ throws TransferCancelledException
+ {
+ final long bytesTransferred = byteTransfered.addAndGet( buffer.remaining() );
+
+ final TransferEvent transferEvent = new AsyncTransferEvent()
+ {
+
+ public EventType getType()
+ {
+ return TransferEvent.EventType.PROGRESSED;
+ }
+
+ public long getTransferredBytes()
+ {
+ return bytesTransferred;
+ }
+
+ public ByteBuffer getDataBuffer()
+ {
+ return buffer.asReadOnlyBuffer();
+ }
+
+ public int getDataLength()
+ {
+ return buffer.remaining();
+ }
+
+ };
+
+ for ( Iterator<TransferListener> iter = listeners.iterator(); iter.hasNext(); )
+ {
+ final TransferListener listener = iter.next();
+ listener.transferProgressed( transferEvent );
+ }
+ }
+
+ void fireTransferSucceeded( final Response response )
+ throws IOException
+ {
+ final long bytesTransferred = byteTransfered.get();
+
+ final TransferEvent transferEvent = new AsyncTransferEvent()
+ {
+
+ public EventType getType()
+ {
+ return TransferEvent.EventType.SUCCEEDED;
+ }
+
+ public long getTransferredBytes()
+ {
+ return bytesTransferred;
+ }
+
+ };
+
+ for ( Iterator<TransferListener> iter = listeners.iterator(); iter.hasNext(); )
+ {
+ final TransferListener listener = iter.next();
+ listener.transferSucceeded( transferEvent );
+ }
+ }
+
+ void fireTransferFailed()
+ throws IOException
+ {
+ final long bytesTransferred = byteTransfered.get();
+
+ final TransferEvent transferEvent = new AsyncTransferEvent()
+ {
+
+ public EventType getType()
+ {
+ return TransferEvent.EventType.FAILED;
+ }
+
+ public long getTransferredBytes()
+ {
+ return bytesTransferred;
+ }
+
+ };
+
+ for ( Iterator<TransferListener> iter = listeners.iterator(); iter.hasNext(); )
+ {
+ final TransferListener listener = iter.next();
+ listener.transferFailed( transferEvent );
+
+ }
+ }
+
+ void fireTransferStarted()
+ throws TransferCancelledException
+ {
+ final TransferEvent transferEvent = new AsyncTransferEvent()
+ {
+
+ public EventType getType()
+ {
+ return TransferEvent.EventType.STARTED;
+ }
+
+ public long getTransferredBytes()
+ {
+ return 0;
+ }
+
+ };
+
+ for ( Iterator<TransferListener> iter = listeners.iterator(); iter.hasNext(); )
+ {
+ final TransferListener listener = iter.next();
+ listener.transferStarted( transferEvent );
+ }
+ }
+
+ public boolean addTransferListener( TransferListener listener )
+ {
+ if ( listener == null )
+ {
+ return false;
+ }
+ return listeners.offer( listener );
+ }
+
+ public boolean removeTransferListener( TransferListener listener )
+ {
+ if ( listener == null )
+ {
+ return false;
+ }
+ return listeners.remove( listener );
+ }
+
+ protected HttpResponseStatus status()
+ {
+ return status;
+ }
+
+ abstract class AsyncTransferEvent
+ implements TransferEvent
+ {
+
+ public RequestType getRequestType()
+ {
+ return requestType;
+ }
+
+ public TransferResource getResource()
+ {
+ return transferResource;
+ }
+
+ public ByteBuffer getDataBuffer()
+ {
+ return null;
+ }
+
+ public int getDataLength()
+ {
+ return 0;
+ }
+
+ public Exception getException()
+ {
+ return ( Exception.class.isAssignableFrom( exception.get().getClass() ) ? Exception.class.cast( exception.get() )
+ : new Exception( exception.get() ) );
+ }
+
+ @Override
+ public String toString()
+ {
+ return getRequestType() + " " + getType() + " " + getResource();
+ }
+
+ }
+
+}

Back to the top