Skip to content

Commit

Permalink
Downgrade Java sources/tools.jar to be JDK7 compatible.
Browse files Browse the repository at this point in the history
  • Loading branch information
schroederc committed Jan 29, 2015
1 parent 78be325 commit a2824bd
Show file tree
Hide file tree
Showing 18 changed files with 132 additions and 96 deletions.
1 change: 1 addition & 0 deletions buildtools/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ function ninjaBuildHeader(engine) {
'gotool': engine.settings.properties['go_path'],
'java': engine.settings.properties['java_path'],
'javac': engine.settings.properties['javac_path'],
'javacopts': (engine.settings.properties['javac_opts'] || []).join(' '),
'javajar': engine.settings.properties['jar_path'],
'protocpath': engine.settings.properties['protoc_path']
};
Expand Down
4 changes: 2 additions & 2 deletions buildtools/rules.ninja
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ rule run_test

rule javac
command = mkdir -p $out.classes && $
'$javac' -cp '$classpath' $in -d $out.classes && $
'$javac' $javacopts -cp '$classpath' $in -d $out.classes && $
'$javajar' cf $out -C $out.classes .
description = javac $owner

Expand Down Expand Up @@ -63,7 +63,7 @@ rule linker
rule protoc_java
command = mkdir -p $out.srcs $out.classes && $
$protocpath/protoc --java_out=$out.srcs $in && $
$javac -cp $classpath -d $out.classes $$(find $out.srcs -name '*.java') && $
$javac $javacopts -cp $classpath -d $out.classes $$(find $out.srcs -name '*.java') && $
$javajar cf $out -C $out.classes .
description = protoc_java $owner

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ public EntrySet getFileNode(String digest, byte[] contents, String encoding) {
*/
public NodeBuilder newNode(NodeKind kind, Iterable<EntrySet> dependencies) {
NodeBuilder builder = newNode(kind);
dependencies.forEach(e -> builder.addSignatureSalt(e.getVName()));
for (EntrySet e : dependencies) {
builder.addSignatureSalt(e.getVName());
};
return builder;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@

package com.google.devtools.kythe.analyzers.java;

import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;

import com.google.common.base.Joiner;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import com.google.devtools.kythe.analyzers.base.EdgeKind;
import com.google.devtools.kythe.analyzers.base.EntrySet;
import com.google.devtools.kythe.common.FormattingLogger;
Expand Down Expand Up @@ -53,9 +52,9 @@
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;

/** {@link JCTreeScanner} that emits Kythe nodes and edges. */
Expand Down Expand Up @@ -89,17 +88,18 @@ public static void emitEntries(Context context, JavaEntrySets entrySets,
public JavaNode visitTopLevel(JCCompilationUnit compilation, Void v) {
EntrySet fileNode = entrySets.getFileNode(filePositions);

List<JavaNode> decls = scanList(compilation.getTypeDecls(), v).stream()
.filter(Objects::nonNull)
.collect(toList());
decls.stream()
.forEach(n -> entrySets.emitEdge(n.entries, EdgeKind.CHILDOF, fileNode));
List<JavaNode> decls = scanList(compilation.getTypeDecls(), v);
decls.removeAll(Collections.singleton(null));
for (JavaNode n : decls) {
entrySets.emitEdge(n.entries, EdgeKind.CHILDOF, fileNode);
}

if (compilation.getPackageName() != null) {
EntrySet pkgNode = entrySets.getPackageNode(compilation.packge);
emitAnchor(compilation.getPackageName(), EdgeKind.REF, pkgNode);
decls.stream()
.forEach(n -> entrySets.emitEdge(n.entries, EdgeKind.CHILDOF, pkgNode));
for (JavaNode n : decls) {
entrySets.emitEdge(n.entries, EdgeKind.CHILDOF, pkgNode);
}
}

scanList(compilation.getImports(), v);
Expand Down Expand Up @@ -145,11 +145,12 @@ public JavaNode visitClassDef(JCClassDecl classDef, Void v) {
emitEdge(classNode, EdgeKind.IMPLEMENTS, implNode);
}

classDef.getMembers().stream()
.map(member -> scan(member, v))
.filter(Objects::nonNull)
.forEach(member ->
entrySets.emitEdge(member.entries, EdgeKind.CHILDOF, classNode));
for (JCTree member : classDef.getMembers()) {
JavaNode n = scan(member, v);
if (n != null) {
entrySets.emitEdge(n.entries, EdgeKind.CHILDOF, classNode);
}
}

return new JavaNode(classNode, signature.get());
}
Expand All @@ -161,6 +162,10 @@ public JavaNode visitMethodDef(JCMethodDecl methodDef, Void v) {
scan(methodDef.getBody(), v);
JavaNode returnType = scan(methodDef.getReturnType(), v);
List<JavaNode> params = scanList(methodDef.getParameters(), v);
List<EntrySet> paramTypes = Lists.newLinkedList();
for (JavaNode n : params) {
paramTypes.add(n.typeNode);
}

Optional<String> signature = signatureGenerator.getSignature(methodDef.sym);
if (signature.isPresent()) {
Expand All @@ -183,9 +188,7 @@ public JavaNode visitMethodDef(JCMethodDecl methodDef, Void v) {
}

emitOrdinalEdges(methodNode, EdgeKind.PARAM, params);
EntrySet fnTypeNode = entrySets.newFunctionType(ret, params.stream()
.map(n -> n.typeNode)
.collect(toList()));
EntrySet fnTypeNode = entrySets.newFunctionType(ret, paramTypes);
entrySets.emitEdge(methodNode, EdgeKind.TYPED, fnTypeNode);

ClassSymbol ownerClass = (ClassSymbol) methodDef.sym.owner;
Expand Down Expand Up @@ -230,15 +233,18 @@ public JavaNode visitTypeApply(JCTypeApply tApply, Void v) {
JavaNode typeCtorNode = scan(tApply.getType(), v);

List<JavaNode> arguments = scanList(tApply.getTypeArguments(), v);
List<EntrySet> argEntries = arguments.stream()
.map(n -> n.entries)
.collect(toList());
List<EntrySet> argEntries = Lists.newLinkedList();
List<String> argNames = Lists.newLinkedList();
for (JavaNode n : arguments) {
argEntries.add(n.entries);
argNames.add(n.qualifiedName);
}

EntrySet typeNode = entrySets.newTApply(typeCtorNode.entries, argEntries);
emitAnchor(tApply, EdgeKind.REF, typeNode);

String qualifiedName = typeCtorNode.qualifiedName
+ "<" + arguments.stream().map(n -> n.qualifiedName).collect(joining(",")) + ">";
+ "<" + Joiner.on(',').join(argNames) + ">";
entrySets.emitName(typeNode, qualifiedName);

return new JavaNode(typeNode, qualifiedName);
Expand Down Expand Up @@ -364,8 +370,11 @@ private void emitEdge(EntrySet sourceNode, EdgeKind kind, JavaNode target) {

// Unwraps each target EntrySet and emits an ordinal edge to each from the given source node
private void emitOrdinalEdges(EntrySet node, EdgeKind kind, List<JavaNode> targets) {
entrySets.emitOrdinalEdges(node, kind,
targets.stream().map(n -> n.entries).collect(toList()));
List<EntrySet> entries = Lists.newLinkedList();
for (JavaNode n : targets) {
entries.add(n.entries);
}
entrySets.emitOrdinalEdges(node, kind, entries);
}

@Deprecated
Expand All @@ -375,7 +384,11 @@ private JavaNode todoNode(String message) {
}

private <T extends JCTree> List<JavaNode> scanList(List<T> trees, Void v) {
return trees.stream().map(t -> scan(t, v)).collect(toList());
List<JavaNode> nodes = Lists.newLinkedList();
for (T t : trees) {
nodes.add(scan(t, v));
}
return nodes;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package com.google.devtools.kythe.extractors.java;

import static java.util.stream.Collectors.toList;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Charsets;
import com.google.common.base.Joiner;
Expand Down Expand Up @@ -225,26 +223,25 @@ public CompilationDescription extract(String target, Iterable<String> sources,
sourcepath, processorpath, processors, options, outputPath);

List<FileData> fileContents = ExtractorUtils.convertBytesToFileDatas(results.fileContents);
List<FileInput> compilationFileInputs = fileContents.stream()
.map(data -> {
String relativePath = results.relativePaths.get(data.getInfo().getPath());
VName vname = fileVNames.lookupBaseVName(relativePath);
if (vname.getPath() == "") {
vname = vname.toBuilder().setPath(data.getInfo().getPath()).build();
}
String sourceBasename = results.sourceFileNames.get(data.getInfo().getPath());
if (sourceBasename != null && vname.getPath().endsWith(".java")
&& !vname.getPath().endsWith(sourceBasename)) {
Path fixedPath = Paths.get(vname.getPath()).getParent().resolve(sourceBasename);
vname = vname.toBuilder().setPath(fixedPath.toString()).build();
}
return FileInput.newBuilder()
.setInfo(data.getInfo())
.setVName(vname)
.build();
})
.sorted(CompilationFileInputComparator.getComparator())
.collect(toList());
List<FileInput> compilationFileInputs = Lists.newLinkedList();
for (FileData data : fileContents) {
String relativePath = results.relativePaths.get(data.getInfo().getPath());
VName vname = fileVNames.lookupBaseVName(relativePath);
if (vname.getPath() == "") {
vname = vname.toBuilder().setPath(data.getInfo().getPath()).build();
}
String sourceBasename = results.sourceFileNames.get(data.getInfo().getPath());
if (sourceBasename != null && vname.getPath().endsWith(".java")
&& !vname.getPath().endsWith(sourceBasename)) {
Path fixedPath = Paths.get(vname.getPath()).getParent().resolve(sourceBasename);
vname = vname.toBuilder().setPath(fixedPath.toString()).build();
}
compilationFileInputs.add(FileInput.newBuilder()
.setInfo(data.getInfo())
.setVName(vname)
.build());
}
Collections.sort(compilationFileInputs, CompilationFileInputComparator.getComparator());

CompilationUnit compilationUnit = buildCompilationUnit(target, removeOutputDirOption(options),
compilationFileInputs, results.hasErrors, results.newSourcePath, results.newClassPath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ public static FileVNames staticCorpus(String corpus) {
}

public static FileVNames fromFile(String configFile) throws IOException {
return new FileVNames(GSON.fromJson(new FileReader(configFile), CONFIG_TYPE));
return new FileVNames(GSON.<List<BaseFileVName>>fromJson(new FileReader(configFile), CONFIG_TYPE));
}

public static FileVNames fromJson(String json) {
return new FileVNames(GSON.fromJson(json, CONFIG_TYPE));
return new FileVNames(GSON.<List<BaseFileVName>>fromJson(json, CONFIG_TYPE));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

package com.google.devtools.kythe.platform.indexpack;

import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
import com.google.common.base.Throwables;
import com.google.common.collect.Iterables;
import com.google.common.collect.Iterators;
Expand All @@ -25,6 +27,7 @@
import com.google.common.io.ByteStreams;
import com.google.devtools.kythe.extractors.shared.CompilationDescription;
import com.google.devtools.kythe.proto.Analysis.CompilationUnit;
import com.google.devtools.kythe.proto.Analysis.CompilationUnit.FileInput;
import com.google.devtools.kythe.proto.Analysis.FileData;
import com.google.devtools.kythe.util.JsonUtil;
import com.google.gson.Gson;
Expand Down Expand Up @@ -53,7 +56,6 @@
import java.nio.file.Paths;
import java.util.Iterator;
import java.util.UUID;
import java.util.Objects;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;

Expand Down Expand Up @@ -127,20 +129,28 @@ public Path getRoot() {
* each unit's required inputs.
*/
public Iterator<CompilationDescription> readDescriptions() throws IOException {
return Iterators.transform(readUnits(), this::completeDescription);
return Iterators.transform(readUnits(), new Function<CompilationUnit, CompilationDescription>() {
@Override
public CompilationDescription apply(CompilationUnit unit) {
return completeDescription(unit);
}
});
}

/** Returns a complete {@link CompilationDescription} of the given {@link CompilationUnit}. */
public CompilationDescription completeDescription(CompilationUnit unit) {
return new CompilationDescription(unit, Iterables.transform(unit.getRequiredInputList(),
(input) -> {
try {
return FileData.newBuilder()
.setInfo(input.getInfo())
.setContent(ByteString.copyFrom(readFile(input.getInfo().getDigest())))
.build();
} catch (IOException ioe) {
throw Throwables.propagate(ioe);
new Function<FileInput, FileData>() {
@Override
public FileData apply(FileInput input) {
try {
return FileData.newBuilder()
.setInfo(input.getInfo())
.setContent(ByteString.copyFrom(readFile(input.getInfo().getDigest())))
.build();
} catch (IOException ioe) {
throw Throwables.propagate(ioe);
}
}
}));
}
Expand Down Expand Up @@ -168,23 +178,31 @@ public CompilationUnit readUnit(String key) throws IOException {
}

/** Returns an {@link Iterator} of the units stored in the archive with a given format key. */
public <T> Iterator<T> readUnits(final String formatKey, Class<T> cls) throws IOException {
public <T> Iterator<T> readUnits(final String formatKey, final Class<T> cls) throws IOException {
Preconditions.checkNotNull(formatKey);
return Iterators.filter(
Iterators.transform(Files.newDirectoryStream(unitDir, "*" + UNIT_SUFFIX).iterator(),
(path) -> {
try {
String name = path.getFileName().toString();
if (!name.endsWith(UNIT_SUFFIX)) {
throw new IllegalStateException("Received path without unit suffix: " + path);
new Function<Path, T>() {
@Override
public T apply(Path path) {
try {
String name = path.getFileName().toString();
if (!name.endsWith(UNIT_SUFFIX)) {
throw new IllegalStateException("Received path without unit suffix: " + path);
}
String key = name.substring(0, name.length() - UNIT_SUFFIX.length());
return readUnit(key, formatKey, cls);
} catch (IOException ioe) {
throw Throwables.propagate(ioe);
}
String key = name.substring(0, name.length() - UNIT_SUFFIX.length());
return readUnit(key, formatKey, cls);
} catch (IOException ioe) {
throw Throwables.propagate(ioe);
}
}),
Objects::nonNull);
new Predicate<T>() {
@Override
public boolean apply(T unit) {
return unit != null;
}
});
}

/**
Expand Down Expand Up @@ -291,7 +309,7 @@ public JsonElement serialize(UnitWrapper unit, Type t, JsonSerializationContext
public UnitWrapper deserialize(JsonElement json, Type t, JsonDeserializationContext ctx) {
JsonObject obj = json.getAsJsonObject();
return new UnitWrapper(
ctx.deserialize(obj.get(FORMAT_KEY_LABEL), String.class),
ctx.<String>deserialize(obj.get(FORMAT_KEY_LABEL), String.class),
obj.get(CONTENT_LABEL));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public boolean apply(Diagnostic<?> diag) {

public static JavaCompilationDetails createDetails(CompilationUnit compilationUnit,
FileDataProvider fileDataProvider, boolean useStdErr) {
return createDetails(compilationUnit, fileDataProvider, false, ImmutableList.of(), useStdErr);
return createDetails(
compilationUnit, fileDataProvider, false, ImmutableList.<Processor>of(), useStdErr);
}

public static JavaCompilationDetails createDetails(CompilationUnit compilationUnit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public Future<byte[]> startLookup(String path, String digest) {
byte[] content = fileContents.get(digest);
return content != null
? Futures.immediateFuture(content)
: Futures.immediateFailedFuture(new RuntimeException(
: Futures.<byte[]>immediateFailedFuture(new RuntimeException(
"Cache does not contain file for digest: " + digest));
}
}
1 change: 1 addition & 0 deletions kythe/java/com/google/devtools/kythe/util/CAMPFIRE
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"jars": [
"//third_party/gson",
"//third_party/gson:proto",
"//third_party/guava",
"//third_party/protobuf:protobuf_jar"
]
}
Expand Down
Loading

0 comments on commit a2824bd

Please sign in to comment.