use of com.google.devtools.j2objc.file.InputFile in project j2objc by google.
the class GenerationBatch method processJarFile.
private void processJarFile(String filename) {
File f = findJarFile(filename);
if (f == null) {
ErrorUtil.error("No such file: " + filename);
return;
}
// don't support Java-like source paths.
if (options.emitLineDirectives()) {
ErrorUtil.warning("source debugging of jar files is not supported: " + filename);
}
GenerationUnit combinedUnit = null;
if (options.getHeaderMap().combineSourceJars()) {
combinedUnit = GenerationUnit.newCombinedJarUnit(filename, options);
}
try {
ZipFile zfile = new ZipFile(f);
try {
Enumeration<? extends ZipEntry> enumerator = zfile.entries();
File tempDir = FileUtil.createTempDir(J2OBJC_TEMP_DIR_PREFIX);
String tempDirPath = tempDir.getAbsolutePath();
options.fileUtil().addTempDir(tempDirPath);
options.fileUtil().appendSourcePath(tempDirPath);
while (enumerator.hasMoreElements()) {
ZipEntry entry = enumerator.nextElement();
String internalPath = entry.getName();
if (internalPath.endsWith(".java")) {
// Extract JAR file to a temporary directory
File outputFile = options.fileUtil().extractZipEntry(tempDir, zfile, entry);
InputFile newFile = new RegularInputFile(outputFile.getAbsolutePath(), internalPath);
if (combinedUnit != null) {
inputs.add(new ProcessingContext(newFile, combinedUnit));
} else {
addExtractedJarSource(newFile, filename, internalPath);
}
}
}
} finally {
// Also closes input stream.
zfile.close();
}
} catch (ZipException e) {
// Also catches JarExceptions
logger.fine(e.getMessage());
ErrorUtil.error("Error reading file " + filename + " as a zip or jar file.");
} catch (IOException e) {
ErrorUtil.error(e.getMessage());
}
}
use of com.google.devtools.j2objc.file.InputFile in project j2objc by google.
the class InputFilePreprocessor method processPackageInfoSource.
private void processPackageInfoSource(ProcessingContext input) throws IOException {
InputFile file = input.getFile();
String source = options.fileUtil().readFile(file);
CompilationUnit compilationUnit = parser.parse(FileUtil.getMainTypeName(file), file.getUnitName(), source);
if (compilationUnit != null) {
extractPackagePrefix(file, compilationUnit);
}
}
use of com.google.devtools.j2objc.file.InputFile in project j2objc by google.
the class BuildClosureQueue method getFileForName.
private InputFile getFileForName(String name) {
// Check if class exists on classpath.
if (findClassFile(name)) {
logger.finest("no source for " + name + ", class found");
return null;
}
InputFile inputFile = null;
try {
inputFile = options.fileUtil().findOnSourcePath(name);
} catch (IOException e) {
ErrorUtil.warning(e.getMessage());
}
if (inputFile == null) {
return null;
}
// Check if the source file is older than the generated header file.
File headerSource = new File(options.fileUtil().getOutputDirectory(), name.replace('.', File.separatorChar) + ".h");
if (headerSource.exists() && inputFile.lastModified() < headerSource.lastModified()) {
return null;
}
return inputFile;
}
use of com.google.devtools.j2objc.file.InputFile in project j2objc by google.
the class BuildClosureQueue method getNextFile.
/**
* Returns the next Java source file to be processed. Returns null if the
* queue is empty.
*/
public InputFile getNextFile() {
for (Iterator<String> iter = queuedNames.iterator(); iter.hasNext(); ) {
String name = iter.next();
iter.remove();
processedNames.add(name);
InputFile file = getFileForName(name);
if (file != null) {
return file;
}
}
return null;
}
use of com.google.devtools.j2objc.file.InputFile in project j2objc by google.
the class InputFilePreprocessor method processRegularSource.
private void processRegularSource(ProcessingContext input) throws IOException {
InputFile file = input.getFile();
String source = options.fileUtil().readFile(file);
boolean shouldMapHeaders = options.getHeaderMap().useSourceDirectories();
boolean doIncompatibleStripping = source.contains("J2ObjCIncompatible");
if (!(shouldMapHeaders || doIncompatibleStripping)) {
// No need to parse.
return;
}
Parser.ParseResult parseResult = parser.parseWithoutBindings(file, source);
if (parseResult == null) {
// The parser found and reported one or more errors.
return;
}
String qualifiedName = parseResult.mainTypeName();
if (shouldMapHeaders) {
options.getHeaderMap().put(qualifiedName, input.getGenerationUnit().getOutputPath() + ".h");
}
if (doIncompatibleStripping) {
parseResult.stripIncompatibleSource();
File strippedDir = getCreatedStrippedSourcesDir();
String relativePath = qualifiedName.replace('.', File.separatorChar) + ".java";
File strippedFile = new File(strippedDir, relativePath);
Files.createParentDirs(strippedFile);
Files.write(parseResult.getSource(), strippedFile, options.fileUtil().getCharset());
input.setFile(new RegularInputFile(strippedFile.getPath(), relativePath));
}
}
Aggregations