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 eclipse-equinox#484
  • Loading branch information
Raghunandana Murthappa authored and raghucssit committed Mar 18, 2024
1 parent 041c27e commit bb299b1
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
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,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<IInstallableUnit> extraUnits = new ArrayList<>();
IInstallableUnit jreiU = JREAction.createJreIU();
extraUnits.add(jreiU);
context.setExtraInstallableUnits(extraUnits);
}

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

Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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) {
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 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.
Original file line number Diff line number Diff line change
Expand Up @@ -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 bb299b1

Please sign in to comment.