From a6955e7692c0703ad173709f3a13353774b31de8 Mon Sep 17 00:00:00 2001 From: Naohide Sano Date: Sun, 18 Feb 2024 01:20:24 +0900 Subject: [PATCH 1/4] i didn't know that jna Native#load has capability to load native in jar --- .github/workflows/maven-publish.yml | 34 -------- pom.xml | 31 ------- rococoa-core/pom.xml | 116 +++++++++----------------- rococoa-core/src/test/java/Test1.java | 90 ++++++++++++++++++++ 4 files changed, 130 insertions(+), 141 deletions(-) delete mode 100644 .github/workflows/maven-publish.yml create mode 100644 rococoa-core/src/test/java/Test1.java diff --git a/.github/workflows/maven-publish.yml b/.github/workflows/maven-publish.yml deleted file mode 100644 index 39cd8ae..0000000 --- a/.github/workflows/maven-publish.yml +++ /dev/null @@ -1,34 +0,0 @@ -# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created -# For more information see: https://github.com/actions/setup-java#apache-maven-with-a-settings-path - -name: Maven Package - -on: - release: - types: [created] - -jobs: - build: - - runs-on: macos-14 - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - java-version: '17' - distribution: 'temurin' - cache: maven - server-id: github # Value of the distributionManagement/repository/id field of the pom.xml - settings-path: ${{ github.workspace }} # location for the settings.xml file - - - name: Build with Maven - run: mvn -B install --file pom.xml - - - name: Publish to GitHub Packages Apache Maven - run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml -Dmaven.test.skip=true - env: - GITHUB_TOKEN: ${{ github.token }} diff --git a/pom.xml b/pom.xml index 0f093fe..51111f9 100644 --- a/pom.xml +++ b/pom.xml @@ -104,30 +104,6 @@ org.apache.maven.plugins - maven-dependency-plugin - 3.3.0 - - - copy - generate-resources - - copy - - - - - org.rococoa - rococoa-core - dylib - test - false - ${project.build.testOutputDirectory} - librococoa.dylib - - - - - @@ -235,13 +211,6 @@ - - - github - https://maven.pkg.github.com/umjammer/rococoa-core - - - org.junit.jupiter diff --git a/rococoa-core/pom.xml b/rococoa-core/pom.xml index 4dada27..932f58e 100644 --- a/rococoa-core/pom.xml +++ b/rococoa-core/pom.xml @@ -16,6 +16,37 @@ jar https://github.com/umjammer/rococoa + + + test1 + + + + org.apache.maven.plugins + maven-antrun-plugin + 3.1.0 + + run + + + + + + + + + + + + + + + + + + + + @@ -82,7 +113,7 @@ - -o ${project.build.directory}/librococoa-${project.version}.dylib + -o ${project.build.outputDirectory}/librococoa.dylib @@ -105,6 +136,14 @@ test-jar + + + + true + Test1 + + + @@ -124,81 +163,6 @@ - - org.apache.maven.plugins - maven-install-plugin - 3.1.1 - - - install-test-library - install - - install-file - - - org.rococoa - rococoa-core - ${project.parent.version} - dylib - test - ${project.build.testOutputDirectory}/librococoa.dylib - - - - install-library - install - - install-file - - - org.rococoa - rococoa-core - ${project.parent.version} - dylib - ${project.build.directory}/librococoa-${project.version}.dylib - - - - - - - org.codehaus.mojo - exec-maven-plugin - 3.1.0 - - - - deploy-library - deploy - - exec - - - mvn - - deploy:deploy-file - -DgroupId=${project.groupId} - -DartifactId=${project.artifactId} - -Dversion=${project.version} - -Dpackaging=dylib - -Dfile=${project.build.directory}/librococoa-${project.version}.dylib - -DrepositoryId=github - -Durl=https://maven.pkg.github.com/umjammer/rococoa - -DgeneratePom=false - -s - ${env.GITHUB_WORKSPACE}/settings.xml - - - ${env.GITHUB_TOKEN} - - - - - diff --git a/rococoa-core/src/test/java/Test1.java b/rococoa-core/src/test/java/Test1.java new file mode 100644 index 0000000..9676449 --- /dev/null +++ b/rococoa-core/src/test/java/Test1.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2023 by Naohide Sano, All rights reserved. + * + * Programmed by Naohide Sano + */ + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.Reader; +import java.lang.invoke.CallSite; +import java.lang.invoke.ConstantCallSite; +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodType; +import java.nio.charset.Charset; +import java.util.Map; +import java.util.Scanner; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.Executors; +import java.util.concurrent.atomic.AtomicReference; + +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.rococoa.cocoa.foundation.NSString; +import vavi.util.Debug; + +import static org.junit.jupiter.api.Assertions.assertTrue; + + +/** + * Test1. + * + * @author Naohide Sano (nsano) + * @version 0.00 2023-06-30 nsano initial version
+ */ +public class Test1 { + + @Test + @Disabled + void test1() throws Exception { +// MethodHandle methodHandleFieldDirect = lookup.unreflectGetter(fieldName); +// CallSite callSiteField = new ConstantCallSite(methodHandleFieldDirect); +// methodHandleFieldDirect = callSiteField.dynamicInvoker(); +// name = (String) methodHandleFieldDirect.invokeExact(new Employee()); +// +// +////Lookup invoke dynamic +// methodType = MethodType.methodType(String.class); +// methodHandle = lookup.findVirtual(Employee.class, "getName", methodType); +// CallSite callSiteMethod = new ConstantCallSite(methodHandleFieldDirect); +// methodHandle = callSiteMethod.dynamicInvoker(); + } + + @Test +// @Disabled + void test2() throws Exception { + String jh = System.getProperty("java.home"); +Debug.println("JAVA_HOME: " + jh); + ProcessBuilder pb = new ProcessBuilder().command("mvn", "-P", "test1", "antrun:run", "-Dvalue=umjammer"); + Map env = pb.environment(); + env.put("JAVA_HOME", jh); + pb.redirectErrorStream(true); + CountDownLatch cdl = new CountDownLatch(1); + Process p = pb.start(); + AtomicReference result = new AtomicReference<>(); + Executors.newSingleThreadExecutor().submit(() -> { + int r = 0; + try { r = p.waitFor(); } catch (InterruptedException ignored) {} +Debug.println("result: " + r); + + try (Scanner s = new Scanner(p.getInputStream())) { + while (s.hasNextLine()) { + String line = s.nextLine(); +System.out.println(line); + if (line.contains("[java]")) { + result.set(line); + } + } + } + + cdl.countDown(); + }); + cdl.await(); + assertTrue(result.get().contains("Hello world! umjammer"), result.get()); + } + + /** */ + public static void main(String[] args) { + System.err.println(NSString.stringWithString("Hello world! " + (args.length > 0 ? args[0] : "")).toString()); + } +} From d0fb19682a73a1f7650b5bad7e9748d8ed83ed0d Mon Sep 17 00:00:00 2001 From: Naohide Sano Date: Sun, 18 Feb 2024 09:01:36 +0900 Subject: [PATCH 2/4] update settings --- .github/workflows/codeql-analysis.yml | 6 +++++- .github/workflows/maven.yml | 2 +- README.md | 10 ++++------ pom.xml | 11 ++--------- rococoa-cocoa/pom.xml | 8 +------- rococoa-contrib/pom.xml | 20 ++++++++------------ rococoa-core/pom.xml | 3 +-- 7 files changed, 22 insertions(+), 38 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 5690a6b..096187d 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -18,6 +18,10 @@ jobs: analyze: name: Analyze runs-on: macos-14 + permissions: + actions: read + contents: read + security-events: write strategy: fail-fast: false @@ -30,7 +34,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index ef4207b..bb2b339 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -16,7 +16,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Check w/o SNAPSHOT when "bump version" if: ${{ contains(github.event.head_commit.message, 'bump version') }} diff --git a/README.md b/README.md index 42ba802..7548fb0 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![GitHub Packages](https://github.com/umjammer/rococoa/actions/workflows/maven-publish.yml/badge.svg)](https://github.com/umjammer?tab=packages&repo_name=rococoa) +[![Release](https://jitpack.io/v/umjammer/rococoa.svg)](https://jitpack.io/#umjammer/rococoa) [![Java CI](https://github.com/umjammer/rococoa/actions/workflows/maven.yml/badge.svg)](https://github.com/umjammer/rococoa/actions/workflows/maven.yml) [![CodeQL](https://github.com/umjammer/rococoa/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/umjammer/rococoa/actions/workflows/codeql-analysis.yml) ![Java](https://img.shields.io/badge/Java-17-b07219) @@ -20,13 +20,11 @@ implementation of Objective-C interfaces in Java. * ~~[the reason](https://github.com/java-native-access/jna/issues/463#issuecomment-1286015013)~~ -> actually https://github.com/java-native-access/jna/issues/1476#issuecomment-1292804072 * https://www.mikeash.com/pyblog/objc_msgsends-new-prototype.html * obj-c block -* methods has **varargs don't** work (works less equal 8?) +* methods have **varargs don't** work (works less equal 8?) ## Installation - * https://github.com/umjammer/rococoa/packages/ - * this project uses github packages. add a personal access token to `~/.m2/settings.xml` - * see https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-apache-maven-registry + * https://jitpack.io/#umjammer/rococoa ## How To @@ -36,7 +34,7 @@ implementation of Objective-C interfaces in Java. * [iTunes Library](https://github.com/umjammer/vavi-sound-sandbox/tree/master/src/main/java/vavix/rococoa/ituneslibrary) * [AudioUnit Java MIDI SPI synthesizer](https://github.com/umjammer/vavi-sound-sandbox/tree/master/src/main/java/vavi/sound/midi/rococoa) * [CoreMidi Java MIDI SPI](https://github.com/umjammer/osxmidi4j) -* [NSSpeechSynthesizer Java Speech API](https://github.com/umjammer/vavi-speech2/tree/master/src/main/java/vavi/speech/rococoa/jsapi2) +* [AVSpeechSynthesizer Java Speech API](https://github.com/umjammer/vavi-speech2/tree/master/src/main/java/vavi/speech/rococoa/jsapi2) * [HEIF Java ImageIO SPI](https://github.com/umjammer/vavi-image-sandbox/tree/master/src/main/java/vavix/imageio/rococoa) * [MTLibrary](https://github.com/umjammer/vavi-apps-padsynth/tree/main/src/main/java/vavix/rococoa/multitouch) * [KeyChain Java crypto Keystore SPI](https://github.com/umjammer/vavi-crypto-sandbox/tree/1.0.2/src/main/java/vavix/rococoa/keychain) diff --git a/pom.xml b/pom.xml index 51111f9..52a8a1b 100644 --- a/pom.xml +++ b/pom.xml @@ -104,6 +104,8 @@ org.apache.maven.plugins + maven-surefire-plugin + 3.2.2 @@ -150,15 +152,6 @@ - - org.apache.maven.plugins - maven-resources-plugin - 3.3.1 - true - - UTF-8 - - diff --git a/rococoa-cocoa/pom.xml b/rococoa-cocoa/pom.xml index 999c30d..ae78378 100644 --- a/rococoa-cocoa/pom.xml +++ b/rococoa-cocoa/pom.xml @@ -18,15 +18,9 @@ - - org.apache.maven.plugins - maven-dependency-plugin - 3.6.1 - org.apache.maven.plugins maven-surefire-plugin - 3.2.2 false @@ -61,7 +55,7 @@ com.github.umjammer vavi-commons - 1.1.9 + 1.1.10 test
diff --git a/rococoa-contrib/pom.xml b/rococoa-contrib/pom.xml index 0da2aa6..54f75a3 100644 --- a/rococoa-contrib/pom.xml +++ b/rococoa-contrib/pom.xml @@ -18,15 +18,9 @@ - - org.apache.maven.plugins - maven-dependency-plugin - 3.6.1 - org.apache.maven.plugins maven-surefire-plugin - 3.2.2 false @@ -67,12 +61,6 @@ test-jar test - - com.github.umjammer - vavi-commons - 1.1.9 - test - io.github.artsok rerunner-jupiter @@ -80,6 +68,13 @@ test + + com.github.umjammer + vavi-commons + 1.1.10 + test + + com.github.sarxos webcam-capture @@ -93,6 +88,7 @@ dc4b67c6cc test + org.slf4j slf4j-jdk14 diff --git a/rococoa-core/pom.xml b/rococoa-core/pom.xml index 932f58e..6faa9e4 100644 --- a/rococoa-core/pom.xml +++ b/rococoa-core/pom.xml @@ -151,7 +151,6 @@ org.apache.maven.plugins maven-surefire-plugin - 3.2.2 false @@ -192,7 +191,7 @@ com.github.umjammer vavi-commons - 1.1.9 + 1.1.10 test From abb77af047d6e50c7f1110f7e1a76aaaa8f7c4aa Mon Sep 17 00:00:00 2001 From: Naohide Sano Date: Sun, 18 Feb 2024 09:04:59 +0900 Subject: [PATCH 3/4] bump version --- pom.xml | 2 +- rococoa-cocoa/pom.xml | 2 +- rococoa-contrib/pom.xml | 2 +- rococoa-core/pom.xml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 52a8a1b..99ae041 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.rococoa rococoa-parent - 0.8.6 + 0.8.7 pom diff --git a/rococoa-cocoa/pom.xml b/rococoa-cocoa/pom.xml index ae78378..83cbe6c 100644 --- a/rococoa-cocoa/pom.xml +++ b/rococoa-cocoa/pom.xml @@ -10,7 +10,7 @@ org.rococoa rococoa-parent - 0.8.6 + 0.8.7 Rococoa Cocoa Mappings diff --git a/rococoa-contrib/pom.xml b/rococoa-contrib/pom.xml index 54f75a3..5e7a2ba 100644 --- a/rococoa-contrib/pom.xml +++ b/rococoa-contrib/pom.xml @@ -10,7 +10,7 @@ org.rococoa rococoa-parent - 0.8.6 + 0.8.7 Rococoa Contrib diff --git a/rococoa-core/pom.xml b/rococoa-core/pom.xml index 6faa9e4..009c227 100644 --- a/rococoa-core/pom.xml +++ b/rococoa-core/pom.xml @@ -9,7 +9,7 @@ org.rococoa rococoa-parent - 0.8.6 + 0.8.7 Rococoa Core From e60bcc611ec4b48ec33c08947aea14e3ba6fb1ff Mon Sep 17 00:00:00 2001 From: Naohide Sano Date: Sun, 18 Feb 2024 09:56:00 +0900 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=A5=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rococoa-core/src/test/java/Test1.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rococoa-core/src/test/java/Test1.java b/rococoa-core/src/test/java/Test1.java index 9676449..bdac40d 100644 --- a/rococoa-core/src/test/java/Test1.java +++ b/rococoa-core/src/test/java/Test1.java @@ -20,6 +20,7 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable; import org.rococoa.cocoa.foundation.NSString; import vavi.util.Debug; @@ -51,7 +52,7 @@ void test1() throws Exception { } @Test -// @Disabled + @DisabledIfEnvironmentVariable(named = "GITHUB_WORKFLOW", matches = ".*") void test2() throws Exception { String jh = System.getProperty("java.home"); Debug.println("JAVA_HOME: " + jh);