From 2d1ea7124b576764137cad7ca3f458a71a8fd69b Mon Sep 17 00:00:00 2001 From: Khalid Shakir Date: Mon, 27 Aug 2012 12:04:50 -0400 Subject: [PATCH] One less Queue command line requirement: -tempDir now defaults to .queue/tmp. Also moved queueScatterGather to .queue/scatterGather. --- .../broadinstitute/sting/utils/io/IOUtils.java | 17 +++++++++++++---- .../sting/queue/QCommandLine.scala | 8 +++++--- .../ScatterGatherableFunction.scala | 2 +- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/public/java/src/org/broadinstitute/sting/utils/io/IOUtils.java b/public/java/src/org/broadinstitute/sting/utils/io/IOUtils.java index 160df0e51..b79211e74 100644 --- a/public/java/src/org/broadinstitute/sting/utils/io/IOUtils.java +++ b/public/java/src/org/broadinstitute/sting/utils/io/IOUtils.java @@ -48,14 +48,23 @@ public class IOUtils { * @param tempDir Temporary directory. */ public static void checkTempDir(File tempDir) { + if (isDefaultTempDir(tempDir)) + throw new UserException.BadTmpDir("java.io.tmpdir must be explicitly set"); + if (!tempDir.exists() && !tempDir.mkdirs()) + throw new UserException.BadTmpDir("Could not create directory: " + tempDir.getAbsolutePath()); + } + + /** + * Returns true if the directory is a default temporary directory. + * @param tempDir the directory to check. + * @return true if the directory is a default temporary directory. + */ + public static boolean isDefaultTempDir(File tempDir) { String tempDirPath = tempDir.getAbsolutePath(); // Keeps the user from leaving the temp directory as the default, and on Macs from having pluses // in the path which can cause problems with the Google Reflections library. // see also: http://benjchristensen.com/2009/09/22/mac-osx-10-6-java-java-io-tmpdir/ - if (tempDirPath.startsWith("/var/folders/") || (tempDirPath.equals("/tmp")) || (tempDirPath.equals("/tmp/"))) - throw new UserException.BadTmpDir("java.io.tmpdir must be explicitly set"); - if (!tempDir.exists() && !tempDir.mkdirs()) - throw new UserException.BadTmpDir("Could not create directory: " + tempDir.getAbsolutePath()); + return (tempDirPath.startsWith("/var/folders/") || (tempDirPath.equals("/tmp")) || (tempDirPath.equals("/tmp/"))); } /** diff --git a/public/scala/src/org/broadinstitute/sting/queue/QCommandLine.scala b/public/scala/src/org/broadinstitute/sting/queue/QCommandLine.scala index 775847ba9..0d0fab9d1 100644 --- a/public/scala/src/org/broadinstitute/sting/queue/QCommandLine.scala +++ b/public/scala/src/org/broadinstitute/sting/queue/QCommandLine.scala @@ -64,10 +64,10 @@ object QCommandLine extends Logging { Runtime.getRuntime.removeShutdownHook(shutdownHook) qCommandLine.shutdown() } catch { - case _ => /* ignore, example 'java.lang.IllegalStateException: Shutdown in progress' */ + case e: Exception => /* ignore, example 'java.lang.IllegalStateException: Shutdown in progress' */ } if (CommandLineProgram.result != 0) - System.exit(CommandLineProgram.result); + System.exit(CommandLineProgram.result) } catch { case e: Exception => CommandLineProgram.exitSystemWithError(e) } @@ -105,9 +105,11 @@ class QCommandLine extends CommandLineProgram with Logging { def execute = { if (settings.qSettings.runName == null) settings.qSettings.runName = FilenameUtils.removeExtension(scripts.head.getName) + if (IOUtils.isDefaultTempDir(settings.qSettings.tempDirectory)) + settings.qSettings.tempDirectory = IOUtils.absolute(settings.qSettings.runDirectory, ".queue/tmp") qGraph.initializeWithSettings(settings) - val allQScripts = pluginManager.createAllTypes(); + val allQScripts = pluginManager.createAllTypes() for (script <- allQScripts) { logger.info("Scripting " + pluginManager.getName(script.getClass.asSubclass(classOf[QScript]))) loadArgumentsIntoObject(script) diff --git a/public/scala/src/org/broadinstitute/sting/queue/function/scattergather/ScatterGatherableFunction.scala b/public/scala/src/org/broadinstitute/sting/queue/function/scattergather/ScatterGatherableFunction.scala index 4578f0e82..5dd7d4c79 100644 --- a/public/scala/src/org/broadinstitute/sting/queue/function/scattergather/ScatterGatherableFunction.scala +++ b/public/scala/src/org/broadinstitute/sting/queue/function/scattergather/ScatterGatherableFunction.scala @@ -91,7 +91,7 @@ trait ScatterGatherableFunction extends CommandLineFunction { if (qSettings.jobScatterGatherDirectory != null) { this.scatterGatherDirectory = IOUtils.absolute(qSettings.jobScatterGatherDirectory) } else { - this.scatterGatherDirectory = IOUtils.absolute(this.commandDirectory, "queueScatterGather") + this.scatterGatherDirectory = IOUtils.absolute(this.commandDirectory, ".queue/scatterGather") } } }