public void test_configurePackagesFilter() throws Exception {
   IProject project = mock(IProject.class);
   IProjectUtilities.configurePackagesFilter(project);
   verify(project)
       .createFilter(
           anyInt(), any(FileInfoMatcherDescription.class), anyInt(), any(IProgressMonitor.class));
 }
 public void test_newProjectDescription() throws Exception {
   MockWorkspaceRoot root = new MockWorkspaceRoot();
   IProjectDescription description =
       IProjectUtilities.newDartProjectDescription(root, "foo", null);
   assertNotNull(description);
   assertEquals("foo", description.getName());
   assertNull(description.getLocation());
 }
 @SuppressWarnings("deprecation")
 public void test_newProjectDescription_outsideWorkspace() throws Exception {
   MockWorkspaceRoot root = new MockWorkspaceRoot();
   IPath loc = new Path("/some/other/place");
   IProjectDescription description = IProjectUtilities.newDartProjectDescription(root, "foo", loc);
   assertNotNull(description);
   assertEquals("foo", description.getName());
   assertFalse(root.getLocation().isPrefixOf(description.getLocation()));
 }
  /**
   * Create a ProjectType.WEB project or a ProjectType.SERVER project.
   *
   * @param project
   * @param projectType
   * @throws CoreException
   */
  private IFile createProjectContent(
      IProject project, IFolder folder, String name, AbstractSample sampleContent)
      throws CoreException {
    IProjectUtilities.configurePackagesFilter(project);

    if (sampleContent == null) {
      return null;
    }

    IContainer container = project;

    if (folder != null) {
      container = folder;
    }

    return sampleContent.generateInto(container, name);
  }
Пример #5
0
  /**
   * Creates a new project resource.
   *
   * @param name the project name
   * @param newProjectHandle the project handle
   * @param projectType the type of project
   * @param location the location
   * @param runnableContext a context for executing the creation operation
   * @param shell the shell (for UI context)
   * @return the created project resource, or <code>null</code> if the project was not created
   */
  public static IProject createNewProject(
      String name,
      final IProject newProjectHandle,
      final ProjectType projectType,
      URI location,
      final IRunnableContext runnableContext,
      final Shell shell) {

    final IProjectDescription description = createProjectDescription(newProjectHandle, location);

    // create the new project operation
    IRunnableWithProgress op =
        new IRunnableWithProgress() {
          @Override
          public void run(IProgressMonitor monitor) throws InvocationTargetException {
            CreateProjectOperation op =
                new CreateProjectOperation(description, ResourceMessages.NewProject_windowTitle);
            try {
              IStatus status = op.execute(monitor, WorkspaceUndoUtil.getUIInfoAdapter(shell));

              if (status.isOK() && projectType != ProjectType.NONE) {
                createProjectContent(newProjectHandle, projectType);
              }
            } catch (ExecutionException e) {
              throw new InvocationTargetException(e);
            } catch (CoreException e) {
              throw new InvocationTargetException(e);
            }
          }
        };

    try {
      runnableContext.run(true, true, op);
    } catch (InterruptedException e) {
      return null;
    } catch (InvocationTargetException e) {
      Throwable t = e.getTargetException();
      if (t instanceof ExecutionException && t.getCause() instanceof CoreException) {
        CoreException cause = (CoreException) t.getCause();
        StatusAdapter status;
        if (cause.getStatus().getCode() == IResourceStatus.CASE_VARIANT_EXISTS) {
          status =
              new StatusAdapter(
                  StatusUtil.newStatus(
                      IStatus.WARNING,
                      NLS.bind(
                          ResourceMessages.NewProject_caseVariantExistsError,
                          newProjectHandle.getName()),
                      cause));
        } else {
          status =
              new StatusAdapter(
                  StatusUtil.newStatus(
                      cause.getStatus().getSeverity(),
                      ResourceMessages.NewProject_errorMessage,
                      cause));
        }
        status.setProperty(
            IStatusAdapterConstants.TITLE_PROPERTY, ResourceMessages.NewProject_errorMessage);
        StatusManager.getManager().handle(status, StatusManager.BLOCK);
      } else {
        StatusAdapter status =
            new StatusAdapter(
                new Status(
                    IStatus.WARNING,
                    IDEWorkbenchPlugin.IDE_WORKBENCH,
                    0,
                    NLS.bind(ResourceMessages.NewProject_internalError, t.getMessage()),
                    t));
        status.setProperty(
            IStatusAdapterConstants.TITLE_PROPERTY, ResourceMessages.NewProject_errorMessage);
        StatusManager.getManager().handle(status, StatusManager.LOG | StatusManager.BLOCK);
      }
      return null;
    }
    try {
      IProjectUtilities.configurePackagesFilter(newProjectHandle);
    } catch (CoreException e) {
      DartCore.logError("Could not set package filter on folder " + newProjectHandle.getName(), e);
    }

    return newProjectHandle;
  }