@SuppressWarnings("unchecked")
 protected boolean matchesDefaultValue(Job job) {
   ParametersDefinitionProperty property =
       (ParametersDefinitionProperty) job.getProperty(ParametersDefinitionProperty.class);
   if (property != null) {
     List<ParameterDefinition> defs = property.getParameterDefinitions();
     for (ParameterDefinition def : defs) {
       boolean multiline = isValueMultiline(def);
       String svalue = getStringValue(def);
       boolean matches = matchesParameter(def.getName(), svalue, multiline, def.getDescription());
       if (matches) {
         return true;
       }
     }
   }
   return false;
 }
Ejemplo n.º 2
0
  /*
   * Convert an individual Hudson parameter definition to an OSLC Property.
   */
  private Property toProperty(StaplerRequest request, ParameterDefinition def)
      throws URISyntaxException {
    Property prop = new Property();
    prop.setName(def.getName());
    prop.setDescription(def.getDescription());

    if (def instanceof BooleanParameterDefinition) {
      prop.setValueType(new URI(XSDDatatype.XSDboolean.getURI()));
    } else if (def instanceof StringParameterDefinition
        || def instanceof PasswordParameterDefinition) {
      prop.setValueType(new URI(XSDDatatype.XSDstring.getURI()));
    } else if (def instanceof ChoiceParameterDefinition) {
      prop.setValueType(new URI(XSDDatatype.XSDstring.getURI()));
      ChoiceParameterDefinition choices = (ChoiceParameterDefinition) def;
      prop.setAllowedValuesCollection(choices.getChoices());
    }
    // TODO: Other types?

    ParameterValue defaultValue = def.getDefaultParameterValue();
    if (defaultValue == null) {
      prop.setOccurs(Occurs.ExactlyOne);
    } else {
      prop.setOccurs(Occurs.ZeroOrOne);
      if (!defaultValue.isSensitive()) {
        if (defaultValue instanceof BooleanParameterValue) {
          BooleanParameterValue bool = (BooleanParameterValue) defaultValue;
          prop.setDefaultValue(bool.value);
        } else if (defaultValue instanceof StringParameterValue) {
          StringParameterValue str = (StringParameterValue) defaultValue;
          prop.setDefaultValue(str.value);
        }
        // TODO: Other types?
      }
    }

    return prop;
  }