iwarapter / gradle-sonar-packaging-plugin

Gradle Plugin for building SonarQube plugins.
Other
19 stars 11 forks source link

Plugin packaging: nearly there, except Sonar does not accept it... #3

Closed fge closed 9 years ago

fge commented 9 years ago

Contents of the generated plugin by maven and gradle:

fge@alustriel:~/work/src/sonar-objectscript$ jar tf sonar-objectscript-plugin/target/sonar-objectscript-plugin-0.1.0-SNAPSHOT.jar 
META-INF/
META-INF/MANIFEST.MF
es/
es/litesolutions/
es/litesolutions/sonar/
es/litesolutions/sonar/objectscript/
es/litesolutions/sonar/objectscript/ObjectScriptProfile.class
es/litesolutions/sonar/objectscript/ObjectScriptRulesDefinition.class
es/litesolutions/sonar/objectscript/ObjectScriptPluginProperties.class
es/litesolutions/sonar/objectscript/ObjectScriptSquidSensor.class
es/litesolutions/sonar/objectscript/ObjectScriptLanguage.class
es/litesolutions/sonar/objectscript/ObjectScriptPlugin.class
es/litesolutions/sonar/SonarConstants.class
META-INF/lib/
META-INF/lib/grappa-2.0.0-beta.4.jar
META-INF/lib/asm-debug-all-5.0.3.jar
META-INF/lib/jitescript-0.4.0.jar
META-INF/lib/jaxen-1.1.4.jar
META-INF/lib/sonar-objectscript-checks-0.1.0-SNAPSHOT.jar
META-INF/lib/sslr-core-1.20.jar
META-INF/lib/sslr-squid-bridge-2.6.jar
META-INF/lib/sonar-objectscript-squid-0.1.0-SNAPSHOT.jar
META-INF/lib/sslr-xpath-1.20.jar
META-INF/maven/
META-INF/maven/es.litesolutions/
META-INF/maven/es.litesolutions/sonar-objectscript-plugin/
META-INF/maven/es.litesolutions/sonar-objectscript-plugin/pom.xml
META-INF/maven/es.litesolutions/sonar-objectscript-plugin/pom.properties
fge@alustriel:~/work/src/sonar-objectscript$ jar tf sonar-objectscript-plugin/build/libs/sonar-objectscript-plugin-0.1.0-SNAPSHOT.jar 
META-INF/
META-INF/MANIFEST.MF
es/
es/litesolutions/
es/litesolutions/sonar/
es/litesolutions/sonar/SonarConstants.class
es/litesolutions/sonar/objectscript/
es/litesolutions/sonar/objectscript/ObjectScriptPluginProperties.class
es/litesolutions/sonar/objectscript/ObjectScriptLanguage.class
es/litesolutions/sonar/objectscript/ObjectScriptRulesDefinition.class
es/litesolutions/sonar/objectscript/ObjectScriptProfile.class
es/litesolutions/sonar/objectscript/ObjectScriptPlugin.class
es/litesolutions/sonar/objectscript/ObjectScriptSquidSensor.class
META-INF/lib/
META-INF/lib/sonar-objectscript-checks-0.1.0-SNAPSHOT.jar
META-INF/lib/sonar-objectscript-squid-0.1.0-SNAPSHOT.jar
META-INF/lib/grappa-2.0.0-beta.4-all.jar
META-INF/lib/asm-debug-all-5.0.3.jar
META-INF/lib/jitescript-0.4.0.jar
META-INF/lib/sslr-squid-bridge-2.6.jar
META-INF/lib/sslr-core-1.20.jar
META-INF/lib/sslr-xpath-1.20.jar
META-INF/lib/jaxen-1.1.4.jar

What Sonar tells me when I start it up (5.1) is:

java.lang.IllegalArgumentException: Dependency META-INF/lib/sonar-objectscript-checks:0.1.0-SNAPSHOT.jar can not be found in sonar-objectscript-plugin-0.1.0-SNAPSHOT.jar

        at org.sonar.core.plugins.PluginJarInstaller.copyDependencies(PluginJarInstaller.java:53) ~[sonar-core-5.1.jar:na]
        at org.sonar.core.plugins.PluginJarInstaller.install(PluginJarInstaller.java:40) ~[sonar-core-5.1.jar:na]
        at org.sonar.server.plugins.ServerPluginJarInstaller.installToDir(ServerPluginJarInstaller.java:37) ~[sonar-server-5.1.jar:na]
        at org.sonar.server.plugins.ServerPluginJarsInstaller.deploy(ServerPluginJarsInstaller.java:235) ~[sonar-server-5.1.jar:na]
        at org.sonar.server.plugins.ServerPluginJarsInstaller.deployPlugins(ServerPluginJarsInstaller.java:217) ~[sonar-server-5.1.jar:na]
        at org.sonar.server.plugins.ServerPluginJarsInstaller.install(ServerPluginJarsInstaller.java:73) ~[sonar-server-5.1.jar:na]
        at org.sonar.server.plugins.ServerPluginRepository.start(ServerPluginRepository.java:49) ~[sonar-server-5.1.jar:na]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_40]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_40]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_40]
        at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_40]
        at org.picocontainer.lifecycle.ReflectionLifecycleStrategy.invokeMethod(ReflectionLifecycleStrategy.java:110) ~[picocontainer-2.14.3.jar:na]
        at org.picocontainer.lifecycle.ReflectionLifecycleStrategy.start(ReflectionLifecycleStrategy.java:89) ~[picocontainer-2.14.3.jar:na]
        at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.start(AbstractInjectionFactory.java:84) ~[picocontainer-2.14.3.jar:na]
        at org.picocontainer.behaviors.AbstractBehavior.start(AbstractBehavior.java:169) ~[picocontainer-2.14.3.jar:na]
[etc etc]

All other components compile etc correctly.

The build.gradle in the packaging directory looks like this:

fge@alustriel:~/work/src/sonar-objectscript$ cat sonar-objectscript-plugin/build.gradle 
buildscript {
    repositories {
        mavenCentral();
        mavenLocal();
    }
    dependencies {
        classpath(group: "com.iadams.plugins",
            name: "gradle-sonar-packaging-plugin",
            version: "0.1-SNAPSHOT");
    }
};

apply(plugin: "com.iadams.sonar-packaging");

configurations {
    provided;
    compile.extendsFrom(provided);
}

dependencies {
    compile project(":sonar-objectscript-checks");

    provided(group: "org.codehaus.sonar", name: "sonar-plugin-api", 
        version: "5.0.1");
}

sonarPackaging {
    pluginKey = "objectscript";
    pluginClass = "es.litesolutions.sonar.objectscript.ObjectScriptPlugin";
    pluginName = "ObjectScript";
    pluginDescription = "Plugin for ObjectScript language";
}

Note that checks defines the version, which is defined in the main build.gradle as being 0.1.0-SNAPSHOT (by the way, why do I have to redefine it in subprojects?)

More details on demand.

iwarapter commented 9 years ago

Do you have a small demo project? I can clone and test?

fge commented 9 years ago

Sorry, I don't... Anyway, I have just found that one element of the packaging differs and that's in the Plugin-Dependencies entries.

While the maven plugin generates "artifact-version.jar", this plugin generates "artifact:version.jar"... Maybe that explains it, I don't know; I have just modified the source and will try again.

I'll keep you informed.

iwarapter commented 9 years ago

Yeah when i write to the manifest i generate the entries here: https://github.com/iwarapter/gradle-sonar-packaging-plugin/blob/master/src/main/groovy/com/iadams/gradle/plugins/tasks/PackagePluginTask.groovy#L136

If the manifest is wrong thats where it will be from!

iwarapter commented 9 years ago

Also noticed this difference: META-INF/lib/grappa-2.0.0-beta.4-all.jar META-INF/lib/grappa-2.0.0-beta.4.jar

fge commented 9 years ago

Spot on! I think it's the problem...

In module sonar-objectscript-squid:

dependencies {
    compile(group: "com.github.fge", name: "grappa",
        version: "2.0.0-beta.4", classifier: "all") {
        exclude(group: "com.google.guava", module: "guava");
    };
    compile(group: "org.codehaus.sonar", name: "sonar-plugin-api",
        version: "5.0.1");
    compile(group: "org.codehaus.sonar.sslr-squid-bridge",
        name: "sslr-squid-bridge", version: "2.6");
    testCompile(group: "com.fasterxml.jackson.core",
        name: "jackson-databind", version: "2.5.1");
}

Note the classifier...

fge commented 9 years ago

OK, so, anyway, this quick patch solves the problem of : vs -:

diff --git a/src/main/groovy/com/iadams/gradle/plugins/tasks/PackagePluginTask.groovy b/src/main/groovy/com/iadams/gradle/plugins/tasks/PackagePluginTask.groovy
index 0c9642e..d19dc56 100644
--- a/src/main/groovy/com/iadams/gradle/plugins/tasks/PackagePluginTask.groovy
+++ b/src/main/groovy/com/iadams/gradle/plugins/tasks/PackagePluginTask.groovy
@@ -133,7 +133,7 @@ class PackagePluginTask extends Jar {
         if(!getSkipDependenciesPackaging()) {

             List<ResolvedDependency> dependencies = new DependencyQuery(project).getNotProvidedDependencies()
-            manifest.attributes.put(PluginManifest.DEPENDENCIES, dependencies.collect{ "META-INF/lib/${it.moduleName}:${it.moduleVersion}.jar" }.join(' '))
+            manifest.attributes.put(PluginManifest.DEPENDENCIES, dependencies.collect{ "META-INF/lib/${it.moduleName}-${it.moduleVersion}.jar" }.join(' '))

             if(dependencies.size()>0){
                 logger.info "Following dependencies are packaged in the plugin:\n"

This and the classifier stuff should solve it all, I believe

fge commented 9 years ago

OK, now I don't know how the problem should be solved; the maven plugin, somehow, picked the correct dependency but renamed it! While the gradle plugin picked it as is but only accounted for the name and version and not a potential qualifier...

I suck at groovy, which doesn't help matters; but there are potentially two solutions:

I'll try and do the second solution since it will be easier for me and keep you informed...

fge commented 9 years ago

OK, I've just submitted a PR.

As you will see, it's far from being "groovy"... I only know Java. And I know it's not perfect... I think the collection of such information should be done earlier on.

Well, it Works For Me(tm)...

fge commented 9 years ago

OK well, as far as I'm concerned this issue can be closed.

When do you think a first version will be published? I'd like to code an example plugin using your plugin and sonar-sslr-grappa

iwarapter commented 9 years ago

There are a few other small bits that need doing, no blockers to publishing an initial version. I'll try and get this published in the next day or two.

iwarapter commented 9 years ago

An initial version has been released https://plugins.gradle.org/plugin/com.iadams.sonar-packaging

iwarapter commented 9 years ago

@fge Have you had a chance to use the initial version?

fge commented 9 years ago

Yes, I have been using it for several weeks straight for my language plugin without a hitch :)

I mentioned in on dev@sonar, didn't you notice?

iwarapter commented 9 years ago

Didn't see anything after i posted on the release, i just wanted to add a little bit to the readme of examples of it being used.

fge commented 9 years ago

Argh...

Well, I use it in a project which is commercial :(

What I'll do is convert https://github.com/litesolutions/sonar-dummylanguage to use your plugin and tell you when it's done.

Sorry for that :/