Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 342193 - Target Platform service throws exceptions if run without OSGi
Summary: Target Platform service throws exceptions if run without OSGi
Status: VERIFIED FIXED
Alias: None
Product: PDE
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.7   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 3.7 M7   Edit
Assignee: Curtis Windatt CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 343640 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-04-07 12:31 EDT by Curtis Windatt CLA
Modified: 2011-04-25 11:03 EDT (History)
3 users (show)

See Also:
Michael_Rennie: review+


Attachments
Fix (4.72 KB, patch)
2011-04-07 15:55 EDT, Curtis Windatt CLA
no flags Details | Diff
New Fix (5.67 KB, patch)
2011-04-18 17:04 EDT, Curtis Windatt CLA
no flags Details | Diff
update (17.83 KB, patch)
2011-04-19 14:53 EDT, Michael Rennie CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Curtis Windatt CLA 2011-04-07 12:31:12 EDT
The target platform service is being used by API Tools and other tooling.  In some cases (such as the API tools use scan task) the code is called when not running OSGi.

There are two known issues preventing this:

1) The target service is only accessible through the OSGi service framework

We already have a workaround for this.  Calling getDefault() on TargetPlatformService.  We should explain this in the doc of both the getDefault() method and in the service doc as well.

2) NPE when trying to get the local target handle location

We try to get the plug-in state location.  The fix here should be to either provide an alternate location when the state is unavailable or disable local handles when there is no state.
Comment 1 Curtis Windatt CLA 2011-04-07 15:55:25 EDT
Created attachment 192777 [details]
Fix
Comment 2 Curtis Windatt CLA 2011-04-15 10:27:48 EDT
Fixed in HEAD.  Mike please verify.
Comment 3 Michael Rennie CLA 2011-04-15 15:05:59 EDT
testing running an API use scan from the command line in windows, it appears the fix just pushes the NPE to a different location:

BUILD FAILED
C:\Users\mrennie\Desktop\build.ent:43: java.lang.NullPointerException
        at org.eclipse.pde.internal.core.target.AbstractBundleContainer.resolveV
ariables(AbstractBundleContainer.java:80)
        at org.eclipse.pde.internal.core.target.ProfileBundleContainer.resolveHo
meLocation(ProfileBundleContainer.java:210)
        at org.eclipse.pde.internal.core.target.ProfileBundleContainer.resolveBu
ndles(ProfileBundleContainer.java:104)
        at org.eclipse.pde.internal.core.target.AbstractBundleContainer.resolve(
AbstractBundleContainer.java:97)
        at org.eclipse.pde.api.tools.internal.model.ApiModelFactory.addComponent
s(ApiModelFactory.java:225)
        at org.eclipse.pde.api.tools.internal.tasks.CommonUtilsTask.createBaseli
ne(CommonUtilsTask.java:75)
        at org.eclipse.pde.api.tools.internal.tasks.ApiUseTask.getBaseline(ApiUs
eTask.java:454)
        at org.eclipse.pde.api.tools.internal.tasks.ApiUseTask.execute(ApiUseTas
k.java:287)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:48)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:600)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.jav
a:106)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.Target.execute(Target.java:390)
        at org.apache.tools.ant.Target.performTasks(Target.java:411)
        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
        at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExe
cutor.java:41)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
        at org.apache.tools.ant.Main.runBuild(Main.java:809)
        at org.apache.tools.ant.Main.startAnt(Main.java:217)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)

Total time: 2 seconds
Comment 4 Michael Rennie CLA 2011-04-18 09:25:43 EDT
Chatting with Curtis, we think it might be better to remove the 'fixes' from PDE and handle the the non-OSGi case in API tools. In the case that the target platform service is not available, we should just fall-back to using a directory of bundles rather than trying to use the non-OSGi version of the service.
Comment 5 Curtis Windatt CLA 2011-04-18 14:50:20 EDT
I have removed the run without OSGi hacks in TargetPlatformService and LocalTargetHandle.  I will look at fixing ApiModelFactory today.
Comment 6 Curtis Windatt CLA 2011-04-18 17:04:32 EDT
Created attachment 193533 [details]
New Fix

This fix changes how the baseline gets created.  If the target is not available we (silently) revert to searching the plug-ins directory.
Comment 7 Curtis Windatt CLA 2011-04-18 17:05:11 EDT
Mike, please review this new patch and see whether it would be satisfactory for the server tooling in 3.7.
Comment 8 Michael Rennie CLA 2011-04-19 11:40:11 EDT
Not sure yet if it is related but now I get the following (with the patch applied):

BUILD FAILED
C:\Users\mrennie\Desktop\build.ent:43: java.lang.NoSuchMethodError: org/objectwe
b/asm/ClassReader.accept(Lorg/objectweb/asm/ClassVisitor;I)V
        at org.eclipse.pde.api.tools.internal.model.TypeStructureBuilder.buildTy
peStructure(TypeStructureBuilder.java:194)
        at org.eclipse.pde.api.tools.internal.model.AbstractApiTypeRoot.getStruc
ture(AbstractApiTypeRoot.java:53)
        at org.eclipse.pde.api.tools.internal.provisional.search.ApiSearchEngine
$ReferenceExtractor.visit(ApiSearchEngine.java:97)
        at org.eclipse.pde.api.tools.internal.model.ArchiveApiTypeContainer.acce
pt(ArchiveApiTypeContainer.java:204)
        at org.eclipse.pde.api.tools.internal.model.AbstractApiTypeContainer.acc
ept(AbstractApiTypeContainer.java:56)
        at org.eclipse.pde.api.tools.internal.model.Component.accept(Component.j
ava:62)
        at org.eclipse.pde.api.tools.internal.provisional.search.ApiSearchEngine
.searchReferences(ApiSearchEngine.java:244)
        at org.eclipse.pde.api.tools.internal.provisional.search.ApiSearchEngine
.search(ApiSearchEngine.java:310)
        at org.eclipse.pde.api.tools.internal.tasks.ApiUseTask.execute(ApiUseTas
k.java:315)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:48)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:600)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.jav
a:106)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.Target.execute(Target.java:390)
        at org.apache.tools.ant.Target.performTasks(Target.java:411)
        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
        at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExe
cutor.java:41)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
        at org.apache.tools.ant.Main.runBuild(Main.java:809)
        at org.apache.tools.ant.Main.startAnt(Main.java:217)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)

Total time: 4 seconds
Comment 9 Michael Rennie CLA 2011-04-19 14:53:19 EDT
Created attachment 193614 [details]
update

This is an updated patch that cleans up a bit of the directory scanning code and removes automatically appending 'plugins' to the path for the location.
Comment 10 Michael Rennie CLA 2011-04-19 14:57:09 EDT
Here is an example build file that can be used to run the use task from the commandline:

<project name="apiusetask" basedir="." default="run">
    <property name="loc" value=""/>
    <property name="xml.loc" value=""/>
    <property name="html.loc" value=""/>
    <property name="eclipse.install.dir" value=""/>
    <property name="eclipse.lib.dir" value=""/>
    <property name="apiuse.task.props" value=""/>
   
    <target name="init" depends="extract-apitoolingjar">
        <taskdef file="${apiuse.task.props}">
            <classpath>
                <fileset dir="${eclipse.install.dir}">
                    <include name="*.jar"/>
                </fileset>
                <fileset dir="${eclipse.lib.dir}">
                    <include name="*.jar"/>
                </fileset>
            </classpath>
        </taskdef>
    </target>
    <target name="extract-apitoolingjar">
        <unjar overwrite="true" dest="${eclipse.lib.dir}">
            <fileset dir="${eclipse.install.dir}">
                <include name="org.eclipse.pde.api.tools_*.jar"/>
            </fileset>
            <patternset>
                <include name="**\*.jar"/>
            </patternset>
        </unjar>
        <move file="${eclipse.lib.dir}\lib\apitooling-ant.jar"
                     overwrite="true"     
                     todir="${eclipse.lib.dir}"/>
        <delete dir="${eclipse.lib.dir}\lib\" includeemptydirs="true"/>
    </target>
    <target name="run" depends="init">
        <apiuse
            location="${loc}"
            scopepattern=".*"
            report="${xml.loc}"
            considerinternal="true"
	    considerillegaluse="true"
            debug="true"
        />
        <apiuse_reportconversion
            xmlfiles="${xml.loc}"
            htmlfiles="${html.loc}"
            debug="true"
        />
    </target>
</project>
Comment 11 Michael Rennie CLA 2011-04-19 15:17:10 EDT
applied updated patch to HEAD
Comment 12 Michael Rennie CLA 2011-04-19 15:17:19 EDT
.
Comment 13 Michael Rennie CLA 2011-04-25 11:03:01 EDT
*** Bug 343640 has been marked as a duplicate of this bug. ***