mirror of https://github.com/apache/archiva.git
Adding local path to repository API
This commit is contained in:
parent
2fe8227634
commit
754b2d5940
|
@ -168,7 +168,7 @@ public class ArchivaCli
|
|||
private void doScan( String path, String[] consumers )
|
||||
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() );
|
||||
|
||||
List<KnownRepositoryContentConsumer> knownConsumerList = new ArrayList<>();
|
||||
|
|
|
@ -102,6 +102,12 @@ public interface ArchivaConfiguration
|
|||
*/
|
||||
public Path getRepositoryBaseDir();
|
||||
|
||||
/**
|
||||
* Returns the base directory for remote repositories
|
||||
* @return
|
||||
*/
|
||||
public Path getRemoteRepositoryBaseDir();
|
||||
|
||||
/**
|
||||
* Returns the data directory where repositories and metadata reside
|
||||
* @return
|
||||
|
|
|
@ -90,6 +90,8 @@ import java.util.Set;
|
|||
* <p>
|
||||
* 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.
|
||||
*
|
||||
* FIXME: The synchronization must be improved, the current impl may lead to inconsistent data or multiple getConfiguration() calls (martin_s@apache.org)
|
||||
* </p>
|
||||
*/
|
||||
@Service("archivaConfiguration#default")
|
||||
|
@ -176,6 +178,7 @@ public class DefaultArchivaConfiguration
|
|||
|
||||
private volatile Path dataDirectory;
|
||||
private volatile Path repositoryBaseDirectory;
|
||||
private volatile Path remoteRepositoryBaseDirectory;
|
||||
|
||||
@PostConstruct
|
||||
private void init() {
|
||||
|
@ -261,6 +264,17 @@ public class DefaultArchivaConfiguration
|
|||
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();
|
||||
|
@ -941,6 +955,14 @@ public class DefaultArchivaConfiguration
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path getRemoteRepositoryBaseDir() {
|
||||
if (remoteRepositoryBaseDirectory==null) {
|
||||
getConfiguration();
|
||||
}
|
||||
return remoteRepositoryBaseDirectory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path getDataDirectory() {
|
||||
if (dataDirectory==null) {
|
||||
|
|
|
@ -1546,6 +1546,13 @@
|
|||
<type>String</type>
|
||||
<required>false</required>
|
||||
</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>
|
||||
<name>defaultLanguage</name>
|
||||
<type>String</type>
|
||||
|
|
|
@ -39,7 +39,9 @@ import org.apache.archiva.repository.features.RemoteIndexFeature;
|
|||
import org.apache.archiva.repository.features.StagingRepositoryFeature;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
||||
import java.net.URI;
|
||||
import java.nio.file.Paths;
|
||||
import java.time.Duration;
|
||||
import java.time.Period;
|
||||
import java.util.HashSet;
|
||||
|
@ -69,19 +71,19 @@ public class RepositoryProviderMock implements RepositoryProvider
|
|||
@Override
|
||||
public EditableManagedRepository createManagedInstance( String id, String name )
|
||||
{
|
||||
return new BasicManagedRepository( id, name );
|
||||
return new BasicManagedRepository( id, name, Paths.get("target/repositories") );
|
||||
}
|
||||
|
||||
@Override
|
||||
public EditableRemoteRepository createRemoteInstance( String id, String name )
|
||||
{
|
||||
return new BasicRemoteRepository( id, name );
|
||||
return new BasicRemoteRepository( id, name , Paths.get("target/remotes"));
|
||||
}
|
||||
|
||||
@Override
|
||||
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 );
|
||||
return managedRepository;
|
||||
}
|
||||
|
@ -128,7 +130,7 @@ public class RepositoryProviderMock implements RepositoryProvider
|
|||
public ManagedRepository createStagingInstance( ManagedRepositoryConfiguration configuration ) throws RepositoryException
|
||||
{
|
||||
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 );
|
||||
return managedRepository;
|
||||
}
|
||||
|
@ -136,7 +138,7 @@ public class RepositoryProviderMock implements RepositoryProvider
|
|||
@Override
|
||||
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 );
|
||||
return remoteRepository;
|
||||
}
|
||||
|
|
|
@ -84,7 +84,7 @@ public class SimpleArtifactConsumerTest
|
|||
Files.createDirectories( repoDir );
|
||||
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() );
|
||||
|
||||
repositoryRegistry.putRepository(testRepository);
|
||||
|
|
|
@ -47,9 +47,10 @@ public class ArtifactMissingChecksumsConsumerTest
|
|||
{
|
||||
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.setLocation( Paths.get( "target/test-classes/test-repo/" ).toUri() );
|
||||
repoConfig.setLocation(basePath.resolve("test-repo/" ).toUri() );
|
||||
|
||||
consumer = applicationContext.getBean( "knownRepositoryContentConsumer#create-missing-checksums",
|
||||
KnownRepositoryContentConsumer.class );
|
||||
|
|
|
@ -166,13 +166,14 @@ public abstract class AbstractRepositoryPurgeTest
|
|||
|
||||
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.SNAPSHOT );
|
||||
ArtifactCleanupFeature atf = config.getFeature( ArtifactCleanupFeature.class ).get();
|
||||
atf.setRetentionPeriod( Period.ofDays( TEST_DAYS_OLDER) );
|
||||
String path = AbstractRepositoryPurgeTest.fixPath(
|
||||
Paths.get( "target/test-" + getName() + "/" + repoId ).toAbsolutePath().toString() );
|
||||
basePath.resolve( repoId ).toAbsolutePath().toString() );
|
||||
config.setLocation( new URI( path ) );
|
||||
atf.setDeleteReleasedSnapshots( true );
|
||||
atf.setRetentionCount( TEST_RETENTION_COUNT );
|
||||
|
|
|
@ -40,6 +40,7 @@ import org.apache.archiva.repository.features.StagingRepositoryFeature;
|
|||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.net.URI;
|
||||
import java.nio.file.Paths;
|
||||
import java.time.Duration;
|
||||
import java.time.Period;
|
||||
import java.util.HashSet;
|
||||
|
@ -69,19 +70,19 @@ public class RepositoryProviderMock implements RepositoryProvider
|
|||
@Override
|
||||
public EditableManagedRepository createManagedInstance( String id, String name )
|
||||
{
|
||||
return new BasicManagedRepository( id, name );
|
||||
return new BasicManagedRepository( id, name, Paths.get("target/repositories") );
|
||||
}
|
||||
|
||||
@Override
|
||||
public EditableRemoteRepository createRemoteInstance( String id, String name )
|
||||
{
|
||||
return new BasicRemoteRepository( id, name );
|
||||
return new BasicRemoteRepository( id, name, Paths.get("target/remotes") );
|
||||
}
|
||||
|
||||
@Override
|
||||
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 );
|
||||
return managedRepository;
|
||||
}
|
||||
|
@ -128,7 +129,7 @@ public class RepositoryProviderMock implements RepositoryProvider
|
|||
public ManagedRepository createStagingInstance( ManagedRepositoryConfiguration configuration ) throws RepositoryException
|
||||
{
|
||||
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 );
|
||||
return managedRepository;
|
||||
}
|
||||
|
@ -136,7 +137,7 @@ public class RepositoryProviderMock implements RepositoryProvider
|
|||
@Override
|
||||
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 );
|
||||
return remoteRepository;
|
||||
}
|
||||
|
|
|
@ -132,7 +132,7 @@ public class NexusIndexerConsumerTest
|
|||
// initialize to set the file types to be processed
|
||||
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.setLayout( "default" );
|
||||
repositoryConfig.setScanned( true );
|
||||
|
|
|
@ -92,7 +92,7 @@ public class DefaultLegacyRepositoryConverter
|
|||
{
|
||||
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.setLayout( "legacy" );
|
||||
|
||||
|
|
|
@ -521,13 +521,7 @@ public class MavenIndexManager implements ArchivaIndexManager
|
|||
|
||||
IndexingContext context;
|
||||
// take care first about repository location as can be relative
|
||||
Path repositoryDirectory = PathUtil.getPathFromUri( repository.getLocation( ) );
|
||||
|
||||
if ( !repositoryDirectory.isAbsolute( ) )
|
||||
{
|
||||
repositoryDirectory =
|
||||
repositoryDirectory.resolve( "repositories" ).resolve( repositoryDirectory );
|
||||
}
|
||||
Path repositoryDirectory = repository.getLocalPath();
|
||||
|
||||
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 @@ public abstract class AbstractProxyTestCase
|
|||
protected ManagedRepositoryContent createRepository( String id, String name, String path, String layout )
|
||||
throws Exception
|
||||
{
|
||||
MavenManagedRepository repo = new MavenManagedRepository(id, name);
|
||||
MavenManagedRepository repo = new MavenManagedRepository(id, name, Paths.get(path).getParent());
|
||||
repo.setLocation( new URI(path) );
|
||||
repo.setLayout( layout );
|
||||
|
||||
|
|
|
@ -123,7 +123,7 @@ public class HttpProxyTransferTest
|
|||
// Make the destination dir.
|
||||
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.setLayout( "default" );
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.apache.archiva.configuration.*;
|
|||
import org.apache.archiva.redback.components.registry.Registry;
|
||||
import org.apache.archiva.redback.components.registry.RegistryException;
|
||||
import org.apache.archiva.redback.components.registry.RegistryListener;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.easymock.EasyMock;
|
||||
import org.easymock.IMocksControl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -160,4 +161,24 @@ public class MockConfiguration
|
|||
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.apache.archiva.repository.features.StagingRepositoryFeature;
|
|||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.net.URI;
|
||||
import java.nio.file.Paths;
|
||||
import java.time.Duration;
|
||||
import java.time.Period;
|
||||
import java.util.HashSet;
|
||||
|
@ -69,19 +70,19 @@ public class RepositoryProviderMock implements RepositoryProvider
|
|||
@Override
|
||||
public EditableManagedRepository createManagedInstance( String id, String name )
|
||||
{
|
||||
return new BasicManagedRepository( id, name );
|
||||
return new BasicManagedRepository( id, name , Paths.get("target/repositories"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EditableRemoteRepository createRemoteInstance( String id, String name )
|
||||
{
|
||||
return new BasicRemoteRepository( id, name );
|
||||
return new BasicRemoteRepository( id, name, Paths.get("target/remotes") );
|
||||
}
|
||||
|
||||
@Override
|
||||
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 );
|
||||
return managedRepository;
|
||||
}
|
||||
|
@ -128,7 +129,7 @@ public class RepositoryProviderMock implements RepositoryProvider
|
|||
public ManagedRepository createStagingInstance( ManagedRepositoryConfiguration configuration ) throws RepositoryException
|
||||
{
|
||||
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 );
|
||||
return managedRepository;
|
||||
}
|
||||
|
@ -136,7 +137,7 @@ public class RepositoryProviderMock implements RepositoryProvider
|
|||
@Override
|
||||
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 );
|
||||
return remoteRepository;
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.apache.archiva.indexer.ArchivaIndexingContext;
|
|||
import org.apache.archiva.repository.features.RepositoryFeature;
|
||||
|
||||
import java.net.URI;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
@ -86,14 +87,22 @@ public interface Repository {
|
|||
*/
|
||||
URI getLocation();
|
||||
|
||||
|
||||
/**
|
||||
* This returns the absolute location uri of this repository. Some repository locations may be relative to
|
||||
* the base repository directory or uri. This returns the absolute path of the repository.
|
||||
* If the location is absolute already this method returns the same URI as getLocation().
|
||||
* Returns the local path that this repository uses, if it stores data locally. You should keep in
|
||||
* mind, that repository implementations may not store any data in this directory. E.g. if the
|
||||
* 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.
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.apache.archiva.repository;
|
|||
*/
|
||||
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
|
@ -35,14 +36,14 @@ public abstract class AbstractManagedRepository extends AbstractRepository imple
|
|||
private Set<ReleaseScheme> activeReleaseSchemes = new HashSet<>( );
|
||||
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
|
||||
|
|
|
@ -20,6 +20,10 @@ package org.apache.archiva.repository;
|
|||
*/
|
||||
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.time.Duration;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
@ -43,14 +47,14 @@ public abstract class AbstractRemoteRepository extends AbstractRepository implem
|
|||
private String proxyId;
|
||||
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
|
||||
|
@ -138,4 +142,13 @@ public abstract class AbstractRemoteRepository extends AbstractRepository implem
|
|||
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.CronType;
|
|||
import com.cronutils.model.definition.CronDefinition;
|
||||
import com.cronutils.model.definition.CronDefinitionBuilder;
|
||||
import com.cronutils.parser.CronParser;
|
||||
import org.apache.archiva.common.utils.PathUtil;
|
||||
import org.apache.archiva.indexer.ArchivaIndexingContext;
|
||||
import org.apache.archiva.repository.features.RepositoryFeature;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import java.net.URI;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
@ -59,17 +63,21 @@ public abstract class AbstractRepository implements EditableRepository
|
|||
|
||||
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.names.put( primaryLocale, name);
|
||||
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 );
|
||||
this.id = id;
|
||||
this.names.put( primaryLocale, name);
|
||||
this.type = type;
|
||||
this.repositoryBase=repositoryBase;
|
||||
}
|
||||
|
||||
protected void setPrimaryLocale(Locale locale) {
|
||||
|
@ -118,8 +126,19 @@ public abstract class AbstractRepository implements EditableRepository
|
|||
return location;
|
||||
}
|
||||
|
||||
public URI getAbsoluteLocation() {
|
||||
return baseUri.resolve( location );
|
||||
@Override
|
||||
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
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.apache.archiva.repository.features.ArtifactCleanupFeature;
|
|||
import org.apache.archiva.repository.features.IndexCreationFeature;
|
||||
import org.apache.archiva.repository.features.StagingRepositoryFeature;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
|
@ -46,15 +47,15 @@ public class BasicManagedRepository extends AbstractManagedRepository
|
|||
StagingRepositoryFeature.class.toString()
|
||||
}, 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();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.apache.archiva.repository;
|
|||
|
||||
import org.apache.archiva.repository.features.RemoteIndexFeature;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
|
@ -41,15 +42,15 @@ public class BasicRemoteRepository extends AbstractRemoteRepository
|
|||
RemoteIndexFeature.class.toString()
|
||||
}, 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();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
|
@ -192,14 +192,14 @@ public class RepositoryRegistryTest
|
|||
@Test
|
||||
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" );
|
||||
repositoryRegistry.putRepository(managedRepository);
|
||||
|
||||
assertNotNull(managedRepository.getContent());
|
||||
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 updatedRepo = null;
|
||||
try {
|
||||
|
@ -208,7 +208,7 @@ public class RepositoryRegistryTest
|
|||
} catch (RepositoryException e) {
|
||||
// OK
|
||||
}
|
||||
managedRepository = new BasicManagedRepository( "internal", "Test repo" );
|
||||
managedRepository = new BasicManagedRepository( "internal", "Test repo", archivaConfiguration.getRepositoryBaseDir() );
|
||||
managedRepository.setDescription( managedRepository.getPrimaryLocale(), "This is just a test" );
|
||||
updatedRepo = repositoryRegistry.putRepository( managedRepository );
|
||||
|
||||
|
@ -283,7 +283,7 @@ public class RepositoryRegistryTest
|
|||
@Test
|
||||
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 newRepo = repositoryRegistry.putRepository(remoteRepository);
|
||||
|
||||
|
@ -291,7 +291,7 @@ public class RepositoryRegistryTest
|
|||
assertNotNull(remoteRepository.getContent());
|
||||
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 updatedRepo = null;
|
||||
try
|
||||
|
@ -302,7 +302,7 @@ public class RepositoryRegistryTest
|
|||
// OK
|
||||
}
|
||||
|
||||
remoteRepository = new BasicRemoteRepository( "central", "Test repo" );
|
||||
remoteRepository = new BasicRemoteRepository( "central", "Test repo", archivaConfiguration.getRemoteRepositoryBaseDir() );
|
||||
remoteRepository.setDescription( remoteRepository.getPrimaryLocale(), "This is just a test" );
|
||||
updatedRepo = repositoryRegistry.putRepository( remoteRepository );
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@ import org.apache.archiva.repository.features.StagingRepositoryFeature;
|
|||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.net.URI;
|
||||
import java.nio.file.Paths;
|
||||
import java.time.Duration;
|
||||
import java.time.Period;
|
||||
import java.util.HashSet;
|
||||
|
@ -69,19 +70,19 @@ public class RepositoryProviderMock implements RepositoryProvider
|
|||
@Override
|
||||
public EditableManagedRepository createManagedInstance( String id, String name )
|
||||
{
|
||||
return new BasicManagedRepository( id, name );
|
||||
return new BasicManagedRepository( id, name, Paths.get("target/repositories") );
|
||||
}
|
||||
|
||||
@Override
|
||||
public EditableRemoteRepository createRemoteInstance( String id, String name )
|
||||
{
|
||||
return new BasicRemoteRepository( id, name );
|
||||
return new BasicRemoteRepository( id, name , Paths.get("target/remotes"));
|
||||
}
|
||||
|
||||
@Override
|
||||
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 );
|
||||
return managedRepository;
|
||||
}
|
||||
|
@ -128,7 +129,7 @@ public class RepositoryProviderMock implements RepositoryProvider
|
|||
public ManagedRepository createStagingInstance( ManagedRepositoryConfiguration configuration ) throws RepositoryException
|
||||
{
|
||||
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 );
|
||||
managedRepository.getFeature(StagingRepositoryFeature.class).get().setStageRepoNeeded(false);
|
||||
return managedRepository;
|
||||
|
@ -137,7 +138,7 @@ public class RepositoryProviderMock implements RepositoryProvider
|
|||
@Override
|
||||
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 );
|
||||
return remoteRepository;
|
||||
}
|
||||
|
|
|
@ -76,14 +76,14 @@ public class RepositoryContentConsumersTest
|
|||
|
||||
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() );
|
||||
return repo;
|
||||
}
|
||||
|
||||
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 ) );
|
||||
return repo;
|
||||
}
|
||||
|
|
|
@ -64,14 +64,14 @@ public class RepositoryScannerTest
|
|||
|
||||
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());
|
||||
return repo;
|
||||
}
|
||||
|
||||
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 ) );
|
||||
return repo;
|
||||
}
|
||||
|
|
|
@ -91,8 +91,9 @@ public class ArchivaIndexingTaskExecutorTest
|
|||
{
|
||||
super.setUp();
|
||||
|
||||
repositoryConfig = new BasicManagedRepository( "test-repo", "Test Repository");
|
||||
Path repoLocation = Paths.get( System.getProperty( "basedir" ), "target/test-classes/test-repo" ).toAbsolutePath();
|
||||
Path baseDir = Paths.get(System.getProperty("basedir"), "target/test-classes").toAbsolutePath();
|
||||
repositoryConfig = new BasicManagedRepository( "test-repo", "Test Repository", baseDir);
|
||||
Path repoLocation = baseDir.resolve("test-repo" );
|
||||
repositoryConfig.setLocation(repoLocation.toUri() );
|
||||
repositoryConfig.setLayout( "default" );
|
||||
repositoryConfig.setScanned( true );
|
||||
|
|
|
@ -77,8 +77,7 @@ public class DavResourceTest
|
|||
|
||||
private LockManager lockManager;
|
||||
|
||||
private MavenManagedRepository repository = new MavenManagedRepository( "repo001", "repo001");
|
||||
|
||||
private MavenManagedRepository repository;
|
||||
@Override
|
||||
@Before
|
||||
public void setUp()
|
||||
|
@ -88,6 +87,8 @@ public class DavResourceTest
|
|||
session = new ArchivaDavSession();
|
||||
baseDir = Paths.get( "target/DavResourceTest" );
|
||||
Files.createDirectories( baseDir );
|
||||
repository = new MavenManagedRepository( "repo001", "repo001", baseDir);
|
||||
|
||||
myResource = baseDir.resolve( "myresource.jar" );
|
||||
Files.createFile(myResource);
|
||||
resourceFactory = new RootContextDavResourceFactory();
|
||||
|
|
|
@ -70,14 +70,14 @@ public class MavenManagedRepository extends AbstractManagedRepository
|
|||
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
|
||||
|
|
|
@ -11,6 +11,7 @@ import org.apache.archiva.repository.features.IndexCreationFeature;
|
|||
import org.apache.archiva.repository.features.RemoteIndexFeature;
|
||||
import org.apache.archiva.repository.features.RepositoryFeature;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.Locale;
|
||||
|
||||
/*
|
||||
|
@ -53,14 +54,14 @@ public class MavenRemoteRepository extends AbstractRemoteRepository
|
|||
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
|
||||
|
|
|
@ -62,63 +62,58 @@ import java.util.Set;
|
|||
* Provider for the maven2 repository implementations
|
||||
*/
|
||||
@Service("mavenRepositoryProvider")
|
||||
public class MavenRepositoryProvider implements RepositoryProvider
|
||||
{
|
||||
public class MavenRepositoryProvider implements RepositoryProvider {
|
||||
|
||||
|
||||
@Inject
|
||||
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 {
|
||||
TYPES.add( RepositoryType.MAVEN);
|
||||
TYPES.add(RepositoryType.MAVEN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<RepositoryType> provides( )
|
||||
{
|
||||
public Set<RepositoryType> provides() {
|
||||
return TYPES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EditableManagedRepository createManagedInstance(String id, String name) {
|
||||
return new MavenManagedRepository(id, name);
|
||||
return new MavenManagedRepository(id, name, archivaConfiguration.getRepositoryBaseDir());
|
||||
}
|
||||
|
||||
@Override
|
||||
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;
|
||||
try {
|
||||
if (StringUtils.isEmpty( uriStr )) {
|
||||
if (StringUtils.isEmpty(uriStr)) {
|
||||
return new URI("");
|
||||
}
|
||||
if (uriStr.startsWith("/")) {
|
||||
// only absolute paths are prepended with file scheme
|
||||
uri = new URI("file://"+uriStr);
|
||||
} else
|
||||
{
|
||||
uri = new URI( uriStr );
|
||||
uri = new URI("file://" + uriStr);
|
||||
} else {
|
||||
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);
|
||||
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) {
|
||||
String newCfg = "file://"+uriStr;
|
||||
try
|
||||
{
|
||||
String newCfg = "file://" + uriStr;
|
||||
try {
|
||||
uri = new URI(newCfg);
|
||||
}
|
||||
catch ( URISyntaxException e1 )
|
||||
{
|
||||
} catch (URISyntaxException e1) {
|
||||
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);
|
||||
|
@ -126,56 +121,48 @@ public class MavenRepositoryProvider implements RepositoryProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
public ManagedRepository createManagedInstance( ManagedRepositoryConfiguration cfg ) throws RepositoryException
|
||||
{
|
||||
MavenManagedRepository repo = new MavenManagedRepository(cfg.getId() ,cfg.getName());
|
||||
updateManagedInstance( repo, cfg );
|
||||
public ManagedRepository createManagedInstance(ManagedRepositoryConfiguration cfg) throws RepositoryException {
|
||||
MavenManagedRepository repo = new MavenManagedRepository(cfg.getId(), cfg.getName(), archivaConfiguration.getRepositoryBaseDir());
|
||||
updateManagedInstance(repo, cfg);
|
||||
return repo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateManagedInstance( EditableManagedRepository repo , ManagedRepositoryConfiguration cfg ) throws RepositoryException
|
||||
{
|
||||
try
|
||||
{
|
||||
repo.setLocation( getURIFromString( cfg.getLocation() ) );
|
||||
public void updateManagedInstance(EditableManagedRepository repo, ManagedRepositoryConfiguration cfg) throws RepositoryException {
|
||||
try {
|
||||
repo.setLocation(getURIFromString(cfg.getLocation()));
|
||||
} catch (UnsupportedURIException e) {
|
||||
throw new RepositoryException("The location entry is not a valid uri: " + cfg.getLocation());
|
||||
}
|
||||
catch ( UnsupportedURIException e )
|
||||
{
|
||||
throw new RepositoryException( "The location entry is not a valid uri: "+cfg.getLocation() );
|
||||
}
|
||||
setBaseConfig( repo, cfg );
|
||||
Path repoDir = PathUtil.getPathFromUri(repo.getAbsoluteLocation());
|
||||
setBaseConfig(repo, cfg);
|
||||
Path repoDir = repo.getLocalPath();
|
||||
if (!Files.exists(repoDir)) {
|
||||
log.debug("Creating repo directory {}", repoDir);
|
||||
try
|
||||
{
|
||||
Files.createDirectories( repoDir );
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
log.error("Could not create directory {} for repository {}", repo.getAbsoluteLocation(), repo.getId(), e);
|
||||
throw new RepositoryException( "Could not create directory for repository "+repo.getAbsoluteLocation() );
|
||||
try {
|
||||
Files.createDirectories(repoDir);
|
||||
} catch (IOException e) {
|
||||
log.error("Could not create directory {} for repository {}", repo.getLocalPath(), repo.getId(), e);
|
||||
throw new RepositoryException("Could not create directory for repository " + repo.getLocalPath());
|
||||
}
|
||||
}
|
||||
repo.setSchedulingDefinition(cfg.getRefreshCronExpression());
|
||||
repo.setBlocksRedeployment( cfg.isBlockRedeployments() );
|
||||
repo.setScanned( cfg.isScanned() );
|
||||
repo.setBlocksRedeployment(cfg.isBlockRedeployments());
|
||||
repo.setScanned(cfg.isScanned());
|
||||
if (cfg.isReleases()) {
|
||||
repo.addActiveReleaseScheme( ReleaseScheme.RELEASE);
|
||||
repo.addActiveReleaseScheme(ReleaseScheme.RELEASE);
|
||||
}
|
||||
if (cfg.isSnapshots()) {
|
||||
repo.addActiveReleaseScheme(ReleaseScheme.SNAPSHOT);
|
||||
}
|
||||
|
||||
StagingRepositoryFeature stagingRepositoryFeature = repo.getFeature( StagingRepositoryFeature.class ).get();
|
||||
stagingRepositoryFeature.setStageRepoNeeded( cfg.isStageRepoNeeded() );
|
||||
StagingRepositoryFeature stagingRepositoryFeature = repo.getFeature(StagingRepositoryFeature.class).get();
|
||||
stagingRepositoryFeature.setStageRepoNeeded(cfg.isStageRepoNeeded());
|
||||
|
||||
IndexCreationFeature indexCreationFeature = repo.getFeature( IndexCreationFeature.class ).get( );
|
||||
indexCreationFeature.setSkipPackedIndexCreation( cfg.isSkipPackedIndexCreation() );
|
||||
indexCreationFeature.setIndexPath( getURIFromString( cfg.getIndexDir() ) );
|
||||
IndexCreationFeature indexCreationFeature = repo.getFeature(IndexCreationFeature.class).get();
|
||||
indexCreationFeature.setSkipPackedIndexCreation(cfg.isSkipPackedIndexCreation());
|
||||
indexCreationFeature.setIndexPath(getURIFromString(cfg.getIndexDir()));
|
||||
Path indexPath;
|
||||
if (indexCreationFeature.getIndexPath().getScheme()==null) {
|
||||
if (indexCreationFeature.getIndexPath().getScheme() == null) {
|
||||
indexPath = Paths.get(indexCreationFeature.getIndexPath().getPath());
|
||||
} else {
|
||||
indexPath = Paths.get(indexCreationFeature.getIndexPath());
|
||||
|
@ -184,44 +171,39 @@ public class MavenRepositoryProvider implements RepositoryProvider
|
|||
if (indexPath.isAbsolute()) {
|
||||
absoluteIndexPath = indexPath;
|
||||
} else {
|
||||
absoluteIndexPath = PathUtil.getPathFromUri( repo.getLocation()).resolve(indexCreationFeature.getIndexPath().getPath());
|
||||
absoluteIndexPath = PathUtil.getPathFromUri(repo.getLocation()).resolve(indexCreationFeature.getIndexPath().getPath());
|
||||
}
|
||||
try
|
||||
{
|
||||
Files.createDirectories( absoluteIndexPath );
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
try {
|
||||
Files.createDirectories(absoluteIndexPath);
|
||||
} catch (IOException e) {
|
||||
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.setRetentionCount( cfg.getRetentionCount() );
|
||||
artifactCleanupFeature.setRetentionPeriod( Period.ofDays( cfg.getRetentionPeriod() ) );
|
||||
artifactCleanupFeature.setDeleteReleasedSnapshots(cfg.isDeleteReleasedSnapshots());
|
||||
artifactCleanupFeature.setRetentionCount(cfg.getRetentionCount());
|
||||
artifactCleanupFeature.setRetentionPeriod(Period.ofDays(cfg.getRetentionPeriod()));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ManagedRepository createStagingInstance( ManagedRepositoryConfiguration baseConfiguration ) throws RepositoryException
|
||||
{
|
||||
public ManagedRepository createStagingInstance(ManagedRepositoryConfiguration baseConfiguration) throws RepositoryException {
|
||||
log.debug("Creating staging instance for {}", baseConfiguration.getId());
|
||||
return createManagedInstance( getStageRepoConfig( baseConfiguration ) );
|
||||
return createManagedInstance(getStageRepoConfig(baseConfiguration));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public RemoteRepository createRemoteInstance( RemoteRepositoryConfiguration cfg ) throws RepositoryException
|
||||
{
|
||||
MavenRemoteRepository repo = new MavenRemoteRepository( cfg.getId( ), cfg.getName( ) );
|
||||
updateRemoteInstance( repo, cfg );
|
||||
public RemoteRepository createRemoteInstance(RemoteRepositoryConfiguration cfg) throws RepositoryException {
|
||||
MavenRemoteRepository repo = new MavenRemoteRepository(cfg.getId(), cfg.getName(), archivaConfiguration.getRemoteRepositoryBaseDir());
|
||||
updateRemoteInstance(repo, cfg);
|
||||
return repo;
|
||||
}
|
||||
|
||||
private String convertUriToPath(URI uri) {
|
||||
if (uri.getScheme()==null) {
|
||||
if (uri.getScheme() == null) {
|
||||
return uri.getPath();
|
||||
} else if ("file".equals(uri.getScheme())) {
|
||||
return Paths.get(uri).toString();
|
||||
|
@ -231,96 +213,83 @@ public class MavenRepositoryProvider implements RepositoryProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
public void updateRemoteInstance( EditableRemoteRepository repo, RemoteRepositoryConfiguration cfg ) throws RepositoryException
|
||||
{
|
||||
setBaseConfig( repo, cfg );
|
||||
repo.setCheckPath( cfg.getCheckPath() );
|
||||
repo.setSchedulingDefinition( cfg.getRefreshCronExpression() );
|
||||
try
|
||||
{
|
||||
public void updateRemoteInstance(EditableRemoteRepository repo, RemoteRepositoryConfiguration cfg) throws RepositoryException {
|
||||
setBaseConfig(repo, cfg);
|
||||
repo.setCheckPath(cfg.getCheckPath());
|
||||
repo.setSchedulingDefinition(cfg.getRefreshCronExpression());
|
||||
try {
|
||||
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 )
|
||||
{
|
||||
log.error("Could not set remote url "+cfg.getUrl());
|
||||
throw new RepositoryException( "The url config is not a valid uri: "+cfg.getUrl() );
|
||||
}
|
||||
repo.setTimeout( Duration.ofSeconds( cfg.getTimeout() ) );
|
||||
RemoteIndexFeature remoteIndexFeature = repo.getFeature( RemoteIndexFeature.class ).get();
|
||||
remoteIndexFeature.setDownloadRemoteIndex( cfg.isDownloadRemoteIndex() );
|
||||
remoteIndexFeature.setDownloadRemoteIndexOnStartup( cfg.isDownloadRemoteIndexOnStartup() );
|
||||
remoteIndexFeature.setDownloadTimeout( Duration.ofSeconds( cfg.getRemoteDownloadTimeout()) );
|
||||
remoteIndexFeature.setProxyId( cfg.getRemoteDownloadNetworkProxyId() );
|
||||
if (cfg.isDownloadRemoteIndex())
|
||||
{
|
||||
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.setTimeout(Duration.ofSeconds(cfg.getTimeout()));
|
||||
RemoteIndexFeature remoteIndexFeature = repo.getFeature(RemoteIndexFeature.class).get();
|
||||
remoteIndexFeature.setDownloadRemoteIndex(cfg.isDownloadRemoteIndex());
|
||||
remoteIndexFeature.setDownloadRemoteIndexOnStartup(cfg.isDownloadRemoteIndexOnStartup());
|
||||
remoteIndexFeature.setDownloadTimeout(Duration.ofSeconds(cfg.getRemoteDownloadTimeout()));
|
||||
remoteIndexFeature.setProxyId(cfg.getRemoteDownloadNetworkProxyId());
|
||||
if (cfg.isDownloadRemoteIndex()) {
|
||||
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.setExtraParameters( cfg.getExtraParameters() );
|
||||
repo.setExtraHeaders(cfg.getExtraHeaders());
|
||||
repo.setExtraParameters(cfg.getExtraParameters());
|
||||
PasswordCredentials credentials = new PasswordCredentials("", new char[0]);
|
||||
if (cfg.getPassword()!=null && cfg.getUsername()!=null)
|
||||
{
|
||||
credentials.setPassword( cfg.getPassword( ).toCharArray( ) );
|
||||
credentials.setUsername( cfg.getUsername() );
|
||||
repo.setCredentials( credentials );
|
||||
if (cfg.getPassword() != null && cfg.getUsername() != null) {
|
||||
credentials.setPassword(cfg.getPassword().toCharArray());
|
||||
credentials.setUsername(cfg.getUsername());
|
||||
repo.setCredentials(credentials);
|
||||
} else {
|
||||
credentials.setPassword( new char[0] );
|
||||
credentials.setPassword(new char[0]);
|
||||
}
|
||||
if (cfg.getIndexDir()!=null) {
|
||||
IndexCreationFeature indexCreationFeature = repo.getFeature( IndexCreationFeature.class ).get();
|
||||
indexCreationFeature.setIndexPath( getURIFromString( cfg.getIndexDir() ) );
|
||||
if (cfg.getIndexDir() != null) {
|
||||
IndexCreationFeature indexCreationFeature = repo.getFeature(IndexCreationFeature.class).get();
|
||||
indexCreationFeature.setIndexPath(getURIFromString(cfg.getIndexDir()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public RemoteRepositoryConfiguration getRemoteConfiguration( RemoteRepository remoteRepository ) throws RepositoryException
|
||||
{
|
||||
public RemoteRepositoryConfiguration getRemoteConfiguration(RemoteRepository remoteRepository) throws RepositoryException {
|
||||
if (!(remoteRepository instanceof MavenRemoteRepository)) {
|
||||
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() );
|
||||
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());
|
||||
}
|
||||
RemoteRepositoryConfiguration cfg = new RemoteRepositoryConfiguration();
|
||||
cfg.setType( remoteRepository.getType().toString() );
|
||||
cfg.setId( remoteRepository.getId() );
|
||||
cfg.setName( remoteRepository.getName() );
|
||||
cfg.setDescription( remoteRepository.getDescription() );
|
||||
cfg.setType(remoteRepository.getType().toString());
|
||||
cfg.setId(remoteRepository.getId());
|
||||
cfg.setName(remoteRepository.getName());
|
||||
cfg.setDescription(remoteRepository.getDescription());
|
||||
cfg.setUrl(remoteRepository.getLocation().toString());
|
||||
cfg.setTimeout( (int)remoteRepository.getTimeout().toMillis()/1000 );
|
||||
cfg.setCheckPath( remoteRepository.getCheckPath() );
|
||||
RepositoryCredentials creds = remoteRepository.getLoginCredentials( );
|
||||
if (creds!=null)
|
||||
{
|
||||
cfg.setTimeout((int) remoteRepository.getTimeout().toMillis() / 1000);
|
||||
cfg.setCheckPath(remoteRepository.getCheckPath());
|
||||
RepositoryCredentials creds = remoteRepository.getLoginCredentials();
|
||||
if (creds != null) {
|
||||
if (creds instanceof PasswordCredentials) {
|
||||
PasswordCredentials pCreds = (PasswordCredentials) creds;
|
||||
cfg.setPassword( new String(pCreds.getPassword()) );
|
||||
cfg.setUsername( pCreds.getUsername() );
|
||||
cfg.setPassword(new String(pCreds.getPassword()));
|
||||
cfg.setUsername(pCreds.getUsername());
|
||||
}
|
||||
}
|
||||
cfg.setLayout( remoteRepository.getLayout() );
|
||||
cfg.setExtraParameters( remoteRepository.getExtraParameters() );
|
||||
cfg.setExtraHeaders( remoteRepository.getExtraHeaders() );
|
||||
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() );
|
||||
cfg.setLayout(remoteRepository.getLayout());
|
||||
cfg.setExtraParameters(remoteRepository.getExtraParameters());
|
||||
cfg.setExtraHeaders(remoteRepository.getExtraHeaders());
|
||||
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());
|
||||
|
||||
|
||||
return cfg;
|
||||
|
@ -328,125 +297,104 @@ public class MavenRepositoryProvider implements RepositoryProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
public ManagedRepositoryConfiguration getManagedConfiguration( ManagedRepository managedRepository ) throws RepositoryException
|
||||
{
|
||||
public ManagedRepositoryConfiguration getManagedConfiguration(ManagedRepository managedRepository) throws RepositoryException {
|
||||
if (!(managedRepository instanceof MavenManagedRepository)) {
|
||||
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() );
|
||||
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());
|
||||
}
|
||||
ManagedRepositoryConfiguration cfg = new ManagedRepositoryConfiguration();
|
||||
cfg.setType( managedRepository.getType().toString() );
|
||||
cfg.setId( managedRepository.getId() );
|
||||
cfg.setName( managedRepository.getName() );
|
||||
cfg.setDescription( managedRepository.getDescription() );
|
||||
cfg.setLocation( convertUriToPath( managedRepository.getLocation() ) );
|
||||
cfg.setLayout( managedRepository.getLayout() );
|
||||
cfg.setRefreshCronExpression( managedRepository.getSchedulingDefinition() );
|
||||
cfg.setScanned( managedRepository.isScanned() );
|
||||
cfg.setBlockRedeployments( managedRepository.blocksRedeployments() );
|
||||
StagingRepositoryFeature stagingRepositoryFeature = managedRepository.getFeature( StagingRepositoryFeature.class ).get();
|
||||
cfg.setType(managedRepository.getType().toString());
|
||||
cfg.setId(managedRepository.getId());
|
||||
cfg.setName(managedRepository.getName());
|
||||
cfg.setDescription(managedRepository.getDescription());
|
||||
cfg.setLocation(convertUriToPath(managedRepository.getLocation()));
|
||||
cfg.setLayout(managedRepository.getLayout());
|
||||
cfg.setRefreshCronExpression(managedRepository.getSchedulingDefinition());
|
||||
cfg.setScanned(managedRepository.isScanned());
|
||||
cfg.setBlockRedeployments(managedRepository.blocksRedeployments());
|
||||
StagingRepositoryFeature stagingRepositoryFeature = managedRepository.getFeature(StagingRepositoryFeature.class).get();
|
||||
cfg.setStageRepoNeeded(stagingRepositoryFeature.isStageRepoNeeded());
|
||||
IndexCreationFeature indexCreationFeature = managedRepository.getFeature( IndexCreationFeature.class ).get();
|
||||
cfg.setIndexDir(convertUriToPath( indexCreationFeature.getIndexPath() ));
|
||||
cfg.setSkipPackedIndexCreation( indexCreationFeature.isSkipPackedIndexCreation() );
|
||||
IndexCreationFeature indexCreationFeature = managedRepository.getFeature(IndexCreationFeature.class).get();
|
||||
cfg.setIndexDir(convertUriToPath(indexCreationFeature.getIndexPath()));
|
||||
cfg.setSkipPackedIndexCreation(indexCreationFeature.isSkipPackedIndexCreation());
|
||||
|
||||
ArtifactCleanupFeature artifactCleanupFeature = managedRepository.getFeature( ArtifactCleanupFeature.class ).get();
|
||||
cfg.setRetentionCount( artifactCleanupFeature.getRetentionCount());
|
||||
cfg.setRetentionPeriod( artifactCleanupFeature.getRetentionPeriod().getDays() );
|
||||
ArtifactCleanupFeature artifactCleanupFeature = managedRepository.getFeature(ArtifactCleanupFeature.class).get();
|
||||
cfg.setRetentionCount(artifactCleanupFeature.getRetentionCount());
|
||||
cfg.setRetentionPeriod(artifactCleanupFeature.getRetentionPeriod().getDays());
|
||||
cfg.setDeleteReleasedSnapshots(artifactCleanupFeature.isDeleteReleasedSnapshots());
|
||||
|
||||
if (managedRepository.getActiveReleaseSchemes().contains( ReleaseScheme.RELEASE )) {
|
||||
cfg.setReleases( true );
|
||||
if (managedRepository.getActiveReleaseSchemes().contains(ReleaseScheme.RELEASE)) {
|
||||
cfg.setReleases(true);
|
||||
} else {
|
||||
cfg.setReleases( false );
|
||||
cfg.setReleases(false);
|
||||
}
|
||||
if (managedRepository.getActiveReleaseSchemes().contains( ReleaseScheme.SNAPSHOT )) {
|
||||
cfg.setSnapshots( true );
|
||||
if (managedRepository.getActiveReleaseSchemes().contains(ReleaseScheme.SNAPSHOT)) {
|
||||
cfg.setSnapshots(true);
|
||||
} else {
|
||||
cfg.setSnapshots( false );
|
||||
cfg.setSnapshots(false);
|
||||
}
|
||||
return cfg;
|
||||
|
||||
}
|
||||
|
||||
private ManagedRepositoryConfiguration getStageRepoConfig( ManagedRepositoryConfiguration repository )
|
||||
{
|
||||
private ManagedRepositoryConfiguration getStageRepoConfig(ManagedRepositoryConfiguration repository) {
|
||||
ManagedRepositoryConfiguration stagingRepository = new ManagedRepositoryConfiguration();
|
||||
stagingRepository.setId( repository.getId() + StagingRepositoryFeature.STAGING_REPO_POSTFIX );
|
||||
stagingRepository.setLayout( repository.getLayout() );
|
||||
stagingRepository.setName( repository.getName() + StagingRepositoryFeature.STAGING_REPO_POSTFIX );
|
||||
stagingRepository.setBlockRedeployments( repository.isBlockRedeployments() );
|
||||
stagingRepository.setRetentionPeriod( repository.getRetentionPeriod() );
|
||||
stagingRepository.setDeleteReleasedSnapshots( repository.isDeleteReleasedSnapshots() );
|
||||
stagingRepository.setStageRepoNeeded( false );
|
||||
stagingRepository.setId(repository.getId() + StagingRepositoryFeature.STAGING_REPO_POSTFIX);
|
||||
stagingRepository.setLayout(repository.getLayout());
|
||||
stagingRepository.setName(repository.getName() + StagingRepositoryFeature.STAGING_REPO_POSTFIX);
|
||||
stagingRepository.setBlockRedeployments(repository.isBlockRedeployments());
|
||||
stagingRepository.setRetentionPeriod(repository.getRetentionPeriod());
|
||||
stagingRepository.setDeleteReleasedSnapshots(repository.isDeleteReleasedSnapshots());
|
||||
stagingRepository.setStageRepoNeeded(false);
|
||||
|
||||
String path = repository.getLocation();
|
||||
int lastIndex = path.replace( '\\', '/' ).lastIndexOf( '/' );
|
||||
stagingRepository.setLocation( path.substring( 0, lastIndex ) + "/" + stagingRepository.getId() );
|
||||
int lastIndex = path.replace('\\', '/').lastIndexOf('/');
|
||||
stagingRepository.setLocation(path.substring(0, lastIndex) + "/" + stagingRepository.getId());
|
||||
|
||||
if ( StringUtils.isNotBlank( repository.getIndexDir() ) )
|
||||
{
|
||||
if (StringUtils.isNotBlank(repository.getIndexDir())) {
|
||||
Path indexDir = null;
|
||||
try
|
||||
{
|
||||
indexDir = Paths.get( new URI(repository.getIndexDir().startsWith( "file://" ) ? repository.getIndexDir() : "file://"+repository.getIndexDir()) );
|
||||
if ( indexDir.isAbsolute() )
|
||||
{
|
||||
Path newDir = Paths.get(new URI(stagingRepository.getLocation().startsWith( "file://" ) ? stagingRepository.getLocation() : "file://"+stagingRepository.getLocation())).resolve(".index");
|
||||
try {
|
||||
indexDir = Paths.get(new URI(repository.getIndexDir().startsWith("file://") ? repository.getIndexDir() : "file://" + repository.getIndexDir()));
|
||||
if (indexDir.isAbsolute()) {
|
||||
Path newDir = Paths.get(new URI(stagingRepository.getLocation().startsWith("file://") ? stagingRepository.getLocation() : "file://" + stagingRepository.getLocation())).resolve(".index");
|
||||
log.debug("Changing index directory {} -> {}", indexDir, newDir);
|
||||
stagingRepository.setIndexDir( newDir.toString() );
|
||||
}
|
||||
else
|
||||
{
|
||||
stagingRepository.setIndexDir(newDir.toString());
|
||||
} else {
|
||||
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());
|
||||
stagingRepository.setIndexDir( "" );
|
||||
stagingRepository.setIndexDir("");
|
||||
}
|
||||
// in case of absolute dir do not use the same
|
||||
}
|
||||
stagingRepository.setRefreshCronExpression( repository.getRefreshCronExpression() );
|
||||
stagingRepository.setReleases( repository.isReleases() );
|
||||
stagingRepository.setRetentionCount( repository.getRetentionCount() );
|
||||
stagingRepository.setScanned( repository.isScanned() );
|
||||
stagingRepository.setSnapshots( repository.isSnapshots() );
|
||||
stagingRepository.setSkipPackedIndexCreation( repository.isSkipPackedIndexCreation() );
|
||||
stagingRepository.setRefreshCronExpression(repository.getRefreshCronExpression());
|
||||
stagingRepository.setReleases(repository.isReleases());
|
||||
stagingRepository.setRetentionCount(repository.getRetentionCount());
|
||||
stagingRepository.setScanned(repository.isScanned());
|
||||
stagingRepository.setSnapshots(repository.isSnapshots());
|
||||
stagingRepository.setSkipPackedIndexCreation(repository.isSkipPackedIndexCreation());
|
||||
// do not duplicate description
|
||||
//stagingRepository.getDescription("")
|
||||
return stagingRepository;
|
||||
}
|
||||
|
||||
private void setBaseConfig( EditableRepository repo, AbstractRepositoryConfiguration cfg) throws RepositoryException {
|
||||
String baseUriStr = archivaConfiguration.getConfiguration().getArchivaRuntimeConfiguration().getRepositoryBaseDirectory();
|
||||
if (baseUriStr==null) {
|
||||
baseUriStr = Paths.get(System.getProperty( "appserver.base" )).resolve("repositories").normalize().toString();
|
||||
}
|
||||
try
|
||||
{
|
||||
URI baseUri = new URI(baseUriStr);
|
||||
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() );
|
||||
private void setBaseConfig(EditableRepository repo, AbstractRepositoryConfiguration cfg) throws RepositoryException {
|
||||
|
||||
URI baseUri = archivaConfiguration.getRepositoryBaseDir().toUri();
|
||||
repo.setBaseUri(baseUri);
|
||||
|
||||
repo.setName(repo.getPrimaryLocale(), cfg.getName());
|
||||
repo.setDescription(repo.getPrimaryLocale(), cfg.getDescription());
|
||||
repo.setLayout(cfg.getLayout());
|
||||
}
|
||||
|
||||
public ArchivaConfiguration getArchivaConfiguration( )
|
||||
{
|
||||
public ArchivaConfiguration getArchivaConfiguration() {
|
||||
return archivaConfiguration;
|
||||
}
|
||||
|
||||
public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration )
|
||||
{
|
||||
public void setArchivaConfiguration(ArchivaConfiguration archivaConfiguration) {
|
||||
this.archivaConfiguration = archivaConfiguration;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package org.apache.archiva.configuration;
|
|||
|
||||
import org.apache.archiva.redback.components.registry.RegistryException;
|
||||
import org.apache.archiva.redback.components.registry.RegistryListener;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
@ -103,4 +104,23 @@ public class TestConfiguration
|
|||
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.configuration.ConfigurationListener;
|
|||
import org.apache.archiva.redback.components.registry.Registry;
|
||||
import org.apache.archiva.redback.components.registry.RegistryException;
|
||||
import org.apache.archiva.redback.components.registry.RegistryListener;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.easymock.IMocksControl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
@ -146,4 +147,24 @@ public class MockConfiguration
|
|||
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 javax.inject.Inject;
|
|||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
|
@ -53,14 +54,14 @@ public abstract class AbstractRepositoryLayerTestCase
|
|||
|
||||
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() );
|
||||
return repo;
|
||||
}
|
||||
|
||||
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 ) );
|
||||
return repo;
|
||||
}
|
||||
|
@ -69,7 +70,7 @@ public abstract class AbstractRepositoryLayerTestCase
|
|||
String layout )
|
||||
throws Exception
|
||||
{
|
||||
MavenManagedRepository repo = new MavenManagedRepository( id, name );
|
||||
MavenManagedRepository repo = new MavenManagedRepository( id, name, location.getParent() );
|
||||
repo.setLocation( location.toAbsolutePath().toUri() );
|
||||
repo.setLayout( layout );
|
||||
|
||||
|
@ -83,7 +84,7 @@ public abstract class AbstractRepositoryLayerTestCase
|
|||
protected RemoteRepositoryContent createRemoteRepositoryContent( String id, String name, String url, String layout )
|
||||
throws Exception
|
||||
{
|
||||
MavenRemoteRepository repo = new MavenRemoteRepository(id, name);
|
||||
MavenRemoteRepository repo = new MavenRemoteRepository(id, name, Paths.get("target/remotes"));
|
||||
repo.setLocation( new URI( url ) );
|
||||
repo.setLayout( layout );
|
||||
|
||||
|
|
|
@ -515,7 +515,7 @@ public class RepositoryRequestTest
|
|||
String layout )
|
||||
throws Exception
|
||||
{
|
||||
MavenManagedRepository repo = new MavenManagedRepository( id, name);
|
||||
MavenManagedRepository repo = new MavenManagedRepository( id, name, archivaConfiguration.getRepositoryBaseDir());
|
||||
repo.setLocation( location.toAbsolutePath().toUri() );
|
||||
repo.setLayout( layout );
|
||||
|
||||
|
|
|
@ -41,6 +41,7 @@ import org.junit.Test;
|
|||
import java.net.URI;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.time.Duration;
|
||||
import java.time.Period;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
@ -213,7 +214,7 @@ public class MavenRepositoryProviderTest
|
|||
|
||||
@Test
|
||||
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.setScanned( true );
|
||||
|
@ -258,7 +259,7 @@ public class MavenRepositoryProviderTest
|
|||
|
||||
@Test
|
||||
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.setScanned( true );
|
||||
|
|
|
@ -30,6 +30,7 @@ import org.springframework.test.context.ContextConfiguration;
|
|||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
|
@ -48,17 +49,17 @@ public class Maven2RepositoryStorageTest
|
|||
{
|
||||
String href = "/repository/internal/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";
|
||||
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/";
|
||||
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";
|
||||
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 class DuplicateArtifactsConsumerTest
|
|||
|
||||
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() );
|
||||
|
||||
metadataRepository = mock( MetadataRepository.class );
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.apache.archiva.configuration;
|
|||
|
||||
import org.apache.archiva.redback.components.registry.RegistryException;
|
||||
import org.apache.archiva.redback.components.registry.RegistryListener;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
@ -103,4 +104,29 @@ public class StubConfiguration
|
|||
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…
Reference in New Issue