@Override protected File getPropertyDefaultValue() { File tmpFolder; if (JPService.testMode()) { tmpFolder = new File(SYSTEM_TMP_DIRECTORY + File.separatorChar + TEST_DIRECTORY + File.separatorChar + convertIntoValidFileName(JPService.getApplicationName()) + File.separatorChar + convertIntoValidFileName(System.getProperty("user.name", "mrpink"))); } else { tmpFolder = new File(SYSTEM_TMP_DIRECTORY + File.separatorChar + convertIntoValidFileName(JPService.getApplicationName()) + File.separatorChar + convertIntoValidFileName(System.getProperty("user.name", "mrpink"))); } try { FileUtils.forceMkdir(tmpFolder); tmpDefaultDirectory = tmpFolder; return tmpFolder; } catch (IOException ex) { JPService.printError("Could not create tmp folder :(", ex); tmpDefaultDirectory = tmpFolder; return new File("/tmp"); } }
private void deleteDirectoryIfEmpty(final File file) { if (!file.isDirectory()) { return; } for (File child : file.listFiles()) { deleteDirectoryIfEmpty(child); } if (file.listFiles().length == 0) { FileUtils.deleteQuietly(file); } }
@Override public void validate() throws JPValidationException { if (JPService.testMode()) { setAutoCreateMode(FileHandler.AutoMode.On); setExistenceHandling(FileHandler.ExistenceHandling.Must); } super.validate(); }
@Override public void run() { try { // just exit if not yet available if(getValue() == null) { return; } // cleanup tmp folder if (getValue().exists()) { FileUtils.deleteQuietly(getValue()); } // cleanup parent folder if structure is known if (getValue().getAbsolutePath().equals(tmpDefaultDirectory.getAbsolutePath())) { if (JPService.testMode()) { deleteDirectoryIfEmpty(new File(SYSTEM_TMP_DIRECTORY + File.separatorChar + TEST_DIRECTORY + File.separatorChar + convertIntoValidFileName(JPService.getApplicationName()))); deleteDirectoryIfEmpty(new File(SYSTEM_TMP_DIRECTORY + File.separatorChar + TEST_DIRECTORY)); } else { deleteDirectoryIfEmpty(new File(SYSTEM_TMP_DIRECTORY + File.separatorChar + convertIntoValidFileName(JPService.getApplicationName()))); } } } catch (IllegalArgumentException ex) { JPService.printError("Could not delete tmp directory!", ex); } } });
@Override protected File getPropertyDefaultValue() { // use tmp folder in test case if (JPService.testMode()) { try { return JPService.getProperty(JPTmpDirectory.class).getValue(); } catch (JPNotAvailableException ex) { // exception is already printed in constructore so no further forwarding needed. new FatalImplementationErrorException("Could not link test tmp directory as bco home path for java tests.", this, ex); } } // use bco home system variable if defined String systemDefinedHome = System.getenv(SYSTEM_VARIABLE_BCO_HOME); if (systemDefinedHome != null) { return new File(systemDefinedHome); } return new File(DEFAULT_PATH); }
@Override protected File getPropertyDefaultValue() throws JPNotAvailableException { if (JPService.testMode()) { return JPService.getProperty(JPTmpDirectory.class).getValue(); } // load prefix via system variable String globalPrefix = System.getenv("prefix"); if (globalPrefix != null) { return new File(globalPrefix); } // load prefix via system variable globalPrefix = System.getenv("PREFIX"); if (globalPrefix != null) { return new File(globalPrefix); } // use global usr folder as prefix return JPService.getProperty(JPUsrDirectory.class).getValue(); }