Skip to content

Labels for new pages, ISO Encoding for confluence page data #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion rocks.inspectit.releaseplugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</parent>
<groupId>rocks.inspectit</groupId>
<artifactId>release-helper</artifactId>
<version>1.3</version>
<version>1.3.3</version>
<packaging>hpi</packaging>

<name>Jenkins Release Helper Plugin</name>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
package rocks.inspectit.releaseplugin;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.text.StrSubstitutor;
import org.kohsuke.stapler.AncestorInPath;

import com.cloudbees.plugins.credentials.CredentialsProvider;
import com.cloudbees.plugins.credentials.common.StandardListBoxModel;

import hudson.EnvVars;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Action;
import hudson.model.BuildListener;
import hudson.model.Computer;
import hudson.model.ItemGroup;
import hudson.model.ParameterValue;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Computer;
import hudson.model.ParametersAction;
import hudson.security.ACL;
import hudson.security.AccessControlled;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.BuildStepMonitor;
import hudson.tasks.Builder;
import hudson.util.ListBoxModel;

import java.util.HashMap;
import java.util.Map;

import jenkins.model.Jenkins;

import org.apache.commons.lang.text.StrSubstitutor;
import org.kohsuke.stapler.AncestorInPath;

import rocks.inspectit.releaseplugin.credentials.JIRAProjectCredentials;

import com.cloudbees.plugins.credentials.CredentialsProvider;
import com.cloudbees.plugins.credentials.common.StandardListBoxModel;

/**
*
* Parent class for build steps which need an access to Jira.
Expand All @@ -38,120 +36,109 @@
*/
public abstract class AbstractJIRAAction extends Builder {

/**
* represents an internal id of the chosen credentials to access JIRA.
*/
private String jiraCredentialsID;

/**
* Constructor.
* @param jiraCredentialsID the id of the jira credentials which will be used
*/
public AbstractJIRAAction(String jiraCredentialsID) {
this.jiraCredentialsID = jiraCredentialsID;
}


/**
* @return the ID representing the credentials to access JIRA
*/
public String getJiraCredentialsID() {
return jiraCredentialsID;
}


/**
* Translates the credentialsID into the actual credentials object.
* @return
* the credentials or null if none where chosen.
*/
public JIRAProjectCredentials getJiraCredentials() {
return JIRAProjectCredentials.getByID(jiraCredentialsID);
}




@Override
public Action getProjectAction(AbstractProject<?, ?> project) {
return null;
}

/**
* Returns a StringSubstitutor replacing variables e.g. ${varName} with
* their content.
*
* Considers build parameters AND environment variables, while giving priority to the build parameters.
*
* @param build
* the current build
* @param lis
* the listener of the current build
* @return a string substitutor replacing all variables with their content.
*/
protected StrSubstitutor getVariablesSubstitutor(AbstractBuild<?, ?> build, BuildListener lis) {
ParametersAction params = build.getAction(ParametersAction.class);
Map<String, String> variables = new HashMap<String, String>();
EnvVars env;
try {
env = build.getEnvironment(lis);
} catch (Exception e) {
throw new RuntimeException(e);
}
for (Map.Entry<String, String> en : env.entrySet()) {
variables.put(en.getKey(), en.getValue());
}
if (params != null) {
for (ParameterValue val : params.getParameters()) {
variables.put(val.getName(), val.getValue().toString());
}
}
StrSubstitutor subs = new StrSubstitutor(variables);
return subs;
}

@Override
public BuildStepMonitor getRequiredMonitorService() {
return BuildStepMonitor.BUILD;
}


/**
* The descriptor-class.
*
* @author JKU
*/
public abstract static class DescriptorImpl extends BuildStepDescriptor<Builder> {


@Override
public boolean isApplicable(@SuppressWarnings("rawtypes") Class<? extends AbstractProject> jobType) {
return true;
}


/**
* Method for filling the credentials listbox with the available JIRA credentials.
* @param context the context
* @return a ListBoxModel containing all available credentials.
*/
//the method lookupCredentials is actually not deprecated, it has been replaced with
//a same signature method with a variable number of arguments.
@SuppressWarnings("deprecation")
public ListBoxModel doFillJiraCredentialsIDItems(@AncestorInPath ItemGroup<?> context) {
if (!(context instanceof AccessControlled ? (AccessControlled) context : Jenkins.getInstance()).hasPermission(Computer.CONFIGURE)) {
return new ListBoxModel();
}
return new StandardListBoxModel().withAll(
CredentialsProvider.lookupCredentials(JIRAProjectCredentials.class, context, ACL.SYSTEM));

}

}





/**
* represents an internal id of the chosen credentials to access JIRA.
*/
private String jiraCredentialsID;

/**
* Constructor.
*
* @param jiraCredentialsID the id of the jira credentials which will be used
*/
public AbstractJIRAAction(String jiraCredentialsID) {
this.jiraCredentialsID = jiraCredentialsID;
}

/**
* @return the ID representing the credentials to access JIRA
*/
public String getJiraCredentialsID() {
return jiraCredentialsID;
}

/**
* Translates the credentialsID into the actual credentials object.
*
* @return the credentials or null if none where chosen.
*/
public JIRAProjectCredentials getJiraCredentials() {
return JIRAProjectCredentials.getByID(jiraCredentialsID);
}

@Override
public Action getProjectAction(AbstractProject< ?, ? > project) {
return null;
}

/**
* Returns a StringSubstitutor replacing variables e.g. ${varName} with their content.
*
* Considers build parameters AND environment variables, while giving priority to the build parameters.
*
* @param build the current build
* @param lis the listener of the current build
* @return a string substitutor replacing all variables with their content.
*/
protected StrSubstitutor getVariablesSubstitutor(AbstractBuild< ?, ? > build, BuildListener lis) {
ParametersAction params = build.getAction(ParametersAction.class);
Map< String, String > variables = new HashMap< String, String >();
EnvVars env;
try {
env = build.getEnvironment(lis);
} catch (Exception e) {
throw new RuntimeException(e);
}
for (Map.Entry< String, String > en : env.entrySet()) {
variables.put(en.getKey(), en.getValue());
}
if (params != null) {
for (ParameterValue val : params.getParameters()) {
if (val.getValue() != null) {
variables.put(val.getName(), val.getValue().toString());
}
}
}
StrSubstitutor subs = new StrSubstitutor(variables);
return subs;
}

@Override
public BuildStepMonitor getRequiredMonitorService() {
return BuildStepMonitor.BUILD;
}

/**
* The descriptor-class.
*
* @author JKU
*/
public abstract static class DescriptorImpl extends BuildStepDescriptor< Builder > {

@Override
public boolean isApplicable(@SuppressWarnings("rawtypes") Class< ? extends AbstractProject > jobType) {
return true;
}

/**
* Method for filling the credentials listbox with the available JIRA credentials.
*
* @param context the context
* @return a ListBoxModel containing all available credentials.
*/
// the method lookupCredentials is actually not deprecated, it has been replaced with
// a same signature method with a variable number of arguments.
@SuppressWarnings("deprecation")
public ListBoxModel doFillJiraCredentialsIDItems(@AncestorInPath ItemGroup< ? > context) {
if (!(context instanceof AccessControlled ? (AccessControlled) context : Jenkins.getInstance())
.hasPermission(Computer.CONFIGURE)) {
return new ListBoxModel();
}
return new StandardListBoxModel()
.withAll(CredentialsProvider.lookupCredentials(JIRAProjectCredentials.class, context, ACL.SYSTEM));

}

}

}
Loading