use of org.apache.archiva.repository.features.IndexCreationFeature in project archiva by apache.
the class RepositoryProviderMock method updateManagedInstance.
@Override
public void updateManagedInstance(EditableManagedRepository managedRepository, ManagedRepositoryConfiguration configuration) throws RepositoryException {
try {
managedRepository.setName(managedRepository.getPrimaryLocale(), configuration.getName());
managedRepository.setLocation(new URI(configuration.getLocation() == null ? "" : configuration.getLocation()));
managedRepository.setBaseUri(new URI(""));
managedRepository.setBlocksRedeployment(configuration.isBlockRedeployments());
managedRepository.setDescription(managedRepository.getPrimaryLocale(), configuration.getDescription());
managedRepository.setLayout(configuration.getLayout());
managedRepository.setScanned(configuration.isScanned());
managedRepository.setSchedulingDefinition(configuration.getRefreshCronExpression());
if (configuration.isReleases()) {
managedRepository.addActiveReleaseScheme(ReleaseScheme.RELEASE);
}
if (configuration.isSnapshots()) {
managedRepository.addActiveReleaseScheme(ReleaseScheme.SNAPSHOT);
}
ArtifactCleanupFeature acf = managedRepository.getFeature(ArtifactCleanupFeature.class).get();
acf.setRetentionPeriod(Period.ofDays(configuration.getRetentionPeriod()));
acf.setDeleteReleasedSnapshots(configuration.isDeleteReleasedSnapshots());
acf.setRetentionCount(configuration.getRetentionCount());
IndexCreationFeature icf = managedRepository.getFeature(IndexCreationFeature.class).get();
icf.setIndexPath(new URI(configuration.getIndexDir()));
icf.setSkipPackedIndexCreation(configuration.isSkipPackedIndexCreation());
StagingRepositoryFeature srf = managedRepository.getFeature(StagingRepositoryFeature.class).get();
srf.setStageRepoNeeded(configuration.isStageRepoNeeded());
} catch (Exception e) {
throw new RepositoryException("Error", e);
}
}
use of org.apache.archiva.repository.features.IndexCreationFeature in project archiva by apache.
the class ArchivaDavResourceFactory method getResourceFromGroup.
private DavResource getResourceFromGroup(DavServletRequest request, List<String> repositories, ArchivaDavResourceLocator locator, RepositoryGroupConfiguration repositoryGroupConfiguration) throws DavException {
if (repositoryGroupConfiguration.getRepositories() == null || repositoryGroupConfiguration.getRepositories().isEmpty()) {
Path file = Paths.get(System.getProperty("appserver.base"), "groups/" + repositoryGroupConfiguration.getId());
return new ArchivaDavResource(file.toString(), "groups/" + repositoryGroupConfiguration.getId(), null, request.getDavSession(), locator, this, mimeTypes, auditListeners, scheduler, fileLockManager);
}
List<Path> mergedRepositoryContents = new ArrayList<>();
// multiple repo types so we guess they are all the same type
// so use the first one
// FIXME add a method with group in the repository storage
String firstRepoId = repositoryGroupConfiguration.getRepositories().get(0);
String path = getLogicalResource(locator, repositoryRegistry.getManagedRepository(firstRepoId), false);
if (path.startsWith("/")) {
path = path.substring(1);
}
LogicalResource logicalResource = new LogicalResource(path);
// flow:
// if the current user logged in has permission to any of the repositories, allow user to
// browse the repo group but displaying only the repositories which the user has permission to access.
// otherwise, prompt for authentication.
String activePrincipal = getActivePrincipal(request);
boolean allow = isAllowedToContinue(request, repositories, activePrincipal);
// remove last /
String pathInfo = StringUtils.removeEnd(request.getPathInfo(), "/");
if (allow) {
if (StringUtils.endsWith(pathInfo, repositoryGroupConfiguration.getMergedIndexPath())) {
Path mergedRepoDir = buildMergedIndexDirectory(repositories, activePrincipal, request, repositoryGroupConfiguration);
mergedRepositoryContents.add(mergedRepoDir);
} else {
if (StringUtils.equalsIgnoreCase(pathInfo, "/" + repositoryGroupConfiguration.getId())) {
Path tmpDirectory = Paths.get(SystemUtils.getJavaIoTmpDir().toString(), repositoryGroupConfiguration.getId(), repositoryGroupConfiguration.getMergedIndexPath());
if (!Files.exists(tmpDirectory)) {
synchronized (tmpDirectory.toAbsolutePath().toString()) {
if (!Files.exists(tmpDirectory)) {
try {
Files.createDirectories(tmpDirectory);
} catch (IOException e) {
throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Could not create direcotory " + tmpDirectory);
}
}
}
}
mergedRepositoryContents.add(tmpDirectory.getParent());
}
for (String repository : repositories) {
ManagedRepositoryContent managedRepository = null;
ManagedRepository repo = repositoryRegistry.getManagedRepository(repository);
if (repo == null) {
throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Invalid managed repository <" + repository + ">");
}
managedRepository = repo.getContent();
if (managedRepository == null) {
log.error("Inconsistency detected. Repository content not found for '{}'", repository);
throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Invalid managed repository <" + repository + ">");
}
Path resourceFile = Paths.get(managedRepository.getRepoRoot(), logicalResource.getPath());
if (Files.exists(resourceFile)) {
// in case of group displaying index directory doesn't have sense !!
IndexCreationFeature idf = managedRepository.getRepository().getFeature(IndexCreationFeature.class).get();
String repoIndexDirectory = idf.getIndexPath().toString();
if (StringUtils.isNotEmpty(repoIndexDirectory)) {
if (!Paths.get(repoIndexDirectory).isAbsolute()) {
repoIndexDirectory = Paths.get(managedRepository.getRepository().getLocation()).resolve(StringUtils.isEmpty(repoIndexDirectory) ? ".indexer" : repoIndexDirectory).toAbsolutePath().toString();
}
}
if (StringUtils.isEmpty(repoIndexDirectory)) {
repoIndexDirectory = Paths.get(managedRepository.getRepository().getLocation()).resolve(".indexer").toAbsolutePath().toString();
}
if (!StringUtils.equals(FilenameUtils.normalize(repoIndexDirectory), FilenameUtils.normalize(resourceFile.toAbsolutePath().toString()))) {
// for prompted authentication
if (httpAuth.getSecuritySession(request.getSession(true)) != null) {
try {
if (isAuthorized(request, repository)) {
mergedRepositoryContents.add(resourceFile);
log.debug("Repository '{}' accessed by '{}'", repository, activePrincipal);
}
} catch (DavException e) {
// TODO: review exception handling
log.debug("Skipping repository '{}' for user '{}': {}", managedRepository, activePrincipal, e.getMessage());
}
} else {
// for the current user logged in
try {
if (servletAuth.isAuthorized(activePrincipal, repository, WebdavMethodUtil.getMethodPermission(request.getMethod()))) {
mergedRepositoryContents.add(resourceFile);
log.debug("Repository '{}' accessed by '{}'", repository, activePrincipal);
}
} catch (UnauthorizedException e) {
// TODO: review exception handling
log.debug("Skipping repository '{}' for user '{}': {}", managedRepository, activePrincipal, e.getMessage());
}
}
}
}
}
}
} else {
throw new UnauthorizedDavException(locator.getRepositoryId(), "User not authorized.");
}
ArchivaVirtualDavResource resource = new ArchivaVirtualDavResource(mergedRepositoryContents, logicalResource.getPath(), mimeTypes, locator, this);
// compatibility with MRM-440 to ensure browsing the repository group works ok
if (resource.isCollection() && !request.getRequestURI().endsWith("/")) {
throw new BrowserRedirectException(resource.getHref());
}
return resource;
}
use of org.apache.archiva.repository.features.IndexCreationFeature in project archiva by apache.
the class MavenIndexManagerTest method createTestContext.
private ArchivaIndexingContext createTestContext() throws URISyntaxException, IndexCreationFailedException, IOException {
indexPath = Paths.get("target/repositories/test-repo/.index-test");
FileUtils.deleteDirectory(indexPath);
repository = new MavenManagedRepository("test-repo", "Test Repo", Paths.get("target/repositories"));
repository.setLocation(new URI("test-repo"));
IndexCreationFeature icf = repository.getFeature(IndexCreationFeature.class).get();
icf.setIndexPath(new URI(".index-test"));
ctx = mavenIndexManager.createContext(repository);
return ctx;
}
use of org.apache.archiva.repository.features.IndexCreationFeature in project archiva by apache.
the class ArchivaIndexManagerMock method getIndexPath.
private Path getIndexPath(Repository repo) throws IOException {
IndexCreationFeature icf = repo.getFeature(IndexCreationFeature.class).get();
Path repoDir = repo.getLocalPath();
URI indexDir = icf.getIndexPath();
Path indexDirectory = null;
if (!StringUtils.isEmpty(indexDir.toString())) {
indexDirectory = PathUtil.getPathFromUri(indexDir);
// not absolute so create it in repository directory
if (!indexDirectory.isAbsolute()) {
indexDirectory = repoDir.resolve(indexDirectory);
}
} else {
indexDirectory = repoDir.resolve(".index");
}
if (!Files.exists(indexDirectory)) {
Files.createDirectories(indexDirectory);
}
return indexDirectory;
}
use of org.apache.archiva.repository.features.IndexCreationFeature in project archiva by apache.
the class GenericIndexManager method getIndexPath.
private Path getIndexPath(Repository repo) throws IOException {
IndexCreationFeature icf = repo.getFeature(IndexCreationFeature.class).get();
Path repoDir = repo.getLocalPath();
URI indexDir = icf.getIndexPath();
Path indexDirectory = null;
if (!StringUtils.isEmpty(indexDir.toString())) {
indexDirectory = PathUtil.getPathFromUri(indexDir);
// not absolute so create it in repository directory
if (!indexDirectory.isAbsolute()) {
indexDirectory = repoDir.resolve(indexDirectory);
}
} else {
indexDirectory = repoDir.resolve(DEFAULT_INDEXER_DIR);
}
if (!Files.exists(indexDirectory)) {
Files.createDirectories(indexDirectory);
}
return indexDirectory;
}
Aggregations