mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Get rid of "file-based library" concept
This commit is contained in:
@@ -34,7 +34,7 @@ public abstract class DownloadableLibraryTypeBase extends DownloadableLibraryTyp
|
||||
@NotNull String groupId,
|
||||
@NotNull Icon icon,
|
||||
@NotNull URL... localUrls) {
|
||||
super(new PersistentLibraryKind<LibraryVersionProperties>(libraryTypeId, false) {
|
||||
super(new PersistentLibraryKind<LibraryVersionProperties>(libraryTypeId) {
|
||||
@NotNull
|
||||
@Override
|
||||
public LibraryVersionProperties createDefaultProperties() {
|
||||
|
||||
+51
-30
@@ -36,7 +36,12 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.Collections.singletonList;
|
||||
|
||||
@PlatformTestCase.WrapInCommand
|
||||
public class DirectoryIndexImplTest extends IdeaTestCase {
|
||||
@@ -55,6 +60,9 @@ public class DirectoryIndexImplTest extends IdeaTestCase {
|
||||
private VirtualFile myTestSrc1;
|
||||
private VirtualFile myPack1Dir;
|
||||
private VirtualFile myPack2Dir;
|
||||
private VirtualFile myFileLibDir;
|
||||
private VirtualFile myFileLibSrc;
|
||||
private VirtualFile myFileLibCls;
|
||||
private VirtualFile myLibDir;
|
||||
private VirtualFile myLibSrcDir;
|
||||
private VirtualFile myLibClsDir;
|
||||
@@ -73,10 +81,11 @@ public class DirectoryIndexImplTest extends IdeaTestCase {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
myRootVFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(root);
|
||||
assertNotNull(myRootVFile);
|
||||
/*
|
||||
root
|
||||
lib
|
||||
file.src
|
||||
file.cls
|
||||
module1
|
||||
src1
|
||||
pack1
|
||||
@@ -93,16 +102,21 @@ public class DirectoryIndexImplTest extends IdeaTestCase {
|
||||
out
|
||||
module1
|
||||
*/
|
||||
myRootVFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(root);
|
||||
assertNotNull(myRootVFile);
|
||||
|
||||
myFileLibDir = myRootVFile.createChildDirectory(DirectoryIndexImplTest.this, "lib");
|
||||
myFileLibSrc = myFileLibDir.createChildData(DirectoryIndexImplTest.this, "file.src");
|
||||
myFileLibCls = myFileLibDir.createChildData(DirectoryIndexImplTest.this, "file.cls");
|
||||
myModule1Dir = myRootVFile.createChildDirectory(DirectoryIndexImplTest.this, "module1");
|
||||
mySrcDir1 = myModule1Dir.createChildDirectory(DirectoryIndexImplTest.this, "src1");
|
||||
myPack1Dir = mySrcDir1.createChildDirectory(DirectoryIndexImplTest.this, "pack1");
|
||||
myTestSrc1 = mySrcDir1.createChildDirectory(DirectoryIndexImplTest.this, "testSrc");
|
||||
myPack2Dir = myTestSrc1.createChildDirectory(DirectoryIndexImplTest.this, "pack2");
|
||||
|
||||
myLibDir = myModule1Dir.createChildDirectory(DirectoryIndexImplTest.this, "lib");
|
||||
myLibSrcDir = myLibDir.createChildDirectory(DirectoryIndexImplTest.this, "src");
|
||||
myLibClsDir = myLibDir.createChildDirectory(DirectoryIndexImplTest.this, "cls");
|
||||
|
||||
myModule2Dir = myModule1Dir.createChildDirectory(DirectoryIndexImplTest.this, "module2");
|
||||
mySrcDir2 = myModule2Dir.createChildDirectory(DirectoryIndexImplTest.this, "src2");
|
||||
myCvsDir = mySrcDir2.createChildDirectory(DirectoryIndexImplTest.this, "CVS");
|
||||
@@ -114,6 +128,7 @@ public class DirectoryIndexImplTest extends IdeaTestCase {
|
||||
myModule1OutputDir = myOutputDir.createChildDirectory(DirectoryIndexImplTest.this, "module1");
|
||||
|
||||
getCompilerProjectExtension().setCompilerOutputUrl(myOutputDir.getUrl());
|
||||
ModuleManager moduleManager = ModuleManager.getInstance(myProject);
|
||||
|
||||
// fill roots of module1
|
||||
{
|
||||
@@ -121,10 +136,10 @@ public class DirectoryIndexImplTest extends IdeaTestCase {
|
||||
PsiTestUtil.addContentRoot(myModule, myModule1Dir);
|
||||
PsiTestUtil.addSourceRoot(myModule, mySrcDir1);
|
||||
PsiTestUtil.addSourceRoot(myModule, myTestSrc1, true);
|
||||
ModuleRootModificationUtil.addModuleLibrary(myModule, "lib.js",
|
||||
singletonList(myFileLibCls.getUrl()), singletonList(myFileLibSrc.getUrl()));
|
||||
}
|
||||
|
||||
ModuleManager moduleManager = ModuleManager.getInstance(myProject);
|
||||
|
||||
// fill roots of module2
|
||||
{
|
||||
VirtualFile moduleFile = myModule2Dir.createChildData(DirectoryIndexImplTest.this, "module2.iml");
|
||||
@@ -133,8 +148,8 @@ public class DirectoryIndexImplTest extends IdeaTestCase {
|
||||
PsiTestUtil.addContentRoot(myModule2, myModule2Dir);
|
||||
PsiTestUtil.addSourceRoot(myModule2, mySrcDir2);
|
||||
PsiTestUtil.addExcludedRoot(myModule2, myExcludeDir);
|
||||
ModuleRootModificationUtil.addModuleLibrary(myModule2, "lib", Collections.singletonList(myLibClsDir.getUrl()),
|
||||
Collections.singletonList(myLibSrcDir.getUrl()));
|
||||
ModuleRootModificationUtil.addModuleLibrary(myModule2, "lib",
|
||||
singletonList(myLibClsDir.getUrl()), singletonList(myLibSrcDir.getUrl()));
|
||||
}
|
||||
|
||||
// fill roots of module3
|
||||
@@ -164,28 +179,32 @@ public class DirectoryIndexImplTest extends IdeaTestCase {
|
||||
public void testDirInfos() {
|
||||
checkInfoNull(myRootVFile);
|
||||
|
||||
checkInfo(myModule1Dir, myModule, false, false, false, false, null, new Module[]{});
|
||||
checkInfo(mySrcDir1, myModule, true, false, false, false, "", new Module[]{myModule});
|
||||
checkInfo(myPack1Dir, myModule, true, false, false, false, "pack1", new Module[]{myModule});
|
||||
checkInfo(myTestSrc1, myModule, true, true, false, false, "", new Module[]{myModule});
|
||||
checkInfo(myPack2Dir, myModule, true, true, false, false, "pack2", new Module[]{myModule});
|
||||
checkInfo(myLibDir, myModule, false, false, false, false, null, new Module[]{});
|
||||
// beware: files in directory index
|
||||
checkInfo(myFileLibSrc, null, false, false, false, true, "");
|
||||
checkInfo(myFileLibCls, null, false, false, true, false, "");
|
||||
|
||||
checkInfo(myLibSrcDir, myModule, false, false, false, true, "", new Module[]{myModule2});
|
||||
checkInfo(myLibClsDir, myModule, false, false, true, false, "", new Module[]{myModule2});
|
||||
checkInfo(myModule1Dir, myModule, false, false, false, false, null);
|
||||
checkInfo(mySrcDir1, myModule, true, false, false, false, "", myModule);
|
||||
checkInfo(myPack1Dir, myModule, true, false, false, false, "pack1", myModule);
|
||||
checkInfo(myTestSrc1, myModule, true, true, false, false, "", myModule);
|
||||
checkInfo(myPack2Dir, myModule, true, true, false, false, "pack2", myModule);
|
||||
|
||||
checkInfo(myModule2Dir, myModule2, false, false, false, false, null, new Module[]{});
|
||||
checkInfo(mySrcDir2, myModule2, true, false, false, false, "", new Module[]{myModule2, myModule3});
|
||||
checkInfo(myLibDir, myModule, false, false, false, false, null);
|
||||
checkInfo(myLibSrcDir, myModule, false, false, false, true, "", myModule2);
|
||||
checkInfo(myLibClsDir, myModule, false, false, true, false, "", myModule2);
|
||||
|
||||
checkInfo(myModule2Dir, myModule2, false, false, false, false, null);
|
||||
checkInfo(mySrcDir2, myModule2, true, false, false, false, "", myModule2, myModule3);
|
||||
checkInfoNull(myCvsDir);
|
||||
checkInfoNull(myExcludeDir);
|
||||
|
||||
checkInfo(myModule3Dir, myModule3, false, false, false, false, null, new Module[]{});
|
||||
checkInfo(myModule3Dir, myModule3, false, false, false, false, null);
|
||||
}
|
||||
|
||||
public void testDirsByPackageName() {
|
||||
checkPackage(new VirtualFile[]{mySrcDir1, myTestSrc1, myLibSrcDir, myLibClsDir, mySrcDir2}, "");
|
||||
checkPackage(new VirtualFile[]{myPack1Dir}, "pack1");
|
||||
checkPackage(new VirtualFile[]{myPack2Dir}, "pack2");
|
||||
checkPackage("", myFileLibSrc, myFileLibCls, mySrcDir1, myTestSrc1, myLibSrcDir, myLibClsDir, mySrcDir2);
|
||||
checkPackage("pack1", myPack1Dir);
|
||||
checkPackage("pack2", myPack2Dir);
|
||||
}
|
||||
|
||||
public void testCreateDir() throws Exception {
|
||||
@@ -310,8 +329,8 @@ public class DirectoryIndexImplTest extends IdeaTestCase {
|
||||
|
||||
myIndex.checkConsistency();
|
||||
|
||||
checkInfo(myModule2Dir, myModule2, false, false, false, false, null, new Module[]{});
|
||||
checkInfo(mySrcDir2, myModule2, true, false, false, false, "", new Module[]{myModule2, myModule3});
|
||||
checkInfo(myModule2Dir, myModule2, false, false, false, false, null);
|
||||
checkInfo(mySrcDir2, myModule2, true, false, false, false, "", myModule2, myModule3);
|
||||
}
|
||||
|
||||
public void testResettingProjectOutputPath() throws Exception {
|
||||
@@ -464,8 +483,8 @@ public class DirectoryIndexImplTest extends IdeaTestCase {
|
||||
|
||||
myIndex.checkConsistency();
|
||||
|
||||
checkInfo(myModule1Dir, myModule, false, false, true, false, "", new Module[]{myModule});
|
||||
checkInfo(mySrcDir1, myModule, true, false, true, false, "", new Module[]{myModule});
|
||||
checkInfo(myModule1Dir, myModule, false, false, true, false, "", myModule);
|
||||
checkInfo(mySrcDir1, myModule, true, false, true, false, "", myModule);
|
||||
}
|
||||
|
||||
|
||||
@@ -477,13 +496,13 @@ public class DirectoryIndexImplTest extends IdeaTestCase {
|
||||
}
|
||||
|
||||
private void checkInfo(VirtualFile dir,
|
||||
Module module,
|
||||
@Nullable Module module,
|
||||
boolean isInModuleSource,
|
||||
boolean isTestSource,
|
||||
boolean isInLibrary,
|
||||
boolean isInLibrarySource,
|
||||
@Nullable String packageName,
|
||||
Module[] modulesOfOrderEntries) {
|
||||
Module... modulesOfOrderEntries) {
|
||||
DirectoryInfo info = myIndex.getInfoForDirectory(dir);
|
||||
assertNotNull(info);
|
||||
assertEquals(module, info.module);
|
||||
@@ -493,7 +512,9 @@ public class DirectoryIndexImplTest extends IdeaTestCase {
|
||||
assertEquals(isInLibrarySource, info.isInLibrarySource);
|
||||
|
||||
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
|
||||
assertEquals(packageName, fileIndex.getPackageNameByDirectory(dir));
|
||||
if (dir.isDirectory()) {
|
||||
assertEquals(packageName, fileIndex.getPackageNameByDirectory(dir));
|
||||
}
|
||||
|
||||
assertEquals(modulesOfOrderEntries.length, info.getOrderEntries().size());
|
||||
for (Module aModule : modulesOfOrderEntries) {
|
||||
@@ -513,7 +534,7 @@ public class DirectoryIndexImplTest extends IdeaTestCase {
|
||||
assertNull(info);
|
||||
}
|
||||
|
||||
private void checkPackage(VirtualFile[] expectedDirs, String packageName) {
|
||||
private void checkPackage(String packageName, VirtualFile... expectedDirs) {
|
||||
VirtualFile[] actualDirs = myIndex.getDirectoriesByPackageName(packageName, true).toArray(VirtualFile.EMPTY_ARRAY);
|
||||
assertNotNull(actualDirs);
|
||||
HashSet<VirtualFile> set1 = new HashSet<VirtualFile>();
|
||||
|
||||
+4
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -65,9 +65,11 @@ abstract class LibraryOrderEntryBaseImpl extends OrderEntryBaseImpl implements L
|
||||
|
||||
public VirtualFile[] getRootFiles(@NotNull OrderRootType type) {
|
||||
RootProvider rootProvider = getRootProvider();
|
||||
return rootProvider == null ? VirtualFile.EMPTY_ARRAY : filterDirectories(rootProvider.getFiles(type));
|
||||
return rootProvider != null ? rootProvider.getFiles(type) : VirtualFile.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
/** @deprecated has no sense (to remove in IDEA 13) */
|
||||
@SuppressWarnings({"MethodMayBeStatic", "UnusedDeclaration"})
|
||||
protected VirtualFile[] filterDirectories(@NotNull VirtualFile[] files) {
|
||||
List<VirtualFile> filtered = ContainerUtil.mapNotNull(files, new NullableFunction<VirtualFile, VirtualFile>() {
|
||||
@Override
|
||||
|
||||
+4
-22
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,11 +19,12 @@ package com.intellij.openapi.roots.impl;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.roots.*;
|
||||
import com.intellij.openapi.roots.impl.libraries.LibraryEx;
|
||||
import com.intellij.openapi.roots.libraries.*;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTable;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.InvalidDataException;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.pointers.VirtualFilePointerManager;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
@@ -44,15 +45,11 @@ class LibraryOrderEntryImpl extends LibraryOrderEntryBaseImpl implements Library
|
||||
@NonNls private static final String LEVEL_ATTR = "level";
|
||||
private final MyOrderEntryLibraryTableListener myLibraryListener = new MyOrderEntryLibraryTableListener();
|
||||
@NonNls private static final String EXPORTED_ATTR = "exported";
|
||||
private PersistentLibraryKind myLibraryKind;
|
||||
|
||||
LibraryOrderEntryImpl(@NotNull Library library, @NotNull RootModelImpl rootModel, @NotNull ProjectRootManagerImpl projectRootManager) {
|
||||
super(rootModel, projectRootManager);
|
||||
LOG.assertTrue(library.getTable() != null);
|
||||
myLibrary = library;
|
||||
if (myLibrary instanceof LibraryEx) {
|
||||
myLibraryKind = ((LibraryEx)myLibrary).getKind();
|
||||
}
|
||||
addListeners();
|
||||
init();
|
||||
}
|
||||
@@ -79,7 +76,6 @@ class LibraryOrderEntryImpl extends LibraryOrderEntryBaseImpl implements Library
|
||||
}
|
||||
else {
|
||||
myLibrary = that.myLibrary;
|
||||
myLibraryKind = that.myLibraryKind;
|
||||
}
|
||||
myExported = that.myExported;
|
||||
myScope = that.myScope;
|
||||
@@ -109,9 +105,6 @@ class LibraryOrderEntryImpl extends LibraryOrderEntryBaseImpl implements Library
|
||||
myLibraryName = null;
|
||||
myLibraryLevel = null;
|
||||
myLibrary = library;
|
||||
if (library instanceof LibraryEx) {
|
||||
myLibraryKind = ((LibraryEx)library).getKind();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -251,9 +244,6 @@ class LibraryOrderEntryImpl extends LibraryOrderEntryBaseImpl implements Library
|
||||
myLibrary = newLibrary;
|
||||
myLibraryName = null;
|
||||
myLibraryLevel = null;
|
||||
if (newLibrary instanceof LibraryEx && myLibraryKind == null) {
|
||||
myLibraryKind = ((LibraryEx)newLibrary).getKind();
|
||||
}
|
||||
updateFromRootProviderAndSubscribe();
|
||||
}
|
||||
}
|
||||
@@ -291,12 +281,4 @@ class LibraryOrderEntryImpl extends LibraryOrderEntryBaseImpl implements Library
|
||||
public void afterLibraryRemoved(Library library) {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected VirtualFile[] filterDirectories(@NotNull VirtualFile[] files) {
|
||||
if (myLibraryKind != null && myLibraryKind.isFileBased()) {
|
||||
return files;
|
||||
}
|
||||
return super.filterDirectories(files);
|
||||
}
|
||||
}
|
||||
|
||||
+11
-7
@@ -23,23 +23,27 @@ import org.jetbrains.annotations.NotNull;
|
||||
* @author yole
|
||||
*/
|
||||
public abstract class PersistentLibraryKind<P extends LibraryProperties> extends LibraryKind {
|
||||
private final boolean myFileBased;
|
||||
|
||||
/**
|
||||
* @param kindId must be unique among all {@link com.intellij.openapi.roots.libraries.LibraryType} and {@link com.intellij.openapi.roots.libraries.LibraryPresentationProvider} implementations
|
||||
* @param based
|
||||
* @param kindId must be unique among all {@link com.intellij.openapi.roots.libraries.LibraryType} and
|
||||
* {@link com.intellij.openapi.roots.libraries.LibraryPresentationProvider} implementations.
|
||||
*/
|
||||
public PersistentLibraryKind(@NotNull @NonNls String kindId) {
|
||||
super(kindId);
|
||||
}
|
||||
|
||||
/** @deprecated 'fileBased' has no sense, use {@linkplain #PersistentLibraryKind(String)} (to remove in IDEA 13) */
|
||||
@SuppressWarnings("UnusedParameters")
|
||||
public PersistentLibraryKind(@NotNull @NonNls String kindId, boolean fileBased) {
|
||||
super(kindId);
|
||||
myFileBased = fileBased;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public abstract P createDefaultProperties();
|
||||
|
||||
|
||||
/** @deprecated has no sense (to remove in IDEA 13) */
|
||||
@SuppressWarnings({"UnusedDeclaration", "MethodMayBeStatic"})
|
||||
public boolean isFileBased() {
|
||||
return myFileBased;
|
||||
return false;
|
||||
}
|
||||
|
||||
public OrderRootType[] getAdditionalRootTypes() {
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ import javax.swing.*;
|
||||
* @author nik
|
||||
*/
|
||||
public class RepositoryLibraryType extends LibraryType<RepositoryLibraryProperties> {
|
||||
private static final PersistentLibraryKind<RepositoryLibraryProperties> LIBRARY_KIND = new PersistentLibraryKind<RepositoryLibraryProperties>("repository", false) {
|
||||
private static final PersistentLibraryKind<RepositoryLibraryProperties> LIBRARY_KIND = new PersistentLibraryKind<RepositoryLibraryProperties>("repository") {
|
||||
@NotNull
|
||||
@Override
|
||||
public RepositoryLibraryProperties createDefaultProperties() {
|
||||
|
||||
Reference in New Issue
Block a user