View Javadoc

1   package org.apache.maven.shared.jar.identification.exposers;
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 org.apache.maven.shared.jar.JarAnalyzer;
23  import org.apache.maven.shared.jar.identification.JarIdentification;
24  import org.apache.maven.shared.jar.identification.JarIdentificationExposer;
25  
26  import java.util.Iterator;
27  import java.util.Map;
28  import java.util.jar.Attributes;
29  import java.util.jar.Manifest;
30  
31  /**
32   * Exposer that examines a JAR's manifest to derive Maven metadata.
33   *
34   * @plexus.component role="org.apache.maven.shared.jar.identification.JarIdentificationExposer" role-hint="manifest"
35   */
36  public class ManifestExposer
37      implements JarIdentificationExposer
38  {
39      public void expose( JarIdentification identification, JarAnalyzer jarAnalyzer )
40      {
41          Manifest manifest = jarAnalyzer.getJarData().getManifest();
42          if ( manifest != null )
43          {
44              addManifestAttributeValues( manifest.getMainAttributes(), identification );
45  
46              Map entries = manifest.getEntries();
47              Iterator itentries = entries.entrySet().iterator();
48              while ( itentries.hasNext() )
49              {
50                  Map.Entry entry = (Map.Entry) itentries.next();
51                  Attributes attribs = (Attributes) entry.getValue();
52  
53                  addManifestAttributeValues( attribs, identification );
54              }
55          }
56      }
57  
58      private void addManifestAttributeValues( Attributes attribs, JarIdentification identification )
59      {
60          identification.addName( attribs.getValue( Attributes.Name.IMPLEMENTATION_TITLE ) );
61          identification.addVersion( attribs.getValue( Attributes.Name.IMPLEMENTATION_VERSION ) );
62          identification.addVendor( attribs.getValue( Attributes.Name.IMPLEMENTATION_VENDOR ) );
63  
64          identification.addName( attribs.getValue( Attributes.Name.SPECIFICATION_TITLE ) );
65          identification.addVersion( attribs.getValue( Attributes.Name.SPECIFICATION_VERSION ) );
66          identification.addVendor( attribs.getValue( Attributes.Name.SPECIFICATION_VENDOR ) );
67  
68          identification.addGroupId( attribs.getValue( Attributes.Name.EXTENSION_NAME ) );
69      }
70  }