mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
OrderEnumerator: option to exclude the main module output added
This commit is contained in:
@@ -38,6 +38,9 @@ public class OrderEnumeratorTest extends ModuleRootManagerTestCase {
|
||||
assertClassRoots(orderEntries(myModule).withoutSdk().productionOnly(), output);
|
||||
assertSourceRoots(orderEntries(myModule), srcRoot, testRoot);
|
||||
assertSourceRoots(orderEntries(myModule).productionOnly(), srcRoot);
|
||||
|
||||
assertEnumeratorRoots(orderEntries(myModule).withoutSdk().classes().withoutSelfModuleOutput(), output);
|
||||
assertEnumeratorRoots(orderEntries(myModule).withoutSdk().productionOnly().classes().withoutSelfModuleOutput());
|
||||
}
|
||||
|
||||
public void testLibraryScope() throws Exception {
|
||||
@@ -61,6 +64,7 @@ public class OrderEnumeratorTest extends ModuleRootManagerTestCase {
|
||||
assertClassRoots(orderEntries(myModule).withoutSdk().recursively(), testOutput, output, getJDomJar());
|
||||
assertSourceRoots(orderEntries(myModule), srcRoot, testRoot);
|
||||
assertSourceRoots(orderEntries(myModule).recursively(), srcRoot, testRoot, getJDomSources());
|
||||
assertEnumeratorRoots(orderEntries(myModule).withoutSdk().recursively().classes().withoutSelfModuleOutput(), testOutput, output, getJDomJar());
|
||||
}
|
||||
|
||||
public void testModuleDependencyScope() throws Exception {
|
||||
|
||||
@@ -62,6 +62,15 @@ public interface OrderRootsEnumerator {
|
||||
*/
|
||||
OrderRootsEnumerator usingCache();
|
||||
|
||||
/**
|
||||
* This method makes sense only when dependencies of a module are processed (i.e. the enumerator instance is obtained by using {@link OrderEnumerator#orderEntries(com.intellij.openapi.module.Module)} or
|
||||
* {@link ModuleRootModel#orderEntries()}). It instructs the enumerator to skip the output of the main module (if {@link com.intellij.openapi.roots.OrderEnumerator#productionOnly()}
|
||||
* option is not specified then only the test output will be skipped)
|
||||
*
|
||||
* @return this instance
|
||||
*/
|
||||
OrderRootsEnumerator withoutSelfModuleOutput();
|
||||
|
||||
/**
|
||||
* Use <code>provider</code> to obtain roots of an library or jdk order entry instead of {@link OrderEntry#getFiles(OrderRootType)} method. Note that
|
||||
* this option won't affect result of {@link #getUrls()} method
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.intellij.openapi.roots.impl;
|
||||
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.roots.ModuleRootModel;
|
||||
import com.intellij.openapi.roots.OrderEntry;
|
||||
import com.intellij.util.Processor;
|
||||
import gnu.trove.THashSet;
|
||||
@@ -37,5 +38,9 @@ public class ModuleOrderEnumerator extends OrderEnumeratorBase {
|
||||
processEntries(myRootModel, processor, myRecursively ? new THashSet<Module>() : null, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMainModuleModel(@NotNull ModuleRootModel rootModel) {
|
||||
return rootModel.equals(myRootModel);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -306,6 +306,10 @@ abstract class OrderEnumeratorBase extends OrderEnumerator {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isMainModuleModel(@NotNull ModuleRootModel rootModel) {
|
||||
return false;
|
||||
}
|
||||
|
||||
private class OrderEntryProcessor<R> implements Processor<OrderEntry> {
|
||||
private R myValue;
|
||||
private final RootPolicy<R> myPolicy;
|
||||
|
||||
+28
-4
@@ -39,6 +39,7 @@ public class OrderRootsEnumeratorImpl implements OrderRootsEnumerator {
|
||||
private final OrderRootType myRootType;
|
||||
private boolean myUsingCache;
|
||||
private NotNullFunction<OrderEntry, VirtualFile[]> myCustomRootProvider;
|
||||
private boolean myWithoutSelfModuleOutput;
|
||||
|
||||
public OrderRootsEnumeratorImpl(OrderEnumeratorBase orderEnumerator, OrderRootType rootType) {
|
||||
myOrderEnumerator = orderEnumerator;
|
||||
@@ -88,6 +89,7 @@ public class OrderRootsEnumeratorImpl implements OrderRootsEnumerator {
|
||||
|
||||
private void checkCanUseCache() {
|
||||
LOG.assertTrue(myCustomRootProvider == null, "Caching not supported for OrderRootsEnumerator with 'usingCustomRootProvider' option");
|
||||
LOG.assertTrue(!myWithoutSelfModuleOutput, "Caching not supported for OrderRootsEnumerator with 'withoutSelfModuleOutput' option");
|
||||
}
|
||||
|
||||
private Collection<VirtualFile> computeRoots() {
|
||||
@@ -163,6 +165,12 @@ public class OrderRootsEnumeratorImpl implements OrderRootsEnumerator {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderRootsEnumerator withoutSelfModuleOutput() {
|
||||
myWithoutSelfModuleOutput = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderRootsEnumerator usingCustomRootProvider(@NotNull NotNullFunction<OrderEntry, VirtualFile[]> provider) {
|
||||
myCustomRootProvider = provider;
|
||||
@@ -170,25 +178,41 @@ public class OrderRootsEnumeratorImpl implements OrderRootsEnumerator {
|
||||
}
|
||||
|
||||
private void collectModuleRoots(ModuleRootModel rootModel, Collection<VirtualFile> result) {
|
||||
final boolean productionOnly = myOrderEnumerator.isProductionOnly();
|
||||
if (myRootType.equals(OrderRootType.SOURCES)) {
|
||||
Collections.addAll(result, rootModel.getSourceRoots(!myOrderEnumerator.isProductionOnly()));
|
||||
Collections.addAll(result, rootModel.getSourceRoots(!productionOnly));
|
||||
}
|
||||
else if (myRootType.equals(OrderRootType.CLASSES)) {
|
||||
final CompilerModuleExtension extension = rootModel.getModuleExtension(CompilerModuleExtension.class);
|
||||
if (extension != null) {
|
||||
Collections.addAll(result, extension.getOutputRoots(!myOrderEnumerator.isProductionOnly()));
|
||||
if (myWithoutSelfModuleOutput && myOrderEnumerator.isMainModuleModel(rootModel)) {
|
||||
if (!productionOnly) {
|
||||
Collections.addAll(result, extension.getOutputRoots(false));
|
||||
}
|
||||
}
|
||||
else {
|
||||
Collections.addAll(result, extension.getOutputRoots(!productionOnly));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void collectModuleRootsUrls(ModuleRootModel rootModel, Collection<String> result) {
|
||||
final boolean productionOnly = myOrderEnumerator.isProductionOnly();
|
||||
if (myRootType.equals(OrderRootType.SOURCES)) {
|
||||
Collections.addAll(result, rootModel.getSourceRootUrls(!myOrderEnumerator.isProductionOnly()));
|
||||
Collections.addAll(result, rootModel.getSourceRootUrls(!productionOnly));
|
||||
}
|
||||
else if (myRootType.equals(OrderRootType.CLASSES)) {
|
||||
final CompilerModuleExtension extension = rootModel.getModuleExtension(CompilerModuleExtension.class);
|
||||
if (extension != null) {
|
||||
Collections.addAll(result, extension.getOutputRootUrls(!myOrderEnumerator.isProductionOnly()));
|
||||
if (myWithoutSelfModuleOutput && myOrderEnumerator.isMainModuleModel(rootModel)) {
|
||||
if (!productionOnly) {
|
||||
Collections.addAll(result, extension.getOutputRootUrls(false));
|
||||
}
|
||||
}
|
||||
else {
|
||||
Collections.addAll(result, extension.getOutputRootUrls(!productionOnly));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user