Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 311482 - [doc] how to get and use provisioning agents needs some documentation
Summary: [doc] how to get and use provisioning agents needs some documentation
Status: RESOLVED WORKSFORME
Alias: None
Product: Equinox
Classification: Eclipse Project
Component: p2 (show other bugs)
Version: 3.6   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: P2 Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-04 03:11 EDT by David Williams CLA
Modified: 2019-09-04 01:57 EDT (History)
1 user (show)

See Also:


Attachments
team project set to pull example code from WTP cvs repository. (299 bytes, application/octet-stream)
2010-05-04 03:17 EDT, David Williams CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description David Williams CLA 2010-05-04 03:11:59 EDT
I finally dove in to write a small app to add or update the mirrorURL attribute of an artifacts repository, and it kind of works ... but throws an NPE near the end (when the value actually changes). 

Its from line 1004 of SimpleArtifactRepository. Apparently no 'agent' is ever set. 

//force repository manager to reload this repository because it caches properties
ArtifactRepositoryManager manager = (ArtifactRepositoryManager) getProvisioningAgent().getService(IArtifactRepositoryManager.SERVICE_NAME);

  
I started with the example at the bottom of 
http://wiki.eclipse.org/Equinox/p2/Publisher

I'll attach a team project set to pull in the wtp releng project, but it is a very simple class ... the meaty part below, and it is after/during the "setProperty" that the NPE occurs in SimpleArtifactRepository. 


private IPublisherInfo createPublisherInfo() throws ProvisionException, URISyntaxException {
PublisherInfo result = new PublisherInfo();

String repoURI = "file:/" + getRepositoryDirectory();
SimpleArtifactRepositoryFactory simpleArtifactRepositoryFactory = new SimpleArtifactRepositoryFactory();
// at least from workspace, NPE is thrown during "reload" if the
// property is indeed changed (different from what it was)
IArtifactRepository artifactRepository = simpleArtifactRepositoryFactory.load(new URI(repoURI), 0, null);
if (artifactRepository != null) {
    artifactRepository.setProperty("p2.mirrorURL", getMirrorURLString());
    result.setArtifactRepository(artifactRepository);
    result.setArtifactOptions(IPublisherInfo.A_OVERWRITE);
}
return result;
}
Comment 1 David Williams CLA 2010-05-04 03:17:09 EDT
Created attachment 166907 [details]
team project set to pull example code from WTP cvs repository. 

There's several classes in that tools project, the one in question is AddMirrorURL. 

The key part of actually using/running it as an application is

-application org.eclipse.wtp.releng.tools.addmirrorurl 
-Dp2.artifact.repo=D:/buildzips/M7/org.eclipse.releng.tools-3.6M7
-Dp2.mirrorURL=http://dddd

Hope this helps.
Comment 2 David Williams CLA 2010-05-04 03:18:57 EDT
Oh, and in case I wasn't clear, it actually does work. It updates the artifacts.jar at the URI I give it, and does not change anything else (a key part of this working :) 

I'm sure there's an easier way?
Comment 3 David Williams CLA 2010-05-04 14:19:54 EDT
I "fixed" the NPE by setting an agent on the repository. I'd actually tried that before opening this bug, it didn't work, but got new inspiration from bug 305731, and then got it to work without NPE, by following examples/references giving there in that bug (so ... I probably did it wrong the first time). 

I'll leave this open a short time ... if my day goes well, I'll try and improve the documentation or example at http://wiki.eclipse.org/Equinox/p2/Publisher and then close.
Comment 4 David Williams CLA 2010-05-04 16:19:02 EDT
I give up. I was going to update the example at 
http://wiki.eclipse.org/Equinox/p2/Publisher
so it used an agent ... or I could at least point to some documents on getting/using an agent, but couldn't find any I could understand. 
Seems I'll have to sleep on 
http://wiki.eclipse.org/Equinox/p2/Multiple_Agents

Feel free to close this as you'd like ... just trying to 
be helpful as always ... you know I'd never complain ... :) 

I got my agent as follows ... but, that's just following examples, and pretty sure there's other/better ways or complications I don't know about. 


    public static IProvisioningAgent getProvisioningAgent() {
        IProvisioningAgent result = null;
        if (bundleContext == null) {
            throw new IllegalStateException("bundleContext was null. can not get provisioning agenet. Perhaps bundle was not started?");
        }
        ServiceReference reference = bundleContext.getServiceReference(IProvisioningAgent.SERVICE_NAME);
        if (reference == null) {
            result = null;
            System.out.println("Could not get IProvisioningAgent service?");
        }
        result = (IProvisioningAgent) bundleContext.getService(reference);

        return result;
    }
Comment 5 Pascal Rapicault CLA 2010-05-07 07:15:27 EDT
I have posted my slides from API talk on slideshare.net/PascalRapicault/discovering-the-p2-api
At the end there is a complete example on how to get an agent and install something using the operations.
Comment 6 Eclipse Genie CLA 2018-11-21 12:53:10 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 7 Lars Vogel CLA 2019-09-04 01:55:15 EDT
This bug was marked as stalebug a while ago. Marking as worksforme.

If this report is still relevant for the current release, please reopen and remove the stalebug whiteboard tag.
Comment 8 Lars Vogel CLA 2019-09-04 01:57:01 EDT
This bug was marked as stalebug a while ago. Marking as worksforme.

If this report is still relevant for the current release, please reopen and remove the stalebug whiteboard tag.