Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Faceted Project Framework » How to define implementation library programmatically for a facet?
How to define implementation library programmatically for a facet? [message #531174] Tue, 04 May 2010 05:03 Go to next message
Dave Lin is currently offline Dave Lin
Messages: 4
Registered: July 2009
Junior Member
Hi,

Our team develop a product with RESTful support, and we would like to add JAX-RS facet in RAD dynamically when user create first RESTful service in our project. We are able to add the JAX-RS facet programmatically based on J2EE server version. The problem is, we are not sure how to choose correct JAX-RS implementation library. Does anyone have experiences on this? Thanks!

Dave

Here is what we want to do:

WAS     JAX-RS facet version      JAX-RS implementation library
6.1        1.0	                        IBM WebSphere JAX-RS library for WAS v6.1
7.0        1.0	                        IBM WebSphere JAX-RS library for WAS v7.0
8.0        1.1	                        IBM WebSphere JAX-RS library for WAS v8.0 (expected)
Re: How to define implementation library programmatically for a facet? [message #532041 is a reply to message #531174] Thu, 06 May 2010 20:48 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin Komissarchik
Messages: 941
Registered: July 2009
Senior Member
You might get better answers on a RAD forum as it will take knowledge of this facet's implementation to help you along.

I would start looking at this facet's install configuration object. If you have a handle on IFacetedProjectWorkingCopy, add this facet, then look at pending actions. Find the action corresponding to installing this facet. It will have the config object attached to it. Browse this object in the debugger to see what kind of API it exposes.

It is possible that this facet leverages library provider framework, in which case you will see LibraryInstallDelegate held somewhere inside the config object. If you find this object, you should be able to figure out how to change the library or we can help you on this forum with library provider framework api questions.

- Konstantin
Re: How to define implementation library programmatically for a facet? [message #532062 is a reply to message #531174] Fri, 07 May 2010 01:35 Go to previous messageGo to next message
Dave Lin is currently offline Dave Lin
Messages: 4
Registered: July 2009
Junior Member
Here is how we solve it. We just modify the .classpath directly

try{                            
    IRuntime runtime = J2eeUtils.getRuntime(project);                            
    String runtimeVersion = J2eeUtils.getRuntimeVersion(runtime);
    IClasspathEntry[] existingEntries = null;
    IJavaProject javaProject = JavaCore.create(project);
    ArrayList entriesToSave = new ArrayList();
    existingEntries = javaProject.getRawClasspath();
    for (int i = 0; i < existingEntries.length; i++)
    {
        IClasspathEntry entry = existingEntries[i];
        boolean keepEntry = true;
        if ((entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) &&
            (entry.getPath().toString().startsWith("org.eclipse.jst.ws.jaxrs.core.internal.jaxrslibrarycontainer")))              //remove orinigal jaxrs library
        {                                    
            keepEntry = false;
        }

        if (keepEntry)
            entriesToSave.add(entry);
    }
    
    //add new jaxrs library for different WAS version                            
    if("6.1".equals(runtimeVersion))                                
        entriesToSave.add(JavaCore.newContainerEntry(new org.eclipse.core.runtime.Path("?????")));
    else if("7.0".equals(runtimeVersion))
        entriesToSave.add(JavaCore.newContainerEntry(new org.eclipse.core.runtime.Path("?????")));
    else if("8.0".equals(runtimeVersion))
        entriesToSave.add(JavaCore.newContainerEntry(new org.eclipse.core.runtime.Path("?????")));
                                
    IClasspathEntry[] cp = (IClasspathEntry[])(entriesToSave.toArray(new IClasspathEntry[entriesToSave.size()]));
    javaProject.setRawClasspath(cp, monitor);
    javaProject.save(monitor, true);                                
}
catch(Exception e) {}  


Re: How to define implementation library programmatically for a facet? [message #572599 is a reply to message #531174] Thu, 06 May 2010 20:48 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin Komissarchik
Messages: 941
Registered: July 2009
Senior Member
You might get better answers on a RAD forum as it will take knowledge of this facet's implementation to help you along.

I would start looking at this facet's install configuration object. If you have a handle on IFacetedProjectWorkingCopy, add this facet, then look at pending actions. Find the action corresponding to installing this facet. It will have the config object attached to it. Browse this object in the debugger to see what kind of API it exposes.

It is possible that this facet leverages library provider framework, in which case you will see LibraryInstallDelegate held somewhere inside the config object. If you find this object, you should be able to figure out how to change the library or we can help you on this forum with library provider framework api questions.

- Konstantin
Re: How to define implementation library programmatically for a facet? [message #572626 is a reply to message #531174] Fri, 07 May 2010 01:35 Go to previous message
Dave Lin is currently offline Dave Lin
Messages: 4
Registered: July 2009
Junior Member
Here is how we solve it. We just modify the .classpath directly


try{
IRuntime runtime = J2eeUtils.getRuntime(project);
String runtimeVersion = J2eeUtils.getRuntimeVersion(runtime);
IClasspathEntry[] existingEntries = null;
IJavaProject javaProject = JavaCore.create(project);
ArrayList entriesToSave = new ArrayList();
existingEntries = javaProject.getRawClasspath();
for (int i = 0; i < existingEntries.length; i++)
{
IClasspathEntry entry = existingEntries[i];
boolean keepEntry = true;
if ((entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) &&
(entry.getPath().toString().startsWith(" org.eclipse.jst.ws.jaxrs.core.internal.jaxrslibrarycontainer "))) //remove orinigal jaxrs library
{
keepEntry = false;
}

if (keepEntry)
entriesToSave.add(entry);
}

//add new jaxrs library for different WAS version
if("6.1".equals(runtimeVersion))
entriesToSave.add(JavaCore.newContainerEntry(new org.eclipse.core.runtime.Path("?????")));
else if("7.0".equals(runtimeVersion))
entriesToSave.add(JavaCore.newContainerEntry(new org.eclipse.core.runtime.Path("?????")));
else if("8.0".equals(runtimeVersion))
entriesToSave.add(JavaCore.newContainerEntry(new org.eclipse.core.runtime.Path("?????")));

IClasspathEntry[] cp = (IClasspathEntry[])(entriesToSave.toArray(new IClasspathEntry[entriesToSave.size()]));
javaProject.setRawClasspath(cp, monitor);
javaProject.save(monitor, true);
}
catch(Exception e) {}
Previous Topic:How to define implementation library programmatically for a facet?
Next Topic:Headless facet installation
Goto Forum:
  


Current Time: Thu Oct 23 14:40:41 GMT 2014

Powered by FUDForum. Page generated in 0.02328 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software