- 创建插件
- 命名插件
- 配置插件
- Condition&Function
package com.polarion.capital.example.conditions; import com.polarion.alm.tracker.model.IWorkItem; import com.polarion.alm.tracker.workflow.IArguments; import com.polarion.alm.tracker.workflow.ICallContext; import com.polarion.alm.tracker.workflow.ICondition; /** * Each implementation of workflow condition has to implement ICondition class. * This condition will simply count number of comments. The workflow condition * will be successful if the method 'passesCondition' will return true. * * @return true if WI has at least 1 comment, or false otherwise * * @author Michal Antolik */ public class ConditionExample implements ICondition { public boolean passesCondition(ICallContext context, IArguments arguments) { IWorkItem wi = context.getWorkItem(); return !wi.getApprovals().isEmpty(); } }
public class FunctionExample implements IFunction { static final private long day = 24 * 3600 * 1000L; static final private long hour = 3600 * 1000L; /* * (non-Javadoc) * * @see com.polarion.alm.tracker.workflow.IFunction#execute(com.polarion.alm.tracker.workflow.ICallContext, * com.polarion.alm.tracker.workflow.IArguments) */ public void execute(ICallContext context, IArguments arguments) { String field = arguments.getAsString("field"); IWorkItem wi = context.getWorkItem(); ICustomField cf = wi.getCustomFieldPrototype(field); if (cf == null) { throw new UserFriendlyRuntimeException( "Invalid action parameter: Specified field doesn't exist."); } IType type = cf.getType(); if (!(type instanceof IPrimitiveType) || !(((IPrimitiveType) type).getTypeName() .equals("java.lang.String"))) { throw new UserFriendlyRuntimeException( "Invalid action parameter: Incorrect field type - expected 'string'"); } long creationDate = wi.getCreated().getTime(); long now = Calendar.getInstance().getTimeInMillis(); long diff = now - creationDate; long days = diff / day; long hours = (diff - days * day) / hour; StringBuffer time = new StringBuffer(); if (days > 0) { time.append(days).append(" days "); } if (hours > 0) { time.append(hours).append(" hours"); } if (time.length() == 0) { time.append("less than 1 hour"); } wi.setCustomField(field, time.toString()); } }
特别注意:<module id="com.polarion.capital.example" version="1.0.0"> id设置为项目名称,此处如果不设置会导致插件无法正常使用。
-
部署插件
部署地址目录结构参考:E:\programs\Polarion_2304\polarion\extensions\README.txt
-
插件使用
插件部署后,重启Polarion服务才可以使用。