use of org.apache.archiva.configuration.Configuration 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.Configuration 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);
}
}
}
}
use of org.apache.archiva.configuration.Configuration in project archiva by apache.
the class Maven2RepositoryMergerTest method testMerge.
@Test
public void testMerge() throws Exception {
String targetRepoPath = "target/test-repository-target";
Path mergedArtifact = Paths.get(targetRepoPath, "com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100308.230825-1.jar");
Path mavenMetadata = Paths.get(targetRepoPath, "com/example/test/test-artifact/maven-metadata.xml");
Path pom = Paths.get(targetRepoPath, "com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100308.230825-1.pom");
assertFalse(Files.exists(mergedArtifact));
assertFalse(Files.exists(mavenMetadata));
assertFalse(Files.exists(pom));
Configuration c = new Configuration();
ManagedRepositoryConfiguration testRepo = new ManagedRepositoryConfiguration();
testRepo.setId(TEST_REPO_ID);
testRepo.setLocation("target/test-repository");
RepositoryScanningConfiguration repoScanConfig = new RepositoryScanningConfiguration();
List<String> knownContentConsumers = new ArrayList<>();
knownContentConsumers.add("metadata-updater12");
repoScanConfig.setKnownContentConsumers(knownContentConsumers);
c.setRepositoryScanning(repoScanConfig);
ManagedRepositoryConfiguration targetRepo = new ManagedRepositoryConfiguration();
targetRepo.setId("target-rep");
targetRepo.setLocation(targetRepoPath);
c.addManagedRepository(testRepo);
c.addManagedRepository(targetRepo);
configuration.save(c);
when(metadataRepository.getArtifacts(TEST_REPO_ID)).thenReturn(getArtifacts());
repositoryMerger.merge(metadataRepository, TEST_REPO_ID, "target-rep");
verify(metadataRepository).getArtifacts(TEST_REPO_ID);
assertTrue(Files.exists(mergedArtifact));
assertTrue(Files.exists(mavenMetadata));
assertTrue(Files.exists(pom));
}
Aggregations