@Override
        public void before() throws Throwable {
          super.before();

          content = new JellyScriptContent();
          listener = StreamTaskListener.fromStdout();

          publisher = new ExtendedEmailPublisher();
          publisher.defaultContent =
              "For only 10 easy payment of $69.99 , AWESOME-O 4000 can be yours!";
          publisher.defaultSubject = "How would you like your very own AWESOME-O 4000?";
          publisher.recipientList = "*****@*****.**";

          Field f = ExtendedEmailPublisherDescriptor.class.getDeclaredField("defaultBody");
          f.setAccessible(true);
          f.set(publisher.getDescriptor(), "Give me $4000 and I'll mail you a check for $40,000!");
          f = ExtendedEmailPublisherDescriptor.class.getDeclaredField("defaultSubject");
          f.setAccessible(true);
          f.set(publisher.getDescriptor(), "Nigerian needs your help!");

          f = ExtendedEmailPublisherDescriptor.class.getDeclaredField("recipientList");
          f.setAccessible(true);
          f.set(publisher.getDescriptor(), "*****@*****.**");

          f = ExtendedEmailPublisherDescriptor.class.getDeclaredField("hudsonUrl");
          f.setAccessible(true);
          f.set(publisher.getDescriptor(), "http://localhost/");

          build = mock(AbstractBuild.class);
          AbstractProject project = mock(AbstractProject.class);
          DescribableList publishers = mock(DescribableList.class);
          when(publishers.get(ExtendedEmailPublisher.class)).thenReturn(publisher);
          when(project.getPublishersList()).thenReturn(publishers);
          when(build.getProject()).thenReturn(project);
        }
    @Override
    public BuildAliasSetter newInstance(final StaplerRequest req, final JSONObject formData)
        throws FormException {

      final DescribableList<AliasProvider, AliasProvider.Descriptor> providers = emptyProviders();
      try {

        providers.rebuildHetero(req, formData, providerKinds(), "providers");
      } catch (final IOException ex) {

        throw new FormException("rebuildHetero failed", ex, "none");
      }

      return new BuildAliasSetter(providers);
    }
 @Override
 public boolean configure(StaplerRequest req, JSONObject json) throws FormException {
   try {
     authenticators.rebuildHetero(
         req, json, QueueItemAuthenticatorDescriptor.all(), "authenticators");
     return true;
   } catch (IOException e) {
     throw new FormException(e, "authenticators");
   }
 }
Пример #4
0
 public void load() {
   XmlFile file = getConfigFile();
   if (file.exists()) {
     try {
       file.unmarshal(this);
     } catch (IOException e) {
       LOGGER.log(Level.WARNING, "Failed to load " + file, e);
     }
   }
   properties.setOwner(this);
   updateTransientActions();
 }
  private LinkedHashSet<String> aliases(
      final AbstractBuild<?, ?> build, final BuildListener listener)
      throws IOException, InterruptedException {

    final LinkedHashSet<String> aliases = new LinkedHashSet<String>(providers.size());
    for (final AliasProvider provider : providers) {

      final List<String> names = provider.names(build, listener);
      aliases.addAll(names);
    }

    return filterAliases(aliases, listener);
  }
Пример #6
0
 /**
  * Gets the view properties configured for this view.
  *
  * @since 1.406
  */
 public DescribableList<ViewProperty, ViewPropertyDescriptor> getProperties() {
   // readResolve was the best place to do this, but for compatibility reasons,
   // this class can no longer have readResolve() (the mechanism itself isn't suitable for class
   // hierarchy)
   // see JENKINS-9431
   //
   // until we have that, putting this logic here.
   synchronized (PropertyList.class) {
     if (properties == null) {
       properties = new PropertyList(this);
     } else {
       properties.setOwner(this);
     }
     return properties;
   }
 }
Пример #7
0
  /** Accepts the update to the node configuration. */
  @RequirePOST
  public void doConfigSubmit(StaplerRequest req, StaplerResponse rsp)
      throws IOException, ServletException, FormException {
    final Jenkins app = Jenkins.getInstance();

    app.checkPermission(Jenkins.ADMINISTER);

    properties.rebuild(req, req.getSubmittedForm(), getApplicablePropertyDescriptors());

    this.description = req.getSubmittedForm().getString("description");

    updateTransientActions();
    save();

    FormApply.success(".").generateResponse(req, rsp, null);
  }
 private Object readResolve() {
   authenticators.setOwner(this);
   return this;
 }
  /** {@inheritDoc} */
  @SuppressWarnings("unchecked")
  public HealthReport getBuildHealth() {
    if (health != null) {
      return health;
    }
    // try to get targets from root project (for maven modules targets are null)
    DescribableList rootpublishers = owner.getProject().getRootProject().getPublishersList();

    if (rootpublishers != null) {
      CoberturaPublisher publisher =
          (CoberturaPublisher) rootpublishers.get(CoberturaPublisher.class);
      if (publisher != null) {
        healthyTarget = publisher.getHealthyTarget();
        unhealthyTarget = publisher.getUnhealthyTarget();
      }
    }

    if (healthyTarget == null || unhealthyTarget == null) {
      return null;
    }

    if (result == null) {
      CoverageResult projectCoverage = getResult();
      result = new EnumMap<CoverageMetric, Ratio>(CoverageMetric.class);
      result.putAll(projectCoverage.getResults());
    }
    Map<CoverageMetric, Integer> scores = healthyTarget.getRangeScores(unhealthyTarget, result);
    int minValue = 100;
    CoverageMetric minKey = null;
    for (Map.Entry<CoverageMetric, Integer> e : scores.entrySet()) {
      if (e.getValue() < minValue) {
        minKey = e.getKey();
        minValue = e.getValue();
      }
    }
    if (minKey == null) {
      if (result == null || result.size() == 0) {
        return null;
      } else {
        for (Map.Entry<CoverageMetric, Integer> e : scores.entrySet()) {
          minKey = e.getKey();
        }
        if (minKey != null) {
          Localizable localizedDescription =
              Messages._CoberturaBuildAction_description(
                  result.get(minKey).getPercentage(),
                  result.get(minKey).toString(),
                  minKey.getName());
          health = new HealthReport(minValue, localizedDescription);
          return health;
        }
        return null;
      }

    } else {
      Localizable localizedDescription =
          Messages._CoberturaBuildAction_description(
              result.get(minKey).getPercentage(), result.get(minKey).toString(), minKey.getName());
      health = new HealthReport(minValue, localizedDescription);
      return health;
    }
  }
Пример #10
0
 @Exported
 public List<LabelAtomProperty> getPropertiesList() {
   return properties.toList();
 }