Discovering the p2 API
-
Upload
pascal-rapicault -
Category
Technology
-
view
6.039 -
download
2
description
Transcript of Discovering the p2 API
© Sonatype, inc. All right reserved. Made available under Creative Commons Att. Nc Nd 2.5.license 1
Discovering the p2 API
Pascal RapicaultSonatype, p2 Lead
© Sonatype, inc. All right reserved. Made available under Creative Commons Att. Nc Nd 2.5.license 2
Who are the p2 committers?
© Sonatype, inc. All right reserved. Made available under Creative Commons Att. Nc Nd 2.5.license 3
History
• 3.4 / 3.5 provisional API
• 3.6 / Helios is the first official release of the API
© Sonatype, inc. All right reserved. Made available under Creative Commons Att. Nc Nd 2.5.license 4
3 levels of API
• Graphical User Interface
• Headless Operations
• Core APIs + SPIs
© Sonatype, inc. All right reserved. Made available under Creative Commons Att. Nc Nd 2.5.license 5
Graphical User Interface
• GUI is SWT-based and designed to be reused in RCP / Eclipse applications.
• Ease of reuse:– Add the p2.ui.sdk bundle, done (if you use IDE) .
– Add the p2.ui bundle, write a few extensions, done.org.eclipse.equinox.p2.ui
org.eclipse.equinox.p2.ui.sdk
© Sonatype, inc. All right reserved. Made available under Creative Commons Att. Nc Nd 2.5.license 6
Graphical User Interface
© Sonatype, inc. All right reserved. Made available under Creative Commons Att. Nc Nd 2.5.license 7
Reusing individual UI elements
• Most the pages / wizards can be reused– Installed dialog
– Repository management
– License manager
– Install/Update/Uninstall wizard
org.eclipse.equinox.p2.ui
o.e.e.p2.ui.InstalledSoftwarePage
o.e.e.p2.ui.RepositoryManipulationPage
o.e.e.p2.ui.AcceptLicensesWizardPage
o.e.e.p2.ui.ProvisioningUtil#open*Wizard
© Sonatype, inc. All right reserved. Made available under Creative Commons Att. Nc Nd 2.5.license 8
Tweaking the existing UI
• The Policy class– Show / hide repository selection– Drill down– Show categories– Content of the restart dialog – …
org.eclipse.equinox.p2.ui
org.eclipse.equinox.p2.ui.Policy
© Sonatype, inc. All right reserved. Made available under Creative Commons Att. Nc Nd 2.5.license 9
Tweaking the existing UI
© Sonatype, inc. All right reserved. Made available under Creative Commons Att. Nc Nd 2.5.license 10
More on UI reuse
• See examples on the p2 wiki– http://wiki.eclipse.org/Equinox/p2/Examples
• Susan’s and Steffen’s talk– http://www.eclipsecon.org/2010/sessions/?
page=sessions&id=1205
© Sonatype, inc. All right reserved. Made available under Creative Commons Att. Nc Nd 2.5.license 11
3 levels of API
• Graphical User Interface
• Headless Operations
• Core APIs + SPIs
© Sonatype, inc. All right reserved. Made available under Creative Commons Att. Nc Nd 2.5.license 12
Headless operations
• High level operations to install / update / uninstall
• Focused on the Eclipse / OSGi use cases• Encapsulates:– Dependency resolution– Download– Modification of the system– Restart
org.eclipse.equinox.p2.operations
org.eclipse.equinox.p2.operations
© Sonatype, inc. All right reserved. Made available under Creative Commons Att. Nc Nd 2.5.license 13
Headless operations example
InstallOperation op = new InstallOperation(session, iusToInstall);if (op.resolveModal(new NullProgressMonitor()).isOK())
op.getProvisioningJob(new NullProgressMonitor()).schedule();
© Sonatype, inc. All right reserved. Made available under Creative Commons Att. Nc Nd 2.5.license 14
3 levels of API
• Graphical User Interface
• Headless Operations
• Core APIs + SPIs
© Sonatype, inc. All right reserved. Made available under Creative Commons Att. Nc Nd 2.5.license 15
Core concepts
profile registry/profile
repository
installable unit/metadata
agent
planner
engine
query/queryable
© Sonatype, inc. All right reserved. Made available under Creative Commons Att. Nc Nd 2.5.license 16
TransportsHttp/HttpsFile systemVolume
Repositoriesp2Update Site
Engine
Eclipse/OSGiNative/OS
Planner/Director
Profile registryRuntimes
Provisioning operation requested
Metadata fetched and constraints analyzed
IU install, uninstall, update operations
Artifact availability and mirroring
Mirroring
Data transfer
IUs configured into runtimes
Profile updated
Metadata repo Artifact repoCore concepts
© Sonatype, inc. All right reserved. Made available under Creative Commons Att. Nc Nd 2.5.license 17
How do I get an IU?
• IUs can be obtained from– Querying the metadata repository – Querying the profile– Querying …
– Programmatically createdorg.eclipse.equinox.p2.metadata
org.eclipse.equinox.p2.metadata.MetadataFactory
© Sonatype, inc. All right reserved. Made available under Creative Commons Att. Nc Nd 2.5.license 18
Queries / QueryableHow do I query?
• What is queryable?– Almost everything is queryable (repository, repository
manager, profile, …)
• How do I create a query?– QueryUtil.create*– Domain specific queries (e.g. in eclipse.touchpoint)– p2 QL, p2-specific query language
• http://wiki.eclipse.org/Query_Language_for_p2
org.eclipse.equinox.p2.query.IQueryable
org.eclipse.equinox.p2.query.QueryUtil
org.eclipse.equinox.p2.metadataorg.eclipse.equinox.p2.ql
© Sonatype, inc. All right reserved. Made available under Creative Commons Att. Nc Nd 2.5.license 19
The repository managerHow do I get a repository?
• Artifact / metadata repository manager• Addition / removal of repositories• Enable / disable repositories• Load
• Artifact / metadata repository• Add• Remove• Query
org.eclipse.equinox.p2.repository
org.eclipse.equinox.p2.repository.IMetadataRepositoryorg.eclipse.equinox.p2.repository.IArtifactRepository
o.e.e.p2.repository.IMetadataRepositoryManagero.e.e.p2.repository.IArtifactRepositoryManager
© Sonatype, inc. All right reserved. Made available under Creative Commons Att. Nc Nd 2.5.license 20
Provisioning agentHow do I get a repository manager or p2 components?
• The agent groups related services together– It is the starting point of everything.– It is the executable version of the p2 area (e.g the p2 folder in the eclipse
install)
– Several agents can run at once in one VM. Groups the services together. Allows to change some services (see implementations of IAgentServiceFactory)
– If you are only dealing with the running instance:• Obtain the IProvisioningAgent service from the OSGi registry• Create it using the IProvisioningContext#createAgent(null)org.eclipse.equinox.p2.core
org.eclipse.equinox.p2.core.IProvisioningAgentorg.eclipse.equinox.p2.core.IProvisioningAgentProvider
© Sonatype, inc. All right reserved. Made available under Creative Commons Att. Nc Nd 2.5.license 21
Profile / profile registryHow do I know what is installed?
• A profile is the complete description in terms of IUs of what is installed.
• The profile registry knows about all the profiles in a given p2 area
org.eclipse.equinox.p2.engineorg.eclipse.equinox.p2.engine.IProfile
org.eclipse.equinox.p2.engineorg.eclipse.equinox.p2.engine.IProfileRegistry
© Sonatype, inc. All right reserved. Made available under Creative Commons Att. Nc Nd 2.5.license 22
What is not API?
• Repository serialized format• Layout of files on disk under the p2 folder
© Sonatype, inc. All right reserved. Made available under Creative Commons Att. Nc Nd 2.5.license 23
Summary
• 3 levels of API tailored for different needs Simple things should be simple Complex things should be possible
This API is for YOU! Tell us what you think.
© Sonatype, inc. All right reserved. Made available under Creative Commons Att. Nc Nd 2.5.license 24
Thank you
mailto:[email protected]://wiki.eclipse.org/Equinox/p2
© Sonatype, inc. All right reserved. Made available under Creative Commons Att. Nc Nd 2.5.license 25
Code snippet to install• ProvisioningSession session = null;
• //get the agent• ServiceReference sr = Activator.sContext.getServiceReference(IProvisioningAgentProvider.SERVICE_NAME);• IProvisioningAgentProvider agentProvider = null;• if (sr == null)• return;• agentProvider = (IProvisioningAgentProvider) Activator.sContext.getService(sr);• IProvisioningAgent agent = agentProvider.createAgent(new URI("file:/Applications/eclipse63/p2"));
• //get the repo managers• IMetadataRepositoryManager manager = (IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME);• IArtifactRepositoryManager artifactManager = (IArtifactRepositoryManager) agent.getService(IArtifactRepositoryManager.SERVICE_NAME);
• //Loading reppos• IMetadataRepository metadataRepo = manager.loadRepository(new URI("file:/Users/Pascal/tmp/demo/"), new NullProgressMonitor());• IArtifactRepository artifactRepo = artifactManager.loadRepository(new URI("file:/Users/Pascal/tmp/demo/"), new NullProgressMonitor());
• //Querying• Collection toInstall = metadataRepo.query(QueryUtil.createIUQuery("org.eclipse.equinox.p2.demo.feature.group"), new
NullProgressMonitor()).toUnmodifiableSet();
• InstallOperation installOperation = new InstallOperation(session, toInstall);• if (installOperation.resolveModal(new NullProgressMonitor()).isOK())• installOperation.getProvisioningJob(new NullProgressMonitor()).schedule();• agent.close()