private Path extractIfRequired(final Path buildDir)
     throws MojoFailureException, MojoExecutionException {
   if (jbossHome != null) {
     // we do not need to download WildFly
     return Paths.get(jbossHome);
   }
   final String artifact =
       ArtifactNameSplitter.of(this.artifact)
           .setArtifactId(artifactId)
           .setClassifier(classifier)
           .setGroupId(groupId)
           .setPackaging(packaging)
           .setVersion(version)
           .asString();
   final Path result = artifactResolver.resolve(project, artifact).toPath();
   final Path target = buildDir.resolve(WILDFLY_DIR);
   // Delete the target if it exists
   if (Files.exists(target)) {
     try {
       Archives.deleteDirectory(target);
     } catch (IOException e) {
       throw new MojoFailureException("Could not delete target directory: " + target, e);
     }
   }
   try {
     Archives.unzip(result, target);
     final Iterator<Path> iterator = Files.newDirectoryStream(target).iterator();
     if (iterator.hasNext()) return iterator.next();
   } catch (IOException e) {
     throw new MojoFailureException("Artifact was not successfully extracted: " + result, e);
   }
   throw new MojoFailureException("Artifact was not successfully extracted: " + result);
 }
Esempio n. 2
0
  @Test
  public void testThatOriginalBuildParamsDepsDoNotPropagateToArchive() {
    SourcePathResolver pathResolver = new SourcePathResolver(new BuildRuleResolver());

    // Create an `Archive` rule using build params with an existing dependency,
    // as if coming from a `TargetNode` which had declared deps.  These should *not*
    // propagate to the `Archive` rule, since it only cares about dependencies generating
    // it's immediate inputs.
    BuildRule dep =
        new FakeBuildRule(
            BuildRuleParamsFactory.createTrivialBuildRuleParams(
                BuildTargetFactory.newInstance("//:fake")),
            pathResolver);
    BuildTarget target = BuildTargetFactory.newInstance("//:archive");
    BuildRuleParams params =
        new FakeBuildRuleParamsBuilder(BuildTargetFactory.newInstance("//:dummy"))
            .setDeps(ImmutableSortedSet.of(dep))
            .build();
    Archive archive =
        Archives.createArchiveRule(
            pathResolver, target, params, DEFAULT_ARCHIVER, DEFAULT_OUTPUT, DEFAULT_INPUTS);

    // Verify that the archive rules dependencies are empty.
    assertEquals(archive.getDeps(), ImmutableSortedSet.<BuildRule>of());
  }
Esempio n. 3
0
  @Test
  public void testThatBuildTargetSourcePathDepsAndPathsArePropagated() {
    BuildRuleResolver resolver = new BuildRuleResolver();
    BuildTarget target = BuildTargetFactory.newInstance("//foo:bar");
    BuildRuleParams params = BuildRuleParamsFactory.createTrivialBuildRuleParams(target);

    // Create a couple of genrules to generate inputs for an archive rule.
    Genrule genrule1 =
        (Genrule)
            GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:genrule"))
                .setOut("foo/bar.o")
                .build(resolver);
    Genrule genrule2 =
        (Genrule)
            GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:genrule2"))
                .setOut("foo/test.o")
                .build(resolver);

    // Build the archive using a normal input the outputs of the genrules above.
    Archive archive =
        Archives.createArchiveRule(
            new SourcePathResolver(resolver),
            target,
            params,
            DEFAULT_ARCHIVER,
            DEFAULT_OUTPUT,
            ImmutableList.<SourcePath>of(
                new TestSourcePath("simple.o"),
                new BuildTargetSourcePath(genrule1.getBuildTarget()),
                new BuildTargetSourcePath(genrule2.getBuildTarget())));

    // Verify that the archive dependencies include the genrules providing the
    // SourcePath inputs.
    assertEquals(ImmutableSortedSet.<BuildRule>of(genrule1, genrule2), archive.getDeps());
  }