diff --git a/java/src/org/broadinstitute/sting/jna/clibrary/LibC.java b/java/src/org/broadinstitute/sting/jna/clibrary/LibC.java new file mode 100644 index 000000000..17a15cd94 --- /dev/null +++ b/java/src/org/broadinstitute/sting/jna/clibrary/LibC.java @@ -0,0 +1,179 @@ +/* + * Copyright (c) 2010, The Broad Institute + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +package org.broadinstitute.sting.jna.clibrary; + +import com.sun.jna.*; + +/** + * Sparse port of the Standard C Library libc -lc. + */ +@SuppressWarnings("unused") +public class LibC { + + static { + Native.register("c"); + } + + /** Operation not permitted */ + public static final int EPERM = 1; + + /** No such file or directory */ + public static final int ENOENT = 2; + + /** No such process */ + public static final int ESRCH = 3; + + /** Interrupted system call */ + public static final int EINTR = 4; + + /** I/O error */ + public static final int EIO = 5; + + /** No such device or address */ + public static final int ENXIO = 6; + + /** Argument list too long */ + public static final int E2BIG = 7; + + /** Exec format error */ + public static final int ENOEXEC = 8; + + /** Bad file number */ + public static final int EBADF = 9; + + /** No child processes */ + public static final int ECHILD = 10; + + /** Try again */ + public static final int EAGAIN = 11; + + /** Out of memory */ + public static final int ENOMEM = 12; + + /** Permission denied */ + public static final int EACCES = 13; + + /** Bad address */ + public static final int EFAULT = 14; + + /** Block device required */ + public static final int ENOTBLK = 15; + + /** Device or resource busy */ + public static final int EBUSY = 16; + + /** File exists */ + public static final int EEXIST = 17; + + /** Cross-device link */ + public static final int EXDEV = 18; + + /** No such device */ + public static final int ENODEV = 19; + + /** Not a directory */ + public static final int ENOTDIR = 20; + + /** Is a directory */ + public static final int EISDIR = 21; + + /** Invalid argument */ + public static final int EINVAL = 22; + + /** File table overflow */ + public static final int ENFILE = 23; + + /** Too many open files */ + public static final int EMFILE = 24; + + /** Not a typewriter */ + public static final int ENOTTY = 25; + + /** Text file busy */ + public static final int ETXTBSY = 26; + + /** File too large */ + public static final int EFBIG = 27; + + /** No space left on device */ + public static final int ENOSPC = 28; + + /** Illegal seek */ + public static final int ESPIPE = 29; + + /** Read-only file system */ + public static final int EROFS = 30; + + /** Too many links */ + public static final int EMLINK = 31; + + /** Broken pipe */ + public static final int EPIPE = 32; + + /** Math argument out of domain of func */ + public static final int EDOM = 33; + + /** Math result not representable */ + public static final int ERANGE = 34; + + /** + * Inserts or resets the environment variable name in the current environment list. If the variable name does not exist + * in the list, it is inserted with the given value. If the variable does exist, the argument overwrite is tested; if overwrite is zero, the + * variable is not reset, otherwise it is reset to the given value. + * @param name the environment variable name + * @param value the given value + * @param overwrite if overwrite is zero, the variable is not reset, otherwise it is reset to the given value + * @return the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indicate the error. + * @throws LastErrorException [ENOMEM] The function failed because it was unable to allocate memory for the environment. + */ + public static native int setenv(String name, String value, int overwrite) throws LastErrorException; + + /** + * Obtains the current value of the environment variable, name. + * @param name the environment variable name + * @return the value of the environment variable as a NUL-terminated string. If the variable name is not in the current environment, NULL is returned. + */ + public static native String getenv(String name); + + /** + * The unsetenv() function deletes all instances of the variable name pointed to by name from the list. Note that only the variable name + * (e.g., "NAME") should be given; "NAME=value" will not work. + * @param name the environment variable name + * @return the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indicate the error. + * @throws LastErrorException The function failed. + */ + public static native int unsetenv(String name) throws LastErrorException; + + public static class timeval extends Structure { + public static class ByReference extends timeval implements Structure.ByReference { + } + + public static class ByValue extends timeval implements Structure.ByValue { + } + + public NativeLong tv_sec; + public NativeLong tv_usec; + } +} diff --git a/java/src/org/broadinstitute/sting/jna/clibrary/Time.java b/java/src/org/broadinstitute/sting/jna/clibrary/Time.java deleted file mode 100644 index 004a960a3..000000000 --- a/java/src/org/broadinstitute/sting/jna/clibrary/Time.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2010, The Broad Institute - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - -package org.broadinstitute.sting.jna.clibrary; - -import com.sun.jna.NativeLong; -import com.sun.jna.Structure; - -/** - * Sparse JNA port of time.h - */ -@SuppressWarnings("unused") -public class Time { - public static class timeval extends Structure { - public static class ByReference extends timeval implements Structure.ByReference { - } - - public static class ByValue extends timeval implements Structure.ByValue { - } - - public NativeLong tv_sec; - public NativeLong tv_usec; - } -} diff --git a/java/src/org/broadinstitute/sting/jna/lsf/v7_0_6/LibBat.java b/java/src/org/broadinstitute/sting/jna/lsf/v7_0_6/LibBat.java index 1c1f66260..63aa35aa1 100644 --- a/java/src/org/broadinstitute/sting/jna/lsf/v7_0_6/LibBat.java +++ b/java/src/org/broadinstitute/sting/jna/lsf/v7_0_6/LibBat.java @@ -27,6 +27,7 @@ package org.broadinstitute.sting.jna.lsf.v7_0_6; import com.sun.jna.*; import com.sun.jna.ptr.*; import org.broadinstitute.sting.jna.clibrary.JNAUtils; +import org.broadinstitute.sting.jna.clibrary.LibC; /** * JNA wrappers for LSF's lsbatch.h and -lbat @@ -59,6 +60,9 @@ public class LibBat { NativeLibrary.addSearchPath("bat", lsfLibDir); } NativeLibrary.getInstance("lsf"); + // via Platform LSF Configuration Reference, by default quiet the BSUB output. + if ("Y".equals(System.getProperty("BSUB_QUIET", "Y"))) + LibC.setenv("BSUB_QUIET", "Y", 1); Native.register("bat"); } diff --git a/java/src/org/broadinstitute/sting/jna/lsf/v7_0_6/LibLsf.java b/java/src/org/broadinstitute/sting/jna/lsf/v7_0_6/LibLsf.java index 8b1f30ed8..78148c6af 100644 --- a/java/src/org/broadinstitute/sting/jna/lsf/v7_0_6/LibLsf.java +++ b/java/src/org/broadinstitute/sting/jna/lsf/v7_0_6/LibLsf.java @@ -29,7 +29,7 @@ import com.sun.jna.ptr.FloatByReference; import com.sun.jna.ptr.IntByReference; import com.sun.jna.ptr.PointerByReference; import org.broadinstitute.sting.jna.clibrary.JNAUtils; -import org.broadinstitute.sting.jna.clibrary.Time.*; +import org.broadinstitute.sting.jna.clibrary.LibC.*; /** * JNA wrappers for LSF's lsf.h and -llsf diff --git a/java/test/org/broadinstitute/sting/jna/clibrary/JNAUtilsUnitTest.java b/java/test/org/broadinstitute/sting/jna/clibrary/LibCUnitTest.java similarity index 72% rename from java/test/org/broadinstitute/sting/jna/clibrary/JNAUtilsUnitTest.java rename to java/test/org/broadinstitute/sting/jna/clibrary/LibCUnitTest.java index 694a411fa..1d88dd6af 100644 --- a/java/test/org/broadinstitute/sting/jna/clibrary/JNAUtilsUnitTest.java +++ b/java/test/org/broadinstitute/sting/jna/clibrary/LibCUnitTest.java @@ -24,22 +24,20 @@ package org.broadinstitute.sting.jna.clibrary; -import com.sun.jna.Library; -import com.sun.jna.Native; import org.broadinstitute.sting.BaseTest; import org.testng.Assert; import org.testng.annotations.Test; -public class JNAUtilsUnitTest extends BaseTest { - - public interface CLib extends Library { - public CLib INSTANCE = (CLib) Native.loadLibrary("c", CLib.class); - public int atol(String str); - } +public class LibCUnitTest extends BaseTest { @Test - public void testCLibJna() { - int result = CLib.INSTANCE.atol("10"); - Assert.assertEquals(result, 10); + public void testEnvironment() { + String testProperty = "test_property"; + String testValue = "value"; + Assert.assertEquals(LibC.getenv(testProperty), null); + Assert.assertEquals(LibC.setenv(testProperty, testValue, 1), 0); + Assert.assertEquals(LibC.getenv(testProperty), testValue); + Assert.assertEquals(LibC.unsetenv(testProperty), 0); + Assert.assertEquals(LibC.getenv(testProperty), null); } }