Search in sources :

Example 1 with InputFile

use of com.google.devtools.j2objc.file.InputFile in project j2objc by google.

the class FileUtil method findOnPaths.

private static InputFile findOnPaths(String qualifiedName, List<String> paths, String extension) throws IOException {
    String sourceFileName = qualifiedName.replace('.', File.separatorChar) + extension;
    // Zip/jar files always use forward slashes.
    String jarEntryName = qualifiedName.replace('.', '/') + extension;
    for (String pathEntry : paths) {
        File f = new File(pathEntry);
        if (f.isDirectory()) {
            RegularInputFile regularFile = new RegularInputFile(pathEntry + File.separatorChar + sourceFileName, sourceFileName);
            if (regularFile.exists()) {
                return regularFile;
            }
        } else {
            // Assume it's a jar file
            JarredInputFile jarFile = new JarredInputFile(pathEntry, jarEntryName);
            if (jarFile.exists()) {
                return jarFile;
            }
        }
    }
    return null;
}
Also used : RegularInputFile(com.google.devtools.j2objc.file.RegularInputFile) InputFile(com.google.devtools.j2objc.file.InputFile) RegularInputFile(com.google.devtools.j2objc.file.RegularInputFile) File(java.io.File) JarredInputFile(com.google.devtools.j2objc.file.JarredInputFile) ZipFile(java.util.zip.ZipFile) JarredInputFile(com.google.devtools.j2objc.file.JarredInputFile)

Example 2 with InputFile

use of com.google.devtools.j2objc.file.InputFile in project j2objc by google.

the class PackageInfoLookup method findPackageData.

private PackageData findPackageData(String packageName) {
    try {
        String fileName = packageName + ".package-info";
        // First look on the sourcepath.
        InputFile sourceFile = fileUtil.findOnSourcePath(fileName);
        if (sourceFile != null) {
            return parseDataFromSourceFile(sourceFile);
        }
        // Then look on the classpath.
        InputFile classFile = fileUtil.findOnClassPath(fileName);
        if (classFile != null) {
            return parseDataFromClassFile(classFile);
        }
    } catch (IOException e) {
    // Continue with no package-info data.
    }
    return EMPTY_DATA;
}
Also used : IOException(java.io.IOException) InputFile(com.google.devtools.j2objc.file.InputFile)

Example 3 with InputFile

use of com.google.devtools.j2objc.file.InputFile in project j2objc by google.

the class FileProcessor method processBuildClosureDependencies.

public void processBuildClosureDependencies() {
    if (closureQueue != null) {
        while (true) {
            InputFile file = closureQueue.getNextFile();
            if (file == null) {
                processBatch();
                file = closureQueue.getNextFile();
            }
            if (file == null) {
                break;
            }
            processInput(ProcessingContext.fromFile(file, options));
        }
    }
}
Also used : InputFile(com.google.devtools.j2objc.file.InputFile)

Example 4 with InputFile

use of com.google.devtools.j2objc.file.InputFile in project j2objc by google.

the class FileProcessor method processInput.

private void processInput(ProcessingContext input) {
    try {
        InputFile file = input.getFile();
        if (isBatchable(file)) {
            batchInputs.add(input);
            if (batchInputs.size() == batchSize) {
                processBatch();
            }
            return;
        }
        logger.finest("parsing " + file);
        CompilationUnit compilationUnit = parser.parse(file);
        if (compilationUnit == null) {
            handleError(input);
            return;
        }
        processCompiledSource(input, compilationUnit);
    } catch (RuntimeException | Error e) {
        ErrorUtil.fatalError(e, input.getOriginalSourcePath());
    }
}
Also used : CompilationUnit(com.google.devtools.j2objc.ast.CompilationUnit) InputFile(com.google.devtools.j2objc.file.InputFile)

Example 5 with InputFile

use of com.google.devtools.j2objc.file.InputFile in project j2objc by google.

the class GenerationBatch method processJavaFile.

private void processJavaFile(String filename) {
    InputFile inputFile;
    try {
        inputFile = new RegularInputFile(filename, filename);
        if (!inputFile.exists()) {
            // Convert to a qualified name and search on the sourcepath.
            String qualifiedName = filename.substring(0, filename.length() - 5).replace(File.separatorChar, '.');
            inputFile = options.fileUtil().findOnSourcePath(qualifiedName);
            if (inputFile == null) {
                ErrorUtil.error("No such file: " + filename);
                return;
            }
        }
    } catch (IOException e) {
        ErrorUtil.warning(e.getMessage());
        return;
    }
    addSource(inputFile);
}
Also used : RegularInputFile(com.google.devtools.j2objc.file.RegularInputFile) IOException(java.io.IOException) InputFile(com.google.devtools.j2objc.file.InputFile) RegularInputFile(com.google.devtools.j2objc.file.RegularInputFile)

Aggregations

InputFile (com.google.devtools.j2objc.file.InputFile)10 RegularInputFile (com.google.devtools.j2objc.file.RegularInputFile)5 File (java.io.File)4 IOException (java.io.IOException)4 CompilationUnit (com.google.devtools.j2objc.ast.CompilationUnit)2 ZipFile (java.util.zip.ZipFile)2 JarredInputFile (com.google.devtools.j2objc.file.JarredInputFile)1 GenerationUnit (com.google.devtools.j2objc.gen.GenerationUnit)1 Parser (com.google.devtools.j2objc.util.Parser)1 ZipEntry (java.util.zip.ZipEntry)1 ZipException (java.util.zip.ZipException)1