|
20 | 20 |
|
21 | 21 | import javax.inject.Inject; |
22 | 22 |
|
23 | | -import java.io.File; |
24 | 23 | import java.nio.file.Files; |
25 | 24 | import java.util.List; |
26 | 25 |
|
27 | 26 | import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; |
28 | 27 | import org.codehaus.plexus.PlexusContainer; |
| 28 | +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; |
29 | 29 | import org.codehaus.plexus.testing.PlexusTest; |
30 | 30 | import org.junit.jupiter.api.Test; |
31 | 31 |
|
| 32 | +import static org.assertj.core.api.Assertions.assertThat; |
32 | 33 | import static org.codehaus.plexus.testing.PlexusExtension.getTestFile; |
33 | 34 | import static org.junit.jupiter.api.Assertions.assertEquals; |
34 | 35 |
|
35 | 36 | @PlexusTest |
36 | 37 | class ArtifactHandlerTest { |
| 38 | + private static final String[] EXPECTED_COLUMN_HEADERS = new String[] { |
| 39 | + "", "type", "classifier", "extension", "packaging", "language", "added to classpath", "includesDependencies" |
| 40 | + }; |
| 41 | + private static final List<String> VALID_PACKAGING_TYPES = List.of( |
| 42 | + "aar", |
| 43 | + "apk", |
| 44 | + "bundle", |
| 45 | + "ear", |
| 46 | + "eclipse-plugin", |
| 47 | + "eclipse-test-plugin", |
| 48 | + "ejb", |
| 49 | + "hpi", |
| 50 | + "jar", |
| 51 | + "java-source", |
| 52 | + "javadoc", |
| 53 | + "jpi", |
| 54 | + "kar", |
| 55 | + "lpkg", |
| 56 | + "maven-archetype", |
| 57 | + "maven-plugin", |
| 58 | + "nar", |
| 59 | + "par", |
| 60 | + "pom", |
| 61 | + "rar", |
| 62 | + "sar", |
| 63 | + "swc", |
| 64 | + "swf", |
| 65 | + "test-jar", |
| 66 | + "war", |
| 67 | + "zip"); |
| 68 | + private static final String ARTIFACT_HANDLERS_APT = "src/site/apt/artifact-handlers.apt"; |
| 69 | + |
37 | 70 | @Inject |
38 | 71 | PlexusContainer container; |
39 | 72 |
|
40 | 73 | @Test |
41 | | - @SuppressWarnings("checkstyle:UnusedLocalVariable") |
42 | 74 | void testAptConsistency() throws Exception { |
43 | | - File apt = getTestFile("src/site/apt/artifact-handlers.apt"); |
44 | | - |
45 | | - List<String> lines = Files.readAllLines(apt.toPath()); |
46 | | - |
47 | | - for (String line : lines) { |
| 75 | + for (String line : Files.readAllLines(getTestFile(ARTIFACT_HANDLERS_APT).toPath())) { |
48 | 76 | if (line.startsWith("||")) { |
49 | | - String[] cols = line.split("\\|\\|"); |
50 | | - String[] expected = new String[] { |
51 | | - "", |
52 | | - "type", |
53 | | - "classifier", |
54 | | - "extension", |
55 | | - "packaging", |
56 | | - "language", |
57 | | - "added to classpath", |
58 | | - "includesDependencies", |
59 | | - "" |
60 | | - }; |
61 | | - |
62 | 77 | int i = 0; |
63 | | - for (String col : cols) { |
64 | | - assertEquals(expected[i++], col.trim(), "Wrong column header"); |
| 78 | + for (String col : line.split("\\|\\|")) { |
| 79 | + assertEquals(EXPECTED_COLUMN_HEADERS[i++], col.trim(), "Wrong column header"); |
65 | 80 | } |
66 | 81 | } else if (line.startsWith("|")) { |
67 | 82 | String[] cols = line.split("\\|"); |
68 | | - |
69 | 83 | String type = trimApt(cols[1]); |
70 | | - String classifier = trimApt(cols[2]); |
71 | | - String extension = trimApt(cols[3], type); |
72 | | - String packaging = trimApt(cols[4], type); |
73 | | - String language = trimApt(cols[5]); |
74 | | - String addedToClasspath = trimApt(cols[6]); |
75 | | - String includesDependencies = trimApt(cols[7]); |
76 | | - |
77 | | - ArtifactHandler handler = |
78 | | - container.lookup(ArtifactHandlerManager.class).getArtifactHandler(type); |
79 | | - assertEquals(handler.getExtension(), extension, type + " extension"); |
80 | | - // Packaging/Directory is Maven1 remnant!!! |
81 | | - // assertEquals(handler.getPackaging(), packaging, type + " packaging"); |
82 | | - assertEquals(handler.getClassifier(), classifier, type + " classifier"); |
83 | | - assertEquals(handler.getLanguage(), language, type + " language"); |
84 | | - assertEquals( |
85 | | - handler.isAddedToClasspath() ? "true" : null, addedToClasspath, type + " addedToClasspath"); |
86 | | - assertEquals( |
87 | | - handler.isIncludesDependencies() ? "true" : null, |
88 | | - includesDependencies, |
89 | | - type + " includesDependencies"); |
| 84 | + assertHeader( |
| 85 | + type, |
| 86 | + trimApt(cols[3], type), |
| 87 | + trimApt(cols[4], type), |
| 88 | + trimApt(cols[2]), |
| 89 | + trimApt(cols[5]), |
| 90 | + trimApt(cols[6]), |
| 91 | + trimApt(cols[7])); |
90 | 92 | } |
91 | 93 | } |
92 | 94 | } |
93 | 95 |
|
| 96 | + private void assertHeader( |
| 97 | + String type, |
| 98 | + String extension, |
| 99 | + String packaging, |
| 100 | + String classifier, |
| 101 | + String language, |
| 102 | + String addedToClasspath, |
| 103 | + String includesDependencies) |
| 104 | + throws ComponentLookupException { |
| 105 | + ArtifactHandler handler = container.lookup(ArtifactHandlerManager.class).getArtifactHandler(type); |
| 106 | + assertEquals(handler.getExtension(), extension, type + " extension"); |
| 107 | + // Packaging/Directory is Maven1 remnant!!! |
| 108 | + // assertEquals(handler.getPackaging(), packaging, type + " packaging"); |
| 109 | + assertThat(handler.getPackaging()).isNotEmpty(); |
| 110 | + assertThat(VALID_PACKAGING_TYPES).contains(packaging); |
| 111 | + assertEquals(handler.getClassifier(), classifier, type + " classifier"); |
| 112 | + assertEquals(handler.getLanguage(), language, type + " language"); |
| 113 | + assertEquals(handler.isAddedToClasspath() ? "true" : null, addedToClasspath, type + " addedToClasspath"); |
| 114 | + assertEquals( |
| 115 | + handler.isIncludesDependencies() ? "true" : null, includesDependencies, type + " includesDependencies"); |
| 116 | + } |
| 117 | + |
94 | 118 | private String trimApt(String content, String type) { |
95 | 119 | String value = trimApt(content); |
96 | 120 | return "= type".equals(value) ? type : value; |
97 | 121 | } |
98 | 122 |
|
99 | 123 | private String trimApt(String content) { |
100 | | - content = content.replace('<', ' ').replace('>', ' ').trim(); |
101 | | - |
102 | | - return (content.length() == 0) ? null : content; |
| 124 | + String value = content.replace('<', ' ').replace('>', ' ').trim(); |
| 125 | + return value.isEmpty() ? null : value; |
103 | 126 | } |
104 | 127 | } |
0 commit comments