private long getContainerTimestamp(TypeNameMatch match) {
   try {
     IType type = match.getType();
     IResource resource = type.getResource();
     if (resource != null) {
       URI location = resource.getLocationURI();
       if (location != null) {
         IFileInfo info = EFS.getStore(location).fetchInfo();
         if (info.exists()) {
           // The element could be removed from the build path. So check
           // if the Java element still exists.
           IJavaElement element = JavaCore.create(resource);
           if (element != null && element.exists()) return info.getLastModified();
         }
       }
     } else { // external JAR
       IPackageFragmentRoot root = match.getPackageFragmentRoot();
       if (root.exists()) {
         IFileInfo info = EFS.getLocalFileSystem().getStore(root.getPath()).fetchInfo();
         if (info.exists()) {
           return info.getLastModified();
         }
       }
     }
   } catch (CoreException e) {
     // Fall through
   }
   return IResource.NULL_STAMP;
 }
  /**
   * Performs a git clone to a temporary location and then copies the files over top the already
   * generated project. This is because git cannot clone into an existing directory.
   *
   * @param monitor
   * @throws Exception
   */
  protected void cloneAfter(IProgressMonitor monitor) throws Exception {
    SubMonitor sub =
        SubMonitor.convert(monitor, Messages.AbstractNewProjectWizard_CloningFromGitMsg, 100);
    // clone to tmp dir then copy files over top the project!
    File tmpFile = File.createTempFile("delete_me", "tmp"); // $NON-NLS-1$ //$NON-NLS-2$
    File dest = new File(tmpFile.getParent(), "git_clone_tmp"); // $NON-NLS-1$
    GitExecutable.instance()
        .clone(
            selectedTemplate.getLocation(),
            Path.fromOSString(dest.getAbsolutePath()),
            true,
            sub.newChild(85));

    IFileStore tmpClone = EFS.getStore(dest.toURI());
    // Wipe the .git folder before copying? Wipe the .project file before copying?
    IFileStore dotGit = tmpClone.getChild(".git"); // $NON-NLS-1$
    dotGit.delete(EFS.NONE, sub.newChild(2));

    IFileStore dotProject = tmpClone.getChild(IProjectDescription.DESCRIPTION_FILE_NAME);
    if (dotProject.fetchInfo().exists()) {
      dotProject.delete(EFS.NONE, sub.newChild(1));
    }
    // OK, copy the cloned template's contents over
    IFileStore projectStore = EFS.getStore(newProject.getLocationURI());
    tmpClone.copy(projectStore, EFS.OVERWRITE, sub.newChild(9));
    // Now get rid of the temp clone!
    tmpClone.delete(EFS.NONE, sub.newChild(3));
    sub.done();
  }
  /*
   * (non-Javadoc)
   * @see com.aptana.index.core.IIndexFileContributor#contributeFiles(java.net.URI)
   */
  public Set<IFileStore> getFiles(URI containerURI) {
    IContainer[] containers =
        ResourcesPlugin.getWorkspace().getRoot().findContainersForLocationURI(containerURI);
    Set<IFileStore> result = new HashSet<IFileStore>();

    if (containers != null && containers.length > 0) {
      for (IContainer container : containers) {
        if (container instanceof IProject) {
          IProject project = (IProject) container;
          Set<BuildPathEntry> entries = BuildPathManager.getInstance().getBuildPaths(project);

          if (entries != null) {
            for (BuildPathEntry entry : entries) {
              try {
                IFileStore fileStore = EFS.getStore(entry.getPath());

                result.add(fileStore);
              } catch (CoreException e) {
                IdeLog.logError(BuildPathCorePlugin.getDefault(), e.getMessage(), e);
              }
            }
          }
        }
      }
    }

    return result;
  }
  @Override
  protected StandardDiagramLayout initLayoutModel() {
    StandardDiagramLayout layoutModel = null;
    try {
      String fileName = computeLayoutFileName(this.editorInput);
      if (fileName != null) {
        final XmlResourceStore resourceStore;

        if (this.editorInput instanceof IFileEditorInput) {
          IFileEditorInput fileInput = (IFileEditorInput) this.editorInput;
          IFolder layoutFolder = (IFolder) fileInput.getFile().getParent();
          IFile layoutFile = layoutFolder.getFile(fileName);
          resourceStore = new XmlResourceStore(new WorkspaceFileResourceStore(layoutFile));
        } else if (this.editorInput instanceof FileStoreEditorInput) {
          FileStoreEditorInput fileStoreInput = (FileStoreEditorInput) this.editorInput;
          IFileStore store = EFS.getStore(fileStoreInput.getURI());
          File localFile = store.toLocalFile(EFS.NONE, null);
          // if no local file is available, obtain a cached file
          if (localFile == null) localFile = store.toLocalFile(EFS.CACHE, null);
          if (localFile == null) throw new IllegalArgumentException();
          File layoutFile = new File(localFile.getParentFile(), fileName);
          resourceStore = new XmlResourceStore(new FileResourceStore(layoutFile));
        } else {
          throw new IllegalStateException();
        }

        layoutModel = StandardDiagramLayout.TYPE.instantiate(new RootXmlResource(resourceStore));
      }
    } catch (Exception e) {
      Sapphire.service(LoggingService.class).log(e);
    }

    return layoutModel;
  }
示例#5
0
 private static IFileStore getFileStore(String filename) {
   try {
     return EFS.getStore((new Path(filename).toFile().toURI()));
   } catch (CoreException e) {
   }
   return null;
 }
  public void testIndexWithEmptyContent() throws Exception {
    File tmpDir = null;
    try {
      String src = "\n";

      // Generate some files to index!
      tmpDir =
          new File(
              FileUtil.getTempDirectory().toOSString(),
              "testIndexWithEmptyContent" + System.currentTimeMillis());
      tmpDir.mkdirs();

      File coffeeFile = new File(tmpDir, "index_me.coffee");
      IOUtil.write(new FileOutputStream(coffeeFile), src);

      IFileStore fileStore = EFS.getStore(coffeeFile.toURI());
      BuildContext context = new FileStoreBuildContext(fileStore);

      IProgressMonitor monitor = new NullProgressMonitor();
      indexer.index(context, null, monitor);
    } finally {
      // Clean up the generated files!
      FileUtil.deleteRecursively(tmpDir);
    }
  }
  /**
   * Returns true for: - non-hidden projects - non-RDT projects - projects that does not have remote
   * systems temporary nature - projects that are located remotely
   */
  public boolean isCandidate(IProject project) {
    boolean a = false;
    boolean b = false;
    boolean c = false;
    boolean d = false;
    a = !project.isHidden();
    try {
      // b = !project.hasNature(RemoteNature.REMOTE_NATURE_ID);
      try {
        ServiceModelManager.getInstance().getConfigurations(project);
      } catch (ProjectNotConfiguredException e) {
        b = true;
      }
      c = !project.hasNature("org.eclipse.rse.ui.remoteSystemsTempNature"); // $NON-NLS-1$

      IHost host = RSEUtils.getConnection(project.getLocationURI());
      if (host != null) {
        d = !host.getSystemType().isLocal();
      } else {
        IFileStore fileStore = EFS.getStore(project.getLocationURI());
        if (fileStore != null) {
          if (!(fileStore instanceof LocalFile)) {
            d = true;
          }
        }
      }

    } catch (CoreException e) {
      RDTLog.logError(e);
    }

    return a && b && c && d;
  }
  private static IFileEditorInput getFileStorage(int index) throws CoreException {
    String filename = getBatchDateString();
    filename += (index > 0 ? "_" + index : "") + ".tcl";
    IFolder templateFolder =
        SicsVisualBatchViewer.getProjectFolder(
            SicsVisualBatchViewer.EXPERIMENT_PROJECT, FOLDER_TEMPLATE);
    IFile templateFile = templateFolder.getFile(FILE_TEMPLATE);
    IFolder folder =
        SicsVisualBatchViewer.getProjectFolder(
            SicsVisualBatchViewer.EXPERIMENT_PROJECT, SicsVisualBatchViewer.AUTOSAVE_FOLDER);
    IFileEditorInput input = new FileEditorInput(folder.getFile(filename));
    if (input.exists()) {
      return getFileStorage(index++);
    } else {
      try {
        byte[] read = null;
        if (templateFile.exists()) {
          long size = EFS.getStore(templateFile.getLocationURI()).fetchInfo().getLength();
          //					long size = templateFolder.getLocation().toFile().length();
          read = new byte[(int) size];
          InputStream inputStream = templateFile.getContents();
          inputStream.read(read);
        } else {
          read = new byte[0];
          templateFile.create(new ByteArrayInputStream(read), IResource.ALLOW_MISSING_LOCAL, null);
        }
        input.getFile().create(new ByteArrayInputStream(read), IResource.ALLOW_MISSING_LOCAL, null);
      } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }

    return input;
  }
  public static boolean isExecutable(IPath path) {
    if (path == null) {
      return false;
    }
    File file = path.toFile();
    if (file == null || !file.exists() || file.isDirectory()) {
      return false;
    }

    // OK, file exists
    try {
      Method m = File.class.getMethod("canExecute"); // $NON-NLS-1$
      if (m != null) {
        return (Boolean) m.invoke(file);
      }
    } catch (Exception e) {
    }

    // File.canExecute() doesn't exist; do our best to determine if file is executable...
    if (Platform.OS_WIN32.equals(Platform.getOS())) {
      return true;
    }
    IFileStore fileStore = EFS.getLocalFileSystem().getStore(path);
    return fileStore.fetchInfo().getAttribute(EFS.ATTRIBUTE_EXECUTABLE);
  }
 @Override
 protected String computeLayoutFileName(IEditorInput editorInput)
     throws CoreException, IOException {
   String fileName = null;
   if (editorInput instanceof FileEditorInput) {
     FileEditorInput fileEditorInput = (FileEditorInput) editorInput;
     IFile ifile = fileEditorInput.getFile();
     fileName = ifile.getName();
   } else if (editorInput instanceof FileStoreEditorInput) {
     FileStoreEditorInput fileStoreInput = (FileStoreEditorInput) editorInput;
     IFileStore store = EFS.getStore(fileStoreInput.getURI());
     File localFile = store.toLocalFile(EFS.NONE, null);
     // if no local file is available, obtain a cached file
     if (localFile == null) localFile = store.toLocalFile(EFS.CACHE, null);
     if (localFile == null) throw new IllegalArgumentException();
     fileName = localFile.getName();
   }
   if (fileName != null && fileName.endsWith(".xml")) {
     fileName = fileName.substring(0, fileName.indexOf(".xml"));
   }
   if (fileName != null) {
     fileName += ".layout";
   }
   return fileName;
 }
示例#11
0
 private void openFile(File file, DotGraphView view) {
   if (view.currentFile == null) { // no workspace file for cur. graph
     IFileStore fileStore = EFS.getLocalFileSystem().getStore(new Path("")); // $NON-NLS-1$
     fileStore = fileStore.getChild(file.getAbsolutePath());
     if (!fileStore.fetchInfo().isDirectory() && fileStore.fetchInfo().exists()) {
       IWorkbenchPage page = view.getSite().getPage();
       try {
         IDE.openEditorOnFileStore(page, fileStore);
       } catch (PartInitException e) {
         e.printStackTrace();
       }
     }
   } else {
     IWorkspace workspace = ResourcesPlugin.getWorkspace();
     IPath location = Path.fromOSString(file.getAbsolutePath());
     IFile copy = workspace.getRoot().getFileForLocation(location);
     IEditorRegistry registry = PlatformUI.getWorkbench().getEditorRegistry();
     if (registry.isSystemExternalEditorAvailable(copy.getName())) {
       try {
         view.getViewSite()
             .getPage()
             .openEditor(new FileEditorInput(copy), IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
       } catch (PartInitException e) {
         e.printStackTrace();
       }
     }
   }
 }
示例#12
0
 public IFileStore getStore(URI uri) {
   try {
     //			System.out.println("looking for store:" + uri);
     if (tstypeURICache.containsKey(uri)) {
       return (TypeSpaceFileStore) tstypeURICache.get(uri);
     } else {
       //				System.out.println("creating store:" + uri);
       if (canInitialize(uri.getHost())) {
         TypeSpaceFileStore store = new TypeSpaceFileStore("root", null, uri);
         tstypeURICache.put(uri, store);
         return store;
       }
     }
   } catch (Exception e) {
     Activator.getDefault()
         .getLog()
         .log(
             (IStatus)
                 new Status(
                     Status.ERROR,
                     Activator.PLUGIN_ID,
                     "could not create store for " + uri.toString(),
                     e));
   }
   return EFS.getNullFileSystem().getStore(uri);
 }
示例#13
0
 private static IEditorInput getEditorInput(final IErlElement element0) {
   IErlElement element = element0;
   final IResource resource = element.getResource();
   if (resource instanceof IFile) {
     IFile file = (IFile) resource;
     file = resolveFile(file);
     return new FileEditorInput(file);
   }
   String filePath = element.getFilePath();
   while (filePath == null) {
     final IParent parent = element.getParent();
     if (parent instanceof IErlElement) {
       element = (IErlElement) parent;
       filePath = element.getFilePath();
     } else {
       break;
     }
   }
   if (filePath != null) {
     final IPath path = new Path(filePath);
     IFileStore fileStore = EFS.getLocalFileSystem().getStore(path.removeLastSegments(1));
     fileStore = fileStore.getChild(path.lastSegment());
     final IFileInfo fetchInfo = fileStore.fetchInfo();
     if (!fetchInfo.isDirectory() && fetchInfo.exists()) {
       if (element instanceof IErlModule && element.getParent() instanceof IErlExternal) {
         return new ErlangExternalEditorInput(fileStore, (IErlModule) element);
       }
       return new FileStoreEditorInput(fileStore);
     }
   }
   return null;
 }
示例#14
0
  /** Allow user to specify a TAU bin directory. */
  protected void handleBinBrowseButtonSelected(Text field, String group) {
    final DirectoryDialog dialog = new DirectoryDialog(getShell());
    IFileStore path = null;
    final String correctPath = getFieldContent(field.getText());
    if (correctPath != null) {
      path = EFS.getLocalFileSystem().getStore(new Path(correctPath)); // new File(correctPath);
      if (path.fetchInfo().exists()) {
        dialog.setFilterPath(
            !path.fetchInfo().isDirectory() ? correctPath : path.getParent().toURI().getPath());
      }
    }
    // The specified directory previously had to contain at least one
    // recognizable TAU makefile in its lib sub-directory to be accepted.
    // String tlpath = correctPath+File.separator+"lib";
    //
    // class makefilter implements FilenameFilter{
    // public boolean accept(File dir, String name) {
    // if(name.indexOf("Makefile.tau")!=0 || name.indexOf("-pdt")<=0)
    // return false;
    // return true;
    // }
    // }
    // File[] mfiles=null;
    // makefilter mfilter = new makefilter();
    // File test = new File(tlpath);

    dialog.setText(
        Messages.ToolLocationPreferencePage_Select
            + group
            + Messages.ToolLocationPreferencePage_BinDirectory);
    // dialog.setMessage("You must select a valid TAU bin directory.  Such a directory should be
    // created when you configure and install TAU.  It should contain least one valid stub makefile
    // configured with the Program Database Toolkit (pdt)");

    final String selectedPath = dialog.open(); // null;
    if (selectedPath != null) {
      field.setText(selectedPath);
      // while(true)
      // {
      // selectedPath = dialog.open();
      // if(selectedPath==null)
      // break;
      //
      // tlpath=selectedPath+File.separator+"lib";
      // test = new File(tlpath);
      // if(test.exists()){
      // mfiles = test.listFiles(mfilter);
      // }
      // if (mfiles!=null&&mfiles.length>0)
      // {
      // if (selectedPath != null)
      // tauBin.setText(selectedPath);
      // break;
      // }
      // }
    }
  }
 protected void createSystemFileContexts(InputContextManager manager, FileStoreEditorInput input) {
   try {
     IFileStore store = EFS.getStore(input.getURI());
     IEditorInput in = new FileStoreEditorInput(store);
     manager.putContext(in, new CategoryInputContext(this, in, true));
   } catch (CoreException e) {
     PDEPlugin.logException(e);
   }
 }
示例#16
0
文件: MME.java 项目: gedaofeng/xmind3
  /**
   * Creates an editor input using the given file. Note that if there's Eclipse IDE running, the
   * result will be an {@link org.eclipse.ui.ide.FileStoreEditorInput}; otherwise an instance of
   * {@link FileEditorInput} will be returned.
   *
   * @param file The file
   * @return A new editor input representing the given file.
   * @throws CoreException if the creation failed
   */
  public static IEditorInput createFileEditorInput(File file) throws CoreException {
    if (file == null) throw new IllegalArgumentException("File is null"); // $NON-NLS-1$

    Bundle ide = getIDE();
    if (ide != null) {
      IFileStore fileStore = EFS.getStore(file.toURI());
      return createFileEditorInput(ide, fileStore);
    }
    return new FileEditorInput(file);
  }
  // temp code for grabbing files from filesystem
  protected IFileStore tempGetFileStore(IPath path) {
    // first check if we have an alias registered
    if (path.segmentCount() > 0) {
      URI alias = aliasRegistry.lookupAlias(path.segment(0));
      if (alias != null)
        try {
          return EFS.getStore(alias).getFileStore(path.removeFirstSegments(1));
        } catch (CoreException e) {
          LogHelper.log(
              new Status(
                  IStatus.WARNING,
                  HostingActivator.PI_SERVER_HOSTING,
                  1,
                  "An error occured when getting file store for path '"
                      + path
                      + "' and alias '"
                      + alias
                      + '\'',
                  e)); //$NON-NLS-1$ //$NON-NLS-2$
          // fallback is to try the same path relatively to the root
        }
    }
    // assume it is relative to the root
    try {
      return EFS.getStore(rootStoreURI).getFileStore(path);
    } catch (CoreException e) {
      LogHelper.log(
          new Status(
              IStatus.WARNING,
              HostingActivator.PI_SERVER_HOSTING,
              1,
              "An error occured when getting file store for path '"
                  + path
                  + "' and root '"
                  + rootStoreURI
                  + '\'',
              e)); //$NON-NLS-1$ //$NON-NLS-2$
      // fallback and return null
    }

    return null;
  }
 protected void doFSSetUp() throws Exception {
   repositoryPath = getRandomLocation();
   URI uri = URIUtil.toURI(repositoryPath); // encoded
   StringBuffer sb = new StringBuffer();
   sb.append(GitFileSystem.SCHEME_GIT);
   sb.append("://test/");
   sb.append(uri.toString());
   sb.append("?/");
   baseStore = EFS.getStore(URI.create(sb.toString()));
   baseStore.mkdir(EFS.NONE, null);
 }
  /* (non-Javadoc)
   * @see org.eclipse.ui.texteditor.AbstractDocumentProvider#doSaveDocument(org.eclipse.core.runtime.IProgressMonitor, java.lang.Object, org.eclipse.jface.text.IDocument, boolean)
   * tau 21.03.2005
   */
  protected void doSaveDocument(
      IProgressMonitor monitor, Object element, IDocument document, boolean overwrite)
      throws CoreException {

    if (element instanceof IFileEditorInput) {
      doSaveFileResource(monitor, element, document, overwrite);
    } else if (element instanceof IAdaptable) {
      // reuses code from TextFileDocumentProvider to handle external files (195615)
      // TODO consider converting the super class to TextFileDocumentProvider
      IAdaptable adaptable = (IAdaptable) element;

      ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
      ITextFileBuffer fileBuffer = null;
      LocationKind locationKind = null;

      ILocationProvider provider =
          (ILocationProvider) adaptable.getAdapter(ILocationProvider.class);
      if (provider instanceof ILocationProviderExtension) {
        URI uri = ((ILocationProviderExtension) provider).getURI(element);
        if (ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(uri).length == 0) {
          IFileStore fileStore = EFS.getStore(uri);
          manager.connectFileStore(fileStore, getProgressMonitor());
          fileBuffer = manager.getFileStoreTextFileBuffer(fileStore);
        }
      }
      if (fileBuffer == null && provider != null) {
        IPath location = provider.getPath(element);
        if (location != null) {
          locationKind = LocationKind.NORMALIZE;
          manager.connect(location, locationKind, getProgressMonitor());
          fileBuffer = manager.getTextFileBuffer(location, locationKind);
        }
      }

      if (fileBuffer != null) {
        fileBuffer.getDocument().set(document.get());
        fileBuffer.commit(null, true);
      }
    }

    // tau 21.03.05
    // First attempt show Message Connection through SQLScrapbookEditorInput
    if (element instanceof SQLScrapbookEditorInput)
      ((SQLScrapbookEditorInput) element).showMessageConnection();
    // Second attempt show Message Connection through sqlEditor
    IEditorPart editor =
        PlatformUI.getWorkbench()
            .getActiveWorkbenchWindow()
            .getActivePage()
            .findEditor((IEditorInput) element);
    if ((editor != null) && (editor instanceof SQLEditor)) {
      ((SQLEditor) editor).refreshConnectionStatus();
    }
  }
 private static IEditorInput getEditorInput(Source source) {
   {
     IResource resource = DartCore.getProjectManager().getResource(source);
     // TODO(scheglov) clean up when ProjectManager will return IFile
     if (resource instanceof IFile) {
       return new FileEditorInput((IFile) resource);
     }
   }
   URI uri = new File(source.getFullName()).toURI();
   IFileStore fileStore = EFS.getLocalFileSystem().getStore(uri);
   return new FileStoreEditorInput(fileStore);
 }
  private static File toLocalFile(URI locationURI) {
    if (locationURI == null) return null;

    try {
      IFileStore store = EFS.getStore(locationURI);
      return store.toLocalFile(0, null);
    } catch (CoreException ex) {
      SpringCore.log("Error while converting URI to local file: " + locationURI.toString(), ex);
    }

    return null;
  }
  protected void createAndOpenFile(String filename, String extension, String content)
      throws IOException, PartInitException {
    file = File.createTempFile(filename, extension);
    FileWriter writer = new FileWriter(file);
    writer.write(content);
    writer.close();

    editor =
        (ITextEditor)
            IDE.openEditorOnFileStore(
                UIUtils.getActivePage(), EFS.getLocalFileSystem().fromLocalFile(file));
  }
  /** Checks whether the specified inclusion exists. */
  public boolean getInclusionExists(final String path) {
    if (UNCPathConverter.isUNC(path)) {
      try {
        IFileStore store = EFS.getStore(UNCPathConverter.getInstance().toURI(path));
        return store.fetchInfo().exists();
      } catch (CoreException e) {
        return false;
      }
    }

    return new File(path).exists();
  }
示例#24
0
  public static boolean openEditor(final UiAutomatorResult r) {
    final IFileStore fileStore =
        EFS.getLocalFileSystem().getStore(new Path(r.uiHierarchy.getAbsolutePath()));
    if (!fileStore.fetchInfo().exists()) {
      return false;
    }

    final AtomicBoolean status = new AtomicBoolean(false);

    final IWorkbench workbench = PlatformUI.getWorkbench();
    workbench
        .getDisplay()
        .syncExec(
            new Runnable() {
              @Override
              public void run() {
                IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
                if (window == null) {
                  return;
                }

                IWorkbenchPage page = window.getActivePage();
                if (page == null) {
                  return;
                }

                // try to switch perspectives if possible
                if (page.isEditorAreaVisible() == false && InstallDetails.isAdtInstalled()) {
                  try {
                    workbench.showPerspective(
                        "org.eclipse.jdt.ui.JavaPerspective", window); // $NON-NLS-1$
                  } catch (WorkbenchException e) {
                  }
                }

                IEditorPart editor = null;
                try {
                  editor = IDE.openEditorOnFileStore(page, fileStore);
                } catch (PartInitException e) {
                  return;
                }

                if (!(editor instanceof UiAutomatorViewer)) {
                  return;
                }

                ((UiAutomatorViewer) editor).setModel(r.model, r.uiHierarchy, r.screenshot);
                status.set(true);
              }
            });

    return status.get();
  }
示例#25
0
  @Test
  public void testLocalFileProxy() {
    IRemoteFileProxy fileProxy = null;
    try {
      fileProxy = proxyManager.getFileProxy(localProject.getProject());
      assertTrue("Should have returned a remote launcher", fileProxy instanceof LocalFileProxy);
    } catch (CoreException e) {
      fail("Should have returned a launcher: " + e.getCause());
    }

    /*
     * Test getDirectorySeparator()
     */
    String ds = fileProxy.getDirectorySeparator();
    assertNotNull(ds);
    /*
     *  Test getResource()
     */
    IFileStore actualFileStore =
        fileProxy.getResource(localProject.getProject().getLocation().toOSString());
    assertNotNull(actualFileStore);

    IFileStore expectedFileStore = null;
    try {
      expectedFileStore = EFS.getStore(localProject.getLocationURI());
    } catch (CoreException e) {
      fail("Unabled to get FileStore to local project: " + e.getMessage());
    }
    assertEquals("FileStore to local project folder diverge", expectedFileStore, actualFileStore);
    assertTrue(actualFileStore.fetchInfo().isDirectory());

    actualFileStore = fileProxy.getResource("/filenotexits");
    assertNotNull(actualFileStore);
    IFileInfo fileInfo = actualFileStore.fetchInfo();
    assertNotNull(fileInfo);
    assertFalse(fileInfo.exists());

    /*
     * Test getWorkingDir()
     */
    URI workingDir = fileProxy.getWorkingDir();
    assertNotNull(workingDir);
    assertEquals(localProject.getLocationURI(), workingDir);

    /*
     * Test toPath()
     */
    assertEquals(
        localProject.getProject().getLocation().toOSString(),
        fileProxy.toPath(localProject.getLocationURI()));
  }
 public void testSetReadOnly() {
   IFileStore file = baseStore.getChild("file");
   ensureExists(file, false);
   IFileInfo info = EFS.createFileInfo();
   info.setAttribute(EFS.ATTRIBUTE_READ_ONLY, true);
   try {
     file.putInfo(info, EFS.SET_ATTRIBUTES, getMonitor());
   } catch (CoreException e) {
     fail("1.99", e);
   }
   info = file.fetchInfo();
   assertEquals("1.0", true, info.getAttribute(EFS.ATTRIBUTE_READ_ONLY));
   assertEquals("1.1", file.getName(), info.getName());
 }
示例#27
0
  private IEditorInput getUnzippedEditorInput() throws Exception {

    final InputStream in = ZipUtils.getStreamForFile(EclipseUtils.getFile(getEditorInput()));
    final String fileName = getEditorInput().getName();
    final String zipExt = FileUtils.getFileExtension(fileName);
    // This might not work, depending on how file is named.
    final String origExt =
        FileUtils.getFileExtension(fileName.substring(0, fileName.length() - zipExt.length() - 1));

    final File file = File.createTempFile(fileName, "." + origExt);
    file.deleteOnExit();
    FileUtils.write(new BufferedInputStream(in), file);

    final IFileStore externalFile = EFS.getLocalFileSystem().fromLocalFile(file);
    return new FileStoreEditorInput(externalFile);
  }
  /**
   * This version will return token level Scopes.
   *
   * @throws Exception
   */
  public void testGetScopeAtOffsetSourceViewer() throws Exception {
    setUpStandardScopes();

    createAndOpenFile(
        "testing",
        ".js",
        "if(Object.isUndefined(Effect))\nthrow(\"dragdrop.js requires including script.aculo.us' effects.js library\");");

    editor =
        (ITextEditor)
            IDE.openEditorOnFileStore(
                UIUtils.getActivePage(), EFS.getLocalFileSystem().fromLocalFile(file));

    assertScope("source.js keyword.control.js", 1);
    assertScope("source.js support.class.js", 7);
  }
示例#29
0
文件: MME.java 项目: gedaofeng/xmind3
 public static IFileStore getFileStore(Object input) {
   IFileStore fileStore = (IFileStore) getAdapter(input, IFileStore.class);
   if (fileStore == null) {
     File file = (File) getAdapter(input, File.class);
     if (file != null) {
       try {
         fileStore = EFS.getStore(file.toURI());
       } catch (CoreException ignore) {
       }
     }
   }
   if (fileStore == null) {
     fileStore = forceFileStore(input);
   }
   return fileStore;
 }
  protected void okPressed() {
    Object selectedElement = getSelectedElement();
    IDeveloperStudioElement resource = (IDeveloperStudioElement) selectedElement;

    /*
    if (resource.getSource() instanceof IFile) {
    	IFile selectedIFile = (IFile) resource.getSource();
    	ipathOfselection = selectedIFile.getFullPath().toString();

    	IProject project = selectedIFile.getProject();
    	RegistryFileImpl rpi = (RegistryFileImpl)selectedElement;
    	String fileName = rpi.getName();
    	String fullPath = rpi.getPath();
    	int index = fullPath.lastIndexOf('/');
    	String path = "";
    	if (index > 0) {
    		path = fullPath.substring(0,index);
    	}

    	if (path != null && !path.isEmpty())
    		try {
    			CreateNewConfigurationDialog.createRegistryResourcesForInputScemaAndOutputSchema(fileName, project, path);
    		} catch (Exception e) {
    			log.error(e.getMessage());
    		}
    }
    */

    if (showOpenResourceCheckBox && chkOpenResource.getSelection()) {
      try {
        if (resource.getSource() instanceof IFile) {
          IDE.openEditor(
              PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(),
              (IFile) resource.getSource());
        } else if (resource.getSource() instanceof File && ((File) resource.getSource()).isFile()) {
          IFileStore fileStore =
              EFS.getLocalFileSystem().getStore(((File) resource.getSource()).toURI());
          IWorkbenchPage page =
              PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
          IDE.openEditorOnFileStore(page, fileStore);
        }
      } catch (PartInitException e) {
        log.error("Error opening the resource file", e);
      }
    }
    super.okPressed();
  }