From 1265c21645d3fae74eca896ad5facb3ddbafcf3c Mon Sep 17 00:00:00 2001 From: jdcasey Date: Tue, 22 Sep 2009 21:32:48 +0000 Subject: [PATCH] Revert so I can move to a branch and work until race conditions are fixed. [NEXUS-2684] Fixed JettyResourceFetcher to handle redirects properly, and to avoid caching the transferred content in a buffer in memory. Adding a proof-of-context, which I need to figure out how to use to build an automated test out of. This reverts commit 12a6317fc9dcf866d1b34acbfbbf4fba74aad1ff. git-svn-id: file:///opt/svn/repositories/sonatype.org/nexus/trunk/nexus-indexer@5054 2aa8b3fc-8ebb-4439-a84f-95066eaea8ab --- .../updater/jetty/JettyResourceFetcher.java | 120 ++++--- .../updater/jetty/JettyTransferEvent.java | 223 ------------- .../updater/jetty/NtlmConnectionHelper.java | 22 +- .../index/updater/jetty/ResourceExchange.java | 311 +++--------------- .../jetty/TransferListenerSupport.java | 22 +- .../index/updater/FullBootProofOfConcept.java | 112 ------- 6 files changed, 157 insertions(+), 653 deletions(-) delete mode 100644 src/main/java/org/sonatype/nexus/index/updater/jetty/JettyTransferEvent.java delete mode 100644 src/test/java/org/sonatype/nexus/index/updater/FullBootProofOfConcept.java diff --git a/src/main/java/org/sonatype/nexus/index/updater/jetty/JettyResourceFetcher.java b/src/main/java/org/sonatype/nexus/index/updater/jetty/JettyResourceFetcher.java index 84ba4e172d..bdf5325a78 100644 --- a/src/main/java/org/sonatype/nexus/index/updater/jetty/JettyResourceFetcher.java +++ b/src/main/java/org/sonatype/nexus/index/updater/jetty/JettyResourceFetcher.java @@ -1,5 +1,8 @@ package org.sonatype.nexus.index.updater.jetty; +import static org.codehaus.plexus.util.IOUtil.close; + +import org.apache.maven.wagon.LazyFileOutputStream; import org.apache.maven.wagon.authentication.AuthenticationInfo; import org.apache.maven.wagon.events.TransferEvent; import org.apache.maven.wagon.events.TransferListener; @@ -17,7 +20,10 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.net.URL; +import java.util.zip.GZIPInputStream; public class JettyResourceFetcher implements ResourceFetcher @@ -36,8 +42,6 @@ public class JettyResourceFetcher private HttpFields headers; - private int maxRedirects = 4; - // END: configuration fields. // transient fields. @@ -53,29 +57,10 @@ public void retrieve( final String name, final File targetFile ) throws IOException, FileNotFoundException { HttpFields exchangeHeaders = buildHeaders(); - ResourceExchange exchange = new ResourceExchange( targetFile, exchangeHeaders, maxRedirects, listenerSupport ); - + ResourceExchange exchange = new ResourceExchange( exchangeHeaders ); + exchange.setURL( url ); exchange.setMethod( HttpMethods.GET ); - StringBuilder getUrl = new StringBuilder( url ); - if ( getUrl.charAt( getUrl.length() - 1 ) != '/' && !name.startsWith( "/" ) ) - { - getUrl.append( '/' ); - } - getUrl.append( name ); - - exchange.setURL( getUrl.toString() ); - - exchange = get( exchange ); - while ( exchange.prepareForRedirect() ) - { - exchange = get( exchange ); - } - } - - private ResourceExchange get( final ResourceExchange exchange ) - throws IOException - { httpClient.send( exchange ); try { @@ -94,8 +79,6 @@ private ResourceExchange get( final ResourceExchange exchange ) { case ServerResponse.SC_OK: case ServerResponse.SC_NOT_MODIFIED: - case ServerResponse.SC_MOVED_PERMANENTLY: - case ServerResponse.SC_MOVED_TEMPORARILY: break; case ServerResponse.SC_FORBIDDEN: @@ -119,7 +102,9 @@ private ResourceExchange get( final ResourceExchange exchange ) } } - return exchange; + getTransfer( targetFile, exchange ); + targetFile.setLastModified( exchange.getLastModified() ); + listenerSupport.fireGetCompleted( url, targetFile ); } public void connect( final String id, final String url ) @@ -278,17 +263,6 @@ public String getId() } } - public int getMaxRedirects() - { - return maxRedirects; - } - - public JettyResourceFetcher setMaxRedirects( final int maxRedirects ) - { - this.maxRedirects = maxRedirects; - return this; - } - public int getMaxConnections() { return maxConnections; @@ -346,6 +320,78 @@ public JettyResourceFetcher addTransferListener( final TransferListener listener return this; } + private void getTransfer( final File targetFile, final ResourceExchange exchange ) + throws IOException + { + listenerSupport.fireGetStarted( url, targetFile ); + + File destinationDirectory = targetFile.getParentFile(); + if ( destinationDirectory != null && !destinationDirectory.exists() ) + { + destinationDirectory.mkdirs(); + if ( !destinationDirectory.exists() ) + { + throw new IOException( "Specified destination directory cannot be created: " + destinationDirectory ); + } + } + + InputStream input = null; + OutputStream output = null; + try + { + input = getResponseContentSource( exchange ); + output = new LazyFileOutputStream( targetFile ); + + byte[] buffer = new byte[4096]; + + TransferEvent transferEvent = + new TransferEvent( null, listenerSupport.resourceFor( url ), TransferEvent.TRANSFER_PROGRESS, + TransferEvent.REQUEST_GET ); + + transferEvent.setTimestamp( System.currentTimeMillis() ); + + int remaining = exchange.getContentLength(); + while ( remaining > 0 ) + { + int n = input.read( buffer, 0, Math.min( buffer.length, remaining ) ); + + if ( n == -1 ) + { + break; + } + + listenerSupport.fireTransferProgress( transferEvent, buffer, n ); + + output.write( buffer, 0, n ); + + remaining -= n; + } + output.flush(); + } + finally + { + close( input ); + close( output ); + } + } + + private InputStream getResponseContentSource( final ResourceExchange exchange ) + throws IOException + { + InputStream source = exchange.getResponseContentSource(); + + if ( source != null ) + { + String contentEncoding = exchange.getContentEncoding(); + if ( contentEncoding != null && "gzip".equalsIgnoreCase( contentEncoding ) ) + { + source = new GZIPInputStream( source ); + } + } + + return source; + } + private HttpFields buildHeaders() { HttpFields result = new HttpFields(); diff --git a/src/main/java/org/sonatype/nexus/index/updater/jetty/JettyTransferEvent.java b/src/main/java/org/sonatype/nexus/index/updater/jetty/JettyTransferEvent.java deleted file mode 100644 index 8d9c1f8692..0000000000 --- a/src/main/java/org/sonatype/nexus/index/updater/jetty/JettyTransferEvent.java +++ /dev/null @@ -1,223 +0,0 @@ -package org.sonatype.nexus.index.updater.jetty; - -import org.apache.maven.wagon.ConnectionException; -import org.apache.maven.wagon.ResourceDoesNotExistException; -import org.apache.maven.wagon.TransferFailedException; -import org.apache.maven.wagon.Wagon; -import org.apache.maven.wagon.authentication.AuthenticationException; -import org.apache.maven.wagon.authentication.AuthenticationInfo; -import org.apache.maven.wagon.authorization.AuthorizationException; -import org.apache.maven.wagon.events.SessionListener; -import org.apache.maven.wagon.events.TransferEvent; -import org.apache.maven.wagon.events.TransferListener; -import org.apache.maven.wagon.proxy.ProxyInfo; -import org.apache.maven.wagon.proxy.ProxyInfoProvider; -import org.apache.maven.wagon.repository.Repository; -import org.apache.maven.wagon.resource.Resource; - -import java.io.File; -import java.util.List; - -public class JettyTransferEvent - extends TransferEvent -{ - - private static final long serialVersionUID = 1L; - - public JettyTransferEvent( final String url, final Exception exception, final int requestType ) - { - super( new DummyWagon(), resourceFor( url ), exception, requestType ); - } - - public JettyTransferEvent( final String url, final int eventType, final int requestType ) - { - super( new DummyWagon(), resourceFor( url ), eventType, requestType ); - } - - private static Resource resourceFor( final String url ) - { - Resource res = new Resource(); - res.setName( url ); - - return res; - } - - public static final class DummyWagon - implements Wagon - { - - public void addSessionListener( final SessionListener listener ) - { - // TODO Auto-generated method stub - - } - - public void addTransferListener( final TransferListener listener ) - { - // TODO Auto-generated method stub - - } - - public void connect( final Repository source ) - throws ConnectionException, AuthenticationException - { - // TODO Auto-generated method stub - - } - - public void connect( final Repository source, final ProxyInfo proxyInfo ) - throws ConnectionException, AuthenticationException - { - // TODO Auto-generated method stub - - } - - public void connect( final Repository source, final ProxyInfoProvider proxyInfoProvider ) - throws ConnectionException, AuthenticationException - { - // TODO Auto-generated method stub - - } - - public void connect( final Repository source, final AuthenticationInfo authenticationInfo ) - throws ConnectionException, AuthenticationException - { - // TODO Auto-generated method stub - - } - - public void connect( final Repository source, final AuthenticationInfo authenticationInfo, - final ProxyInfo proxyInfo ) - throws ConnectionException, AuthenticationException - { - // TODO Auto-generated method stub - - } - - public void connect( final Repository source, final AuthenticationInfo authenticationInfo, - final ProxyInfoProvider proxyInfoProvider ) - throws ConnectionException, AuthenticationException - { - // TODO Auto-generated method stub - - } - - public void disconnect() - throws ConnectionException - { - // TODO Auto-generated method stub - - } - - public void get( final String resourceName, final File destination ) - throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException - { - // TODO Auto-generated method stub - - } - - public List getFileList( final String destinationDirectory ) - throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException - { - // TODO Auto-generated method stub - return null; - } - - public boolean getIfNewer( final String resourceName, final File destination, final long timestamp ) - throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException - { - // TODO Auto-generated method stub - return false; - } - - public Repository getRepository() - { - // TODO Auto-generated method stub - return null; - } - - public int getTimeout() - { - // TODO Auto-generated method stub - return 0; - } - - public boolean hasSessionListener( final SessionListener listener ) - { - // TODO Auto-generated method stub - return false; - } - - public boolean hasTransferListener( final TransferListener listener ) - { - // TODO Auto-generated method stub - return false; - } - - public boolean isInteractive() - { - // TODO Auto-generated method stub - return false; - } - - public void openConnection() - throws ConnectionException, AuthenticationException - { - // TODO Auto-generated method stub - - } - - public void put( final File source, final String destination ) - throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException - { - // TODO Auto-generated method stub - - } - - public void putDirectory( final File sourceDirectory, final String destinationDirectory ) - throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException - { - // TODO Auto-generated method stub - - } - - public void removeSessionListener( final SessionListener listener ) - { - // TODO Auto-generated method stub - - } - - public void removeTransferListener( final TransferListener listener ) - { - // TODO Auto-generated method stub - - } - - public boolean resourceExists( final String resourceName ) - throws TransferFailedException, AuthorizationException - { - // TODO Auto-generated method stub - return false; - } - - public void setInteractive( final boolean interactive ) - { - // TODO Auto-generated method stub - - } - - public void setTimeout( final int timeoutValue ) - { - // TODO Auto-generated method stub - - } - - public boolean supportsDirectoryCopy() - { - // TODO Auto-generated method stub - return false; - } - - } - -} diff --git a/src/main/java/org/sonatype/nexus/index/updater/jetty/NtlmConnectionHelper.java b/src/main/java/org/sonatype/nexus/index/updater/jetty/NtlmConnectionHelper.java index 89b6c64d04..0ca83e19cf 100644 --- a/src/main/java/org/sonatype/nexus/index/updater/jetty/NtlmConnectionHelper.java +++ b/src/main/java/org/sonatype/nexus/index/updater/jetty/NtlmConnectionHelper.java @@ -24,8 +24,10 @@ import org.apache.maven.wagon.authentication.AuthenticationInfo; import org.apache.maven.wagon.authorization.AuthorizationException; import org.apache.maven.wagon.proxy.ProxyInfo; +import org.codehaus.plexus.util.IOUtil; import org.eclipse.jetty.http.HttpFields; +import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.net.Authenticator; import java.net.HttpURLConnection; @@ -33,6 +35,7 @@ import java.net.URL; import java.net.URLConnection; import java.util.Enumeration; +import java.util.zip.GZIPInputStream; public class NtlmConnectionHelper { @@ -112,24 +115,21 @@ public void doGet( final URL url, final ResourceExchange exchange, final boolean if ( doGet ) { InputStream is = urlConnection.getInputStream(); - String contentEncoding = urlConnection.getHeaderField( "Content-Encoding" ); - if ( contentEncoding != null ) + boolean isGZipped = contentEncoding == null ? false : "gzip".equalsIgnoreCase( contentEncoding ); + if ( isGZipped ) { - exchange.setContentEncoding( contentEncoding ); + is = new GZIPInputStream( is ); } - exchange.setContentLength( urlConnection.getContentLength() ); - exchange.setLastModified( urlConnection.getLastModified() ); - exchange.setResponseContentStream( is ); - } - else - { - exchange.setLastModified( urlConnection.getLastModified() ); + ByteArrayOutputStream content = new ByteArrayOutputStream(); + IOUtil.copy( is, content ); + exchange.setResponseContentBytes( content.toByteArray() ); } + exchange.setLastModified( urlConnection.getLastModified() ); + exchange.setContentLength( urlConnection.getContentLength() ); exchange.setResponseStatus( responseCode ); - exchange.onResponseComplete(); } private void addHeaders( final URLConnection urlConnection ) diff --git a/src/main/java/org/sonatype/nexus/index/updater/jetty/ResourceExchange.java b/src/main/java/org/sonatype/nexus/index/updater/jetty/ResourceExchange.java index 9ae4a7f8bb..e2299608dc 100644 --- a/src/main/java/org/sonatype/nexus/index/updater/jetty/ResourceExchange.java +++ b/src/main/java/org/sonatype/nexus/index/updater/jetty/ResourceExchange.java @@ -1,67 +1,35 @@ package org.sonatype.nexus.index.updater.jetty; -import org.apache.maven.wagon.events.TransferEvent; -import org.codehaus.plexus.util.IOUtil; import org.eclipse.jetty.client.ContentExchange; import org.eclipse.jetty.http.HttpFields; import org.eclipse.jetty.http.HttpHeaders; import org.eclipse.jetty.io.Buffer; import org.eclipse.jetty.io.BufferUtil; -import org.eclipse.jetty.io.nio.NIOBuffer; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; +import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStream; -import java.nio.ByteBuffer; -import java.nio.channels.FileChannel; +import java.io.UnsupportedEncodingException; import java.util.Date; import java.util.Enumeration; -import java.util.zip.GZIPInputStream; - -import edu.emory.mathcs.backport.java.util.Arrays; public class ResourceExchange extends ContentExchange { - private final File targetFile; - - private final int maxRedirects; - - private final TransferListenerSupport listenerSupport; - - protected long lastModified; - - private int redirectCount = 0; - - private boolean redirectionRequested; - - private String redirectionUrl; - - private FileChannel targetChannel; - - private File tmpFile; + protected byte[] _responseContentBytes; - private String originalUrl; + protected int _responseStatus; - private TransferEvent transferEvent; + protected int _contentLength; - private String contentEncoding; + protected String _contentEncoding; - private int responseCode; + protected long _lastModified; - private int contentLength; - - public ResourceExchange( final File targetFile, final HttpFields httpHeaders, final int maxRedirects, - final TransferListenerSupport listenerSupport ) + public ResourceExchange( final HttpFields httpHeaders ) { super( false ); - this.targetFile = targetFile; - this.maxRedirects = maxRedirects; - this.listenerSupport = listenerSupport; addRequestHeaders( httpHeaders ); } @@ -78,265 +46,86 @@ private void addRequestHeaders( final HttpFields headers ) } } - @SuppressWarnings( "deprecation" ) - @Override - public void onResponseHeader( final Buffer name, final Buffer value ) - throws IOException + public int getContentLength() { - super.onResponseHeader( name, value ); - int header = HttpHeaders.CACHE.getOrdinal( name ); - switch ( header ) - { - case HttpHeaders.CONTENT_ENCODING_ORDINAL: - { - contentEncoding = value.toString(); - break; - } - case HttpHeaders.CONTENT_LENGTH_ORDINAL: - { - contentLength = Integer.parseInt( value.toString() ); - break; - } - case HttpHeaders.LAST_MODIFIED_ORDINAL: - { - String lastModifiedStr = BufferUtil.to8859_1_String( value ); - lastModified = - ( lastModifiedStr == null || lastModifiedStr.length() == 0 ? 0 : Date.parse( lastModifiedStr ) ); - break; - } - case HttpHeaders.LOCATION_ORDINAL: - { - redirectionUrl = value.toString(); - - System.out.println( redirectionUrl ); - redirectCount++; - - break; - } - } + return _contentLength; } - @Override - public void onResponseStatus( final Buffer version, final int status, final Buffer reason ) - throws IOException + public void setContentLength( final int length ) { - super.onResponseStatus( version, status, reason ); - if ( status == ServerResponse.SC_MOVED_PERMANENTLY || status == ServerResponse.SC_MOVED_TEMPORARILY ) - { - redirectionRequested = true; - } + _contentLength = length; } - public int getMaxRedirects() + public String getContentEncoding() { - return maxRedirects; + return _contentEncoding; } - public int getRedirectCount() + public void setContentEncoding( final String encoding ) { - return redirectCount; + _contentEncoding = encoding; } - public boolean prepareForRedirect() + public long getLastModified() { - if ( redirectionRequested && redirectCount < maxRedirects ) - { - setURL( redirectionUrl ); - - reset(); - return true; - } - - return false; + return _lastModified; } - @Override - public void reset() + public void setLastModified( final long time ) { - super.reset(); - - redirectionRequested = false; - redirectionUrl = null; + _lastModified = time; } - @Override - protected synchronized void onResponseContent( final Buffer content ) - throws IOException + public void setResponseStatus( final int status ) { - if ( !redirectionRequested ) - { - if ( targetChannel == null ) - { - File destinationDirectory = targetFile.getParentFile(); - if ( destinationDirectory != null && !destinationDirectory.exists() ) - { - destinationDirectory.mkdirs(); - if ( !destinationDirectory.exists() ) - { - throw new IOException( "Specified destination directory cannot be created: " - + destinationDirectory ); - } - } - - newTempFile(); - targetChannel = new FileOutputStream( tmpFile ).getChannel(); - - listenerSupport.fireGetStarted( originalUrl, targetFile ); - - transferEvent = - new JettyTransferEvent( originalUrl, TransferEvent.TRANSFER_PROGRESS, TransferEvent.REQUEST_GET ); - - } - - if ( content instanceof NIOBuffer ) - { - targetChannel.write( ( (NIOBuffer) content ).getByteBuffer() ); - } - else - { - targetChannel.write( ByteBuffer.wrap( content.asArray() ) ); - } - - transferEvent.setTimestamp( System.currentTimeMillis() ); - listenerSupport.fireTransferProgress( transferEvent, content.array(), contentLength ); - } - } - - private void newTempFile() - { - tmpFile = new File( targetFile.getAbsolutePath() + ".tmp" ); - } - - @Override - protected void onResponseComplete() - throws IOException - { - if ( targetChannel != null && targetChannel.isOpen() ) - { - targetChannel.close(); - - if ( "gzip".equals( contentEncoding ) ) - { - InputStream in = null; - OutputStream out = null; - try - { - in = new GZIPInputStream( new FileInputStream( tmpFile ) ); - out = new FileOutputStream( targetFile ); - - listenerSupport.fireDebug( "Unpacking GZIP content to destination: " + targetFile ); - IOUtil.copy( in, out ); - } - finally - { - IOUtil.close( in ); - IOUtil.close( out ); - } - } - else - { - if ( targetFile.exists() ) - { - targetFile.delete(); - } - - tmpFile.renameTo( targetFile ); - targetFile.setLastModified( lastModified ); - } - - tmpFile = null; - - listenerSupport.fireGetCompleted( originalUrl, targetFile ); - transferEvent = null; - } + _responseStatus = status; } @Override - public void setURL( final String url ) - { - if ( originalUrl == null ) - { - originalUrl = url; - } - - super.setURL( url ); - } - - void setResponseContentStream( final InputStream in ) - throws IOException + public int getResponseStatus() { - if ( targetChannel != null ) - { - if ( targetChannel.isOpen() ) - { - targetChannel.close(); - } - - targetChannel = null; - if ( tmpFile.exists() ) - { - tmpFile.delete(); - } - } - - newTempFile(); - - OutputStream out = null; - try + if ( _responseStatus != 0 ) { - out = new FileOutputStream( tmpFile ); - - transferEvent = - new JettyTransferEvent( originalUrl, TransferEvent.TRANSFER_PROGRESS, TransferEvent.REQUEST_GET ); - - byte[] buf = new byte[4096]; - int read = -1; - while ( ( read = in.read( buf ) ) > -1 ) - { - transferEvent.setTimestamp( System.currentTimeMillis() ); - listenerSupport.fireTransferProgress( transferEvent, Arrays.copyOf( buf, read ), contentLength ); - - out.write( buf, 0, read ); - } - - IOUtil.copy( in, out ); - out.flush(); + return _responseStatus; } - finally + else { - IOUtil.close( out ); + return super.getResponseStatus(); } } - void setLastModified( final long lastModified ) + public void setResponseContentBytes( final byte[] bytes ) { - this.lastModified = lastModified; + _responseContentBytes = bytes; } - void setResponseStatus( final int responseCode ) + public InputStream getResponseContentSource() + throws UnsupportedEncodingException { - this.responseCode = responseCode; + return new ByteArrayInputStream( _responseContentBytes != null ? _responseContentBytes + : getResponseContentBytes() ); } + @SuppressWarnings( "deprecation" ) @Override - public int getResponseStatus() + public void onResponseHeader( final Buffer name, final Buffer value ) + throws IOException { - if ( responseCode > 0 ) + super.onResponseHeader( name, value ); + int header = HttpHeaders.CACHE.getOrdinal( name ); + switch ( header ) { - return responseCode; + case HttpHeaders.CONTENT_LENGTH_ORDINAL: + _contentLength = BufferUtil.toInt( value ); + break; + case HttpHeaders.CONTENT_ENCODING_ORDINAL: + _contentEncoding = BufferUtil.to8859_1_String( value ); + break; + case HttpHeaders.LAST_MODIFIED_ORDINAL: + String lastModifiedStr = BufferUtil.to8859_1_String( value ); + _lastModified = + ( lastModifiedStr == null || lastModifiedStr.length() == 0 ? 0 : Date.parse( lastModifiedStr ) ); + break; } - - return super.getResponseStatus(); - } - - void setContentEncoding( final String contentEncoding ) - { - this.contentEncoding = contentEncoding; } - - void setContentLength( final int contentLength ) - { - this.contentLength = contentLength; - } - } diff --git a/src/main/java/org/sonatype/nexus/index/updater/jetty/TransferListenerSupport.java b/src/main/java/org/sonatype/nexus/index/updater/jetty/TransferListenerSupport.java index beaf9fe46e..ca2062ca49 100644 --- a/src/main/java/org/sonatype/nexus/index/updater/jetty/TransferListenerSupport.java +++ b/src/main/java/org/sonatype/nexus/index/updater/jetty/TransferListenerSupport.java @@ -3,6 +3,7 @@ import org.apache.maven.wagon.events.TransferEvent; import org.apache.maven.wagon.events.TransferEventSupport; import org.apache.maven.wagon.events.TransferListener; +import org.apache.maven.wagon.resource.Resource; import java.io.File; @@ -17,7 +18,7 @@ public void addTransferListener( final TransferListener listener ) void fireTransferError( final String url, final Exception e, final int requestType ) { - TransferEvent transferEvent = new JettyTransferEvent( url, e, requestType ); + TransferEvent transferEvent = new TransferEvent( null, resourceFor( url ), e, requestType ); transferEventSupport.fireTransferError( transferEvent ); } @@ -32,7 +33,7 @@ void fireGetCompleted( final String url, final File localFile ) long timestamp = System.currentTimeMillis(); TransferEvent transferEvent = - new JettyTransferEvent( url, TransferEvent.TRANSFER_COMPLETED, TransferEvent.REQUEST_GET ); + new TransferEvent( null, resourceFor( url ), TransferEvent.TRANSFER_COMPLETED, TransferEvent.REQUEST_GET ); transferEvent.setTimestamp( timestamp ); @@ -41,12 +42,20 @@ void fireGetCompleted( final String url, final File localFile ) transferEventSupport.fireTransferCompleted( transferEvent ); } + Resource resourceFor( final String url ) + { + Resource res = new Resource(); + res.setName( url ); + + return res; + } + void fireGetStarted( final String url, final File localFile ) { long timestamp = System.currentTimeMillis(); TransferEvent transferEvent = - new JettyTransferEvent( url, TransferEvent.TRANSFER_STARTED, TransferEvent.REQUEST_GET ); + new TransferEvent( null, resourceFor( url ), TransferEvent.TRANSFER_STARTED, TransferEvent.REQUEST_GET ); transferEvent.setTimestamp( timestamp ); @@ -60,7 +69,7 @@ void fireGetInitiated( final String url, final File localFile ) long timestamp = System.currentTimeMillis(); TransferEvent transferEvent = - new JettyTransferEvent( url, TransferEvent.TRANSFER_INITIATED, TransferEvent.REQUEST_GET ); + new TransferEvent( null, resourceFor( url ), TransferEvent.TRANSFER_INITIATED, TransferEvent.REQUEST_GET ); transferEvent.setTimestamp( timestamp ); @@ -69,9 +78,4 @@ void fireGetInitiated( final String url, final File localFile ) transferEventSupport.fireTransferInitiated( transferEvent ); } - public void fireDebug( final String message ) - { - transferEventSupport.fireDebug( message ); - } - } diff --git a/src/test/java/org/sonatype/nexus/index/updater/FullBootProofOfConcept.java b/src/test/java/org/sonatype/nexus/index/updater/FullBootProofOfConcept.java deleted file mode 100644 index 25abe3b4d0..0000000000 --- a/src/test/java/org/sonatype/nexus/index/updater/FullBootProofOfConcept.java +++ /dev/null @@ -1,112 +0,0 @@ -package org.sonatype.nexus.index.updater; - -import org.apache.maven.wagon.events.TransferEvent; -import org.apache.maven.wagon.events.TransferListener; -import org.codehaus.plexus.DefaultPlexusContainer; -import org.codehaus.plexus.PlexusContainer; -import org.codehaus.plexus.PlexusContainerException; -import org.codehaus.plexus.component.repository.exception.ComponentLookupException; -import org.codehaus.plexus.util.FileUtils; -import org.sonatype.nexus.index.context.DefaultIndexingContext; -import org.sonatype.nexus.index.context.IndexCreator; -import org.sonatype.nexus.index.context.IndexingContext; -import org.sonatype.nexus.index.context.UnsupportedExistingLuceneIndexException; - -import java.io.File; -import java.io.IOException; -import java.text.ParseException; -import java.util.ArrayList; -import java.util.List; - -public class FullBootProofOfConcept -{ - - public static void main( final String[] args ) - throws IOException, ComponentLookupException, PlexusContainerException, ParseException, - UnsupportedExistingLuceneIndexException - { - File basedir = File.createTempFile( "nexus-indexer.", ".dir" ); - try - { - FileUtils.forceDelete( basedir ); - } - catch ( IOException e ) - { - // just do your best to delete this. - } - - basedir.mkdirs(); - - PlexusContainer container = new DefaultPlexusContainer(); - - IndexCreator min = container.lookup( IndexCreator.class, "min" ); - IndexCreator jar = container.lookup( IndexCreator.class, "jarContent" ); - - List creators = new ArrayList(); - creators.add( min ); - creators.add( jar ); - - String repositoryId = "test"; - String repositoryUrl = "http://repo1.maven.org/maven2/"; - String indexUrl = repositoryUrl + ".index"; - - IndexingContext ctx = - new DefaultIndexingContext( repositoryId, repositoryId, basedir, basedir, repositoryUrl, indexUrl, - creators, true ); - - IndexUpdateRequest updateRequest = new IndexUpdateRequest( ctx ); - updateRequest.setTransferListener( new TransferListener() - { - - private int col = 0; - - private int count = 0; - - public void transferStarted( final TransferEvent transferEvent ) - { - System.out.println( "Started transfer: " + transferEvent.getResource().getName() ); - } - - public void transferProgress( final TransferEvent transferEvent, final byte[] buffer, final int length ) - { - if ( count > 16384 ) - { - if ( col > 80 ) - { - System.out.println(); - col = 0; - } - - System.out.print( '.' ); - col++; - count = 0; - } - - count += length; - } - - public void transferInitiated( final TransferEvent transferEvent ) - { - } - - public void transferError( final TransferEvent transferEvent ) - { - System.out.println( "[ERROR]: " + transferEvent.getException().getLocalizedMessage() ); - transferEvent.getException().printStackTrace(); - } - - public void transferCompleted( final TransferEvent transferEvent ) - { - System.out.println( "\nCompleted transfer: " + transferEvent.getResource().getName() ); - } - - public void debug( final String message ) - { - System.out.println( "[DEBUG]: " + message ); - } - } ); - - container.lookup( IndexUpdater.class ).fetchAndUpdateIndex( updateRequest ); - } - -}