Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Re: Dynamic output path
Re: Dynamic output path [message #248333] Tue, 02 October 2007 19:03 Go to next message
Eclipse UserFriend
Originally posted by: mikesnare.gmail.com

I think I'm getting somewhere, but any help would be appreciated.

I've registered a CompilationParticipant that does the following:
1. Determine if the project being built is a project for which this
dynamic output path is necessary. How that's done isn't important here.
2. If it is, set a variable using
ResourcesPlugin.getWorkspace().getPathVariableManager().setV alue() that is
specific to the project being used (a simple combination of project name
and another known string).
3. The project references this known variable in it's .project and
..classpath files.

The end result is a classpath entry for output specifying
EXTERNAL_CLASSPATH along with the correct linkedResource in the .project
file to define the variable bound to that linkedResource. But, unless I
manually create a new directory named EXTERNAL_CLASSPATH and bind it to
the variable in eclipse, what happens is that the output is generated to
the EXTERNAL_CLASSPATH directory under the project instead of correctly
resolving to the variable.

I think that if I can add a Linked Resource programmatically somehow, this
will start to work, but I can't figure out how to do that. Any ideas?

Thanks,
-Mike
Re: Dynamic output path [message #248345 is a reply to message #248333] Wed, 03 October 2007 08:38 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: benno_baumgartner.ch.ibm.com

Mike Snare wrote:
> I think I'm getting somewhere, but any help would be appreciated.
>
> I've registered a CompilationParticipant that does the following:
> 1. Determine if the project being built is a project for which this
> dynamic output path is necessary. How that's done isn't important here.
> 2. If it is, set a variable using
> ResourcesPlugin.getWorkspace().getPathVariableManager().setV alue() that
> is specific to the project being used (a simple combination of project
> name and another known string).
> 3. The project references this known variable in it's .project and
> .classpath files.
>
> The end result is a classpath entry for output specifying
> EXTERNAL_CLASSPATH along with the correct linkedResource in the .project
> file to define the variable bound to that linkedResource. But, unless I
> manually create a new directory named EXTERNAL_CLASSPATH and bind it to
> the variable in eclipse, what happens is that the output is generated to
> the EXTERNAL_CLASSPATH directory under the project instead of correctly
> resolving to the variable.
>
> I think that if I can add a Linked Resource programmatically somehow,
> this will start to work, but I can't figure out how to do that. Any ideas?
>
> Thanks,
> -Mike

Hi Mike

I'm not sure why the variable is not resolved. Try to use classpath
variables. See JavaCore#setClasspathVariable and
org.eclipse.jdt.core.ClasspathVariableInitializer . It may also be
possible, that setting the value of the variable in the
CompilationParticipant is too late.

To create a linked folder see
org.eclipse.core.resources.IFolder.createLink(IPath, int, IProgressMonitor)

HTH
Benno
Re: Dynamic output path [message #248348 is a reply to message #248333] Wed, 03 October 2007 14:50 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: wharley.bea.com

"Mike Snare" <mikesnare@gmail.com> wrote in message
news:op.tzlecfdl7go789@mlpc40.opnet.com...
>I think I'm getting somewhere, but any help would be appreciated.
>
> I've registered a CompilationParticipant that does the following:
> 1. Determine if the project being built is a project for which this
> dynamic output path is necessary. How that's done isn't important here.
> 2. If it is, set a variable using
> ResourcesPlugin.getWorkspace().getPathVariableManager().setV alue() that is
> specific to the project being used (a simple combination of project name
> and another known string).

Which CompilationParticipant API are you using to set this? As a general
rule it's pretty hard to change anything that affects the build from within
the build - on purpose, as it creates a potentially endless recursion - but
I think you *might* be able to do it from
CompilationParticipant.aboutToBuild().

The APT team spent a lot of time trying to fix the classpath on the fly from
inside the build, and we finally gave up; the best we were able to do was
add "required" folders in the nick of time, but not actually change the
classpath itself. Classpath resolution and verification happens very early
in the cycle.
Re: Dynamic output path [message #248353 is a reply to message #248348] Wed, 03 October 2007 16:03 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mikesnare.gmail.com

Thanks, it is the 'aboutToBuild' in which I'm doing it.

The problem is that I don't know of another way.
ClasspathVariableInitializer is not an option, because it's not tied to
any project. The variable that needs to be initialized is tied to the
project by name.

I think that if I could hook in when a project is loaded but before the
classpath is set, I might be able to do this. Any ideas how that can be
done? Maybe a resource listener of some sort?

I'm successfuly creating a link thanks to the other poster, and I can even
verify that the link is correct using validateLinkLocation and
folder.getLocation.

At this point, I think part of my problem is stale project data for the
workspace. I'll post back when I get it working with basic instructions.

Thanks,
-Mike

On Wed, 03 Oct 2007 14:50:14 -0400, Walter Harley <wharley@bea.com> wrote:

> "Mike Snare" <mikesnare@gmail.com> wrote in message
> news:op.tzlecfdl7go789@mlpc40.opnet.com...
>> I think I'm getting somewhere, but any help would be appreciated.
>>
>> I've registered a CompilationParticipant that does the following:
>> 1. Determine if the project being built is a project for which this
>> dynamic output path is necessary. How that's done isn't important here.
>> 2. If it is, set a variable using
>> ResourcesPlugin.getWorkspace().getPathVariableManager().setV alue() that
>> is
>> specific to the project being used (a simple combination of project name
>> and another known string).
>
> Which CompilationParticipant API are you using to set this? As a general
> rule it's pretty hard to change anything that affects the build from
> within
> the build - on purpose, as it creates a potentially endless recursion -
> but
> I think you *might* be able to do it from
> CompilationParticipant.aboutToBuild().
>
> The APT team spent a lot of time trying to fix the classpath on the fly
> from
> inside the build, and we finally gave up; the best we were able to do was
> add "required" folders in the nick of time, but not actually change the
> classpath itself. Classpath resolution and verification happens very
> early
> in the cycle.
>
>



--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Re: Dynamic output path [message #248358 is a reply to message #248345] Wed, 03 October 2007 16:04 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mikesnare.gmail.com

Thanks! Using a classpath variable seems to *almost* do the trick. I'm
still working out some kinks, and I'll post back when I figure this out.

Thanks also for the createLink hint. That's just what I needed.

-Mike

On Wed, 03 Oct 2007 08:38:25 -0400, Benno Baumgartner
<benno_baumgartner@ch.ibm.com> wrote:

> Hi Mike
> I'm not sure why the variable is not resolved. Try to use classpath
> variables. See JavaCore#setClasspathVariable and
> org.eclipse.jdt.core.ClasspathVariableInitializer . It may also be
> possible, that setting the value of the variable in the
> CompilationParticipant is too late.
> To create a linked folder see
> org.eclipse.core.resources.IFolder.createLink(IPath, int,
> IProgressMonitor)
> HTH
> Benno



--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Re: Dynamic output path [message #248385 is a reply to message #248333] Thu, 04 October 2007 14:18 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mikesnare.gmail.com

To close this out in the event someone else needs to do the same thing,
here's how I got this working.

Manually edit the .classpath and .project files so that the .classpath
references an EXTERNAL_CLASSES directory, and the .project file defines a
linkedResource for this that is bound to the <ProjectName>_VIEWVAR
variable. Fill in the <ProjectName> with the exact name of your project.

Register a CompilationParticipant that overrides both the isActive and
aboutToBuild methods.

The isActive simply determines whether or not your plugin should actually
make any attempt to muck with the output directory. That's a
project-specific concern, and can be as easy as loading a properties file
in the project directory and checking a value in it if that works for you.

The aboutToBuild is the meat of the process. The first thing is to
determine the proper desired output path. In my case, this involved a
call to the cleartool executable to determine the name of the clearcase
view hosting the current project. I then used this as an element in a new
path (the actual result isn't important, just that it's dynamic).

I then create a classpath variable using JavaCore.setClasspathVariable
whose name is some well-defined combination of the project name and some
other static. This helps in avoiding overlaps between different
projects. Thus, if my project is named MyProject and the view loaded is
my_view I would, at this point, have a classpath variable defined with the
name "MyProject_VIEWVAR" with the value
"D:\local_output\my_view\MyProject\classes". For another project named
"AnotherProject" in the view "another_view", it would be variable
"AnotherProject_VIEWVAR" with the value
"D:\local_output\another_view\AnotherProject\classes".

Now that the classpath variable is good, I have to set up the link. This
is pretty canonical, but the logic is to use a standard name for the
output path in your .classpath and get that resource, then link it. This
will be the same name you used when registering the output path in the
..classpath. In the running example, it's "EXTERNAL_CLASSES". Get that
resource from the project, check if it is linked, validate the link, and,
if necessary, set up the link using IFolder.createLink. At this point in
the process you have all the data you need.

Create a new workspace, import the project to the workspace, and voila.

Dynamic output paths.

-Mike

On Tue, 02 Oct 2007 19:03:41 -0400, Mike Snare <mikesnare@gmail.com> wrote:

> I think I'm getting somewhere, but any help would be appreciated.
>
> I've registered a CompilationParticipant that does the following:
> 1. Determine if the project being built is a project for which this
> dynamic output path is necessary. How that's done isn't important here.
> 2. If it is, set a variable using
> ResourcesPlugin.getWorkspace().getPathVariableManager().setV alue() that
> is specific to the project being used (a simple combination of project
> name and another known string).
> 3. The project references this known variable in it's .project and
> .classpath files.
>
> The end result is a classpath entry for output specifying
> EXTERNAL_CLASSPATH along with the correct linkedResource in the .project
> file to define the variable bound to that linkedResource. But, unless I
> manually create a new directory named EXTERNAL_CLASSPATH and bind it to
> the variable in eclipse, what happens is that the output is generated to
> the EXTERNAL_CLASSPATH directory under the project instead of correctly
> resolving to the variable.
>
> I think that if I can add a Linked Resource programmatically somehow,
> this will start to work, but I can't figure out how to do that. Any
> ideas?
>
> Thanks,
> -Mike



--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Re: Dynamic output path [message #248408 is a reply to message #248385] Thu, 04 October 2007 18:08 Go to previous message
Eclipse UserFriend
When I was working with clearcase we had a script that changes the drive
letter associated with the local directory for the "current" view. So we
could rely on the fact that T:\ is always the temp directory for our
current view.

More clearcase work, but simpler life with eclipse.

Genady Beryozkin
http://www.genady.net/



Mike Snare wrote:
> To close this out in the event someone else needs to do the same
> thing, here's how I got this working.
>
> Manually edit the .classpath and .project files so that the .classpath
> references an EXTERNAL_CLASSES directory, and the .project file
> defines a linkedResource for this that is bound to the
> <ProjectName>_VIEWVAR variable. Fill in the <ProjectName> with the
> exact name of your project.
>
> Register a CompilationParticipant that overrides both the isActive and
> aboutToBuild methods.
>
> The isActive simply determines whether or not your plugin should
> actually make any attempt to muck with the output directory. That's a
> project-specific concern, and can be as easy as loading a properties
> file in the project directory and checking a value in it if that works
> for you.
>
> The aboutToBuild is the meat of the process. The first thing is to
> determine the proper desired output path. In my case, this involved a
> call to the cleartool executable to determine the name of the
> clearcase view hosting the current project. I then used this as an
> element in a new path (the actual result isn't important, just that
> it's dynamic).
>
> I then create a classpath variable using JavaCore.setClasspathVariable
> whose name is some well-defined combination of the project name and
> some other static. This helps in avoiding overlaps between different
> projects. Thus, if my project is named MyProject and the view loaded
> is my_view I would, at this point, have a classpath variable defined
> with the name "MyProject_VIEWVAR" with the value
> "D:\local_output\my_view\MyProject\classes". For another project
> named "AnotherProject" in the view "another_view", it would be
> variable "AnotherProject_VIEWVAR" with the value
> "D:\local_output\another_view\AnotherProject\classes".
>
> Now that the classpath variable is good, I have to set up the link.
> This is pretty canonical, but the logic is to use a standard name for
> the output path in your .classpath and get that resource, then link
> it. This will be the same name you used when registering the output
> path in the .classpath. In the running example, it's
> "EXTERNAL_CLASSES". Get that resource from the project, check if it
> is linked, validate the link, and, if necessary, set up the link using
> IFolder.createLink. At this point in the process you have all the
> data you need.
>
> Create a new workspace, import the project to the workspace, and voila.
>
> Dynamic output paths.
>
> -Mike
>
> On Tue, 02 Oct 2007 19:03:41 -0400, Mike Snare <mikesnare@gmail.com>
> wrote:
>
>> I think I'm getting somewhere, but any help would be appreciated.
>>
>> I've registered a CompilationParticipant that does the following:
>> 1. Determine if the project being built is a project for which
>> this dynamic output path is necessary. How that's done isn't
>> important here.
>> 2. If it is, set a variable using
>> ResourcesPlugin.getWorkspace().getPathVariableManager().setV alue()
>> that is specific to the project being used (a simple combination of
>> project name and another known string).
>> 3. The project references this known variable in it's .project
>> and .classpath files.
>>
>> The end result is a classpath entry for output specifying
>> EXTERNAL_CLASSPATH along with the correct linkedResource in the
>> .project file to define the variable bound to that linkedResource.
>> But, unless I manually create a new directory named
>> EXTERNAL_CLASSPATH and bind it to the variable in eclipse, what
>> happens is that the output is generated to the EXTERNAL_CLASSPATH
>> directory under the project instead of correctly resolving to the
>> variable.
>>
>> I think that if I can add a Linked Resource programmatically somehow,
>> this will start to work, but I can't figure out how to do that. Any
>> ideas?
>>
>> Thanks,
>> -Mike
>
>
>
Previous Topic:Java version mismatch in org.eclipse.jdt.compiler.tool bundle?
Next Topic:Filter resources from being refreshed or managed by eclipse?
Goto Forum:
  


Current Time: Wed Jun 04 11:31:47 EDT 2025

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

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

Back to the top