use of org.apache.archiva.configuration.FileTypes in project archiva by apache.
the class MetadataTools method getFirstArtifact.
/**
* Get the first Artifact found in the provided VersionedReference location.
*
* @param managedRepository the repository to search within.
* @param reference the reference to the versioned reference to search within
* @return the ArtifactReference to the first artifact located within the versioned reference. or null if
* no artifact was found within the versioned reference.
* @throws IOException if the versioned reference is invalid (example: doesn't exist, or isn't a directory)
* @throws LayoutException
*/
public ArtifactReference getFirstArtifact(ManagedRepositoryContent managedRepository, VersionedReference reference) throws LayoutException, IOException {
String path = toPath(reference);
int idx = path.lastIndexOf('/');
if (idx > 0) {
path = path.substring(0, idx);
}
Path repoDir = Paths.get(managedRepository.getRepoRoot(), path);
if (!Files.exists(repoDir)) {
throw new IOException("Unable to gather the list of snapshot versions on a non-existant directory: " + repoDir.toAbsolutePath());
}
if (!Files.isDirectory(repoDir)) {
throw new IOException("Unable to gather the list of snapshot versions on a non-directory: " + repoDir.toAbsolutePath());
}
try (Stream<Path> stream = Files.list(repoDir)) {
String result = stream.filter(Files::isRegularFile).map(path1 -> PathUtil.getRelative(managedRepository.getRepoRoot(), path1)).filter(filetypes::matchesArtifactPattern).findFirst().orElse(null);
if (result != null) {
return managedRepository.toArtifactReference(result);
}
}
// No artifact was found.
return null;
}
use of org.apache.archiva.configuration.FileTypes in project archiva by apache.
the class NexusIndexerConsumerTest method setUp.
@Override
@Before
public void setUp() throws Exception {
super.setUp();
scheduler = new ArchivaTaskSchedulerStub();
ArchivaConfiguration configuration = applicationContext.getBean(ArchivaConfiguration.class);
FileTypes filetypes = applicationContext.getBean(FileTypes.class);
nexusIndexerConsumer = new NexusIndexerConsumer(scheduler, configuration, filetypes, indexCreators, managedRepositoryAdmin);
// initialize to set the file types to be processed
nexusIndexerConsumer.initialize();
repositoryConfig = new BasicManagedRepository("test-repo", "Test Repository", Paths.get("target/test-classes"));
repositoryConfig.setLocation(new URI("target/test-classes/test-repo"));
repositoryConfig.setLayout("default");
repositoryConfig.setScanned(true);
repositoryConfig.addActiveReleaseScheme(ReleaseScheme.RELEASE);
repositoryConfig.removeActiveReleaseScheme(ReleaseScheme.SNAPSHOT);
repositoryRegistry.putRepository(repositoryConfig);
}
use of org.apache.archiva.configuration.FileTypes in project archiva by apache.
the class RepositoryPurgeConsumerTest method assertNotConsumed.
@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");
// 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));
}
use of org.apache.archiva.configuration.FileTypes in project archiva by apache.
the class ManagedDefaultRepositoryContent method getVersions.
@Override
public Set<String> getVersions(VersionedReference reference) throws ContentNotFoundException {
String path = toMetadataPath(reference);
int idx = path.lastIndexOf('/');
if (idx > 0) {
path = path.substring(0, idx);
}
Path repoBase = PathUtil.getPathFromUri(repository.getLocation());
Path repoDir = repoBase.resolve(path);
if (!Files.exists(repoDir)) {
throw new ContentNotFoundException("Unable to get versions on a non-existant directory: " + repoDir.toAbsolutePath());
}
if (!Files.isDirectory(repoDir)) {
throw new ContentNotFoundException("Unable to get versions on a non-directory: " + repoDir.toAbsolutePath());
}
Set<String> foundVersions = new HashSet<>();
try (Stream<Path> stream = Files.list(repoDir)) {
return stream.filter(Files::isRegularFile).map(p -> repoBase.relativize(p).toString()).filter(p -> !filetypes.matchesDefaultExclusions(p)).filter(filetypes::matchesArtifactPattern).map(path1 -> {
try {
return toArtifactReference(path1);
} catch (LayoutException e) {
log.debug("Not processing file that is not an artifact: {}", e.getMessage());
return null;
}
}).filter(Objects::nonNull).map(ar -> ar.getVersion()).collect(Collectors.toSet());
} catch (IOException e) {
log.error("Could not read directory {}: {}", repoDir, e.getMessage(), e);
}
return Collections.emptySet();
}
Aggregations