All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.plugins.buildstability.ci.hudson.HudsonServer Maven / Gradle / Ivy

There is a newer version: 1.2.1
Show newest version
/*
 * Sonar Build Stability Plugin
 * Copyright (C) 2010 SonarSource
 * [email protected]
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
 */
package org.sonar.plugins.buildstability.ci.hudson;

import org.sonar.plugins.buildstability.ci.api.Build;

import org.apache.commons.lang.StringUtils;
import org.apache.http.impl.client.DefaultHttpClient;
import org.sonar.plugins.buildstability.ci.api.AbstractServer;
import org.sonar.plugins.buildstability.ci.api.Unmarshaller;

import java.io.IOException;

/**
 * See Hudson Remote access API.
 *
 * @author Evgeny Mandrikov
 */
public class HudsonServer extends AbstractServer {
  public static final String SYSTEM = "Hudson";
  public static final String SYSTEM_JENKINS = "Jenkins";
  public static final String PATTERN = "/job/";

  private static final Unmarshaller BUILD_UNMARSHALLER = new HudsonBuildUnmarshaller();

  private boolean useJSecurityCheck;

  @Override
  public String getBuildUrl(String number) {
    return getHost() + "/job/" + getKey() + "/" + number + "/api/xml/";
  }

  @Override
  public String getLastBuildUrl() {
    return getBuildUrl("lastBuild");
  }

  @Override
  public Unmarshaller getBuildUnmarshaller() {
    return BUILD_UNMARSHALLER;
  }

  @Override
  public void doLogin(DefaultHttpClient client) throws IOException {
    if (!isUseJSecurityCheck()) {
      super.doLogin(client);
      return;
    }
    if (!StringUtils.isBlank(getUsername()) && !StringUtils.isBlank(getPassword())) {
      HudsonUtils.doLogin(client, getHost(), getUsername(), getPassword());
    }
  }

  public boolean isUseJSecurityCheck() {
    return useJSecurityCheck;
  }

  public void setUseJSecurityCheck(boolean useJSecurityCheck) {
    this.useJSecurityCheck = useJSecurityCheck;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy