|
1 | 1 | package io.sloeber.core.api;
|
2 | 2 |
|
3 | 3 | import java.io.File;
|
| 4 | +import java.lang.reflect.InvocationTargetException; |
4 | 5 | import java.net.URI;
|
5 | 6 | import java.util.ArrayList;
|
6 | 7 | import java.util.List;
|
|
39 | 40 | import org.eclipse.core.runtime.Path;
|
40 | 41 | import org.eclipse.core.runtime.Platform;
|
41 | 42 | import org.eclipse.core.runtime.Status;
|
| 43 | +import org.eclipse.core.runtime.SubMonitor; |
| 44 | +import org.eclipse.core.runtime.jobs.IJobManager; |
| 45 | +import org.eclipse.core.runtime.jobs.Job; |
42 | 46 | import org.eclipse.core.runtime.preferences.IEclipsePreferences;
|
43 | 47 | import org.eclipse.core.runtime.preferences.InstanceScope;
|
| 48 | +import org.eclipse.ui.PlatformUI; |
| 49 | +import org.eclipse.ui.actions.WorkspaceModifyOperation; |
44 | 50 |
|
45 | 51 | import io.sloeber.core.Activator;
|
46 | 52 | import io.sloeber.core.InternalBoardDescriptor;
|
@@ -573,18 +579,16 @@ public boolean configureProject(IProject project, IProgressMonitor monitor) {
|
573 | 579 | * Method to create a project based on the board
|
574 | 580 | */
|
575 | 581 | public IProject createProject(String projectName, URI projectURI, CodeDescriptor codeDescription,
|
576 |
| - CompileOptions compileOptions, IProgressMonitor monitor) throws Exception { |
| 582 | + CompileOptions compileOptions, IProgressMonitor monitor) { |
577 | 583 |
|
578 | 584 | String realProjectName = Common.MakeNameCompileSafe(projectName);
|
579 | 585 |
|
580 | 586 | IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
|
581 | 587 | final IProject newProjectHandle = root.getProject(realProjectName);
|
582 | 588 | final IWorkspace workspace = ResourcesPlugin.getWorkspace();
|
583 |
| - |
584 |
| - ICoreRunnable runnable = new ICoreRunnable() { |
| 589 | + WorkspaceModifyOperation op = new WorkspaceModifyOperation() { |
585 | 590 | @Override
|
586 |
| - public void run(IProgressMonitor internalMonitor) throws CoreException { |
587 |
| - |
| 591 | + protected void execute(IProgressMonitor internalMonitor) throws CoreException { |
588 | 592 | try {
|
589 | 593 | // Create the base project
|
590 | 594 | IWorkspaceDescription workspaceDesc = workspace.getDescription();
|
@@ -636,32 +640,28 @@ public void run(IProgressMonitor internalMonitor) throws CoreException {
|
636 | 640 | compileOptions.save(curConfig);
|
637 | 641 | save(curConfig);
|
638 | 642 | }
|
| 643 | + SubMonitor refreshMonitor = SubMonitor.convert(internalMonitor, 3); |
| 644 | + newProjectHandle.open(refreshMonitor); |
| 645 | + newProjectHandle.refreshLocal(IResource.DEPTH_INFINITE, refreshMonitor); |
639 | 646 | cCorePlugin.setProjectDescription(newProjectHandle, prjCDesc, true, null);
|
640 |
| - |
641 |
| - ManagedBuildManager.getBuildInfo(newProjectHandle).setValid(true); |
642 | 647 | } catch (Exception e) {
|
643 | 648 | Common.log(new Status(IStatus.INFO, io.sloeber.core.Activator.getId(),
|
644 | 649 | "Project creation failed: " + newProjectHandle.getName(), e)); //$NON-NLS-1$
|
645 | 650 | }
|
646 |
| - |
| 651 | + Common.log(new Status(Const.SLOEBER_STATUS_DEBUG, Activator.getId(),"internal creation of project is done: "+newProjectHandle.getName())); |
647 | 652 | }
|
648 | 653 | };
|
649 | 654 |
|
650 | 655 | try {
|
651 |
| - // turn indexer off |
652 | 656 | IndexerController.doNotIndex(newProjectHandle);
|
653 |
| - workspace.run(runnable, root, IWorkspace.AVOID_UPDATE, monitor); |
654 |
| - final IProgressMonitor refreshMonitor = new NullProgressMonitor(); |
655 |
| - newProjectHandle.refreshLocal(IResource.DEPTH_INFINITE, refreshMonitor); |
656 |
| - // refreshMonitor.wait(); |
657 |
| - IndexerController.Index(newProjectHandle); |
658 |
| - } catch (CoreException e2) { |
| 657 | + op.run(monitor); |
| 658 | + } catch (InvocationTargetException | InterruptedException e) { |
659 | 659 | Common.log(new Status(IStatus.INFO, io.sloeber.core.Activator.getId(),
|
660 |
| - "Project creation failed: " + newProjectHandle.getName(),e2)); //$NON-NLS-1$ |
| 660 | + "Project creation failed: " + newProjectHandle.getName(),e)); //$NON-NLS-1$ |
661 | 661 | }
|
662 | 662 |
|
663 | 663 | monitor.done();
|
664 |
| - |
| 664 | + IndexerController.Index(newProjectHandle); |
665 | 665 | return newProjectHandle;
|
666 | 666 | }
|
667 | 667 |
|
|
0 commit comments