Git Product home page Git Product logo

rococoa's Introduction

 Welcome to Rococoa

Rococoa is a generic Java binding to the Mac Objective-C object system. It allows the creation and use of Objective-C objects in Java, and the implementation of Objective-C interfaces in Java.

Java CI with Maven

Rococoa Acknowledgements

Rococoa owes much to the following people and organisations

  • JNA does all the heavy lifting of calling into Cocoa and marshaling parameters. Timothy Wall also added pass struct by value and other extension points to make our life simpler.
  • Paul Loy was the alpha guinea-pig.
  • Simon Taylor, Gareth Sylvester-Bradley and Dion Crannitch for Objective-C help.
  • Richard Care, Matt Bowers, Andy Collins and Morgan David let it go.
  • Apple Inc produced Quicktime, Java on Mac OS, the Cocoa-Java Bridge and Quicktime for Java, then killed at least 2 of them. If you know Java and Cocoa your name could be on this list! Get involved!. This project is now maintained by iterate GmbH.

Projects using Rococoa

Make sure you comply with the GNU Lesser General Public License when releasing an application that uses Rococoa.

  • Cyberduck - Libre file transfer client for macOS and Windows. Command line interface (CLI) for Linux, macOS and Windows.

Usage

Maven Artifacts (LGPL)

Maven artifacts are available in a repository hosted on Amazon S3.

  • Use the following Maven configuration in your project POM to reference artifacts from Cyberduck
<repositories>
   <repository>
       <id>maven.cyberduck.io-release</id>
       <url>http://repo.maven.cyberduck.io.s3.amazonaws.com/releases/</url>
       <layout>default</layout>
       <releases>
           <enabled>true</enabled>
       </releases>
       <snapshots>
           <enabled>false</enabled>
       </snapshots>
   </repository>
</repositories>
  • You will need to add the AWS Maven Wagon to your build using
<build>
    <extensions>
        <extension>
            <groupId>org.springframework.build</groupId>
            <artifactId>aws-maven</artifactId>
            <version>5.0.0.RELEASE</version>
        </extension>
    </extensions>
</build>
  • Add the dependencies as follows
<dependency>
    <groupId>org.rococoa</groupId>
    <artifactId>rococoa-core</artifactId>
    <version>0.9.1</version>
</dependency>
<dependency>
    <groupId>org.rococoa</groupId>
    <artifactId>librococoa</artifactId>
    <version>0.9.1</version>
    <type>dylib</type>
    <scope>runtime</scope>
</dependency>

Documentation

Change History

0.9.1

  • Support for Apple silicon

0.8.0

  • Rewrite implementation of cstringPtrForSelector to be failsave using CFStringGetMaximumSizeForEncoding

0.7.0

0.5.0

0.3.0

  • Functioning 64-bit (and hence Java 6) support thanks to Paul Loy for fixes and discussions, and Andy Thompson for NSInteger et al
  • We should now correctly l small structs as return values, not just NSSize!
  • Improved NSDictionary
  • Support for JNA-3.0.4

0.2.0

  • Much more rigorous memory management.
  • Selectors are now cached on the Java side.
  • Fixed problem #9 where we could only have one delegate or notification thanks to Adrian Ross for diagnosis and fix.
  • Much expanded set of parameter and return types for delegates and notifications thanks to Andy Thompson for suggestions and help.
  • Fix defect #10 where delegates and notifications failed after the autorelease pool is released. Now use Rococoa.proxy rather than wrap.
  • Now use JNA-3.0.3 (NB slightly patched, please make sure that Rococoa precedes JNA in the classpath

0.1.4

  • Reworked CFString handling to use UTF-8 and hence support extended characters.
  • Now support delegates and notifications, using Rococoa.wrap(Object)

0.1.3

  • Now ship a Universal Binary dylib

0.1.2

  • Added LGPL licence files and these release notes.

0.1.1

  • Changes to allow the checked-out code to build.

0.1.0

  • First published to dev.java.net.

rococoa's People

Contributors

dependabot[bot] avatar dkocher avatar googlecodeexporter avatar jlmuir avatar umjammer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rococoa's Issues

No mapping for callbacks with parameters as reference

A NSMenu delegate implementing 

menuHasKeyEquivalent_forEvent_target_action(NSMenu menu, NSEvent event, ID 
target, Selector action);

is not possible. There is no specific mapping in NSInvocationMapperLookup for 
the selector argument. This is mapped to NativeLong instead.


Original issue reported on code.google.com by [email protected] on 1 Oct 2010 at 3:05

Maven central

Hello,

First, thank you about the amazing work on this library.
Do you have any plan to publish it to maven central ? Do you need help to do it ?

JNA direct mapping

One should look into possible performance benefits of using JNA direct
mapping if possible at all.

Original issue reported on code.google.com by [email protected] on 6 Oct 2009 at 9:56

Getting error while capturing screenshot of specific window.

I want to capture screenshot of specific application on Mac. I find a piece of code on net and used it and got this error.

2022-06-01 13:11:27.327 java[38630:745393] *** Assertion failure in -[NSBitmapImageRep initWithCGImage:],NSBitmapImageRep.m:1254
2022-06-01 13:11:27.327 java[38630:745393] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: cgImage != NULL'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007fff20494beb __exceptionPreprocess + 242
    1   libobjc.A.dylib                     0x00007fff201cdd92 objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff204bdd82 +[NSException raise:format:arguments:] + 88
    3   Foundation                          0x00007fff2127d4e2 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191
    4   AppKit                              0x00007fff22ec04df -[NSBitmapImageRep initWithCGImage:] + 214
    5   jna1422728435769209689.tmp          0x0000000124a95fda ffi_prep_go_closure + 1370
    6   ???                                 0x00007000010f5188 0x0 + 123145320092040
)
libc++abi: terminating with uncaught exception of type NSException

This is the method.

private BufferedImage getWindowImage(int windowId) {

    CoreGraphicsLibrary.CGRect bounds = new CoreGraphicsLibrary.CGRect.CGRectByValue();
    bounds.origin = new CoreGraphicsLibrary.CGPoint();
    bounds.origin.x = 0;
    bounds.origin.y = 0;
    bounds.size = new CoreGraphicsLibrary.CGSize();
    bounds.size.width = 0;
    bounds.size.height = 0;
    ID imageRef = CoreGraphicsLibrary.INSTANCE.CGWindowListCreateImage(bounds, CoreGraphicsLibrary.kCGWindowListOptionIncludingWindow | CoreGraphicsLibrary.kCGWindowListExcludeDesktopElements, windowId, CoreGraphicsLibrary.kCGWindowImageBoundsIgnoreFraming | CoreGraphicsLibrary.kCGWindowImageNominalResolution);

    NSBitmapImageRep imageRep = NSBitmapImageRep.CLASS.alloc().initWithCGImage(imageRef);
    imageRep.retain();

    int width = imageRep.pixelsWide();
    int height = imageRep.pixelsHigh();

    int windowTitleHeight = determineWindowTitleHeight(height, width);

    int heightWithoutTitle = height - windowTitleHeight;

    Pointer bitmapPointer = imageRep.bitmapData();
    if (bitmapPointer == null || bitmapPointer == Pointer.NULL) {
        imageRep.release();
        return null;



    } else {
        int[] data = bitmapPointer.getIntArray(0, width * height);

        if (heightWithoutTitle > 512) {
            BufferedImage image = new BufferedImage(width, heightWithoutTitle, BufferedImage.TYPE_INT_RGB);

            // Start on row windowTitleHeight to exclude the window titlebar
            int idx = windowTitleHeight * width;

            // Manually write each pixel to the raster because OS X generates ARGB screenshots but BufferedImage expects RGB data.
            WritableRaster raster = image.getRaster();
            for (int y = 0; y < heightWithoutTitle; y++) {

                for (int x = 0; x < width; x++) {
                    int pixel = data[idx++];
                    raster.setSample(x, y, 0, pixel >> 8 & 0xFF);   // Red is the second byte
                    raster.setSample(x, y, 1, pixel >> 16 & 0xFF);  // Green is the third byte
                    raster.setSample(x, y, 2, pixel >> 24 & 0xFF);  // Blue is the fourth byte
                }
            }

            // Now that we have a copy of the image in a Java object it's safe to release the native pointers
            Foundation.cfRelease(imageRef);
            imageRep.release();

            return image;

        } else {
            // The window is too small to generate an image
            return null;
        }
    }

}

Missing usage of objc_msgSend_fpret

https://developer.apple.com/documentation/objectivec/1456697-objc_msgsend_fpret

On the i386 platform, the ABI for functions returning a floating-point value is incompatible with that for functions returning an integral type. On the i386 platform, therefore, you must use objc_msgSend_fpret for functions that for functions returning non-integral type. For float or long double return types, cast the function to an appropriate function pointer type first. This function is not used on the PPC or PPC64 platforms.

Load librococoa.dylib from JAR file - no java.library.path change required

In theory, you should be able to load the dylib file from the rococoa jar file. 
This means that library users will not have to change java.library.path. The 
code that should allow this to happen is shown below. Note that it uses 
commons-io but another I/O mechanism could be used.

    private static void loadLibrary() {
        try {
            // have to use a stream
            InputStream in = RococoaManager.class.getResourceAsStream("/lib/librococoa.dylib");
            // always write to different location
            File fileOut = File.createTempFile("lib", ".dylib");
            OutputStream out = FileUtils.openOutputStream(fileOut);
            IOUtils.copy(in, out);
            in.close();
            out.close();
            System.load(fileOut.toString());
        } catch (Exception e) {
            throw new RuntimeException("Failed to load rococoa native library", e);
        }
    }

Original issue reported on code.google.com by [email protected] on 17 Mar 2013 at 11:06

Exception Handling

Java has exceptions, Cocoa has exceptions. We should make them meet in the
middle through Rococoa magic.

Original issue reported on code.google.com by [email protected] on 6 Oct 2009 at 10:04

Obj-C GC capable

We might want to support running Rococoa in a automatic memory management
environment with garbage collection turned on in the Obj-C runtime. Some
work has already been done by using CFRetain/CFRelease instead of `NSObject
retain/release` but this remains completly untested.

Original issue reported on code.google.com by [email protected] on 6 Oct 2009 at 1:18

"NSXXX(0x128307fa0) - NSView not correctly initialized. Did you forget to call super?"

When instantiating NSView subclasses using initWithFrame: in Rococoa, there
is a
warning logged that says e.g. for NSButton: "NSButton(0x128307fa0) - NSView not
correctly initialized. Did you forget to call super?". It is only of cosmetical
importance as it seems. Nevertheless, for future reference I post here
references to RubyCocoa that had the same issue.

http://github.com/timburks/nu/blob/master/notes/HACKS?raw=true
http://sourceforge.net/tracker/index.php?func=detail&aid=1215220&group_id=44114&
atid=438476

Don't know if a similar hack could be applied to Rococoa.

Original issue reported on code.google.com by [email protected] on 6 Oct 2009 at 10:04

Current snapshot in SVN does not build with maven

Hi,

The code currently in SVN does not build for me due to missing dependencies. 
I've fixed it by updating the pom.xml files to use the latest version of 
jnaerator (0.9.5 snapshot) and added http://nativelibs4java.sourceforge.net as 
a repository source - see attached patch file.

I also added two removeObserver() methods to NSNotificationCenter.


Cheers,

- Dave L

Original issue reported on code.google.com by [email protected] on 11 Aug 2010 at 8:39

Attachments:

Autorelease pool allocation in callOnMainThread

It should be decided wether it is Rococoa or the responsibility of the
caller wheter an autorelease pool neeeds to be created when calling
`callOnMainThread`. Currently a pool is created by Rococoa but this may be
redundant if the caller has already created one of its own before invoking
`Foundation.runOnMainThread`.

This is in
[http://code.google.com/p/rococoa/source/browse/trunk/rococoa/rococoa-core/src/m
ain/native/Rococoa.m#8
Rococoa.m].


Original issue reported on code.google.com by [email protected] on 7 Oct 2009 at 12:37

Struct test failures with JNA 3.2.4

The testSendAndReceiveStructByReference and testSendAndReceiveStructByValue 
test methods in 
JavaProxyTest fail with JNA 3.2.4. The return value is always 0.

Original issue reported on code.google.com by [email protected] on 28 Nov 2009 at 7:55

JNA: could not detach thread

First of all thank you so much for your amazing work on Rococoa, it's a life saver!

I'm writing a new app using rococoa, everything looks fine except that I get lots of this message on the console output:

JNA: could not detach thread

I'm trying to figure out if this is just a warning or something I should worry about. There isn't much to be found about this message in Google. Some folks say it can be ignored. Another thing I'm trying to understand is whether I'm doing something wrong that triggers that message or if it's something that can only be remedied in Rococoa. Do you have any thoughts?

explain where to get xcodebuild from in README.md

mvn install fails with [ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.7:run (build-native) on project rococoa-core: An Ant BuildException has occured: Execute failed: java.io.IOException: Cannot run program "xcodebuild" (in directory "/mnt/richtercloud/sources/rococoa/rococoa/rococoa-core"): error=2, Datei oder Verzeichnis nicht gefunden [ERROR] around Ant part ...<exec dir="." executable="xcodebuild" failonerror="true">... @ 4:60 in /mnt/richtercloud/sources/rococoa/rococoa/rococoa-core/target/antrun/build-main.xml

NSObject should be an abstract class

As per the discussion on the dev mailing list, NSObject and all it's
'concrete' subclasses should be abstract classes. This allows Protocols to
be implemented as interfaces.

We need this before we can create mappings from the BridgeSupport files.

Original issue reported on code.google.com by [email protected] on 18 Oct 2009 at 10:16

  • Blocking: #4

Test failures in QTMovieTest

What steps will reproduce the problem?
1. check out from svn
2. cd into rococoa-core and *mvn install*
3. cd into rococoa-cocoa
4. ensure there is no librococoa.dylib in there
5. *mvn test*

What is the expected output? What do you see instead?

I expected it to succeed but got the following:

Macintosh:rococoa-cocoa paulloy$ mvn test
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Rococoa Cocoa Mappings
[INFO]    task-segment: [test]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources]
[INFO] Using encoding: 'UTF-8' to copy filtered resources.
[INFO] [compiler:compile]
[INFO] Nothing to compile - all classes are up to date
[INFO] [dependency:copy {execution: copy}]
[INFO] Configured Artifact: org.rococoa:rococoa-core:0.5:dylib
[INFO] Copying rococoa-core-0.5.dylib to
/Users/paulloy/Documents/workspace-gc/rococoa/rococoa/rococoa-cocoa/librococoa.d
ylib
[INFO] [resources:testResources]
[INFO] Using encoding: 'UTF-8' to copy filtered resources.
[INFO] [compiler:testCompile]
[INFO] Nothing to compile - all classes are up to date
[INFO] [surefire:test]
[INFO] Surefire report directory:
/Users/paulloy/Documents/workspace-gc/rococoa/rococoa/rococoa-cocoa/target/suref
ire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running org.rococoa.cocoa.qtkit.QTMovieTest
main    RococoaTestCase.logVersions - Running with JAVA_HOME = null,
java.version = 1.6.0_15, sizeof(Pointer) = 8
main    Foundation.<clinit> - Initializing Foundation
main    Foundation.<clinit> - exit initializing Foundation
main    Rococoa.create - creating [NSAutoreleasePool
(org.rococoa.cocoa.foundation.NSAutoreleasePool)].new()
main    Foundation.getClass - calling objc_getClass(NSAutoreleasePool)
main    Foundation.send - sending (ID) [ID 0x7fff7104c498].new()
main    NSObjectInvocationHandler.<init> - Creating NSObjectInvocationHandler
for id [ID 0x10140ebc0], javaclass class
org.rococoa.cocoa.foundation.NSAutoreleasePool. retain = false, retainCount = 1
main    Foundation.getClass - calling objc_getClass(NSObject)
main    NSObjectInvocationHandler.<init> - Creating NSObjectInvocationHandler
for id [ID 0x7fff705da4a8], javaclass interface
org.rococoa.NSObject$_Class. retain = false, retainCount = -1
main    Foundation.getClass - calling objc_getClass(NSThread)
Thread- Foundation.getClass - calling objc_getClass(QTMovie)
Thread- NSObjectInvocationHandler.<init> - Creating
NSObjectInvocationHandler for id [ID 0x7fff70ec2928], javaclass interface
org.rococoa.cocoa.qtkit.QTMovie$_Class. retain = true, retainCount = -1
Thread- Foundation.send - sending (boolean) [ID 0x7fff710524d8].isMainThread()
Thread- Foundation.cfRetain - calling cfRetain([ID 0x7fff70ec2928])
Thread- Foundation.getClass - calling objc_getClass(NSDictionary)
Thread- NSObjectInvocationHandler.<init> - Creating
NSObjectInvocationHandler for id [ID 0x7fff705da048], javaclass interface
org.rococoa.cocoa.foundation.NSDictionary$_Class. retain = false,
retainCount = -1
Thread- Foundation.getClass - calling objc_getClass(NSArray)
Thread- NSObjectInvocationHandler.<init> - Creating
NSObjectInvocationHandler for id [ID 0x7fff705d9d28], javaclass interface
org.rococoa.cocoa.foundation.NSArray$_Class. retain = false, retainCount = -1
main    NSObjectInvocationHandler.invoke - invoking [_Class [ID
0x7fff70ec2928]].movieWithFile_error(/Users/paulloy/Documents/workspace-gc/rococ
oa/rococoa/rococoa-cocoa/NOSUCH,
org.rococoa.NSObjectByReference@11be51)
main    Foundation.send - sending (boolean) [ID 0x7fff710524d8].isMainThread()
Thread- Foundation.send - sending (QTMovie) [ID
0x7fff70ec2928].movieWithFile:error:(/Users/paulloy/Documents/workspace-gc/rococ
oa/rococoa/rococoa-cocoa/NOSUCH,
org.rococoa.IDByReference@1014b1)
Thread- Foundation.send - sending (ID) [ID 0x1001155d0].autorelease()
Invalid memory access of location 0x0 rip=0x7fff87cc0340

/bin/sh: line 1:  5930 Segmentation fault     
/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home/bin/java
-jar
/var/folders/sZ/sZS0ADi2HlOY-6BxwCXt4k+++TI/-Tmp-/surefirebooter2639509870858234
768.jar
/var/folders/sZ/sZS0ADi2HlOY-6BxwCXt4k+++TI/-Tmp-/surefire3501010980469964977tmp
/var/folders/sZ/sZS0ADi2HlOY-6BxwCXt4k+++TI/-Tmp-/surefire4648069105603304709tmp
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] There are test failures.

Please refer to
/Users/paulloy/Documents/workspace-gc/rococoa/rococoa/rococoa-cocoa/target/suref
ire-reports
for the individual test results.
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7 seconds
[INFO] Finished at: Mon Oct 05 23:54:51 BST 2009
[INFO] Final Memory: 26M/80M
[INFO] ------------------------------------------------------------------------

*Java version*:

java version "1.6.0_15"
Java(TM) SE Runtime Environment (build 1.6.0_15-b03-219)
Java HotSpot(TM) 64-Bit Server VM (build 14.1-b02-90, mixed mode)

*OSX*: snow leopard

Original issue reported on code.google.com by [email protected] on 5 Oct 2009 at 10:59

Copyright notice not on all source files

Anyone can help by putting the following copyright/licence notice on source
files without the notice:

/*
 * Copyright 2007, 2008, 2009 Duncan McGregor
 * 
 * This file is part of Rococoa, a library to allow Java to talk to Cocoa.
 * 
 * Rococoa is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Rococoa is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with Rococoa.  If not, see <http://www.gnu.org/licenses/>.
 */

Original issue reported on code.google.com by [email protected] on 18 Oct 2009 at 10:58

mappings should not exist in rococoa-core

org.rococoa.cocoa package should be removed from rococoa-core. Any mappings
needed for tests should be inner classes in those tests.

All mappings will be generated by the jnaerator / rococoa-bridge-support
projects and will exist in rococoa-cocoa.

Original issue reported on code.google.com by [email protected] on 23 Oct 2009 at 11:49

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.