Discovering the p2 API

25
Discovering the p2 API Pascal Rapicault Sonatype, p2 Lead onatype, inc. All right reserved. Made available under Creative Commons Att. Nc Nd 2.5.license 1

description

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

Transcript of Discovering the p2 API

Page 1: 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

Page 2: Discovering the p2 API

© Sonatype, inc. All right reserved. Made available under Creative Commons Att. Nc Nd 2.5.license 2

Who are the p2 committers?

Page 3: Discovering the p2 API

© 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

Page 4: Discovering the p2 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

Page 5: Discovering the p2 API

© 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

Page 6: Discovering the p2 API

© Sonatype, inc. All right reserved. Made available under Creative Commons Att. Nc Nd 2.5.license 6

Graphical User Interface

Page 7: Discovering the p2 API

© 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

Page 8: Discovering the p2 API

© 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

Page 9: Discovering the p2 API

© Sonatype, inc. All right reserved. Made available under Creative Commons Att. Nc Nd 2.5.license 9

Tweaking the existing UI

Page 10: Discovering the p2 API

© 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

Page 11: Discovering the p2 API

© 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

Page 12: Discovering the p2 API

© 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

Page 13: Discovering the p2 API

© 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();

Page 14: Discovering the p2 API

© 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

Page 15: Discovering the p2 API

© 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

Page 16: Discovering the p2 API

© 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

Page 17: Discovering the p2 API

© 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

Page 18: Discovering the p2 API

© 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

Page 19: Discovering the p2 API

© 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

Page 20: Discovering the p2 API

© 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

Page 21: Discovering the p2 API

© 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

Page 22: Discovering the p2 API

© 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

Page 23: Discovering the p2 API

© 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.

Page 24: Discovering the p2 API

© 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

Page 25: Discovering the p2 API

© 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()