use of com.intellij.openapi.vfs.VirtualFileManager in project intellij-community by JetBrains.
the class PersistentFileSetManager method loadState.
@Override
public void loadState(Element state) {
final VirtualFileManager vfManager = VirtualFileManager.getInstance();
for (Object child : state.getChildren(FILE_ELEMENT)) {
if (child instanceof Element) {
final Element fileElement = (Element) child;
final Attribute filePathAttr = fileElement.getAttribute(PATH_ATTR);
if (filePathAttr != null) {
final String filePath = filePathAttr.getValue();
VirtualFile vf = vfManager.findFileByUrl(filePath);
if (vf != null) {
myFiles.add(vf);
}
}
}
}
}
use of com.intellij.openapi.vfs.VirtualFileManager in project intellij-community by JetBrains.
the class AntConfigurationImpl method loadState.
public void loadState(Element state) {
myIsInitialized = Boolean.FALSE;
try {
myAntWorkspaceConfiguration.loadFromProjectSettings(state);
} catch (InvalidDataException e) {
LOG.error(e);
return;
}
List<Pair<Element, String>> files = new ArrayList<>();
for (Iterator<Element> iterator = state.getChildren(BUILD_FILE).iterator(); iterator.hasNext(); ) {
Element element = iterator.next();
iterator.remove();
String url = element.getAttributeValue(URL);
if (url != null) {
files.add(Pair.create(element, url));
}
}
final VirtualFileManager vfManager = VirtualFileManager.getInstance();
// contexts
myAntFileToContextFileMap.clear();
for (Element element : state.getChildren(CONTEXT_MAPPING)) {
String url = element.getAttributeValue(URL);
String contextUrl = element.getAttributeValue(CONTEXT);
VirtualFile file = vfManager.findFileByUrl(url);
VirtualFile contextFile = vfManager.findFileByUrl(contextUrl);
if (file != null && contextFile != null) {
myAntFileToContextFileMap.put(file, contextFile);
}
}
getProperties().readExternal(state);
runWhenInitialized(() -> {
String title = AntBundle.message("loading.ant.config.progress");
queueLater(new Task.Backgroundable(getProject(), title, false) {
public void run(@NotNull final ProgressIndicator indicator) {
if (getProject().isDisposed()) {
return;
}
indicator.setIndeterminate(true);
indicator.pushState();
try {
indicator.setText(title);
ApplicationManager.getApplication().runReadAction(() -> {
try {
myInitThread = Thread.currentThread();
// first, remove existing files
for (AntBuildFile file : myBuildFiles) {
removeBuildFileImpl(file);
}
myBuildFiles.clear();
// then fill the configuration with the files configured in xml
List<Pair<Element, AntBuildFileBase>> buildFiles = new ArrayList<>(files.size());
for (Pair<Element, String> pair : files) {
final Element element = pair.getFirst();
final VirtualFile file = vfManager.findFileByUrl(pair.getSecond());
if (file == null) {
continue;
}
try {
final AntBuildFileBase buildFile = addBuildFileImpl(file);
buildFile.readProperties(element);
buildFiles.add(Pair.create(element, buildFile));
} catch (AntNoFileException ignored) {
} catch (InvalidDataException e) {
LOG.error(e);
}
}
// updating properties separately to avoid unnecessary building of PSI after clearing caches
for (Pair<Element, AntBuildFileBase> pair : buildFiles) {
final AntBuildFileBase buildFile = pair.getSecond();
buildFile.updateProperties();
final VirtualFile vFile = buildFile.getVirtualFile();
final String buildFileUrl = vFile != null ? vFile.getUrl() : null;
for (Element e : pair.getFirst().getChildren(EXECUTE_ON_ELEMENT)) {
final String eventId = e.getAttributeValue(EVENT_ELEMENT);
ExecutionEvent event = null;
final String targetName = e.getAttributeValue(TARGET_ELEMENT);
if (ExecuteBeforeCompilationEvent.TYPE_ID.equals(eventId)) {
event = ExecuteBeforeCompilationEvent.getInstance();
} else if (ExecuteAfterCompilationEvent.TYPE_ID.equals(eventId)) {
event = ExecuteAfterCompilationEvent.getInstance();
} else if ("beforeRun".equals(eventId)) {
/*
for compatibility with previous format
<buildFile url="file://$PROJECT_DIR$/module/src/support-scripts.xml">
<executeOn event="beforeRun" target="prebuild-steps" runConfigurationType="Application" runConfigurationName="Main" />
</buildFile>
*/
final String configType = e.getAttributeValue("runConfigurationType");
final String configName = e.getAttributeValue("runConfigurationName");
convertToBeforeRunTask(myProject, buildFileUrl, targetName, configType, configName);
} else if (ExecuteCompositeTargetEvent.TYPE_ID.equals(eventId)) {
try {
event = new ExecuteCompositeTargetEvent(targetName);
} catch (WrongNameFormatException e1) {
LOG.info(e1);
event = null;
}
}
if (event != null) {
try {
event.readExternal(e, getProject());
setTargetForEvent(buildFile, targetName, event);
} catch (InvalidDataException readFailed) {
LOG.info(readFailed.getMessage());
}
}
}
}
AntWorkspaceConfiguration.getInstance(getProject()).loadFileProperties();
} catch (InvalidDataException e) {
LOG.error(e);
} finally {
try {
incModificationCount();
updateRegisteredActions();
} finally {
myInitThread = null;
myIsInitialized = Boolean.TRUE;
ApplicationManager.getApplication().invokeLater(() -> myEventDispatcher.getMulticaster().configurationLoaded(), ModalityState.any());
}
}
});
} finally {
indicator.popState();
}
}
});
});
}
use of com.intellij.openapi.vfs.VirtualFileManager in project intellij-community by JetBrains.
the class IdeaJdk method setupSdkPathsFromIDEAProject.
private static void setupSdkPathsFromIDEAProject(Sdk sdk, SdkModificator sdkModificator, SdkModel sdkModel) throws IOException {
ProgressIndicator indicator = ObjectUtils.assertNotNull(ProgressManager.getInstance().getProgressIndicator());
String sdkHome = ObjectUtils.notNull(sdk.getHomePath());
JpsModel model = JpsSerializationManager.getInstance().loadModel(sdkHome, PathManager.getOptionsPath());
JpsSdkReference<JpsDummyElement> sdkRef = model.getProject().getSdkReferencesTable().getSdkReference(JpsJavaSdkType.INSTANCE);
String sdkName = sdkRef == null ? null : sdkRef.getSdkName();
Sdk internalJava = sdkModel.findSdk(sdkName);
if (internalJava != null && isValidInternalJdk(sdk, internalJava)) {
setInternalJdk(sdk, sdkModificator, internalJava);
}
Set<VirtualFile> addedRoots = ContainerUtil.newTroveSet();
VirtualFileManager vfsManager = VirtualFileManager.getInstance();
JpsJavaExtensionService javaService = JpsJavaExtensionService.getInstance();
boolean isUltimate = vfsManager.findFileByUrl(VfsUtilCore.pathToUrl(sdkHome + "/ultimate/ultimate-resources")) != null;
Set<String> suppressedModules = ContainerUtil.newTroveSet("jps-plugin-system");
Set<String> ultimateModules = ContainerUtil.newTroveSet("platform-ultimate", "ultimate-resources", "ultimate-verifier", "diagram-api", "diagram-impl", "uml-plugin");
List<JpsModule> modules = JBIterable.from(model.getProject().getModules()).filter(o -> {
if (suppressedModules.contains(o.getName()))
return false;
if (o.getName().endsWith("-ide"))
return false;
String contentUrl = ContainerUtil.getFirstItem(o.getContentRootsList().getUrls());
if (contentUrl == null)
return true;
return !isUltimate || contentUrl.contains("/community/") || ultimateModules.contains(o.getName());
}).toList();
indicator.setIndeterminate(false);
double delta = 1 / (2 * Math.max(0.5, modules.size()));
for (JpsModule o : modules) {
indicator.setFraction(indicator.getFraction() + delta);
for (JpsDependencyElement dep : o.getDependenciesList().getDependencies()) {
ProgressManager.checkCanceled();
JpsLibrary library = dep instanceof JpsLibraryDependency ? ((JpsLibraryDependency) dep).getLibrary() : null;
JpsLibraryType<?> libraryType = library == null ? null : library.getType();
if (!(libraryType instanceof JpsJavaLibraryType))
continue;
JpsJavaDependencyExtension extension = javaService.getDependencyExtension(dep);
if (extension == null)
continue;
// do not check extension.getScope(), plugin projects need tests too
for (JpsLibraryRoot jps : library.getRoots(JpsOrderRootType.COMPILED)) {
VirtualFile root = vfsManager.findFileByUrl(jps.getUrl());
if (root == null || !addedRoots.add(root))
continue;
sdkModificator.addRoot(root, OrderRootType.CLASSES);
}
for (JpsLibraryRoot jps : library.getRoots(JpsOrderRootType.SOURCES)) {
VirtualFile root = vfsManager.findFileByUrl(jps.getUrl());
if (root == null || !addedRoots.add(root))
continue;
sdkModificator.addRoot(root, OrderRootType.SOURCES);
}
}
}
for (JpsModule o : modules) {
indicator.setFraction(indicator.getFraction() + delta);
String outputUrl = javaService.getOutputUrl(o, false);
VirtualFile outputRoot = outputUrl == null ? null : vfsManager.findFileByUrl(outputUrl);
if (outputRoot == null)
continue;
sdkModificator.addRoot(outputRoot, OrderRootType.CLASSES);
for (JpsModuleSourceRoot jps : o.getSourceRoots()) {
ProgressManager.checkCanceled();
VirtualFile root = vfsManager.findFileByUrl(jps.getUrl());
if (root == null || !addedRoots.add(root))
continue;
sdkModificator.addRoot(root, OrderRootType.SOURCES);
}
}
indicator.setFraction(1.0);
}
use of com.intellij.openapi.vfs.VirtualFileManager in project android by JetBrains.
the class ThemeEditorTable method getPopupMenuAtCell.
private JPopupMenu getPopupMenuAtCell(final int row, final int column) {
if (row < 0 || column < 0) {
return null;
}
TableModel rawModel = getModel();
if (!(rawModel instanceof AttributesTableModel)) {
return null;
}
final AttributesTableModel model = (AttributesTableModel) rawModel;
AttributesTableModel.RowContents contents = model.getRowContents(this.convertRowIndexToModel(row));
if (contents instanceof AttributesTableModel.AttributeContents) {
final AttributesTableModel.AttributeContents attribute = (AttributesTableModel.AttributeContents) contents;
final EditedStyleItem item = attribute.getValue();
if (item == null) {
return null;
}
final JBPopupMenu popupMenu = new JBPopupMenu();
if (attribute.getCellClass(1) == ConfiguredThemeEditorStyle.class) {
popupMenu.add(new AbstractAction(GO_TO_DECLARATION) {
@Override
public void actionPerformed(ActionEvent e) {
myGoToListener.goTo(item);
}
});
} else {
final ResourceResolver resolver = myContext.getResourceResolver();
assert resolver != null;
final Project project = myContext.getProject();
final ResourceValue resourceValue = resolver.resolveResValue(item.getSelectedValue());
final File file = new File(resourceValue.getValue());
final VirtualFileManager manager = VirtualFileManager.getInstance();
final VirtualFile virtualFile = file.exists() ? manager.findFileByUrl("file://" + file.getAbsolutePath()) : null;
if (virtualFile != null) {
popupMenu.add(new AbstractAction(GO_TO_DECLARATION) {
@Override
public void actionPerformed(ActionEvent e) {
final OpenFileDescriptor descriptor = new OpenFileDescriptor(project, virtualFile);
FileEditorManager.getInstance(project).openEditor(descriptor, true);
}
});
}
}
myJavadocAction.setCurrentItem(item);
popupMenu.add(myJavadocAction);
final ConfiguredThemeEditorStyle selectedStyle = model.getSelectedStyle();
if (!selectedStyle.isReadOnly() && selectedStyle.hasItem(item)) {
popupMenu.add(new AbstractAction("Reset value") {
@Override
public void actionPerformed(ActionEvent e) {
selectedStyle.removeAttribute(item.getQualifiedName());
model.fireTableCellUpdated(attribute.getRowIndex(), 0);
}
});
}
return popupMenu;
} else if (contents instanceof AttributesTableModel.ParentAttribute) {
final ConfiguredThemeEditorStyle parentStyle = model.getSelectedStyle().getParent();
if (parentStyle == null) {
return null;
}
final JBPopupMenu menu = new JBPopupMenu();
menu.add(new AbstractAction(GO_TO_DECLARATION) {
@Override
public void actionPerformed(ActionEvent e) {
myGoToListener.goToParent();
}
});
return menu;
}
return null;
}
use of com.intellij.openapi.vfs.VirtualFileManager in project android by JetBrains.
the class ResourceFolderManager method computeFolders.
private List<VirtualFile> computeFolders() {
if (myFacet.requiresAndroidModel()) {
JpsAndroidModuleProperties state = myFacet.getConfiguration().getState();
AndroidModel androidModel = myFacet.getAndroidModel();
List<VirtualFile> resDirectories = new ArrayList<>();
if (androidModel == null) {
// Read string property
if (state != null) {
String path = state.RES_FOLDERS_RELATIVE_PATH;
if (path != null) {
VirtualFileManager manager = VirtualFileManager.getInstance();
// writes the property
for (String url : Splitter.on(';').omitEmptyStrings().trimResults().split(path)) {
VirtualFile dir = manager.findFileByUrl(url);
if (dir != null) {
resDirectories.add(dir);
}
}
} else {
// First time; have not yet computed the res folders
// just try the default: src/main/res/ (from Gradle templates), res/ (from exported Eclipse projects)
String mainRes = '/' + FD_SOURCES + '/' + FD_MAIN + '/' + FD_RES;
VirtualFile dir = AndroidRootUtil.getFileByRelativeModulePath(myFacet.getModule(), mainRes, true);
if (dir != null) {
resDirectories.add(dir);
} else {
String res = '/' + FD_RES;
dir = AndroidRootUtil.getFileByRelativeModulePath(myFacet.getModule(), res, true);
if (dir != null) {
resDirectories.add(dir);
}
}
}
}
} else {
for (IdeaSourceProvider provider : IdeaSourceProvider.getCurrentSourceProviders(myFacet)) {
resDirectories.addAll(provider.getResDirectories());
}
// before the gradle model has been initialized asynchronously
if (state != null) {
StringBuilder path = new StringBuilder(400);
for (VirtualFile dir : resDirectories) {
if (path.length() != 0) {
// Deliberately using ';' instead of File.pathSeparator since on Unix File.pathSeparator is ":"
// which is also used in URLs, meaning we could end up with something like "file://foo:file://bar"
path.append(';');
}
path.append(dir.getUrl());
}
state.RES_FOLDERS_RELATIVE_PATH = path.toString();
}
// Also refresh the app resources whenever the variant changes
if (!myVariantListenerAdded) {
myVariantListenerAdded = true;
BuildVariantView.getInstance(myFacet.getModule().getProject()).addListener(this::invalidate);
}
}
// Listen to root change events. Be notified when project is initialized so we can update the
// resource set, if necessary.
ProjectResourceRepositoryRootListener.ensureSubscribed(myFacet.getModule().getProject());
return resDirectories;
} else {
return new ArrayList<>(myFacet.getMainIdeaSourceProvider().getResDirectories());
}
}
Aggregations