aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-server/src
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-10-16 12:02:33 +0200
committerGrégoire Aubert <gregoire.aubert@sonarsource.com>2017-10-23 08:01:13 -0700
commitfcd1611d29cea9b5ce667d6b56200ee6a174af4d (patch)
tree483f9e9ac9c5ee40e16a4119f3aabb3caf388717 /server/sonar-server/src
parenta41cbd9d77ee847456795c524c3c41d12f4492e8 (diff)
downloadsonarqube-fcd1611d29cea9b5ce667d6b56200ee6a174af4d.tar.gz
sonarqube-fcd1611d29cea9b5ce667d6b56200ee6a174af4d.zip
SONAR-9951 add internal extension point LicenseCommit
Diffstat (limited to 'server/sonar-server/src')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/edition/CommitPendingEditionOnStartup.java33
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/license/LicenseCommit.java37
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/license/package-info.java23
3 files changed, 89 insertions, 4 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/edition/CommitPendingEditionOnStartup.java b/server/sonar-server/src/main/java/org/sonar/server/edition/CommitPendingEditionOnStartup.java
index 42909c09508..98abad4ed78 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/edition/CommitPendingEditionOnStartup.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/edition/CommitPendingEditionOnStartup.java
@@ -19,13 +19,27 @@
*/
package org.sonar.server.edition;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
import org.sonar.api.Startable;
+import org.sonar.server.license.LicenseCommit;
public class CommitPendingEditionOnStartup implements Startable {
private final MutableEditionManagementState editionManagementState;
+ @CheckForNull
+ private final LicenseCommit licenseCommit;
+ /**
+ * Used by Pico when license-manager is not installed and therefor no implementation of {@link LicenseCommit} is
+ * is available.
+ */
public CommitPendingEditionOnStartup(MutableEditionManagementState editionManagementState) {
+ this(editionManagementState, null);
+ }
+
+ public CommitPendingEditionOnStartup(MutableEditionManagementState editionManagementState, @Nullable LicenseCommit licenseCommit) {
this.editionManagementState = editionManagementState;
+ this.licenseCommit = licenseCommit;
}
@Override
@@ -36,19 +50,30 @@ public class CommitPendingEditionOnStartup implements Startable {
return;
case MANUAL_IN_PROGRESS:
case AUTOMATIC_READY:
- // TODO save new license with plugin manager
- editionManagementState.finalizeInstallation();
+ finalizeInstall(status);
break;
case AUTOMATIC_IN_PROGRESS:
- // FIXME temporary hack until download of edition is implemented
+ // FIXME temporary hack until download of edition is implemented, should move status to AUTOMATIC_FAILURE
editionManagementState.automaticInstallReady();
- editionManagementState.finalizeInstallation();
+ finalizeInstall(status);
break;
default:
throw new IllegalStateException("Unsupported status " + status);
}
}
+ private void finalizeInstall(EditionManagementState.PendingStatus status) {
+ // license manager is not installed, can't finalize
+ if (licenseCommit == null) {
+ return;
+ }
+
+ String newLicense = editionManagementState.getPendingLicense()
+ .orElseThrow(() -> new IllegalStateException(String.format("When state is %s, a license should be available in staging", status)));
+ licenseCommit.update(newLicense);
+ editionManagementState.finalizeInstallation();
+ }
+
@Override
public void stop() {
// nothing to do
diff --git a/server/sonar-server/src/main/java/org/sonar/server/license/LicenseCommit.java b/server/sonar-server/src/main/java/org/sonar/server/license/LicenseCommit.java
new file mode 100644
index 00000000000..52ca34524c8
--- /dev/null
+++ b/server/sonar-server/src/main/java/org/sonar/server/license/LicenseCommit.java
@@ -0,0 +1,37 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * 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 org.sonar.server.license;
+
+import org.sonar.api.ExtensionPoint;
+
+@ExtensionPoint
+public interface LicenseCommit {
+ /**
+ * Installs the specified license on SonarQube.
+ *
+ * @throws IllegalArgumentException if new license is invalid or cannot be read
+ */
+ void update(String newLicense);
+
+ /**
+ * Remove any license installed on SonarQube.
+ */
+ void delete();
+}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/license/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/license/package-info.java
new file mode 100644
index 00000000000..f56c663e273
--- /dev/null
+++ b/server/sonar-server/src/main/java/org/sonar/server/license/package-info.java
@@ -0,0 +1,23 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * 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.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.server.license;
+
+import javax.annotation.ParametersAreNonnullByDefault;