Skip to content

Commit

Permalink
[FIXED JENKINS-9480] - request for textarea instead of textbox for ex…
Browse files Browse the repository at this point in the history
…ec command
  • Loading branch information
bap2000 committed May 6, 2011
1 parent 29a6339 commit 5600e29
Show file tree
Hide file tree
Showing 4 changed files with 178 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/main/java/jenkins/plugins/publish_over/JellySupport.java
@@ -0,0 +1,41 @@
/*
* The MIT License
*
* Copyright (C) 2010-2011 by Anthony Robinson
*
* 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 jenkins.plugins.publish_over;

import java.util.regex.Pattern;

public class JellySupport {

public static final int MINIMUM_MINIMUM_HEIGHT = 1;
public static final int DEFAULT_MINIMUM_HEIGHT = 5;
private static final Pattern LINE_END = Pattern.compile("\r?\n");

public static final int textAreaHeight(final int minimum, final String content) {
final int min = Math.max(minimum, MINIMUM_MINIMUM_HEIGHT);
if (content == null) return min;
return Math.max(min, LINE_END.split(content).length);
}

}
1 change: 1 addition & 0 deletions src/main/resources/pojelly/taglib
@@ -0,0 +1 @@
Publish Over ... jelly tags
76 changes: 76 additions & 0 deletions src/main/resources/pojelly/textarea.jelly
@@ -0,0 +1,76 @@
<!--
~ The MIT License
~
~ Copyright (C) 2004-2011 by Sun Microsystems, Inc., Kohsuke Kawaguchi, Johnathon Jamison, Yahoo! Inc, Anthony Robinson
~
~ 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.
-->

<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:f="/lib/form">
<st:documentation>
&lt;textarea> tag on steroids.
The textarea will be rendered to fit the content. It also gets the resize handle.

<st:attribute name="field">
Used for databinding. TBD.
</st:attribute>
<st:attribute name="name">
This becomes @name of the &lt;textarea> tag.
If @field is specified, this value is inferred from it.
</st:attribute>
<st:attribute name="value">
The initial value of the field. This becomes the value of the &lt;textarea> tag.
If @field is specified, the current property from the "instance" object
will be set as the initial value automatically,
which is the recommended approach.
</st:attribute>
<st:attribute name="default">
The default value of the text box, in case both @value is and 'instance[field]' is null.
</st:attribute>
<st:attribute name="checkUrl">
If specified, the value entered in this input field will be checked (via AJAX)
against this URL, and errors will be rendered under the text field.

If @field is specified, this will be inferred automatically,
which is the recommended approach.
</st:attribute>
<st:attribute name="minRows">
If specified, the minimum height (rows) of the textarea (when initially rendered)
</st:attribute>
</st:documentation>

<f:prepareDatabinding />
<j:new var="poj" className="jenkins.plugins.publish_over.JellySupport" useContextClassLoader="true"/>
<j:set var="minRows" value="${attrs.minRows ?: poj.DEFAULT_MINIMUM_HEIGHT}"/>
<j:set var="value" value="${attrs.value ?: instance[attrs.field] ?: attrs.default}" />
<j:invoke var="numRows" method="textAreaHeight" on="${poj}">
<j:arg type="int" value="${minRows}"/>
<j:arg type="java.lang.String" value="${value}"/>
</j:invoke>
<textarea id="${attrs.id}" style="${attrs.style}"
name ="${attrs.name ?: '_.'+attrs.field}"
class="setting-input ${attrs.checkUrl!=null?'validated':''} ${attrs.class}"
checkUrl="${attrs.checkUrl}"
rows="${numRows}">
<st:out value="${value}" />
</textarea>
<!-- resize handle -->
<div class="textarea-handle"/>
</j:jelly>
60 changes: 60 additions & 0 deletions src/test/java/jenkins/plugins/publish_over/JellySupportTest.java
@@ -0,0 +1,60 @@
/*
* The MIT License
*
* Copyright (C) 2010-2011 by Anthony Robinson
*
* 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 jenkins.plugins.publish_over;

import org.junit.Test;
import static org.junit.Assert.assertEquals;

public class JellySupportTest {

@Test public void textAreaHeightMinimumIfNoContent() {
assertEquals(3, JellySupport.textAreaHeight(3, null));
}

@Test public void textAreaHeightMinimumIfEmpty() {
assertEquals(1, JellySupport.textAreaHeight(1, ""));
}

@Test public void textAreaHeightUnixContentLines() {
assertEquals(3, JellySupport.textAreaHeight(1, "one\ntwo\nthree"));
}

@Test public void textAreaHeightWindowsContentLines() {
assertEquals(3, JellySupport.textAreaHeight(1, "one\r\ntwo\r\nthree"));
}

@Test public void textAreaHeightMinimumIfGreaterThanHeight() {
assertEquals(3, JellySupport.textAreaHeight(3, "one\ntwo"));
}

@Test public void textAreaHeightContentHeightIfGreaterThanMinimum() {
assertEquals(3, JellySupport.textAreaHeight(2, "one\ntwo\nthree"));
}

@Test public void textAreaHeightEnforceMinimumMinimum() {
assertEquals(JellySupport.MINIMUM_MINIMUM_HEIGHT, JellySupport.textAreaHeight(JellySupport.MINIMUM_MINIMUM_HEIGHT -1, null));
}

}

0 comments on commit 5600e29

Please sign in to comment.