mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
java compiler migrated to new OrderEnumerator api, wrong OrderRootType constants deprecated
This commit is contained in:
@@ -25,13 +25,11 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.roots.*;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.vfs.VfsUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.util.Chunk;
|
||||
import com.intellij.util.JarClasspathHelper;
|
||||
import com.intellij.util.PathUtil;
|
||||
import com.intellij.util.StringBuilderSpinAllocator;
|
||||
import com.intellij.util.*;
|
||||
import com.intellij.util.containers.OrderedSet;
|
||||
import gnu.trove.THashMap;
|
||||
import gnu.trove.TObjectHashingStrategy;
|
||||
@@ -194,28 +192,16 @@ public class ModuleChunk extends Chunk<Module> {
|
||||
public OrderedSet<VirtualFile> getCompilationClasspathFiles() {
|
||||
final Set<Module> modules = getNodes();
|
||||
|
||||
final OrderedSet<VirtualFile> cpFiles = new OrderedSet<VirtualFile>(TObjectHashingStrategy.CANONICAL);
|
||||
OrderedSet<VirtualFile> cpFiles = new OrderedSet<VirtualFile>(TObjectHashingStrategy.CANONICAL);
|
||||
for (final Module module : modules) {
|
||||
|
||||
final OrderEntry[] orderEntries = ModuleRootManager.getInstance(module).getOrderEntries();
|
||||
boolean skip = true;
|
||||
for (OrderEntry orderEntry : orderEntries) {
|
||||
if (orderEntry instanceof JdkOrderEntry) {
|
||||
skip = false;
|
||||
continue;
|
||||
}
|
||||
if (skip) {
|
||||
continue;
|
||||
}
|
||||
|
||||
VirtualFile[] files = orderEntry.getFiles((mySourcesFilter & TEST_SOURCES) == 0 ? OrderRootType.PRODUCTION_COMPILATION_CLASSES : OrderRootType.COMPILATION_CLASSES);
|
||||
if (orderEntry instanceof ModuleOrderEntry) {
|
||||
Project project = module.getProject();
|
||||
JarClasspathHelper.patchFiles(files, project);
|
||||
}
|
||||
cpFiles.addAll(Arrays.asList(files));
|
||||
OrderEnumerator enumerator = OrderEnumerator.orderEntries(module).compileOnly().satisfying(new AfterJdkOrderEntryCondition());
|
||||
if ((mySourcesFilter & TEST_SOURCES) == 0) {
|
||||
enumerator = enumerator.productionOnly();
|
||||
}
|
||||
cpFiles.addAll(enumerator.recursively().exportedOnly().getClassesRoots());
|
||||
}
|
||||
cpFiles = JarClasspathHelper.patchFiles(cpFiles, myContext.getProject());
|
||||
|
||||
return cpFiles;
|
||||
}
|
||||
|
||||
@@ -228,52 +214,21 @@ public class ModuleChunk extends Chunk<Module> {
|
||||
final OrderedSet<VirtualFile> cpFiles = new OrderedSet<VirtualFile>(TObjectHashingStrategy.CANONICAL);
|
||||
final OrderedSet<VirtualFile> jdkFiles = new OrderedSet<VirtualFile>(TObjectHashingStrategy.CANONICAL);
|
||||
for (final Module module : modules) {
|
||||
final OrderEntry[] orderEntries = ModuleRootManager.getInstance(module).getOrderEntries();
|
||||
for (OrderEntry orderEntry : orderEntries) {
|
||||
if (orderEntry instanceof JdkOrderEntry) {
|
||||
jdkFiles.addAll(Arrays.asList(orderEntry.getFiles(OrderRootType.CLASSES)));
|
||||
break;
|
||||
}
|
||||
else {
|
||||
if ((mySourcesFilter & TEST_SOURCES) == 0) {
|
||||
cpFiles.addAll(Arrays.asList(orderEntry.getFiles(OrderRootType.PRODUCTION_COMPILATION_CLASSES)));
|
||||
}
|
||||
else {
|
||||
cpFiles.addAll(Arrays.asList(orderEntry.getFiles(OrderRootType.COMPILATION_CLASSES)));
|
||||
}
|
||||
}
|
||||
OrderEnumerator enumerator = OrderEnumerator.orderEntries(module).compileOnly().satisfying(new BeforeJdkOrderEntryCondition());
|
||||
if ((mySourcesFilter & TEST_SOURCES) == 0) {
|
||||
enumerator = enumerator.productionOnly();
|
||||
}
|
||||
cpFiles.addAll(enumerator.recursively().exportedOnly().getClassesRoots());
|
||||
jdkFiles.addAll(OrderEnumerator.orderEntries(module).sdkOnly().getClassesRoots());
|
||||
}
|
||||
cpFiles.addAll(jdkFiles);
|
||||
return cpFiles;
|
||||
}
|
||||
|
||||
private static String convertToStringPath(final OrderedSet<VirtualFile> cpFiles) {
|
||||
final StringBuilder classpathBuffer = StringBuilderSpinAllocator.alloc();
|
||||
try {
|
||||
for (final VirtualFile file : cpFiles) {
|
||||
final String path = PathUtil.getLocalPath(file);
|
||||
//if (file.getFileSystem() instanceof LocalFileSystem && file.isDirectory()) {
|
||||
// path = tryZipFor(file.getPath());
|
||||
//}
|
||||
//else {
|
||||
// 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);
|
||||
}
|
||||
PathsList classpath = new PathsList();
|
||||
classpath.addVirtualFiles(cpFiles);
|
||||
return classpath.getPathsString();
|
||||
}
|
||||
|
||||
//private String tryZipFor(String outputDir) {
|
||||
@@ -327,4 +282,29 @@ public class ModuleChunk extends Chunk<Module> {
|
||||
public LanguageLevel getLanguageLevel() {
|
||||
return LanguageLevelUtil.getEffectiveLanguageLevel(getModules()[0]);
|
||||
}
|
||||
|
||||
private static class BeforeJdkOrderEntryCondition implements Condition<OrderEntry> {
|
||||
private boolean myJdkFound;
|
||||
|
||||
@Override
|
||||
public boolean value(OrderEntry orderEntry) {
|
||||
if (orderEntry instanceof JdkOrderEntry) {
|
||||
myJdkFound = true;
|
||||
}
|
||||
return !myJdkFound;
|
||||
}
|
||||
}
|
||||
|
||||
private static class AfterJdkOrderEntryCondition implements Condition<OrderEntry> {
|
||||
private boolean myJdkFound;
|
||||
|
||||
@Override
|
||||
public boolean value(OrderEntry orderEntry) {
|
||||
if (orderEntry instanceof JdkOrderEntry) {
|
||||
myJdkFound = true;
|
||||
return false;
|
||||
}
|
||||
return myJdkFound;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,29 +17,38 @@ package com.intellij.util;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.CompilerProjectExtension;
|
||||
import com.intellij.openapi.roots.OrderEnumerator;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.containers.OrderedSet;
|
||||
import gnu.trove.TObjectHashingStrategy;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
*/
|
||||
public class JarClasspathHelper {
|
||||
|
||||
public static void patchFiles(VirtualFile[] files, Project project) {
|
||||
public static OrderedSet<VirtualFile> patchFiles(OrderedSet<VirtualFile> files, Project project) {
|
||||
if (!Registry.is("jar.build")) {
|
||||
return;
|
||||
return files;
|
||||
}
|
||||
String path = getJarsPath(project);
|
||||
for (int i = 0, filesLength = files.length; i < filesLength; i++) {
|
||||
VirtualFile file = files[i];
|
||||
|
||||
final OrderedSet<VirtualFile> result = new OrderedSet<VirtualFile>(TObjectHashingStrategy.CANONICAL);
|
||||
final Collection<VirtualFile> modulesOutputs = OrderEnumerator.orderEntries(project).withoutLibraries().withoutSdk().getClassesRoots();
|
||||
for (VirtualFile file : files) {
|
||||
VirtualFile jar = getJarFile(path, file.getName());
|
||||
if (jar != null) {
|
||||
files[i] = jar;
|
||||
if (modulesOutputs.contains(file) && jar != null) {
|
||||
result.add(jar);
|
||||
}
|
||||
else {
|
||||
result.add(file);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.intellij.util.PathsList;
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
@SuppressWarnings({"deprecation"})
|
||||
public class OrderEntriesTest extends ModuleRootManagerTestCase {
|
||||
public void testLibrary() throws Exception {
|
||||
addLibraryDependency(myModule, createJDomLibrary());
|
||||
@@ -92,7 +93,7 @@ public class OrderEntriesTest extends ModuleRootManagerTestCase {
|
||||
private PathsList collectByOrderEnumerator(OrderRootType type) {
|
||||
final OrderEnumerator base = OrderEnumerator.orderEntries(myModule);
|
||||
if (type == OrderRootType.CLASSES_AND_OUTPUT) {
|
||||
return base.recursively().getPathsList();
|
||||
return base.compileOnly().recursively().getPathsList();
|
||||
}
|
||||
if (type == OrderRootType.COMPILATION_CLASSES) {
|
||||
return base.recursively().exportedOnly().getPathsList();
|
||||
|
||||
@@ -69,6 +69,10 @@ public abstract class OrderEnumerator {
|
||||
return withoutSdk().withoutDepModules().withoutModuleSourceEntries();
|
||||
}
|
||||
|
||||
public OrderEnumerator sdkOnly() {
|
||||
return withoutDepModules().withoutLibraries().withoutModuleSourceEntries();
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively process modules on which the module depends
|
||||
* @return this instance
|
||||
|
||||
@@ -44,6 +44,13 @@ public class OrderRootType {
|
||||
* <li> production and test output for modules
|
||||
* <li> classes roots for libraries and jdk unless scope is 'provided'
|
||||
* <li> recursively for module dependencies with scope != 'provided'
|
||||
*
|
||||
* @deprecated
|
||||
* <ul>
|
||||
* <li> for libraries and jdk use {@link #CLASSES}
|
||||
* <li> to get module output roots use {@link CompilerModuleExtension#getOutputRoots}<code>(true)</code>
|
||||
* <li> to recursively process module dependencies use <code>OrderEnumerator.orderEntries(module).compileOnly().recursively()</code>
|
||||
* </ul>
|
||||
*/
|
||||
public static final OrderRootType CLASSES_AND_OUTPUT = new OrderRootType("CLASSES_AND_OUTPUT");
|
||||
|
||||
@@ -53,6 +60,13 @@ public class OrderRootType {
|
||||
* <li> production and test output for modules
|
||||
* <li> classes roots for libraries and jdk
|
||||
* <li> recursively for module dependencies: only exported items
|
||||
|
||||
* @deprecated
|
||||
* <ul>
|
||||
* <li> for libraries and jdk use {@link #CLASSES}
|
||||
* <li> to get module output roots use {@link CompilerModuleExtension#getOutputRoots}<code>(true)</code>
|
||||
* <li> to recursively process module dependencies use <code>OrderEnumerator.orderEntries(module).recursively().exportedOnly()</code>
|
||||
* </ul>
|
||||
*/
|
||||
public static final OrderRootType COMPILATION_CLASSES = new OrderRootType("COMPILATION_CLASSES");
|
||||
|
||||
@@ -62,6 +76,13 @@ public class OrderRootType {
|
||||
* <li> production output for modules
|
||||
* <li> classes roots for libraries and jdk with scope suitable for production compile
|
||||
* <li> recursively for module dependencies with scope suitable for production compile: only exported items
|
||||
|
||||
* @deprecated
|
||||
* <ul>
|
||||
* <li> for libraries and jdk use {@link #CLASSES}
|
||||
* <li> to get module output root use {@link CompilerModuleExtension#getCompilerOutputPath()}
|
||||
* <li> to recursively process module dependencies use <code>OrderEnumerator.orderEntries(module).compileOnly().productionOnly().recursively().exportedOnly()</code>
|
||||
* </ul>
|
||||
*/
|
||||
public static final OrderRootType PRODUCTION_COMPILATION_CLASSES = new OrderRootType("PRODUCTION_COMPILATION_CLASSES");
|
||||
|
||||
|
||||
@@ -123,15 +123,20 @@ public class PathsList {
|
||||
}
|
||||
|
||||
public String getPathsString() {
|
||||
final StringBuffer buffer = new StringBuffer();
|
||||
String separator = "";
|
||||
final List<String> classPath = getPathList();
|
||||
for (final String path : classPath) {
|
||||
buffer.append(separator);
|
||||
buffer.append(path);
|
||||
separator = File.pathSeparator;
|
||||
final StringBuilder buffer = StringBuilderSpinAllocator.alloc();
|
||||
try {
|
||||
String separator = "";
|
||||
final List<String> classPath = getPathList();
|
||||
for (final String path : classPath) {
|
||||
buffer.append(separator);
|
||||
buffer.append(path);
|
||||
separator = File.pathSeparator;
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
finally {
|
||||
StringBuilderSpinAllocator.dispose(buffer);
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
public List<String> getPathList() {
|
||||
|
||||
Reference in New Issue
Block a user