use of org.apache.archiva.repository.storage.StorageAsset in project archiva by apache.
the class ChecksumTransferTest method testGetChecksumBadSha1BadMd5FixSetting.
@Test
public void testGetChecksumBadSha1BadMd5FixSetting() throws Exception {
String path = "org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar";
setupTestableManagedRepository(path);
Path expectedFile = managedDefaultDir.resolve(path);
BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout(BaseRepositoryContentLayout.class);
Artifact artifact = layout.getArtifact(path);
FileUtils.deleteDirectory(expectedFile.getParent());
assertFalse(Files.exists(expectedFile));
// Configure Connector (usually done within archiva.xml configuration)
saveConnector(ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false);
StorageAsset downloadedFile = proxyHandler.fetchFromProxies(managedDefaultRepository.getRepository(), artifact);
Path proxied1File = Paths.get(REPOPATH_PROXIED1, path);
assertFileEquals(expectedFile, downloadedFile.getFilePath(), proxied1File);
assertNoTempFiles(expectedFile);
assertChecksums(expectedFile, "4ec20a12dc91557330bd0b39d1805be5e329ae56 get-checksum-both-bad-1.0.jar", "a292491a35925465e693a44809a078b5 get-checksum-both-bad-1.0.jar");
}
use of org.apache.archiva.repository.storage.StorageAsset in project archiva by apache.
the class ManagedDefaultRepositoryContent method toItem.
@Override
public ContentItem toItem(String path) throws LayoutException {
StorageAsset asset = getRepository().getAsset(path);
ContentItem item = getItemFromPath(asset);
if (item instanceof DataItem) {
Artifact artifact = adaptItem(Artifact.class, item);
if (asset.getParent() == null) {
throw new LayoutException("Path too short for maven artifact " + path);
}
String version = asset.getParent().getName();
if (asset.getParent().getParent() == null) {
throw new LayoutException("Path too short for maven artifact " + path);
}
String project = item.getAsset().getParent().getParent().getName();
DataItem dataItem = (DataItem) item;
if (StringUtils.isEmpty(dataItem.getExtension())) {
throw new LayoutException("Missing type on maven artifact");
}
if (!project.equals(artifact.getId())) {
throw new LayoutException("The maven artifact id " + artifact.getId() + " does not match the project id: " + project);
}
boolean versionIsGenericSnapshot = VersionUtil.isGenericSnapshot(version);
boolean artifactVersionIsSnapshot = VersionUtil.isSnapshot(artifact.getArtifactVersion());
if (versionIsGenericSnapshot && !artifactVersionIsSnapshot) {
throw new LayoutException("The maven artifact has no snapshot version in snapshot directory " + dataItem);
}
if (!versionIsGenericSnapshot && artifactVersionIsSnapshot) {
throw new LayoutException("The maven artifact version " + artifact.getArtifactVersion() + " is a snapshot version but inside a non snapshot directory " + version);
}
if (!versionIsGenericSnapshot && !version.equals(artifact.getArtifactVersion())) {
throw new LayoutException("The maven artifact version " + artifact.getArtifactVersion() + " does not match the version directory " + version);
}
}
return item;
}
use of org.apache.archiva.repository.storage.StorageAsset in project archiva by apache.
the class ManagedDefaultRepositoryContent method getItemFileFilterFromSelector.
Predicate<StorageAsset> getItemFileFilterFromSelector(ItemSelector selector) {
if (!selector.hasNamespace() && !selector.hasProjectId()) {
throw new IllegalArgumentException("Selector must have at least namespace and projectid");
}
StringBuilder pathMatcher = new StringBuilder("^");
if (selector.hasNamespace()) {
String path = "/" + String.join("/", selector.getNamespace().split("\\."));
if (path.contains("*")) {
appendPatternRegex(pathMatcher, path);
} else {
pathMatcher.append(Pattern.quote(path));
}
}
if (selector.hasProjectId()) {
pathMatcher.append("/");
if (selector.getProjectId().contains("*")) {
appendPatternRegex(pathMatcher, selector.getProjectId());
} else {
pathMatcher.append(Pattern.quote(selector.getProjectId()));
}
}
if (selector.hasVersion()) {
pathMatcher.append("/");
if (selector.getVersion().contains("*")) {
appendPatternRegex(pathMatcher, selector.getVersion());
} else {
pathMatcher.append(Pattern.quote(selector.getVersion()));
}
}
pathMatcher.append(".*");
final Pattern pathPattern = Pattern.compile(pathMatcher.toString());
final Predicate<StorageAsset> pathPredicate = (StorageAsset asset) -> pathPattern.matcher(asset.getPath()).matches();
if (selector.hasArtifactId() || selector.hasArtifactVersion() || selector.hasClassifier() || selector.hasType() || selector.hasExtension()) {
return getArtifactFileFilterFromSelector(selector).and(pathPredicate);
} else {
return pathPredicate;
}
}
use of org.apache.archiva.repository.storage.StorageAsset in project archiva by apache.
the class ManagedDefaultRepositoryContent method getArtifact.
@Override
public Artifact getArtifact(final ItemSelector selectorArg) throws ContentAccessException {
ItemSelector selector = selectorArg;
if (!selectorArg.hasProjectId()) {
throw new IllegalArgumentException("Project id must be set");
}
if (!selectorArg.hasVersion()) {
if (selectorArg.hasArtifactVersion() && VersionUtil.isSnapshot(selectorArg.getArtifactVersion())) {
selector = ArchivaItemSelector.builder().withSelector(selectorArg).withVersion(VersionUtil.getBaseVersion(selectorArg.getArtifactVersion())).build();
} else if (selectorArg.hasArtifactVersion()) {
selector = ArchivaItemSelector.builder().withSelector(selectorArg).withVersion(selectorArg.getArtifactVersion()).build();
} else {
throw new IllegalArgumentException("Version must be set");
}
}
if (!selectorArg.hasArtifactId()) {
throw new IllegalArgumentException("Artifact id must be set");
}
final StorageAsset artifactDir = getAsset(selector.getNamespace(), selector.getProjectId(), selector.getVersion());
final String artifactVersion = mavenContentHelper.getArtifactVersion(artifactDir, selector);
final String classifier = MavenContentHelper.getClassifier(selector);
final String extension = MavenContentHelper.getArtifactExtension(selector);
final String artifactId = StringUtils.isEmpty(selector.getArtifactId()) ? selector.getProjectId() : selector.getArtifactId();
final String fileName = MavenContentHelper.getArtifactFileName(artifactId, artifactVersion, classifier, extension);
final StorageAsset path = getAsset(selector.getNamespace(), selector.getProjectId(), selector.getVersion(), fileName);
try {
return getArtifactFromPath(path);
} catch (LayoutException e) {
throw new IllegalArgumentException("The selector is not valid " + e.getMessage(), e);
}
}
use of org.apache.archiva.repository.storage.StorageAsset in project archiva by apache.
the class ChecksumTransferTest method testGetWithNoChecksumsUsingFailSetting.
@Test
public void testGetWithNoChecksumsUsingFailSetting() throws Exception {
String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar";
setupTestableManagedRepository(path);
Path expectedFile = managedDefaultDir.resolve(path);
BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout(BaseRepositoryContentLayout.class);
Artifact artifact = layout.getArtifact(path);
FileUtils.deleteDirectory(expectedFile.getParent());
assertFalse(Files.exists(expectedFile));
// Configure Connector (usually done within archiva.xml configuration)
saveConnector(ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false);
StorageAsset downloadedFile = proxyHandler.fetchFromProxies(managedDefaultRepository.getRepository(), artifact);
assertNotDownloaded(downloadedFile);
assertChecksums(expectedFile, null, null);
}
Aggregations