Search in sources :

Example 1 with InputStreamProvider

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;
    }
}
Also used : InputStreamProvider(com.google.idea.blaze.base.io.InputStreamProvider) InputStreamReader(java.io.InputStreamReader) Matcher(java.util.regex.Matcher) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) File(java.io.File) Nullable(javax.annotation.Nullable)

Example 2 with InputStreamProvider

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;
    }
}
Also used : InputStreamProvider(com.google.idea.blaze.base.io.InputStreamProvider) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) PackageManifest(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.PackageManifest) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) JavaSourcePackage(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.JavaSourcePackage) IOException(java.io.IOException)

Aggregations

InputStreamProvider (com.google.idea.blaze.base.io.InputStreamProvider)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 JavaSourcePackage (com.google.devtools.intellij.ideinfo.IntellijIdeInfo.JavaSourcePackage)1 PackageManifest (com.google.devtools.intellij.ideinfo.IntellijIdeInfo.PackageManifest)1 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)1 BufferedInputStream (java.io.BufferedInputStream)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStreamReader (java.io.InputStreamReader)1 Matcher (java.util.regex.Matcher)1 Nullable (javax.annotation.Nullable)1