Пример #1
0
  /**
   * Creates a new project resource with the selected name.
   *
   * <p>In normal usage, this method is invoked after the user has pressed Finish on the wizard; the
   * enablement of the Finish button implies that all controls on the pages currently contain valid
   * values.
   *
   * <p>Note that this wizard caches the new project once it has been successfully created;
   * subsequent invocations of this method will answer the same project resource without attempting
   * to create it again.
   *
   * @param monitor TODO
   * @return the created project resource, or <code>null</code> if the project was not created
   */
  protected IProject createNewProject(IProgressMonitor monitor) throws InvocationTargetException {
    SubMonitor sub = SubMonitor.convert(monitor, 100);
    // Project description creation
    IProjectDescription description =
        ResourceUtil.getProjectDescription(destPath, getProjectNatures(), getProjectBuilders());
    description.setName(newProject.getName());
    description.setLocationURI(location);
    // Update the referenced project in case it was initialized.
    if (refProjects != null && refProjects.length > 0) {
      description.setReferencedProjects(refProjects);
    }
    sub.worked(10);

    if (!applySourcedProjectFilesAfterProjectCreated() && isCloneFromGit()) {
      cloneFromGit(newProject, description, sub.newChild(90));
    } else {
      doBasicCreateProject(newProject, description, sub.newChild(75));
      if (!applySourcedProjectFilesAfterProjectCreated()
          && selectedTemplate != null
          && !isCloneFromGit()) {
        selectedTemplate.apply(newProject, true);
      }
    }

    return newProject;
  }
  private IProject createProject(final GridProjectProperties props, final IProgressMonitor monitor)
      throws CoreException {

    monitor.subTask(Messages.getString("GridProjectCreationOperation.init_task")); // $NON-NLS-1$

    String projectName = props.getProjectName();
    IPath projectPath = props.getProjectLocation();
    IProject[] referencesProjects = props.getReferencesProjects();

    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    IProject project = workspaceRoot.getProject(projectName);

    IStatus status = ResourcesPlugin.getWorkspace().validateProjectLocation(project, projectPath);
    if (status.getSeverity() != IStatus.OK) {
      throw new CoreException(status);
    }

    IProjectDescription desc = project.getWorkspace().newProjectDescription(projectName);
    desc.setLocation(projectPath);
    if (referencesProjects != null) {
      desc.setReferencedProjects(referencesProjects);
    }
    project.create(desc, new SubProgressMonitor(monitor, 50));
    project.open(new SubProgressMonitor(monitor, 50));

    createProjectStructure(project, props);
    setProjectProperties(project, props);

    if (monitor.isCanceled()) {
      throw new OperationCanceledException();
    }

    return project;
  }
    @Override
    public void setUp() throws Exception {
      cproject =
          cpp
              ? CProjectHelper.createCCProject(
                  "OnlineContent" + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER)
              : CProjectHelper.createCProject(
                  "OnlineContent" + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER);
      Bundle b = CTestPlugin.getDefault().getBundle();
      testData =
          TestSourceReader.getContentsForTest(
              b, "parser", IndexBindingResolutionTestBase.this.getClass(), getName(), 2);
      referenced = createReferencedContent();

      TestScannerProvider.sIncludes =
          new String[] {referenced.getProject().getLocation().toOSString()};
      IFile references =
          TestSourceReader.createFile(
              cproject.getProject(),
              new Path("refs.c" + (cpp ? "pp" : "")),
              testData[1].toString());

      IProject[] refs = new IProject[] {referenced.getProject()};
      IProjectDescription pd = cproject.getProject().getDescription();
      pd.setReferencedProjects(refs);
      cproject.getProject().setDescription(pd, new NullProgressMonitor());

      IndexerPreferences.set(
          cproject.getProject(), IndexerPreferences.KEY_INDEXER_ID, IPDOMManager.ID_FAST_INDEXER);
      CCorePlugin.getIndexManager().reindex(cproject);
      waitForIndexer(cproject);

      if (DEBUG) {
        System.out.println("Online: " + getName());
        ((PDOM) CCoreInternals.getPDOMManager().getPDOM(cproject)).accept(new PDOMPrettyPrinter());
      }

      index = CCorePlugin.getIndexManager().getIndex(cproject, IIndexManager.ADD_DEPENDENCIES);
      index.acquireReadLock();
      ast = TestSourceReader.createIndexBasedAST(index, cproject, references);
    }
  /**
   * SIMPLY COPIED;
   *
   * @param currentProject
   * @param containerProject
   * @param className
   * @throws CoreException
   */
  private void doProjectReferenceChange(
      IProject currentProject, IJavaProject containerProject, String className)
      throws CoreException {
    if (currentProject == null || currentProject.equals(containerProject.getProject())) {
      return;
    }

    IProjectDescription desc = currentProject.getDescription();
    IProject[] refs = desc.getReferencedProjects();
    IProject[] newRefs = new IProject[refs.length + 1];
    System.arraycopy(refs, 0, newRefs, 0, refs.length);
    newRefs[refs.length] = containerProject.getProject();
    desc.setReferencedProjects(newRefs);
    currentProject.setDescription(desc, new NullProgressMonitor());

    IPath dependsOnPath = containerProject.getProject().getFullPath();

    IJavaProject javaProject = (IJavaProject) currentProject.getNature(JavaCore.NATURE_ID);
    IClasspathEntry prjEntry = JavaCore.newProjectEntry(dependsOnPath, true);

    boolean dependsOnPresent = false;
    for (IClasspathEntry cpEntry : javaProject.getRawClasspath()) {
      if (cpEntry.equals(prjEntry)) {
        dependsOnPresent = true;
      }
    }

    if (!dependsOnPresent) {
      IClasspathEntry[] entryList = new IClasspathEntry[1];
      entryList[0] = prjEntry;
      ArrayList<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>();
      newEntries.addAll(Arrays.asList(javaProject.getRawClasspath()));
      newEntries.addAll(Arrays.asList(entryList));
      javaProject.setRawClasspath(newEntries.toArray(new IClasspathEntry[0]), null);
    }
  }
Пример #5
0
  /**
   * Creates a new project resource with the entered name.
   *
   * @return the created project resource, or <code>null</code> if the project was not created
   */
  protected IProject createNewProject(final Object... additionalArgsToConfigProject) {
    // get a project handle
    final IProject newProjectHandle = projectPage.getProjectHandle();

    // get a project descriptor
    IPath defaultPath = Platform.getLocation();
    IPath newPath = projectPage.getLocationPath();
    if (defaultPath.equals(newPath)) {
      newPath = null;
    } else {
      // The user entered the path and it's the same as it'd be if he chose the default path.
      IPath withName = defaultPath.append(newProjectHandle.getName());
      if (newPath.toFile().equals(withName.toFile())) {
        newPath = null;
      }
    }

    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    final IProjectDescription description =
        workspace.newProjectDescription(newProjectHandle.getName());
    description.setLocation(newPath);

    // update the referenced project if provided
    if (referencePage != null) {
      IProject[] refProjects = referencePage.getReferencedProjects();
      if (refProjects.length > 0) {
        description.setReferencedProjects(refProjects);
      }
    }

    final String projectType = projectPage.getProjectType();
    final String projectInterpreter = projectPage.getProjectInterpreter();
    // define the operation to create a new project
    WorkspaceModifyOperation op =
        new WorkspaceModifyOperation() {
          protected void execute(IProgressMonitor monitor) throws CoreException {

            createAndConfigProject(
                newProjectHandle,
                description,
                projectType,
                projectInterpreter,
                monitor,
                additionalArgsToConfigProject);
          }
        };

    // run the operation to create a new project
    try {
      getContainer().run(true, true, op);
    } catch (InterruptedException e) {
      return null;
    } catch (InvocationTargetException e) {
      Throwable t = e.getTargetException();
      if (t instanceof CoreException) {
        if (((CoreException) t).getStatus().getCode() == IResourceStatus.CASE_VARIANT_EXISTS) {
          MessageDialog.openError(
              getShell(),
              "Unable to create project",
              "Another project with the same name (and different case) already exists.");
        } else {
          ErrorDialog.openError(
              getShell(), "Unable to create project", null, ((CoreException) t).getStatus());
        }
      } else {
        // Unexpected runtime exceptions and errors may still occur.
        PydevPlugin.log(IStatus.ERROR, t.toString(), t);
        MessageDialog.openError(getShell(), "Unable to create project", t.getMessage());
      }
      return null;
    }

    return newProjectHandle;
  }
  public static void updateProjectReferences(
      IIncludePathEntry[] newEntries,
      IIncludePathEntry[] oldEntries,
      final IProject project,
      SubProgressMonitor monitor) {
    try {
      boolean changedReferences = false;
      final IProjectDescription projectDescription = project.getDescription();
      List<IProject> referenced = new ArrayList<IProject>();
      List<String> referencedNames = new ArrayList<String>();
      IProject[] referencedProjects = projectDescription.getReferencedProjects();
      for (IProject refProject : referencedProjects) {
        referenced.add(refProject);
        referencedNames.add(refProject.getName());
      }

      for (IIncludePathEntry oldEntry : oldEntries) {
        if (oldEntry.getEntryKind() == IIncludePathEntry.IPE_PROJECT) {
          String projectName = oldEntry.getPath().lastSegment();
          if (!containsProject(newEntries, projectName)) {
            if (((IncludePathEntry) oldEntry).createdReference) {
              int index = referencedNames.indexOf(projectName);
              if (index >= 0) {
                changedReferences = true;
                referencedNames.remove(index);
                referenced.remove(index);
              }
            }
          }
        }
      }

      for (IIncludePathEntry newEntry : newEntries) {
        if (newEntry.getEntryKind() == IIncludePathEntry.IPE_PROJECT) {
          String projectName = newEntry.getPath().lastSegment();
          if (!containsProject(oldEntries, projectName)) {
            if (!referencedNames.contains(projectName)) {
              changedReferences = true;
              ((IncludePathEntry) newEntry).createdReference = true;
              referenced.add(ResourcesPlugin.getWorkspace().getRoot().getProject(projectName));
              referencedNames.add(projectName);
            }
          }
        }
      }
      if (changedReferences) {
        IProject[] referenceProjects =
            (IProject[]) referenced.toArray(new IProject[referenced.size()]);
        projectDescription.setReferencedProjects(referenceProjects);
        WorkspaceJob job =
            new WorkspaceJob(CoreMessages.getString("IncludePathEntry_2")) // $NON-NLS-1$
            {
              public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
                project.setDescription(projectDescription, monitor);
                return Status.OK_STATUS;
              }
            };
        job.setRule(project.getParent());
        job.schedule();
      }
    } catch (CoreException e) {
      PHPEplPlugin.logError(e);
    }
  }
Пример #7
0
 /** Sets the referenced projects for project as being the javaProject passed. */
 protected void setProjectReference(
     IProgressMonitor monitor, IProject project, IJavaProject javaProject) throws CoreException {
   IProjectDescription description = project.getDescription();
   description.setReferencedProjects(new IProject[] {javaProject.getProject()});
   project.setDescription(description, monitor);
 }
  /**
   * Imports the selected projects.
   *
   * @param monitor
   * @throws CoreException
   */
  protected void doFinish(IProgressMonitor monitor) throws CoreException {

    monitor.beginTask("Importing the Service Assembly...", IProgressMonitor.UNKNOWN);
    List<SaImportBean> importBeans = this.page.getImportsBeans();

    List<IProject> suDependencies = new ArrayList<IProject>();
    List<MavenBean> suMavenBeans = new ArrayList<MavenBean>();
    for (SaImportBean saBean : importBeans) {

      // Deal with the SU projects first
      for (SuImportBean suBean : saBean.getSuBeans()) {

        if (!suBean.isToCreate()) continue;

        try {
          // Delete the project?
          if (suBean.isToOverwrite()) {
            IProject p =
                ResourcesPlugin.getWorkspace().getRoot().getProject(suBean.getProjectName());
            if (p.exists()) p.delete(true, monitor);
          }

          IProject project = null;
          URI pLocUri = null;
          if (!this.page.isAtDefaultLocation())
            pLocUri = new File(this.page.getProjectLocation(), suBean.getProjectName()).toURI();

          project =
              PetalsServicesProjectUtils.createSuProject(
                  suBean.getProjectName(),
                  pLocUri,
                  suBean.getComponentName(),
                  suBean.getComponentVersion(),
                  suBean.getSuType(),
                  false,
                  monitor);
          suDependencies.add(project);

          // Create the POM artifacts for the SA
          // Elements match what is set in
          // PetalsServicesProjectUtils#createPetalsSuProjectStructure().
          MavenBean suMavenBean = new MavenBean();
          suMavenBean.setArtifactId(project.getName());
          suMavenBeans.add(suMavenBean);

          // Copy the resources
          File jbiXmlFile = new File(suBean.getJbiXmlLocation());
          File targetFile = project.getLocation().append(PetalsConstants.LOC_JBI_FILE).toFile();
          if (!jbiXmlFile.exists()) throw new IOException("The jbi.xml does not exist.");

          IoUtils.moveFileRobustly(jbiXmlFile, targetFile, true);
          IFolder resFolder = project.getFolder(PetalsConstants.LOC_RES_FOLDER);
          File resFile = resFolder.getLocation().toFile();

          for (File fileToCopy : jbiXmlFile.getParentFile().getParentFile().listFiles()) {
            if (!"meta-inf".equalsIgnoreCase(fileToCopy.getName()))
              IoUtils.copyFileInDirectory(fileToCopy, resFile, false);
          }

          // Keep the project to show it at the end
          this.resourcesToSelect.add(project);
          monitor.worked(5);
          project.refreshLocal(IResource.DEPTH_INFINITE, monitor);

        } catch (Exception e) {
          PetalsServicesPlugin.log(e, IStatus.ERROR);
        }
      }

      // Deal with the SA project then
      if (saBean.isToCreate()) {

        // Delete the existing project?
        if (saBean.isToOverwrite()) {
          IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject(saBean.getProjectName());
          if (p.exists()) p.delete(true, monitor);
        }

        // Create the SA project
        URI pLocUri = null;
        if (!this.page.isAtDefaultLocation())
          pLocUri = new File(this.page.getProjectLocation(), saBean.getProjectName()).toURI();

        // Generate a basic POM
        MavenBean saMavenBean = new MavenBean();
        saMavenBean.setName(saBean.getProjectName());
        saMavenBean.setArtifactId(saMavenBean.getName());
        saMavenBean.dependencies.addAll(suMavenBeans);

        // Get the parent pom.xml
        MavenBean parentBean = MavenUtils.getPomParentElements();
        if (parentBean != null) {
          saMavenBean.setParentArtifactId(parentBean.getArtifactId());
          saMavenBean.setParentGroupId(parentBean.getGroupId());
          saMavenBean.setParentVersion(parentBean.getVersion());
        }

        try {
          // Create the project
          IProject saProject =
              PetalsServicesProjectUtils.createSaProject(
                  saBean.getProjectName(), pLocUri, saMavenBean, monitor);

          this.resourcesToSelect.add(saProject);

          // Copy the resources
          File jbiXmlFile = new File(saBean.getJbiXmlLocation());
          File targetFile = saProject.getLocation().append(PetalsConstants.LOC_JBI_FILE).toFile();
          if (!jbiXmlFile.exists()) throw new IOException("The jbi.xml does not exist.");

          IoUtils.moveFileRobustly(jbiXmlFile, targetFile, true);

          // Set the SU dependencies
          saProject.refreshLocal(IResource.DEPTH_INFINITE, monitor);
          IProjectDescription desc = saProject.getDescription();
          IProject[] projects = new IProject[suDependencies.size()];
          desc.setReferencedProjects(suDependencies.toArray(projects));
          saProject.setDescription(desc, null);

        } catch (CoreException e) {
          PetalsServicesPlugin.log(e, IStatus.ERROR);

        } catch (Exception e) {
          PetalsServicesPlugin.log(e, IStatus.ERROR);
        }
      }
    }

    monitor.worked(1);
  }