View Javadoc

1   package org.apache.maven.shared.jar;
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.classes.JarClasses;
23  import org.apache.maven.shared.jar.identification.JarIdentification;
24  import org.codehaus.plexus.util.StringUtils;
25  
26  import java.io.File;
27  import java.util.Collections;
28  import java.util.List;
29  import java.util.jar.Attributes;
30  import java.util.jar.Manifest;
31  
32  /**
33   * Class that contains details of a single JAR file and it's entries.
34   */
35  public final class JarData
36  {
37      /**
38       * The JAR file.
39       */
40      private final File file;
41  
42      /**
43       * Whether the JAR file is sealed.
44       */
45      private final boolean sealed;
46  
47      /**
48       * The hashcode for the entire file's contents.
49       */
50      private String fileHash;
51  
52      /**
53       * The hashcode for the file's class data contents.
54       */
55      private String bytecodeHash;
56  
57      /**
58       * The JAR's manifest.
59       */
60      private final Manifest manifest;
61  
62      /**
63       * Information about the JAR's classes.
64       */
65      private JarClasses jarClasses;
66  
67      /**
68       * The JAR entries.
69       */
70      private final List entries;
71  
72      /**
73       * Information about the JAR's identifying features.
74       */
75      private JarIdentification jarIdentification;
76  
77      /**
78       * Constructor.
79       *
80       * @param file     the JAR file
81       * @param manifest the JAR manifest
82       * @param entries  the JAR entries
83       */
84      public JarData( File file, Manifest manifest, List entries )
85      {
86          this.file = file;
87  
88          this.manifest = manifest;
89  
90          this.entries = Collections.unmodifiableList( entries );
91  
92          boolean sealed = false;
93          if ( this.manifest != null )
94          {
95              String sval = this.manifest.getMainAttributes().getValue( Attributes.Name.SEALED );
96              if ( StringUtils.isNotEmpty( sval ) )
97              {
98                  sealed = "true".equalsIgnoreCase( sval.trim() );
99              }
100         }
101         this.sealed = sealed;
102     }
103 
104     public List getEntries()
105     {
106         return entries;
107     }
108 
109     public Manifest getManifest()
110     {
111         return manifest;
112     }
113 
114     public File getFile()
115     {
116         return file;
117     }
118 
119     public boolean isSealed()
120     {
121         return sealed;
122     }
123 
124     public void setFileHash( String fileHash )
125     {
126         this.fileHash = fileHash;
127     }
128 
129     public String getFileHash()
130     {
131         return fileHash;
132     }
133 
134     public void setBytecodeHash( String bytecodeHash )
135     {
136         this.bytecodeHash = bytecodeHash;
137     }
138 
139     public String getBytecodeHash()
140     {
141         return bytecodeHash;
142     }
143 
144     public boolean isDebugPresent()
145     {
146         return jarClasses.isDebugPresent();
147     }
148 
149     public void setJarClasses( JarClasses jarClasses )
150     {
151         this.jarClasses = jarClasses;
152     }
153 
154     public int getNumEntries()
155     {
156         return entries.size();
157     }
158 
159     public int getNumClasses()
160     {
161         return jarClasses.getClassNames().size();
162     }
163 
164     public int getNumPackages()
165     {
166         return jarClasses.getPackages().size();
167     }
168 
169     public String getJdkRevision()
170     {
171         return jarClasses.getJdkRevision();
172     }
173 
174     public void setJarIdentification( JarIdentification jarIdentification )
175     {
176         this.jarIdentification = jarIdentification;
177     }
178 
179     public JarIdentification getJarIdentification()
180     {
181         return jarIdentification;
182     }
183 
184     public JarClasses getJarClasses()
185     {
186         return jarClasses;
187     }
188 }