View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
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.codehaus.plexus.PlexusContainer;
28  import org.codehaus.plexus.testing.PlexusTest;
29  import org.junit.jupiter.api.Test;
30  
31  import static org.codehaus.plexus.testing.PlexusExtension.getTestFile;
32  import static org.junit.jupiter.api.Assertions.assertEquals;
33  
34  @PlexusTest
35  class ArtifactHandlerTest {
36      @Inject
37      PlexusContainer container;
38  
39      @Test
40      void testAptConsistency() throws Exception {
41          File apt = getTestFile("src/site/apt/artifact-handlers.apt");
42  
43          List<String> lines = Files.readAllLines(apt.toPath());
44  
45          for (String line : lines) {
46              if (line.startsWith("||")) {
47                  String[] cols = line.split("\\|\\|");
48                  String[] expected = new String[] {
49                      "",
50                      "type",
51                      "classifier",
52                      "extension",
53                      "packaging",
54                      "language",
55                      "added to classpath",
56                      "includesDependencies",
57                      ""
58                  };
59  
60                  int i = 0;
61                  for (String col : cols) {
62                      assertEquals(expected[i++], col.trim(), "Wrong column header");
63                  }
64              } else if (line.startsWith("|")) {
65                  String[] cols = line.split("\\|");
66  
67                  String type = trimApt(cols[1]);
68                  String classifier = trimApt(cols[2]);
69                  String extension = trimApt(cols[3], type);
70                  String packaging = trimApt(cols[4], type);
71                  String language = trimApt(cols[5]);
72                  String addedToClasspath = trimApt(cols[6]);
73                  String includesDependencies = trimApt(cols[7]);
74  
75                  ArtifactHandler handler = container.lookup(ArtifactHandler.class, type);
76                  assertEquals(handler.getExtension(), extension, type + " extension");
77                  assertEquals(handler.getPackaging(), packaging, type + " packaging");
78                  assertEquals(handler.getClassifier(), classifier, type + " classifier");
79                  assertEquals(handler.getLanguage(), language, type + " language");
80                  assertEquals(
81                          handler.isAddedToClasspath() ? "true" : null, addedToClasspath, type + " addedToClasspath");
82                  assertEquals(
83                          handler.isIncludesDependencies() ? "true" : null,
84                          includesDependencies,
85                          type + " includesDependencies");
86              }
87          }
88      }
89  
90      private String trimApt(String content, String type) {
91          String value = trimApt(content);
92          return "= type".equals(value) ? type : value;
93      }
94  
95      private String trimApt(String content) {
96          content = content.replace('<', ' ').replace('>', ' ').trim();
97  
98          return (content.length() == 0) ? null : content;
99      }
100 }