DefaultMetadataResolver implements MetadataResolver, Service { public List<MetadataResult> resolveMetadata( RepositorySystemSession session, Collection<? extends MetadataRequest> requests ) { SyncContext syncContext = syncContextFactory.newInstance( session, false ); try { Collection<Metadata> metadata = new ArrayList<Metadata>( requests.size() ); for ( MetadataRequest request : requests ) { metadata.add( request.getMetadata() ); } syncContext.acquire( null, metadata ); return resolve( session, requests ); } finally { syncContext.release(); } } DefaultMetadataResolver();  DefaultMetadataResolver( Logger logger, RepositoryEventDispatcher repositoryEventDispatcher,
                                    UpdateCheckManager updateCheckManager,
                                    RemoteRepositoryManager remoteRepositoryManager,
                                    SyncContextFactory syncContextFactory ); void initService( ServiceLocator locator ); DefaultMetadataResolver setLogger( Logger logger ); DefaultMetadataResolver setRepositoryEventDispatcher( RepositoryEventDispatcher repositoryEventDispatcher ); DefaultMetadataResolver setUpdateCheckManager( UpdateCheckManager updateCheckManager ); DefaultMetadataResolver setRemoteRepositoryManager( RemoteRepositoryManager remoteRepositoryManager ); DefaultMetadataResolver setSyncContextFactory( SyncContextFactory syncContextFactory ); List<MetadataResult> resolveMetadata( RepositorySystemSession session,
                                                 Collection<? extends MetadataRequest> requests );  }
@Test public void testRemoveMetadataIfMissing() throws IOException { connector = new RecordingRepositoryConnector() { @Override public void get( Collection<? extends ArtifactDownload> artifactDownloads, Collection<? extends MetadataDownload> metadataDownloads ) { super.get( artifactDownloads, metadataDownloads ); for ( MetadataDownload d : metadataDownloads ) { d.setException( new MetadataNotFoundException( metadata, repository ) ); } } }; manager.setConnector( connector ); File file = new File( session.getLocalRepository().getBasedir(), session.getLocalRepositoryManager().getPathForRemoteMetadata( metadata, repository, "" ) ); TestFileUtils.write( file.getAbsolutePath(), file ); metadata.setFile( file ); MetadataRequest request = new MetadataRequest( metadata, repository, "" ); request.setDeleteLocalCopyIfMissing( true ); List<MetadataResult> results = resolver.resolveMetadata( session, Arrays.asList( request ) ); assertEquals( 1, results.size() ); MetadataResult result = results.get( 0 ); assertNotNull( result.getException() ); assertEquals( false, file.exists() ); }
@Test public void testOfflineSessionResolveMetadataMissing() { session.setOffline( true ); MetadataRequest request = new MetadataRequest( metadata, repository, "" ); List<MetadataResult> results = resolver.resolveMetadata( session, Arrays.asList( request ) ); assertEquals( 1, results.size() ); MetadataResult result = results.get( 0 ); assertSame( request, result.getRequest() ); assertNotNull( result.getException() ); assertNull( result.getMetadata() ); connector.assertSeenExpected(); }
@Test public void testOfflineSessionResolveMetadata() throws IOException { session.setOffline( true ); String path = session.getLocalRepositoryManager().getPathForRemoteMetadata( metadata, repository, "" ); File file = new File( session.getLocalRepository().getBasedir(), path ); TestFileUtils.write( file.getAbsolutePath(), file ); metadata = metadata.setFile( file ); MetadataRequest request = new MetadataRequest( metadata, repository, "" ); List<MetadataResult> results = resolver.resolveMetadata( session, Arrays.asList( request ) ); assertEquals( 1, results.size() ); MetadataResult result = results.get( 0 ); assertSame( request, result.getRequest() ); assertNull( String.valueOf( result.getException() ), result.getException() ); assertNotNull( result.getMetadata() ); assertNotNull( result.getMetadata().getFile() ); assertEquals( file, result.getMetadata().getFile() ); assertEquals( metadata.setFile( null ), result.getMetadata().setFile( null ) ); connector.assertSeenExpected(); }
@Test public void testNoRepositoryFailing() { MetadataRequest request = new MetadataRequest( metadata, null, "" ); List<MetadataResult> results = resolver.resolveMetadata( session, Arrays.asList( request ) ); assertEquals( 1, results.size() ); MetadataResult result = results.get( 0 ); assertSame( request, result.getRequest() ); assertNotNull( "" + ( result.getMetadata() != null ? result.getMetadata().getFile() : result.getMetadata() ), result.getException() ); assertEquals( MetadataNotFoundException.class, result.getException().getClass() ); assertNull( result.getMetadata() ); }