use of org.apache.archiva.repository.content.Artifact in project archiva by apache.
the class Maven2RepositoryStorage method isProjectVersion.
private boolean isProjectVersion(StorageAsset dir) {
final String artifactId = dir.getParent().getName();
final String projectVersion = dir.getName();
// check if there is a POM artifact file to ensure it is a version directory
Predicate<StorageAsset> filter;
if (VersionUtil.isSnapshot(projectVersion)) {
filter = new PomFilenameFilter(artifactId, projectVersion);
} else {
final String pomFile = artifactId + "-" + projectVersion + ".pom";
filter = new PomFileFilter(pomFile);
}
if (dir.list().stream().filter(f -> !f.isContainer()).anyMatch(filter)) {
return true;
}
// if a metadata file is present, check if this is the "version" directory, marking it as a project version
ArchivaRepositoryMetadata metadata = readMetadata(dir);
if (metadata != null && projectVersion.equals(metadata.getVersion())) {
return true;
}
return false;
}
use of org.apache.archiva.repository.content.Artifact in project archiva by apache.
the class ManagedDefaultRepositoryContentTest method testArtifactListWithArtifactSelectorWithClassifier.
@Test
public void testArtifactListWithArtifactSelectorWithClassifier() {
ItemSelector selector = ArchivaItemSelector.builder().withNamespace("org.apache.maven").withProjectId("test").withVersion("1.0-SNAPSHOT").withArtifactId("test").withClassifier("javadoc").withArtifactVersion("1.0-20050611.112233-1").build();
List<? extends Artifact> results = repoContent.getArtifacts(selector);
assertNotNull(results);
assertEquals(1, results.size());
Artifact artifact = results.stream().filter(a -> a.getFileName().equalsIgnoreCase("test-1.0-20050611.112233-1-javadoc.jar")).findFirst().get();
assertNotNull(artifact);
assertEquals("javadoc", artifact.getClassifier());
assertEquals("javadoc", artifact.getType());
}
use of org.apache.archiva.repository.content.Artifact in project archiva by apache.
the class ManagedDefaultRepositoryContentTest method checkArtifactListWithVersionSelector1.
private void checkArtifactListWithVersionSelector1(List<? extends Artifact> results) {
assertNotNull(results);
assertEquals(2, results.size());
Artifact mainArtifact = results.stream().filter(a -> a.getFileName().equals("jdbc-2.0.jar")).findFirst().get();
assertNotNull(mainArtifact);
assertEquals(BaseArtifactTypes.MAIN, mainArtifact.getDataType());
Artifact metaArtifact = results.stream().filter(a -> a.getFileName().equals("maven-metadata-repository.xml")).findFirst().get();
assertNotNull(metaArtifact);
assertEquals(MavenTypes.REPOSITORY_METADATA, metaArtifact.getDataType());
}
use of org.apache.archiva.repository.content.Artifact in project archiva by apache.
the class ManagedDefaultRepositoryContentTest method testGetRelatedArtifactsFromArtifact.
@Test
public void testGetRelatedArtifactsFromArtifact() {
ItemSelector selector = ArchivaItemSelector.builder().withNamespace("org.apache.maven.shared").withProjectId("maven-downloader").withVersion("1.1").withExtension("jar").withArtifactId("maven-downloader").build();
Artifact artifact = repoContent.getArtifact(selector);
assertNotNull(artifact);
List<? extends Artifact> artifacts = repoContent.getArtifacts(artifact);
assertNotNull(artifacts);
assertEquals(2, artifacts.size());
}
use of org.apache.archiva.repository.content.Artifact in project archiva by apache.
the class ManagedDefaultRepositoryContentTest method testAddArtifact.
@Test
public void testAddArtifact() throws IOException, URISyntaxException, LayoutException {
ManagedRepository repo = createManagedRepoWithContent("delete-repository");
ManagedRepositoryContent myRepoContent = repo.getContent();
BaseRepositoryContentLayout layout = myRepoContent.getLayout(BaseRepositoryContentLayout.class);
Path repoRoot = repo.getRoot().getFilePath();
Path tmpFile = Files.createTempFile("archiva-mvn-repotest", "jar");
try (OutputStream outputStream = Files.newOutputStream(tmpFile)) {
for (int i = 0; i < 255; i++) {
outputStream.write("test.test.test\n".getBytes(Charset.forName("UTF-8")));
}
}
Path file = repoRoot.resolve("org/apache/maven/samplejar/2.0/samplejar-2.0.jar");
FileTime lmt = Files.getLastModifiedTime(file);
ArchivaItemSelector selector = ArchivaItemSelector.builder().withNamespace("org.apache.maven").withProjectId("samplejar").withVersion("2.0").withArtifactId("samplejar").withArtifactVersion("2.0").withExtension("jar").build();
Artifact artifact = layout.getArtifact(selector);
layout.addArtifact(tmpFile, artifact);
FileTime lmtAfter = Files.getLastModifiedTime(file);
assertNotEquals(lmtAfter, lmt);
Reader ln = Files.newBufferedReader(file, Charset.forName("UTF-8"));
char[] content = new char[50];
ln.read(content);
assertTrue(new String(content).startsWith("test.test.test"));
tmpFile = Files.createTempFile("archiva-mvn-repotest", "jar");
try (OutputStream outputStream = Files.newOutputStream(tmpFile)) {
for (int i = 0; i < 255; i++) {
outputStream.write("test.test.test\n".getBytes(Charset.forName("UTF-8")));
}
}
file = repoRoot.resolve("org/apache/maven/samplejar/2.0/samplejar-2.0.test");
assertFalse(Files.exists(file));
assertTrue(Files.exists(tmpFile));
selector = ArchivaItemSelector.builder().withNamespace("org.apache.maven").withProjectId("samplejar").withVersion("2.0").withArtifactId("samplejar").withArtifactVersion("2.0").withExtension("test").build();
artifact = layout.getArtifact(selector);
layout.addArtifact(tmpFile, artifact);
ln = Files.newBufferedReader(file, Charset.forName("UTF-8"));
ln.read(content);
assertTrue(new String(content).startsWith("test.test.test"));
}
Aggregations