From: Martin Stockhammer Date: Thu, 9 Nov 2017 16:32:45 +0000 (+0100) Subject: Moving some interfaces to the repository-api module X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e4af2d6c41cdf814bd5b3b6e8f33140d099d6f89;p=archiva.git Moving some interfaces to the repository-api module --- diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/connector/RepositoryConnector.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/connector/RepositoryConnector.java new file mode 100644 index 000000000..6f653e279 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/connector/RepositoryConnector.java @@ -0,0 +1,45 @@ +package org.apache.archiva.repository.connector; + +/* + * 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.repository.ManagedRepositoryContent; +import org.apache.archiva.repository.RemoteRepositoryContent; + +import java.util.List; + +/** + * RepositoryConnector + * + * + */ +public interface RepositoryConnector +{ + ManagedRepositoryContent getSourceRepository(); + + RemoteRepositoryContent getTargetRepository(); + + List getBlacklist(); + + List getWhitelist(); + + boolean isDisabled(); + + void setDisabled(boolean disabled); +} diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/PathParser.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/PathParser.java new file mode 100644 index 000000000..ddbcb6d59 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/PathParser.java @@ -0,0 +1,43 @@ +package org.apache.archiva.repository.content; + +/* + * 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.model.ArtifactReference; +import org.apache.archiva.repository.LayoutException; + +/** + * PathParser interface. + * + * + */ +public interface PathParser +{ + + /** + * Take a path and get the ArtifactReference associated with it. + * + * @param path the relative path to parse. + * @return the ArtifactReference for the provided path. (never null) + * @throws LayoutException if there was a problem parsing the path. + */ + ArtifactReference toArtifactReference( String path ) + throws LayoutException; + +} diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/connector/RepositoryConnector.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/connector/RepositoryConnector.java deleted file mode 100644 index 6f653e279..000000000 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/connector/RepositoryConnector.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.apache.archiva.repository.connector; - -/* - * 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.repository.ManagedRepositoryContent; -import org.apache.archiva.repository.RemoteRepositoryContent; - -import java.util.List; - -/** - * RepositoryConnector - * - * - */ -public interface RepositoryConnector -{ - ManagedRepositoryContent getSourceRepository(); - - RemoteRepositoryContent getTargetRepository(); - - List getBlacklist(); - - List getWhitelist(); - - boolean isDisabled(); - - void setDisabled(boolean disabled); -} diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/PathParser.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/PathParser.java deleted file mode 100644 index ddbcb6d59..000000000 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/PathParser.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.apache.archiva.repository.content; - -/* - * 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.model.ArtifactReference; -import org.apache.archiva.repository.LayoutException; - -/** - * PathParser interface. - * - * - */ -public interface PathParser -{ - - /** - * Take a path and get the ArtifactReference associated with it. - * - * @param path the relative path to parse. - * @return the ArtifactReference for the provided path. (never null) - * @throws LayoutException if there was a problem parsing the path. - */ - ArtifactReference toArtifactReference( String path ) - throws LayoutException; - -} diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/test/java/org/apache/archiva/repository/RepositoryRegistryTest.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/test/java/org/apache/archiva/repository/RepositoryRegistryTest.java deleted file mode 100644 index 01dcbd253..000000000 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/test/java/org/apache/archiva/repository/RepositoryRegistryTest.java +++ /dev/null @@ -1,511 +0,0 @@ -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. - */ - -import org.apache.archiva.configuration.ArchivaConfiguration; -import org.apache.archiva.configuration.Configuration; -import org.apache.archiva.configuration.ManagedRepositoryConfiguration; -import org.apache.archiva.configuration.RemoteRepositoryConfiguration; -import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.test.context.ContextConfiguration; - -import javax.inject.Inject; -import java.io.IOException; -import java.net.URISyntaxException; -import java.net.URL; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.StandardCopyOption; -import java.util.Collection; - -import static org.junit.Assert.*; - -/** - * Test for RepositoryRegistry - */ -@RunWith(ArchivaSpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" }) -public class RepositoryRegistryTest -{ - - @Inject - RepositoryRegistry repositoryRegistry; - - @Inject - ArchivaConfiguration archivaConfiguration; - - private static final Path userCfg = Paths.get(System.getProperty( "user.home" ), ".m2/archiva.xml"); - - private static Path cfgCopy; - private static Path archivaCfg; - - @BeforeClass - public static void classSetup() throws IOException, URISyntaxException - { - URL archivaCfgUri = Thread.currentThread().getContextClassLoader().getResource( "archiva.xml" ); - if (archivaCfgUri!=null) { - archivaCfg = Paths.get(archivaCfgUri.toURI()); - cfgCopy = Files.createTempFile( "archiva-backup", ".xml" ); - Files.copy( archivaCfg, cfgCopy, StandardCopyOption.REPLACE_EXISTING); - } - } - - @AfterClass - public static void classTearDown() throws IOException - { - if (cfgCopy!=null) { - Files.deleteIfExists( cfgCopy ); - } - } - - @Before - public void setUp( ) throws Exception - { - assertNotNull( repositoryRegistry ); - Files.deleteIfExists( userCfg ); - URL archivaCfgUri = Thread.currentThread().getContextClassLoader().getResource( "archiva.xml" ); - if (archivaCfgUri!=null) { - archivaCfg = Paths.get(archivaCfgUri.toURI()); - if (Files.exists(cfgCopy)) - { - Files.copy( cfgCopy, archivaCfg , StandardCopyOption.REPLACE_EXISTING); - } - } - archivaConfiguration.reload(); - repositoryRegistry.reload(); - } - - @After - public void tearDown( ) throws Exception - { - Files.deleteIfExists( userCfg ); - if (cfgCopy!=null && Files.exists(cfgCopy)) { - Files.copy(cfgCopy, archivaCfg, StandardCopyOption.REPLACE_EXISTING); - } - } - - @Test - public void getRepositories( ) throws Exception - { - Collection repos = repositoryRegistry.getRepositories( ); - assertEquals( 5, repos.size( ) ); - assertTrue(repos.stream().anyMatch( rep -> rep.getId().equals("internal") )); - assertTrue( repos.stream( ).anyMatch( rep -> rep.getId( ).equals( "snapshots") ) ); - assertTrue(repos.stream().anyMatch( rep -> rep.getId().equals( "central") )); - } - - @Test - public void getManagedRepositories( ) throws Exception - { - Collection repos = repositoryRegistry.getManagedRepositories(); - assertEquals( 4, repos.size( ) ); - assertTrue(repos.stream().anyMatch( rep -> rep.getId().equals("internal") )); - assertTrue( repos.stream( ).anyMatch( rep -> rep.getId( ).equals( "snapshots") ) ); - } - - @Test - public void getRemoteRepositories( ) throws Exception - { - Collection repos = repositoryRegistry.getRemoteRepositories( ); - assertEquals( 1, repos.size( ) ); - assertTrue(repos.stream().anyMatch( rep -> rep.getId().equals( "central") )); - } - - @Test - public void getRepository( ) throws Exception - { - Repository repo = repositoryRegistry.getRepository( "internal" ); - assertNotNull(repo); - assertEquals("internal", repo.getId()); - assertEquals("Archiva Managed Internal Repository", repo.getName()); - assertEquals("This is internal repository.", repo.getDescription()); - assertEquals( "default", repo.getLayout( ) ); - assertEquals("0 0 * * * ?", repo.getSchedulingDefinition()); - assertTrue(repo instanceof ManagedRepository); - assertTrue( repo.hasIndex( ) ); - assertTrue(repo.isScanned()); - assertEquals(RepositoryType.MAVEN, repo.getType()); - } - - @Test - public void getManagedRepository( ) throws Exception - { - ManagedRepository repo = repositoryRegistry.getManagedRepository( "internal" ); - assertNotNull(repo); - assertEquals("internal", repo.getId()); - assertEquals("Archiva Managed Internal Repository", repo.getName()); - assertEquals("This is internal repository.", repo.getDescription()); - assertEquals( "default", repo.getLayout( ) ); - assertEquals("0 0 * * * ?", repo.getSchedulingDefinition()); - assertTrue( repo.hasIndex( ) ); - assertTrue(repo.isScanned()); - assertEquals(RepositoryType.MAVEN, repo.getType()); - assertTrue(repo.getActiveReleaseSchemes().contains(ReleaseScheme.RELEASE)); - assertFalse( repo.getActiveReleaseSchemes( ).contains( ReleaseScheme.SNAPSHOT ) ); - assertNotNull(repo.getContent()); - - assertNull(repositoryRegistry.getManagedRepository( "xyu" )); - - } - - @Test - public void getRemoteRepository( ) throws Exception - { - RemoteRepository repo = repositoryRegistry.getRemoteRepository( "central" ); - assertNotNull(repo); - assertEquals("central", repo.getId()); - assertEquals("Central Repository", repo.getName()); - assertEquals("", repo.getDescription()); - assertEquals( "default", repo.getLayout( ) ); - assertEquals("0 0 08 ? * SUN", repo.getSchedulingDefinition()); - assertTrue( repo.hasIndex( ) ); - assertTrue(repo.isScanned()); - assertEquals(RepositoryType.MAVEN, repo.getType()); - - assertEquals(35, repo.getTimeout().getSeconds()); - } - - @Test - public void putManagedRepository( ) throws Exception - { - BasicManagedRepository managedRepository = new BasicManagedRepository( "test001", "Test repo" ); - managedRepository.setDescription( managedRepository.getPrimaryLocale(), "This is just a test" ); - repositoryRegistry.putRepository(managedRepository); - - assertNotNull(managedRepository.getContent()); - assertEquals(6, repositoryRegistry.getRepositories().size()); - - managedRepository = new BasicManagedRepository( "central", "Test repo" ); - managedRepository.setDescription( managedRepository.getPrimaryLocale(), "This is just a test" ); - ManagedRepository updatedRepo = null; - try { - repositoryRegistry.putRepository( managedRepository ); - throw new RuntimeException("Repository exception should be thrown, if there exists a remote repository already with that id"); - } catch (RepositoryException e) { - // OK - } - managedRepository = new BasicManagedRepository( "internal", "Test repo" ); - managedRepository.setDescription( managedRepository.getPrimaryLocale(), "This is just a test" ); - updatedRepo = repositoryRegistry.putRepository( managedRepository ); - - assertTrue(updatedRepo==managedRepository); - assertNotNull(managedRepository.getContent()); - assertEquals(6, repositoryRegistry.getRepositories().size()); - ManagedRepository managedRepository1 = repositoryRegistry.getManagedRepository( "internal" ); - assertEquals("Test repo", managedRepository1.getName()); - assertTrue(managedRepository1==managedRepository); - - } - - @Test - public void putManagedRepositoryFromConfig( ) throws Exception - { - ManagedRepositoryConfiguration cfg = new ManagedRepositoryConfiguration(); - cfg.setId("test002"); - cfg.setName("This is test 002"); - ManagedRepository repo = repositoryRegistry.putRepository( cfg ); - assertNotNull(repo); - assertEquals("test002", repo.getId()); - assertEquals("This is test 002", repo.getName()); - assertNotNull(repo.getContent()); - archivaConfiguration.reload(); - Collection repos = repositoryRegistry.getManagedRepositories(); - assertEquals(5, repos.size()); - - ManagedRepository internalRepo = repositoryRegistry.getManagedRepository( "internal" ); - cfg = new ManagedRepositoryConfiguration(); - cfg.setId("internal"); - cfg.setName("This is internal test 002"); - repo = repositoryRegistry.putRepository( cfg ); - assertTrue(internalRepo==repo); - assertEquals("This is internal test 002",repo.getName()); - assertEquals(5, repositoryRegistry.getManagedRepositories().size()); - - repositoryRegistry.reload(); - assertEquals(5, repositoryRegistry.getManagedRepositories().size()); - - } - - @Test - public void putManagedRepositoryFromConfigWithoutSave( ) throws Exception - { - Configuration configuration = archivaConfiguration.getConfiguration(); - ManagedRepositoryConfiguration cfg = new ManagedRepositoryConfiguration(); - cfg.setId("test002"); - cfg.setName("This is test 002"); - ManagedRepository repo = repositoryRegistry.putRepository( cfg, configuration ); - assertNotNull(repo); - assertEquals("test002", repo.getId()); - assertEquals("This is test 002", repo.getName()); - assertNotNull(repo.getContent()); - archivaConfiguration.reload(); - assertEquals(3, archivaConfiguration.getConfiguration().getManagedRepositories().size()); - Collection repos = repositoryRegistry.getManagedRepositories(); - assertEquals(5, repos.size()); - - ManagedRepository internalRepo = repositoryRegistry.getManagedRepository( "internal" ); - cfg = new ManagedRepositoryConfiguration(); - cfg.setId("internal"); - cfg.setName("This is internal test 002"); - repo = repositoryRegistry.putRepository( cfg, configuration ); - assertTrue(internalRepo==repo); - assertEquals("This is internal test 002",repo.getName()); - assertEquals(5, repositoryRegistry.getManagedRepositories().size()); - - repositoryRegistry.reload(); - assertEquals(4, repositoryRegistry.getManagedRepositories().size()); - } - - @Test - public void putRemoteRepository( ) throws Exception - { - BasicRemoteRepository remoteRepository = new BasicRemoteRepository( "test001", "Test repo" ); - remoteRepository.setDescription( remoteRepository.getPrimaryLocale(), "This is just a test" ); - RemoteRepository newRepo = repositoryRegistry.putRepository(remoteRepository); - - assertTrue(remoteRepository==newRepo); - assertNotNull(remoteRepository.getContent()); - assertEquals(6, repositoryRegistry.getRepositories().size()); - - remoteRepository = new BasicRemoteRepository( "internal", "Test repo" ); - remoteRepository.setDescription( remoteRepository.getPrimaryLocale(), "This is just a test" ); - RemoteRepository updatedRepo = null; - try - { - updatedRepo = repositoryRegistry.putRepository( remoteRepository ); - throw new RuntimeException("Should throw repository exception, if repository exists already and is not the same type."); - } catch (RepositoryException e) { - // OK - } - - remoteRepository = new BasicRemoteRepository( "central", "Test repo" ); - remoteRepository.setDescription( remoteRepository.getPrimaryLocale(), "This is just a test" ); - updatedRepo = repositoryRegistry.putRepository( remoteRepository ); - - assertTrue(updatedRepo==remoteRepository); - assertNotNull(remoteRepository.getContent()); - assertEquals(6, repositoryRegistry.getRepositories().size()); - RemoteRepository remoteRepository1 = repositoryRegistry.getRemoteRepository( "central" ); - assertEquals("Test repo", remoteRepository1.getName()); - assertTrue(remoteRepository1==remoteRepository); - } - - @Test - public void putRemoteRepositoryFromConfig( ) throws Exception - { - RemoteRepositoryConfiguration cfg = new RemoteRepositoryConfiguration(); - cfg.setId("test002"); - cfg.setName("This is test 002"); - RemoteRepository repo = repositoryRegistry.putRepository( cfg ); - assertNotNull(repo); - assertEquals("test002", repo.getId()); - assertEquals("This is test 002", repo.getName()); - assertNotNull(repo.getContent()); - archivaConfiguration.reload(); - Collection repos = repositoryRegistry.getRemoteRepositories(); - assertEquals(2, repos.size()); - - RemoteRepository internalRepo = repositoryRegistry.getRemoteRepository( "central" ); - cfg = new RemoteRepositoryConfiguration(); - cfg.setId("central"); - cfg.setName("This is central test 002"); - repo = repositoryRegistry.putRepository( cfg ); - assertTrue(internalRepo==repo); - assertEquals("This is central test 002",repo.getName()); - assertEquals(2, repositoryRegistry.getRemoteRepositories().size()); - - repositoryRegistry.reload(); - assertEquals(2, repositoryRegistry.getRemoteRepositories().size()); - } - - @Test - public void putRemoteRepositoryFromConfigWithoutSave( ) throws Exception - { - Configuration configuration = archivaConfiguration.getConfiguration(); - RemoteRepositoryConfiguration cfg = new RemoteRepositoryConfiguration(); - cfg.setId("test002"); - cfg.setName("This is test 002"); - RemoteRepository repo = repositoryRegistry.putRepository( cfg, configuration ); - assertNotNull(repo); - assertEquals("test002", repo.getId()); - assertEquals("This is test 002", repo.getName()); - assertNotNull(repo.getContent()); - archivaConfiguration.reload(); - assertEquals(1, archivaConfiguration.getConfiguration().getRemoteRepositories().size()); - Collection repos = repositoryRegistry.getRemoteRepositories(); - assertEquals(2, repos.size()); - - RemoteRepository internalRepo = repositoryRegistry.getRemoteRepository( "central" ); - cfg = new RemoteRepositoryConfiguration(); - cfg.setId("central"); - cfg.setName("This is central test 002"); - repo = repositoryRegistry.putRepository( cfg, configuration ); - assertTrue(internalRepo==repo); - assertEquals("This is central test 002",repo.getName()); - assertEquals(2, repositoryRegistry.getRemoteRepositories().size()); - - repositoryRegistry.reload(); - assertEquals(1, repositoryRegistry.getRemoteRepositories().size()); - } - - @Test - public void removeRepository( ) throws Exception - { - assertEquals(5, repositoryRegistry.getRepositories().size()); - Repository repo = repositoryRegistry.getRepository( "snapshots" ); - repositoryRegistry.removeRepository( repo ); - assertEquals(4, repositoryRegistry.getRepositories().size()); - assertTrue( repositoryRegistry.getRepositories( ).stream( ).noneMatch( rep -> rep.getId( ).equals( "snapshots" ) ) ); - archivaConfiguration.reload(); - repositoryRegistry.reload(); - assertEquals(4, repositoryRegistry.getRepositories().size()); - } - - @Test - public void removeManagedRepository( ) throws Exception - { - - assertEquals(4, repositoryRegistry.getManagedRepositories().size()); - ManagedRepository repo = repositoryRegistry.getManagedRepository( "snapshots" ); - repositoryRegistry.removeRepository( repo ); - assertEquals(3, repositoryRegistry.getManagedRepositories().size()); - assertTrue( repositoryRegistry.getManagedRepositories( ).stream( ).noneMatch( rep -> rep.getId( ).equals( "snapshots" ) ) ); - archivaConfiguration.reload(); - repositoryRegistry.reload(); - assertEquals(3, repositoryRegistry.getManagedRepositories().size()); - } - - @Test - public void removeManagedRepositoryWithoutSave( ) throws Exception - { - Configuration configuration = archivaConfiguration.getConfiguration(); - assertEquals(4, repositoryRegistry.getManagedRepositories().size()); - ManagedRepository repo = repositoryRegistry.getManagedRepository( "snapshots" ); - repositoryRegistry.removeRepository( repo, configuration ); - assertEquals(3, repositoryRegistry.getManagedRepositories().size()); - assertTrue( repositoryRegistry.getManagedRepositories( ).stream( ).noneMatch( rep -> rep.getId( ).equals( "snapshots" ) ) ); - archivaConfiguration.reload(); - repositoryRegistry.reload(); - assertEquals(4, repositoryRegistry.getManagedRepositories().size()); - } - - - @Test - public void removeRemoteRepository( ) throws Exception - { - assertEquals(1, repositoryRegistry.getRemoteRepositories().size()); - RemoteRepository repo = repositoryRegistry.getRemoteRepository( "central" ); - repositoryRegistry.removeRepository( repo ); - assertEquals(0, repositoryRegistry.getRemoteRepositories().size()); - assertTrue( repositoryRegistry.getRemoteRepositories( ).stream( ).noneMatch( rep -> rep.getId( ).equals( "central" ) ) ); - archivaConfiguration.reload(); - repositoryRegistry.reload(); - assertEquals(0, repositoryRegistry.getRemoteRepositories().size()); - } - - @Test - public void removeRemoteRepositoryWithoutSave( ) throws Exception - { - Configuration configuration = archivaConfiguration.getConfiguration(); - assertEquals(1, repositoryRegistry.getRemoteRepositories().size()); - RemoteRepository repo = repositoryRegistry.getRemoteRepository( "central" ); - repositoryRegistry.removeRepository( repo, configuration ); - assertEquals(0, repositoryRegistry.getRemoteRepositories().size()); - assertTrue( repositoryRegistry.getRemoteRepositories( ).stream( ).noneMatch( rep -> rep.getId( ).equals( "central" ) ) ); - archivaConfiguration.reload(); - repositoryRegistry.reload(); - assertEquals(1, repositoryRegistry.getRemoteRepositories().size()); - } - - - @Test - public void cloneManagedRepo( ) throws Exception - { - ManagedRepository managedRepository = repositoryRegistry.getManagedRepository( "internal" ); - - try - { - repositoryRegistry.clone(managedRepository, "snapshots"); - throw new RuntimeException("RepositoryRegistry exception should be thrown if id exists already."); - } - catch ( RepositoryException e ) - { - // OK - } - - try - { - repositoryRegistry.clone(managedRepository, "central"); - throw new RuntimeException("RepositoryRegistry exception should be thrown if id exists already."); - } - catch ( RepositoryException e ) - { - // OK - } - - ManagedRepository clone = repositoryRegistry.clone( managedRepository, "newinternal" ); - assertNotNull(clone); - assertNull(clone.getContent()); - assertEquals("Archiva Managed Internal Repository", clone.getName()); - assertFalse(managedRepository==clone); - - } - - @Test - public void cloneRemoteRepo( ) throws Exception - { - RemoteRepository remoteRepository = repositoryRegistry.getRemoteRepository( "central" ); - - try - { - repositoryRegistry.clone(remoteRepository, "snapshots"); - throw new RuntimeException("RepositoryRegistry exception should be thrown if id exists already."); - } - catch ( RepositoryException e ) - { - // OK - } - - try - { - repositoryRegistry.clone(remoteRepository, "central"); - throw new RuntimeException("RepositoryRegistry exception should be thrown if id exists already."); - } - catch ( RepositoryException e ) - { - // OK - } - - RemoteRepository clone = repositoryRegistry.clone( remoteRepository, "newCentral" ); - assertNotNull(clone); - assertNull(clone.getContent()); - assertEquals("Central Repository", clone.getName()); - assertFalse(remoteRepository==clone); - - } - -} \ No newline at end of file diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java deleted file mode 100644 index 1fb613335..000000000 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java +++ /dev/null @@ -1,169 +0,0 @@ -package org.apache.archiva.repository.mock; - -/* - * 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.model.ArchivaArtifact; -import org.apache.archiva.model.ArtifactReference; -import org.apache.archiva.model.ProjectReference; -import org.apache.archiva.model.VersionedReference; -import org.apache.archiva.repository.ContentNotFoundException; -import org.apache.archiva.repository.ManagedRepository; -import org.apache.archiva.repository.ManagedRepositoryContent; -import org.apache.archiva.repository.RepositoryException; -import org.apache.archiva.repository.layout.LayoutException; -import org.springframework.stereotype.Service; - -import java.nio.file.Path; -import java.util.Set; - -/** - * @author Martin Stockhammer - */ -@Service("managedRepositoryContent#mock") -public class ManagedRepositoryContentMock implements ManagedRepositoryContent -{ - private ManagedRepository repository; - - @Override - public void deleteVersion( VersionedReference reference ) throws ContentNotFoundException - { - - } - - @Override - public void deleteArtifact( ArtifactReference artifactReference ) throws ContentNotFoundException - { - - } - - @Override - public void deleteGroupId( String groupId ) throws ContentNotFoundException - { - - } - - @Override - public void deleteProject( String namespace, String projectId ) throws RepositoryException - { - - } - - @Override - public String getId( ) - { - return null; - } - - @Override - public Set getRelatedArtifacts( ArtifactReference reference ) throws ContentNotFoundException - { - return null; - } - - @Override - public String getRepoRoot( ) - { - return null; - } - - @Override - public ManagedRepository getRepository( ) - { - return repository; - } - - @Override - public Set getVersions( ProjectReference reference ) throws ContentNotFoundException, LayoutException - { - return null; - } - - @Override - public Set getVersions( VersionedReference reference ) throws ContentNotFoundException - { - return null; - } - - @Override - public boolean hasContent( ArtifactReference reference ) - { - return false; - } - - @Override - public boolean hasContent( ProjectReference reference ) - { - return false; - } - - @Override - public boolean hasContent( VersionedReference reference ) - { - return false; - } - - @Override - public void setRepository( ManagedRepository repo ) - { - this.repository = repo; - } - - @Override - public ArtifactReference toArtifactReference( String path ) throws LayoutException - { - return null; - } - - @Override - public Path toFile( ArtifactReference reference ) - { - return null; - } - - @Override - public Path toFile( ArchivaArtifact reference ) - { - return null; - } - - @Override - public String toMetadataPath( ProjectReference reference ) - { - return null; - } - - @Override - public String toMetadataPath( VersionedReference reference ) - { - return null; - } - - @Override - public String toPath( ArtifactReference reference ) - { - return null; - } - - @Override - public String toPath( ArchivaArtifact reference ) - { - return null; - } -} diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/test/java/org/apache/archiva/repository/mock/RemoteRepositoryContentMock.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/test/java/org/apache/archiva/repository/mock/RemoteRepositoryContentMock.java deleted file mode 100644 index 238b0cf61..000000000 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/test/java/org/apache/archiva/repository/mock/RemoteRepositoryContentMock.java +++ /dev/null @@ -1,78 +0,0 @@ -package org.apache.archiva.repository.mock; - -/* - * 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.model.ArtifactReference; -import org.apache.archiva.model.RepositoryURL; -import org.apache.archiva.repository.RemoteRepository; -import org.apache.archiva.repository.RemoteRepositoryContent; -import org.apache.archiva.repository.layout.LayoutException; -import org.springframework.stereotype.Service; - -/** - * @author Martin Stockhammer - */ -@Service("remoteRepositoryContent#mock") -public class RemoteRepositoryContentMock implements RemoteRepositoryContent -{ - RemoteRepository repository; - - @Override - public String getId( ) - { - return null; - } - - @Override - public RemoteRepository getRepository( ) - { - return null; - } - - @Override - public RepositoryURL getURL( ) - { - return null; - } - - @Override - public void setRepository( RemoteRepository repo ) - { - this.repository = repo; - } - - @Override - public ArtifactReference toArtifactReference( String path ) throws LayoutException - { - return null; - } - - @Override - public String toPath( ArtifactReference reference ) - { - return null; - } - - @Override - public RepositoryURL toURL( ArtifactReference reference ) - { - return null; - } -} diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/test/java/org/apache/archiva/repository/mock/RepositoryProviderMock.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/test/java/org/apache/archiva/repository/mock/RepositoryProviderMock.java deleted file mode 100644 index 834ce5ba2..000000000 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/test/java/org/apache/archiva/repository/mock/RepositoryProviderMock.java +++ /dev/null @@ -1,231 +0,0 @@ -package org.apache.archiva.repository.mock; - -/* - * 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.configuration.ManagedRepositoryConfiguration; -import org.apache.archiva.configuration.RemoteRepositoryConfiguration; -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.ManagedRepository; -import org.apache.archiva.repository.PasswordCredentials; -import org.apache.archiva.repository.ReleaseScheme; -import org.apache.archiva.repository.RemoteRepository; -import org.apache.archiva.repository.RepositoryCredentials; -import org.apache.archiva.repository.RepositoryException; -import org.apache.archiva.repository.RepositoryProvider; -import org.apache.archiva.repository.RepositoryType; -import org.apache.archiva.repository.features.ArtifactCleanupFeature; -import org.apache.archiva.repository.features.IndexCreationFeature; -import org.apache.archiva.repository.features.RemoteIndexFeature; -import org.apache.archiva.repository.features.StagingRepositoryFeature; -import org.springframework.stereotype.Service; - -import java.net.URI; -import java.time.Duration; -import java.time.Period; -import java.util.HashSet; -import java.util.Set; - -/** - * Just a simple mock class for the repository provider - */ -@Service("mockRepositoryProvider") -public class RepositoryProviderMock implements RepositoryProvider -{ - - private static final Set TYPES = new HashSet<>( ); - - static - { - TYPES.add( RepositoryType.MAVEN ); - TYPES.add( RepositoryType.NPM ); - } - - @Override - public Set provides( ) - { - return TYPES; - } - - @Override - public EditableManagedRepository createManagedInstance( String id, String name ) - { - return new BasicManagedRepository( id, name ); - } - - @Override - public EditableRemoteRepository createRemoteInstance( String id, String name ) - { - return new BasicRemoteRepository( id, name ); - } - - @Override - public ManagedRepository createManagedInstance( ManagedRepositoryConfiguration configuration ) throws RepositoryException - { - BasicManagedRepository managedRepository = new BasicManagedRepository( configuration.getId( ), configuration.getName( ) ); - updateManagedInstance( managedRepository, configuration ); - return managedRepository; - } - - - @Override - public void updateManagedInstance( EditableManagedRepository managedRepository, ManagedRepositoryConfiguration configuration ) throws RepositoryException - { - try - { - managedRepository.setName( managedRepository.getPrimaryLocale(), configuration.getName( ) ); - managedRepository.setLocation( new URI( configuration.getLocation( )==null ?"" : configuration.getLocation() ) ); - managedRepository.setBaseUri( new URI( "" ) ); - managedRepository.setBlocksRedeployment( configuration.isBlockRedeployments( ) ); - managedRepository.setDescription( managedRepository.getPrimaryLocale(), configuration.getDescription( ) ); - managedRepository.setLayout( configuration.getLayout( ) ); - managedRepository.setScanned( configuration.isScanned( ) ); - managedRepository.setSchedulingDefinition( configuration.getRefreshCronExpression( ) ); - if (configuration.isReleases()) { - managedRepository.addActiveReleaseScheme( ReleaseScheme.RELEASE ); - } - if (configuration.isSnapshots()) { - managedRepository.addActiveReleaseScheme( ReleaseScheme.SNAPSHOT ); - } - ArtifactCleanupFeature acf = managedRepository.getFeature( ArtifactCleanupFeature.class ).get( ); - acf.setRetentionPeriod( Period.ofDays( configuration.getRetentionPeriod( ) ) ); - acf.setDeleteReleasedSnapshots( configuration.isDeleteReleasedSnapshots( ) ); - acf.setRetentionCount( configuration.getRetentionCount( ) ); - IndexCreationFeature icf = managedRepository.getFeature( IndexCreationFeature.class ).get( ); - icf.setIndexPath( new URI( configuration.getIndexDir( ) ) ); - icf.setSkipPackedIndexCreation( configuration.isSkipPackedIndexCreation( ) ); - StagingRepositoryFeature srf = managedRepository.getFeature( StagingRepositoryFeature.class ).get( ); - srf.setStageRepoNeeded( configuration.isStageRepoNeeded( ) ); - } - catch ( Exception e ) - { - throw new RepositoryException( "Error", e ); - } - - } - - - @Override - public ManagedRepository createStagingInstance( ManagedRepositoryConfiguration configuration ) throws RepositoryException - { - String id = configuration.getId( ) + StagingRepositoryFeature.STAGING_REPO_POSTFIX; - BasicManagedRepository managedRepository = new BasicManagedRepository( id, configuration.getName( ) ); - updateManagedInstance( managedRepository, configuration ); - return managedRepository; - } - - @Override - public RemoteRepository createRemoteInstance( RemoteRepositoryConfiguration configuration ) throws RepositoryException - { - BasicRemoteRepository remoteRepository = new BasicRemoteRepository( configuration.getId( ), configuration.getName( ) ); - updateRemoteInstance( remoteRepository, configuration ); - return remoteRepository; - } - - @Override - public void updateRemoteInstance( EditableRemoteRepository remoteRepository, RemoteRepositoryConfiguration configuration ) throws RepositoryException - { - try - { - remoteRepository.setName( remoteRepository.getPrimaryLocale(), configuration.getName( ) ); - remoteRepository.setBaseUri( new URI( "" ) ); - remoteRepository.setDescription( remoteRepository.getPrimaryLocale(), configuration.getDescription( ) ); - remoteRepository.setLayout( configuration.getLayout( ) ); - remoteRepository.setSchedulingDefinition( configuration.getRefreshCronExpression( ) ); - remoteRepository.setCheckPath( configuration.getCheckPath( ) ); - remoteRepository.setExtraHeaders( configuration.getExtraHeaders( ) ); - remoteRepository.setExtraParameters( configuration.getExtraParameters( ) ); - remoteRepository.setTimeout( Duration.ofSeconds( configuration.getTimeout( ) ) ); - char[] pwd = configuration.getPassword()==null ? "".toCharArray() : configuration.getPassword().toCharArray(); - remoteRepository.setCredentials( new PasswordCredentials( configuration.getUsername( ), pwd ) ); - remoteRepository.setLocation( new URI( configuration.getUrl( )==null ? "" : configuration.getUrl() ) ); - RemoteIndexFeature rif = remoteRepository.getFeature( RemoteIndexFeature.class ).get( ); - rif.setDownloadRemoteIndexOnStartup( configuration.isDownloadRemoteIndexOnStartup( ) ); - rif.setDownloadRemoteIndex( configuration.isDownloadRemoteIndex( ) ); - rif.setIndexUri( new URI( configuration.getIndexDir( ) ) ); - rif.setDownloadTimeout( Duration.ofSeconds( configuration.getRemoteDownloadTimeout( ) ) ); - rif.setProxyId( configuration.getRemoteDownloadNetworkProxyId( ) ); - } - catch ( Exception e ) - { - throw new RepositoryException( "Error", e ); - } - - } - - @Override - public ManagedRepositoryConfiguration getManagedConfiguration( ManagedRepository managedRepository ) throws RepositoryException - { - ManagedRepositoryConfiguration configuration = new ManagedRepositoryConfiguration( ); - configuration.setId( managedRepository.getId( ) ); - configuration.setName(managedRepository.getName()); - configuration.setLocation( managedRepository.getLocation( ) == null ? "" : managedRepository.getLocation().toString( ) ); - configuration.setBlockRedeployments( managedRepository.blocksRedeployments( ) ); - configuration.setDescription( managedRepository.getDescription( ) ); - configuration.setLayout( managedRepository.getLayout( ) ); - configuration.setScanned( managedRepository.isScanned( ) ); - configuration.setRefreshCronExpression( managedRepository.getSchedulingDefinition( ) ); - configuration.setReleases( managedRepository.getActiveReleaseSchemes().contains(ReleaseScheme.RELEASE) ); - configuration.setSnapshots( managedRepository.getActiveReleaseSchemes().contains(ReleaseScheme.SNAPSHOT) ); - ArtifactCleanupFeature acf = managedRepository.getFeature( ArtifactCleanupFeature.class ).get( ); - configuration.setRetentionPeriod( acf.getRetentionPeriod( ).getDays( ) ); - configuration.setDeleteReleasedSnapshots( acf.isDeleteReleasedSnapshots( ) ); - configuration.setRetentionCount( acf.getRetentionCount( ) ); - IndexCreationFeature icf = managedRepository.getFeature( IndexCreationFeature.class ).get( ); - configuration.setSkipPackedIndexCreation( icf.isSkipPackedIndexCreation( ) ); - configuration.setIndexDir( icf.getIndexPath( ) == null ? "" : icf.getIndexPath().toString( ) ); - StagingRepositoryFeature srf = managedRepository.getFeature( StagingRepositoryFeature.class ).get( ); - configuration.setStageRepoNeeded( srf.isStageRepoNeeded( ) ); - return configuration; - } - - - @Override - public RemoteRepositoryConfiguration getRemoteConfiguration( RemoteRepository remoteRepository ) throws RepositoryException - { - RemoteRepositoryConfiguration configuration = new RemoteRepositoryConfiguration( ); - configuration.setId( remoteRepository.getId( ) ); - configuration.setName( remoteRepository.getName( ) ); - configuration.setDescription( remoteRepository.getDescription( ) ); - configuration.setLayout( remoteRepository.getLayout( ) ); - configuration.setRefreshCronExpression( remoteRepository.getSchedulingDefinition( ) ); - configuration.setCheckPath( remoteRepository.getCheckPath( ) ); - configuration.setExtraHeaders( remoteRepository.getExtraHeaders( ) ); - configuration.setExtraParameters( remoteRepository.getExtraParameters( ) ); - configuration.setTimeout( (int) remoteRepository.getTimeout( ).getSeconds( ) ); - RepositoryCredentials creds = remoteRepository.getLoginCredentials( ); - if (creds!=null) - { - PasswordCredentials pwdCreds = (PasswordCredentials) creds; - configuration.setUsername( pwdCreds.getUsername( ) ); - configuration.setPassword( new String( pwdCreds.getPassword( ) ) ); - } - configuration.setUrl( remoteRepository.getLocation( ) == null ? "" : remoteRepository.getLocation().toString( ) ); - RemoteIndexFeature rif = remoteRepository.getFeature( RemoteIndexFeature.class ).get( ); - configuration.setDownloadRemoteIndex( rif.isDownloadRemoteIndex( ) ); - configuration.setDownloadRemoteIndexOnStartup( rif.isDownloadRemoteIndexOnStartup( ) ); - configuration.setIndexDir( rif.getIndexUri( )==null ? "" : rif.getIndexUri().toString( ) ); - configuration.setRemoteDownloadNetworkProxyId( rif.getProxyId( ) ); - return configuration; - } - -} diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/test/resources/archiva.xml b/archiva-modules/archiva-base/archiva-repository-layer/src/main/test/resources/archiva.xml deleted file mode 100644 index 308c673b7..000000000 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/test/resources/archiva.xml +++ /dev/null @@ -1,202 +0,0 @@ - - - - 3.0.0 - - - internal - Archiva Managed Internal Repository - This is internal repository. - ${appserver.base}/repositories/internal - ${appserver.base}/repositories/internal/.indexer - default - true - false - true - true - 0 0 * * * ? - 30 - - - staging - Repository with staging - This is repository with staging. - ${appserver.base}/repositories/internal - ${appserver.base}/repositories/internal/.indexer - default - true - false - true - true - 0 0 * * * ? - 30 - true - - - snapshots - Archiva Managed Snapshot Repository - ${appserver.base}/repositories/snapshots - ${appserver.base}/repositories/snapshots/.indexer - default - false - true - false - true - 0 0\,30 * * * ? - 30 - - - - - central - Central Repository - https://repo.maven.apache.org/maven2 - default - 35 - - - - - - internal - central - - - disabled - once - fix - cached - - - **/* - - - - - - - jaxen/jars/jaxen-1.0-FCS-full.jar - jaxen:jaxen:1.0-FCS:full:jar - - - - - - - artifacts - - **/*.pom - **/*.jar - **/*.ear - **/*.war - **/*.car - **/*.sar - **/*.mar - **/*.rar - **/*.dtd - **/*.tld - **/*.tar.gz - **/*.tar.bz2 - **/*.zip - - - - indexable-content - - **/*.txt - **/*.TXT - **/*.block - **/*.config - **/*.pom - **/*.xml - **/*.xsd - **/*.dtd - **/*.tld - - - - auto-remove - - **/*.bak - **/*~ - **/*- - - - - ignored - - **/.htaccess - **/KEYS - **/*.rb - **/*.sh - **/.svn/** - **/.DAV/** - .index/** - .indexer/** - - - - - create-missing-checksums - validate-checksum - validate-signature - index-content - auto-remove - auto-rename - metadata-updater - create-archiva-metadata - duplicate-artifacts - - - - update-db-bad-content - - - - - - true - true - - - - - - jpa - - - cached - - - - - - - http://download.oracle.com/maven - com/sleepycat/je/license.txt - - - https://download.oracle.com/maven - com/sleepycat/je/license.txt - - - - - diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/test/resources/log4j2-test.xml b/archiva-modules/archiva-base/archiva-repository-layer/src/main/test/resources/log4j2-test.xml deleted file mode 100644 index 3919a985f..000000000 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/test/resources/log4j2-test.xml +++ /dev/null @@ -1,45 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/test/resources/spring-context.xml b/archiva-modules/archiva-base/archiva-repository-layer/src/main/test/resources/spring-context.xml deleted file mode 100644 index 2b7748f3c..000000000 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/test/resources/spring-context.xml +++ /dev/null @@ -1,53 +0,0 @@ - - - - - - - - - - - - - - - - - ]]> - - - - - - \ No newline at end of file diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/RepositoryRegistryTest.java b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/RepositoryRegistryTest.java new file mode 100644 index 000000000..01dcbd253 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/RepositoryRegistryTest.java @@ -0,0 +1,511 @@ +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. + */ + +import org.apache.archiva.configuration.ArchivaConfiguration; +import org.apache.archiva.configuration.Configuration; +import org.apache.archiva.configuration.ManagedRepositoryConfiguration; +import org.apache.archiva.configuration.RemoteRepositoryConfiguration; +import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.test.context.ContextConfiguration; + +import javax.inject.Inject; +import java.io.IOException; +import java.net.URISyntaxException; +import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; +import java.util.Collection; + +import static org.junit.Assert.*; + +/** + * Test for RepositoryRegistry + */ +@RunWith(ArchivaSpringJUnit4ClassRunner.class) +@ContextConfiguration(locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" }) +public class RepositoryRegistryTest +{ + + @Inject + RepositoryRegistry repositoryRegistry; + + @Inject + ArchivaConfiguration archivaConfiguration; + + private static final Path userCfg = Paths.get(System.getProperty( "user.home" ), ".m2/archiva.xml"); + + private static Path cfgCopy; + private static Path archivaCfg; + + @BeforeClass + public static void classSetup() throws IOException, URISyntaxException + { + URL archivaCfgUri = Thread.currentThread().getContextClassLoader().getResource( "archiva.xml" ); + if (archivaCfgUri!=null) { + archivaCfg = Paths.get(archivaCfgUri.toURI()); + cfgCopy = Files.createTempFile( "archiva-backup", ".xml" ); + Files.copy( archivaCfg, cfgCopy, StandardCopyOption.REPLACE_EXISTING); + } + } + + @AfterClass + public static void classTearDown() throws IOException + { + if (cfgCopy!=null) { + Files.deleteIfExists( cfgCopy ); + } + } + + @Before + public void setUp( ) throws Exception + { + assertNotNull( repositoryRegistry ); + Files.deleteIfExists( userCfg ); + URL archivaCfgUri = Thread.currentThread().getContextClassLoader().getResource( "archiva.xml" ); + if (archivaCfgUri!=null) { + archivaCfg = Paths.get(archivaCfgUri.toURI()); + if (Files.exists(cfgCopy)) + { + Files.copy( cfgCopy, archivaCfg , StandardCopyOption.REPLACE_EXISTING); + } + } + archivaConfiguration.reload(); + repositoryRegistry.reload(); + } + + @After + public void tearDown( ) throws Exception + { + Files.deleteIfExists( userCfg ); + if (cfgCopy!=null && Files.exists(cfgCopy)) { + Files.copy(cfgCopy, archivaCfg, StandardCopyOption.REPLACE_EXISTING); + } + } + + @Test + public void getRepositories( ) throws Exception + { + Collection repos = repositoryRegistry.getRepositories( ); + assertEquals( 5, repos.size( ) ); + assertTrue(repos.stream().anyMatch( rep -> rep.getId().equals("internal") )); + assertTrue( repos.stream( ).anyMatch( rep -> rep.getId( ).equals( "snapshots") ) ); + assertTrue(repos.stream().anyMatch( rep -> rep.getId().equals( "central") )); + } + + @Test + public void getManagedRepositories( ) throws Exception + { + Collection repos = repositoryRegistry.getManagedRepositories(); + assertEquals( 4, repos.size( ) ); + assertTrue(repos.stream().anyMatch( rep -> rep.getId().equals("internal") )); + assertTrue( repos.stream( ).anyMatch( rep -> rep.getId( ).equals( "snapshots") ) ); + } + + @Test + public void getRemoteRepositories( ) throws Exception + { + Collection repos = repositoryRegistry.getRemoteRepositories( ); + assertEquals( 1, repos.size( ) ); + assertTrue(repos.stream().anyMatch( rep -> rep.getId().equals( "central") )); + } + + @Test + public void getRepository( ) throws Exception + { + Repository repo = repositoryRegistry.getRepository( "internal" ); + assertNotNull(repo); + assertEquals("internal", repo.getId()); + assertEquals("Archiva Managed Internal Repository", repo.getName()); + assertEquals("This is internal repository.", repo.getDescription()); + assertEquals( "default", repo.getLayout( ) ); + assertEquals("0 0 * * * ?", repo.getSchedulingDefinition()); + assertTrue(repo instanceof ManagedRepository); + assertTrue( repo.hasIndex( ) ); + assertTrue(repo.isScanned()); + assertEquals(RepositoryType.MAVEN, repo.getType()); + } + + @Test + public void getManagedRepository( ) throws Exception + { + ManagedRepository repo = repositoryRegistry.getManagedRepository( "internal" ); + assertNotNull(repo); + assertEquals("internal", repo.getId()); + assertEquals("Archiva Managed Internal Repository", repo.getName()); + assertEquals("This is internal repository.", repo.getDescription()); + assertEquals( "default", repo.getLayout( ) ); + assertEquals("0 0 * * * ?", repo.getSchedulingDefinition()); + assertTrue( repo.hasIndex( ) ); + assertTrue(repo.isScanned()); + assertEquals(RepositoryType.MAVEN, repo.getType()); + assertTrue(repo.getActiveReleaseSchemes().contains(ReleaseScheme.RELEASE)); + assertFalse( repo.getActiveReleaseSchemes( ).contains( ReleaseScheme.SNAPSHOT ) ); + assertNotNull(repo.getContent()); + + assertNull(repositoryRegistry.getManagedRepository( "xyu" )); + + } + + @Test + public void getRemoteRepository( ) throws Exception + { + RemoteRepository repo = repositoryRegistry.getRemoteRepository( "central" ); + assertNotNull(repo); + assertEquals("central", repo.getId()); + assertEquals("Central Repository", repo.getName()); + assertEquals("", repo.getDescription()); + assertEquals( "default", repo.getLayout( ) ); + assertEquals("0 0 08 ? * SUN", repo.getSchedulingDefinition()); + assertTrue( repo.hasIndex( ) ); + assertTrue(repo.isScanned()); + assertEquals(RepositoryType.MAVEN, repo.getType()); + + assertEquals(35, repo.getTimeout().getSeconds()); + } + + @Test + public void putManagedRepository( ) throws Exception + { + BasicManagedRepository managedRepository = new BasicManagedRepository( "test001", "Test repo" ); + managedRepository.setDescription( managedRepository.getPrimaryLocale(), "This is just a test" ); + repositoryRegistry.putRepository(managedRepository); + + assertNotNull(managedRepository.getContent()); + assertEquals(6, repositoryRegistry.getRepositories().size()); + + managedRepository = new BasicManagedRepository( "central", "Test repo" ); + managedRepository.setDescription( managedRepository.getPrimaryLocale(), "This is just a test" ); + ManagedRepository updatedRepo = null; + try { + repositoryRegistry.putRepository( managedRepository ); + throw new RuntimeException("Repository exception should be thrown, if there exists a remote repository already with that id"); + } catch (RepositoryException e) { + // OK + } + managedRepository = new BasicManagedRepository( "internal", "Test repo" ); + managedRepository.setDescription( managedRepository.getPrimaryLocale(), "This is just a test" ); + updatedRepo = repositoryRegistry.putRepository( managedRepository ); + + assertTrue(updatedRepo==managedRepository); + assertNotNull(managedRepository.getContent()); + assertEquals(6, repositoryRegistry.getRepositories().size()); + ManagedRepository managedRepository1 = repositoryRegistry.getManagedRepository( "internal" ); + assertEquals("Test repo", managedRepository1.getName()); + assertTrue(managedRepository1==managedRepository); + + } + + @Test + public void putManagedRepositoryFromConfig( ) throws Exception + { + ManagedRepositoryConfiguration cfg = new ManagedRepositoryConfiguration(); + cfg.setId("test002"); + cfg.setName("This is test 002"); + ManagedRepository repo = repositoryRegistry.putRepository( cfg ); + assertNotNull(repo); + assertEquals("test002", repo.getId()); + assertEquals("This is test 002", repo.getName()); + assertNotNull(repo.getContent()); + archivaConfiguration.reload(); + Collection repos = repositoryRegistry.getManagedRepositories(); + assertEquals(5, repos.size()); + + ManagedRepository internalRepo = repositoryRegistry.getManagedRepository( "internal" ); + cfg = new ManagedRepositoryConfiguration(); + cfg.setId("internal"); + cfg.setName("This is internal test 002"); + repo = repositoryRegistry.putRepository( cfg ); + assertTrue(internalRepo==repo); + assertEquals("This is internal test 002",repo.getName()); + assertEquals(5, repositoryRegistry.getManagedRepositories().size()); + + repositoryRegistry.reload(); + assertEquals(5, repositoryRegistry.getManagedRepositories().size()); + + } + + @Test + public void putManagedRepositoryFromConfigWithoutSave( ) throws Exception + { + Configuration configuration = archivaConfiguration.getConfiguration(); + ManagedRepositoryConfiguration cfg = new ManagedRepositoryConfiguration(); + cfg.setId("test002"); + cfg.setName("This is test 002"); + ManagedRepository repo = repositoryRegistry.putRepository( cfg, configuration ); + assertNotNull(repo); + assertEquals("test002", repo.getId()); + assertEquals("This is test 002", repo.getName()); + assertNotNull(repo.getContent()); + archivaConfiguration.reload(); + assertEquals(3, archivaConfiguration.getConfiguration().getManagedRepositories().size()); + Collection repos = repositoryRegistry.getManagedRepositories(); + assertEquals(5, repos.size()); + + ManagedRepository internalRepo = repositoryRegistry.getManagedRepository( "internal" ); + cfg = new ManagedRepositoryConfiguration(); + cfg.setId("internal"); + cfg.setName("This is internal test 002"); + repo = repositoryRegistry.putRepository( cfg, configuration ); + assertTrue(internalRepo==repo); + assertEquals("This is internal test 002",repo.getName()); + assertEquals(5, repositoryRegistry.getManagedRepositories().size()); + + repositoryRegistry.reload(); + assertEquals(4, repositoryRegistry.getManagedRepositories().size()); + } + + @Test + public void putRemoteRepository( ) throws Exception + { + BasicRemoteRepository remoteRepository = new BasicRemoteRepository( "test001", "Test repo" ); + remoteRepository.setDescription( remoteRepository.getPrimaryLocale(), "This is just a test" ); + RemoteRepository newRepo = repositoryRegistry.putRepository(remoteRepository); + + assertTrue(remoteRepository==newRepo); + assertNotNull(remoteRepository.getContent()); + assertEquals(6, repositoryRegistry.getRepositories().size()); + + remoteRepository = new BasicRemoteRepository( "internal", "Test repo" ); + remoteRepository.setDescription( remoteRepository.getPrimaryLocale(), "This is just a test" ); + RemoteRepository updatedRepo = null; + try + { + updatedRepo = repositoryRegistry.putRepository( remoteRepository ); + throw new RuntimeException("Should throw repository exception, if repository exists already and is not the same type."); + } catch (RepositoryException e) { + // OK + } + + remoteRepository = new BasicRemoteRepository( "central", "Test repo" ); + remoteRepository.setDescription( remoteRepository.getPrimaryLocale(), "This is just a test" ); + updatedRepo = repositoryRegistry.putRepository( remoteRepository ); + + assertTrue(updatedRepo==remoteRepository); + assertNotNull(remoteRepository.getContent()); + assertEquals(6, repositoryRegistry.getRepositories().size()); + RemoteRepository remoteRepository1 = repositoryRegistry.getRemoteRepository( "central" ); + assertEquals("Test repo", remoteRepository1.getName()); + assertTrue(remoteRepository1==remoteRepository); + } + + @Test + public void putRemoteRepositoryFromConfig( ) throws Exception + { + RemoteRepositoryConfiguration cfg = new RemoteRepositoryConfiguration(); + cfg.setId("test002"); + cfg.setName("This is test 002"); + RemoteRepository repo = repositoryRegistry.putRepository( cfg ); + assertNotNull(repo); + assertEquals("test002", repo.getId()); + assertEquals("This is test 002", repo.getName()); + assertNotNull(repo.getContent()); + archivaConfiguration.reload(); + Collection repos = repositoryRegistry.getRemoteRepositories(); + assertEquals(2, repos.size()); + + RemoteRepository internalRepo = repositoryRegistry.getRemoteRepository( "central" ); + cfg = new RemoteRepositoryConfiguration(); + cfg.setId("central"); + cfg.setName("This is central test 002"); + repo = repositoryRegistry.putRepository( cfg ); + assertTrue(internalRepo==repo); + assertEquals("This is central test 002",repo.getName()); + assertEquals(2, repositoryRegistry.getRemoteRepositories().size()); + + repositoryRegistry.reload(); + assertEquals(2, repositoryRegistry.getRemoteRepositories().size()); + } + + @Test + public void putRemoteRepositoryFromConfigWithoutSave( ) throws Exception + { + Configuration configuration = archivaConfiguration.getConfiguration(); + RemoteRepositoryConfiguration cfg = new RemoteRepositoryConfiguration(); + cfg.setId("test002"); + cfg.setName("This is test 002"); + RemoteRepository repo = repositoryRegistry.putRepository( cfg, configuration ); + assertNotNull(repo); + assertEquals("test002", repo.getId()); + assertEquals("This is test 002", repo.getName()); + assertNotNull(repo.getContent()); + archivaConfiguration.reload(); + assertEquals(1, archivaConfiguration.getConfiguration().getRemoteRepositories().size()); + Collection repos = repositoryRegistry.getRemoteRepositories(); + assertEquals(2, repos.size()); + + RemoteRepository internalRepo = repositoryRegistry.getRemoteRepository( "central" ); + cfg = new RemoteRepositoryConfiguration(); + cfg.setId("central"); + cfg.setName("This is central test 002"); + repo = repositoryRegistry.putRepository( cfg, configuration ); + assertTrue(internalRepo==repo); + assertEquals("This is central test 002",repo.getName()); + assertEquals(2, repositoryRegistry.getRemoteRepositories().size()); + + repositoryRegistry.reload(); + assertEquals(1, repositoryRegistry.getRemoteRepositories().size()); + } + + @Test + public void removeRepository( ) throws Exception + { + assertEquals(5, repositoryRegistry.getRepositories().size()); + Repository repo = repositoryRegistry.getRepository( "snapshots" ); + repositoryRegistry.removeRepository( repo ); + assertEquals(4, repositoryRegistry.getRepositories().size()); + assertTrue( repositoryRegistry.getRepositories( ).stream( ).noneMatch( rep -> rep.getId( ).equals( "snapshots" ) ) ); + archivaConfiguration.reload(); + repositoryRegistry.reload(); + assertEquals(4, repositoryRegistry.getRepositories().size()); + } + + @Test + public void removeManagedRepository( ) throws Exception + { + + assertEquals(4, repositoryRegistry.getManagedRepositories().size()); + ManagedRepository repo = repositoryRegistry.getManagedRepository( "snapshots" ); + repositoryRegistry.removeRepository( repo ); + assertEquals(3, repositoryRegistry.getManagedRepositories().size()); + assertTrue( repositoryRegistry.getManagedRepositories( ).stream( ).noneMatch( rep -> rep.getId( ).equals( "snapshots" ) ) ); + archivaConfiguration.reload(); + repositoryRegistry.reload(); + assertEquals(3, repositoryRegistry.getManagedRepositories().size()); + } + + @Test + public void removeManagedRepositoryWithoutSave( ) throws Exception + { + Configuration configuration = archivaConfiguration.getConfiguration(); + assertEquals(4, repositoryRegistry.getManagedRepositories().size()); + ManagedRepository repo = repositoryRegistry.getManagedRepository( "snapshots" ); + repositoryRegistry.removeRepository( repo, configuration ); + assertEquals(3, repositoryRegistry.getManagedRepositories().size()); + assertTrue( repositoryRegistry.getManagedRepositories( ).stream( ).noneMatch( rep -> rep.getId( ).equals( "snapshots" ) ) ); + archivaConfiguration.reload(); + repositoryRegistry.reload(); + assertEquals(4, repositoryRegistry.getManagedRepositories().size()); + } + + + @Test + public void removeRemoteRepository( ) throws Exception + { + assertEquals(1, repositoryRegistry.getRemoteRepositories().size()); + RemoteRepository repo = repositoryRegistry.getRemoteRepository( "central" ); + repositoryRegistry.removeRepository( repo ); + assertEquals(0, repositoryRegistry.getRemoteRepositories().size()); + assertTrue( repositoryRegistry.getRemoteRepositories( ).stream( ).noneMatch( rep -> rep.getId( ).equals( "central" ) ) ); + archivaConfiguration.reload(); + repositoryRegistry.reload(); + assertEquals(0, repositoryRegistry.getRemoteRepositories().size()); + } + + @Test + public void removeRemoteRepositoryWithoutSave( ) throws Exception + { + Configuration configuration = archivaConfiguration.getConfiguration(); + assertEquals(1, repositoryRegistry.getRemoteRepositories().size()); + RemoteRepository repo = repositoryRegistry.getRemoteRepository( "central" ); + repositoryRegistry.removeRepository( repo, configuration ); + assertEquals(0, repositoryRegistry.getRemoteRepositories().size()); + assertTrue( repositoryRegistry.getRemoteRepositories( ).stream( ).noneMatch( rep -> rep.getId( ).equals( "central" ) ) ); + archivaConfiguration.reload(); + repositoryRegistry.reload(); + assertEquals(1, repositoryRegistry.getRemoteRepositories().size()); + } + + + @Test + public void cloneManagedRepo( ) throws Exception + { + ManagedRepository managedRepository = repositoryRegistry.getManagedRepository( "internal" ); + + try + { + repositoryRegistry.clone(managedRepository, "snapshots"); + throw new RuntimeException("RepositoryRegistry exception should be thrown if id exists already."); + } + catch ( RepositoryException e ) + { + // OK + } + + try + { + repositoryRegistry.clone(managedRepository, "central"); + throw new RuntimeException("RepositoryRegistry exception should be thrown if id exists already."); + } + catch ( RepositoryException e ) + { + // OK + } + + ManagedRepository clone = repositoryRegistry.clone( managedRepository, "newinternal" ); + assertNotNull(clone); + assertNull(clone.getContent()); + assertEquals("Archiva Managed Internal Repository", clone.getName()); + assertFalse(managedRepository==clone); + + } + + @Test + public void cloneRemoteRepo( ) throws Exception + { + RemoteRepository remoteRepository = repositoryRegistry.getRemoteRepository( "central" ); + + try + { + repositoryRegistry.clone(remoteRepository, "snapshots"); + throw new RuntimeException("RepositoryRegistry exception should be thrown if id exists already."); + } + catch ( RepositoryException e ) + { + // OK + } + + try + { + repositoryRegistry.clone(remoteRepository, "central"); + throw new RuntimeException("RepositoryRegistry exception should be thrown if id exists already."); + } + catch ( RepositoryException e ) + { + // OK + } + + RemoteRepository clone = repositoryRegistry.clone( remoteRepository, "newCentral" ); + assertNotNull(clone); + assertNull(clone.getContent()); + assertEquals("Central Repository", clone.getName()); + assertFalse(remoteRepository==clone); + + } + +} \ No newline at end of file diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java new file mode 100644 index 000000000..72ef7e37d --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java @@ -0,0 +1,169 @@ +package org.apache.archiva.repository.mock; + +/* + * 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.model.ArchivaArtifact; +import org.apache.archiva.model.ArtifactReference; +import org.apache.archiva.model.ProjectReference; +import org.apache.archiva.model.VersionedReference; +import org.apache.archiva.repository.ContentNotFoundException; +import org.apache.archiva.repository.ManagedRepository; +import org.apache.archiva.repository.ManagedRepositoryContent; +import org.apache.archiva.repository.RepositoryException; +import org.apache.archiva.repository.LayoutException; +import org.springframework.stereotype.Service; + +import java.nio.file.Path; +import java.util.Set; + +/** + * @author Martin Stockhammer + */ +@Service("managedRepositoryContent#mock") +public class ManagedRepositoryContentMock implements ManagedRepositoryContent +{ + private ManagedRepository repository; + + @Override + public void deleteVersion( VersionedReference reference ) throws ContentNotFoundException + { + + } + + @Override + public void deleteArtifact( ArtifactReference artifactReference ) throws ContentNotFoundException + { + + } + + @Override + public void deleteGroupId( String groupId ) throws ContentNotFoundException + { + + } + + @Override + public void deleteProject( String namespace, String projectId ) throws RepositoryException + { + + } + + @Override + public String getId( ) + { + return null; + } + + @Override + public Set getRelatedArtifacts( ArtifactReference reference ) throws ContentNotFoundException + { + return null; + } + + @Override + public String getRepoRoot( ) + { + return null; + } + + @Override + public ManagedRepository getRepository( ) + { + return repository; + } + + @Override + public Set getVersions( ProjectReference reference ) throws ContentNotFoundException, LayoutException + { + return null; + } + + @Override + public Set getVersions( VersionedReference reference ) throws ContentNotFoundException + { + return null; + } + + @Override + public boolean hasContent( ArtifactReference reference ) + { + return false; + } + + @Override + public boolean hasContent( ProjectReference reference ) + { + return false; + } + + @Override + public boolean hasContent( VersionedReference reference ) + { + return false; + } + + @Override + public void setRepository( ManagedRepository repo ) + { + this.repository = repo; + } + + @Override + public ArtifactReference toArtifactReference( String path ) throws LayoutException + { + return null; + } + + @Override + public Path toFile( ArtifactReference reference ) + { + return null; + } + + @Override + public Path toFile( ArchivaArtifact reference ) + { + return null; + } + + @Override + public String toMetadataPath( ProjectReference reference ) + { + return null; + } + + @Override + public String toMetadataPath( VersionedReference reference ) + { + return null; + } + + @Override + public String toPath( ArtifactReference reference ) + { + return null; + } + + @Override + public String toPath( ArchivaArtifact reference ) + { + return null; + } +} diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/mock/RemoteRepositoryContentMock.java b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/mock/RemoteRepositoryContentMock.java new file mode 100644 index 000000000..ecce0cf10 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/mock/RemoteRepositoryContentMock.java @@ -0,0 +1,78 @@ +package org.apache.archiva.repository.mock; + +/* + * 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.model.ArtifactReference; +import org.apache.archiva.model.RepositoryURL; +import org.apache.archiva.repository.RemoteRepository; +import org.apache.archiva.repository.RemoteRepositoryContent; +import org.apache.archiva.repository.LayoutException; +import org.springframework.stereotype.Service; + +/** + * @author Martin Stockhammer + */ +@Service("remoteRepositoryContent#mock") +public class RemoteRepositoryContentMock implements RemoteRepositoryContent +{ + RemoteRepository repository; + + @Override + public String getId( ) + { + return null; + } + + @Override + public RemoteRepository getRepository( ) + { + return null; + } + + @Override + public RepositoryURL getURL( ) + { + return null; + } + + @Override + public void setRepository( RemoteRepository repo ) + { + this.repository = repo; + } + + @Override + public ArtifactReference toArtifactReference( String path ) throws LayoutException + { + return null; + } + + @Override + public String toPath( ArtifactReference reference ) + { + return null; + } + + @Override + public RepositoryURL toURL( ArtifactReference reference ) + { + return null; + } +} diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/mock/RepositoryProviderMock.java b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/mock/RepositoryProviderMock.java new file mode 100644 index 000000000..834ce5ba2 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/mock/RepositoryProviderMock.java @@ -0,0 +1,231 @@ +package org.apache.archiva.repository.mock; + +/* + * 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.configuration.ManagedRepositoryConfiguration; +import org.apache.archiva.configuration.RemoteRepositoryConfiguration; +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.ManagedRepository; +import org.apache.archiva.repository.PasswordCredentials; +import org.apache.archiva.repository.ReleaseScheme; +import org.apache.archiva.repository.RemoteRepository; +import org.apache.archiva.repository.RepositoryCredentials; +import org.apache.archiva.repository.RepositoryException; +import org.apache.archiva.repository.RepositoryProvider; +import org.apache.archiva.repository.RepositoryType; +import org.apache.archiva.repository.features.ArtifactCleanupFeature; +import org.apache.archiva.repository.features.IndexCreationFeature; +import org.apache.archiva.repository.features.RemoteIndexFeature; +import org.apache.archiva.repository.features.StagingRepositoryFeature; +import org.springframework.stereotype.Service; + +import java.net.URI; +import java.time.Duration; +import java.time.Period; +import java.util.HashSet; +import java.util.Set; + +/** + * Just a simple mock class for the repository provider + */ +@Service("mockRepositoryProvider") +public class RepositoryProviderMock implements RepositoryProvider +{ + + private static final Set TYPES = new HashSet<>( ); + + static + { + TYPES.add( RepositoryType.MAVEN ); + TYPES.add( RepositoryType.NPM ); + } + + @Override + public Set provides( ) + { + return TYPES; + } + + @Override + public EditableManagedRepository createManagedInstance( String id, String name ) + { + return new BasicManagedRepository( id, name ); + } + + @Override + public EditableRemoteRepository createRemoteInstance( String id, String name ) + { + return new BasicRemoteRepository( id, name ); + } + + @Override + public ManagedRepository createManagedInstance( ManagedRepositoryConfiguration configuration ) throws RepositoryException + { + BasicManagedRepository managedRepository = new BasicManagedRepository( configuration.getId( ), configuration.getName( ) ); + updateManagedInstance( managedRepository, configuration ); + return managedRepository; + } + + + @Override + public void updateManagedInstance( EditableManagedRepository managedRepository, ManagedRepositoryConfiguration configuration ) throws RepositoryException + { + try + { + managedRepository.setName( managedRepository.getPrimaryLocale(), configuration.getName( ) ); + managedRepository.setLocation( new URI( configuration.getLocation( )==null ?"" : configuration.getLocation() ) ); + managedRepository.setBaseUri( new URI( "" ) ); + managedRepository.setBlocksRedeployment( configuration.isBlockRedeployments( ) ); + managedRepository.setDescription( managedRepository.getPrimaryLocale(), configuration.getDescription( ) ); + managedRepository.setLayout( configuration.getLayout( ) ); + managedRepository.setScanned( configuration.isScanned( ) ); + managedRepository.setSchedulingDefinition( configuration.getRefreshCronExpression( ) ); + if (configuration.isReleases()) { + managedRepository.addActiveReleaseScheme( ReleaseScheme.RELEASE ); + } + if (configuration.isSnapshots()) { + managedRepository.addActiveReleaseScheme( ReleaseScheme.SNAPSHOT ); + } + ArtifactCleanupFeature acf = managedRepository.getFeature( ArtifactCleanupFeature.class ).get( ); + acf.setRetentionPeriod( Period.ofDays( configuration.getRetentionPeriod( ) ) ); + acf.setDeleteReleasedSnapshots( configuration.isDeleteReleasedSnapshots( ) ); + acf.setRetentionCount( configuration.getRetentionCount( ) ); + IndexCreationFeature icf = managedRepository.getFeature( IndexCreationFeature.class ).get( ); + icf.setIndexPath( new URI( configuration.getIndexDir( ) ) ); + icf.setSkipPackedIndexCreation( configuration.isSkipPackedIndexCreation( ) ); + StagingRepositoryFeature srf = managedRepository.getFeature( StagingRepositoryFeature.class ).get( ); + srf.setStageRepoNeeded( configuration.isStageRepoNeeded( ) ); + } + catch ( Exception e ) + { + throw new RepositoryException( "Error", e ); + } + + } + + + @Override + public ManagedRepository createStagingInstance( ManagedRepositoryConfiguration configuration ) throws RepositoryException + { + String id = configuration.getId( ) + StagingRepositoryFeature.STAGING_REPO_POSTFIX; + BasicManagedRepository managedRepository = new BasicManagedRepository( id, configuration.getName( ) ); + updateManagedInstance( managedRepository, configuration ); + return managedRepository; + } + + @Override + public RemoteRepository createRemoteInstance( RemoteRepositoryConfiguration configuration ) throws RepositoryException + { + BasicRemoteRepository remoteRepository = new BasicRemoteRepository( configuration.getId( ), configuration.getName( ) ); + updateRemoteInstance( remoteRepository, configuration ); + return remoteRepository; + } + + @Override + public void updateRemoteInstance( EditableRemoteRepository remoteRepository, RemoteRepositoryConfiguration configuration ) throws RepositoryException + { + try + { + remoteRepository.setName( remoteRepository.getPrimaryLocale(), configuration.getName( ) ); + remoteRepository.setBaseUri( new URI( "" ) ); + remoteRepository.setDescription( remoteRepository.getPrimaryLocale(), configuration.getDescription( ) ); + remoteRepository.setLayout( configuration.getLayout( ) ); + remoteRepository.setSchedulingDefinition( configuration.getRefreshCronExpression( ) ); + remoteRepository.setCheckPath( configuration.getCheckPath( ) ); + remoteRepository.setExtraHeaders( configuration.getExtraHeaders( ) ); + remoteRepository.setExtraParameters( configuration.getExtraParameters( ) ); + remoteRepository.setTimeout( Duration.ofSeconds( configuration.getTimeout( ) ) ); + char[] pwd = configuration.getPassword()==null ? "".toCharArray() : configuration.getPassword().toCharArray(); + remoteRepository.setCredentials( new PasswordCredentials( configuration.getUsername( ), pwd ) ); + remoteRepository.setLocation( new URI( configuration.getUrl( )==null ? "" : configuration.getUrl() ) ); + RemoteIndexFeature rif = remoteRepository.getFeature( RemoteIndexFeature.class ).get( ); + rif.setDownloadRemoteIndexOnStartup( configuration.isDownloadRemoteIndexOnStartup( ) ); + rif.setDownloadRemoteIndex( configuration.isDownloadRemoteIndex( ) ); + rif.setIndexUri( new URI( configuration.getIndexDir( ) ) ); + rif.setDownloadTimeout( Duration.ofSeconds( configuration.getRemoteDownloadTimeout( ) ) ); + rif.setProxyId( configuration.getRemoteDownloadNetworkProxyId( ) ); + } + catch ( Exception e ) + { + throw new RepositoryException( "Error", e ); + } + + } + + @Override + public ManagedRepositoryConfiguration getManagedConfiguration( ManagedRepository managedRepository ) throws RepositoryException + { + ManagedRepositoryConfiguration configuration = new ManagedRepositoryConfiguration( ); + configuration.setId( managedRepository.getId( ) ); + configuration.setName(managedRepository.getName()); + configuration.setLocation( managedRepository.getLocation( ) == null ? "" : managedRepository.getLocation().toString( ) ); + configuration.setBlockRedeployments( managedRepository.blocksRedeployments( ) ); + configuration.setDescription( managedRepository.getDescription( ) ); + configuration.setLayout( managedRepository.getLayout( ) ); + configuration.setScanned( managedRepository.isScanned( ) ); + configuration.setRefreshCronExpression( managedRepository.getSchedulingDefinition( ) ); + configuration.setReleases( managedRepository.getActiveReleaseSchemes().contains(ReleaseScheme.RELEASE) ); + configuration.setSnapshots( managedRepository.getActiveReleaseSchemes().contains(ReleaseScheme.SNAPSHOT) ); + ArtifactCleanupFeature acf = managedRepository.getFeature( ArtifactCleanupFeature.class ).get( ); + configuration.setRetentionPeriod( acf.getRetentionPeriod( ).getDays( ) ); + configuration.setDeleteReleasedSnapshots( acf.isDeleteReleasedSnapshots( ) ); + configuration.setRetentionCount( acf.getRetentionCount( ) ); + IndexCreationFeature icf = managedRepository.getFeature( IndexCreationFeature.class ).get( ); + configuration.setSkipPackedIndexCreation( icf.isSkipPackedIndexCreation( ) ); + configuration.setIndexDir( icf.getIndexPath( ) == null ? "" : icf.getIndexPath().toString( ) ); + StagingRepositoryFeature srf = managedRepository.getFeature( StagingRepositoryFeature.class ).get( ); + configuration.setStageRepoNeeded( srf.isStageRepoNeeded( ) ); + return configuration; + } + + + @Override + public RemoteRepositoryConfiguration getRemoteConfiguration( RemoteRepository remoteRepository ) throws RepositoryException + { + RemoteRepositoryConfiguration configuration = new RemoteRepositoryConfiguration( ); + configuration.setId( remoteRepository.getId( ) ); + configuration.setName( remoteRepository.getName( ) ); + configuration.setDescription( remoteRepository.getDescription( ) ); + configuration.setLayout( remoteRepository.getLayout( ) ); + configuration.setRefreshCronExpression( remoteRepository.getSchedulingDefinition( ) ); + configuration.setCheckPath( remoteRepository.getCheckPath( ) ); + configuration.setExtraHeaders( remoteRepository.getExtraHeaders( ) ); + configuration.setExtraParameters( remoteRepository.getExtraParameters( ) ); + configuration.setTimeout( (int) remoteRepository.getTimeout( ).getSeconds( ) ); + RepositoryCredentials creds = remoteRepository.getLoginCredentials( ); + if (creds!=null) + { + PasswordCredentials pwdCreds = (PasswordCredentials) creds; + configuration.setUsername( pwdCreds.getUsername( ) ); + configuration.setPassword( new String( pwdCreds.getPassword( ) ) ); + } + configuration.setUrl( remoteRepository.getLocation( ) == null ? "" : remoteRepository.getLocation().toString( ) ); + RemoteIndexFeature rif = remoteRepository.getFeature( RemoteIndexFeature.class ).get( ); + configuration.setDownloadRemoteIndex( rif.isDownloadRemoteIndex( ) ); + configuration.setDownloadRemoteIndexOnStartup( rif.isDownloadRemoteIndexOnStartup( ) ); + configuration.setIndexDir( rif.getIndexUri( )==null ? "" : rif.getIndexUri().toString( ) ); + configuration.setRemoteDownloadNetworkProxyId( rif.getProxyId( ) ); + return configuration; + } + +} diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/resources/archiva.xml b/archiva-modules/archiva-base/archiva-repository-layer/src/test/resources/archiva.xml new file mode 100644 index 000000000..308c673b7 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/resources/archiva.xml @@ -0,0 +1,202 @@ + + + + 3.0.0 + + + internal + Archiva Managed Internal Repository + This is internal repository. + ${appserver.base}/repositories/internal + ${appserver.base}/repositories/internal/.indexer + default + true + false + true + true + 0 0 * * * ? + 30 + + + staging + Repository with staging + This is repository with staging. + ${appserver.base}/repositories/internal + ${appserver.base}/repositories/internal/.indexer + default + true + false + true + true + 0 0 * * * ? + 30 + true + + + snapshots + Archiva Managed Snapshot Repository + ${appserver.base}/repositories/snapshots + ${appserver.base}/repositories/snapshots/.indexer + default + false + true + false + true + 0 0\,30 * * * ? + 30 + + + + + central + Central Repository + https://repo.maven.apache.org/maven2 + default + 35 + + + + + + internal + central + + + disabled + once + fix + cached + + + **/* + + + + + + + jaxen/jars/jaxen-1.0-FCS-full.jar + jaxen:jaxen:1.0-FCS:full:jar + + + + + + + artifacts + + **/*.pom + **/*.jar + **/*.ear + **/*.war + **/*.car + **/*.sar + **/*.mar + **/*.rar + **/*.dtd + **/*.tld + **/*.tar.gz + **/*.tar.bz2 + **/*.zip + + + + indexable-content + + **/*.txt + **/*.TXT + **/*.block + **/*.config + **/*.pom + **/*.xml + **/*.xsd + **/*.dtd + **/*.tld + + + + auto-remove + + **/*.bak + **/*~ + **/*- + + + + ignored + + **/.htaccess + **/KEYS + **/*.rb + **/*.sh + **/.svn/** + **/.DAV/** + .index/** + .indexer/** + + + + + create-missing-checksums + validate-checksum + validate-signature + index-content + auto-remove + auto-rename + metadata-updater + create-archiva-metadata + duplicate-artifacts + + + + update-db-bad-content + + + + + + true + true + + + + + + jpa + + + cached + + + + + + + http://download.oracle.com/maven + com/sleepycat/je/license.txt + + + https://download.oracle.com/maven + com/sleepycat/je/license.txt + + + + + diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/resources/log4j2-test.xml b/archiva-modules/archiva-base/archiva-repository-layer/src/test/resources/log4j2-test.xml new file mode 100644 index 000000000..3919a985f --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/resources/log4j2-test.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 new file mode 100644 index 000000000..2b7748f3c --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/resources/spring-context.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + ]]> + + + + + + \ No newline at end of file