diff --git a/src/main/java/org/jenkins/plugins/lockableresources/LockStep.java b/src/main/java/org/jenkins/plugins/lockableresources/LockStep.java index 6a9cca988..7577885a4 100644 --- a/src/main/java/org/jenkins/plugins/lockableresources/LockStep.java +++ b/src/main/java/org/jenkins/plugins/lockableresources/LockStep.java @@ -98,7 +98,7 @@ public String getFunctionName() { @NonNull @Override public String getDisplayName() { - return "Lock shared resource"; + return Messages.LockStep_displayName(); } @Override diff --git a/src/main/java/org/jenkins/plugins/lockableresources/LockStepResource.java b/src/main/java/org/jenkins/plugins/lockableresources/LockStepResource.java index c89e80dfa..cc4f82d3a 100644 --- a/src/main/java/org/jenkins/plugins/lockableresources/LockStepResource.java +++ b/src/main/java/org/jenkins/plugins/lockableresources/LockStepResource.java @@ -86,10 +86,10 @@ public void validate() { */ public static void validate(String resource, String label, int quantity) { if (label != null && !label.isEmpty() && resource != null && !resource.isEmpty()) { - throw new IllegalArgumentException("Label and resource name cannot be specified simultaneously."); + throw new IllegalArgumentException(Messages.error_labelAndNameSpecified()); } if (label != null && !LockableResourcesManager.get().isValidLabel( label ) ) { - throw new IllegalArgumentException("The label does not exist: " + label); + throw new IllegalArgumentException(Messages.error_labelDoesNotExist(label)); } } @@ -101,7 +101,7 @@ public static class DescriptorImpl extends Descriptor { @NonNull @Override public String getDisplayName() { - return "Resource"; + return Messages.LockStepResource_displayName(); } @RequirePOST @@ -124,13 +124,13 @@ public static FormValidation doCheckLabel(@QueryParameter String value, String resourceLabel = Util.fixEmpty(value); String resourceName = Util.fixEmpty(resource); if (resourceLabel != null && resourceName != null) { - return FormValidation.error("Label and resource name cannot be specified simultaneously."); + return FormValidation.error(Messages.error_labelAndNameSpecified()); } if ((resourceLabel == null) && (resourceName == null)) { - return FormValidation.error("Either label or resource name must be specified."); + return FormValidation.error(Messages.error_labelOrNameMustBeSpecified()); } if (resourceLabel != null && !LockableResourcesManager.get().isValidLabel(resourceLabel)) { - return FormValidation.error("The label does not exist: " + resourceLabel); + return FormValidation.error(Messages.error_labelDoesNotExist(resourceLabel)); } return FormValidation.ok(); } diff --git a/src/main/java/org/jenkins/plugins/lockableresources/LockableResource.java b/src/main/java/org/jenkins/plugins/lockableresources/LockableResource.java index a28abaed6..e50eefee4 100644 --- a/src/main/java/org/jenkins/plugins/lockableresources/LockableResource.java +++ b/src/main/java/org/jenkins/plugins/lockableresources/LockableResource.java @@ -475,7 +475,7 @@ public static class DescriptorImpl extends Descriptor { @NonNull @Override public String getDisplayName() { - return "Resource"; + return Messages.LockableResource_displayName(); } } } diff --git a/src/main/java/org/jenkins/plugins/lockableresources/LockableResourcesManager.java b/src/main/java/org/jenkins/plugins/lockableresources/LockableResourcesManager.java index 1c56a13f2..e7a19e9ea 100644 --- a/src/main/java/org/jenkins/plugins/lockableresources/LockableResourcesManager.java +++ b/src/main/java/org/jenkins/plugins/lockableresources/LockableResourcesManager.java @@ -865,7 +865,7 @@ public synchronized void unreserve(List resources) { @NonNull @Override public String getDisplayName() { - return "External Resources"; + return Messages.LockableResourcesManager_displayName(); } public synchronized void reset(List resources) { diff --git a/src/main/java/org/jenkins/plugins/lockableresources/RequiredResourcesProperty.java b/src/main/java/org/jenkins/plugins/lockableresources/RequiredResourcesProperty.java index 5a720143a..4f27d9c82 100644 --- a/src/main/java/org/jenkins/plugins/lockableresources/RequiredResourcesProperty.java +++ b/src/main/java/org/jenkins/plugins/lockableresources/RequiredResourcesProperty.java @@ -137,7 +137,7 @@ public static class DescriptorImpl extends JobPropertyDescriptor { @NonNull @Override public String getDisplayName() { - return "Required Lockable Resources"; + return Messages.RequiredResourcesProperty_displayName(); } @Override @@ -167,8 +167,7 @@ public FormValidation doCheckResourceNames(@QueryParameter String value, if (names == null) { return FormValidation.ok(); } else if (labelVal != null || script) { - return FormValidation.error( - "Only label, groovy expression, or resources can be defined, not more than one."); + return FormValidation.error(Messages.error_labelAndNameOrGroovySpecified()); } else { List wrongNames = new ArrayList<>(); for (String name : names.split("\\s+")) { @@ -187,8 +186,7 @@ public FormValidation doCheckResourceNames(@QueryParameter String value, return FormValidation.ok(); } else { return FormValidation - .error("The following resources do not exist: " - + wrongNames); + .error(Messages.error_resourceDoesNotExist(wrongNames)); } } } @@ -209,13 +207,13 @@ public FormValidation doCheckLabelName( return FormValidation.ok(); } else if (names != null || script) { return FormValidation.error( - "Only label, groovy expression, or resources can be defined, not more than one."); + Messages.error_labelAndNameOrGroovySpecified()); } else { if (LockableResourcesManager.get().isValidLabel(label)) { return FormValidation.ok(); } else { return FormValidation.error( - "The label does not exist: " + label); + Messages.error_labelDoesNotExist(label)); } } } @@ -243,7 +241,7 @@ public FormValidation doCheckResourceNumber(@QueryParameter String value, numAsInt = Integer.parseInt(number); } catch(NumberFormatException e) { return FormValidation.error( - "Could not parse the given value as integer."); + Messages.error_couldNotParseToint()); } int numResources = 0; if (names != null) { @@ -254,7 +252,7 @@ public FormValidation doCheckResourceNumber(@QueryParameter String value, if (numResources < numAsInt) { return FormValidation.error(String.format( - "Given amount %d is greater than amount of resources: %d.", + Messages.error_givenAmountIsGreaterThatResurcesAmount(), numAsInt, numResources)); } diff --git a/src/main/java/org/jenkins/plugins/lockableresources/actions/LockableResourcesRootAction.java b/src/main/java/org/jenkins/plugins/lockableresources/actions/LockableResourcesRootAction.java index 80d5b369f..000af1164 100644 --- a/src/main/java/org/jenkins/plugins/lockableresources/actions/LockableResourcesRootAction.java +++ b/src/main/java/org/jenkins/plugins/lockableresources/actions/LockableResourcesRootAction.java @@ -171,7 +171,7 @@ public void doUnlock(StaplerRequest req, StaplerResponse rsp) String name = req.getParameter("resource"); LockableResource r = LockableResourcesManager.get().fromName(name); if (r == null) { - rsp.sendError(404, "Resource not found " + name); + rsp.sendError(404, Messages.error_resourceDoesNotExist(name)); return; } @@ -191,7 +191,7 @@ public void doReserve(StaplerRequest req, StaplerResponse rsp) String name = req.getParameter("resource"); LockableResource r = LockableResourcesManager.get().fromName(name); if (r == null) { - rsp.sendError(404, "Resource not found " + name); + rsp.sendError(404, Messages.error_resourceDoesNotExist(name)); return; } @@ -200,7 +200,7 @@ public void doReserve(StaplerRequest req, StaplerResponse rsp) String userName = getUserName(); if (userName != null) { if (!LockableResourcesManager.get().reserve(resources, userName)) { - rsp.sendError(423, "Resource '" + name + "' already reserved or locked!"); + rsp.sendError(423, Messages.error_resourceAlreadyLocked(name)); return; } } @@ -216,7 +216,7 @@ public void doSteal(StaplerRequest req, StaplerResponse rsp) String name = req.getParameter("resource"); LockableResource r = LockableResourcesManager.get().fromName(name); if (r == null) { - rsp.sendError(404, "Resource not found " + name); + rsp.sendError(404, Messages.error_resourceDoesNotExist(name)); return; } @@ -246,7 +246,7 @@ public void doReassign(StaplerRequest req, StaplerResponse rsp) String name = req.getParameter("resource"); LockableResource r = LockableResourcesManager.get().fromName(name); if (r == null) { - rsp.sendError(404, "Resource not found " + name); + rsp.sendError(404, Messages.error_resourceDoesNotExist(name)); return; } @@ -274,7 +274,7 @@ public void doUnreserve(StaplerRequest req, StaplerResponse rsp) String name = req.getParameter("resource"); LockableResource r = LockableResourcesManager.get().fromName(name); if (r == null) { - rsp.sendError(404, "Resource not found " + name); + rsp.sendError(404, Messages.error_resourceDoesNotExist(name)); return; } @@ -302,7 +302,7 @@ public void doReset(StaplerRequest req, StaplerResponse rsp) String name = req.getParameter("resource"); LockableResource r = LockableResourcesManager.get().fromName(name); if (r == null) { - rsp.sendError(404, "Resource not found " + name); + rsp.sendError(404, Messages.error_resourceDoesNotExist(name)); return; } @@ -325,7 +325,7 @@ public void doSaveNote(final StaplerRequest req, final StaplerResponse rsp) final LockableResource resource = getResource(resourceName); if (resource == null) { - rsp.sendError(404, "Resource not found: '" + resourceName + "'!"); + rsp.sendError(404, Messages.error_resourceDoesNotExist(resourceName)); } else { String resourceNote = req.getParameter("note"); if (resourceNote == null) { diff --git a/src/main/resources/org/jenkins/plugins/lockableresources/Messages.properties b/src/main/resources/org/jenkins/plugins/lockableresources/Messages.properties index 23f8110ec..13dc7a0a2 100644 --- a/src/main/resources/org/jenkins/plugins/lockableresources/Messages.properties +++ b/src/main/resources/org/jenkins/plugins/lockableresources/Messages.properties @@ -20,4 +20,18 @@ LockableResourcesRootAction.StealPermission.Description=This permission grants t LockableResourcesRootAction.ViewPermission=View LockableResourcesRootAction.ViewPermission.Description=This permission grants the ability to view \ lockable resources. - +# Java errors +error.labelDoesNotExist=The resource label does not exist: {0}. +error.resourceDoesNotExist=The resource does not exist: {0}. +error.labelOrNameMustBeSpecified=Either resource label or resource name must be specified. +error.labelAndNameSpecified=Resource label and resource name cannot be specified simultaneously. +error.labelAndNameOrGroovySpecified=Only resource label, groovy expression, or resource names can be defined, not more than one. +error.couldNotParseToint=Could not parse the given value as integer. +error.givenAmountIsGreaterThatResurcesAmount=Given amount %d is greater than amount of resources: %d. +error.resourceAlreadyLocked=Resource {0} already reserved or locked! +# display-names +LockStep.displayName=Lock shared resource +LockStepResource.displayName=Resource +LockableResource.displayName=Resource +LockableResourcesManager.displayName=External Resources +RequiredResourcesProperty.displayName=Required Lockable Resources diff --git a/src/test/java/org/jenkins/plugins/lockableresources/LockStepTest.java b/src/test/java/org/jenkins/plugins/lockableresources/LockStepTest.java index 0590f7ff5..713d06a18 100644 --- a/src/test/java/org/jenkins/plugins/lockableresources/LockStepTest.java +++ b/src/test/java/org/jenkins/plugins/lockableresources/LockStepTest.java @@ -1432,7 +1432,7 @@ public void lockWithInvalidLabel() throws Exception { WorkflowRun b1 = p.scheduleBuild2(0).waitForStart(); j.waitForCompletion(b1); j.assertBuildStatus(Result.FAILURE, b1); - j.assertLogContains("The label does not exist: invalidLabel", b1); + j.assertLogContains("The resource label does not exist: invalidLabel", b1); isPaused(b1, 0, 0); } diff --git a/src/test/java/org/jenkins/plugins/lockableresources/LockableResourceManagerTest.java b/src/test/java/org/jenkins/plugins/lockableresources/LockableResourceManagerTest.java index 48d2f3376..cab9283b5 100644 --- a/src/test/java/org/jenkins/plugins/lockableresources/LockableResourceManagerTest.java +++ b/src/test/java/org/jenkins/plugins/lockableresources/LockableResourceManagerTest.java @@ -28,22 +28,22 @@ public void validationFailure() throws Exception { r.setLabels("some-label"); assertEquals( - "Only label, groovy expression, or resources can be defined, not more than one.", + "Only resource label, groovy expression, or resource names can be defined, not more than one.", d.doCheckResourceNames("resource1", null, true, null).getMessage()); assertEquals( - "Only label, groovy expression, or resources can be defined, not more than one.", + "Only resource label, groovy expression, or resource names can be defined, not more than one.", d.doCheckResourceNames("resource1", "some-label", false, null).getMessage()); assertEquals( - "Only label, groovy expression, or resources can be defined, not more than one.", + "Only resource label, groovy expression, or resource names can be defined, not more than one.", d.doCheckResourceNames("resource1", "some-label", true, null).getMessage()); assertEquals( - "Only label, groovy expression, or resources can be defined, not more than one.", + "Only resource label, groovy expression, or resource names can be defined, not more than one.", d.doCheckLabelName("some-label", "resource1", false, null).getMessage()); assertEquals( - "Only label, groovy expression, or resources can be defined, not more than one.", + "Only resource label, groovy expression, or resource names can be defined, not more than one.", d.doCheckLabelName("some-label", null, true, null).getMessage()); assertEquals( - "Only label, groovy expression, or resources can be defined, not more than one.", + "Only resource label, groovy expression, or resource names can be defined, not more than one.", d.doCheckLabelName("some-label", "resource1", true, null).getMessage()); assertEquals(FormValidation.ok(), d.doCheckResourceNames("resource1", null, false, null));