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 java.io.File;
22  import java.util.List;
23  
24  import org.codehaus.plexus.PlexusTestCase;
25  import org.codehaus.plexus.util.FileUtils;
26  
27  public class ArtifactHandlerTest extends PlexusTestCase {
28      public void testAptConsistency() throws Exception {
29          File apt = getTestFile("src/site/apt/artifact-handlers.apt");
30  
31          List<String> lines = FileUtils.loadFile(apt);
32  
33          for (String line : lines) {
34              if (line.startsWith("||")) {
35                  String[] cols = line.split("\\|\\|");
36                  String[] expected = new String[] {
37                      "",
38                      "type",
39                      "classifier",
40                      "extension",
41                      "packaging",
42                      "language",
43                      "added to classpath",
44                      "includesDependencies",
45                      ""
46                  };
47  
48                  int i = 0;
49                  for (String col : cols) {
50                      assertEquals("Wrong column header", expected[i++], col.trim());
51                  }
52              } else if (line.startsWith("|")) {
53                  String[] cols = line.split("\\|");
54  
55                  String type = trimApt(cols[1]);
56                  String classifier = trimApt(cols[2]);
57                  String extension = trimApt(cols[3], type);
58                  String packaging = trimApt(cols[4], type);
59                  String language = trimApt(cols[5]);
60                  String addedToClasspath = trimApt(cols[6]);
61                  String includesDependencies = trimApt(cols[7]);
62  
63                  ArtifactHandler handler = lookup(ArtifactHandler.class, type);
64                  assertEquals(type + " extension", handler.getExtension(), extension);
65                  assertEquals(type + " packaging", handler.getPackaging(), packaging);
66                  assertEquals(type + " classifier", handler.getClassifier(), classifier);
67                  assertEquals(type + " language", handler.getLanguage(), language);
68                  assertEquals(
69                          type + " addedToClasspath", handler.isAddedToClasspath() ? "true" : null, addedToClasspath);
70                  assertEquals(
71                          type + " includesDependencies",
72                          handler.isIncludesDependencies() ? "true" : null,
73                          includesDependencies);
74              }
75          }
76      }
77  
78      private String trimApt(String content, String type) {
79          String value = trimApt(content);
80          return "= type".equals(value) ? type : value;
81      }
82  
83      private String trimApt(String content) {
84          content = content.replace('<', ' ').replace('>', ' ').trim();
85  
86          return (content.length() == 0) ? null : content;
87      }
88  }