Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Discovering the p2 API

7,217 views

Published on

This presentation goes over the main concepts of the p2 API and provide some

Published in: Technology
  • Be the first to comment

Discovering the p2 API

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

×