Hi Eduard,

Now, this "how do I find from the code in my plugin what path to use for given project?" is a concise question and so is easier (and longer) to answer :-). I'm not very good at answering things, but let me have a try with this question.

== How do I find ...?

The "how do I find [...] from the code in my plugin" is an easy question.

In NetBeans the answer is usually the same independently of what you're looking for:

- Many NetBeans objects are also "Lookup.Provider"s [1], that give you a "Lookup" [2] to look inside them. - Once you have one object's lookup you just ask it for whatever you want to find.

Here's a tutorial for the Lookup API. I'm not sure if you need it, but I'm adding it just in case:

https://dzone.com/articles/netbeans-lookups-explained

== Projects

In your case you should have a "Project" [3] object somehow.

The "Project" objects represent projects in the IDE. Note that these "Project" objects implement the "Lookup.Provider" interface, so they return a Lookup object that you can use to find stuff in the project itself.

Of course there're many kinds of "Project" objects in NetBeans: you have Maven Projects [4], Ant Projects [5] (which in turn have many variants, including JavaEE Projects, for instance).

The good thing is that all these project types are just an implementation of the "Project" [3] interface, which in turn is a "Lookup.Provider" [1]. This means that you can "lookup for things" in all projects using the same interface.

== Project Sources

Now, right to the point of your question,

> My question now is: "how do I find from the code in my plugin what path
> to use for given project?" Is there, for instance, an SPI tat i could
> lookup to find it?

Yes, in fact there's a whole Project API to look things up in Projects!

The Project API is here: https://bits.netbeans.org/12.0/javadoc/org-netbeans-modules-projectapi/overview-summary.html

Note that there's also a Project SPI that you can use if you're building a Project of your own and want to add features to the Project.

And a possible answer to your question is in the "ProjectUtils" class in the API (that simplifies all Lookup for you), here:

http://bits.netbeans.org/dev/javadoc/org-netbeans-modules-projectapi/org/netbeans/api/project/ProjectUtils.html#getSources-org.netbeans.api.project.Project-

Sorry for the long answer. Feel free to ask any other questions you may have.

Kind regards,
Antonio


[1]
http://bits.netbeans.org/dev/javadoc/org-openide-util-lookup/org/openide/util/Lookup.Provider.html

[2]
http://bits.netbeans.org/dev/javadoc/org-openide-util-lookup/org/openide/util/Lookup.html

[3]
http://bits.netbeans.org/dev/javadoc/org-netbeans-modules-projectapi/org/netbeans/api/project/Project.html

[4]
https://github.com/apache/netbeans/blob/master/java/maven/src/org/netbeans/modules/maven/NbMavenProjectImpl.java

[5]
http://netbeans.apache.org/tutorials/nbm-projecttypeant.html


El 21/6/20 a las 11:18, Eduard Karel de Jong escribió:
Hello Antonio,

Thanks for confirming that different types of projects in NB use different paths to store generated code.

My question now is: "how do I find from the code in my plugin what path to use for given project?" Is there, for instance, an SPI tat i could lookup to find it?

Or, maybe, it does not matter as NB combines all the possible paths in the various projects. In that case i could fix the location at, for instance "build/generated code," the path used in projects built with ant.

I tried google searches and they consistently misinterpret the question and go nowhere.
Cheers
Edaurd

antonio wrote on 20/06/2020 11:27:
Hi,

This depends on the build-system supporting the project type.

For instance, for Maven projects people usually leave generated sources in "target/generated-sources/whatever", while others use "src/main/whatever". For Maven projects you can customize these directories in your pom.xml.

AFAIK NetBeans correctly detects the generated sources folders and shows them in the IDE.

HTH,
Antonio


El 19/6/20 a las 17:20, Eduard Karel de Jong escribió:
Hi,

I'm working on a NB module that generates java code from files in software dev projects and  different types of projects have different locations for the generated files.

Is the location for generating code relevant and if so, is there a generic way to determine the proper location for a particular project type?

Thanks for any hint on how to find the answer to this question.

Cheers
eduard de jong


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@netbeans.apache.org
For additional commands, e-mail: dev-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists




---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@netbeans.apache.org
For additional commands, e-mail: dev-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists






---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@netbeans.apache.org
For additional commands, e-mail: dev-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists



Reply via email to