Skip to content

Commit

Permalink
CWE-151163:
Browse files Browse the repository at this point in the history
ISPW/Git - Add Build function to ISPW Operations Plugin in Jenkins
https://agile.compuware.com/browse/CWE-151163
  • Loading branch information
zyad-compuware committed Aug 23, 2019
1 parent 7164480 commit edc96a6
Show file tree
Hide file tree
Showing 9 changed files with 549 additions and 3 deletions.
126 changes: 126 additions & 0 deletions src/main/java/com/compuware/ispw/model/rest/BuildResponse.java
@@ -0,0 +1,126 @@
/**
* These materials contain confidential information and trade secrets of Compuware Corporation. You shall maintain the materials
* as confidential and shall not disclose its contents to any third party except as may be required by law or regulation. Use,
* disclosure, or reproduction is prohibited without the prior express written permission of Compuware Corporation.
*
* All Compuware products listed within the materials are trademarks of Compuware Corporation. All other company or product
* names are trademarks of their respective owners.
*
* Copyright (c) 2019 Compuware Corporation. All rights reserved.
*/
package com.compuware.ispw.model.rest;

import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

/**
*
*/
@XmlRootElement(name="build")
@XmlAccessorType(XmlAccessType.NONE)
public class BuildResponse
{
@XmlElement(name = "setId")
private String setId;
@XmlElement(name = "assignmentId")
private String assignmentId;
@XmlElement(name = "message")
private String message;
@XmlElement(name = "url")
private String url;
@XmlElement(name = "tasks")
private List<TaskInfo> tasksBuilt = new ArrayList<>();

/**
* @return the setId
*/
public String getSetId()
{
return setId;
}

/**
* @param setId
* the setId to set
*/
public void setSetId(String setId)
{
this.setId = setId;
}

/**
* @return the assignmentId
*/
public String getAssignmentId()
{
return assignmentId;
}

/**
* @param assignmentId
* the assignmentId to set
*/
public void setAssignmentId(String assignmentId)
{
this.assignmentId = assignmentId;
}

/**
* @return the message
*/
public String getMessage()
{
return message;
}

/**
* @param message the message to set
*/
public void setMessage(String message)
{
this.message = message;
}

/**
* @return the url
*/
public String getUrl()
{
return url;
}

/**
* @param url the url to set
*/
public void setUrl(String url)
{
this.url = url;
}

/**
* @return the tasksBuilt
*/
public List<TaskInfo> getTasksBuilt()
{
return tasksBuilt;
}

public void addTaskBuilt(TaskInfo builtTask)
{
tasksBuilt.add(builtTask);
}

/**
* @param tasksBuilt
* the tasksBuilt to set
*/
public void setTasksBuilt(List<TaskInfo> tasksBuilt)
{
this.tasksBuilt = tasksBuilt;
}

}
11 changes: 11 additions & 0 deletions src/main/java/com/compuware/ispw/restapi/IspwContextPathBean.java
Expand Up @@ -13,6 +13,7 @@
*
*/
public class IspwContextPathBean {
private String application;
private String srid;
private String assignmentId;
private String releaseId;
Expand Down Expand Up @@ -116,4 +117,14 @@ public void setApprover(String approver)
{
this.approver = StringUtils.trimToEmpty(approver).toUpperCase();
}

public String getApplication()
{
return this.application;
}

public void setApplication(String application)
{
this.application = application;
}
}
22 changes: 20 additions & 2 deletions src/main/java/com/compuware/ispw/restapi/IspwRestApiRequest.java
Expand Up @@ -19,6 +19,7 @@
import com.cloudbees.plugins.credentials.common.StandardListBoxModel;
import com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials;
import com.cloudbees.plugins.credentials.domains.URIRequirementBuilder;
import com.compuware.ispw.model.rest.BuildResponse;
import com.compuware.ispw.model.rest.SetInfoResponse;
import com.compuware.ispw.model.rest.TaskResponse;
import com.compuware.ispw.restapi.action.IAction;
Expand Down Expand Up @@ -369,6 +370,13 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
logger.println("...ispwRequestBean=" + ispwRequestBean);

this.url = cesUrl + ispwRequestBean.getContextPath(); // CES URL

// Added for the case within BuildTaskAction where some parameters are not required if other parameters are inputed
if (this.url.contains("?&")) //$NON-NLS-1$
{
this.url = this.url.replace("?&", "?"); //$NON-NLS-1$ //$NON-NLS-2$
}

this.requestBody = ispwRequestBean.getJsonRequest();
this.token = cesIspwToken; // CES TOKEN

Expand Down Expand Up @@ -416,9 +424,19 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen

// polling status if no webhook
if (webhookToken == null && !skipWaitingForSet) {
if (respObject != null && respObject instanceof TaskResponse) {
String setId = StringUtils.EMPTY;
if (respObject instanceof TaskResponse)
{
TaskResponse taskResp = (TaskResponse) respObject;
String setId = taskResp.getSetId();
setId = taskResp.getSetId();
}
else if (respObject instanceof BuildResponse)
{
BuildResponse buildResp = (BuildResponse) respObject;
setId = buildResp.getSetId();
}
if (!setId.equals(StringUtils.EMPTY) && (respObject instanceof TaskResponse || respObject instanceof BuildResponse))
{

HashSet<String> set = new HashSet<String>();

Expand Down
@@ -0,0 +1,65 @@
/**
* These materials contain confidential information and trade secrets of Compuware Corporation. You shall maintain the materials
* as confidential and shall not disclose its contents to any third party except as may be required by law or regulation. Use,
* disclosure, or reproduction is prohibited without the prior express written permission of Compuware Corporation.
*
* All Compuware products listed within the materials are trademarks of Compuware Corporation. All other company or product
* names are trademarks of their respective owners.
*
* Copyright (c) 2019 Compuware Corporation. All rights reserved.
*/
package com.compuware.ispw.restapi.action;

import java.io.PrintStream;
import com.compuware.ispw.model.rest.BuildResponse;
import com.compuware.ispw.restapi.Constants;
import com.compuware.ispw.restapi.IspwContextPathBean;
import com.compuware.ispw.restapi.IspwRequestBean;
import com.compuware.ispw.restapi.JsonProcessor;
import com.compuware.ispw.restapi.WebhookToken;
import com.compuware.ispw.restapi.util.RestApiUtils;

/**
* Action to build an assignment
*/
public class BuildAssignmentAction extends SetInfoPostAction
{
private static final String[] defaultProps = new String[]{assignmentId, level, runtimeConfiguration};

private static final String contextPath = "/ispw/{srid}/assignments/{assignmentId}/tasks/build?level={level}"; //$NON-NLS-1$

public static String getDefaultProps()
{
return RestApiUtils.join(Constants.LINE_SEPARATOR, defaultProps, true);
}

public BuildAssignmentAction(PrintStream logger)
{
super(logger);
}

@Override
public IspwRequestBean getIspwRequestBean(String srid, String ispwRequestBody, WebhookToken webhookToken)
{
return getIspwRequestBean(srid, ispwRequestBody, webhookToken, contextPath);
}

@SuppressWarnings("nls")
@Override
public void startLog(PrintStream logger, IspwContextPathBean ispwContextPathBean, Object jsonObject)
{
logger.println("Building tasks in assignment " + ispwContextPathBean.getAssignmentId() + " at level "
+ ispwContextPathBean.getLevel());
}

@SuppressWarnings("nls")
@Override
public Object endLog(PrintStream logger, IspwRequestBean ispwRequestBean, String responseJson)
{
BuildResponse buildResp = new JsonProcessor().parse(responseJson, BuildResponse.class);
logger.println("Set " + buildResp.getSetId() + " created to build tasks in assignment "
+ ispwRequestBean.getIspwContextPathBean().getAssignmentId());

return buildResp;
}
}
@@ -0,0 +1,65 @@
/**
* These materials contain confidential information and trade secrets of Compuware Corporation. You shall maintain the materials
* as confidential and shall not disclose its contents to any third party except as may be required by law or regulation. Use,
* disclosure, or reproduction is prohibited without the prior express written permission of Compuware Corporation.
*
* All Compuware products listed within the materials are trademarks of Compuware Corporation. All other company or product
* names are trademarks of their respective owners.
*
* Copyright (c) 2019 Compuware Corporation. All rights reserved.
*/
package com.compuware.ispw.restapi.action;

import java.io.PrintStream;
import com.compuware.ispw.model.rest.BuildResponse;
import com.compuware.ispw.restapi.Constants;
import com.compuware.ispw.restapi.IspwContextPathBean;
import com.compuware.ispw.restapi.IspwRequestBean;
import com.compuware.ispw.restapi.JsonProcessor;
import com.compuware.ispw.restapi.WebhookToken;
import com.compuware.ispw.restapi.util.RestApiUtils;

/**
*
*/
public class BuildReleaseAction extends SetInfoPostAction
{
private static final String[] defaultProps = new String[]{releaseId, level, runtimeConfiguration};

private static final String contextPath = "/ispw/{srid}/releases/{releaseId}/tasks/build?level={level}&assignmentId={assignmentId}"; //$NON-NLS-1$

public static String getDefaultProps()
{
return RestApiUtils.join(Constants.LINE_SEPARATOR, defaultProps, true);
}

public BuildReleaseAction(PrintStream logger)
{
super(logger);
}

@Override
public IspwRequestBean getIspwRequestBean(String srid, String ispwRequestBody, WebhookToken webhookToken)
{
return getIspwRequestBean(srid, ispwRequestBody, webhookToken, contextPath);
}

@SuppressWarnings("nls")
@Override
public void startLog(PrintStream logger, IspwContextPathBean ispwContextPathBean, Object jsonObject)
{
logger.println("Building tasks in release " + ispwContextPathBean.getReleaseId() + " at level "
+ ispwContextPathBean.getLevel());
}

@SuppressWarnings("nls")
@Override
public Object endLog(PrintStream logger, IspwRequestBean ispwRequestBean, String responseJson)
{
BuildResponse buildResp = new JsonProcessor().parse(responseJson, BuildResponse.class);
logger.println("Set " + buildResp.getSetId() + " created to build tasks in release "
+ ispwRequestBean.getIspwContextPathBean().getReleaseId());

return buildResp;
}
}

0 comments on commit edc96a6

Please sign in to comment.