コード例 #1
0
 /*
  * Filter elements to avoid having files of directory traces listed as
  * separate traces.
  */
 private void filterElements(TracePackageElement parentElement) {
   for (TracePackageElement childElement : parentElement.getChildren()) {
     filterElements(childElement);
     if (childElement instanceof TracePackageTraceElement) {
       // no need to do length check here
       RemoteImportTraceFilesElement filesElement =
           (RemoteImportTraceFilesElement) childElement.getChildren()[0];
       IFileStore parentFile = filesElement.getRemoteFile().getParent();
       if (fDirectoryTraces.contains(
           TmfTraceCoreUtils.newSafePath(parentFile.toURI().getPath()))) {
         removeChild(childElement, parentElement);
         continue;
       }
       IFileStore grandParentFile = parentFile.getParent();
       if (grandParentFile != null
           && fDirectoryTraces.contains(
               TmfTraceCoreUtils.newSafePath(grandParentFile.toURI().getPath()))) {
         // ignore file if grandparent is a directory trace
         // for example: file is a index file of a LTTng kernel trace
         parentElement.removeChild(childElement);
         if (parentElement.getChildren().length == 0) {
           TracePackageElement grandParentElement = parentElement.getParent();
           removeChild(parentElement, grandParentElement);
         }
         continue;
       }
     } else if (childElement instanceof RemoteImportFolderElement) {
       if (childElement.getChildren().length == 0) {
         parentElement.removeChild(childElement);
       }
     }
   }
 }
コード例 #2
0
 private static void openXmlEditor(final IFileStore fileStore, int line, int column, String name) {
   assert fileStore != null;
   IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
   if (window != null) {
     IWorkbenchPage page = window.getActivePage();
     if (page != null) {
       try {
         if (!fileStore.getName().endsWith(".pom")) { // .pom means stuff from local repository?
           IEditorPart part = IDE.openEditorOnFileStore(page, fileStore);
           reveal(selectEditorPage(part), line, column);
         } else {
           // we need special EditorInput for stuff from repository
           name = name + ".pom"; // $NON-NLS-1$
           File file = new File(fileStore.toURI());
           try {
             IEditorInput input =
                 new MavenPathStorageEditorInput(
                     name, name, file.getAbsolutePath(), readStream(new FileInputStream(file)));
             IEditorPart part = OpenPomAction.openEditor(input, name);
             reveal(selectEditorPage(part), line, column);
           } catch (IOException e) {
             log.error("failed opening editor", e);
           }
         }
       } catch (PartInitException e) {
         MessageDialog.openInformation(
             Display.getDefault().getActiveShell(), //
             Messages.PomHyperlinkDetector_error_title,
             NLS.bind(Messages.PomHyperlinkDetector_error_message, fileStore, e.toString()));
       }
     }
   }
 }
  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);
  }
コード例 #4
0
  /**
   * 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();
  }
コード例 #5
0
ファイル: GitUtils.java プロジェクト: Corly/orion.server
 /**
  * Returns the existing git repositories for the given file path, following the given traversal
  * rule.
  *
  * @param path expected format /file/{Workspace}/{projectName}[/{path}]
  * @return a map of all git repositories found, or <code>null</code> if the provided path format
  *     doesn't match the expected format.
  * @throws CoreException
  */
 public static Map<IPath, File> getGitDirs(IPath path, Traverse traverse) throws CoreException {
   IPath p = path.removeFirstSegments(1); // remove /file
   IFileStore fileStore = NewFileServlet.getFileStore(null, p);
   if (fileStore == null) return null;
   Map<IPath, File> result = new HashMap<IPath, File>();
   File file = fileStore.toLocalFile(EFS.NONE, null);
   // jgit can only handle a local file
   if (file == null) return result;
   switch (traverse) {
     case CURRENT:
       if (RepositoryCache.FileKey.isGitRepository(file, FS.DETECTED)) {
         result.put(new Path(""), file); // $NON-NLS-1$
       } else if (RepositoryCache.FileKey.isGitRepository(
           new File(file, Constants.DOT_GIT), FS.DETECTED)) {
         result.put(new Path(""), new File(file, Constants.DOT_GIT)); // $NON-NLS-1$
       }
       break;
     case GO_UP:
       getGitDirsInParents(file, result);
       break;
     case GO_DOWN:
       getGitDirsInChildren(file, p, result);
       break;
   }
   return result;
 }
コード例 #6
0
  /** @see junit.framework.TestCase#tearDown() */
  protected void tearDown() throws Exception {
    try {
      if (clientDirectory.fetchInfo().exists()) {
        // clientDirectory.delete(EFS.NONE, null);
        // assertFalse(clientDirectory.fetchInfo().exists());
      }
    } finally {
      if (clientManager.isConnected()) {
        clientManager.disconnect(null);
      }
    }

    try {
      if (serverDirectory.fetchInfo().exists()) {
        // serverDirectory.delete(EFS.NONE, null);
        // assertFalse(serverDirectory.fetchInfo().exists());
      }
    } finally {
      if (serverManager.isConnected()) {
        serverManager.disconnect(null);
      }
    }

    super.tearDown();
  }
コード例 #7
0
    @Override
    public ImageDescriptor getImageDescriptor(Object object) {
      if (object instanceof IFileStore) {
        IFileStore fileStore = (IFileStore) object;

        try {
          if (fileStore.fetchInfo().isDirectory()) {
            return PlatformUI.getWorkbench()
                .getSharedImages()
                .getImageDescriptor(ISharedImages.IMG_OBJ_FOLDER);
          }

          IEditorDescriptor descriptor = IDE.getEditorDescriptor(fileStore.getName());

          if (descriptor != null) {
            return descriptor.getImageDescriptor();
          } else {
            return PlatformUI.getWorkbench()
                .getSharedImages()
                .getImageDescriptor(ISharedImages.IMG_OBJ_FILE);
          }
        } catch (PartInitException e) {

        }
      }

      return null;
    }
コード例 #8
0
  protected void testFilesExists(
      HashMap<String, IFileStore> destMap,
      IFileStore sourceRoot,
      IFileStore sourceFile,
      int timeTolerance)
      throws CoreException {
    String relPath = EFSUtils.getRelativePath(sourceRoot, sourceFile, null);
    IFileStore destFile = destMap.get(relPath);
    // System.out.println("Comparing " + relPath);

    assertNotNull(MessageFormat.format("File {0} not found on destination", relPath), destFile);
    IFileInfo f1 = sourceFile.fetchInfo(IExtendedFileStore.DETAILED, null);
    IFileInfo f2 = destFile.fetchInfo(IExtendedFileStore.DETAILED, null);
    if (!f1.isDirectory()) {
      long sourceFileTime = f1.getLastModified();
      long destFileTime = f2.getLastModified();
      long timeDiff = destFileTime - sourceFileTime;

      assertTrue(
          MessageFormat.format(
              "File {0} is {1} seconds newer on destination", relPath, (int) timeDiff / 1000),
          -timeTolerance <= timeDiff && timeDiff <= timeTolerance);
      assertEquals(
          MessageFormat.format("File {0} different sizes", relPath),
          f1.getLength(),
          f2.getLength());
    }
  }
コード例 #9
0
  @Override
  public Object[] getChildren(Object element) {
    try {
      if (element instanceof IWorkspaceRoot) {
        IWorkspaceRoot root = (IWorkspaceRoot) element;

        List<Object> children = new ArrayList<Object>();

        children.addAll(Arrays.asList(root.members()));
        children.add(SdkDirectoryNode.INSTANCE);

        return children.toArray();
      } else if (element instanceof IContainer) {
        IContainer container = (IContainer) element;
        return filteredMembers(container).toArray();
      } else if (element instanceof IFileStore) {
        IFileStore fileStore = (IFileStore) element;
        return fileStore.childStores(EFS.NONE, null);
      } else if (element instanceof SdkDirectoryNode) {
        return ((SdkDirectoryNode) element).getLibraries();
      } else if (element instanceof SdkLibraryNode) {
        return ((SdkLibraryNode) element).getFiles();
      }
    } catch (CoreException ce) {
      // fall through
    }

    return NO_CHILDREN;
  }
コード例 #10
0
ファイル: EditorUtility.java プロジェクト: CODINGLFQ/erlide
 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;
 }
コード例 #11
0
ファイル: DotGraphView.java プロジェクト: seok86/gef4
 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
 private boolean handlePost(
     HttpServletRequest request, HttpServletResponse response, IFileStore dir)
     throws JSONException, CoreException, ServletException, IOException {
   // setup and precondition checks
   JSONObject requestObject = OrionServlet.readJSONRequest(request);
   String name = computeName(request, requestObject);
   if (name.length() == 0)
     return statusHandler.handleRequest(
         request,
         response,
         new ServerStatus(
             IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "File name not specified.", null));
   int options = getCreateOptions(request);
   IFileStore toCreate = dir.getChild(name);
   boolean destinationExists = toCreate.fetchInfo().exists();
   if (!validateOptions(request, response, toCreate, destinationExists, options)) return true;
   // perform the operation
   if (performPost(request, response, requestObject, toCreate, options)) {
     // write the response
     URI location = URIUtil.append(getURI(request), name);
     JSONObject result = ServletFileStoreHandler.toJSON(toCreate, toCreate.fetchInfo(), location);
     OrionServlet.writeJSONResponse(request, response, result);
     response.setHeader(ProtocolConstants.HEADER_LOCATION, location.toString());
     // response code should indicate if a new resource was actually created or not
     response.setStatus(
         destinationExists ? HttpServletResponse.SC_OK : HttpServletResponse.SC_CREATED);
   }
   return true;
 }
コード例 #13
0
 @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;
 }
コード例 #14
0
  @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;
  }
コード例 #15
0
 private static IFileStore getFolderStore(IAdaptable destination) {
   IFileStore store = Utils.getFileStore(destination);
   IFileInfo info = Utils.getFileInfo(destination);
   if (store != null && info != null && !info.isDirectory()) {
     store = store.getParent();
   }
   return store;
 }
コード例 #16
0
 @Override
 public Object getParent(Object object) {
   if (object instanceof IFileStore) {
     IFileStore fileStore = (IFileStore) object;
     return fileStore.getParent();
   } else {
     return null;
   }
 }
コード例 #17
0
 @Override
 public String getLabel(Object object) {
   if (object instanceof IFileStore) {
     IFileStore fileStore = (IFileStore) object;
     return fileStore.getName();
   } else {
     return null;
   }
 }
コード例 #18
0
 public UniversalUniqueIdentifier addBlob(IFileStore target, boolean moveContents)
     throws CoreException {
   UniversalUniqueIdentifier uuid = new UniversalUniqueIdentifier();
   folderFor(uuid).mkdir(EFS.NONE, null);
   IFileStore destination = fileFor(uuid);
   if (moveContents) target.move(destination, EFS.NONE, null);
   else target.copy(destination, EFS.NONE, null);
   return uuid;
 }
コード例 #19
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;
      // }
      // }
    }
  }
コード例 #20
0
ファイル: MME.java プロジェクト: gedaofeng/xmind3
 public static File getFile(Object input) {
   IFileStore fileStore = getFileStore(input);
   if (fileStore != null) {
     try {
       return fileStore.toLocalFile(0, new NullProgressMonitor());
     } catch (CoreException ignore) {
     }
   }
   return null;
 }
コード例 #21
0
 private void clean(IFileStore root, boolean deleteIfEmpty, IProgressMonitor monitor)
     throws CoreException {
   if (monitor.isCanceled()) throw new OperationCanceledException();
   if (isUMLFile(root) && MDDUtil.isGenerated(root.toURI())) {
     safeDelete(root);
     return;
   }
   IFileStore[] children = root.childStores(EFS.NONE, null);
   for (int i = 0; i < children.length; i++) clean(children[i], false, monitor);
   if (deleteIfEmpty && root.childStores(EFS.NONE, null).length == 0) root.delete(EFS.NONE, null);
 }
コード例 #22
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();
  }
コード例 #23
0
 @Override
 public Object[] getChildren(Object object) {
   try {
     if (object instanceof IFileStore) {
       IFileStore fileStore = (IFileStore) object;
       return fileStore.childStores(EFS.NONE, null);
     }
   } catch (CoreException exception) {
     // fall through
   }
   return NO_CHILDREN;
 }
コード例 #24
0
  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;
  }
コード例 #25
0
  /** 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();
  }
コード例 #26
0
ファイル: FileProxyTest.java プロジェクト: eclipse/linuxtools
  @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()));
  }
コード例 #27
0
  /**
   * @param sourceStore the file to be copied
   * @param sourceRoot the source root
   * @param destinationRoot the destination root
   * @param monitor the progress monitor
   * @return true if the file is successfully copied, false if the operation did not go through for
   *     any reason
   */
  protected boolean copyFile(
      IFileStore sourceStore,
      IFileStore sourceRoot,
      IFileStore destinationRoot,
      IProgressMonitor monitor) {
    if (sourceStore == null) {
      return false;
    }

    boolean success = true;
    IFileStore[] sourceStores = null, targetStores = null;
    try {
      if (sourceStore.equals(sourceRoot)) {
        // copying the whole source
        sourceStores = sourceRoot.childStores(EFS.NONE, monitor);
        targetStores = new IFileStore[sourceStores.length];
        for (int i = 0; i < targetStores.length; ++i) {
          targetStores[i] = destinationRoot.getChild(sourceStores[i].getName());
        }
      } else if (sourceRoot.isParentOf(sourceStore)) {
        // finds the relative path of the file to be copied and maps to
        // the destination target
        sourceStores = new IFileStore[1];
        sourceStores[0] = sourceStore;

        targetStores = new IFileStore[1];
        String sourceRootPath = sourceRoot.toString();
        String sourcePath = sourceStore.toString();
        int index = sourcePath.indexOf(sourceRootPath);
        if (index > -1) {
          String relativePath = sourcePath.substring(index + sourceRootPath.length());
          targetStores[0] = destinationRoot.getFileStore(new Path(relativePath));
          // makes sure the parent folder is created on the destination side
          IFileStore parent = getFolderStore(targetStores[0]);
          if (parent != targetStores[0]) {
            parent.mkdir(EFS.NONE, monitor);
          }
        }
      }
      if (sourceStores == null) {
        // the file to be copied is not a child of the source root;
        // cannot copy
        success = false;
        sourceStores = new IFileStore[0];
        targetStores = new IFileStore[0];
      }

      for (int i = 0; i < sourceStores.length; ++i) {
        success = copyFile(sourceStores[i], targetStores[i], monitor) && success;
      }
    } catch (CoreException e) {
      // TODO: report the error
      success = false;
    }
    return success;
  }
コード例 #28
0
  private IHyperlink openModule(Node current, ITextViewer textViewer, int offset) {
    while (current != null && !(current instanceof Element)) {
      current = current.getParentNode();
    }
    if (current == null) {
      return null;
    }
    String pathUp = XmlUtils.pathUp(current, 2);
    if (!"modules/module".equals(pathUp)) { // $NON-NLS-1$
      // just in case we are in some random plugin configuration snippet..
      return null;
    }

    ITextFileBuffer buf =
        FileBuffers.getTextFileBufferManager().getTextFileBuffer(textViewer.getDocument());
    if (buf == null) {
      // for repository based poms..
      return null;
    }
    IFileStore folder = buf.getFileStore().getParent();

    String path = XmlUtils.getTextValue(current);
    final String fPath = path;
    // construct IPath for the child pom file, handle relative paths..
    while (folder != null && path.startsWith("../")) { // $NON-NLS-1$
      folder = folder.getParent();
      path = path.substring("../".length()); // $NON-NLS-1$
    }
    if (folder == null) {
      return null;
    }
    IFileStore modulePom = folder.getChild(path);
    if (!modulePom.getName().endsWith("xml")) { // $NON-NLS-1$
      modulePom = modulePom.getChild("pom.xml"); // $NON-NLS-1$
    }
    final IFileStore fileStore = modulePom;
    if (!fileStore.fetchInfo().exists()) {
      return null;
    }
    assert current instanceof IndexedRegion;
    final IndexedRegion region = (IndexedRegion) current;

    return new IHyperlink() {
      public IRegion getHyperlinkRegion() {
        return new Region(region.getStartOffset(), region.getEndOffset() - region.getStartOffset());
      }

      public String getHyperlinkText() {
        return NLS.bind(Messages.PomHyperlinkDetector_open_module, fPath);
      }

      public String getTypeLabel() {
        return "pom-module"; //$NON-NLS-1$
      }

      public void open() {
        openXmlEditor(fileStore);
      }
    };
  }
コード例 #29
0
  // returns true if the request has been served, false if not (only if failEarlyOn404 is true)
  private boolean serveOrionFile(
      HttpServletRequest req,
      HttpServletResponse resp,
      IHostedSite site,
      IPath path,
      boolean failEarlyOn404)
      throws ServletException {
    String userName = site.getUserName();
    String workspaceId = site.getWorkspaceId();
    String workspaceUri = WORKSPACE_SERVLET_ALIAS + "/" + workspaceId; // $NON-NLS-1$
    boolean allow = false;
    // Check that user who launched the hosted site really has access to the workspace
    try {
      if (AuthorizationService.checkRights(userName, workspaceUri, "GET")) { // $NON-NLS-1$
        allow = true;
      }
    } catch (JSONException e) {
      throw new ServletException(e);
    }

    if (allow) {
      // FIXME: this code is copied from NewFileServlet, fix it
      // start copied
      String pathInfo = path.toString();
      IPath filePath = pathInfo == null ? Path.ROOT : new Path(pathInfo);
      IFileStore file = tempGetFileStore(filePath);
      if (file == null || !file.fetchInfo().exists()) {
        if (failEarlyOn404) {
          return false;
        }
        handleException(
            resp,
            new ServerStatus(IStatus.ERROR, 404, NLS.bind("File not found: {0}", filePath), null));
      }
      if (fileSerializer.handleRequest(req, resp, file)) {
        // return;
      }
      // end copied

      if (file != null) {
        addEditHeaders(resp, site, path);
        addContentTypeHeader(resp, path);
      }
    } else {
      String msg = NLS.bind("No rights to access {0}", workspaceUri);
      handleException(
          resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_FORBIDDEN, msg, null));
    }
    return true;
  }
コード例 #30
0
 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());
 }