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          List<String> lines = FileUtils.loadFile( apt );
37  
38          for ( String line : lines )
39          {
40              if ( line.startsWith( "||" ) )
41              {
42                  String[] cols = line.split( "\\|\\|" );
43                  String[] expected =
44                      new String[] { "", "type", "classifier", "extension", "packaging", "language", "added to classpath",
45                          "includesDependencies", "" };
46  
47                  int i = 0;
48                  for ( String col : cols )
49                  {
50                      assertEquals( "Wrong column header", expected[i++], col.trim() );
51                  }
52              }
53              else if ( line.startsWith( "|" ) )
54              {
55                  String[] cols = line.split( "\\|" );
56  
57                  String type = trimApt( cols[1] );
58                  String classifier = trimApt( cols[2] );
59                  String extension = trimApt( cols[3], type );
60                  String packaging = trimApt( cols[4], type );
61                  String language = trimApt( cols[5] );
62                  String addedToClasspath = trimApt( cols[6] );
63                  String includesDependencies = trimApt( cols[7] );
64  
65                  ArtifactHandler handler = lookup( ArtifactHandler.class, type );
66                  assertEquals( type + " extension", handler.getExtension(), extension );
67                  assertEquals( type + " packaging", handler.getPackaging(), packaging );
68                  assertEquals( type + " classifier", handler.getClassifier(), classifier );
69                  assertEquals( type + " language", handler.getLanguage(), language );
70                  assertEquals( type + " addedToClasspath", handler.isAddedToClasspath() ? "true" : null, addedToClasspath );
71                  assertEquals( type + " includesDependencies", handler.isIncludesDependencies() ? "true" : null, includesDependencies );
72              }
73          }
74      }
75  
76      private String trimApt( String content, String type )
77      {
78          String value = trimApt( content );
79          return "= type".equals( value ) ? type : value;
80      }
81  
82      private String trimApt( String content )
83      {
84          content = content.replace( '<', ' ' ).replace( '>', ' ' ).trim();
85  
86          return ( content.length() == 0 ) ? null : content;
87      }
88  }