Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.447</version><!-- which version of Jenkins is this plugin built against? -->
<version>1.532.3</version><!-- which version of Jenkins is this plugin built against? -->
</parent>

<groupId>com.seitenbau.jenkins.plugins</groupId>
<artifactId>dynamicparameter</artifactId>
<packaging>hpi</packaging>
<version>0.2.1-SNAPSHOT</version>

<version>0.2.1</version>
<name>Jenkins Dynamic Parameter Plug-in</name>
<description>
This plugin allows build parameters with dynamically generated default values.
</description>

<licenses>
<license>
<name>Apache License</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
import hudson.remoting.VirtualChannel;

import java.util.Collections;
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -142,7 +143,7 @@ public final String getScriptResultAsString(Map<String, String> parameters)
}

@Override
public final ParameterValue createValue(StaplerRequest req, JSONObject jo)
public ParameterValue createValue(StaplerRequest req, JSONObject jo)
{
final JSONObject parameterJsonModel = new JSONObject(false);
final Object value = jo.get("value");
Expand Down Expand Up @@ -181,7 +182,7 @@ private StringParameterValue createStringParameterValueFor(String name, String v
* @return if the value is valid the same parameter value
* @throws IllegalArgumentException if the value in not valid
*/
protected StringParameterValue checkParameterValue(StringParameterValue value)
protected ParameterValue checkParameterValue(ParameterValue value)
{
return value;
}
Expand Down Expand Up @@ -235,7 +236,11 @@ private final Object executeScript(Map<String, String> parameters)
}
}
}
Callable<Object, Throwable> call = prepareLocalCall(parameters);

// for "local" scripts, expose the current Jenkins job as "currentJob" variable
Map<String, Object> p = new HashMap<String, Object>(parameters);
p.put("currentJob", JenkinsUtils.findCurrentProject(getUUID()));
Callable<Object, Throwable> call = prepareLocalCall((Map)p);
return call.call();
}
catch (Throwable e)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
* Copyright 2012 Seitenbau
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.seitenbau.jenkins.plugins.dynamicparameter;

import hudson.Extension;
import hudson.model.ParameterValue;
import hudson.model.BooleanParameterValue;

import java.util.Collections;

import net.sf.json.JSONObject;

import org.jvnet.localizer.ResourceBundleHolder;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;

/** Text parameter, with dynamically generated default value. */
public class BooleanParameterDefinition extends ScriptParameterDefinition
{
/** Serial version UID. */
private static final long serialVersionUID = 3162331168133114084L;

private final Boolean readonlyInputField;

/**
* Constructor with the parameter which are injected by the jenkins runtime.
*
* @param name parameter name
* @param script script, which generates the parameter value
* @param description parameter description
* @param uuid identifier (optional)
* @param remote execute the script on a remote node
* @param readonlyInputField should the input field marked as read only true / false
* @param classPath the class path description
*/
@DataBoundConstructor
public BooleanParameterDefinition(String name, String script, String description, String uuid,
Boolean remote, Boolean readonlyInputField, String classPath)
{
super(name, script, description, uuid, remote, classPath);
this.readonlyInputField = readonlyInputField;
}


/**
* Execute the script and return the default value for this parameter.
* @return the default value generated by the script or {@code null}
*/
public final boolean getDefaultValue()
{
return Boolean.parseBoolean(getScriptResultAsString(Collections.<String, String> emptyMap()));
}

/**
* Return default parameter value - used by trigger mechanism.
*/
@Override
public ParameterValue getDefaultParameterValue() {
BooleanParameterValue booleanParameterValue = new BooleanParameterValue(getName(), getDefaultValue());
return booleanParameterValue;
}

/**
* Return a Parameter value object for a command line parameter.
*/
@Override
public ParameterValue createValue(String value)
{
BooleanParameterValue parameterValue = new BooleanParameterValue(getName(), Boolean.parseBoolean(value), getDescription());
return checkParameterValue(parameterValue);
}

@Override
public ParameterValue createValue(StaplerRequest req, JSONObject jo)
{
BooleanParameterValue value = req.bindJSON(BooleanParameterValue.class, jo);
value.setDescription(getDescription());
return value;
}

public final boolean isReadonlyInputField()
{
if(readonlyInputField == null)
{
return false;
}
return readonlyInputField;
}

/** Parameter descriptor. */
@Extension
public static final class DescriptorImpl extends BaseDescriptor
{
private static final String DISPLAY_NAME = "DisplayName";

@Override
public final String getDisplayName()
{
return ResourceBundleHolder.get(BooleanParameterDefinition.class).format(DISPLAY_NAME);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ public abstract class ScriptParameterDefinition extends BaseParameterDefinition
private final String _script;

/** Local class path. */
private final FilePath _localBaseDirectory;

private final String _localBaseDirectory;
/** Remote class path. */
private final String _remoteBaseDirectory;

/** Class path. */
private final String _classPath;

Expand All @@ -72,7 +72,7 @@ protected ScriptParameterDefinition(String name, String script, String descripti
{
super(name, description, uuid, remote);

_localBaseDirectory = new FilePath(DynamicParameterConfiguration.INSTANCE.getBaseDirectoryFile());
_localBaseDirectory = DynamicParameterConfiguration.INSTANCE.getBaseDirectoryFile().toString();
_remoteBaseDirectory = DEFAULT_REMOTE_CLASSPATH;
_classPath = classPath;
_script = script;
Expand All @@ -82,7 +82,7 @@ protected ScriptParameterDefinition(String name, String script, String descripti
* Local class path directory.
* @return directory on the local node
*/
public final FilePath getLocalBaseDirectory()
public final String getLocalBaseDirectory()
{
return _localBaseDirectory;
}
Expand Down Expand Up @@ -149,7 +149,7 @@ private FilePath[] setupLocalClassPaths()
for (int i = 0; i < localClassPaths.length; i++)
{
String path = paths[i];
FilePath localClassPath = new FilePath(getLocalBaseDirectory(), path);
FilePath localClassPath = new FilePath(new FilePath(new File(getLocalBaseDirectory())), path);
localClassPaths[i] = localClassPath;
}
return localClassPaths;
Expand All @@ -174,7 +174,7 @@ private FilePath[] setupRemoteClassPaths(VirtualChannel channel) throws IOExcept
{
String path = paths[i];

FilePath localClassPath = new FilePath(getLocalBaseDirectory(), path);
FilePath localClassPath = new FilePath(new FilePath(new File(getLocalBaseDirectory())), path);
FilePath remoteClassPath = new FilePath(remoteBaseDirectory, path);

localClassPath.copyRecursiveTo(remoteClassPath);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* Copyright 2012 Seitenbau
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.seitenbau.jenkins.plugins.dynamicparameter;

import hudson.Extension;
import hudson.model.ParameterValue;
import hudson.model.StringParameterValue;
import hudson.model.TextParameterValue;

import java.util.Collections;

import net.sf.json.JSONObject;

import org.jvnet.localizer.ResourceBundleHolder;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;

/** Text parameter, with dynamically generated default value. */
public class TextParameterDefinition extends ScriptParameterDefinition
{
/** Serial version UID. */
private static final long serialVersionUID = 3162331168133114084L;

private final Boolean readonlyInputField;

/**
* Constructor with the parameter which are injected by the jenkins runtime.
*
* @param name parameter name
* @param script script, which generates the parameter value
* @param description parameter description
* @param uuid identifier (optional)
* @param remote execute the script on a remote node
* @param readonlyInputField should the input field marked as read only true / false
* @param classPath the class path description
*/
@DataBoundConstructor
public TextParameterDefinition(String name, String script, String description, String uuid,
Boolean remote, Boolean readonlyInputField, String classPath)
{
super(name, script, description, uuid, remote, classPath);
this.readonlyInputField = readonlyInputField;
}


/**
* Execute the script and return the default value for this parameter.
* @return the default value generated by the script or {@code null}
*/
public final String getDefaultValue()
{
return getScriptResultAsString(Collections.<String, String> emptyMap());
}

/**
* Return default parameter value - used by trigger mechanism.
*/
@Override
public ParameterValue getDefaultParameterValue() {
TextParameterValue stringParameterValue = new TextParameterValue(getName(), getDefaultValue());
return stringParameterValue;
}

/**
* Return a Parameter value object for a command line parameter.
*/
@Override
public ParameterValue createValue(String value)
{
StringParameterValue parameterValue = new TextParameterValue(getName(), value, getDescription());
return checkParameterValue(parameterValue);
}

@Override
public ParameterValue createValue(StaplerRequest req, JSONObject jo)
{
TextParameterValue value = req.bindJSON(TextParameterValue.class, jo);
value.setDescription(getDescription());
return value;
}

public final boolean isReadonlyInputField()
{
if(readonlyInputField == null)
{
return false;
}
return readonlyInputField;
}

/** Parameter descriptor. */
@Extension
public static final class DescriptorImpl extends BaseDescriptor
{
private static final String DISPLAY_NAME = "DisplayName";

@Override
public final String getDisplayName()
{
return ResourceBundleHolder.get(TextParameterDefinition.class).format(DISPLAY_NAME);
}
}

}
Loading