Search in sources :

Example 1 with RepositoryException

use of org.apache.archiva.repository.RepositoryException in project archiva by apache.

the class MavenRepositoryProvider method updateManagedInstance.

@Override
public void updateManagedInstance(EditableManagedRepository repo, ManagedRepositoryConfiguration cfg) throws RepositoryException {
    try {
        repo.setLocation(getURIFromString(cfg.getLocation()));
    } catch (UnsupportedURIException e) {
        throw new RepositoryException("The location entry is not a valid uri: " + cfg.getLocation());
    }
    setBaseConfig(repo, cfg);
    Path repoDir = repo.getLocalPath();
    if (!Files.exists(repoDir)) {
        log.debug("Creating repo directory {}", repoDir);
        try {
            Files.createDirectories(repoDir);
        } catch (IOException e) {
            log.error("Could not create directory {} for repository {}", repo.getLocalPath(), repo.getId(), e);
            throw new RepositoryException("Could not create directory for repository " + repo.getLocalPath());
        }
    }
    repo.setSchedulingDefinition(cfg.getRefreshCronExpression());
    repo.setBlocksRedeployment(cfg.isBlockRedeployments());
    repo.setScanned(cfg.isScanned());
    if (cfg.isReleases()) {
        repo.addActiveReleaseScheme(ReleaseScheme.RELEASE);
    }
    if (cfg.isSnapshots()) {
        repo.addActiveReleaseScheme(ReleaseScheme.SNAPSHOT);
    }
    StagingRepositoryFeature stagingRepositoryFeature = repo.getFeature(StagingRepositoryFeature.class).get();
    stagingRepositoryFeature.setStageRepoNeeded(cfg.isStageRepoNeeded());
    IndexCreationFeature indexCreationFeature = repo.getFeature(IndexCreationFeature.class).get();
    indexCreationFeature.setSkipPackedIndexCreation(cfg.isSkipPackedIndexCreation());
    indexCreationFeature.setIndexPath(getURIFromString(cfg.getIndexDir()));
    indexCreationFeature.setPackedIndexPath(getURIFromString(cfg.getPackedIndexDir()));
    /* -> Should be created by MavenIndexProvider

        Path indexPath;
        if (indexCreationFeature.getIndexPath().getScheme() == null) {
            indexPath = Paths.get(indexCreationFeature.getIndexPath().getPath());
        } else {
            indexPath = Paths.get(indexCreationFeature.getIndexPath());
        }
        Path absoluteIndexPath;
        if (indexPath.isAbsolute()) {
            absoluteIndexPath = indexPath;
        } else {
            absoluteIndexPath = PathUtil.getPathFromUri(repo.getLocation()).resolve(indexCreationFeature.getIndexPath().getPath());
        }
        try {
            Files.createDirectories(absoluteIndexPath);
        } catch (IOException e) {
            log.error("Could not create index directory {}", absoluteIndexPath);
            throw new RepositoryException("Could not create index directory " + absoluteIndexPath);
        }*/
    ArtifactCleanupFeature artifactCleanupFeature = repo.getFeature(ArtifactCleanupFeature.class).get();
    artifactCleanupFeature.setDeleteReleasedSnapshots(cfg.isDeleteReleasedSnapshots());
    artifactCleanupFeature.setRetentionCount(cfg.getRetentionCount());
    artifactCleanupFeature.setRetentionPeriod(Period.ofDays(cfg.getRetentionPeriod()));
}
Also used : Path(java.nio.file.Path) IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) UnsupportedURIException(org.apache.archiva.repository.UnsupportedURIException) RepositoryException(org.apache.archiva.repository.RepositoryException) IOException(java.io.IOException) ArtifactCleanupFeature(org.apache.archiva.repository.features.ArtifactCleanupFeature) StagingRepositoryFeature(org.apache.archiva.repository.features.StagingRepositoryFeature)

Example 2 with RepositoryException

use of org.apache.archiva.repository.RepositoryException in project archiva by apache.

the class RepositoryProviderMock method updateRemoteInstance.

@Override
public void updateRemoteInstance(EditableRemoteRepository remoteRepository, RemoteRepositoryConfiguration configuration) throws RepositoryException {
    try {
        remoteRepository.setName(remoteRepository.getPrimaryLocale(), configuration.getName());
        remoteRepository.setBaseUri(new URI(""));
        remoteRepository.setDescription(remoteRepository.getPrimaryLocale(), configuration.getDescription());
        remoteRepository.setLayout(configuration.getLayout());
        remoteRepository.setSchedulingDefinition(configuration.getRefreshCronExpression());
        remoteRepository.setCheckPath(configuration.getCheckPath());
        remoteRepository.setExtraHeaders(configuration.getExtraHeaders());
        remoteRepository.setExtraParameters(configuration.getExtraParameters());
        remoteRepository.setTimeout(Duration.ofSeconds(configuration.getTimeout()));
        char[] pwd = configuration.getPassword() == null ? "".toCharArray() : configuration.getPassword().toCharArray();
        remoteRepository.setCredentials(new PasswordCredentials(configuration.getUsername(), pwd));
        remoteRepository.setLocation(new URI(configuration.getUrl() == null ? "" : configuration.getUrl()));
        RemoteIndexFeature rif = remoteRepository.getFeature(RemoteIndexFeature.class).get();
        rif.setDownloadRemoteIndexOnStartup(configuration.isDownloadRemoteIndexOnStartup());
        rif.setDownloadRemoteIndex(configuration.isDownloadRemoteIndex());
        rif.setIndexUri(new URI(configuration.getIndexDir()));
        rif.setDownloadTimeout(Duration.ofSeconds(configuration.getRemoteDownloadTimeout()));
        rif.setProxyId(configuration.getRemoteDownloadNetworkProxyId());
    } catch (Exception e) {
        throw new RepositoryException("Error", e);
    }
}
Also used : PasswordCredentials(org.apache.archiva.repository.PasswordCredentials) RemoteIndexFeature(org.apache.archiva.repository.features.RemoteIndexFeature) RepositoryException(org.apache.archiva.repository.RepositoryException) URI(java.net.URI) RepositoryException(org.apache.archiva.repository.RepositoryException)

Example 3 with RepositoryException

use of org.apache.archiva.repository.RepositoryException in project archiva by apache.

the class CleanupReleasedSnapshotsRepositoryPurge method process.

@Override
public void process(String path) throws RepositoryPurgeException {
    try {
        Path artifactFile = Paths.get(repository.getRepoRoot(), path);
        if (!Files.exists(artifactFile)) {
            // Nothing to do here, file doesn't exist, skip it.
            return;
        }
        ArtifactReference artifactRef = repository.toArtifactReference(path);
        if (!VersionUtil.isSnapshot(artifactRef.getVersion())) {
            // Nothing to do here, not a snapshot, skip it.
            return;
        }
        ProjectReference reference = new ProjectReference();
        reference.setGroupId(artifactRef.getGroupId());
        reference.setArtifactId(artifactRef.getArtifactId());
        // 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)) {
                try {
                    ManagedRepositoryContent repoContent = repo.getContent();
                    for (String version : repoContent.getVersions(reference)) {
                        if (!VersionUtil.isSnapshot(version)) {
                            releasedVersions.add(version);
                        }
                    }
                } catch (RepositoryException e) {
                // swallow
                }
            }
        }
        Collections.sort(releasedVersions, VersionComparator.getInstance());
        // Now clean out any version that is earlier than the highest released version.
        boolean needsMetadataUpdate = false;
        VersionedReference versionRef = new VersionedReference();
        versionRef.setGroupId(artifactRef.getGroupId());
        versionRef.setArtifactId(artifactRef.getArtifactId());
        MetadataRepository metadataRepository = repositorySession.getRepository();
        if (releasedVersions.contains(VersionUtil.getReleaseVersion(artifactRef.getVersion()))) {
            versionRef.setVersion(artifactRef.getVersion());
            repository.deleteVersion(versionRef);
            for (RepositoryListener listener : listeners) {
                listener.deleteArtifact(metadataRepository, repository.getId(), artifactRef.getGroupId(), artifactRef.getArtifactId(), artifactRef.getVersion(), artifactFile.getFileName().toString());
            }
            metadataRepository.removeProjectVersion(repository.getId(), artifactRef.getGroupId(), artifactRef.getArtifactId(), artifactRef.getVersion());
            needsMetadataUpdate = true;
        }
        if (needsMetadataUpdate) {
            updateMetadata(artifactRef);
        }
    } catch (LayoutException e) {
        log.debug("Not processing file that is not an artifact: {}", e.getMessage());
    } catch (ContentNotFoundException e) {
        throw new RepositoryPurgeException(e.getMessage(), e);
    } catch (MetadataRepositoryException e) {
        log.error("Could not remove metadata during cleanup of released snapshots of {}", path, e);
    }
}
Also used : Path(java.nio.file.Path) RepositoryListener(org.apache.archiva.repository.events.RepositoryListener) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) ProjectReference(org.apache.archiva.model.ProjectReference) ContentNotFoundException(org.apache.archiva.repository.ContentNotFoundException) ArrayList(java.util.ArrayList) RepositoryException(org.apache.archiva.repository.RepositoryException) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) VersionedReference(org.apache.archiva.model.VersionedReference) LayoutException(org.apache.archiva.repository.LayoutException) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent) ArtifactReference(org.apache.archiva.model.ArtifactReference)

Example 4 with RepositoryException

use of org.apache.archiva.repository.RepositoryException in project archiva by apache.

the class Maven2RepositoryMerger method merge.

@Override
public void merge(MetadataRepository metadataRepository, String sourceRepoId, String targetRepoId) throws RepositoryMergerException {
    try {
        List<ArtifactMetadata> artifactsInSourceRepo = metadataRepository.getArtifacts(sourceRepoId);
        for (ArtifactMetadata artifactMetadata : artifactsInSourceRepo) {
            artifactMetadata.setRepositoryId(targetRepoId);
            createFolderStructure(sourceRepoId, targetRepoId, artifactMetadata);
        }
    } catch (MetadataRepositoryException e) {
        throw new RepositoryMergerException(e.getMessage(), e);
    } catch (IOException e) {
        throw new RepositoryMergerException(e.getMessage(), e);
    } catch (RepositoryException e) {
        throw new RepositoryMergerException(e.getMessage(), e);
    }
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) RepositoryException(org.apache.archiva.repository.RepositoryException) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) IOException(java.io.IOException) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata)

Example 5 with RepositoryException

use of org.apache.archiva.repository.RepositoryException in project archiva by apache.

the class DefaultRemoteRepositoryAdmin method updateRemoteRepository.

@Override
public Boolean updateRemoteRepository(org.apache.archiva.admin.model.beans.RemoteRepository remoteRepository, AuditInformation auditInformation) throws RepositoryAdminException {
    String repositoryId = remoteRepository.getId();
    triggerAuditEvent(repositoryId, null, AuditEvent.MODIFY_REMOTE_REPO, auditInformation);
    // update means : remove and add
    Configuration configuration = getArchivaConfiguration().getConfiguration();
    RemoteRepositoryConfiguration remoteRepositoryConfiguration = getRepositoryConfiguration(remoteRepository);
    try {
        repositoryRegistry.putRepository(remoteRepositoryConfiguration, configuration);
    } catch (RepositoryException e) {
        log.error("Could not update remote repository {}: {}", remoteRepositoryConfiguration.getId(), e.getMessage(), e);
        throw new RepositoryAdminException("Update of remote repository failed" + (e.getMessage() == null ? "" : ": " + e.getMessage()));
    }
    saveConfiguration(configuration);
    return Boolean.TRUE;
}
Also used : RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) Configuration(org.apache.archiva.configuration.Configuration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) RepositoryException(org.apache.archiva.repository.RepositoryException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException)

Aggregations

RepositoryException (org.apache.archiva.repository.RepositoryException)33 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)14 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)13 Path (java.nio.file.Path)12 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)12 IOException (java.io.IOException)11 ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)11 Configuration (org.apache.archiva.configuration.Configuration)7 ArtifactReference (org.apache.archiva.model.ArtifactReference)7 URI (java.net.URI)6 MetadataRepository (org.apache.archiva.metadata.repository.MetadataRepository)6 RepositorySession (org.apache.archiva.metadata.repository.RepositorySession)6 IndexCreationFeature (org.apache.archiva.repository.features.IndexCreationFeature)6 RemoteIndexFeature (org.apache.archiva.repository.features.RemoteIndexFeature)6 StagingRepositoryFeature (org.apache.archiva.repository.features.StagingRepositoryFeature)6 ManagedRepository (org.apache.archiva.admin.model.beans.ManagedRepository)5 PasswordCredentials (org.apache.archiva.repository.PasswordCredentials)5 ManagedRepositoryConfiguration (org.apache.archiva.configuration.ManagedRepositoryConfiguration)4 ProxyConnectorConfiguration (org.apache.archiva.configuration.ProxyConnectorConfiguration)4 RemoteRepositoryConfiguration (org.apache.archiva.configuration.RemoteRepositoryConfiguration)4