Source:
<code>private void installSyntheticModules( @NotNull PantsCompileOptionsExecutor executor, @NotNull DataNode<ProjectData> projectDataNode, @NotNull Map<String, DataNode<ModuleData>> modules ) { Path projectPath = Paths.get(executor.getBuildRoot().getAbsolutePath()); Set<String> replaced = executor.getOptions().getSelectedTargetSpecs().stream() .map(x -> x.replaceFirst("/?:.*", "")) .collect(Collectors.toSet()); Set<String> replacedWithoutChildren = removeChildren(replaced); Set<String> allContentRoots = modules.values().stream() .flatMap(x -> x.getChildren() .stream()) .map(x -> x.getData(ProjectKeys.CONTENT_ROOT)) .filter(Objects::nonNull) .map(x -> x.getRootPath()) .collect(Collectors.toSet()); replacedWithoutChildren.removeAll(allContentRoots); for (String path: replaced) { <START> String moduleName = projectPath.relativize(Paths.get(path)).toString().replaceAll("/", "_") + "-project-root"; <END> final ModuleData moduleData = new ModuleData( moduleName, PantsConstants.SYSTEM_ID, ModuleTypeId.JAVA_MODULE, moduleName, path, new File(path).getAbsolutePath() ); DataNode<ModuleData> moduleDataNode = projectDataNode.createChild(ProjectKeys.MODULE, moduleData); modules.put(moduleName , moduleDataNode); final ContentRootData contentRoot = new ContentRootData(PantsConstants.SYSTEM_ID, path); moduleDataNode.createChild(ProjectKeys.CONTENT_ROOT, contentRoot); } }</code><technical_language>Fastpass -project-root naming convention feels a bit weird. suggestions for a clearer more self-explanatory name</technical_language>

Target:
private void installSyntheticModules( @NotNull PantsCompileOptionsExecutor executor, @NotNull DataNode<ProjectData> projectDataNode, @NotNull Map<String, DataNode<ModuleData>> modules ) { Path projectPath = Paths.get(executor.getBuildRoot().getAbsolutePath()); Set<String> targetSpecPaths = executor.getOptions().getSelectedTargetSpecs().stream() .map(x -> x.replaceFirst("/?:.*", "")) .map(x -> Paths.get(x).isAbsolute() ? projectPath.relativize(Paths.get(x)).toString() : x) .collect(Collectors.toSet()); Set<String> targetSpecPathsWithoutChildren = removeChildren(targetSpecPaths); Set<String> allContentRoots = modules.values().stream() .flatMap(x -> x.getChildren() .stream()) .map(x -> x.getData(ProjectKeys.CONTENT_ROOT)) .filter(Objects::nonNull) .map(x -> x.getRootPath()) .collect(Collectors.toSet()); targetSpecPathsWithoutChildren.removeIf(targetSpec -> allContentRoots.stream().anyMatch(contentRoot -> projectPath.resolve(targetSpec).startsWith(contentRoot))); for (String targetPath: targetSpecPathsWithoutChildren) { String relativePath = targetPath; String moduleName = relativePath.replaceAll("/", "_") + "-project-root"; final ModuleData moduleData = new ModuleData( moduleName, PantsConstants.SYSTEM_ID, ModuleTypeId.JAVA_MODULE, moduleName, targetPath, new File(executor.getBuildRoot(), relativePath).getAbsolutePath() ); DataNode<ModuleData> moduleDataNode = projectDataNode.createChild(ProjectKeys.MODULE, moduleData); modules.put(moduleName , moduleDataNode); final ContentRootData contentRoot = new ContentRootData(PantsConstants.SYSTEM_ID, targetPath); moduleDataNode.createChild(ProjectKeys.CONTENT_ROOT, contentRoot); } }