DefaultDeployer implements Deployer, Service { public DeployResult deploy( RepositorySystemSession session, DeployRequest request ) throws DeploymentException { if ( session.isOffline() ) { throw new DeploymentException( "The repository system is in offline mode, deployment impossible" ); } SyncContext syncContext = syncContextFactory.newInstance( session, false ); try { return deploy( syncContext, session, request ); } finally { syncContext.release(); } } DefaultDeployer();  DefaultDeployer( Logger logger, FileProcessor fileProcessor,
                            RepositoryEventDispatcher repositoryEventDispatcher,
                            RemoteRepositoryManager remoteRepositoryManager, UpdateCheckManager updateCheckManager,
                            List<MetadataGeneratorFactory> metadataFactories, SyncContextFactory syncContextFactory ); void initService( ServiceLocator locator ); DefaultDeployer setLogger( Logger logger ); DefaultDeployer setFileProcessor( FileProcessor fileProcessor ); DefaultDeployer setRepositoryEventDispatcher( RepositoryEventDispatcher repositoryEventDispatcher ); DefaultDeployer setRemoteRepositoryManager( RemoteRepositoryManager remoteRepositoryManager ); DefaultDeployer setUpdateCheckManager( UpdateCheckManager updateCheckManager ); DefaultDeployer addMetadataGeneratorFactory( MetadataGeneratorFactory factory ); DefaultDeployer setMetadataFactories( List<MetadataGeneratorFactory> metadataFactories ); DefaultDeployer setSyncContextFactory( SyncContextFactory syncContextFactory ); DeployResult deploy( RepositorySystemSession session, DeployRequest request );  }
@Test public void testSuccessfulDeploy() throws DeploymentException { connector.setExpectPut( artifact ); connector.setExpectPut( metadata ); request.addArtifact( artifact ); request.addMetadata( metadata ); deployer.deploy( session, request ); connector.assertSeenExpected(); }
@Test( expected = DeploymentException.class ) public void testNullArtifactFile() throws DeploymentException { request.addArtifact( artifact.setFile( null ) ); deployer.deploy( session, request ); }
@Test( expected = DeploymentException.class ) public void testNullMetadataFile() throws DeploymentException { request.addArtifact( artifact.setFile( null ) ); deployer.deploy( session, request ); }
@Test public void testSuccessfulArtifactEvents() throws DeploymentException { request.addArtifact( artifact ); deployer.deploy( session, request ); List<EventWrapper> events = listener.getEvents(); assertEquals( 2, events.size() ); EventWrapper wrapper = events.get( 0 ); assertEquals( ARTIFACT_DEPLOYING, wrapper.getType() ); RepositoryEvent event = wrapper.getEvent(); assertEquals( artifact, event.getArtifact() ); assertNull( event.getException() ); wrapper = events.get( 1 ); assertEquals( ARTIFACT_DEPLOYED, wrapper.getType() ); event = wrapper.getEvent(); assertEquals( artifact, event.getArtifact() ); assertNull( event.getException() ); }
@Test public void testFailingArtifactEvents() { connector = new RecordingRepositoryConnector() { @Override public void get( Collection<? extends ArtifactDownload> artifactDownloads, Collection<? extends MetadataDownload> metadataDownloads ) { metadataDownloads = metadataDownloads == null ? Collections.<MetadataDownload> emptyList() : metadataDownloads; artifactDownloads = artifactDownloads == null ? Collections.<ArtifactDownload> emptyList() : artifactDownloads; for ( MetadataDownload d : metadataDownloads ) { d.setState( State.ACTIVE ); d.setException( new MetadataTransferException( d.getMetadata(), null, "failed" ) ); d.setState( State.DONE ); } for ( ArtifactDownload d : artifactDownloads ) { d.setState( State.ACTIVE ); d.setException( new ArtifactTransferException( d.getArtifact(), null, "failed" ) ); d.setState( State.DONE ); } } @Override public void put( Collection<? extends ArtifactUpload> artifactUploads, Collection<? extends MetadataUpload> metadataUploads ) { metadataUploads = metadataUploads == null ? Collections.<MetadataUpload> emptyList() : metadataUploads; artifactUploads = artifactUploads == null ? Collections.<ArtifactUpload> emptyList() : artifactUploads; for ( MetadataUpload d : metadataUploads ) { d.setState( State.ACTIVE ); d.setException( new MetadataTransferException( d.getMetadata(), null, "failed" ) ); d.setState( State.DONE ); } for ( ArtifactUpload d : artifactUploads ) { d.setState( State.ACTIVE ); d.setException( new ArtifactTransferException( d.getArtifact(), null, "failed" ) ); d.setState( State.DONE ); } } }; manager.setConnector( connector ); request.addArtifact( artifact ); try { deployer.deploy( session, request ); fail( "expected exception" ); } catch ( DeploymentException e ) { List<EventWrapper> events = listener.getEvents(); assertEquals( 2, events.size() ); EventWrapper wrapper = events.get( 0 ); assertEquals( ARTIFACT_DEPLOYING, wrapper.getType() ); RepositoryEvent event = wrapper.getEvent(); assertEquals( artifact, event.getArtifact() ); assertNull( event.getException() ); wrapper = events.get( 1 ); assertEquals( ARTIFACT_DEPLOYED, wrapper.getType() ); event = wrapper.getEvent(); assertEquals( artifact, event.getArtifact() ); assertNotNull( event.getException() ); } }
@Test public void testSuccessfulMetadataEvents() throws DeploymentException { request.addMetadata( metadata ); deployer.deploy( session, request ); List<EventWrapper> events = listener.getEvents(); assertEquals( 2, events.size() ); EventWrapper wrapper = events.get( 0 ); assertEquals( METADATA_DEPLOYING, wrapper.getType() ); RepositoryEvent event = wrapper.getEvent(); assertEquals( metadata, event.getMetadata() ); assertNull( event.getException() ); wrapper = events.get( 1 ); assertEquals( METADATA_DEPLOYED, wrapper.getType() ); event = wrapper.getEvent(); assertEquals( metadata, event.getMetadata() ); assertNull( event.getException() ); }
@Test public void testFailingMetdataEvents() { connector = new RecordingRepositoryConnector() { @Override public void get( Collection<? extends ArtifactDownload> artifactDownloads, Collection<? extends MetadataDownload> metadataDownloads ) { metadataDownloads = metadataDownloads == null ? Collections.<MetadataDownload> emptyList() : metadataDownloads; artifactDownloads = artifactDownloads == null ? Collections.<ArtifactDownload> emptyList() : artifactDownloads; for ( MetadataDownload d : metadataDownloads ) { d.setState( State.ACTIVE ); d.setException( new MetadataTransferException( d.getMetadata(), null, "failed" ) ); d.setState( State.DONE ); } for ( ArtifactDownload d : artifactDownloads ) { d.setState( State.ACTIVE ); d.setException( new ArtifactTransferException( d.getArtifact(), null, "failed" ) ); d.setState( State.DONE ); } } @Override public void put( Collection<? extends ArtifactUpload> artifactUploads, Collection<? extends MetadataUpload> metadataUploads ) { metadataUploads = metadataUploads == null ? Collections.<MetadataUpload> emptyList() : metadataUploads; artifactUploads = artifactUploads == null ? Collections.<ArtifactUpload> emptyList() : artifactUploads; for ( MetadataUpload d : metadataUploads ) { d.setState( State.ACTIVE ); d.setException( new MetadataTransferException( d.getMetadata(), null, "failed" ) ); d.setState( State.DONE ); } for ( ArtifactUpload d : artifactUploads ) { d.setState( State.ACTIVE ); d.setException( new ArtifactTransferException( d.getArtifact(), null, "failed" ) ); d.setState( State.DONE ); } } }; manager.setConnector( connector ); request.addMetadata( metadata ); try { deployer.deploy( session, request ); fail( "expected exception" ); } catch ( DeploymentException e ) { List<EventWrapper> events = listener.getEvents(); assertEquals( 2, events.size() ); EventWrapper wrapper = events.get( 0 ); assertEquals( METADATA_DEPLOYING, wrapper.getType() ); RepositoryEvent event = wrapper.getEvent(); assertEquals( metadata, event.getMetadata() ); assertNull( event.getException() ); wrapper = events.get( 1 ); assertEquals( METADATA_DEPLOYED, wrapper.getType() ); event = wrapper.getEvent(); assertEquals( metadata, event.getMetadata() ); assertNotNull( event.getException() ); } }
@Test public void testStaleLocalMetadataCopyGetsDeletedBeforeMergeWhenMetadataIsNotCurrentlyPresentInRemoteRepo() throws Exception { MergeableMetadata metadata = new MergeableMetadata() { public Metadata setFile( File file ) { return this; } public String getVersion() { return ""; } public String getType() { return "test.properties"; } public Nature getNature() { return Nature.RELEASE; } public String getGroupId() { return "org"; } public File getFile() { return null; } public String getArtifactId() { return "aether"; } public void merge( File current, File result ) throws RepositoryException { Properties props = new Properties(); try { if ( current.isFile() ) { TestFileUtils.read( props, current ); } props.setProperty( "new", "value" ); TestFileUtils.write( props, result ); } catch ( IOException e ) { throw new RepositoryException( e.getMessage(), e ); } } public boolean isMerged() { return false; } }; manager.setConnector( new RepositoryConnector() { public void put( Collection<? extends ArtifactUpload> artifactUploads, Collection<? extends MetadataUpload> metadataUploads ) { } public void get( Collection<? extends ArtifactDownload> artifactDownloads, Collection<? extends MetadataDownload> metadataDownloads ) { if ( metadataDownloads != null ) { for ( MetadataDownload download : metadataDownloads ) { download.setException( new MetadataNotFoundException( download.getMetadata(), null, null ) ); } } } public void close() { } } ); request.addMetadata( metadata ); File metadataFile = new File( session.getLocalRepository().getBasedir(), session.getLocalRepositoryManager().getPathForRemoteMetadata( metadata, request.getRepository(), "" ) ); Properties props = new Properties(); props.setProperty( "old", "value" ); TestFileUtils.write( props, metadataFile ); deployer.deploy( session, request ); props = new Properties(); TestFileUtils.read( props, metadataFile ); assertNull( props.toString(), props.get( "old" ) ); }