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;
}
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());
}
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;"));
}
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());
}
Aggregations