Skip to content

Commit

Permalink
Refresh the P2 repository on reload
Browse files Browse the repository at this point in the history
One common annoyance is that if one hits the reload button for a
location in a target that then sometimes it seems nothing happens
especially if one has modified the repository shortly after using it,
for example there was an error that now is corrected or a local
repository was rebuild.

This can be fixed by
1) Edit the location
2) Hit "manage" button
3) Search for the offending site
4) Hit the "Reload" button

This then throws away some internal P2 state so the repository is
reloaded fresh.

This now changes the reload operation in a way that performs these steps
always when the user chooses to refresh an IU location.
  • Loading branch information
laeubi committed Dec 30, 2023
1 parent e2c3009 commit 44778dc
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*******************************************************************************/
package org.eclipse.pde.internal.ui.shared.target;

import java.net.URI;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
Expand All @@ -25,8 +26,15 @@
import org.eclipse.core.runtime.IAdapterFactory;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.operations.RepositoryTracker;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
import org.eclipse.equinox.p2.ui.ProvisioningUI;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.TreePath;
Expand Down Expand Up @@ -164,12 +172,60 @@ public IStatus remove(ITargetDefinition target, TreePath[] treePaths) {

@Override
public IStatus reload(ITargetDefinition target, ITargetLocation[] targetLocations, IProgressMonitor monitor) {
// delete profile
try {
// TODO might want to merge forceCheckTarget into delete Profile?
SubMonitor convert = SubMonitor.convert(monitor, 100);
// delete profile
convert.setTaskName(Messages.IUFactory_taskDeleteProfile);
P2TargetUtils.forceCheckTarget(target);
P2TargetUtils.deleteProfile(target.getHandle());
return Status.OK_STATUS;
convert.worked(25);
// refresh p2 managed caches...
IProvisioningAgent agent = P2TargetUtils.getAgent();
IArtifactRepositoryManager artifactRepositoryManager = agent.getService(IArtifactRepositoryManager.class);
IMetadataRepositoryManager metadataRepositoryManager = agent.getService(IMetadataRepositoryManager.class);
ProvisioningUI ui = ProvisioningUI.getDefaultUI();
ui.signalRepositoryOperationStart();
try {
RepositoryTracker repositoryTracker = ui.getRepositoryTracker();
convert.setTaskName(Messages.IUFactory_taskRefreshRepositories);
MultiStatus reloadStatus = new MultiStatus(IUFactory.class, 0,
Messages.IUFactory_errorRefreshRepositories);
for (ITargetLocation targetLocation : targetLocations) {
if (targetLocation instanceof IUBundleContainer iu) {
URI[] repositories = iu.getRepositories();
if (repositories != null) {
convert.setWorkRemaining(repositories.length * 2);
for (URI repositoryUri : repositories) {
repositoryTracker.clearRepositoryNotFound(repositoryUri);
try {
if (artifactRepositoryManager != null) {
artifactRepositoryManager.refreshRepository(repositoryUri, convert.split(1));
}
if (metadataRepositoryManager != null) {
metadataRepositoryManager.refreshRepository(repositoryUri, convert.split(1));
}
} catch (CoreException e) {
IStatus error = e.getStatus();
if (error.getCode() == ProvisionException.REPOSITORY_NOT_FOUND) {
repositoryTracker.addNotFound(repositoryUri);
}
reloadStatus.add(error);
}
}
}
}
}
if (reloadStatus.isOK()) {
return Status.OK_STATUS;
}
IStatus[] children = reloadStatus.getChildren();
if (children.length == 1) {
return children[0];
}
return reloadStatus;
} finally {
ui.signalRepositoryOperationComplete(null, false);
}
} catch (CoreException e) {
return e.getStatus();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ public class Messages extends NLS {
public static String IncludedBundlesTree_1;
public static String IncludedBundlesTree_2;
public static String IncludedBundlesTree_3;

public static String IUFactory_taskDeleteProfile;

public static String IUFactory_taskRefreshRepositories;

public static String IUFactory_errorRefreshRepositories;
public static String PreviewContainerPage_0;
public static String PreviewContainerPage_1;
public static String PreviewContainerPage_2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ IncludedBundlesTree_0=&Select
IncludedBundlesTree_1=&Deselect
IncludedBundlesTree_2=Select &All
IncludedBundlesTree_3=Deselec&t All
IUFactory_taskDeleteProfile=Delete Profile...
IUFactory_taskRefreshRepositories=Refresh Repositories...
IUFactory_errorRefreshRepositories=Reload Repositories failed
PreviewContainerPage_0=Operation cancelled
PreviewContainerPage_1=Preview Contents
PreviewContainerPage_2=The plug-ins found in the container are visible below
Expand Down

0 comments on commit 44778dc

Please sign in to comment.