Skip to content

Commit 2580545

Browse files
authored
Remove custom stylesheet in jelly files. Use standard select for NodeJS installations (#181)
1 parent bbf75dc commit 2580545

File tree

8 files changed

+59
-48
lines changed

8 files changed

+59
-48
lines changed

src/main/java/jenkins/plugins/nodejs/NodeJSBuildWrapper.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
*/
2424
package jenkins.plugins.nodejs;
2525

26+
import edu.umd.cs.findbugs.annotations.CheckForNull;
27+
import edu.umd.cs.findbugs.annotations.NonNull;
28+
import edu.umd.cs.findbugs.annotations.Nullable;
2629
import hudson.AbortException;
2730
import hudson.EnvVars;
2831
import hudson.Extension;
@@ -32,6 +35,7 @@
3235
import hudson.console.ConsoleLogFilter;
3336
import hudson.model.AbstractProject;
3437
import hudson.model.Computer;
38+
import hudson.model.Item;
3539
import hudson.model.ItemGroup;
3640
import hudson.model.Node;
3741
import hudson.model.Run;
@@ -51,9 +55,6 @@
5155
import java.util.logging.Level;
5256
import java.util.logging.Logger;
5357
import java.util.regex.Pattern;
54-
import edu.umd.cs.findbugs.annotations.CheckForNull;
55-
import edu.umd.cs.findbugs.annotations.NonNull;
56-
import edu.umd.cs.findbugs.annotations.Nullable;
5758
import jenkins.plugins.nodejs.cache.CacheLocationLocator;
5859
import jenkins.plugins.nodejs.cache.DefaultCacheLocationLocator;
5960
import jenkins.plugins.nodejs.tools.NodeJSInstallation;
@@ -68,6 +69,7 @@
6869
import org.kohsuke.stapler.DataBoundConstructor;
6970
import org.kohsuke.stapler.DataBoundSetter;
7071
import org.kohsuke.stapler.QueryParameter;
72+
import org.kohsuke.stapler.verb.POST;
7173

7274
/**
7375
* A simple build wrapper that contribute the NodeJS bin path to the PATH
@@ -254,8 +256,15 @@ public String getDisplayName() {
254256
return Messages.NodeJSBuildWrapper_displayName();
255257
}
256258

257-
public NodeJSInstallation[] getInstallations() {
258-
return NodeJSUtils.getInstallations();
259+
/**
260+
* Returns all tools defined in the tool page.
261+
*
262+
* @param item context against check permission
263+
* @return a collection of tools name.
264+
*/
265+
@POST
266+
public ListBoxModel doFillNodeJSInstallationNameItems(@Nullable @AncestorInPath Item item) {
267+
return NodeJSDescriptorUtils.getNodeJSInstallations(item, false);
259268
}
260269

261270
/**
@@ -264,6 +273,7 @@ public NodeJSInstallation[] getInstallations() {
264273
* @param context where lookup
265274
* @return a collection of user npmrc files.
266275
*/
276+
@POST
267277
public ListBoxModel doFillConfigIdItems(@AncestorInPath ItemGroup<?> context) {
268278
return NodeJSDescriptorUtils.getConfigs(context);
269279
}
@@ -275,7 +285,8 @@ public ListBoxModel doFillConfigIdItems(@AncestorInPath ItemGroup<?> context) {
275285
* @param configId the identifier of an npmrc file
276286
* @return an validation form for the given npmrc file identifier.
277287
*/
278-
public FormValidation doCheckConfigId(@Nullable @AncestorInPath ItemGroup<?> context, @CheckForNull @QueryParameter final String configId) {
288+
public FormValidation doCheckConfigId(@Nullable @AncestorInPath ItemGroup<?> context,
289+
@CheckForNull @QueryParameter final String configId) {
279290
return NodeJSDescriptorUtils.checkConfig(context, configId);
280291
}
281292

@@ -294,7 +305,7 @@ private static final class SecretFilter extends ConsoleLogFilter implements Seri
294305
}
295306

296307
@Override
297-
public OutputStream decorateLogger(Run build, OutputStream logger) {
308+
public OutputStream decorateLogger(@SuppressWarnings("rawtypes") Run build, OutputStream logger) {
298309
return new SecretPatterns.MaskingOutputStream(logger, () -> Pattern.compile(pattern.getPlainText()), charset);
299310
}
300311

src/main/java/jenkins/plugins/nodejs/NodeJSCommandInterpreter.java

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,8 @@
2323
*/
2424
package jenkins.plugins.nodejs;
2525

26-
import java.io.IOException;
27-
import java.util.ArrayList;
28-
2926
import edu.umd.cs.findbugs.annotations.CheckForNull;
3027
import edu.umd.cs.findbugs.annotations.Nullable;
31-
32-
import org.jenkinsci.Symbol;
33-
import org.jenkinsci.lib.configprovider.model.ConfigFile;
34-
import org.jenkinsci.lib.configprovider.model.ConfigFileManager;
35-
import org.jenkinsci.plugins.configfiles.common.CleanTempFilesAction;
36-
import org.kohsuke.stapler.AncestorInPath;
37-
import org.kohsuke.stapler.DataBoundConstructor;
38-
import org.kohsuke.stapler.DataBoundSetter;
39-
import org.kohsuke.stapler.QueryParameter;
40-
4128
import hudson.AbortException;
4229
import hudson.EnvVars;
4330
import hudson.Extension;
@@ -47,6 +34,7 @@
4734
import hudson.model.AbstractBuild;
4835
import hudson.model.AbstractProject;
4936
import hudson.model.Environment;
37+
import hudson.model.Item;
5038
import hudson.model.ItemGroup;
5139
import hudson.model.Node;
5240
import hudson.model.TaskListener;
@@ -56,10 +44,21 @@
5644
import hudson.util.ArgumentListBuilder;
5745
import hudson.util.FormValidation;
5846
import hudson.util.ListBoxModel;
47+
import java.io.IOException;
48+
import java.util.ArrayList;
5949
import jenkins.plugins.nodejs.cache.CacheLocationLocator;
6050
import jenkins.plugins.nodejs.cache.DefaultCacheLocationLocator;
6151
import jenkins.plugins.nodejs.tools.NodeJSInstallation;
6252
import jenkins.plugins.nodejs.tools.Platform;
53+
import org.jenkinsci.Symbol;
54+
import org.jenkinsci.lib.configprovider.model.ConfigFile;
55+
import org.jenkinsci.lib.configprovider.model.ConfigFileManager;
56+
import org.jenkinsci.plugins.configfiles.common.CleanTempFilesAction;
57+
import org.kohsuke.stapler.AncestorInPath;
58+
import org.kohsuke.stapler.DataBoundConstructor;
59+
import org.kohsuke.stapler.DataBoundSetter;
60+
import org.kohsuke.stapler.QueryParameter;
61+
import org.kohsuke.stapler.verb.POST;
6362

6463
/**
6564
* This class executes a JavaScript file using node. The file should contain
@@ -276,25 +275,23 @@ public String getDisplayName() {
276275
}
277276

278277
/**
279-
* Return the help file.
278+
* Returns all tools defined in the tool page.
280279
*
281-
* @return the help file URL path
280+
* @param item context against check permission
281+
* @return a collection of tools name.
282282
*/
283-
@Override
284-
public String getHelpFile() {
285-
return "/plugin/nodejs/help.html";
286-
}
287-
288-
public NodeJSInstallation[] getInstallations() {
289-
return NodeJSUtils.getInstallations();
283+
@POST
284+
public ListBoxModel doFillNodeJSInstallationNameItems(@Nullable @AncestorInPath Item item) {
285+
return NodeJSDescriptorUtils.getNodeJSInstallations(item, true);
290286
}
291287

292288
/**
293289
* Gather all defined npmrc config files.
294290
*
295-
* @param context where loopup
291+
* @param context where lookup
296292
* @return a collection of user npmrc files.
297293
*/
294+
@POST
298295
public ListBoxModel doFillConfigIdItems(@AncestorInPath ItemGroup<?> context) {
299296
return NodeJSDescriptorUtils.getConfigs(context);
300297
}
@@ -306,6 +303,7 @@ public ListBoxModel doFillConfigIdItems(@AncestorInPath ItemGroup<?> context) {
306303
* @param configId the identifier of an npmrc file
307304
* @return an validation form for the given npmrc file identifier.
308305
*/
306+
@POST
309307
public FormValidation doCheckConfigId(@Nullable @AncestorInPath ItemGroup<?> context, @CheckForNull @QueryParameter final String configId) {
310308
return NodeJSDescriptorUtils.checkConfig(context, configId);
311309
}

src/main/java/jenkins/plugins/nodejs/NodeJSDescriptorUtils.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@
2929

3030
import org.jenkinsci.lib.configprovider.model.Config;
3131
import org.jenkinsci.plugins.configfiles.ConfigFiles;
32-
32+
import hudson.model.Item;
3333
import hudson.model.ItemGroup;
3434
import hudson.util.FormValidation;
3535
import hudson.util.ListBoxModel;
3636
import jenkins.plugins.nodejs.configfiles.NPMConfig;
3737
import jenkins.plugins.nodejs.configfiles.NPMConfig.NPMConfigProvider;
38+
import jenkins.plugins.nodejs.tools.NodeJSInstallation;
3839
import jenkins.plugins.nodejs.configfiles.VerifyConfigProviderException;
3940

4041
/*package*/ final class NodeJSDescriptorUtils {
@@ -61,7 +62,7 @@ public static ListBoxModel getConfigs(@Nullable ItemGroup<?> context) {
6162

6263
/**
6364
* Verify that the given configId exists in the given context.
64-
*
65+
*
6566
* @param context where lookup
6667
* @param configId the identifier of an npmrc file
6768
* @return an validation form for the given npmrc file identifier, otherwise
@@ -82,4 +83,18 @@ public static FormValidation checkConfig(@Nullable ItemGroup<?> context, @CheckF
8283
return FormValidation.ok();
8384
}
8485

86+
public static ListBoxModel getNodeJSInstallations(@Nullable Item item, boolean allowDefault) {
87+
ListBoxModel items = new ListBoxModel();
88+
if (item == null || !item.hasPermission(Item.CONFIGURE)) {
89+
return items;
90+
}
91+
if (allowDefault) {
92+
items.add(Messages.NodeJSInstallation_default(), "");
93+
}
94+
for (NodeJSInstallation tool : NodeJSUtils.getInstallations()) {
95+
items.add(tool.getName(), tool.getName());
96+
}
97+
return items;
98+
}
99+
85100
}

src/main/resources/jenkins/plugins/nodejs/Messages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ NodeJSInstaller.FailedToInstallNodeJS=Failed to install NodeJS. Exit code={0}
2626
NodeJSInstaller.installFromCache=Installing NodeJS from {0} to {1} on {2}
2727
NodeJSInstaller.failedToUnpack=Failed to unpack {0} ({1} bytes read)
2828
NodeJSInstallation.displayName=NodeJS
29+
NodeJSInstallation.default=- use system default -
2930
NodeJSBuildWrapper.displayName=Provide Node & npm bin/ folder to PATH
3031
NodeJSCommandInterpreter.displayName=Execute NodeJS script
3132
NodeJSCommandInterpreter.commandFailed=command execution failed

src/main/resources/jenkins/plugins/nodejs/NodeJSBuildWrapper/config.jelly

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@ THE SOFTWARE.
2424
<?jelly escape-by-default='true'?>
2525
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
2626
<f:entry title="${%nodeJSInstallationName.title}" description="${%nodeJSInstallationName.description}">
27-
<select class="setting-input" name="_.nodeJSInstallationName">
28-
<j:forEach var="inst" items="${descriptor.installations}">
29-
<f:option selected="${inst.name==instance.nodeJSInstallationName}">${inst.name}</f:option>
30-
</j:forEach>
31-
</select>
27+
<f:select field="nodeJSInstallationName" />
3228
</f:entry>
3329

3430
<f:entry title="${%configId.title}">

src/main/resources/jenkins/plugins/nodejs/NodeJSCommandInterpreter/config.jelly

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,7 @@ THE SOFTWARE.
2424
<?jelly escape-by-default='true'?>
2525
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
2626
<f:entry title="${%nodeJSInstallationName.title}" description="${%nodeJSInstallationName.description}">
27-
<select class="setting-input" name="_.nodeJSInstallationName">
28-
<f:option value="">${%nodeJSInstallationName.emptyValue}</f:option>
29-
<j:forEach var="inst" items="${descriptor.installations}">
30-
<f:option selected="${inst.name==instance.nodeJSInstallationName}">${inst.name}</f:option>
31-
</j:forEach>
32-
</select>
27+
<f:select field="nodeJSInstallationName" />
3328
</f:entry>
3429

3530
<f:entry title="${%command.title}" description="See &lt;a href='${rootURL}/env-vars.html' target=_new>the list of available environment variables&lt;/a> accessible by process.env.ENV_VARIABLE.">

src/main/webapp/help.html renamed to src/main/resources/jenkins/plugins/nodejs/NodeJSCommandInterpreter/help.html

File renamed without changes.

src/test/java/jenkins/plugins/nodejs/SimpleNodeJSCommandInterpreterTest.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,6 @@ void testDescriptorGetDisplayNameShouldGiveExpectedValue() {
9090
assertThat(descriptor.getDisplayName()).isEqualTo(Messages.NodeJSCommandInterpreter_displayName());
9191
}
9292

93-
@Test
94-
void testDescriptorGetHelpFileShouldGiveExpectedValue() {
95-
assertThat(descriptor.getHelpFile()).isEqualTo("/plugin/nodejs/help.html");
96-
}
97-
9893
private static File newFolder(File root, String... subDirs) throws IOException {
9994
String subFolder = String.join("/", subDirs);
10095
File result = new File(root, subFolder);

0 commit comments

Comments
 (0)