Search in sources :

Example 1 with PathTokenizer

use of org.apache.tools.ant.PathTokenizer in project intellij-community by JetBrains.

the class AntMultiPathStringConverter method fromString.

public List<File> fromString(@Nullable @NonNls String s, ConvertContext context) {
    final GenericAttributeValue attribValue = context.getInvocationElement().getParentOfType(GenericAttributeValue.class, false);
    if (attribValue == null) {
        return null;
    }
    final String path = attribValue.getStringValue();
    if (path == null) {
        return null;
    }
    final List<File> result = new ArrayList<>();
    Computable<String> basedirComputable = null;
    final PathTokenizer pathTokenizer = new PathTokenizer(path);
    while (pathTokenizer.hasMoreTokens()) {
        File file = new File(pathTokenizer.nextToken());
        if (!file.isAbsolute()) {
            if (basedirComputable == null) {
                basedirComputable = new Computable<String>() {

                    final String myBaseDir;

                    {
                        final AntDomProject antProject = getEffectiveAntProject(attribValue);
                        myBaseDir = antProject != null ? antProject.getProjectBasedirPath() : null;
                    }

                    public String compute() {
                        return myBaseDir;
                    }
                };
            }
            final String baseDir = basedirComputable.compute();
            if (baseDir == null) {
                continue;
            }
            file = new File(baseDir, path);
        }
        result.add(file);
    }
    return result;
}
Also used : PathTokenizer(org.apache.tools.ant.PathTokenizer) ArrayList(java.util.ArrayList) File(java.io.File)

Example 2 with PathTokenizer

use of org.apache.tools.ant.PathTokenizer in project intellij-community by JetBrains.

the class AntMultiPathStringConverter method createReferences.

@NotNull
public PsiReference[] createReferences(GenericDomValue<List<File>> genericDomValue, PsiElement element, ConvertContext context) {
    final GenericAttributeValue attributeValue = (GenericAttributeValue) genericDomValue;
    final String cpString = genericDomValue.getRawText();
    if (cpString == null || cpString.length() == 0) {
        return PsiReference.EMPTY_ARRAY;
    }
    final List<PsiReference> result = new ArrayList<>();
    final PathTokenizer pathTokenizer = new PathTokenizer(cpString);
    int searchFromIndex = 0;
    while (pathTokenizer.hasMoreTokens()) {
        final String path = pathTokenizer.nextToken();
        if (path.length() > 0) {
            final int pathBeginIndex = cpString.indexOf(path, searchFromIndex);
            final AntDomFileReferenceSet refSet = new AntDomFileReferenceSet(attributeValue, path, pathBeginIndex, false);
            ContainerUtil.addAll(result, refSet.getAllReferences());
            searchFromIndex = pathBeginIndex;
        }
    }
    return result.toArray(new PsiReference[result.size()]);
}
Also used : PathTokenizer(org.apache.tools.ant.PathTokenizer) ArrayList(java.util.ArrayList) PsiReference(com.intellij.psi.PsiReference) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with PathTokenizer

use of org.apache.tools.ant.PathTokenizer in project intellij-community by JetBrains.

the class AntDomPathElement method getFiles.

@NotNull
protected List<File> getFiles(AntDomPattern pattern, Set<AntFilesProvider> processed) {
    final List<File> files = new ArrayList<>();
    final File baseDir = getCanonicalFile(".");
    addLocation(baseDir, files, getLocation().getStringValue());
    final String pathString = getPath().getStringValue();
    if (pathString != null) {
        final PathTokenizer tokenizer = new PathTokenizer(pathString);
        while (tokenizer.hasMoreTokens()) {
            addLocation(baseDir, files, tokenizer.nextToken());
        }
    }
    return files;
}
Also used : PathTokenizer(org.apache.tools.ant.PathTokenizer) ArrayList(java.util.ArrayList) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with PathTokenizer

use of org.apache.tools.ant.PathTokenizer in project ant by apache.

the class FileUtils method translatePath.

/**
 * Translate a path into its native (platform specific) format.
 * <p>
 * This method uses PathTokenizer to separate the input path
 * into its components. This handles DOS style paths in a relatively
 * sensible way. The file separators are then converted to their platform
 * specific versions.
 *
 * @param toProcess The path to be translated.
 *                  May be <code>null</code>.
 *
 * @return the native version of the specified path or
 *         an empty string if the path is <code>null</code> or empty.
 *
 * @since ant 1.7
 * @see PathTokenizer
 */
public static String translatePath(String toProcess) {
    if (toProcess == null || toProcess.isEmpty()) {
        return "";
    }
    StringBuilder path = new StringBuilder(toProcess.length() + EXPAND_SPACE);
    PathTokenizer tokenizer = new PathTokenizer(toProcess);
    while (tokenizer.hasMoreTokens()) {
        String pathComponent = tokenizer.nextToken();
        pathComponent = pathComponent.replace('/', File.separatorChar);
        pathComponent = pathComponent.replace('\\', File.separatorChar);
        if (path.length() != 0) {
            path.append(File.pathSeparatorChar);
        }
        path.append(pathComponent);
    }
    return path.toString();
}
Also used : PathTokenizer(org.apache.tools.ant.PathTokenizer)

Example 5 with PathTokenizer

use of org.apache.tools.ant.PathTokenizer in project ant by apache.

the class Path method translatePath.

/**
 * Splits a PATH (with : or ; as separators) into its parts.
 * @param project the project to use
 * @param source a <code>String</code> value
 * @return an array of strings, one for each path element
 */
public static String[] translatePath(Project project, String source) {
    if (source == null) {
        return new String[0];
    }
    final List<String> result = new ArrayList<>();
    PathTokenizer tok = new PathTokenizer(source);
    while (tok.hasMoreTokens()) {
        StringBuffer element = new StringBuffer();
        String pathElement = tok.nextToken();
        try {
            element.append(resolveFile(project, pathElement).getPath());
        } catch (BuildException e) {
            project.log("Dropping path element " + pathElement + " as it is not valid relative to the project", Project.MSG_VERBOSE);
        }
        for (int i = 0; i < element.length(); i++) {
            translateFileSep(element, i);
        }
        result.add(element.toString());
    }
    return result.toArray(new String[result.size()]);
}
Also used : PathTokenizer(org.apache.tools.ant.PathTokenizer) ArrayList(java.util.ArrayList) BuildException(org.apache.tools.ant.BuildException)

Aggregations

PathTokenizer (org.apache.tools.ant.PathTokenizer)5 ArrayList (java.util.ArrayList)4 File (java.io.File)2 NotNull (org.jetbrains.annotations.NotNull)2 PsiReference (com.intellij.psi.PsiReference)1 BuildException (org.apache.tools.ant.BuildException)1