Skip to content

Commit

Permalink
New Workspace Wizard and after creation synchronization
Browse files Browse the repository at this point in the history
---
 Signed-off-by: Peter Kriens <[email protected]>

Signed-off-by: Peter Kriens <[email protected]>
  • Loading branch information
pkriens committed Apr 3, 2024
1 parent 4a8a869 commit d8f49e8
Show file tree
Hide file tree
Showing 11 changed files with 1,436 additions and 15 deletions.
25 changes: 22 additions & 3 deletions bndtools.core/_plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
<startupParticipant
class="bndtools.javasearch.JavaSearchStartupParticipant" />
</extension>
<extension point="org.eclipse.ui.startup">
<startup
class="bndtools.central.Starter" />
</extension>

<!-- EDITORS -->
<extension point="org.eclipse.ui.editors">
Expand Down Expand Up @@ -143,14 +147,29 @@
preferredPerspectives="bndtools.perspective" icon="icons/bricks.png"
name="Bnd OSGi Project" project="true">
</wizard>
<wizard id="bndtools.workspaceWizard"
<wizard id="bndtools.workspaceWizard"
category="bndtools.wizardCategory"
class="bndtools.wizards.newworkspace.NewWorkspaceWizard"
finalPerspective="bndtools.perspective"
preferredPerspectives="bndtools.perspective"
icon="icons/bndtools-logo-16x16.png" name="New bnd workspace">
<description>
Creates a new bnd workspace. You will be able to select template fragments
that will define the new workspace. At finish, you can switch to the new
workspace.
</description>
</wizard>
<wizard id="bndtools.workspaceWizardDeprecated"
category="bndtools.wizardCategory"
class="bndtools.wizards.workspace.WorkspaceSetupWizard"
finalPerspective="bndtools.perspective"
preferredPerspectives="bndtools.perspective"
icon="icons/bndtools-logo-16x16.png" name="Bnd OSGi Workspace"
project="true">
icon="icons/bndtools-logo-16x16.png" name="Bnd OSGi Workspace (Deprecated)">
<description>
Old style workspace creation, will be deprecated in a coming release.
</description>
</wizard>

<category id="bndtools.serviceWizardCategory" name="OSGi Services" />
<wizard id="bndtools.newServiceWiz"
category="bndtools.serviceWizardCategory"
Expand Down
8 changes: 5 additions & 3 deletions bndtools.core/bnd.bnd
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ Export-Package: org.osgi.service.metatype.annotations
org.eclipse.core.runtime,\
org.eclipse.jface,\
org.eclipse.jface.text,\
org.eclipse.compare;version=latest,\
org.eclipse.compare.core;version=latest,\
org.eclipse.compare;version=latest,\
org.eclipse.compare.core;version=latest,\
org.eclipse.core.resources,\
org.eclipse.swt,\
org.eclipse.swt.cocoa.macosx.x86_64,\
Expand Down Expand Up @@ -116,7 +116,9 @@ Export-Package: org.osgi.service.metatype.annotations
org.eclipse.e4.core.services,\
org.osgi.service.event,\
org.eclipse.jdt.annotation,\
org.apache.felix.gogo.runtime;version=1.1.6
org.apache.felix.gogo.runtime;version='1.1.6',\
org.eclipse.jgit,\
org.eclipse.egit.core

-testpath: \
slf4j.api,\
Expand Down
70 changes: 64 additions & 6 deletions bndtools.core/src/bndtools/central/Central.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,20 @@
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IPerspectiveDescriptor;
import org.eclipse.ui.IPerspectiveRegistry;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.intro.IIntroManager;
import org.eclipse.ui.intro.IIntroPart;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
Expand Down Expand Up @@ -72,6 +81,7 @@
import aQute.service.reporter.Reporter;
import bndtools.Plugin;
import bndtools.central.RepositoriesViewRefresher.RefreshModel;
import bndtools.central.sync.WorkspaceSynchronizer;
import bndtools.preferences.BndPreferences;

public class Central implements IStartupParticipant {
Expand All @@ -88,6 +98,7 @@ public class Central implements IStartupParticipant {

private static final Supplier<EclipseWorkspaceRepository> eclipseWorkspaceRepository = Memoize
.supplier(EclipseWorkspaceRepository::new);
private final static AtomicBoolean syncing = new AtomicBoolean();

private static Auxiliary auxiliary;

Expand All @@ -96,7 +107,6 @@ public class Central implements IStartupParticipant {
private final BundleContext bundleContext;
private final Map<IJavaProject, Project> javaProjectToModel = new HashMap<>();
private final List<ModelListener> listeners = new CopyOnWriteArrayList<>();

private RepositoryListenerPluginTracker repoListenerTracker;
private final InternalPluginTracker internalPlugins;

Expand Down Expand Up @@ -135,7 +145,6 @@ public Central() {
@Override
public void start() {
instance = this;

repoListenerTracker = new RepositoryListenerPluginTracker(bundleContext);
repoListenerTracker.open();
internalPlugins.open();
Expand Down Expand Up @@ -416,9 +425,58 @@ private static File getWorkspaceDirectory() throws CoreException {
.getParentFile();
}

String path = Platform.getInstanceLocation()
.getURL()
.getPath();

if (IO.isWindows() && path.startsWith("/"))
path = path.substring(1);

File folder = new File(path);
File build = IO.getFile(folder, "cnf/build.bnd");
if (build.isFile()) {
if (syncing.getAndSet(true) == false) {
Job job = Job.create("sync ws", mon -> {
WorkspaceSynchronizer wss = new WorkspaceSynchronizer();
wss.synchronize(false, mon, () -> {
syncing.set(false);
});
setBndtoolsPerspective();
final IIntroManager introManager = PlatformUI.getWorkbench()
.getIntroManager();
IIntroPart part = introManager.getIntro();
introManager.closeIntro(part);
});
job.schedule();
}
return folder;
}

return null;
}

public static void setBndtoolsPerspective() {
Display.getDefault()
.syncExec(() -> {
IWorkbenchWindow window = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow();
if (window != null) {
IWorkbenchPage page = window.getActivePage();
IPerspectiveRegistry reg = PlatformUI.getWorkbench()
.getPerspectiveRegistry();
// Replace "your.perspective.id" with the
// actual ID
// of
// the perspective you want to switch to
IPerspectiveDescriptor bndtools = reg.findPerspectiveWithId("bndtools.perspective");
if (bndtools != null)
page.setPerspective(bndtools);

return;
}
});
}

/**
* Determine if the given directory is a workspace.
*
Expand Down Expand Up @@ -700,8 +758,8 @@ public static IResource toResource(File file) {
* @throws Exception If the callable throws an exception.
*/
public static <V> V bndCall(BiFunctionWithException<Callable<V>, BooleanSupplier, V> lockMethod,
FunctionWithException<BiConsumer<String, RunnableWithException>, V> callable,
IProgressMonitor monitorOrNull) throws Exception {
FunctionWithException<BiConsumer<String, RunnableWithException>, V> callable, IProgressMonitor monitorOrNull)
throws Exception {
IProgressMonitor monitor = monitorOrNull == null ? new NullProgressMonitor() : monitorOrNull;
Task task = new Task() {
@Override
Expand All @@ -728,14 +786,14 @@ public void abort() {
try {
Callable<V> with = () -> TaskManager.with(task, () -> callable.apply((name, runnable) -> after.add(() -> {
monitor.subTask(name);
try {
try {
runnable.run();
} catch (Exception e) {
if (!(e instanceof OperationCanceledException)) {
status.add(new Status(IStatus.ERROR, runnable.getClass(),
"Unexpected exception in bndCall after action: " + name, e));
}
}
}
})));
return lockMethod.apply(with, monitor::isCanceled);
} finally {
Expand Down
15 changes: 15 additions & 0 deletions bndtools.core/src/bndtools/central/Starter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package bndtools.central;

import org.eclipse.ui.IStartup;

public class Starter implements IStartup {

@Override
public void earlyStartup() {
try {
Central.getWorkspace();
} catch (Exception e) {
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
* with the file system. Any deltas are processed by creating or deleting the
* project.
*/
@Component(enabled = false)
@Component(enabled = true)
public class SynchronizeWorkspaceWithEclipse {
static IWorkspace eclipse = ResourcesPlugin.getWorkspace();
final static IWorkspaceRoot root = eclipse.getRoot();
Expand Down Expand Up @@ -86,8 +86,6 @@ private void sync(Collection<Project> doNotUse) {
return;
}

// No need to turn off autobuild as the lock will take care of it

Job sync = Job.create("sync workspace", (IProgressMonitor monitor) -> {

Map<String, IProject> projects = Stream.of(root.getProjects())
Expand Down
1 change: 1 addition & 0 deletions bndtools.core/src/bndtools/perspective/BndPerspective.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public void createInitialLayout(IPageLayout layout) {
// new actions - Java project creation wizard
layout.addNewWizardShortcut(PartConstants.WIZARD_ID_NEWPROJECT);
layout.addNewWizardShortcut(PartConstants.WIZARD_ID_NEWWORKSPACE);
layout.addNewWizardShortcut(PartConstants.WIZARD_ID_NEWWORKSPACE + "Deprecated");
layout.addNewWizardShortcut(PartConstants.WIZARD_ID_NEWBNDRUN);
layout.addNewWizardShortcut(PartConstants.WIZARD_ID_NEWBND);
layout.addNewWizardShortcut(PartConstants.WIZARD_ID_NEWBLUEPRINT_XML);
Expand Down
Loading

0 comments on commit d8f49e8

Please sign in to comment.