Java Code Examples for org.eclipse.core.resources.IProjectDescription#setLocationURI()

The following examples show how to use org.eclipse.core.resources.IProjectDescription#setLocationURI() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BazelProjectSupport.java    From eclipse with Apache License 2.0 6 votes vote down vote up
private static IProject createBaseProject(String projectName, URI location) {
  IProject newProject = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);

  if (!newProject.exists()) {
    URI projectLocation = location;
    IProjectDescription desc =
        newProject.getWorkspace().newProjectDescription(newProject.getName());
    if (location != null
        && ResourcesPlugin.getWorkspace().getRoot().getLocationURI().equals(location)) {
      projectLocation = null;
    }

    desc.setLocationURI(projectLocation);
    try {
      newProject.create(desc, null);
      if (!newProject.isOpen()) {
        newProject.open(null);
      }
    } catch (CoreException e) {
      e.printStackTrace();
    }
  }

  return newProject;
}
 
Example 2
Source File: ResourceUtilTest.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Create test parameter for the parameterized runner.
 *
 * @return The list of test parameters
 * @throws CoreException
 *             if core error occurs
 */
@Parameters(name = "{index}: ({0})")
public static Iterable<Object[]> getTracePaths() throws CoreException {
    IProgressMonitor progressMonitor = new NullProgressMonitor();
    IWorkspace workspace = ResourcesPlugin.getWorkspace();

    // Create a project inside workspace location
    fWorkspaceRoot = workspace.getRoot();
    fSomeProject = fWorkspaceRoot.getProject(SOME_PROJECT_NAME);
    fSomeProject.create(progressMonitor);
    fSomeProject.open(progressMonitor);

    // Create an other project outside the workspace location
    URI projectLocation = fProjectFolder.getRoot().toURI();
    fSomeOtherProject = fWorkspaceRoot.getProject(SOME_OTHER_PROJECT_NAME);
    IProjectDescription description = workspace.newProjectDescription(fSomeOtherProject.getName());
    if (projectLocation != null) {
        description.setLocationURI(projectLocation);
    }
    fSomeOtherProject.create(description, progressMonitor);
    fSomeOtherProject.open(progressMonitor);
    return Arrays.asList(new Object[][] { {fSomeProject}, {fSomeOtherProject} });
}
 
Example 3
Source File: JReFrameworker.java    From JReFrameworker with MIT License 6 votes vote down vote up
private static IJavaProject createProject(String projectName, IPath projectPath, IProject project, IProgressMonitor monitor) throws CoreException {
	IProjectDescription projectDescription = project.getWorkspace().newProjectDescription(project.getName());
	URI location = getProjectLocation(projectName, projectPath);
	projectDescription.setLocationURI(location);
	
	// make this a JReFrameworker project
	projectDescription.setNatureIds(new String[] { JReFrameworkerNature.NATURE_ID, JavaCore.NATURE_ID });

	// build first with Java compiler then JReFramewoker bytecode operations
	BuildCommand javaBuildCommand = new BuildCommand();
	javaBuildCommand.setBuilderName(JavaCore.BUILDER_ID);
	BuildCommand jrefBuildCommand = new BuildCommand();
	jrefBuildCommand.setBuilderName(JReFrameworkerBuilder.BUILDER_ID);
	projectDescription.setBuildSpec(new ICommand[]{ javaBuildCommand, jrefBuildCommand});

	// create and open the Eclipse project
	project.create(projectDescription, null);
	IJavaProject jProject = JavaCore.create(project);
	project.open(new NullProgressMonitor());
	return jProject;
}
 
Example 4
Source File: YangProjectSupport.java    From yang-design-studio with Eclipse Public License 1.0 6 votes vote down vote up
private static IProject createBaseProject(String projectName, URI location)
{
  IProject newProject = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
  if (!newProject.exists())
  {
    URI projectLocation = location;
    IProjectDescription desc = newProject.getWorkspace().newProjectDescription(newProject.getName());
    if ((location != null) && (ResourcesPlugin.getWorkspace().getRoot().getLocationURI().equals(location))) {
      projectLocation = null;
    }
    desc.setLocationURI(projectLocation);
    try
    {
      newProject.create(desc, null);
      if (!newProject.isOpen()) {
        newProject.open(null);
      }
    }
    catch (CoreException e)
    {
      e.printStackTrace();
    }
  }
  System.out.println("returning project");
  return newProject;
}
 
Example 5
Source File: HybridProjectCreator.java    From thym with Eclipse Public License 1.0 6 votes vote down vote up
private IProject createBasicProject( String name, URI location, IProgressMonitor monitor ) throws CoreException {
    
    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    IProject newProject = workspaceRoot.getProject(name);
    
    if ( !newProject.exists() ){
        IProjectDescription description = newProject.getWorkspace().newProjectDescription(name);
        if( location != null ){
            description.setLocationURI(location);
        }
        
        newProject.create(description, monitor);
        if( !newProject.isOpen() ){
            newProject.open(monitor);
        }
    }
    return newProject;
}
 
Example 6
Source File: CreateAppEngineWtpProject.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(IProgressMonitor monitor) throws InvocationTargetException, CoreException {
  IWorkspace workspace = ResourcesPlugin.getWorkspace();
  IProject newProject = config.getProject();
  URI location = config.getEclipseProjectLocationUri();

  String name = newProject.getName();
  IProjectDescription description = workspace.newProjectDescription(name);
  description.setLocationURI(location);

  String operationLabel = getDescription();
  SubMonitor subMonitor = SubMonitor.convert(monitor, operationLabel, 120);
  CreateProjectOperation operation = new CreateProjectOperation(description, operationLabel);
  try {
    operation.execute(subMonitor.newChild(10), uiInfoAdapter);
    mostImportant = createAndConfigureProjectContent(newProject, config, subMonitor.newChild(80));
  } catch (ExecutionException ex) {
    throw new InvocationTargetException(ex);
  }

  IFacetedProject facetedProject = ProjectFacetsManager.create(
      newProject, true /* convertIfNecessary */, subMonitor.newChild(5));
  addAppEngineFacet(facetedProject, subMonitor.newChild(6));

  addAdditionalDependencies(newProject, config, subMonitor.newChild(20));

  fixTestSourceDirectorySettings(newProject, subMonitor.newChild(5));
}
 
Example 7
Source File: NewProjectCreator.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
private static IProject createProject(String projectName, String location) {
    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    String workspacePath = ResourceUtils.getAbsolutePath(workspaceRoot);
    String differentCasingProjectName = ResourceUtils.checkResourceExistWithDifferentCasing(workspaceRoot, projectName);
    if (differentCasingProjectName != null) {
        projectName = differentCasingProjectName;
    }
    
    cleanProjectArea(projectName, location);
    
    IProject newProject = workspaceRoot
            .getProject(projectName);
    
    URI projectLocation = new File(location).toURI();
    IProjectDescription desc = newProject.getWorkspace().newProjectDescription(newProject.getName());
    String locationParent = new File(location).getParent();
    if (location != null && (workspacePath.equals(location) || workspacePath.equals(locationParent))) {
        projectLocation = null;
    } else if (location == null) {
        projectLocation = null;
    }
    desc.setLocationURI(projectLocation);
    try {
        newProject.create(desc, null);
    } catch (CoreException e) {
        LogHelper.logError(e);
    }

    return newProject;
}
 
Example 8
Source File: VibeLauncherBuilderTester.java    From ice with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * <p>
 * A utility operation that sets up the IProject space for the tests. It
 * creates a CaebatTesterWorkspace for the launcher to be built in.
 * </p>
 */
private void setupIProject() {
	URI defaultProjectLocation = null;
	String separator = System.getProperty("file.separator");

	try {
		// Get the project handle
		IProject project = projectSpace;
		// If the project does not exist, create it
		if (!project.exists()) {
			// Set the location as ${workspace_loc}/ItemTesterWorkspace
			defaultProjectLocation = (new File(
					System.getProperty("user.home") + separator
							+ "ICETests" + separator
							+ "caebatTesterWorkspace")).toURI();
			// Create the project description
			IProjectDescription desc = ResourcesPlugin.getWorkspace()
					.newProjectDescription("caebatTesterWorkspace");
			// Set the location of the project
			desc.setLocationURI(defaultProjectLocation);
			// Create the project
			project.create(desc, null);
		}
		// Open the project if it is not already open
		if (project.exists() && !project.isOpen()) {
			project.open(null);
		}
	} catch (CoreException e) {
		// Catch for creating the project
		e.printStackTrace();
		fail();
	}

}
 
Example 9
Source File: MultiLauncherTester.java    From ice with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * <p>
 * This operation is called before the test to setup the project space.
 * </p>
 * 
 */
@BeforeClass
public static void Before() {

	// Local Declarations
	IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
	URI defaultProjectLocation = null;
	String separator = System.getProperty("file.separator");
	String filename = null;

	// Setup the project
	try {
		// Get the project handle
		projectSpace = workspaceRoot.getProject("itemTesterWorkspace");
		// If the project does not exist, create it
		if (!projectSpace.exists()) {
			// Set the location as ${workspace_loc}/ItemTesterWorkspace
			defaultProjectLocation = (new File(
					System.getProperty("user.dir") + separator
							+ "itemTesterWorkspace")).toURI();
			// Create the project description
			IProjectDescription desc = ResourcesPlugin.getWorkspace()
					.newProjectDescription("itemTesterWorkspace");
			// Set the location of the project
			desc.setLocationURI(defaultProjectLocation);
			// Create the project
			projectSpace.create(desc, null);
		}
		// Open the project if it is not already open
		if (projectSpace.exists() && !projectSpace.isOpen()) {
			projectSpace.open(null);
		}
	} catch (CoreException e) {
		// Catch for creating the project
		e.printStackTrace();
		fail();
	}

}
 
Example 10
Source File: FileEntryTester.java    From ice with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * <p>
 * This operation checks the project setup of the Item to ensure that
 * calling the constructor with an IProject and Item.setProject() setup the
 * project reference such that Item.hasProject() returns true.
 * </p>
 * 
 */
@BeforeClass
public static void beforeClass() {

	// Local Declarations
	IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
	URI defaultProjectLocation = null;
	String separator = System.getProperty("file.separator");

	// Setup the project
	try {
		// Get the project handle
		project = workspaceRoot.getProject("itemData");
		// If the project does not exist, create it
		if (!project.exists()) {
			// Set the location as ${workspace_loc}/ItemTesterWorkspace
			defaultProjectLocation = new File(
					System.getProperty("user.home") + separator + "ICETests"
							+ separator + "itemData").toURI();
			// Create the project description
			IProjectDescription desc = ResourcesPlugin.getWorkspace()
					.newProjectDescription("itemData");
			// Set the location of the project
			desc.setLocationURI(defaultProjectLocation);
			// Create the project
			project.create(desc, null);
		}
		// Open the project if it is not already open
		if (project.exists() && !project.isOpen()) {
			project.open(null);
		}
	} catch (CoreException e) {
		// Catch for creating the project
		e.printStackTrace();
		fail();
	}
}
 
Example 11
Source File: BatMLModelTester.java    From ice with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * This operation sets up the workspace.
 */
@BeforeClass
public static void beforeTests() {

	// Local Declarations
	IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
	URI defaultProjectLocation = null;
	IProject project = null;
	String projectName = "batMLTesterWorkspace";
	String separator = System.getProperty("file.separator");

	// Setup the project
	try {
		// Get the project handle
		project = workspaceRoot.getProject(projectName);
		// If the project does not exist, create it
		if (!project.exists()) {
			// Set the location as
			// ${workspace_loc}/CAEBATModelTesterWorkspace
			defaultProjectLocation = (new File(
					System.getProperty("user.home") + separator
							+ "ICETests" + separator + projectName))
					.toURI();
			// Create the project description
			IProjectDescription desc = ResourcesPlugin.getWorkspace()
					.newProjectDescription(projectName);
			// Set the location of the project
			desc.setLocationURI(defaultProjectLocation);
			// Create the project
			project.create(desc, null);
		}
		// Open the project if it is not already open
		if (project.exists() && !project.isOpen()) {
			project.open(null);
		}
		// 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;
}
 
Example 12
Source File: PROTEUSLauncherTester.java    From ice with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Creates a fake workspace in the bundle for all PROTEUSLauncher unit tests 
 * to utilize throughout their execution. Once the workspace resource is no
 * longer needed, it is left to each individual test to close and delete
 * the project workspace.
 * @author Anna Wojtowicz
 * 
 */
public void setupFakeProject() {
	
	// Setup a dummy project workspace
	URI projectLocation = null;
	String separator = System.getProperty("file.separator");

	try {
		// Get the project handle
		workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
		project = workspaceRoot.getProject("PROTEUSTesterWorkspace");

		// If the project does not exist, create it
		if (!project.exists()) {

			// Define the location as ${workspace_loc}/PROTEUSTesterWorkspace
			projectLocation = (new File(
					System.getProperty("user.dir") 
					+ separator + "PROTEUSTesterWorkspace")).toURI();

			// Create the project description
			IProjectDescription desc = ResourcesPlugin.getWorkspace()
					.newProjectDescription("PROTEUSTesterWorkspace");

			// Set the location of the project
			desc.setLocationURI(projectLocation);

			// Create the project
			project.create(desc, null);
		}

		// Open the project if it is not already open
		if (project.exists() && !project.isOpen()) {
			project.open(null);
		}

	} catch (CoreException e) {
		e.printStackTrace();
		fail("Project workspace could not be created.");
	}
}
 
Example 13
Source File: XMLPersistenceProviderTester.java    From ice with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * This operation creates a project that is used during the persistence and
 * loading tests.
 * 
 * @param projectName
 *            The name for the new project.
 * @return The new Eclipse project.
 */
private static IProject createProject(String projectName) {

	// Local Declarations
	IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
	URI defaultProjectLocation = null;
	String separator = System.getProperty("file.separator");
	String userDir = System.getProperty("user.home") + separator
			+ "ICETests" + separator + "persistenceData";
	String projectPath = userDir + separator + projectName;
	IProject createdProject = null;

	// Setup the project
	try {
		// Get the project handle
		createdProject = workspaceRoot.getProject(projectName);
		// If the project does not exist, create it
		if (!createdProject.exists()) {
			// Set the location as ${workspace_loc}/ItemTesterWorkspace
			defaultProjectLocation = (new File(projectPath).toURI());
			// Create the project description
			IProjectDescription desc = ResourcesPlugin.getWorkspace()
					.newProjectDescription(projectName);
			// Set the location of the project
			desc.setLocationURI(defaultProjectLocation);
			// Create the project
			createdProject.create(desc, null);
		}
		// Open the project if it is not already open
		if (createdProject.exists() && !createdProject.isOpen()) {
			createdProject.open(null);
		}
		// Refresh the workspace
		createdProject.refreshLocal(IResource.DEPTH_INFINITE, null);
	} catch (CoreException e) {
		// Catch exception for creating the project
		e.printStackTrace();
		fail();
	}

	return createdProject;
}
 
Example 14
Source File: JobLauncherTester.java    From ice with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * <p>
 * This operation checks the JobLauncher to ensure that it can manage
 * multiple input files.
 * </p>
 * 
 */
@Test
public void checkMultipleInputFiles() {

	// Local Declarations
	String name = "JLwMF"; // JobLauncher with Multiple Files
	String desc = "Duritanium Alloy";
	int numFiles = 0, numExtraFiles = 0, totalFiles = 0;
	Form jobForm = null;
	DataComponent fileComponent = null;
	ArrayList<IEntry> fileEntries = null;
	Random rng = new Random(2013052111);
	IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
	URI defaultProjectLocation = null;
	IProject project = null;
	String separator = System.getProperty("file.separator");
	// Setup the project
	try {
		// Get the project handle
		project = workspaceRoot.getProject("itemTesterWorkspace");
		// If the project does not exist, create it
		if (!project.exists()) {
			// Set the location as ${workspace_loc}/ItemTesterWorkspace
			defaultProjectLocation = (new File(System.getProperty("user.dir") + separator + "itemTesterWorkspace"))
					.toURI();
			// Create the project description
			IProjectDescription projectDesc = ResourcesPlugin.getWorkspace()
					.newProjectDescription("itemTesterWorkspace");
			// Set the location of the project
			projectDesc.setLocationURI(defaultProjectLocation);
			// Create the project
			project.create(projectDesc, null);
		}
		// Open the project if it is not already open
		if (project.exists() && !project.isOpen()) {
			project.open(null);
		}
	} catch (CoreException e) {
		// Catch for creating the project
		e.printStackTrace();
		fail();
	}

	// Set up the launcher
	JobLauncher launcher = new JobLauncher(project);
	launcher.setDescription("JobLauncher with multiple files");
	launcher.setId(5);
	launcher.setName(name);

	// Get the form and make sure that there is only one file to start
	jobForm = launcher.getForm();
	assertNotNull(jobForm);
	fileComponent = (DataComponent) jobForm.getComponent(1);
	assertNotNull(fileComponent);
	fileEntries = fileComponent.retrieveAllEntries();
	numFiles = fileEntries.size();
	assertEquals(1, numFiles);

	// Add a few files
	numExtraFiles = rng.nextInt(50) + 1; // +1 such that at least one added
	totalFiles = 1 + numExtraFiles; // 1 by default + the extras
	for (int i = 0; i < numExtraFiles; i++) {
		launcher.addInputType(name + " " + i, name + i + "File", desc + " " + i, null);
	}

	// Check that the files were added
	numFiles = fileEntries.size();
	assertEquals(totalFiles, numFiles);

	// Check the names and descriptions
	for (int i = 1; i < totalFiles; i++) {
		assertEquals(name + " " + (i - 1), fileEntries.get(i).getName());
		assertEquals(desc + " " + (i - 1), fileEntries.get(i).getDescription());
	}

	return;
}
 
Example 15
Source File: GeometryEditorBuilderTester.java    From ice with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * <p>
 * This operations checks the GeometryEditorBuilder to make sure that it
 * properly creates GeometryEditors. It also checks the name and the type of
 * the GeometryEditorBuilder and the GeometryEditor.
 * </p>
 * 
 */
@Test
public void checkConstruction() {

	// Local Declarations
	IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
	URI defaultProjectLocation = null;
	IProject project = null;
	String separator = System.getProperty("file.separator");
	String filename = null;

	// Setup the project workspace
	try {
		// Get the project handle
		project = workspaceRoot.getProject("itemTesterWorkspace");
		// If the project does not exist, create it
		if (!project.exists()) {
			// Set the location as ${workspace_loc}/ItemTesterWorkspace
			defaultProjectLocation = (new File(
					System.getProperty("user.dir") + separator
							+ "itemTesterWorkspace")).toURI();
			// Create the project description
			IProjectDescription desc = ResourcesPlugin.getWorkspace()
					.newProjectDescription("itemTesterWorkspace");
			// Set the location of the project
			desc.setLocationURI(defaultProjectLocation);
			// Create the project
			project.create(desc, null);
		}
		// Open the project if it is not already open
		if (project.exists() && !project.isOpen()) {
			project.open(null);
		}
	} catch (CoreException e) {
		// Catch for creating the project
		e.printStackTrace();
		fail();
	}

	// Instantiate the builder
	geometryEditorBuilder = new GeometryEditorBuilder();

	// Check the name - the static value, the getter and the comparison of
	// the two
	assertEquals("Geometry Editor", geometryEditorBuilder.name);
	assertEquals("Geometry Editor", geometryEditorBuilder.getItemName());
	assertEquals(geometryEditorBuilder.name,
			geometryEditorBuilder.getItemName());

	// Check the type - the static value, the getter and the comparison of
	// the two
	assertEquals(ItemType.Geometry, geometryEditorBuilder.type);
	assertEquals(ItemType.Geometry, geometryEditorBuilder.getItemType());
	assertEquals(geometryEditorBuilder.type,
			geometryEditorBuilder.getItemType());

	// Make sure construction works properly
	Item editor = geometryEditorBuilder.build(project);
	assertNotNull(editor);
	assertTrue(editor instanceof GeometryEditor);
	assertEquals("Geometry Editor", editor.getName());
	assertEquals(ItemType.Geometry, editor.getItemType());

	return;

}
 
Example 16
Source File: CoreTester.java    From ice with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * This is a utility operation that returns the project of the given name
 * for the test. It removes any old test files from the project . It
 * attempts to create the project if it does not exist.
 *
 * @param name
 *            the name of the project to retrieve from the Workspace
 * @return the project
 */
public IProject getProject(String name) {

	IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
	URI defaultProjectLocation = null;
	IProject project = null;
	String separator = System.getProperty("file.separator");

	// Setup the project space so that the output file can be checked.
	System.out.println("CoreTester Workspace Root = " + workspaceRoot.getLocation());
	System.out.println("Constructing project " + name);
	try {
		// Get the project handle
		project = workspaceRoot.getProject(name);
		// If the project does not exist, create it
		if (!project.exists()) {
			defaultProjectLocation = (new File(System.getProperty("user.dir") + separator + name)).toURI();
			// Create the project description
			IProjectDescription desc = ResourcesPlugin.getWorkspace().newProjectDescription(name);
			// Set the location of the project
			desc.setLocationURI(defaultProjectLocation);
			System.out.println("CoreTester Message: " + "Project location is " + desc.getLocationURI());
			// Create the project
			project.create(desc, null);
		}
		// Open the project if it is not already open
		if (project.exists() && !project.isOpen()) {
			project.open(null);
		}
	} catch (CoreException e) {
		// Catch for creating the project
		e.printStackTrace();
		fail();
	}

	// Clean out any old test files
	try {
		for (IResource resource : project.members()) {
			resource.delete(true, null);
		}
	} catch (CoreException e1) {
		// Complain
		e1.printStackTrace();
		fail();
	}

	return project;
}