Example usage for org.apache.commons.io FilenameUtils normalize

List of usage examples for org.apache.commons.io FilenameUtils normalize

Introduction

In this page you can find the example usage for org.apache.commons.io FilenameUtils normalize.

Prototype

public static String normalize(String filename) 

Source Link

Document

Normalizes a path, removing double and single dot path steps.

Usage

From source file:net.grinder.engine.agent.AgentImplementationEx.java

private Properties rebaseSystemClassPath(Properties properties, File curDir) {
    Properties newProperties = new Properties();
    newProperties.putAll(properties);//from  w  w w. j  a v  a2s  .  c  o  m
    StringBuilder newClassPath = new StringBuilder();
    boolean isFirst = true;
    for (String each : StringUtils.split(properties.getProperty("java.class.path"), File.pathSeparator)) {
        File file = new File(each);
        if (!file.isAbsolute()) {
            file = new File(curDir, each);
        }
        if (!isFirst) {
            newClassPath.append(File.pathSeparator);
        }
        isFirst = false;
        newClassPath.append(FilenameUtils.normalize(file.getAbsolutePath()));
    }
    newProperties.put("java.class.path", newClassPath.toString());
    return newProperties;
}

From source file:de.innovationgate.wgpublisher.plugins.WGAPlugin.java

public String getFilePath() {
    return FilenameUtils.normalize(getParent().getCore().getWGAFile(_filePath).getAbsolutePath());
}

From source file:com.redhat.rhn.common.util.StringUtil.java

/**
 * Add a path onto another path (either local path or networked service).
 * This ensures double '/'s aren't included
 * @param originalPath The start of the path (i.e. http://localhost/, or
 * /var/www/)/*from w ww. j av a 2 s.  c  o m*/
 * @param toAdd what to add (i.e. /pub/test.file)
 * @return the full path with no duplicate '/'s
 */
public static String addPath(String originalPath, String toAdd) {
    return FilenameUtils.normalize(originalPath + File.separator + toAdd);
}

From source file:com.igormaznitsa.jute.JuteMojo.java

private void fillListByTestMethods(final TestContainer base, final File testRoot,
        final List<String> testClassFilePaths,
        final Map<TestClassProcessor, List<TestContainer>> detectedTestMap) throws IOException {
    final String testRootPath = FilenameUtils.normalize(testRoot.getAbsolutePath() + File.separatorChar);

    for (final String classFilePath : testClassFilePaths) {
        final String normalizedClassFilePath = FilenameUtils.normalize(classFilePath);
        final String standardJavaClassName = Utils.toStandardJavaClassName(testRootPath,
                normalizedClassFilePath);

        getLog().debug("Process class file : " + normalizedClassFilePath + '[' + standardJavaClassName + ']');

        if (!Utils.checkClassAndMethodForPattern(this.juteTest, standardJavaClassName, "", true)) {
            getLog().debug("Excluded for 'juteTest' (" + this.juteTest + ')');
            continue;
        }//  ww w . j a  v a  2  s.  c  o m

        final InputStream classInStream = new FileInputStream(normalizedClassFilePath);
        try {
            final ClassReader classReader = new ClassReader(classInStream);
            final List<TestContainer> listOfDetectedMethods = new ArrayList<TestContainer>();

            final TestClassProcessor tcv = new TestClassProcessor(this.onlyAnnotated, this.juteTest,
                    normalizedClassFilePath, base, this.getLog(), listOfDetectedMethods,
                    normalizeStringArray(this.includeTests), normalizeStringArray(this.excludeTests));
            classReader.accept(tcv, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);

            getLog().debug("Class file " + normalizedClassFilePath + " has " + listOfDetectedMethods.size()
                    + " detected methods");

            detectedTestMap.put(tcv, Utils.sortDetectedClassMethodsForNameAndOrder(listOfDetectedMethods));
        } finally {
            IOUtils.closeQuietly(classInStream);
        }
    }
}

From source file:com.igormaznitsa.mvngolang.AbstractGolangMojo.java

@Nullable
private ProcessExecutor prepareExecutor(@Nullable final ProxySettings proxySettings)
        throws IOException, MojoFailureException {
    initConsoleBuffers();/*from ww w . ja va  2s  . c o  m*/

    final String execNameAdaptedForOs = adaptExecNameForOS(makeExecutableFileSubpath());
    final File detectedRoot = findGoRoot(proxySettings);
    final String gobin = getGoBin();
    final File gopath = findGoPath(true);

    if (isMojoMustNotBeExecuted()) {
        return null;
    }

    final String toolName = FilenameUtils
            .normalize(GetUtils.ensureNonNull(getUseGoTool(), execNameAdaptedForOs));
    final File executableFileInPathOrRoot = new File(getPathToFolder(detectedRoot) + toolName);

    final File executableFileInBin = gobin == null ? null
            : new File(getPathToFolder(gobin) + adaptExecNameForOS(getExec()));

    final File[] exeVariants = new File[] { executableFileInBin, executableFileInPathOrRoot };

    final File foundExecutableTool = findExisting(exeVariants);

    if (foundExecutableTool == null) {
        throw new MojoFailureException("Can't find executable file : " + Arrays.toString(exeVariants));
    } else {
        logOptionally("Executable file detected : " + foundExecutableTool);
    }

    final List<String> commandLine = new ArrayList<String>();
    commandLine.add(foundExecutableTool.getAbsolutePath());

    final String gocommand = getGoCommand();
    if (!gocommand.isEmpty()) {
        commandLine.add(getGoCommand());
    }

    for (final String s : getCommandFlags()) {
        commandLine.add(s);
    }

    for (final String s : getBuildFlags()) {
        commandLine.add(s);
    }

    for (final String s : getTailArguments()) {
        commandLine.add(s);
    }

    for (final String s : getOptionalExtraTailArguments()) {
        commandLine.add(s);
    }

    final StringBuilder cli = new StringBuilder();
    int index = 0;
    for (final String s : commandLine) {
        if (cli.length() > 0) {
            cli.append(' ');
        }
        if (index == 0) {
            cli.append(execNameAdaptedForOs);
        } else {
            cli.append(s);
        }
        index++;
    }

    getLog().info(String.format("Prepared command line : %s", cli.toString()));

    final ProcessExecutor result = new ProcessExecutor(commandLine);

    final File sourcesFile = getSources(isSourceFolderRequired());
    logOptionally("GoLang project sources folder : " + sourcesFile);
    if (sourcesFile.isDirectory()) {
        result.directory(sourcesFile);
    }

    logOptionally("");
    logOptionally("....Environment vars....");

    addEnvVar(result, "GOROOT", detectedRoot.getAbsolutePath());
    addEnvVar(result, "GOPATH", preparePath(gopath.getAbsolutePath(), getExtraPathToAddToGoPathBeforeSources(),
            removeSrcFolderAtEndIfPresented(sourcesFile.getAbsolutePath()), getExtraPathToAddToGoPathToEnd()));

    if (gobin == null)
        getLog().warn("GOBIN is disabled by direct order");
    else
        addEnvVar(result, "GOBIN", gobin);

    final String trgtOs = this.getTargetOS();
    final String trgtArch = this.getTargetArch();
    final String trgtArm = this.getTargetArm();

    if (trgtOs != null) {
        addEnvVar(result, "GOOS", trgtOs);
    }

    if (trgtArm != null) {
        addEnvVar(result, "GOARM", trgtArm);
    }

    if (trgtArch != null) {
        addEnvVar(result, "GOARCH", trgtArch);
    }

    final File gorootbootstrap = findGoRootBootstrap(true);
    if (gorootbootstrap != null) {
        addEnvVar(result, "GOROOT_BOOTSTRAP", gorootbootstrap.getAbsolutePath());
    }

    String thePath = GetUtils.ensureNonNullStr(System.getenv("PATH"));
    thePath = preparePath(thePath, (detectedRoot + File.separator + getExecSubpath()), gobin);
    addEnvVar(result, "PATH", thePath);

    for (final Map.Entry<?, ?> record : getEnv().entrySet()) {
        addEnvVar(result, record.getKey().toString(), record.getValue().toString());
    }

    logOptionally("........................");

    result.redirectOutput(this.consoleOutBuffer);
    result.redirectError(this.consoleErrBuffer);

    return result;
}

From source file:ffx.ui.MainPanel.java

/**
 * Attempts to load the supplied file//w ww  .  j ava2s . co  m
 *
 * @param file File to open
 * @param commandDescription Description of the command that created this
 * file.
 * @return a {@link java.lang.Thread} object.
 */
private UIFileOpener openInit(File file, String commandDescription) {
    if (file == null || !file.isFile() || !file.canRead()) {
        return null;
    }
    file = new File(FilenameUtils.normalize(file.getAbsolutePath()));
    // Set the Current Working Directory based on this file.
    setCWD(file.getParentFile());

    // Get "filename" from "filename.extension".
    String name = file.getName();
    String extension = FilenameUtils.getExtension(name);

    /**
     * Run a Force Field X script.
     */
    if (extension.equalsIgnoreCase("ffx") || extension.equalsIgnoreCase("groovy")) {
        ModelingShell shell = getModelingShell();
        shell.runFFXScript(file);
        boolean shutDown = Boolean.parseBoolean(System.getProperty("ffx.shutDown", "true"));
        if (java.awt.GraphicsEnvironment.isHeadless() && shutDown) {
            exit();
        } else {
            return null;
        }
    }

    // Create the CompositeConfiguration properties.
    CompositeConfiguration properties = Keyword.loadProperties(file);
    // Create an FFXSystem for this file.
    FFXSystem newSystem = new FFXSystem(file, commandDescription, properties);
    // Create a Force Field.
    forceFieldFilter = new ForceFieldFilter(properties);
    ForceField forceField = forceFieldFilter.parse();
    String patches[] = properties.getStringArray("patch");
    for (String patch : patches) {
        logger.info(" Attempting to read force field patch from " + patch + ".");
        CompositeConfiguration patchConfiguration = new CompositeConfiguration();
        patchConfiguration.addProperty("parameters", patch);
        forceFieldFilter = new ForceFieldFilter(patchConfiguration);
        ForceField patchForceField = forceFieldFilter.parse();
        forceField.append(patchForceField);
        if (RotamerLibrary.addRotPatch(patch)) {
            logger.info(String.format(" Loaded rotamer definitions from patch %s.", patch));
        }
    }
    newSystem.setForceField(forceField);
    SystemFilter systemFilter = null;

    // Decide what parser to use.
    if (xyzFileFilter.acceptDeep(file)) {
        // Use the TINKER Cartesian Coordinate File Parser.
        systemFilter = new XYZFilter(file, newSystem, forceField, properties);
    } else if (intFileFilter.acceptDeep(file)) {
        // Use the TINKER Internal Coordinate File Parser.
        systemFilter = new INTFilter(file, newSystem, forceField, properties);
    } else {
        // Use the PDB File Parser.
        systemFilter = new PDBFilter(file, newSystem, forceField, properties);
    }

    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    activeFilter = systemFilter;
    UIFileOpener fileOpener = new UIFileOpener(systemFilter, this);
    if (fileOpenerThreads > 0) {
        fileOpener.setNThreads(fileOpenerThreads);
    }
    return fileOpener;
    //return new UIFileOpener(systemFilter, this);
}

From source file:ffx.ui.MainPanel.java

/**
 * Attempts to load the supplied file/*  ww  w .  ja va  2 s .  c o  m*/
 *
 * @param files Files to open
 * @param commandDescription Description of the command that created this
 * file.
 * @return a {@link java.lang.Thread} object.
 */
private UIFileOpener openInit(List<File> files, String commandDescription) {
    if (files == null) {
        return null;
    }
    File file = new File(FilenameUtils.normalize(files.get(0).getAbsolutePath()));
    // Set the Current Working Directory based on this file.
    setCWD(file.getParentFile());

    // Get "filename" from "filename.extension".
    String name = file.getName();
    String extension = FilenameUtils.getExtension(name);

    // Create the CompositeConfiguration properties.
    CompositeConfiguration properties = Keyword.loadProperties(file);
    forceFieldFilter = new ForceFieldFilter(properties);
    ForceField forceField = forceFieldFilter.parse();

    // Create an FFXSystem for this file.
    FFXSystem newSystem = new FFXSystem(file, commandDescription, properties);
    String patches[] = properties.getStringArray("patch");
    for (String patch : patches) {
        logger.info(" Attempting to read force field patch from " + patch + ".");
        CompositeConfiguration patchConfiguration = new CompositeConfiguration();
        patchConfiguration.addProperty("parameters", patch);
        forceFieldFilter = new ForceFieldFilter(patchConfiguration);
        ForceField patchForceField = forceFieldFilter.parse();
        forceField.append(patchForceField);
        if (RotamerLibrary.addRotPatch(patch)) {
            logger.info(String.format(" Loaded rotamer definitions from patch %s.", patch));
        }
    }
    newSystem.setForceField(forceField);
    // Decide what parser to use.
    SystemFilter systemFilter = null;
    if (xyzFileFilter.acceptDeep(file)) {
        // Use the TINKER Cartesian Coordinate File Parser.
        systemFilter = new XYZFilter(files, newSystem, forceField, properties);
    } else if (intFileFilter.acceptDeep(file)) {
        // Use the TINKER Internal Coordinate File Parser.
        systemFilter = new INTFilter(files, newSystem, forceField, properties);
    } else {
        // Use the PDB File Parser.
        systemFilter = new PDBFilter(files, newSystem, forceField, properties);
    }

    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    activeFilter = systemFilter;
    //return new UIFileOpener(systemFilter, this);
    UIFileOpener fileOpener = new UIFileOpener(systemFilter, this);
    if (fileOpenerThreads > 0) {
        fileOpener.setNThreads(fileOpenerThreads);
    }
    return fileOpener;
}

From source file:net.sourceforge.pmd.cpd.ApexCpdTest.java

@Before
public void setUp() {
    String path = FilenameUtils.normalize("src/test/resources/net/sourceforge/pmd/cpd/issue427");
    testdir = new File(path);
}

From source file:net.sourceforge.pmd.docs.GenerateRuleDocsCmd.java

public static List<String> findAdditionalRulesets(Path basePath) {
    try {//from  w w  w .  j  a  va  2s . c  o  m
        List<String> additionalRulesets = new ArrayList<>();
        Pattern rulesetPattern = Pattern.compile("^.+" + Pattern.quote(File.separator) + "pmd-\\w+"
                + Pattern.quote(FilenameUtils.normalize("/src/main/resources/rulesets/")) + "\\w+"
                + Pattern.quote(File.separator) + "\\w+.xml$");
        Files.walkFileTree(basePath, new SimpleFileVisitor<Path>() {
            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                if (rulesetPattern.matcher(file.toString()).matches()) {
                    additionalRulesets.add(file.toString());
                }

                return FileVisitResult.CONTINUE;
            }
        });
        return additionalRulesets;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:net.sourceforge.pmd.docs.RuleDocGenerator.java

private Path getAbsoluteOutputPath(String filename) {
    return root.resolve(FilenameUtils.normalize(filename));
}