@Before
  public void setUp() throws Exception {

    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();

    FileUtils.mkdir(new File(root.getLocation().toFile(), "Sub"), true);
    gitDir = new File(new File(root.getLocation().toFile(), "Sub"), Constants.DOT_GIT);

    repository = FileRepositoryBuilder.create(gitDir);
    repository.create();

    project = root.getProject(TEST_PROJECT);
    project.create(null);
    project.open(null);
    IProjectDescription description = project.getDescription();
    description.setLocation(root.getLocation().append(TEST_PROJECT_LOC));
    project.move(description, IResource.FORCE, null);

    project2 = root.getProject(TEST_PROJECT2);
    project2.create(null);
    project2.open(null);
    gitDir2 = new File(project2.getLocation().toFile().getAbsoluteFile(), Constants.DOT_GIT);
    repository2 = FileRepositoryBuilder.create(gitDir2);
    repository2.create();

    RepositoryMapping mapping = RepositoryMapping.create(project, gitDir);
    RepositoryMapping mapping2 = RepositoryMapping.create(project2, gitDir2);

    GitProjectData projectData = new GitProjectData(project);
    GitProjectData projectData2 = new GitProjectData(project2);
    projectData.setRepositoryMappings(Collections.singletonList(mapping));
    projectData.store();
    projectData2.setRepositoryMappings(Collections.singletonList(mapping2));
    projectData2.store();
    GitProjectData.add(project, projectData);
    GitProjectData.add(project2, projectData2);

    RepositoryProvider.map(project, GitProvider.class.getName());
    RepositoryProvider.map(project2, GitProvider.class.getName());

    JGitTestUtil.write(
        new File(repository.getWorkTree(), TEST_PROJECT + "/" + TEST_FILE), "Some data");
    JGitTestUtil.write(new File(repository2.getWorkTree(), TEST_FILE2), "Some other data");
    project.refreshLocal(IResource.DEPTH_INFINITE, null);
    project2.refreshLocal(IResource.DEPTH_INFINITE, null);
    git = new Git(repository);
    git.add().addFilepattern(".").call();
    git.commit().setMessage("Initial commit").call();

    git = new Git(repository2);
    git.add().addFilepattern(".").call();
    git.commit().setMessage("Initial commit").call();
    git.branchRename().setNewName("main").call();
  }
  /**
   * 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 createExternalSourceArchivesProject(IProject project, IProgressMonitor monitor)
     throws CoreException {
   IProjectDescription desc = project.getWorkspace().newProjectDescription(project.getName());
   IPath stateLocation = CeylonPlugin.getInstance().getStateLocation();
   desc.setLocation(stateLocation.append(EXTERNAL_PROJECT_NAME));
   project.create(desc, IResource.HIDDEN, monitor);
 }
  /**
   * Creates a project resource given the project handle and description.
   *
   * @param description the project description to create a project resource for
   * @param projectHandle the project handle to create a project resource for
   * @param monitor the progress monitor to show visual progress with
   * @exception CoreException if the operation fails
   * @exception OperationCanceledException if the operation is canceled
   */
  private void createProject(
      IProjectDescription description, IProject projectHandle, IProgressMonitor monitor)
      throws CoreException, OperationCanceledException {

    projectHandle.create(description, new SubProgressMonitor(monitor, 1000));

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

    // projectHandle.open(IResource.BACKGROUND_REFRESH, new SubProgressMonitor(monitor, 1000));
    projectHandle.open(IResource.NONE, new SubProgressMonitor(monitor, 1000));

    // Create the corresponding ModelProject
    ModelWorkspace mWorkspace =
        ModelWorkspaceManager.getModelWorkspaceManager().getModelWorkspace();
    ModelProject mProject = new ModelProjectImpl(projectHandle, mWorkspace);

    // Create the corresponding ModelFolders and ModelResources
    List iResources = new ArrayList();
    addMembersToList(projectHandle, iResources);
    for (Iterator iter = iResources.iterator(); iter.hasNext(); ) {
      IResource iResource = (IResource) iter.next();
      ModelWorkspaceManager.create(iResource, mProject);
    }
  }
 protected IProject createProject() throws CoreException {
   IWorkspace workspace = ResourcesPlugin.getWorkspace();
   IProject project = workspace.getRoot().getProject(PROJECT_NAME);
   project.create(new NullProgressMonitor());
   project.open(new NullProgressMonitor());
   return project;
 }
  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 boolean performFinish() {
    try {
      // TODO Auto-generated method stub
      // See http://www.programcreek.com/2011/05/eclipse-jdt-tutorial-java-model/
      //

      IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
      // Crea un nuevo projecto
      final IProject project = root.getProject(page.getProjectName());
      project.create(null);
      project.open(null);

      // Map props = project.getPersistentProperties();

      /*			//Crear el proyecto Java
      			IProjectDescription description = project.getDescription();
      			//description.setLocation(page.getLocationPath());
      			//Associate nature
      			description.setNatureIds(new String[]{JavaCore.NATURE_ID});
      			project.setDescription(description, null);
      			IJavaProject javaProject = JavaCore.create(project);
      */
      IFolder folder = project.getFolder("models");
      folder.create(true, true, null);
      folder = project.getFolder("src-gen");
      folder.create(true, true, null);

      return true;
    } catch (CoreException e) {
      // TODO Auto-generated catch block
      MessageDialog.openError(getShell(), "Error", e.getMessage());
      return false;
    }
  }
Example #8
0
  public void testResourceDelta() throws CoreException {
    IProject[] prjs = new IProject[] {fProject};
    fProject.create(new NullProgressMonitor());
    fProject.open(new NullProgressMonitor());

    IFile[] files = ResourceLookup.findFilesByName(new Path("abc.h"), prjs, true);
    assertEquals(0, files.length);

    IFolder f1 = createFolder(fProject, "folder1");
    createFolder(fProject, "folder2");
    IFile f2 = createFile(fProject, "abc.h");
    files = ResourceLookup.findFilesByName(new Path("abc.h"), prjs, true);
    assertEquals(1, files.length);

    createFile(fProject, "folder1/abc.h");
    files = ResourceLookup.findFilesByName(new Path("abc.h"), prjs, true);
    assertEquals(2, files.length);

    createFile(fProject, "folder2/abC.h");
    files = ResourceLookup.findFilesByName(new Path("abc.h"), prjs, true);
    assertEquals(3, files.length);

    f1.delete(true, new NullProgressMonitor());
    files = ResourceLookup.findFilesByName(new Path("abc.h"), prjs, true);
    assertEquals(2, files.length);

    f2.delete(true, new NullProgressMonitor());
    files = ResourceLookup.findFilesByName(new Path("abc.h"), prjs, true);
    assertEquals(1, files.length);
  }
Example #9
0
  public void testFindFilesByLocation() throws Exception {
    fProject.create(new NullProgressMonitor());
    fProject.open(new NullProgressMonitor());
    createFolder(fProject, "folder1");
    createFolder(fProject, "folder2");
    IFile file = createFile(fProject, "abc.h");
    createFile(fProject, "folder1/abc.h");
    createFile(fProject, "folder2/abC.h");

    URI uri = file.getLocationURI();
    IPath path = file.getLocation();
    IFile[] files = ResourceLookup.findFilesForLocationURI(uri);
    assertEquals(1, files.length);
    files = ResourceLookup.findFilesForLocation(path);
    assertEquals(1, files.length);

    if (new File("a").equals(new File("A"))) {
      URI upperCase =
          new URI(uri.getScheme(), uri.getSchemeSpecificPart().toUpperCase(), uri.getFragment());
      IPath upperCasePath = new Path(path.toString().toUpperCase());
      files = ResourceLookup.findFilesForLocationURI(upperCase);
      assertEquals(1, files.length);
      files = ResourceLookup.findFilesForLocation(upperCasePath);
      assertEquals(1, files.length);
    }
  }
  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());
  }
  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;
  }
 protected IProject getNamedTestProject(String name) throws CoreException {
   IProject target = getWorkspace().getRoot().getProject(name);
   if (!target.exists()) {
     target.create(null);
     target.open(null);
   }
   assertExistsInFileSystem(target);
   return target;
 }
Example #13
0
  public static IFile getDataFileForInput(final IEditorInput input) {
    final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();

    if (input instanceof ToscaDiagramEditorInput) {
      final ToscaDiagramEditorInput tdei = (ToscaDiagramEditorInput) input;

      return tdei.getToscaFile();
    } else if (input instanceof DiagramEditorInput) {
      final DiagramEditorInput dei = (DiagramEditorInput) input;

      IPath path = new Path(dei.getUri().trimFragment().toPlatformString(true));

      return recreateDataFile(path);
    } else if (input instanceof FileEditorInput) {
      final FileEditorInput fei = (FileEditorInput) input;

      return fei.getFile();
    } else if (input instanceof IURIEditorInput) {
      // opened externally to Eclipse
      final IURIEditorInput uei = (IURIEditorInput) input;
      final java.net.URI uri = uei.getURI();
      final String path = uri.getPath();

      try {
        final IProject importProject = root.getProject("import"); // $NON-NLS-1$
        if (!importProject.exists()) {
          importProject.create(null);
        }

        importProject.open(null);

        final InputStream is = new FileInputStream(path);

        final String fileName;
        if (path.contains("/")) { // $NON-NLS-1$
          fileName = path.substring(path.lastIndexOf("/") + 1); // $NON-NLS-1$
        } else {
          fileName = path.substring(path.lastIndexOf("\\") + 1); // $NON-NLS-1$
        }

        IFile importFile = importProject.getFile(fileName);
        if (importFile.exists()) {
          importFile.delete(true, null);
        }

        importFile.create(is, true, null);

        return importProject.getFile(fileName);
      } catch (CoreException exception) {
        exception.printStackTrace();
      } catch (FileNotFoundException exception) {
        exception.printStackTrace();
      }
    }

    return null;
  }
 @BeforeClass
 public static void createProfileApplicationProject() throws CoreException {
   IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
   IProject project = workspaceRoot.getProject(TRACING_PA_PROJECT);
   if (!project.exists()) {
     project.create(null);
     project.open(null);
   }
 }
Example #15
0
  @Test
  public void testDS5175() {
    try {
      IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("someProject");
      project.create(null);
      project.open(null);
      new OfsProjectInitializer().updateConfiguration(project, null);
      IOfsProject proj = OfsCore.getOfsProject(project);
      IOfsProject ofsProject = OfsCore.getOfsProjectManager().getOfsProject(project);
      ofsProjects.put("someProject", ofsProject);
      copyResourceInModelsProject(
          proj, C_FILE, H_FILE, CPP_FILE, CS_FILE, SVC_FILE, CONFIG_FILE, B_FILE);

      IFile tempFile = getProject("someProject").getFile(C_FILE);
      IEditorPart part = openDefaultEditor(tempFile);
      Assert.assertNotNull(part);

      tempFile = getProject("someProject").getFile(B_FILE);
      part = openDefaultEditor(tempFile);
      Assert.assertNotNull(part);
      part = null;
      tempFile = null;

      tempFile = getProject("someProject").getFile(CPP_FILE);
      part = openDefaultEditor(tempFile);
      Assert.assertNotNull(part);
      part = null;
      tempFile = null;

      tempFile = getProject("someProject").getFile(CONFIG_FILE);
      part = openDefaultEditor(tempFile);
      Assert.assertNotNull(part);
      part = null;
      tempFile = null;

      tempFile = getProject("someProject").getFile(CS_FILE);
      part = openDefaultEditor(tempFile);
      Assert.assertNotNull(part);
      part = null;
      tempFile = null;

      tempFile = getProject("someProject").getFile(SVC_FILE);
      part = openDefaultEditor(tempFile);
      Assert.assertNotNull(part);
      part = null;
      tempFile = null;

      tempFile = getProject("someProject").getFile(H_FILE);
      part = openDefaultEditor(tempFile);
      Assert.assertNotNull(part);
      part = null;
      tempFile = null;
    } catch (CoreException e) {
      e.printStackTrace();
    }
  }
 /** Creates a pydev_unit_test_project to be used in the tests */
 protected IProject createProject(IProgressMonitor monitor, String projectName)
     throws CoreException {
   IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
   if (project.exists()) {
     project.delete(true, monitor);
   }
   project.create(monitor);
   project.open(monitor);
   return project;
 }
Example #17
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;
  }
Example #18
0
 private IProject createProject()
     throws CoreException, InvocationTargetException, InterruptedException {
   IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
   IProject project = root.getProject(projectName);
   project.create(null);
   project.open(null);
   if (addDebriefSamplesButton.getSelection()) {
     importSamples(project);
   }
   return project;
 }
  private void createProject(String projName) {
    IProjectDescription description =
        ResourcesPlugin.getWorkspace().newProjectDescription(projName);

    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projName);
    try {
      project.create(description, new NullProgressMonitor());
      project.open(new NullProgressMonitor());
    } catch (CoreException e) {
      e.printStackTrace();
    }
  }
 /**
  * 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 #21
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 #22
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 #23
0
  public static IJavaProject createJavaProject(final String projectName, String[] projectNatures) {

    IProject project = null;
    IJavaProject javaProject = null;
    try {
      IWorkspace workspace = ResourcesPlugin.getWorkspace();
      project = workspace.getRoot().getProject(projectName);
      deleteProject(project);

      javaProject = JavaCore.create(project);
      IProjectDescription projectDescription =
          ResourcesPlugin.getWorkspace().newProjectDescription(projectName);
      project.create(projectDescription, null);
      List<IClasspathEntry> classpathEntries = new ArrayList<IClasspathEntry>();
      projectDescription.setNatureIds(projectNatures);

      final ICommand java = projectDescription.newCommand();
      java.setBuilderName(JavaCore.BUILDER_ID);

      final ICommand manifest = projectDescription.newCommand();
      manifest.setBuilderName("org.eclipse.pde.ManifestBuilder");

      final ICommand schema = projectDescription.newCommand();
      schema.setBuilderName("org.eclipse.pde.SchemaBuilder");

      projectDescription.setBuildSpec(new ICommand[] {java, manifest, schema});

      project.open(null);
      project.setDescription(projectDescription, null);

      classpathEntries.add(
          JavaCore.newContainerEntry(
              new Path(
                  "org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5")));
      classpathEntries.add(
          JavaCore.newContainerEntry(new Path("org.eclipse.pde.core.requiredPlugins")));

      javaProject.setRawClasspath(
          classpathEntries.toArray(new IClasspathEntry[classpathEntries.size()]), null);

      makeJava5Compliant(javaProject);

      javaProject.setOutputLocation(new Path("/" + projectName + "/bin"), null);
      createManifest(projectName, project);
      //			project.build(IncrementalProjectBuilder.FULL_BUILD, null);
      refreshExternalArchives(javaProject);
      refresh(javaProject);
    } catch (final Exception exception) {
      throw new RuntimeException(exception);
    }
    return javaProject;
  }
Example #24
0
 /** Creates a temporary project under current workspace. */
 public static void createTemporaryProject() {
   IWorkspace workspace = ResourcesPlugin.getWorkspace();
   IWorkspaceRoot root = workspace.getRoot();
   IProject proj = root.getProject(PluginConstants.T24_TEMPORARY_IDE_PROJECT);
   try {
     if (!proj.exists()) {
       proj.create(null);
     }
     proj.open(null);
   } catch (CoreException e) {
     e.printStackTrace();
   }
 }
  public TestJavaProject(final String name)
      throws CoreException, InvocationTargetException, InterruptedException {
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    project = root.getProject(name);
    project.create(null);
    project.open(null);

    javaProject = JavaCore.create(project);
    IFolder binFolder = createBinFolder();
    setJavaNature();
    javaProject.setRawClasspath(new IClasspathEntry[0], null);
    createOutputFolder(binFolder);
    addSystemLibraries();
  }
 /**
  * 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;
 }
 private IProject createProject(String dirPath) throws CoreException {
   long start = System.currentTimeMillis();
   IWorkspace workspace = ResourcesPlugin.getWorkspace();
   IWorkspaceRoot root = workspace.getRoot();
   String projectName = "test";
   IProject project = root.getProject(projectName);
   IProjectDescription description = workspace.newProjectDescription(projectName);
   description.setLocation(new Path(dirPath));
   project.create(description, null);
   project.open(null);
   long delta = System.currentTimeMillis() - start;
   System.out.println("Open project in " + delta + " ms");
   return project;
 }
  /**
   * @see
   *     it.unitn.disi.unagi.application.services.IManageProjectsService#createNewProject(org.eclipse.core.runtime.IProgressMonitor,
   *     java.lang.String)
   */
  @Override
  public IProject createNewProject(IProgressMonitor progressMonitor, String name)
      throws CouldNotSaveUnagiProjectException {
    LogUtil.log.info("Creating a new project: {0}.", name); // $NON-NLS-1$

    // Obtains a project descriptor with the desired name from the workspace.
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IProject project = root.getProject(name);

    // If the project already exists, throws a Unagi exception.
    if (project.exists()) {
      LogUtil.log.warn(
          "A project with the same name already exists in the workspace: {0}.",
          name); //$NON-NLS-1$
      throw new CouldNotSaveUnagiProjectException(project);
    }

    try {
      // Creates and opens the project.
      project.create(progressMonitor);
      project.open(progressMonitor);

      // Sets the Unagi project nature.
      IProjectDescription description = project.getDescription();
      String[] natures = description.getNatureIds();
      String[] newNatures = new String[natures.length + 1];
      System.arraycopy(natures, 0, newNatures, 0, natures.length);
      newNatures[natures.length] = UnagiProjectNature.NATURE_ID;
      description.setNatureIds(newNatures);
      project.setDescription(description, progressMonitor);

      // Creates the project's subfolders.
      for (String subdir : PROJECT_SUBDIRS) {
        IFolder folder = project.getFolder(subdir);
        folder.create(true, true, progressMonitor);
      }
    }

    // If any other errors occurred, throw an exception.
    catch (CoreException e) {
      LogUtil.log.error(
          "Unagi caught an Eclipse exception while trying to create project: {0}.",
          e, name); // $NON-NLS-1$
      throw new CouldNotSaveUnagiProjectException(project, e);
    }

    LogUtil.log.info("Successfully created and opened Unagi project: {0}.", name); // $NON-NLS-1$
    return project;
  }
 public static final void prepareWorkspace() throws CoreException {
   IWorkspace workspace = ResourcesPlugin.getWorkspace();
   IProject project = workspace.getRoot().getProject(JAVA_EXAMPLE_PROJECT);
   BlockingProgressMonitor monitor = new BlockingProgressMonitor();
   if (!project.exists()) {
     project.create(monitor);
     monitor.blockUntilDone();
   }
   assertThat(project.exists(), is(true));
   if (!project.isOpen()) {
     project.open(monitor);
     monitor.blockUntilDone();
   }
   workspace.build(IncrementalProjectBuilder.FULL_BUILD, monitor);
 }
  @BeforeClass
  public static void beforeTests() {

    // Local Declarations
    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    IProject project = null;
    String separator = System.getProperty("file.separator");
    String userDir =
        System.getProperty("user.home")
            + separator
            + "ICETests"
            + separator
            + "caebatTesterWorkspace";
    // Enable Debugging
    System.setProperty("DebugICE", "");

    // Setup the project
    try {
      // Get the project handle
      IPath projectPath = new Path(userDir + separator + ".project");
      // Create the project description
      IProjectDescription desc = ResourcesPlugin.getWorkspace().loadProjectDescription(projectPath);
      // Get the project handle and create it
      project = workspaceRoot.getProject(desc.getName());
      // Get the project handle and create it
      project = workspaceRoot.getProject(desc.getName());
      // Create the project if it doesn't exist
      if (!project.exists()) {
        project.create(desc, new NullProgressMonitor());
      }
      // Open the project if it is not already open
      if (project.exists() && !project.isOpen()) {
        project.open(new NullProgressMonitor());
      }
      // Refresh the workspace
      project.refreshLocal(IResource.DEPTH_INFINITE, null);
    } catch (CoreException e) {
      // Catch exception for creating the project
      e.printStackTrace();
      fail();
    }

    // Set the global project reference.
    projectSpace = project;

    return;
  }