Search in sources :

Example 6 with IWorkspaceDescription

use of org.eclipse.core.resources.IWorkspaceDescription 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 7 with IWorkspaceDescription

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

the class RPMProjectNatureTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    IWorkspaceDescription desc;
    workspace = ResourcesPlugin.getWorkspace();
    if (workspace == null) {
        fail("Workspace was not setup");
    }
    root = workspace.getRoot();
    monitor = new NullProgressMonitor();
    if (root == null) {
        fail("Workspace root was not setup");
    }
    desc = workspace.getDescription();
    desc.setAutoBuilding(false);
    workspace.setDescription(desc);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IWorkspaceDescription(org.eclipse.core.resources.IWorkspaceDescription) BeforeClass(org.junit.BeforeClass)

Example 8 with IWorkspaceDescription

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

the class AbstractSWTBotTest method setUpWorkbench.

@BeforeClass
public static void setUpWorkbench() throws Exception {
    SWTWorkbenchBot bot = new SWTWorkbenchBot();
    try {
        bot.viewByTitle("Welcome").close();
        // hide Subclipse Usage stats popup if present/installed
        bot.shell("Subclipse Usage").activate();
        bot.button("Cancel").click();
    } catch (WidgetNotFoundException e) {
    // ignore
    }
    // Set C/C++ perspective.
    bot.perspectiveByLabel("C/C++").activate();
    bot.sleep(500);
    for (SWTBotShell sh : bot.shells()) {
        if (sh.getText().startsWith("C/C++")) {
            sh.activate();
            bot.sleep(500);
            break;
        }
    }
    // Turn off automatic building by default to avoid timing issues
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IWorkspaceDescription desc = workspace.getDescription();
    boolean isAutoBuilding = desc.isAutoBuilding();
    if (isAutoBuilding) {
        desc.setAutoBuilding(false);
        workspace.setDescription(desc);
    }
    projectExplorer = bot.viewByTitle("Project Explorer");
}
Also used : SWTWorkbenchBot(org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot) WidgetNotFoundException(org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException) IWorkspaceDescription(org.eclipse.core.resources.IWorkspaceDescription) IWorkspace(org.eclipse.core.resources.IWorkspace) SWTBotShell(org.eclipse.swtbot.swt.finder.widgets.SWTBotShell) BeforeClass(org.junit.BeforeClass)

Aggregations

IWorkspaceDescription (org.eclipse.core.resources.IWorkspaceDescription)8 IWorkspace (org.eclipse.core.resources.IWorkspace)6 BeforeClass (org.junit.BeforeClass)4 CoreException (org.eclipse.core.runtime.CoreException)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 File (java.io.File)2 URL (java.net.URL)2 IIndexManager (org.eclipse.cdt.core.index.IIndexManager)2 LocalFile (org.eclipse.core.internal.filesystem.local.LocalFile)2 IProject (org.eclipse.core.resources.IProject)2 IPath (org.eclipse.core.runtime.IPath)2 IStatus (org.eclipse.core.runtime.IStatus)2 Path (org.eclipse.core.runtime.Path)2 SWTWorkbenchBot (org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot)2 WidgetNotFoundException (org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException)2 SWTBotShell (org.eclipse.swtbot.swt.finder.widgets.SWTBotShell)2 ImportOperation (org.eclipse.ui.wizards.datatransfer.ImportOperation)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URI (java.net.URI)1