@Override public String toString() { return getState() + " " + getArtifact() + " - " + ( isExistenceCheck() ? "?" : "" ) + getFile(); }
public TransferWrapper( ArtifactTransfer transfer ) { this.artifactTransfer = transfer; this.transfer = transfer; this.type = Type.ARTIFACT; if ( transfer instanceof ArtifactDownload ) { this.checksumPolicy = ( (ArtifactDownload) transfer ).getChecksumPolicy(); this.existenceCheck = ( (ArtifactDownload) transfer ).isExistenceCheck(); } }
/** * Creates a new download with the specified properties. * * @param artifact The artifact to download, may be {@code null}. * @param context The context in which this download is performed, may be {@code null}. * @param file The local file to download the artifact to, may be {@code null}. * @param checksumPolicy The checksum policy, may be {@code null}. */ public ArtifactDownload( Artifact artifact, String context, File file, String checksumPolicy ) { setArtifact( artifact ); setRequestContext( context ); setFile( file ); setChecksumPolicy( checksumPolicy ); }
ArtifactDownload download = new ArtifactDownload(); download.setArtifact( artifact ); download.setRequestContext( item.request.getRequestContext() ); download.setTrace( item.trace ); if ( item.local.getFile() != null ) download.setFile( item.local.getFile() ); download.setExistenceCheck( true ); download.setFile( new File( lrm.getRepository().getBasedir(), path ) ); new UpdateCheck<Artifact, ArtifactTransferException>(); check.setItem( artifact ); check.setFile( download.getFile() ); check.setFileValid( !download.isExistenceCheck() ); check.setRepository( group.repository ); check.setPolicy( policy.getUpdatePolicy() ); download.setChecksumPolicy( policy.getChecksumPolicy() ); download.setRepositories( item.repository.getMirroredRepositories() ); downloads.add( download ); item.download = download; artifactDownloading( session, download.getTrace(), download.getArtifact(), group.repository ); download.setException( new ArtifactTransferException( download.getArtifact(), group.repository, e ) ); item.updateCheck.setException( download.getException() ); updateCheckManager.touchArtifact( session, item.updateCheck );
String resource = layout.getPath( download.getArtifact() ).getPath(); GetTask<?> task = new GetTask<ArtifactTransfer>( resource, download.isExistenceCheck() ? null : download.getFile(), download.getChecksumPolicy(), latch, download, ARTIFACT, true ); tasks.add( task ); task.run();
new ArtifactDownload( art, null, artFile, RepositoryPolicy.CHECKSUM_POLICY_FAIL ); MetadataDownload metaDown = new MetadataDownload( meta, null, metaFile, RepositoryPolicy.CHECKSUM_POLICY_FAIL ); MetadataDownload metaDown = metaDowns[j]; assertNull( "artifact download had exception: " + artDown.getException(), artDown.getException() ); assertNull( "metadata download had exception: " + metaDown.getException(), metaDown.getException() ); assertEquals( State.DONE, artDown.getState() ); assertEquals( State.DONE, metaDown.getState() );
@Override public void get(Collection<? extends ArtifactDownload> artifactDownloads, Collection<? extends MetadataDownload> metadataDownloads) { if (artifactDownloads != null) { for (ArtifactDownload a : artifactDownloads) { a.setException(new ArtifactNotFoundException(a.getArtifact(), repository)); } } if (metadataDownloads != null) { for (MetadataDownload m : metadataDownloads) { m.setException(new MetadataNotFoundException(m.getMetadata(), repository)); } } }
File downAFile = new File( dir, "downA.file" ); downAFile.deleteOnExit(); ArtifactDownload downA = new ArtifactDownload( artifact, "", downAFile, RepositoryPolicy.CHECKSUM_POLICY_FAIL ); assertNull( String.valueOf( downA.getException() ), downA.getException() ); assertNull( String.valueOf( downM.getException() ), downM.getException() );
obj = new ArtifactDownload( artifact, context, safeFile( file ), checksumPolicy );
/** * Sets the context of this transfer. * * @param context The context id, may be {@code null}. * @return This transfer for chaining, never {@code null}. */ public ArtifactDownload setRequestContext( String context ) { this.context = ( context != null ) ? context : ""; if ( State.NEW.equals( getState() ) ) { contexts = Collections.singleton( context ); } return this; }
ArtifactDownload download = new ArtifactDownload(); download.setArtifact( artifact ); download.setRequestContext( item.request.getRequestContext() ); download.setTrace( item.trace ); if ( item.local.getFile() != null ) download.setFile( item.local.getFile() ); download.setExistenceCheck( true ); download.setFile( new File( lrm.getRepository().getBasedir(), path ) ); new UpdateCheck<Artifact, ArtifactTransferException>(); check.setItem( artifact ); check.setFile( download.getFile() ); check.setFileValid( !download.isExistenceCheck() ); check.setRepository( group.repository ); check.setPolicy( policy.getUpdatePolicy() ); download.setChecksumPolicy( policy.getChecksumPolicy() ); download.setRepositories( item.repository.getMirroredRepositories() ); downloads.add( download ); item.download = download; artifactDownloading( session, download.getTrace(), download.getArtifact(), group.repository ); download.setException( new ArtifactTransferException( download.getArtifact(), group.repository, e ) ); item.updateCheck.setException( download.getException() ); updateCheckManager.touchArtifact( session, item.updateCheck );
String resource = layout.getPath( download.getArtifact() ).getPath(); GetTask<?> task = new GetTask<ArtifactTransfer>( resource, download.isExistenceCheck() ? null : download.getFile(), download.getChecksumPolicy(), download, ARTIFACT ); tasks.add( task ); executor.execute( errorForwarder.wrap( task ) );
new ArtifactDownload( art, null, artFile, RepositoryPolicy.CHECKSUM_POLICY_FAIL ); MetadataDownload metaDown = new MetadataDownload( meta, null, metaFile, RepositoryPolicy.CHECKSUM_POLICY_FAIL ); MetadataDownload metaDown = metaDowns[j]; assertNull( "artifact download had exception: " + artDown.getException(), artDown.getException() ); assertNull( "metadata download had exception: " + metaDown.getException(), metaDown.getException() ); assertEquals( State.DONE, artDown.getState() ); assertEquals( State.DONE, metaDown.getState() );
File downAFile = new File( dir, "downA.file" ); downAFile.deleteOnExit(); ArtifactDownload downA = new ArtifactDownload( artifact, "", downAFile, RepositoryPolicy.CHECKSUM_POLICY_FAIL ); assertNull( String.valueOf( downA.getException() ), downA.getException() ); assertNull( String.valueOf( downM.getException() ), downM.getException() );
obj = new ArtifactDownload( artifact, context, safeFile( file ), checksumPolicy );
@Test public void testBlocking() throws NoRepositoryConnectorException, IOException { RepositoryConnector connector = factory().newInstance( session, repository ); int count = 10; byte[] pattern = "tmpFile".getBytes( "UTF-8" ); File tmpFile = TestFileUtils.createTempFile( pattern, 100000 ); List<ArtifactUpload> artUps = ConnectorTestUtils.createTransfers( ArtifactUpload.class, count, tmpFile ); List<MetadataUpload> metaUps = ConnectorTestUtils.createTransfers( MetadataUpload.class, count, tmpFile ); List<ArtifactDownload> artDowns = ConnectorTestUtils.createTransfers( ArtifactDownload.class, count, null ); List<MetadataDownload> metaDowns = ConnectorTestUtils.createTransfers( MetadataDownload.class, count, null ); // this should block until all transfers are done - racing condition, better way to test this? connector.put( artUps, metaUps ); connector.get( artDowns, metaDowns ); for ( int i = 0; i < count; i++ ) { ArtifactUpload artUp = artUps.get( i ); MetadataUpload metaUp = metaUps.get( i ); ArtifactDownload artDown = artDowns.get( i ); MetadataDownload metaDown = metaDowns.get( i ); assertTrue( Transfer.State.DONE.equals( artUp.getState() ) ); assertTrue( Transfer.State.DONE.equals( artDown.getState() ) ); assertTrue( Transfer.State.DONE.equals( metaUp.getState() ) ); assertTrue( Transfer.State.DONE.equals( metaDown.getState() ) ); } connector.close(); }
String resource = layout.getPath( download.getArtifact() ).getPath(); GetTask<?> task = new GetTask<ArtifactTransfer>( resource, download.isExistenceCheck() ? null : download.getFile(), download.getChecksumPolicy(), latch, download, ARTIFACT, true ); tasks.add( task ); task.run();
@Test public void testFileHandleLeakage() throws IOException, NoRepositoryConnectorException { StubArtifact artifact = new StubArtifact( "testGroup", "testArtifact", "", "jar", "1-test" ); StubMetadata metadata = new StubMetadata( "testGroup", "testArtifact", "1-test", "maven-metadata.xml", Metadata.Nature.RELEASE_OR_SNAPSHOT ); RepositoryConnector connector = factory().newInstance( session, repository ); File tmpFile = TestFileUtils.createTempFile( "testFileHandleLeakage" ); ArtifactUpload artUp = new ArtifactUpload( artifact, tmpFile ); connector.put( Arrays.asList( artUp ), null ); assertTrue( "Leaking file handle in artifact upload", tmpFile.delete() ); tmpFile = TestFileUtils.createTempFile( "testFileHandleLeakage" ); MetadataUpload metaUp = new MetadataUpload( metadata, tmpFile ); connector.put( null, Arrays.asList( metaUp ) ); assertTrue( "Leaking file handle in metadata upload", tmpFile.delete() ); tmpFile = TestFileUtils.createTempFile( "testFileHandleLeakage" ); ArtifactDownload artDown = new ArtifactDownload( artifact, null, tmpFile, null ); connector.get( Arrays.asList( artDown ), null ); new File( tmpFile.getAbsolutePath() + ".sha1" ).deleteOnExit(); assertTrue( "Leaking file handle in artifact download", tmpFile.delete() ); tmpFile = TestFileUtils.createTempFile( "testFileHandleLeakage" ); MetadataDownload metaDown = new MetadataDownload( metadata, null, tmpFile, null ); connector.get( null, Arrays.asList( metaDown ) ); new File( tmpFile.getAbsolutePath() + ".sha1" ).deleteOnExit(); assertTrue( "Leaking file handle in metadata download", tmpFile.delete() ); connector.close(); }
@Test public void testBlocking() throws NoRepositoryConnectorException, IOException { RepositoryConnector connector = factory().newInstance( session, repository ); int count = 10; byte[] pattern = "tmpFile".getBytes( "UTF-8" ); File tmpFile = TestFileUtils.createTempFile( pattern, 100000 ); List<ArtifactUpload> artUps = ConnectorTestUtils.createTransfers( ArtifactUpload.class, count, tmpFile ); List<MetadataUpload> metaUps = ConnectorTestUtils.createTransfers( MetadataUpload.class, count, tmpFile ); List<ArtifactDownload> artDowns = ConnectorTestUtils.createTransfers( ArtifactDownload.class, count, null ); List<MetadataDownload> metaDowns = ConnectorTestUtils.createTransfers( MetadataDownload.class, count, null ); // this should block until all transfers are done - racing condition, better way to test this? connector.put( artUps, metaUps ); connector.get( artDowns, metaDowns ); for ( int i = 0; i < count; i++ ) { ArtifactUpload artUp = artUps.get( i ); MetadataUpload metaUp = metaUps.get( i ); ArtifactDownload artDown = artDowns.get( i ); MetadataDownload metaDown = metaDowns.get( i ); assertTrue( Transfer.State.DONE.equals( artUp.getState() ) ); assertTrue( Transfer.State.DONE.equals( artDown.getState() ) ); assertTrue( Transfer.State.DONE.equals( metaUp.getState() ) ); assertTrue( Transfer.State.DONE.equals( metaDown.getState() ) ); } connector.close(); }
@Test public void testFileHandleLeakage() throws IOException, NoRepositoryConnectorException { StubArtifact artifact = new StubArtifact( "testGroup", "testArtifact", "", "jar", "1-test" ); StubMetadata metadata = new StubMetadata( "testGroup", "testArtifact", "1-test", "maven-metadata.xml", Metadata.Nature.RELEASE_OR_SNAPSHOT ); RepositoryConnector connector = factory().newInstance( session, repository ); File tmpFile = TestFileUtils.createTempFile( "testFileHandleLeakage" ); ArtifactUpload artUp = new ArtifactUpload( artifact, tmpFile ); connector.put( Arrays.asList( artUp ), null ); assertTrue( "Leaking file handle in artifact upload", tmpFile.delete() ); tmpFile = TestFileUtils.createTempFile( "testFileHandleLeakage" ); MetadataUpload metaUp = new MetadataUpload( metadata, tmpFile ); connector.put( null, Arrays.asList( metaUp ) ); assertTrue( "Leaking file handle in metadata upload", tmpFile.delete() ); tmpFile = TestFileUtils.createTempFile( "testFileHandleLeakage" ); ArtifactDownload artDown = new ArtifactDownload( artifact, null, tmpFile, null ); connector.get( Arrays.asList( artDown ), null ); new File( tmpFile.getAbsolutePath() + ".sha1" ).deleteOnExit(); assertTrue( "Leaking file handle in artifact download", tmpFile.delete() ); tmpFile = TestFileUtils.createTempFile( "testFileHandleLeakage" ); MetadataDownload metaDown = new MetadataDownload( metadata, null, tmpFile, null ); connector.get( null, Arrays.asList( metaDown ) ); new File( tmpFile.getAbsolutePath() + ".sha1" ).deleteOnExit(); assertTrue( "Leaking file handle in metadata download", tmpFile.delete() ); connector.close(); }