Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » Headless 'Install new Software'
Headless 'Install new Software' [message #507146] Tue, 12 January 2010 05:22 Go to next message
mirko fucci is currently offline mirko fucciFriend
Messages: 10
Registered: July 2009
Junior Member

Is it possible ?
Somebody can post the code needed to discover installable units from sites and install if they're not installed in current profile ?

Thanks.
Re: Headless 'Install new Software' [message #507197 is a reply to message #507146] Tue, 12 January 2010 13:10 Go to previous messageGo to next message
Mickael Istria is currently offline Mickael IstriaFriend
Messages: 865
Registered: July 2009
Location: Grenoble, France
Senior Member

Hello,

This page should contain everything you wanna know: http://wiki.eclipse.org/Equinox_p2_director_application

Regards,
--
Mickael Istria - BonitaSoft S.A.
http://www.bonitasoft.com/products/downloads.php
Re: Headless 'Install new Software' [message #507201 is a reply to message #507197] Tue, 12 January 2010 13:36 Go to previous messageGo to next message
mirko fucci is currently offline mirko fucciFriend
Messages: 10
Registered: July 2009
Junior Member
sorry, maybe it wasn't clear i need to perfom install new software programmatically and with no user interaction.
Re: Headless 'Install new Software' [message #507553 is a reply to message #507201] Wed, 13 January 2010 19:55 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

mirko fucci wrote:
> sorry, maybe it wasn't clear i need to perfom install new software
> programmatically and with no user interaction.

yes, that's what the director does. For a repo you can -list its
contents, and you can -list IUs in an install. You can install IUs into
your local install. It's all command line.

You would have to write the code/shell script that figured out which IUs
are new and need to be installed.

PW




--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: Headless 'Install new Software' [message #509874 is a reply to message #507553] Mon, 25 January 2010 16:16 Go to previous messageGo to next message
mirko fucci is currently offline mirko fucciFriend
Messages: 10
Registered: July 2009
Junior Member
i've found a solution, i think it's a very trivial code portion for p2 programmers but i've spent too much time to find needed informations and write it ... i'm surprised i didn't get any help.
I hope this code will be useful who need to migrate from old rcp features update to new one (p2).

package org.eclipse.equinox.p2.custom;

import java.lang.reflect.InvocationTargetException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
import org.eclipse.equinox.internal.p2.ui.PlanAnalyzer;
import org.eclipse.equinox.internal.p2.ui.ProvUIActivator;
import org.eclipse.equinox.internal.p2.ui.ProvUIMessages;
import org.eclipse.equinox.internal.p2.ui.model.ElementUtils;
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionEx ception;
import org.eclipse.equinox.internal.provisional.p2.director.Profile ChangeRequest;
import org.eclipse.equinox.internal.provisional.p2.engine.IProfile;
import org.eclipse.equinox.internal.provisional.p2.engine.IProfileR egistry;
import org.eclipse.equinox.internal.provisional.p2.engine.Provision ingContext;
import org.eclipse.equinox.internal.provisional.p2.metadata.IInstal lableUnit;
import org.eclipse.equinox.internal.provisional.p2.metadata.query.I nstallableUnitQuery;
import org.eclipse.equinox.internal.provisional.p2.metadata.reposit ory.IMetadataRepository;
import org.eclipse.equinox.internal.provisional.p2.metadata.reposit ory.IMetadataRepositoryManager;
import org.eclipse.equinox.internal.provisional.p2.query.Collector;
import org.eclipse.equinox.internal.provisional.p2.ui.IStatusCodes;
import org.eclipse.equinox.internal.provisional.p2.ui.ProvUI;
import org.eclipse.equinox.internal.provisional.p2.ui.ProvisioningO perationRunner;
import org.eclipse.equinox.internal.provisional.p2.ui.actions.Insta llAction;
import org.eclipse.equinox.internal.provisional.p2.ui.operations.Pl annerResolutionOperation;
import org.eclipse.equinox.internal.provisional.p2.ui.operations.Pr ofileModificationOperation;
import org.eclipse.equinox.p2.autoupdate.internal.Activator;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.ui.internal.WorkbenchPlugin;
import org.eclipse.ui.statushandlers.StatusManager;

@SuppressWarnings({"restriction","unchecked"})

public class HeadlessInstallNew {

private String siteAddress = "";
private String profileId = "";

private IInstallableUnit[] localUnits = null;
private IInstallableUnit[] remoteUnits = null;

public HeadlessInstallNew(String siteAddress, String profileId){
this.siteAddress = siteAddress;
this.profileId = profileId;
}

public HeadlessInstallNew(String siteAddress){
this.siteAddress = siteAddress;
//this.profileId = profileId;
}

private boolean installedNew = false;

public boolean installNewFeatures(){

IRunnableWithProgress runnable = new IRunnableWithProgress() {

public void run(IProgressMonitor monitor)
throws InvocationTargetException, InterruptedException {

loadLocalUnits(monitor);

try {

loadRemoteUnits(monitor);

} catch (ProvisionException e1) {

//e1.printStackTrace();
return;

} catch (URISyntaxException e1) {

//e1.printStackTrace();
return;
}

List featToinstall = new ArrayList();

boolean foundNew = false;

//IPlanner planner = null;
for (int i=0;i<remoteUnits.length;i++){
if (!isInstalled(remoteUnits[i])){

//planner = (IPlanner) ServiceHelper.getService(Activator.getContext(), IPlanner.class.getName());
//if (planner == null)
// return;

featToinstall.add(remoteUnits[i]);
foundNew=true;

log("NEW : " + remoteUnits[i].getId());

}
}

if (foundNew){

log("SI PROCEDE ALL'INSTALLAZIONE");

PlannerResolutionOperation resolutionOperation = null;
MultiStatus status = PlanAnalyzer.getProfileChangeAlteredStatus();

log("STEP 1");

ProfileChangeRequest request = computeProfileChangeRequest(featToinstall.toArray(), status, monitor);

log("STEP 2"+request);

ProvisioningContext provisioningContext = new ProvisioningContext();

if (request != null) {

resolutionOperation = new PlannerResolutionOperation(ProvUIMessages.ProfileModificatio nWizardPage_ResolutionOperationLabel, profileId, request, provisioningContext, status, false);

log("STEP 3");

try {

resolutionOperation.execute(monitor);
log("STEP 4");

} catch (ProvisionException e) {

log(e);

ProvUI.handleException(e, null, StatusManager.SHOW | StatusManager.LOG);
resolutionOperation = null;

//couldNotResolve = true;
IStatus status1 = new MultiStatus(ProvUIActivator.PLUGIN_ID, IStatusCodes.UNEXPECTED_NOTHING_TO_DO, "Unresolved", null);
StatusManager.getManager().handle(status1, StatusManager.LOG);

}

ProfileModificationOperation op = createProfileModificationOperation(resolutionOperation);
log("STEP 5");

try{

ProvisioningOperationRunner.schedule(op, /*StatusManager.SHOW |*/ StatusManager.LOG);

log("STEP 6");

installedNew = true;

} catch (Exception e) {

log(e);
e.printStackTrace();

}
}
}
}

};

try {

new ProgressMonitorDialog(null).run(true, true, runnable);

} catch (InvocationTargetException e) {

e.printStackTrace();
log(e);
return installedNew;

} catch (InterruptedException e) {

log(e);
return installedNew;

}

return installedNew;
}

private ProfileModificationOperation createProfileModificationOperation(PlannerResolutionOperatio n op) {
return new ProfileModificationOperation(getOperationLabel(), profileId, op.getProvisioningPlan(), op.getProvisioningContext());
}

protected ProfileChangeRequest computeProfileChangeRequest(Object[] selectedElements, MultiStatus additionalStatus, IProgressMonitor monitor) {
IInstallableUnit[] selected = ElementUtils.elementsToIUs(selectedElements);
return InstallAction.computeProfileChangeRequest(selected, profileId, additionalStatus, monitor);
}

protected String getOperationLabel() {
return ProvUIMessages.InstallIUOperationLabel;
}

private boolean isInstalled(IInstallableUnit iInstallableUnit) {
boolean found = false;
for (int i=0;i<localUnits.length;i++){
if (localUnits[i].getId().equalsIgnoreCase(iInstallableUnit.get Id())){
found=true;
}
}
return found;
}

private void loadLocalUnits(IProgressMonitor monitor) {

monitor.beginTask("Analisi delle feature installate", 20);

IProfileRegistry profileRegistry = (IProfileRegistry) ServiceHelper.getService(Activator.getContext(), IProfileRegistry.class.getName());
if (profileRegistry == null)
return;

IProfile profs[] = (IProfile[]) profileRegistry.getProfiles();
IProfile profile = profs[0];

this.profileId = profile.getProfileId();

log("PROFILE ID : " + profileId);

//profileRegistry.getProfile("SDKProfile");
//getProfile(IProfileRegistry.SELF);
//profileId
//IProfile profile = profileRegistry.getProfile(IProfileRegistry.SELF);

if (profile == null)
return;

Collector localCollector = profile.query(InstallableUnitQuery.ANY, new Collector(), null);
if (localCollector.isEmpty())
return;

localUnits = new IInstallableUnit[localCollector.size()];
Iterator it = localCollector.iterator();

int i=0;
while (it.hasNext()){
IInstallableUnit unit = (IInstallableUnit) it.next();
localUnits[i++] = unit;
if (unit.getId().endsWith("feature.group"))
log("LOCAL : " + unit.getId()+ "-" + unit.getVersion());
}


}

private void loadRemoteUnits(IProgressMonitor monitor) throws ProvisionException, URISyntaxException {

monitor.beginTask("Analisi delle feature remote", 20);

IMetadataRepositoryManager metadataRepositoryManager = getMetadataRepositoryManager();
IMetadataRepository repo = metadataRepositoryManager.loadRepository(new URI(siteAddress), null);

List list = new ArrayList();
IInstallableUnit unit = null;
Collector collector = repo.query(InstallableUnitQuery.ANY, new Collector(), null);
Iterator it = collector.iterator();
int i = 0;
while (it.hasNext()){
unit = (IInstallableUnit) it.next();
if (unit.getId().endsWith("feature.group")){
log("REMOTE " + unit.getId() + "-" + unit.getVersion());
i++;
list.add(unit);
//remoteUnits[i++]=unit;
}
}

remoteUnits = new IInstallableUnit[i];
list.toArray(remoteUnits);

}


protected static IMetadataRepositoryManager getMetadataRepositoryManager() {
return (IMetadataRepositoryManager) ServiceHelper.getService(Activator.getContext(), IMetadataRepositoryManager.class.getName());
}

private void log (Exception e){

WorkbenchPlugin.log(
new Status(Status.ERROR,
Activator.getContext().getBundle().getSymbolicName(),
Status.ERROR, e.getMessage(), e));


}
private void log (String message){

WorkbenchPlugin.log(new Status(Status.OK,
Activator.getContext().getBundle().getSymbolicName(),
Status.OK, message, null));

}
}
Re: Headless 'Install new Software' [message #512173 is a reply to message #507146] Thu, 04 February 2010 09:59 Go to previous messageGo to next message
Igor Jacy Lino Campista is currently offline Igor Jacy Lino CampistaFriend
Messages: 34
Registered: July 2009
Member
Hi,

I was looking sometime ago for something similar but was not that straight forward.

I analyzed the update sites and discover that there are P2 and non-P2 compliant sites. You can get content, site.xml and site.jar files directly from update site address.

I created an ant script that:
-Downloads the site info for a given update site.
-A simple java application that parses the xml gets the available plugins with versions. information. It generates a very simple txt file with the info.
-And if I want to, I can install headless any feature that I want independent of its version since I get the latest every time.


The installation, depending if the site is P2 or non-P2, will use the equinox or the update manager headless for the installation.


It has served me well.

Cheers,
Igor


Re: Headless 'Install new Software' [message #512379 is a reply to message #512173] Thu, 04 February 2010 19:40 Go to previous messageGo to next message
Fred Bickford IV is currently offline Fred Bickford IVFriend
Messages: 4
Registered: July 2009
Junior Member
Igor, I posted something today(before your post) that may be similar,
would you be interested in sharing your solution ?

Thanks

-Fred

Igor Jacy Lino Campista wrote:
> Hi,
>
> I was looking sometime ago for something similar but was not that
> straight forward.
>
> I analyzed the update sites and discover that there are P2 and non-P2
> compliant sites. You can get content, site.xml and site.jar files
> directly from update site address.
> I created an ant script that:
> -Downloads the site info for a given update site.
> -A simple java application that parses the xml gets the available
> plugins with versions. information. It generates a very simple txt file
> with the info.
> -And if I want to, I can install headless any feature that I want
> independent of its version since I get the latest every time.
>
>
> The installation, depending if the site is P2 or non-P2, will use the
> equinox or the update manager headless for the installation.
>
>
> It has served me well.
>
> Cheers,
> Igor
>
>
>
Re: Headless 'Install new Software' [message #1854206 is a reply to message #512379] Sat, 06 August 2022 17:32 Go to previous message
Alexey Langer is currently offline Alexey LangerFriend
Messages: 7
Registered: August 2022
Junior Member
For those still looking for an answer:

This task can be solved using the console version of the oomph installer https://github.com/a-langer/eclipse-oomph-console. It allows you to install Eclipse in headless mode (from command line) with a set of required plugins.
Previous Topic:I have problem building my application because of artifact org.eclipse.osgi not found
Next Topic:Publishing artifacts throws error
Goto Forum:
  


Current Time: Mon Oct 07 05:20:16 GMT 2024

Powered by FUDForum. Page generated in 0.04021 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top