diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9523f17b4f..0beb76d3e6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,12 +5,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## Unreleased
-
### Added
- Introduced merge detection for receive hooks ([#1278](https://github.com/scm-manager/scm-manager/pull/1278))
- Anonymous mode for the web ui ([#1284](https://github.com/scm-manager/scm-manager/pull/1284))
- Add link to source file in diff sections ([#1267](https://github.com/scm-manager/scm-manager/pull/1267))
- Check versions of plugin dependencies on plugin installation ([#1283](https://github.com/scm-manager/scm-manager/pull/1283))
+- Sign PR merges and commits performed through ui with generated private key ([#1285](https://github.com/scm-manager/scm-manager/pull/1285))
+- Add generic popover component to ui-components ([#1285](https://github.com/scm-manager/scm-manager/pull/1285))
+- Show changeset signatures in ui and add public keys ([#1273](https://github.com/scm-manager/scm-manager/pull/1273))
### Fixed
- Repository names may not end with ".git" ([#1277](https://github.com/scm-manager/scm-manager/pull/1277))
diff --git a/docs/de/user/repo/assets/repository-code-changesetsView.png b/docs/de/user/repo/assets/repository-code-changesetsView.png
index 4974525c4e..446babec5c 100644
Binary files a/docs/de/user/repo/assets/repository-code-changesetsView.png and b/docs/de/user/repo/assets/repository-code-changesetsView.png differ
diff --git a/docs/de/user/repo/code.md b/docs/de/user/repo/code.md
index 9ec3f29938..a779564ea0 100644
--- a/docs/de/user/repo/code.md
+++ b/docs/de/user/repo/code.md
@@ -17,6 +17,8 @@ Die Übersicht der Changesets/Commits zeigt die Änderungshistorie je Branch an.
Über den Details-Button kann man sich den Inhalt / die Änderungen dieses Changesets ansehen.
+Der Schlüssel Icon zeigt an, ob ein Changeset signiert wurde. Um die Signatur zu validieren, können die Benutzer ihre öffentlichen Schlüssel (Public Keys) im SCM-Manager hinterlegen. Ein grüner Schlüssel bedeutet die Signatur konnte erfolgreich gegen einen hinterlegten öffentlichen Schlüssel im SCM-Manager verifiziert werden. Ein grauer Schlüssel heißt, dass die Signatur zu keinem Schlüssel im SCM-Manager passt. Und ein roter Schlüssel warnt vor einer ungültigen (möglicherweise gefälschten) Signatur.
+
Über den Sources-Button gelangt man zur Sources-Übersicht und es wird der Datenstand zum Zeitpunkt nach diesem Commit angezeigt.

diff --git a/docs/de/user/user/assets/user-settings-publickeys.png b/docs/de/user/user/assets/user-settings-publickeys.png
new file mode 100644
index 0000000000..1608e46b04
Binary files /dev/null and b/docs/de/user/user/assets/user-settings-publickeys.png differ
diff --git a/docs/de/user/user/settings.md b/docs/de/user/user/settings.md
index d9ec76446b..d09de0b98e 100644
--- a/docs/de/user/user/settings.md
+++ b/docs/de/user/user/settings.md
@@ -19,3 +19,8 @@ Hier werden die globalen (nicht-Repository-bezogenen) Berechtigungen für einen
Für die einzelnen Rechte sind Tooltips verfügbar, welche Auskunft über die Auswirkungen der jeweiligen Berechtigung geben.

+
+### Öffentliche Schlüssel
+Es können öffentliche Schlüssel (Public Keys) zu Benutzern hinzugefügt werden, um die Changeset Signaturen damit zu verifizieren.
+
+
diff --git a/docs/en/user/repo/assets/repository-code-changesetsView.png b/docs/en/user/repo/assets/repository-code-changesetsView.png
index 4b466543d6..4cb8f63736 100644
Binary files a/docs/en/user/repo/assets/repository-code-changesetsView.png and b/docs/en/user/repo/assets/repository-code-changesetsView.png differ
diff --git a/docs/en/user/repo/code.md b/docs/en/user/repo/code.md
index b0a8995c88..b0037d563b 100644
--- a/docs/en/user/repo/code.md
+++ b/docs/en/user/repo/code.md
@@ -17,6 +17,8 @@ The changesets/commits overview shows the change history of the branch. Each ent
The Details button leads to the content/changes of a changeset.
+The key icon shows if the changeset was signed. The users can add their public keys to SCM-Manager for signature verification. The green key means that the signature could be verified successfully against an existing public key. The grey key shows that no matching key could be found for the signature. The red key warns you about an invalid (possible faked) signature.
+
The Sources button leads to the sources overview that shows the state from after this commit.

diff --git a/docs/en/user/user/assets/user-settings-publickeys.png b/docs/en/user/user/assets/user-settings-publickeys.png
new file mode 100644
index 0000000000..498fe1e336
Binary files /dev/null and b/docs/en/user/user/assets/user-settings-publickeys.png differ
diff --git a/docs/en/user/user/settings.md b/docs/en/user/user/settings.md
index ec37893bab..328fe414af 100644
--- a/docs/en/user/user/settings.md
+++ b/docs/en/user/user/settings.md
@@ -19,3 +19,8 @@ In the permissions section, the global, therefore not repository-specific permis
There is a tooltip for each permission that provide some more details about the option.

+
+### Public keys
+Add public keys to users to enable changeset signature verification.
+
+
diff --git a/pom.xml b/pom.xml
index c3b5a43318..11ad3f3ff2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -525,6 +525,26 @@
1.14
+
+
+
+ org.bouncycastle
+ bcpg-jdk15on
+ ${bouncycastle.version}
+
+
+
+ org.bouncycastle
+ bcprov-jdk15on
+ ${bouncycastle.version}
+
+
+
+ org.bouncycastle
+ bcpkix-jdk15on
+ ${bouncycastle.version}
+
+
@@ -595,7 +615,7 @@
org.apache.maven.pluginsmaven-enforcer-plugin
- 3.0.0-M1
+ 3.0.0-M3enforce-java
@@ -639,7 +659,7 @@
org.codehaus.mojoextra-enforcer-rules
- 1.0-beta-7
+ 1.3
@@ -899,6 +919,7 @@
4.2.32.3.36.1.5.Final
+ 1.651.6.2
diff --git a/scm-core/pom.xml b/scm-core/pom.xml
index f7df981723..9d4f7e388f 100644
--- a/scm-core/pom.xml
+++ b/scm-core/pom.xml
@@ -112,6 +112,12 @@
${guice.version}
+
+ com.google.inject.extensions
+ guice-assistedinject
+ ${guice.version}
+
+
diff --git a/scm-core/src/main/java/sonia/scm/api/v2/resources/ChangesetDto.java b/scm-core/src/main/java/sonia/scm/api/v2/resources/ChangesetDto.java
index bd94f9e33f..823df43582 100644
--- a/scm-core/src/main/java/sonia/scm/api/v2/resources/ChangesetDto.java
+++ b/scm-core/src/main/java/sonia/scm/api/v2/resources/ChangesetDto.java
@@ -61,6 +61,8 @@ public class ChangesetDto extends HalRepresentation {
private List contributors;
+ private List signatures;
+
public ChangesetDto(Links links, Embedded embedded) {
super(links, embedded);
}
diff --git a/scm-core/src/main/java/sonia/scm/api/v2/resources/SignatureDto.java b/scm-core/src/main/java/sonia/scm/api/v2/resources/SignatureDto.java
new file mode 100644
index 0000000000..e25943e025
--- /dev/null
+++ b/scm-core/src/main/java/sonia/scm/api/v2/resources/SignatureDto.java
@@ -0,0 +1,54 @@
+/*
+ * 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.api.v2.resources;
+
+import de.otto.edison.hal.HalRepresentation;
+import de.otto.edison.hal.Links;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import sonia.scm.repository.Person;
+import sonia.scm.repository.SignatureStatus;
+
+import java.util.Optional;
+import java.util.Set;
+
+@Getter
+@Setter
+@NoArgsConstructor
+@SuppressWarnings("squid:S2160")
+public class SignatureDto extends HalRepresentation {
+
+ private String keyId;
+ private String type;
+ private SignatureStatus status;
+ private Optional owner;
+ private Set contacts;
+
+ public SignatureDto(Links links) {
+ super(links);
+ }
+
+}
diff --git a/scm-core/src/main/java/sonia/scm/repository/Changeset.java b/scm-core/src/main/java/sonia/scm/repository/Changeset.java
index e2c980db37..914fd8f90a 100644
--- a/scm-core/src/main/java/sonia/scm/repository/Changeset.java
+++ b/scm-core/src/main/java/sonia/scm/repository/Changeset.java
@@ -32,6 +32,7 @@ import sonia.scm.util.ValidationUtil;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.Date;
import java.util.List;
@@ -85,6 +86,8 @@ public class Changeset extends BasicPropertiesAware implements ModelObject {
*/
private Collection contributors;
+ private List signatures = new ArrayList<>();
+
public Changeset() {}
public Changeset(String id, Long date, Person author)
@@ -348,4 +351,31 @@ public class Changeset extends BasicPropertiesAware implements ModelObject {
this.contributors.addAll(contributors);
}
}
+
+ /**
+ * Sets a collection of signatures which belong to this changeset.
+ * @param signatures collection of signatures
+ * @since 2.4.0
+ */
+ public void setSignatures(Collection signatures) {
+ this.signatures = new ArrayList<>(signatures);
+ }
+
+ /**
+ * Returns a immutable list of signatures.
+ * @return signatures
+ * @since 2.4.0
+ */
+ public List getSignatures() {
+ return Collections.unmodifiableList(signatures);
+ }
+
+ /**
+ * Adds a signature to the list of signatures.
+ * @param signature
+ * @since 2.4.0
+ */
+ public void addSignature(Signature signature) {
+ signatures.add(signature);
+ }
}
diff --git a/scm-core/src/main/java/sonia/scm/repository/Signature.java b/scm-core/src/main/java/sonia/scm/repository/Signature.java
new file mode 100644
index 0000000000..f0f3e1e492
--- /dev/null
+++ b/scm-core/src/main/java/sonia/scm/repository/Signature.java
@@ -0,0 +1,53 @@
+/*
+ * 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 lombok.Value;
+
+import java.io.Serializable;
+import java.util.Optional;
+import java.util.Set;
+
+/**
+ * Signature is the output of a signature verification.
+ *
+ * @since 2.4.0
+ */
+@Value
+public class Signature implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ private final String keyId;
+ private final String type;
+ private final SignatureStatus status;
+ private final String owner;
+ private final Set contacts;
+
+ public Optional getOwner() {
+ return Optional.ofNullable(owner);
+ }
+
+}
diff --git a/scm-core/src/main/java/sonia/scm/repository/SignatureStatus.java b/scm-core/src/main/java/sonia/scm/repository/SignatureStatus.java
new file mode 100644
index 0000000000..73961353ea
--- /dev/null
+++ b/scm-core/src/main/java/sonia/scm/repository/SignatureStatus.java
@@ -0,0 +1,32 @@
+/*
+ * 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;
+
+/**
+ * @since 2.4.0
+ */
+public enum SignatureStatus {
+ VERIFIED, NOT_FOUND, INVALID;
+}
diff --git a/scm-core/src/main/java/sonia/scm/repository/api/MergeCommandBuilder.java b/scm-core/src/main/java/sonia/scm/repository/api/MergeCommandBuilder.java
index f704b16b3d..55e1f44f3c 100644
--- a/scm-core/src/main/java/sonia/scm/repository/api/MergeCommandBuilder.java
+++ b/scm-core/src/main/java/sonia/scm/repository/api/MergeCommandBuilder.java
@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-
+
package sonia.scm.repository.api;
import com.google.common.base.Preconditions;
@@ -137,6 +137,16 @@ public class MergeCommandBuilder {
return this;
}
+ /**
+ * Disables adding a verifiable signature to the merge commit.
+ * @return This builder instance.
+ * @since 2.4.0
+ */
+ public MergeCommandBuilder disableSigning() {
+ request.setSign(false);
+ return this;
+ }
+
/**
* Use this to set the strategy of the merge commit manually.
*
diff --git a/scm-core/src/main/java/sonia/scm/repository/api/ModifyCommandBuilder.java b/scm-core/src/main/java/sonia/scm/repository/api/ModifyCommandBuilder.java
index 3067d7a054..aeccb24b99 100644
--- a/scm-core/src/main/java/sonia/scm/repository/api/ModifyCommandBuilder.java
+++ b/scm-core/src/main/java/sonia/scm/repository/api/ModifyCommandBuilder.java
@@ -164,6 +164,16 @@ public class ModifyCommandBuilder {
return this;
}
+ /**
+ * Disables adding a verifiable signature to the modification commit.
+ * @return This builder instance.
+ * @since 2.4.0
+ */
+ public ModifyCommandBuilder disableSigning() {
+ request.setSign(false);
+ return this;
+ }
+
/**
* Set the expected revision of the branch, before the changes are applied. If the branch does not have the
* expected revision, a concurrent modification exception will be thrown when the command is executed and no
diff --git a/scm-core/src/main/java/sonia/scm/repository/api/RepositoryServiceFactory.java b/scm-core/src/main/java/sonia/scm/repository/api/RepositoryServiceFactory.java
index 31ca9ca15d..d7074b7f4b 100644
--- a/scm-core/src/main/java/sonia/scm/repository/api/RepositoryServiceFactory.java
+++ b/scm-core/src/main/java/sonia/scm/repository/api/RepositoryServiceFactory.java
@@ -55,6 +55,8 @@ import sonia.scm.repository.RepositoryPermissions;
import sonia.scm.repository.spi.RepositoryServiceProvider;
import sonia.scm.repository.spi.RepositoryServiceResolver;
import sonia.scm.repository.work.WorkdirProvider;
+import sonia.scm.security.PublicKeyCreatedEvent;
+import sonia.scm.security.PublicKeyDeletedEvent;
import sonia.scm.security.ScmSecurityException;
import java.util.Set;
@@ -100,14 +102,12 @@ import static sonia.scm.NotFoundException.notFound;
*
*
* @author Sebastian Sdorra
- * @since 1.17
- *
* @apiviz.landmark
* @apiviz.uses sonia.scm.repository.api.RepositoryService
+ * @since 1.17
*/
@Singleton
-public final class RepositoryServiceFactory
-{
+public final class RepositoryServiceFactory {
/**
* the logger for RepositoryServiceFactory
@@ -122,12 +122,11 @@ public final class RepositoryServiceFactory
* should not be called manually, it should only be used by the injection
* container.
*
- *
- * @param configuration configuration
- * @param cacheManager cache manager
+ * @param configuration configuration
+ * @param cacheManager cache manager
* @param repositoryManager manager for repositories
- * @param resolvers a set of {@link RepositoryServiceResolver}
- * @param preProcessorUtil helper object for pre processor handling
+ * @param resolvers a set of {@link RepositoryServiceResolver}
+ * @param preProcessorUtil helper object for pre processor handling
* @param protocolProviders
* @param workdirProvider
* @since 1.21
@@ -136,8 +135,7 @@ public final class RepositoryServiceFactory
public RepositoryServiceFactory(ScmConfiguration configuration,
CacheManager cacheManager, RepositoryManager repositoryManager,
Set resolvers, PreProcessorUtil preProcessorUtil,
- Set protocolProviders, WorkdirProvider workdirProvider)
- {
+ @SuppressWarnings("rawtypes") Set protocolProviders, WorkdirProvider workdirProvider) {
this(
configuration, cacheManager, repositoryManager, resolvers,
preProcessorUtil, protocolProviders, workdirProvider, ScmEventBus.getInstance()
@@ -146,11 +144,10 @@ public final class RepositoryServiceFactory
@VisibleForTesting
RepositoryServiceFactory(ScmConfiguration configuration,
- CacheManager cacheManager, RepositoryManager repositoryManager,
- Set resolvers, PreProcessorUtil preProcessorUtil,
- Set protocolProviders, WorkdirProvider workdirProvider,
- ScmEventBus eventBus)
- {
+ CacheManager cacheManager, RepositoryManager repositoryManager,
+ Set resolvers, PreProcessorUtil preProcessorUtil,
+ Set protocolProviders, WorkdirProvider workdirProvider,
+ ScmEventBus eventBus) {
this.configuration = configuration;
this.cacheManager = cacheManager;
this.repositoryManager = repositoryManager;
@@ -167,19 +164,16 @@ public final class RepositoryServiceFactory
/**
* Creates a new RepositoryService for the given repository.
*
- *
* @param repositoryId id of the repository
- *
* @return a implementation of RepositoryService
- * for the given type of repository
- *
- * @throws NotFoundException if no repository
- * with the given id is available
+ * for the given type of repository
+ * @throws NotFoundException if no repository
+ * with the given id is available
* @throws RepositoryServiceNotFoundException if no repository service
- * implementation for this kind of repository is available
- * @throws IllegalArgumentException if the repository id is null or empty
- * @throws ScmSecurityException if current user has not read permissions
- * for that repository
+ * implementation for this kind of repository is available
+ * @throws IllegalArgumentException if the repository id is null or empty
+ * @throws ScmSecurityException if current user has not read permissions
+ * for that repository
*/
public RepositoryService create(String repositoryId) {
Preconditions.checkArgument(!Strings.isNullOrEmpty(repositoryId),
@@ -187,8 +181,7 @@ public final class RepositoryServiceFactory
Repository repository = repositoryManager.get(repositoryId);
- if (repository == null)
- {
+ if (repository == null) {
throw new NotFoundException(Repository.class, repositoryId);
}
@@ -198,29 +191,24 @@ public final class RepositoryServiceFactory
/**
* Creates a new RepositoryService for the given repository.
*
- *
* @param namespaceAndName namespace and name of the repository
- *
* @return a implementation of RepositoryService
- * for the given type of repository
- *
- * @throws NotFoundException if no repository
- * with the given id is available
+ * for the given type of repository
+ * @throws NotFoundException if no repository
+ * with the given id is available
* @throws RepositoryServiceNotFoundException if no repository service
- * implementation for this kind of repository is available
- * @throws IllegalArgumentException if one of the parameters is null or empty
- * @throws ScmSecurityException if current user has not read permissions
- * for that repository
+ * implementation for this kind of repository is available
+ * @throws IllegalArgumentException if one of the parameters is null or empty
+ * @throws ScmSecurityException if current user has not read permissions
+ * for that repository
*/
- public RepositoryService create(NamespaceAndName namespaceAndName)
- {
+ public RepositoryService create(NamespaceAndName namespaceAndName) {
Preconditions.checkArgument(namespaceAndName != null,
"a non empty namespace and name is required");
Repository repository = repositoryManager.get(namespaceAndName);
- if (repository == null)
- {
+ if (repository == null) {
throw notFound(entity(namespaceAndName));
}
@@ -230,20 +218,16 @@ public final class RepositoryServiceFactory
/**
* Creates a new RepositoryService for the given repository.
*
- *
* @param repository the repository
- *
* @return a implementation of RepositoryService
- * for the given type of repository
- *
+ * for the given type of repository
* @throws RepositoryServiceNotFoundException if no repository service
- * implementation for this kind of repository is available
- * @throws NullPointerException if the repository is null
- * @throws ScmSecurityException if current user has not read permissions
- * for that repository
+ * implementation for this kind of repository is available
+ * @throws NullPointerException if the repository is null
+ * @throws ScmSecurityException if current user has not read permissions
+ * for that repository
*/
- public RepositoryService create(Repository repository)
- {
+ public RepositoryService create(Repository repository) {
Preconditions.checkNotNull(repository, "repository is required");
// check for read permissions of current user
@@ -251,14 +235,11 @@ public final class RepositoryServiceFactory
RepositoryService service = null;
- for (RepositoryServiceResolver resolver : resolvers)
- {
+ for (RepositoryServiceResolver resolver : resolvers) {
RepositoryServiceProvider provider = resolver.resolve(repository);
- if (provider != null)
- {
- if (logger.isDebugEnabled())
- {
+ if (provider != null) {
+ if (logger.isDebugEnabled()) {
logger.debug(
"create new repository service for repository {} of type {}",
repository.getName(), repository.getType());
@@ -271,8 +252,7 @@ public final class RepositoryServiceFactory
}
}
- if (service == null)
- {
+ if (service == null) {
throw new RepositoryServiceNotFoundException(repository);
}
@@ -284,8 +264,7 @@ public final class RepositoryServiceFactory
/**
* Hook and listener to clear all relevant repository caches.
*/
- private static class CacheClearHook
- {
+ private static class CacheClearHook {
private final Set> caches = Sets.newHashSet();
private final CacheManager cacheManager;
@@ -296,8 +275,7 @@ public final class RepositoryServiceFactory
*
* @param cacheManager cache manager
*/
- public CacheClearHook(CacheManager cacheManager)
- {
+ public CacheClearHook(CacheManager cacheManager) {
this.cacheManager = cacheManager;
this.caches.add(cacheManager.getCache(BlameCommandBuilder.CACHE_NAME));
this.caches.add(cacheManager.getCache(BrowseCommandBuilder.CACHE_NAME));
@@ -324,12 +302,10 @@ public final class RepositoryServiceFactory
* @param event hook event
*/
@Subscribe(referenceType = ReferenceType.STRONG)
- public void onEvent(PostReceiveRepositoryHookEvent event)
- {
+ public void onEvent(PostReceiveRepositoryHookEvent event) {
Repository repository = event.getRepository();
- if (repository != null)
- {
+ if (repository != null) {
String id = repository.getId();
clearCaches(id);
@@ -342,10 +318,8 @@ public final class RepositoryServiceFactory
* @param event repository event
*/
@Subscribe(referenceType = ReferenceType.STRONG)
- public void onEvent(RepositoryEvent event)
- {
- if (event.getEventType() == HandlerEventType.DELETE)
- {
+ public void onEvent(RepositoryEvent event) {
+ if (event.getEventType() == HandlerEventType.DELETE) {
clearCaches(event.getItem().getId());
}
}
@@ -357,37 +331,53 @@ public final class RepositoryServiceFactory
cacheManager.getCache(BranchesCommandBuilder.CACHE_NAME).removeAll(predicate);
}
+ @Subscribe
+ public void onEvent(PublicKeyDeletedEvent event) {
+ cacheManager.getCache(LogCommandBuilder.CACHE_NAME).clear();
+ }
+
+ @Subscribe
+ public void onEvent(PublicKeyCreatedEvent event) {
+ cacheManager.getCache(LogCommandBuilder.CACHE_NAME).clear();
+ }
+
@SuppressWarnings({"unchecked", "java:S3740", "rawtypes"})
- private void clearCaches(final String repositoryId)
- {
- if (logger.isDebugEnabled())
- {
+ private void clearCaches(final String repositoryId) {
+ if (logger.isDebugEnabled()) {
logger.debug("clear caches for repository id {}", repositoryId);
}
RepositoryCacheKeyPredicate predicate = new RepositoryCacheKeyPredicate(repositoryId);
- caches.forEach((cache) -> {
- cache.removeAll(predicate);
- });
+ caches.forEach(cache -> cache.removeAll(predicate));
}
}
//~--- fields ---------------------------------------------------------------
- /** cache manager */
+ /**
+ * cache manager
+ */
private final CacheManager cacheManager;
- /** scm-manager configuration */
+ /**
+ * scm-manager configuration
+ */
private final ScmConfiguration configuration;
- /** pre processor util */
+ /**
+ * pre processor util
+ */
private final PreProcessorUtil preProcessorUtil;
- /** repository manager */
+ /**
+ * repository manager
+ */
private final RepositoryManager repositoryManager;
- /** service resolvers */
+ /**
+ * service resolvers
+ */
private final Set resolvers;
private Set protocolProviders;
diff --git a/scm-core/src/main/java/sonia/scm/repository/spi/MergeCommandRequest.java b/scm-core/src/main/java/sonia/scm/repository/spi/MergeCommandRequest.java
index 043f0f9648..5fa755668f 100644
--- a/scm-core/src/main/java/sonia/scm/repository/spi/MergeCommandRequest.java
+++ b/scm-core/src/main/java/sonia/scm/repository/spi/MergeCommandRequest.java
@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-
+
package sonia.scm.repository.spi;
import com.google.common.base.MoreObjects;
@@ -43,6 +43,7 @@ public class MergeCommandRequest implements Validateable, Resetable, Serializabl
private Person author;
private String messageTemplate;
private MergeStrategy mergeStrategy;
+ private boolean sign = true;
public String getBranchToMerge() {
return branchToMerge;
@@ -84,6 +85,14 @@ public class MergeCommandRequest implements Validateable, Resetable, Serializabl
this.mergeStrategy = mergeStrategy;
}
+ public boolean isSign() {
+ return sign;
+ }
+
+ public void setSign(boolean sign) {
+ this.sign = sign;
+ }
+
public boolean isValid() {
return !Strings.isNullOrEmpty(getBranchToMerge())
&& !Strings.isNullOrEmpty(getTargetBranch());
@@ -92,6 +101,7 @@ public class MergeCommandRequest implements Validateable, Resetable, Serializabl
public void reset() {
this.setBranchToMerge(null);
this.setTargetBranch(null);
+ this.setSign(true);
}
@Override
@@ -109,7 +119,8 @@ public class MergeCommandRequest implements Validateable, Resetable, Serializabl
return Objects.equal(branchToMerge, other.branchToMerge)
&& Objects.equal(targetBranch, other.targetBranch)
&& Objects.equal(author, other.author)
- && Objects.equal(mergeStrategy, other.mergeStrategy);
+ && Objects.equal(mergeStrategy, other.mergeStrategy)
+ && Objects.equal(sign, other.sign);
}
@Override
@@ -124,6 +135,7 @@ public class MergeCommandRequest implements Validateable, Resetable, Serializabl
.add("targetBranch", targetBranch)
.add("author", author)
.add("mergeStrategy", mergeStrategy)
+ .add("sign", sign)
.toString();
}
}
diff --git a/scm-core/src/main/java/sonia/scm/repository/spi/ModificationsCommandRequest.java b/scm-core/src/main/java/sonia/scm/repository/spi/ModificationsCommandRequest.java
index d0c05fd99d..507af8b514 100644
--- a/scm-core/src/main/java/sonia/scm/repository/spi/ModificationsCommandRequest.java
+++ b/scm-core/src/main/java/sonia/scm/repository/spi/ModificationsCommandRequest.java
@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-
+
package sonia.scm.repository.spi;
diff --git a/scm-core/src/main/java/sonia/scm/repository/spi/ModifyCommandRequest.java b/scm-core/src/main/java/sonia/scm/repository/spi/ModifyCommandRequest.java
index 8f077430df..e82df8c15a 100644
--- a/scm-core/src/main/java/sonia/scm/repository/spi/ModifyCommandRequest.java
+++ b/scm-core/src/main/java/sonia/scm/repository/spi/ModifyCommandRequest.java
@@ -49,6 +49,7 @@ public class ModifyCommandRequest implements Resetable, Validateable, CommandWit
private String branch;
private String expectedRevision;
private boolean defaultPath;
+ private boolean sign = true;
@Override
public void reset() {
@@ -57,6 +58,7 @@ public class ModifyCommandRequest implements Resetable, Validateable, CommandWit
commitMessage = null;
branch = null;
defaultPath = false;
+ sign = true;
}
public void addRequest(PartialRequest request) {
@@ -75,6 +77,10 @@ public class ModifyCommandRequest implements Resetable, Validateable, CommandWit
this.branch = branch;
}
+ public void setSign(boolean sign) {
+ this.sign = sign;
+ }
+
public List getRequests() {
return Collections.unmodifiableList(requests);
}
@@ -112,6 +118,10 @@ public class ModifyCommandRequest implements Resetable, Validateable, CommandWit
this.defaultPath = defaultPath;
}
+ public boolean isSign() {
+ return sign;
+ }
+
public interface PartialRequest {
void execute(ModifyCommand.Worker worker) throws IOException;
}
diff --git a/scm-core/src/main/java/sonia/scm/security/GPG.java b/scm-core/src/main/java/sonia/scm/security/GPG.java
new file mode 100644
index 0000000000..2f75b8d5dc
--- /dev/null
+++ b/scm-core/src/main/java/sonia/scm/security/GPG.java
@@ -0,0 +1,66 @@
+/*
+ * 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.security;
+
+import java.util.Optional;
+
+/**
+ * Allows signing and verification using gpg.
+ *
+ * @since 2.4.0
+ */
+public interface GPG {
+
+ /**
+ * Returns the id of the key from the given signature.
+ *
+ * @param signature signature
+ * @return public key id
+ */
+ String findPublicKeyId(byte[] signature);
+
+ /**
+ * Returns the public key with the given id or an empty optional.
+ *
+ * @param id id of public
+ * @return public key or empty optional
+ */
+ Optional findPublicKey(String id);
+
+ /**
+ * Returns all public keys assigned to the given username
+ *
+ * @param username username of the public key owner
+ * @return collection of public keys
+ */
+ Iterable findPublicKeysByUsername(String username);
+
+ /**
+ * Returns the default private key of the currently authenticated user.
+ *
+ * @return default private key
+ */
+ PrivateKey getPrivateKey();
+}
diff --git a/scm-core/src/main/java/sonia/scm/security/NotPublicKeyException.java b/scm-core/src/main/java/sonia/scm/security/NotPublicKeyException.java
new file mode 100644
index 0000000000..3d8775a09a
--- /dev/null
+++ b/scm-core/src/main/java/sonia/scm/security/NotPublicKeyException.java
@@ -0,0 +1,46 @@
+/*
+ * 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.security;
+
+import sonia.scm.BadRequestException;
+import sonia.scm.ContextEntry;
+
+import java.util.List;
+
+@SuppressWarnings("squid:MaximumInheritanceDepth") // exceptions have a deep inheritance depth themselves; therefore we accept this here
+public class NotPublicKeyException extends BadRequestException {
+ public NotPublicKeyException(List context, String message) {
+ super(context, message);
+ }
+
+ public NotPublicKeyException(List context, String message, Exception cause) {
+ super(context, message, cause);
+ }
+
+ @Override
+ public String getCode() {
+ return "BxS5wX2v71";
+ }
+}
diff --git a/scm-core/src/main/java/sonia/scm/security/PrivateKey.java b/scm-core/src/main/java/sonia/scm/security/PrivateKey.java
new file mode 100644
index 0000000000..0ae639a3db
--- /dev/null
+++ b/scm-core/src/main/java/sonia/scm/security/PrivateKey.java
@@ -0,0 +1,57 @@
+/*
+ * 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.security;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+/**
+ * Can be used to create signatures of data.
+ * @since 2.4.0
+ */
+public interface PrivateKey {
+
+ /**
+ * Returns the key's id.
+ * @return id
+ */
+ String getId();
+
+ /**
+ * Creates a signature for the given data.
+ * @param stream data stream to sign
+ * @return signature
+ */
+ byte[] sign(InputStream stream);
+
+ /**
+ * Creates a signature for the given data.
+ * @param data data to sign
+ * @return signature
+ */
+ default byte[] sign(byte[] data) {
+ return sign(new ByteArrayInputStream(data));
+ }
+}
diff --git a/scm-core/src/main/java/sonia/scm/security/PublicKey.java b/scm-core/src/main/java/sonia/scm/security/PublicKey.java
new file mode 100644
index 0000000000..003863d696
--- /dev/null
+++ b/scm-core/src/main/java/sonia/scm/security/PublicKey.java
@@ -0,0 +1,88 @@
+/*
+ * 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.security;
+
+import sonia.scm.repository.Person;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.Optional;
+import java.util.Set;
+
+/**
+ * The public key can be used to verify signatures.
+ *
+ * @since 2.4.0
+ */
+public interface PublicKey {
+
+ /**
+ * Returns id of the public key.
+ *
+ * @return id of key
+ */
+ String getId();
+
+ /**
+ * Returns the username of the owner or an empty optional.
+ *
+ * @return owner or empty optional
+ */
+ Optional getOwner();
+
+ /**
+ * Returns raw of the public key.
+ *
+ * @return raw of key
+ */
+ String getRaw();
+
+ /**
+ * Returns the contacts of the publickey.
+ *
+ * @return owner or empty optional
+ */
+ Set getContacts();
+
+ /**
+ * Verifies that the signature is valid for the given data.
+ *
+ * @param stream stream of data to verify
+ * @param signature signature
+ * @return {@code true} if the signature is valid for the given data
+ */
+ boolean verify(InputStream stream, byte[] signature);
+
+ /**
+ * Verifies that the signature is valid for the given data.
+ *
+ * @param data data to verify
+ * @param signature signature
+ * @return {@code true} if the signature is valid for the given data
+ */
+ default boolean verify(byte[] data, byte[] signature) {
+ return verify(new ByteArrayInputStream(data), signature);
+ }
+}
diff --git a/scm-core/src/main/java/sonia/scm/security/PublicKeyCreatedEvent.java b/scm-core/src/main/java/sonia/scm/security/PublicKeyCreatedEvent.java
new file mode 100644
index 0000000000..a598533088
--- /dev/null
+++ b/scm-core/src/main/java/sonia/scm/security/PublicKeyCreatedEvent.java
@@ -0,0 +1,44 @@
+/*
+ * 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.security;
+
+import sonia.scm.event.Event;
+
+/**
+ * This event is fired when a public key was created in SCM-Manager.
+ * @since 2.4.0
+ */
+@Event
+public final class PublicKeyCreatedEvent {
+ private final PublicKey key;
+
+ public PublicKeyCreatedEvent(PublicKey key) {
+ this.key = key;
+ }
+
+ public PublicKey getKey() {
+ return key;
+ }
+}
diff --git a/scm-core/src/main/java/sonia/scm/security/PublicKeyDeletedEvent.java b/scm-core/src/main/java/sonia/scm/security/PublicKeyDeletedEvent.java
new file mode 100644
index 0000000000..833af8dee2
--- /dev/null
+++ b/scm-core/src/main/java/sonia/scm/security/PublicKeyDeletedEvent.java
@@ -0,0 +1,44 @@
+/*
+ * 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.security;
+
+import sonia.scm.event.Event;
+
+/**
+ * This event is fired when a public key was removed from SCM-Manager.
+ * @since 2.4.0
+ */
+@Event
+public final class PublicKeyDeletedEvent {
+ private final PublicKey key;
+
+ public PublicKeyDeletedEvent(PublicKey key) {
+ this.key = key;
+ }
+
+ public PublicKey getKey() {
+ return key;
+ }
+}
diff --git a/scm-core/src/main/java/sonia/scm/user/User.java b/scm-core/src/main/java/sonia/scm/user/User.java
index cd2afb282d..1b0a3b2388 100644
--- a/scm-core/src/main/java/sonia/scm/user/User.java
+++ b/scm-core/src/main/java/sonia/scm/user/User.java
@@ -50,7 +50,7 @@ import java.security.Principal;
@StaticPermissions(
value = "user",
globalPermissions = {"create", "list", "autocomplete"},
- permissions = {"read", "modify", "delete", "changePassword"},
+ permissions = {"read", "modify", "delete", "changePassword", "changePublicKeys"},
custom = true, customGlobal = true
)
@XmlRootElement(name = "users")
diff --git a/scm-plugins/scm-git-plugin/src/main/java/org/eclipse/jgit/transport/ScmTransportProtocol.java b/scm-plugins/scm-git-plugin/src/main/java/org/eclipse/jgit/transport/ScmTransportProtocol.java
index 6c5efe722c..61c3013f36 100644
--- a/scm-plugins/scm-git-plugin/src/main/java/org/eclipse/jgit/transport/ScmTransportProtocol.java
+++ b/scm-plugins/scm-git-plugin/src/main/java/org/eclipse/jgit/transport/ScmTransportProtocol.java
@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-
+
package org.eclipse.jgit.transport;
//~--- non-JDK imports --------------------------------------------------------
@@ -29,200 +29,106 @@ package org.eclipse.jgit.transport;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Inject;
import com.google.inject.Provider;
-
import org.eclipse.jgit.errors.NoRemoteRepositoryException;
-import org.eclipse.jgit.errors.NotSupportedException;
import org.eclipse.jgit.errors.TransportException;
import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryCache;
-
+import sonia.scm.repository.GitChangesetConverterFactory;
import sonia.scm.repository.GitRepositoryHandler;
import sonia.scm.repository.spi.HookEventFacade;
import sonia.scm.web.CollectingPackParserListener;
import sonia.scm.web.GitReceiveHook;
-//~--- JDK imports ------------------------------------------------------------
-
import java.io.File;
-
import java.util.Set;
+//~--- JDK imports ------------------------------------------------------------
+
/**
- *
* @author Sebastian Sdorra
*/
-public class ScmTransportProtocol extends TransportProtocol
-{
+public class ScmTransportProtocol extends TransportProtocol {
- /** Field description */
public static final String NAME = "scm";
-
- /** Field description */
private static final Set SCHEMES = ImmutableSet.of(NAME);
- //~--- constructors ---------------------------------------------------------
+ private Provider converterFactory;
+ private Provider hookEventFacadeProvider;
+ private Provider repositoryHandlerProvider;
- /**
- * Constructs ...
- *
- */
- public ScmTransportProtocol() {}
+ public ScmTransportProtocol() {
+ }
- /**
- * Constructs ...
- *
- *
- *
- * @param hookEventFacadeProvider
- *
- * @param repositoryHandlerProvider
- */
@Inject
public ScmTransportProtocol(
+ Provider converterFactory,
Provider hookEventFacadeProvider,
- Provider repositoryHandlerProvider)
- {
+ Provider repositoryHandlerProvider) {
+ this.converterFactory = converterFactory;
this.hookEventFacadeProvider = hookEventFacadeProvider;
this.repositoryHandlerProvider = repositoryHandlerProvider;
}
- //~--- methods --------------------------------------------------------------
-
- /**
- * Method description
- *
- *
- * @param uri
- * @param local
- * @param remoteName
- *
- * @return
- */
@Override
- public boolean canHandle(URIish uri, Repository local, String remoteName)
- {
- if ((uri.getPath() == null) || (uri.getPort() > 0)
- || (uri.getUser() != null) || (uri.getPass() != null)
- || (uri.getHost() != null)
- || ((uri.getScheme() != null) &&!getSchemes().contains(uri.getScheme())))
- {
- return false;
- }
-
- return true;
+ public boolean canHandle(URIish uri, Repository local, String remoteName) {
+ return (uri.getPath() != null) && (uri.getPort() <= 0)
+ && (uri.getUser() == null) && (uri.getPass() == null)
+ && (uri.getHost() == null)
+ && ((uri.getScheme() == null) || getSchemes().contains(uri.getScheme()));
}
- /**
- * Method description
- *
- *
- * @param uri
- * @param local
- * @param remoteName
- *
- * @return
- *
- * @throws NotSupportedException
- * @throws TransportException
- */
@Override
- public Transport open(URIish uri, Repository local, String remoteName)
- throws TransportException
- {
+ public Transport open(URIish uri, Repository local, String remoteName) throws TransportException {
File localDirectory = local.getDirectory();
File path = local.getFS().resolve(localDirectory, uri.getPath());
File gitDir = RepositoryCache.FileKey.resolve(path, local.getFS());
- if (gitDir == null)
- {
+ if (gitDir == null) {
throw new NoRemoteRepositoryException(uri, JGitText.get().notFound);
}
- //J-
return new TransportLocalWithHooks(
+ converterFactory.get(),
hookEventFacadeProvider.get(),
repositoryHandlerProvider.get(),
local, uri, gitDir
);
- //J+
}
- //~--- get methods ----------------------------------------------------------
-
- /**
- * Method description
- *
- *
- * @return
- */
@Override
- public String getName()
- {
+ public String getName() {
return NAME;
}
- /**
- * Method description
- *
- *
- * @return
- */
@Override
- public Set getSchemes()
- {
+ public Set getSchemes() {
return SCHEMES;
}
- //~--- inner classes --------------------------------------------------------
+ private static class TransportLocalWithHooks extends TransportLocal {
- /**
- * Class description
- *
- *
- * @version Enter version here..., 13/05/19
- * @author Enter your name here...
- */
- private static class TransportLocalWithHooks extends TransportLocal
- {
+ private final GitChangesetConverterFactory converterFactory;
+ private final GitRepositoryHandler handler;
+ private final HookEventFacade hookEventFacade;
- /**
- * Constructs ...
- *
- *
- *
- * @param hookEventFacade
- * @param handler
- * @param local
- * @param uri
- * @param gitDir
- */
- public TransportLocalWithHooks(HookEventFacade hookEventFacade,
- GitRepositoryHandler handler, Repository local, URIish uri, File gitDir)
- {
+ public TransportLocalWithHooks(
+ GitChangesetConverterFactory converterFactory,
+ HookEventFacade hookEventFacade,
+ GitRepositoryHandler handler,
+ Repository local, URIish uri, File gitDir) {
super(local, uri, gitDir);
+ this.converterFactory = converterFactory;
this.hookEventFacade = hookEventFacade;
this.handler = handler;
}
- //~--- methods ------------------------------------------------------------
-
- /**
- * Method description
- *
- *
- * @param dst
- *
- * @return
- */
@Override
- ReceivePack createReceivePack(Repository dst)
- {
+ ReceivePack createReceivePack(Repository dst) {
ReceivePack pack = new ReceivePack(dst);
- if ((hookEventFacade != null) && (handler != null))
- {
- GitReceiveHook hook = new GitReceiveHook(hookEventFacade, handler);
+ if ((hookEventFacade != null) && (handler != null) && (converterFactory != null)) {
+ GitReceiveHook hook = new GitReceiveHook(converterFactory, hookEventFacade, handler);
pack.setPreReceiveHook(hook);
pack.setPostReceiveHook(hook);
@@ -232,22 +138,6 @@ public class ScmTransportProtocol extends TransportProtocol
return pack;
}
-
- //~--- fields -------------------------------------------------------------
-
- /** Field description */
- private GitRepositoryHandler handler;
-
- /** Field description */
- private HookEventFacade hookEventFacade;
}
-
- //~--- fields ---------------------------------------------------------------
-
- /** Field description */
- private Provider hookEventFacadeProvider;
-
- /** Field description */
- private Provider repositoryHandlerProvider;
}
diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/protocolcommand/git/BaseReceivePackFactory.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/protocolcommand/git/BaseReceivePackFactory.java
index 9b18991d1a..028e91009d 100644
--- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/protocolcommand/git/BaseReceivePackFactory.java
+++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/protocolcommand/git/BaseReceivePackFactory.java
@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-
+
package sonia.scm.protocolcommand.git;
import org.eclipse.jgit.lib.Repository;
@@ -29,6 +29,7 @@ import org.eclipse.jgit.transport.ReceivePack;
import org.eclipse.jgit.transport.resolver.ReceivePackFactory;
import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException;
import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException;
+import sonia.scm.repository.GitChangesetConverterFactory;
import sonia.scm.repository.GitRepositoryHandler;
import sonia.scm.repository.spi.HookEventFacade;
import sonia.scm.web.CollectingPackParserListener;
@@ -39,9 +40,9 @@ public abstract class BaseReceivePackFactory implements ReceivePackFactory
private final GitRepositoryHandler handler;
private final GitReceiveHook hook;
- protected BaseReceivePackFactory(GitRepositoryHandler handler, HookEventFacade hookEventFacade) {
+ protected BaseReceivePackFactory(GitChangesetConverterFactory converterFactory, GitRepositoryHandler handler, HookEventFacade hookEventFacade) {
this.handler = handler;
- this.hook = new GitReceiveHook(hookEventFacade, handler);
+ this.hook = new GitReceiveHook(converterFactory, hookEventFacade, handler);
}
@Override
diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/protocolcommand/git/ScmReceivePackFactory.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/protocolcommand/git/ScmReceivePackFactory.java
index f15ccfcf99..a999a57d4d 100644
--- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/protocolcommand/git/ScmReceivePackFactory.java
+++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/protocolcommand/git/ScmReceivePackFactory.java
@@ -21,21 +21,22 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-
+
package sonia.scm.protocolcommand.git;
import com.google.inject.Inject;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.transport.ReceivePack;
import sonia.scm.protocolcommand.RepositoryContext;
+import sonia.scm.repository.GitChangesetConverterFactory;
import sonia.scm.repository.GitRepositoryHandler;
import sonia.scm.repository.spi.HookEventFacade;
public class ScmReceivePackFactory extends BaseReceivePackFactory {
@Inject
- public ScmReceivePackFactory(GitRepositoryHandler handler, HookEventFacade hookEventFacade) {
- super(handler, hookEventFacade);
+ public ScmReceivePackFactory(GitChangesetConverterFactory converterFactory, GitRepositoryHandler handler, HookEventFacade hookEventFacade) {
+ super(converterFactory, handler, hookEventFacade);
}
@Override
diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitChangesetConverter.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitChangesetConverter.java
index 0f08f54aaa..1262353e1d 100644
--- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitChangesetConverter.java
+++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitChangesetConverter.java
@@ -26,6 +26,7 @@ package sonia.scm.repository;
//~--- non-JDK imports --------------------------------------------------------
+import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import org.eclipse.jgit.lib.ObjectId;
@@ -33,138 +34,55 @@ import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.treewalk.TreeWalk;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.eclipse.jgit.util.RawParseUtils;
+import sonia.scm.security.GPG;
+import sonia.scm.security.PublicKey;
import sonia.scm.util.Util;
+import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import java.util.Optional;
//~--- JDK imports ------------------------------------------------------------
/**
- *
* @author Sebastian Sdorra
*/
-public class GitChangesetConverter implements Closeable
-{
+public class GitChangesetConverter implements Closeable {
- /**
- * the logger for GitChangesetConverter
- */
- private static final Logger logger =
- LoggerFactory.getLogger(GitChangesetConverter.class);
-
- //~--- constructors ---------------------------------------------------------
-
- /**
- * Constructs ...
- *
- *
- * @param repository
- */
- public GitChangesetConverter(org.eclipse.jgit.lib.Repository repository)
- {
- this(repository, null);
- }
-
- /**
- * Constructs ...
- *
- *
- * @param repository
- * @param revWalk
- */
- public GitChangesetConverter(org.eclipse.jgit.lib.Repository repository,
- RevWalk revWalk)
- {
- this.repository = repository;
-
- if (revWalk != null)
- {
- this.revWalk = revWalk;
-
- }
- else
- {
- this.revWalk = new RevWalk(repository);
- }
+ private final GPG gpg;
+ private final Multimap tags;
+ private final TreeWalk treeWalk;
+ public GitChangesetConverter(GPG gpg, org.eclipse.jgit.lib.Repository repository, RevWalk revWalk) {
+ this.gpg = gpg;
this.tags = GitUtil.createTagMap(repository, revWalk);
- treeWalk = new TreeWalk(repository);
+ this.treeWalk = new TreeWalk(repository);
}
- //~--- methods --------------------------------------------------------------
-
- /**
- * Method description
- *
- */
- @Override
- public void close()
- {
- GitUtil.release(treeWalk);
- }
-
- /**
- * Method description
- *
- *
- * @param commit
- *
- * @return
- *
- * @throws IOException
- */
- public Changeset createChangeset(RevCommit commit)
- {
+ public Changeset createChangeset(RevCommit commit) {
return createChangeset(commit, Collections.emptyList());
}
- /**
- * Method description
- *
- *
- * @param commit
- * @param branch
- *
- * @return
- *
- * @throws IOException
- */
- public Changeset createChangeset(RevCommit commit, String branch)
- {
+ public Changeset createChangeset(RevCommit commit, String branch) {
return createChangeset(commit, Lists.newArrayList(branch));
}
- /**
- * Method description
- *
- *
- *
- * @param commit
- * @param branches
- *
- * @return
- *
- * @throws IOException
- */
- public Changeset createChangeset(RevCommit commit, List branches)
- {
+ public Changeset createChangeset(RevCommit commit, List branches) {
String id = commit.getId().name();
List parentList = null;
RevCommit[] parents = commit.getParents();
- if (Util.isNotEmpty(parents))
- {
- parentList = new ArrayList();
+ if (Util.isNotEmpty(parents)) {
+ parentList = new ArrayList<>();
- for (RevCommit parent : parents)
- {
+ for (RevCommit parent : parents) {
parentList.add(parent.getId().name());
}
}
@@ -175,8 +93,7 @@ public class GitChangesetConverter implements Closeable
Person author = createPersonFor(authorIndent);
String message = commit.getFullMessage();
- if (message != null)
- {
+ if (message != null) {
message = message.trim();
}
@@ -185,41 +102,83 @@ public class GitChangesetConverter implements Closeable
changeset.addContributor(new Contributor("Committed-by", createPersonFor(committerIdent)));
}
- if (parentList != null)
- {
+ if (parentList != null) {
changeset.setParents(parentList);
}
Collection tagCollection = tags.get(commit.getId());
- if (Util.isNotEmpty(tagCollection))
- {
-
+ if (Util.isNotEmpty(tagCollection)) {
// create a copy of the tag collection to reduce memory on caching
changeset.getTags().addAll(Lists.newArrayList(tagCollection));
}
changeset.setBranches(branches);
+ Signature signature = createSignature(commit);
+ if (signature != null) {
+ changeset.addSignature(signature);
+ }
+
return changeset;
}
+ private static final byte[] GPG_HEADER = {'g', 'p', 'g', 's', 'i', 'g'};
+
+ private Signature createSignature(RevCommit commit) {
+ byte[] raw = commit.getRawBuffer();
+
+ int start = RawParseUtils.headerStart(GPG_HEADER, raw, 0);
+ if (start < 0) {
+ return null;
+ }
+
+ int end = RawParseUtils.headerEnd(raw, start);
+ byte[] signature = Arrays.copyOfRange(raw, start, end);
+
+ String publicKeyId = gpg.findPublicKeyId(signature);
+ if (Strings.isNullOrEmpty(publicKeyId)) {
+ // key not found
+ return new Signature(publicKeyId, "gpg", SignatureStatus.NOT_FOUND, null, Collections.emptySet());
+ }
+
+ Optional publicKeyById = gpg.findPublicKey(publicKeyId);
+ if (!publicKeyById.isPresent()) {
+ // key not found
+ return new Signature(publicKeyId, "gpg", SignatureStatus.NOT_FOUND, null, Collections.emptySet());
+ }
+
+ PublicKey publicKey = publicKeyById.get();
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ try {
+ byte[] headerPrefix = Arrays.copyOfRange(raw, 0, start - GPG_HEADER.length - 1);
+ baos.write(headerPrefix);
+
+ byte[] headerSuffix = Arrays.copyOfRange(raw, end + 1, raw.length);
+ baos.write(headerSuffix);
+ } catch (IOException ex) {
+ // this will never happen, because we are writing into memory
+ throw new IllegalStateException("failed to write into memory", ex);
+ }
+
+ boolean verified = publicKey.verify(baos.toByteArray(), signature);
+ return new Signature(
+ publicKeyId,
+ "gpg",
+ verified ? SignatureStatus.VERIFIED : SignatureStatus.INVALID,
+ publicKey.getOwner().orElse(null),
+ publicKey.getContacts()
+ );
+ }
+
public Person createPersonFor(PersonIdent personIndent) {
return new Person(personIndent.getName(), personIndent.getEmailAddress());
}
+ @Override
+ public void close() {
+ GitUtil.release(treeWalk);
+ }
- //~--- fields ---------------------------------------------------------------
-
- /** Field description */
- private org.eclipse.jgit.lib.Repository repository;
-
- /** Field description */
- private RevWalk revWalk;
-
- /** Field description */
- private Multimap tags;
-
- /** Field description */
- private TreeWalk treeWalk;
}
diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitChangesetConverterFactory.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitChangesetConverterFactory.java
new file mode 100644
index 0000000000..4f4389fa2e
--- /dev/null
+++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitChangesetConverterFactory.java
@@ -0,0 +1,50 @@
+/*
+ * 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 org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.revwalk.RevWalk;
+import sonia.scm.security.GPG;
+
+import javax.inject.Inject;
+
+public class GitChangesetConverterFactory {
+
+ private final GPG gpg;
+
+ @Inject
+ public GitChangesetConverterFactory(GPG gpg) {
+ this.gpg = gpg;
+ }
+
+ public GitChangesetConverter create(Repository repository) {
+ return new GitChangesetConverter(gpg, repository, new RevWalk(repository));
+ }
+
+ public GitChangesetConverter create(Repository repository, RevWalk revWalk) {
+ return new GitChangesetConverter(gpg, repository, revWalk);
+ }
+
+}
diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitHookChangesetCollector.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitHookChangesetCollector.java
index 3071f590bc..5d7de5ce27 100644
--- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitHookChangesetCollector.java
+++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitHookChangesetCollector.java
@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-
+
package sonia.scm.repository;
//~--- non-JDK imports --------------------------------------------------------
@@ -72,9 +72,10 @@ public class GitHookChangesetCollector
* @param rpack
* @param receiveCommands
*/
- public GitHookChangesetCollector(ReceivePack rpack,
+ public GitHookChangesetCollector(GitChangesetConverterFactory converterFactory, ReceivePack rpack,
List receiveCommands)
{
+ this.converterFactory = converterFactory;
this.rpack = rpack;
this.receiveCommands = receiveCommands;
this.listener = CollectingPackParserListener.get(rpack);
@@ -100,14 +101,14 @@ public class GitHookChangesetCollector
try
{
walk = rpack.getRevWalk();
- converter = new GitChangesetConverter(repository, walk);
+ converter = converterFactory.create(repository, walk);
for (ReceiveCommand rc : receiveCommands)
{
String ref = rc.getRefName();
-
+
logger.trace("handle receive command, type={}, ref={}, result={}", rc.getType(), ref, rc.getResult());
-
+
if (rc.getType() == ReceiveCommand.Type.DELETE)
{
logger.debug("skip delete of ref {}", ref);
@@ -130,7 +131,7 @@ public class GitHookChangesetCollector
builder.append(rc.getType()).append(", ref=");
builder.append(rc.getRefName()).append(", result=");
builder.append(rc.getResult());
-
+
logger.error(builder.toString(), ex);
}
}
@@ -222,5 +223,6 @@ public class GitHookChangesetCollector
private final List receiveCommands;
+ private final GitChangesetConverterFactory converterFactory;
private final ReceivePack rpack;
}
diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/ScmGpgSigner.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/ScmGpgSigner.java
new file mode 100644
index 0000000000..423cd2aca8
--- /dev/null
+++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/ScmGpgSigner.java
@@ -0,0 +1,61 @@
+/*
+ * 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 org.eclipse.jgit.api.errors.CanceledException;
+import org.eclipse.jgit.lib.CommitBuilder;
+import org.eclipse.jgit.lib.GpgSignature;
+import org.eclipse.jgit.lib.GpgSigner;
+import org.eclipse.jgit.lib.PersonIdent;
+import org.eclipse.jgit.transport.CredentialsProvider;
+import sonia.scm.security.GPG;
+
+import javax.inject.Inject;
+import java.io.UnsupportedEncodingException;
+
+public class ScmGpgSigner extends GpgSigner {
+
+ private final GPG gpg;
+
+ @Inject
+ public ScmGpgSigner(GPG gpg) {
+ this.gpg = gpg;
+ }
+
+ @Override
+ public void sign(CommitBuilder commitBuilder, String keyId, PersonIdent personIdent, CredentialsProvider credentialsProvider) throws CanceledException {
+ try {
+ final byte[] signature = this.gpg.getPrivateKey().sign(commitBuilder.build());
+ commitBuilder.setGpgSignature(new GpgSignature(signature));
+ } catch (UnsupportedEncodingException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ @Override
+ public boolean canLocateSigningKey(String keyId, PersonIdent personIdent, CredentialsProvider credentialsProvider) throws CanceledException {
+ return true;
+ }
+}
diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/ScmGpgSignerInitializer.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/ScmGpgSignerInitializer.java
new file mode 100644
index 0000000000..144601275d
--- /dev/null
+++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/ScmGpgSignerInitializer.java
@@ -0,0 +1,53 @@
+/*
+ * 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 org.eclipse.jgit.lib.GpgSigner;
+import sonia.scm.plugin.Extension;
+
+import javax.inject.Inject;
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+@Extension
+public class ScmGpgSignerInitializer implements ServletContextListener {
+
+ private final ScmGpgSigner scmGpgSigner;
+
+ @Inject
+ public ScmGpgSignerInitializer(ScmGpgSigner scmGpgSigner) {
+ this.scmGpgSigner = scmGpgSigner;
+ }
+
+ @Override
+ public void contextInitialized(ServletContextEvent servletContextEvent) {
+ GpgSigner.setDefault(scmGpgSigner);
+ }
+
+ @Override
+ public void contextDestroyed(ServletContextEvent servletContextEvent) {
+ // Do nothing
+ }
+}
diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/api/GitReceiveHookMergeDetectionProvider.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/api/GitReceiveHookMergeDetectionProvider.java
index 03a5b59837..bac6eb6348 100644
--- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/api/GitReceiveHookMergeDetectionProvider.java
+++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/api/GitReceiveHookMergeDetectionProvider.java
@@ -28,6 +28,7 @@ import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.transport.ReceiveCommand;
+import sonia.scm.repository.GitChangesetConverterFactory;
import sonia.scm.repository.GitUtil;
import sonia.scm.repository.spi.GitLogComputer;
import sonia.scm.repository.spi.HookMergeDetectionProvider;
@@ -39,11 +40,13 @@ public class GitReceiveHookMergeDetectionProvider implements HookMergeDetectionP
private final Repository repository;
private final String repositoryId;
private final List receiveCommands;
+ private final GitChangesetConverterFactory converterFactory;
- public GitReceiveHookMergeDetectionProvider(Repository repository, String repositoryId, List receiveCommands) {
+ public GitReceiveHookMergeDetectionProvider(Repository repository, String repositoryId, List receiveCommands, GitChangesetConverterFactory converterFactory) {
this.repository = repository;
this.repositoryId = repositoryId;
this.receiveCommands = receiveCommands;
+ this.converterFactory = converterFactory;
}
@Override
@@ -53,7 +56,7 @@ public class GitReceiveHookMergeDetectionProvider implements HookMergeDetectionP
request.setAncestorChangeset(findRelevantRevisionForBranchIfToBeUpdated(target));
request.setPagingLimit(1);
- return new GitLogComputer(repositoryId, repository).compute(request).getTotal() == 0;
+ return new GitLogComputer(repositoryId, repository, converterFactory).compute(request).getTotal() == 0;
}
private String findRelevantRevisionForBranchIfToBeUpdated(String branch) {
diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/AbstractGitCommand.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/AbstractGitCommand.java
index 9e13e82971..c083123242 100644
--- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/AbstractGitCommand.java
+++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/AbstractGitCommand.java
@@ -63,11 +63,9 @@ import static sonia.scm.repository.GitUtil.getBranchIdOrCurrentHead;
//~--- JDK imports ------------------------------------------------------------
/**
- *
* @author Sebastian Sdorra
*/
-class AbstractGitCommand
-{
+class AbstractGitCommand {
/**
* the logger for AbstractGitCommand
@@ -77,11 +75,9 @@ class AbstractGitCommand
/**
* Constructs ...
*
- * @param context
- *
+ * @param context
*/
- AbstractGitCommand(GitContext context)
- {
+ AbstractGitCommand(GitContext context) {
this.repository = context.getRepository();
this.context = context;
}
@@ -91,19 +87,16 @@ class AbstractGitCommand
/**
* Method description
*
- *
* @return
- *
* @throws IOException
*/
- Repository open() throws IOException
- {
+ Repository open() throws IOException {
return context.open();
}
ObjectId getCommitOrDefault(Repository gitRepository, String requestedCommit) throws IOException {
ObjectId commit;
- if ( Strings.isNullOrEmpty(requestedCommit) ) {
+ if (Strings.isNullOrEmpty(requestedCommit)) {
commit = getDefaultBranch(gitRepository);
} else {
commit = gitRepository.resolve(requestedCommit);
@@ -121,7 +114,7 @@ class AbstractGitCommand
}
Ref getBranchOrDefault(Repository gitRepository, String requestedBranch) throws IOException {
- if ( Strings.isNullOrEmpty(requestedBranch) ) {
+ if (Strings.isNullOrEmpty(requestedBranch)) {
String defaultBranchName = context.getConfig().getDefaultBranch();
return getBranchIdOrCurrentHead(gitRepository, defaultBranchName);
} else {
@@ -220,7 +213,7 @@ class AbstractGitCommand
}
}
- Optional doCommit(String message, Person author) {
+ Optional doCommit(String message, Person author, boolean sign) {
Person authorToUse = determineAuthor(author);
try {
Status status = clone.status().call();
@@ -229,6 +222,8 @@ class AbstractGitCommand
.setAuthor(authorToUse.getName(), authorToUse.getMail())
.setCommitter("SCM-Manager", "noreply@scm-manager.org")
.setMessage(message)
+ .setSign(sign)
+ .setSigningKey(sign ? "SCM-MANAGER-DEFAULT-KEY" : null)
.call());
} else {
return empty();
@@ -288,9 +283,13 @@ class AbstractGitCommand
//~--- fields ---------------------------------------------------------------
- /** Field description */
+ /**
+ * Field description
+ */
protected GitContext context;
- /** Field description */
+ /**
+ * Field description
+ */
protected sonia.scm.repository.Repository repository;
}
diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/AbstractGitIncomingOutgoingCommand.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/AbstractGitIncomingOutgoingCommand.java
index 1b03a5a55e..94b1451d68 100644
--- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/AbstractGitIncomingOutgoingCommand.java
+++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/AbstractGitIncomingOutgoingCommand.java
@@ -36,6 +36,7 @@ import org.eclipse.jgit.revwalk.RevWalk;
import sonia.scm.repository.Changeset;
import sonia.scm.repository.ChangesetPagingResult;
import sonia.scm.repository.GitChangesetConverter;
+import sonia.scm.repository.GitChangesetConverterFactory;
import sonia.scm.repository.GitRepositoryHandler;
import sonia.scm.repository.GitUtil;
import sonia.scm.repository.InternalRepositoryException;
@@ -58,18 +59,10 @@ public abstract class AbstractGitIncomingOutgoingCommand
/** Field description */
private static final String REMOTE_REF_PREFIX = "refs/remote/scm/%s/";
- //~--- constructors ---------------------------------------------------------
-
- /**
- * Constructs ...
- *
- * @param handler
- * @param context
- */
- AbstractGitIncomingOutgoingCommand(GitRepositoryHandler handler, GitContext context)
- {
+ AbstractGitIncomingOutgoingCommand(GitContext context, GitRepositoryHandler handler, GitChangesetConverterFactory converterFactory) {
super(context);
this.handler = handler;
+ this.converterFactory = converterFactory;
}
//~--- methods --------------------------------------------------------------
@@ -132,7 +125,7 @@ public abstract class AbstractGitIncomingOutgoingCommand
try
{
walk = new RevWalk(git.getRepository());
- converter = new GitChangesetConverter(git.getRepository(), walk);
+ converter = converterFactory.create(git.getRepository(), walk);
org.eclipse.jgit.api.LogCommand log = git.log();
@@ -203,4 +196,5 @@ public abstract class AbstractGitIncomingOutgoingCommand
/** Field description */
private GitRepositoryHandler handler;
+ private final GitChangesetConverterFactory converterFactory;
}
diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitBlameCommand.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitBlameCommand.java
index 5c1f074a90..d99343b350 100644
--- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitBlameCommand.java
+++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitBlameCommand.java
@@ -41,6 +41,7 @@ import sonia.scm.repository.GitUtil;
import sonia.scm.repository.InternalRepositoryException;
import sonia.scm.repository.Person;
+import javax.inject.Inject;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -64,6 +65,7 @@ public class GitBlameCommand extends AbstractGitCommand implements BlameCommand
//~--- constructors ---------------------------------------------------------
+ @Inject
public GitBlameCommand(GitContext context)
{
super(context);
diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitBranchCommand.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitBranchCommand.java
index eb372ff063..43bfb68578 100644
--- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitBranchCommand.java
+++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitBranchCommand.java
@@ -43,6 +43,7 @@ import sonia.scm.repository.api.HookContext;
import sonia.scm.repository.api.HookContextFactory;
import sonia.scm.repository.api.HookFeature;
+import javax.inject.Inject;
import java.io.IOException;
import java.util.List;
import java.util.Set;
@@ -57,6 +58,7 @@ public class GitBranchCommand extends AbstractGitCommand implements BranchComman
private final HookContextFactory hookContextFactory;
private final ScmEventBus eventBus;
+ @Inject
GitBranchCommand(GitContext context, HookContextFactory hookContextFactory, ScmEventBus eventBus) {
super(context);
this.hookContextFactory = hookContextFactory;
diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitBranchesCommand.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitBranchesCommand.java
index cd7892461b..d026affd8b 100644
--- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitBranchesCommand.java
+++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitBranchesCommand.java
@@ -38,6 +38,7 @@ import sonia.scm.repository.Branch;
import sonia.scm.repository.GitUtil;
import sonia.scm.repository.InternalRepositoryException;
+import javax.inject.Inject;
import java.io.IOException;
import java.util.List;
import java.util.Optional;
@@ -53,6 +54,7 @@ public class GitBranchesCommand extends AbstractGitCommand implements BranchesCo
private static final Logger LOG = LoggerFactory.getLogger(GitBranchesCommand.class);
+ @Inject
public GitBranchesCommand(GitContext context)
{
super(context);
diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitBrowseCommand.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitBrowseCommand.java
index ab5a7d33b4..05792b9707 100644
--- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitBrowseCommand.java
+++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitBrowseCommand.java
@@ -57,6 +57,7 @@ import sonia.scm.store.BlobStore;
import sonia.scm.util.Util;
import sonia.scm.web.lfs.LfsBlobStoreFactory;
+import javax.inject.Inject;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
@@ -111,6 +112,11 @@ public class GitBrowseCommand extends AbstractGitCommand
private int resultCount = 0;
+ @Inject
+ public GitBrowseCommand(GitContext context, LfsBlobStoreFactory lfsBlobStoreFactory, SyncAsyncExecutorProvider executorProvider) {
+ this(context, lfsBlobStoreFactory, executorProvider.createExecutorWithDefaultTimeout());
+ }
+
public GitBrowseCommand(GitContext context, LfsBlobStoreFactory lfsBlobStoreFactory, SyncAsyncExecutor executor) {
super(context);
this.lfsBlobStoreFactory = lfsBlobStoreFactory;
diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitCatCommand.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitCatCommand.java
index 4629e4bce2..8c2e3b44d5 100644
--- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitCatCommand.java
+++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitCatCommand.java
@@ -44,6 +44,7 @@ import sonia.scm.util.IOUtil;
import sonia.scm.util.Util;
import sonia.scm.web.lfs.LfsBlobStoreFactory;
+import javax.inject.Inject;
import java.io.Closeable;
import java.io.FilterInputStream;
import java.io.IOException;
@@ -61,6 +62,7 @@ public class GitCatCommand extends AbstractGitCommand implements CatCommand {
private final LfsBlobStoreFactory lfsBlobStoreFactory;
+ @Inject
public GitCatCommand(GitContext context, LfsBlobStoreFactory lfsBlobStoreFactory) {
super(context);
this.lfsBlobStoreFactory = lfsBlobStoreFactory;
diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitContextFactory.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitContextFactory.java
new file mode 100644
index 0000000000..04bb37bed0
--- /dev/null
+++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitContextFactory.java
@@ -0,0 +1,48 @@
+/*
+ * 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.spi;
+
+import sonia.scm.api.v2.resources.GitRepositoryConfigStoreProvider;
+import sonia.scm.repository.GitRepositoryHandler;
+import sonia.scm.repository.Repository;
+
+import javax.inject.Inject;
+
+class GitContextFactory {
+
+ private final GitRepositoryHandler handler;
+ private final GitRepositoryConfigStoreProvider storeProvider;
+
+ @Inject
+ GitContextFactory(GitRepositoryHandler handler, GitRepositoryConfigStoreProvider storeProvider) {
+ this.handler = handler;
+ this.storeProvider = storeProvider;
+ }
+
+ GitContext create(Repository repository) {
+ return new GitContext(handler.getDirectory(repository.getId()), repository, storeProvider);
+ }
+
+}
diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitDiffCommand.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitDiffCommand.java
index adb7a7bd0e..c0ed1a53bc 100644
--- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitDiffCommand.java
+++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitDiffCommand.java
@@ -29,6 +29,7 @@ import org.eclipse.jgit.diff.DiffFormatter;
import org.eclipse.jgit.util.QuotedString;
import sonia.scm.repository.api.DiffCommandBuilder;
+import javax.inject.Inject;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -41,6 +42,7 @@ import static java.nio.charset.StandardCharsets.UTF_8;
*/
public class GitDiffCommand extends AbstractGitCommand implements DiffCommand {
+ @Inject
GitDiffCommand(GitContext context) {
super(context);
}
diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitDiffResultCommand.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitDiffResultCommand.java
index fed865c576..e55d8badae 100644
--- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitDiffResultCommand.java
+++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitDiffResultCommand.java
@@ -32,6 +32,7 @@ import sonia.scm.repository.api.DiffFile;
import sonia.scm.repository.api.DiffResult;
import sonia.scm.repository.api.Hunk;
+import javax.inject.Inject;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Iterator;
@@ -39,6 +40,7 @@ import java.util.stream.Collectors;
public class GitDiffResultCommand extends AbstractGitCommand implements DiffResultCommand {
+ @Inject
GitDiffResultCommand(GitContext context) {
super(context);
}
diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitHookChangesetProvider.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitHookChangesetProvider.java
index 3280e2c5c4..1dbe652371 100644
--- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitHookChangesetProvider.java
+++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitHookChangesetProvider.java
@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-
+
package sonia.scm.repository.spi;
//~--- non-JDK imports --------------------------------------------------------
@@ -29,6 +29,7 @@ package sonia.scm.repository.spi;
import org.eclipse.jgit.transport.ReceiveCommand;
import org.eclipse.jgit.transport.ReceivePack;
+import sonia.scm.repository.GitChangesetConverterFactory;
import sonia.scm.repository.GitHookChangesetCollector;
//~--- JDK imports ------------------------------------------------------------
@@ -39,56 +40,27 @@ import java.util.List;
*
* @author Sebastian Sdorra
*/
-public class GitHookChangesetProvider implements HookChangesetProvider
-{
+public class GitHookChangesetProvider implements HookChangesetProvider {
- /**
- * Constructs ...
- *
- *
- * @param receivePack
- * @param receiveCommands
- */
- public GitHookChangesetProvider(ReceivePack receivePack,
- List receiveCommands)
- {
+ private final GitChangesetConverterFactory converterFactory;
+ private final ReceivePack receivePack;
+ private final List receiveCommands;
+
+ private HookChangesetResponse response;
+
+ public GitHookChangesetProvider(GitChangesetConverterFactory converterFactory, ReceivePack receivePack,
+ List receiveCommands) {
+ this.converterFactory = converterFactory;
this.receivePack = receivePack;
this.receiveCommands = receiveCommands;
}
- //~--- methods --------------------------------------------------------------
-
- /**
- * Method description
- *
- *
- * @param request
- *
- * @return
- */
@Override
- public synchronized HookChangesetResponse handleRequest(
- HookChangesetRequest request)
- {
- if (response == null)
- {
- GitHookChangesetCollector collector =
- new GitHookChangesetCollector(receivePack, receiveCommands);
-
+ public synchronized HookChangesetResponse handleRequest(HookChangesetRequest request) {
+ if (response == null) {
+ GitHookChangesetCollector collector = new GitHookChangesetCollector(converterFactory, receivePack, receiveCommands);
response = new HookChangesetResponse(collector.collectChangesets());
}
-
return response;
}
-
- //~--- fields ---------------------------------------------------------------
-
- /** Field description */
- private List receiveCommands;
-
- /** Field description */
- private ReceivePack receivePack;
-
- /** Field description */
- private HookChangesetResponse response;
}
diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitHookContextProvider.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitHookContextProvider.java
index bc8d633add..13a11007a2 100644
--- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitHookContextProvider.java
+++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitHookContextProvider.java
@@ -30,6 +30,7 @@ import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.transport.ReceiveCommand;
import org.eclipse.jgit.transport.ReceivePack;
import sonia.scm.repository.api.GitHookBranchProvider;
+import sonia.scm.repository.GitChangesetConverterFactory;
import sonia.scm.repository.api.GitHookMessageProvider;
import sonia.scm.repository.api.GitHookTagProvider;
import sonia.scm.repository.api.GitReceiveHookMergeDetectionProvider;
@@ -62,14 +63,16 @@ public class GitHookContextProvider extends HookContextProvider
//~--- constructors ---------------------------------------------------------
+ private final GitChangesetConverterFactory converterFactory;
+
/**
* Constructs a new instance
* @param receivePack git receive pack
* @param receiveCommands received commands
*/
public GitHookContextProvider(
- ReceivePack receivePack,
- List receiveCommands,
+ GitChangesetConverterFactory converterFactory, ReceivePack receivePack,
+ List receiveCommands,
Repository repository,
String repositoryId
) {
@@ -77,8 +80,9 @@ public class GitHookContextProvider extends HookContextProvider
this.receiveCommands = receiveCommands;
this.repository = repository;
this.repositoryId = repositoryId;
- this.changesetProvider = new GitHookChangesetProvider(receivePack,
+ this.changesetProvider = new GitHookChangesetProvider(converterFactory, receivePack,
receiveCommands);
+ this.converterFactory = converterFactory;
}
//~--- methods --------------------------------------------------------------
@@ -110,7 +114,7 @@ public class GitHookContextProvider extends HookContextProvider
@Override
public HookMergeDetectionProvider getMergeDetectionProvider() {
- return new GitReceiveHookMergeDetectionProvider(repository, repositoryId, receiveCommands);
+ return new GitReceiveHookMergeDetectionProvider(repository, repositoryId, receiveCommands, converterFactory);
}
@Override
diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitIncomingCommand.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitIncomingCommand.java
index f6e818bcdb..205d9e9e3f 100644
--- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitIncomingCommand.java
+++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitIncomingCommand.java
@@ -29,8 +29,10 @@ package sonia.scm.repository.spi;
import org.eclipse.jgit.api.LogCommand;
import org.eclipse.jgit.lib.ObjectId;
import sonia.scm.repository.ChangesetPagingResult;
+import sonia.scm.repository.GitChangesetConverterFactory;
import sonia.scm.repository.GitRepositoryHandler;
+import javax.inject.Inject;
import java.io.IOException;
//~--- JDK imports ------------------------------------------------------------
@@ -40,18 +42,11 @@ import java.io.IOException;
* @author Sebastian Sdorra
*/
public class GitIncomingCommand extends AbstractGitIncomingOutgoingCommand
- implements IncomingCommand
-{
+ implements IncomingCommand {
- /**
- * Constructs ...
- *
- * @param handler
- * @param context
- */
- GitIncomingCommand(GitRepositoryHandler handler, GitContext context)
- {
- super(handler, context);
+ @Inject
+ GitIncomingCommand(GitContext context, GitRepositoryHandler handler, GitChangesetConverterFactory converterFactory) {
+ super(context, handler, converterFactory);
}
//~--- get methods ----------------------------------------------------------
diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitLogCommand.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitLogCommand.java
index 340df65c16..e0f0b2868b 100644
--- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitLogCommand.java
+++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitLogCommand.java
@@ -36,10 +36,12 @@ import org.slf4j.LoggerFactory;
import sonia.scm.repository.Changeset;
import sonia.scm.repository.ChangesetPagingResult;
import sonia.scm.repository.GitChangesetConverter;
+import sonia.scm.repository.GitChangesetConverterFactory;
import sonia.scm.repository.GitUtil;
import sonia.scm.repository.InternalRepositoryException;
import sonia.scm.util.IOUtil;
+import javax.inject.Inject;
import java.io.IOException;
import static sonia.scm.ContextEntry.ContextBuilder.entity;
@@ -60,6 +62,7 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand
private static final Logger logger =
LoggerFactory.getLogger(GitLogCommand.class);
public static final String REVISION = "Revision";
+ private final GitChangesetConverterFactory converterFactory;
//~--- constructors ---------------------------------------------------------
@@ -70,9 +73,11 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand
* @param context
*
*/
- GitLogCommand(GitContext context)
+ @Inject
+ GitLogCommand(GitContext context, GitChangesetConverterFactory converterFactory)
{
super(context);
+ this.converterFactory = converterFactory;
}
//~--- get methods ----------------------------------------------------------
@@ -110,7 +115,7 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand
if (commit != null)
{
- converter = new GitChangesetConverter(gr, revWalk);
+ converter = converterFactory.create(gr, revWalk);
if (isBranchRequested(request)) {
String branch = request.getBranch();
@@ -177,7 +182,7 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand
if (Strings.isNullOrEmpty(request.getBranch())) {
request.setBranch(context.getConfig().getDefaultBranch());
}
- return new GitLogComputer(this.repository.getId(), gitRepository).compute(request);
+ return new GitLogComputer(this.repository.getId(), gitRepository, converterFactory).compute(request);
} catch (IOException e) {
throw new InternalRepositoryException(repository, "could not create change log", e);
}
diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitLogComputer.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitLogComputer.java
index eae8ea5851..b33460fb37 100644
--- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitLogComputer.java
+++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitLogComputer.java
@@ -42,6 +42,7 @@ import sonia.scm.NotFoundException;
import sonia.scm.repository.Changeset;
import sonia.scm.repository.ChangesetPagingResult;
import sonia.scm.repository.GitChangesetConverter;
+import sonia.scm.repository.GitChangesetConverterFactory;
import sonia.scm.repository.GitUtil;
import sonia.scm.repository.InternalRepositoryException;
import sonia.scm.util.IOUtil;
@@ -59,10 +60,12 @@ public class GitLogComputer {
private final String repositoryId;
private final Repository gitRepository;
+ private final GitChangesetConverterFactory converterFactory;
- public GitLogComputer(String repositoryId, Repository repository) {
+ public GitLogComputer(String repositoryId, Repository repository, GitChangesetConverterFactory converterFactory) {
this.repositoryId = repositoryId;
this.gitRepository = repository;
+ this.converterFactory = converterFactory;
}
public ChangesetPagingResult compute(LogCommandRequest request) {
@@ -123,7 +126,7 @@ public class GitLogComputer {
revWalk = new RevWalk(gitRepository);
- converter = new GitChangesetConverter(gitRepository, revWalk);
+ converter = converterFactory.create(gitRepository, revWalk);
if (!Strings.isNullOrEmpty(request.getPath())) {
revWalk.setTreeFilter(
diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitMergeCommand.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitMergeCommand.java
index 9f362edeb6..bd4e6b26b5 100644
--- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitMergeCommand.java
+++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitMergeCommand.java
@@ -36,6 +36,7 @@ import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.merge.ResolveMerger;
import org.eclipse.jgit.treewalk.CanonicalTreeParser;
import org.eclipse.jgit.treewalk.filter.PathFilter;
+import sonia.scm.repository.GitRepositoryHandler;
import sonia.scm.repository.GitWorkingCopyFactory;
import sonia.scm.repository.InternalRepositoryException;
import sonia.scm.repository.api.MergeCommandResult;
@@ -43,6 +44,7 @@ import sonia.scm.repository.api.MergeDryRunCommandResult;
import sonia.scm.repository.api.MergeStrategy;
import sonia.scm.repository.api.MergeStrategyNotSupportedException;
+import javax.inject.Inject;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Set;
@@ -61,6 +63,11 @@ public class GitMergeCommand extends AbstractGitCommand implements MergeCommand
MergeStrategy.SQUASH
);
+ @Inject
+ GitMergeCommand(GitContext context, GitRepositoryHandler handler) {
+ this(context, handler.getWorkingCopyFactory());
+ }
+
GitMergeCommand(GitContext context, GitWorkingCopyFactory workingCopyFactory) {
super(context);
this.workingCopyFactory = workingCopyFactory;
diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitMergeStrategy.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitMergeStrategy.java
index 0b79ec7204..72a3f23b5f 100644
--- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitMergeStrategy.java
+++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitMergeStrategy.java
@@ -56,6 +56,7 @@ abstract class GitMergeStrategy extends AbstractGitCommand.GitCloneWorker doCommit() {
logger.debug("merged branch {} into {}", branchToMerge, targetBranch);
- return doCommit(MessageFormat.format(determineMessageTemplate(), branchToMerge, targetBranch), author);
+ return doCommit(MessageFormat.format(determineMessageTemplate(), branchToMerge, targetBranch), author, sign);
}
MergeCommandResult createSuccessResult(String newRevision) {
diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitModificationsCommand.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitModificationsCommand.java
index 918d276148..e907081f2c 100644
--- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitModificationsCommand.java
+++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitModificationsCommand.java
@@ -41,6 +41,7 @@ import sonia.scm.repository.Modified;
import sonia.scm.repository.Removed;
import sonia.scm.repository.Renamed;
+import javax.inject.Inject;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.ArrayList;
@@ -53,7 +54,8 @@ import static sonia.scm.ContextEntry.ContextBuilder.entity;
@Slf4j
public class GitModificationsCommand extends AbstractGitCommand implements ModificationsCommand {
- protected GitModificationsCommand(GitContext context) {
+ @Inject
+ GitModificationsCommand(GitContext context) {
super(context);
}
diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitModifyCommand.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitModifyCommand.java
index 9e0f5449d3..01271d0fc3 100644
--- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitModifyCommand.java
+++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitModifyCommand.java
@@ -34,11 +34,13 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.ConcurrentModificationException;
import sonia.scm.NoChangesMadeException;
+import sonia.scm.repository.GitRepositoryHandler;
import sonia.scm.repository.GitWorkingCopyFactory;
import sonia.scm.repository.InternalRepositoryException;
import sonia.scm.repository.Repository;
import sonia.scm.web.lfs.LfsBlobStoreFactory;
+import javax.inject.Inject;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
@@ -53,6 +55,11 @@ public class GitModifyCommand extends AbstractGitCommand implements ModifyComman
private final GitWorkingCopyFactory workingCopyFactory;
private final LfsBlobStoreFactory lfsBlobStoreFactory;
+ @Inject
+ GitModifyCommand(GitContext context, GitRepositoryHandler repositoryHandler, LfsBlobStoreFactory lfsBlobStoreFactory) {
+ this(context, repositoryHandler.getWorkingCopyFactory(), lfsBlobStoreFactory);
+ }
+
GitModifyCommand(GitContext context, GitWorkingCopyFactory workingCopyFactory, LfsBlobStoreFactory lfsBlobStoreFactory) {
super(context);
this.workingCopyFactory = workingCopyFactory;
@@ -86,7 +93,7 @@ public class GitModifyCommand extends AbstractGitCommand implements ModifyComman
r.execute(this);
}
failIfNotChanged(() -> new NoChangesMadeException(repository, ModifyWorker.this.request.getBranch()));
- Optional revCommit = doCommit(request.getCommitMessage(), request.getAuthor());
+ Optional revCommit = doCommit(request.getCommitMessage(), request.getAuthor(), request.isSign());
push();
return revCommit.orElseThrow(() -> new NoChangesMadeException(repository, ModifyWorker.this.request.getBranch())).name();
}
diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitOutgoingCommand.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitOutgoingCommand.java
index 03acf9e914..30192d4297 100644
--- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitOutgoingCommand.java
+++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitOutgoingCommand.java
@@ -29,8 +29,10 @@ package sonia.scm.repository.spi;
import org.eclipse.jgit.api.LogCommand;
import org.eclipse.jgit.lib.ObjectId;
import sonia.scm.repository.ChangesetPagingResult;
+import sonia.scm.repository.GitChangesetConverterFactory;
import sonia.scm.repository.GitRepositoryHandler;
+import javax.inject.Inject;
import java.io.IOException;
//~--- JDK imports ------------------------------------------------------------
@@ -40,18 +42,12 @@ import java.io.IOException;
* @author Sebastian Sdorra
*/
public class GitOutgoingCommand extends AbstractGitIncomingOutgoingCommand
- implements OutgoingCommand
-{
+ implements OutgoingCommand {
- /**
- * Constructs ...
- *
- * @param handler
- * @param context
- */
- GitOutgoingCommand(GitRepositoryHandler handler, GitContext context)
+ @Inject
+ GitOutgoingCommand(GitContext context, GitRepositoryHandler handler, GitChangesetConverterFactory converterFactory)
{
- super(handler, context);
+ super(context, handler, converterFactory);
}
//~--- get methods ----------------------------------------------------------
diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitPullCommand.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitPullCommand.java
index 53b7a59916..422391fd19 100644
--- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitPullCommand.java
+++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitPullCommand.java
@@ -44,6 +44,7 @@ import sonia.scm.repository.InternalRepositoryException;
import sonia.scm.repository.Repository;
import sonia.scm.repository.api.PullResponse;
+import javax.inject.Inject;
import java.io.File;
import java.io.IOException;
import java.net.URL;
@@ -73,6 +74,7 @@ public class GitPullCommand extends AbstractGitPushOrPullCommand
* @param handler
* @param context
*/
+ @Inject
public GitPullCommand(GitRepositoryHandler handler, GitContext context)
{
super(handler, context);
diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitPushCommand.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitPushCommand.java
index fd874524f4..ddbfb6a8e1 100644
--- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitPushCommand.java
+++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitPushCommand.java
@@ -31,6 +31,7 @@ import org.slf4j.LoggerFactory;
import sonia.scm.repository.GitRepositoryHandler;
import sonia.scm.repository.api.PushResponse;
+import javax.inject.Inject;
import java.io.IOException;
//~--- JDK imports ------------------------------------------------------------
@@ -55,8 +56,8 @@ public class GitPushCommand extends AbstractGitPushOrPullCommand
* @param handler
* @param context
*/
- public GitPushCommand(GitRepositoryHandler handler, GitContext context)
- {
+ @Inject
+ public GitPushCommand(GitRepositoryHandler handler, GitContext context) {
super(handler, context);
this.handler = handler;
}
diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitRepositoryServiceProvider.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitRepositoryServiceProvider.java
index 862631c32c..fae69a47cf 100644
--- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitRepositoryServiceProvider.java
+++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitRepositoryServiceProvider.java
@@ -25,21 +25,14 @@
package sonia.scm.repository.spi;
import com.google.common.collect.ImmutableSet;
-import sonia.scm.api.v2.resources.GitRepositoryConfigStoreProvider;
-import sonia.scm.event.ScmEventBus;
+import com.google.inject.AbstractModule;
+import com.google.inject.Injector;
import sonia.scm.repository.Feature;
-import sonia.scm.repository.GitRepositoryHandler;
-import sonia.scm.repository.Repository;
import sonia.scm.repository.api.Command;
-import sonia.scm.repository.api.HookContextFactory;
-import sonia.scm.web.lfs.LfsBlobStoreFactory;
-import java.io.IOException;
import java.util.EnumSet;
import java.util.Set;
-//~--- JDK imports ------------------------------------------------------------
-
/**
*
* @author Sebastian Sdorra
@@ -47,8 +40,6 @@ import java.util.Set;
public class GitRepositoryServiceProvider extends RepositoryServiceProvider
{
- /** Field description */
- //J-
public static final Set COMMANDS = ImmutableSet.of(
Command.BLAME,
Command.BROWSE,
@@ -66,105 +57,51 @@ public class GitRepositoryServiceProvider extends RepositoryServiceProvider
Command.MERGE,
Command.MODIFY
);
+
protected static final Set FEATURES = EnumSet.of(Feature.INCOMING_REVISION);
- //J+
+
+ private final GitContext context;
+ private final Injector commandInjector;
//~--- constructors ---------------------------------------------------------
- public GitRepositoryServiceProvider(GitRepositoryHandler handler, Repository repository, GitRepositoryConfigStoreProvider storeProvider, LfsBlobStoreFactory lfsBlobStoreFactory, HookContextFactory hookContextFactory, ScmEventBus eventBus, SyncAsyncExecutorProvider executorProvider) {
- this.handler = handler;
- this.lfsBlobStoreFactory = lfsBlobStoreFactory;
- this.hookContextFactory = hookContextFactory;
- this.eventBus = eventBus;
- this.executorProvider = executorProvider;
- this.context = new GitContext(handler.getDirectory(repository.getId()), repository, storeProvider);
+ GitRepositoryServiceProvider(Injector injector, GitContext context) {
+ this.context = context;
+ commandInjector = injector.createChildInjector(new AbstractModule() {
+ @Override
+ protected void configure() {
+ bind(GitContext.class).toInstance(context);
+ }
+ });
}
- //~--- methods --------------------------------------------------------------
-
- /**
- * Method description
- *
- *
- * @throws IOException
- */
@Override
- public void close() throws IOException
- {
- context.close();
- }
-
- //~--- get methods ----------------------------------------------------------
-
- /**
- * Method description
- *
- *
- * @return
- */
- @Override
- public BlameCommand getBlameCommand()
- {
+ public BlameCommand getBlameCommand() {
return new GitBlameCommand(context);
}
- /**
- * Method description
- *
- *
- * @return
- */
@Override
- public BranchesCommand getBranchesCommand()
- {
+ public BranchesCommand getBranchesCommand() {
return new GitBranchesCommand(context);
}
- /**
- * Method description
- *
- *
- * @return
- */
@Override
- public BranchCommand getBranchCommand()
- {
- return new GitBranchCommand(context, hookContextFactory, eventBus);
+ public BranchCommand getBranchCommand() {
+ return commandInjector.getInstance(GitBranchCommand.class);
}
- /**
- * Method description
- *
- *
- * @return
- */
@Override
- public BrowseCommand getBrowseCommand()
- {
- return new GitBrowseCommand(context, lfsBlobStoreFactory, executorProvider.createExecutorWithDefaultTimeout());
+ public BrowseCommand getBrowseCommand() {
+ return commandInjector.getInstance(GitBrowseCommand.class);
}
- /**
- * Method description
- *
- *
- * @return
- */
@Override
- public CatCommand getCatCommand()
- {
- return new GitCatCommand(context, lfsBlobStoreFactory);
+ public CatCommand getCatCommand() {
+ return commandInjector.getInstance(GitCatCommand.class);
}
- /**
- * Method description
- *
- *
- * @return
- */
@Override
- public DiffCommand getDiffCommand()
- {
+ public DiffCommand getDiffCommand() {
return new GitDiffCommand(context);
}
@@ -173,28 +110,14 @@ public class GitRepositoryServiceProvider extends RepositoryServiceProvider
return new GitDiffResultCommand(context);
}
- /**
- * Method description
- *
- *
- * @return
- */
@Override
- public IncomingCommand getIncomingCommand()
- {
- return new GitIncomingCommand(handler, context);
+ public IncomingCommand getIncomingCommand() {
+ return commandInjector.getInstance(GitIncomingCommand.class);
}
- /**
- * Method description
- *
- *
- * @return
- */
@Override
- public LogCommand getLogCommand()
- {
- return new GitLogCommand(context);
+ public LogCommand getLogCommand() {
+ return commandInjector.getInstance(GitLogCommand.class);
}
@Override
@@ -202,93 +125,48 @@ public class GitRepositoryServiceProvider extends RepositoryServiceProvider
return new GitModificationsCommand(context);
}
- /**
- * Method description
- *
- *
- * @return
- */
@Override
- public OutgoingCommand getOutgoingCommand()
- {
- return new GitOutgoingCommand(handler, context);
+ public OutgoingCommand getOutgoingCommand() {
+ return commandInjector.getInstance(GitOutgoingCommand.class);
}
- /**
- * Method description
- *
- *
- * @return
- */
@Override
- public PullCommand getPullCommand()
- {
- return new GitPullCommand(handler, context);
+ public PullCommand getPullCommand() {
+ return commandInjector.getInstance(GitPullCommand.class);
}
- /**
- * Method description
- *
- *
- * @return
- */
@Override
- public PushCommand getPushCommand()
- {
- return new GitPushCommand(handler, context);
+ public PushCommand getPushCommand() {
+ return commandInjector.getInstance(GitPushCommand.class);
}
- /**
- * Method description
- *
- *
- * @return
- */
@Override
- public Set getSupportedCommands()
- {
- return COMMANDS;
- }
-
- /**
- * Method description
- *
- *
- * @return
- */
- @Override
- public TagsCommand getTagsCommand()
- {
+ public TagsCommand getTagsCommand() {
return new GitTagsCommand(context);
}
@Override
public MergeCommand getMergeCommand() {
- return new GitMergeCommand(context, handler.getWorkingCopyFactory());
+ return commandInjector.getInstance(GitMergeCommand.class);
}
@Override
public ModifyCommand getModifyCommand() {
- return new GitModifyCommand(context, handler.getWorkingCopyFactory(), lfsBlobStoreFactory);
+ return commandInjector.getInstance(GitModifyCommand.class);
+ }
+
+ @Override
+ public Set getSupportedCommands() {
+ return COMMANDS;
}
@Override
public Set getSupportedFeatures() {
return FEATURES;
}
-//~--- fields ---------------------------------------------------------------
- /** Field description */
- private final GitContext context;
-
- /** Field description */
- private final GitRepositoryHandler handler;
-
- private final LfsBlobStoreFactory lfsBlobStoreFactory;
-
- private final HookContextFactory hookContextFactory;
-
- private final ScmEventBus eventBus;
-
- private final SyncAsyncExecutorProvider executorProvider;
+ @Override
+ public void close() {
+ context.close();
+ }
}
diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitRepositoryServiceResolver.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitRepositoryServiceResolver.java
index 8ffda05ad3..7ff06dd140 100644
--- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitRepositoryServiceResolver.java
+++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitRepositoryServiceResolver.java
@@ -21,19 +21,16 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-
+
package sonia.scm.repository.spi;
//~--- non-JDK imports --------------------------------------------------------
import com.google.inject.Inject;
-import sonia.scm.api.v2.resources.GitRepositoryConfigStoreProvider;
-import sonia.scm.event.ScmEventBus;
+import com.google.inject.Injector;
import sonia.scm.plugin.Extension;
import sonia.scm.repository.GitRepositoryHandler;
import sonia.scm.repository.Repository;
-import sonia.scm.repository.api.HookContextFactory;
-import sonia.scm.web.lfs.LfsBlobStoreFactory;
/**
*
@@ -42,31 +39,20 @@ import sonia.scm.web.lfs.LfsBlobStoreFactory;
@Extension
public class GitRepositoryServiceResolver implements RepositoryServiceResolver {
- private final GitRepositoryHandler handler;
- private final GitRepositoryConfigStoreProvider storeProvider;
- private final LfsBlobStoreFactory lfsBlobStoreFactory;
- private final HookContextFactory hookContextFactory;
- private final ScmEventBus eventBus;
- private final SyncAsyncExecutorProvider executorProvider;
+ private final Injector injector;
+ private final GitContextFactory contextFactory;
@Inject
- public GitRepositoryServiceResolver(GitRepositoryHandler handler, GitRepositoryConfigStoreProvider storeProvider, LfsBlobStoreFactory lfsBlobStoreFactory, HookContextFactory hookContextFactory, ScmEventBus eventBus, SyncAsyncExecutorProvider executorProvider) {
- this.handler = handler;
- this.storeProvider = storeProvider;
- this.lfsBlobStoreFactory = lfsBlobStoreFactory;
- this.hookContextFactory = hookContextFactory;
- this.eventBus = eventBus;
- this.executorProvider = executorProvider;
+ public GitRepositoryServiceResolver(Injector injector, GitContextFactory contextFactory) {
+ this.injector = injector;
+ this.contextFactory = contextFactory;
}
@Override
public GitRepositoryServiceProvider resolve(Repository repository) {
- GitRepositoryServiceProvider provider = null;
-
if (GitRepositoryHandler.TYPE_NAME.equalsIgnoreCase(repository.getType())) {
- provider = new GitRepositoryServiceProvider(handler, repository, storeProvider, lfsBlobStoreFactory, hookContextFactory, eventBus, executorProvider);
+ return new GitRepositoryServiceProvider(injector, contextFactory.create(repository));
}
-
- return provider;
+ return null;
}
}
diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/web/GitReceiveHook.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/web/GitReceiveHook.java
index a9d74e0357..a093b5cda3 100644
--- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/web/GitReceiveHook.java
+++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/web/GitReceiveHook.java
@@ -34,6 +34,7 @@ import org.eclipse.jgit.transport.ReceiveCommand;
import org.eclipse.jgit.transport.ReceivePack;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import sonia.scm.repository.GitChangesetConverterFactory;
import sonia.scm.repository.GitRepositoryHandler;
import sonia.scm.repository.RepositoryHookType;
import sonia.scm.repository.spi.GitHookContextProvider;
@@ -66,9 +67,10 @@ public class GitReceiveHook implements PreReceiveHook, PostReceiveHook
* @param hookEventFacade
* @param handler
*/
- public GitReceiveHook(HookEventFacade hookEventFacade,
- GitRepositoryHandler handler)
+ public GitReceiveHook(GitChangesetConverterFactory converterFactory, HookEventFacade hookEventFacade,
+ GitRepositoryHandler handler)
{
+ this.converterFactory = converterFactory;
this.hookEventFacade = hookEventFacade;
this.handler = handler;
}
@@ -122,7 +124,7 @@ public class GitReceiveHook implements PreReceiveHook, PostReceiveHook
logger.trace("resolved repository to {}", repositoryId);
- GitHookContextProvider context = new GitHookContextProvider(rpack, receiveCommands, repository, repositoryId);
+ GitHookContextProvider context = new GitHookContextProvider(converterFactory, rpack, receiveCommands, repository, repositoryId);
hookEventFacade.handle(repositoryId).fireHookEvent(type, context);
@@ -187,6 +189,7 @@ public class GitReceiveHook implements PreReceiveHook, PostReceiveHook
/** Field description */
private GitRepositoryHandler handler;
+ private final GitChangesetConverterFactory converterFactory;
/** Field description */
private HookEventFacade hookEventFacade;
}
diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/web/GitReceivePackFactory.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/web/GitReceivePackFactory.java
index b4b43ea5b5..dc18189da9 100644
--- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/web/GitReceivePackFactory.java
+++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/web/GitReceivePackFactory.java
@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-
+
package sonia.scm.web;
//~--- non-JDK imports --------------------------------------------------------
@@ -34,6 +34,7 @@ import org.eclipse.jgit.transport.resolver.ReceivePackFactory;
import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException;
import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException;
import sonia.scm.protocolcommand.git.BaseReceivePackFactory;
+import sonia.scm.repository.GitChangesetConverterFactory;
import sonia.scm.repository.GitRepositoryHandler;
import sonia.scm.repository.spi.HookEventFacade;
@@ -53,8 +54,8 @@ public class GitReceivePackFactory extends BaseReceivePackFactory wrapped;
@Inject
- public GitReceivePackFactory(GitRepositoryHandler handler, HookEventFacade hookEventFacade) {
- super(handler, hookEventFacade);
+ public GitReceivePackFactory(GitChangesetConverterFactory converterFactory, GitRepositoryHandler handler, HookEventFacade hookEventFacade) {
+ super(converterFactory, handler, hookEventFacade);
this.wrapped = new DefaultReceivePackFactory();
}
diff --git a/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/protocolcommand/git/BaseReceivePackFactoryTest.java b/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/protocolcommand/git/BaseReceivePackFactoryTest.java
index 8fa2ecddaa..cc178c2ef8 100644
--- a/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/protocolcommand/git/BaseReceivePackFactoryTest.java
+++ b/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/protocolcommand/git/BaseReceivePackFactoryTest.java
@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-
+
package sonia.scm.protocolcommand.git;
import org.eclipse.jgit.api.Git;
@@ -40,6 +40,7 @@ import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import sonia.scm.repository.GitConfig;
import sonia.scm.repository.GitRepositoryHandler;
+import sonia.scm.repository.GitTestHelper;
import sonia.scm.web.CollectingPackParserListener;
import sonia.scm.web.GitReceiveHook;
@@ -82,7 +83,7 @@ public class BaseReceivePackFactoryTest {
ReceivePack receivePack = new ReceivePack(repository);
when(wrappedReceivePackFactory.create(request, repository)).thenReturn(receivePack);
- factory = new BaseReceivePackFactory