예제 #1
0
  /**
   * Write the version of the metadata into a known file overwriting any existing file contents.
   * Writing the version file isn't really crucial, so the function is silent about failure
   */
  private static void writeWorkspaceVersion() {
    if (WORKSPACE_CHECK_REFERENCE_BUNDLE_VERSION == null) {
      // no reference bundle installed, no check possible
      return;
    }

    Location instanceLoc = Platform.getInstanceLocation();
    if (instanceLoc == null || instanceLoc.isReadOnly()) {
      return;
    }

    File versionFile = getVersionFile(instanceLoc.getURL(), true);
    if (versionFile == null) {
      return;
    }

    OutputStream output = null;
    try {
      output = new FileOutputStream(versionFile);
      Properties props = new Properties();

      // write new property
      props.setProperty(
          WORKSPACE_CHECK_REFERENCE_BUNDLE_NAME,
          WORKSPACE_CHECK_REFERENCE_BUNDLE_VERSION.toString());

      // write legacy property with an incremented version,
      // so that pre-4.4 IDEs will also warn about the workspace
      props.setProperty(
          WORKSPACE_CHECK_REFERENCE_BUNDLE_NAME_LEGACY, WORKSPACE_CHECK_LEGACY_VERSION_INCREMENTED);

      props.store(output, null);
    } catch (IOException e) {
      IDEWorkbenchPlugin.log(
          "Could not write version file", //$NON-NLS-1$
          StatusUtil.newStatus(IStatus.ERROR, e.getMessage(), e));
    } finally {
      try {
        if (output != null) {
          output.close();
        }
      } catch (IOException e) {
        // do nothing
      }
    }
  }
예제 #2
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;
  }
  /**
   * 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.
   *
   * @return the created project resource, or <code>null</code> if the project was not created
   */
  private IProject createNewProject() {
    if (newProject != null) {
      return newProject;
    }

    // get a project handle
    final String projectName = page.getProjectName();
    IProject projectHandle = page.getProjectHandle(projectName);
    if (projectHandle.exists()) {
      String newProjectName = ProjectUtils.generateUniqueNameFrom(projectName);
      projectHandle = page.getProjectHandle(newProjectName);
    }
    final AbstractSample sampleContent = page.getCurrentSample();
    final IProject newProjectHandle = projectHandle;
    // get a project descriptor
    URI location = page.getLocationURI();

    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(getShell()));

              if (status.isOK()) {
                createdFile =
                    createProjectContent(newProjectHandle, null, projectName, sampleContent);
              }
            } catch (ExecutionException e) {
              throw new InvocationTargetException(e);
            } catch (CoreException e) {
              throw new InvocationTargetException(e);
            }
          }
        };

    try {
      getContainer().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;
    }

    newProject = newProjectHandle;

    return newProject;
  }