Search in sources :

Example 61 with IProjectDescription

use of org.eclipse.core.resources.IProjectDescription in project Palladio-Editors-Sirius by PalladioSimulator.

the class NewPalladioProjectWizard method performFinish.

@Override
public boolean performFinish() {
    final IProject projectHandle = this.projectCreationPage.getProjectHandle();
    final java.net.URI projectURI = (!this.projectCreationPage.useDefaults()) ? this.projectCreationPage.getLocationURI() : null;
    final IWorkspace workspace = ResourcesPlugin.getWorkspace();
    final IProjectDescription desc = workspace.newProjectDescription(projectHandle.getName());
    desc.setLocationURI(projectURI);
    /*
         * Creating the project encapsulated in a workspace operation
         */
    final WorkspaceModifyOperation op = new WorkspaceModifyOperation() {

        @Override
        protected void execute(final IProgressMonitor monitor) throws CoreException {
            NewPalladioProjectWizard.this.project = createProject(desc, projectHandle, monitor);
        }
    };
    /*
         * This isn't as robust as the code in the BasicNewProjectResourceWizard class. Consider
         * beefing this up to improve error handling.
         */
    try {
        getContainer().run(true, true, op);
    } catch (final Exception e) {
        MessageDialog.openError(getShell(), "Error", "An unexpected error occured. See stack trace");
        e.printStackTrace();
        return false;
    }
    if (this.project == null) {
        return false;
    }
    BasicNewProjectResourceWizard.updatePerspective(this.config);
    BasicNewProjectResourceWizard.selectAndReveal(this.project, this.workbench.getActiveWorkbenchWindow());
    if (!getCurrentPerspectiveId().equals(PERSPECTIVE_ID)) {
        boolean confirm = MessageDialog.openConfirm(getShell(), "Palladio Perspective", "This project is associated with the Palladio perspective.\n\nDo you want to open this perspective now?");
        if (confirm)
            openPalladioPerspective();
    }
    return true;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) IProject(org.eclipse.core.resources.IProject) WorkbenchException(org.eclipse.ui.WorkbenchException) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Example 62 with IProjectDescription

use of org.eclipse.core.resources.IProjectDescription in project linuxtools by eclipse.

the class ProjectInitializationRule method createProject.

/**
 * @param description
 * @param projectName
 * @param workspace
 * @param project
 * @throws InvocationTargetException
 * @throws InterruptedException
 * @throws CoreException
 * @throws OperationCanceledException
 */
static void createProject(final IProjectDescription description, final String projectName, final IWorkspace workspace, final IProject project) throws InvocationTargetException, OperationCanceledException, CoreException, InterruptedException {
    // import from file system
    // import project from location copying files - use default project
    // location for this workspace
    // if location is null, project already exists in this location or
    // some error condition occurred.
    final IProjectDescription desc = workspace.newProjectDescription(projectName);
    desc.setBuildSpec(description.getBuildSpec());
    desc.setComment(description.getComment());
    desc.setDynamicReferences(description.getDynamicReferences());
    desc.setNatureIds(description.getNatureIds());
    desc.setReferencedProjects(description.getReferencedProjects());
    try {
        project.create(desc, null);
        project.open(IResource.BACKGROUND_REFRESH, null);
    } catch (CoreException e) {
        throw new InvocationTargetException(e);
    }
    buildProject(project);
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IProjectDescription(org.eclipse.core.resources.IProjectDescription) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 63 with IProjectDescription

use of org.eclipse.core.resources.IProjectDescription in project linuxtools by eclipse.

the class AbstractTest method createExternalProject.

/**
 * Create a CDT project outside the default workspace.
 *
 * @param bundle
 *            The plug-in bundle.
 * @param projname
 *            The name of the project.
 * @param absProjectPath
 *            Absolute path to the directory to which the project should be
 *            mapped outside the workspace.
 * @return A new external CDT project.
 * @throws CoreException
 * @throws URISyntaxException
 * @throws IOException
 * @throws InvocationTargetException
 * @throws InterruptedException
 */
protected IProject createExternalProject(Bundle bundle, final String projname, final Path absProjectPath) throws CoreException, URISyntaxException, IOException, InvocationTargetException, InterruptedException {
    IProject externalProject;
    // Turn off auto-building
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IWorkspaceDescription wspDesc = workspace.getDescription();
    wspDesc.setAutoBuilding(false);
    workspace.setDescription(wspDesc);
    // Create external project
    IWorkspaceRoot root = workspace.getRoot();
    externalProject = root.getProject(projname);
    IProjectDescription description = workspace.newProjectDescription(projname);
    URI fileProjectURL = new URI("file://" + absProjectPath.toString());
    description.setLocationURI(fileProjectURL);
    externalProject = CCorePlugin.getDefault().createCDTProject(description, externalProject, new NullProgressMonitor());
    assertNotNull(externalProject);
    externalProject.open(null);
    try {
        // CDT opens the Project with BACKGROUND_REFRESH enabled which
        // causes the
        // refresh manager to refresh the project 200ms later. This Job
        // interferes
        // with the resource change handler firing see: bug 271264
        Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_REFRESH, null);
    } catch (Exception e) {
    // Ignore
    }
    assertTrue(externalProject.isOpen());
    // Import boiler-plate files which can then be built and profiled
    URL location = FileLocator.find(bundle, new Path("resources/" + projname), // $NON-NLS-1$
    null);
    File testDir = new File(FileLocator.toFileURL(location).toURI());
    ImportOperation op = new ImportOperation(externalProject.getFullPath(), testDir, FileSystemStructureProvider.INSTANCE, new IOverwriteQuery() {

        @Override
        public String queryOverwrite(String pathString) {
            return ALL;
        }
    });
    op.setCreateContainerStructure(false);
    op.run(null);
    IStatus status = op.getStatus();
    if (!status.isOK()) {
        throw new CoreException(status);
    }
    // Make sure import went well
    assertNotNull(externalProject.findMember(new Path(IMPORTED_SOURCE_FILE)));
    // Index the project
    IIndexManager indexMgr = CCorePlugin.getIndexManager();
    indexMgr.joinIndexer(IIndexManager.FOREVER, new NullProgressMonitor());
    // These natures must be enabled at this point to continue
    assertTrue(externalProject.isNatureEnabled(ScannerConfigNature.NATURE_ID));
    assertTrue(externalProject.isNatureEnabled(ManagedCProjectNature.MNG_NATURE_ID));
    return externalProject;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IOverwriteQuery(org.eclipse.ui.dialogs.IOverwriteQuery) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) ImportOperation(org.eclipse.ui.wizards.datatransfer.ImportOperation) IIndexManager(org.eclipse.cdt.core.index.IIndexManager) URI(java.net.URI) IProject(org.eclipse.core.resources.IProject) URISyntaxException(java.net.URISyntaxException) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) URL(java.net.URL) IWorkspaceDescription(org.eclipse.core.resources.IWorkspaceDescription) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) LocalFile(org.eclipse.core.internal.filesystem.local.LocalFile) File(java.io.File)

Example 64 with IProjectDescription

use of org.eclipse.core.resources.IProjectDescription in project linuxtools by eclipse.

the class CreaterepoProjectCreator method create.

/**
 * Create a createrepo project given a project name and the progress
 * monitor. The new project will contain an empty repodata folder.
 *
 * @param projectName The name of the project.
 * @param locationPath The location path of the project
 * @param monitor The progress monitor.
 * @return The newly created project.
 * @throws CoreException Thrown when creating a project fails.
 */
public static IProject create(String projectName, IPath locationPath, String repoName, IProgressMonitor monitor) throws CoreException {
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IProject project = root.getProject(projectName);
    IProjectDescription description = ResourcesPlugin.getWorkspace().newProjectDescription(projectName);
    if (!Platform.getLocation().equals(locationPath)) {
        description.setLocation(locationPath);
    }
    description.setNatureIds(new String[] { CreaterepoProjectNature.CREATEREPO_NATURE_ID });
    project.create(description, monitor);
    project.open(monitor);
    IFile repoFile = project.getFile(repoName);
    InputStream stream = new ByteArrayInputStream(ICreaterepoConstants.EMPTY_STRING.getBytes());
    if (!repoFile.exists()) {
        repoFile.create(stream, true, monitor);
    }
    return project;
}
Also used : IFile(org.eclipse.core.resources.IFile) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IProjectDescription(org.eclipse.core.resources.IProjectDescription) IProject(org.eclipse.core.resources.IProject)

Example 65 with IProjectDescription

use of org.eclipse.core.resources.IProjectDescription in project linuxtools by eclipse.

the class RpmlintNature method configure.

@Override
public void configure() throws CoreException {
    IProjectDescription desc = project.getDescription();
    ICommand[] commands = desc.getBuildSpec();
    for (ICommand command : commands) {
        if (command.getBuilderName().equals(RpmlintBuilder.BUILDER_ID)) {
            return;
        }
    }
    ICommand[] newCommands = new ICommand[commands.length + 1];
    System.arraycopy(commands, 0, newCommands, 0, commands.length);
    ICommand command = desc.newCommand();
    command.setBuilderName(RpmlintBuilder.BUILDER_ID);
    newCommands[newCommands.length - 1] = command;
    desc.setBuildSpec(newCommands);
    project.setDescription(desc, null);
}
Also used : ICommand(org.eclipse.core.resources.ICommand) IProjectDescription(org.eclipse.core.resources.IProjectDescription)

Aggregations

IProjectDescription (org.eclipse.core.resources.IProjectDescription)68 IProject (org.eclipse.core.resources.IProject)35 CoreException (org.eclipse.core.runtime.CoreException)18 IWorkspace (org.eclipse.core.resources.IWorkspace)16 IPath (org.eclipse.core.runtime.IPath)13 ICommand (org.eclipse.core.resources.ICommand)12 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)11 File (java.io.File)9 IStatus (org.eclipse.core.runtime.IStatus)9 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)8 Path (org.eclipse.core.runtime.Path)8 Status (org.eclipse.core.runtime.Status)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 URI (java.net.URI)5 IResource (org.eclipse.core.resources.IResource)5 Test (org.junit.Test)5 HashSet (java.util.HashSet)4 InputStream (java.io.InputStream)3 IFile (org.eclipse.core.resources.IFile)3 Resource (org.eclipse.emf.ecore.resource.Resource)3