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 JarIdentification jarIdentification;
84
85
86
87
88 private JarVersionedRuntimes versionedRuntimes;
89
90
91
92
93
94
95
96
97 public JarData(File file, Manifest manifest, List<JarEntry> entries) {
98 this.file = file;
99
100 this.manifest = manifest;
101
102 this.entries = Collections.unmodifiableList(entries);
103
104 this.aSealed = isAttributePresent(Attributes.Name.SEALED);
105 this.multiRelease = isAttributePresent(ATTR_MULTI_RELEASE);
106 }
107
108 public List<JarEntry> getEntries() {
109 return entries;
110 }
111
112 public Manifest getManifest() {
113 return manifest;
114 }
115
116 public File getFile() {
117 return file;
118 }
119
120 public boolean isSealed() {
121 return aSealed;
122 }
123
124 public boolean isMultiRelease() {
125 return multiRelease;
126 }
127
128 public void setFileHash(String fileHash) {
129 this.fileHash = fileHash;
130 }
131
132 public String getFileHash() {
133 return fileHash;
134 }
135
136 public void setBytecodeHash(String bytecodeHash) {
137 this.bytecodeHash = bytecodeHash;
138 }
139
140 public String getBytecodeHash() {
141 return bytecodeHash;
142 }
143
144 public boolean isDebugPresent() {
145 return jarClasses.isDebugPresent();
146 }
147
148 public void setJarClasses(JarClasses jarClasses) {
149 this.jarClasses = jarClasses;
150 }
151
152 public int getNumEntries() {
153 return entries.size();
154 }
155
156 public int getNumClasses() {
157 return jarClasses.getClassNames().size();
158 }
159
160 public int getNumPackages() {
161 return jarClasses.getPackages().size();
162 }
163
164 public String getJdkRevision() {
165 return jarClasses.getJdkRevision();
166 }
167
168 public void setJarIdentification(JarIdentification jarIdentification) {
169 this.jarIdentification = jarIdentification;
170 }
171
172 public JarIdentification getJarIdentification() {
173 return jarIdentification;
174 }
175
176 public JarClasses getJarClasses() {
177 return jarClasses;
178 }
179
180 public void setVersionedRuntimes(JarVersionedRuntimes versionedRuntimess) {
181 this.versionedRuntimes = versionedRuntimess;
182 }
183
184 public JarVersionedRuntimes getVersionedRuntimes() {
185 return this.versionedRuntimes;
186 }
187
188 private boolean isAttributePresent(Attributes.Name attrName) {
189 if (this.manifest != null) {
190 String sval = this.manifest.getMainAttributes().getValue(attrName);
191 return sval != null && "true".equalsIgnoreCase(sval.trim());
192 }
193 return false;
194 }
195 }