From fcd1611d29cea9b5ce667d6b56200ee6a174af4d Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Mon, 16 Oct 2017 12:02:33 +0200 Subject: [PATCH] SONAR-9951 add internal extension point LicenseCommit --- .../CommitPendingEditionOnStartup.java | 33 +++++++++++++++-- .../sonar/server/license/LicenseCommit.java | 37 +++++++++++++++++++ .../sonar/server/license/package-info.java | 23 ++++++++++++ 3 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 server/sonar-server/src/main/java/org/sonar/server/license/LicenseCommit.java create mode 100644 server/sonar-server/src/main/java/org/sonar/server/license/package-info.java 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; -- 2.39.5