List of usage examples for org.apache.commons.io FilenameUtils normalize
public static String normalize(String filename)
From source file:net.grinder.engine.agent.PropertyBuilder.java
/** * Rebase class path from relative path to absolute path. * * @param classPath class path//from w w w .ja v a 2 s .com * @return converted path. */ public String rebaseCustomClassPath(String classPath) { StringBuilder newClassPath = new StringBuilder(); boolean isFirst = true; for (String each : StringUtils.split(classPath, ";:")) { File file = new File(baseDirectory.getFile(), each); if (!isFirst) { newClassPath.append(File.pathSeparator); } isFirst = false; newClassPath.append(FilenameUtils.normalize(file.getAbsolutePath())); } return newClassPath.toString(); }
From source file:de.alpharogroup.lang.PropertiesUtils.java
/** * Load properties.//from w w w.j a va2s. c o m * * @param packagePath * the package path without the file name * @param fileName * the file name * @return the properties * @throws IOException * Signals that an I/O exception has occurred. */ public static Properties loadProperties(String packagePath, String fileName) throws IOException { StringBuilder sb = new StringBuilder(); packagePath = FilenameUtils.normalize(packagePath); final String slash = "/"; if (packagePath.startsWith(slash)) { // remove first slash... if (packagePath.endsWith(slash)) { sb.append(packagePath.substring(1, packagePath.length())); } else { // append slash at the end... sb.append(packagePath.substring(1, packagePath.length())).append(slash); } } else { if (packagePath.endsWith(slash)) { // remove first char... sb.append(packagePath); } else { // remove first char... sb.append(packagePath).append(slash); } } packagePath = sb.toString().trim(); sb = new StringBuilder(); if (fileName.startsWith(slash)) { sb.append(fileName.substring(1, fileName.length())); } fileName = sb.toString().trim(); return loadProperties(packagePath + fileName); }
From source file:hudson.gridmaven.MavenModuleSetBuild.java
private static String normalizePath(String relPath) { relPath = StringUtils.trimToEmpty(relPath); if (StringUtils.isEmpty(relPath)) { LOGGER.config("No need to normalize an empty path."); } else {//from ww w . ja va 2 s . c om if (FilenameUtils.indexOfLastSeparator(relPath) == -1) { LOGGER.config("No need to normalize " + relPath); } else { String tmp = FilenameUtils.normalize(relPath); if (tmp == null) { LOGGER.config( "Path " + relPath + " can not be normalized (parent dir is unknown). Keeping as is."); } else { LOGGER.config("Normalized path " + relPath + " to " + tmp); relPath = tmp; } relPath = FilenameUtils.separatorsToUnix(relPath); } } LOGGER.fine("Returning path " + relPath); return relPath; }
From source file:de.uzk.hki.da.cb.UpdateMetadataAction.java
private void copyMetsFiles(EadMetsMetadataStructure emms, String repName) throws IOException { List<String> metse = emms.getMetsRefsInEad(); for (int mmm = 0; mmm < metse.size(); mmm++) { String mets = metse.get(mmm); String normMets = FilenameUtils.normalize(mets); if (normMets != null) { mets = normMets;/*from ww w .j a v a 2 s . co m*/ } File srcFile = new File(wa.dataPath() + "/" + o.getLatest(mets).getPath()); File dstFile = new File(wa.dataPath() + "/" + repName + "/" + mets); FileUtils.copyFile(srcFile, dstFile); DAFile dstDaFile = new DAFile(repName, mets); DAFile srcDaFile = o.getLatest(mets); dstDaFile.setFormatPUID(srcDaFile.getFormatPUID()); o.getLatestPackage().getFiles().add(dstDaFile); Event e = new Event(); e.setSource_file(srcDaFile); e.setTarget_file(dstDaFile); e.setType("COPY"); e.setDate(new Date()); e.setAgent_type("NODE"); e.setAgent_name(n.getName()); o.getLatestPackage().getEvents().add(e); logger.debug("Copied metadata file \"{}\" to \"{}\"", srcDaFile.toString(), dstDaFile); } }
From source file:aurelienribon.gdxsetupui.ProjectSetup.java
private void move(File base, String path1, String path2) throws IOException { if (path1.equals(path2)) return;/* w ww.j a va 2 s . c om*/ File file1 = new File(base, FilenameUtils.normalize(path1)); File file2 = new File(base, FilenameUtils.normalize(path2)); FileUtils.deleteQuietly(file2); if (file1.isDirectory()) FileUtils.moveDirectory(file1, file2); else FileUtils.moveFile(file1, file2); }
From source file:io.cloudslang.lang.tools.build.SlangBuildMain.java
private static void configureLog4j() { String configFilename = System.getProperty(LOG4J_CONFIGURATION_KEY); String errorMessage = null;/*from ww w . j av a 2s.c o m*/ try { if (StringUtils.isEmpty(configFilename)) { errorMessage = "Config file name is empty."; } else { String normalizedPath = FilenameUtils.normalize(configFilename); if (normalizedPath == null) { errorMessage = "Normalized config file path is null."; } else if (!isUnderAppHome(normalizedPath, getNormalizedApplicationHome())) { errorMessage = "Normalized config file path[" + normalizedPath + "] " + "is not under application home directory"; } else { if (!isRegularFile(get(normalizedPath), NOFOLLOW_LINKS)) { errorMessage = "Normalized config file path[" + normalizedPath + "]" + " does not lead to a regular file."; } else { Properties log4jProperties = new Properties(); try (InputStream log4jInputStream = SlangBuildMain.class .getResourceAsStream(normalizedPath)) { log4jProperties.load(log4jInputStream); PropertyConfigurator.configure(log4jProperties); } } } } } catch (IOException | RuntimeException ex) { errorMessage = ex.getMessage(); } if (StringUtils.isNotEmpty(errorMessage)) { System.out.printf("%s%n\t%s%n\t%s%n", LOG4J_ERROR_PREFIX, errorMessage, LOG4J_ERROR_SUFFIX); } }
From source file:com.ejisto.modules.cargo.CargoManager.java
private AbstractInstalledLocalContainer createContainer(String homeDir, String cargoId, String containerId, Configuration configuration) { if (configuration == null) { File configurationDir = new File(homeDir); configuration = loadExistingConfiguration(cargoId, configurationDir); }/*from ww w . j a va 2 s . co m*/ String agentPath = ContainerUtils.extractAgentJar(System.getProperty("java.class.path")); StringBuilder jvmArgs = new StringBuilder("-javaagent:"); jvmArgs.append(agentPath); jvmArgs.append(" -noverify -Djava.net.preferIPv4Stack=true"); jvmArgs.append(" -Dejisto.http.port=").append(System.getProperty(HTTP_LISTEN_PORT.getValue())); jvmArgs.append(" -D").append(StringConstants.CLASS_DEBUG_PATH.getValue()).append("=") .append(FilenameUtils.normalize(System.getProperty("java.io.tmpdir") + "/")); jvmArgs.append(" -D").append(StringConstants.ACTIVATE_IN_MEMORY_RELOAD.getValue()).append("=false"); String existingConfiguration = configuration.getPropertyValue(GeneralPropertySet.JVMARGS); if (StringUtils.isNotBlank(existingConfiguration)) { jvmArgs.append(" ").append(existingConfiguration); } configuration.setProperty(GeneralPropertySet.JVMARGS, jvmArgs.append(" ").toString()); DefaultContainerFactory containerFactory = new DefaultContainerFactory(); AbstractInstalledLocalContainer container = (AbstractInstalledLocalContainer) containerFactory .createContainer(cargoId, org.codehaus.cargo.container.ContainerType.INSTALLED, configuration); container.setHome(homeDir); container.setLogger(new ServerLogger(containerId)); container.addExtraClasspath(agentPath); return container; }
From source file:de.extra.client.plugins.responseprocessplugin.filesystem.FileSystemResultPackageDataResponseProcessPlugin.java
/** * /*from w w w . ja v a 2 s .c o m*/ * Wenn IncomingFileName ber DataSource Plugin gesetzt ist , wird dieser * Name bernommen, sonst Erzeugt einen eindeitigen Filenamen mit * milissekunden und ResponseID. * * @param responseId * @return */ private String buildFilename(final String incomingFileName, final String responseId) { final StringBuilder fileName = new StringBuilder(); if (incomingFileName != null) { fileName.append(incomingFileName); } else { String cleanResponseId = FilenameUtils.normalize(responseId); cleanResponseId = StringUtils.substringBefore(cleanResponseId, " "); fileName.append("RESPONSE_").append(cleanResponseId); fileName.append("_").append(System.currentTimeMillis()); } return fileName.toString(); }
From source file:io.cloudslang.lang.tools.build.SlangBuildMain.java
private static String getNormalizedApplicationHome() { String appHome = System.getProperty(APP_HOME_KEY); if (StringUtils.isEmpty(appHome)) { throw new RuntimeException(APP_HOME_KEY + " system property is empty"); }/*w w w .j ava 2s .c o m*/ String normalizedAppHome = FilenameUtils.normalize(appHome); if (normalizedAppHome == null) { throw new RuntimeException("Normalized app home path is null."); } return normalizedAppHome; }
From source file:io.cloudslang.lang.tools.build.SlangBuildMain.java
private static Set<String> readChangedFilesFromSource(String filePath) throws IOException { String normalizedPath = FilenameUtils.normalize(filePath); if (!get(normalizedPath).isAbsolute()) { throw new RuntimeException(MESSAGE_ERROR_LOADING_SMART_MODE_CONFIG_FILE + " Path[" + normalizedPath + "] is not an absolute path."); }/*from w w w . j a v a 2 s .c o m*/ if (!isRegularFile(get(normalizedPath), NOFOLLOW_LINKS)) { throw new RuntimeException(MESSAGE_ERROR_LOADING_SMART_MODE_CONFIG_FILE + " Path[" + normalizedPath + "] does not lead to a regular file."); } return ArgumentProcessorUtils.loadChangedItems(normalizedPath); }