Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,85 +20,109 @@

import javax.inject.Inject;

import java.io.File;
import java.nio.file.Files;
import java.util.List;

import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.testing.PlexusTest;
import org.junit.jupiter.api.Test;

import static java.nio.file.Files.readAllLines;
import static org.assertj.core.api.Assertions.assertThat;
import static org.codehaus.plexus.testing.PlexusExtension.getTestFile;
import static org.junit.jupiter.api.Assertions.assertEquals;

@PlexusTest
class ArtifactHandlerTest {
private static final String[] EXPECTED_COLUMN_HEADERS = new String[] {
"", "type", "classifier", "extension", "packaging", "language", "added to classpath", "includesDependencies"
};
private static final List<String> VALID_PACKAGING_TYPES = List.of(
"aar",
"apk",
"bundle",
"ear",
"eclipse-plugin",
"eclipse-test-plugin",
"ejb",
"hpi",
"jar",
"java-source",
"javadoc",
"jpi",
"kar",
"lpkg",
"maven-archetype",
"maven-plugin",
"nar",
"par",
"pom",
"rar",
"sar",
"swc",
"swf",
"test-jar",
"war",
"zip");
private static final String ARTIFACT_HANDLERS_APT = "src/site/apt/artifact-handlers.apt";

@Inject
PlexusContainer container;

@Test
@SuppressWarnings("checkstyle:UnusedLocalVariable")
void testAptConsistency() throws Exception {
File apt = getTestFile("src/site/apt/artifact-handlers.apt");

List<String> lines = Files.readAllLines(apt.toPath());

for (String line : lines) {
for (String line : readAllLines(getTestFile(ARTIFACT_HANDLERS_APT).toPath())) {
if (line.startsWith("||")) {
String[] cols = line.split("\\|\\|");
String[] expected = new String[] {
"",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is required

"type",
"classifier",
"extension",
"packaging",
"language",
"added to classpath",
"includesDependencies",
""
Copy link
Contributor Author

@Pankraz76 Pankraz76 May 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not required. "foo", works as well.

};

int i = 0;
for (String col : cols) {
assertEquals(expected[i++], col.trim(), "Wrong column header");
for (String col : line.split("\\|\\|")) {
assertEquals(EXPECTED_COLUMN_HEADERS[i++], col.trim(), "Wrong column header");
}
} else if (line.startsWith("|")) {
String[] cols = line.split("\\|");

String type = trimApt(cols[1]);
String classifier = trimApt(cols[2]);
String extension = trimApt(cols[3], type);
String packaging = trimApt(cols[4], type);
String language = trimApt(cols[5]);
String addedToClasspath = trimApt(cols[6]);
String includesDependencies = trimApt(cols[7]);

ArtifactHandler handler =
container.lookup(ArtifactHandlerManager.class).getArtifactHandler(type);
assertEquals(handler.getExtension(), extension, type + " extension");
// Packaging/Directory is Maven1 remnant!!!
// assertEquals(handler.getPackaging(), packaging, type + " packaging");
assertEquals(handler.getClassifier(), classifier, type + " classifier");
assertEquals(handler.getLanguage(), language, type + " language");
assertEquals(
handler.isAddedToClasspath() ? "true" : null, addedToClasspath, type + " addedToClasspath");
assertEquals(
handler.isIncludesDependencies() ? "true" : null,
includesDependencies,
type + " includesDependencies");
assertHeader(
type,
trimApt(cols[3], type),
trimApt(cols[4], type),
trimApt(cols[2]),
trimApt(cols[5]),
trimApt(cols[6]),
trimApt(cols[7]));
}
}
}

private void assertHeader(
String type,
String extension,
String packaging,
String classifier,
String language,
String addedToClasspath,
String includesDependencies)
throws ComponentLookupException {
ArtifactHandler handler = container.lookup(ArtifactHandlerManager.class).getArtifactHandler(type);
assertEquals(handler.getExtension(), extension, type + " extension");
// Packaging/Directory is Maven1 remnant!!!
// assertEquals(handler.getPackaging(), packaging, type + " packaging");
assertThat(handler.getPackaging()).isNotEmpty();
assertThat(VALID_PACKAGING_TYPES).contains(packaging);
assertEquals(handler.getClassifier(), classifier, type + " classifier");
assertEquals(handler.getLanguage(), language, type + " language");
assertEquals(handler.isAddedToClasspath() ? "true" : null, addedToClasspath, type + " addedToClasspath");
assertEquals(
handler.isIncludesDependencies() ? "true" : null, includesDependencies, type + " includesDependencies");
}

private String trimApt(String content, String type) {
String value = trimApt(content);
return "= type".equals(value) ? type : value;
}

private String trimApt(String content) {
content = content.replace('<', ' ').replace('>', ' ').trim();

return (content.length() == 0) ? null : content;
String value = content.replace('<', ' ').replace('>', ' ').trim();
return value.isEmpty() ? null : value;
}
}