diff --git a/CHANGES.md b/CHANGES.md index 5126c46898..55094754f3 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -9,6 +9,7 @@ Features -------- * [#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). * [#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/) +* [#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). Bug Fixes --------- diff --git a/ant-tools-src/com/sun/jna/CalcAndroidVersion.java b/ant-tools-src/com/sun/jna/ant/CalcAndroidVersion.java similarity index 99% rename from ant-tools-src/com/sun/jna/CalcAndroidVersion.java rename to ant-tools-src/com/sun/jna/ant/CalcAndroidVersion.java index 6afe9d404e..cdf1ccfdee 100644 --- a/ant-tools-src/com/sun/jna/CalcAndroidVersion.java +++ b/ant-tools-src/com/sun/jna/ant/CalcAndroidVersion.java @@ -22,7 +22,7 @@ * containing JNA, in file "AL2.0". */ -package com.sun.jna; +package com.sun.jna.ant; import java.io.IOException; import org.apache.tools.ant.Project; diff --git a/ant-tools-src/com/sun/jna/ant/Exports.java b/ant-tools-src/com/sun/jna/ant/Exports.java new file mode 100644 index 0000000000..107082d289 --- /dev/null +++ b/ant-tools-src/com/sun/jna/ant/Exports.java @@ -0,0 +1,77 @@ +/* Copyright (c) 2020 Matthias Bläsing, All Rights Reserved + * + * The contents of this file is dual-licensed under 2 + * alternative Open Source/Free licenses: LGPL 2.1 or later and + * Apache License 2.0. (starting with JNA version 4.0.0). + * + * You can freely decide which license you want to apply to + * the project. + * + * You may obtain a copy of the LGPL License at: + * + * http://www.gnu.org/licenses/licenses.html + * + * A copy is also included in the downloadable source code package + * containing JNA, in file "LGPL2.1". + * + * You may obtain a copy of the Apache License at: + * + * http://www.apache.org/licenses/ + * + * A copy is also included in the downloadable source code package + * containing JNA, in file "AL2.0". + */ + +package com.sun.jna.ant; + +import java.util.HashSet; +import java.util.Set; + +public class Exports { + private String packageName; + private String to; + + public String getPackage() { + return packageName; + } + + public void setPackage(String packageName) { + this.packageName = packageName; + } + + public String getBinaryPackageName() { + return packageName.replace(".", "/"); + } + + public String getTo() { + return to; + } + + public void setTo(String to) { + this.to = to; + } + + public String[] getToList() { + if(to == null) { + return null; + } else { + Set toList = new HashSet(); + for(String s: to.split(",")) { + String entry = s.trim(); + if(! entry.isEmpty()) { + toList.add(entry); + } + } + if(toList.isEmpty()) { + return null; + } else { + return toList.toArray(new String[0]); + } + } + } + + @Override + public String toString() { + return "Export{" + "package=" + packageName + ", to=" + to + '}'; + } +} diff --git a/ant-tools-src/com/sun/jna/ant/ModuleGenerator.java b/ant-tools-src/com/sun/jna/ant/ModuleGenerator.java new file mode 100644 index 0000000000..76215fec2f --- /dev/null +++ b/ant-tools-src/com/sun/jna/ant/ModuleGenerator.java @@ -0,0 +1,193 @@ +/* Copyright (c) 2020 Matthias Bläsing, All Rights Reserved + * + * The contents of this file is dual-licensed under 2 + * alternative Open Source/Free licenses: LGPL 2.1 or later and + * Apache License 2.0. (starting with JNA version 4.0.0). + * + * You can freely decide which license you want to apply to + * the project. + * + * You may obtain a copy of the LGPL License at: + * + * http://www.gnu.org/licenses/licenses.html + * + * A copy is also included in the downloadable source code package + * containing JNA, in file "LGPL2.1". + * + * You may obtain a copy of the Apache License at: + * + * http://www.apache.org/licenses/ + * + * A copy is also included in the downloadable source code package + * containing JNA, in file "AL2.0". + */ + +package com.sun.jna.ant; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.ModuleVisitor; +import static org.objectweb.asm.Opcodes.*; + +public class ModuleGenerator { + private String name; + private String version; + private boolean open; + private String mainClass; + private File targetFile; + private List exports = new ArrayList(); + private List opens = new ArrayList(); + private List requires = new ArrayList(); + private List packages = new ArrayList(); + + public File getTargetFile() { + return targetFile; + } + + public void setTargetFile(File targetFile) { + this.targetFile = targetFile; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public boolean isOpen() { + return open; + } + + public void setOpen(boolean open) { + this.open = open; + } + + public String getMainClass() { + return mainClass; + } + + public void setMainClass(String mainClass) { + this.mainClass = mainClass; + } + + public String getMainClassBinary() { + if(mainClass != null) { + return mainClass.replace(".", "/"); + } else { + return mainClass; + } + } + + public Exports createExports() { + Exports export = new Exports(); + this.exports.add(export); + return export; + } + + public List getExports() { + return exports; + } + + public void setExports(List exports) { + this.exports = exports; + } + + public Requires createRequires() { + Requires require = new Requires(); + this.requires.add(require); + return require; + } + + public List getRequires() { + return requires; + } + + public void setRequires(List requires) { + this.requires = requires; + } + + public Opens createOpens() { + Opens openEntry = new Opens(); + this.opens.add(openEntry); + return openEntry; + } + + public List getOpens() { + return opens; + } + + public void setOpens(List opens) { + this.opens = opens; + } + + public Package createPackage() { + Package packageEntry = new Package(); + this.packages.add(packageEntry); + return packageEntry; + } + + public List getPackages() { + return packages; + } + + public void setPackages(List packageEntry) { + this.packages = packageEntry; + } + + public void execute() throws IOException { + System.out.println(this); + ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); + cw.visit(V9, ACC_MODULE, "module-info", null, null, null); + ModuleVisitor mv = cw.visitModule(name, (open ? ACC_OPEN : 0), version); + mv.visitRequire("java.base", ACC_MANDATED, null); + for(Requires require: requires) { + mv.visitRequire( + require.getModule(), + (require.isStatic() ? ACC_STATIC : 0)|( require.isTransitive() ? ACC_TRANSITIVE : 0), + null); + } + for(Exports export: exports) { + mv.visitExport( + export.getBinaryPackageName(), + 0, + export.getToList() + ); + } + for(Opens openEntry: opens) { + mv.visitOpen( + openEntry.getBinaryPackageName(), + 0, + openEntry.getToList()); + } + for(Package packageEntry: packages) { + mv.visitPackage(packageEntry.getName()); + } + if(getMainClassBinary() != null) { + mv.visitMainClass(getMainClassBinary()); + } + mv.visitEnd(); + cw.visitEnd(); + try (FileOutputStream fos = new FileOutputStream(targetFile)) { + fos.write(cw.toByteArray()); + } + } + + @Override + public String toString() { + return "ModuleGenerator{" + "name=" + name + ", version=" + version + ", open=" + open + ", mainClass=" + mainClass + ", targetFile=" + targetFile + ", exports=" + exports + ", opens=" + opens + ", requires=" + requires + ", packages=" + packages + '}'; + } +} diff --git a/ant-tools-src/com/sun/jna/ant/Opens.java b/ant-tools-src/com/sun/jna/ant/Opens.java new file mode 100644 index 0000000000..07a6c8241b --- /dev/null +++ b/ant-tools-src/com/sun/jna/ant/Opens.java @@ -0,0 +1,77 @@ +/* Copyright (c) 2020 Matthias Bläsing, All Rights Reserved + * + * The contents of this file is dual-licensed under 2 + * alternative Open Source/Free licenses: LGPL 2.1 or later and + * Apache License 2.0. (starting with JNA version 4.0.0). + * + * You can freely decide which license you want to apply to + * the project. + * + * You may obtain a copy of the LGPL License at: + * + * http://www.gnu.org/licenses/licenses.html + * + * A copy is also included in the downloadable source code package + * containing JNA, in file "LGPL2.1". + * + * You may obtain a copy of the Apache License at: + * + * http://www.apache.org/licenses/ + * + * A copy is also included in the downloadable source code package + * containing JNA, in file "AL2.0". + */ + +package com.sun.jna.ant; + +import java.util.HashSet; +import java.util.Set; + +public class Opens { + private String packageName; + private String to; + + public String getPackage() { + return packageName; + } + + public void setPackage(String packageName) { + this.packageName = packageName; + } + + public String getBinaryPackageName() { + return packageName.replace(".", "/"); + } + + public String getTo() { + return to; + } + + public void setTo(String to) { + this.to = to; + } + + public String[] getToList() { + if(to == null) { + return null; + } else { + Set toList = new HashSet(); + for(String s: to.split(",")) { + String entry = s.trim(); + if(! entry.isEmpty()) { + toList.add(entry); + } + } + if(toList.isEmpty()) { + return null; + } else { + return toList.toArray(new String[0]); + } + } + } + + @Override + public String toString() { + return "Opens{" + "packageName=" + packageName + ", to=" + to + '}'; + } +} diff --git a/ant-tools-src/com/sun/jna/ant/Package.java b/ant-tools-src/com/sun/jna/ant/Package.java new file mode 100644 index 0000000000..4b6fbaf196 --- /dev/null +++ b/ant-tools-src/com/sun/jna/ant/Package.java @@ -0,0 +1,42 @@ +/* Copyright (c) 2020 Matthias Bläsing, All Rights Reserved + * + * The contents of this file is dual-licensed under 2 + * alternative Open Source/Free licenses: LGPL 2.1 or later and + * Apache License 2.0. (starting with JNA version 4.0.0). + * + * You can freely decide which license you want to apply to + * the project. + * + * You may obtain a copy of the LGPL License at: + * + * http://www.gnu.org/licenses/licenses.html + * + * A copy is also included in the downloadable source code package + * containing JNA, in file "LGPL2.1". + * + * You may obtain a copy of the Apache License at: + * + * http://www.apache.org/licenses/ + * + * A copy is also included in the downloadable source code package + * containing JNA, in file "AL2.0". + */ + +package com.sun.jna.ant; + +public class Package { + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public String toString() { + return "Package{" + "name=" + name + '}'; + } +} diff --git a/ant-tools-src/com/sun/jna/ant/Requires.java b/ant-tools-src/com/sun/jna/ant/Requires.java new file mode 100644 index 0000000000..45ec6d6e9e --- /dev/null +++ b/ant-tools-src/com/sun/jna/ant/Requires.java @@ -0,0 +1,60 @@ +/* Copyright (c) 2020 Matthias Bläsing, All Rights Reserved + * + * The contents of this file is dual-licensed under 2 + * alternative Open Source/Free licenses: LGPL 2.1 or later and + * Apache License 2.0. (starting with JNA version 4.0.0). + * + * You can freely decide which license you want to apply to + * the project. + * + * You may obtain a copy of the LGPL License at: + * + * http://www.gnu.org/licenses/licenses.html + * + * A copy is also included in the downloadable source code package + * containing JNA, in file "LGPL2.1". + * + * You may obtain a copy of the Apache License at: + * + * http://www.apache.org/licenses/ + * + * A copy is also included in the downloadable source code package + * containing JNA, in file "AL2.0". + */ + +package com.sun.jna.ant; + +public class Requires { + private String module; + private boolean transitive; + private boolean _static; + + public String getModule() { + return module; + } + + public void setModule(String module) { + this.module = module; + } + + public boolean isTransitive() { + return transitive; + } + + public void setTransitive(boolean transitive) { + this.transitive = transitive; + } + + public boolean isStatic() { + return _static; + } + + public void setStatic(boolean _static) { + this._static = _static; + } + + @Override + public String toString() { + return "Requires{" + "module=" + module + ", transitive=" + transitive + '}'; + } +} diff --git a/build-ant-tools.xml b/build-ant-tools.xml new file mode 100644 index 0000000000..bb73fc7462 --- /dev/null +++ b/build-ant-tools.xml @@ -0,0 +1,20 @@ + + + Builds and tests JNA + + + + + + + + + + + + + \ No newline at end of file diff --git a/build.xml b/build.xml index 43ad2b0e2e..32b1c5d870 100644 --- a/build.xml +++ b/build.xml @@ -2,7 +2,8 @@ + xmlns:if="ant:if" + xmlns:unless="ant:unless"> Builds and tests JNA @@ -135,6 +138,7 @@ + @@ -171,20 +175,10 @@ classpathref="maven-ant-tasks.classpath" /> - - - - - - - - - - + + + + @@ -431,36 +425,38 @@ - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + @@ -614,6 +637,10 @@ osname=macosx;processor=x86;processor=x86-64;processor=ppc + + + + @@ -1363,8 +1390,8 @@ cd .. - - + + @@ -1435,6 +1462,14 @@ cd .. + + + + + + + + @@ -1442,6 +1477,14 @@ cd .. + + + + + + + + @@ -1452,9 +1495,9 @@ cd .. - - - + + + @@ -1463,9 +1506,9 @@ cd .. - - - + + + @@ -1480,9 +1523,9 @@ cd .. - - - + + + @@ -1493,9 +1536,9 @@ cd .. - - - + + + diff --git a/contrib/platform/build.xml b/contrib/platform/build.xml index 7df4b112e6..51d54e1688 100644 --- a/contrib/platform/build.xml +++ b/contrib/platform/build.xml @@ -2,7 +2,9 @@ + xmlns:as="antlib:org.codehaus.mojo.animal_sniffer" + xmlns:if="ant:if" + xmlns:unless="ant:unless"> Builds and tests platform-specific code. - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + @@ -160,6 +180,46 @@ com.sun.jna.platform.wince;version=${osgi.version} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -183,8 +243,8 @@ com.sun.jna.platform.wince;version=${osgi.version} Running platform tests: ${test.src.dir} - - + + Saving test results in ${results.junit} diff --git a/lib/asm-8.0.1.jar b/lib/asm-8.0.1.jar new file mode 100644 index 0000000000..744fecc025 Binary files /dev/null and b/lib/asm-8.0.1.jar differ diff --git a/nbproject/project.xml b/nbproject/project.xml index 80ef8fc5b1..63e82e1e33 100644 --- a/nbproject/project.xml +++ b/nbproject/project.xml @@ -99,7 +99,7 @@ auxiliary.show.customizer.message= ant-tools-src - src:lib/ant.jar + src:lib/ant.jar:lib/asm-8.0.1.jar 1.6