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 248687 - Multiple Maven WebResources and beans.xml
Summary: Multiple Maven WebResources and beans.xml
Status: RESOLVED FIXED
Alias: None
Product: javaee
Classification: Unclassified
Component: CDI (show other bugs)
Version: 8.0.1
Hardware: PC Windows 7
: P2 normal (vote)
Assignee: Petr Hejl
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-11-17 10:51 UTC by yblazart
Modified: 2015-04-30 10:31 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description yblazart 2014-11-17 10:51:07 UTC
When you have multiple webResource, for example making Angulars with gulp : 

 <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <webResources>
                        <resource>
                            <directory>src/main/webapp</directory>
                        </resource>
                        <resource>
                            <directory>src/main/web</directory>
                            <excludes>
                                <exclude>**/*</exclude>
                            </excludes>
                        </resource>
                        <resource>
                            <directory>target/gulp-dist</directory>
                        </resource>
                    </webResources>                  
                </configuration>
            </plugin>

First, in the project view, I can see that the order of the showed webapp directories is not necessary the same than if the pom.
Each time I reload the project, the order can change.

Second, the beans.xml file is normally in src/main/webapp.
BUT it's only detected by netbeans when this directory is the first in the project view.

Otherwise, netbeans show me errors where I have @inject and propose to create the beans.xml. 
And for exemple if the first showed directory is target/gulp-dist, netbeans create the beans.xml inside it....
Comment 1 Sergey Petrov 2014-11-17 13:46:34 UTC
I don't see p1 here
Comment 2 yblazart 2014-11-17 16:03:49 UTC
This is a really annoying bug. That's why I putted P1.
The beans.xml could contains specific informations and must be in src/main/webapp, not in the others dierctories.

So, I readed the code, that what I thinks, but as I'm not a netbeans RCP specialist, I let other people check : 

In "Context and Dependency Injection support" (web.beans), we have the WebCdiUtil class.

Line 79 we have this : 
WebModule wm = WebModule.getWebModule(project.getProjectDirectory());

So I understand it could check only one WebModule, the code could be easily modified to give back a WebModule array ?

For exempel, in org.netbeans.modules.web.api.webmodule.WebModule, add : 

    public static List<WebModule> getWebModules (FileObject file) {
        List<WebModule> webModules = new ArrayList<WebModule>();
        Parameters.notNull("file", file); // NOI18N
        Iterator it = implementations.allInstances().iterator();
        while (it.hasNext()) {
            WebModuleProvider impl = (WebModuleProvider)it.next();
            WebModule wm = impl.findWebModule (file);
            if (wm != null) {
                webModules.add(wm);
            }
        }
        return webModules;
    }  

And in org.netbeans.modules.web.beans.WebCdiUtil, change method with

   public Collection<FileObject> getBeansTargetFolder(boolean create) {
        Project project = getProject();
        if (project == null) {
            return Collections.emptyList();
        }
        List<WebModule> wmList = WebModule.getWebModules(project.getProjectDirectory());
        if (wmList != null && wmList.size() > 0) {
            Collection<FileObject> fileObjects = new ArrayList<>();
            for (WebModule wm : wmList) {
                if (wm != null && wm.getDocumentBase() != null) {
                    FileObject webInf = wm.getWebInf();
                    if (webInf == null && create) {
                        try {
                            webInf = FileUtil.createFolder(wm.getDocumentBase(), WEB_INF);
                        } catch (IOException ex) {
                            Logger.getLogger(WebCdiUtil.class.getName()).log(
                                    Level.WARNING, null, ex);
                        }
                    }
                    fileObjects.add(webInf);
                }
            }
            if (fileObjects.size() > 0) {
                return fileObjects;
            }
        }
        return super.getBeansTargetFolder(create);
    }
Comment 3 Sergey Petrov 2014-11-17 16:29:36 UTC
yes it may be but if look at category cdi, it's some specific use case is broken rather then cdi itself, and no data loss etc.
as it's hard to have a product without issues and the same regarding hints, hints should be configurable i/e/ be able to switch off at least.  
Anyway I like to try to verify next week what you've suggested.
Comment 4 Sergey Petrov 2014-11-17 16:29:57 UTC
>p2 to be in view for next week
Comment 5 roti 2015-02-16 11:57:27 UTC
Exactly the same problem with 8.0.2 and filtering in pom.xml:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.3</version>
    <configuration>
        <filters>
            <filter>src/main/resources/${myProfile}/filters/ejb-jar.properties</filter>
        </filters>
        <webResources>
            <resource>
                <directory>src/main/webapp/WEB-INF</directory>
                <filtering>true</filtering>
                <targetPath>WEB-INF</targetPath>
                <includes>
                    <include>ejb-jar.xml</include>
                </includes>
            </resource>
        </webResources>
    </configuration>
</plugin>
Comment 6 Petr Hejl 2015-04-17 14:38:34 UTC
Ordering problem fixed in web-main a1fe45a117cd.
Comment 7 Petr Hejl 2015-04-17 15:31:48 UTC
Fixed in web-main d8081985857b.
Comment 8 Quality Engineering 2015-04-20 11:57:56 UTC
Integrated into 'main-silver', will be available in build *201504201004* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/a1fe45a117cd
User: Petr Hejl <phejl@netbeans.org>
Log: #248687 - Multiple Maven WebResources and beans.xml
Comment 9 roti 2015-04-30 10:31:36 UTC
tested with 201504290001, and works great!
thanx