diff --git a/pom.xml b/pom.xml index 435e2fe..cd48652 100644 --- a/pom.xml +++ b/pom.xml @@ -1,5 +1,6 @@ - + 4.0.0 com.englishtown @@ -31,7 +32,7 @@ 5.5.0 ${bitbucket.version} - 6.3.17 + 6.3.21 diff --git a/src/main/java/com/englishtown/bitbucket/hook/DefaultPasswordEncryptor.java b/src/main/java/com/englishtown/bitbucket/hook/DefaultPasswordEncryptor.java index 7d9dd86..c5f38f6 100644 --- a/src/main/java/com/englishtown/bitbucket/hook/DefaultPasswordEncryptor.java +++ b/src/main/java/com/englishtown/bitbucket/hook/DefaultPasswordEncryptor.java @@ -6,6 +6,7 @@ import javax.crypto.*; import javax.crypto.spec.SecretKeySpec; import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.util.Base64; @@ -51,9 +52,7 @@ protected byte[] runCipher(byte[] data, boolean encrypt) { Cipher cipher = getCipher(mode); return cipher.doFinal(data); - } catch (IllegalBlockSizeException e) { - throw new RuntimeException(e); - } catch (BadPaddingException e) { + } catch (IllegalBlockSizeException | BadPaddingException e) { throw new RuntimeException(e); } } @@ -68,11 +67,7 @@ private Cipher getCipher(int mode) { cipher.init(mode, secretKey); return cipher; - } catch (NoSuchAlgorithmException e) { - throw new RuntimeException(e); - } catch (NoSuchPaddingException e) { - throw new RuntimeException(e); - } catch (InvalidKeyException e) { + } catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException e) { throw new RuntimeException(e); } @@ -91,12 +86,8 @@ public String encrypt(String password) { if (isEncrypted(password)) { return password; } - try { - byte[] encryptedData = runCipher(password.getBytes("UTF-8"), true); - return ENCRYPTED_PREFIX + Base64.getEncoder().encodeToString(encryptedData); - } catch (UnsupportedEncodingException e) { - throw new RuntimeException(e); - } + byte[] encryptedData = runCipher(password.getBytes(StandardCharsets.UTF_8), true); + return ENCRYPTED_PREFIX + Base64.getEncoder().encodeToString(encryptedData); } @Override @@ -104,13 +95,9 @@ public String decrypt(String password) { if (!isEncrypted(password)) { return password; } - try { - byte[] encryptedData = Base64.getDecoder().decode(password.substring(ENCRYPTED_PREFIX.length())); - byte[] clearData = runCipher(encryptedData, false); - return new String(clearData, "UTF-8"); - } catch (UnsupportedEncodingException e) { - throw new RuntimeException(e); - } + byte[] encryptedData = Base64.getDecoder().decode(password.substring(ENCRYPTED_PREFIX.length())); + byte[] clearData = runCipher(encryptedData, false); + return new String(clearData, StandardCharsets.UTF_8); } } diff --git a/src/main/java/com/englishtown/bitbucket/hook/DefaultSettingsReflectionHelper.java b/src/main/java/com/englishtown/bitbucket/hook/DefaultSettingsReflectionHelper.java index accaf8d..e5fd7ef 100644 --- a/src/main/java/com/englishtown/bitbucket/hook/DefaultSettingsReflectionHelper.java +++ b/src/main/java/com/englishtown/bitbucket/hook/DefaultSettingsReflectionHelper.java @@ -24,10 +24,7 @@ public void set(Map values, Settings settings) { field.setAccessible(true); field.set(settings, values); - } catch (NoSuchFieldException e) { - throw new RuntimeException("Unable to encrypt the password. Check for an updated version of the mirror " + - "hook.", e); - } catch (IllegalAccessException e) { + } catch (NoSuchFieldException | IllegalAccessException e) { throw new RuntimeException("Unable to encrypt the password. Check for an updated version of the mirror " + "hook.", e); } diff --git a/src/main/java/com/englishtown/bitbucket/hook/MirrorRepositoryHook.java b/src/main/java/com/englishtown/bitbucket/hook/MirrorRepositoryHook.java index 643904d..87f8b97 100644 --- a/src/main/java/com/englishtown/bitbucket/hook/MirrorRepositoryHook.java +++ b/src/main/java/com/englishtown/bitbucket/hook/MirrorRepositoryHook.java @@ -63,7 +63,7 @@ public MirrorRepositoryHook(ConcurrencyService concurrencyService, int attempts = propertiesService.getPluginProperty(PROP_ATTEMPTS, 5); int threads = propertiesService.getPluginProperty(PROP_THREADS, 3); - pushExecutor = concurrencyService.getBucketedExecutor(getClass().getSimpleName(), + pushExecutor = concurrencyService.getBucketedExecutor(getClass().getCanonicalName(), new BucketedExecutorSettings.Builder<>(MirrorRequest::toString, pushProcessor) .batchSize(Integer.MAX_VALUE) // Coalesce all requests into a single push .maxAttempts(attempts) @@ -120,18 +120,15 @@ public Repository visit(@Nonnull RepositoryScope scope) { if (repository == null) { return; } - + boolean ok = true; + logger.debug("MirrorRepositoryHook: validate started."); try { - boolean ok = true; - logger.debug("MirrorRepositoryHook: validate started."); - List mirrorSettings = getMirrorSettings(settings, false, false, false); for (MirrorSettings ms : mirrorSettings) { if (!validate(ms, errors)) { ok = false; } } - // If no errors, run the mirror command if (ok) { updateSettings(mirrorSettings, settings); @@ -155,7 +152,6 @@ private List getMirrorSettings(Settings settings, boolean defTag for (String key : allSettings.keySet()) { if (key.startsWith(SETTING_MIRROR_REPO_URL)) { String suffix = key.substring(SETTING_MIRROR_REPO_URL.length()); - MirrorSettings ms = new MirrorSettings(); ms.mirrorRepoUrl = settings.getString(SETTING_MIRROR_REPO_URL + suffix, ""); ms.username = settings.getString(SETTING_USERNAME + suffix, ""); @@ -173,7 +169,7 @@ private List getMirrorSettings(Settings settings, boolean defTag return results; } - private void schedulePushes(Repository repository, List list) { + private void schedulePushes(final Repository repository, List list) { list.forEach(settings -> pushExecutor.schedule(new MirrorRequest(repository, settings), 5L, TimeUnit.SECONDS)); } diff --git a/src/main/resources/static/mirror-repository-hook.js b/src/main/resources/static/mirror-repository-hook.js index 67c030d..cb65a19 100644 --- a/src/main/resources/static/mirror-repository-hook.js +++ b/src/main/resources/static/mirror-repository-hook.js @@ -1,7 +1,7 @@ define('et/hook/mirror', ['jquery', 'exports'], function ($, exports) { exports.init = function (createSubView, createButton) { - $('#et-add-button').click(function () { + $('#et-add-button').click(function() { try { var currIndex, index = 0, name, html; diff --git a/src/test/java/com/englishtown/bitbucket/hook/DefaultSettingsReflectionHelperTest.java b/src/test/java/com/englishtown/bitbucket/hook/DefaultSettingsReflectionHelperTest.java index 64bce75..098c0d0 100644 --- a/src/test/java/com/englishtown/bitbucket/hook/DefaultSettingsReflectionHelperTest.java +++ b/src/test/java/com/englishtown/bitbucket/hook/DefaultSettingsReflectionHelperTest.java @@ -48,7 +48,7 @@ public String getString(@Nonnull String key) { return (String) values.get(key); } - @Nonnull + @Nullable @Override public String getString(@Nonnull String key, @Nonnull String defaultValue) { return null;