@Override public void validate() throws JPValidationException { final File value = getValue(); if (value == null) { throw new JPValidationException(getClass().getSimpleName() + " is not defined but can be set manually with " + getDefaultExample(), getErrorReport()); } try { FileHandler.handle(value, type, existenceHandling, autoCreateMode); } catch (Exception ex) { throw new JPValidationException("Could not handle " + type.name() + "[" + value + "]!", ex); } }
@Override protected File parse(List<String> arguments) throws Exception { return new File(getOneArgumentResult()); }
@Override protected void setValue(File value, ValueType valueType) { // if file is already referred absolute than use it and ignore parent directory. if (value.isAbsolute()) { super.setValue(value, valueType); return; } try { File parent = getParentDirectory(); // if parent file is not defined just use the value directly if (parent == null) { super.setValue(value, valueType); return; } // build value with parent folder super.setValue(new File(parent, value.getPath()), valueType); } catch (JPServiceException ex) { // ignore value because parent seems to be invalid and value itself is not absolute! addErrorReport(new JPServiceException("Parent directory is not valid!", ex), valueType); } }
@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); } } });