/**
   * 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 createNewProject() {
    if (newProject != null) {
      return newProject;
    }

    // get a project handle
    final IProject newProjectHandle = mainPage.getProjectHandle();
    // get a project descriptor
    URI location = null;
    if (!mainPage.useDefaults()) {
      location = mainPage.getLocationURI();
    }

    IProjectDescription description =
        ResourceUtil.getProjectDescription(
            mainPage.getLocationPath(), sample.getNatures(), ArrayUtil.NO_STRINGS);
    description.setName(newProjectHandle.getName());
    description.setLocationURI(location);

    try {
      if (sample.isRemote()) {
        cloneFromGit(sample.getLocation(), newProjectHandle, description);
      } else {
        doBasicCreateProject(newProjectHandle, description);

        // FIXME Move the logic for extracting/applying samples to IProjectSample! See
        // IProjectTemplate!
        ZipUtil.extract(
            new File(sample.getLocation()),
            newProjectHandle.getLocation(),
            ZipUtil.Conflict.PROMPT,
            new NullProgressMonitor());

        doPostProjectCreation(newProjectHandle);
      }
    } catch (IOException e) {
      return null;
    } catch (CoreException e) {
      return null;
    }

    newProject = newProjectHandle;
    return newProject;
  }
  protected void perfValidate(String filename, int iterations) throws Exception {
    // read in the file
    URL url =
        FileLocator.find(
            Platform.getBundle(JSCorePlugin.PLUGIN_ID),
            Path.fromPortableString("performance/" + filename),
            null);
    File file = ResourceUtil.resourcePathToFile(url);
    IFileStore fileStore = EFS.getStore(file.toURI());

    // Ok now actually validate the thing, the real work
    for (int i = 0; i < iterations; i++) {
      EditorTestHelper.joinBackgroundActivities();

      // Force a re-parse every time so we're comparing apples to apples for JSLint
      BuildContext context =
          new FileStoreBuildContext(fileStore) {
            @Override
            protected ParseResult parse(
                String contentType, IParseState parseState, WorkingParseResult working)
                throws Exception {
              if (reparseEveryTime()) {
                return new JSParser().parse(parseState);
              }
              return super.parse(contentType, parseState, working);
            }
          };
      // Don't measure reading in string...
      context.getContents();

      startMeasuring();
      validator.buildFile(context, null);
      stopMeasuring();
    }
    commitMeasurements();
    assertPerformance();
  }
Example #4
0
  private void readElement(IConfigurationElement element) {
    String elementName = element.getName();

    if (ELEMENT_CATEGORY.equals(elementName)) {
      String id = element.getAttribute(ATTR_ID);
      if (StringUtil.isEmpty(id)) {
        return;
      }
      String name = element.getAttribute(ATTR_NAME);
      if (StringUtil.isEmpty(name)) {
        return;
      }
      SampleCategory category = new SampleCategory(id, name, element);
      categories.put(id, category);

      String iconFile = element.getAttribute(ATTR_ICON);
      if (!StringUtil.isEmpty(iconFile)) {
        Bundle bundle = Platform.getBundle(element.getNamespaceIdentifier());
        URL url = bundle.getEntry(iconFile);
        category.setIconFile(ResourceUtil.resourcePathToString(url));
      }
    } else if (ELEMENT_SAMPLESINFO.equals(elementName)) {
      // either a local path or remote git url needs to be defined
      String path = null;
      boolean isRemote = false;

      Bundle bundle = Platform.getBundle(element.getNamespaceIdentifier());
      IConfigurationElement[] localPaths = element.getChildren(ELEMENT_LOCAL);
      if (localPaths.length > 0) {
        String location = localPaths[0].getAttribute(ATTR_LOCATION);
        URL url = bundle.getEntry(location);
        path = ResourceUtil.resourcePathToString(url);
      } else {
        IConfigurationElement[] remotePaths = element.getChildren(ELEMENT_REMOTE);
        if (remotePaths.length > 0) {
          path = remotePaths[0].getAttribute(ATTR_LOCATION);
          isRemote = true;
        }
      }
      if (path == null) {
        return;
      }

      String id = element.getAttribute(ATTR_ID);
      if (StringUtil.isEmpty(id)) {
        return;
      }
      String name = element.getAttribute(ATTR_NAME);
      if (StringUtil.isEmpty(name)) {
        return;
      }

      String categoryId = element.getAttribute(ATTR_CATEGORY);
      SampleCategory category = categories.get(categoryId);
      if (category == null) {
        categoryId = "default"; // $NON-NLS-1$
        category = categories.get(categoryId);
        if (category == null) {
          category =
              new SampleCategory(categoryId, Messages.SamplesManager_DefaultCategory_Name, element);
        }
      }

      List<SamplesReference> samples = sampleRefsByCategory.get(categoryId);
      if (samples == null) {
        samples = new ArrayList<SamplesReference>();
        sampleRefsByCategory.put(categoryId, samples);
      }

      String description = element.getAttribute(ATTR_DESCRIPTION);

      URL iconUrl = null;
      String iconPath = element.getAttribute(ATTR_ICON);
      if (!StringUtil.isEmpty(iconPath)) {
        URL url = bundle.getEntry(iconPath);
        try {
          iconUrl = FileLocator.toFileURL(url);
        } catch (IOException e) {
          IdeLog.logError(
              SamplesPlugin.getDefault(),
              MessageFormat.format(
                  "Unable to retrieve the icon at {0} for sample {1}",
                  iconPath, name), // $NON-NLS-1$
              e);
        }
      }
      Map<String, URL> iconUrls = new HashMap<String, URL>();
      iconUrls.put(SamplesReference.DEFAULT_ICON_KEY, iconUrl);

      SamplesReference samplesRef =
          new SamplesReference(category, id, name, path, isRemote, description, iconUrls, element);
      samples.add(samplesRef);
      samplesById.put(id, samplesRef);

      String infoFile = element.getAttribute(ATTR_INFOFILE);
      if (!StringUtil.isEmpty(infoFile)) {
        URL url = bundle.getEntry(infoFile);
        samplesRef.setInfoFile(ResourceUtil.resourcePathToString(url));
      }

      IConfigurationElement[] natures = element.getChildren(ELEMENT_NATURE);
      List<String> natureIds = new ArrayList<String>();
      String natureId;
      for (IConfigurationElement nature : natures) {
        natureId = nature.getAttribute(ATTR_ID);
        if (!StringUtil.isEmpty(natureId)) {
          natureIds.add(natureId);
        }
      }
      samplesRef.setNatures(natureIds.toArray(new String[natureIds.size()]));

      IConfigurationElement[] includes = element.getChildren(ELEMENT_INCLUDE);
      List<String> includePaths = new ArrayList<String>();
      String includePath;
      URL url;
      for (IConfigurationElement include : includes) {
        includePath = include.getAttribute(ATTR_PATH);
        if (!StringUtil.isEmpty(includePath)) {
          url = bundle.getEntry(includePath);
          path = ResourceUtil.resourcePathToString(url);
          if (path != null) {
            includePaths.add(path);
          }
        }
      }
      samplesRef.setIncludePaths(includePaths.toArray(new String[includePaths.size()]));
    }
  }