Skip to content

Commit

Permalink
Enhance p2 director with "addJREIU" option.
Browse files Browse the repository at this point in the history
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 #484
  • Loading branch information
raghucssit committed Mar 19, 2024
1 parent e262a15 commit 29dc915
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.equinox.p2.director.app;singleton:=true
Bundle-Version: 1.3.300.qualifier
Bundle-Version: 1.3.400.qualifier
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.200,2.0.0)"
Bundle-RequiredExecutionEnvironment: JavaSE-17
Bundle-ActivationPolicy: lazy
Import-Package: org.bouncycastle.openpgp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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$
Expand Down Expand Up @@ -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<IInstallableUnit> installs,
Collection<IInstallableUnit> uninstalls) {
Expand Down Expand Up @@ -1058,6 +1063,10 @@ 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) {
context.setExtraInstallableUnits(List.of(JREAction.createJREIU()));
}

ProfileChangeRequest request = buildProvisioningRequest(profile, installs, uninstalls);
printRequest(request);

Expand Down Expand Up @@ -1361,6 +1370,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));
}
Expand Down Expand Up @@ -1593,6 +1607,7 @@ private static void performHelpInfo(boolean documentation) {
OPTION_TRUSTED_PGP_KEYS, //
OPTION_TRUSTED_CERTIFCATES, //
OPTION_HELP, //
OPTION_ADD_JRE_IU, //
};

for (CommandLineOption allOption : allOptions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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 a default JRE installable unit as an extra IU. This IU satisfies JRE dependencies in the case that the content metadata does not otherwise provide an IU for that purpose.
5 changes: 3 additions & 2 deletions bundles/org.eclipse.equinox.p2.publisher/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %bundleName
Bundle-SymbolicName: org.eclipse.equinox.p2.publisher;singleton:=true
Bundle-Version: 1.9.100.qualifier
Bundle-Version: 1.9.200.qualifier
Bundle-Activator: org.eclipse.equinox.internal.p2.publisher.Activator
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -95,13 +94,7 @@ private static Status newWarningStatus(String message) {
* If the jreLocation is <code>null</code>, 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$
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -296,11 +295,11 @@ private void generateJREIUData(InstallableUnitDescription iu) {

List<IProvidedCapability> 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();
Expand Down Expand Up @@ -510,4 +509,13 @@ private Map<String, String> 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());
}
}

0 comments on commit 29dc915

Please sign in to comment.