Java Code Examples for com.intellij.openapi.vfs.VirtualFileSystem#findFileByPath()

The following examples show how to use com.intellij.openapi.vfs.VirtualFileSystem#findFileByPath() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OclProjectJdkWizardStep.java    From reasonml-idea-plugin with MIT License 6 votes vote down vote up
@Override
public boolean validate() throws ConfigurationException {
    VirtualFileSystem fileSystem = LocalFileSystem.getInstance();

    VirtualFile sdkHome = fileSystem.findFileByPath(c_sdkHome.getText().trim());
    if (sdkHome == null) {
        throw new ConfigurationException("Can't find sdk home directory, make sure it exists");
    }
    if (!sdkHome.isDirectory()) {
        throw new ConfigurationException("Sdk home is not a directory");
    }
    if (!sdkHome.isWritable()) {
        throw new ConfigurationException("sdk home is not writable");
    }

    return super.validate();
}
 
Example 2
Source File: ResourcesPlugin.java    From aem-ide-tooling-4-intellij with Apache License 2.0 6 votes vote down vote up
public IResource findMember(IPath childPath) {
    // I guess we need to figure out if that file is part of the project and if so return an IResource
    DataContext dataContext = DataManager.getInstance().getDataContextFromFocus().getResult();
    VirtualFile file = null;
    if(dataContext != null) {
        Project project = CommonDataKeys.PROJECT.getData(dataContext);
        String aPath = childPath.toOSString();
        VirtualFileSystem vfs = project.getProjectFile().getFileSystem();
        file = vfs.findFileByPath(aPath);
    } else {
        String message = "could not obtain data context";
    }
    //AS TODO: If this is only used as a marker then we are fine but otherwise we need to obtain the current module
    return file == null ? null :
        (file.isDirectory() ? new IFolder() : new IFile());
}
 
Example 3
Source File: IProject.java    From aem-ide-tooling-4-intellij with Apache License 2.0 6 votes vote down vote up
public IFolder getFolder(IPath path) {
    com.headwire.aem.tooling.intellij.communication.MessageManager messageManager = ComponentProvider.getComponent(project,
        com.headwire.aem.tooling.intellij.communication.MessageManager.class
    );
    messageManager.sendDebugNotification("debug.folder.path", path);

    String filePath = path.toOSString();

    messageManager.sendDebugNotification("debug.folder.os.path", filePath);

    VirtualFileSystem vfs = module.getProject().getBaseDir().getFileSystem();
    VirtualFile file = vfs.findFileByPath(path.toOSString());
    if(file != null) {
        return new IFolder(module, file);
    } else {
        return new IFolder(module, new File(path.toOSString()));
    }
}
 
Example 4
Source File: HaxeClasspathEntry.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
public HaxeClasspathEntry(@Nullable String name, @NotNull String url) {
  myName = name;
  myUrl = url;

  // Try to fix the URL if it wasn't correct.
  if (!url.contains(URLUtil.SCHEME_SEPARATOR)) {
    if (LOG.isDebugEnabled()) {
      LOG.debug("Fixing malformed URL passed by " + HaxeDebugUtil.printCallers(5));
    }
    VirtualFileSystem vfs = VirtualFileManager.getInstance().getFileSystem(LocalFileSystem.PROTOCOL);
    VirtualFile file = vfs.findFileByPath(url);
    if (null != file) {
      myUrl = file.getUrl();
    }
  }

  if (null != myName) {
    if (HaxelibNameUtil.isManagedLibrary(myName)) {
      myName = HaxelibNameUtil.parseHaxelib(myName);
      myIsManagedEntry = true;
    }
  }
}
 
Example 5
Source File: SlingProject4IntelliJ.java    From aem-ide-tooling-4-intellij with Apache License 2.0 5 votes vote down vote up
public SlingProject4IntelliJ(ServerConfiguration.Module module) {
    logger.debug("Getting Started, Module: " + module);
    this.module = module;
    Project project = module.getProject();
    VirtualFileSystem vfs = project.getBaseDir().getFileSystem();
    for(String path: module.getUnifiedModule().getContentDirectoryPaths()) {
        if(Util.pathEndsWithFolder(path, JCR_ROOT_FOLDER_NAME)) {
            File folder = new File(path);
            if(folder.exists() && folder.isDirectory()) {
                syncDirectory = new SlingResource4IntelliJ(this, vfs.findFileByPath(path));
                break;
            }
        }
    }
}
 
Example 6
Source File: HaxeCompilerError.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
public String getUrl() {

    VirtualFileSystem vfs = VirtualFileManager.getInstance().getFileSystem(LocalFileSystem.PROTOCOL);
    VirtualFile file = vfs.findFileByPath(getPath());

    StringBuilder msg = new StringBuilder(file.getUrl());
    msg.append('#');
    msg.append(getLine());
    msg.append(':');
    msg.append(getColumn());
    return msg.toString();
  }
 
Example 7
Source File: OclProjectJdkWizardStep.java    From reasonml-idea-plugin with MIT License 4 votes vote down vote up
@Override
public void onWizardFinished() throws CommitStepException {
    Sdk odk = null;

    if (c_rdSelectExisting.isSelected()) {
        JdkComboBox.JdkComboBoxItem selectedItem = c_selExistingSdk.getSelectedItem();
        odk = selectedItem == null ? null : selectedItem.getJdk();
    } else if (c_rdDownloadSdk.isSelected()) {
        String selectedSdk = (String) c_selDownload.getSelectedItem();
        String sdkHomeValue = PropertiesComponent.getInstance().getValue(SDK_HOME);
        if (sdkHomeValue != null) {
            VirtualFileSystem fileSystem = LocalFileSystem.getInstance();
            VirtualFile sdkHome = fileSystem.findFileByPath(sdkHomeValue);

            if (selectedSdk != null && sdkHome != null) {
                int pos = selectedSdk.lastIndexOf('.');
                String patch = selectedSdk.substring(pos + 1);
                String majorMinor = selectedSdk.substring(0, pos);
                pos = majorMinor.lastIndexOf('.');
                String major = majorMinor.substring(0, pos);
                String minor = majorMinor.substring(pos + 1);

                // Download SDK from distribution site
                LOG.debug("Download SDK", selectedSdk);
                ProgressManager.getInstance().run(SdkDownloader.modalTask(major, minor, patch, sdkHome, m_context.getProject()));

                // Create SDK
                LOG.debug("Create SDK", selectedSdk);
                File targetSdkLocation = new File(sdkHome.getCanonicalPath(), "ocaml-" + selectedSdk);
                odk = SdkConfigurationUtil.createAndAddSDK(targetSdkLocation.getAbsolutePath(), new OCamlSdkType());
                if (odk != null) {
                    SdkModificator odkModificator = odk.getSdkModificator();

                    odkModificator.setVersionString(selectedSdk);  // must be set after home path, otherwise setting home path clears the version string
                    odkModificator.setName("OCaml (sources only) " + major);
                    try {
                        addSdkSources(odkModificator, targetSdkLocation);
                    } catch (IOException e) {
                        throw new CommitStepException(e.getMessage());
                    }

                    odkModificator.commitChanges();
                }
            }
        }
    }

    // update selected sdk in builder
    ProjectBuilder builder = m_context.getProjectBuilder();
    if (odk != null && builder instanceof DuneProjectImportBuilder) {
        ((DuneProjectImportBuilder) builder).setModuleSdk(odk);
    }
}