use of org.apache.archiva.configuration.ManagedRepositoryConfiguration in project archiva by apache.
the class FileMetadataRepositoryTest method createManagedRepository.
private static ManagedRepositoryConfiguration createManagedRepository(String repoId, Path directory) {
ManagedRepositoryConfiguration managedRepository = new ManagedRepositoryConfiguration();
managedRepository.setId(repoId);
managedRepository.setLocation(directory.resolve(repoId).toAbsolutePath().toString());
return managedRepository;
}
use of org.apache.archiva.configuration.ManagedRepositoryConfiguration in project archiva by apache.
the class Maven2RepositoryMetadataResolverMRM1411RepoGroupTest method setUp.
@Before
@Override
public void setUp() throws Exception {
super.setUp();
c = new Configuration();
testRepo = new ManagedRepositoryConfiguration();
testRepo.setId(TEST_REPO_ID);
testRepo.setLocation(Paths.get("target/test-repository").toAbsolutePath().toString());
testRepo.setReleases(true);
testRepo.setSnapshots(false);
c.addManagedRepository(testRepo);
testRepoS = new ManagedRepositoryConfiguration();
testRepoS.setId(TEST_SNAP_REPO_ID);
testRepoS.setLocation(Paths.get("target/test-repositorys").toAbsolutePath().toString());
testRepoS.setReleases(false);
testRepoS.setSnapshots(true);
c.addManagedRepository(testRepoS);
RemoteRepositoryConfiguration testRemoteRepo = new RemoteRepositoryConfiguration();
testRemoteRepo.setId(TEST_REMOTE_REPO_ID);
testRemoteRepo.setLayout("default");
testRemoteRepo.setName("Central Repository");
testRemoteRepo.setUrl("http://central.repo.com/maven2");
testRemoteRepo.setTimeout(10);
c.addRemoteRepository(testRemoteRepo);
ProxyConnectorConfiguration proxyConnector = new ProxyConnectorConfiguration();
proxyConnector.setSourceRepoId(TEST_REPO_ID);
proxyConnector.setTargetRepoId(TEST_REMOTE_REPO_ID);
proxyConnector.setDisabled(false);
c.addProxyConnector(proxyConnector);
ProxyConnectorConfiguration proxyConnectors = new ProxyConnectorConfiguration();
proxyConnectors.setSourceRepoId(TEST_SNAP_REPO_ID);
proxyConnectors.setTargetRepoId(TEST_REMOTE_REPO_ID);
proxyConnectors.setDisabled(false);
c.addProxyConnector(proxyConnectors);
List<String> repos = new ArrayList<>();
repos.add(TEST_REPO_ID);
repos.add(TEST_SNAP_REPO_ID);
RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration();
repoGroup.setId(TEST_REPO_GROUP_ID);
repoGroup.setRepositories(repos);
c.addRepositoryGroup(repoGroup);
configuration.save(c);
repositoryRegistry.reload();
assertFalse(c.getManagedRepositories().get(0).isSnapshots());
assertTrue(c.getManagedRepositories().get(0).isReleases());
assertTrue(c.getManagedRepositories().get(1).isSnapshots());
assertFalse(c.getManagedRepositories().get(1).isReleases());
wagonFactory = mock(WagonFactory.class);
storage.setWagonFactory(wagonFactory);
Wagon wagon = new MockWagon();
when(wagonFactory.getWagon(new WagonFactoryRequest().protocol("wagon#http"))).thenReturn(wagon);
}
use of org.apache.archiva.configuration.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.save(configuration);
// artifactFactory = ((DefaultDependencyTreeBuilder)this.builder).getFactory();
}
use of org.apache.archiva.configuration.ManagedRepositoryConfiguration in project archiva by apache.
the class MavenRepositoryProvider method getManagedConfiguration.
@Override
public ManagedRepositoryConfiguration getManagedConfiguration(ManagedRepository managedRepository) throws RepositoryException {
if (!(managedRepository instanceof MavenManagedRepository || managedRepository instanceof BasicManagedRepository)) {
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.setStageRepoNeeded(stagingRepositoryFeature.isStageRepoNeeded());
IndexCreationFeature indexCreationFeature = managedRepository.getFeature(IndexCreationFeature.class).get();
cfg.setIndexDir(convertUriToPath(indexCreationFeature.getIndexPath()));
cfg.setPackedIndexDir(convertUriToPath(indexCreationFeature.getPackedIndexPath()));
cfg.setSkipPackedIndexCreation(indexCreationFeature.isSkipPackedIndexCreation());
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);
} else {
cfg.setReleases(false);
}
if (managedRepository.getActiveReleaseSchemes().contains(ReleaseScheme.SNAPSHOT)) {
cfg.setSnapshots(true);
} else {
cfg.setSnapshots(false);
}
return cfg;
}
use of org.apache.archiva.configuration.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
Path versionMetaDataFileInSourceRepo = pathTranslator.toFile(Paths.get(sourceRepoPath), artifactMetadata.getNamespace(), artifactMetadata.getProject(), artifactMetadata.getVersion(), METADATA_FILENAME);
if (Files.exists(versionMetaDataFileInSourceRepo)) {
// Pattern quote for windows path
String relativePathToVersionMetadataFile = versionMetaDataFileInSourceRepo.toAbsolutePath().toString().split(Pattern.quote(sourceRepoPath))[1];
Path versionMetaDataFileInTargetRepo = Paths.get(targetRepoPath, relativePathToVersionMetadataFile);
if (!Files.exists(versionMetaDataFileInTargetRepo)) {
copyFile(versionMetaDataFileInSourceRepo, versionMetaDataFileInTargetRepo);
} else {
updateVersionMetadata(versionMetaDataFileInTargetRepo, artifactMetadata, lastUpdatedTimestamp);
}
}
// updating project meta data file
Path projectDirectoryInSourceRepo = versionMetaDataFileInSourceRepo.getParent().getParent();
Path projectMetadataFileInSourceRepo = projectDirectoryInSourceRepo.resolve(METADATA_FILENAME);
if (Files.exists(projectMetadataFileInSourceRepo)) {
String relativePathToProjectMetadataFile = projectMetadataFileInSourceRepo.toAbsolutePath().toString().split(Pattern.quote(sourceRepoPath))[1];
Path projectMetadataFileInTargetRepo = Paths.get(targetRepoPath, relativePathToProjectMetadataFile);
if (!Files.exists(projectMetadataFileInTargetRepo)) {
copyFile(projectMetadataFileInSourceRepo, projectMetadataFileInTargetRepo);
} else {
updateProjectMetadata(projectMetadataFileInTargetRepo, artifactMetadata, lastUpdatedTimestamp, timestamp);
}
}
}
}
Aggregations