mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 15:09:39 +07:00
usages of OrderRootType.*CLASSES* migrated to new api
This commit is contained in:
@@ -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<OrderEntry>() {
|
||||
@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<String> jdkUrls = options.getAllJdkUrls();
|
||||
|
||||
final OrderedSet<String> urls = new OrderedSet<String>();
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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<VirtualFile> processedFiles = new HashSet<VirtualFile>();
|
||||
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 {
|
||||
|
||||
@@ -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<VirtualFile> result = new ArrayList<VirtualFile>();
|
||||
|
||||
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<VirtualFile> result = new ArrayList<VirtualFile>();
|
||||
|
||||
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<String> result = new ArrayList<String>();
|
||||
|
||||
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<String> result = new ArrayList<String>();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -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<VirtualFile> compilationClasspath = getCompilationClasspath(moduleA);
|
||||
assertEquals(1, compilationClasspath.size());
|
||||
final Collection<VirtualFile> 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<VirtualFile> compilationClasspath = getCompilationClasspath(m);
|
||||
assertEquals(1, compilationClasspath.size());
|
||||
final Collection<VirtualFile> 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<VirtualFile> runtimeClasspath = getRuntimeClasspath(moduleA);
|
||||
assertEquals(1, runtimeClasspath.size());
|
||||
final Collection<VirtualFile> compilationClasspath = getCompilationClasspath(moduleA);
|
||||
assertEquals(1, compilationClasspath.size());
|
||||
Collection<VirtualFile> 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<VirtualFile> 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<VirtualFile> compilationClasspath = getCompilationClasspath(m);
|
||||
assertEquals(1, compilationClasspath.size());
|
||||
Collection<VirtualFile> 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<VirtualFile> runtimeClasspath = getRuntimeClasspath(moduleA);
|
||||
assertEmpty(runtimeClasspath);
|
||||
final Collection<VirtualFile> 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<VirtualFile> 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<VirtualFile> 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<VirtualFile> getRuntimeClasspath(Module m) {
|
||||
return ModuleRootManager.getInstance(m).orderEntries().productionOnly().runtimeOnly().recursively().getClassesRoots();
|
||||
}
|
||||
|
||||
private static Collection<VirtualFile> getProductionCompileClasspath(Module moduleA) {
|
||||
return ModuleRootManager.getInstance(moduleA).orderEntries().productionOnly().compileOnly().recursively().exportedOnly().getClassesRoots();
|
||||
}
|
||||
|
||||
private static Collection<VirtualFile> getCompilationClasspath(Module m) {
|
||||
return ModuleRootManager.getInstance(m).orderEntries().recursively().exportedOnly().getClassesRoots();
|
||||
}
|
||||
|
||||
private VirtualFile addLibrary(Module m, final DependencyScope scope) {
|
||||
VirtualFile libraryRoot = myFixture.findOrCreateDir("lib");
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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<URL> 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<URL> buildUrls(@Nullable final VirtualFile virtualFile, @Nullable final Module module, OrderRootType rootType) {
|
||||
public static List<URL> buildUrls(@Nullable final VirtualFile virtualFile, @Nullable final Module module, boolean includeModuleOutput) {
|
||||
final List<URL> urls = new ArrayList<URL>();
|
||||
processClassPathItems(virtualFile, module, new Consumer<VirtualFile>() {
|
||||
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<VirtualFile> 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<VirtualFile> 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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user