use of org.apache.archiva.repository.content.Project in project archiva by apache.
the class ManagedDefaultRepositoryContent method applyCharacteristic.
@Override
public <T extends ContentItem> T applyCharacteristic(Class<T> clazz, ContentItem item) throws LayoutException {
if (item.getAsset().isLeaf()) {
if (clazz.isAssignableFrom(Artifact.class)) {
Artifact artifact = getArtifactFromPath(item.getAsset());
item.setCharacteristic(Artifact.class, artifact);
return (T) artifact;
} else {
throw new LayoutException("Could not adapt file to clazz " + clazz);
}
} else {
if (clazz.isAssignableFrom(Version.class)) {
Version version = getVersionFromPath(item.getAsset());
item.setCharacteristic(Version.class, version);
return (T) version;
} else if (clazz.isAssignableFrom(Project.class)) {
Project project = getProjectFromPath(item.getAsset());
item.setCharacteristic(Project.class, project);
return (T) project;
} else if (clazz.isAssignableFrom(Namespace.class)) {
Namespace ns = getNamespaceFromPath(item.getAsset());
item.setCharacteristic(Namespace.class, ns);
return (T) ns;
} else {
throw new LayoutException("Cannot adapt directory to clazz " + clazz);
}
}
}
use of org.apache.archiva.repository.content.Project in project archiva by apache.
the class MetadataTransferTest method assertFetchProjectOrGroup.
/**
* Transfer the metadata file.
*
* @param requestedResource the requested resource
* @throws Exception
*/
private void assertFetchProjectOrGroup(String requestedResource) throws Exception {
Path expectedFile = managedDefaultDir.resolve(requestedResource);
BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout(BaseRepositoryContentLayout.class);
ContentItem metaItem = managedDefaultRepository.toItem(requestedResource);
Project project = layout.adaptItem(Project.class, managedDefaultRepository.getParent(metaItem));
assertNotNull(project);
String metaPath = managedDefaultRepository.toPath(layout.getMetadataItem(project));
StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies(managedDefaultRepository.getRepository(), metaPath).getFile();
assertNotNull("Should have downloaded a file.", downloadedFile);
assertNoTempFiles(expectedFile);
}
use of org.apache.archiva.repository.content.Project in project archiva by apache.
the class CleanupReleasedSnapshotsRepositoryPurge method process.
@Override
public void process(String path) throws RepositoryPurgeException {
try {
StorageAsset artifactFile = repository.getRepository().getRoot().resolve(path);
BaseRepositoryContentLayout layout = repository.getLayout(BaseRepositoryContentLayout.class);
if (!artifactFile.exists()) {
// Nothing to do here, file doesn't exist, skip it.
return;
}
Artifact artifactRef = layout.getArtifact(path);
if (!VersionUtil.isSnapshot(artifactRef.getVersion().getId())) {
// Nothing to do here, not a snapshot, skip it.
return;
}
ItemSelector projectSelector = ArchivaItemSelector.builder().withNamespace(artifactRef.getNamespace().getId()).withProjectId(artifactRef.getId()).build();
// Gether the released versions
List<String> releasedVersions = new ArrayList<>();
Collection<org.apache.archiva.repository.ManagedRepository> repos = repositoryRegistry.getManagedRepositories();
for (org.apache.archiva.repository.ManagedRepository repo : repos) {
if (repo.getActiveReleaseSchemes().contains(ReleaseScheme.RELEASE)) {
BaseRepositoryContentLayout repoContent = repo.getContent().getLayout(BaseRepositoryContentLayout.class);
Project proj = repoContent.getProject(projectSelector);
for (Version version : repoContent.getVersions(proj)) {
if (!VersionUtil.isSnapshot(version.getId())) {
releasedVersions.add(version.getId());
}
}
}
}
Collections.sort(releasedVersions, VersionComparator.getInstance());
// Now clean out any version that is earlier than the highest released version.
boolean needsMetadataUpdate = false;
ArchivaItemSelector.Builder versionSelectorBuilder = ArchivaItemSelector.builder().withNamespace(artifactRef.getNamespace().getId()).withProjectId(artifactRef.getId()).withArtifactId(artifactRef.getId());
MetadataRepository metadataRepository = repositorySession.getRepository();
if (releasedVersions.contains(VersionUtil.getReleaseVersion(artifactRef.getVersion().getId()))) {
ArchivaItemSelector selector = versionSelectorBuilder.withVersion(artifactRef.getVersion().getId()).build();
Version version = layout.getVersion(selector);
if (version.exists()) {
repository.deleteItem(version);
}
for (RepositoryListener listener : listeners) {
listener.deleteArtifact(metadataRepository, repository.getId(), artifactRef.getNamespace().getId(), artifactRef.getId(), artifactRef.getVersion().getId(), artifactFile.getName());
}
metadataRepository.removeProjectVersion(repositorySession, repository.getId(), artifactRef.getNamespace().getId(), artifactRef.getId(), artifactRef.getVersion().getId());
needsMetadataUpdate = true;
}
if (needsMetadataUpdate) {
updateMetadata(artifactRef);
}
} catch (LayoutException e) {
log.debug("Not processing file that is not an artifact: {}", e.getMessage());
} catch (MetadataRepositoryException e) {
log.error("Could not remove metadata during cleanup of released snapshots of {}", path, e);
} catch (ContentAccessException e) {
e.printStackTrace();
} catch (ItemNotFoundException e) {
log.error("Could not find item to delete {}", e.getMessage(), e);
}
}
use of org.apache.archiva.repository.content.Project in project archiva by apache.
the class ManagedDefaultRepositoryContentTest method testGetArtifactFromContentItem.
@Test
public void testGetArtifactFromContentItem() {
ItemSelector selector = ArchivaItemSelector.builder().withNamespace("org.apache.maven").build();
Namespace ns = repoContent.getNamespace(selector);
List<? extends Artifact> artifacts = repoContent.getArtifacts(ns);
assertNotNull(artifacts);
assertEquals(39, artifacts.size());
List<? extends Artifact> artifacts2 = repoContent.getArtifacts((ContentItem) ns);
assertArrayEquals(artifacts.toArray(), artifacts2.toArray());
selector = ArchivaItemSelector.builder().withNamespace("org.apache.maven.shared").withProjectId("maven-downloader").build();
Project project = repoContent.getProject(selector);
artifacts = repoContent.getArtifacts(project);
assertNotNull(artifacts);
assertEquals(27, artifacts.size());
artifacts2 = repoContent.getArtifacts((ContentItem) project);
assertArrayEquals(artifacts.toArray(), artifacts2.toArray());
selector = ArchivaItemSelector.builder().withNamespace("org.apache.maven.shared").withProjectId("maven-downloader").withVersion("1.1").build();
Version version = repoContent.getVersion(selector);
artifacts = repoContent.getArtifacts(version);
assertNotNull(artifacts);
assertEquals(12, artifacts.size());
artifacts2 = repoContent.getArtifacts((ContentItem) version);
assertArrayEquals(artifacts.toArray(), artifacts2.toArray());
}
use of org.apache.archiva.repository.content.Project in project archiva by apache.
the class AbstractRepositoryContentTest method assertLayoutCi.
private void assertLayoutCi(String path, String groupId, String artifactId, String version, String artifactVersion, String classifier, String type) throws LayoutException {
ItemSelector expectedArtifact = createItemSelector(groupId, artifactId, version, artifactVersion, classifier, type);
// --- Artifact Tests.
// Artifact to Path
assertEquals("Artifact <" + expectedArtifact + "> to path:", path, toPath(expectedArtifact));
// --- Artifact Reference Tests
// Path to Artifact Reference.
ItemSelector testReference = toItemSelector(path);
assertItemSelector(testReference, groupId, artifactId, version, artifactVersion, classifier, type);
// And back again, using test Reference from previous step.
assertEquals("Artifact <" + expectedArtifact + "> to path:", path, toPath(testReference));
if (getManaged() != null) {
Namespace ns = null;
Project pr = null;
Version ver = null;
if (StringUtils.isNotEmpty(groupId)) {
ns = getManaged().getLayout(BaseRepositoryContentLayout.class).getNamespace(expectedArtifact);
assertNotNull(ns);
assertEquals(groupId, ns.getId());
}
if (StringUtils.isNotEmpty(artifactId)) {
pr = getManaged().getLayout(BaseRepositoryContentLayout.class).getProject(expectedArtifact);
assertNotNull(pr);
assertEquals(artifactId, pr.getId());
assertEquals(ns, pr.getNamespace());
}
if (StringUtils.isNotEmpty(version)) {
ver = getManaged().getLayout(BaseRepositoryContentLayout.class).getVersion(expectedArtifact);
assertNotNull(ver);
assertEquals(version, ver.getId());
assertEquals(pr, ver.getProject());
}
Artifact artifact = getManaged().getLayout(BaseRepositoryContentLayout.class).getArtifact(expectedArtifact);
assertNotNull(artifact);
assertEquals(artifactId, artifact.getId());
assertEquals(ver, artifact.getVersion());
}
}
Aggregations