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];
}
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);
}
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;
}
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);
}
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];
}
Aggregations