@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;
 }
  @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;
  }
Ejemplo n.º 3
0
 /**
  * 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;
 }
Ejemplo n.º 4
0
 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;
 }
  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;
  }
Ejemplo n.º 6
0
  /**
   * Installs the bundle corresponding to the model.
   *
   * @param model Model of the bundle to be installed.
   */
  private void installBundle(IPluginModelBase model) {
    try {
      final IResource candidateManifest = model.getUnderlyingResource();
      final IProject project = candidateManifest.getProject();

      URL url = null;
      try {
        url = project.getLocationURI().toURL();
      } catch (MalformedURLException e) {
        // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=354360
        try {
          URI uri = project.getLocationURI();
          IFileStore store = EFS.getStore(uri);
          File file = store.toLocalFile(0, null);
          if (file != null) {
            url = file.toURI().toURL();
          }
        } catch (CoreException ex) {
          // Logging both exceptions just to be sure
          AcceleoCommonPlugin.log(e, false);
          AcceleoCommonPlugin.log(ex, false);
        }
      }

      if (url != null) {
        final String candidateLocationReference =
            REFERENCE_URI_PREFIX
                + URLDecoder.decode(
                    url.toExternalForm(), System.getProperty("file.encoding")); // $NON-NLS-1$

        Bundle bundle = getBundle(candidateLocationReference);

        /*
         * Install the bundle if needed. Note that we'll check bundle dependencies in two phases as
         * even if there cannot be cyclic dependencies through the "require-bundle" header, there
         * could be through the "import package" header.
         */
        if (bundle == null) {
          checkRequireBundleDependencies(model);
          bundle = installBundle(candidateLocationReference);
          setBundleClasspath(project, bundle);
          workspaceInstalledBundles.put(model, bundle);
          checkImportPackagesDependencies(model);
        }
        refreshPackages(
            new Bundle[] {
              bundle,
            });
      }
    } catch (BundleException e) {
      String bundleName = model.getBundleDescription().getName();
      if (!logOnceProjectLoad.contains(bundleName)) {
        logOnceProjectLoad.add(bundleName);
        AcceleoCommonPlugin.log(
            new Status(
                IStatus.WARNING,
                AcceleoCommonPlugin.PLUGIN_ID,
                AcceleoCommonMessages.getString(
                    "WorkspaceUtil.InstallationFailure", //$NON-NLS-1$
                    bundleName,
                    e.getMessage()),
                e));
      }
    } catch (MalformedURLException e) {
      AcceleoCommonPlugin.log(e, false);
    } catch (UnsupportedEncodingException e) {
      AcceleoCommonPlugin.log(e, false);
    }
  }