New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NetBeans ignores sourceSets specs #184

Closed
wvreeven opened this Issue Feb 25, 2015 · 14 comments

Comments

Projects
None yet
3 participants
@wvreeven

wvreeven commented Feb 25, 2015

For historic reasons all source code files in my projects reside inside the src directory. However, all test classes are inside /test subdirectories (yuck, I know...).

I added a sourceSets definition in the build.gradle file which gets respected when building and testing with Gradle, both from the command line and from within NetBeans. However, the Projects tab shows all source files both in the Source Packages and Test Packages trees. This is how I defined the sourceSets:

sourceSets {
    main {
        java {
            srcDir 'src'
            exclude '**/test/'
        }
    }
    test {
        java {
            srcDir 'src'
            include '**/test/'
        }
    }
}
@kelemen

This comment has been minimized.

Owner

kelemen commented Feb 25, 2015

Exclude and include patterns are currently ignored by the plugin. Also, currently class path detection will ignore this info as well. This is most likely fixable. If you write me a method which determines if a file (or directory) is in a source root (given the source root path, exclude and include rules), I will make the plugin consider exclude and include patterns. Otherwise, this is a low priority issue because you are the first one requesting it.

By the way, instead of writing srcDir 'src', you should write srcDirs = ['src']. Otherwise, Gradle will check the default source root as well (not that it matters much).

@kelemen kelemen added the enhancement label Feb 25, 2015

@wvreeven

This comment has been minimized.

wvreeven commented Feb 25, 2015

Thanks for the quick reply and the advise you gave me about improving my build.gradle file. I understand it is a low prio issue and I'll consider looking into the method you requested.

@kelemen

This comment has been minimized.

Owner

kelemen commented Feb 28, 2015

Should be fixed in master. Can you verify it works for you? (i.e., clean and build the project and install the created nbm).If it doesn't work, try clearing NetBeans' cache folder.

@kelemen kelemen closed this Mar 4, 2015

@gallardo

This comment has been minimized.

gallardo commented Aug 31, 2015

By the way, instead of writing srcDir 'src', you should write srcDirs = ['src'].

@kelemen Thanks! This is priceless!

@gallardo

This comment has been minimized.

gallardo commented Sep 1, 2015

Uhmmm... I cannot understand why the directories are not filtered?

I'm including only org/opencms/ade/containerpage:

// ...
sourceSets[...+'_gwt'].java.srcDirs=["$gwtDir"]
sourceSets[...+'_gwt'].java.include 'org/opencms/ade/containerpage/**'
// ...

But I see all other directories (their content is correctly filtered, though). Current tree:
image
Expected:
image

I have checked org.netbeans.gradle.project.util.ExcludeIncludeRules and it looks pretty good (it filters out correctly the files that have not been included), but I don't understand yet how the isAllowAll is supposed to work...

@kelemen

This comment has been minimized.

Owner

kelemen commented Sep 1, 2015

Only files are filtered and not directories. The reason for this is because you can - in theory - create complex rules to reinclude subfolders/files and the only way to check it is to check all the files in the source which would extremly inefficient (though there could be some rule of thumbs to detect common patterns). As for isAllowAll, it is simply for optimization purposes to cut some code paths when there are no rules (which is the most common case).

@kelemen

This comment has been minimized.

Owner

kelemen commented Sep 1, 2015

I think, I might add some optimization if there are no "include" rules, if that is what you want.

@kelemen

This comment has been minimized.

Owner

kelemen commented Sep 1, 2015

or if there are only include rules.

@gallardo

This comment has been minimized.

gallardo commented Sep 2, 2015

you can - in theory - create complex rules to reinclude subfolders/files and the only way to check it is to check all the files in the source which would extremly inefficient

I though all files are checked anyway. I'm afraid that without a complete understanding of how the plugin works it's not easy to follow this explanation.

I might add some optimization if there are no "include" rules

In my case, there are only include rules. But again, out of curiosity, you are already testing for all include and exclude patterns (at least, that is what org.netbeans.gradle.project.util.ExcludeInclude.includeFile(...) suggest). What am I missing?

@kelemen

This comment has been minimized.

Owner

kelemen commented Sep 2, 2015

Originally, the plugin did not support these patterns. To keep the same performance, I have to instantiate different classes if there are no rules. The one you need, is an additional check (and maybe an additional classpath, etc. implementation).

@gallardo

This comment has been minimized.

gallardo commented Sep 2, 2015

I'm almost giving up: I have found how the plugin updates the sources (GradleClassPathProvider.updateAllSources()) apparently building a list of PathResourceImplementation. For JavaSourceGroups with declared include/exclude filters, it instantiates ExcludeAwarePathResource, that implements NB's FilteringPathResourceImplementation interface.

So far, so good. From my observations, for my project I have a JavaSourceGroup myModule.mySourceSet.JAVA with a FilteringPathResourceImplementation with include pattern "/blah/blah/**". I'd now have expected that NB invokes the FilteringPathResourceImplementation.includes(urlRoot, resource) for each file/dir. But this doesn't seem to be the case. I have added some logs, but these are never printed out. 😮

So my question: where does NB test if a resource belongs under the corresponding sourceSet tree node? I must be looking at the wrong place!

@kelemen

This comment has been minimized.

Owner

kelemen commented Sep 2, 2015

Those are only for the classpath and not for displaying the source nodes. For displaying the sources in the project view (I believe) the only thing that matters is GradleSourceGroup within GradleProjectSources.

@gallardo

This comment has been minimized.

gallardo commented Sep 2, 2015

Thank you!

@gallardo

This comment has been minimized.

gallardo commented Sep 2, 2015

Now I understand your comments. And no, the solution doesn't seem to be very straightforward.

gallardo added a commit to gallardo/netbeans-gradle-project that referenced this issue Sep 3, 2015

Fix test cases for FilterRules
according to current filter behaviour to set the fundations for
fixing kelemen#184 directory filtering.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment