Skip to content

Commit 841ae46

Browse files
Generate JPMS compatible artifacts in addtion to the existing artifacts
1 parent b8443b8 commit 841ae46

12 files changed

+665
-92
lines changed

CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Features
99
--------
1010
* [#1217](https://github.com/java-native-access/jna/pull/1217): Add mappings for AIX `Perfstat` library to `c.s.j.p.unix.aix` - [@dbwiddis](https://github.com/dbwiddis).
1111
* [#1231](https://github.com/java-native-access/jna/pull/1231): The test suite can now be executed on Windows using either ANSI or UNICODE win32 API by passing `-Dw32.ascii=true/false` to ant. Previously, UNICODE was always used. - [@T-Svensson](https://github.com/T-Svensson/)
12+
* [#1237](https://github.com/java-native-access/jna/pull/1237): *Experimental:* Add artifacts that make jna and jna-platform named modules (provide `module-info.class`). The new artifacts are named `jna-jpms.jar` and `jna-platform-jpms.jar` - [@matthiasblaesing](https://github.com/matthiasblaesing).
1213

1314
Bug Fixes
1415
---------

ant-tools-src/com/sun/jna/CalcAndroidVersion.java ant-tools-src/com/sun/jna/ant/CalcAndroidVersion.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* containing JNA, in file "AL2.0".
2323
*/
2424

25-
package com.sun.jna;
25+
package com.sun.jna.ant;
2626

2727
import java.io.IOException;
2828
import org.apache.tools.ant.Project;
+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/* Copyright (c) 2020 Matthias Bläsing, All Rights Reserved
2+
*
3+
* The contents of this file is dual-licensed under 2
4+
* alternative Open Source/Free licenses: LGPL 2.1 or later and
5+
* Apache License 2.0. (starting with JNA version 4.0.0).
6+
*
7+
* You can freely decide which license you want to apply to
8+
* the project.
9+
*
10+
* You may obtain a copy of the LGPL License at:
11+
*
12+
* http://www.gnu.org/licenses/licenses.html
13+
*
14+
* A copy is also included in the downloadable source code package
15+
* containing JNA, in file "LGPL2.1".
16+
*
17+
* You may obtain a copy of the Apache License at:
18+
*
19+
* http://www.apache.org/licenses/
20+
*
21+
* A copy is also included in the downloadable source code package
22+
* containing JNA, in file "AL2.0".
23+
*/
24+
25+
package com.sun.jna.ant;
26+
27+
import java.util.HashSet;
28+
import java.util.Set;
29+
30+
public class Exports {
31+
private String packageName;
32+
private String to;
33+
34+
public String getPackage() {
35+
return packageName;
36+
}
37+
38+
public void setPackage(String packageName) {
39+
this.packageName = packageName;
40+
}
41+
42+
public String getBinaryPackageName() {
43+
return packageName.replace(".", "/");
44+
}
45+
46+
public String getTo() {
47+
return to;
48+
}
49+
50+
public void setTo(String to) {
51+
this.to = to;
52+
}
53+
54+
public String[] getToList() {
55+
if(to == null) {
56+
return null;
57+
} else {
58+
Set<String> toList = new HashSet<String>();
59+
for(String s: to.split(",")) {
60+
String entry = s.trim();
61+
if(! entry.isEmpty()) {
62+
toList.add(entry);
63+
}
64+
}
65+
if(toList.isEmpty()) {
66+
return null;
67+
} else {
68+
return toList.toArray(new String[0]);
69+
}
70+
}
71+
}
72+
73+
@Override
74+
public String toString() {
75+
return "Export{" + "package=" + packageName + ", to=" + to + '}';
76+
}
77+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
/* Copyright (c) 2020 Matthias Bläsing, All Rights Reserved
2+
*
3+
* The contents of this file is dual-licensed under 2
4+
* alternative Open Source/Free licenses: LGPL 2.1 or later and
5+
* Apache License 2.0. (starting with JNA version 4.0.0).
6+
*
7+
* You can freely decide which license you want to apply to
8+
* the project.
9+
*
10+
* You may obtain a copy of the LGPL License at:
11+
*
12+
* http://www.gnu.org/licenses/licenses.html
13+
*
14+
* A copy is also included in the downloadable source code package
15+
* containing JNA, in file "LGPL2.1".
16+
*
17+
* You may obtain a copy of the Apache License at:
18+
*
19+
* http://www.apache.org/licenses/
20+
*
21+
* A copy is also included in the downloadable source code package
22+
* containing JNA, in file "AL2.0".
23+
*/
24+
25+
package com.sun.jna.ant;
26+
27+
import java.io.File;
28+
import java.io.FileOutputStream;
29+
import java.io.IOException;
30+
import java.util.ArrayList;
31+
import java.util.List;
32+
import org.objectweb.asm.ClassWriter;
33+
import org.objectweb.asm.ModuleVisitor;
34+
import static org.objectweb.asm.Opcodes.*;
35+
36+
public class ModuleGenerator {
37+
private String name;
38+
private String version;
39+
private boolean open;
40+
private String mainClass;
41+
private File targetFile;
42+
private List<Exports> exports = new ArrayList<Exports>();
43+
private List<Opens> opens = new ArrayList<Opens>();
44+
private List<Requires> requires = new ArrayList<Requires>();
45+
private List<Package> packages = new ArrayList<Package>();
46+
47+
public File getTargetFile() {
48+
return targetFile;
49+
}
50+
51+
public void setTargetFile(File targetFile) {
52+
this.targetFile = targetFile;
53+
}
54+
55+
public String getName() {
56+
return name;
57+
}
58+
59+
public void setName(String name) {
60+
this.name = name;
61+
}
62+
63+
public String getVersion() {
64+
return version;
65+
}
66+
67+
public void setVersion(String version) {
68+
this.version = version;
69+
}
70+
71+
public boolean isOpen() {
72+
return open;
73+
}
74+
75+
public void setOpen(boolean open) {
76+
this.open = open;
77+
}
78+
79+
public String getMainClass() {
80+
return mainClass;
81+
}
82+
83+
public void setMainClass(String mainClass) {
84+
this.mainClass = mainClass;
85+
}
86+
87+
public String getMainClassBinary() {
88+
if(mainClass != null) {
89+
return mainClass.replace(".", "/");
90+
} else {
91+
return mainClass;
92+
}
93+
}
94+
95+
public Exports createExports() {
96+
Exports export = new Exports();
97+
this.exports.add(export);
98+
return export;
99+
}
100+
101+
public List<Exports> getExports() {
102+
return exports;
103+
}
104+
105+
public void setExports(List<Exports> exports) {
106+
this.exports = exports;
107+
}
108+
109+
public Requires createRequires() {
110+
Requires require = new Requires();
111+
this.requires.add(require);
112+
return require;
113+
}
114+
115+
public List<Requires> getRequires() {
116+
return requires;
117+
}
118+
119+
public void setRequires(List<Requires> requires) {
120+
this.requires = requires;
121+
}
122+
123+
public Opens createOpens() {
124+
Opens openEntry = new Opens();
125+
this.opens.add(openEntry);
126+
return openEntry;
127+
}
128+
129+
public List<Opens> getOpens() {
130+
return opens;
131+
}
132+
133+
public void setOpens(List<Opens> opens) {
134+
this.opens = opens;
135+
}
136+
137+
public Package createPackage() {
138+
Package packageEntry = new Package();
139+
this.packages.add(packageEntry);
140+
return packageEntry;
141+
}
142+
143+
public List<Package> getPackages() {
144+
return packages;
145+
}
146+
147+
public void setPackages(List<Package> packageEntry) {
148+
this.packages = packageEntry;
149+
}
150+
151+
public void execute() throws IOException {
152+
System.out.println(this);
153+
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
154+
cw.visit(V9, ACC_MODULE, "module-info", null, null, null);
155+
ModuleVisitor mv = cw.visitModule(name, (open ? ACC_OPEN : 0), version);
156+
mv.visitRequire("java.base", ACC_MANDATED, null);
157+
for(Requires require: requires) {
158+
mv.visitRequire(
159+
require.getModule(),
160+
(require.isStatic() ? ACC_STATIC : 0)|( require.isTransitive() ? ACC_TRANSITIVE : 0),
161+
null);
162+
}
163+
for(Exports export: exports) {
164+
mv.visitExport(
165+
export.getBinaryPackageName(),
166+
0,
167+
export.getToList()
168+
);
169+
}
170+
for(Opens openEntry: opens) {
171+
mv.visitOpen(
172+
openEntry.getBinaryPackageName(),
173+
0,
174+
openEntry.getToList());
175+
}
176+
for(Package packageEntry: packages) {
177+
mv.visitPackage(packageEntry.getName());
178+
}
179+
if(getMainClassBinary() != null) {
180+
mv.visitMainClass(getMainClassBinary());
181+
}
182+
mv.visitEnd();
183+
cw.visitEnd();
184+
try (FileOutputStream fos = new FileOutputStream(targetFile)) {
185+
fos.write(cw.toByteArray());
186+
}
187+
}
188+
189+
@Override
190+
public String toString() {
191+
return "ModuleGenerator{" + "name=" + name + ", version=" + version + ", open=" + open + ", mainClass=" + mainClass + ", targetFile=" + targetFile + ", exports=" + exports + ", opens=" + opens + ", requires=" + requires + ", packages=" + packages + '}';
192+
}
193+
}
+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/* Copyright (c) 2020 Matthias Bläsing, All Rights Reserved
2+
*
3+
* The contents of this file is dual-licensed under 2
4+
* alternative Open Source/Free licenses: LGPL 2.1 or later and
5+
* Apache License 2.0. (starting with JNA version 4.0.0).
6+
*
7+
* You can freely decide which license you want to apply to
8+
* the project.
9+
*
10+
* You may obtain a copy of the LGPL License at:
11+
*
12+
* http://www.gnu.org/licenses/licenses.html
13+
*
14+
* A copy is also included in the downloadable source code package
15+
* containing JNA, in file "LGPL2.1".
16+
*
17+
* You may obtain a copy of the Apache License at:
18+
*
19+
* http://www.apache.org/licenses/
20+
*
21+
* A copy is also included in the downloadable source code package
22+
* containing JNA, in file "AL2.0".
23+
*/
24+
25+
package com.sun.jna.ant;
26+
27+
import java.util.HashSet;
28+
import java.util.Set;
29+
30+
public class Opens {
31+
private String packageName;
32+
private String to;
33+
34+
public String getPackage() {
35+
return packageName;
36+
}
37+
38+
public void setPackage(String packageName) {
39+
this.packageName = packageName;
40+
}
41+
42+
public String getBinaryPackageName() {
43+
return packageName.replace(".", "/");
44+
}
45+
46+
public String getTo() {
47+
return to;
48+
}
49+
50+
public void setTo(String to) {
51+
this.to = to;
52+
}
53+
54+
public String[] getToList() {
55+
if(to == null) {
56+
return null;
57+
} else {
58+
Set<String> toList = new HashSet<String>();
59+
for(String s: to.split(",")) {
60+
String entry = s.trim();
61+
if(! entry.isEmpty()) {
62+
toList.add(entry);
63+
}
64+
}
65+
if(toList.isEmpty()) {
66+
return null;
67+
} else {
68+
return toList.toArray(new String[0]);
69+
}
70+
}
71+
}
72+
73+
@Override
74+
public String toString() {
75+
return "Opens{" + "packageName=" + packageName + ", to=" + to + '}';
76+
}
77+
}

0 commit comments

Comments
 (0)