You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@netbeans.apache.org by Eduard Karel de Jong <ed...@dejongfrz.nl> on 2020/06/19 15:20:50 UTC
where to put generated code
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-unsubscribe@netbeans.apache.org
For additional commands, e-mail: dev-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: where to put generated code
Posted by Laszlo Kishalmi <la...@gmail.com>.
Unfortunately generated sources is not well supported under Gradle with
NetBeans at the moment. The PR for that is coming soon but it only will
be part of 12.1
On 6/21/20 2:21 AM, Geertjan Wielenga wrote:
> I’d recommend to target Maven or Gradle.
>
> Gj
>
> On Sun, 21 Jun 2020 at 11:18, Eduard Karel de Jong <ed...@dejongfrz.nl>
> wrote:
>
>> 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-unsubscribe@netbeans.apache.org
>>>> For additional commands, e-mail: dev-help@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-unsubscribe@netbeans.apache.org
>>> For additional commands, e-mail: dev-help@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-unsubscribe@netbeans.apache.org
>> For additional commands, e-mail: dev-help@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-unsubscribe@netbeans.apache.org
For additional commands, e-mail: dev-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: where to put generated code
Posted by Geertjan Wielenga <ge...@apache.org>.
I’d recommend to target Maven or Gradle.
Gj
On Sun, 21 Jun 2020 at 11:18, Eduard Karel de Jong <ed...@dejongfrz.nl>
wrote:
> 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-unsubscribe@netbeans.apache.org
> >> For additional commands, e-mail: dev-help@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-unsubscribe@netbeans.apache.org
> > For additional commands, e-mail: dev-help@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-unsubscribe@netbeans.apache.org
> For additional commands, e-mail: dev-help@netbeans.apache.org
>
> For further information about the NetBeans mailing lists, visit:
> https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
>
>
>
>
Re: where to put generated code
Posted by Antonio <an...@vieiro.net>.
Hi again,
Yep, it seems the "build-helper" Maven plugin is actually considered [1]
and used to return the generated sources URIs.
Also it seems that Maven projects define an _internal_ constant for
generated sources (see [2]), whose value is "GeneratedSources".
You can use that as a parameter to Sources [3] to see the appropriate
folders. So, if I recall correctly, this should be something like:
----
Project p = ... // however you retrieve the project
Sources sources = ProjectUtils.getSources(p);
SourceGroup [] sourceGroups = sources.getSourceGroups("GeneratedSources");
----
Maybe this constant should be made public in the maven project API. In
this case I'd place it somewhere at [4] (and use that constant in [2]).
Also this is an API change, so this requires some extra stuff. I don't
know if adding the constant is a good idea, though.
Hope this helps,
Antonio
[1]
https://github.com/apache/netbeans/blob/f21769aa59dbad7e6d317e05818babd2895cb8ab/java/maven/src/org/netbeans/modules/maven/NbMavenProjectImpl.java#L615
[2]
https://github.com/apache/netbeans/blob/f21769aa59dbad7e6d317e05818babd2895cb8ab/java/maven/src/org/netbeans/modules/maven/classpath/MavenSourcesImpl.java#L81
[3]
https://bits.netbeans.org/12.0/javadoc/org-netbeans-modules-projectapi/org/netbeans/api/project/Sources.html#getSourceGroups-java.lang.String-
[4]
https://github.com/apache/netbeans/blob/master/java/maven/src/org/netbeans/modules/maven/api/Constants.java
El 02/07/2020 a las 18:30, Antonio escribió:
> For instance, you can use the Maven "build-helper" plugin to define any
> directory you want to store generated sources
> (https://www.mojohaus.org/build-helper-maven-plugin/usage.html) I don't
> know if our NbMavenProject is aware of this. You need to investigate it
> yourself.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@netbeans.apache.org
For additional commands, e-mail: dev-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: where to put generated code
Posted by Antonio <an...@vieiro.net>.
Hi,
Some comments inlined below.
El 02/07/2020 a las 17:42, Eduard Karel de Jong escribió:
> Hi Antonio,
>
> Thanks for you answer, those are the details I'd need to implement what
> I called the 'brute force' approach.' Which involves to determine the
> project type by looking for the presence of particularly named build file.
You don't determine the project type by looking for the presence of a
particularly named build file.
You determine the project type by looking it up in the Lookup (as you
usually do in NetBeans):
if (yourProjectInstance.getLookup().lookup(AntProject.class) != null) {
// This is an Ant project
} else if (yourProjectInstance.getLookup().lookup(NbMavenProject.class)
!= null) {
// This is a Maven project
}
>
> As I had not figured out all of these details yet, your answer is spot
> on and with the new input I can get this to work easily now. Thanks
> again :-)
>
> My search, when starting this thread was for a clean, programmatic way,
> i.e. via an API, that would give me a FileObject for the folder where
> I can write my sources. as I know many modules do generated sources, I
> assumed such an API could exist.
I don't think this is feasible in NetBeans, because "generated sourced"
folders may depend on third-party plugins, and can be arbitrary.
For instance, you can use the Maven "build-helper" plugin to define any
directory you want to store generated sources
(https://www.mojohaus.org/build-helper-maven-plugin/usage.html) I don't
know if our NbMavenProject is aware of this. You need to investigate it
yourself.
>
> The code that I wrote did just that, give me a FileObject for the
> folder, except not reliably so, as it was depending on other parts of
> the project already having generated some code in a prior build.
>
> I started that search with Project and ProjectUtil and not finding
> anything useful there looked at the GlobalPathRegistry that got me
> somewhat, but not enough.
The NetBeans Project API is a little bit complex, just because it is
very powerful. Maybe these wiki entries:
http://netbeans.apache.org/wiki/#_programmatic_access_to_java_sources
http://netbeans.apache.org/wiki/#_project_handling
and
http://netbeans.apache.org/wiki/#_project_types
and this tutorial
https://netbeans.apache.org/tutorials/nbm-projectextension.html
is of help.
>
> So, yes, your answer was of great help.
>
> Kind regards
> Eduard
>
> Antonio wrote on 02/07/2020 17:08:
>> Hi Eduard,
>>
>> Ah, I see in your original email that you want to generate code from
>> your plugin. What about this?
>>
>>
>> = Generating sources for Ant based projects:
>>
>> 1.- The code of your plugin must create a directory named
>> "build/generated-sources/your-plugin-name"
>>
>> 2.- The code of your plugin then generates sources under this folder:
>>
>> "build/generated-sources/our-plugin-name/your/package/name/YourClass.java",
>> or any other sources you want to generate.
>>
>> Then NetBeans will automatically detect the folder and add it to your
>> project "Generated sources (your-plugin-name)" and you need to do
>> nothing at all.
>>
>> = Generating sources for Maven based projects:
>>
>> 1.- The code of your plugin must create a directory named
>> "src/main/your-plugin-name"
>>
>> 2.- The code of your plugin then generated sources under this folder:
>> "src/main/your-plugin-name/your/package/name/YourClass.java", or any
>> other sources you want to generate.
>>
>> Then NetBeans will automatically detect the folder and add it to your
>> project "Other Sources" or "Generated Sources (your-plugin-name)" and
>> you need to do nothing at all (not sure about the name, maybe you have
>> to refresh the project?).
>>
>> Does this answer your questions? Is this of any help?
>>
>> Kind regards,
>> Antonio
>>
>>
>>
>> El 02/07/2020 a las 16:39, Antonio escribió:
>>> Hi Eduard,
>>>
>>> Before going any further into investigating any solutions, could you
>>> please explain us what the problem you are trying to solve is?
>>>
>>> Are you trying to generate source code from your plugin? For both
>>> Maven and Ant type projects? Or do you just want to know which the
>>> generated source code folders are for some extra processing in your
>>> plugin?
>>>
>>> If you could explain us the problem in greater detail then we'd be
>>> able to do better suggestions on how to solve it.
>>>
>>> Thanks,
>>> Antonio
>>>
>>> El 01/07/2020 a las 11:12, Eduard Karel de Jong escribió:
>>>> Hello Antonio,
>>>>
>>>> Thanks for your extensive and detailed answer to my question.
>>>>
>>>> After posing my question here, I did dig in a bit further and first
>>>> searched for "Project" in the NB sources and then in their javadoc.
>>>> One of the confusion in that searcg is that Apache Ant uses the term
>>>> Project as reference to the content of a build.xml file. There I
>>>> found the ProjectUtils and associated lookup. Ulitimately, this
>>>> search did not get me an answer: the folder structure is not part of
>>>> the project info accessible via ProjectUtils.
>>>>
>>>> As a way to solve this I looked at
>>>> GlobalPathRegistry.getDefault().getSourceRoots(), which does give a
>>>> list of all possible source loactions in a project. With a filter on
>>>> the name of the 'roots' in the source path to first contain the word
>>>> "generated" and then have a prefix matching the location of the
>>>> project I did find the location to write my generated files into.
>>>> This is an Ant project so further testing was needed starting with
>>>> maven.
>>>>
>>>> At least, that worked when testing it after opening my Ant based
>>>> development project in a target NB instance. It fails in a freshly
>>>> created project, both with Maven and Ant. That it fails in such a
>>>> project is clearly because nothing has been build yet and so the
>>>> folder structure for build results, under the 'build' or 'target'
>>>> folders, respectively for Ant and Maven did not exist.
>>>>
>>>> A possible remedy seemed to be to add a java source file to these
>>>> virgin projects and then doe a build. Indeed, with this action, the
>>>> build and target directory where created by the respective build
>>>> processes. However, the source path after the build was not changed:
>>>> it did still not contain the now existing generated file folder.
>>>> Closing and reopening the projects did not have any effect. (as did
>>>> closing and reopening NetBeans).
>>>>
>>>> So I got stuck.
>>>>
>>>> I could go the brute force route by just peeking in the project
>>>> folder and looking for build.xml or pom.xml eyc to determine the
>>>> project type and then use the appropriate folder name.
>>>>
>>>> Before going there I peeked into the NB source code at
>>>> org.netbeans.modules.java.api.common.classpath.SourcePathImplementation.java
>>>> to look for hints on how to handle this neatly.
>>>> SourcePathImplementation control flow is generic with Ant specific
>>>> operations determined by construction-time parameters, that's a
>>>> start. To modify that code and get a nice solution with something
>>>> like a static method in GlobalPathRegistry would be too much of a
>>>> deviation for me.
>>>>
>>>> Any suggestions on how not to go for the brute force approach?
>>>>
>>>> Cheers
>>>> Eduard de Jong
>>>>
>>>> antonio wrote on 23/06/2020 01:03:
>>>>> 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-unsubscribe@netbeans.apache.org
>>>>>>>> For additional commands, e-mail: dev-help@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-unsubscribe@netbeans.apache.org
>>>>>>> For additional commands, e-mail: dev-help@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-unsubscribe@netbeans.apache.org
For additional commands, e-mail: dev-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: where to put generated code
Posted by Eduard Karel de Jong <ed...@dejongfrz.nl>.
Hi Antonio,
Thanks for you answer, those are the details I'd need to implement what
I called the 'brute force' approach.' Which involves to determine the
project type by looking for the presence of particularly named build file.
As I had not figured out all of these details yet, your answer is spot
on and with the new input I can get this to work easily now. Thanks
again :-)
My search, when starting this thread was for a clean, programmatic way,
i.e. via an API, that would give me a FileObject for the folder where
I can write my sources. as I know many modules do generated sources, I
assumed such an API could exist.
The code that I wrote did just that, give me a FileObject for the
folder, except not reliably so, as it was depending on other parts of
the project already having generated some code in a prior build.
I started that search with Project and ProjectUtil and not finding
anything useful there looked at the GlobalPathRegistry that got me
somewhat, but not enough.
So, yes, your answer was of great help.
Kind regards
Eduard
Antonio wrote on 02/07/2020 17:08:
> Hi Eduard,
>
> Ah, I see in your original email that you want to generate code from
> your plugin. What about this?
>
>
> = Generating sources for Ant based projects:
>
> 1.- The code of your plugin must create a directory named
> "build/generated-sources/your-plugin-name"
>
> 2.- The code of your plugin then generates sources under this folder:
>
> "build/generated-sources/our-plugin-name/your/package/name/YourClass.java",
> or any other sources you want to generate.
>
> Then NetBeans will automatically detect the folder and add it to your
> project "Generated sources (your-plugin-name)" and you need to do
> nothing at all.
>
> = Generating sources for Maven based projects:
>
> 1.- The code of your plugin must create a directory named
> "src/main/your-plugin-name"
>
> 2.- The code of your plugin then generated sources under this folder:
> "src/main/your-plugin-name/your/package/name/YourClass.java", or any
> other sources you want to generate.
>
> Then NetBeans will automatically detect the folder and add it to your
> project "Other Sources" or "Generated Sources (your-plugin-name)" and
> you need to do nothing at all (not sure about the name, maybe you have
> to refresh the project?).
>
> Does this answer your questions? Is this of any help?
>
> Kind regards,
> Antonio
>
>
>
> El 02/07/2020 a las 16:39, Antonio escribió:
>> Hi Eduard,
>>
>> Before going any further into investigating any solutions, could you
>> please explain us what the problem you are trying to solve is?
>>
>> Are you trying to generate source code from your plugin? For both
>> Maven and Ant type projects? Or do you just want to know which the
>> generated source code folders are for some extra processing in your
>> plugin?
>>
>> If you could explain us the problem in greater detail then we'd be
>> able to do better suggestions on how to solve it.
>>
>> Thanks,
>> Antonio
>>
>> El 01/07/2020 a las 11:12, Eduard Karel de Jong escribió:
>>> Hello Antonio,
>>>
>>> Thanks for your extensive and detailed answer to my question.
>>>
>>> After posing my question here, I did dig in a bit further and first
>>> searched for "Project" in the NB sources and then in their javadoc.
>>> One of the confusion in that searcg is that Apache Ant uses the term
>>> Project as reference to the content of a build.xml file. There I
>>> found the ProjectUtils and associated lookup. Ulitimately, this
>>> search did not get me an answer: the folder structure is not part of
>>> the project info accessible via ProjectUtils.
>>>
>>> As a way to solve this I looked at
>>> GlobalPathRegistry.getDefault().getSourceRoots(), which does give a
>>> list of all possible source loactions in a project. With a filter on
>>> the name of the 'roots' in the source path to first contain the word
>>> "generated" and then have a prefix matching the location of the
>>> project I did find the location to write my generated files into.
>>> This is an Ant project so further testing was needed starting with
>>> maven.
>>>
>>> At least, that worked when testing it after opening my Ant based
>>> development project in a target NB instance. It fails in a freshly
>>> created project, both with Maven and Ant. That it fails in such a
>>> project is clearly because nothing has been build yet and so the
>>> folder structure for build results, under the 'build' or 'target'
>>> folders, respectively for Ant and Maven did not exist.
>>>
>>> A possible remedy seemed to be to add a java source file to these
>>> virgin projects and then doe a build. Indeed, with this action, the
>>> build and target directory where created by the respective build
>>> processes. However, the source path after the build was not changed:
>>> it did still not contain the now existing generated file folder.
>>> Closing and reopening the projects did not have any effect. (as did
>>> closing and reopening NetBeans).
>>>
>>> So I got stuck.
>>>
>>> I could go the brute force route by just peeking in the project
>>> folder and looking for build.xml or pom.xml eyc to determine the
>>> project type and then use the appropriate folder name.
>>>
>>> Before going there I peeked into the NB source code at
>>> org.netbeans.modules.java.api.common.classpath.SourcePathImplementation.java
>>> to look for hints on how to handle this neatly.
>>> SourcePathImplementation control flow is generic with Ant specific
>>> operations determined by construction-time parameters, that's a
>>> start. To modify that code and get a nice solution with something
>>> like a static method in GlobalPathRegistry would be too much of a
>>> deviation for me.
>>>
>>> Any suggestions on how not to go for the brute force approach?
>>>
>>> Cheers
>>> Eduard de Jong
>>>
>>> antonio wrote on 23/06/2020 01:03:
>>>> 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-unsubscribe@netbeans.apache.org
>>>>>>> For additional commands, e-mail: dev-help@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-unsubscribe@netbeans.apache.org
>>>>>> For additional commands, e-mail: dev-help@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-unsubscribe@netbeans.apache.org
For additional commands, e-mail: dev-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: where to put generated code
Posted by Antonio <an...@vieiro.net>.
Hi Eduard,
Ah, I see in your original email that you want to generate code from
your plugin. What about this?
= Generating sources for Ant based projects:
1.- The code of your plugin must create a directory named
"build/generated-sources/your-plugin-name"
2.- The code of your plugin then generates sources under this folder:
"build/generated-sources/our-plugin-name/your/package/name/YourClass.java",
or any other sources you want to generate.
Then NetBeans will automatically detect the folder and add it to your
project "Generated sources (your-plugin-name)" and you need to do
nothing at all.
= Generating sources for Maven based projects:
1.- The code of your plugin must create a directory named
"src/main/your-plugin-name"
2.- The code of your plugin then generated sources under this folder:
"src/main/your-plugin-name/your/package/name/YourClass.java", or any
other sources you want to generate.
Then NetBeans will automatically detect the folder and add it to your
project "Other Sources" or "Generated Sources (your-plugin-name)" and
you need to do nothing at all (not sure about the name, maybe you have
to refresh the project?).
Does this answer your questions? Is this of any help?
Kind regards,
Antonio
El 02/07/2020 a las 16:39, Antonio escribió:
> Hi Eduard,
>
> Before going any further into investigating any solutions, could you
> please explain us what the problem you are trying to solve is?
>
> Are you trying to generate source code from your plugin? For both Maven
> and Ant type projects? Or do you just want to know which the generated
> source code folders are for some extra processing in your plugin?
>
> If you could explain us the problem in greater detail then we'd be able
> to do better suggestions on how to solve it.
>
> Thanks,
> Antonio
>
> El 01/07/2020 a las 11:12, Eduard Karel de Jong escribió:
>> Hellp Antonio,
>>
>> Thanks for your extensive and detailed answer to my question.
>>
>> After posing my question here, I did dig in a bit further and first
>> searched for "Project" in the NB sources and then in their javadoc.
>> One of the confusion in that searcg is that Apache Ant uses the term
>> Project as reference to the content of a build.xml file. There I found
>> the ProjectUtils and associated lookup. Ulitimately, this search did
>> not get me an answer: the folder structure is not part of the project
>> info accessible via ProjectUtils.
>>
>> As a way to solve this I looked at
>> GlobalPathRegistry.getDefault().getSourceRoots(), which does give a
>> list of all possible source loactions in a project. With a filter on
>> the name of the 'roots' in the source path to first contain the word
>> "generated" and then have a prefix matching the location of the
>> project I did find the location to write my generated files into. This
>> is an Ant project so further testing was needed starting with maven.
>>
>> At least, that worked when testing it after opening my Ant based
>> development project in a target NB instance. It fails in a freshly
>> created project, both with Maven and Ant. That it fails in such a
>> project is clearly because nothing has been build yet and so the
>> folder structure for build results, under the 'build' or 'target'
>> folders, respectively for Ant and Maven did not exist.
>>
>> A possible remedy seemed to be to add a java source file to these
>> virgin projects and then doe a build. Indeed, with this action, the
>> build and target directory where created by the respective build
>> processes. However, the source path after the build was not changed:
>> it did still not contain the now existing generated file folder.
>> Closing and reopening the projects did not have any effect. (as did
>> closing and reopening NetBeans).
>>
>> So I got stuck.
>>
>> I could go the brute force route by just peeking in the project folder
>> and looking for build.xml or pom.xml eyc to determine the project type
>> and then use the appropriate folder name.
>>
>> Before going there I peeked into the NB source code at
>> org.netbeans.modules.java.api.common.classpath.SourcePathImplementation.java
>> to look for hints on how to handle this neatly.
>> SourcePathImplementation control flow is generic with Ant specific
>> operations determined by construction-time parameters, that's a start.
>> To modify that code and get a nice solution with something like a
>> static method in GlobalPathRegistry would be too much of a deviation
>> for me.
>>
>> Any suggestions on how not to go for the brute force approach?
>>
>> Cheers
>> Eduard de Jong
>>
>> antonio wrote on 23/06/2020 01:03:
>>> 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-unsubscribe@netbeans.apache.org
>>>>>> For additional commands, e-mail: dev-help@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-unsubscribe@netbeans.apache.org
>>>>> For additional commands, e-mail: dev-help@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-unsubscribe@netbeans.apache.org
For additional commands, e-mail: dev-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: where to put generated code
Posted by Antonio <an...@vieiro.net>.
Hi Eduard,
Before going any further into investigating any solutions, could you
please explain us what the problem you are trying to solve is?
Are you trying to generate source code from your plugin? For both Maven
and Ant type projects? Or do you just want to know which the generated
source code folders are for some extra processing in your plugin?
If you could explain us the problem in greater detail then we'd be able
to do better suggestions on how to solve it.
Thanks,
Antonio
El 01/07/2020 a las 11:12, Eduard Karel de Jong escribió:
> Hellp Antonio,
>
> Thanks for your extensive and detailed answer to my question.
>
> After posing my question here, I did dig in a bit further and first
> searched for "Project" in the NB sources and then in their javadoc. One
> of the confusion in that searcg is that Apache Ant uses the term Project
> as reference to the content of a build.xml file. There I found the
> ProjectUtils and associated lookup. Ulitimately, this search did not get
> me an answer: the folder structure is not part of the project info
> accessible via ProjectUtils.
>
> As a way to solve this I looked at
> GlobalPathRegistry.getDefault().getSourceRoots(), which does give a list
> of all possible source loactions in a project. With a filter on the name
> of the 'roots' in the source path to first contain the word "generated"
> and then have a prefix matching the location of the project I did find
> the location to write my generated files into. This is an Ant project so
> further testing was needed starting with maven.
>
> At least, that worked when testing it after opening my Ant based
> development project in a target NB instance. It fails in a freshly
> created project, both with Maven and Ant. That it fails in such a
> project is clearly because nothing has been build yet and so the folder
> structure for build results, under the 'build' or 'target' folders,
> respectively for Ant and Maven did not exist.
>
> A possible remedy seemed to be to add a java source file to these virgin
> projects and then doe a build. Indeed, with this action, the build and
> target directory where created by the respective build processes.
> However, the source path after the build was not changed: it did still
> not contain the now existing generated file folder. Closing and
> reopening the projects did not have any effect. (as did closing and
> reopening NetBeans).
>
> So I got stuck.
>
> I could go the brute force route by just peeking in the project folder
> and looking for build.xml or pom.xml eyc to determine the project type
> and then use the appropriate folder name.
>
> Before going there I peeked into the NB source code at
> org.netbeans.modules.java.api.common.classpath.SourcePathImplementation.java
> to look for hints on how to handle this neatly. SourcePathImplementation
> control flow is generic with Ant specific operations determined by
> construction-time parameters, that's a start. To modify that code and
> get a nice solution with something like a static method in
> GlobalPathRegistry would be too much of a deviation for me.
>
> Any suggestions on how not to go for the brute force approach?
>
> Cheers
> Eduard de Jong
>
> antonio wrote on 23/06/2020 01:03:
>> 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-unsubscribe@netbeans.apache.org
>>>>> For additional commands, e-mail: dev-help@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-unsubscribe@netbeans.apache.org
>>>> For additional commands, e-mail: dev-help@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-unsubscribe@netbeans.apache.org
For additional commands, e-mail: dev-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: where to put generated code
Posted by Eduard Karel de Jong <ed...@dejongfrz.nl>.
Hellp Antonio,
Thanks for your extensive and detailed answer to my question.
After posing my question here, I did dig in a bit further and first
searched for "Project" in the NB sources and then in their javadoc. One
of the confusion in that searcg is that Apache Ant uses the term Project
as reference to the content of a build.xml file. There I found the
ProjectUtils and associated lookup. Ulitimately, this search did not get
me an answer: the folder structure is not part of the project info
accessible via ProjectUtils.
As a way to solve this I looked at
GlobalPathRegistry.getDefault().getSourceRoots(), which does give a list
of all possible source loactions in a project. With a filter on the name
of the 'roots' in the source path to first contain the word "generated"
and then have a prefix matching the location of the project I did find
the location to write my generated files into. This is an Ant project so
further testing was needed starting with maven.
At least, that worked when testing it after opening my Ant based
development project in a target NB instance. It fails in a freshly
created project, both with Maven and Ant. That it fails in such a
project is clearly because nothing has been build yet and so the folder
structure for build results, under the 'build' or 'target' folders,
respectively for Ant and Maven did not exist.
A possible remedy seemed to be to add a java source file to these virgin
projects and then doe a build. Indeed, with this action, the build and
target directory where created by the respective build processes.
However, the source path after the build was not changed: it did still
not contain the now existing generated file folder. Closing and
reopening the projects did not have any effect. (as did closing and
reopening NetBeans).
So I got stuck.
I could go the brute force route by just peeking in the project folder
and looking for build.xml or pom.xml eyc to determine the project type
and then use the appropriate folder name.
Before going there I peeked into the NB source code at
org.netbeans.modules.java.api.common.classpath.SourcePathImplementation.java
to look for hints on how to handle this neatly. SourcePathImplementation
control flow is generic with Ant specific operations determined by
construction-time parameters, that's a start. To modify that code and
get a nice solution with something like a static method in
GlobalPathRegistry would be too much of a deviation for me.
Any suggestions on how not to go for the brute force approach?
Cheers
Eduard de Jong
antonio wrote on 23/06/2020 01:03:
> 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-unsubscribe@netbeans.apache.org
>>>> For additional commands, e-mail: dev-help@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-unsubscribe@netbeans.apache.org
>>> For additional commands, e-mail: dev-help@netbeans.apache.org
>>>
>>> For further information about the NetBeans mailing lists, visit:
>>> https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
>>>
>>>
>>>
>>>
>>
>
Re: where to put generated code
Posted by antonio <an...@vieiro.net>.
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-unsubscribe@netbeans.apache.org
>>> For additional commands, e-mail: dev-help@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-unsubscribe@netbeans.apache.org
>> For additional commands, e-mail: dev-help@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-unsubscribe@netbeans.apache.org
For additional commands, e-mail: dev-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: where to put generated code
Posted by Eduard Karel de Jong <ed...@dejongfrz.nl>.
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-unsubscribe@netbeans.apache.org
>> For additional commands, e-mail: dev-help@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-unsubscribe@netbeans.apache.org
> For additional commands, e-mail: dev-help@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-unsubscribe@netbeans.apache.org
For additional commands, e-mail: dev-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: where to put generated code
Posted by antonio <an...@vieiro.net>.
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-unsubscribe@netbeans.apache.org
> For additional commands, e-mail: dev-help@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-unsubscribe@netbeans.apache.org
For additional commands, e-mail: dev-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists