Ejemplo n.º 1
0
  protected @Override void setUp() throws Exception {
    MockLookup.setLayersAndInstances(TestUtil.testProjectFactory());
    ProjectManager.getDefault().reset();
    FileOwnerQuery.reset();
    scratch = TestUtil.makeScratchDir(this);
    projdir = scratch.createFolder("my-project");
    projdir.createFolder("testproject");
    randomfile = scratch.createData("randomfile");
    projfile = projdir.createData("projfile");
    FileObject projsubdir = projdir.createFolder("projsubdir");
    projfile2 = projsubdir.createData("projfile2");
    subprojdir = projdir.createFolder("subproject");
    subprojdir.createFolder("testproject");
    subprojfile = subprojdir.createData("subprojfile");
    scratch.createFolder("external1").createFolder("subdir").createData("file");
    scratch.createFolder("external2").createFolder("subdir").createData("file");
    scratch.createFolder("external3").createFolder("subproject").createFolder("testproject");
    p = ProjectManager.getDefault().findProject(projdir);
    assertNotNull("found a project successfully", p);

    // make jar:file:/.../projdir/foo.jar!/zipfile/zippedfile
    FileObject foojar = TestFileUtils.writeZipFile(projdir, "foo.jar", "zipdir/zippedfile:");
    FileObject foojarRoot = FileUtil.getArchiveRoot(foojar);
    assertNotNull("have an archive in " + foojar, foojarRoot);
    zippedfile = foojarRoot.getFileObject("zipdir/zippedfile");
    assertNotNull("zippedfile found in it", zippedfile);

    hashedFile = TestFileUtils.writeZipFile(projdir, ".#webapp.jar.1.45", "zipdir/zippedfile:");
    foojarRoot = FileUtil.getArchiveRoot(hashedFile);
    assertNotNull("have an archive in " + hashedFile, foojarRoot);
    hashedFile = foojarRoot.getFileObject("zipdir/zippedfile");
  }
 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()));
 }
  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());
  }