DefaultInstaller implements Installer, Service { public InstallResult install( RepositorySystemSession session, InstallRequest request ) throws InstallationException { SyncContext syncContext = syncContextFactory.newInstance( session, false ); try { return install( syncContext, session, request ); } finally { syncContext.release(); } } DefaultInstaller();  DefaultInstaller( Logger logger, FileProcessor fileProcessor,
                             RepositoryEventDispatcher repositoryEventDispatcher,
                             List<MetadataGeneratorFactory> metadataFactories, SyncContextFactory syncContextFactory ); void initService( ServiceLocator locator ); DefaultInstaller setLogger( Logger logger ); DefaultInstaller setFileProcessor( FileProcessor fileProcessor ); DefaultInstaller setRepositoryEventDispatcher( RepositoryEventDispatcher repositoryEventDispatcher ); DefaultInstaller addMetadataGeneratorFactory( MetadataGeneratorFactory factory ); DefaultInstaller setMetadataFactories( List<MetadataGeneratorFactory> metadataFactories ); DefaultInstaller setSyncContextFactory( SyncContextFactory syncContextFactory ); InstallResult install( RepositorySystemSession session, InstallRequest request );  }
@Test public void testSuccessfulInstall() throws InstallationException, UnsupportedEncodingException, IOException { File artifactFile = new File( session.getLocalRepositoryManager().getRepository().getBasedir(), localArtifactPath ); File metadataFile = new File( session.getLocalRepositoryManager().getRepository().getBasedir(), localMetadataPath ); artifactFile.delete(); metadataFile.delete(); request.addArtifact( artifact ); request.addMetadata( metadata ); InstallResult result = installer.install( session, request ); assertTrue( artifactFile.exists() ); TestFileUtils.assertContent( "artifact".getBytes( "UTF-8" ), artifactFile ); assertTrue( metadataFile.exists() ); TestFileUtils.assertContent( "metadata".getBytes( "UTF-8" ), metadataFile ); assertEquals( result.getRequest(), request ); assertEquals( result.getArtifacts().size(), 1 ); assertTrue( result.getArtifacts().contains( artifact ) ); assertEquals( result.getMetadata().size(), 1 ); assertTrue( result.getMetadata().contains( metadata ) ); assertEquals( 1, lrm.getMetadataRegistration().size() ); assertTrue( lrm.getMetadataRegistration().contains( metadata ) ); assertEquals( 1, lrm.getArtifactRegistration().size() ); assertTrue( lrm.getArtifactRegistration().contains( artifact ) ); }
@Test( expected = InstallationException.class ) public void testNullArtifactFile() throws InstallationException { InstallRequest request = new InstallRequest(); request.addArtifact( artifact.setFile( null ) ); installer.install( session, request ); }
@Test( expected = InstallationException.class ) public void testNullMetadataFile() throws InstallationException { InstallRequest request = new InstallRequest(); request.addMetadata( metadata.setFile( null ) ); installer.install( session, request ); }
@Test( expected = InstallationException.class ) public void testArtifactExistsAsDir() throws InstallationException { String path = session.getLocalRepositoryManager().getPathForLocalArtifact( artifact ); File file = new File( session.getLocalRepository().getBasedir(), path ); assertFalse( file.getAbsolutePath() + " is a file, not directory", file.isFile() ); assertFalse( file.getAbsolutePath() + " already exists", file.exists() ); assertTrue( "failed to setup test: could not create " + file.getAbsolutePath(), file.mkdirs() || file.isDirectory() ); request.addArtifact( artifact ); installer.install( session, request ); }
@Test( expected = InstallationException.class ) public void testMetadataExistsAsDir() throws InstallationException { String path = session.getLocalRepositoryManager().getPathForLocalMetadata( metadata ); assertTrue( "failed to setup test: could not create " + path, new File( session.getLocalRepository().getBasedir(), path ).mkdirs() ); request.addMetadata( metadata ); installer.install( session, request ); }
@Test public void testSuccessfulArtifactEvents() throws InstallationException { InstallRequest request = new InstallRequest(); request.addArtifact( artifact ); installer.install( session, request ); checkEvents( "Repository Event problem", artifact, false ); }
@Test public void testSuccessfulMetadataEvents() throws InstallationException { InstallRequest request = new InstallRequest(); request.addMetadata( metadata ); installer.install( session, request ); checkEvents( "Repository Event problem", metadata, false ); }
@Test public void testSetArtifactTimestamps() throws InstallationException { artifact.getFile().setLastModified( artifact.getFile().lastModified() - 60000 ); request.addArtifact( artifact ); installer.install( session, request ); assertEquals( "artifact timestamp was not set to src file", artifact.getFile().lastModified(), localArtifactFile.lastModified() ); request = new InstallRequest(); request.addArtifact( artifact ); artifact.getFile().setLastModified( artifact.getFile().lastModified() - 60000 ); installer.install( session, request ); assertEquals( "artifact timestamp was not set to src file", artifact.getFile().lastModified(), localArtifactFile.lastModified() ); }