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()); }