This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 198650 - Maven integration does not detect target/generated-resources/[some-maven-plugin] resources
Summary: Maven integration does not detect target/generated-resources/[some-maven-plug...
Status: REOPENED
Alias: None
Product: projects
Classification: Unclassified
Component: Maven (show other bugs)
Version: 6.x
Hardware: PC Windows XP
: P4 normal (vote)
Assignee: Tomas Stupka
URL:
Keywords:
: 154486 (view as bug list)
Depends on: 194090
Blocks: 191864
  Show dependency tree
 
Reported: 2011-05-16 18:33 UTC by lu4242
Modified: 2016-07-10 19:22 UTC (History)
3 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Project for create custom JSF Components with a generation tool (myfaces builder plugin) (59.12 KB, application/x-zip)
2011-05-24 01:37 UTC, lu4242
Details

Note You need to log in before you can comment on or make changes to this bug.
Description lu4242 2011-05-16 18:33:33 UTC
Netbeans maven integration detects correctly paths under target/generated-sources/[some-maven-plugin] but does not take into account resources under target/generated-resources/[some-maven-plugin] .

This cause some side effects, because if you use some generation tool like myfaces-builder-plugin for facelets taglib xml files or .tld files, the IDE doesn't detect it automatically and code completion gets broken. Other editors like eclipse (with mvn eclipse:eclipse integration) detect correctly this case.
Comment 1 Jesse Glick 2011-05-23 23:01:30 UTC
If you have a sample project to demonstrate the problem, that would be great.
Comment 2 lu4242 2011-05-24 01:37:20 UTC
Created attachment 108471 [details]
Project for create custom JSF Components with a generation tool (myfaces builder plugin)

I have attached a maven project for create custom JSF components using MyFaces builder plugin. It generates a .tld and a .taglib.xml file, but when you open the webapp, the files are not readed, because target/generated-resources/myfaces-builder-plugin is not marked as a valid path.

Obviously you can do this:

<resource>
    <directory>target/generated-resources/myfaces-builder-plugin</directory>
</resource>

But the big question is add that is required or not. mvn eclipse:eclipse is smart enough to add the path (take the same project, run mvn eclipse:eclipse and load it with eclipse helios with import >> existing eclipse project into workspace), why netbeans do not?

The code that adds the resource path on myfaces-builder-plugin is here:

http://svn.apache.org/repos/asf/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/BuildMetaDataMojo.java

the lines:

            // Tell Maven to add this directory to its "resources" path. 
            // The maven-resources-plugin will then copy all the files
            // from this directory to its own target directory, which is
            // where the final jar artifact is built from.
            addResourceRoot(project, targetDirectory.getCanonicalPath());
and

    protected void addResourceRoot(MavenProject project, String resourceRoot)
    {
        List resources = project.getBuild().getResources();
        Resource resource = new Resource();
        resource.setDirectory(resourceRoot);
        resources.add(resource);
    }
Comment 3 Jesse Glick 2011-05-25 16:12:36 UTC
Thanks for investigation. There is already code which adds any target/generated-sources/* dirs to the IDE's notion of the source path. This could just be extended to add target/generated-resources/* to the source path (and define source roots of resource type, just like src/main/resources). I can also check whether it is feasible to inspect $project.build.resources (etc.) from the embedder rather than hardcoding these file paths, which would perhaps be more general and reliable.
Comment 4 Jesse Glick 2011-05-25 19:45:40 UTC
(In reply to comment #3)
> I can
> also check whether it is feasible to inspect $project.build.resources (etc.)
> from the embedder rather than hardcoding these file paths

Seems impossible; these modifications are made during actual mojo execution. Whereas m2eclipse runs Maven in-VM for actual builds, NB forks Maven to build; it does call Maven to load projects, but this does not involve calling into plugin code; and AFAIK there is no way to ask plugins what (re)source roots they _would_ add without actually generating files and so on.

It is conceivable that bug #194090 could be used to detect (re)source roots precisely after the project is built, but there would still need to be some heuristic in place for a freshly opened but unbuilt project; and changes to the POM would only be "noticed" by the IDE upon rebuilding.
Comment 5 Jesse Glick 2011-06-01 18:19:23 UTC
Also need to handle build-helper:add-resource and build-helper:add-test-resource.
Comment 6 Milos Kleint 2012-06-05 09:38:19 UTC
*** Bug 154486 has been marked as a duplicate of this bug. ***
Comment 7 Milos Kleint 2012-08-14 07:24:02 UTC
is a feasible workaround to just change the location to target/generated-sources/FOO? we put sources and resources on the same classpath, only care about resource roots when creating new resources by the IDE.
Comment 8 lu4242 2012-08-14 17:40:47 UTC
I tried to set generated-sources instead generated-resources, just updating some params in myfaces-builder-plugin and it does not work with netbeans 7.2. There are two problems:

- The generated sources (.java) are added to the jar file too, because "generated-sources" folder is added as resources folder. 

- Generated resources are not copied to target/classes folder. 

By the previous reasons, it has more sense to use generated-resources/[my maven plugin] as this issue suggest. Note that according to maven, both sources and resources are in different folders because both requires different treatement. Sources are compiled and the result is put on target/classes. Resources are filtered/copied/transformed and the final result is put on target/classes. Mixing both of them is not an option.
Comment 9 Milos Kleint 2012-08-14 20:29:27 UTC
(In reply to comment #8)
> I tried to set generated-sources instead generated-resources, just updating
> some params in myfaces-builder-plugin and it does not work with netbeans 7.2.
> There are two problems:
> 
> - The generated sources (.java) are added to the jar file too, because
> "generated-sources" folder is added as resources folder. 

I didn't suggest target/generated-sources to become the resources root, but target/generated-sources/FOO where foo is the unique identifier for the plugin's output.

> 
> - Generated resources are not copied to target/classes folder. 

I'm not getting how that can be. Are you talking pure maven or some interaction with netbeans Compile-on-Save feature? In pure maven, if you change just the parameter for location, then the plugin will just generate into a different location but everything else stays the same. 

The desired effect was to get the resources show up on classpath and will be noticed by the web related modules. IMHO at least, I don't have a working example project. looking at http://myfaces.apache.org/build-tools/plugins/myfaces-builder-plugin/plugin-info.html I'm not even clear which goal are you using in your project, all parameters I found discuss adding a source root, not resource root.



> 
> By the previous reasons, it has more sense to use generated-resources/[my maven
> plugin] as this issue suggest. Note that according to maven, both sources and
> resources are in different folders because both requires different treatement.
> Sources are compiled and the result is put on target/classes. Resources are
> filtered/copied/transformed and the final result is put on target/classes.
> Mixing both of them is not an option.

That's not what my suggested workaround was meant to accomplish. changing the root to a location the IDE understands has no influence whatsoever on how maven interprets the values. Maven should be humming along the same as before, unless you made some configuration error. Or I misunderstood your problem. A sample project would speak 1000 of words here.
Comment 10 lu4242 2012-08-15 16:22:41 UTC
Ok, now I get it. I was thinking on a solution without change the convention for /generated-sources/[maven-plugin-artifactId]. I tried to redirect the generated resources to /generated-sources/[maven-plugin-artifactId]-resources and it works (before I was mixing both resources and sources on the same dir). It works, the IDE recognize both paths, and is able to take the generated .taglib.xml or .tld and use that information to edit .xhtml (jsf) pages. I can update my config, rebuild, and the changes are reflected in the edition/code completion. 

Since there is no naming convention in this part defined by maven, it is a valid solution (but I like more the one proposed from start). Please close this issue as invalid or won't fix or whatever. Anyway, the question is still open, it seems something to be defined by maven, but anyway, I can fix the problem just setting some params in myfaces-builder-plugin configuration. Thanks for your help.
Comment 11 Milos Kleint 2012-08-17 10:10:19 UTC
i'm keeping the issue open because in order to have all features working correctly the IDE should know the difference between source and resource root. But technically the impact is still unknown and most likely small. ->p4
Comment 12 Martin Balin 2016-07-07 08:37:09 UTC
This old bug may not be relevant anymore. If you can still reproduce it in 8.2 development builds please reopen this issue.

Thanks for your cooperation,
NetBeans IDE 8.2 Release Boss
Comment 13 markiewb 2016-07-10 19:22:25 UTC
(In reply to Milos Kleint from comment #11)
> i'm keeping the issue open because in order to have all features working
> correctly the IDE should know the difference between source and resource
> root. But technically the impact is still unknown and most likely small. ->p4

Still valid in 8.2 dev 
Product Version: NetBeans IDE Dev (Build 201607100002)