public void testGeneratedSources() throws Exception { // #187595
   TestFileUtils.writeFile(
       d,
       "pom.xml",
       "<project xmlns='http://maven.apache.org/POM/4.0.0'>"
           + "<modelVersion>4.0.0</modelVersion>"
           + "<groupId>grp</groupId>"
           + "<artifactId>art</artifactId>"
           + "<packaging>jar</packaging>"
           + "<version>0</version>"
           + "</project>");
   FileObject src = FileUtil.createFolder(d, "src/main/java");
   FileObject gsrc = FileUtil.createFolder(d, "target/generated-sources/xjc");
   gsrc.createData("Whatever.class");
   FileObject tsrc = FileUtil.createFolder(d, "src/test/java");
   FileObject gtsrc = FileUtil.createFolder(d, "target/generated-test-sources/jaxb");
   gtsrc.createData("Whatever.class");
   assertEquals(
       Arrays.asList(src, gsrc),
       Arrays.asList(
           SourceForBinaryQuery.findSourceRoots(new URL(d.toURL(), "target/classes/"))
               .getRoots()));
   assertEquals(
       Arrays.asList(tsrc, gtsrc),
       Arrays.asList(
           SourceForBinaryQuery.findSourceRoots(new URL(d.toURL(), "target/test-classes/"))
               .getRoots()));
 }
Пример #2
0
  private static void addCompileRoot(Project p, FileObject compileRoot) {
    Result2 sources = SourceForBinaryQuery.findSourceRoots2(compileRoot.toURL());

    if (sources.preferSources()) {
      // XXX:
      if (sources.getRoots().length == 0) {
        addAuxCPEntry(p, compileRoot.toURL());
      } else {
        for (FileObject source : sources.getRoots()) {
          addCompileRootAsSource(p, source);
        }
      }
    } else {
      addAuxCPEntry(p, compileRoot.toURL());
    }
  }
  public void testForeignClassBundler() throws Exception { // #155091 and deps
    TestFileUtils.writeFile(
        d,
        "a/pom.xml",
        "<project xmlns='http://maven.apache.org/POM/4.0.0'>"
            + "<modelVersion>4.0.0</modelVersion>"
            + "<groupId>grp</groupId>"
            + "<artifactId>art</artifactId>"
            + "<packaging>jar</packaging>"
            + "<version>0</version>"
            + "</project>");
    FileObject src = FileUtil.createFolder(d, "a/src/main/java");

    File repo = EmbedderFactory.getProjectEmbedder().getLocalRepositoryFile();
    File art =
        new File(
            repo,
            "grp" + File.separator + "art" + File.separator + "0" + File.separator + "art-0.jar");
    URL root = FileUtil.getArchiveRoot(Utilities.toURI(art).toURL());
    Project p = ProjectManager.getDefault().findProject(d.getFileObject("a"));
    FileOwnerQuery.markExternalOwner(
        Utilities.toURI(art), p, FileOwnerQuery.EXTERNAL_ALGORITHM_TRANSIENT);
    MavenFileOwnerQueryImpl.getInstance()
        .registerCoordinates("grp", "art", "0", d.getFileObject("a").toURL());

    SourceForBinaryQuery.Result2 r = SourceForBinaryQuery.findSourceRoots2(root);
    assertEquals(Collections.singletonList(src), Arrays.asList(r.getRoots()));
    assertTrue(r.preferSources());
    TestFileUtils.writeFile(
        d,
        "b/pom.xml",
        "<project xmlns='http://maven.apache.org/POM/4.0.0'>"
            + "<modelVersion>4.0.0</modelVersion>"
            + "<groupId>grp</groupId>"
            + "<artifactId>art</artifactId>"
            + "<packaging>war</packaging>"
            + "<version>0</version>"
            + "</project>");
    src = FileUtil.createFolder(d, "b/src/main/java");

    art =
        new File(
            repo,
            "grp" + File.separator + "art" + File.separator + "0" + File.separator + "art-0.jar");
    FileOwnerQuery.markExternalOwner(
        Utilities.toURI(art),
        ProjectManager.getDefault().findProject(d.getFileObject("b")),
        FileOwnerQuery.EXTERNAL_ALGORITHM_TRANSIENT);
    root = FileUtil.getArchiveRoot(Utilities.toURI(art).toURL());
    p = ProjectManager.getDefault().findProject(d.getFileObject("b"));
    FileOwnerQuery.markExternalOwner(
        Utilities.toURI(art), p, FileOwnerQuery.EXTERNAL_ALGORITHM_TRANSIENT);
    MavenFileOwnerQueryImpl.getInstance()
        .registerCoordinates("grp", "art", "0", d.getFileObject("b").toURL());

    r = SourceForBinaryQuery.findSourceRoots2(root);
    assertEquals(Collections.singletonList(src), Arrays.asList(r.getRoots()));
    assertFalse(r.preferSources());

    // 215242 assert that output dir does prefer sources
    r = SourceForBinaryQuery.findSourceRoots2(new URL(d.toURL(), "b/target/classes/"));
    assertEquals(Collections.singletonList(src), Arrays.asList(r.getRoots()));
    assertTrue(r.preferSources());
  }