Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » P2 » Configure a p2 update repository programmatically [RESOLVED]
Configure a p2 update repository programmatically [RESOLVED] [message #547260] Fri, 16 July 2010 07:00 Go to next message
Daniel Murygin is currently offline Daniel MuryginFriend
Messages: 12
Registered: July 2010
Junior Member
There is an article in the Eclipse wiki how to configure user's p2 default repositories of an RCP application by adding a static conf file to your product:

Adding Self-Update to an RCP Application - Configuring the user's default repositories

I want to do the same programmatically in a Java class when the user changes some configuration details. I could not find appropriate p2 API documentation for that.

[Updated on: Tue, 20 July 2010 07:54]

Report message to a moderator

Re: Configure a p2 update repository programmatically [message #547874 is a reply to message #547260] Tue, 20 July 2010 00:32 Go to previous messageGo to next message
Michael Yara is currently offline Michael YaraFriend
Messages: 27
Registered: July 2009
Junior Member
Daniel,

Here is the code I use to load a Repository from a URI into the manager. repoLocation is an instance of URI. Hopefully this helps.

	
				//Load repository manager
				metadataManager = (IMetadataRepositoryManager) provisioningAgent.getService(IMetadataRepositoryManager.SERVICE_NAME);
				if(metadataManager == null) {
					Throwable throwable = new Throwable(Messages.Updater_could_not_load + " Metadata Repository Manager");
					throwable.fillInStackTrace();
					throw new InvocationTargetException(throwable);
				}

				//Load artifact manager
				artifactManager = (IArtifactRepositoryManager) provisioningAgent.getService(IArtifactRepositoryManager.SERVICE_NAME);
				if(artifactManager == null) {
					Throwable throwable = new Throwable(Messages.Updater_could_not_load + " Artifact Repository Manager");
					throwable.fillInStackTrace();
					throw new InvocationTargetException(throwable);
				}

				//Load repo
				try {
					metadataManager.loadRepository(repoLocation, null);
					artifactManager.loadRepository(repoLocation, null);
				} catch (ProvisionException pe) {
					throw new InvocationTargetException(pe);
				}
Re: Configure a p2 update repository programmatically [message #547917 is a reply to message #547260] Tue, 20 July 2010 07:53 Go to previous messageGo to next message
Daniel Murygin is currently offline Daniel MuryginFriend
Messages: 12
Registered: July 2010
Junior Member
There are also static methods in class ProvisioningHelper from bundle org.eclipse.equinox.p2.console - unfortunately there is no documentation...

// from bundle org.eclipse.equinox.p2.console
    import org.eclipse.equinox.internal.p2.console.ProvisioningHelper;

    URI repoUri = new URI(UPDATE_SITE_URL);
    try {
        ProvisioningHelper.addMetadataRepository(repoUri);         
    } catch( Exception e ) {
        LOG.warn("Can not add update repository: " + repoUri);           
    }
    try {
        ProvisioningHelper.addArtifactRepository(repoUri);          
    } catch( Exception e ) {
        LOG.warn("Can not add update repository: " + repoUri);
    }


Re: Configure a p2 update repository programmatically [message #567924 is a reply to message #547260] Tue, 20 July 2010 00:32 Go to previous messageGo to next message
Michael Yara is currently offline Michael YaraFriend
Messages: 27
Registered: July 2009
Junior Member
Daniel,

Here is the code I use to load a Repository from a URI into the manager. repoLocation is an instance of URI. Hopefully this helps.


//Load repository manager
metadataManager = (IMetadataRepositoryManager) provisioningAgent.getService(IMetadataRepositoryManager.SERV ICE_NAME);
if(metadataManager == null) {
Throwable throwable = new Throwable(Messages.Updater_could_not_load + " Metadata Repository Manager");
throwable.fillInStackTrace();
throw new InvocationTargetException(throwable);
}

//Load artifact manager
artifactManager = (IArtifactRepositoryManager) provisioningAgent.getService(IArtifactRepositoryManager.SERV ICE_NAME);
if(artifactManager == null) {
Throwable throwable = new Throwable(Messages.Updater_could_not_load + " Artifact Repository Manager");
throwable.fillInStackTrace();
throw new InvocationTargetException(throwable);
}

//Load repo
try {
metadataManager.loadRepository(repoLocation, null);
artifactManager.loadRepository(repoLocation, null);
} catch (ProvisionException pe) {
throw new InvocationTargetException(pe);
}
Re: Configure a p2 update repository programmatically [message #567956 is a reply to message #547260] Tue, 20 July 2010 07:53 Go to previous messageGo to next message
Daniel Murygin is currently offline Daniel MuryginFriend
Messages: 12
Registered: July 2010
Junior Member
There are also static methods in class ProvisioningHelper from bundle org.eclipse.equinox.p2.console - unfortunately there is no documentation...

// from bundle org.eclipse.equinox.p2.console
import org.eclipse.equinox.internal.p2.console.ProvisioningHelper;

URI repoUri = new URI(UPDATE_SITE_URL);
try {
ProvisioningHelper.addMetadataRepository(repoUri);
} catch( Exception e ) {
LOG.warn("Can not add update repository: " + repoUri);
}
try {
ProvisioningHelper.addArtifactRepository(repoUri);
} catch( Exception e ) {
LOG.warn("Can not add update repository: " + repoUri);
}
Re: Configure a p2 update repository programmatically [RESOLVED] [message #1004027 is a reply to message #547260] Tue, 22 January 2013 13:11 Go to previous message
Laura V is currently offline Laura VFriend
Messages: 32
Registered: March 2012
Member
Those methods aren't visible anymore in the new api, for whatever reason
Previous Topic:P2 Update in E4 RCP Application
Next Topic:headless update without restart
Goto Forum:
  


Current Time: Sun Dec 21 18:51:47 GMT 2014

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

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