use of com.google.idea.blaze.base.io.InputStreamProvider in project intellij by bazelbuild.
the class JavaSourcePackageReader method getDeclaredPackageOfJavaFile.
@Override
@Nullable
public String getDeclaredPackageOfJavaFile(BlazeContext context, ArtifactLocationDecoder artifactLocationDecoder, SourceArtifact sourceArtifact) {
if (sourceArtifact.artifactLocation.isGenerated()) {
return null;
}
InputStreamProvider inputStreamProvider = InputStreamProvider.getInstance();
File sourceFile = artifactLocationDecoder.decode(sourceArtifact.artifactLocation);
try (InputStream javaInputStream = inputStreamProvider.getFile(sourceFile)) {
BufferedReader javaReader = new BufferedReader(new InputStreamReader(javaInputStream, UTF_8));
String javaLine;
while ((javaLine = javaReader.readLine()) != null) {
Matcher packageMatch = PACKAGE_PATTERN.matcher(javaLine);
if (packageMatch.find()) {
return packageMatch.group(1);
}
}
IssueOutput.warn("No package name string found in java source file: " + sourceFile).inFile(sourceFile).submit(context);
return null;
} catch (FileNotFoundException e) {
IssueOutput.warn("No source file found for: " + sourceFile).inFile(sourceFile).submit(context);
return null;
} catch (IOException e) {
logger.error(e);
return null;
}
}
use of com.google.idea.blaze.base.io.InputStreamProvider in project intellij by bazelbuild.
the class PackageManifestReader method parseManifestFile.
private static Map<ArtifactLocation, String> parseManifestFile(File packageManifest) {
Map<ArtifactLocation, String> outputMap = Maps.newHashMap();
InputStreamProvider inputStreamProvider = InputStreamProvider.getInstance();
try (InputStream input = inputStreamProvider.getFile(packageManifest)) {
try (BufferedInputStream bufferedInputStream = new BufferedInputStream(input)) {
PackageManifest proto = PackageManifest.parseFrom(bufferedInputStream);
for (JavaSourcePackage source : proto.getSourcesList()) {
outputMap.put(fromProto(source.getArtifactLocation()), source.getPackageString());
}
}
return outputMap;
} catch (IOException e) {
logger.error(e);
return outputMap;
}
}
Aggregations