public void testExpandingResourcePath() throws Exception {
    URL dotProjectResource =
        getClass().getResource("/testData/projects/buckminster.test.build_a/.project"); // $NON-NLS
    assertNotNull("No resource found for .project file", dotProjectResource);
    dotProjectResource = FileLocator.toFileURL(dotProjectResource);
    assertNotNull("Unable to resolve .project resource into a file", dotProjectResource);
    File dotProjectFile = new File(dotProjectResource.toURI());

    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IProject project = workspace.getRoot().getProject("buckminster.test.build_a");
    if (!project.isOpen()) {
      IProgressMonitor monitor = new NullProgressMonitor();
      if (!project.exists()) {
        IProjectDescription projectDesc =
            workspace.loadProjectDescription(Path.fromOSString(dotProjectFile.getAbsolutePath()));
        project.create(projectDesc, monitor);
      }
      project.open(monitor);
    }

    assertTrue("No open project was found after materialization", project.isOpen());
    ExpandingProperties<String> properties = new ExpandingProperties<String>();
    String projectPath = properties.get("workspace_loc:buckminster.test.build_a");
    assertNotNull("workspace_loc:<project name> doesn't resolve existing project", projectPath);
    assertEquals(
        "Unexpected physical project location",
        new File(projectPath),
        dotProjectFile.getParentFile());
  }
Example #2
0
 /* (non-Javadoc)
  * @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
  */
 public boolean select(Viewer viewer, Object parent, Object element) {
   // always let through types, we only care about configs
   if (element instanceof ILaunchConfigurationType) {
     return true;
   }
   if (element instanceof ILaunchConfiguration) {
     try {
       ILaunchConfiguration config = (ILaunchConfiguration) element;
       IResource[] resources = config.getMappedResources();
       // if it has no mapping, it might not have migration delegate, so let it pass
       if (resources == null) {
         return true;
       }
       for (int i = 0; i < resources.length; i++) {
         IProject project = resources[i].getProject();
         // we don't want overlap with the deleted projects filter, so we need to allow projects
         // that don't exist through
         if (project != null && (project.isOpen() || !project.exists())) {
           return true;
         }
       }
     } catch (CoreException e) {
     }
   }
   return false;
 }
 /**
  * Replies if the project name is valid.
  *
  * <p>Copied from JDT.
  *
  * @return the validity state.
  */
 protected boolean isValidProjectName() {
   final String name = this.fProjText.getText();
   if (Strings.isNullOrEmpty(name)) {
     setErrorMessage(Messages.MainLaunchConfigurationTab_3);
     return false;
   }
   final IWorkspace workspace = ResourcesPlugin.getWorkspace();
   final IStatus status = workspace.validateName(name, IResource.PROJECT);
   if (status.isOK()) {
     final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(name);
     if (!project.exists()) {
       setErrorMessage(MessageFormat.format(Messages.MainLaunchConfigurationTab_4, name));
       return false;
     }
     if (!project.isOpen()) {
       setErrorMessage(MessageFormat.format(Messages.MainLaunchConfigurationTab_5, name));
       return false;
     }
   } else {
     setErrorMessage(
         MessageFormat.format(Messages.MainLaunchConfigurationTab_6, status.getMessage()));
     return false;
   }
   return true;
 }
  /**
   * Returns the active Model project associated with the specified resource, or <code>null</code>
   * if no Model project yet exists for the resource.
   *
   * @exception IllegalArgumentException if the given resource is not one of an IProject, IFolder,
   *     IRoot or IFile.
   * @see ModelWorkspace
   */
  @Override
  public ModelProject getModelProject(final IResource resource) {
    IProject project = resource.getProject();
    if (project == null || !project.isOpen()) return null;

    if (!DotProjectUtils.isModelerProject(project)) {
      return null;
    }

    // Only if the modelling project is open, is a partner model project created
    ModelProject modelProject = findModelProject(resource);
    if (modelProject == null) {
      switch (resource.getType()) {
        case IResource.FOLDER:
        case IResource.FILE:
        case IResource.PROJECT:
          return new ModelProjectImpl(project, this);
        case IResource.ROOT:
          return null;
        default:
          throw new IllegalArgumentException(
              ModelerCore.Util.getString(
                  "ModelWorkspaceImpl.Invalid_resource_for_ModelProject",
                  resource,
                  this)); //$NON-NLS-1$
      }
    }

    return modelProject;
  }
Example #5
0
  public static void addBuilderToProject(IProject project) {
    if (!project.isOpen()) return;

    IProjectDescription description;
    try {
      description = project.getDescription();
    } catch (CoreException e) {
      Log.log(e);
      return;
    }

    ICommand[] cmds = description.getBuildSpec();
    for (int j = 0; j < cmds.length; j++) if (cmds[j].getBuilderName().equals(BUILDER_ID)) return;

    // Associate builder with project.
    ICommand newCmd = description.newCommand();
    newCmd.setBuilderName(BUILDER_ID);
    List<ICommand> newCmds = new ArrayList<ICommand>();
    newCmds.addAll(Arrays.asList(cmds));
    newCmds.add(newCmd);
    description.setBuildSpec((ICommand[]) newCmds.toArray(new ICommand[newCmds.size()]));
    try {
      project.setDescription(description, null);
    } catch (CoreException e) {
      Log.log(e);
    }
  }
  /**
   * The default implementation recursively traverses the folders of the imported projects and
   * copies all contents into a feature folder with the imported projects name in {@code
   * newProject}. Can be overwritten by extending classes to accomodate {@link
   * IComposerExtensionBase Composers} needs.
   */
  protected void migrateProjects() {
    for (IProject project : projects) {
      IPath destinationPath = new Path(configurationData.sourcePath);

      assert newProject.getFolder(destinationPath).isAccessible()
          : DESTINATIONFOLDER_NOT_ACCESSIBLE_OR_WRONG_PATH;
      assert project.isOpen() : PROJECT + project.getName() + IS_NOT_OPEN_;

      IPath featureFolderPath =
          SPLMigrationUtils.setupFolder(
              newProject.getFolder(destinationPath).getFolder(project.getName()));

      try {
        migrateClassPathDependentContent(project, featureFolderPath);
      } catch (JavaModelException e) {
        e.printStackTrace();
      }

      //			try
      //			{
      //				if(project.hasNature(ANDROID_NATURE))
      //					copyProjectProperties(project, featureFolderPath);
      //			} catch (CoreException e)
      //			{
      //				e.printStackTrace();
      //			}
    }
  }
  public static void initialiseProject(IProject project) {
    if (!project.isOpen()) throw new IllegalArgumentException("Project is not open!");

    ModelManager manager = ModelManager.modelManager();
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    try {
      String property = project.getPersistentProperty(MODELS_KEY);
      if (property == null || property.trim().equals("")) return;
      for (String path : property.split(";")) {
        IResource resource = root.findMember(fromPortableString(path));
        if (!(resource instanceof IFile)) {
          continue;
        }

        //   				EventLogger.getInstance().logModelInitBegin(resource);
        ArchitectureModel model = manager.getArchitectureModel((IFile) resource);
        //   				model.addModelListener(new ModelEventListener(EventLogger.getInstance()));
        //   				EventLogger.getInstance().logModelInitEnd(resource);

        // This will crate an instance of problem manager...
        ModelProblemManager pm = problemManager(model);
        pm.attachToProject(project);
      }

    } catch (CoreException e) {
      e.printStackTrace();
    }
  }
  public static ESBArtifact getESBArtifactFromFile(
      IFile refactoredFile, String projectNatureFilter) {
    IProject esbProject = refactoredFile.getProject();
    try {
      esbProject.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());

      if (esbProject.isOpen() && esbProject.hasNature(projectNatureFilter)) {

        ESBProjectArtifact esbProjectArtifact = new ESBProjectArtifact();
        esbProjectArtifact.fromFile(esbProject.getFile("artifact.xml").getLocation().toFile());
        List<ESBArtifact> allESBArtifacts = esbProjectArtifact.getAllESBArtifacts();

        String originalFileRelativePath =
            FileUtils.getRelativePath(
                    esbProject.getLocation().toFile(), refactoredFile.getLocation().toFile())
                .replaceAll(Pattern.quote(File.separator), "/");

        for (ESBArtifact esbArtifact : allESBArtifacts) {
          if (esbArtifact.getFile().equals(originalFileRelativePath)) {
            return esbArtifact;
          }
        }
      }
    } catch (CoreException e) {
      log.error("Error while reading ESB Project", e);
    } catch (FactoryConfigurationError e) {
      log.error("Error while reading ESB Project", e);
    } catch (Exception e) {
      log.error("Error while reading ESB Project", e);
    }

    return null;
  }
  public static IFile LinkFile(String path) {
    IWorkspace ws = ResourcesPlugin.getWorkspace();
    IProject project = ws.getRoot().getProject("tmp");
    if (!project.exists())
      try {
        project.create(null);
      } catch (CoreException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    if (!project.isOpen())
      try {
        project.open(null);
      } catch (CoreException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    IPath location = new Path(path);
    IFile file = project.getFile(location.lastSegment());

    try {
      file.delete(true, null);
    } catch (CoreException e1) {
    }

    try {
      file.createLink(location, IResource.NONE, null);
    } catch (CoreException e) {
    }
    return file;
  }
  @Override
  protected void setVersionNumber(
      final IProject project, final String newVersion, String notManagedProjectNames) {
    if (project.isOpen()) {
      try {
        if (project.hasNature(Utils.FEATURE_NATURE)) { // for features
          try {
            final IFeatureProjectEditor editor = new FeatureProjectEditor(project);
            editor.init();
            editor.setVersion(newVersion);
            editor.save();
          } catch (final ParserConfigurationException e) {
            Activator.log.error(e);
            notManagedProjectNames += NLS.bind("- {0} \n", project.getName());
          } catch (final SAXException e) {
            Activator.log.error(e);
            notManagedProjectNames += NLS.bind("- {0} \n", project.getName());
          } catch (final IOException e) {
            Activator.log.error(e);
            notManagedProjectNames += NLS.bind("- {0} \n", project.getName());
          } catch (final Throwable e) {
            Activator.log.error(e);
            notManagedProjectNames += NLS.bind("- {0} \n", project.getName());
          }

        } else {
          notManagedProjectNames += NLS.bind("- {0} \n", project.getName());
        }
      } catch (final CoreException e) {
        Activator.log.error(e);
      }
    } else {
      notManagedProjectNames += NLS.bind("- {0} \n", project.getName());
    }
  }
  private void addProjectsSection(Composite parent) {
    Composite composite = createComposite(parent, 1, true);
    initializeDialogUnits(composite);

    Label label = new Label(composite, SWT.NONE);
    label.setText(PROJECTS_TEXT);

    projectList = CheckboxTableViewer.newCheckList(composite, SWT.BORDER);
    projectList.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
    projectList.setLabelProvider(
        new LabelProvider() {
          @Override
          public Image getImage(Object element) {
            return PlatformUI.getWorkbench()
                .getSharedImages()
                .getImage(IDE.SharedImages.IMG_OBJ_PROJECT);
          }

          @Override
          public String getText(Object element) {
            return ((IProject) element).getName();
          }
        });

    // Filter out closed projects!
    ArrayList<IProject> projects = new ArrayList<IProject>();
    for (IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
      if (project.isOpen()) projects.add(project);
    }
    projectList.setContentProvider(new ArrayContentProvider());
    projectList.setInput(projects);

    Dialog.applyDialogFont(composite);
  }
  public void decorate(Object element, IDecoration decoration) {
    if (!(element instanceof IResource)) return;
    IResource resource = (IResource) element;
    if (!resource.exists()) return;
    IProject project = resource.getProject();
    if (project == null) {
      Log.error(
          Messages.getString("ErrorDecorator.PROJECT_FOR")
              + resource.getName()
              + Messages.getString("ErrorDecorator.IS_NULL"),
          new Throwable()); //$NON-NLS-1$ //$NON-NLS-2$
      return;
    }
    try {
      if (!project.isOpen()) return;
      project.open(null);
      if (project.hasNature(LSLProjectNature.ID)) {
        LSLProjectNature nature = (LSLProjectNature) project.getNature(LSLProjectNature.ID);

        if (nature == null) return;

        IMarker[] m =
            resource.findMarkers("lslforge.problem", true, IResource.DEPTH_INFINITE); // $NON-NLS-1$

        if (m == null || m.length == 0) return;
      } else {
        return;
      }
    } catch (CoreException e) {
      Log.error("exception caught trying to determine project nature!", e); // $NON-NLS-1$
      return;
    }

    decoration.addOverlay(descriptor, IDecoration.BOTTOM_LEFT);
  }
  /**
   * Initializes the resource set using the repository content ; if the repository content is empty,
   * creates all the declared indexes.
   *
   * @throws CoreException it the resourceSet cannot be initialized
   */
  private void initializeResourceSet() throws CoreException {

    // We first get the project on which the repository is defined
    IProject project = workspaceConfig.getProject();
    if (!project.exists()) {
      project.create(null);
    }
    if (!project.isOpen()) {
      project.open(null);
    }
    IFolder folder = project.getFolder(workspaceConfig.getRepositoryRelativePath());
    // We created a WorkspaceRepositoryLoader using the indexPathList
    WorkspaceRepositoryLoader loader =
        new WorkspaceRepositoryLoader(this, this.getWorkspaceConfig().getIndexesPathList());
    // If the repository folder exists
    if (folder.exists()) {
      // We load the resourceSet
      loader.loadResourceSet();
    } else {
      // If the repository folder doesn't exist
      // We create it
      folder.create(IResource.NONE, true, null);
      // And use the RepositoryLoader to initialize the resource set with empty content
      loader.loadResourceSet();
    }
    isResourceSetLoaded = true;
  }
  private void stackTracingWasChanged(boolean enabled) {
    IPreferenceStore store = CxxTestPlugin.getDefault().getPreferenceStore();
    String driverFile = store.getString(CxxTestPlugin.CXXTEST_PREF_DRIVER_FILENAME);

    IExtraOptionsUpdater updater = CxxTestPlugin.getDefault().getExtraOptionsUpdater();

    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IProject[] projects = workspace.getRoot().getProjects();

    for (IProject project : projects) {
      if (!project.isOpen()) {
        continue;
      }

      try {
        if (project.hasNature(CxxTestPlugin.CXXTEST_NATURE)) {
          IFile driver = project.getFile(driverFile);

          if (driver != null) {
            driver.delete(true, null);
          }

          updater.updateOptions(project);
        }
      } catch (CoreException e) {
        e.printStackTrace();
      }
    }
  }
  /** {@inheritDoc} */
  @Override
  public void resourceChanged(IResourceChangeEvent pEvent) {

    if (IResourceChangeEvent.POST_CHANGE == pEvent.getType()) {
      // Extract all the additions among the changes
      IResourceDelta delta = pEvent.getDelta();
      IResourceDelta[] added = delta.getAffectedChildren();

      // In all the added resources, process the projects
      for (int i = 0, length = added.length; i < length; i++) {
        IResourceDelta addedi = added[i];

        // Get the project
        IResource resource = addedi.getResource();
        IProject project = resource.getProject();

        if (ProjectsManager.getProject(project.getName()) == null && project.isOpen()) {
          ProjectAdderJob job = new ProjectAdderJob(project);
          job.schedule();
        }
      }
    } else if (IResourceChangeEvent.PRE_DELETE == pEvent.getType()) {
      // detect UNO IDL project about to be deleted
      IResource removed = pEvent.getResource();
      if (ProjectsManager.getProject(removed.getName()) != null) {
        ProjectsManager.removeProject(removed.getName());
      }
    } else if (IResourceChangeEvent.PRE_CLOSE == pEvent.getType()) {
      IResource res = pEvent.getResource();
      if (res != null && ProjectsManager.getProject(res.getName()) != null) {
        // Project about to be closed: remove for the available uno projects
        ProjectsManager.removeProject(res.getName());
      }
    }
  }
  @Override
  protected IStatus run(IProgressMonitor monitor) {
    monitor.beginTask("", IProgressMonitor.UNKNOWN); // $NON-NLS-1$
    while (true) {
      ICProject cproject = fManager.getNextProject();
      if (cproject == null) return Status.OK_STATUS;

      final IProject project = cproject.getProject();
      monitor.setTaskName(project.getName());
      if (!project.isOpen()) {
        if (fManager.fTraceIndexerSetup)
          System.out.println("Indexer: Project is not open: " + project.getName()); // $NON-NLS-1$
      } else if (fManager.postponeSetup(cproject)) {
        if (fManager.fTraceIndexerSetup)
          System.out.println("Indexer: Setup is postponed: " + project.getName()); // $NON-NLS-1$
      } else {
        syncronizeProjectSettings(project, new SubProgressMonitor(monitor, 1));
        if (fManager.getIndexer(cproject) == null) {
          try {
            fManager.createIndexer(cproject, new SubProgressMonitor(monitor, 99));
          } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            return Status.CANCEL_STATUS;
          }
        } else if (fManager.fTraceIndexerSetup) {
          System.out.println(
              "Indexer: No action, indexer already exists: " + project.getName()); // $NON-NLS-1$
        }
      }
    }
  }
Example #17
0
 /**
  * Verify the following things about the project: - is a valid project name given - does the
  * project exist - is the project open - is the project a C/C++ project
  */
 public static ICProject verifyCProject(ILaunchConfiguration configuration) throws CoreException {
   String name = getProjectName(configuration);
   if (name == null) {
     abort(
         LaunchMessages.getString("AbstractCLaunchDelegate.C_Project_not_specified"),
         null, //$NON-NLS-1$
         ICDTLaunchConfigurationConstants.ERR_UNSPECIFIED_PROJECT);
     return null;
   }
   ICProject cproject = getCProject(configuration);
   if (cproject == null && name.length() > 0) {
     IProject proj = ResourcesPlugin.getWorkspace().getRoot().getProject(name);
     if (!proj.exists()) {
       abort(
           LaunchMessages.getFormattedString(
               "AbstractCLaunchDelegate.Project_NAME_does_not_exist", name),
           null, //$NON-NLS-1$
           ICDTLaunchConfigurationConstants.ERR_NOT_A_C_PROJECT);
     } else if (!proj.isOpen()) {
       abort(
           LaunchMessages.getFormattedString(
               "AbstractCLaunchDelegate.Project_NAME_is_closed", name),
           null, //$NON-NLS-1$
           ICDTLaunchConfigurationConstants.ERR_NOT_A_C_PROJECT);
     }
     abort(
         LaunchMessages.getString("AbstractCLaunchDelegate.Not_a_C_CPP_project"),
         null, //$NON-NLS-1$
         ICDTLaunchConfigurationConstants.ERR_NOT_A_C_PROJECT);
   }
   return cproject;
 }
  private IStatus validateProject() {
    hostPageProject = null;

    String str = projectField.getText().trim();
    if (str.length() == 0) {
      return Util.newErrorStatus("Enter the project name");
    }

    IPath path = new Path(str);
    if (path.segmentCount() != 1) {
      return Util.newErrorStatus("Invalid project path");
    }

    IProject project = Util.getWorkspaceRoot().getProject(str);
    if (!project.exists()) {
      return Util.newErrorStatus("Project does not exist");
    }

    if (!project.isOpen()) {
      return Util.newErrorStatus("Project is not open");
    }

    if (!GWTNature.isGWTProject(project)) {
      return Util.newErrorStatus("Project is not a GWT project");
    }

    hostPageProject = project;
    return Status.OK_STATUS;
  }
Example #19
0
  /**
   * {@inheritDoc}
   *
   * @see
   *     org.vimide.core.servlet.VimideHttpServlet#doGet(org.vimide.core.servlet.VimideHttpServletRequest,
   *     org.vimide.core.servlet.VimideHttpServletResponse)
   */
  @Override
  protected void doGet(VimideHttpServletRequest req, VimideHttpServletResponse resp)
      throws ServletException, IOException {
    final List<Map<String, Object>> results = Lists.newArrayList();

    for (IProject project : getProjects()) {
      Map<String, Object> info = Maps.newHashMap();
      info.put("name", project.getName());
      info.put("path", project.getLocation().toOSString());

      if (project.isOpen()) {
        try {
          String[] aliases =
              NaturesMapping.getNatureAliases(project.getDescription().getNatureIds());
          if (null == aliases || aliases.length == 0) aliases = new String[] {"none"};
          info.put("natures", aliases);
        } catch (final Exception e) {
          info.put("natures", ArrayUtils.EMPTY_STRING_ARRAY);
        }
      }

      results.add(info);
    }

    resp.writeAsJson(results);
  }
  public static void addNature(IProject project) {

    if (!project.isOpen()) {
      return;
    }

    // Get the description
    IProjectDescription description;
    try {
      description = project.getDescription();
    } catch (CoreException e) {
      JsonLog.logError("Error get project description: ", e);
      return;
    }

    List<String> newIds = new ArrayList<String>();
    String[] natureIds = description.getNatureIds();
    for (String natureId : natureIds) {
      if (natureId.equals(NATURE_ID)) {
        return;
      }
    }

    newIds.addAll(Arrays.asList(natureIds));
    newIds.add(NATURE_ID);

    // Save description
    description.setNatureIds(newIds.toArray(new String[newIds.size()]));
    try {
      project.setDescription(description, null);
    } catch (CoreException e) {
      JsonLog.logError("Error set project description: ", e);
    }
  }
  private boolean checkStatus() {
    String container = getContainerName();
    if (CoreStringUtil.isEmpty(container)) {
      currentStatus = STATUS_NO_LOCATION;
      return false;
    }
    IProject project = getTargetProject();
    if (project == null) {
      currentStatus = STATUS_NO_LOCATION;
      return false;
    } else if (!project.isOpen()) {
      currentStatus = STATUS_CLOSED_PROJECT;
      return false;
    } else {
      try {
        if (project.getNature(PluginConstants.MODEL_PROJECT_NATURE_ID) == null) {
          currentStatus = STATUS_NO_PROJECT_NATURE;
          return false;
        }
      } catch (CoreException ex) {
        currentStatus = STATUS_NO_PROJECT_NATURE;
        return false;
      }
    }

    String fileText = getFileText();
    if (fileText.length() == 0) {
      currentStatus = STATUS_NO_FILENAME;
      return false;
    }
    fileNameMessage = ModelUtilities.validateModelName(fileText, fileExtension);
    if (fileNameMessage != null) {
      currentStatus = STATUS_BAD_FILENAME;
      return false;
    }
    String fileName = getFileName();
    filePath = new Path(container).append(fileName);
    if (ResourcesPlugin.getWorkspace().getRoot().exists(filePath)) {
      currentStatus = STATUS_FILE_EXISTS;
      return false;
    }
    if (metamodelCombo.getSelectionIndex() < 1) {
      currentStatus = STATUS_NO_METAMODEL;
      return false;
    }
    if (modelTypesCombo.getSelectionIndex() < 1) {
      currentStatus = STATUS_NO_TYPE;
      return false;
    }

    if (metamodelCombo.getSelectionIndex() == 6) {
      // WARN USER OF EXTENSION MODEL DEPRECATION
      currentStatus = STATUS_DEPRECATED_EXTENSION_METAMODEL;
      return true;
    }
    currentStatus = STATUS_OK;
    return true;
  }
  public static boolean hasNature(IProject project) {

    try {
      return project.isOpen() && project.hasNature(NATURE_ID);
    } catch (CoreException e) {
      JsonLog.logError("Error determining if project has nature.: ", e);
      return false;
    }
  }
Example #23
0
 /**
  * Clean all.
  *
  * <p>By default this will simply call a clean project on each open project. Subclasses should
  * override and either add more function to clear out non-project data and then call super. Or
  * if they can handle all of the projects in a faster way, then can completely handle this.
  *
  * @since 1.1.0
  */
 protected void cleanAll() {
   IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
   for (int i = 0; i < projects.length; i++) {
     IProject project = projects[i];
     if (project.isOpen()) {
       cleanProject(project);
     }
   }
 }
 private void handleExistingProjects() {
   ArrayList<Object> result = new ArrayList<>();
   for (int i = 0; i < fModels.length; i++) {
     String id = fModels[i].getPluginBase().getId();
     IProject project = (IProject) PDEPlugin.getWorkspace().getRoot().findMember(id);
     if (project != null && project.isOpen() && WorkspaceModelManager.isPluginProject(project)) {
       result.add(fModels[i]);
     }
   }
   handleSetImportSelection(result);
 }
Example #25
0
  /**
   * Create a plain Eclipse project.
   *
   * @param projectName
   * @return the project handle
   * @throws CoreException if project could not be created
   */
  public static IProject createProject(String projectName) throws CoreException {
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IProject project = root.getProject(projectName);
    if (!project.exists()) project.create(NULL_MONITOR);
    else project.refreshLocal(IResource.DEPTH_INFINITE, null);

    if (!project.isOpen()) project.open(NULL_MONITOR);

    resourcesCreated.add(project);
    return project;
  }
 /**
  * Creates a project using the given name.
  *
  * @param projectName the project name
  * @param monitor the progress monitor
  * @return the newly created project or the existing one if present
  * @throws CoreException if there is an issue creating the project
  */
 public static IProject createProject(final String projectName, IProgressMonitor monitor)
     throws CoreException {
   IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
   if (!project.exists()) {
     project.create(monitor);
     project.open(monitor);
   }
   if (!project.isOpen()) {
     project.open(monitor);
   }
   return project;
 }
Example #27
0
  public void testSwitchBranchClosesOpenProjectsThatDontExistOnDestinationBranch()
      throws Throwable {
    testAddBranch();

    assertCurrentBranch("master");
    assertSwitchBranch("my_new_branch");

    GitIndex index = getRepo().index();
    assertTrue("Expected changed file listing to be empty", index.changedFiles().isEmpty());

    // Create a new project on this branch!
    String projectName = "project_on_branch" + System.currentTimeMillis();

    File projectDir = getRepo().workingDirectory().append(projectName).toFile();
    projectDir.mkdirs();

    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IProject project = workspace.getRoot().getProject(projectName);

    IProjectDescription description = workspace.newProjectDescription(projectName);
    description.setLocation(getRepo().workingDirectory().append(projectName));
    project.create(description, new NullProgressMonitor());

    // Commit the project on this branch!
    index.refresh(new NullProgressMonitor());

    // Now there should be a single file that's been changed!
    List<ChangedFile> changed = index.changedFiles();
    assertEquals(
        "repository changed file listing should contain one entry for new .project file, but does not",
        1,
        changed.size());

    // Make sure it's shown as having unstaged changes only and is NEW
    assertNewUnstagedFile(changed.get(0));

    // Stage the new file
    assertStageFiles(index, changed);
    assertNewStagedFile(changed.get(0));

    assertCommit(index, "Initial commit");

    assertSwitchBranch("master");

    // Assert that the new project is closed!
    project = workspace.getRoot().getProject(projectName);
    assertFalse(project.isOpen());

    // assert that there's no .project file stranded there
    File dotProject = new File(projectDir, IProjectDescription.DESCRIPTION_FILE_NAME);
    assertFalse(dotProject.exists());
  }
Example #28
0
  /**
   * This private operation configures the project area for the Core. It uses the Eclipse Resources
   * Plugin and behaves differently based on the value of the osgi.instance.area system property.
   * <!-- end-UML-doc -->
   *
   * @return True if the setup operation was successful and false otherwise.
   */
  private boolean setupProjectLocation() {

    // Local Declarations
    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    IProject project = null;
    boolean status = true;
    String defaultProjectName = "itemDB";

    // Print some diagnostic information
    if (Platform.getInstanceLocation() != null) {
      logger.info(
          "ICore Message: Default workspace location is "
              + Platform.getInstanceLocation().getURL().toString());
    }
    // Create the project space for the *default* user. This will have to
    // change to something more efficient and better managed when multi-user
    // support is added.
    try {
      // Get the project handle
      project = workspaceRoot.getProject(defaultProjectName);
      // If the project does not exist, create it
      if (!project.exists()) {
        // Create the project description
        IProjectDescription desc =
            ResourcesPlugin.getWorkspace().newProjectDescription(defaultProjectName);
        // Create the project
        project.create(desc, null);
      }

      // Open the project if it is not already open. Note that this is not
      // an "else if" because it always needs to be checked.
      if (project.exists() && !project.isOpen()) {
        project.open(null);
        // Always refresh the project too in case users manipulated the
        // files.
        project.refreshLocal(IResource.DEPTH_INFINITE, null);
      }
      // Add the project to the master table
      projectTable.put("defaultUser", project);
      itemDBProject = project;
    } catch (CoreException e) {
      // Catch for creating the project
      logger.error(getClass().getName() + " Exception!", e);
      status = false;
    }

    // Load any SerializedItems that are stored in the default directory
    if (status) {
      status = loadDefaultAreaItems();
    }
    return status;
  }
Example #29
0
 /**
  * @param project the project we want to know about (if it is null, null is returned)
  * @return the python nature for a project (or null if it does not exist for the project)
  * @note: it's synchronized because more than 1 place could call getPythonNature at the same time
  *     and more than one nature ended up being created from project.getNature().
  */
 public static synchronized PythonNature getPythonNature(IProject project) {
   if (project != null && project.isOpen()) {
     try {
       IProjectNature n = project.getNature(PYTHON_NATURE_ID);
       if (n instanceof PythonNature) {
         return (PythonNature) n;
       }
     } catch (CoreException e) {
       Log.logInfo(e);
     }
   }
   return null;
 }
 /**
  * Creates a project with the given name in the workspace and returns it. If a project with the
  * given name exists, it is refreshed and opened (if closed) and returned
  *
  * @param projectName
  * @param monitor
  * @return a project with the given name
  * @throws CoreException
  */
 public static IProject createProject(String projectName, IProgressMonitor monitor)
     throws CoreException {
   IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
   IProject project = root.getProject(projectName);
   if (!project.exists()) {
     project.create(monitor);
   } else {
     project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
   }
   if (!project.isOpen()) {
     project.open(monitor);
   }
   return project;
 }