kelemen / netbeans-gradle-project

This project is a NetBeans plugin able to open Gradle based Java projects. The implementation is based on Geertjan Wielenga's plugin.
173 stars 57 forks source link

Local maven repo source support. #412

Closed DeanWookey closed 5 years ago

DeanWookey commented 5 years ago

When using local maven repositories, gradle doesn't download and cache the binaries, but instead uses them directly from the local repository. This means the netbeans gradle plugin can't resolve the source and javadoc files correctly.

This pull request deals with 2 cases.

  1. The library is in a local repository with normal versioning.
  2. The library is in a local repository and is a SNAPSHOT.

Unfortunately, because the binaries are in local maven repositories, the check to see if the binary is a child of the gradle cache directory had to be removed:

        FileObject cacheHome = FileUtil.toFileObject(gradleUserHome);
        if (cacheHome == null || !FileUtil.isParentOf(cacheHome, binaryRootObj)) {
            return null;
        }

This broke 2 tests which tested specifically that. I added @Ignore to both of them. I'm not 100% sure why that check was necessary, but if it is, maybe I can work around it while still maintaining the ability to locate source files for local repositories.

DeanWookey commented 5 years ago

My sub projects can't see each other's source files now, so I guess that null tells netbeans the sources aren't external?

kelemen commented 5 years ago

I did a quick check on your commit and if I understand the code correctly, you try to lookup the sources in .m2. This shouldn't be necessary as sources in .m2 are handled by the Maven plugin of NB. Do you have the Maven support disabled? Also, I definitely can't merge this, the check in the beginning is critical: Otherwise this query might steal work from other queries (which should now better). That is, this query is only meant to handle the Gradle cache. Other checks should be in a separate BinaryForSource/SourceForBinary implementation.

DeanWookey commented 5 years ago

I have local maven repositories defined as follows:

repositories {
    mavenCentral()
    maven {
        url "file://${rootDir}/../Repository"
    }
}

Netbeans doesn't find the source jars in that case because gradle doesn't download them to the cache.

I should've created an issue first, but I got carried away in my investigations. I'll investigate the maven plugin, whether that's working etc. Then I'll take a look if there's a better way to do this. I admit I don't really know my way around the code. Thanks for explaining how it works.

DeanWookey commented 5 years ago

My maven plugin is working and I still have the problem where there's no source for anything in a local repository (even though the source files are there). I've created an example application here: https://github.com/DeanWookey/NetbeansGradleMavenLocalTest.

If this is a problem on your end too, would the correct way to go about solving it be to create something like:

org.netbeans.gradle.project.query.MavenLocalBinaryForSourceQuery.java
org.netbeans.gradle.project.query.MavenLocalByBinaryLookup.java
org.netbeans.gradle.project.query.MavenLocalJavadocForBinaryQuery.java
org.netbeans.gradle.project.query.MavenLocalSourceForBinaryQuery.java

, leave the other queries unchanged, and create associated tests?

kelemen commented 5 years ago

I didn't realize that you are not talking about .m2 but a custom local Maven repo.

Having separate queries would work (even in a completely separate plugin) but how do you decide - based on the file path - that you are in such a repository? Will you just check if the associated source file is there where you expect it to be?

By the way, you only need to implement these 3 interfaces (with the appropriate ServiceProviders annotation):

That said, it is probably possible to list those repositories when loading projects (though I'm not sure since Gradle heavily guards its internals nowadays, so you can't always hack around if there is no public API).

DeanWookey commented 5 years ago

New pull request can be found here: https://github.com/kelemen/netbeans-gradle-project/pull/413