Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
EverettHanke committed Nov 13, 2024
2 parents 168d9a1 + ef694eb commit 658fc71
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 115 deletions.
1 change: 1 addition & 0 deletions org.eclipse.pde.doc.user/forceQualifierUpdate.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ Add missing reference/api content
Pick-up javadoc changes
https://github.com/eclipse-platform/eclipse.platform.releng.aggregator/pull/2396
Touch for build JVM change causing using newer jquery
Add new TargetEvents constants
22 changes: 22 additions & 0 deletions ui/org.eclipse.pde.core/.settings/.api_filters
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<component id="org.eclipse.pde.core" version="2">
<resource path="META-INF/MANIFEST.MF">
<filter id="926941240">
<message_arguments>
<message_argument value="3.20.0"/>
<message_argument value="3.19.0"/>
</message_arguments>
</filter>
</resource>
<resource path="src/org/eclipse/pde/core/target/TargetEvents.java" type="org.eclipse.pde.core.target.TargetEvents">
<filter id="336658481">
<message_arguments>
<message_argument value="org.eclipse.pde.core.target.TargetEvents"/>
<message_argument value="TOPIC_TARGET_DELETED"/>
</message_arguments>
</filter>
<filter id="336658481">
<message_arguments>
<message_argument value="org.eclipse.pde.core.target.TargetEvents"/>
<message_argument value="TOPIC_TARGET_SAVED"/>
</message_arguments>
</filter>
</resource>
<resource path="src/org/eclipse/pde/internal/core/project/BundleProjectService.java" type="org.eclipse.pde.internal.core.project.BundleProjectService">
<filter comment="Platform Team allows use of bundle importers for PDE import from source repository" id="640712815">
<message_arguments>
Expand Down
3 changes: 2 additions & 1 deletion ui/org.eclipse.pde.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %name
Bundle-SymbolicName: org.eclipse.pde.core; singleton:=true
Bundle-Version: 3.19.100.qualifier
Bundle-Version: 3.20.0.qualifier
Bundle-Activator: org.eclipse.pde.internal.core.PDECore
Bundle-Vendor: %provider-name
Bundle-Localization: plugin
Expand Down Expand Up @@ -101,6 +101,7 @@ Import-Package: aQute.bnd.build;version="[4.4.0,5.0.0)",
org.eclipse.equinox.internal.p2.publisher.eclipse,
org.eclipse.equinox.p2.publisher,
org.eclipse.equinox.p2.publisher.eclipse,
org.osgi.service.event;version="[1.4.0,2.0.0)",
org.osgi.service.repository;version="[1.1.0,2.0.0)",
org.osgi.util.promise;version="[1.3.0,2.0.0)"
Require-Bundle:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,84 @@
********************************************************************************/
package org.eclipse.pde.core.target;

import org.eclipse.e4.core.services.events.IEventBroker;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventHandler;

/**
* Target events and event topic definitions
* Target events and event topic definitions.
*
* <p>
* The following code is an example of to subscribe to the
* {@link #TOPIC_TARGET_SAVED} event:
* </p>
*
* <pre>
* EventHandler eventHandler = event -> {
* if (event.getProperty(IEventBroker.DATA) instanceof ITargetHandle handle) {
* // Work with the target handle...
* }
* };
* IEclipseContext context = EclipseContextFactory.getServiceContext(bundleContext);
* IEventBroker broker = context.get(IEventBroker.class);
* if (broker != null) {
* broker.subscribe(TargetEvents.TOPIC_TARGET_SAVED, eventHandler);
* // Do not forget to unsubscribe later!
* }
* </pre>
*
* @see ITargetPlatformService
* @see IEventBroker#subscribe(String, EventHandler)
* @see IEventBroker#subscribe(String, String, EventHandler, boolean)
* @see IEventBroker#unsubscribe(EventHandler)
* @since 3.13
*/
public class TargetEvents {

/**
* Base topic for all Target events
* Base topic for all target events.
*/
public static final String TOPIC_BASE = "org/eclipse/pde/core/target/TargetEvents"; //$NON-NLS-1$

/**
* Topic for all Target events
* Topic for all target events.
*/
public static final String TOPIC_ALL = TOPIC_BASE + "/*"; //$NON-NLS-1$

/**
* Sent when workspace target definition is changed
* Sent when workspace target definition is changed.
* <p>
* The {@link IEventBroker#DATA data} {@link Event#getProperty(String) event
* property} of events with this topic is the changed
* {@link ITargetDefinition}.
* </p>
*
* @see ITargetPlatformService#getWorkspaceTargetDefinition()
*/
public static final String TOPIC_WORKSPACE_TARGET_CHANGED = TOPIC_BASE + "/workspaceTargetChanged"; //$NON-NLS-1$

/**
* Sent when a target is saved.
* <p>
* The {@link IEventBroker#DATA data} {@link Event#getProperty(String) event
* property} of events with this topic is the saved {@link ITargetHandle}.
* </p>
*
* @see ITargetPlatformService#saveTargetDefinition(ITargetDefinition)
* @see IEventBroker
* @since 3.20
*/
public static final String TOPIC_TARGET_SAVED = TOPIC_BASE + "/targetSaved"; //$NON-NLS-1$

/**
* Sent when a target is deleted.
* <p>
* The {@link IEventBroker#DATA data} {@link Event#getProperty(String) event
* property} of events with this topic is the deleted {@link ITargetHandle}.
* </p>
*
* @see ITargetPlatformService#deleteTarget(ITargetHandle)
* @since 3.20
*/
public static final String TOPIC_TARGET_DELETED = TOPIC_BASE + "/targetDeleted"; //$NON-NLS-1$
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.pde.core.target.ITargetDefinition;
import org.eclipse.pde.core.target.ITargetHandle;
import org.eclipse.pde.core.target.TargetEvents;

/**
* Common implementation of target handles.
Expand Down Expand Up @@ -53,11 +54,16 @@ public ITargetDefinition getTargetDefinition() throws CoreException {
*/
abstract void delete() throws CoreException;

public final void save(ITargetDefinition definition) throws CoreException {
doSave(definition);
TargetPlatformService.scheduleEvent(TargetEvents.TOPIC_TARGET_SAVED, definition.getHandle());
}

/**
* Saves the definition to underlying storage.
*
* @param definition target to save
* @throws CoreException on failure
*/
abstract void save(ITargetDefinition definition) throws CoreException;
abstract void doSave(ITargetDefinition definition) throws CoreException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected InputStream getInputStream() throws CoreException {


@Override
void save(ITargetDefinition definition) throws CoreException {
void doSave(ITargetDefinition definition) throws CoreException {
try (OutputStream stream = new BufferedOutputStream(new FileOutputStream(fFile))) {
((TargetDefinition) definition).write(stream);
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ protected OutputStream getOutputStream() throws CoreException {
}

@Override
void save(ITargetDefinition definition) throws CoreException {
void doSave(ITargetDefinition definition) throws CoreException {
try (OutputStream stream = getOutputStream()) {
((TargetDefinition) definition).write(stream);
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,14 @@
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceProxy;
import org.eclipse.core.resources.IResourceProxyVisitor;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IPath;
Expand Down Expand Up @@ -100,44 +96,14 @@ public class TargetPlatformService implements ITargetPlatformService {
* The target definition currently being used as the target platform for
* the workspace.
*/
private final AtomicReference<ITargetDefinition> fWorkspaceTarget;
private final AtomicReference<ITargetDefinition> fWorkspaceTarget = new AtomicReference<>();

/**
* vm arguments for default target
*/
private StringBuilder fVMArguments;

private final EventDispatcher eventSendingJob;

/**
* Collects target files in the workspace
*/
static class ResourceProxyVisitor implements IResourceProxyVisitor {

private final List<IResource> fList;

protected ResourceProxyVisitor(List<IResource> list) {
fList = list;
}

/**
* @see org.eclipse.core.resources.IResourceProxyVisitor#visit(org.eclipse.core.resources.IResourceProxy)
*/
@Override
public boolean visit(IResourceProxy proxy) {
if (proxy.getType() == IResource.FILE) {
if (ICoreConstants.TARGET_FILE_EXTENSION.equalsIgnoreCase(IPath.fromOSString(proxy.getName()).getFileExtension())) {
fList.add(proxy.requestResource());
}
return false;
}
return true;
}
}

private TargetPlatformService() {
fWorkspaceTarget = new AtomicReference<>();
eventSendingJob = new EventDispatcher("Sending 'workspace target changed' event", TargetPlatformService.class); //$NON-NLS-1$
}

/**
Expand All @@ -160,6 +126,7 @@ public void deleteTarget(ITargetHandle handle) throws CoreException {
}
((AbstractTargetHandle) handle).delete();
TargetPlatformHelper.getTargetDefinitionMap().remove(handle);
scheduleEvent(TargetEvents.TOPIC_TARGET_DELETED, handle);
}

@Override
Expand Down Expand Up @@ -271,21 +238,23 @@ private List<ITargetHandle> findLocalTargetDefinitions() {
* @return all target definition handles in the workspace
*/
private List<WorkspaceFileTargetHandle> findWorkspaceTargetDefinitions() {
List<IResource> files = new ArrayList<>(10);
ResourceProxyVisitor visitor = new ResourceProxyVisitor(files);
List<IFile> files = new ArrayList<>(10);
try {
ResourcesPlugin.getWorkspace().getRoot().accept(visitor, IResource.NONE);
ResourcesPlugin.getWorkspace().getRoot().accept(proxy -> {
if (proxy.getType() == IResource.FILE) {
if (ICoreConstants.TARGET_FILE_EXTENSION
.equalsIgnoreCase(IPath.fromOSString(proxy.getName()).getFileExtension())) {
files.add((IFile) proxy.requestResource());
}
return false;
}
return true;
}, IResource.NONE);
} catch (CoreException e) {
PDECore.log(e);
return new ArrayList<>(0);
return List.of();
}
Iterator<IResource> iter = files.iterator();
List<WorkspaceFileTargetHandle> handles = new ArrayList<>(files.size());
while (iter.hasNext()) {
IFile file = (IFile) iter.next();
handles.add(new WorkspaceFileTargetHandle(file));
}
return handles;
return files.stream().map(WorkspaceFileTargetHandle::new).toList();
}

@Override
Expand Down Expand Up @@ -361,71 +330,24 @@ public synchronized ITargetDefinition getWorkspaceTargetDefinition() throws Core
*/
public void setWorkspaceTargetDefinition(ITargetDefinition target, boolean asyncEvents) {
ITargetDefinition oldTarget = fWorkspaceTarget.getAndSet(target);
boolean changed = !Objects.equals(oldTarget, target);
if (changed) {
if (asyncEvents) {
eventSendingJob.schedule(target);
} else {
notifyTargetChanged(target);
}
if (!Objects.equals(oldTarget, target)) {
notifyEvent(TargetEvents.TOPIC_WORKSPACE_TARGET_CHANGED, target, asyncEvents);
}
}

static void notifyTargetChanged(ITargetDefinition target) {
public static void scheduleEvent(String topic, Object data) {
notifyEvent(topic, data, true);
}

private static void notifyEvent(String topic, Object data, boolean asyncEvents) {
IEclipseContext context = EclipseContextFactory.getServiceContext(PDECore.getDefault().getBundleContext());
IEventBroker broker = context.get(IEventBroker.class);
if (broker != null) {
broker.send(TargetEvents.TOPIC_WORKSPACE_TARGET_CHANGED, target);
}
}

static class EventDispatcher extends Job {

private final ConcurrentLinkedQueue<ITargetDefinition> queue;
private final Object myFamily;

/**
* @param jobName
* descriptive job name
* @param family
* non null object to control this job execution
**/
public EventDispatcher(String jobName, Object family) {
super(jobName);
Assert.isNotNull(family);
this.myFamily = family;
this.queue = new ConcurrentLinkedQueue<>();
setSystem(true);
}

@Override
public boolean belongsTo(Object family) {
return myFamily == family;
}

@Override
protected IStatus run(IProgressMonitor monitor) {
ITargetDefinition target;
while ((target = queue.poll()) != null && !monitor.isCanceled()) {
notifyTargetChanged(target);
}
if (!queue.isEmpty() && !monitor.isCanceled()) {
// in case actions got faster scheduled then processed
schedule();
}
if (monitor.isCanceled()) {
queue.clear();
return Status.CANCEL_STATUS;
if (asyncEvents) {
broker.post(topic, data);
} else {
broker.send(topic, data);
}
return Status.OK_STATUS;
}

/**
* Enqueue a task asynchronously.
**/
public void schedule(ITargetDefinition target) {
queue.offer(target);
schedule(); // will reschedule if already running
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public String getMemento() throws CoreException {
}

@Override
public void save(ITargetDefinition definition) throws CoreException {
void doSave(ITargetDefinition definition) throws CoreException {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
((TargetDefinition) definition).write(outputStream);
ByteArrayInputStream stream = new ByteArrayInputStream(outputStream.toByteArray());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,7 @@ private IBuildModel getBuildModel() {

public void initialize() {
getBuildModel().addModelChangedListener(this);
IBuildEntry entry = getBuildModel().getBuild().getEntry(IBuildPropertiesConstants.PROPERTY_JAR_EXTRA_CLASSPATH);
getSection().setExpanded(entry != null && entry.getTokens().length > 0);
getSection().setExpanded(true);
}

@Override
Expand Down
Loading

0 comments on commit 658fc71

Please sign in to comment.