Exemplo n.º 1
0
  private static Optional<Map<String, String>> loadOptionalRawMap(
      ExecutionContext context,
      Optional<Path> proguardFullConfigFile,
      Optional<Path> proguardMappingFile)
      throws IOException {
    if (!proguardFullConfigFile.isPresent()) {
      return Optional.absent();
    }

    ProjectFilesystem projectFilesystem = context.getProjectFilesystem();
    Path pathToProguardConfig = proguardFullConfigFile.get();

    // Proguard doesn't print a mapping when obfuscation is disabled.
    boolean obfuscationSkipped =
        Iterables.any(
            projectFilesystem.readLines(pathToProguardConfig),
            Predicates.equalTo("-dontobfuscate"));
    if (obfuscationSkipped) {
      return Optional.absent();
    }

    List<String> lines = projectFilesystem.readLines(proguardMappingFile.get());
    return Optional.of(ProguardMapping.readClassMapping(lines));
  }
Exemplo n.º 2
0
 /**
  * Parses a text file which is supposed to be in the following format: "file_path_without_spaces
  * file_hash ...." i.e. it parses the first two columns of each line and ignores the rest of it.
  *
  * @return A multi map from the file hash to its path, which equals the raw path resolved against
  *     {@code resolvePathAgainst}.
  */
 @VisibleForTesting
 static ImmutableMultimap<String, Path> parseExopackageInfoMetadata(
     Path metadataTxt, Path resolvePathAgainst, ProjectFilesystem filesystem) throws IOException {
   ImmutableMultimap.Builder<String, Path> builder = ImmutableMultimap.builder();
   for (String line : filesystem.readLines(metadataTxt)) {
     // ignore lines that start with '.'
     if (line.startsWith(".")) {
       continue;
     }
     List<String> parts = Splitter.on(' ').splitToList(line);
     if (parts.size() < 2) {
       throw new RuntimeException("Illegal line in metadata file: " + line);
     }
     builder.put(parts.get(1), resolvePathAgainst.resolve(parts.get(0)));
   }
   return builder.build();
 }
Exemplo n.º 3
0
  @Test
  @SuppressWarnings("PMD.UseAssertTrueInsteadOfAssertEquals") // PMD has a bad heuristic here.
  public void testReadValuesStep() throws IOException {
    Path pathToValues = Paths.get("src/values.txt");

    ProjectFilesystem projectFilesystem = EasyMock.createMock(ProjectFilesystem.class);
    EasyMock.expect(projectFilesystem.readLines(pathToValues))
        .andReturn(ImmutableList.of("boolean DEBUG = false", "String FOO = \"BAR\""));
    EasyMock.replay(projectFilesystem);

    ReadValuesStep step = new ReadValuesStep(projectFilesystem, pathToValues);
    ExecutionContext context = TestExecutionContext.newBuilder().build();
    int exitCode = step.execute(context);
    assertEquals(0, exitCode);
    assertEquals(
        BuildConfigFields.fromFields(
            ImmutableList.of(
                BuildConfigFields.Field.of("boolean", "DEBUG", "false"),
                BuildConfigFields.Field.of("String", "FOO", "\"BAR\""))),
        step.get());

    EasyMock.verify(projectFilesystem);
  }