Skip to content
Permalink
Browse files

[FIXED JENKINS-9480] - request for textarea instead of textbox for ex…

…ec command
  • Loading branch information
bap2000 committed May 6, 2011
1 parent 29a6339 commit 5600e294d12b0c0052eb0563bc49098ac205d202
@@ -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);
}

}
@@ -0,0 +1 @@
Publish Over ... jelly tags
@@ -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>
@@ -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.
You can’t perform that action at this time.