From bb299b1a08f1265d1b63e64fb8743aabde77f722 Mon Sep 17 00:00:00 2001 From: Raghunandana Murthappa Date: Mon, 18 Mar 2024 11:38:34 +0100 Subject: [PATCH] Enhance p2 director with "addJREIU" option. P2 Director Application fails to install some of the bundles which has requirements on Java-SE 21. The reason for this issue was missing java profile dependency during installation. This new option includes Jre IU as an extra installable Unit.- Fixes https://github.com/eclipse-equinox/p2/issues/484 --- .../META-INF/MANIFEST.MF | 3 +- .../p2/director/app/DirectorApplication.java | 18 ++++++++++ .../internal/p2/director/app/Messages.java | 2 ++ .../p2/director/app/messages.properties | 3 +- .../META-INF/MANIFEST.MF | 3 +- .../p2/publisher/actions/JREAction.java | 34 ++++++++++++------- 6 files changed, 47 insertions(+), 16 deletions(-) diff --git a/bundles/org.eclipse.equinox.p2.director.app/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.director.app/META-INF/MANIFEST.MF index 6f718cfbc1..238da64ceb 100644 --- a/bundles/org.eclipse.equinox.p2.director.app/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.p2.director.app/META-INF/MANIFEST.MF @@ -7,7 +7,8 @@ Bundle-Activator: org.eclipse.equinox.internal.p2.director.app.Activator Bundle-Vendor: %providerName Bundle-Localization: plugin Export-Package: org.eclipse.equinox.internal.p2.director.app;x-internal:=true -Require-Bundle: org.eclipse.equinox.common;bundle-version="[3.5.0,4.0.0)" +Require-Bundle: org.eclipse.equinox.common;bundle-version="[3.5.0,4.0.0)", + org.eclipse.equinox.p2.publisher;bundle-version="1.9.100" Bundle-RequiredExecutionEnvironment: JavaSE-17 Bundle-ActivationPolicy: lazy Import-Package: org.bouncycastle.openpgp, diff --git a/bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/DirectorApplication.java b/bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/DirectorApplication.java index 17e3400b36..dfed906564 100644 --- a/bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/DirectorApplication.java +++ b/bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/DirectorApplication.java @@ -59,6 +59,7 @@ import org.eclipse.equinox.p2.metadata.VersionRange; import org.eclipse.equinox.p2.planner.IPlanner; import org.eclipse.equinox.p2.planner.IProfileChangeRequest; +import org.eclipse.equinox.p2.publisher.actions.JREAction; import org.eclipse.equinox.p2.query.*; import org.eclipse.equinox.p2.repository.IRepository; import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager; @@ -421,6 +422,9 @@ private String escape(String string) { private static final CommandLineOption OPTION_IGNORED = new CommandLineOption(new String[] { // "-showLocation", "-eclipse.password", "-eclipse.keyring" }, //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$ null, ""); //$NON-NLS-1$ + private static final CommandLineOption OPTION_ADD_JRE_IU = new CommandLineOption(new String[] { // + "-addJREIU" }, //$NON-NLS-1$ + null, Messages.Help_Add_Jre_IU); private static final Integer EXIT_ERROR = 13; static private final String FLAVOR_DEFAULT = "tooling"; //$NON-NLS-1$ @@ -579,6 +583,7 @@ private static File processFileArgument(String arg) { private boolean targetAgentIsSelfAndUp; private boolean noArtifactRepositorySpecified; private AvoidTrustPromptService trustService; + private boolean addJreIU; protected ProfileChangeRequest buildProvisioningRequest(IProfile profile, Collection installs, Collection uninstalls) { @@ -1058,6 +1063,13 @@ private void performProvisioningActions() throws CoreException { context.setProperty(ProvisioningContext.FOLLOW_REPOSITORY_REFERENCES, String.valueOf(followReferences)); context.setProperty(FOLLOW_ARTIFACT_REPOSITORY_REFERENCES, String.valueOf(followReferences)); + if (addJreIU) { + List extraUnits = new ArrayList<>(); + IInstallableUnit jreiU = JREAction.createJreIU(); + extraUnits.add(jreiU); + context.setExtraInstallableUnits(extraUnits); + } + ProfileChangeRequest request = buildProvisioningRequest(profile, installs, uninstalls); printRequest(request); @@ -1361,6 +1373,11 @@ public void processArguments(String[] args) throws CoreException { continue; } + if (OPTION_ADD_JRE_IU.isOption(opt)) { + this.addJreIU = true; + continue; + } + if (opt != null && opt.length() > 0) throw new ProvisionException(NLS.bind(Messages.unknown_option_0, opt)); } @@ -1593,6 +1610,7 @@ private static void performHelpInfo(boolean documentation) { OPTION_TRUSTED_PGP_KEYS, // OPTION_TRUSTED_CERTIFCATES, // OPTION_HELP, // + OPTION_ADD_JRE_IU, // }; for (CommandLineOption allOption : allOptions) { diff --git a/bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/Messages.java b/bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/Messages.java index 058cdaa447..0f1f5738b5 100644 --- a/bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/Messages.java +++ b/bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/Messages.java @@ -117,6 +117,8 @@ public class Messages extends NLS { public static String Cant_write_in_destination; + public static String Help_Add_Jre_IU; + static { // initialize resource bundle NLS.initializeMessages(BUNDLE_NAME, Messages.class); diff --git a/bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/messages.properties b/bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/messages.properties index d325a38518..e80e0baa41 100644 --- a/bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/messages.properties +++ b/bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/messages.properties @@ -88,4 +88,5 @@ File_does_not_exist=File does not exist: {0}. Cannot_set_iu_profile_property_iu_does_not_exist=Unable to set IU profile properties because the following IU does not exist: {0}. Unmatched_iu_profile_property_key_value=Unmatched IU profile property key/value pair: {0}. Bad_format=Bad format ({0}) in IU profile properties file: {1}. -Cant_write_in_destination=The operation you've requested can not be performed because the folder {0} is read only. \ No newline at end of file +Cant_write_in_destination=The operation you've requested can not be performed because the folder {0} is read only. +Help_Add_Jre_IU=Include Default JRE Installable Unit as an extra installable Unit. This IU acts as dependency for actual IU's being installed does not install/provide JRE artifact. \ No newline at end of file diff --git a/bundles/org.eclipse.equinox.p2.publisher/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.publisher/META-INF/MANIFEST.MF index 7ec0c10cd6..752ad6aa40 100644 --- a/bundles/org.eclipse.equinox.p2.publisher/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.p2.publisher/META-INF/MANIFEST.MF @@ -20,7 +20,8 @@ Export-Package: org.eclipse.equinox.internal.p2.publisher; org.eclipse.equinox.p2.publisher.actions; x-friends:="org.eclipse.equinox.p2.updatesite, org.eclipse.equinox.p2.directorywatcher, - org.eclipse.equinox.p2.publisher.eclipse", + org.eclipse.equinox.p2.publisher.eclipse, + org.eclipse.equinox.p2.director.app", org.eclipse.equinox.spi.p2.publisher;x-friends:="org.eclipse.equinox.p2.updatesite,org.eclipse.equinox.p2.publisher.eclipse" Require-Bundle: org.eclipse.equinox.common;bundle-version="[3.18.0,4.0.0)", org.eclipse.osgi;bundle-version="3.8.0" diff --git a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/actions/JREAction.java b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/actions/JREAction.java index 269276d92e..3c518b5b8e 100644 --- a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/actions/JREAction.java +++ b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/actions/JREAction.java @@ -70,8 +70,7 @@ public JREAction(String environment) { @Override public IStatus perform(IPublisherInfo publisherInfo, IPublisherResult results, IProgressMonitor monitor) { String problemMessage = NLS.bind(Messages.message_problemsWhilePublishingEE, jreLocation != null ? jreLocation : environment); resultStatus = new MultiStatus(Activator.ID, 0, problemMessage, null); - - initialize(publisherInfo); + this.info = publisherInfo; IArtifactDescriptor artifact = createJREData(results); if (artifact != null) publishArtifact(artifact, new File[] {jreLocation}, null, publisherInfo, createRootPrefixComputer(jreLocation)); @@ -95,13 +94,7 @@ private static Status newWarningStatus(String message) { * If the jreLocation is null, default information is generated. */ protected IArtifactDescriptor createJREData(IPublisherResult results) { - InstallableUnitDescription iu = new MetadataFactory.InstallableUnitDescription(); - iu.setSingleton(false); - iu.setId(DEFAULT_JRE_NAME); - iu.setVersion(DEFAULT_JRE_VERSION); - iu.setTouchpointType(PublisherHelper.TOUCHPOINT_NATIVE); - - generateJREIUData(iu); + InstallableUnitDescription iu = generateJREIUDesc(); InstallableUnitFragmentDescription cu = new InstallableUnitFragmentDescription(); String configId = "config." + iu.getId();//$NON-NLS-1$ @@ -256,9 +249,15 @@ private static String[] parseEECapabilityVersion(ManifestElement eeCapability, M } } - private void generateJREIUData(InstallableUnitDescription iu) { + private InstallableUnitDescription generateJREIUDesc() { + InstallableUnitDescription iu = new MetadataFactory.InstallableUnitDescription(); + iu.setSingleton(false); + iu.setId(DEFAULT_JRE_NAME); + iu.setVersion(DEFAULT_JRE_VERSION); + iu.setTouchpointType(PublisherHelper.TOUCHPOINT_NATIVE); + initialize(); if (profileProperties == null || profileProperties.size() == 0) - return; //got nothing + return iu; String profileLocation = profileProperties.get(PROFILE_LOCATION); @@ -296,11 +295,11 @@ private void generateJREIUData(InstallableUnitDescription iu) { List capabilities = generateJRECapability(iu.getId(), iu.getVersion()); iu.addProvidedCapabilities(capabilities); + return iu; } - private void initialize(IPublisherInfo publisherInfo) { + private void initialize() { File runtimeProfile = null; - this.info = publisherInfo; if (jreLocation == null && environment == null) { // create a runtime profile StringBuilder buffer = createDefaultProfileFromRunningJvm(); @@ -510,4 +509,13 @@ private Map loadProfile(InputStream stream) { } return null; } + + public static IInstallableUnit createJreIU() { + JREAction jreAction = new JREAction((File) null); + return jreAction.createJreInstallableUnit(); + } + + private IInstallableUnit createJreInstallableUnit() { + return MetadataFactory.createInstallableUnit(generateJREIUDesc()); + } }