-
-
Notifications
You must be signed in to change notification settings - Fork 532
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#348: Add support for Sonarqube 8.9.0
Sonarqube 8.9 packages all the core code and dependencies as a single fat JAR, which means plugins can no longer add code to the classpath by dropping JARs into the `lib/common` directory as this directory does not exist. To allow the plugin's classes to be visible to the Compute Engine and Web class-loaders, a Java Agent has been introduced that intentionally leaks the plugin classes to the Sonarqube application, thereby allowing the Core Extension Loaders to continue to see and initialise the relevant extension classes, thereby allowing them to load the plugin's implementation classes into Sonarqube's dependency management system. The Docker files have been updated to remove the copying of the plugin to the legacy directory, and to pass additional environment variable so the agent options are added to the relevant Sonarqube component's command-line arguments. Similarly, the fall-through logic in `PlatformEditionProvider` that had allowed the plugin to force the Compute Engine to believe it was running in Sonarqube developer edition has been removed, with the edition now being hard-coded to `COMMUNITY`, without any way of over-riding it. To overcome this, the agent that's being used to expose the plugin classes to Sonarqube's class-loaders is also altering the `PlatformEditionProvider` class definition during class-loading to force it to return `DEVELOPER` when running inside Compute Engine, so that the branch enforcement checks in Compute Engine pass. As the `GetBinding` action has been moved into Sonarqube Community Edition's core from Developer edition, it no longer needs to be provided by this plugin, and has been removed to prevent is causing conflicts on application startup.
- Loading branch information
Showing
16 changed files
with
237 additions
and
553 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
src/main/java/com/github/mc1arke/sonarqube/plugin/CommunityBranchAgent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright (C) 2021 Michael Clarke | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* | ||
*/ | ||
package com.github.mc1arke.sonarqube.plugin; | ||
|
||
import javassist.CannotCompileException; | ||
import javassist.ClassPool; | ||
import javassist.CtClass; | ||
import javassist.CtMethod; | ||
import javassist.NotFoundException; | ||
import org.sonar.api.utils.log.Logger; | ||
import org.sonar.api.utils.log.Loggers; | ||
|
||
import java.io.IOException; | ||
import java.lang.instrument.ClassFileTransformer; | ||
import java.lang.instrument.Instrumentation; | ||
import java.lang.instrument.UnmodifiableClassException; | ||
import java.security.ProtectionDomain; | ||
|
||
public final class CommunityBranchAgent { | ||
|
||
private static final Logger LOGGER = Loggers.get(CommunityBranchAgent.class); | ||
|
||
private CommunityBranchAgent() { | ||
super(); | ||
} | ||
|
||
public static void premain(String args, Instrumentation instrumentation) throws UnmodifiableClassException, ClassNotFoundException { | ||
LOGGER.info("Loading agent"); | ||
|
||
if (!"ce".equals(args) && !"web".equals(args)) { | ||
throw new IllegalArgumentException("Invalid/missing agent argument"); | ||
} | ||
|
||
if ("ce".equals(args)) { | ||
redefineEdition(instrumentation); | ||
} | ||
} | ||
|
||
private static void redefineEdition(Instrumentation instrumentation) throws ClassNotFoundException, UnmodifiableClassException { | ||
String targetClassName = "org.sonar.core.platform.PlatformEditionProvider"; | ||
|
||
instrumentation.addTransformer(new ClassFileTransformer() { | ||
|
||
@Override | ||
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, | ||
ProtectionDomain protectionDomain, byte[] byteCode) { | ||
|
||
String finalTargetClassName = targetClassName.replace(".", "/"); | ||
|
||
if (!className.equals(finalTargetClassName)) { | ||
return byteCode; | ||
} | ||
|
||
LOGGER.debug("Transforming class " + targetClassName); | ||
try { | ||
ClassPool cp = ClassPool.getDefault(); | ||
CtClass cc = cp.get(targetClassName); | ||
CtMethod m = cc.getDeclaredMethod("get"); | ||
m.setBody("return java.util.Optional.of(org.sonar.core.platform.EditionProvider.Edition.DEVELOPER);"); | ||
|
||
byteCode = cc.toBytecode(); | ||
cc.detach(); | ||
} catch (NotFoundException | CannotCompileException | IOException e) { | ||
LOGGER.error("Could not transform class, will use default class definition", e); | ||
} | ||
|
||
return byteCode; | ||
} | ||
|
||
}); | ||
|
||
instrumentation.retransformClasses(Class.forName(targetClassName)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 0 additions & 32 deletions
32
src/main/java/com/github/mc1arke/sonarqube/plugin/ce/CommunityBranchEditionProvider.java
This file was deleted.
Oops, something went wrong.
74 changes: 0 additions & 74 deletions
74
.../com/github/mc1arke/sonarqube/plugin/server/pullrequest/ws/action/CountBindingAction.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.