mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-05-07 18:16:46 +02:00
Merge branch 'develop' into feature/hg_hooks_over_tcp
# Conflicts: # CHANGELOG.md
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import de.otto.edison.hal.Embedded;
|
||||
import de.otto.edison.hal.HalRepresentation;
|
||||
import de.otto.edison.hal.Links;
|
||||
@@ -31,11 +32,14 @@ import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
import sonia.scm.repository.Branch;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.Pattern;
|
||||
|
||||
import static sonia.scm.repository.Branch.VALID_BRANCH_NAMES;
|
||||
import java.time.Instant;
|
||||
|
||||
import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@@ -45,10 +49,13 @@ public class BranchDto extends HalRepresentation {
|
||||
|
||||
@NotEmpty
|
||||
@Length(min = 1, max = 100)
|
||||
@Pattern(regexp = VALID_BRANCH_NAMES)
|
||||
@Pattern(regexp = Branch.VALID_BRANCH_NAMES)
|
||||
private String name;
|
||||
private String revision;
|
||||
private boolean defaultBranch;
|
||||
@JsonInclude(NON_NULL)
|
||||
private Instant lastCommitDate;
|
||||
private boolean stale;
|
||||
|
||||
BranchDto(Links links, Embedded embedded) {
|
||||
super(links, embedded);
|
||||
|
||||
@@ -38,11 +38,14 @@ import sonia.scm.web.EdisonHalAppender;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Optional;
|
||||
|
||||
import static de.otto.edison.hal.Link.linkBuilder;
|
||||
import static de.otto.edison.hal.Links.linkingTo;
|
||||
|
||||
@Mapper
|
||||
public abstract class BranchToBranchDtoMapper extends HalAppenderMapper {
|
||||
public abstract class BranchToBranchDtoMapper extends HalAppenderMapper implements InstantAttributeMapper {
|
||||
|
||||
@Inject
|
||||
private ResourceLinks resourceLinks;
|
||||
@@ -68,4 +71,8 @@ public abstract class BranchToBranchDtoMapper extends HalAppenderMapper {
|
||||
|
||||
return new BranchDto(linksBuilder.build(), embeddedBuilder.build());
|
||||
}
|
||||
|
||||
Instant mapOptionalTime(Optional<Long> date) {
|
||||
return date.map(this::mapTime).orElse(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,10 +192,16 @@ public class DefaultPluginManager implements PluginManager {
|
||||
dependencyTracker.addInstalled(plugin.getDescriptor());
|
||||
pendingInstallations.add(pending);
|
||||
eventBus.post(new PluginEvent(PluginEvent.PluginEventType.INSTALLED, plugin));
|
||||
} catch (PluginInstallException ex) {
|
||||
cancelPending(pendingInstallations);
|
||||
eventBus.post(new PluginEvent(PluginEvent.PluginEventType.INSTALLATION_FAILED, plugin));
|
||||
throw ex;
|
||||
} catch (PluginInstallException installException) {
|
||||
try {
|
||||
cancelPending(pendingInstallations);
|
||||
} catch (PluginFailedToCancelInstallationException cancelInstallationException) {
|
||||
LOG.error("could not install plugin {}; uninstallation failed (see next exception)", plugin.getDescriptor().getInformation().getName(), installException);
|
||||
throw cancelInstallationException;
|
||||
} finally {
|
||||
eventBus.post(new PluginEvent(PluginEvent.PluginEventType.INSTALLATION_FAILED, plugin));
|
||||
}
|
||||
throw installException;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.plugin;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
@@ -50,10 +50,14 @@ class PendingPluginInstallation {
|
||||
void cancel() {
|
||||
String name = plugin.getDescriptor().getInformation().getName();
|
||||
LOG.info("cancel installation of plugin {}", name);
|
||||
try {
|
||||
Files.delete(file);
|
||||
} catch (IOException ex) {
|
||||
throw new PluginFailedToCancelInstallationException("failed to cancel plugin installation ", name, ex);
|
||||
if (Files.exists(file)) {
|
||||
try {
|
||||
Files.delete(file);
|
||||
} catch (IOException ex) {
|
||||
throw new PluginFailedToCancelInstallationException("failed to cancel plugin installation ", name, ex);
|
||||
}
|
||||
} else {
|
||||
LOG.info("plugin file {} did not exists for plugin {}; nothing deleted", file, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,8 +108,8 @@ public final class PluginTree
|
||||
throw new PluginConditionFailedException(
|
||||
condition,
|
||||
String.format(
|
||||
"could not load plugin %s, the plugin condition does not match",
|
||||
plugin.getInformation().getId()
|
||||
"could not load plugin %s, the plugin condition does not match: %s",
|
||||
plugin.getInformation().getId(), condition
|
||||
)
|
||||
);
|
||||
//J+
|
||||
|
||||
@@ -59,8 +59,13 @@ class PendingPluginInstallationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldThrowExceptionIfCancelFailed(@TempDir Path directory) {
|
||||
void shouldThrowExceptionIfCancelFailed(@TempDir Path directory) throws IOException {
|
||||
Path file = directory.resolve("file");
|
||||
Files.createDirectory(file);
|
||||
|
||||
Path makeFileNotDeletable = file.resolve("not_deletable");
|
||||
Files.write(makeFileNotDeletable, "42".getBytes());
|
||||
|
||||
when(plugin.getDescriptor().getInformation().getName()).thenReturn("scm-awesome-plugin");
|
||||
|
||||
PendingPluginInstallation installation = new PendingPluginInstallation(plugin, file);
|
||||
|
||||
@@ -48,12 +48,15 @@ import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@@ -239,6 +242,30 @@ class I18nServletTest {
|
||||
assertJson(json);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotHaveInvalidPluginsJsonFiles() throws IOException {
|
||||
String path = getClass().getClassLoader().getResource("locales/en/plugins.json").getPath();
|
||||
assertThat(path).isNotNull();
|
||||
|
||||
Path filePath = Paths.get(path);
|
||||
Path translationRootPath = filePath.getParent().getParent();
|
||||
assertThat(translationRootPath).isDirectoryContaining("glob:**/en");
|
||||
|
||||
Files
|
||||
.list(translationRootPath)
|
||||
.filter(Files::isDirectory)
|
||||
.map(localePath -> localePath.resolve("plugins.json"))
|
||||
.forEach(this::validatePluginsJson);
|
||||
}
|
||||
|
||||
private void validatePluginsJson(Path path) {
|
||||
try {
|
||||
new ObjectMapper().readTree(path.toFile());
|
||||
} catch (IOException e) {
|
||||
fail("error while parsing translation file " + path, e);
|
||||
}
|
||||
}
|
||||
|
||||
private void verifyHeaders(HttpServletResponse response) {
|
||||
verify(response).setCharacterEncoding("UTF-8");
|
||||
verify(response).setContentType("application/json");
|
||||
|
||||
Reference in New Issue
Block a user