Changeset 30822 in osm for applications/editors/josm/plugins/native-password-manager/src/org/netbeans/modules/keyring/gnome/GnomeKeyringLibrary.java
- Timestamp:
- 2014-11-29T16:30:52+01:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/native-password-manager/src/org/netbeans/modules/keyring/gnome/GnomeKeyringLibrary.java
r26335 r30822 43 43 package org.netbeans.modules.keyring.gnome; 44 44 45 import com.sun.jna.DefaultTypeMapper; 46 import com.sun.jna.FromNativeContext; 45 47 import com.sun.jna.Library; 46 48 import com.sun.jna.Native; 47 49 import com.sun.jna.Pointer; 48 50 import com.sun.jna.Structure; 51 import com.sun.jna.ToNativeContext; 52 import com.sun.jna.TypeConverter; 53 import java.io.File; 54 import java.util.Arrays; 55 import java.util.Collections; 56 import java.util.List; 57 import java.util.Map; 49 58 50 59 /** … … 55 64 public interface GnomeKeyringLibrary extends Library { 56 65 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 })); 58 103 59 104 boolean gnome_keyring_is_available(); … … 98 143 public /*GnomeKeyringAttributeList*/Pointer attributes; 99 144 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 } 100 155 } 101 156
Note:
See TracChangeset
for help on using the changeset viewer.