Search in sources :

Example 46 with VisibleForTesting

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.annotations.VisibleForTesting in project buck by facebook.

the class CxxLinkableEnhancer method frameworksToLinkerArg.

@VisibleForTesting
static Arg frameworksToLinkerArg(ImmutableSortedSet<FrameworkPath> frameworkPaths) {
    return new FrameworkPathArg(frameworkPaths) {

        @Override
        public void appendToCommandLine(ImmutableCollection.Builder<String> builder, SourcePathResolver pathResolver) {
            for (FrameworkPath frameworkPath : frameworkPaths) {
                builder.add("-framework");
                builder.add(frameworkPath.getName(pathResolver::getAbsolutePath));
            }
        }
    };
}
Also used : SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 47 with VisibleForTesting

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.annotations.VisibleForTesting in project buck by facebook.

the class BuckDeps method maybeAddDepToTarget.

/**
   * Given the contents of a BUCK file, try to modify the
   * contents to add the given dependency to the given
   * target.
   */
@VisibleForTesting
static String maybeAddDepToTarget(String buckContents, String dependency, String target) {
    int[] targetOffset = findTargetInBuckFileContents(buckContents, target);
    if (targetOffset == null) {
        LOG.warn("Couldn't find target definition for " + target);
        // TODO(ideabuck):  make this a better parser
        return buckContents;
    }
    String targetDef = buckContents.substring(targetOffset[0], targetOffset[1]);
    if (autodepsPattern.matcher(targetDef).find()) {
        // TODO(ideabuck):  Once 'buck autodeps' stabilizes, should we invoke it here?
        return buckContents;
    }
    Matcher exportedDepsMatcher = exportedDepsPattern.matcher(targetDef);
    if (exportedDepsMatcher.find()) {
        String exportedDeps = exportedDepsMatcher.group(1);
        if (exportedDeps.contains(dependency)) {
            // If it already appears in the exported_deps section, nothing to do
            return buckContents;
        }
    }
    Matcher depsMatcher = depsPattern.matcher(targetDef);
    if (!depsMatcher.find()) {
        LOG.warn("Couldn't figure out where to add new dependency on " + dependency + " in definition for " + target);
        return buckContents;
    }
    if (depsMatcher.group(1).contains(dependency)) {
        // already have dep in the deps section
        return buckContents;
    }
    int offset = targetOffset[0] + depsMatcher.start(1);
    return buckContents.substring(0, offset) + "\n\t\t'" + dependency + "'," + buckContents.substring(offset);
}
Also used : Matcher(java.util.regex.Matcher) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 48 with VisibleForTesting

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.annotations.VisibleForTesting in project buck by facebook.

the class BuckDeps method maybeAddVisibilityToTarget.

@VisibleForTesting
static String maybeAddVisibilityToTarget(String buckContents, String visibility, String target) {
    int[] targetOffset = findTargetInBuckFileContents(buckContents, target);
    if (targetOffset == null) {
        LOG.warn("Couldn't find target definition for " + target);
        // TODO(ideabuck):  make this a better parser
        return buckContents;
    }
    String targetDef = buckContents.substring(targetOffset[0], targetOffset[1]);
    Matcher visibilityMatcher = visibilityPattern.matcher(targetDef);
    if (!visibilityMatcher.find()) {
        LOG.warn("Couldn't figure out where to increase visibility for " + target + " to include " + visibility);
        // TODO(ideabuck):  try harder to figure out where to add the visibility
        return buckContents;
    }
    if (visibilityMatcher.group(1).contains(visibility)) {
        // already visibile to this caller
        return buckContents;
    }
    int offset = targetOffset[0] + visibilityMatcher.start(1);
    buckContents = buckContents.substring(0, offset) + "\n\t\t'" + visibility + "'," + buckContents.substring(offset);
    return buckContents;
}
Also used : Matcher(java.util.regex.Matcher) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 49 with VisibleForTesting

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.annotations.VisibleForTesting in project buck by facebook.

the class JavacStep method findFailedImports.

@VisibleForTesting
static ImmutableSet<String> findFailedImports(String output) {
    Iterable<String> lines = Splitter.on(LINE_SEPARATOR).split(output);
    ImmutableSortedSet.Builder<String> failedImports = ImmutableSortedSet.naturalOrder();
    for (String line : lines) {
        if (IS_WARNING.matcher(line).find()) {
            continue;
        }
        for (Pattern missingImportPattern : MISSING_IMPORT_PATTERNS) {
            Matcher lineMatch = missingImportPattern.matcher(line);
            if (lineMatch.matches()) {
                failedImports.add(lineMatch.group(1));
                break;
            }
        }
    }
    return failedImports.build();
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 50 with VisibleForTesting

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.annotations.VisibleForTesting in project buck by facebook.

the class BlockingHttpEndpoint method send.

@VisibleForTesting
HttpResponse send(final HttpURLConnection connection, final String content) throws IOException {
    try (DataOutputStream out = new DataOutputStream(connection.getOutputStream())) {
        out.writeBytes(content);
        out.flush();
        out.close();
        InputStream inputStream = connection.getInputStream();
        String response = CharStreams.toString(new InputStreamReader(inputStream, Charsets.UTF_8));
        return new HttpResponse(response);
    } finally {
        connection.disconnect();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) DataOutputStream(java.io.DataOutputStream) InputStream(java.io.InputStream) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1955 IOException (java.io.IOException)284 ArrayList (java.util.ArrayList)214 Map (java.util.Map)156 HashMap (java.util.HashMap)147 List (java.util.List)113 File (java.io.File)94 ImmutableMap (com.google.common.collect.ImmutableMap)72 HashSet (java.util.HashSet)67 Path (org.apache.hadoop.fs.Path)63 ImmutableList (com.google.common.collect.ImmutableList)60 Path (java.nio.file.Path)60 Set (java.util.Set)52 Matcher (java.util.regex.Matcher)46 Collectors (java.util.stream.Collectors)46 Collection (java.util.Collection)39 Optional (java.util.Optional)38 NotNull (org.jetbrains.annotations.NotNull)37 ImmutableSet (com.google.common.collect.ImmutableSet)34 TreeMap (java.util.TreeMap)34