mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 16:35:45 +01:00
move events to scm-core / move subscriber to landingpage-plugin
This commit is contained in:
@@ -21,7 +21,7 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.plugin;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
@@ -51,7 +51,6 @@ import static sonia.scm.ScmConstraintViolationException.Builder.doThrow;
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@Singleton
|
||||
@@ -173,10 +172,10 @@ public class DefaultPluginManager implements PluginManager {
|
||||
PendingPluginInstallation pending = installer.install(plugin);
|
||||
dependencyTracker.addInstalled(plugin.getDescriptor());
|
||||
pendingInstallations.add(pending);
|
||||
eventBus.post(new PluginEvent(PluginEventType.INSTALLED, plugin));
|
||||
eventBus.post(new PluginEvent(PluginEvent.PluginEventType.INSTALLED, plugin));
|
||||
} catch (PluginInstallException ex) {
|
||||
cancelPending(pendingInstallations);
|
||||
eventBus.post(new PluginEvent(PluginEventType.INSTALLATION_FAILED, plugin));
|
||||
eventBus.post(new PluginEvent(PluginEvent.PluginEventType.INSTALLATION_FAILED, plugin));
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
@@ -258,7 +257,7 @@ public class DefaultPluginManager implements PluginManager {
|
||||
|
||||
Set<String> dependencies = plugin.getDescriptor().getDependencies();
|
||||
if (dependencies != null) {
|
||||
for (String dependency: dependencies){
|
||||
for (String dependency : dependencies) {
|
||||
collectPluginsToInstall(plugins, dependency, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ package sonia.scm.plugin;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import sonia.scm.event.Event;
|
||||
import sonia.scm.event.ScmEventBus;
|
||||
import sonia.scm.net.ahc.AdvancedHttpClient;
|
||||
|
||||
@@ -62,12 +61,8 @@ class PluginCenterLoader {
|
||||
return mapper.map(pluginCenterDto);
|
||||
} catch (Exception ex) {
|
||||
LOG.error("failed to load plugins from plugin center, returning empty list", ex);
|
||||
eventBus.post(new PluginCenterNotAvailableEvent());
|
||||
eventBus.post(new PluginCenterEvent());
|
||||
return Collections.emptySet();
|
||||
}
|
||||
}
|
||||
|
||||
@Event
|
||||
class PluginCenterNotAvailableEvent {}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package sonia.scm.plugin;
|
||||
|
||||
import lombok.Getter;
|
||||
import sonia.scm.event.Event;
|
||||
|
||||
@Getter
|
||||
@Event
|
||||
public class PluginEvent {
|
||||
private final PluginEventType eventType;
|
||||
private final AvailablePlugin plugin;
|
||||
public PluginEvent(PluginEventType eventType, AvailablePlugin plugin) {
|
||||
this.eventType = eventType;
|
||||
this.plugin = plugin;
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package sonia.scm.plugin;
|
||||
|
||||
enum PluginEventType {
|
||||
INSTALLED, INSTALLATION_FAILED
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package sonia.scm.plugin;
|
||||
|
||||
import com.cloudogu.scm.myevents.MyEvent;
|
||||
import com.github.legman.Subscribe;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import sonia.scm.EagerSingleton;
|
||||
import sonia.scm.event.ScmEventBus;
|
||||
import sonia.scm.xml.XmlInstantAdapter;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||
import java.time.Instant;
|
||||
|
||||
@Extension(requires = "scm-landingpage-plugin")
|
||||
@EagerSingleton
|
||||
public class PluginInstallationFailedEventSubscriber {
|
||||
|
||||
private final ScmEventBus eventBus;
|
||||
|
||||
@Inject
|
||||
public PluginInstallationFailedEventSubscriber(ScmEventBus eventBus) {
|
||||
this.eventBus = eventBus;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void handleEvent(PluginEvent pluginEvent) {
|
||||
if (pluginEvent.getEventType() == PluginEventType.INSTALLATION_FAILED) {
|
||||
AvailablePlugin newPlugin = pluginEvent.getPlugin();
|
||||
|
||||
String permission = PluginPermissions.manage().asShiroString();
|
||||
String pluginName = newPlugin.getDescriptor().getInformation().getDisplayName();
|
||||
|
||||
String pluginVersion = newPlugin.getDescriptor().getInformation().getVersion();
|
||||
|
||||
eventBus.post(new PluginInstallationFailedEvent(permission, pluginName, pluginVersion, Instant.now()));
|
||||
}
|
||||
}
|
||||
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
static class PluginInstallationFailedEvent extends MyEvent {
|
||||
private String pluginName;
|
||||
private String pluginVersion;
|
||||
@XmlJavaTypeAdapter(XmlInstantAdapter.class)
|
||||
private Instant date;
|
||||
|
||||
PluginInstallationFailedEvent(String permission, String pluginName, String pluginVersion, Instant date) {
|
||||
super(PluginInstalledEventSubscriber.PluginInstalledEvent.class.getSimpleName(), permission);
|
||||
|
||||
this.pluginName = pluginName;
|
||||
this.pluginVersion = pluginVersion;
|
||||
this.date = date;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package sonia.scm.plugin;
|
||||
|
||||
import com.cloudogu.scm.myevents.MyEvent;
|
||||
import com.github.legman.Subscribe;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import sonia.scm.EagerSingleton;
|
||||
import sonia.scm.event.ScmEventBus;
|
||||
import sonia.scm.xml.XmlInstantAdapter;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||
import java.time.Instant;
|
||||
import java.util.Optional;
|
||||
|
||||
@Extension(requires = "scm-landingpage-plugin")
|
||||
@EagerSingleton
|
||||
public class PluginInstalledEventSubscriber {
|
||||
|
||||
private final ScmEventBus eventBus;
|
||||
private final PluginManager pluginManager;
|
||||
|
||||
@Inject
|
||||
public PluginInstalledEventSubscriber(ScmEventBus eventBus, PluginManager pluginManager) {
|
||||
this.eventBus = eventBus;
|
||||
this.pluginManager = pluginManager;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void handleEvent(PluginEvent pluginEvent) {
|
||||
if (pluginEvent.getEventType() == PluginEventType.INSTALLED) {
|
||||
AvailablePlugin newPlugin = pluginEvent.getPlugin();
|
||||
Optional<InstalledPlugin> installedPlugin = pluginManager.getInstalled(newPlugin.getDescriptor().getInformation().getDisplayName());
|
||||
|
||||
String permission = PluginPermissions.manage().asShiroString();
|
||||
|
||||
String pluginName = newPlugin.getDescriptor().getInformation().getName();
|
||||
|
||||
String previousPluginVersion = null;
|
||||
if (installedPlugin.isPresent()) {
|
||||
previousPluginVersion = installedPlugin.get().getDescriptor().getInformation().getVersion();
|
||||
}
|
||||
|
||||
String newPluginVersion = newPlugin.getDescriptor().getInformation().getVersion();
|
||||
|
||||
eventBus.post(new PluginInstalledEvent(permission, pluginName, previousPluginVersion, newPluginVersion, Instant.now()));
|
||||
}
|
||||
}
|
||||
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
static class PluginInstalledEvent extends MyEvent {
|
||||
private String pluginName;
|
||||
private String previousPluginVersion;
|
||||
private String newPluginVersion;
|
||||
@XmlJavaTypeAdapter(XmlInstantAdapter.class)
|
||||
private Instant date;
|
||||
|
||||
PluginInstalledEvent(String permission, String pluginName, String previousPluginVersion, String newPluginVersion, Instant date) {
|
||||
super(PluginInstalledEventSubscriber.PluginInstalledEvent.class.getSimpleName(), permission);
|
||||
|
||||
this.pluginName = pluginName;
|
||||
this.previousPluginVersion = previousPluginVersion;
|
||||
this.newPluginVersion = newPluginVersion;
|
||||
this.date = date;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package sonia.scm.repository;
|
||||
|
||||
import com.cloudogu.scm.myevents.MyEvent;
|
||||
import com.github.legman.Subscribe;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import sonia.scm.EagerSingleton;
|
||||
import sonia.scm.HandlerEventType;
|
||||
import sonia.scm.event.ScmEventBus;
|
||||
import sonia.scm.plugin.Extension;
|
||||
import sonia.scm.user.User;
|
||||
import sonia.scm.xml.XmlInstantAdapter;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||
import java.time.Instant;
|
||||
|
||||
@Extension(requires = "scm-landingpage-plugin")
|
||||
@EagerSingleton
|
||||
public class RepositoryCreatedEventSubscriber {
|
||||
|
||||
private final ScmEventBus eventBus;
|
||||
|
||||
@Inject
|
||||
public RepositoryCreatedEventSubscriber(ScmEventBus eventBus) {
|
||||
this.eventBus = eventBus;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void handleEvent(RepositoryEvent event) {
|
||||
if (event.getEventType() == HandlerEventType.CREATE) {
|
||||
Repository eventRepo = event.getItem();
|
||||
String permission = RepositoryPermissions.read(event.getItem()).asShiroString();
|
||||
String repository = eventRepo.getNamespace() + "/" + eventRepo.getName();
|
||||
String creator = SecurityUtils.getSubject().getPrincipals().oneByType(User.class).getDisplayName();
|
||||
Instant date = Instant.now();
|
||||
|
||||
eventBus.post(new RepositoryCreatedEvent(permission, repository, creator, date));
|
||||
}
|
||||
}
|
||||
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
static class RepositoryCreatedEvent extends MyEvent {
|
||||
private String repository;
|
||||
private String creator;
|
||||
@XmlJavaTypeAdapter(XmlInstantAdapter.class)
|
||||
private Instant date;
|
||||
|
||||
RepositoryCreatedEvent(String permission, String repository, String creator, Instant date) {
|
||||
super(RepositoryCreatedEvent.class.getSimpleName(), permission);
|
||||
this.repository = repository;
|
||||
this.creator = creator;
|
||||
this.date = date;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user