View Javadoc

1   package org.apache.maven.index.creator;
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  
24  import org.apache.maven.index.ArtifactContext;
25  import org.apache.maven.index.ArtifactInfo;
26  import org.apache.maven.index.context.IndexCreator;
27  import org.codehaus.plexus.PlexusTestCase;
28  
29  /**
30   * @author Alin Dreghiciu
31   */
32  public class JarFileContentsIndexCreatorTest
33      extends PlexusTestCase
34  {
35      protected IndexCreator indexCreator;
36  
37      @Override
38      public void setUp()
39          throws Exception
40      {
41          super.setUp();
42  
43          indexCreator = this.lookup( IndexCreator.class, "jarContent" );
44      }
45  
46      public void test_nexus_2318_indexJarWithClasses()
47          throws Exception
48      {
49          File artifact = new File( getBasedir(), "src/test/nexus-2318/aopalliance/aopalliance/1.0/aopalliance-1.0.jar" );
50  
51          File pom = new File( getBasedir(), "src/test/nexus-2318/aopalliance/aopalliance/1.0/aopalliance-1.0.pom" );
52  
53          ArtifactInfo artifactInfo = new ArtifactInfo( "test", "aopalliance", "aopalliance", "1.0", null );
54  
55          ArtifactContext artifactContext = new ArtifactContext( pom, artifact, null, artifactInfo, null );
56  
57          indexCreator.populateArtifactInfo( artifactContext );
58  
59          assertNotNull( "Classes should not be null", artifactContext.getArtifactInfo().classNames );
60      }
61  
62      public void test_nexus_2318_indexJarWithSources()
63          throws Exception
64      {
65          File artifact =
66              new File( getBasedir(), "src/test/nexus-2318/aopalliance/aopalliance/1.0/aopalliance-1.0-sources.jar" );
67  
68          File pom = new File( getBasedir(), "src/test/nexus-2318/aopalliance/aopalliance/1.0/aopalliance-1.0.pom" );
69  
70          ArtifactInfo artifactInfo = new ArtifactInfo( "test", "aopalliance", "aopalliance", "1.0", null );
71  
72          ArtifactContext artifactContext = new ArtifactContext( pom, artifact, null, artifactInfo, null );
73  
74          indexCreator.populateArtifactInfo( artifactContext );
75  
76          assertNull( "Classes should be null", artifactContext.getArtifactInfo().classNames );
77      }
78  
79      public void testMindexer35ScanWar()
80          throws Exception
81      {
82          File artifact =
83              new File( getBasedir(),
84                  "src/test/mindexer-35/org/apache/maven/indexer/test/sample-war/1.0-SNAPSHOT/sample-war-1.0-SNAPSHOT.war" );
85  
86          File pom =
87              new File( getBasedir(),
88                  "src/test/mindexer-35/org/apache/maven/indexer/test/sample-war/1.0-SNAPSHOT/sample-war-1.0-SNAPSHOT.pom" );
89  
90          ArtifactInfo artifactInfo =
91              new ArtifactInfo( "test", "org.apache.maven.indexer.test", "sample-war", "1.0-SNAPSHOT", null );
92  
93          ArtifactContext artifactContext = new ArtifactContext( pom, artifact, null, artifactInfo, null );
94  
95          indexCreator.populateArtifactInfo( artifactContext );
96  
97          assertTrue( "Classes should contain WebappClass",
98              artifactContext.getArtifactInfo().classNames.contains( "WebappClass" ) );
99          assertEquals( "WebappClass should have proper package",
100             "/org/apache/maven/indexer/samples/webapp/WebappClass", artifactContext.getArtifactInfo().classNames );
101     }
102 }