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.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                  // Packaging/Directory is Maven1 remnant!!!
80                  // assertEquals(handler.getPackaging(), packaging, type + " packaging");
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 }