diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2021-04-06 16:22:45 -0500 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2021-04-14 20:03:29 +0000 |
commit | eca5700aeaaa1b3a6c40c77318d33e98a6dd23dd (patch) | |
tree | 5e8dc292e4f2adfac3eaea166e3042b9815ec354 | |
parent | e0a058d7e9dc8cb4dce7b25e01d9702aa3554576 (diff) | |
download | sonarqube-eca5700aeaaa1b3a6c40c77318d33e98a6dd23dd.tar.gz sonarqube-eca5700aeaaa1b3a6c40c77318d33e98a6dd23dd.zip |
SONAR-14676 Shade core jars into a single jar
4 files changed, 45 insertions, 38 deletions
diff --git a/server/sonar-main/src/main/java/org/sonar/application/command/CommandFactoryImpl.java b/server/sonar-main/src/main/java/org/sonar/application/command/CommandFactoryImpl.java index 3475bb689fc..9bd07d512e6 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/command/CommandFactoryImpl.java +++ b/server/sonar-main/src/main/java/org/sonar/application/command/CommandFactoryImpl.java @@ -23,6 +23,8 @@ import java.io.File; import java.util.Map; import java.util.Optional; import org.slf4j.LoggerFactory; +import org.sonar.api.internal.MetadataLoader; +import org.sonar.api.utils.Version; import org.sonar.application.es.EsInstallation; import org.sonar.application.es.EsLogging; import org.sonar.application.es.EsSettings; @@ -32,8 +34,6 @@ import org.sonar.process.ProcessProperties; import org.sonar.process.Props; import org.sonar.process.System2; -import static org.sonar.process.ProcessProperties.Property.WEB_GRACEFUL_STOP_TIMEOUT; -import static org.sonar.process.ProcessProperties.parseTimeoutMs; import static org.sonar.process.ProcessProperties.Property.CE_GRACEFUL_STOP_TIMEOUT; import static org.sonar.process.ProcessProperties.Property.CE_JAVA_ADDITIONAL_OPTS; import static org.sonar.process.ProcessProperties.Property.CE_JAVA_OPTS; @@ -50,8 +50,10 @@ import static org.sonar.process.ProcessProperties.Property.SEARCH_JAVA_ADDITIONA import static org.sonar.process.ProcessProperties.Property.SEARCH_JAVA_OPTS; import static org.sonar.process.ProcessProperties.Property.SOCKS_PROXY_HOST; import static org.sonar.process.ProcessProperties.Property.SOCKS_PROXY_PORT; +import static org.sonar.process.ProcessProperties.Property.WEB_GRACEFUL_STOP_TIMEOUT; import static org.sonar.process.ProcessProperties.Property.WEB_JAVA_ADDITIONAL_OPTS; import static org.sonar.process.ProcessProperties.Property.WEB_JAVA_OPTS; +import static org.sonar.process.ProcessProperties.parseTimeoutMs; public class CommandFactoryImpl implements CommandFactory { private static final String ENV_VAR_JAVA_TOOL_OPTIONS = "JAVA_TOOL_OPTIONS"; @@ -69,6 +71,7 @@ public class CommandFactoryImpl implements CommandFactory { SOCKS_PROXY_HOST.getKey(), SOCKS_PROXY_PORT.getKey()}; + private static final Version SQ_VERSION = MetadataLoader.loadVersion(org.sonar.api.utils.System2.INSTANCE); private final Props props; private final File tempDir; private final System2 system2; @@ -166,7 +169,7 @@ public class CommandFactoryImpl implements CommandFactory { .setEnvVariable(PATH_LOGS.getKey(), props.nonNullValue(PATH_LOGS.getKey())) .setArgument("sonar.cluster.web.startupLeader", Boolean.toString(leader)) .setClassName("org.sonar.server.app.WebServer") - .addClasspath("./lib/common/*"); + .addClasspath("./lib/sonar-application-" + SQ_VERSION + ".jar"); String driverPath = props.value(JDBC_DRIVER_PATH.getKey()); if (driverPath != null) { command.addClasspath(driverPath); @@ -190,7 +193,7 @@ public class CommandFactoryImpl implements CommandFactory { .setJvmOptions(jvmOptions) .setGracefulStopTimeoutMs(getGracefulStopTimeoutMs(props, CE_GRACEFUL_STOP_TIMEOUT)) .setClassName("org.sonar.ce.app.CeServer") - .addClasspath("./lib/common/*"); + .addClasspath("./lib/sonar-application-" + SQ_VERSION + ".jar"); String driverPath = props.value(JDBC_DRIVER_PATH.getKey()); if (driverPath != null) { command.addClasspath(driverPath); diff --git a/server/sonar-main/src/test/java/org/sonar/application/command/CommandFactoryImplTest.java b/server/sonar-main/src/test/java/org/sonar/application/command/CommandFactoryImplTest.java index 45cdcf1da86..f8d7029008a 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/command/CommandFactoryImplTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/command/CommandFactoryImplTest.java @@ -224,8 +224,7 @@ public class CommandFactoryImplTest { assertThat(command.getClassName()).isEqualTo("org.sonar.server.app.WebServer"); assertThat(command.getWorkDir().getAbsolutePath()).isEqualTo(homeDir.getAbsolutePath()); - assertThat(command.getClasspath()) - .containsExactly("./lib/common/*"); + assertThat(command.getClasspath()).hasSize(1).allMatch(p -> p.toString().startsWith("./lib/sonar-application-")); assertThat(command.getJvmOptions().getAll()) // enforced values .contains("-Djava.awt.headless=true", "-Dfile.encoding=UTF-8") @@ -249,8 +248,7 @@ public class CommandFactoryImplTest { assertThat(command.getClassName()).isEqualTo("org.sonar.ce.app.CeServer"); assertThat(command.getWorkDir().getAbsolutePath()).isEqualTo(homeDir.getAbsolutePath()); - assertThat(command.getClasspath()) - .containsExactly("./lib/common/*"); + assertThat(command.getClasspath()).hasSize(1).allMatch(p -> p.toString().startsWith("./lib/sonar-application-")); assertThat(command.getJvmOptions().getAll()) // enforced values .contains("-Djava.awt.headless=true", "-Dfile.encoding=UTF-8") @@ -298,9 +296,9 @@ public class CommandFactoryImplTest { props.setProperty("sonar.jdbc.driverPath", driverFile.getAbsolutePath()); JavaCommand command = newFactory(props).createWebCommand(true); - - assertThat(command.getClasspath()) - .containsExactlyInAnyOrder("./lib/common/*", driverFile.getAbsolutePath()); + assertThat(command.getClasspath()).hasSize(2); + assertThat(command.getClasspath().get(0).toString()).startsWith("./lib/sonar-application-"); + assertThat(command.getClasspath().get(1)).isEqualTo(driverFile.getAbsolutePath()); } private void prepareEsFileSystem() throws IOException { diff --git a/sonar-application/build.gradle b/sonar-application/build.gradle index b1fe29e3c65..31eaad203ff 100644 --- a/sonar-application/build.gradle +++ b/sonar-application/build.gradle @@ -1,5 +1,7 @@ import org.apache.tools.ant.filters.ReplaceTokens +apply plugin: 'com.github.johnrengelman.shadow' + sonarqube { properties { property 'sonar.projectName', "${projectTitle} :: Application" @@ -26,6 +28,16 @@ configurations { } } +jar.enabled = false +shadowJar { + baseName = 'sonar-application' + classifier = null + mergeServiceFiles() + manifest { + attributes('Main-Class': 'org.sonar.application.App') + } +} + dependencies { // please keep list ordered compile 'org.slf4j:slf4j-api' @@ -54,15 +66,6 @@ dependencies { // declare dependencies in configuration bundledPlugin to be packaged in lib/extensions apply from: 'bundled_plugins.gradle' -jar { - manifest { - attributes( - 'Class-Path': configurations.compile.resolvedConfiguration.files.collect { "common/${it.getName()}" }.join(' '), - 'Main-Class': 'org.sonar.application.App' - ) - } -} - task zip(type: Zip, dependsOn: [configurations.compile]) { duplicatesStrategy DuplicatesStrategy.EXCLUDE def archiveDir = "sonarqube-$version" @@ -70,6 +73,7 @@ task zip(type: Zip, dependsOn: [configurations.compile]) { into("${archiveDir}/") { from file('src/main/assembly') exclude 'conf/sonar.properties' + exclude 'conf/wrapper.conf' exclude 'elasticsearch-patch' // elasticsearch script will be replaced by patched version below exclude 'elasticsearch/bin/elasticsearch' @@ -134,16 +138,21 @@ task zip(type: Zip, dependsOn: [configurations.compile]) { into("${archiveDir}/conf/") { from file('src/main/assembly/conf/sonar.properties') - filter(ReplaceTokens, tokens: [ - 'searchDefaultHeapSize': '512MB', - 'searchJavaOpts' : '-Xmx512m -Xms512m -XX:MaxDirectMemorySize=256m -XX:+HeapDumpOnOutOfMemoryError', - 'ceDefaultHeapSize' : '512MB', - 'ceJavaOpts' : '-Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError', - 'webDefaultHeapSize' : '512MB', - 'webJavaOpts' : '-Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError' - ]) - } - + filter(ReplaceTokens, tokens: [ + 'searchDefaultHeapSize': '512MB', + 'searchJavaOpts' : '-Xmx512m -Xms512m -XX:MaxDirectMemorySize=256m -XX:+HeapDumpOnOutOfMemoryError', + 'ceDefaultHeapSize' : '512MB', + 'ceJavaOpts' : '-Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError', + 'webDefaultHeapSize' : '512MB', + 'webJavaOpts' : '-Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError' + ]) + } + into("${archiveDir}/conf/") { + from file('src/main/assembly/conf/wrapper.conf') + filter(ReplaceTokens, tokens: [ + 'sqversion': version + ]) + } into("${archiveDir}/elasticsearch/") { from file('src/main/assembly/elasticsearch-patch') @@ -153,9 +162,6 @@ task zip(type: Zip, dependsOn: [configurations.compile]) { into("${archiveDir}/elasticsearch/") { from "$buildDir/elasticsearch" } - into("${archiveDir}/lib/") { - from jar - } into("${archiveDir}/lib/extensions/") { from configurations.bundledPlugin } @@ -165,8 +171,8 @@ task zip(type: Zip, dependsOn: [configurations.compile]) { into("${archiveDir}/lib/scanner/") { from configurations.scanner } - into("${archiveDir}/lib/common/") { - from configurations.compile + into("${archiveDir}/lib/") { + from shadowJar } into("${archiveDir}/web/") { duplicatesStrategy DuplicatesStrategy.FAIL diff --git a/sonar-application/src/main/assembly/conf/wrapper.conf b/sonar-application/src/main/assembly/conf/wrapper.conf index d4cdf7e3776..360026d398d 100644 --- a/sonar-application/src/main/assembly/conf/wrapper.conf +++ b/sonar-application/src/main/assembly/conf/wrapper.conf @@ -15,9 +15,9 @@ wrapper.java.command=java wrapper.java.additional.1=-Dsonar.wrapped=true wrapper.java.additional.2=-Djava.awt.headless=true wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp -wrapper.java.classpath.1=../../lib/jsw/*.jar -wrapper.java.classpath.2=../../lib/common/*.jar -wrapper.java.classpath.3=../../lib/*.jar +wrapper.java.classpath.1=../../lib/sonar-application-@sqversion@.jar +wrapper.java.classpath.2=../../lib/jsw/wrapper-3.2.3.jar +wrapper.java.classpath.3=../../lib/sonar-shutdowner-@sqversion@.jar wrapper.java.library.path.1=./lib wrapper.app.parameter.1=org.sonar.application.App wrapper.java.initmemory=8 |