1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.shared.jar;
20
21 import java.io.File;
22 import java.util.Collections;
23 import java.util.List;
24 import java.util.jar.Attributes;
25 import java.util.jar.Attributes.Name;
26 import java.util.jar.JarEntry;
27 import java.util.jar.Manifest;
28
29 import org.apache.maven.shared.jar.classes.JarClasses;
30 import org.apache.maven.shared.jar.classes.JarVersionedRuntimes;
31 import org.apache.maven.shared.jar.identification.JarIdentification;
32
33
34
35
36 public final class JarData {
37
38 private static final Name ATTR_MULTI_RELEASE = new Attributes.Name("Multi-Release");
39
40
41
42
43 private final File file;
44
45
46
47
48 private final boolean aSealed;
49
50
51
52
53 private boolean multiRelease;
54
55
56
57
58 private String fileHash;
59
60
61
62
63 private String bytecodeHash;
64
65
66
67
68 private final Manifest manifest;
69
70
71
72
73 private JarClasses jarClasses;
74
75
76
77
78 private final List<JarEntry> entries;
79
80
81
82
83 private List<JarEntry> rootEntries;
84
85
86
87
88 private JarIdentification jarIdentification;
89
90
91
92
93 private JarVersionedRuntimes versionedRuntimes;
94
95
96
97
98
99
100
101
102 public JarData(File file, Manifest manifest, List<JarEntry> entries) {
103 this.file = file;
104
105 this.manifest = manifest;
106
107 this.entries = Collections.unmodifiableList(entries);
108
109 this.aSealed = isAttributePresent(Attributes.Name.SEALED);
110 this.multiRelease = isAttributePresent(ATTR_MULTI_RELEASE);
111 }
112
113 public List<JarEntry> getEntries() {
114 return entries;
115 }
116
117 public List<JarEntry> getRootEntries() {
118 return rootEntries;
119 }
120
121 public void setRootEntries(List<JarEntry> rootEntries) {
122 this.rootEntries = rootEntries;
123 }
124
125 public Manifest getManifest() {
126 return manifest;
127 }
128
129 public File getFile() {
130 return file;
131 }
132
133 public boolean isSealed() {
134 return aSealed;
135 }
136
137 public boolean isMultiRelease() {
138 return multiRelease;
139 }
140
141 public void setFileHash(String fileHash) {
142 this.fileHash = fileHash;
143 }
144
145 public String getFileHash() {
146 return fileHash;
147 }
148
149 public void setBytecodeHash(String bytecodeHash) {
150 this.bytecodeHash = bytecodeHash;
151 }
152
153 public String getBytecodeHash() {
154 return bytecodeHash;
155 }
156
157 public boolean isDebugPresent() {
158 return jarClasses.isDebugPresent();
159 }
160
161 public void setJarClasses(JarClasses jarClasses) {
162 this.jarClasses = jarClasses;
163 }
164
165 public int getNumEntries() {
166 return entries.size();
167 }
168
169 public int getNumRootEntries() {
170 return rootEntries.size();
171 }
172
173 public int getNumClasses() {
174 return jarClasses.getClassNames().size();
175 }
176
177 public int getNumPackages() {
178 return jarClasses.getPackages().size();
179 }
180
181 public String getJdkRevision() {
182 return jarClasses.getJdkRevision();
183 }
184
185 public void setJarIdentification(JarIdentification jarIdentification) {
186 this.jarIdentification = jarIdentification;
187 }
188
189 public JarIdentification getJarIdentification() {
190 return jarIdentification;
191 }
192
193 public JarClasses getJarClasses() {
194 return jarClasses;
195 }
196
197 public void setVersionedRuntimes(JarVersionedRuntimes versionedRuntimes) {
198 this.versionedRuntimes = versionedRuntimes;
199 }
200
201 public JarVersionedRuntimes getVersionedRuntimes() {
202 return this.versionedRuntimes;
203 }
204
205 private boolean isAttributePresent(Attributes.Name attrName) {
206 if (this.manifest != null) {
207 String sval = this.manifest.getMainAttributes().getValue(attrName);
208 return sval != null && "true".equalsIgnoreCase(sval.trim());
209 }
210 return false;
211 }
212 }