Skip to content

Commit

Permalink
Merge c61243b into d0c921d
Browse files Browse the repository at this point in the history
  • Loading branch information
lazaroclapp committed Jul 19, 2019
2 parents d0c921d + c61243b commit 057d44d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
Expand Up @@ -162,7 +162,16 @@ public MethodParamAnnotations run(
for (String inPath : setInPaths) {
analyzeFile(pkgName, inPath);
if (this.annotateBytecode) {
writeAnnotations(inPath, outPath);
String outFile = outPath;
if (setInPaths.size() > 1) {
outFile =
outPath
+ "/"
+ FilenameUtils.getBaseName(inPath)
+ "-annotated."
+ FilenameUtils.getExtension(inPath);
}
writeAnnotations(inPath, outFile);
}
}
if (!this.annotateBytecode) {
Expand Down Expand Up @@ -388,19 +397,13 @@ private void writeModel(DataOutputStream out) throws IOException {
StubxWriter.write(out, importedAnnotations, packageAnnotations, typeAnnotations, methodRecords);
}

private void writeAnnotations(String inPath, String outPath) throws IOException {
private void writeAnnotations(String inPath, String outFile) throws IOException {
Preconditions.checkArgument(
inPath.endsWith(".jar") || inPath.endsWith(".class"), "invalid input path - " + inPath);
LOG(DEBUG, "DEBUG", "Writing Annotations to " + outPath);
LOG(DEBUG, "DEBUG", "Writing Annotations to " + outFile);

String outFile;
new File(outFile).getParentFile().mkdirs();
if (inPath.endsWith(".jar")) {
outFile =
outPath
+ "/"
+ FilenameUtils.getBaseName(inPath)
+ "-annotated."
+ FilenameUtils.getExtension(inPath);
JarFile jar = new JarFile(inPath);
JarOutputStream jarOS = new JarOutputStream(new FileOutputStream(outFile));
BytecodeAnnotator.annotateBytecodeInJar(jar, jarOS, nonnullParams, nullableReturns, DEBUG);
Expand All @@ -409,7 +412,7 @@ private void writeAnnotations(String inPath, String outPath) throws IOException
// TODO(ragr@): Handle this case.
} else {
InputStream is = new FileInputStream(inPath);
OutputStream os = new FileOutputStream(outPath);
OutputStream os = new FileOutputStream(outFile);
BytecodeAnnotator.annotateBytecodeInClass(is, os, nonnullParams, nullableReturns, DEBUG);
os.close();
}
Expand Down
Expand Up @@ -109,11 +109,11 @@ private void testAnnotationInJarTemplate(
Map<String, String> expectedToActualAnnotationsMap)
throws Exception {
String outputFolderPath = outputFolder.newFolder(pkg).getAbsolutePath();
DefinitelyDerefedParamsDriver driver = new DefinitelyDerefedParamsDriver();
driver.runAndAnnotate(inputJarPath, "", outputFolderPath);

String inputJarName = FilenameUtils.getBaseName(inputJarPath);
String outputJarPath = outputFolderPath + "/" + inputJarName + "-annotated.jar";
DefinitelyDerefedParamsDriver driver = new DefinitelyDerefedParamsDriver();
driver.runAndAnnotate(inputJarPath, "", outputJarPath);

Assert.assertTrue(
testName + ": generated jar does not match the expected jar!",
AnnotationChecker.checkMethodAnnotationsInJar(
Expand Down

0 comments on commit 057d44d

Please sign in to comment.