1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.artifact.handler;
20
21 import javax.inject.Inject;
22
23 import java.io.File;
24 import java.nio.file.Files;
25 import java.util.List;
26
27 import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
28 import org.codehaus.plexus.PlexusContainer;
29 import org.codehaus.plexus.testing.PlexusTest;
30 import org.junit.jupiter.api.Test;
31
32 import static org.codehaus.plexus.testing.PlexusExtension.getTestFile;
33 import static org.junit.jupiter.api.Assertions.assertEquals;
34
35 @PlexusTest
36 class ArtifactHandlerTest {
37 @Inject
38 PlexusContainer container;
39
40 @Test
41 void testAptConsistency() throws Exception {
42 File apt = getTestFile("src/site/apt/artifact-handlers.apt");
43
44 List<String> lines = Files.readAllLines(apt.toPath());
45
46 for (String line : lines) {
47 if (line.startsWith("||")) {
48 String[] cols = line.split("\\|\\|");
49 String[] expected = new String[] {
50 "",
51 "type",
52 "classifier",
53 "extension",
54 "packaging",
55 "language",
56 "added to classpath",
57 "includesDependencies",
58 ""
59 };
60
61 int i = 0;
62 for (String col : cols) {
63 assertEquals(expected[i++], col.trim(), "Wrong column header");
64 }
65 } else if (line.startsWith("|")) {
66 String[] cols = line.split("\\|");
67
68 String type = trimApt(cols[1]);
69 String classifier = trimApt(cols[2]);
70 String extension = trimApt(cols[3], type);
71 String packaging = trimApt(cols[4], type);
72 String language = trimApt(cols[5]);
73 String addedToClasspath = trimApt(cols[6]);
74 String includesDependencies = trimApt(cols[7]);
75
76 ArtifactHandler handler =
77 container.lookup(ArtifactHandlerManager.class).getArtifactHandler(type);
78 assertEquals(handler.getExtension(), extension, type + " extension");
79
80
81 assertEquals(handler.getClassifier(), classifier, type + " classifier");
82 assertEquals(handler.getLanguage(), language, type + " language");
83 assertEquals(
84 handler.isAddedToClasspath() ? "true" : null, addedToClasspath, type + " addedToClasspath");
85 assertEquals(
86 handler.isIncludesDependencies() ? "true" : null,
87 includesDependencies,
88 type + " includesDependencies");
89 }
90 }
91 }
92
93 private String trimApt(String content, String type) {
94 String value = trimApt(content);
95 return "= type".equals(value) ? type : value;
96 }
97
98 private String trimApt(String content) {
99 content = content.replace('<', ' ').replace('>', ' ').trim();
100
101 return (content.length() == 0) ? null : content;
102 }
103 }