Search in sources :

Example 6 with Artifact

use of org.apache.archiva.repository.content.Artifact 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;
}
Also used : DataItem(org.apache.archiva.repository.content.DataItem) LayoutException(org.apache.archiva.repository.content.LayoutException) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) ContentItem(org.apache.archiva.repository.content.ContentItem) ArchivaContentItem(org.apache.archiva.repository.content.base.ArchivaContentItem) Artifact(org.apache.archiva.repository.content.Artifact)

Example 7 with Artifact

use of org.apache.archiva.repository.content.Artifact 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);
        }
    }
}
Also used : ArchivaProject(org.apache.archiva.repository.content.base.ArchivaProject) Project(org.apache.archiva.repository.content.Project) LayoutException(org.apache.archiva.repository.content.LayoutException) Version(org.apache.archiva.repository.content.Version) ArchivaVersion(org.apache.archiva.repository.content.base.ArchivaVersion) Artifact(org.apache.archiva.repository.content.Artifact) ArchivaNamespace(org.apache.archiva.repository.content.base.ArchivaNamespace) Namespace(org.apache.archiva.repository.content.Namespace)

Example 8 with Artifact

use of org.apache.archiva.repository.content.Artifact 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);
}
Also used : Path(java.nio.file.Path) BaseRepositoryContentLayout(org.apache.archiva.repository.content.BaseRepositoryContentLayout) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) Artifact(org.apache.archiva.repository.content.Artifact) Test(org.junit.Test)

Example 9 with Artifact

use of org.apache.archiva.repository.content.Artifact in project archiva by apache.

the class ChecksumTransferTest method testGetAlwaysBadChecksumPresentLocallyAbsentRemoteUsingFixSetting.

@Test
public void testGetAlwaysBadChecksumPresentLocallyAbsentRemoteUsingFixSetting() throws Exception {
    String path = "org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar";
    setupTestableManagedRepository(path);
    Path expectedFile = managedDefaultDir.resolve(path);
    Path remoteFile = Paths.get(REPOPATH_PROXIED1, path);
    setManagedOlderThanRemote(expectedFile, remoteFile);
    BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout(BaseRepositoryContentLayout.class);
    Artifact artifact = layout.getArtifact(path);
    // 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, "96a08dc80a108cba8efd3b20aec91b32a0b2cbd4  get-bad-local-checksum-1.0.jar", "46fdd6ca55bf1d7a7eb0c858f41e0ccd  get-bad-local-checksum-1.0.jar");
}
Also used : Path(java.nio.file.Path) BaseRepositoryContentLayout(org.apache.archiva.repository.content.BaseRepositoryContentLayout) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) Artifact(org.apache.archiva.repository.content.Artifact) Test(org.junit.Test)

Example 10 with Artifact

use of org.apache.archiva.repository.content.Artifact in project archiva by apache.

the class ChecksumTransferTest method testGetAlwaysBadChecksumPresentLocallyAbsentRemoteUsingIgnoredSetting.

@Test
public void testGetAlwaysBadChecksumPresentLocallyAbsentRemoteUsingIgnoredSetting() throws Exception {
    String path = "org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar";
    setupTestableManagedRepository(path);
    Path expectedFile = managedDefaultDir.resolve(path);
    Path remoteFile = Paths.get(REPOPATH_PROXIED1, path);
    setManagedOlderThanRemote(expectedFile, remoteFile);
    BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout(BaseRepositoryContentLayout.class);
    Artifact artifact = layout.getArtifact(path);
    // Configure Connector (usually done within archiva.xml configuration)
    saveConnector(ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, 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);
    // There are no hashcodes on the proxy side to download, hence the local ones should remain invalid.
    assertChecksums(expectedFile, "invalid checksum file", "invalid checksum file");
}
Also used : Path(java.nio.file.Path) BaseRepositoryContentLayout(org.apache.archiva.repository.content.BaseRepositoryContentLayout) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) Artifact(org.apache.archiva.repository.content.Artifact) Test(org.junit.Test)

Aggregations

Artifact (org.apache.archiva.repository.content.Artifact)78 BaseRepositoryContentLayout (org.apache.archiva.repository.content.BaseRepositoryContentLayout)63 Test (org.junit.Test)60 StorageAsset (org.apache.archiva.repository.storage.StorageAsset)59 Path (java.nio.file.Path)54 ArchivaItemSelector (org.apache.archiva.repository.content.base.ArchivaItemSelector)26 ItemSelector (org.apache.archiva.repository.content.ItemSelector)21 LayoutException (org.apache.archiva.repository.content.LayoutException)21 ContentItem (org.apache.archiva.repository.content.ContentItem)19 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)15 IOException (java.io.IOException)13 ManagedRepository (org.apache.archiva.repository.ManagedRepository)13 Project (org.apache.archiva.repository.content.Project)13 MavenMetadataReader (org.apache.archiva.maven.metadata.MavenMetadataReader)12 Version (org.apache.archiva.repository.content.Version)12 ArchivaContentItem (org.apache.archiva.repository.content.base.ArchivaContentItem)12 Reader (java.io.Reader)11 List (java.util.List)11 Collectors (java.util.stream.Collectors)11 Inject (javax.inject.Inject)11