apache / apache/netbeans

Creation of a new java file in non-standard test folder is actually placed into "main" source folder

Open
#5,775 0 comments 0 reactions 0 assignees View on GitHub
kind:bug needs:triage
Dominant language
Java
Stars
3.1k
Forks
935
Avg merge
2d 3h
Merged PRs (30d)
17

Description

### Apache NetBeans version

Apache NetBeans 17

### What happened

We use maven for our applications. We use multiple folders with JUnit tests (sample below). The extra test folder is added to maven by "build-helper-maven-plugin". In netbeans, the folder appears in project window as "Generated Test Sources (java)". The problem is, if I expand that folder and I try to create a new Java Class (right click on package - Java Class), a new file will be created in main folder and default package.

So the problem is not how this extra folder is represented in project window, but it is not possible to create a new source file in that extra folder. It is created in main (not even test folder) and then I have to move it to desired folder manually.

before creating a new file in "extra-test"

├── extra-test
│   └── java
│   └── com
│   └── mycompany
│   └── extra
│   └── HelloTest.java
├── main
│   └── java
│   └── com
│   └── mycompany
│   └── extra
│   └── Main.java
└── test
└── java
└── com
└── mycompany
└── extra
└── NormalTest.java

after creating **NewClass.java** file in "extra-test"
├── extra-test
│   └── java
│   └── com
│   └── mycompany
│   └── extra
│   └── HelloTest.java
├── main
│   └── java
│   ├── com
│   │   └── mycompany
│   │   └── extra
│   │   └── Main.java
│   └── NewClass.java
└── test
└── java
└── com
└── mycompany
└── extra
└── NormalTest.java

### How to reproduce

either you can use attached sample project or...

- Create a new maven java project
- Create a new folder "src/extra-test/java"
- Add a new source to maven:

>




org.apache.maven.plugins
maven-surefire-plugin
3.0.0


org.codehaus.mojo
build-helper-maven-plugin
3.3.0


add-extra-test-source
generate-test-sources

add-test-source



src/extra-test/java






- in project window
-- expand Generated Test Sources (java)
-- click by right button on default package (or any package)
-- select New Java Class
- a new file is created in **src/main/java and** not in **src/extra-test/java**

Similar behavior observerd, when a new file is created from File window as well, not only by Project window).

I can try to fix the issue, but not sure where exactly. "Generated Test Sources (java)" is linked to this source file: _netbeans/java/maven/src/org/netbeans/modules/maven/classpath/MavenSourcesImpl.java_

### Did this work correctly in an earlier version?

No / Don't know

### Operating System

Ubuntu/Windows10

### JDK

JDK19

### Apache NetBeans packaging

Apache NetBeans binary zip, Own source build

### Anything else

The problem is systematic, not random
sample project:
[extra-test-folder.zip](https://github.com/apache/netbeans/files/11153704/extra-test-folder.zip)

screenshots:
![image](https://user-images.githubusercontent.com/60773743/229937550-577b3697-eafb-4b5a-baf7-8ad9fa0faa0d.png)

=>

![image](https://user-images.githubusercontent.com/60773743/229937662-37a093a4-8842-4095-9178-1a82a92ac50b.png)

### Are you willing to submit a pull request?

Yes

Contributor guide

Open the contributing guide

Research direction

Start with netbeans/java/maven/src/org/netbeans/modules/maven/classpath/MavenSourcesImpl.java and reproduce the issue using the described build-helper-maven-plugin configuration or the attached sample project. Trace how the Generated Test Sources (java) node is handled when New Java Class is selected from the Project or Files window. Done means a class created there is placed in the selected extra-test source folder and package rather than src/main/java.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system, developer-experience, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.