From a000ce63b50363081a17eb85444e42f272c04da8 Mon Sep 17 00:00:00 2001 From: Michael Haubenwallner Date: Thu, 14 Mar 2024 09:56:00 +0100 Subject: [PATCH] WIP: improve stability of fetching remote Target Platform --- .../build/p2/TargetPlatformHelper.java | 53 ++++++++++++++++++- .../p2/TaskPublishProductUpdateSite.java | 37 ++----------- 2 files changed, 57 insertions(+), 33 deletions(-) diff --git a/bundles/org.eclipse.tea.library.build/src/org/eclipse/tea/library/build/p2/TargetPlatformHelper.java b/bundles/org.eclipse.tea.library.build/src/org/eclipse/tea/library/build/p2/TargetPlatformHelper.java index 44b9154..28a1ef2 100644 --- a/bundles/org.eclipse.tea.library.build/src/org/eclipse/tea/library/build/p2/TargetPlatformHelper.java +++ b/bundles/org.eclipse.tea.library.build/src/org/eclipse/tea/library/build/p2/TargetPlatformHelper.java @@ -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; @@ -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() { @@ -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 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(); + } } diff --git a/bundles/org.eclipse.tea.library.build/src/org/eclipse/tea/library/build/tasks/p2/TaskPublishProductUpdateSite.java b/bundles/org.eclipse.tea.library.build/src/org/eclipse/tea/library/build/tasks/p2/TaskPublishProductUpdateSite.java index 2ad147d..4f69fa5 100644 --- a/bundles/org.eclipse.tea.library.build/src/org/eclipse/tea/library/build/tasks/p2/TaskPublishProductUpdateSite.java +++ b/bundles/org.eclipse.tea.library.build/src/org/eclipse/tea/library/build/tasks/p2/TaskPublishProductUpdateSite.java @@ -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; @@ -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) { @@ -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". @@ -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 deltaPacks) { File feature = null; @@ -344,8 +318,7 @@ protected File getExecutablesDir(Set deltaPacks) { } } if (feature == null) { - throw new IllegalArgumentException( - "Unable to locate executable feature '" + EXECUTABLE + "'"); + throw new IllegalArgumentException("Unable to locate executable feature '" + EXECUTABLE + "'"); } return feature; }