@Override public boolean evaluate( RepositoryContentConsumer object ) { boolean satisfies = false; RepositoryContentConsumer consumer = (RepositoryContentConsumer) object; if ( wantsFile( consumer, FilenameUtils.separatorsToUnix( basefile.getRelativePath( ) ) ) ) { satisfies = true; // regardless of the timestamp, we record that it was wanted so it doesn't get counted as invalid wantedFileCount++; if ( !consumer.isProcessUnmodified( ) ) { // Timestamp finished points to the last successful scan, not this current one. if ( basefile.lastModified( ) < changesSince ) { // Skip file as no change has occurred. satisfies = false; } } } return satisfies; }
consumer.processFile( basefile.getRelativePath( ), executeOnEntireRepo ); long endTime = System.currentTimeMillis( ); + "{}]: {}", id, basefile.getAbsolutePath( ), e.getMessage( ), e );
public void setBaseDir( String repoDir ) { setBaseDir( new File( repoDir ) ); } }
@Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (excludeMatcher.stream().noneMatch(m -> m.matches(file)) && includeMatcher.stream().allMatch(m -> m.matches(file))) { log.debug( "Walk Step: {}, {}", file ); stats.increaseFileCount(); // consume files regardless - the predicate will check the timestamp Path repoPath = PathUtil.getPathFromUri( repository.getLocation() ); BaseFile basefile = new BaseFile( repoPath.toString(), file.toFile() ); // Timestamp finished points to the last successful scan, not this current one. if ( Files.getLastModifiedTime(file).toMillis() >= changesSince ) { stats.increaseNewFileCount(); } consumerProcessFile.setBasefile( basefile ); consumerWantsFile.setBasefile( basefile ); Closure<RepositoryContentConsumer> processIfWanted = IfClosure.ifClosure( consumerWantsFile, consumerProcessFile ); IterableUtils.forEach( this.knownConsumers, processIfWanted ); if ( consumerWantsFile.getWantedFileCount() <= 0 ) { // Nothing known processed this file. It is invalid! IterableUtils.forEach( this.invalidConsumers, consumerProcessFile ); } } return FileVisitResult.CONTINUE; }
public String getRelativePath() { return PathUtil.getRelative( this.baseDir.getAbsolutePath(), this.toPath() ); }
@SuppressWarnings( "deprecation" ) @Test public void testConsumption() { Path localFile = repoLocation.resolve( "org/apache/maven/plugins/maven-plugin-plugin/2.4.1/maven-metadata.xml" ); ConsumerWantsFilePredicate predicate = new ConsumerWantsFilePredicate(); BaseFile baseFile = new BaseFile( repoLocation.toFile(), localFile.toFile() ); predicate.setBasefile( baseFile ); assertFalse( predicate.evaluate( consumer ) ); }
@SuppressWarnings( "deprecation" ) @Test public void testConsumptionOfOtherMetadata() { Path localFile = repoLocation.resolve( "org/apache/maven/plugins/maven-plugin-plugin/2.4.1/maven-metadata-central.xml" ); ConsumerWantsFilePredicate predicate = new ConsumerWantsFilePredicate(); BaseFile baseFile = new BaseFile( repoLocation.toFile(), localFile.toFile() ); predicate.setBasefile( baseFile ); assertFalse( predicate.evaluate( consumer ) ); }
@Override public boolean evaluate( Object object ) { boolean satisfies = false; if ( object instanceof RepositoryContentConsumer ) { RepositoryContentConsumer consumer = (RepositoryContentConsumer) object; if ( wantsFile( consumer, FilenameUtils.separatorsToUnix( basefile.getRelativePath() ) ) ) { satisfies = true; // regardless of the timestamp, we record that it was wanted so it doesn't get counted as invalid wantedFileCount++; if ( !consumer.isProcessUnmodified() ) { // Timestamp finished points to the last successful scan, not this current one. if ( basefile.lastModified() < changesSince ) { // Skip file as no change has occurred. satisfies = false; } } } } return satisfies; }
consumer.processFile( basefile.getRelativePath(), executeOnEntireRepo ); long endTime = System.currentTimeMillis(); + basefile.getAbsolutePath() + "]: " + e.getMessage(), e );
public void setBaseDir( String repoDir ) { setBaseDir( new File( repoDir ) ); } }
@Override public void directoryWalkStep( int percentage, File file ) { log.debug( "Walk Step: {}, {}", percentage, file ); stats.increaseFileCount(); // consume files regardless - the predicate will check the timestamp BaseFile basefile = new BaseFile( repository.getLocation(), file ); // Timestamp finished points to the last successful scan, not this current one. if ( file.lastModified() >= changesSince ) { stats.increaseNewFileCount(); } consumerProcessFile.setBasefile( basefile ); consumerWantsFile.setBasefile( basefile ); Closure processIfWanted = IfClosure.getInstance( consumerWantsFile, consumerProcessFile ); CollectionUtils.forAllDo( this.knownConsumers, processIfWanted ); if ( consumerWantsFile.getWantedFileCount() <= 0 ) { // Nothing known processed this file. It is invalid! CollectionUtils.forAllDo( this.invalidConsumers, consumerProcessFile ); } }
@SuppressWarnings( "deprecation" ) private void assertNotConsumed( String path ) throws Exception { ArchivaConfiguration archivaConfiguration = applicationContext.getBean( "archivaConfiguration#default", ArchivaConfiguration.class ); FileType fileType = archivaConfiguration.getConfiguration().getRepositoryScanning().getFileTypes().get( 0 ); assertEquals( FileTypes.ARTIFACTS, fileType.getId() ); fileType.addPattern( "**/*.xml" ); // trigger reload //FileTypes fileTypes = applicationContext.getBean( FileTypes.class ); for ( FileTypes fileTypes : applicationContext.getBeansOfType( FileTypes.class ).values() ) { fileTypes.afterConfigurationChange( null, "repositoryScanning.fileTypes", null ); } KnownRepositoryContentConsumer repoPurgeConsumer = applicationContext.getBean( "knownRepositoryContentConsumer#repository-purge", KnownRepositoryContentConsumer.class ); Path repoLocation = Paths.get( "target/test-" + getName() + "/test-repo" ); Path localFile = repoLocation.resolve( path ); ConsumerWantsFilePredicate predicate = new ConsumerWantsFilePredicate(); BaseFile baseFile = new BaseFile( repoLocation.toFile(), localFile.toFile() ); predicate.setBasefile( baseFile ); assertFalse( predicate.evaluate( repoPurgeConsumer ) ); }
BaseFile baseFile = new BaseFile( repoPath.toString(), localFile.toFile() ); ConsumerWantsFilePredicate predicate = new ConsumerWantsFilePredicate( repository ); predicate.setBasefile( baseFile );
BaseFile baseFile = new BaseFile( repository.getLocation(), localFile ); ConsumerWantsFilePredicate predicate = new ConsumerWantsFilePredicate( repository ); predicate.setBasefile( baseFile );