use of org.apache.archiva.configuration.model.ManagedRepositoryConfiguration in project archiva by apache.
the class MavenProxyPropertyLoaderTest method testLoadValidMavenProxyConfiguration.
@Test
public void testLoadValidMavenProxyConfiguration() throws IOException, InvalidConfigurationException {
Path confFile = ArchivaConfigurationTest.getTestFile("src/test/conf/maven-proxy-complete.conf");
Configuration configuration = new Configuration();
NetworkProxyConfiguration proxy = new NetworkProxyConfiguration();
proxy.setHost("original-host");
// overwritten
configuration.addNetworkProxy(proxy);
loader.load(Files.newInputStream(confFile), configuration);
Map<String, ManagedRepositoryConfiguration> repositoryIdMap = configuration.getManagedRepositoriesAsMap();
assertEquals("Count repositories", 1, repositoryIdMap.size());
assertRepositoryExists("maven-proxy", "target", repositoryIdMap.get("maven-proxy"));
Map<String, RemoteRepositoryConfiguration> remoteRepositoryMap = configuration.getRemoteRepositoriesAsMap();
assertEquals("Count repositories", 4, remoteRepositoryMap.size());
assertRepositoryExists("local-repo", "file://target", remoteRepositoryMap.get("local-repo"));
assertRepositoryExists("www-ibiblio-org", "http://www.ibiblio.org/maven2", remoteRepositoryMap.get("www-ibiblio-org"));
assertRepositoryExists("dist-codehaus-org", "http://dist.codehaus.org", remoteRepositoryMap.get("dist-codehaus-org"));
assertRepositoryExists("private-example-com", "http://private.example.com/internal", remoteRepositoryMap.get("private-example-com"));
}
use of org.apache.archiva.configuration.model.ManagedRepositoryConfiguration in project archiva by apache.
the class RepositoryConfigurationComparatorTest method createRepository.
private ManagedRepositoryConfiguration createRepository(String id) {
ManagedRepositoryConfiguration repo = new ManagedRepositoryConfiguration();
repo.setId(id);
return repo;
}
use of org.apache.archiva.configuration.model.ManagedRepositoryConfiguration in project archiva by apache.
the class DependencyTreeBuilderTestMaven3 method setUp.
@Before
@Override
public void setUp() throws Exception {
super.setUp();
Configuration configuration = new Configuration();
ManagedRepositoryConfiguration repoConfig = new ManagedRepositoryConfiguration();
repoConfig.setId(TEST_REPO_ID);
repoConfig.setLocation(Paths.get("target/test-repository").toAbsolutePath().toString());
configuration.addManagedRepository(repoConfig);
config.getConfiguration().getProxyConnectors().clear();
config.save(configuration);
repositoryRegistry.reload();
// artifactFactory = ((DefaultDependencyTreeBuilder)this.builder).getFactory();
}
use of org.apache.archiva.configuration.model.ManagedRepositoryConfiguration in project archiva by apache.
the class MavenRepositoryProviderTest method createManagedInstance.
@Test
public void createManagedInstance() throws Exception {
ManagedRepositoryConfiguration repo = new ManagedRepositoryConfiguration();
repo.setId("testm001");
repo.setName("Managed Test Repo 001");
repo.setDescription("This is a managed test");
repo.setRetentionPeriod(37);
repoLocation = Files.createTempDirectory("test-repo-001");
repo.setLocation(repoLocation.toAbsolutePath().toString());
repo.setSnapshots(true);
repo.setReleases(true);
repo.setRefreshCronExpression("4 0 0 ? * TUE");
repo.setScanned(true);
repo.setBlockRedeployments(true);
repo.setDeleteReleasedSnapshots(true);
repo.setRetentionCount(33);
repo.setSkipPackedIndexCreation(true);
repo.setStageRepoNeeded(true);
repo.setIndexDir("testmanaged/.index");
repo.setLayout("maven2");
repo.setType(RepositoryType.MAVEN.toString());
ManagedRepository mr = provider.createManagedInstance(repo);
assertNotNull(mr.getLocation());
String repoUri = repoLocation.toUri().toString();
assertTrue(Files.exists(repoLocation));
repoUri = repoUri.substring(0, repoUri.length() - 1);
assertEquals(repoUri, mr.getLocation().toString());
assertEquals("This is a managed test", mr.getDescription());
assertEquals("Managed Test Repo 001", mr.getName());
assertEquals(2, mr.getActiveReleaseSchemes().size());
assertTrue(mr.getActiveReleaseSchemes().contains(ReleaseScheme.RELEASE));
assertTrue(mr.getActiveReleaseSchemes().contains(ReleaseScheme.SNAPSHOT));
assertEquals("testm001", mr.getId());
assertTrue(mr.blocksRedeployments());
assertEquals("4 0 0 ? * TUE", mr.getSchedulingDefinition());
assertTrue(mr.isScanned());
ArtifactCleanupFeature artifactCleanupFeature = mr.getFeature(ArtifactCleanupFeature.class);
assertEquals(Period.ofDays(37), artifactCleanupFeature.getRetentionPeriod());
assertTrue(artifactCleanupFeature.isDeleteReleasedSnapshots());
assertEquals(33, artifactCleanupFeature.getRetentionCount());
IndexCreationFeature indexCreationFeature = mr.getFeature(IndexCreationFeature.class);
assertNotNull(indexCreationFeature.getIndexPath());
assertEquals("testmanaged/.index", indexCreationFeature.getIndexPath().toString());
assertFalse(indexCreationFeature.getIndexPath().isAbsolute());
assertTrue(indexCreationFeature.isSkipPackedIndexCreation());
StagingRepositoryFeature stagingRepositoryFeature = mr.getFeature(StagingRepositoryFeature.class);
assertTrue(stagingRepositoryFeature.isStageRepoNeeded());
assertNull(stagingRepositoryFeature.getStagingRepository());
}
use of org.apache.archiva.configuration.model.ManagedRepositoryConfiguration in project archiva by apache.
the class Maven2RepositoryMerger method createFolderStructure.
private void createFolderStructure(String sourceRepoId, String targetRepoId, ArtifactMetadata artifactMetadata) throws IOException, RepositoryException {
Configuration config = configuration.getConfiguration();
ManagedRepositoryConfiguration targetRepoConfig = config.findManagedRepositoryById(targetRepoId);
ManagedRepositoryConfiguration sourceRepoConfig = config.findManagedRepositoryById(sourceRepoId);
Date lastUpdatedTimestamp = Calendar.getInstance().getTime();
TimeZone timezone = TimeZone.getTimeZone("UTC");
DateFormat fmt = new SimpleDateFormat("yyyyMMdd.HHmmss");
fmt.setTimeZone(timezone);
String timestamp = fmt.format(lastUpdatedTimestamp);
String targetRepoPath = targetRepoConfig.getLocation();
String sourceRepoPath = sourceRepoConfig.getLocation();
String artifactPath = pathTranslator.toPath(artifactMetadata.getNamespace(), artifactMetadata.getProject(), artifactMetadata.getProjectVersion(), artifactMetadata.getId());
Path sourceArtifactFile = Paths.get(sourceRepoPath, artifactPath);
Path targetArtifactFile = Paths.get(targetRepoPath, artifactPath);
log.debug("artifactPath {}", artifactPath);
int lastIndex = artifactPath.lastIndexOf(RepositoryPathTranslator.PATH_SEPARATOR);
Path targetFile = Paths.get(targetRepoPath, artifactPath.substring(0, lastIndex));
if (!Files.exists(targetFile)) {
// create the folder structure when it does not exist
Files.createDirectories(targetFile);
}
// artifact copying
copyFile(sourceArtifactFile, targetArtifactFile);
// pom file copying
// TODO need to use path translator to get the pom file path
// String fileName = artifactMetadata.getProject() + "-" + artifactMetadata.getVersion() + ".pom";
//
// File sourcePomFile =
// pathTranslator.toFile( new File( sourceRepoPath ), artifactMetadata.getId(), artifactMetadata.getProject(),
// artifactMetadata.getVersion(), fileName );
//
// String relativePathToPomFile = sourcePomFile.getAbsolutePath().split( sourceRepoPath )[1];
// File targetPomFile = new File( targetRepoPath, relativePathToPomFile );
// pom file copying (file path is taken with out using path translator)
String index = artifactPath.substring(lastIndex + 1);
int last = index.lastIndexOf('.');
Path sourcePomFile = Paths.get(sourceRepoPath, artifactPath.substring(0, lastIndex) + "/" + artifactPath.substring(lastIndex + 1).substring(0, last) + ".pom");
Path targetPomFile = Paths.get(targetRepoPath, artifactPath.substring(0, lastIndex) + "/" + artifactPath.substring(lastIndex + 1).substring(0, last) + ".pom");
if (!Files.exists(targetPomFile) && Files.exists(sourcePomFile)) {
copyFile(sourcePomFile, targetPomFile);
}
// explicitly update only if metadata-updater consumer is not enabled!
if (!config.getRepositoryScanning().getKnownContentConsumers().contains("metadata-updater")) {
// updating version metadata files
FilesystemStorage fsStorage = new FilesystemStorage(Paths.get(sourceRepoPath), new DefaultFileLockManager());
StorageAsset versionMetaDataFileInSourceRepo = pathTranslator.toFile(new FilesystemAsset(fsStorage, "", Paths.get(sourceRepoPath)), artifactMetadata.getNamespace(), artifactMetadata.getProject(), artifactMetadata.getVersion(), METADATA_FILENAME);
if (versionMetaDataFileInSourceRepo.exists()) {
// Pattern quote for windows path
String relativePathToVersionMetadataFile = getRelativeAssetPath(versionMetaDataFileInSourceRepo);
Path versionMetaDataFileInTargetRepo = Paths.get(targetRepoPath, relativePathToVersionMetadataFile);
if (!Files.exists(versionMetaDataFileInTargetRepo)) {
copyFile(versionMetaDataFileInSourceRepo.getFilePath(), versionMetaDataFileInTargetRepo);
} else {
updateVersionMetadata(versionMetaDataFileInTargetRepo, artifactMetadata, lastUpdatedTimestamp);
}
}
// updating project meta data file
StorageAsset projectDirectoryInSourceRepo = versionMetaDataFileInSourceRepo.getParent().getParent();
StorageAsset projectMetadataFileInSourceRepo = projectDirectoryInSourceRepo.resolve(METADATA_FILENAME);
if (projectMetadataFileInSourceRepo.exists()) {
String relativePathToProjectMetadataFile = getRelativeAssetPath(projectMetadataFileInSourceRepo);
Path projectMetadataFileInTargetRepo = Paths.get(targetRepoPath, relativePathToProjectMetadataFile);
if (!Files.exists(projectMetadataFileInTargetRepo)) {
copyFile(projectMetadataFileInSourceRepo.getFilePath(), projectMetadataFileInTargetRepo);
} else {
updateProjectMetadata(projectMetadataFileInTargetRepo, artifactMetadata, lastUpdatedTimestamp, timestamp);
}
}
}
}
Aggregations