mirror of
https://github.com/apache/archiva.git
synced 2025-02-07 18:49:48 +00:00
Adding local path to repository API
This commit is contained in:
parent
2fe8227634
commit
754b2d5940
@ -168,7 +168,7 @@ else if ( command.listConsumers )
|
|||||||
private void doScan( String path, String[] consumers )
|
private void doScan( String path, String[] consumers )
|
||||||
throws ConsumerException, MalformedURLException
|
throws ConsumerException, MalformedURLException
|
||||||
{
|
{
|
||||||
BasicManagedRepository repo = new BasicManagedRepository( Paths.get(path).getFileName().toString(), "Archiva CLI Provided Repo" );
|
BasicManagedRepository repo = new BasicManagedRepository( Paths.get(path).getFileName().toString(), "Archiva CLI Provided Repo", Paths.get(path).getParent());
|
||||||
repo.setLocation( Paths.get(path).toUri() );
|
repo.setLocation( Paths.get(path).toUri() );
|
||||||
|
|
||||||
List<KnownRepositoryContentConsumer> knownConsumerList = new ArrayList<>();
|
List<KnownRepositoryContentConsumer> knownConsumerList = new ArrayList<>();
|
||||||
|
@ -102,6 +102,12 @@ void save( Configuration configuration )
|
|||||||
*/
|
*/
|
||||||
public Path getRepositoryBaseDir();
|
public Path getRepositoryBaseDir();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the base directory for remote repositories
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Path getRemoteRepositoryBaseDir();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the data directory where repositories and metadata reside
|
* Returns the data directory where repositories and metadata reside
|
||||||
* @return
|
* @return
|
||||||
|
@ -90,6 +90,8 @@
|
|||||||
* <p>
|
* <p>
|
||||||
* If the configuration is outdated, it will be upgraded when it is loaded. This is done by checking the version flag
|
* If the configuration is outdated, it will be upgraded when it is loaded. This is done by checking the version flag
|
||||||
* before reading it from the registry.
|
* before reading it from the registry.
|
||||||
|
*
|
||||||
|
* FIXME: The synchronization must be improved, the current impl may lead to inconsistent data or multiple getConfiguration() calls (martin_s@apache.org)
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
@Service("archivaConfiguration#default")
|
@Service("archivaConfiguration#default")
|
||||||
@ -176,6 +178,7 @@ public class DefaultArchivaConfiguration
|
|||||||
|
|
||||||
private volatile Path dataDirectory;
|
private volatile Path dataDirectory;
|
||||||
private volatile Path repositoryBaseDirectory;
|
private volatile Path repositoryBaseDirectory;
|
||||||
|
private volatile Path remoteRepositoryBaseDirectory;
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
private void init() {
|
private void init() {
|
||||||
@ -261,6 +264,17 @@ private Configuration load()
|
|||||||
dataDirectory.resolve(tmpRepoBaseDir);
|
dataDirectory.resolve(tmpRepoBaseDir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
String remoteRepoBaseDir = config.getArchivaRuntimeConfiguration().getRemoteRepositoryBaseDirectory();
|
||||||
|
if (StringUtils.isEmpty(remoteRepoBaseDir)) {
|
||||||
|
remoteRepositoryBaseDirectory = dataDirectory.resolve("remotes");
|
||||||
|
} else {
|
||||||
|
Path tmpRemoteRepoDir = Paths.get(remoteRepoBaseDir);
|
||||||
|
if (tmpRemoteRepoDir.isAbsolute()) {
|
||||||
|
remoteRepositoryBaseDirectory = tmpRemoteRepoDir;
|
||||||
|
} else {
|
||||||
|
dataDirectory.resolve(tmpRemoteRepoDir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
config.getRepositoryGroups();
|
config.getRepositoryGroups();
|
||||||
@ -941,6 +955,14 @@ public Path getRepositoryBaseDir() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Path getRemoteRepositoryBaseDir() {
|
||||||
|
if (remoteRepositoryBaseDirectory==null) {
|
||||||
|
getConfiguration();
|
||||||
|
}
|
||||||
|
return remoteRepositoryBaseDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Path getDataDirectory() {
|
public Path getDataDirectory() {
|
||||||
if (dataDirectory==null) {
|
if (dataDirectory==null) {
|
||||||
|
@ -1546,6 +1546,13 @@
|
|||||||
<type>String</type>
|
<type>String</type>
|
||||||
<required>false</required>
|
<required>false</required>
|
||||||
</field>
|
</field>
|
||||||
|
<field>
|
||||||
|
<name>remoteRepositoryBaseDirectory</name>
|
||||||
|
<version>3.0.0+</version>
|
||||||
|
<description>The base directory for local storage of remote repository data. If not set, it's ${dataDirectory}/remotes.</description>
|
||||||
|
<type>String</type>
|
||||||
|
<required>false</required>
|
||||||
|
</field>
|
||||||
<field>
|
<field>
|
||||||
<name>defaultLanguage</name>
|
<name>defaultLanguage</name>
|
||||||
<type>String</type>
|
<type>String</type>
|
||||||
|
@ -39,7 +39,9 @@
|
|||||||
import org.apache.archiva.repository.features.StagingRepositoryFeature;
|
import org.apache.archiva.repository.features.StagingRepositoryFeature;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.Period;
|
import java.time.Period;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -69,19 +71,19 @@ public Set<RepositoryType> provides( )
|
|||||||
@Override
|
@Override
|
||||||
public EditableManagedRepository createManagedInstance( String id, String name )
|
public EditableManagedRepository createManagedInstance( String id, String name )
|
||||||
{
|
{
|
||||||
return new BasicManagedRepository( id, name );
|
return new BasicManagedRepository( id, name, Paths.get("target/repositories") );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EditableRemoteRepository createRemoteInstance( String id, String name )
|
public EditableRemoteRepository createRemoteInstance( String id, String name )
|
||||||
{
|
{
|
||||||
return new BasicRemoteRepository( id, name );
|
return new BasicRemoteRepository( id, name , Paths.get("target/remotes"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ManagedRepository createManagedInstance( ManagedRepositoryConfiguration configuration ) throws RepositoryException
|
public ManagedRepository createManagedInstance( ManagedRepositoryConfiguration configuration ) throws RepositoryException
|
||||||
{
|
{
|
||||||
BasicManagedRepository managedRepository = new BasicManagedRepository( configuration.getId( ), configuration.getName( ) );
|
BasicManagedRepository managedRepository = new BasicManagedRepository( configuration.getId( ), configuration.getName( ), Paths.get("target/repositories") );
|
||||||
updateManagedInstance( managedRepository, configuration );
|
updateManagedInstance( managedRepository, configuration );
|
||||||
return managedRepository;
|
return managedRepository;
|
||||||
}
|
}
|
||||||
@ -128,7 +130,7 @@ public void updateManagedInstance( EditableManagedRepository managedRepository,
|
|||||||
public ManagedRepository createStagingInstance( ManagedRepositoryConfiguration configuration ) throws RepositoryException
|
public ManagedRepository createStagingInstance( ManagedRepositoryConfiguration configuration ) throws RepositoryException
|
||||||
{
|
{
|
||||||
String id = configuration.getId( ) + StagingRepositoryFeature.STAGING_REPO_POSTFIX;
|
String id = configuration.getId( ) + StagingRepositoryFeature.STAGING_REPO_POSTFIX;
|
||||||
BasicManagedRepository managedRepository = new BasicManagedRepository( id, configuration.getName( ) );
|
BasicManagedRepository managedRepository = new BasicManagedRepository( id, configuration.getName( ), Paths.get("target/repositories") );
|
||||||
updateManagedInstance( managedRepository, configuration );
|
updateManagedInstance( managedRepository, configuration );
|
||||||
return managedRepository;
|
return managedRepository;
|
||||||
}
|
}
|
||||||
@ -136,7 +138,7 @@ public ManagedRepository createStagingInstance( ManagedRepositoryConfiguration c
|
|||||||
@Override
|
@Override
|
||||||
public RemoteRepository createRemoteInstance( RemoteRepositoryConfiguration configuration ) throws RepositoryException
|
public RemoteRepository createRemoteInstance( RemoteRepositoryConfiguration configuration ) throws RepositoryException
|
||||||
{
|
{
|
||||||
BasicRemoteRepository remoteRepository = new BasicRemoteRepository( configuration.getId( ), configuration.getName( ) );
|
BasicRemoteRepository remoteRepository = new BasicRemoteRepository( configuration.getId( ), configuration.getName( ), Paths.get("target/remotes") );
|
||||||
updateRemoteInstance( remoteRepository, configuration );
|
updateRemoteInstance( remoteRepository, configuration );
|
||||||
return remoteRepository;
|
return remoteRepository;
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ private void setUpMockRepository()
|
|||||||
Files.createDirectories( repoDir );
|
Files.createDirectories( repoDir );
|
||||||
repoDir.toFile().deleteOnExit();
|
repoDir.toFile().deleteOnExit();
|
||||||
|
|
||||||
testRepository = new BasicManagedRepository("test-consumer-repository","Test-Consumer-Repository" );
|
testRepository = new BasicManagedRepository("test-consumer-repository","Test-Consumer-Repository", Paths.get("target/repositories") );
|
||||||
testRepository.setLocation( repoDir.toAbsolutePath().toUri() );
|
testRepository.setLocation( repoDir.toAbsolutePath().toUri() );
|
||||||
|
|
||||||
repositoryRegistry.putRepository(testRepository);
|
repositoryRegistry.putRepository(testRepository);
|
||||||
|
@ -47,9 +47,10 @@ public void setUp()
|
|||||||
{
|
{
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
|
||||||
repoConfig = new BasicManagedRepository( "test-repo", "Test Repository");
|
Path basePath = Paths.get("target/test-classes");
|
||||||
|
repoConfig = new BasicManagedRepository( "test-repo", "Test Repository", basePath);
|
||||||
repoConfig.setLayout( "default" );
|
repoConfig.setLayout( "default" );
|
||||||
repoConfig.setLocation( Paths.get( "target/test-classes/test-repo/" ).toUri() );
|
repoConfig.setLocation(basePath.resolve("test-repo/" ).toUri() );
|
||||||
|
|
||||||
consumer = applicationContext.getBean( "knownRepositoryContentConsumer#create-missing-checksums",
|
consumer = applicationContext.getBean( "knownRepositoryContentConsumer#create-missing-checksums",
|
||||||
KnownRepositoryContentConsumer.class );
|
KnownRepositoryContentConsumer.class );
|
||||||
|
@ -166,13 +166,14 @@ protected static String fixPath( String path )
|
|||||||
|
|
||||||
public org.apache.archiva.repository.ManagedRepository getRepoConfiguration( String repoId, String repoName ) throws URISyntaxException
|
public org.apache.archiva.repository.ManagedRepository getRepoConfiguration( String repoId, String repoName ) throws URISyntaxException
|
||||||
{
|
{
|
||||||
config = new BasicManagedRepository( repoId, repoName);
|
Path basePath = Paths.get("target/test-" + getName()).toAbsolutePath();
|
||||||
|
config = new BasicManagedRepository( repoId, repoName, basePath);
|
||||||
config.addActiveReleaseScheme( ReleaseScheme.RELEASE );
|
config.addActiveReleaseScheme( ReleaseScheme.RELEASE );
|
||||||
config.addActiveReleaseScheme( ReleaseScheme.SNAPSHOT );
|
config.addActiveReleaseScheme( ReleaseScheme.SNAPSHOT );
|
||||||
ArtifactCleanupFeature atf = config.getFeature( ArtifactCleanupFeature.class ).get();
|
ArtifactCleanupFeature atf = config.getFeature( ArtifactCleanupFeature.class ).get();
|
||||||
atf.setRetentionPeriod( Period.ofDays( TEST_DAYS_OLDER) );
|
atf.setRetentionPeriod( Period.ofDays( TEST_DAYS_OLDER) );
|
||||||
String path = AbstractRepositoryPurgeTest.fixPath(
|
String path = AbstractRepositoryPurgeTest.fixPath(
|
||||||
Paths.get( "target/test-" + getName() + "/" + repoId ).toAbsolutePath().toString() );
|
basePath.resolve( repoId ).toAbsolutePath().toString() );
|
||||||
config.setLocation( new URI( path ) );
|
config.setLocation( new URI( path ) );
|
||||||
atf.setDeleteReleasedSnapshots( true );
|
atf.setDeleteReleasedSnapshots( true );
|
||||||
atf.setRetentionCount( TEST_RETENTION_COUNT );
|
atf.setRetentionCount( TEST_RETENTION_COUNT );
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.Period;
|
import java.time.Period;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -69,19 +70,19 @@ public Set<RepositoryType> provides( )
|
|||||||
@Override
|
@Override
|
||||||
public EditableManagedRepository createManagedInstance( String id, String name )
|
public EditableManagedRepository createManagedInstance( String id, String name )
|
||||||
{
|
{
|
||||||
return new BasicManagedRepository( id, name );
|
return new BasicManagedRepository( id, name, Paths.get("target/repositories") );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EditableRemoteRepository createRemoteInstance( String id, String name )
|
public EditableRemoteRepository createRemoteInstance( String id, String name )
|
||||||
{
|
{
|
||||||
return new BasicRemoteRepository( id, name );
|
return new BasicRemoteRepository( id, name, Paths.get("target/remotes") );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ManagedRepository createManagedInstance( ManagedRepositoryConfiguration configuration ) throws RepositoryException
|
public ManagedRepository createManagedInstance( ManagedRepositoryConfiguration configuration ) throws RepositoryException
|
||||||
{
|
{
|
||||||
BasicManagedRepository managedRepository = new BasicManagedRepository( configuration.getId( ), configuration.getName( ) );
|
BasicManagedRepository managedRepository = new BasicManagedRepository( configuration.getId( ), configuration.getName( ), Paths.get("target/repositories") );
|
||||||
updateManagedInstance( managedRepository, configuration );
|
updateManagedInstance( managedRepository, configuration );
|
||||||
return managedRepository;
|
return managedRepository;
|
||||||
}
|
}
|
||||||
@ -128,7 +129,7 @@ public void updateManagedInstance( EditableManagedRepository managedRepository,
|
|||||||
public ManagedRepository createStagingInstance( ManagedRepositoryConfiguration configuration ) throws RepositoryException
|
public ManagedRepository createStagingInstance( ManagedRepositoryConfiguration configuration ) throws RepositoryException
|
||||||
{
|
{
|
||||||
String id = configuration.getId( ) + StagingRepositoryFeature.STAGING_REPO_POSTFIX;
|
String id = configuration.getId( ) + StagingRepositoryFeature.STAGING_REPO_POSTFIX;
|
||||||
BasicManagedRepository managedRepository = new BasicManagedRepository( id, configuration.getName( ) );
|
BasicManagedRepository managedRepository = new BasicManagedRepository( id, configuration.getName( ), Paths.get("target/repositories") );
|
||||||
updateManagedInstance( managedRepository, configuration );
|
updateManagedInstance( managedRepository, configuration );
|
||||||
return managedRepository;
|
return managedRepository;
|
||||||
}
|
}
|
||||||
@ -136,7 +137,7 @@ public ManagedRepository createStagingInstance( ManagedRepositoryConfiguration c
|
|||||||
@Override
|
@Override
|
||||||
public RemoteRepository createRemoteInstance( RemoteRepositoryConfiguration configuration ) throws RepositoryException
|
public RemoteRepository createRemoteInstance( RemoteRepositoryConfiguration configuration ) throws RepositoryException
|
||||||
{
|
{
|
||||||
BasicRemoteRepository remoteRepository = new BasicRemoteRepository( configuration.getId( ), configuration.getName( ) );
|
BasicRemoteRepository remoteRepository = new BasicRemoteRepository( configuration.getId( ), configuration.getName( ), Paths.get("target/remotes") );
|
||||||
updateRemoteInstance( remoteRepository, configuration );
|
updateRemoteInstance( remoteRepository, configuration );
|
||||||
return remoteRepository;
|
return remoteRepository;
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,7 @@ public void setUp()
|
|||||||
// initialize to set the file types to be processed
|
// initialize to set the file types to be processed
|
||||||
nexusIndexerConsumer.initialize();
|
nexusIndexerConsumer.initialize();
|
||||||
|
|
||||||
repositoryConfig = new BasicManagedRepository( "test-repo", "Test Repository" );
|
repositoryConfig = new BasicManagedRepository( "test-repo", "Test Repository", Paths.get("target/test-classes") );
|
||||||
repositoryConfig.setLocation( new URI("target/test-classes/test-repo") );
|
repositoryConfig.setLocation( new URI("target/test-classes/test-repo") );
|
||||||
repositoryConfig.setLayout( "default" );
|
repositoryConfig.setLayout( "default" );
|
||||||
repositoryConfig.setScanned( true );
|
repositoryConfig.setScanned( true );
|
||||||
|
@ -92,7 +92,7 @@ public void convertLegacyRepository( Path legacyRepositoryDirectory, Path reposi
|
|||||||
{
|
{
|
||||||
String defaultRepositoryUrl = PathUtil.toUrl( repositoryDirectory );
|
String defaultRepositoryUrl = PathUtil.toUrl( repositoryDirectory );
|
||||||
|
|
||||||
BasicManagedRepository legacyRepository = new BasicManagedRepository( "legacy", "Legacy Repository");
|
BasicManagedRepository legacyRepository = new BasicManagedRepository( "legacy", "Legacy Repository", repositoryDirectory.getParent());
|
||||||
legacyRepository.setLocation( legacyRepositoryDirectory.toAbsolutePath().toUri() );
|
legacyRepository.setLocation( legacyRepositoryDirectory.toAbsolutePath().toUri() );
|
||||||
legacyRepository.setLayout( "legacy" );
|
legacyRepository.setLayout( "legacy" );
|
||||||
|
|
||||||
|
@ -521,13 +521,7 @@ private IndexingContext createManagedContext( ManagedRepository repository ) thr
|
|||||||
|
|
||||||
IndexingContext context;
|
IndexingContext context;
|
||||||
// take care first about repository location as can be relative
|
// take care first about repository location as can be relative
|
||||||
Path repositoryDirectory = PathUtil.getPathFromUri( repository.getLocation( ) );
|
Path repositoryDirectory = repository.getLocalPath();
|
||||||
|
|
||||||
if ( !repositoryDirectory.isAbsolute( ) )
|
|
||||||
{
|
|
||||||
repositoryDirectory =
|
|
||||||
repositoryDirectory.resolve( "repositories" ).resolve( repositoryDirectory );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !Files.exists( repositoryDirectory ) )
|
if ( !Files.exists( repositoryDirectory ) )
|
||||||
{
|
{
|
||||||
|
@ -0,0 +1,89 @@
|
|||||||
|
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.ManagedRepository;
|
||||||
|
import org.apache.archiva.repository.features.IndexCreationFeature;
|
||||||
|
import org.apache.archiva.repository.maven2.MavenManagedRepository;
|
||||||
|
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
@RunWith( ArchivaSpringJUnit4ClassRunner.class )
|
||||||
|
@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
|
||||||
|
public class MavenIndexManagerTest {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
MavenIndexManager mavenIndexManager;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void pack() throws Exception {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void scan() throws Exception {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void update() throws Exception {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void addArtifactsToIndex() throws Exception {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void removeArtifactsFromIndex() throws Exception {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void supportsRepository() throws Exception {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void createContext() throws Exception {
|
||||||
|
MavenManagedRepository repository = new MavenManagedRepository("test-repo", "Test Repo", Paths.get("target/repositories"));
|
||||||
|
repository.setLocation(new URI("test-repo"));
|
||||||
|
IndexCreationFeature icf = repository.getFeature(IndexCreationFeature.class).get();
|
||||||
|
icf.setIndexPath(new URI(".index-test"));
|
||||||
|
ArchivaIndexingContext ctx = mavenIndexManager.createContext(repository);
|
||||||
|
assertNotNull(ctx);
|
||||||
|
assertEquals(repository, ctx.getRepository());
|
||||||
|
assertEquals("test-repo", ctx.getId());
|
||||||
|
Path indexPath = Paths.get("target/repositories/test-repo/.index-test");
|
||||||
|
assertEquals(indexPath.toAbsolutePath(), Paths.get(ctx.getPath()).toAbsolutePath());
|
||||||
|
assertTrue(Files.exists(indexPath));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -354,7 +354,7 @@ else if ( Files.isDirectory(file) )
|
|||||||
protected ManagedRepositoryContent createRepository( String id, String name, String path, String layout )
|
protected ManagedRepositoryContent createRepository( String id, String name, String path, String layout )
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
MavenManagedRepository repo = new MavenManagedRepository(id, name);
|
MavenManagedRepository repo = new MavenManagedRepository(id, name, Paths.get(path).getParent());
|
||||||
repo.setLocation( new URI(path) );
|
repo.setLocation( new URI(path) );
|
||||||
repo.setLayout( layout );
|
repo.setLayout( layout );
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ public void setUp()
|
|||||||
// Make the destination dir.
|
// Make the destination dir.
|
||||||
Files.createDirectories(destRepoDir);
|
Files.createDirectories(destRepoDir);
|
||||||
|
|
||||||
MavenManagedRepository repo = new MavenManagedRepository( MANAGED_ID, "Default Managed Repository" );
|
MavenManagedRepository repo = new MavenManagedRepository( MANAGED_ID, "Default Managed Repository", Paths.get(repoPath).getParent() );
|
||||||
repo.setLocation( new URI(repoPath) );
|
repo.setLocation( new URI(repoPath) );
|
||||||
repo.setLayout( "default" );
|
repo.setLayout( "default" );
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
import org.apache.archiva.redback.components.registry.Registry;
|
import org.apache.archiva.redback.components.registry.Registry;
|
||||||
import org.apache.archiva.redback.components.registry.RegistryException;
|
import org.apache.archiva.redback.components.registry.RegistryException;
|
||||||
import org.apache.archiva.redback.components.registry.RegistryListener;
|
import org.apache.archiva.redback.components.registry.RegistryListener;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.easymock.EasyMock;
|
import org.easymock.EasyMock;
|
||||||
import org.easymock.IMocksControl;
|
import org.easymock.IMocksControl;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@ -160,4 +161,24 @@ public Path getAppServerBaseDir() {
|
|||||||
return Paths.get("");
|
return Paths.get("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Path getRepositoryBaseDir() {
|
||||||
|
return getDataDirectory().resolve("repositories");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Path getRemoteRepositoryBaseDir() {
|
||||||
|
return getDataDirectory().resolve("remotes");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Path getDataDirectory() {
|
||||||
|
if (configuration!=null && StringUtils.isNotEmpty(configuration.getArchivaRuntimeConfiguration().getDataDirectory())) {
|
||||||
|
return Paths.get(configuration.getArchivaRuntimeConfiguration().getDataDirectory());
|
||||||
|
} else {
|
||||||
|
return getAppServerBaseDir().resolve("data");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.Period;
|
import java.time.Period;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -69,19 +70,19 @@ public Set<RepositoryType> provides( )
|
|||||||
@Override
|
@Override
|
||||||
public EditableManagedRepository createManagedInstance( String id, String name )
|
public EditableManagedRepository createManagedInstance( String id, String name )
|
||||||
{
|
{
|
||||||
return new BasicManagedRepository( id, name );
|
return new BasicManagedRepository( id, name , Paths.get("target/repositories"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EditableRemoteRepository createRemoteInstance( String id, String name )
|
public EditableRemoteRepository createRemoteInstance( String id, String name )
|
||||||
{
|
{
|
||||||
return new BasicRemoteRepository( id, name );
|
return new BasicRemoteRepository( id, name, Paths.get("target/remotes") );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ManagedRepository createManagedInstance( ManagedRepositoryConfiguration configuration ) throws RepositoryException
|
public ManagedRepository createManagedInstance( ManagedRepositoryConfiguration configuration ) throws RepositoryException
|
||||||
{
|
{
|
||||||
BasicManagedRepository managedRepository = new BasicManagedRepository( configuration.getId( ), configuration.getName( ) );
|
BasicManagedRepository managedRepository = new BasicManagedRepository( configuration.getId( ), configuration.getName( ) , Paths.get("target/repositories"));
|
||||||
updateManagedInstance( managedRepository, configuration );
|
updateManagedInstance( managedRepository, configuration );
|
||||||
return managedRepository;
|
return managedRepository;
|
||||||
}
|
}
|
||||||
@ -128,7 +129,7 @@ public void updateManagedInstance( EditableManagedRepository managedRepository,
|
|||||||
public ManagedRepository createStagingInstance( ManagedRepositoryConfiguration configuration ) throws RepositoryException
|
public ManagedRepository createStagingInstance( ManagedRepositoryConfiguration configuration ) throws RepositoryException
|
||||||
{
|
{
|
||||||
String id = configuration.getId( ) + StagingRepositoryFeature.STAGING_REPO_POSTFIX;
|
String id = configuration.getId( ) + StagingRepositoryFeature.STAGING_REPO_POSTFIX;
|
||||||
BasicManagedRepository managedRepository = new BasicManagedRepository( id, configuration.getName( ) );
|
BasicManagedRepository managedRepository = new BasicManagedRepository( id, configuration.getName( ), Paths.get("target/repositories") );
|
||||||
updateManagedInstance( managedRepository, configuration );
|
updateManagedInstance( managedRepository, configuration );
|
||||||
return managedRepository;
|
return managedRepository;
|
||||||
}
|
}
|
||||||
@ -136,7 +137,7 @@ public ManagedRepository createStagingInstance( ManagedRepositoryConfiguration c
|
|||||||
@Override
|
@Override
|
||||||
public RemoteRepository createRemoteInstance( RemoteRepositoryConfiguration configuration ) throws RepositoryException
|
public RemoteRepository createRemoteInstance( RemoteRepositoryConfiguration configuration ) throws RepositoryException
|
||||||
{
|
{
|
||||||
BasicRemoteRepository remoteRepository = new BasicRemoteRepository( configuration.getId( ), configuration.getName( ) );
|
BasicRemoteRepository remoteRepository = new BasicRemoteRepository( configuration.getId( ), configuration.getName( ), Paths.get("target/remotes") );
|
||||||
updateRemoteInstance( remoteRepository, configuration );
|
updateRemoteInstance( remoteRepository, configuration );
|
||||||
return remoteRepository;
|
return remoteRepository;
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
import org.apache.archiva.repository.features.RepositoryFeature;
|
import org.apache.archiva.repository.features.RepositoryFeature;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -86,14 +87,22 @@ public interface Repository {
|
|||||||
*/
|
*/
|
||||||
URI getLocation();
|
URI getLocation();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This returns the absolute location uri of this repository. Some repository locations may be relative to
|
* Returns the local path that this repository uses, if it stores data locally. You should keep in
|
||||||
* the base repository directory or uri. This returns the absolute path of the repository.
|
* mind, that repository implementations may not store any data in this directory. E.g. if the
|
||||||
* If the location is absolute already this method returns the same URI as getLocation().
|
* repository data is handled by a database. So the content of this directory is very implementation
|
||||||
|
* specific. Users of this directory must know about the repository file layout if they use this
|
||||||
|
* path.
|
||||||
*
|
*
|
||||||
* @return the absolute uri of the location.
|
* Repository implementations should always return a valid path, even if there is no locally stored data.
|
||||||
|
*
|
||||||
|
* Some extensions may use the path to store their own repository specific data, e.g. statistics, metadata,...
|
||||||
|
*
|
||||||
|
* @return the filesystem path to the repository.
|
||||||
*/
|
*/
|
||||||
URI getAbsoluteLocation();
|
Path getLocalPath();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A repository may allow additional locations that can be used, if the primary location is not available.
|
* A repository may allow additional locations that can be used, if the primary location is not available.
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
@ -35,14 +36,14 @@ public abstract class AbstractManagedRepository extends AbstractRepository imple
|
|||||||
private Set<ReleaseScheme> activeReleaseSchemes = new HashSet<>( );
|
private Set<ReleaseScheme> activeReleaseSchemes = new HashSet<>( );
|
||||||
private Set<ReleaseScheme> uActiveReleaseSchemes = Collections.unmodifiableSet( activeReleaseSchemes );
|
private Set<ReleaseScheme> uActiveReleaseSchemes = Collections.unmodifiableSet( activeReleaseSchemes );
|
||||||
|
|
||||||
public AbstractManagedRepository( RepositoryType type, String id, String name )
|
public AbstractManagedRepository( RepositoryType type, String id, String name, Path basePath )
|
||||||
{
|
{
|
||||||
super( type, id, name );
|
super( type, id, name, basePath );
|
||||||
}
|
}
|
||||||
|
|
||||||
public AbstractManagedRepository( Locale primaryLocale, RepositoryType type, String id, String name )
|
public AbstractManagedRepository( Locale primaryLocale, RepositoryType type, String id, String name, Path basePath )
|
||||||
{
|
{
|
||||||
super( primaryLocale, type, id, name );
|
super( primaryLocale, type, id, name, basePath );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -20,6 +20,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -43,14 +47,14 @@ public abstract class AbstractRemoteRepository extends AbstractRepository implem
|
|||||||
private String proxyId;
|
private String proxyId;
|
||||||
private RemoteRepositoryContent content;
|
private RemoteRepositoryContent content;
|
||||||
|
|
||||||
public AbstractRemoteRepository( RepositoryType type, String id, String name )
|
public AbstractRemoteRepository( RepositoryType type, String id, String name , Path repositoryBase)
|
||||||
{
|
{
|
||||||
super( type, id, name );
|
super( type, id, name, repositoryBase );
|
||||||
}
|
}
|
||||||
|
|
||||||
public AbstractRemoteRepository( Locale primaryLocale, RepositoryType type, String id, String name )
|
public AbstractRemoteRepository( Locale primaryLocale, RepositoryType type, String id, String name, Path repositoryBase )
|
||||||
{
|
{
|
||||||
super( primaryLocale, type, id, name );
|
super( primaryLocale, type, id, name, repositoryBase );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -138,4 +142,13 @@ public Duration getTimeout( )
|
|||||||
return timeout;
|
return timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remote repositories resolve always relative to the base directory.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Path getLocalPath() {
|
||||||
|
return repositoryBase.resolve(getId());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -23,10 +23,14 @@
|
|||||||
import com.cronutils.model.definition.CronDefinition;
|
import com.cronutils.model.definition.CronDefinition;
|
||||||
import com.cronutils.model.definition.CronDefinitionBuilder;
|
import com.cronutils.model.definition.CronDefinitionBuilder;
|
||||||
import com.cronutils.parser.CronParser;
|
import com.cronutils.parser.CronParser;
|
||||||
|
import org.apache.archiva.common.utils.PathUtil;
|
||||||
import org.apache.archiva.indexer.ArchivaIndexingContext;
|
import org.apache.archiva.indexer.ArchivaIndexingContext;
|
||||||
import org.apache.archiva.repository.features.RepositoryFeature;
|
import org.apache.archiva.repository.features.RepositoryFeature;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -59,17 +63,21 @@ public abstract class AbstractRepository implements EditableRepository
|
|||||||
|
|
||||||
Map<Class<? extends RepositoryFeature<?>>, RepositoryFeature<?>> featureMap = new HashMap<>( );
|
Map<Class<? extends RepositoryFeature<?>>, RepositoryFeature<?>> featureMap = new HashMap<>( );
|
||||||
|
|
||||||
public AbstractRepository(RepositoryType type, String id, String name) {
|
protected Path repositoryBase;
|
||||||
|
|
||||||
|
public AbstractRepository(RepositoryType type, String id, String name, Path repositoryBase) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.names.put( primaryLocale, name);
|
this.names.put( primaryLocale, name);
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
this.repositoryBase=repositoryBase;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AbstractRepository(Locale primaryLocale, RepositoryType type, String id, String name) {
|
public AbstractRepository(Locale primaryLocale, RepositoryType type, String id, String name, Path repositoryBase) {
|
||||||
setPrimaryLocale( primaryLocale );
|
setPrimaryLocale( primaryLocale );
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.names.put( primaryLocale, name);
|
this.names.put( primaryLocale, name);
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
this.repositoryBase=repositoryBase;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setPrimaryLocale(Locale locale) {
|
protected void setPrimaryLocale(Locale locale) {
|
||||||
@ -118,8 +126,19 @@ public URI getLocation( )
|
|||||||
return location;
|
return location;
|
||||||
}
|
}
|
||||||
|
|
||||||
public URI getAbsoluteLocation() {
|
@Override
|
||||||
return baseUri.resolve( location );
|
public Path getLocalPath() {
|
||||||
|
Path localPath;
|
||||||
|
if (getLocation().getScheme()=="file" || StringUtils.isEmpty(getLocation().getScheme())) {
|
||||||
|
localPath = PathUtil.getPathFromUri(getLocation());
|
||||||
|
if (localPath.isAbsolute()) {
|
||||||
|
return localPath;
|
||||||
|
} else {
|
||||||
|
return repositoryBase.resolve(localPath);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return repositoryBase.resolve(getId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
import org.apache.archiva.repository.features.IndexCreationFeature;
|
import org.apache.archiva.repository.features.IndexCreationFeature;
|
||||||
import org.apache.archiva.repository.features.StagingRepositoryFeature;
|
import org.apache.archiva.repository.features.StagingRepositoryFeature;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -46,15 +47,15 @@ public class BasicManagedRepository extends AbstractManagedRepository
|
|||||||
StagingRepositoryFeature.class.toString()
|
StagingRepositoryFeature.class.toString()
|
||||||
}, true, true, true, true, true );
|
}, true, true, true, true, true );
|
||||||
|
|
||||||
public BasicManagedRepository( String id, String name )
|
public BasicManagedRepository( String id, String name, Path basePath )
|
||||||
{
|
{
|
||||||
super( RepositoryType.MAVEN, id, name );
|
super( RepositoryType.MAVEN, id, name, basePath );
|
||||||
initFeatures();
|
initFeatures();
|
||||||
}
|
}
|
||||||
|
|
||||||
public BasicManagedRepository( Locale primaryLocale, RepositoryType type, String id, String name )
|
public BasicManagedRepository( Locale primaryLocale, RepositoryType type, String id, String name, Path basePath )
|
||||||
{
|
{
|
||||||
super( primaryLocale, type, id, name );
|
super( primaryLocale, type, id, name, basePath );
|
||||||
initFeatures();
|
initFeatures();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
import org.apache.archiva.repository.features.RemoteIndexFeature;
|
import org.apache.archiva.repository.features.RemoteIndexFeature;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -41,15 +42,15 @@ public class BasicRemoteRepository extends AbstractRemoteRepository
|
|||||||
RemoteIndexFeature.class.toString()
|
RemoteIndexFeature.class.toString()
|
||||||
}, true, true, true, true, true );
|
}, true, true, true, true, true );
|
||||||
|
|
||||||
public BasicRemoteRepository( String id, String name )
|
public BasicRemoteRepository( String id, String name, Path basePath )
|
||||||
{
|
{
|
||||||
super( RepositoryType.MAVEN, id, name );
|
super( RepositoryType.MAVEN, id, name, basePath);
|
||||||
initFeatures();
|
initFeatures();
|
||||||
}
|
}
|
||||||
|
|
||||||
public BasicRemoteRepository( Locale primaryLocale, RepositoryType type, String id, String name )
|
public BasicRemoteRepository( Locale primaryLocale, RepositoryType type, String id, String name, Path basePath )
|
||||||
{
|
{
|
||||||
super( primaryLocale, type, id, name );
|
super( primaryLocale, type, id, name, basePath );
|
||||||
initFeatures();
|
initFeatures();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,14 +192,14 @@ public void getRemoteRepository( ) throws Exception
|
|||||||
@Test
|
@Test
|
||||||
public void putManagedRepository( ) throws Exception
|
public void putManagedRepository( ) throws Exception
|
||||||
{
|
{
|
||||||
BasicManagedRepository managedRepository = new BasicManagedRepository( "test001", "Test repo" );
|
BasicManagedRepository managedRepository = new BasicManagedRepository( "test001", "Test repo", archivaConfiguration.getRepositoryBaseDir() );
|
||||||
managedRepository.setDescription( managedRepository.getPrimaryLocale(), "This is just a test" );
|
managedRepository.setDescription( managedRepository.getPrimaryLocale(), "This is just a test" );
|
||||||
repositoryRegistry.putRepository(managedRepository);
|
repositoryRegistry.putRepository(managedRepository);
|
||||||
|
|
||||||
assertNotNull(managedRepository.getContent());
|
assertNotNull(managedRepository.getContent());
|
||||||
assertEquals(6, repositoryRegistry.getRepositories().size());
|
assertEquals(6, repositoryRegistry.getRepositories().size());
|
||||||
|
|
||||||
managedRepository = new BasicManagedRepository( "central", "Test repo" );
|
managedRepository = new BasicManagedRepository( "central", "Test repo", archivaConfiguration.getRepositoryBaseDir() );
|
||||||
managedRepository.setDescription( managedRepository.getPrimaryLocale(), "This is just a test" );
|
managedRepository.setDescription( managedRepository.getPrimaryLocale(), "This is just a test" );
|
||||||
ManagedRepository updatedRepo = null;
|
ManagedRepository updatedRepo = null;
|
||||||
try {
|
try {
|
||||||
@ -208,7 +208,7 @@ public void putManagedRepository( ) throws Exception
|
|||||||
} catch (RepositoryException e) {
|
} catch (RepositoryException e) {
|
||||||
// OK
|
// OK
|
||||||
}
|
}
|
||||||
managedRepository = new BasicManagedRepository( "internal", "Test repo" );
|
managedRepository = new BasicManagedRepository( "internal", "Test repo", archivaConfiguration.getRepositoryBaseDir() );
|
||||||
managedRepository.setDescription( managedRepository.getPrimaryLocale(), "This is just a test" );
|
managedRepository.setDescription( managedRepository.getPrimaryLocale(), "This is just a test" );
|
||||||
updatedRepo = repositoryRegistry.putRepository( managedRepository );
|
updatedRepo = repositoryRegistry.putRepository( managedRepository );
|
||||||
|
|
||||||
@ -283,7 +283,7 @@ public void putManagedRepositoryFromConfigWithoutSave( ) throws Exception
|
|||||||
@Test
|
@Test
|
||||||
public void putRemoteRepository( ) throws Exception
|
public void putRemoteRepository( ) throws Exception
|
||||||
{
|
{
|
||||||
BasicRemoteRepository remoteRepository = new BasicRemoteRepository( "test001", "Test repo" );
|
BasicRemoteRepository remoteRepository = new BasicRemoteRepository( "test001", "Test repo", archivaConfiguration.getRemoteRepositoryBaseDir() );
|
||||||
remoteRepository.setDescription( remoteRepository.getPrimaryLocale(), "This is just a test" );
|
remoteRepository.setDescription( remoteRepository.getPrimaryLocale(), "This is just a test" );
|
||||||
RemoteRepository newRepo = repositoryRegistry.putRepository(remoteRepository);
|
RemoteRepository newRepo = repositoryRegistry.putRepository(remoteRepository);
|
||||||
|
|
||||||
@ -291,7 +291,7 @@ public void putRemoteRepository( ) throws Exception
|
|||||||
assertNotNull(remoteRepository.getContent());
|
assertNotNull(remoteRepository.getContent());
|
||||||
assertEquals(6, repositoryRegistry.getRepositories().size());
|
assertEquals(6, repositoryRegistry.getRepositories().size());
|
||||||
|
|
||||||
remoteRepository = new BasicRemoteRepository( "internal", "Test repo" );
|
remoteRepository = new BasicRemoteRepository( "internal", "Test repo", archivaConfiguration.getRemoteRepositoryBaseDir() );
|
||||||
remoteRepository.setDescription( remoteRepository.getPrimaryLocale(), "This is just a test" );
|
remoteRepository.setDescription( remoteRepository.getPrimaryLocale(), "This is just a test" );
|
||||||
RemoteRepository updatedRepo = null;
|
RemoteRepository updatedRepo = null;
|
||||||
try
|
try
|
||||||
@ -302,7 +302,7 @@ public void putRemoteRepository( ) throws Exception
|
|||||||
// OK
|
// OK
|
||||||
}
|
}
|
||||||
|
|
||||||
remoteRepository = new BasicRemoteRepository( "central", "Test repo" );
|
remoteRepository = new BasicRemoteRepository( "central", "Test repo", archivaConfiguration.getRemoteRepositoryBaseDir() );
|
||||||
remoteRepository.setDescription( remoteRepository.getPrimaryLocale(), "This is just a test" );
|
remoteRepository.setDescription( remoteRepository.getPrimaryLocale(), "This is just a test" );
|
||||||
updatedRepo = repositoryRegistry.putRepository( remoteRepository );
|
updatedRepo = repositoryRegistry.putRepository( remoteRepository );
|
||||||
|
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.Period;
|
import java.time.Period;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -69,19 +70,19 @@ public Set<RepositoryType> provides( )
|
|||||||
@Override
|
@Override
|
||||||
public EditableManagedRepository createManagedInstance( String id, String name )
|
public EditableManagedRepository createManagedInstance( String id, String name )
|
||||||
{
|
{
|
||||||
return new BasicManagedRepository( id, name );
|
return new BasicManagedRepository( id, name, Paths.get("target/repositories") );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EditableRemoteRepository createRemoteInstance( String id, String name )
|
public EditableRemoteRepository createRemoteInstance( String id, String name )
|
||||||
{
|
{
|
||||||
return new BasicRemoteRepository( id, name );
|
return new BasicRemoteRepository( id, name , Paths.get("target/remotes"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ManagedRepository createManagedInstance( ManagedRepositoryConfiguration configuration ) throws RepositoryException
|
public ManagedRepository createManagedInstance( ManagedRepositoryConfiguration configuration ) throws RepositoryException
|
||||||
{
|
{
|
||||||
BasicManagedRepository managedRepository = new BasicManagedRepository( configuration.getId( ), configuration.getName( ) );
|
BasicManagedRepository managedRepository = new BasicManagedRepository( configuration.getId( ), configuration.getName( ), Paths.get("target/repositories") );
|
||||||
updateManagedInstance( managedRepository, configuration );
|
updateManagedInstance( managedRepository, configuration );
|
||||||
return managedRepository;
|
return managedRepository;
|
||||||
}
|
}
|
||||||
@ -128,7 +129,7 @@ public void updateManagedInstance( EditableManagedRepository managedRepository,
|
|||||||
public ManagedRepository createStagingInstance( ManagedRepositoryConfiguration configuration ) throws RepositoryException
|
public ManagedRepository createStagingInstance( ManagedRepositoryConfiguration configuration ) throws RepositoryException
|
||||||
{
|
{
|
||||||
String id = configuration.getId( ) + StagingRepositoryFeature.STAGING_REPO_POSTFIX;
|
String id = configuration.getId( ) + StagingRepositoryFeature.STAGING_REPO_POSTFIX;
|
||||||
BasicManagedRepository managedRepository = new BasicManagedRepository( id, configuration.getName( ) );
|
BasicManagedRepository managedRepository = new BasicManagedRepository( id, configuration.getName( ) , Paths.get("target/repositories"));
|
||||||
updateManagedInstance( managedRepository, configuration );
|
updateManagedInstance( managedRepository, configuration );
|
||||||
managedRepository.getFeature(StagingRepositoryFeature.class).get().setStageRepoNeeded(false);
|
managedRepository.getFeature(StagingRepositoryFeature.class).get().setStageRepoNeeded(false);
|
||||||
return managedRepository;
|
return managedRepository;
|
||||||
@ -137,7 +138,7 @@ public ManagedRepository createStagingInstance( ManagedRepositoryConfiguration c
|
|||||||
@Override
|
@Override
|
||||||
public RemoteRepository createRemoteInstance( RemoteRepositoryConfiguration configuration ) throws RepositoryException
|
public RemoteRepository createRemoteInstance( RemoteRepositoryConfiguration configuration ) throws RepositoryException
|
||||||
{
|
{
|
||||||
BasicRemoteRepository remoteRepository = new BasicRemoteRepository( configuration.getId( ), configuration.getName( ) );
|
BasicRemoteRepository remoteRepository = new BasicRemoteRepository( configuration.getId( ), configuration.getName( ), Paths.get("target/remotes") );
|
||||||
updateRemoteInstance( remoteRepository, configuration );
|
updateRemoteInstance( remoteRepository, configuration );
|
||||||
return remoteRepository;
|
return remoteRepository;
|
||||||
}
|
}
|
||||||
|
@ -76,14 +76,14 @@ public class RepositoryContentConsumersTest
|
|||||||
|
|
||||||
protected ManagedRepository createRepository( String id, String name, Path location )
|
protected ManagedRepository createRepository( String id, String name, Path location )
|
||||||
{
|
{
|
||||||
BasicManagedRepository repo = new BasicManagedRepository( id, name );
|
BasicManagedRepository repo = new BasicManagedRepository( id, name , location.getParent() );
|
||||||
repo.setLocation( location.toAbsolutePath().toUri() );
|
repo.setLocation( location.toAbsolutePath().toUri() );
|
||||||
return repo;
|
return repo;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected RemoteRepository createRemoteRepository( String id, String name, String url ) throws URISyntaxException
|
protected RemoteRepository createRemoteRepository( String id, String name, String url ) throws URISyntaxException
|
||||||
{
|
{
|
||||||
BasicRemoteRepository repo = new BasicRemoteRepository(id, name);
|
BasicRemoteRepository repo = new BasicRemoteRepository(id, name, Paths.get("remotes"));
|
||||||
repo.setLocation( new URI( url ) );
|
repo.setLocation( new URI( url ) );
|
||||||
return repo;
|
return repo;
|
||||||
}
|
}
|
||||||
|
@ -64,14 +64,14 @@ public class RepositoryScannerTest
|
|||||||
|
|
||||||
protected EditableManagedRepository createRepository( String id, String name, Path location )
|
protected EditableManagedRepository createRepository( String id, String name, Path location )
|
||||||
{
|
{
|
||||||
BasicManagedRepository repo = new BasicManagedRepository(id, name);
|
BasicManagedRepository repo = new BasicManagedRepository(id, name, location.getParent());
|
||||||
repo.setLocation( location.toAbsolutePath().toUri());
|
repo.setLocation( location.toAbsolutePath().toUri());
|
||||||
return repo;
|
return repo;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected EditableRemoteRepository createRemoteRepository( String id, String name, String url ) throws URISyntaxException
|
protected EditableRemoteRepository createRemoteRepository( String id, String name, String url ) throws URISyntaxException
|
||||||
{
|
{
|
||||||
BasicRemoteRepository repo = new BasicRemoteRepository(id, name);
|
BasicRemoteRepository repo = new BasicRemoteRepository(id, name, Paths.get("remotes"));
|
||||||
repo.setLocation( new URI( url ) );
|
repo.setLocation( new URI( url ) );
|
||||||
return repo;
|
return repo;
|
||||||
}
|
}
|
||||||
|
@ -91,8 +91,9 @@ public void setUp()
|
|||||||
{
|
{
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
|
||||||
repositoryConfig = new BasicManagedRepository( "test-repo", "Test Repository");
|
Path baseDir = Paths.get(System.getProperty("basedir"), "target/test-classes").toAbsolutePath();
|
||||||
Path repoLocation = Paths.get( System.getProperty( "basedir" ), "target/test-classes/test-repo" ).toAbsolutePath();
|
repositoryConfig = new BasicManagedRepository( "test-repo", "Test Repository", baseDir);
|
||||||
|
Path repoLocation = baseDir.resolve("test-repo" );
|
||||||
repositoryConfig.setLocation(repoLocation.toUri() );
|
repositoryConfig.setLocation(repoLocation.toUri() );
|
||||||
repositoryConfig.setLayout( "default" );
|
repositoryConfig.setLayout( "default" );
|
||||||
repositoryConfig.setScanned( true );
|
repositoryConfig.setScanned( true );
|
||||||
|
@ -77,8 +77,7 @@ public class DavResourceTest
|
|||||||
|
|
||||||
private LockManager lockManager;
|
private LockManager lockManager;
|
||||||
|
|
||||||
private MavenManagedRepository repository = new MavenManagedRepository( "repo001", "repo001");
|
private MavenManagedRepository repository;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Before
|
@Before
|
||||||
public void setUp()
|
public void setUp()
|
||||||
@ -88,6 +87,8 @@ public void setUp()
|
|||||||
session = new ArchivaDavSession();
|
session = new ArchivaDavSession();
|
||||||
baseDir = Paths.get( "target/DavResourceTest" );
|
baseDir = Paths.get( "target/DavResourceTest" );
|
||||||
Files.createDirectories( baseDir );
|
Files.createDirectories( baseDir );
|
||||||
|
repository = new MavenManagedRepository( "repo001", "repo001", baseDir);
|
||||||
|
|
||||||
myResource = baseDir.resolve( "myresource.jar" );
|
myResource = baseDir.resolve( "myresource.jar" );
|
||||||
Files.createFile(myResource);
|
Files.createFile(myResource);
|
||||||
resourceFactory = new RootContextDavResourceFactory();
|
resourceFactory = new RootContextDavResourceFactory();
|
||||||
|
@ -70,14 +70,14 @@ public class MavenManagedRepository extends AbstractManagedRepository
|
|||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
public MavenManagedRepository( String id, String name )
|
public MavenManagedRepository( String id, String name, Path basePath )
|
||||||
{
|
{
|
||||||
super( RepositoryType.MAVEN, id, name );
|
super( RepositoryType.MAVEN, id, name, basePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MavenManagedRepository( Locale primaryLocale, String id, String name )
|
public MavenManagedRepository( Locale primaryLocale, String id, String name, Path basePath )
|
||||||
{
|
{
|
||||||
super( primaryLocale, RepositoryType.MAVEN, id, name );
|
super( primaryLocale, RepositoryType.MAVEN, id, name, basePath );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
import org.apache.archiva.repository.features.RemoteIndexFeature;
|
import org.apache.archiva.repository.features.RemoteIndexFeature;
|
||||||
import org.apache.archiva.repository.features.RepositoryFeature;
|
import org.apache.archiva.repository.features.RepositoryFeature;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -53,14 +54,14 @@ public class MavenRemoteRepository extends AbstractRemoteRepository
|
|||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
public MavenRemoteRepository( String id, String name )
|
public MavenRemoteRepository( String id, String name, Path basePath )
|
||||||
{
|
{
|
||||||
super( RepositoryType.MAVEN, id, name );
|
super( RepositoryType.MAVEN, id, name, basePath );
|
||||||
}
|
}
|
||||||
|
|
||||||
public MavenRemoteRepository( Locale primaryLocale, String id, String name )
|
public MavenRemoteRepository( Locale primaryLocale, String id, String name, Path basePath )
|
||||||
{
|
{
|
||||||
super( primaryLocale, RepositoryType.MAVEN, id, name );
|
super( primaryLocale, RepositoryType.MAVEN, id, name, basePath );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -62,63 +62,58 @@
|
|||||||
* Provider for the maven2 repository implementations
|
* Provider for the maven2 repository implementations
|
||||||
*/
|
*/
|
||||||
@Service("mavenRepositoryProvider")
|
@Service("mavenRepositoryProvider")
|
||||||
public class MavenRepositoryProvider implements RepositoryProvider
|
public class MavenRepositoryProvider implements RepositoryProvider {
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private ArchivaConfiguration archivaConfiguration;
|
private ArchivaConfiguration archivaConfiguration;
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger( MavenRepositoryProvider.class );
|
private static final Logger log = LoggerFactory.getLogger(MavenRepositoryProvider.class);
|
||||||
|
|
||||||
|
static final Set<RepositoryType> TYPES = new HashSet<>();
|
||||||
|
|
||||||
static final Set<RepositoryType> TYPES = new HashSet<>( );
|
|
||||||
static {
|
static {
|
||||||
TYPES.add( RepositoryType.MAVEN);
|
TYPES.add(RepositoryType.MAVEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<RepositoryType> provides( )
|
public Set<RepositoryType> provides() {
|
||||||
{
|
|
||||||
return TYPES;
|
return TYPES;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EditableManagedRepository createManagedInstance(String id, String name) {
|
public EditableManagedRepository createManagedInstance(String id, String name) {
|
||||||
return new MavenManagedRepository(id, name);
|
return new MavenManagedRepository(id, name, archivaConfiguration.getRepositoryBaseDir());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EditableRemoteRepository createRemoteInstance(String id, String name) {
|
public EditableRemoteRepository createRemoteInstance(String id, String name) {
|
||||||
return new MavenRemoteRepository(id, name);
|
return new MavenRemoteRepository(id, name, archivaConfiguration.getRemoteRepositoryBaseDir());
|
||||||
}
|
}
|
||||||
|
|
||||||
private URI getURIFromString( String uriStr) throws RepositoryException {
|
private URI getURIFromString(String uriStr) throws RepositoryException {
|
||||||
URI uri;
|
URI uri;
|
||||||
try {
|
try {
|
||||||
if (StringUtils.isEmpty( uriStr )) {
|
if (StringUtils.isEmpty(uriStr)) {
|
||||||
return new URI("");
|
return new URI("");
|
||||||
}
|
}
|
||||||
if (uriStr.startsWith("/")) {
|
if (uriStr.startsWith("/")) {
|
||||||
// only absolute paths are prepended with file scheme
|
// only absolute paths are prepended with file scheme
|
||||||
uri = new URI("file://"+uriStr);
|
uri = new URI("file://" + uriStr);
|
||||||
} else
|
} else {
|
||||||
{
|
uri = new URI(uriStr);
|
||||||
uri = new URI( uriStr );
|
|
||||||
}
|
}
|
||||||
if (uri.getScheme()!=null && !"file".equals(uri.getScheme())) {
|
if (uri.getScheme() != null && !"file".equals(uri.getScheme())) {
|
||||||
log.error("Bad URI scheme found: {}, URI={}", uri.getScheme(), uri);
|
log.error("Bad URI scheme found: {}, URI={}", uri.getScheme(), uri);
|
||||||
throw new RepositoryException("The uri "+uriStr+" is not valid. Only file:// URI is allowed for maven.");
|
throw new RepositoryException("The uri " + uriStr + " is not valid. Only file:// URI is allowed for maven.");
|
||||||
}
|
}
|
||||||
} catch (URISyntaxException e) {
|
} catch (URISyntaxException e) {
|
||||||
String newCfg = "file://"+uriStr;
|
String newCfg = "file://" + uriStr;
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
uri = new URI(newCfg);
|
uri = new URI(newCfg);
|
||||||
}
|
} catch (URISyntaxException e1) {
|
||||||
catch ( URISyntaxException e1 )
|
|
||||||
{
|
|
||||||
log.error("Could not create URI from {} -> ", uriStr, newCfg);
|
log.error("Could not create URI from {} -> ", uriStr, newCfg);
|
||||||
throw new RepositoryException( "The config entry "+uriStr+" cannot be converted to URI." );
|
throw new RepositoryException("The config entry " + uriStr + " cannot be converted to URI.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.debug("Setting location uri: {}", uri);
|
log.debug("Setting location uri: {}", uri);
|
||||||
@ -126,56 +121,48 @@ private URI getURIFromString( String uriStr) throws RepositoryException {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ManagedRepository createManagedInstance( ManagedRepositoryConfiguration cfg ) throws RepositoryException
|
public ManagedRepository createManagedInstance(ManagedRepositoryConfiguration cfg) throws RepositoryException {
|
||||||
{
|
MavenManagedRepository repo = new MavenManagedRepository(cfg.getId(), cfg.getName(), archivaConfiguration.getRepositoryBaseDir());
|
||||||
MavenManagedRepository repo = new MavenManagedRepository(cfg.getId() ,cfg.getName());
|
updateManagedInstance(repo, cfg);
|
||||||
updateManagedInstance( repo, cfg );
|
|
||||||
return repo;
|
return repo;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateManagedInstance( EditableManagedRepository repo , ManagedRepositoryConfiguration cfg ) throws RepositoryException
|
public void updateManagedInstance(EditableManagedRepository repo, ManagedRepositoryConfiguration cfg) throws RepositoryException {
|
||||||
{
|
try {
|
||||||
try
|
repo.setLocation(getURIFromString(cfg.getLocation()));
|
||||||
{
|
} catch (UnsupportedURIException e) {
|
||||||
repo.setLocation( getURIFromString( cfg.getLocation() ) );
|
throw new RepositoryException("The location entry is not a valid uri: " + cfg.getLocation());
|
||||||
}
|
}
|
||||||
catch ( UnsupportedURIException e )
|
setBaseConfig(repo, cfg);
|
||||||
{
|
Path repoDir = repo.getLocalPath();
|
||||||
throw new RepositoryException( "The location entry is not a valid uri: "+cfg.getLocation() );
|
|
||||||
}
|
|
||||||
setBaseConfig( repo, cfg );
|
|
||||||
Path repoDir = PathUtil.getPathFromUri(repo.getAbsoluteLocation());
|
|
||||||
if (!Files.exists(repoDir)) {
|
if (!Files.exists(repoDir)) {
|
||||||
log.debug("Creating repo directory {}", repoDir);
|
log.debug("Creating repo directory {}", repoDir);
|
||||||
try
|
try {
|
||||||
{
|
Files.createDirectories(repoDir);
|
||||||
Files.createDirectories( repoDir );
|
} catch (IOException e) {
|
||||||
}
|
log.error("Could not create directory {} for repository {}", repo.getLocalPath(), repo.getId(), e);
|
||||||
catch ( IOException e )
|
throw new RepositoryException("Could not create directory for repository " + repo.getLocalPath());
|
||||||
{
|
|
||||||
log.error("Could not create directory {} for repository {}", repo.getAbsoluteLocation(), repo.getId(), e);
|
|
||||||
throw new RepositoryException( "Could not create directory for repository "+repo.getAbsoluteLocation() );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
repo.setSchedulingDefinition(cfg.getRefreshCronExpression());
|
repo.setSchedulingDefinition(cfg.getRefreshCronExpression());
|
||||||
repo.setBlocksRedeployment( cfg.isBlockRedeployments() );
|
repo.setBlocksRedeployment(cfg.isBlockRedeployments());
|
||||||
repo.setScanned( cfg.isScanned() );
|
repo.setScanned(cfg.isScanned());
|
||||||
if (cfg.isReleases()) {
|
if (cfg.isReleases()) {
|
||||||
repo.addActiveReleaseScheme( ReleaseScheme.RELEASE);
|
repo.addActiveReleaseScheme(ReleaseScheme.RELEASE);
|
||||||
}
|
}
|
||||||
if (cfg.isSnapshots()) {
|
if (cfg.isSnapshots()) {
|
||||||
repo.addActiveReleaseScheme(ReleaseScheme.SNAPSHOT);
|
repo.addActiveReleaseScheme(ReleaseScheme.SNAPSHOT);
|
||||||
}
|
}
|
||||||
|
|
||||||
StagingRepositoryFeature stagingRepositoryFeature = repo.getFeature( StagingRepositoryFeature.class ).get();
|
StagingRepositoryFeature stagingRepositoryFeature = repo.getFeature(StagingRepositoryFeature.class).get();
|
||||||
stagingRepositoryFeature.setStageRepoNeeded( cfg.isStageRepoNeeded() );
|
stagingRepositoryFeature.setStageRepoNeeded(cfg.isStageRepoNeeded());
|
||||||
|
|
||||||
IndexCreationFeature indexCreationFeature = repo.getFeature( IndexCreationFeature.class ).get( );
|
IndexCreationFeature indexCreationFeature = repo.getFeature(IndexCreationFeature.class).get();
|
||||||
indexCreationFeature.setSkipPackedIndexCreation( cfg.isSkipPackedIndexCreation() );
|
indexCreationFeature.setSkipPackedIndexCreation(cfg.isSkipPackedIndexCreation());
|
||||||
indexCreationFeature.setIndexPath( getURIFromString( cfg.getIndexDir() ) );
|
indexCreationFeature.setIndexPath(getURIFromString(cfg.getIndexDir()));
|
||||||
Path indexPath;
|
Path indexPath;
|
||||||
if (indexCreationFeature.getIndexPath().getScheme()==null) {
|
if (indexCreationFeature.getIndexPath().getScheme() == null) {
|
||||||
indexPath = Paths.get(indexCreationFeature.getIndexPath().getPath());
|
indexPath = Paths.get(indexCreationFeature.getIndexPath().getPath());
|
||||||
} else {
|
} else {
|
||||||
indexPath = Paths.get(indexCreationFeature.getIndexPath());
|
indexPath = Paths.get(indexCreationFeature.getIndexPath());
|
||||||
@ -184,44 +171,39 @@ public void updateManagedInstance( EditableManagedRepository repo , ManagedRepos
|
|||||||
if (indexPath.isAbsolute()) {
|
if (indexPath.isAbsolute()) {
|
||||||
absoluteIndexPath = indexPath;
|
absoluteIndexPath = indexPath;
|
||||||
} else {
|
} else {
|
||||||
absoluteIndexPath = PathUtil.getPathFromUri( repo.getLocation()).resolve(indexCreationFeature.getIndexPath().getPath());
|
absoluteIndexPath = PathUtil.getPathFromUri(repo.getLocation()).resolve(indexCreationFeature.getIndexPath().getPath());
|
||||||
}
|
}
|
||||||
try
|
try {
|
||||||
{
|
Files.createDirectories(absoluteIndexPath);
|
||||||
Files.createDirectories( absoluteIndexPath );
|
} catch (IOException e) {
|
||||||
}
|
|
||||||
catch ( IOException e )
|
|
||||||
{
|
|
||||||
log.error("Could not create index directory {}", absoluteIndexPath);
|
log.error("Could not create index directory {}", absoluteIndexPath);
|
||||||
throw new RepositoryException( "Could not create index directory "+absoluteIndexPath );
|
throw new RepositoryException("Could not create index directory " + absoluteIndexPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
ArtifactCleanupFeature artifactCleanupFeature = repo.getFeature( ArtifactCleanupFeature.class ).get();
|
ArtifactCleanupFeature artifactCleanupFeature = repo.getFeature(ArtifactCleanupFeature.class).get();
|
||||||
|
|
||||||
artifactCleanupFeature.setDeleteReleasedSnapshots( cfg.isDeleteReleasedSnapshots() );
|
artifactCleanupFeature.setDeleteReleasedSnapshots(cfg.isDeleteReleasedSnapshots());
|
||||||
artifactCleanupFeature.setRetentionCount( cfg.getRetentionCount() );
|
artifactCleanupFeature.setRetentionCount(cfg.getRetentionCount());
|
||||||
artifactCleanupFeature.setRetentionPeriod( Period.ofDays( cfg.getRetentionPeriod() ) );
|
artifactCleanupFeature.setRetentionPeriod(Period.ofDays(cfg.getRetentionPeriod()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ManagedRepository createStagingInstance( ManagedRepositoryConfiguration baseConfiguration ) throws RepositoryException
|
public ManagedRepository createStagingInstance(ManagedRepositoryConfiguration baseConfiguration) throws RepositoryException {
|
||||||
{
|
|
||||||
log.debug("Creating staging instance for {}", baseConfiguration.getId());
|
log.debug("Creating staging instance for {}", baseConfiguration.getId());
|
||||||
return createManagedInstance( getStageRepoConfig( baseConfiguration ) );
|
return createManagedInstance(getStageRepoConfig(baseConfiguration));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RemoteRepository createRemoteInstance( RemoteRepositoryConfiguration cfg ) throws RepositoryException
|
public RemoteRepository createRemoteInstance(RemoteRepositoryConfiguration cfg) throws RepositoryException {
|
||||||
{
|
MavenRemoteRepository repo = new MavenRemoteRepository(cfg.getId(), cfg.getName(), archivaConfiguration.getRemoteRepositoryBaseDir());
|
||||||
MavenRemoteRepository repo = new MavenRemoteRepository( cfg.getId( ), cfg.getName( ) );
|
updateRemoteInstance(repo, cfg);
|
||||||
updateRemoteInstance( repo, cfg );
|
|
||||||
return repo;
|
return repo;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String convertUriToPath(URI uri) {
|
private String convertUriToPath(URI uri) {
|
||||||
if (uri.getScheme()==null) {
|
if (uri.getScheme() == null) {
|
||||||
return uri.getPath();
|
return uri.getPath();
|
||||||
} else if ("file".equals(uri.getScheme())) {
|
} else if ("file".equals(uri.getScheme())) {
|
||||||
return Paths.get(uri).toString();
|
return Paths.get(uri).toString();
|
||||||
@ -231,96 +213,83 @@ private String convertUriToPath(URI uri) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateRemoteInstance( EditableRemoteRepository repo, RemoteRepositoryConfiguration cfg ) throws RepositoryException
|
public void updateRemoteInstance(EditableRemoteRepository repo, RemoteRepositoryConfiguration cfg) throws RepositoryException {
|
||||||
{
|
setBaseConfig(repo, cfg);
|
||||||
setBaseConfig( repo, cfg );
|
repo.setCheckPath(cfg.getCheckPath());
|
||||||
repo.setCheckPath( cfg.getCheckPath() );
|
repo.setSchedulingDefinition(cfg.getRefreshCronExpression());
|
||||||
repo.setSchedulingDefinition( cfg.getRefreshCronExpression() );
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
repo.setLocation(new URI(cfg.getUrl()));
|
repo.setLocation(new URI(cfg.getUrl()));
|
||||||
|
} catch (UnsupportedURIException | URISyntaxException e) {
|
||||||
|
log.error("Could not set remote url " + cfg.getUrl());
|
||||||
|
throw new RepositoryException("The url config is not a valid uri: " + cfg.getUrl());
|
||||||
}
|
}
|
||||||
catch ( UnsupportedURIException | URISyntaxException e )
|
repo.setTimeout(Duration.ofSeconds(cfg.getTimeout()));
|
||||||
{
|
RemoteIndexFeature remoteIndexFeature = repo.getFeature(RemoteIndexFeature.class).get();
|
||||||
log.error("Could not set remote url "+cfg.getUrl());
|
remoteIndexFeature.setDownloadRemoteIndex(cfg.isDownloadRemoteIndex());
|
||||||
throw new RepositoryException( "The url config is not a valid uri: "+cfg.getUrl() );
|
remoteIndexFeature.setDownloadRemoteIndexOnStartup(cfg.isDownloadRemoteIndexOnStartup());
|
||||||
}
|
remoteIndexFeature.setDownloadTimeout(Duration.ofSeconds(cfg.getRemoteDownloadTimeout()));
|
||||||
repo.setTimeout( Duration.ofSeconds( cfg.getTimeout() ) );
|
remoteIndexFeature.setProxyId(cfg.getRemoteDownloadNetworkProxyId());
|
||||||
RemoteIndexFeature remoteIndexFeature = repo.getFeature( RemoteIndexFeature.class ).get();
|
if (cfg.isDownloadRemoteIndex()) {
|
||||||
remoteIndexFeature.setDownloadRemoteIndex( cfg.isDownloadRemoteIndex() );
|
try {
|
||||||
remoteIndexFeature.setDownloadRemoteIndexOnStartup( cfg.isDownloadRemoteIndexOnStartup() );
|
remoteIndexFeature.setIndexUri(new URI(cfg.getRemoteIndexUrl()));
|
||||||
remoteIndexFeature.setDownloadTimeout( Duration.ofSeconds( cfg.getRemoteDownloadTimeout()) );
|
} catch (URISyntaxException e) {
|
||||||
remoteIndexFeature.setProxyId( cfg.getRemoteDownloadNetworkProxyId() );
|
log.error("Could not set remote index url " + cfg.getRemoteIndexUrl());
|
||||||
if (cfg.isDownloadRemoteIndex())
|
remoteIndexFeature.setDownloadRemoteIndex(false);
|
||||||
{
|
remoteIndexFeature.setDownloadRemoteIndexOnStartup(false);
|
||||||
try
|
|
||||||
{
|
|
||||||
remoteIndexFeature.setIndexUri( new URI( cfg.getRemoteIndexUrl( ) ) );
|
|
||||||
}
|
|
||||||
catch ( URISyntaxException e )
|
|
||||||
{
|
|
||||||
log.error( "Could not set remote index url " + cfg.getRemoteIndexUrl( ) );
|
|
||||||
remoteIndexFeature.setDownloadRemoteIndex( false );
|
|
||||||
remoteIndexFeature.setDownloadRemoteIndexOnStartup( false );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
repo.setExtraHeaders( cfg.getExtraHeaders() );
|
repo.setExtraHeaders(cfg.getExtraHeaders());
|
||||||
repo.setExtraParameters( cfg.getExtraParameters() );
|
repo.setExtraParameters(cfg.getExtraParameters());
|
||||||
PasswordCredentials credentials = new PasswordCredentials("", new char[0]);
|
PasswordCredentials credentials = new PasswordCredentials("", new char[0]);
|
||||||
if (cfg.getPassword()!=null && cfg.getUsername()!=null)
|
if (cfg.getPassword() != null && cfg.getUsername() != null) {
|
||||||
{
|
credentials.setPassword(cfg.getPassword().toCharArray());
|
||||||
credentials.setPassword( cfg.getPassword( ).toCharArray( ) );
|
credentials.setUsername(cfg.getUsername());
|
||||||
credentials.setUsername( cfg.getUsername() );
|
repo.setCredentials(credentials);
|
||||||
repo.setCredentials( credentials );
|
|
||||||
} else {
|
} else {
|
||||||
credentials.setPassword( new char[0] );
|
credentials.setPassword(new char[0]);
|
||||||
}
|
}
|
||||||
if (cfg.getIndexDir()!=null) {
|
if (cfg.getIndexDir() != null) {
|
||||||
IndexCreationFeature indexCreationFeature = repo.getFeature( IndexCreationFeature.class ).get();
|
IndexCreationFeature indexCreationFeature = repo.getFeature(IndexCreationFeature.class).get();
|
||||||
indexCreationFeature.setIndexPath( getURIFromString( cfg.getIndexDir() ) );
|
indexCreationFeature.setIndexPath(getURIFromString(cfg.getIndexDir()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RemoteRepositoryConfiguration getRemoteConfiguration( RemoteRepository remoteRepository ) throws RepositoryException
|
public RemoteRepositoryConfiguration getRemoteConfiguration(RemoteRepository remoteRepository) throws RepositoryException {
|
||||||
{
|
|
||||||
if (!(remoteRepository instanceof MavenRemoteRepository)) {
|
if (!(remoteRepository instanceof MavenRemoteRepository)) {
|
||||||
log.error("Wrong remote repository type "+remoteRepository.getClass().getName());
|
log.error("Wrong remote repository type " + remoteRepository.getClass().getName());
|
||||||
throw new RepositoryException( "The given repository type cannot be handled by the maven provider: "+remoteRepository.getClass().getName() );
|
throw new RepositoryException("The given repository type cannot be handled by the maven provider: " + remoteRepository.getClass().getName());
|
||||||
}
|
}
|
||||||
RemoteRepositoryConfiguration cfg = new RemoteRepositoryConfiguration();
|
RemoteRepositoryConfiguration cfg = new RemoteRepositoryConfiguration();
|
||||||
cfg.setType( remoteRepository.getType().toString() );
|
cfg.setType(remoteRepository.getType().toString());
|
||||||
cfg.setId( remoteRepository.getId() );
|
cfg.setId(remoteRepository.getId());
|
||||||
cfg.setName( remoteRepository.getName() );
|
cfg.setName(remoteRepository.getName());
|
||||||
cfg.setDescription( remoteRepository.getDescription() );
|
cfg.setDescription(remoteRepository.getDescription());
|
||||||
cfg.setUrl(remoteRepository.getLocation().toString());
|
cfg.setUrl(remoteRepository.getLocation().toString());
|
||||||
cfg.setTimeout( (int)remoteRepository.getTimeout().toMillis()/1000 );
|
cfg.setTimeout((int) remoteRepository.getTimeout().toMillis() / 1000);
|
||||||
cfg.setCheckPath( remoteRepository.getCheckPath() );
|
cfg.setCheckPath(remoteRepository.getCheckPath());
|
||||||
RepositoryCredentials creds = remoteRepository.getLoginCredentials( );
|
RepositoryCredentials creds = remoteRepository.getLoginCredentials();
|
||||||
if (creds!=null)
|
if (creds != null) {
|
||||||
{
|
|
||||||
if (creds instanceof PasswordCredentials) {
|
if (creds instanceof PasswordCredentials) {
|
||||||
PasswordCredentials pCreds = (PasswordCredentials) creds;
|
PasswordCredentials pCreds = (PasswordCredentials) creds;
|
||||||
cfg.setPassword( new String(pCreds.getPassword()) );
|
cfg.setPassword(new String(pCreds.getPassword()));
|
||||||
cfg.setUsername( pCreds.getUsername() );
|
cfg.setUsername(pCreds.getUsername());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cfg.setLayout( remoteRepository.getLayout() );
|
cfg.setLayout(remoteRepository.getLayout());
|
||||||
cfg.setExtraParameters( remoteRepository.getExtraParameters() );
|
cfg.setExtraParameters(remoteRepository.getExtraParameters());
|
||||||
cfg.setExtraHeaders( remoteRepository.getExtraHeaders() );
|
cfg.setExtraHeaders(remoteRepository.getExtraHeaders());
|
||||||
cfg.setRefreshCronExpression( remoteRepository.getSchedulingDefinition() );
|
cfg.setRefreshCronExpression(remoteRepository.getSchedulingDefinition());
|
||||||
|
|
||||||
IndexCreationFeature indexCreationFeature = remoteRepository.getFeature( IndexCreationFeature.class ).get();
|
|
||||||
cfg.setIndexDir( convertUriToPath( indexCreationFeature.getIndexPath()));
|
|
||||||
|
|
||||||
RemoteIndexFeature remoteIndexFeature = remoteRepository.getFeature( RemoteIndexFeature.class ).get();
|
|
||||||
cfg.setRemoteIndexUrl( remoteIndexFeature.getIndexUri().toString() );
|
|
||||||
cfg.setRemoteDownloadTimeout( (int)remoteIndexFeature.getDownloadTimeout().get( ChronoUnit.SECONDS ) );
|
|
||||||
cfg.setDownloadRemoteIndexOnStartup( remoteIndexFeature.isDownloadRemoteIndexOnStartup() );
|
|
||||||
cfg.setDownloadRemoteIndex( remoteIndexFeature.isDownloadRemoteIndex() );
|
|
||||||
cfg.setRemoteDownloadNetworkProxyId( remoteIndexFeature.getProxyId() );
|
|
||||||
|
|
||||||
|
IndexCreationFeature indexCreationFeature = remoteRepository.getFeature(IndexCreationFeature.class).get();
|
||||||
|
cfg.setIndexDir(convertUriToPath(indexCreationFeature.getIndexPath()));
|
||||||
|
|
||||||
|
RemoteIndexFeature remoteIndexFeature = remoteRepository.getFeature(RemoteIndexFeature.class).get();
|
||||||
|
cfg.setRemoteIndexUrl(remoteIndexFeature.getIndexUri().toString());
|
||||||
|
cfg.setRemoteDownloadTimeout((int) remoteIndexFeature.getDownloadTimeout().get(ChronoUnit.SECONDS));
|
||||||
|
cfg.setDownloadRemoteIndexOnStartup(remoteIndexFeature.isDownloadRemoteIndexOnStartup());
|
||||||
|
cfg.setDownloadRemoteIndex(remoteIndexFeature.isDownloadRemoteIndex());
|
||||||
|
cfg.setRemoteDownloadNetworkProxyId(remoteIndexFeature.getProxyId());
|
||||||
|
|
||||||
|
|
||||||
return cfg;
|
return cfg;
|
||||||
@ -328,125 +297,104 @@ public RemoteRepositoryConfiguration getRemoteConfiguration( RemoteRepository re
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ManagedRepositoryConfiguration getManagedConfiguration( ManagedRepository managedRepository ) throws RepositoryException
|
public ManagedRepositoryConfiguration getManagedConfiguration(ManagedRepository managedRepository) throws RepositoryException {
|
||||||
{
|
|
||||||
if (!(managedRepository instanceof MavenManagedRepository)) {
|
if (!(managedRepository instanceof MavenManagedRepository)) {
|
||||||
log.error("Wrong remote repository type "+managedRepository.getClass().getName());
|
log.error("Wrong remote repository type " + managedRepository.getClass().getName());
|
||||||
throw new RepositoryException( "The given repository type cannot be handled by the maven provider: "+managedRepository.getClass().getName() );
|
throw new RepositoryException("The given repository type cannot be handled by the maven provider: " + managedRepository.getClass().getName());
|
||||||
}
|
}
|
||||||
ManagedRepositoryConfiguration cfg = new ManagedRepositoryConfiguration();
|
ManagedRepositoryConfiguration cfg = new ManagedRepositoryConfiguration();
|
||||||
cfg.setType( managedRepository.getType().toString() );
|
cfg.setType(managedRepository.getType().toString());
|
||||||
cfg.setId( managedRepository.getId() );
|
cfg.setId(managedRepository.getId());
|
||||||
cfg.setName( managedRepository.getName() );
|
cfg.setName(managedRepository.getName());
|
||||||
cfg.setDescription( managedRepository.getDescription() );
|
cfg.setDescription(managedRepository.getDescription());
|
||||||
cfg.setLocation( convertUriToPath( managedRepository.getLocation() ) );
|
cfg.setLocation(convertUriToPath(managedRepository.getLocation()));
|
||||||
cfg.setLayout( managedRepository.getLayout() );
|
cfg.setLayout(managedRepository.getLayout());
|
||||||
cfg.setRefreshCronExpression( managedRepository.getSchedulingDefinition() );
|
cfg.setRefreshCronExpression(managedRepository.getSchedulingDefinition());
|
||||||
cfg.setScanned( managedRepository.isScanned() );
|
cfg.setScanned(managedRepository.isScanned());
|
||||||
cfg.setBlockRedeployments( managedRepository.blocksRedeployments() );
|
cfg.setBlockRedeployments(managedRepository.blocksRedeployments());
|
||||||
StagingRepositoryFeature stagingRepositoryFeature = managedRepository.getFeature( StagingRepositoryFeature.class ).get();
|
StagingRepositoryFeature stagingRepositoryFeature = managedRepository.getFeature(StagingRepositoryFeature.class).get();
|
||||||
cfg.setStageRepoNeeded(stagingRepositoryFeature.isStageRepoNeeded());
|
cfg.setStageRepoNeeded(stagingRepositoryFeature.isStageRepoNeeded());
|
||||||
IndexCreationFeature indexCreationFeature = managedRepository.getFeature( IndexCreationFeature.class ).get();
|
IndexCreationFeature indexCreationFeature = managedRepository.getFeature(IndexCreationFeature.class).get();
|
||||||
cfg.setIndexDir(convertUriToPath( indexCreationFeature.getIndexPath() ));
|
cfg.setIndexDir(convertUriToPath(indexCreationFeature.getIndexPath()));
|
||||||
cfg.setSkipPackedIndexCreation( indexCreationFeature.isSkipPackedIndexCreation() );
|
cfg.setSkipPackedIndexCreation(indexCreationFeature.isSkipPackedIndexCreation());
|
||||||
|
|
||||||
ArtifactCleanupFeature artifactCleanupFeature = managedRepository.getFeature( ArtifactCleanupFeature.class ).get();
|
ArtifactCleanupFeature artifactCleanupFeature = managedRepository.getFeature(ArtifactCleanupFeature.class).get();
|
||||||
cfg.setRetentionCount( artifactCleanupFeature.getRetentionCount());
|
cfg.setRetentionCount(artifactCleanupFeature.getRetentionCount());
|
||||||
cfg.setRetentionPeriod( artifactCleanupFeature.getRetentionPeriod().getDays() );
|
cfg.setRetentionPeriod(artifactCleanupFeature.getRetentionPeriod().getDays());
|
||||||
cfg.setDeleteReleasedSnapshots(artifactCleanupFeature.isDeleteReleasedSnapshots());
|
cfg.setDeleteReleasedSnapshots(artifactCleanupFeature.isDeleteReleasedSnapshots());
|
||||||
|
|
||||||
if (managedRepository.getActiveReleaseSchemes().contains( ReleaseScheme.RELEASE )) {
|
if (managedRepository.getActiveReleaseSchemes().contains(ReleaseScheme.RELEASE)) {
|
||||||
cfg.setReleases( true );
|
cfg.setReleases(true);
|
||||||
} else {
|
} else {
|
||||||
cfg.setReleases( false );
|
cfg.setReleases(false);
|
||||||
}
|
}
|
||||||
if (managedRepository.getActiveReleaseSchemes().contains( ReleaseScheme.SNAPSHOT )) {
|
if (managedRepository.getActiveReleaseSchemes().contains(ReleaseScheme.SNAPSHOT)) {
|
||||||
cfg.setSnapshots( true );
|
cfg.setSnapshots(true);
|
||||||
} else {
|
} else {
|
||||||
cfg.setSnapshots( false );
|
cfg.setSnapshots(false);
|
||||||
}
|
}
|
||||||
return cfg;
|
return cfg;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ManagedRepositoryConfiguration getStageRepoConfig( ManagedRepositoryConfiguration repository )
|
private ManagedRepositoryConfiguration getStageRepoConfig(ManagedRepositoryConfiguration repository) {
|
||||||
{
|
|
||||||
ManagedRepositoryConfiguration stagingRepository = new ManagedRepositoryConfiguration();
|
ManagedRepositoryConfiguration stagingRepository = new ManagedRepositoryConfiguration();
|
||||||
stagingRepository.setId( repository.getId() + StagingRepositoryFeature.STAGING_REPO_POSTFIX );
|
stagingRepository.setId(repository.getId() + StagingRepositoryFeature.STAGING_REPO_POSTFIX);
|
||||||
stagingRepository.setLayout( repository.getLayout() );
|
stagingRepository.setLayout(repository.getLayout());
|
||||||
stagingRepository.setName( repository.getName() + StagingRepositoryFeature.STAGING_REPO_POSTFIX );
|
stagingRepository.setName(repository.getName() + StagingRepositoryFeature.STAGING_REPO_POSTFIX);
|
||||||
stagingRepository.setBlockRedeployments( repository.isBlockRedeployments() );
|
stagingRepository.setBlockRedeployments(repository.isBlockRedeployments());
|
||||||
stagingRepository.setRetentionPeriod( repository.getRetentionPeriod() );
|
stagingRepository.setRetentionPeriod(repository.getRetentionPeriod());
|
||||||
stagingRepository.setDeleteReleasedSnapshots( repository.isDeleteReleasedSnapshots() );
|
stagingRepository.setDeleteReleasedSnapshots(repository.isDeleteReleasedSnapshots());
|
||||||
stagingRepository.setStageRepoNeeded( false );
|
stagingRepository.setStageRepoNeeded(false);
|
||||||
|
|
||||||
String path = repository.getLocation();
|
String path = repository.getLocation();
|
||||||
int lastIndex = path.replace( '\\', '/' ).lastIndexOf( '/' );
|
int lastIndex = path.replace('\\', '/').lastIndexOf('/');
|
||||||
stagingRepository.setLocation( path.substring( 0, lastIndex ) + "/" + stagingRepository.getId() );
|
stagingRepository.setLocation(path.substring(0, lastIndex) + "/" + stagingRepository.getId());
|
||||||
|
|
||||||
if ( StringUtils.isNotBlank( repository.getIndexDir() ) )
|
if (StringUtils.isNotBlank(repository.getIndexDir())) {
|
||||||
{
|
|
||||||
Path indexDir = null;
|
Path indexDir = null;
|
||||||
try
|
try {
|
||||||
{
|
indexDir = Paths.get(new URI(repository.getIndexDir().startsWith("file://") ? repository.getIndexDir() : "file://" + repository.getIndexDir()));
|
||||||
indexDir = Paths.get( new URI(repository.getIndexDir().startsWith( "file://" ) ? repository.getIndexDir() : "file://"+repository.getIndexDir()) );
|
if (indexDir.isAbsolute()) {
|
||||||
if ( indexDir.isAbsolute() )
|
Path newDir = Paths.get(new URI(stagingRepository.getLocation().startsWith("file://") ? stagingRepository.getLocation() : "file://" + stagingRepository.getLocation())).resolve(".index");
|
||||||
{
|
|
||||||
Path newDir = Paths.get(new URI(stagingRepository.getLocation().startsWith( "file://" ) ? stagingRepository.getLocation() : "file://"+stagingRepository.getLocation())).resolve(".index");
|
|
||||||
log.debug("Changing index directory {} -> {}", indexDir, newDir);
|
log.debug("Changing index directory {} -> {}", indexDir, newDir);
|
||||||
stagingRepository.setIndexDir( newDir.toString() );
|
stagingRepository.setIndexDir(newDir.toString());
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
log.debug("Keeping index directory {}", repository.getIndexDir());
|
log.debug("Keeping index directory {}", repository.getIndexDir());
|
||||||
stagingRepository.setIndexDir( repository.getIndexDir() );
|
stagingRepository.setIndexDir(repository.getIndexDir());
|
||||||
}
|
}
|
||||||
}
|
} catch (URISyntaxException e) {
|
||||||
catch ( URISyntaxException e )
|
|
||||||
{
|
|
||||||
log.error("Could not parse index path as uri {}", repository.getIndexDir());
|
log.error("Could not parse index path as uri {}", repository.getIndexDir());
|
||||||
stagingRepository.setIndexDir( "" );
|
stagingRepository.setIndexDir("");
|
||||||
}
|
}
|
||||||
// in case of absolute dir do not use the same
|
// in case of absolute dir do not use the same
|
||||||
}
|
}
|
||||||
stagingRepository.setRefreshCronExpression( repository.getRefreshCronExpression() );
|
stagingRepository.setRefreshCronExpression(repository.getRefreshCronExpression());
|
||||||
stagingRepository.setReleases( repository.isReleases() );
|
stagingRepository.setReleases(repository.isReleases());
|
||||||
stagingRepository.setRetentionCount( repository.getRetentionCount() );
|
stagingRepository.setRetentionCount(repository.getRetentionCount());
|
||||||
stagingRepository.setScanned( repository.isScanned() );
|
stagingRepository.setScanned(repository.isScanned());
|
||||||
stagingRepository.setSnapshots( repository.isSnapshots() );
|
stagingRepository.setSnapshots(repository.isSnapshots());
|
||||||
stagingRepository.setSkipPackedIndexCreation( repository.isSkipPackedIndexCreation() );
|
stagingRepository.setSkipPackedIndexCreation(repository.isSkipPackedIndexCreation());
|
||||||
// do not duplicate description
|
// do not duplicate description
|
||||||
//stagingRepository.getDescription("")
|
//stagingRepository.getDescription("")
|
||||||
return stagingRepository;
|
return stagingRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setBaseConfig( EditableRepository repo, AbstractRepositoryConfiguration cfg) throws RepositoryException {
|
private void setBaseConfig(EditableRepository repo, AbstractRepositoryConfiguration cfg) throws RepositoryException {
|
||||||
String baseUriStr = archivaConfiguration.getConfiguration().getArchivaRuntimeConfiguration().getRepositoryBaseDirectory();
|
|
||||||
if (baseUriStr==null) {
|
URI baseUri = archivaConfiguration.getRepositoryBaseDir().toUri();
|
||||||
baseUriStr = Paths.get(System.getProperty( "appserver.base" )).resolve("repositories").normalize().toString();
|
repo.setBaseUri(baseUri);
|
||||||
}
|
|
||||||
try
|
repo.setName(repo.getPrimaryLocale(), cfg.getName());
|
||||||
{
|
repo.setDescription(repo.getPrimaryLocale(), cfg.getDescription());
|
||||||
URI baseUri = new URI(baseUriStr);
|
repo.setLayout(cfg.getLayout());
|
||||||
repo.setBaseUri( baseUri );
|
|
||||||
}
|
|
||||||
catch ( URISyntaxException e )
|
|
||||||
{
|
|
||||||
log.error("Could not set base URI {}: {}", baseUriStr, e.getMessage(), e);
|
|
||||||
throw new RepositoryException( "Could not set base URI "+ baseUriStr);
|
|
||||||
}
|
|
||||||
repo.setName( repo.getPrimaryLocale(), cfg.getName() );
|
|
||||||
repo.setDescription( repo.getPrimaryLocale(), cfg.getDescription() );
|
|
||||||
repo.setLayout( cfg.getLayout() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArchivaConfiguration getArchivaConfiguration( )
|
public ArchivaConfiguration getArchivaConfiguration() {
|
||||||
{
|
|
||||||
return archivaConfiguration;
|
return archivaConfiguration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration )
|
public void setArchivaConfiguration(ArchivaConfiguration archivaConfiguration) {
|
||||||
{
|
|
||||||
this.archivaConfiguration = archivaConfiguration;
|
this.archivaConfiguration = archivaConfiguration;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import org.apache.archiva.redback.components.registry.RegistryException;
|
import org.apache.archiva.redback.components.registry.RegistryException;
|
||||||
import org.apache.archiva.redback.components.registry.RegistryListener;
|
import org.apache.archiva.redback.components.registry.RegistryListener;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
@ -103,4 +104,23 @@ public Path getAppServerBaseDir() {
|
|||||||
return Paths.get("");
|
return Paths.get("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Path getRepositoryBaseDir() {
|
||||||
|
return getDataDirectory().resolve("repositories");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Path getRemoteRepositoryBaseDir() {
|
||||||
|
return getDataDirectory().resolve("remotes");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Path getDataDirectory() {
|
||||||
|
if (configuration!=null && StringUtils.isNotEmpty(configuration.getArchivaRuntimeConfiguration().getDataDirectory())) {
|
||||||
|
return Paths.get(configuration.getArchivaRuntimeConfiguration().getDataDirectory());
|
||||||
|
} else {
|
||||||
|
return getAppServerBaseDir().resolve("data");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
import org.apache.archiva.redback.components.registry.Registry;
|
import org.apache.archiva.redback.components.registry.Registry;
|
||||||
import org.apache.archiva.redback.components.registry.RegistryException;
|
import org.apache.archiva.redback.components.registry.RegistryException;
|
||||||
import org.apache.archiva.redback.components.registry.RegistryListener;
|
import org.apache.archiva.redback.components.registry.RegistryListener;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.easymock.IMocksControl;
|
import org.easymock.IMocksControl;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@ -146,4 +147,24 @@ public Path getAppServerBaseDir() {
|
|||||||
return Paths.get("");
|
return Paths.get("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Path getRepositoryBaseDir() {
|
||||||
|
return getDataDirectory().resolve("repositories");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Path getRemoteRepositoryBaseDir() {
|
||||||
|
return getDataDirectory().resolve("remotes");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Path getDataDirectory() {
|
||||||
|
if (configuration!=null && StringUtils.isNotEmpty(configuration.getArchivaRuntimeConfiguration().getDataDirectory())) {
|
||||||
|
return Paths.get(configuration.getArchivaRuntimeConfiguration().getDataDirectory());
|
||||||
|
} else {
|
||||||
|
return getAppServerBaseDir().resolve("data");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -53,14 +54,14 @@ public abstract class AbstractRepositoryLayerTestCase
|
|||||||
|
|
||||||
protected MavenManagedRepository createRepository( String id, String name, Path location )
|
protected MavenManagedRepository createRepository( String id, String name, Path location )
|
||||||
{
|
{
|
||||||
MavenManagedRepository repo = new MavenManagedRepository( id, name);
|
MavenManagedRepository repo = new MavenManagedRepository( id, name, location.getParent().toAbsolutePath());
|
||||||
repo.setLocation( location.toAbsolutePath().toUri() );
|
repo.setLocation( location.toAbsolutePath().toUri() );
|
||||||
return repo;
|
return repo;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected MavenRemoteRepository createRemoteRepository( String id, String name, String url ) throws URISyntaxException
|
protected MavenRemoteRepository createRemoteRepository( String id, String name, String url ) throws URISyntaxException
|
||||||
{
|
{
|
||||||
MavenRemoteRepository repo = new MavenRemoteRepository(id, name);
|
MavenRemoteRepository repo = new MavenRemoteRepository(id, name, Paths.get("target/remotes"));
|
||||||
repo.setLocation( new URI( url ) );
|
repo.setLocation( new URI( url ) );
|
||||||
return repo;
|
return repo;
|
||||||
}
|
}
|
||||||
@ -69,7 +70,7 @@ protected ManagedRepositoryContent createManagedRepositoryContent( String id, St
|
|||||||
String layout )
|
String layout )
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
MavenManagedRepository repo = new MavenManagedRepository( id, name );
|
MavenManagedRepository repo = new MavenManagedRepository( id, name, location.getParent() );
|
||||||
repo.setLocation( location.toAbsolutePath().toUri() );
|
repo.setLocation( location.toAbsolutePath().toUri() );
|
||||||
repo.setLayout( layout );
|
repo.setLayout( layout );
|
||||||
|
|
||||||
@ -83,7 +84,7 @@ protected ManagedRepositoryContent createManagedRepositoryContent( String id, St
|
|||||||
protected RemoteRepositoryContent createRemoteRepositoryContent( String id, String name, String url, String layout )
|
protected RemoteRepositoryContent createRemoteRepositoryContent( String id, String name, String url, String layout )
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
MavenRemoteRepository repo = new MavenRemoteRepository(id, name);
|
MavenRemoteRepository repo = new MavenRemoteRepository(id, name, Paths.get("target/remotes"));
|
||||||
repo.setLocation( new URI( url ) );
|
repo.setLocation( new URI( url ) );
|
||||||
repo.setLayout( layout );
|
repo.setLayout( layout );
|
||||||
|
|
||||||
|
@ -515,7 +515,7 @@ protected ManagedRepositoryContent createManagedRepositoryContent( String id, St
|
|||||||
String layout )
|
String layout )
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
MavenManagedRepository repo = new MavenManagedRepository( id, name);
|
MavenManagedRepository repo = new MavenManagedRepository( id, name, archivaConfiguration.getRepositoryBaseDir());
|
||||||
repo.setLocation( location.toAbsolutePath().toUri() );
|
repo.setLocation( location.toAbsolutePath().toUri() );
|
||||||
repo.setLayout( layout );
|
repo.setLayout( layout );
|
||||||
|
|
||||||
|
@ -41,6 +41,7 @@
|
|||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.Period;
|
import java.time.Period;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
@ -213,7 +214,7 @@ public void createRemoteInstance( ) throws Exception
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getManagedConfiguration() throws Exception {
|
public void getManagedConfiguration() throws Exception {
|
||||||
MavenManagedRepository repo = new MavenManagedRepository( "test01", "My Test repo" );
|
MavenManagedRepository repo = new MavenManagedRepository( "test01", "My Test repo", Paths.get("target/repositories") );
|
||||||
|
|
||||||
repo.setLocation( new URI("file:///this.is/a/test") );
|
repo.setLocation( new URI("file:///this.is/a/test") );
|
||||||
repo.setScanned( true );
|
repo.setScanned( true );
|
||||||
@ -258,7 +259,7 @@ public void getManagedConfiguration() throws Exception {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getRemoteConfiguration() throws Exception {
|
public void getRemoteConfiguration() throws Exception {
|
||||||
MavenRemoteRepository repo = new MavenRemoteRepository( "test01", "My Test repo" );
|
MavenRemoteRepository repo = new MavenRemoteRepository( "test01", "My Test repo", Paths.get("target/remotes") );
|
||||||
|
|
||||||
repo.setLocation( new URI("https://this.is/a/test") );
|
repo.setLocation( new URI("https://this.is/a/test") );
|
||||||
repo.setScanned( true );
|
repo.setScanned( true );
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -48,17 +49,17 @@ public void testGetLogicalPath()
|
|||||||
{
|
{
|
||||||
String href = "/repository/internal/org/apache/maven/someartifact.jar";
|
String href = "/repository/internal/org/apache/maven/someartifact.jar";
|
||||||
Assert.assertEquals( "/org/apache/maven/someartifact.jar",
|
Assert.assertEquals( "/org/apache/maven/someartifact.jar",
|
||||||
repositoryStorage.getFilePath( href, new MavenManagedRepository( "repo01", "repo01") ) );
|
repositoryStorage.getFilePath( href, new MavenManagedRepository( "repo01", "repo01", Paths.get("target/repositories")) ) );
|
||||||
|
|
||||||
href = "repository/internal/org/apache/maven/someartifact.jar";
|
href = "repository/internal/org/apache/maven/someartifact.jar";
|
||||||
Assert.assertEquals( "/org/apache/maven/someartifact.jar",
|
Assert.assertEquals( "/org/apache/maven/someartifact.jar",
|
||||||
repositoryStorage.getFilePath( href, new MavenManagedRepository( "repo01", "repo01" ) ) );
|
repositoryStorage.getFilePath( href, new MavenManagedRepository( "repo01", "repo01", Paths.get("target/repositories") ) ) );
|
||||||
|
|
||||||
href = "repository/internal/org/apache/maven/";
|
href = "repository/internal/org/apache/maven/";
|
||||||
Assert.assertEquals( "/org/apache/maven/", repositoryStorage.getFilePath( href, new MavenManagedRepository("repo01", "repo01") ) );
|
Assert.assertEquals( "/org/apache/maven/", repositoryStorage.getFilePath( href, new MavenManagedRepository("repo01", "repo01", Paths.get("target/repositories")) ) );
|
||||||
|
|
||||||
href = "mypath";
|
href = "mypath";
|
||||||
Assert.assertEquals( "/", repositoryStorage.getFilePath( href, new MavenManagedRepository("repo01", "repo01") ) );
|
Assert.assertEquals( "/", repositoryStorage.getFilePath( href, new MavenManagedRepository("repo01", "repo01", Paths.get("target/repositories")) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ public void setUp()
|
|||||||
|
|
||||||
assertNotNull( consumer );
|
assertNotNull( consumer );
|
||||||
|
|
||||||
config = new BasicManagedRepository(TEST_REPO, TEST_REPO);
|
config = new BasicManagedRepository(TEST_REPO, TEST_REPO, Paths.get("target"));
|
||||||
config.setLocation( Paths.get( "target/test-repository" ).toAbsolutePath().toUri() );
|
config.setLocation( Paths.get( "target/test-repository" ).toAbsolutePath().toUri() );
|
||||||
|
|
||||||
metadataRepository = mock( MetadataRepository.class );
|
metadataRepository = mock( MetadataRepository.class );
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
import org.apache.archiva.redback.components.registry.RegistryException;
|
import org.apache.archiva.redback.components.registry.RegistryException;
|
||||||
import org.apache.archiva.redback.components.registry.RegistryListener;
|
import org.apache.archiva.redback.components.registry.RegistryListener;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
@ -103,4 +104,29 @@ public Path getAppServerBaseDir() {
|
|||||||
return Paths.get("");
|
return Paths.get("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Path getRepositoryBaseDir() {
|
||||||
|
return getDataDirectory().resolve("repositories");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Path getRemoteRepositoryBaseDir() {
|
||||||
|
return getDataDirectory().resolve("remotes");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Path getDataDirectory() {
|
||||||
|
if (configuration!=null && StringUtils.isNotEmpty(configuration.getArchivaRuntimeConfiguration().getDataDirectory())) {
|
||||||
|
Path dataDir = Paths.get(configuration.getArchivaRuntimeConfiguration().getDataDirectory());
|
||||||
|
if (dataDir.isAbsolute()) {
|
||||||
|
return dataDir;
|
||||||
|
} else {
|
||||||
|
return getAppServerBaseDir().resolve(dataDir);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return getAppServerBaseDir().resolve("data");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user