Ignore:
Timestamp:
2014-11-29T16:30:52+01:00 (10 years ago)
Author:
donvip
Message:

[josm_native-password-manager] update Netbeans Keyring code + make plugin rely on JNA plugin

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/native-password-manager/src/org/netbeans/modules/keyring/gnome/GnomeKeyringLibrary.java

    r26335 r30822  
    4343package org.netbeans.modules.keyring.gnome;
    4444
     45import com.sun.jna.DefaultTypeMapper;
     46import com.sun.jna.FromNativeContext;
    4547import com.sun.jna.Library;
    4648import com.sun.jna.Native;
    4749import com.sun.jna.Pointer;
    4850import com.sun.jna.Structure;
     51import com.sun.jna.ToNativeContext;
     52import com.sun.jna.TypeConverter;
     53import java.io.File;
     54import java.util.Arrays;
     55import java.util.Collections;
     56import java.util.List;
     57import java.util.Map;
    4958
    5059/**
     
    5564public interface GnomeKeyringLibrary extends Library {
    5665
    57     GnomeKeyringLibrary LIBRARY = (GnomeKeyringLibrary) Native.loadLibrary("gnome-keyring", GnomeKeyringLibrary.class);
     66    class LibFinder {
     67        private static final String GENERIC = "gnome-keyring";
     68        // http://packages.ubuntu.com/search?suite=precise&arch=any&mode=exactfilename&searchon=contents&keywords=libgnome-keyring.so.0
     69        private static final String EXPLICIT_ONEIRIC = "/usr/lib/libgnome-keyring.so.0";
     70        private static Object load(Map<?,?> options) {
     71            try {
     72                return Native.loadLibrary(GENERIC, GnomeKeyringLibrary.class, options);
     73            } catch (UnsatisfiedLinkError x) {
     74                // #203735: on Oneiric, may have trouble finding right lib.
     75                // Precise is using multiarch (#211401) which should work automatically using JNA 3.4+ (#211403).
     76                // Unclear if this workaround is still needed for Oneiric with 3.4, but seems harmless to leave it in for now.
     77                if (new File(EXPLICIT_ONEIRIC).isFile()) {
     78                    return Native.loadLibrary(EXPLICIT_ONEIRIC, GnomeKeyringLibrary.class, options);
     79                } else {
     80                    throw x;
     81                }
     82            }
     83        }
     84        private LibFinder() {}
     85    }
     86
     87    GnomeKeyringLibrary LIBRARY = (GnomeKeyringLibrary) LibFinder.load(Collections.singletonMap(OPTION_TYPE_MAPPER, new DefaultTypeMapper() {
     88        {
     89            addTypeConverter(Boolean.TYPE, new TypeConverter() { // #198921
     90                @Override public Object toNative(Object value, ToNativeContext context) {
     91                    return Boolean.TRUE.equals(value) ? 1 : 0;
     92                }
     93                @Override public Object fromNative(Object value, FromNativeContext context) {
     94                    return ((Integer) value).intValue() != 0;
     95                }
     96                @Override public Class<?> nativeType() {
     97                    // gint is 32-bit int
     98                    return Integer.class;
     99                }
     100            });
     101        }
     102    }));
    58103
    59104    boolean gnome_keyring_is_available();
     
    98143        public /*GnomeKeyringAttributeList*/Pointer attributes;
    99144        public String secret;
     145
     146        @Override
     147        protected List<String> getFieldOrder() {
     148            return Arrays.asList( new String[] {
     149                "keyring",
     150                "item_id",
     151                "attributes",
     152                "secret",
     153            } );
     154        }
    100155    }
    101156
Note: See TracChangeset for help on using the changeset viewer.