Example #1
0
 public static String getCamelVersion(IProject project) {
   IPath pomPathValue =
       project.getProject().getRawLocation() != null
           ? project.getProject().getRawLocation().append("pom.xml")
           : ResourcesPlugin.getWorkspace()
               .getRoot()
               .getLocation()
               .append(project.getFullPath().append("pom.xml"));
   String pomPath = pomPathValue.toOSString();
   final File pomFile = new File(pomPath);
   try {
     final org.apache.maven.model.Model model = MavenPlugin.getMaven().readModel(pomFile);
     List<org.apache.maven.model.Dependency> deps = model.getDependencies();
     for (Iterator<org.apache.maven.model.Dependency> iterator = deps.iterator();
         iterator.hasNext(); ) {
       org.apache.maven.model.Dependency dependency = iterator.next();
       if (dependency.getArtifactId().equals("camel-core")) {
         return dependency.getVersion();
       }
     }
   } catch (CoreException e) {
     // not found, go with default
   }
   return org.fusesource.ide.camel.editor.Activator.getDefault().getCamelVersion();
 }
  private void handleBrowse() {
    IContainer container;
    if (_project == null) {
      container = ResourcesPlugin.getWorkspace().getRoot();
    } else {
      container = _project.getProject();
    }
    ClasspathResourceSelectionDialog dialog =
        new ClasspathResourceSelectionDialog(_panel.getShell(), container, "bpel");
    if (dialog.open() == SelectionDialog.OK) {
      Object[] result = dialog.getResult();
      if (result.length > 0 && result[0] instanceof IFile) {
        IFile bpelFile = (IFile) result[0];
        String bpelFilePath = JavaUtil.getJavaPathForResource(bpelFile).toString();
        _implementation = BPELFactory.eINSTANCE.createBPELImplementation();

        // load process
        final QName processName = Activator.getDefault().getProcessForFile(bpelFile);
        // get process qname
        _implementation.setProcess(processName);

        // update the text box, which should trigger a validate
        _bpelFileText.setText(bpelFilePath);
      }
    }
  }
Example #3
0
  public static void updateMavenDependencies(
      final List<Dependency> dependencies, final IProject project) throws CoreException {
    final IFile pomIFile = project.getProject().getFile("pom.xml");
    final File pomFile = new File(pomIFile.getLocationURI());
    final org.apache.maven.model.Model pom = MavenPlugin.getMaven().readModel(pomFile);

    // Check if dependency already in the pom
    final List<Dependency> missingDependencies = new ArrayList<>();
    for (final Dependency dependency : dependencies) {
      boolean found = false;
      for (final org.apache.maven.model.Dependency pomDependency : pom.getDependencies()) {
        if (pomDependency.getGroupId().equalsIgnoreCase(dependency.getGroupId())
            && pomDependency.getArtifactId().equalsIgnoreCase(dependency.getArtifactId())) {
          // check for correct version
          if (!pomDependency.getVersion().equalsIgnoreCase(dependency.getVersion())) {
            pomDependency.setVersion(dependency.getVersion());
          }
          found = true;
          break;
        }
      }
      if (!found) {
        missingDependencies.add(dependency);
      }
    }

    for (final Dependency dependency : missingDependencies) {
      final org.apache.maven.model.Dependency pomDependency =
          new org.apache.maven.model.Dependency();
      pomDependency.setGroupId(dependency.getGroupId());
      pomDependency.setArtifactId(dependency.getArtifactId());
      pomDependency.setVersion(dependency.getVersion());
      pom.addDependency(pomDependency);
    }

    if (!missingDependencies.isEmpty()) {
      try (final OutputStream stream = new BufferedOutputStream(new FileOutputStream(pomFile))) {
        MavenPlugin.getMaven().writeModel(pom, stream);
        pomIFile.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
      } catch (final Exception e) {
        Activator.error(e);
      }
    }
  }
 /**
  * Method returns array of project names which are open and has windows azure nature.
  *
  * @return String[]
  */
 private String[] getProjects() {
   IWorkspace workspace = ResourcesPlugin.getWorkspace();
   IWorkspaceRoot root = workspace.getRoot();
   String[] projects = null;
   ArrayList<String> projList = new ArrayList<String>();
   try {
     for (IProject wRoot : root.getProjects()) {
       if (wRoot.isOpen() && !wRoot.hasNature(Messages.waProjNature)) {
         projList.add(wRoot.getProject().getName());
       }
     }
     projects = new String[projList.size()];
     projects = projList.toArray(projects);
   } catch (Exception e) {
     PluginUtil.displayErrorDialogAndLog(
         this.getShell(), Messages.projSelTtl, Messages.projSelMsg, e);
   }
   return projects;
 }
Example #5
0
  /**
   * checks if we need to add a maven dependency for the chosen component and inserts it into the
   * pom.xml if needed
   */
  public static void updateMavenDependencies(
      List<org.fusesource.ide.camel.model.catalog.Dependency> compDeps) throws CoreException {
    RiderDesignEditor editor = Activator.getDiagramEditor();
    if (editor == null) {
      Activator.getLogger()
          .error(
              "Unable to add component dependencies because Editor instance can't be determined.");
      return;
    }

    IProject project = editor.getCamelContextFile().getProject();
    if (project == null) {
      Activator.getLogger()
          .error(
              "Unable to add component dependencies because selected project can't be determined.");
      return;
    }

    IPath pomPathValue =
        project.getProject().getRawLocation() != null
            ? project.getProject().getRawLocation().append("pom.xml")
            : ResourcesPlugin.getWorkspace()
                .getRoot()
                .getLocation()
                .append(project.getFullPath().append("pom.xml"));
    String pomPath = pomPathValue.toOSString();
    final File pomFile = new File(pomPath);
    final Model model = MavenPlugin.getMaven().readModel(pomFile);

    // then check if component dependency is already a dep
    ArrayList<org.fusesource.ide.camel.model.catalog.Dependency> missingDeps =
        new ArrayList<org.fusesource.ide.camel.model.catalog.Dependency>();
    List<Dependency> deps = model.getDependencies();
    for (org.fusesource.ide.camel.model.catalog.Dependency conDep : compDeps) {
      boolean found = false;
      for (Dependency pomDep : deps) {
        if (pomDep.getGroupId().equalsIgnoreCase(conDep.getGroupId())
            && pomDep.getArtifactId().equalsIgnoreCase(conDep.getArtifactId())) {
          // check for correct version
          if (pomDep.getVersion().equalsIgnoreCase(conDep.getVersion()) == false) {
            // not the correct version - change it to fit
            pomDep.setVersion(conDep.getVersion());
          }
          found = true;
          break;
        }
      }
      if (!found) {
        missingDeps.add(conDep);
      }
    }

    for (org.fusesource.ide.camel.model.catalog.Dependency missDep : missingDeps) {
      Dependency dep = new Dependency();
      dep.setGroupId(missDep.getGroupId());
      dep.setArtifactId(missDep.getArtifactId());
      dep.setVersion(missDep.getVersion());
      model.addDependency(dep);
    }

    if (missingDeps.size() > 0) {
      OutputStream os = null;
      try {
        os = new BufferedOutputStream(new FileOutputStream(pomFile));
        MavenPlugin.getMaven().writeModel(model, os);
        IFile pomIFile = project.getProject().getFile("pom.xml");
        if (pomIFile != null) {
          pomIFile.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
        }
      } catch (Exception ex) {
        Activator.getLogger().error(ex);
      } finally {
        try {
          if (os != null) {
            os.close();
          }
        } catch (IOException e) {
          Activator.getLogger().error(e);
        }
      }
    }
  }
Example #6
0
 /**
  * Disconnects provider from project
  *
  * @param project
  * @throws CoreException
  */
 public void disconnect(IProject project) throws CoreException {
   Collection<IProject> projects = Collections.singleton(project.getProject());
   DisconnectProviderOperation disconnect = new DisconnectProviderOperation(projects);
   disconnect.execute(null);
 }