Search in sources :

Example 51 with IWorkspace

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

the class CProjectHelper method createCProject2.

/**
 * Creates a ICProject.
 */
private static ICProject createCProject2(final String projectName, String binFolderName) throws CoreException {
    final IWorkspace ws = ResourcesPlugin.getWorkspace();
    final ICProject[] newProject = new ICProject[1];
    ws.run((IWorkspaceRunnable) monitor -> {
        IWorkspaceRoot root = ws.getRoot();
        IProject project = root.getProject(projectName);
        if (!project.exists()) {
            project.create(null);
        } else {
            project.refreshLocal(IResource.DEPTH_INFINITE, null);
        }
        if (!project.isOpen()) {
            project.open(null);
        }
        if (!project.hasNature(CProjectNature.C_NATURE_ID)) {
            String projectId = PLUGIN_ID + ".TestProject";
            addNatureToProject(project, CProjectNature.C_NATURE_ID, null);
            CCorePlugin.getDefault().mapCProjectOwner(project, projectId, false);
        }
        addDefaultBinaryParser(project);
        newProject[0] = CCorePlugin.getDefault().getCoreModel().create(project);
    }, null);
    return newProject[0];
}
Also used : CProjectNature(org.eclipse.cdt.core.CProjectNature) ICConfigExtensionReference(org.eclipse.cdt.core.settings.model.ICConfigExtensionReference) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) CoreException(org.eclipse.core.runtime.CoreException) ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CCProjectNature(org.eclipse.cdt.core.CCProjectNature) IStatus(org.eclipse.core.runtime.IStatus) CCorePlugin(org.eclipse.cdt.core.CCorePlugin) IProject(org.eclipse.core.resources.IProject) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) IResource(org.eclipse.core.resources.IResource) Assert.fail(org.junit.Assert.fail) ICProject(org.eclipse.cdt.core.model.ICProject) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) ICProject(org.eclipse.cdt.core.model.ICProject) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IWorkspace(org.eclipse.core.resources.IWorkspace) IProject(org.eclipse.core.resources.IProject)

Example 52 with IWorkspace

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

the class AbstractTest method buildProject.

protected void buildProject(IProject proj) throws CoreException {
    IWorkspace wsp = ResourcesPlugin.getWorkspace();
    final IProject curProject = proj;
    ISchedulingRule rule = wsp.getRuleFactory().buildRule();
    Job buildJob = new // $NON-NLS-1$
    Job(// $NON-NLS-1$
    "project build job") {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            try {
                curProject.build(IncrementalProjectBuilder.FULL_BUILD, null);
            } catch (CoreException e) {
                fail(e.getStatus().getMessage());
            } catch (OperationCanceledException e) {
                fail(NLS.bind(Messages.getString("AbstractTest.Build_cancelled"), curProject.getName(), // $NON-NLS-1$
                e.getMessage()));
            }
            return Status.OK_STATUS;
        }
    };
    buildJob.setRule(rule);
    buildJob.schedule();
    try {
        buildJob.join();
    } catch (InterruptedException e) {
        fail(NLS.bind(Messages.getString("AbstractTest.Build_interrupted"), curProject.getName(), // $NON-NLS-1$
        e.getMessage()));
    }
    IStatus status = buildJob.getResult();
    if (status.getCode() != IStatus.OK) {
        fail(NLS.bind(Messages.getString("AbstractTest.Build_failed"), curProject.getName(), // $NON-NLS-1$
        status.getMessage()));
    }
    IWorkspaceRunnable runnable = monitor -> curProject.refreshLocal(IResource.DEPTH_INFINITE, null);
    wsp.run(runnable, wsp.getRoot(), IWorkspace.AVOID_UPDATE, null);
}
Also used : DebugPlugin(org.eclipse.debug.core.DebugPlugin) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) LocalFile(org.eclipse.core.internal.filesystem.local.LocalFile) CoreException(org.eclipse.core.runtime.CoreException) CProjectHelper(org.eclipse.linuxtools.internal.profiling.tests.CProjectHelper) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) IncrementalProjectBuilder(org.eclipse.core.resources.IncrementalProjectBuilder) ManagedCProjectNature(org.eclipse.cdt.managedbuilder.core.ManagedCProjectNature) IStatus(org.eclipse.core.runtime.IStatus) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IPath(org.eclipse.core.runtime.IPath) IOverwriteQuery(org.eclipse.ui.dialogs.IOverwriteQuery) Assert.fail(org.junit.Assert.fail) URI(java.net.URI) Bundle(org.osgi.framework.Bundle) EFS(org.eclipse.core.filesystem.EFS) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) ImportOperation(org.eclipse.ui.wizards.datatransfer.ImportOperation) NLS(org.eclipse.osgi.util.NLS) Status(org.eclipse.core.runtime.Status) IBinary(org.eclipse.cdt.core.model.IBinary) EFSExtensionManager(org.eclipse.cdt.utils.EFSExtensionManager) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) ILaunchManager(org.eclipse.debug.core.ILaunchManager) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWorkspaceDescription(org.eclipse.core.resources.IWorkspaceDescription) ScannerConfigNature(org.eclipse.cdt.build.core.scannerconfig.ScannerConfigNature) Path(org.eclipse.core.runtime.Path) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) FileSystemStructureProvider(org.eclipse.ui.wizards.datatransfer.FileSystemStructureProvider) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CCorePlugin(org.eclipse.cdt.core.CCorePlugin) IProject(org.eclipse.core.resources.IProject) IWorkspace(org.eclipse.core.resources.IWorkspace) ICProject(org.eclipse.cdt.core.model.ICProject) IFileStore(org.eclipse.core.filesystem.IFileStore) Job(org.eclipse.core.runtime.jobs.Job) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) File(java.io.File) IDebugUIConstants(org.eclipse.debug.ui.IDebugUIConstants) FileLocator(org.eclipse.core.runtime.FileLocator) ICDTLaunchConfigurationConstants(org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants) IIndexManager(org.eclipse.cdt.core.index.IIndexManager) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProjectDescription(org.eclipse.core.resources.IProjectDescription) IResource(org.eclipse.core.resources.IResource) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) Job(org.eclipse.core.runtime.jobs.Job) IProject(org.eclipse.core.resources.IProject) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 53 with IWorkspace

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

the class AbstractTest method createProject.

protected ICProject createProject(Bundle bundle, String projname) throws CoreException, URISyntaxException, IOException, InvocationTargetException, InterruptedException {
    // Turn off auto-building
    IWorkspace wsp = ResourcesPlugin.getWorkspace();
    IWorkspaceDescription desc = wsp.getDescription();
    desc.setAutoBuilding(false);
    wsp.setDescription(desc);
    ICProject proj = CProjectHelper.createCProject(projname, BIN_DIR);
    URL location = FileLocator.find(bundle, new Path("resources/" + projname), // $NON-NLS-1$
    null);
    File testDir = new File(FileLocator.toFileURL(location).toURI());
    IProject project = proj.getProject();
    // Add these natures before project is imported due to #273079
    ManagedCProjectNature.addManagedNature(project, null);
    ScannerConfigNature.addScannerConfigNature(project);
    ImportOperation op = new ImportOperation(project.getFullPath(), testDir, FileSystemStructureProvider.INSTANCE, pathString -> IOverwriteQuery.ALL);
    op.setCreateContainerStructure(false);
    op.run(null);
    IStatus status = op.getStatus();
    if (!status.isOK()) {
        throw new CoreException(status);
    }
    // Index the project
    IIndexManager indexManager = CCorePlugin.getIndexManager();
    indexManager.reindex(proj);
    indexManager.joinIndexer(IIndexManager.FOREVER, new NullProgressMonitor());
    // These natures must be enabled at this point to continue
    assertTrue(project.isNatureEnabled(ScannerConfigNature.NATURE_ID));
    assertTrue(project.isNatureEnabled(ManagedCProjectNature.MNG_NATURE_ID));
    return proj;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) IWorkspaceDescription(org.eclipse.core.resources.IWorkspaceDescription) ICProject(org.eclipse.cdt.core.model.ICProject) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) ImportOperation(org.eclipse.ui.wizards.datatransfer.ImportOperation) IIndexManager(org.eclipse.cdt.core.index.IIndexManager) LocalFile(org.eclipse.core.internal.filesystem.local.LocalFile) File(java.io.File) URL(java.net.URL) IProject(org.eclipse.core.resources.IProject)

Example 54 with IWorkspace

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

the class CheckDevhelp method testParseMyApp.

@Test
public void testParseMyApp() throws IOException {
    // We need to have a devhelp directory with contents to test.
    // Copy over the needed devhelp/html2 contents in this test plug-in
    // to the workspace.  This test verifies: bug 433507 and also
    // tests non-breaking spaces used in latest gtk-doc devhelp generation.
    ClassLoader cl = getClass().getClassLoader();
    Bundle bundle = null;
    if (cl instanceof BundleReference) {
        bundle = ((BundleReference) cl).getBundle();
    }
    IWorkspace ws = ResourcesPlugin.getWorkspace();
    IPath wslocpath = ws.getRoot().getLocation();
    // $NON-NLS-1$
    IPath outfilepath = wslocpath.append("devhelp/html2/myapp");
    File outfiledir = outfilepath.toFile();
    assertTrue(outfiledir.mkdirs());
    // $NON-NLS-1$
    outfilepath = outfilepath.append("myapp.devhelp2");
    File outfile = outfilepath.toFile();
    // $NON-NLS-1$
    IPath outfilepath2 = wslocpath.append("devhelp/html2/myapp/myapp.html");
    File outfile2 = outfilepath2.toFile();
    // $NON-NLS-1$
    IPath outfilepath3 = wslocpath.append("devhelp/html2/myapp/myapp2.html");
    File outfile3 = outfilepath3.toFile();
    // $NON-NLS-1$
    IPath outfilepath4 = wslocpath.append("devhelp/html2/myapp/style.css");
    File outfile4 = outfilepath4.toFile();
    outfile.createNewFile();
    outfile2.createNewFile();
    outfile3.createNewFile();
    outfile4.createNewFile();
    try (InputStream in = FileLocator.openStream(bundle, new Path("devhelp/html2/myapp/myapp.devhelp2"), false)) {
        // $NON-NLS-1$
        Files.copy(in, Paths.get(outfile.toURI()), StandardCopyOption.REPLACE_EXISTING);
    }
    try (InputStream in2 = FileLocator.openStream(bundle, new Path("devhelp/html2/myapp/myapp.html"), false)) {
        // $NON-NLS-1$
        Files.copy(in2, Paths.get(outfile2.toURI()), StandardCopyOption.REPLACE_EXISTING);
    }
    try (InputStream in3 = FileLocator.openStream(bundle, new Path("devhelp/html2/myapp/myapp2.html"), false)) {
        // $NON-NLS-1$
        Files.copy(in3, Paths.get(outfile3.toURI()), StandardCopyOption.REPLACE_EXISTING);
    }
    try (InputStream in4 = FileLocator.openStream(bundle, new Path("devhelp/html2/myapp/myapp2.html"), false)) {
        // $NON-NLS-1$
        Files.copy(in4, Paths.get(outfile4.toURI()), StandardCopyOption.REPLACE_EXISTING);
    }
    // $NON-NLS-1$
    IPath x = wslocpath.append("devhelp/html2");
    ParseDevHelp.DevHelpParser p = new ParseDevHelp.DevHelpParser(x.toOSString());
    LibHoverInfo hover = p.parse(new NullProgressMonitor());
    assertNotNull(hover);
    Map<String, FunctionInfo> functions = hover.functions;
    assertNotNull(functions);
    assertFalse(functions.isEmpty());
    // $NON-NLS-1$
    FunctionInfo f = functions.get("myapp_init");
    assertNotNull(f);
    String desc = f.getDescription();
    assertFalse(desc.isEmpty());
    String endOfDesc = desc.substring(desc.length() - 50);
    // $NON-NLS-1$
    assertEquals("pointer to application's argv. </p></dd>\n\n\n</dl>\n\n", endOfDesc);
    // $NON-NLS-1$
    FunctionInfo g = functions.get("myapp_init_check");
    assertNotNull(g);
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IPath(org.eclipse.core.runtime.IPath) Bundle(org.osgi.framework.Bundle) InputStream(java.io.InputStream) FunctionInfo(org.eclipse.linuxtools.cdt.libhover.FunctionInfo) BundleReference(org.osgi.framework.BundleReference) LibHoverInfo(org.eclipse.linuxtools.cdt.libhover.LibHoverInfo) ParseDevHelp(org.eclipse.linuxtools.internal.cdt.libhover.devhelp.ParseDevHelp) IWorkspace(org.eclipse.core.resources.IWorkspace) File(java.io.File) Test(org.junit.Test)

Example 55 with IWorkspace

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

the class CProjectHelper method createCCProject.

public static ICProject createCCProject(final String projectName, final String binFolderName, final String indexerID) throws CoreException {
    final IWorkspace ws = ResourcesPlugin.getWorkspace();
    final ICProject[] newProject = new ICProject[1];
    ws.run((IWorkspaceRunnable) monitor -> {
        ICProject cproject = createCProject(projectName, binFolderName, indexerID);
        if (!cproject.getProject().hasNature(CCProjectNature.CC_NATURE_ID)) {
            addNatureToProject(cproject.getProject(), CCProjectNature.CC_NATURE_ID, null);
        }
        newProject[0] = cproject;
    }, null);
    return newProject[0];
}
Also used : CProjectNature(org.eclipse.cdt.core.CProjectNature) IndexerPreferences(org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences) ICConfigExtensionReference(org.eclipse.cdt.core.settings.model.ICConfigExtensionReference) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) CoreException(org.eclipse.core.runtime.CoreException) ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CCProjectNature(org.eclipse.cdt.core.CCProjectNature) CCorePlugin(org.eclipse.cdt.core.CCorePlugin) IProject(org.eclipse.core.resources.IProject) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) IResource(org.eclipse.core.resources.IResource) ICProject(org.eclipse.cdt.core.model.ICProject) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) ICProject(org.eclipse.cdt.core.model.ICProject) IWorkspace(org.eclipse.core.resources.IWorkspace)

Aggregations

IWorkspace (org.eclipse.core.resources.IWorkspace)118 IProject (org.eclipse.core.resources.IProject)55 CoreException (org.eclipse.core.runtime.CoreException)54 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)37 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)36 IPath (org.eclipse.core.runtime.IPath)35 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)29 IStatus (org.eclipse.core.runtime.IStatus)27 IFile (org.eclipse.core.resources.IFile)24 PersistenceException (org.talend.commons.exception.PersistenceException)23 IProjectDescription (org.eclipse.core.resources.IProjectDescription)21 File (java.io.File)19 InvocationTargetException (java.lang.reflect.InvocationTargetException)19 Path (org.eclipse.core.runtime.Path)19 ISchedulingRule (org.eclipse.core.runtime.jobs.ISchedulingRule)19 IResource (org.eclipse.core.resources.IResource)18 Status (org.eclipse.core.runtime.Status)14 IOException (java.io.IOException)13 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)13 ArrayList (java.util.ArrayList)12