List of usage examples for org.apache.commons.io ExtendedFileUtils toString
public static final String toString(File f)
null
-safe way to retrieve a String representation of a File instance. From source file:net.community.chest.gitcloud.facade.ConfigUtils.java
/** * Checks that a give property value that represents a folder is valid as follows:</BR> * <UL>//from w w w .jav a2 s . c o m * <LI>If exists, then it must be a folder with read/write/execute permissions</LI> * <LI>Otherwise, it is created along with its parents</LI> * <UL> * @param propName The property name (used for meaningful exception message) * @param propValue The {@link File} to verify * @return <code>false</code> if this is an already existing folder, <code>true</code> * if had to create it (and its parents) * @throws IllegalStateException if any of the validation tests fails * @see File#mkdirs() */ public static final boolean verifyFolderProperty(String propName, File propValue) throws IllegalStateException { if (propValue.exists()) { if (!propValue.isDirectory()) { throw new IllegalStateException("verifyFolderProperty(" + propName + ") not a folder: " + ExtendedFileUtils.toString(propValue)); } if (!propValue.canRead()) { throw new IllegalStateException("verifyFolderProperty(" + propName + ") non-readable: " + ExtendedFileUtils.toString(propValue)); } if (!propValue.canWrite()) { throw new IllegalStateException("verifyFolderProperty(" + propName + ") non-writeable: " + ExtendedFileUtils.toString(propValue)); } if (!propValue.canExecute()) { throw new IllegalStateException("verifyFolderProperty(" + propName + ") non-listable: " + ExtendedFileUtils.toString(propValue)); } return false; } else { if (!propValue.mkdirs()) { throw new IllegalStateException("verifyFolderProperty(" + propName + ") failed to create: " + ExtendedFileUtils.toString(propValue)); } return true; } }
From source file:net.community.chest.gitcloud.facade.backend.git.BackendRepositoryResolver.java
public BackendRepositoryResolver(File baseDir) { reposRoot = Validate.notNull(baseDir, "No base folder", ArrayUtils.EMPTY_OBJECT_ARRAY); if (reposRoot.exists()) { Assert.state(reposRoot.isDirectory(), "Non-folder root: " + reposRoot); } else {/* w w w . ja v a 2 s . c o m*/ Assert.state(reposRoot.mkdirs(), "Cannot create root folder: " + reposRoot); } resolver = new FileResolver<C>(reposRoot, true); logger.info("Base dir: " + ExtendedFileUtils.toString(reposRoot)); synchronized (holder) { Assert.state(holder.get() == null, "Double registered resolver"); holder.set(this); } }
From source file:net.community.chest.gitcloud.facade.AbstractContextInitializer.java
@Override public void initialize(ConfigurableApplicationContext applicationContext) { ConfigurableEnvironment environment = applicationContext.getEnvironment(); MutablePropertySources propSources = environment.getPropertySources(); ExtendedPlaceholderResolver sourcesResolver = ExtendedPlaceholderResolverUtils .toPlaceholderResolver(propSources); File appBase = resolveApplicationBase(propSources, sourcesResolver); File configFile = getApplicationConfigFile(appBase, sourcesResolver); Collection<String> activeProfiles = resolveActiveProfiles(sourcesResolver); if (ExtendedCollectionUtils.size(activeProfiles) > 0) { environment.setActiveProfiles(activeProfiles.toArray(new String[activeProfiles.size()])); }//from w w w .j av a2s. c o m try { ensureFoldersExistence(appBase, configFile, sourcesResolver); } catch (IOException e) { logger.error("ensureFoldersExistence(" + ExtendedFileUtils.toString(appBase) + ")" + " " + e.getClass().getSimpleName() + ": " + e.getMessage()); } if (logger.isDebugEnabled()) { showArtifactsVersions(); } }
From source file:net.community.chest.gitcloud.facade.AbstractEnvironmentInitializer.java
protected void contextInitialized(ServletContext context) { PlaceholderResolver contextResolver = ServletUtils.toPlaceholderResolver(context); Pair<File, Boolean> result = ConfigUtils.resolveGitcloudBase(new AggregatedExtendedPlaceholderResolver( contextResolver, ExtendedPlaceholderResolverUtils.SYSPROPS_RESOLVER, ExtendedPlaceholderResolverUtils.ENVIRON_RESOLVER)); File rootDir = result.getLeft(); Boolean baseExists = result.getRight(); if (!baseExists.booleanValue()) { System.setProperty(ConfigUtils.GITCLOUD_BASE_PROP, rootDir.getAbsolutePath()); logger.info("contextInitialized(" + context.getContextPath() + ") - added " + ConfigUtils.GITCLOUD_BASE_PROP + ": " + ExtendedFileUtils.toString(rootDir)); } else {//from w ww . jav a 2 s. co m logger.info("contextInitialized(" + context.getContextPath() + ") using " + ConfigUtils.GITCLOUD_BASE_PROP + ": " + ExtendedFileUtils.toString(rootDir)); } extractConfigFiles(new File(rootDir, ConfigUtils.CONF_DIR_NAME)); }
From source file:net.community.chest.gitcloud.facade.AbstractEnvironmentInitializer.java
protected void extractConfigFiles(File confDir, String resPrefix, Collection<String> names) { if (ConfigUtils.verifyFolderProperty(ConfigUtils.CONF_DIR_NAME, confDir)) { logger.info("extractConfigFiles(" + resPrefix + ") - created " + ExtendedFileUtils.toString(confDir)); }/* w ww. java 2s . c o m*/ ClassLoader cl = ExtendedClassUtils.getDefaultClassLoader(getClass()); for (String fileName : names) { File targetFile = new File(confDir, fileName); if (targetFile.exists()) { logger.info("extractConfigFiles(" + fileName + ")[" + resPrefix + "] skip - already exists: " + ExtendedFileUtils.toString(targetFile)); continue; } try { long copyLength = extractConfigFile(cl.getResourceAsStream(resPrefix + "/" + fileName), targetFile, getWorkBuf(ExtendedIOUtils.DEFAULT_BUFFER_SIZE_VALUE)); if (copyLength <= 0L) { throw new StreamCorruptedException("Bad copy count: " + copyLength); } logger.info("extractConfigFiles(" + resPrefix + ")[" + fileName + "] " + copyLength + " bytes: " + ExtendedFileUtils.toString(targetFile)); } catch (IOException e) { RuntimeException thrown = new RuntimeException( "extractConfigFiles(" + resPrefix + ")[" + fileName + "]" + " failed (" + e.getClass().getSimpleName() + ")" + " to extract contents: " + e.getMessage(), e); logger.warn(thrown.getMessage(), e); throw thrown; } } }
From source file:net.community.chest.gitcloud.facade.AbstractContextInitializer.java
protected <C extends Collection<File>> C verifyFolderProperty(String propName, File propValue, C outputCollection) {/*from ww w . java 2 s. com*/ if (ConfigUtils.verifyFolderProperty(propName, propValue)) { logger.info("verifyFolderProperty(" + propName + ") created: " + ExtendedFileUtils.toString(propValue)); outputCollection.add(propValue); } return outputCollection; }
From source file:net.community.chest.gitcloud.facade.AbstractContextInitializer.java
protected File resolveApplicationBase(MutablePropertySources propSources, ExtendedPlaceholderResolver sourcesResolver) { Pair<File, Boolean> result = ConfigUtils.resolveGitcloudBase(sourcesResolver); File rootDir = result.getLeft(); Boolean baseExists = result.getRight(); if (!baseExists.booleanValue()) { propSources.addFirst(new MapPropertySource("gitcloudBase", Collections .<String, Object>singletonMap(ConfigUtils.GITCLOUD_BASE_PROP, rootDir.getAbsolutePath()))); System.setProperty(ConfigUtils.GITCLOUD_BASE_PROP, rootDir.getAbsolutePath()); logger.info("resolveApplicationBase - added " + ConfigUtils.GITCLOUD_BASE_PROP + ": " + ExtendedFileUtils.toString(rootDir)); }//from w w w .ja va2 s. c o m return rootDir; }