Skip to content

Commit

Permalink
Bad workspace init bundle example
Browse files Browse the repository at this point in the history
Bundle uses immediate service to init workspace to default location,
before prompt is even shown.

See eclipse-equinox/equinox.bundles#21
  • Loading branch information
iloveeclipse committed Apr 22, 2022
1 parent 1cd5e17 commit 7e50e68
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
11 changes: 11 additions & 0 deletions BadWorkspaceInit/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: BadWorkspaceInit
Bundle-SymbolicName: BadWorkspaceInit
Bundle-Version: 1.0.0.qualifier
Automatic-Module-Name: BadWorkspaceInit
Bundle-RequiredExecutionEnvironment: JavaSE-11
Require-Bundle: org.eclipse.core.resources,
org.eclipse.core.runtime
Service-Component: OSGI-INF/startupComponent.xml
Bundle-ActivationPolicy: lazy
4 changes: 4 additions & 0 deletions BadWorkspaceInit/OSGI-INF/startupComponent.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="start" immediate="true" name="projectLocker">
<implementation class="de.loskutov.workspace.StartupComponent"/>
</scr:component>
5 changes: 5 additions & 0 deletions BadWorkspaceInit/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
OSGI-INF/
35 changes: 35 additions & 0 deletions BadWorkspaceInit/src/de/loskutov/workspace/StartupComponent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package de.loskutov.workspace;

import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;

public class StartupComponent {

public StartupComponent() {
super();
}

public void start() {
Job job = new Job("Bad workspace init") {
@Override
protected IStatus run(IProgressMonitor monitor) {
// IContainer c = null;
// String encoding = ResourcesPlugin.getEncoding();
IWorkspace workspace = ResourcesPlugin.getWorkspace();
if(workspace == null) {
return Status.OK_STATUS;
}
String message = "Workspace is there: " + workspace;
System.err.println(message);
IStatus error = Status.error(message, new Exception("Using default workspace!!!"));
return error;
}
};
job.schedule();
}
}

0 comments on commit 7e50e68

Please sign in to comment.