From c830d83087bb36fed6e58e82e8609da6aba69d47 Mon Sep 17 00:00:00 2001 From: nik Date: Thu, 1 Jul 2010 09:49:27 +0400 Subject: [PATCH] usages of OrderRootType.*CLASSES* migrated to new api --- .../compiler/ant/ModuleChunkClasspath.java | 216 +++++++++--------- .../impl/rmiCompiler/RmicCompiler.java | 40 +--- .../impl/CompilerModuleExtensionImpl.java | 58 +++-- .../intellij/roots/DependencyScopeTest.java | 71 +++--- .../com/intellij/roots/OrderEntriesTest.java | 2 +- .../src/com/intellij/psi/jsp/JspSpiUtil.java | 24 +- .../roots/CompilerModuleExtension.java | 4 + 7 files changed, 205 insertions(+), 210 deletions(-) diff --git a/java/compiler/impl/src/com/intellij/compiler/ant/ModuleChunkClasspath.java b/java/compiler/impl/src/com/intellij/compiler/ant/ModuleChunkClasspath.java index d9ff911ebcb3..203d7b0e9f9b 100644 --- a/java/compiler/impl/src/com/intellij/compiler/ant/ModuleChunkClasspath.java +++ b/java/compiler/impl/src/com/intellij/compiler/ant/ModuleChunkClasspath.java @@ -24,6 +24,7 @@ import com.intellij.openapi.roots.*; import com.intellij.openapi.vfs.JarFileSystem; import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.util.ArrayUtil; +import com.intellij.util.Processor; import com.intellij.util.containers.OrderedSet; import gnu.trove.TObjectHashingStrategy; @@ -85,116 +86,103 @@ public class ModuleChunkClasspath extends Path { processedModules.add(module); final ProjectEx project = (ProjectEx)chunk.getProject(); final File baseDir = BuildProperties.getProjectBaseDir(project); - for (final OrderEntry orderEntry : ModuleRootManager.getInstance(module).getOrderEntries()) { - if (!orderEntry.isValid()) { - continue; - } - if (orderEntry instanceof ExportableOrderEntry) { - ExportableOrderEntry e = (ExportableOrderEntry)orderEntry; - switch (e.getScope()) { - case COMPILE: - break; - case PROVIDED: - if (generateRuntimeClasspath && !generateTestClasspath) { - continue; - } - break; - case RUNTIME: - if (!generateRuntimeClasspath) { - continue; - } - break; - case TEST: - if (!generateTestClasspath) { - continue; - } - break; - } - } - if (!generateRuntimeClasspath) { - // needed for compilation classpath only - if ((orderEntry instanceof ModuleSourceOrderEntry)) { - // this is the entry for outpath of the currently processed module - if (!generateTestClasspath && (dependencyLevel == 0 || chunk.contains(module))) { - // the root module is never included - continue; - } - } - else { - final boolean isExported = (orderEntry instanceof ExportableOrderEntry) && ((ExportableOrderEntry)orderEntry).isExported(); - if (dependencyLevel > 0 && !isExported) { - if (!(orderEntry instanceof ModuleOrderEntry)) { - // non-exported dependencies are excluded and not processed - continue; - } - } - } - } - if (orderEntry instanceof JdkOrderEntry) { - if (genOptions.forceTargetJdk && !generateRuntimeClasspath) { - pathItems - .add(new PathRefItem(BuildProperties.propertyRef(BuildProperties.getModuleChunkJdkClasspathProperty(chunk.getName())))); - } - } - else if (orderEntry instanceof ModuleOrderEntry) { - final ModuleOrderEntry moduleOrderEntry = (ModuleOrderEntry)orderEntry; - final Module dependentModule = moduleOrderEntry.getModule(); - if (!chunk.contains(dependentModule)) { - if (generateRuntimeClasspath && !genOptions.inlineRuntimeClasspath) { - // in case of runtime classpath, just an referenced to corresponding classpath is created - final ModuleChunk depChunk = genOptions.getChunkByModule(dependentModule); - if (!processedChunks.contains(depChunk)) { - // chunk references are included in the runtime classpath only once - processedChunks.add(depChunk); - String property = generateTestClasspath ? BuildProperties.getTestRuntimeClasspathProperty(depChunk.getName()) - : BuildProperties.getRuntimeClasspathProperty(depChunk.getName()); - pathItems.add(new PathRefItem(property)); - } - } - else { - // in case of compile classpath or inlined runtime classpath, - // the referenced module is processed recursively - processModule(dependentModule, dependencyLevel + 1, moduleOrderEntry.isExported()); - } - } - } - else if (orderEntry instanceof LibraryOrderEntry) { - final LibraryOrderEntry libraryOrderEntry = (LibraryOrderEntry)orderEntry; - final String libraryName = libraryOrderEntry.getLibraryName(); - if (((LibraryOrderEntry)orderEntry).isModuleLevel()) { - CompositeGenerator gen = new CompositeGenerator(); - gen.setHasLeadingNewline(false); - LibraryDefinitionsGeneratorFactory.genLibraryContent(project, genOptions, libraryOrderEntry.getLibrary(), baseDir, gen); - pathItems.add(new GeneratorItem(libraryName, gen)); - } - else { - pathItems.add(new PathRefItem(BuildProperties.getLibraryPathId(libraryName))); - } - } - else if (orderEntry instanceof ModuleSourceOrderEntry) { - // Module source entry? - for (String url : getCompilationClasses(orderEntry, ((GenerationOptionsImpl)genOptions), generateRuntimeClasspath, - generateTestClasspath, dependencyLevel == 0)) { - if (url.endsWith(JarFileSystem.JAR_SEPARATOR)) { - url = url.substring(0, url.length() - JarFileSystem.JAR_SEPARATOR.length()); - } - final String propertyRef = genOptions.getPropertyRefForUrl(url); - if (propertyRef != null) { - pathItems.add(new PathElementItem(propertyRef)); - } - else { - final String path = VirtualFileManager.extractPath(url); - pathItems.add(new PathElementItem( - GenerationUtils.toRelativePath(path, chunk.getBaseDir(), moduleChunkBasedirProperty, genOptions))); - } - } - } - else { - // Unknown order entry type. If it is actually encountered, extension point should be implemented - pathItems.add(new GeneratorItem(orderEntry.getClass().getName(), - new Comment("Unknown OrderEntryType: " + orderEntry.getClass().getName()))); + OrderEnumerator enumerator = ModuleRootManager.getInstance(module).orderEntries(); + if (generateRuntimeClasspath) { + enumerator = enumerator.runtimeOnly(); + } + else { + enumerator = enumerator.compileOnly(); + if (!generateTestClasspath && (dependencyLevel == 0 || chunk.contains(module))) { + // this is the entry for outpath of the currently processed module + // the root module is never included + enumerator = enumerator.withoutModuleSourceEntries(); } } + if (!generateTestClasspath) { + enumerator = enumerator.productionOnly(); + } + enumerator.forEach(new Processor() { + @Override + public boolean process(OrderEntry orderEntry) { + if (!orderEntry.isValid()) { + return true; + } + + if (!generateRuntimeClasspath && !(orderEntry instanceof ModuleOrderEntry)) { + // needed for compilation classpath only + final boolean isExported = (orderEntry instanceof ExportableOrderEntry) && ((ExportableOrderEntry)orderEntry).isExported(); + if (dependencyLevel > 0 && !isExported) { + // non-exported dependencies are excluded and not processed + return true; + } + } + + if (orderEntry instanceof JdkOrderEntry) { + if (genOptions.forceTargetJdk && !generateRuntimeClasspath) { + pathItems.add(new PathRefItem(BuildProperties.propertyRef(BuildProperties.getModuleChunkJdkClasspathProperty(chunk.getName())))); + } + } + else if (orderEntry instanceof ModuleOrderEntry) { + final ModuleOrderEntry moduleOrderEntry = (ModuleOrderEntry)orderEntry; + final Module dependentModule = moduleOrderEntry.getModule(); + if (!chunk.contains(dependentModule)) { + if (generateRuntimeClasspath && !genOptions.inlineRuntimeClasspath) { + // in case of runtime classpath, just an referenced to corresponding classpath is created + final ModuleChunk depChunk = genOptions.getChunkByModule(dependentModule); + if (!processedChunks.contains(depChunk)) { + // chunk references are included in the runtime classpath only once + processedChunks.add(depChunk); + String property = generateTestClasspath ? BuildProperties.getTestRuntimeClasspathProperty(depChunk.getName()) + : BuildProperties.getRuntimeClasspathProperty(depChunk.getName()); + pathItems.add(new PathRefItem(property)); + } + } + else { + // in case of compile classpath or inlined runtime classpath, + // the referenced module is processed recursively + processModule(dependentModule, dependencyLevel + 1, moduleOrderEntry.isExported()); + } + } + } + else if (orderEntry instanceof LibraryOrderEntry) { + final LibraryOrderEntry libraryOrderEntry = (LibraryOrderEntry)orderEntry; + final String libraryName = libraryOrderEntry.getLibraryName(); + if (((LibraryOrderEntry)orderEntry).isModuleLevel()) { + CompositeGenerator gen = new CompositeGenerator(); + gen.setHasLeadingNewline(false); + LibraryDefinitionsGeneratorFactory.genLibraryContent(project, genOptions, libraryOrderEntry.getLibrary(), baseDir, gen); + pathItems.add(new GeneratorItem(libraryName, gen)); + } + else { + pathItems.add(new PathRefItem(BuildProperties.getLibraryPathId(libraryName))); + } + } + else if (orderEntry instanceof ModuleSourceOrderEntry) { + // Module source entry? + for (String url : getCompilationClasses(module, ((GenerationOptionsImpl)genOptions), generateRuntimeClasspath, + generateTestClasspath, dependencyLevel == 0)) { + if (url.endsWith(JarFileSystem.JAR_SEPARATOR)) { + url = url.substring(0, url.length() - JarFileSystem.JAR_SEPARATOR.length()); + } + final String propertyRef = genOptions.getPropertyRefForUrl(url); + if (propertyRef != null) { + pathItems.add(new PathElementItem(propertyRef)); + } + else { + final String path = VirtualFileManager.extractPath(url); + pathItems.add(new PathElementItem( + GenerationUtils.toRelativePath(path, chunk.getBaseDir(), moduleChunkBasedirProperty, genOptions))); + } + } + } + else { + // Unknown order entry type. If it is actually encountered, extension point should be implemented + pathItems.add(new GeneratorItem(orderEntry.getClass().getName(), + new Comment("Unknown OrderEntryType: " + orderEntry.getClass().getName()))); + } + return true; + } + }); } }.processModule(module, 0, false); } @@ -225,24 +213,26 @@ public class ModuleChunkClasspath extends Path { } } - private static String[] getCompilationClasses(final OrderEntry orderEntry, + private static String[] getCompilationClasses(final Module module, final GenerationOptionsImpl options, final boolean forRuntime, final boolean forTest, final boolean firstLevel) { + final CompilerModuleExtension extension = CompilerModuleExtension.getInstance(module); + if (extension == null) return ArrayUtil.EMPTY_STRING_ARRAY; + if (!forRuntime) { if (forTest) { - return orderEntry.getUrls(firstLevel ? OrderRootType.PRODUCTION_COMPILATION_CLASSES : OrderRootType.COMPILATION_CLASSES); + return extension.getOutputRootUrls(!firstLevel); } else { - return firstLevel ? new String[0] : orderEntry.getUrls(OrderRootType.PRODUCTION_COMPILATION_CLASSES); + return firstLevel ? ArrayUtil.EMPTY_STRING_ARRAY : extension.getOutputRootUrls(false); } } final Set jdkUrls = options.getAllJdkUrls(); final OrderedSet urls = new OrderedSet(); - urls.addAll(Arrays.asList(orderEntry.getUrls(forTest ? OrderRootType.COMPILATION_CLASSES - : OrderRootType.PRODUCTION_COMPILATION_CLASSES))); + urls.addAll(Arrays.asList(extension.getOutputRootUrls(forTest))); urls.removeAll(jdkUrls); return ArrayUtil.toStringArray(urls); } diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/rmiCompiler/RmicCompiler.java b/java/compiler/impl/src/com/intellij/compiler/impl/rmiCompiler/RmicCompiler.java index 04972a1e68f3..7b25a94add96 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/rmiCompiler/RmicCompiler.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/rmiCompiler/RmicCompiler.java @@ -31,7 +31,10 @@ import com.intellij.openapi.module.Module; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.project.Project; import com.intellij.openapi.projectRoots.Sdk; -import com.intellij.openapi.roots.*; +import com.intellij.openapi.roots.ModuleRootManager; +import com.intellij.openapi.roots.OrderEnumerator; +import com.intellij.openapi.roots.ProjectFileIndex; +import com.intellij.openapi.roots.ProjectRootManager; import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.io.FileUtil; @@ -39,8 +42,7 @@ import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.ArrayUtil; -import com.intellij.util.PathUtil; -import com.intellij.util.StringBuilderSpinAllocator; +import com.intellij.util.PathsList; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -385,35 +387,9 @@ public class RmicCompiler implements ClassPostProcessingCompiler{ } private static String getCompilationClasspath(Module module) { - final StringBuilder classpathBuffer = StringBuilderSpinAllocator.alloc(); - try { - final OrderEntry[] orderEntries = ModuleRootManager.getInstance(module).getOrderEntries(); - final Set processedFiles = new HashSet(); - for (final OrderEntry orderEntry : orderEntries) { - if (orderEntry instanceof JdkOrderEntry) { - continue; - } - final VirtualFile[] files = orderEntry.getFiles(OrderRootType.COMPILATION_CLASSES); - for (VirtualFile file : files) { - if (processedFiles.contains(file)) { - continue; - } - processedFiles.add(file); - final String path = PathUtil.getLocalPath(file); - if (path == null) { - continue; - } - if (classpathBuffer.length() > 0) { - classpathBuffer.append(File.pathSeparatorChar); - } - classpathBuffer.append(path); - } - } - return classpathBuffer.toString(); - } - finally { - StringBuilderSpinAllocator.dispose(classpathBuffer); - } + final OrderEnumerator enumerator = ModuleRootManager.getInstance(module).orderEntries().withoutSdk().compileOnly().recursively().exportedOnly(); + final PathsList pathsList = enumerator.getPathsList(); + return pathsList.getPathsString(); } private static final class RemoteClassValidityState implements ValidityState { diff --git a/java/java-impl/src/com/intellij/openapi/roots/impl/CompilerModuleExtensionImpl.java b/java/java-impl/src/com/intellij/openapi/roots/impl/CompilerModuleExtensionImpl.java index 07493a68eeba..bebc8d23bd9e 100644 --- a/java/java-impl/src/com/intellij/openapi/roots/impl/CompilerModuleExtensionImpl.java +++ b/java/java-impl/src/com/intellij/openapi/roots/impl/CompilerModuleExtensionImpl.java @@ -299,40 +299,50 @@ public class CompilerModuleExtensionImpl extends CompilerModuleExtension { if (OrderRootType.CLASSES_AND_OUTPUT.equals(type) || OrderRootType.COMPILATION_CLASSES.equals(type) || OrderRootType.PRODUCTION_COMPILATION_CLASSES.equals(type)) { - final ArrayList result = new ArrayList(); - - final VirtualFile outputPathForTests = OrderRootType.PRODUCTION_COMPILATION_CLASSES.equals(type) ? null : getCompilerOutputPathForTests(); - if (outputPathForTests != null) { - result.add(outputPathForTests); - } - - VirtualFile outputRoot = getCompilerOutputPath(); - if (outputRoot != null && !outputRoot.equals(outputPathForTests)) { - result.add(outputRoot); - } - return VfsUtil.toVirtualFileArray(result); + return getOutputRoots(!OrderRootType.PRODUCTION_COMPILATION_CLASSES.equals(type)); } return null; } + @Override + public VirtualFile[] getOutputRoots(final boolean includeTests) { + final ArrayList result = new ArrayList(); + + final VirtualFile outputPathForTests = includeTests ? getCompilerOutputPathForTests() : null; + if (outputPathForTests != null) { + result.add(outputPathForTests); + } + + VirtualFile outputRoot = getCompilerOutputPath(); + if (outputRoot != null && !outputRoot.equals(outputPathForTests)) { + result.add(outputRoot); + } + return VfsUtil.toVirtualFileArray(result); + } + @Override public String[] getRootUrls(final OrderRootType type) { if (OrderRootType.CLASSES_AND_OUTPUT.equals(type) || OrderRootType.COMPILATION_CLASSES.equals(type) || OrderRootType.PRODUCTION_COMPILATION_CLASSES.equals(type)) { - final List result = new ArrayList(); - - final String outputPathForTests = OrderRootType.PRODUCTION_COMPILATION_CLASSES.equals(type) ? null : getCompilerOutputUrlForTests(); - if (outputPathForTests != null) { - result.add(outputPathForTests); - } - - String outputRoot = getCompilerOutputUrl(); - if (outputRoot != null && !outputRoot.equals(outputPathForTests)) { - result.add(outputRoot); - } - return ArrayUtil.toStringArray(result); + return getOutputRootUrls(!OrderRootType.PRODUCTION_COMPILATION_CLASSES.equals(type)); } return null; } + + @Override + public String[] getOutputRootUrls(final boolean includeTests) { + final List result = new ArrayList(); + + final String outputPathForTests = includeTests ? getCompilerOutputUrlForTests() : null; + if (outputPathForTests != null) { + result.add(outputPathForTests); + } + + String outputRoot = getCompilerOutputUrl(); + if (outputRoot != null && !outputRoot.equals(outputPathForTests)) { + result.add(outputRoot); + } + return ArrayUtil.toStringArray(result); + } } \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/roots/DependencyScopeTest.java b/java/java-tests/testSrc/com/intellij/roots/DependencyScopeTest.java index f4286ff0f794..5bb5646847db 100644 --- a/java/java-tests/testSrc/com/intellij/roots/DependencyScopeTest.java +++ b/java/java-tests/testSrc/com/intellij/roots/DependencyScopeTest.java @@ -10,6 +10,7 @@ import com.intellij.testFramework.fixtures.impl.LightTempDirTestFixtureImpl; import com.intellij.util.PathsList; import java.io.IOException; +import java.util.Collection; /** * @author yole @@ -38,10 +39,10 @@ public class DependencyScopeTest extends ModuleTestCase { assertFalse(moduleA.getModuleWithDependenciesAndLibrariesScope(false).contains(classB)); assertFalse(moduleA.getModuleWithDependenciesAndLibrariesScope(false).isSearchInModuleContent(moduleB)); - final VirtualFile[] compilationClasspath = ModuleRootManager.getInstance(moduleA).getFiles(OrderRootType.COMPILATION_CLASSES); - assertEquals(1, compilationClasspath.length); - final VirtualFile[] productionCompilationClasspath = ModuleRootManager.getInstance(moduleA).getFiles(OrderRootType.PRODUCTION_COMPILATION_CLASSES); - assertEquals(0, productionCompilationClasspath.length); + final Collection compilationClasspath = getCompilationClasspath(moduleA); + assertEquals(1, compilationClasspath.size()); + final Collection productionCompilationClasspath = getProductionCompileClasspath(moduleA); + assertEmpty(productionCompilationClasspath); final PathsList pathsList = OrderEnumerator.orderEntries(moduleA).recursively().getPathsList(); assertEquals(1, pathsList.getPathList().size()); @@ -77,35 +78,34 @@ public class DependencyScopeTest extends ModuleTestCase { assertTrue(m.getModuleWithDependenciesAndLibrariesScope(true).contains(libraryClass)); assertFalse(m.getModuleWithDependenciesAndLibrariesScope(false).contains(libraryClass)); - final VirtualFile[] compilationClasspath = ModuleRootManager.getInstance(m).getFiles(OrderRootType.COMPILATION_CLASSES); - assertEquals(1, compilationClasspath.length); - final VirtualFile[] productionCompilationClasspath = ModuleRootManager.getInstance(m).getFiles(OrderRootType.PRODUCTION_COMPILATION_CLASSES); - assertEquals(0, productionCompilationClasspath.length); + final Collection compilationClasspath = getCompilationClasspath(m); + assertEquals(1, compilationClasspath.size()); + final Collection productionCompilationClasspath = getProductionCompileClasspath(m); + assertEmpty(productionCompilationClasspath); } public void testRuntimeModuleDependency() throws IOException { Module moduleA = createModule("a.iml", StdModuleTypes.JAVA); addDependentModule(moduleA, DependencyScope.RUNTIME); - final VirtualFile[] runtimeClasspath = ModuleRootManager.getInstance(moduleA).getFiles(OrderRootType.CLASSES_AND_OUTPUT); - assertEquals(1, runtimeClasspath.length); - final VirtualFile[] compilationClasspath = ModuleRootManager.getInstance(moduleA).getFiles(OrderRootType.COMPILATION_CLASSES); - assertEquals(1, compilationClasspath.length); - VirtualFile[] production = ModuleRootManager.getInstance(moduleA).getFiles(OrderRootType.PRODUCTION_COMPILATION_CLASSES); - assertEquals(0, production.length); + final Collection runtimeClasspath = getRuntimeClasspath(moduleA); + assertEquals(1, runtimeClasspath.size()); + final Collection compilationClasspath = getCompilationClasspath(moduleA); + assertEquals(1, compilationClasspath.size()); + Collection production = getProductionCompileClasspath(moduleA); + assertEmpty(production); } public void testRuntimeLibraryDependency() throws IOException { Module m = createModule("a.iml", StdModuleTypes.JAVA); VirtualFile libraryRoot = addLibrary(m, DependencyScope.RUNTIME); - final VirtualFile[] runtimeClasspath = ModuleRootManager.getInstance(m).getFiles(OrderRootType.CLASSES_AND_OUTPUT); - assertEquals(1, runtimeClasspath.length); - assertEquals(libraryRoot, runtimeClasspath [0]); + final Collection runtimeClasspath = getRuntimeClasspath(m); + assertOrderedEquals(runtimeClasspath, libraryRoot); - final VirtualFile[] compilationClasspath = ModuleRootManager.getInstance(m).getFiles(OrderRootType.COMPILATION_CLASSES); - assertEquals(1, compilationClasspath.length); - VirtualFile[] production = ModuleRootManager.getInstance(m).getFiles(OrderRootType.PRODUCTION_COMPILATION_CLASSES); - assertEquals(0, production.length); + final Collection compilationClasspath = getCompilationClasspath(m); + assertEquals(1, compilationClasspath.size()); + Collection production = getProductionCompileClasspath(m); + assertEmpty(production); VirtualFile libraryClass = myFixture.createFile("lib/Test.java", "public class Test { }"); assertTrue(m.getModuleWithDependenciesAndLibrariesScope(true).contains(libraryClass)); @@ -115,28 +115,39 @@ public class DependencyScopeTest extends ModuleTestCase { public void testProvidedModuleDependency() throws IOException { Module moduleA = createModule("a.iml", StdModuleTypes.JAVA); addDependentModule(moduleA, DependencyScope.PROVIDED); - final VirtualFile[] runtimeClasspath = ModuleRootManager.getInstance(moduleA).getFiles(OrderRootType.CLASSES_AND_OUTPUT); - assertEquals(0, runtimeClasspath.length); - final VirtualFile[] compilationClasspath = ModuleRootManager.getInstance(moduleA).getFiles(OrderRootType.COMPILATION_CLASSES); - assertEquals(1, compilationClasspath.length); + Collection runtimeClasspath = getRuntimeClasspath(moduleA); + assertEmpty(runtimeClasspath); + final Collection compilationClasspath = getCompilationClasspath(moduleA); + assertEquals(1, compilationClasspath.size()); } public void testProvidedLibraryDependency() throws IOException { Module m = createModule("a.iml", StdModuleTypes.JAVA); VirtualFile libraryRoot = addLibrary(m, DependencyScope.PROVIDED); - final VirtualFile[] runtimeClasspath = ModuleRootManager.getInstance(m).getFiles(OrderRootType.CLASSES_AND_OUTPUT); - assertEquals(0, runtimeClasspath.length); + final Collection runtimeClasspath = getRuntimeClasspath(m); + assertEmpty(runtimeClasspath); - final VirtualFile[] compilationClasspath = ModuleRootManager.getInstance(m).getFiles(OrderRootType.COMPILATION_CLASSES); - assertEquals(1, compilationClasspath.length); - assertEquals(libraryRoot, compilationClasspath [0]); + final Collection compilationClasspath = getCompilationClasspath(m); + assertOrderedEquals(compilationClasspath, libraryRoot); VirtualFile libraryClass = myFixture.createFile("lib/Test.java", "public class Test { }"); assertTrue(m.getModuleWithDependenciesAndLibrariesScope(true).contains(libraryClass)); assertTrue(m.getModuleWithDependenciesAndLibrariesScope(false).contains(libraryClass)); } + private static Collection getRuntimeClasspath(Module m) { + return ModuleRootManager.getInstance(m).orderEntries().productionOnly().runtimeOnly().recursively().getClassesRoots(); + } + + private static Collection getProductionCompileClasspath(Module moduleA) { + return ModuleRootManager.getInstance(moduleA).orderEntries().productionOnly().compileOnly().recursively().exportedOnly().getClassesRoots(); + } + + private static Collection getCompilationClasspath(Module m) { + return ModuleRootManager.getInstance(m).orderEntries().recursively().exportedOnly().getClassesRoots(); + } + private VirtualFile addLibrary(Module m, final DependencyScope scope) { VirtualFile libraryRoot = myFixture.findOrCreateDir("lib"); diff --git a/java/java-tests/testSrc/com/intellij/roots/OrderEntriesTest.java b/java/java-tests/testSrc/com/intellij/roots/OrderEntriesTest.java index bb36326f98f8..f9412ed323ec 100644 --- a/java/java-tests/testSrc/com/intellij/roots/OrderEntriesTest.java +++ b/java/java-tests/testSrc/com/intellij/roots/OrderEntriesTest.java @@ -98,7 +98,7 @@ public class OrderEntriesTest extends ModuleRootManagerTestCase { return base.recursively().exportedOnly().getPathsList(); } if (type == OrderRootType.PRODUCTION_COMPILATION_CLASSES) { - return base.productionOnly().recursively().exportedOnly().getPathsList(); + return base.productionOnly().compileOnly().recursively().exportedOnly().getPathsList(); } if (type == OrderRootType.CLASSES) { return base.withoutModuleSourceEntries().recursively().exportedOnly().getPathsList(); diff --git a/java/jsp-spi/src/com/intellij/psi/jsp/JspSpiUtil.java b/java/jsp-spi/src/com/intellij/psi/jsp/JspSpiUtil.java index 35e5b4080a67..542fdd95908e 100644 --- a/java/jsp-spi/src/com/intellij/psi/jsp/JspSpiUtil.java +++ b/java/jsp-spi/src/com/intellij/psi/jsp/JspSpiUtil.java @@ -19,7 +19,7 @@ import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.module.Module; import com.intellij.openapi.roots.ModuleRootManager; -import com.intellij.openapi.roots.OrderRootType; +import com.intellij.openapi.roots.OrderEnumerator; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.vfs.JarFileSystem; import com.intellij.openapi.vfs.VirtualFile; @@ -138,37 +138,41 @@ public abstract class JspSpiUtil { } public static List buildUrls(@Nullable final VirtualFile virtualFile, @Nullable final Module module) { - return buildUrls(virtualFile, module, OrderRootType.CLASSES_AND_OUTPUT); + return buildUrls(virtualFile, module, true); } - public static List buildUrls(@Nullable final VirtualFile virtualFile, @Nullable final Module module, OrderRootType rootType) { + public static List buildUrls(@Nullable final VirtualFile virtualFile, @Nullable final Module module, boolean includeModuleOutput) { final List urls = new ArrayList(); processClassPathItems(virtualFile, module, new Consumer() { public void consume(final VirtualFile file) { addUrl(urls, file); } - }, rootType); + }, includeModuleOutput); return urls; } public static void processClassPathItems(final VirtualFile virtualFile, final Module module, final Consumer consumer) { - processClassPathItems(virtualFile, module, consumer, OrderRootType.CLASSES_AND_OUTPUT); + processClassPathItems(virtualFile, module, consumer, true); } public static void processClassPathItems(final VirtualFile virtualFile, final Module module, final Consumer consumer, - OrderRootType rootType) { + boolean includeModuleOutput) { if (isJarFile(virtualFile)){ consumer.consume(virtualFile); } if (module != null) { - for (VirtualFile file1 : ModuleRootManager.getInstance(module).getFiles(rootType)) { + OrderEnumerator enumerator = ModuleRootManager.getInstance(module).orderEntries().recursively(); + if (!includeModuleOutput) { + enumerator = enumerator.withoutModuleSourceEntries(); + } + for (VirtualFile root : enumerator.getClassesRoots()) { final VirtualFile file; - if (file1.getFileSystem().getProtocol().equals(JarFileSystem.PROTOCOL)) { - file = JarFileSystem.getInstance().getVirtualFileForJar(file1); + if (root.getFileSystem().getProtocol().equals(JarFileSystem.PROTOCOL)) { + file = JarFileSystem.getInstance().getVirtualFileForJar(root); } else { - file = file1; + file = root; } consumer.consume(file); } diff --git a/platform/lang-api/src/com/intellij/openapi/roots/CompilerModuleExtension.java b/platform/lang-api/src/com/intellij/openapi/roots/CompilerModuleExtension.java index 76d277992d06..110f7eded5ac 100644 --- a/platform/lang-api/src/com/intellij/openapi/roots/CompilerModuleExtension.java +++ b/platform/lang-api/src/com/intellij/openapi/roots/CompilerModuleExtension.java @@ -97,4 +97,8 @@ public abstract class CompilerModuleExtension extends ModuleExtension { public abstract void setExcludeOutput(boolean exclude); public abstract boolean isExcludeOutput(); + + public abstract VirtualFile[] getOutputRoots(boolean includeTests); + + public abstract String[] getOutputRootUrls(boolean includeTests); } \ No newline at end of file