コード例 #1
0
ファイル: BndEditor.java プロジェクト: rkrzewski/bndtools
  private void setPartNameForInput(IEditorInput input) {
    Pair<String, String> fileAndProject = getFileAndProject(input);
    String path = fileAndProject.getFirst();
    String projectName = fileAndProject.getSecond();

    String name = input.getName();
    if (isMainWorkspaceConfig(path, projectName) || isExtWorkspaceConfig(path, projectName)) {
      name = path;
    } else if (Project.BNDFILE.equals(name)) {
      IResource resource = ResourceUtil.getResource(input);
      if (resource != null) name = projectName;
    } else if (name.endsWith(".bnd")) {
      IResource resource = ResourceUtil.getResource(input);
      if (resource != null)
        name = projectName + "." + name.substring(0, name.length() - ".bnd".length());
    } else if (name.endsWith(".bndrun")) {
      name = name.substring(0, name.length() - ".bndrun".length());
    }
    setPartName(name);
  }
コード例 #2
0
  @Override
  public boolean performFinish() {
    MultiStatus status =
        new MultiStatus(Plugin.PLUGIN_ID, 0, "Failed to install one or more bundles", null);

    List<File> files = fileSelectionPage.getFiles();
    selectedBundles = new LinkedList<Pair<String, String>>();
    for (File file : files) {
      Jar jar = null;
      try {
        jar = new Jar(file);
        jar.setDoNotTouchManifest();

        Attributes mainAttribs = jar.getManifest().getMainAttributes();
        String bsn = BundleUtils.getBundleSymbolicName(mainAttribs);
        String version = mainAttribs.getValue(Constants.BUNDLE_VERSION);
        if (version == null) version = "0";
        selectedBundles.add(Pair.newInstance(bsn, version));
      } catch (IOException e) {
        status.add(
            new Status(
                IStatus.ERROR,
                Plugin.PLUGIN_ID,
                0,
                MessageFormat.format("Failed to analyse JAR: {0}", file.getPath()),
                e));
        continue;
      }

      try {
        File newFile = repository.put(jar);

        RefreshFileJob refreshJob = new RefreshFileJob(newFile);
        if (refreshJob.isFileInWorkspace()) refreshJob.schedule();
      } catch (Exception e) {
        status.add(
            new Status(
                IStatus.ERROR,
                Plugin.PLUGIN_ID,
                0,
                MessageFormat.format("Failed to add JAR to repository: {0}", file.getPath()),
                e));
        continue;
      }
    }

    if (status.isOK()) {
      return true;
    } else {
      ErrorDialog.openError(getShell(), "Error", null, status);
      return false;
    }
  }
コード例 #3
0
ファイル: BndEditor.java プロジェクト: rkrzewski/bndtools
 static Pair<String, String> getFileAndProject(IEditorInput input) {
   String path;
   String projectName;
   if (input instanceof IFileEditorInput) {
     IFile file = ((IFileEditorInput) input).getFile();
     path = file.getProjectRelativePath().toString();
     projectName = file.getProject().getName();
   } else {
     path = input.getName();
     projectName = null;
   }
   return Pair.newInstance(path, projectName);
 }
コード例 #4
0
ファイル: BndEditor.java プロジェクト: rkrzewski/bndtools
  void updatePages() {
    List<String> requiredPageIds = new LinkedList<String>();

    // Need to know the file and project names.
    Pair<String, String> fileAndProject = getFileAndProject(getEditorInput());
    String path = fileAndProject.getFirst();
    String projectName = fileAndProject.getSecond();

    if (isMainWorkspaceConfig(path, projectName)) {
      requiredPageIds.add(WORKSPACE_PAGE);
    } else if (isExtWorkspaceConfig(path, projectName)) {
      requiredPageIds.add(WORKSPACE_EXT_PAGE);
      setTitleImage(buildFileImg);
    } else if (path.endsWith(LaunchConstants.EXT_BNDRUN)) {
      requiredPageIds.addAll(getPagesBndRun());
    } else {
      requiredPageIds.addAll(getPagesBnd(path));
    }
    requiredPageIds.add(SOURCE_PAGE);

    // Remove pages no longer required and remember the rest in a map
    int i = 0;
    Map<String, IFormPage> pageCache = new HashMap<String, IFormPage>(requiredPageIds.size());
    while (i < getPageCount()) {
      IFormPage current = (IFormPage) pages.get(i);
      if (!requiredPageIds.contains(current.getId())) removePage(i);
      else {
        pageCache.put(current.getId(), current);
        i++;
      }
    }

    // Cache new pages
    for (String pageId : requiredPageIds) {
      if (!pageCache.containsKey(pageId)) {
        IFormPage page =
            SOURCE_PAGE.equals(pageId)
                ? sourcePage
                : pageFactories.get(pageId).createPage(this, model, pageId);
        pageCache.put(pageId, page);
      }
    }

    // Add pages back in
    int requiredPointer = 0;
    int existingPointer = 0;

    while (requiredPointer < requiredPageIds.size()) {
      try {
        String requiredId = requiredPageIds.get(requiredPointer);
        if (existingPointer >= getPageCount()) {
          if (SOURCE_PAGE.equals(requiredId)) addPage(sourcePage, getEditorInput());
          else addPage(pageCache.get(requiredId));
        } else {
          IFormPage existingPage = (IFormPage) pages.get(existingPointer);
          if (!requiredId.equals(existingPage.getId())) {
            if (SOURCE_PAGE.equals(requiredId))
              addPage(existingPointer, sourcePage, getEditorInput());
            else addPage(existingPointer, pageCache.get(requiredId));
          }
        }
        existingPointer++;
      } catch (PartInitException e) {
        logger.logError("Error adding page(s) to the editor.", e);
      }
      requiredPointer++;
    }

    // Set the source page title
    setPageText(sourcePage.getIndex(), "Source");
  }