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