List of usage examples for org.apache.commons.io FilenameUtils concat
public static String concat(String basePath, String fullFilenameToAdd)
From source file:org.apache.flex.compiler.internal.tree.mxml.MXMLNodeBase.java
/** * Resolves the path specified in an MXML tag's <code>source</code> * attribute.//from www.java2 s . co m * * @param builder The {@code MXMLTreeBuilder} object which is building this * MXML tree. * @param attribute The <code>source</code> attribute. * @return A resolved and normalized path to the external file. */ public static String resolveSourceAttributePath(MXMLTreeBuilder builder, IMXMLTagAttributeData attribute, MXMLNodeInfo info) { if (info != null) info.hasSourceAttribute = true; String sourcePath = attribute.getMXMLDialect().trim(attribute.getRawValue()); if (sourcePath.isEmpty() && builder != null) { ICompilerProblem problem = new MXMLEmptyAttributeProblem(attribute); builder.addProblem(problem); return null; } String resolvedPath; if ((new File(sourcePath)).isAbsolute()) { // If the source attribute specifies an absolute path, // it doesn't need to be resolved. resolvedPath = sourcePath; } else { // Otherwise, resolve it relative to the MXML file. String mxmlPath = attribute.getParent().getParent().getPath(); resolvedPath = FilenameUtils.getPrefix(mxmlPath) + FilenameUtils.getPath(mxmlPath); resolvedPath = FilenameUtils.concat(resolvedPath, sourcePath); } String normalizedPath = FilenameNormalization.normalize(resolvedPath); // Make the compilation unit dependent on the external file. if (builder != null) builder.getFileScope().addSourceDependency(normalizedPath); return normalizedPath; }
From source file:org.apache.geode.distributed.internal.ClusterConfigurationService.java
public ClusterConfigurationService(Cache cache) throws IOException { this.cache = (GemFireCacheImpl) cache; Properties properties = cache.getDistributedSystem().getProperties(); // resolve the cluster config dir String clusterConfigRootDir = properties.getProperty(CLUSTER_CONFIGURATION_DIR); if (StringUtils.isBlank(clusterConfigRootDir)) { clusterConfigRootDir = System.getProperty("user.dir"); } else {//from w w w .j ava 2 s . c o m File diskDir = new File(clusterConfigRootDir); if (!diskDir.exists() && !diskDir.mkdirs()) { throw new IOException("Cannot create directory : " + clusterConfigRootDir); } clusterConfigRootDir = diskDir.getCanonicalPath(); } // resolve the file paths String configDiskDirName = CLUSTER_CONFIG_DISK_DIR_PREFIX + cache.getDistributedSystem().getName(); configDirPath = FilenameUtils.concat(clusterConfigRootDir, CLUSTER_CONFIG_ARTIFACTS_DIR_NAME); configDiskDirPath = FilenameUtils.concat(clusterConfigRootDir, configDiskDirName); sharedConfigLockingService = getSharedConfigLockService(cache.getDistributedSystem()); status.set(SharedConfigurationStatus.NOT_STARTED); }
From source file:org.apache.geode.distributed.internal.ClusterConfigurationService.java
/** * Add jar information into the shared configuration and save the jars in the file system used * when deploying jars//from w w w . java 2 s .c o m * * @return true on success */ public boolean addJarsToThisLocator(String[] jarNames, byte[][] jarBytes, String[] groups) { boolean success = true; lockSharedConfiguration(); try { if (groups == null) { groups = new String[] { ClusterConfigurationService.CLUSTER_CONFIG }; } Region<String, Configuration> configRegion = getConfigurationRegion(); for (String group : groups) { Configuration configuration = configRegion.get(group); if (configuration == null) { configuration = new Configuration(group); createConfigDirIfNecessary(group); } String groupDir = FilenameUtils.concat(configDirPath, group); for (int i = 0; i < jarNames.length; i++) { String filePath = FilenameUtils.concat(groupDir, jarNames[i]); File jarFile = new File(filePath); try { FileUtils.writeByteArrayToFile(jarFile, jarBytes[i]); } catch (IOException e) { logger.info(e); } } // update the record after writing the jars to the file system, since the listener // will need the jars on file to upload to other locators. Need to update the jars // using a new copy of the Configuration so that the change listener will pick up the jar // name changes. Configuration configurationCopy = new Configuration(configuration); configurationCopy.addJarNames(jarNames); configRegion.put(group, configurationCopy); } } catch (Exception e) { success = false; logger.info(e.getMessage(), e); } finally { unlockSharedConfiguration(); } return success; }
From source file:org.apache.geode.distributed.internal.SharedConfiguration.java
public SharedConfiguration(Cache cache) throws IOException { this.cache = (GemFireCacheImpl) cache; this.configDiskDirName = CLUSTER_CONFIG_DISK_DIR_PREFIX + cache.getDistributedSystem().getName(); String clusterConfigDir = cache.getDistributedSystem().getProperties() .getProperty(CLUSTER_CONFIGURATION_DIR); if (StringUtils.isBlank(clusterConfigDir)) { clusterConfigDir = System.getProperty("user.dir"); } else {/*from w w w . j a va2 s .co m*/ File diskDir = new File(clusterConfigDir); if (!diskDir.exists() && !diskDir.mkdirs()) { throw new IOException("Cannot create directory : " + clusterConfigDir); } clusterConfigDir = diskDir.getCanonicalPath(); } this.configDiskDirPath = FilenameUtils.concat(clusterConfigDir, this.configDiskDirName); configDirPath = FilenameUtils.concat(clusterConfigDir, CLUSTER_CONFIG_ARTIFACTS_DIR_NAME); sharedConfigLockingService = getSharedConfigLockService(cache.getDistributedSystem()); status.set(SharedConfigurationStatus.NOT_STARTED); }
From source file:org.apache.geode.distributed.internal.SharedConfiguration.java
/** * Add jar information into the shared configuration and save the jars in the file system * @return true on success/*from w w w .ja va 2 s . co m*/ */ public boolean addJars(String[] jarNames, byte[][] jarBytes, String[] groups) { boolean success = true; try { if (groups == null) { groups = new String[] { SharedConfiguration.CLUSTER_CONFIG }; } Region<String, Configuration> configRegion = getConfigurationRegion(); for (String group : groups) { Configuration configuration = configRegion.get(group); if (configuration == null) { configuration = new Configuration(group); writeConfig(configuration); } configuration.addJarNames(jarNames); configRegion.put(group, configuration); String groupDir = FilenameUtils.concat(configDirPath, group); writeJarFiles(groupDir, jarNames, jarBytes); } } catch (Exception e) { success = false; logger.info(e.getMessage(), e); } return success; }
From source file:org.apache.geode.distributed.internal.SharedConfiguration.java
public Object[] getAllJars(Set<String> groups) throws Exception { Set<String> jarsAdded = new HashSet<String>(); Object[] jars = new Object[2]; for (String group : groups) { Configuration configuration = getConfiguration(group); if (configuration != null) { jarsAdded.addAll(configuration.getJarNames()); }/*from w w w . ja v a2 s . c o m*/ } int numJars = jarsAdded.size(); jarsAdded.clear(); if (numJars > 0) { String[] jarNames = new String[numJars]; byte[][] jarBytes = new byte[numJars][]; int ctr = 0; for (String group : groups) { Configuration configuration = getConfiguration(group); if (configuration != null) { Set<String> jarNameSet = configuration.getJarNames(); for (String jarName : jarNameSet) { String groupDirPath = FilenameUtils.concat(configDirPath, group); if (!jarsAdded.contains(jarName)) { String jarFilePath = FilenameUtils.concat(groupDirPath, jarName); jarNames[ctr] = jarName; jarBytes[ctr] = FileUtils.readFileToByteArray(new File(jarFilePath)); ctr++; } } } } jars[0] = jarNames; jars[1] = jarBytes; } return jars; }
From source file:org.apache.geode.distributed.internal.SharedConfiguration.java
/** * Removes the jar files from the shared configuration. * @param jarNames Names of the jar files. * @param groups Names of the groups which had the jar file deployed. * @return true on success.// www. java 2 s . c om */ public boolean removeJars(final String[] jarNames, String[] groups) { boolean success = true; try { Region<String, Configuration> configRegion = getConfigurationRegion(); if (groups == null) { Set<String> groupSet = configRegion.keySet(); groups = groupSet.toArray(new String[groupSet.size()]); } for (String group : groups) { Configuration configuration = (Configuration) configRegion.get(group); if (configuration != null) { String dirPath = FilenameUtils.concat(getSharedConfigurationDirPath(), configuration.getConfigName()); removeJarFiles(dirPath, jarNames); } } for (String group : groups) { Configuration configuration = (Configuration) configRegion.get(group); if (configuration != null) { if (!configuration.getJarNames().isEmpty()) { configuration.removeJarNames(jarNames); configRegion.put(group, configuration); } } } } catch (Exception e) { logger.info("Exception occurred while deleting the jar files", e); success = false; } return success; }
From source file:org.apache.geode.distributed.internal.SharedConfiguration.java
public void renameExistingSharedConfigDirectory() { File configDirFile = new File(configDirPath); if (configDirFile.exists()) { String configDirFileName2 = CLUSTER_CONFIG_ARTIFACTS_DIR_NAME + new SimpleDateFormat("yyyyMMddhhmm").format(new Date()) + "." + System.nanoTime(); File configDirFile2 = new File(FilenameUtils.concat(configDirFileName2, configDirFileName2)); try {//from w ww .j a va 2s . c o m FileUtils.moveDirectoryToDirectory(configDirFile, configDirFile2, true); } catch (IOException e) { logger.info(e); } } }
From source file:org.apache.geode.distributed.internal.SharedConfiguration.java
/** * Writes the contents of the {@link Configuration} to the file system *//* w w w . jav a 2 s.c o m*/ public void writeConfig(final Configuration configuration) throws Exception { File configDir = new File(getSharedConfigurationDirPath()); if (!configDir.exists()) { if (!configDir.mkdirs()) { throw new IOException("Cannot create directory : " + getSharedConfigurationDirPath()); } } String dirPath = FilenameUtils.concat(getSharedConfigurationDirPath(), configuration.getConfigName()); File file = new File(dirPath); if (!file.exists()) { if (!file.mkdir()) { throw new IOException("Cannot create directory : " + dirPath); } } writeProperties(dirPath, configuration); writeCacheXml(dirPath, configuration); }
From source file:org.apache.geode.distributed.internal.SharedConfiguration.java
/** * Gets the Jar from existing locators in the system *///from ww w . ja va 2s . c o m private void getAllJarsFromOtherLocators() throws Exception { logger.info("Getting Jar files from other locators"); DM dm = cache.getDistributionManager(); DistributedMember me = cache.getMyId(); Set<DistributedMember> locators = new HashSet<DistributedMember>( dm.getAllHostedLocatorsWithSharedConfiguration().keySet()); locators.remove(me); String[] jarNames = null; byte[][] jarBytes = null; if (locators.isEmpty()) { logger.info("No other locators present"); return; } ResultCollector<?, List<Object>> rc = (ResultCollector<?, List<Object>>) CliUtil .executeFunction(getAllJarsFunction, null, locators); List<Object> results = rc.getResult(); for (Object result : results) { if (result != null) { if (!(result instanceof Exception)) { Object[] jars = (Object[]) result; jarNames = (String[]) jars[0]; jarBytes = (byte[][]) jars[1]; break; } } } if (jarNames != null && jarBytes != null) { Map<String, Integer> jarIndex = new HashMap<String, Integer>(); for (int i = 0; i < jarNames.length; i++) { String jarName = jarNames[i]; jarIndex.put(jarName, i); } Map<String, Configuration> entireConfiguration = getEntireConfiguration(); Set<String> groups = entireConfiguration.keySet(); for (String group : groups) { Configuration config = entireConfiguration.get(group); Set<String> groupJarNames = config.getJarNames(); String groupDirPath = FilenameUtils.concat(configDirPath, group); for (String groupJarName : groupJarNames) { Integer index = jarIndex.get(groupJarName); if (index != null) { String jarFilePath = FilenameUtils.concat(groupDirPath, groupJarName); byte[] jarData = jarBytes[index.intValue()]; try { FileUtils.writeByteArrayToFile(new File(jarFilePath), jarData); } catch (IOException e) { logger.info(e.getMessage(), e); } } else { //This should NEVER happen logger.error("JarFile {} not delivered.", groupJarName); } } } } else { logger.info("No deployed jars found on other locators."); } }