|
Re: Finding the context root and tomcat version of WTP projects programmatically [message #181676 is a reply to message #181674] |
Mon, 16 October 2006 21:43 |
Eclipse User |
|
|
|
Originally posted by: kosta.bea.com
I will answer half of your question and let other folks answer the rest.
Here is a bit of code that you should use to check whether a project has
a certain facet...
import org.eclipse.wst.common.project.facet.core.*;
....
final IFacetedProject fproj = ProjectFacetsManager.create( <IProject> );
if( fproj != null )
{
final IProjectFacet f
= ProjectFacetsManager.getProjectFacet( "jst.web" );
return fproj.hasProjectFacet( f );
}
- Konstantin
|
|
|
|
|
Re: Finding the context root and tomcat version of WTP projects programmatically [message #181704 is a reply to message #181694] |
Tue, 17 October 2006 22:09 |
Eclipse User |
|
|
|
Originally posted by: kosta.bea.com
To get at the web content directory, you can use the virtual component
api...
import org.eclipse.wst.common.componentcore.resources.*;
final IVirtualComponent vc = ComponentCore.createComponent( <IProject> );
if( vc != null )
{
return vc.getRootFolder().getUnderlyingFolder();
}
Getting tomcat version is a bit tricker since I don't know the context
that you are trying to do this in. If the project is targetting a tomcat
runtime, then you can do the following:
import org.eclipse.wst.common.project.facet.core.*;
import org.eclipse.wst.common.project.facet.core.runtime.*;
final IFacetedProject fproj = ProjectFacetsManager.create( <IProject> );
if( fproj != null )
{
for( Iterator itr = fproj.getTargetedRuntimes().iterator();
itr.hasNext(); )
{
final IRuntime r = (IRuntime) itr.next();
// I am getting lazy here, but use r.getRuntimeComponents()
// method to examine the composition of the runtime. Each
// component has type and version. You can look for the
// tomcat type and then check the version.
}
}
- Konstantin
|
|
|
Re: Finding the context root and tomcat version of WTP projects programmatically [message #181707 is a reply to message #181704] |
Tue, 17 October 2006 23:06 |
Larry Isaacs Messages: 1354 Registered: July 2009 |
Senior Member |
|
|
For each IRuntime r, you can use:
String typeid = r.getRuntimeType().getId();
to get a string that will end with two digits indicating the version as
32, 40, 41, 50, or 55. I'm not sure if it is technically public API,
but this approach is probably reliable as I don't think the id strings
will be changing. See the plugin.xml file in the
org.eclipse.jst.server.tomcat.core plug-in to see the full id strings.
They are declared at the beginning of this file.
Cheers,
Larry
Konstantin Komissarchik wrote:
> To get at the web content directory, you can use the virtual component
> api...
>
> import org.eclipse.wst.common.componentcore.resources.*;
>
> final IVirtualComponent vc = ComponentCore.createComponent( <IProject> );
>
> if( vc != null )
> {
> return vc.getRootFolder().getUnderlyingFolder();
> }
>
> Getting tomcat version is a bit tricker since I don't know the context
> that you are trying to do this in. If the project is targetting a tomcat
> runtime, then you can do the following:
>
> import org.eclipse.wst.common.project.facet.core.*;
> import org.eclipse.wst.common.project.facet.core.runtime.*;
>
> final IFacetedProject fproj = ProjectFacetsManager.create( <IProject> );
>
> if( fproj != null )
> {
> for( Iterator itr = fproj.getTargetedRuntimes().iterator();
> itr.hasNext(); )
> {
> final IRuntime r = (IRuntime) itr.next();
>
> // I am getting lazy here, but use r.getRuntimeComponents()
> // method to examine the composition of the runtime. Each
> // component has type and version. You can look for the
> // tomcat type and then check the version.
> }
> }
>
> - Konstantin
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.09187 seconds