use of org.apache.archiva.rest.api.model.ArtifactContentEntry in project archiva by apache.
the class DefaultBrowseService method readFileEntries.
protected List<ArtifactContentEntry> readFileEntries(final Path file, final String filterPath, final String repoId) throws IOException {
String cleanedfilterPath = filterPath == null ? "" : (StringUtils.startsWith(filterPath, "/") ? StringUtils.substringAfter(filterPath, "/") : filterPath);
Map<String, ArtifactContentEntry> artifactContentEntryMap = new HashMap<>();
int filterDepth = StringUtils.countMatches(cleanedfilterPath, "/");
if (!StringUtils.endsWith(cleanedfilterPath, "/") && !StringUtils.isEmpty(cleanedfilterPath)) {
filterDepth++;
}
JarFile jarFile = new JarFile(file.toFile());
try {
Enumeration<JarEntry> jarEntryEnumeration = jarFile.entries();
while (jarEntryEnumeration.hasMoreElements()) {
JarEntry currentEntry = jarEntryEnumeration.nextElement();
String cleanedEntryName = //
StringUtils.endsWith(currentEntry.getName(), "/") ? StringUtils.substringBeforeLast(currentEntry.getName(), "/") : currentEntry.getName();
String entryRootPath = getRootPath(cleanedEntryName);
int depth = StringUtils.countMatches(cleanedEntryName, "/");
if (//
StringUtils.isEmpty(cleanedfilterPath) && //
!artifactContentEntryMap.containsKey(entryRootPath) && depth == filterDepth) {
artifactContentEntryMap.put(entryRootPath, new ArtifactContentEntry(entryRootPath, !currentEntry.isDirectory(), depth, repoId));
} else {
if (//
StringUtils.startsWith(cleanedEntryName, cleanedfilterPath) && (depth == filterDepth || (!currentEntry.isDirectory() && depth == filterDepth))) {
artifactContentEntryMap.put(cleanedEntryName, new ArtifactContentEntry(cleanedEntryName, !currentEntry.isDirectory(), depth, repoId));
}
}
}
if (StringUtils.isNotEmpty(cleanedfilterPath)) {
Map<String, ArtifactContentEntry> filteredArtifactContentEntryMap = new HashMap<>();
for (Map.Entry<String, ArtifactContentEntry> entry : artifactContentEntryMap.entrySet()) {
filteredArtifactContentEntryMap.put(entry.getKey(), entry.getValue());
}
List<ArtifactContentEntry> sorted = getSmallerDepthEntries(filteredArtifactContentEntryMap);
if (sorted == null) {
return Collections.emptyList();
}
Collections.sort(sorted, ArtifactContentEntryComparator.INSTANCE);
return sorted;
}
} finally {
if (jarFile != null) {
jarFile.close();
}
}
List<ArtifactContentEntry> sorted = new ArrayList<>(artifactContentEntryMap.values());
Collections.sort(sorted, ArtifactContentEntryComparator.INSTANCE);
return sorted;
}
use of org.apache.archiva.rest.api.model.ArtifactContentEntry in project archiva by apache.
the class BrowseServiceTest method readArtifactContentEntries.
@Test
public void readArtifactContentEntries() throws Exception {
BrowseService browseService = getBrowseService(authorizationHeader, true);
List<ArtifactContentEntry> artifactContentEntries = browseService.getArtifactContentEntries("commons-logging", "commons-logging", "1.1", null, null, null, TEST_REPO_ID);
log.info("artifactContentEntries: {}", artifactContentEntries);
//
assertThat(artifactContentEntries).isNotNull().isNotEmpty().hasSize(//
2).contains(//
new ArtifactContentEntry("org", false, 0, TEST_REPO_ID), new ArtifactContentEntry("META-INF", false, 0, TEST_REPO_ID));
}
use of org.apache.archiva.rest.api.model.ArtifactContentEntry in project archiva by apache.
the class ArtifactContentEntriesTests method readArtifactContentEntriesRootSlash.
@Test
public void readArtifactContentEntriesRootSlash() throws Exception {
Path file = Paths.get(getBasedir(), "src/test/repo-with-osgi/commons-logging/commons-logging/1.1/commons-logging-1.1.jar");
List<ArtifactContentEntry> artifactContentEntries = browseService.readFileEntries(file, "/", "foo");
log.info("artifactContentEntries: {}", artifactContentEntries);
assertThat(artifactContentEntries).isNotNull().isNotEmpty().hasSize(2).contains(new ArtifactContentEntry("org", false, 0, "foo"), new ArtifactContentEntry("META-INF", false, 0, "foo"));
}
use of org.apache.archiva.rest.api.model.ArtifactContentEntry in project archiva by apache.
the class BrowseServiceTest method readArtifactContentEntriesFilesAndDirectories.
@Test
public void readArtifactContentEntriesFilesAndDirectories() throws Exception {
BrowseService browseService = getBrowseService(authorizationHeader, true);
List<ArtifactContentEntry> artifactContentEntries = browseService.getArtifactContentEntries("commons-logging", "commons-logging", "1.1", null, null, "org/apache/commons/logging/", TEST_REPO_ID);
log.info("artifactContentEntries: {}", artifactContentEntries);
assertThat(artifactContentEntries).isNotNull().isNotEmpty().hasSize(10).contains(new ArtifactContentEntry("org/apache/commons/logging/impl", false, 4, TEST_REPO_ID), new ArtifactContentEntry("org/apache/commons/logging/LogSource.class", true, 4, TEST_REPO_ID));
}
use of org.apache.archiva.rest.api.model.ArtifactContentEntry in project archiva by apache.
the class BrowseServiceTest method readArtifactContentEntriesRootPath.
@Test
public void readArtifactContentEntriesRootPath() throws Exception {
BrowseService browseService = getBrowseService(authorizationHeader, true);
List<ArtifactContentEntry> artifactContentEntries = browseService.getArtifactContentEntries("commons-logging", "commons-logging", "1.1", null, null, "org/", TEST_REPO_ID);
log.info("artifactContentEntries: {}", artifactContentEntries);
//
assertThat(artifactContentEntries).isNotNull().isNotEmpty().hasSize(//
1).contains(new ArtifactContentEntry("org/apache", false, 1, TEST_REPO_ID));
}
Aggregations