use of com.intellij.openapi.roots.ContentEntry in project intellij-plugins by JetBrains.
the class FlashUmlTest method doTestImpl.
private DiagramBuilder doTestImpl(@Nullable File projectRoot, String[] files, String[] additionalClasses, Computable<GlobalSearchScope> scopeProvider, @Nullable EnumSet<FlashUmlDependenciesSettingsOption> dependencies, @Nullable String expectedFileNamePrefix) throws Exception {
List<VirtualFile> vFiles = new ArrayList<>(files.length);
for (String file : files) {
vFiles.add(getVirtualFile(BASE_PATH + file));
}
ApplicationManager.getApplication().runWriteAction(() -> {
final ModuleRootManager rootManager = ModuleRootManager.getInstance(myModule);
final ModifiableRootModel rootModel = rootManager.getModifiableModel();
ContentEntry[] contentEntries = rootModel.getContentEntries();
for (ContentEntry contentEntry : contentEntries) {
rootModel.removeContentEntry(contentEntry);
}
rootModel.commit();
});
configureByFiles(projectRoot, VfsUtilCore.toVirtualFileArray(vFiles));
final LinkedHashMap<Integer, String> markers = JSTestUtils.extractPositionMarkers(getProject(), getEditor().getDocument());
assertFalse(markers.isEmpty());
DiagramBuilder builder = null;
int i = 1;
for (Map.Entry<Integer, String> marker : markers.entrySet()) {
getEditor().getCaretModel().moveToOffset(marker.getKey());
i++;
String expectedPrefix = StringUtil.isNotEmpty(marker.getValue()) ? marker.getValue() : expectedFileNamePrefix;
final DataContext dataContext = DataManager.getInstance().getDataContext();
final DiagramProvider[] providers = DiagramProvider.findProviders(dataContext, "unknown");
final FlashUmlProvider provider = ContainerUtil.findInstance(providers, FlashUmlProvider.class);
assertNotNull("Flash UML provider not found", provider);
final String actualOriginFqn = provider.getVfsResolver().getQualifiedName(provider.getElementManager().findInDataContext(dataContext));
final Object actualOrigin = provider.getVfsResolver().resolveElementByFQN(actualOriginFqn, getProject());
builder = UmlGraphBuilderFactory.create(myProject, provider, actualOrigin, null);
Disposer.register(getTestRootDisposable(), builder);
final DiagramDataModel<Object> model = builder.getDataModel();
DiagramConfiguration configuration = DiagramConfiguration.getConfiguration();
String originalCategories = configuration.categories.get(provider.getID());
if (dependencies != null) {
model.setShowDependencies(true);
EnumSet<FlashUmlDependenciesSettingsOption> disabledOptions = EnumSet.complementOf(dependencies);
configuration.categories.put(provider.getID(), StringUtil.join(disabledOptions, option -> option.getDisplayName(), ";"));
} else {
model.setShowDependencies(false);
}
try {
model.refreshDataModel();
// first limit elements by scope
Collection<DiagramNode<Object>> nodesToRemove = new ArrayList<>();
for (DiagramNode<Object> node : model.getNodes()) {
if (node.getIdentifyingElement() instanceof JSClass && !scopeProvider.compute().contains(((JSClass) node.getIdentifyingElement()).getContainingFile().getVirtualFile())) {
nodesToRemove.add(node);
}
}
for (DiagramNode<Object> node : nodesToRemove) {
model.removeNode(node);
}
builder.updateGraph();
// then add explicitly required classes
for (String aClass : additionalClasses) {
JSClass c = JSTestUtils.findClassByQName(aClass, GlobalSearchScope.allScope(myProject));
final DiagramNode node = model.addElement(c);
if (node != null) {
builder.createDraggedNode(node, node.getTooltip(), DiagramUtils.getBestPositionForNode(builder));
builder.updateGraph();
}
}
assertModel(expectedPrefix, provider, actualOriginFqn, model);
} finally {
configuration.categories.put(provider.getID(), originalCategories);
}
}
assert builder != null;
return builder;
}
use of com.intellij.openapi.roots.ContentEntry in project intellij-plugins by JetBrains.
the class CreateFlexUnitTestDialog method createTestSourceFolderAndPackage.
@Nullable
private static PsiDirectory createTestSourceFolderAndPackage(final Module module, final String srcRootPath, final String packageName) {
final String path = FileUtil.toSystemIndependentName(srcRootPath);
VirtualFile contentRoot = null;
for (VirtualFile root : ModuleRootManager.getInstance(module).getContentRoots()) {
if (path.startsWith(root.getPath() + "/")) {
contentRoot = root;
break;
}
}
if (contentRoot != null) {
final ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
try {
final VirtualFile finalContentRoot = contentRoot;
final VirtualFile folder = ApplicationManager.getApplication().runWriteAction((NullableComputable<VirtualFile>) () -> {
try {
final VirtualFile srcRoot = VfsUtil.createDirectoryIfMissing(finalContentRoot, path.substring((finalContentRoot.getPath() + "/").length()));
final VirtualFile folder1 = packageName.isEmpty() ? srcRoot : VfsUtil.createDirectoryIfMissing(srcRoot, packageName.replace('.', '/'));
final ContentEntry contentEntry = MarkRootActionBase.findContentEntry(model, folder1);
if (contentEntry != null) {
contentEntry.addSourceFolder(srcRoot, true);
model.commit();
return folder1;
}
} catch (IOException ignore) {
}
return null;
});
return folder == null ? null : PsiManager.getInstance(module.getProject()).findDirectory(folder);
} finally {
if (model.isWritable()) {
model.dispose();
}
}
}
return null;
}
use of com.intellij.openapi.roots.ContentEntry in project intellij-plugins by JetBrains.
the class CreateFlexUnitTestDialog method suggestTestSourceRootPath.
private static String suggestTestSourceRootPath(final Module module, final VirtualFile file) {
if (file != null) {
final ContentEntry contentEntry = MarkRootActionBase.findContentEntry(ModuleRootManager.getInstance(module), file);
if (contentEntry != null) {
boolean mavenStyle = false;
for (VirtualFile srcRoot : contentEntry.getSourceFolderFiles()) {
if (srcRoot.getUrl().equals(contentEntry.getUrl() + "/src/main/flex")) {
mavenStyle = true;
break;
}
}
final String basePath = VfsUtilCore.urlToPath(contentEntry.getUrl()) + (mavenStyle ? "/src/test/flex" : "/testSrc");
String path = basePath;
int i = 0;
while (LocalFileSystem.getInstance().findFileByPath(path) != null) {
path = basePath + (++i);
}
return path;
}
}
return "";
}
use of com.intellij.openapi.roots.ContentEntry in project intellij-plugins by JetBrains.
the class DartServerRootsHandler method updateRoots.
private void updateRoots() {
final DartSdk sdk = DartSdk.getDartSdk(myProject);
if (sdk == null || !DartAnalysisServerService.isDartSdkVersionSufficient(sdk)) {
DartAnalysisServerService.getInstance(myProject).stopServer();
}
final List<String> newIncludedRoots = new SmartList<>();
final List<String> newExcludedRoots = new SmartList<>();
if (sdk != null) {
@SuppressWarnings("ConstantConditions") final String dotIdeaPath = PathUtil.getParentPath(myProject.getProjectFilePath());
if (dotIdeaPath.endsWith("/.idea")) {
newExcludedRoots.add(FileUtil.toSystemDependentName(dotIdeaPath));
}
for (Module module : DartSdkLibUtil.getModulesWithDartSdkEnabled(myProject)) {
final Set<String> excludedPackageSymlinkUrls = getExcludedPackageSymlinkUrls(module);
for (ContentEntry contentEntry : ModuleRootManager.getInstance(module).getContentEntries()) {
final String contentEntryUrl = contentEntry.getUrl();
if (contentEntryUrl.startsWith(URLUtil.FILE_PROTOCOL + URLUtil.SCHEME_SEPARATOR)) {
newIncludedRoots.add(FileUtil.toSystemDependentName(VfsUtilCore.urlToPath(contentEntryUrl)));
for (String excludedUrl : contentEntry.getExcludeFolderUrls()) {
if (excludedUrl.startsWith(contentEntryUrl) && !excludedPackageSymlinkUrls.contains(excludedUrl)) {
newExcludedRoots.add(FileUtil.toSystemDependentName(VfsUtilCore.urlToPath(excludedUrl)));
}
}
}
}
}
}
if (!myIncludedRoots.equals(newIncludedRoots) || !myExcludedRoots.equals(newExcludedRoots)) {
myIncludedRoots.clear();
myExcludedRoots.clear();
if (DartAnalysisServerService.getInstance(myProject).updateRoots(newIncludedRoots, newExcludedRoots)) {
myIncludedRoots.addAll(newIncludedRoots);
myExcludedRoots.addAll(newExcludedRoots);
}
}
}
use of com.intellij.openapi.roots.ContentEntry in project intellij-plugins by JetBrains.
the class DartModuleBuilder method setupRootModel.
@Override
public void setupRootModel(final ModifiableRootModel modifiableRootModel) throws ConfigurationException {
final ContentEntry contentEntry = doAddContentEntry(modifiableRootModel);
final VirtualFile baseDir = contentEntry == null ? null : contentEntry.getFile();
if (baseDir != null) {
setupProject(modifiableRootModel, baseDir, myWizardData);
}
}
Aggregations