From c6e4e563d6698aa7cb5772878bc0fe22066b7884 Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Sat, 11 Nov 2017 00:07:56 +0100 Subject: [PATCH] Implementation of new archivaindexer Not finished yet, but uses the maven index service via spring dependency injection Moving some maven specific classes to subpackages --- .../configuration/ArchivaConfiguration.java | 3 + .../DefaultArchivaConfiguration.java | 10 + .../archiva-maven2-indexer/pom.xml | 33 +++- .../maven/DefaultIndexUpdateSideEffect.java | 47 +++++ .../indexer/maven/MavenIndexContext.java | 122 +++++++++++++ .../indexer/maven/MavenIndexManager.java | 171 ++++++++++++++++++ .../merger/DefaultIndexMerger.java | 6 +- .../search/MavenRepositorySearch.java | 7 +- .../resources/META-INF/spring-context.xml | 12 +- .../search/AbstractMavenRepositorySearch.java | 5 +- .../search/MavenRepositorySearchOSGITest.java | 5 +- .../MavenRepositorySearchPaginateTest.java | 6 +- .../search/MavenRepositorySearchTest.java | 8 +- .../src/test/resources/spring-context.xml | 1 + .../archiva/proxy/MockConfiguration.java | 24 +-- .../archiva/indexer/ArchivaIndexManager.java | 13 +- .../indexer/ArchivaIndexingContext.java | 7 +- .../archiva-webapp/src/test/log4j2-test.xml | 2 +- .../configuration/TestConfiguration.java | 11 ++ .../maven2/conf/MockConfiguration.java | 11 ++ .../configuration/StubConfiguration.java | 11 ++ 21 files changed, 466 insertions(+), 49 deletions(-) create mode 100644 archiva-modules/archiva-base/archiva-maven2-indexer/src/main/java/org/apache/archiva/indexer/maven/DefaultIndexUpdateSideEffect.java create mode 100644 archiva-modules/archiva-base/archiva-maven2-indexer/src/main/java/org/apache/archiva/indexer/maven/MavenIndexContext.java create mode 100644 archiva-modules/archiva-base/archiva-maven2-indexer/src/main/java/org/apache/archiva/indexer/maven/MavenIndexManager.java rename archiva-modules/archiva-base/archiva-maven2-indexer/src/main/java/org/apache/archiva/indexer/{ => maven}/merger/DefaultIndexMerger.java (95%) rename archiva-modules/archiva-base/archiva-maven2-indexer/src/main/java/org/apache/archiva/indexer/{ => maven}/search/MavenRepositorySearch.java (99%) rename archiva-modules/archiva-base/archiva-maven2-indexer/src/test/java/org/apache/archiva/indexer/{ => maven}/search/AbstractMavenRepositorySearch.java (98%) rename archiva-modules/archiva-base/archiva-maven2-indexer/src/test/java/org/apache/archiva/indexer/{ => maven}/search/MavenRepositorySearchOSGITest.java (92%) rename archiva-modules/archiva-base/archiva-maven2-indexer/src/test/java/org/apache/archiva/indexer/{ => maven}/search/MavenRepositorySearchPaginateTest.java (91%) rename archiva-modules/archiva-base/archiva-maven2-indexer/src/test/java/org/apache/archiva/indexer/{ => maven}/search/MavenRepositorySearchTest.java (99%) diff --git a/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/ArchivaConfiguration.java b/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/ArchivaConfiguration.java index 02d2b1362..acda2b710 100644 --- a/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/ArchivaConfiguration.java +++ b/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/ArchivaConfiguration.java @@ -22,6 +22,7 @@ package org.apache.archiva.configuration; import org.apache.archiva.redback.components.registry.RegistryException; import org.apache.archiva.redback.components.registry.RegistryListener; +import java.nio.file.Path; import java.util.List; import java.util.Locale; @@ -92,5 +93,7 @@ public interface ArchivaConfiguration public Locale getDefaultLocale(); public List getLanguagePriorities(); + + public Path getAppServerBaseDir(); } diff --git a/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/DefaultArchivaConfiguration.java b/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/DefaultArchivaConfiguration.java index 6983be0ac..0222a426a 100644 --- a/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/DefaultArchivaConfiguration.java +++ b/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/DefaultArchivaConfiguration.java @@ -891,6 +891,16 @@ public class DefaultArchivaConfiguration return languagePriorities; } + @Override + public Path getAppServerBaseDir() { + String basePath = registry.getString("appserver.base"); + if (!StringUtils.isEmpty(basePath)) { + return Paths.get(basePath); + } else { + return Paths.get(""); + } + } + @Override public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue ) { diff --git a/archiva-modules/archiva-base/archiva-maven2-indexer/pom.xml b/archiva-modules/archiva-base/archiva-maven2-indexer/pom.xml index f0a90a5d1..bc141b654 100644 --- a/archiva-modules/archiva-base/archiva-maven2-indexer/pom.xml +++ b/archiva-modules/archiva-base/archiva-maven2-indexer/pom.xml @@ -122,11 +122,6 @@ archiva-mock test - - org.apache.archiva - archiva-configuration - test - org.apache.archiva archiva-repository-admin-default @@ -183,7 +178,35 @@ hsqldb test + + org.apache.archiva + archiva-configuration + + + org.apache.maven.indexer + indexer-core + shaded-lucene + + + org.apache.maven + maven-core + + + org.sonatype.sisu + sisu-guava + + + org.sonatype.sisu + sisu-inject + + + org.sonatype.sisu + sisu-guice + + + + diff --git a/archiva-modules/archiva-base/archiva-maven2-indexer/src/main/java/org/apache/archiva/indexer/maven/DefaultIndexUpdateSideEffect.java b/archiva-modules/archiva-base/archiva-maven2-indexer/src/main/java/org/apache/archiva/indexer/maven/DefaultIndexUpdateSideEffect.java new file mode 100644 index 000000000..cb66cbb53 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-maven2-indexer/src/main/java/org/apache/archiva/indexer/maven/DefaultIndexUpdateSideEffect.java @@ -0,0 +1,47 @@ +package org.apache.archiva.indexer.maven; + +/* + * 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.maven.index.context.IndexingContext; +import org.apache.maven.index.updater.IndexUpdateSideEffect; +import org.apache.maven.index_shaded.lucene.store.Directory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +/** + * Not doing much but required at least one implementation + * + * @since 3.0.0 + */ +@Service("archivaIndexUpdater") +public class DefaultIndexUpdateSideEffect + implements IndexUpdateSideEffect +{ + private static final Logger LOGGER = LoggerFactory.getLogger( DefaultIndexUpdateSideEffect.class ); + + @Override + public void updateIndex( Directory directory, IndexingContext indexingContext, boolean b ) + { + LOGGER.info( "updating index: {} with directory: {}", // + indexingContext.getId(), // + directory.toString() ); + } +} diff --git a/archiva-modules/archiva-base/archiva-maven2-indexer/src/main/java/org/apache/archiva/indexer/maven/MavenIndexContext.java b/archiva-modules/archiva-base/archiva-maven2-indexer/src/main/java/org/apache/archiva/indexer/maven/MavenIndexContext.java new file mode 100644 index 000000000..30cc72795 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-maven2-indexer/src/main/java/org/apache/archiva/indexer/maven/MavenIndexContext.java @@ -0,0 +1,122 @@ +package org.apache.archiva.indexer.maven; + +/* + * 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.indexer.ArchivaIndexingContext; +import org.apache.archiva.repository.Repository; +import org.apache.maven.index.context.IndexingContext; + +import java.io.IOException; +import java.net.URI; +import java.nio.file.Files; +import java.sql.Date; +import java.time.ZonedDateTime; +import java.util.Set; + +/** + * Maven implementation of index context + */ +public class MavenIndexContext implements ArchivaIndexingContext { + + private IndexingContext delegate; + private Repository repository; + + MavenIndexContext(Repository repository, IndexingContext delegate) { + this.delegate = delegate; + this.repository = repository; + + } + + @Override + public String getId() { + return delegate.getId(); + } + + @Override + public Repository getRepository() { + return repository; + } + + @Override + public URI getPath() { + return delegate.getIndexDirectoryFile().toURI(); + } + + @Override + public boolean isEmpty() throws IOException { + return Files.list(delegate.getIndexDirectoryFile().toPath()).count()==0; + } + + @Override + public void commit() throws IOException { + delegate.commit(); + } + + @Override + public void rollback() throws IOException { + delegate.rollback(); + } + + @Override + public void optimize() throws IOException { + delegate.optimize(); + } + + @Override + public void close(boolean deleteFiles) throws IOException { + delegate.close(deleteFiles); + } + + @Override + public void purge() throws IOException { + delegate.purge(); + } + + @Override + public boolean supports(Class clazz) { + return IndexingContext.class.equals(clazz); + } + + @Override + public T getBaseContext(Class clazz) throws UnsupportedOperationException { + if (IndexingContext.class.equals(clazz)) { + return (T) delegate; + } else { + throw new UnsupportedOperationException("The class "+clazz+" is not supported by the maven indexer"); + } + } + + @Override + public Set getGroups() throws IOException { + return delegate.getAllGroups(); + } + + @Override + public void updateTimestamp(boolean save) throws IOException { + delegate.updateTimestamp(save); + } + + @Override + public void updateTimestamp(boolean save, ZonedDateTime time) throws IOException { + delegate.updateTimestamp(save, Date.from(time.toInstant())); + } + + +} diff --git a/archiva-modules/archiva-base/archiva-maven2-indexer/src/main/java/org/apache/archiva/indexer/maven/MavenIndexManager.java b/archiva-modules/archiva-base/archiva-maven2-indexer/src/main/java/org/apache/archiva/indexer/maven/MavenIndexManager.java new file mode 100644 index 000000000..12d858648 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-maven2-indexer/src/main/java/org/apache/archiva/indexer/maven/MavenIndexManager.java @@ -0,0 +1,171 @@ +package org.apache.archiva.indexer.maven; + +/* + * 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.configuration.ArchivaConfiguration; +import org.apache.archiva.indexer.ArchivaIndexManager; +import org.apache.archiva.indexer.ArchivaIndexingContext; +import org.apache.archiva.model.ArtifactReference; +import org.apache.archiva.repository.ManagedRepository; +import org.apache.archiva.repository.RemoteRepository; +import org.apache.archiva.repository.Repository; +import org.apache.archiva.repository.RepositoryType; +import org.apache.archiva.repository.features.RemoteIndexFeature; +import org.apache.maven.index.Indexer; +import org.apache.maven.index.context.IndexCreator; +import org.apache.maven.index.context.IndexingContext; +import org.apache.maven.index_shaded.lucene.index.IndexFormatTooOldException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +import javax.inject.Inject; +import java.io.IOException; +import java.net.URI; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; + +/** + * Maven implementation of index manager + */ +@Service("archivaIndexManager#maven") +public class MavenIndexManager implements ArchivaIndexManager { + + private static final Logger log = LoggerFactory.getLogger(MavenIndexManager.class); + + @Inject + private Indexer indexer; + + @Inject + private List indexCreators; + + @Inject + private ArchivaConfiguration archivaConfiguration; + + @Override + public void pack(ArchivaIndexingContext context) { + + } + + @Override + public void scan(ArchivaIndexingContext context, boolean update) { + + } + + @Override + public void update(ArchivaIndexingContext context, URI remoteUpdateUri, boolean fullUpdate) { + + } + + @Override + public void addArtifactToIndex(ArchivaIndexingContext context, ArtifactReference artifactReference) { + + } + + @Override + public void removeArtifactFromIndex(ArchivaIndexingContext context, ArtifactReference artifactReference) { + + } + + @Override + public boolean supportsRepository(RepositoryType type) { + return false; + } + + @Override + public ArchivaIndexingContext createContext(Repository remoteRepository) throws IOException { + IndexingContext mvnCtx = null; + if (remoteRepository instanceof RemoteRepository) { + mvnCtx = createRemoteContext((RemoteRepository) remoteRepository); + } else if (remoteRepository instanceof ManagedRepository) { + // TODO: Implement managed repository index creation + mvnCtx = null; + } + MavenIndexContext context = new MavenIndexContext(remoteRepository, mvnCtx); + return null; + } + + private IndexingContext createRemoteContext(RemoteRepository remoteRepository) throws IOException { + Path appServerBase = archivaConfiguration.getAppServerBaseDir(); + + String contextKey = "remote-" + remoteRepository.getId(); + + // create remote repository path + Path repoDir = appServerBase.resolve( "data").resolve( "remotes" ).resolve( remoteRepository.getId() ); + if ( !Files.exists(repoDir) ) + { + Files.createDirectories(repoDir); + } + + Path indexDirectory = null; + + // is there configured indexDirectory ? + if (remoteRepository.supportsFeature(RemoteIndexFeature.class)) { + RemoteIndexFeature rif = remoteRepository.getFeature(RemoteIndexFeature.class).get(); + indexDirectory = PathUtil.getPathFromUri(rif.getIndexUri()); + if (!indexDirectory.isAbsolute()) { + indexDirectory = repoDir.resolve(indexDirectory); + } + + // if not configured use a default value + if (indexDirectory == null) { + indexDirectory = repoDir.resolve(".index"); + } + if (!Files.exists(indexDirectory)) { + Files.createDirectories(indexDirectory); + } + + try { + + return indexer.createIndexingContext(contextKey, remoteRepository.getId(), repoDir.toFile(), indexDirectory.toFile(), + remoteRepository.getLocation() == null ? null : remoteRepository.getLocation().toString(), + calculateIndexRemoteUrl(remoteRepository.getLocation(), rif), + true, false, + indexCreators); + } catch (IndexFormatTooOldException e) { + // existing index with an old lucene format so we need to delete it!!! + // 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); + return indexer.createIndexingContext(contextKey, remoteRepository.getId(), repoDir.toFile(), indexDirectory.toFile(), + remoteRepository.getLocation() == null ? null : remoteRepository.getLocation().toString(), + calculateIndexRemoteUrl(remoteRepository.getLocation(), rif), + true, false, + indexCreators); + + } + } else { + throw new IOException("No remote index defined"); + } + } + + private String calculateIndexRemoteUrl(URI baseUri, RemoteIndexFeature rif) { + if (rif.getIndexUri()==null) { + return baseUri.resolve(".index").toString(); + } else { + return baseUri.resolve(rif.getIndexUri()).toString(); + } + } + + +} diff --git a/archiva-modules/archiva-base/archiva-maven2-indexer/src/main/java/org/apache/archiva/indexer/merger/DefaultIndexMerger.java b/archiva-modules/archiva-base/archiva-maven2-indexer/src/main/java/org/apache/archiva/indexer/maven/merger/DefaultIndexMerger.java similarity index 95% rename from archiva-modules/archiva-base/archiva-maven2-indexer/src/main/java/org/apache/archiva/indexer/merger/DefaultIndexMerger.java rename to archiva-modules/archiva-base/archiva-maven2-indexer/src/main/java/org/apache/archiva/indexer/maven/merger/DefaultIndexMerger.java index b4daa8bd8..0e0cd9059 100644 --- a/archiva-modules/archiva-base/archiva-maven2-indexer/src/main/java/org/apache/archiva/indexer/merger/DefaultIndexMerger.java +++ b/archiva-modules/archiva-base/archiva-maven2-indexer/src/main/java/org/apache/archiva/indexer/maven/merger/DefaultIndexMerger.java @@ -1,4 +1,4 @@ -package org.apache.archiva.indexer.merger; +package org.apache.archiva.indexer.maven.merger; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -19,6 +19,10 @@ package org.apache.archiva.indexer.merger; */ import org.apache.archiva.common.utils.FileUtils; +import org.apache.archiva.indexer.merger.IndexMerger; +import org.apache.archiva.indexer.merger.IndexMergerException; +import org.apache.archiva.indexer.merger.IndexMergerRequest; +import org.apache.archiva.indexer.merger.TemporaryGroupIndex; import org.apache.commons.lang.time.StopWatch; import org.apache.maven.index.NexusIndexer; import org.apache.maven.index.context.IndexCreator; diff --git a/archiva-modules/archiva-base/archiva-maven2-indexer/src/main/java/org/apache/archiva/indexer/search/MavenRepositorySearch.java b/archiva-modules/archiva-base/archiva-maven2-indexer/src/main/java/org/apache/archiva/indexer/maven/search/MavenRepositorySearch.java similarity index 99% rename from archiva-modules/archiva-base/archiva-maven2-indexer/src/main/java/org/apache/archiva/indexer/search/MavenRepositorySearch.java rename to archiva-modules/archiva-base/archiva-maven2-indexer/src/main/java/org/apache/archiva/indexer/maven/search/MavenRepositorySearch.java index b6f49840e..590cdd244 100644 --- a/archiva-modules/archiva-base/archiva-maven2-indexer/src/main/java/org/apache/archiva/indexer/search/MavenRepositorySearch.java +++ b/archiva-modules/archiva-base/archiva-maven2-indexer/src/main/java/org/apache/archiva/indexer/maven/search/MavenRepositorySearch.java @@ -1,4 +1,4 @@ -package org.apache.archiva.indexer.search; +package org.apache.archiva.indexer.maven.search; /* * Licensed to the Apache Software Foundation (ASF) under one @@ -25,6 +25,7 @@ import org.apache.archiva.admin.model.beans.ProxyConnector; import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin; import org.apache.archiva.admin.model.proxyconnector.ProxyConnectorAdmin; import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException; +import org.apache.archiva.indexer.search.*; import org.apache.archiva.indexer.util.SearchUtil; import org.apache.archiva.model.ArchivaArtifactModel; import org.apache.archiva.model.ArtifactReference; @@ -96,8 +97,8 @@ public class MavenRepositorySearch * @see RepositorySearch#search(String, List, String, SearchResultLimits, List) */ @Override - public SearchResults search( String principal, List selectedRepos, String term, SearchResultLimits limits, - List previousSearchTerms ) + public SearchResults search(String principal, List selectedRepos, String term, SearchResultLimits limits, + List previousSearchTerms ) throws RepositorySearchException { List indexingContextIds = addIndexingContexts( selectedRepos ); diff --git a/archiva-modules/archiva-base/archiva-maven2-indexer/src/main/resources/META-INF/spring-context.xml b/archiva-modules/archiva-base/archiva-maven2-indexer/src/main/resources/META-INF/spring-context.xml index 8c0de11db..870a13b56 100644 --- a/archiva-modules/archiva-base/archiva-maven2-indexer/src/main/resources/META-INF/spring-context.xml +++ b/archiva-modules/archiva-base/archiva-maven2-indexer/src/main/resources/META-INF/spring-context.xml @@ -22,23 +22,15 @@ - + - - - org.apache.maven.index.DefaultNexusIndexer - - diff --git a/archiva-modules/archiva-base/archiva-maven2-indexer/src/test/java/org/apache/archiva/indexer/search/AbstractMavenRepositorySearch.java b/archiva-modules/archiva-base/archiva-maven2-indexer/src/test/java/org/apache/archiva/indexer/maven/search/AbstractMavenRepositorySearch.java similarity index 98% rename from archiva-modules/archiva-base/archiva-maven2-indexer/src/test/java/org/apache/archiva/indexer/search/AbstractMavenRepositorySearch.java rename to archiva-modules/archiva-base/archiva-maven2-indexer/src/test/java/org/apache/archiva/indexer/maven/search/AbstractMavenRepositorySearch.java index ab85ec59b..07fcc09ba 100644 --- a/archiva-modules/archiva-base/archiva-maven2-indexer/src/test/java/org/apache/archiva/indexer/search/AbstractMavenRepositorySearch.java +++ b/archiva-modules/archiva-base/archiva-maven2-indexer/src/test/java/org/apache/archiva/indexer/maven/search/AbstractMavenRepositorySearch.java @@ -1,4 +1,4 @@ -package org.apache.archiva.indexer.search; +package org.apache.archiva.indexer.maven.search; /* * Licensed to the Apache Software Foundation (ASF) under one @@ -28,6 +28,9 @@ import org.apache.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.configuration.Configuration; import org.apache.archiva.configuration.ConfigurationListener; import org.apache.archiva.configuration.ManagedRepositoryConfiguration; +import org.apache.archiva.indexer.maven.search.MavenRepositorySearch; +import org.apache.archiva.indexer.search.SearchResultHit; +import org.apache.archiva.indexer.search.SearchResults; import org.apache.archiva.repository.RepositoryRegistry; import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; import org.apache.commons.lang.SystemUtils; diff --git a/archiva-modules/archiva-base/archiva-maven2-indexer/src/test/java/org/apache/archiva/indexer/search/MavenRepositorySearchOSGITest.java b/archiva-modules/archiva-base/archiva-maven2-indexer/src/test/java/org/apache/archiva/indexer/maven/search/MavenRepositorySearchOSGITest.java similarity index 92% rename from archiva-modules/archiva-base/archiva-maven2-indexer/src/test/java/org/apache/archiva/indexer/search/MavenRepositorySearchOSGITest.java rename to archiva-modules/archiva-base/archiva-maven2-indexer/src/test/java/org/apache/archiva/indexer/maven/search/MavenRepositorySearchOSGITest.java index 69429303d..e99947fa8 100644 --- a/archiva-modules/archiva-base/archiva-maven2-indexer/src/test/java/org/apache/archiva/indexer/search/MavenRepositorySearchOSGITest.java +++ b/archiva-modules/archiva-base/archiva-maven2-indexer/src/test/java/org/apache/archiva/indexer/maven/search/MavenRepositorySearchOSGITest.java @@ -1,4 +1,4 @@ -package org.apache.archiva.indexer.search; +package org.apache.archiva.indexer.maven.search; /* * Licensed to the Apache Software Foundation (ASF) under one @@ -19,6 +19,9 @@ package org.apache.archiva.indexer.search; * under the License. */ +import org.apache.archiva.indexer.search.SearchFields; +import org.apache.archiva.indexer.search.SearchResultHit; +import org.apache.archiva.indexer.search.SearchResults; import org.easymock.EasyMock; import org.junit.Test; diff --git a/archiva-modules/archiva-base/archiva-maven2-indexer/src/test/java/org/apache/archiva/indexer/search/MavenRepositorySearchPaginateTest.java b/archiva-modules/archiva-base/archiva-maven2-indexer/src/test/java/org/apache/archiva/indexer/maven/search/MavenRepositorySearchPaginateTest.java similarity index 91% rename from archiva-modules/archiva-base/archiva-maven2-indexer/src/test/java/org/apache/archiva/indexer/search/MavenRepositorySearchPaginateTest.java rename to archiva-modules/archiva-base/archiva-maven2-indexer/src/test/java/org/apache/archiva/indexer/maven/search/MavenRepositorySearchPaginateTest.java index 802444a67..c8498b29a 100644 --- a/archiva-modules/archiva-base/archiva-maven2-indexer/src/test/java/org/apache/archiva/indexer/search/MavenRepositorySearchPaginateTest.java +++ b/archiva-modules/archiva-base/archiva-maven2-indexer/src/test/java/org/apache/archiva/indexer/maven/search/MavenRepositorySearchPaginateTest.java @@ -1,4 +1,4 @@ -package org.apache.archiva.indexer.search; +package org.apache.archiva.indexer.maven.search; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -19,6 +19,10 @@ package org.apache.archiva.indexer.search; */ import junit.framework.TestCase; +import org.apache.archiva.indexer.maven.search.MavenRepositorySearch; +import org.apache.archiva.indexer.search.SearchResultHit; +import org.apache.archiva.indexer.search.SearchResultLimits; +import org.apache.archiva.indexer.search.SearchResults; import org.apache.archiva.indexer.util.SearchUtil; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/archiva-modules/archiva-base/archiva-maven2-indexer/src/test/java/org/apache/archiva/indexer/search/MavenRepositorySearchTest.java b/archiva-modules/archiva-base/archiva-maven2-indexer/src/test/java/org/apache/archiva/indexer/maven/search/MavenRepositorySearchTest.java similarity index 99% rename from archiva-modules/archiva-base/archiva-maven2-indexer/src/test/java/org/apache/archiva/indexer/search/MavenRepositorySearchTest.java rename to archiva-modules/archiva-base/archiva-maven2-indexer/src/test/java/org/apache/archiva/indexer/maven/search/MavenRepositorySearchTest.java index 3c10633b0..1cc157482 100644 --- a/archiva-modules/archiva-base/archiva-maven2-indexer/src/test/java/org/apache/archiva/indexer/search/MavenRepositorySearchTest.java +++ b/archiva-modules/archiva-base/archiva-maven2-indexer/src/test/java/org/apache/archiva/indexer/maven/search/MavenRepositorySearchTest.java @@ -1,4 +1,4 @@ -package org.apache.archiva.indexer.search; +package org.apache.archiva.indexer.maven.search; /* * Licensed to the Apache Software Foundation (ASF) under one @@ -19,20 +19,16 @@ package org.apache.archiva.indexer.search; * under the License. */ -import org.apache.archiva.configuration.ConfigurationEvent; -import org.apache.archiva.configuration.ConfigurationListener; +import org.apache.archiva.indexer.search.*; import org.apache.archiva.indexer.util.SearchUtil; -import org.apache.archiva.repository.RepositoryRegistry; import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; import org.apache.maven.index_shaded.lucene.index.IndexUpgrader; import org.codehaus.plexus.util.FileUtils; import org.easymock.EasyMock; -import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; -import javax.inject.Inject; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; diff --git a/archiva-modules/archiva-base/archiva-maven2-indexer/src/test/resources/spring-context.xml b/archiva-modules/archiva-base/archiva-maven2-indexer/src/test/resources/spring-context.xml index e0bf5c41c..13ef95f3c 100644 --- a/archiva-modules/archiva-base/archiva-maven2-indexer/src/test/resources/spring-context.xml +++ b/archiva-modules/archiva-base/archiva-maven2-indexer/src/test/resources/spring-context.xml @@ -28,6 +28,7 @@ default-lazy-init="false"> + diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/MockConfiguration.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/MockConfiguration.java index fce694934..54a0b94da 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/MockConfiguration.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/MockConfiguration.java @@ -19,12 +19,7 @@ package org.apache.archiva.proxy; * under the License. */ -import org.apache.archiva.configuration.ArchivaConfiguration; -import org.apache.archiva.configuration.Configuration; -import org.apache.archiva.configuration.ConfigurationListener; -import org.apache.archiva.configuration.FileType; -import org.apache.archiva.configuration.FileTypes; -import org.apache.archiva.configuration.RepositoryScanningConfiguration; +import org.apache.archiva.configuration.*; import org.apache.archiva.redback.components.registry.Registry; import org.apache.archiva.redback.components.registry.RegistryException; import org.apache.archiva.redback.components.registry.RegistryListener; @@ -32,12 +27,10 @@ import org.easymock.EasyMock; import org.easymock.IMocksControl; import org.springframework.stereotype.Service; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Locale; -import java.util.Set; import javax.annotation.PostConstruct; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.*; /** * MockConfiguration @@ -158,4 +151,13 @@ public class MockConfiguration { return Locale.LanguageRange.parse( "en,fr,de" ); } + + @Override + public Path getAppServerBaseDir() { + if (System.getProperties().containsKey("appserver.base")) { + return Paths.get(System.getProperty("appserver.base")); + } else { + return Paths.get(""); + } + } } diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/indexer/ArchivaIndexManager.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/indexer/ArchivaIndexManager.java index 189138330..4663db620 100644 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/indexer/ArchivaIndexManager.java +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/indexer/ArchivaIndexManager.java @@ -23,6 +23,7 @@ import org.apache.archiva.model.ArtifactReference; import org.apache.archiva.repository.Repository; import org.apache.archiva.repository.RepositoryType; +import java.io.IOException; import java.net.URI; public interface ArchivaIndexManager { @@ -31,14 +32,14 @@ public interface ArchivaIndexManager { * Compresses the index to a more dense packed format. * @param context */ - void pack(ArchivaIndexingContext context); + void pack(ArchivaIndexingContext context) throws IOException; /** * Rescans the whole repository, this index is associated to. * @param context * @param update */ - void scan(ArchivaIndexingContext context, boolean update); + void scan(ArchivaIndexingContext context, boolean update) throws IOException; /** * Updates the index from the remote url. @@ -46,21 +47,21 @@ public interface ArchivaIndexManager { * @param remoteUpdateUri * @param fullUpdate */ - void update(ArchivaIndexingContext context, URI remoteUpdateUri, boolean fullUpdate); + void update(ArchivaIndexingContext context, URI remoteUpdateUri, boolean fullUpdate) throws IOException; /** * Adds a artifact to the index. * @param context * @param artifactReference */ - void addArtifactToIndex(ArchivaIndexingContext context, ArtifactReference artifactReference); + void addArtifactToIndex(ArchivaIndexingContext context, ArtifactReference artifactReference) throws IOException; /** * Removes a artifact from the index. * @param context * @param artifactReference */ - void removeArtifactFromIndex(ArchivaIndexingContext context, ArtifactReference artifactReference); + void removeArtifactFromIndex(ArchivaIndexingContext context, ArtifactReference artifactReference) throws IOException; /** @@ -75,5 +76,5 @@ public interface ArchivaIndexManager { * @param repository the repository for which the index context should be created * @return the index context */ - ArchivaIndexingContext createContext(Repository repository); + ArchivaIndexingContext createContext(Repository repository) throws IOException; } diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/indexer/ArchivaIndexingContext.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/indexer/ArchivaIndexingContext.java index 23496e779..ee7cfc1b1 100644 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/indexer/ArchivaIndexingContext.java +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/indexer/ArchivaIndexingContext.java @@ -25,6 +25,7 @@ import org.apache.archiva.repository.RepositoryType; import java.io.IOException; import java.net.URI; import java.time.LocalDateTime; +import java.time.ZonedDateTime; import java.util.Set; /** @@ -55,7 +56,7 @@ public interface ArchivaIndexingContext { * Returns true, if the index has no entries or is not initialized. * @return */ - boolean isEmpty(); + boolean isEmpty() throws IOException; /** * Writes the last changes to the index. @@ -111,7 +112,7 @@ public interface ArchivaIndexingContext { * Returns the list of groups that are assigned to this index * @return */ - Set getGroups(); + Set getGroups() throws IOException; /** * Updates the timestamp of the index. @@ -126,5 +127,5 @@ public interface ArchivaIndexingContext { * @param time * @throws IOException */ - void updateTimestamp(boolean save, LocalDateTime time) throws IOException; + void updateTimestamp(boolean save, ZonedDateTime time) throws IOException; } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/log4j2-test.xml b/archiva-modules/archiva-web/archiva-webapp/src/test/log4j2-test.xml index 55668911a..b4965e64c 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/log4j2-test.xml +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/log4j2-test.xml @@ -52,7 +52,7 @@ --> - + diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/configuration/TestConfiguration.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/configuration/TestConfiguration.java index ce931e30d..1283f62f7 100644 --- a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/configuration/TestConfiguration.java +++ b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/configuration/TestConfiguration.java @@ -4,6 +4,8 @@ import org.apache.archiva.redback.components.registry.RegistryException; import org.apache.archiva.redback.components.registry.RegistryListener; import org.springframework.stereotype.Service; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.List; import java.util.Locale; @@ -92,4 +94,13 @@ public class TestConfiguration { return Locale.LanguageRange.parse("en,fr,de"); } + + @Override + public Path getAppServerBaseDir() { + if (System.getProperties().containsKey("appserver.base")) { + return Paths.get(System.getProperty("appserver.base")); + } else { + return Paths.get(""); + } + } } diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/conf/MockConfiguration.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/conf/MockConfiguration.java index d41cff046..a8d783756 100644 --- a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/conf/MockConfiguration.java +++ b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/conf/MockConfiguration.java @@ -28,6 +28,8 @@ import org.apache.archiva.redback.components.registry.RegistryListener; import org.easymock.IMocksControl; import org.springframework.stereotype.Service; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.HashSet; import java.util.List; import java.util.Locale; @@ -135,4 +137,13 @@ public class MockConfiguration { return Locale.LanguageRange.parse( "en,fr,de" ); } + + @Override + public Path getAppServerBaseDir() { + if (System.getProperties().containsKey("appserver.base")) { + return Paths.get(System.getProperty("appserver.base")); + } else { + return Paths.get(""); + } + } } 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 1709f1930..0206edb9f 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 @@ -23,6 +23,8 @@ import org.apache.archiva.redback.components.registry.RegistryException; import org.apache.archiva.redback.components.registry.RegistryListener; import org.springframework.stereotype.Service; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.List; import java.util.Locale; @@ -92,4 +94,13 @@ public class StubConfiguration { return Locale.LanguageRange.parse( "en,fr,de" ); } + + @Override + public Path getAppServerBaseDir() { + if (System.getProperties().containsKey("appserver.base")) { + return Paths.get(System.getProperty("appserver.base")); + } else { + return Paths.get(""); + } + } } -- 2.39.5