Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bundles/org.eclipse.equinox.p2.ui.sdk/plugin.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Update.command=Check for Updates
Update.command.mnemonic=U
Install.command=Install New Software...
Install.command.mnemonic=S
InstallSources.command=Install Sources
InstallSources.command.mnemonic=o
InstallationDetails.command=Installation Details
InstallationDetails.command.mnemonic=I
TempInstallView.command=Installation Information
Expand Down
18 changes: 18 additions & 0 deletions bundles/org.eclipse.equinox.p2.ui.sdk/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
name="%Install.command"
id="org.eclipse.equinox.p2.ui.sdk.install">
</command>
<command
name="%InstallSources.command"
id="org.eclipse.equinox.p2.ui.sdk.installSources">
</command>
<command
defaultHandler="org.eclipse.ui.internal.about.InstallationHandler"
id="org.eclipse.equinox.p2.ui.sdk.installationDetails"
Expand All @@ -70,6 +74,10 @@
commandId="org.eclipse.equinox.p2.ui.sdk.install"
class="org.eclipse.equinox.internal.p2.ui.sdk.InstallNewSoftwareHandler">
</handler>
<handler
commandId="org.eclipse.equinox.p2.ui.sdk.installSources"
class="org.eclipse.equinox.internal.p2.ui.sdk.InstallSourcesHandler">
</handler>
</extension>
<extension
point="org.eclipse.ui.menus">
Expand All @@ -93,6 +101,16 @@
</command>

</menuContribution>
<menuContribution
locationURI="menu:help?after=org.eclipse.equinox.p2.ui.sdk.install">
<command
commandId="org.eclipse.equinox.p2.ui.sdk.installSources"
mnemonic="%InstallSources.command.mnemonic"
id="org.eclipse.equinox.p2.ui.sdk.installSources"
icon="icons/obj/iu_obj.svg">
</command>

</menuContribution>
</extension>

<extension
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/*******************************************************************************
* Copyright (c) 2025 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Contributors - initial API and implementation
*******************************************************************************/
package org.eclipse.equinox.internal.p2.ui.sdk;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.runtime.*;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.equinox.internal.p2.director.ProfileChangeRequest;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.engine.*;
import org.eclipse.equinox.p2.operations.*;
import org.eclipse.equinox.p2.ui.ProvisioningUI;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.statushandlers.StatusManager;

/**
* InstallSourcesHandler toggles the installation of source bundles.
* When enabled, it sets the org.eclipse.update.install.sources profile property
* to "true" and triggers an update operation to fetch missing sources.
* When disabled, it sets the property to "false".
*
* @since 3.5
*/
public class InstallSourcesHandler extends AbstractHandler {

private static final String INSTALL_SOURCES_PROPERTY = "org.eclipse.update.install.sources"; //$NON-NLS-1$

@Override
public Object execute(ExecutionEvent event) {
// Get the provisioning UI and check for a valid profile
ProvisioningUI provUI = getProvisioningUI();
String profileId = provUI.getProfileId();
IProvisioningAgent agent = provUI.getSession().getProvisioningAgent();
IProfile profile = null;

if (agent != null) {
IProfileRegistry registry = agent.getService(IProfileRegistry.class);
if (registry != null) {
profile = registry.getProfile(profileId);
}
}

if (profile == null) {
MessageDialog.openInformation(null, ProvSDKMessages.Handler_SDKUpdateUIMessageTitle,
ProvSDKMessages.Handler_CannotLaunchUI);
StatusManager.getManager().handle(ProvSDKUIActivator.getNoSelfProfileStatus());
return null;
}

// Toggle the install sources property
String currentValue = profile.getProperty(INSTALL_SOURCES_PROPERTY);
boolean installSources = !"true".equals(currentValue); //$NON-NLS-1$

// Create a profile change request to set the property
ProfileChangeRequest request = new ProfileChangeRequest(profile);
request.setProfileProperty(INSTALL_SOURCES_PROPERTY, String.valueOf(installSources));

// Create and execute a provisioning operation
ProvisioningJob job = new ProvisioningJob(ProvSDKMessages.InstallSourcesHandler_JobName,
provUI.getSession()) {

@Override
public IStatus runModal(IProgressMonitor monitor) {
SubMonitor sub = SubMonitor.convert(monitor, ProvSDKMessages.InstallSourcesHandler_ProgressTaskName, 100);

try {
// Apply the profile property change
IPlanner planner = provUI.getSession().getPlanner();
IEngine engine = provUI.getSession().getEngine();

ProvisioningContext context = new ProvisioningContext(agent);
IProvisioningPlan plan = planner.getProvisioningPlan(request, context, sub.newChild(30));

if (plan.getStatus().isOK()) {
IStatus result = engine.perform(plan, sub.newChild(70));
if (result.isOK()) {
// If we enabled install sources, trigger an update to fetch missing sources
if (installSources) {
PlatformUI.getWorkbench().getDisplay().asyncExec(() -> {
MessageDialog.openInformation(PlatformUI.getWorkbench().getModalDialogShellProvider().getShell(),
ProvSDKMessages.InstallSourcesHandler_EnabledTitle,
ProvSDKMessages.InstallSourcesHandler_EnabledMessage);
// Trigger an update operation to fetch sources
triggerUpdateForSources(provUI);
});
} else {
PlatformUI.getWorkbench().getDisplay().asyncExec(() -> {
MessageDialog.openInformation(PlatformUI.getWorkbench().getModalDialogShellProvider().getShell(),
ProvSDKMessages.InstallSourcesHandler_DisabledTitle,
ProvSDKMessages.InstallSourcesHandler_DisabledMessage);
});
}
}
return result;
} else {
return plan.getStatus();
}
} finally {
sub.done();
}
}
};

job.setUser(true);
job.schedule();

return null;
}

/**
* Triggers an update operation to fetch missing source bundles
*/
private void triggerUpdateForSources(ProvisioningUI provUI) {
UpdateOperation op = provUI.getUpdateOperation(null, null);

Job updateJob = new Job(ProvSDKMessages.InstallSourcesHandler_UpdateJobName) {
@Override
protected IStatus run(IProgressMonitor monitor) {
IStatus result = op.resolveModal(monitor);
if (result.isOK() && op.hasResolved()) {
// Schedule the provisioning job
ProvisioningJob provJob = op.getProvisioningJob(monitor);
if (provJob != null) {
provJob.schedule();
}
}
return Status.OK_STATUS;
}
};
updateJob.setUser(true);
updateJob.schedule();
}

protected ProvisioningUI getProvisioningUI() {
return ProvisioningUI.getDefaultUI();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,12 @@ public class ProvSDKMessages extends NLS {
public static String TrustPreferencePage_TrustAllYes;
public static String TrustPreferencePage_TypeColumn;
public static String TrustPreferencePage_ValidityColumn;
public static String InstallSourcesHandler_DisabledMessage;
public static String InstallSourcesHandler_DisabledTitle;
public static String InstallSourcesHandler_EnabledMessage;
public static String InstallSourcesHandler_EnabledTitle;
public static String InstallSourcesHandler_JobName;
public static String InstallSourcesHandler_ProgressTaskName;
public static String InstallSourcesHandler_UpdateJobName;

}
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,10 @@ TrustPreferencePage_TrustAllNo=No, Prompt Me Instead
TrustPreferencePage_TrustAllYes=Yes, I Accept the Risk
TrustPreferencePage_TypeColumn=Type
TrustPreferencePage_ValidityColumn=Validity Dates
InstallSourcesHandler_DisabledMessage=Source bundle installation has been disabled. Source bundles will not be automatically installed.
InstallSourcesHandler_DisabledTitle=Install Sources Disabled
InstallSourcesHandler_EnabledMessage=Source bundle installation has been enabled. An update will be performed to fetch missing source bundles.
InstallSourcesHandler_EnabledTitle=Install Sources Enabled
InstallSourcesHandler_JobName=Toggling source bundle installation
InstallSourcesHandler_ProgressTaskName=Updating source installation preference...
InstallSourcesHandler_UpdateJobName=Fetching source bundles...