From 380c152114e6e8648558bb9f24ac529dc2d7d811 Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Sat, 22 Jun 2019 19:31:49 +0200 Subject: [PATCH] Using storageAsset for Index API --- .../mock/RepositoryProviderMock.java | 28 ++++ .../group/DefaultRepositoryGroupAdmin.java | 7 +- .../admin/mock/ArchivaIndexManagerMock.java | 30 ++-- .../MockMergedRemoteIndexesScheduler.java | 2 +- .../archiva/indexer/GenericIndexManager.java | 128 -------------- .../repository/EditableRepositoryGroup.java | 2 - .../archiva/repository/RelocatablePath.java | 18 ++ .../archiva/repository/RepositoryGroup.java | 6 - .../archiva/repository/RequestPathMapper.java | 18 ++ .../features/IndexCreationFeature.java | 13 +- .../indexer/merger/BasicIndexMerger.java | 156 ++++++++++++++++++ .../DefaultMergedRemoteIndexesScheduler.java | 36 ++-- .../repository/AbstractRepositoryGroup.java | 12 -- .../src/test/resources/spring-context.xml | 7 + .../indexer/maven/DefaultIndexMerger.java | 1 - .../indexer/maven/MavenIndexManager.java | 65 +++----- .../maven2/MavenRepositoryGroup.java | 7 +- .../maven2/MavenRepositoryProvider.java | 27 ++- .../index/mock/ArchivaIndexManagerMock.java | 30 ++-- .../maven2/MavenRepositoryProviderTest.java | 10 +- .../maven/ArchivaIndexingTaskExecutor.java | 4 +- .../ArchivaIndexingTaskExecutorTest.java | 44 +++-- .../archiva/webdav/ArchivaDavResource.java | 2 +- .../webdav/ArchivaDavResourceFactory.java | 106 ++++++------ .../webdav/ArchivaDavResourceFactoryTest.java | 2 +- .../archiva/webdav/DavResourceTest.java | 22 ++- .../UnauthenticatedDavResourceFactory.java | 2 +- .../configuration/StubConfiguration.java | 6 + 28 files changed, 473 insertions(+), 318 deletions(-) delete mode 100644 archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/indexer/GenericIndexManager.java create mode 100644 archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/indexer/merger/BasicIndexMerger.java diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/repository/mock/RepositoryProviderMock.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/repository/mock/RepositoryProviderMock.java index 303fd7653..b4df20d33 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/repository/mock/RepositoryProviderMock.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/repository/mock/RepositoryProviderMock.java @@ -21,10 +21,12 @@ package org.apache.archiva.repository.mock; import org.apache.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.archiva.configuration.RemoteRepositoryConfiguration; +import org.apache.archiva.configuration.RepositoryGroupConfiguration; import org.apache.archiva.repository.BasicManagedRepository; import org.apache.archiva.repository.BasicRemoteRepository; import org.apache.archiva.repository.EditableManagedRepository; import org.apache.archiva.repository.EditableRemoteRepository; +import org.apache.archiva.repository.EditableRepositoryGroup; import org.apache.archiva.repository.ManagedRepository; import org.apache.archiva.repository.PasswordCredentials; import org.apache.archiva.repository.ReleaseScheme; @@ -32,6 +34,7 @@ import org.apache.archiva.repository.RemoteRepository; import org.apache.archiva.repository.RepositoryCredentials; import org.apache.archiva.repository.RepositoryEvent; import org.apache.archiva.repository.RepositoryException; +import org.apache.archiva.repository.RepositoryGroup; import org.apache.archiva.repository.RepositoryProvider; import org.apache.archiva.repository.RepositoryType; import org.apache.archiva.repository.features.ArtifactCleanupFeature; @@ -80,6 +83,13 @@ public class RepositoryProviderMock implements RepositoryProvider return new BasicRemoteRepository( id, name, Paths.get("target/remotes") ); } + @Override + public EditableRepositoryGroup createRepositoryGroup( String id, String name ) + { + + return null; + } + @Override public ManagedRepository createManagedInstance( ManagedRepositoryConfiguration configuration ) throws RepositoryException { @@ -175,6 +185,18 @@ public class RepositoryProviderMock implements RepositoryProvider } + @Override + public RepositoryGroup createRepositoryGroup( RepositoryGroupConfiguration configuration ) throws RepositoryException + { + return null; + } + + @Override + public void updateRepositoryGroupInstance( EditableRepositoryGroup repositoryGroup, RepositoryGroupConfiguration configuration ) throws RepositoryException + { + + } + @Override public ManagedRepositoryConfiguration getManagedConfiguration( ManagedRepository managedRepository ) { @@ -201,6 +223,12 @@ public class RepositoryProviderMock implements RepositoryProvider return configuration; } + @Override + public RepositoryGroupConfiguration getRepositoryGroupConfiguration( RepositoryGroup repositoryGroup ) throws RepositoryException + { + return null; + } + @Override public RemoteRepositoryConfiguration getRemoteConfiguration( RemoteRepository remoteRepository ) diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/group/DefaultRepositoryGroupAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/group/DefaultRepositoryGroupAdmin.java index 41ab30cae..a4b766a54 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/group/DefaultRepositoryGroupAdmin.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/group/DefaultRepositoryGroupAdmin.java @@ -30,6 +30,7 @@ import org.apache.archiva.configuration.RepositoryGroupConfiguration; import org.apache.archiva.metadata.model.facets.AuditEvent; import org.apache.archiva.indexer.merger.MergedRemoteIndexesScheduler; import org.apache.archiva.repository.RepositoryRegistry; +import org.apache.archiva.repository.features.IndexCreationFeature; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -394,7 +395,11 @@ public class DefaultRepositoryGroupAdmin private RepositoryGroup convertRepositoryGroupObject( org.apache.archiva.repository.RepositoryGroup group ) { RepositoryGroup rg = new RepositoryGroup( group.getId( ), group.getRepositories().stream().map(r -> r.getId()).collect( Collectors.toList()) ); - rg.setMergedIndexPath( group.getMergedIndexPath().getPath() ); + if (group.supportsFeature( IndexCreationFeature.class )) + { + IndexCreationFeature indexCreationFeature = group.getFeature( IndexCreationFeature.class ).get(); + rg.setMergedIndexPath( indexCreationFeature.getIndexPath().getPath() ); + } rg.setCronExpression( group.getSchedulingDefinition() ); rg.setMergedIndexTtl( group.getMergedIndexTTL() ); return rg; diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/ArchivaIndexManagerMock.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/ArchivaIndexManagerMock.java index 126f421cb..7a787894e 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/ArchivaIndexManagerMock.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/ArchivaIndexManagerMock.java @@ -40,6 +40,8 @@ import org.apache.archiva.repository.RemoteRepository; import org.apache.archiva.repository.Repository; import org.apache.archiva.repository.RepositoryType; import org.apache.archiva.repository.UnsupportedRepositoryTypeException; +import org.apache.archiva.repository.content.FilesystemAsset; +import org.apache.archiva.repository.content.StorageAsset; import org.apache.archiva.repository.features.IndexCreationFeature; import org.apache.archiva.repository.features.RemoteIndexFeature; import org.apache.commons.lang.StringUtils; @@ -477,7 +479,7 @@ public class ArchivaIndexManagerMock implements ArchivaIndexManager { } if (context.supports(IndexingContext.class)) { try { - Path newPath = getIndexPath(repo); + StorageAsset newPath = getIndexPath(repo); IndexingContext ctx = context.getBaseContext(IndexingContext.class); Path oldPath = ctx.getIndexDirectoryFile().toPath(); if (oldPath.equals(newPath)) { @@ -491,7 +493,7 @@ public class ArchivaIndexManagerMock implements ArchivaIndexManager { return createContext(repo); } else { context.close(false); - Files.move(oldPath, newPath); + Files.move(oldPath, newPath.getFilePath()); return createContext(repo); } } catch (IOException e) { @@ -517,17 +519,22 @@ public class ArchivaIndexManagerMock implements ArchivaIndexManager { } } - private Path getIndexPath(Repository repo) throws IOException { + private StorageAsset getIndexPath( Repository repo) throws IOException { IndexCreationFeature icf = repo.getFeature(IndexCreationFeature.class).get(); Path repoDir = repo.getLocalPath(); URI indexDir = icf.getIndexPath(); + String indexPath = indexDir.getPath(); Path indexDirectory = null; if ( ! StringUtils.isEmpty(indexDir.toString( ) ) ) { indexDirectory = PathUtil.getPathFromUri( indexDir ); // not absolute so create it in repository directory - if ( !indexDirectory.isAbsolute( ) ) + if ( indexDirectory.isAbsolute( ) ) + { + indexPath = indexDirectory.getFileName().toString(); + } + else { indexDirectory = repoDir.resolve( indexDirectory ); } @@ -535,13 +542,14 @@ public class ArchivaIndexManagerMock implements ArchivaIndexManager { else { indexDirectory = repoDir.resolve( ".index" ); + indexPath = ".index"; } if ( !Files.exists( indexDirectory ) ) { Files.createDirectories( indexDirectory ); } - return indexDirectory; + return new FilesystemAsset( indexPath, indexDirectory); } private IndexingContext createRemoteContext(RemoteRepository remoteRepository ) throws IOException @@ -558,7 +566,7 @@ public class ArchivaIndexManagerMock implements ArchivaIndexManager { Files.createDirectories( repoDir ); } - Path indexDirectory = null; + StorageAsset indexDirectory = null; // is there configured indexDirectory ? if ( remoteRepository.supportsFeature( RemoteIndexFeature.class ) ) @@ -577,7 +585,7 @@ public class ArchivaIndexManagerMock implements ArchivaIndexManager { // delete it first then recreate it. log.warn( "the index of repository {} is too old we have to delete and recreate it", // remoteRepository.getId( ) ); - org.apache.archiva.common.utils.FileUtils.deleteDirectory( indexDirectory ); + org.apache.archiva.common.utils.FileUtils.deleteDirectory( indexDirectory.getFilePath() ); return getIndexingContext( remoteRepository, contextKey, repoDir, indexDirectory, remoteIndexUrl ); } @@ -588,9 +596,9 @@ public class ArchivaIndexManagerMock implements ArchivaIndexManager { } } - private IndexingContext getIndexingContext( Repository repository, String contextKey, Path repoDir, Path indexDirectory, String indexUrl ) throws IOException + private IndexingContext getIndexingContext( Repository repository, String contextKey, Path repoDir, StorageAsset indexDirectory, String indexUrl ) throws IOException { - return indexer.createIndexingContext( contextKey, repository.getId( ), repoDir.toFile( ), indexDirectory.toFile( ), + return indexer.createIndexingContext( contextKey, repository.getId( ), repoDir.toFile( ), indexDirectory.getFilePath().toFile( ), repository.getLocation( ) == null ? null : repository.getLocation( ).toString( ), indexUrl, true, false, @@ -616,7 +624,7 @@ public class ArchivaIndexManagerMock implements ArchivaIndexManager { } } - Path indexDirectory = null; + StorageAsset indexDirectory = null; if ( repository.supportsFeature( IndexCreationFeature.class ) ) { @@ -634,7 +642,7 @@ public class ArchivaIndexManagerMock implements ArchivaIndexManager { // delete it first then recreate it. log.warn( "the index of repository {} is too old we have to delete and recreate it", // repository.getId( ) ); - org.apache.archiva.common.utils.FileUtils.deleteDirectory( indexDirectory ); + org.apache.archiva.common.utils.FileUtils.deleteDirectory( indexDirectory.getFilePath() ); context = getIndexingContext( repository, repository.getId( ), repositoryDirectory, indexDirectory, indexUrl ); context.setSearchable( repository.isScanned( ) ); } diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/MockMergedRemoteIndexesScheduler.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/MockMergedRemoteIndexesScheduler.java index 6cd910c2d..4cb8ca78d 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/MockMergedRemoteIndexesScheduler.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/MockMergedRemoteIndexesScheduler.java @@ -19,8 +19,8 @@ package org.apache.archiva.admin.mock; * under the License. */ -import org.apache.archiva.admin.model.beans.RepositoryGroup; import org.apache.archiva.indexer.merger.MergedRemoteIndexesScheduler; +import org.apache.archiva.repository.RepositoryGroup; import org.springframework.stereotype.Service; import java.nio.file.Path; diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/indexer/GenericIndexManager.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/indexer/GenericIndexManager.java deleted file mode 100644 index 9ec3f9081..000000000 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/indexer/GenericIndexManager.java +++ /dev/null @@ -1,128 +0,0 @@ -package org.apache.archiva.indexer; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.archiva.common.utils.PathUtil; -import org.apache.archiva.repository.Repository; -import org.apache.archiva.repository.RepositoryType; -import org.apache.archiva.repository.features.IndexCreationFeature; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Service; - -import java.io.IOException; -import java.net.URI; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Collection; - -@Service("indexManager#none") -public class GenericIndexManager implements ArchivaIndexManager { - - private final Logger log = LoggerFactory.getLogger(GenericIndexManager.class); - - public static final String DEFAULT_INDEXER_DIR = ".indexer"; - - @Override - public void pack(ArchivaIndexingContext context) { - - } - - @Override - public void scan(ArchivaIndexingContext context) { - - } - - @Override - public void update(ArchivaIndexingContext context, boolean fullUpdate) { - - } - - @Override - public void addArtifactsToIndex(ArchivaIndexingContext context, Collection artifactReference) { - - } - - @Override - public void removeArtifactsFromIndex(ArchivaIndexingContext context, Collection artifactReference) { - - } - - @Override - public boolean supportsRepository(RepositoryType type) { - return false; - } - - @Override - public ArchivaIndexingContext createContext(Repository repository) { - return null; - } - - @Override - public ArchivaIndexingContext reset(ArchivaIndexingContext context) throws IndexUpdateFailedException { - return null; - } - - @Override - public ArchivaIndexingContext move(ArchivaIndexingContext context, Repository repo) throws IndexCreationFailedException { - return null; - } - - @Override - public void updateLocalIndexPath(Repository repo) { - if (repo.supportsFeature(IndexCreationFeature.class)) { - IndexCreationFeature icf = repo.getFeature(IndexCreationFeature.class).get(); - try { - icf.setLocalIndexPath(getIndexPath(repo)); - } catch (IOException e) { - log.error("Could not set local index path for {}. New URI: {}", repo.getId(), icf.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; - } - -} diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/EditableRepositoryGroup.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/EditableRepositoryGroup.java index dff3dc85d..60e955bac 100644 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/EditableRepositoryGroup.java +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/EditableRepositoryGroup.java @@ -35,7 +35,5 @@ public interface EditableRepositoryGroup extends EditableRepository,RepositoryGr ManagedRepository removeRepository(String repoId); - void setMergedIndexPath(String path); - void setMergedIndexTTL(int timeInSeconds); } diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RelocatablePath.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RelocatablePath.java index 055abe48b..aa200c4e5 100644 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RelocatablePath.java +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RelocatablePath.java @@ -1,4 +1,22 @@ package org.apache.archiva.repository; +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ /** * @author Martin Stockhammer diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryGroup.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryGroup.java index 93b368c1d..8386c5838 100644 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryGroup.java +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryGroup.java @@ -63,12 +63,6 @@ public interface RepositoryGroup extends Repository, RepositoryStorage { */ boolean contains(String id); - /** - * Returns the path to the merged index - * @return - */ - StorageAsset getMergedIndexPath(); - /** * Returns the time to live in seconds for the merged index. * diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RequestPathMapper.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RequestPathMapper.java index d06615fba..e438b44ce 100644 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RequestPathMapper.java +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RequestPathMapper.java @@ -1,4 +1,22 @@ package org.apache.archiva.repository; +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ /** * diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/features/IndexCreationFeature.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/features/IndexCreationFeature.java index 5e68fdd5d..d22f1dfe0 100644 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/features/IndexCreationFeature.java +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/features/IndexCreationFeature.java @@ -22,6 +22,7 @@ package org.apache.archiva.repository.features; import org.apache.archiva.repository.Repository; import org.apache.archiva.repository.RepositoryEventListener; +import org.apache.archiva.repository.content.StorageAsset; import org.apache.commons.lang.StringUtils; import java.net.URI; @@ -44,9 +45,9 @@ public class IndexCreationFeature extends AbstractFeature implements RepositoryF private URI packedIndexPath; - private Path localIndexPath; + private StorageAsset localIndexPath; - private Path localPackedIndexPath; + private StorageAsset localPackedIndexPath; private Repository repo; @@ -126,7 +127,7 @@ public class IndexCreationFeature extends AbstractFeature implements RepositoryF * * @return */ - public Path getLocalIndexPath() { + public StorageAsset getLocalIndexPath() { return localIndexPath; } @@ -136,7 +137,7 @@ public class IndexCreationFeature extends AbstractFeature implements RepositoryF * * @param localIndexPath */ - public void setLocalIndexPath(Path localIndexPath) { + public void setLocalIndexPath(StorageAsset localIndexPath) { this.localIndexPath = localIndexPath; } @@ -163,7 +164,7 @@ public class IndexCreationFeature extends AbstractFeature implements RepositoryF * Returns the directory where the packed index is stored. * @return */ - public Path getLocalPackedIndexPath() { + public StorageAsset getLocalPackedIndexPath() { return localPackedIndexPath; } @@ -173,7 +174,7 @@ public class IndexCreationFeature extends AbstractFeature implements RepositoryF * * @param localPackedIndexPath */ - public void setLocalPackedIndexPath(Path localPackedIndexPath) { + public void setLocalPackedIndexPath(StorageAsset localPackedIndexPath) { this.localPackedIndexPath = localPackedIndexPath; } diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/indexer/merger/BasicIndexMerger.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/indexer/merger/BasicIndexMerger.java new file mode 100644 index 000000000..8df80d7ac --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/indexer/merger/BasicIndexMerger.java @@ -0,0 +1,156 @@ +package org.apache.archiva.indexer.merger; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.common.utils.FileUtils; +import org.apache.archiva.indexer.ArchivaIndexingContext; +import org.apache.archiva.repository.RepositoryRegistry; +import org.apache.commons.lang.time.StopWatch; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.scheduling.annotation.Async; + +import javax.inject.Inject; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Collection; +import java.util.List; +import java.util.Objects; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.stream.Collectors; + +/** + * @author Martin Stockhammer + */ +public class BasicIndexMerger implements IndexMerger +{ + @Inject + RepositoryRegistry repositoryRegistry; + + private Logger log = LoggerFactory.getLogger( getClass() ); + + + private List temporaryGroupIndexes = new CopyOnWriteArrayList<>(); + + private List runningGroups = new CopyOnWriteArrayList<>(); + + @Inject + public BasicIndexMerger( ) + { + } + + @Override + public ArchivaIndexingContext buildMergedIndex( IndexMergerRequest indexMergerRequest ) + throws IndexMergerException + { + String groupId = indexMergerRequest.getGroupId(); + + if ( runningGroups.contains( groupId ) ) + { + log.info( "skip build merge remote indexes for id: '{}' as already running", groupId ); + return null; + } + + runningGroups.add( groupId ); + + StopWatch stopWatch = new StopWatch(); + stopWatch.reset(); + stopWatch.start(); + + Path mergedIndexDirectory = indexMergerRequest.getMergedIndexDirectory(); + + String tempRepoId = mergedIndexDirectory.getFileName().toString(); + + try + { + Path indexLocation = mergedIndexDirectory.resolve( indexMergerRequest.getMergedIndexPath() ); + + List members = indexMergerRequest.getRepositoriesIds( ).stream( ).map( id -> + repositoryRegistry.getRepository( id ) ) + .map( repo -> repo.getIndexingContext() ).filter( Objects::nonNull ).collect( Collectors.toList() ); + + members.get( 0 ). + if ( indexMergerRequest.isPackIndex() ) + { + IndexPackingRequest request = new IndexPackingRequest( mergedCtx, // + mergedCtx.acquireIndexSearcher().getIndexReader(), // + indexLocation.toFile() ); + indexPacker.packIndex( request ); + } + + if ( indexMergerRequest.isTemporary() ) + { + temporaryGroupIndexes.add( new TemporaryGroupIndex( mergedIndexDirectory, tempRepoId, groupId, + indexMergerRequest.getMergedIndexTtl() ) ); + } + stopWatch.stop(); + log.info( "merged index for repos {} in {} s", indexMergerRequest.getRepositoriesIds(), + stopWatch.getTime() ); + return new MavenIndexContext(repositoryRegistry.getRepositoryGroup(groupId), mergedCtx); + } + catch ( IOException e) + { + throw new IndexMergerException( e.getMessage(), e ); + } + finally + { + runningGroups.remove( groupId ); + } + } + + @Async + @Override + public void cleanTemporaryGroupIndex( TemporaryGroupIndex temporaryGroupIndex ) + { + if ( temporaryGroupIndex == null ) + { + return; + } + + try + { + + Optional ctxOpt = temporaryContextes.stream( ).filter( ctx -> ctx.getId( ).equals( temporaryGroupIndex.getIndexId( ) ) ).findFirst( ); + if (ctxOpt.isPresent()) { + IndexingContext ctx = ctxOpt.get(); + indexer.closeIndexingContext( ctx, true ); + temporaryGroupIndexes.remove( temporaryGroupIndex ); + temporaryContextes.remove( ctx ); + Path directory = temporaryGroupIndex.getDirectory(); + if ( directory != null && Files.exists(directory) ) + { + FileUtils.deleteDirectory( directory ); + } + } + } + catch ( IOException e ) + { + log.warn( "fail to delete temporary group index {}", temporaryGroupIndex.getIndexId(), e ); + } + } + + @Override + public Collection getTemporaryGroupIndexes() + { + return this.temporaryGroupIndexes; + } + +} diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/indexer/merger/DefaultMergedRemoteIndexesScheduler.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/indexer/merger/DefaultMergedRemoteIndexesScheduler.java index fb762b653..b2be61184 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/indexer/merger/DefaultMergedRemoteIndexesScheduler.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/indexer/merger/DefaultMergedRemoteIndexesScheduler.java @@ -21,6 +21,7 @@ package org.apache.archiva.indexer.merger; import org.apache.archiva.repository.ManagedRepository; import org.apache.archiva.repository.RepositoryGroup; +import org.apache.archiva.repository.features.IndexCreationFeature; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -68,20 +69,33 @@ public class DefaultMergedRemoteIndexesScheduler List repositories = repositoryGroup.getRepositories(); - IndexMergerRequest indexMergerRequest = - new IndexMergerRequest( repositories.stream().map(r -> r.getId()).collect(Collectors.toList()), true, repositoryGroup.getId(), - repositoryGroup.getMergedIndexPath().getFilePath().toString(), - repositoryGroup.getMergedIndexTTL() ).mergedIndexDirectory( directory ); + if (repositoryGroup.supportsFeature( IndexCreationFeature.class )) + { + + IndexCreationFeature indexCreationFeature = repositoryGroup.getFeature( IndexCreationFeature.class ).get(); + Path indexPath = indexCreationFeature.getLocalIndexPath().getFilePath(); + if (indexPath!=null) + { + IndexMergerRequest indexMergerRequest = + new IndexMergerRequest( repositories.stream( ).map( r -> r.getId( ) ).collect( Collectors.toList( ) ), true, repositoryGroup.getId( ), + indexPath.toString( ), + repositoryGroup.getMergedIndexTTL( ) ).mergedIndexDirectory( directory ); - MergedRemoteIndexesTaskRequest taskRequest = - new MergedRemoteIndexesTaskRequest( indexMergerRequest, indexMerger ); + MergedRemoteIndexesTaskRequest taskRequest = + new MergedRemoteIndexesTaskRequest( indexMergerRequest, indexMerger ); - logger.info( "schedule merge remote index for group {} with cron {}", repositoryGroup.getId(), - repositoryGroup.getSchedulingDefinition() ); + logger.info( "schedule merge remote index for group {} with cron {}", repositoryGroup.getId( ), + repositoryGroup.getSchedulingDefinition( ) ); - ScheduledFuture scheduledFuture = - taskScheduler.schedule( new MergedRemoteIndexesTask( taskRequest ), cronTrigger ); - scheduledFutureMap.put( repositoryGroup.getId(), scheduledFuture ); + ScheduledFuture scheduledFuture = + taskScheduler.schedule( new MergedRemoteIndexesTask( taskRequest ), cronTrigger ); + scheduledFutureMap.put( repositoryGroup.getId( ), scheduledFuture ); + } else { + logger.error("Requested index merger for repository group {} with non local index path {}", repositoryGroup.getId(), indexCreationFeature.getLocalIndexPath()); + } + } else { + logger.error("Scheduling merged index for repository group {}, but it does not support IndexCreationFeature.", repositoryGroup.getId()); + } } @Override diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractRepositoryGroup.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractRepositoryGroup.java index 11be643bb..1fb61f540 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractRepositoryGroup.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractRepositoryGroup.java @@ -40,8 +40,6 @@ public class AbstractRepositoryGroup extends AbstractRepository implements Edita private ListOrderedMap repositories = new ListOrderedMap<>(); - private String mergedIndexPath; - private int mergedIndexTTL; private final ReadWriteLock rwl = new ReentrantReadWriteLock(); @@ -132,11 +130,6 @@ public class AbstractRepositoryGroup extends AbstractRepository implements Edita } } - @Override - public void setMergedIndexPath(String path) { - this.mergedIndexPath = path; - } - @Override public void setMergedIndexTTL(int timeInSeconds) { this.mergedIndexTTL = timeInSeconds; @@ -172,11 +165,6 @@ public class AbstractRepositoryGroup extends AbstractRepository implements Edita } } - @Override - public StorageAsset getMergedIndexPath() { - return storage.getAsset(mergedIndexPath); - } - @Override public int getMergedIndexTTL() { return mergedIndexTTL; diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/resources/spring-context.xml b/archiva-modules/archiva-base/archiva-repository-layer/src/test/resources/spring-context.xml index 4c58e4d8c..1d41a6ed4 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/test/resources/spring-context.xml +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/resources/spring-context.xml @@ -47,4 +47,11 @@ + + + + + + \ No newline at end of file diff --git a/archiva-modules/archiva-maven/archiva-maven-indexer/src/main/java/org/apache/archiva/indexer/maven/DefaultIndexMerger.java b/archiva-modules/archiva-maven/archiva-maven-indexer/src/main/java/org/apache/archiva/indexer/maven/DefaultIndexMerger.java index e41834136..12607ce4c 100644 --- a/archiva-modules/archiva-maven/archiva-maven-indexer/src/main/java/org/apache/archiva/indexer/maven/DefaultIndexMerger.java +++ b/archiva-modules/archiva-maven/archiva-maven-indexer/src/main/java/org/apache/archiva/indexer/maven/DefaultIndexMerger.java @@ -21,7 +21,6 @@ package org.apache.archiva.indexer.maven; import org.apache.archiva.common.utils.FileUtils; import org.apache.archiva.indexer.ArchivaIndexingContext; import org.apache.archiva.indexer.UnsupportedBaseContextException; -import org.apache.archiva.indexer.maven.MavenIndexContext; import org.apache.archiva.indexer.merger.IndexMerger; import org.apache.archiva.indexer.merger.IndexMergerException; import org.apache.archiva.indexer.merger.IndexMergerRequest; diff --git a/archiva-modules/archiva-maven/archiva-maven-indexer/src/main/java/org/apache/archiva/indexer/maven/MavenIndexManager.java b/archiva-modules/archiva-maven/archiva-maven-indexer/src/main/java/org/apache/archiva/indexer/maven/MavenIndexManager.java index 375f726eb..f75ebcf46 100644 --- a/archiva-modules/archiva-maven/archiva-maven-indexer/src/main/java/org/apache/archiva/indexer/maven/MavenIndexManager.java +++ b/archiva-modules/archiva-maven/archiva-maven-indexer/src/main/java/org/apache/archiva/indexer/maven/MavenIndexManager.java @@ -40,6 +40,8 @@ import org.apache.archiva.repository.RemoteRepository; import org.apache.archiva.repository.Repository; import org.apache.archiva.repository.RepositoryType; import org.apache.archiva.repository.UnsupportedRepositoryTypeException; +import org.apache.archiva.repository.content.FilesystemAsset; +import org.apache.archiva.repository.content.StorageAsset; import org.apache.archiva.repository.features.IndexCreationFeature; import org.apache.archiva.repository.features.RemoteIndexFeature; import org.apache.commons.lang.StringUtils; @@ -492,7 +494,7 @@ public class MavenIndexManager implements ArchivaIndexManager { } if (context.supports(IndexingContext.class)) { try { - Path newPath = getIndexPath(repo); + StorageAsset newPath = getIndexPath(repo); IndexingContext ctx = context.getBaseContext(IndexingContext.class); Path oldPath = ctx.getIndexDirectoryFile().toPath(); if (oldPath.equals(newPath)) { @@ -506,7 +508,7 @@ public class MavenIndexManager implements ArchivaIndexManager { return createContext(repo); } else { context.close(false); - Files.move(oldPath, newPath); + Files.move(oldPath, newPath.getFilePath()); return createContext(repo); } } catch (IOException e) { @@ -533,58 +535,45 @@ public class MavenIndexManager implements ArchivaIndexManager { } } - private Path getIndexPath(Repository repo) throws IOException { - IndexCreationFeature icf = repo.getFeature(IndexCreationFeature.class).get(); - Path repoDir = repo.getLocalPath(); - URI indexDir = icf.getIndexPath(); + private StorageAsset getIndexPath(URI indexDir, Path repoDir, String defaultDir) throws IOException + { + String indexPath = indexDir.getPath(); Path indexDirectory = null; if ( ! StringUtils.isEmpty(indexDir.toString( ) ) ) { indexDirectory = PathUtil.getPathFromUri( indexDir ); // not absolute so create it in repository directory - if ( !indexDirectory.isAbsolute( ) ) + if ( indexDirectory.isAbsolute( ) ) + { + indexPath = indexDirectory.getFileName().toString(); + } + else { indexDirectory = repoDir.resolve( indexDirectory ); } } else { - indexDirectory = repoDir.resolve( DEFAULT_INDEXER_DIR ); + indexDirectory = repoDir.resolve( defaultDir ); + indexPath = defaultDir; } if ( !Files.exists( indexDirectory ) ) { Files.createDirectories( indexDirectory ); } - return indexDirectory; + return new FilesystemAsset( indexPath, indexDirectory); } - private Path getPackedIndexPath(Repository repo) throws IOException { + private StorageAsset getIndexPath( Repository repo) throws IOException { IndexCreationFeature icf = repo.getFeature(IndexCreationFeature.class).get(); - Path repoDir = repo.getLocalPath(); - URI indexDir = icf.getPackedIndexPath(); - 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_PACKED_INDEX_DIR ); - } + return getIndexPath( icf.getIndexPath(), repo.getLocalPath(), DEFAULT_INDEXER_DIR ); + } - if ( !Files.exists( indexDirectory ) ) - { - Files.createDirectories( indexDirectory ); - } - return indexDirectory; + private StorageAsset getPackedIndexPath(Repository repo) throws IOException { + IndexCreationFeature icf = repo.getFeature(IndexCreationFeature.class).get(); + return getIndexPath(icf.getPackedIndexPath(), repo.getLocalPath(), DEFAULT_PACKED_INDEX_DIR); } private IndexingContext createRemoteContext(RemoteRepository remoteRepository ) throws IOException @@ -601,7 +590,7 @@ public class MavenIndexManager implements ArchivaIndexManager { Files.createDirectories( repoDir ); } - Path indexDirectory = null; + StorageAsset indexDirectory = null; // is there configured indexDirectory ? if ( remoteRepository.supportsFeature( RemoteIndexFeature.class ) ) @@ -620,7 +609,7 @@ public class MavenIndexManager implements ArchivaIndexManager { // delete it first then recreate it. log.warn( "the index of repository {} is too old we have to delete and recreate it", // remoteRepository.getId( ) ); - org.apache.archiva.common.utils.FileUtils.deleteDirectory( indexDirectory ); + org.apache.archiva.common.utils.FileUtils.deleteDirectory( indexDirectory.getFilePath() ); return getIndexingContext( remoteRepository, contextKey, repoDir, indexDirectory, remoteIndexUrl ); } @@ -631,9 +620,9 @@ public class MavenIndexManager implements ArchivaIndexManager { } } - private IndexingContext getIndexingContext( Repository repository, String contextKey, Path repoDir, Path indexDirectory, String indexUrl ) throws IOException + private IndexingContext getIndexingContext( Repository repository, String contextKey, Path repoDir, StorageAsset indexDirectory, String indexUrl ) throws IOException { - return indexer.createIndexingContext( contextKey, repository.getId( ), repoDir.toFile( ), indexDirectory.toFile( ), + return indexer.createIndexingContext( contextKey, repository.getId( ), repoDir.toFile( ), indexDirectory.getFilePath().toFile( ), repository.getLocation( ) == null ? null : repository.getLocation( ).toString( ), indexUrl, true, false, @@ -659,7 +648,7 @@ public class MavenIndexManager implements ArchivaIndexManager { } } - Path indexDirectory = null; + StorageAsset indexDirectory = null; if ( repository.supportsFeature( IndexCreationFeature.class ) ) { @@ -677,7 +666,7 @@ public class MavenIndexManager implements ArchivaIndexManager { // delete it first then recreate it. log.warn( "the index of repository {} is too old we have to delete and recreate it", // repository.getId( ) ); - org.apache.archiva.common.utils.FileUtils.deleteDirectory( indexDirectory ); + org.apache.archiva.common.utils.FileUtils.deleteDirectory( indexDirectory.getFilePath() ); context = getIndexingContext( repository, repository.getId( ), repositoryDirectory, indexDirectory, indexUrl ); context.setSearchable( repository.isScanned( ) ); } diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryGroup.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryGroup.java index 24c0b958d..094d18275 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryGroup.java +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryGroup.java @@ -22,6 +22,7 @@ package org.apache.archiva.repository.maven2; import org.apache.archiva.common.filelock.FileLockManager; import org.apache.archiva.repository.*; import org.apache.archiva.repository.content.FilesystemStorage; +import org.apache.archiva.repository.features.IndexCreationFeature; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -36,7 +37,7 @@ public class MavenRepositoryGroup extends AbstractRepositoryGroup implements Edi new ReleaseScheme[] { ReleaseScheme.RELEASE, ReleaseScheme.SNAPSHOT }, new String[] { MavenManagedRepository.DEFAULT_LAYOUT, MavenManagedRepository.LEGACY_LAYOUT}, new String[] {}, - new String[] {}, + new String[] {IndexCreationFeature.class.getName()}, false, false, false, @@ -48,6 +49,8 @@ public class MavenRepositoryGroup extends AbstractRepositoryGroup implements Edi private FileLockManager lockManager; private FilesystemStorage fsStorage; + private IndexCreationFeature indexCreationFeature; + public MavenRepositoryGroup(String id, String name, Path repositoryBase, FileLockManager lockManager) { super(RepositoryType.MAVEN, id, name, repositoryBase); @@ -78,5 +81,7 @@ public class MavenRepositoryGroup extends AbstractRepositoryGroup implements Edi throw new RuntimeException("Fatal error while accessing repository path "+ getRepositoryBase(), e); } setStorage(fsStorage); + this.indexCreationFeature = new IndexCreationFeature(this, this); + addFeature( this.indexCreationFeature ); } } diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryProvider.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryProvider.java index f04602636..0584dee2e 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryProvider.java +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryProvider.java @@ -22,6 +22,7 @@ package org.apache.archiva.repository.maven2; import org.apache.archiva.common.filelock.FileLockManager; import org.apache.archiva.configuration.*; import org.apache.archiva.repository.*; +import org.apache.archiva.repository.content.FilesystemAsset; import org.apache.archiva.repository.features.ArtifactCleanupFeature; import org.apache.archiva.repository.features.IndexCreationFeature; import org.apache.archiva.repository.features.RemoteIndexFeature; @@ -252,9 +253,26 @@ public class MavenRepositoryProvider implements RepositoryProvider { @Override public void updateRepositoryGroupInstance(EditableRepositoryGroup repositoryGroup, RepositoryGroupConfiguration configuration) throws RepositoryException { repositoryGroup.setName(repositoryGroup.getPrimaryLocale(), configuration.getName()); - repositoryGroup.setMergedIndexPath(configuration.getMergedIndexPath()); repositoryGroup.setMergedIndexTTL(configuration.getMergedIndexTtl()); repositoryGroup.setSchedulingDefinition(configuration.getCronExpression()); + if (repositoryGroup.supportsFeature( IndexCreationFeature.class )) { + IndexCreationFeature indexCreationFeature = repositoryGroup.getFeature( IndexCreationFeature.class ).get(); + try + { + indexCreationFeature.setIndexPath( new URI(configuration.getMergedIndexPath()) ); + Path localPath = Paths.get(indexCreationFeature.getIndexPath()); + if (localPath.isAbsolute()) { + indexCreationFeature.setLocalIndexPath( new FilesystemAsset(localPath.getFileName().toString(), localPath) ); + } else + { + indexCreationFeature.setLocalIndexPath( new FilesystemAsset(localPath.toString(), archivaConfiguration.getRepositoryGroupBaseDir( ).resolve( localPath ))); + } + } + catch ( URISyntaxException e ) + { + log.error("Could not set the index path for repository group {}", repositoryGroup.getId()); + } + } // References to other repositories are set filled by the registry } @@ -351,7 +369,12 @@ public class MavenRepositoryProvider implements RepositoryProvider { RepositoryGroupConfiguration cfg = new RepositoryGroupConfiguration(); cfg.setId(repositoryGroup.getId()); cfg.setName(repositoryGroup.getName()); - cfg.setMergedIndexPath(repositoryGroup.getMergedIndexPath().getPath()); + if (repositoryGroup.supportsFeature( IndexCreationFeature.class )) + { + IndexCreationFeature indexCreationFeature = repositoryGroup.getFeature( IndexCreationFeature.class ).get(); + + cfg.setMergedIndexPath( indexCreationFeature.getIndexPath().toString() ); + } cfg.setMergedIndexTtl(repositoryGroup.getMergedIndexTTL()); cfg.setRepositories(repositoryGroup.getRepositories().stream().map(r -> r.getId()).collect(Collectors.toList())); cfg.setCronExpression(repositoryGroup.getSchedulingDefinition()); diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/index/mock/ArchivaIndexManagerMock.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/index/mock/ArchivaIndexManagerMock.java index de3ea76a1..902199d53 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/index/mock/ArchivaIndexManagerMock.java +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/index/mock/ArchivaIndexManagerMock.java @@ -40,6 +40,8 @@ import org.apache.archiva.repository.RemoteRepository; import org.apache.archiva.repository.Repository; import org.apache.archiva.repository.RepositoryType; import org.apache.archiva.repository.UnsupportedRepositoryTypeException; +import org.apache.archiva.repository.content.FilesystemAsset; +import org.apache.archiva.repository.content.StorageAsset; import org.apache.archiva.repository.features.IndexCreationFeature; import org.apache.archiva.repository.features.RemoteIndexFeature; import org.apache.commons.lang.StringUtils; @@ -479,7 +481,7 @@ public class ArchivaIndexManagerMock implements ArchivaIndexManager { } if (context.supports(IndexingContext.class)) { try { - Path newPath = getIndexPath(repo); + StorageAsset newPath = getIndexPath(repo); IndexingContext ctx = context.getBaseContext(IndexingContext.class); Path oldPath = ctx.getIndexDirectoryFile().toPath(); if (oldPath.equals(newPath)) { @@ -493,7 +495,7 @@ public class ArchivaIndexManagerMock implements ArchivaIndexManager { return createContext(repo); } else { context.close(false); - Files.move(oldPath, newPath); + Files.move(oldPath, newPath.getFilePath()); return createContext(repo); } } catch (IOException e) { @@ -520,17 +522,22 @@ public class ArchivaIndexManagerMock implements ArchivaIndexManager { } - private Path getIndexPath(Repository repo) throws IOException { + private StorageAsset getIndexPath( Repository repo) throws IOException { IndexCreationFeature icf = repo.getFeature(IndexCreationFeature.class).get(); Path repoDir = repo.getLocalPath(); URI indexDir = icf.getIndexPath(); + String indexPath = indexDir.getPath(); Path indexDirectory = null; if ( ! StringUtils.isEmpty(indexDir.toString( ) ) ) { indexDirectory = PathUtil.getPathFromUri( indexDir ); // not absolute so create it in repository directory - if ( !indexDirectory.isAbsolute( ) ) + if ( indexDirectory.isAbsolute( ) ) + { + indexPath = indexDirectory.getFileName().toString(); + } + else { indexDirectory = repoDir.resolve( indexDirectory ); } @@ -538,13 +545,14 @@ public class ArchivaIndexManagerMock implements ArchivaIndexManager { else { indexDirectory = repoDir.resolve( ".index" ); + indexPath = ".index"; } if ( !Files.exists( indexDirectory ) ) { Files.createDirectories( indexDirectory ); } - return indexDirectory; + return new FilesystemAsset( indexPath, indexDirectory ); } private IndexingContext createRemoteContext(RemoteRepository remoteRepository ) throws IOException @@ -561,7 +569,7 @@ public class ArchivaIndexManagerMock implements ArchivaIndexManager { Files.createDirectories( repoDir ); } - Path indexDirectory = null; + StorageAsset indexDirectory = null; // is there configured indexDirectory ? if ( remoteRepository.supportsFeature( RemoteIndexFeature.class ) ) @@ -580,7 +588,7 @@ public class ArchivaIndexManagerMock implements ArchivaIndexManager { // delete it first then recreate it. log.warn( "the index of repository {} is too old we have to delete and recreate it", // remoteRepository.getId( ) ); - org.apache.archiva.common.utils.FileUtils.deleteDirectory( indexDirectory ); + org.apache.archiva.common.utils.FileUtils.deleteDirectory( indexDirectory.getFilePath() ); return getIndexingContext( remoteRepository, contextKey, repoDir, indexDirectory, remoteIndexUrl ); } @@ -591,9 +599,9 @@ public class ArchivaIndexManagerMock implements ArchivaIndexManager { } } - private IndexingContext getIndexingContext( Repository repository, String contextKey, Path repoDir, Path indexDirectory, String indexUrl ) throws IOException + private IndexingContext getIndexingContext( Repository repository, String contextKey, Path repoDir, StorageAsset indexDirectory, String indexUrl ) throws IOException { - return indexer.createIndexingContext( contextKey, repository.getId( ), repoDir.toFile( ), indexDirectory.toFile( ), + return indexer.createIndexingContext( contextKey, repository.getId( ), repoDir.toFile( ), indexDirectory.getFilePath().toFile( ), repository.getLocation( ) == null ? null : repository.getLocation( ).toString( ), indexUrl, true, false, @@ -619,7 +627,7 @@ public class ArchivaIndexManagerMock implements ArchivaIndexManager { } } - Path indexDirectory = null; + StorageAsset indexDirectory = null; if ( repository.supportsFeature( IndexCreationFeature.class ) ) { @@ -637,7 +645,7 @@ public class ArchivaIndexManagerMock implements ArchivaIndexManager { // delete it first then recreate it. log.warn( "the index of repository {} is too old we have to delete and recreate it", // repository.getId( ) ); - org.apache.archiva.common.utils.FileUtils.deleteDirectory( indexDirectory ); + org.apache.archiva.common.utils.FileUtils.deleteDirectory( indexDirectory.getFilePath() ); context = getIndexingContext( repository, repository.getId( ), repositoryDirectory, indexDirectory, indexUrl ); context.setSearchable( repository.isScanned( ) ); } diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven2/MavenRepositoryProviderTest.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven2/MavenRepositoryProviderTest.java index 8511b9991..4280100a6 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven2/MavenRepositoryProviderTest.java +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven2/MavenRepositoryProviderTest.java @@ -37,6 +37,7 @@ import org.junit.Before; import org.junit.Test; import java.net.URI; +import java.net.URISyntaxException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -295,7 +296,8 @@ public class MavenRepositoryProviderTest } @Test - public void getRepositoryGroupConfiguration() throws RepositoryException { + public void getRepositoryGroupConfiguration() throws RepositoryException, URISyntaxException + { MavenRepositoryGroup repositoryGroup = new MavenRepositoryGroup("group1","group1",Paths.get("target/groups"), new DefaultFileLockManager()); MavenManagedRepository repo1 = new MavenManagedRepository( "test01", "My Test repo", Paths.get("target/repositories") ); @@ -304,7 +306,8 @@ public class MavenRepositoryProviderTest repositoryGroup.setDescription(repositoryGroup.getPrimaryLocale(), "Repository group"); repositoryGroup.setLayout("non-default"); - repositoryGroup.setMergedIndexPath(".index2"); + IndexCreationFeature indexCreationFeature = repositoryGroup.getFeature( IndexCreationFeature.class ).get(); + indexCreationFeature.setIndexPath( new URI(".index2") ); repositoryGroup.setName(repositoryGroup.getPrimaryLocale(), "Repo Group 1"); repositoryGroup.setMergedIndexTTL(1005); repositoryGroup.setSchedulingDefinition("0 0 04 ? * THU"); @@ -351,7 +354,8 @@ public class MavenRepositoryProviderTest assertEquals("group2", grp.getId()); assertEquals("Group 2", grp.getName()); assertEquals("0 0 03 ? * MON", grp.getSchedulingDefinition()); - assertEquals(".index-abc", grp.getMergedIndexPath().getName()); + IndexCreationFeature indexCreationFeature = grp.getFeature( IndexCreationFeature.class ).get(); + assertEquals(".index-abc", indexCreationFeature.getIndexPath()); assertEquals(504, grp.getMergedIndexTTL()); assertEquals(0, grp.getRepositories().size()); // assertTrue(grp.getRepositories().stream().anyMatch(r -> "test01".equals(r.getId()))); diff --git a/archiva-modules/archiva-maven/archiva-maven-scheduler/src/main/java/org/apache/archiva/scheduler/indexing/maven/ArchivaIndexingTaskExecutor.java b/archiva-modules/archiva-maven/archiva-maven-scheduler/src/main/java/org/apache/archiva/scheduler/indexing/maven/ArchivaIndexingTaskExecutor.java index 8192cce2b..ea88d8f3d 100644 --- a/archiva-modules/archiva-maven/archiva-maven-scheduler/src/main/java/org/apache/archiva/scheduler/indexing/maven/ArchivaIndexingTaskExecutor.java +++ b/archiva-modules/archiva-maven/archiva-maven-scheduler/src/main/java/org/apache/archiva/scheduler/indexing/maven/ArchivaIndexingTaskExecutor.java @@ -262,14 +262,14 @@ public class ArchivaIndexingTaskExecutor if ( repository.supportsFeature( IndexCreationFeature.class ) ) { IndexCreationFeature icf = repository.getFeature( IndexCreationFeature.class ).get( ); - if ( !icf.isSkipPackedIndexCreation( ) && icf.getLocalPackedIndexPath( ) != null ) + if ( !icf.isSkipPackedIndexCreation( ) && icf.getLocalPackedIndexPath( ) != null && icf.getLocalIndexPath().getFilePath()!=null ) { log.debug( "Creating packed index from {} on {}", context.getIndexDirectoryFile( ), icf.getLocalPackedIndexPath( ) ); IndexPackingRequest request = new IndexPackingRequest( context, // context.acquireIndexSearcher( ).getIndexReader( ), // - icf.getLocalPackedIndexPath( ).toFile( ) ); + icf.getLocalPackedIndexPath( ).getFilePath().toFile( ) ); indexPacker.packIndex( request ); context.updateTimestamp( true ); diff --git a/archiva-modules/archiva-maven/archiva-maven-scheduler/src/test/java/org/apache/archiva/scheduler/indexing/maven/ArchivaIndexingTaskExecutorTest.java b/archiva-modules/archiva-maven/archiva-maven-scheduler/src/test/java/org/apache/archiva/scheduler/indexing/maven/ArchivaIndexingTaskExecutorTest.java index 758568ba9..a8ace80c1 100644 --- a/archiva-modules/archiva-maven/archiva-maven-scheduler/src/test/java/org/apache/archiva/scheduler/indexing/maven/ArchivaIndexingTaskExecutorTest.java +++ b/archiva-modules/archiva-maven/archiva-maven-scheduler/src/test/java/org/apache/archiva/scheduler/indexing/maven/ArchivaIndexingTaskExecutorTest.java @@ -26,6 +26,7 @@ import org.apache.archiva.repository.BasicManagedRepository; import org.apache.archiva.repository.ManagedRepository; import org.apache.archiva.repository.ReleaseScheme; import org.apache.archiva.repository.RepositoryRegistry; +import org.apache.archiva.repository.content.StorageAsset; import org.apache.archiva.repository.features.IndexCreationFeature; import org.apache.archiva.scheduler.indexing.ArtifactIndexingTask; import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; @@ -275,20 +276,27 @@ public class ArchivaIndexingTaskExecutorTest Path basePath = repo.getLocalPath(); IndexCreationFeature icf = repo.getFeature( IndexCreationFeature.class ).get(); - Path packedIndexDirectory = icf.getLocalPackedIndexPath(); - Path indexerDirectory = icf.getLocalIndexPath(); - - for (Path dir : new Path[] { packedIndexDirectory, indexerDirectory }) { - Files.list(dir).filter(path -> path.getFileName().toString().startsWith("nexus-maven-repository-index")) - .forEach(path -> + StorageAsset packedIndexDirectory = icf.getLocalPackedIndexPath(); + StorageAsset indexerDirectory = icf.getLocalIndexPath(); + + for (StorageAsset dir : new StorageAsset[] { packedIndexDirectory, indexerDirectory }) { + if (dir.getFilePath()!=null) + { + Path localDirPath = dir.getFilePath(); + Files.list( localDirPath ).filter( path -> path.getFileName( ).toString( ).startsWith( "nexus-maven-repository-index" ) ) + .forEach( path -> { - try { - System.err.println("Deleting " + path); - Files.delete(path); - } catch (IOException e) { - e.printStackTrace(); + try + { + System.err.println( "Deleting " + path ); + Files.delete( path ); + } + catch ( IOException e ) + { + e.printStackTrace( ); } - }); + } ); + } } @@ -310,20 +318,20 @@ public class ArchivaIndexingTaskExecutorTest indexingExecutor.executeTask( task ); - assertTrue( Files.exists(packedIndexDirectory) ); - assertTrue( Files.exists(indexerDirectory) ); + assertTrue( Files.exists(packedIndexDirectory.getFilePath()) ); + assertTrue( Files.exists(indexerDirectory.getFilePath()) ); // test packed index file creation //no more zip //Assertions.assertThat(new File( indexerDirectory, "nexus-maven-repository-index.zip" )).exists(); - Assertions.assertThat( Files.exists(packedIndexDirectory.resolve("nexus-maven-repository-index.properties" ) )); - Assertions.assertThat( Files.exists(packedIndexDirectory.resolve("nexus-maven-repository-index.gz" ) )); - assertFalse( Files.exists(packedIndexDirectory.resolve("nexus-maven-repository-index.1.gz" ) )); + Assertions.assertThat( Files.exists(packedIndexDirectory.getFilePath().resolve("nexus-maven-repository-index.properties" ) )); + Assertions.assertThat( Files.exists(packedIndexDirectory.getFilePath().resolve("nexus-maven-repository-index.gz" ) )); + assertFalse( Files.exists(packedIndexDirectory.getFilePath().resolve("nexus-maven-repository-index.1.gz" ) )); // unpack .zip index //unzipIndex( indexerDirectory.getPath(), destDir.getPath() ); - DefaultIndexUpdater.FileFetcher fetcher = new DefaultIndexUpdater.FileFetcher( packedIndexDirectory.toFile() ); + DefaultIndexUpdater.FileFetcher fetcher = new DefaultIndexUpdater.FileFetcher( packedIndexDirectory.getFilePath().toFile() ); IndexUpdateRequest updateRequest = new IndexUpdateRequest( getIndexingContext(), fetcher ); //updateRequest.setLocalIndexCacheDir( indexerDirectory ); indexUpdater.fetchAndUpdateIndex( updateRequest ); diff --git a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResource.java b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResource.java index 82697485d..da68c1cdb 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResource.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResource.java @@ -223,7 +223,7 @@ public class ArchivaDavResource } else if ( outputContext.hasStream() ) { - IndexWriter writer = new IndexWriter( getContent(), asset, logicalResource ); + IndexWriter writer = new IndexWriter( asset, logicalResource ); writer.write( outputContext ); } } diff --git a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java index 238cedb84..e4f96c72e 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java @@ -176,12 +176,6 @@ public class ArchivaDavResourceFactory */ private final LockManager lockManager = new SimpleLockManager(); - private ChecksummedFile checksum; - - private Digester digestSha1; - - private Digester digestMd5; - @Inject @Named( value = "archivaTaskScheduler#repository" ) private RepositoryArchivaTaskScheduler scheduler; @@ -193,8 +187,7 @@ public class ArchivaDavResourceFactory private ApplicationContext applicationContext; @Inject - public ArchivaDavResourceFactory( ApplicationContext applicationContext, PlexusSisuBridge plexusSisuBridge, - ArchivaConfiguration archivaConfiguration ) + public ArchivaDavResourceFactory( ApplicationContext applicationContext, ArchivaConfiguration archivaConfiguration ) throws PlexusSisuBridgeException { this.archivaConfiguration = archivaConfiguration; @@ -420,7 +413,12 @@ public class ArchivaDavResourceFactory String rootPath = StringUtils.substringBeforeLast( pathInfo, "/" ); - if ( StringUtils.endsWith( rootPath, repoGroup.getMergedIndexPath().getPath() ) ) + String mergedIndexPath = "/"; + if (repoGroup.supportsFeature( IndexCreationFeature.class )) { + mergedIndexPath = repoGroup.getFeature( IndexCreationFeature.class ).get().getIndexPath().getPath(); + } + + if ( StringUtils.endsWith( rootPath, mergedIndexPath ) ) { // we are in the case of index file request String requestedFileName = StringUtils.substringAfterLast( pathInfo, "/" ); @@ -1044,11 +1042,16 @@ public class ArchivaDavResourceFactory // remove last / String pathInfo = StringUtils.removeEnd( request.getPathInfo(), "/" ); + String mergedIndexPath = "/"; + if (repositoryGroup.supportsFeature( IndexCreationFeature.class )) { + IndexCreationFeature indexCreationFeature = repositoryGroup.getFeature( IndexCreationFeature.class ).get(); + mergedIndexPath = indexCreationFeature.getIndexPath().getPath(); + } if ( allow ) { - if ( StringUtils.endsWith( pathInfo, repositoryGroup.getMergedIndexPath().getPath() ) ) + if ( StringUtils.endsWith( pathInfo, mergedIndexPath ) ) { Path mergedRepoDirPath = buildMergedIndexDirectory( activePrincipal, request, repositoryGroup ); @@ -1061,7 +1064,7 @@ public class ArchivaDavResourceFactory { Path tmpDirectory = Paths.get( SystemUtils.getJavaIoTmpDir().toString(), id, - repositoryGroup.getMergedIndexPath().getFilePath().toString() ); + mergedIndexPath ); if ( !Files.exists(tmpDirectory) ) { synchronized ( tmpDirectory.toAbsolutePath().toString() ) @@ -1101,25 +1104,9 @@ public class ArchivaDavResourceFactory { // 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() ) ) ) + StorageAsset repoIndexDirectory = idf.getLocalIndexPath(); + if ( !StringUtils.equals( FilenameUtils.normalize( repoIndexDirectory.getPath() ), + FilenameUtils.normalize( logicalResource.getPath() ) ) ) { // for prompted authentication if ( httpAuth.getSecuritySession( request.getSession( true ) ) != null ) @@ -1368,34 +1355,43 @@ public class ArchivaDavResourceFactory } } + log.info( "generate temporary merged index for repository group '{}' for repositories '{}'", id, authzRepos ); - Path tempRepoFile = Files.createTempDirectory( "temp" ); - tempRepoFile.toFile().deleteOnExit(); - - IndexMergerRequest indexMergerRequest = - new IndexMergerRequest( authzRepos, true, id, - repositoryGroup.getMergedIndexPath().getFilePath().toString(), - repositoryGroup.getMergedIndexTTL() ).mergedIndexDirectory( - tempRepoFile ).temporary( true ); - - MergedRemoteIndexesTaskRequest taskRequest = - new MergedRemoteIndexesTaskRequest( indexMergerRequest, indexMerger ); - - MergedRemoteIndexesTask job = new MergedRemoteIndexesTask( taskRequest ); - - ArchivaIndexingContext indexingContext = job.execute().getIndexingContext(); - - Path mergedRepoDir = Paths.get(indexingContext.getPath()); - TemporaryGroupIndex temporaryGroupIndex = - new TemporaryGroupIndex( mergedRepoDir, indexingContext.getId(), id, - repositoryGroup.getMergedIndexTTL() ) // - .setCreationTime( new Date().getTime() ); - temporaryGroupIndexMap.put( id, temporaryGroupIndex ); - session.setAttribute( TemporaryGroupIndexSessionCleaner.TEMPORARY_INDEX_SESSION_KEY, - temporaryGroupIndexMap ); - return mergedRepoDir; + IndexCreationFeature indexCreationFeature = repositoryGroup.getFeature( IndexCreationFeature.class ).get(); + Path indexPath = indexCreationFeature.getLocalIndexPath().getFilePath(); + if (indexPath!=null) + { + Path tempRepoFile = Files.createTempDirectory( "temp" ); + tempRepoFile.toFile( ).deleteOnExit( ); + + IndexMergerRequest indexMergerRequest = + new IndexMergerRequest( authzRepos, true, id, + indexPath.toString( ), + repositoryGroup.getMergedIndexTTL( ) ).mergedIndexDirectory( + tempRepoFile ).temporary( true ); + + MergedRemoteIndexesTaskRequest taskRequest = + new MergedRemoteIndexesTaskRequest( indexMergerRequest, indexMerger ); + + MergedRemoteIndexesTask job = new MergedRemoteIndexesTask( taskRequest ); + + ArchivaIndexingContext indexingContext = job.execute( ).getIndexingContext( ); + + Path mergedRepoDir = Paths.get( indexingContext.getPath( ) ); + TemporaryGroupIndex temporaryGroupIndex = + new TemporaryGroupIndex( mergedRepoDir, indexingContext.getId( ), id, + repositoryGroup.getMergedIndexTTL( ) ) // + .setCreationTime( new Date( ).getTime( ) ); + temporaryGroupIndexMap.put( id, temporaryGroupIndex ); + session.setAttribute( TemporaryGroupIndexSessionCleaner.TEMPORARY_INDEX_SESSION_KEY, + temporaryGroupIndexMap ); + return mergedRepoDir; + } else { + log.error("Local index path for repository group {} does not exist.", repositoryGroup.getId()); + throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR ); + } } catch ( RepositorySearchException e ) { diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java index e153a545f..8c7cf4a65 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java @@ -718,7 +718,7 @@ public class ArchivaDavResourceFactoryTest ArchivaConfiguration archivaConfiguration ) throws PlexusSisuBridgeException { - super( applicationContext, plexusSisuBridge, archivaConfiguration ); + super( applicationContext, archivaConfiguration ); } @Override diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/DavResourceTest.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/DavResourceTest.java index a9bef0410..72b016f29 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/DavResourceTest.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/DavResourceTest.java @@ -22,6 +22,8 @@ package org.apache.archiva.webdav; import junit.framework.TestCase; import org.apache.archiva.common.filelock.FileLockManager; import org.apache.archiva.common.utils.FileUtils; +import org.apache.archiva.repository.LayoutException; +import org.apache.archiva.repository.content.FilesystemAsset; import org.apache.archiva.repository.events.AuditListener; import org.apache.archiva.repository.maven2.MavenManagedRepository; import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; @@ -47,6 +49,7 @@ import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; import javax.inject.Inject; +import javax.servlet.http.HttpServletResponse; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -116,10 +119,10 @@ public class DavResourceTest } } - private DavResource getDavResource( String logicalPath, Path file ) + private DavResource getDavResource( String logicalPath, Path file ) throws LayoutException { - return new ArchivaDavResource( file.toAbsolutePath().toString(), logicalPath, repository, session, resourceLocator, - resourceFactory, mimeTypes, Collections. emptyList(), null, fileLockManager ); + return new ArchivaDavResource( new FilesystemAsset( logicalPath, file.toAbsolutePath()) , logicalPath, repository, session, resourceLocator, + resourceFactory, mimeTypes, Collections. emptyList(), null); } @Test @@ -338,9 +341,16 @@ public class DavResourceTest public DavResource createResource( DavResourceLocator locator, DavSession session ) throws DavException { - return new ArchivaDavResource( baseDir.toAbsolutePath().toString(), "/", repository, session, resourceLocator, - resourceFactory, mimeTypes, Collections. emptyList(), - null, fileLockManager ); + try + { + return new ArchivaDavResource( new FilesystemAsset( "/" , baseDir.toAbsolutePath()), "/", repository, session, resourceLocator, + resourceFactory, mimeTypes, Collections. emptyList(), + null ); + } + catch ( LayoutException e ) + { + throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e ); + } } } } diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/UnauthenticatedDavResourceFactory.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/UnauthenticatedDavResourceFactory.java index 081f1c983..0390913a8 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/UnauthenticatedDavResourceFactory.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/UnauthenticatedDavResourceFactory.java @@ -43,7 +43,7 @@ public class UnauthenticatedDavResourceFactory ArchivaConfiguration archivaConfiguration ) throws PlexusSisuBridgeException { - super( applicationContext, plexusSisuBridge, archivaConfiguration ); + super( applicationContext, archivaConfiguration ); } @Override diff --git a/archiva-modules/plugins/stage-repository-merge/src/test/java/org/apache/archiva/configuration/StubConfiguration.java b/archiva-modules/plugins/stage-repository-merge/src/test/java/org/apache/archiva/configuration/StubConfiguration.java index 077edb9da..50bf74570 100644 --- a/archiva-modules/plugins/stage-repository-merge/src/test/java/org/apache/archiva/configuration/StubConfiguration.java +++ b/archiva-modules/plugins/stage-repository-merge/src/test/java/org/apache/archiva/configuration/StubConfiguration.java @@ -115,6 +115,12 @@ public class StubConfiguration return getDataDirectory().resolve("remotes"); } + @Override + public Path getRepositoryGroupBaseDir( ) + { + return getDataDirectory().resolve("group"); + } + @Override public Path getDataDirectory() { if (configuration!=null && StringUtils.isNotEmpty(configuration.getArchivaRuntimeConfiguration().getDataDirectory())) { -- 2.39.5