Search in sources :

Example 1 with JarredInputFile

use of com.google.devtools.j2objc.file.JarredInputFile 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 JarredInputFile

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

the class FileUtilTest method testJarSourceExists.

// Verify that source exists in a jar file.
public void testJarSourceExists() throws IOException {
    File file = new File(getResourceAsFile("example.jar"));
    JarredInputFile jarEntry = new JarredInputFile(file.getPath(), "com/google/test/package-info.java");
    assertTrue(jarEntry.exists());
}
Also used : JarredInputFile(com.google.devtools.j2objc.file.JarredInputFile) File(java.io.File) JarredInputFile(com.google.devtools.j2objc.file.JarredInputFile)

Example 3 with JarredInputFile

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

the class FileUtilTest method testReadJarSource.

// Verify that source can be read from a jar file. Reading from
// files doesn't need testing, since j2objc itself can't build
// without being able to do so.
public void testReadJarSource() throws IOException {
    File file = new File(getResourceAsFile("example.jar"));
    JarredInputFile jarEntry = new JarredInputFile(file.getPath(), "com/google/test/package-info.java");
    String source = options.fileUtil().readFile(jarEntry);
    assertTrue(source.contains("package com.google.test;"));
}
Also used : JarredInputFile(com.google.devtools.j2objc.file.JarredInputFile) File(java.io.File) JarredInputFile(com.google.devtools.j2objc.file.JarredInputFile)

Example 4 with JarredInputFile

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

the class TranslationProcessorTest method testJarBatchTranslation.

public void testJarBatchTranslation() throws IOException {
    String fooSource = "package mypkg; class Foo {}";
    String barSource = "package mypkg; class Bar {}";
    File jarFile = getTempFile("test.jar");
    JarOutputStream jar = new JarOutputStream(new FileOutputStream(jarFile));
    try {
        JarEntry fooEntry = new JarEntry("mypkg/Foo.java");
        jar.putNextEntry(fooEntry);
        jar.write(fooSource.getBytes());
        jar.closeEntry();
        JarEntry barEntry = new JarEntry("mypkg/Bar.java");
        jar.putNextEntry(barEntry);
        jar.write(barSource.getBytes());
        jar.closeEntry();
    } finally {
        jar.close();
    }
    options.fileUtil().appendSourcePath(jarFile.getPath());
    options.setBatchTranslateMaximum(2);
    GenerationBatch batch = new GenerationBatch(options);
    batch.addSource(new JarredInputFile(getTempDir() + "/test.jar", "mypkg/Foo.java"));
    batch.addSource(new JarredInputFile(getTempDir() + "/test.jar", "mypkg/Bar.java"));
    TranslationProcessor processor = new TranslationProcessor(J2ObjC.createParser(options), null);
    processor.processInputs(batch.getInputs());
    assertEquals(0, ErrorUtil.errorCount());
}
Also used : FileOutputStream(java.io.FileOutputStream) JarOutputStream(java.util.jar.JarOutputStream) JarEntry(java.util.jar.JarEntry) JarredInputFile(com.google.devtools.j2objc.file.JarredInputFile) RegularInputFile(com.google.devtools.j2objc.file.RegularInputFile) File(java.io.File) JarredInputFile(com.google.devtools.j2objc.file.JarredInputFile)

Aggregations

JarredInputFile (com.google.devtools.j2objc.file.JarredInputFile)4 File (java.io.File)4 RegularInputFile (com.google.devtools.j2objc.file.RegularInputFile)2 InputFile (com.google.devtools.j2objc.file.InputFile)1 FileOutputStream (java.io.FileOutputStream)1 JarEntry (java.util.jar.JarEntry)1 JarOutputStream (java.util.jar.JarOutputStream)1 ZipFile (java.util.zip.ZipFile)1