예제 #1
0
  private Set<Resource> addProjectBuildBundles(Resolver resolver) {
    if (!Project.BNDFILE.equals(runFile.getName())) return Collections.emptySet();

    Set<Resource> result = new HashSet<Resource>();
    try {

      Project model = Workspace.getProject(runFile.getProject().getLocation().toFile());
      for (Builder builder : model.getSubBuilders()) {
        File file = new File(model.getTarget(), builder.getBsn() + ".jar");
        if (file.isFile()) {
          JarInputStream stream = null;
          try {
            stream = new JarInputStream(new FileInputStream(file));
            Manifest manifest = stream.getManifest();

            Resource resource = helper.createResource(manifest.getMainAttributes());
            result.add(resource);
            resolver.add(resource);
          } catch (IOException e) {
            Plugin.logError("Error reading project bundle " + file, e);
          } finally {
            if (stream != null) stream.close();
          }
        }
      }
    } catch (Exception e) {
      Plugin.logError("Error getting builders for project: " + runFile.getProject(), e);
    }
    return result;
  }
 Project getProject() {
   Project project = null;
   try {
     BndEditModel model = (BndEditModel) getManagedForm().getInput();
     IResource resource = model.getBndResource();
     File projectDir = resource.getProject().getLocation().toFile();
     if (Project.BNDFILE.equals(resource.getName())) {
       project = Workspace.getProject(projectDir);
     } else {
       project = new Project(Central.getWorkspace(), projectDir, resource.getLocation().toFile());
     }
   } catch (Exception e) {
     Plugin.logError("Error getting project from editor model", e);
   }
   return project;
 }
예제 #3
0
  @Override
  public void init(IEditorSite site, IEditorInput input) throws PartInitException {
    super.init(site, input);
    sourcePage.init(site, input);

    setPartNameForInput(input);

    IResource resource = ResourceUtil.getResource(input);
    if (resource != null) {
      resource.getWorkspace().addResourceChangeListener(this);
    }

    final IDocumentProvider docProvider = sourcePage.getDocumentProvider();
    IDocument document = docProvider.getDocument(input);
    try {
      model.loadFrom(new IDocumentWrapper(document));
      model.setProjectFile(Project.BNDFILE.equals(input.getName()));

      if (resource != null) {
        model.setBndResource(resource.getLocation().toFile());
      }
      // model.addPropertyChangeListener(modelListener);
    } catch (IOException e) {
      throw new PartInitException("Error reading editor input.", e);
    }

    // Ensure the field values are updated if the file content is replaced
    docProvider.addElementStateListener(
        new IElementStateListener() {
          public void elementMoved(Object originalElement, Object movedElement) {}

          public void elementDirtyStateChanged(Object element, boolean isDirty) {}

          public void elementDeleted(Object element) {}

          public void elementContentReplaced(Object element) {
            try {
              model.loadFrom(new IDocumentWrapper(docProvider.getDocument(element)));
            } catch (IOException e) {
              logger.logError("Error loading model from document.", e);
            }
          }

          public void elementContentAboutToBeReplaced(Object element) {}
        });
  }
예제 #4
0
  private List<String> getPagesBnd(String fileName) {
    List<String> pages = new ArrayList<String>(5);

    boolean isProjectFile = Project.BNDFILE.equals(fileName);
    List<String> subBndFiles = model.getSubBndFiles();
    boolean isSubBundles = subBndFiles != null && !subBndFiles.isEmpty();

    for (Entry<String, IFormPageFactory> pageEntry : pageFactories.entrySet()) {
      String pageId = pageEntry.getKey();
      IFormPageFactory page = pageEntry.getValue();

      if (!isSubBundles && page.supportsMode(IFormPageFactory.Mode.bundle)) pages.add(pageId);
      else if (isProjectFile && page.supportsMode(IFormPageFactory.Mode.build)) pages.add(pageId);
      else if (isProjectFile && page.supportsMode(IFormPageFactory.Mode.run)) pages.add(pageId);
    }

    return pages;
  }
예제 #5
0
  private Project getProject() throws Exception {
    File file = runFile.getLocation().toFile();

    Project result;
    if ("bndrun".equals(runFile.getFileExtension())) {
      result = new Project(Central.getWorkspace(), file.getParentFile(), file);

      File bndbnd = new File(file.getParentFile(), Project.BNDFILE);
      if (bndbnd.isFile()) {
        Project parentProject = Workspace.getProject(file.getParentFile());
        result.setParent(parentProject);
      }
    } else if (Project.BNDFILE.equals(runFile.getName())) {
      result = Workspace.getProject(file.getParentFile());
    } else {
      throw new Exception("Invalid run file: " + runFile.getLocation());
    }
    return result;
  }
예제 #6
0
  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);
  }
예제 #7
0
 private void launchSelectedObject(Object selected, String mode) throws CoreException {
   if (selected instanceof IJavaElement) {
     launchJavaElement((IJavaElement) selected, mode);
   } else if (selected instanceof IResource
       && Project.BNDFILE.equals(((IResource) selected).getName())) {
     IProject project = ((IResource) selected).getProject();
     launchProject(project, mode);
   } else if (selected instanceof IFile
       && ((IFile) selected).getName().endsWith(LaunchConstants.EXT_BNDRUN)) {
     IFile bndRunFile = (IFile) selected;
     launchBndRun(bndRunFile, mode);
   } else if (selected instanceof IAdaptable) {
     IAdaptable adaptable = (IAdaptable) selected;
     IJavaElement javaElement = (IJavaElement) adaptable.getAdapter(IJavaElement.class);
     if (javaElement != null) {
       launchJavaElement(javaElement, mode);
     } else {
       IResource resource = (IResource) adaptable.getAdapter(IResource.class);
       if (resource != null && resource != selected) launchSelectedObject(resource, mode);
     }
   }
 }