EnhancedLocalRepositoryManager extends SimpleLocalRepositoryManager { @Override public LocalArtifactResult find( RepositorySystemSession session, LocalArtifactRequest request ) { String path = getPathForArtifact( request.getArtifact(), false ); File file = new File( getRepository().getBasedir(), path ); LocalArtifactResult result = new LocalArtifactResult( request ); if ( file.isFile() ) { result.setFile( file ); Properties props = readRepos( file ); if ( props.get( getKey( file, LOCAL_REPO_ID ) ) != null ) { result.setAvailable( true ); } else { String context = request.getContext(); for ( RemoteRepository repository : request.getRepositories() ) { if ( props.get( getKey( file, getRepositoryKey( repository, context ) ) ) != null ) { result.setAvailable( true ); result.setRepository( repository ); break; } } if ( !result.isAvailable() && !isTracked( props, file ) ) { result.setAvailable( true ); } } } return result; } EnhancedLocalRepositoryManager( File basedir ); @Override EnhancedLocalRepositoryManager setLogger( Logger logger ); @Override LocalArtifactResult find( RepositorySystemSession session, LocalArtifactRequest request ); @Override void add( RepositorySystemSession session, LocalArtifactRegistration request );  }
@Test public void testFindLocalArtifact() throws Exception { addLocalArtifact( artifact ); LocalArtifactRequest request = new LocalArtifactRequest( artifact, null, null ); LocalArtifactResult result = manager.find( session, request ); assertTrue( result.isAvailable() ); }
@Test public void testFindRemoteArtifact() throws Exception { addRemoteArtifact( artifact ); LocalArtifactRequest request = new LocalArtifactRequest( artifact, Arrays.asList( repository ), testContext ); LocalArtifactResult result = manager.find( session, request ); assertTrue( result.isAvailable() ); }
@Test public void testDoNotFindDifferentContext() throws Exception { addRemoteArtifact( artifact ); LocalArtifactRequest request = new LocalArtifactRequest( artifact, Arrays.asList( repository ), "different" ); LocalArtifactResult result = manager.find( session, request ); assertFalse( result.isAvailable() ); }
@Test public void testDoNotFindNullFile() throws Exception { artifact = artifact.setFile( null ); addLocalArtifact( artifact ); LocalArtifactRequest request = new LocalArtifactRequest( artifact, Arrays.asList( repository ), testContext ); LocalArtifactResult result = manager.find( session, request ); assertFalse( result.isAvailable() ); }
@Test public void testDoNotFindDeletedFile() throws Exception { addLocalArtifact( artifact ); assertTrue( "could not delete artifact file", artifactFile.delete() ); LocalArtifactRequest request = new LocalArtifactRequest( artifact, Arrays.asList( repository ), testContext ); LocalArtifactResult result = manager.find( session, request ); assertFalse( result.isAvailable() ); }
@Test public void testFindUntrackedFile() throws Exception { copy( artifact, manager.getPathForLocalArtifact( artifact ) ); LocalArtifactRequest request = new LocalArtifactRequest( artifact, Arrays.asList( repository ), testContext ); LocalArtifactResult result = manager.find( session, request ); assertTrue( result.isAvailable() ); }
@Test public void testFindLocalMetadata() throws Exception { addMetadata( metadata, null ); LocalMetadataRequest request = new LocalMetadataRequest( metadata, null, testContext ); LocalMetadataResult result = manager.find( session, request ); assertNotNull( result.getFile() ); }
@Test public void testFindLocalMetadataNoVersion() throws Exception { addMetadata( noVerMetadata, null ); LocalMetadataRequest request = new LocalMetadataRequest( noVerMetadata, null, testContext ); LocalMetadataResult result = manager.find( session, request ); assertNotNull( result.getFile() ); }
@Test public void testDoNotFindRemoteMetadataDifferentContext() throws Exception { addMetadata( noVerMetadata, repository ); addMetadata( metadata, repository ); LocalMetadataRequest request = new LocalMetadataRequest( noVerMetadata, repository, "different" ); LocalMetadataResult result = manager.find( session, request ); assertNull( result.getFile() ); request = new LocalMetadataRequest( metadata, repository, "different" ); result = manager.find( session, request ); assertNull( result.getFile() ); }
@Test public void testFindArtifactUsesTimestampedVersion() throws Exception { Artifact artifact = new DefaultArtifact( "g.i.d:a.i.d:1.0-SNAPSHOT" ); File file = new File( basedir, manager.getPathForLocalArtifact( artifact ) ); TestFileUtils.write( "test", file ); addLocalArtifact( artifact ); artifact = artifact.setVersion( "1.0-20110329.221805-4" ); LocalArtifactRequest request = new LocalArtifactRequest(); request.setArtifact( artifact ); LocalArtifactResult result = manager.find( session, request ); assertNull( result.toString(), result.getFile() ); assertFalse( result.toString(), result.isAvailable() ); }