private static String url2path(String url) { String path = VfsUtilCore.urlToPath(url); int separatorIndex = path.indexOf(JarFileSystem.JAR_SEPARATOR); if (separatorIndex < 0) return path; return path.substring(0, separatorIndex); }
public boolean visitRoot(VirtualFile root, Module module, Sdk sdk, boolean isModuleSource) { String vpath = VfsUtilCore.urlToPath(root.getUrl()); if (myPath.startsWith(vpath)) { myResult = vpath; return false; } else { return true; } }
@Nullable private VirtualFile createFileFromTemplate( @Nullable final Project project, String url, final String templateName, final boolean forceNew) { final LocalFileSystem fileSystem = LocalFileSystem.getInstance(); final File file = new File(VfsUtilCore.urlToPath(url)); VirtualFile existingFile = fileSystem.refreshAndFindFileByIoFile(file); if (existingFile != null) { existingFile.refresh(false, false); if (!existingFile.isValid()) { existingFile = null; } } if (existingFile != null && !forceNew) { return existingFile; } try { String text = getText(templateName, project); final VirtualFile childData; if (existingFile == null || existingFile.isDirectory()) { final VirtualFile virtualFile; if (!FileUtil.createParentDirs(file) || (virtualFile = fileSystem.refreshAndFindFileByIoFile(file.getParentFile())) == null) { throw new IOException( IdeBundle.message("error.message.unable.to.create.file", file.getPath())); } childData = virtualFile.createChildData(this, file.getName()); } else { childData = existingFile; } VfsUtil.saveText(childData, text); return childData; } catch (final IOException e) { LOG.info(e); ApplicationManager.getApplication() .invokeLater( new Runnable() { @Override public void run() { Messages.showErrorDialog( IdeBundle.message( "message.text.error.creating.deployment.descriptor", e.getLocalizedMessage()), IdeBundle.message("message.text.creating.deployment.descriptor")); } }); } return null; }
@Override public void after(@NotNull final List<? extends VFileEvent> events) { incModificationCount(); for (FilePointerPartNode node : myPointersToUpdateUrl) { synchronized (this) { VirtualFilePointerImpl pointer = node.leaf; String urlBefore = pointer.getUrlNoUpdate(); Pair<VirtualFile, String> after = node.update(); String urlAfter = after.second; if (URL_COMPARATOR.compare(urlBefore, urlAfter) != 0) { // url has changed, reinsert FilePointerPartNode root = myPointers.get(pointer.getListener()); int useCount = node.useCount; node.remove(); FilePointerPartNode newNode = root.findPointerOrCreate(VfsUtilCore.urlToPath(urlAfter), 0, after); VirtualFilePointerImpl existingPointer = newNode.leaf; if (existingPointer != null) { // can happen when e.g. file renamed to the existing file // merge two pointers pointer.myNode = newNode; } else { newNode.associate(pointer, after); } newNode.incrementUsageCount(useCount); } } } VirtualFilePointer[] pointersToFireArray = toPointers(myPointersToFire); for (VirtualFilePointer pointer : pointersToFireArray) { ((VirtualFilePointerImpl) pointer).myNode.update(); } for (EventDescriptor event : myEvents) { event.fireAfter(); } if (pointersToFireArray.length != 0) { myBus.syncPublisher(VirtualFilePointerListener.TOPIC).validityChanged(pointersToFireArray); } myPointersToUpdateUrl = Collections.emptyList(); myEvents = Collections.emptyList(); myPointersToFire = Collections.emptyList(); for (FilePointerPartNode root : myPointers.values()) { root.checkConsistency(); } }
@NotNull private Map<String, GradleModuleResourceConfiguration> generateAffectedGradleModulesConfiguration( @NotNull CompileContext context) { final Map<String, GradleModuleResourceConfiguration> affectedGradleModuleConfigurations = ContainerUtil.newTroveMap(); //noinspection MismatchedQueryAndUpdateOfCollection final Map<String, ExternalProject> lazyExternalProjectMap = new FactoryMap<String, ExternalProject>() { @Nullable @Override protected ExternalProject create(String gradleProjectPath) { return myExternalProjectDataService.getRootExternalProject( GradleConstants.SYSTEM_ID, new File(gradleProjectPath)); } }; for (Module module : context.getCompileScope().getAffectedModules()) { if (!ExternalSystemApiUtil.isExternalSystemAwareModule(GradleConstants.SYSTEM_ID, module)) continue; if (shouldBeBuiltByExternalSystem(module)) continue; final String gradleProjectPath = module.getOptionValue(ExternalSystemConstants.ROOT_PROJECT_PATH_KEY); assert gradleProjectPath != null; final ExternalProject externalRootProject = lazyExternalProjectMap.get(gradleProjectPath); if (externalRootProject == null) { context.addMessage( CompilerMessageCategory.ERROR, String.format( "Unable to make the module: %s, related gradle configuration was not found. " + "Please, re-import the Gradle project and try again.", module.getName()), VfsUtilCore.pathToUrl(gradleProjectPath), -1, -1); continue; } ExternalProject externalProject = myExternalProjectDataService.findExternalProject(externalRootProject, module); if (externalProject == null) { LOG.warn("Unable to find config for module: " + module.getName()); continue; } GradleModuleResourceConfiguration resourceConfig = new GradleModuleResourceConfiguration(); resourceConfig.id = new ModuleVersion( externalProject.getGroup(), externalProject.getName(), externalProject.getVersion()); resourceConfig.directory = FileUtil.toSystemIndependentName(externalProject.getProjectDir().getPath()); final ExternalSourceSet mainSourcesSet = externalProject.getSourceSets().get("main"); addResources(resourceConfig.resources, mainSourcesSet, ExternalSystemSourceType.RESOURCE); final ExternalSourceSet testSourcesSet = externalProject.getSourceSets().get("test"); addResources( resourceConfig.testResources, testSourcesSet, ExternalSystemSourceType.TEST_RESOURCE); final CompilerModuleExtension compilerModuleExtension = CompilerModuleExtension.getInstance(module); if (compilerModuleExtension != null && compilerModuleExtension.isCompilerOutputPathInherited()) { String outputPath = VfsUtilCore.urlToPath(compilerModuleExtension.getCompilerOutputUrl()); for (ResourceRootConfiguration resource : resourceConfig.resources) { resource.targetPath = outputPath; } String testOutputPath = VfsUtilCore.urlToPath(compilerModuleExtension.getCompilerOutputUrlForTests()); for (ResourceRootConfiguration resource : resourceConfig.testResources) { resource.targetPath = testOutputPath; } } affectedGradleModuleConfigurations.put(module.getName(), resourceConfig); } return affectedGradleModuleConfigurations; }
/** @param contentEntryEditor : null means to clear the editor */ public void setContentEntryEditor(final ContentEntryEditor contentEntryEditor) { if (myContentEntryEditor != null && myContentEntryEditor.equals(contentEntryEditor)) { return; } if (myFileSystemTree != null) { Disposer.dispose(myFileSystemTree); myFileSystemTree = null; } if (myContentEntryEditor != null) { myContentEntryEditor.removeContentEntryEditorListener(myContentEntryEditorListener); myContentEntryEditor = null; } if (contentEntryEditor == null) { ((DefaultTreeModel) myTree.getModel()).setRoot(EMPTY_TREE_ROOT); myTreePanel.setVisible(false); if (myFileSystemTree != null) { Disposer.dispose(myFileSystemTree); } return; } myTreePanel.setVisible(true); myContentEntryEditor = contentEntryEditor; myContentEntryEditor.addContentEntryEditorListener(myContentEntryEditorListener); final ContentEntry entry = contentEntryEditor.getContentEntry(); assert entry != null : contentEntryEditor; final VirtualFile file = entry.getFile(); myDescriptor.setRoots(file); if (file == null) { final String path = VfsUtilCore.urlToPath(entry.getUrl()); myDescriptor.setTitle(FileUtil.toSystemDependentName(path)); } final Runnable init = new Runnable() { @Override public void run() { //noinspection ConstantConditions myFileSystemTree.updateTree(); myFileSystemTree.select(file, null); } }; myFileSystemTree = new FileSystemTreeImpl( myProject, myDescriptor, myTree, getContentEntryCellRenderer(), init, null) { @Override protected AbstractTreeBuilder createTreeBuilder( JTree tree, DefaultTreeModel treeModel, AbstractTreeStructure treeStructure, Comparator<NodeDescriptor> comparator, FileChooserDescriptor descriptor, final Runnable onInitialized) { return new MyFileTreeBuilder( tree, treeModel, treeStructure, comparator, descriptor, onInitialized); } }; myFileSystemTree.showHiddens(true); Disposer.register(myProject, myFileSystemTree); final NewFolderAction newFolderAction = new MyNewFolderAction(); final DefaultActionGroup mousePopupGroup = new DefaultActionGroup(); mousePopupGroup.add(myEditingActionsGroup); mousePopupGroup.addSeparator(); mousePopupGroup.add(newFolderAction); myFileSystemTree.registerMouseListener(mousePopupGroup); }