Skip to content

Commit

Permalink
Merge pull request #20 from haubi/stabilize-targetplatform-download
Browse files Browse the repository at this point in the history
improve stability of fetching remote Target Platform
  • Loading branch information
haubi authored Mar 14, 2024
2 parents 7a82f23 + a000ce6 commit 23090fb
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,22 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.query.IQueryResult;
import org.eclipse.pde.core.target.ITargetDefinition;
import org.eclipse.pde.core.target.ITargetHandle;
import org.eclipse.pde.core.target.ITargetLocation;
import org.eclipse.pde.core.target.ITargetPlatformService;
import org.eclipse.pde.core.target.LoadTargetDefinitionJob;
import org.eclipse.pde.internal.core.target.P2TargetUtils;
import org.eclipse.tea.core.services.TaskingLog;
import org.eclipse.tea.library.build.internal.Activator;

Expand All @@ -45,7 +50,21 @@ public static Job setTargetPlatform(TaskingLog log, String tp, IProject bep, boo
}

log.debug("loading target definition");
final LoadTargetDefinitionJob job = new LoadTargetDefinitionJob(definition);
final LoadTargetDefinitionJob job = new LoadTargetDefinitionJob(definition) {

@Override
public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
IStatus result = super.runInWorkspace(monitor);
if (result == Status.OK_STATUS) {
try {
resolveTargetDefinition(getCurrentTargetDefinition(), monitor);
} catch (OperationCanceledException e) {
return Status.CANCEL_STATUS;
}
}
return result;
}
};
job.setUser(user);
job.addJobChangeListener(new JobChangeAdapter() {

Expand Down Expand Up @@ -121,4 +140,36 @@ public static ITargetPlatformService getTargetPlatformService() {
ITargetPlatformService.class.getName());
}

public static void resolveTargetDefinition(ITargetDefinition targetDefinition, IProgressMonitor mon)
throws CoreException {
for (ITargetLocation loc : targetDefinition.getTargetLocations()) {
if (!isOK(loc.getStatus())) {
// trigger the updates
loc.resolve(targetDefinition, mon);
}
}

// work around ITargetLocation.resolve() implementations not properly
// waiting for the particular resolver jobs to finish
IQueryResult<IInstallableUnit> ius = P2TargetUtils.getIUs(targetDefinition, mon);
int count[] = { 0 };
ius.forEach(i -> count[0]++);

for (ITargetLocation loc : targetDefinition.getTargetLocations()) {
if (!isOK(loc.getStatus())) {
throw new RuntimeException(
"Failed to resolve " + loc.getType() + "-type content for target definition '"
+ targetDefinition.getName() + "': " + getMessage(loc.getStatus()));
}
}

}

private static boolean isOK(IStatus status) {
return status == null ? false : status.isOK();
}

private static String getMessage(IStatus status) {
return status == null ? "no status" : status.getMessage();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import org.eclipse.pde.core.target.TargetBundle;
import org.eclipse.pde.core.target.TargetFeature;
import org.eclipse.pde.internal.build.Utils;
import org.eclipse.pde.internal.core.target.P2TargetUtils;
import org.eclipse.tea.core.services.TaskingLog;
import org.eclipse.tea.library.build.config.BuildDirectories;
import org.eclipse.tea.library.build.internal.Activator;
Expand Down Expand Up @@ -151,26 +150,9 @@ public void run(TaskingLog log, UpdateSiteManager um, WorkspaceBuild wb, JarMana

ITargetDefinition targetDefinition = TargetPlatformHelper.getCurrentTargetDefinition();

int fSize = featureLocations.size();
for (ITargetLocation loc : targetDefinition.getTargetLocations()) {
if (!isOK(loc.getStatus())) {
// trigger the updates
loc.resolve(targetDefinition, mon);
}
}

// work around ITargetLocation.resolve() implementations not properly
// waiting for the particular resolver jobs to finish
P2TargetUtils.getIUs(targetDefinition, mon);

for (ITargetLocation loc : targetDefinition.getTargetLocations()) {
if (!isOK(loc.getStatus())) {
throw new RuntimeException(
"Failed to resolve " + loc.getType() + "-type content for target definition '"
+ targetDefinition.getName() + "': " + getMessage(loc.getStatus()));
}
}
TargetPlatformHelper.resolveTargetDefinition(targetDefinition, mon);

int fSize = featureLocations.size();
for (ITargetLocation loc : targetDefinition.getTargetLocations()) {
TargetFeature[] targetFeatures = loc.getFeatures();
if (targetFeatures != null) {
Expand Down Expand Up @@ -258,14 +240,6 @@ public void run(TaskingLog log, UpdateSiteManager um, WorkspaceBuild wb, JarMana
}
}

private static boolean isOK(IStatus status) {
return status == null ? false : status.isOK();
}

private String getMessage(IStatus status) {
return status == null ? "no status" : status.getMessage();
}

/**
* Checks whether a given feature location looks like a delta-pack. A delta
* pack's feature name starts with "org.eclipse.equinox.executable".
Expand Down Expand Up @@ -319,8 +293,8 @@ private Properties readProperties(FeatureBuild feature) {
}

/**
* Computes and returns the location of the feature containing the
* newest version of executables
* Computes and returns the location of the feature containing the newest
* version of executables
*/
protected File getExecutablesDir(Set<File> deltaPacks) {
File feature = null;
Expand All @@ -344,8 +318,7 @@ protected File getExecutablesDir(Set<File> deltaPacks) {
}
}
if (feature == null) {
throw new IllegalArgumentException(
"Unable to locate executable feature '" + EXECUTABLE + "'");
throw new IllegalArgumentException("Unable to locate executable feature '" + EXECUTABLE + "'");
}
return feature;
}
Expand Down

0 comments on commit 23090fb

Please sign in to comment.