org.eclipse.mylyn.hudson.core_0.9.1.v20120425-0100

16:46:42.807 INFO  jd.cli.Main - Decompiling org.eclipse.mylyn.hudson.core_0.9.1.v20120425-0100.jar
package org.eclipse.mylyn.hudson.core;

import java.io.File;
import org.eclipse.mylyn.builds.core.spi.BuildConnector;
import org.eclipse.mylyn.internal.hudson.core.HudsonConnector;

public class HudsonCore
{
  public static BuildConnector createConnector(File cacheFile)
  {
    return new HudsonConnector(cacheFile);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.hudson.core.HudsonCore
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.hudson.core;

import java.io.Reader;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.EnumSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.mylyn.builds.core.BuildState;
import org.eclipse.mylyn.builds.core.BuildStatus;
import org.eclipse.mylyn.builds.core.EditType;
import org.eclipse.mylyn.builds.core.IArtifact;
import org.eclipse.mylyn.builds.core.IBooleanParameterDefinition;
import org.eclipse.mylyn.builds.core.IBuild;
import org.eclipse.mylyn.builds.core.IBuildCause;
import org.eclipse.mylyn.builds.core.IBuildFactory;
import org.eclipse.mylyn.builds.core.IBuildParameterDefinition;
import org.eclipse.mylyn.builds.core.IBuildPlan;
import org.eclipse.mylyn.builds.core.IBuildReference;
import org.eclipse.mylyn.builds.core.IChange;
import org.eclipse.mylyn.builds.core.IChangeArtifact;
import org.eclipse.mylyn.builds.core.IChangeSet;
import org.eclipse.mylyn.builds.core.IChoiceParameterDefinition;
import org.eclipse.mylyn.builds.core.IFileParameterDefinition;
import org.eclipse.mylyn.builds.core.IHealthReport;
import org.eclipse.mylyn.builds.core.IParameterDefinition;
import org.eclipse.mylyn.builds.core.IPasswordParameterDefinition;
import org.eclipse.mylyn.builds.core.IStringParameterDefinition;
import org.eclipse.mylyn.builds.core.ITestCase;
import org.eclipse.mylyn.builds.core.ITestResult;
import org.eclipse.mylyn.builds.core.ITestSuite;
import org.eclipse.mylyn.builds.core.IUser;
import org.eclipse.mylyn.builds.core.TestCaseResult;
import org.eclipse.mylyn.builds.core.spi.BuildPlanRequest;
import org.eclipse.mylyn.builds.core.spi.BuildServerBehaviour;
import org.eclipse.mylyn.builds.core.spi.BuildServerConfiguration;
import org.eclipse.mylyn.builds.core.spi.GetBuildsRequest;
import org.eclipse.mylyn.builds.core.spi.GetBuildsRequest.Kind;
import org.eclipse.mylyn.builds.core.spi.GetBuildsRequest.Scope;
import org.eclipse.mylyn.builds.core.spi.RunBuildRequest;
import org.eclipse.mylyn.builds.internal.core.BuildFactory;
import org.eclipse.mylyn.commons.core.operations.IOperationMonitor;
import org.eclipse.mylyn.commons.repositories.core.RepositoryLocation;
import org.eclipse.mylyn.internal.hudson.core.client.HudsonConfiguration;
import org.eclipse.mylyn.internal.hudson.core.client.HudsonConfigurationCache;
import org.eclipse.mylyn.internal.hudson.core.client.HudsonException;
import org.eclipse.mylyn.internal.hudson.core.client.HudsonResourceNotFoundException;
import org.eclipse.mylyn.internal.hudson.core.client.HudsonServerInfo;
import org.eclipse.mylyn.internal.hudson.core.client.HudsonTestReport;
import org.eclipse.mylyn.internal.hudson.core.client.RestfulHudsonClient;
import org.eclipse.mylyn.internal.hudson.core.client.RestfulHudsonClient.BuildId;
import org.eclipse.mylyn.internal.hudson.model.HudsonModelAbstractBuild;
import org.eclipse.mylyn.internal.hudson.model.HudsonModelBallColor;
import org.eclipse.mylyn.internal.hudson.model.HudsonModelBuild;
import org.eclipse.mylyn.internal.hudson.model.HudsonModelHealthReport;
import org.eclipse.mylyn.internal.hudson.model.HudsonModelJob;
import org.eclipse.mylyn.internal.hudson.model.HudsonModelRun;
import org.eclipse.mylyn.internal.hudson.model.HudsonModelRunArtifact;
import org.eclipse.mylyn.internal.hudson.model.HudsonModelUser;
import org.eclipse.mylyn.internal.hudson.model.HudsonScmChangeLogSet;
import org.eclipse.mylyn.internal.hudson.model.HudsonTasksJunitCaseResult;
import org.eclipse.mylyn.internal.hudson.model.HudsonTasksJunitSuiteResult;
import org.eclipse.mylyn.internal.hudson.model.HudsonTasksJunitTestResult;
import org.eclipse.mylyn.internal.hudson.model.HudsonTasksTestAggregatedTestResultAction;
import org.eclipse.mylyn.internal.hudson.model.HudsonTasksTestAggregatedTestResultActionChildReport;
import org.eclipse.osgi.util.NLS;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class HudsonServerBehaviour
  extends BuildServerBehaviour
{
  private final RestfulHudsonClient client;
  private final RepositoryLocation location;
  
  public HudsonServerBehaviour(RepositoryLocation location, HudsonConfigurationCache cache)
  {
    this.location = location;
    client = new RestfulHudsonClient(location, cache);
  }
  
  public RepositoryLocation getLocation()
  {
    return location;
  }
  
  protected HudsonModelBuild createBuildParameter(IBuild build)
  {
    HudsonModelBuild hudsonBuild = new HudsonModelBuild();
    hudsonBuild.setNumber(build.getBuildNumber());
    return hudsonBuild;
  }
  
  protected HudsonModelJob createJobParameter(IBuildPlan plan)
  {
    HudsonModelJob job = new HudsonModelJob();
    job.setName(plan.getId());
    return job;
  }
  
  public List<IBuild> getBuilds(GetBuildsRequest request, IOperationMonitor monitor)
    throws CoreException
  {
    try
    {
      HudsonTestReport hudsonTestReport;
      if ((request.getKind() == GetBuildsRequest.Kind.LAST) || (request.getKind() == GetBuildsRequest.Kind.SELECTED))
      {
        HudsonModelJob job = createJobParameter(request.getPlan());
        HudsonModelBuild requestBuild;
        HudsonModelBuild requestBuild;
        if (request.getKind() == GetBuildsRequest.Kind.LAST)
        {
          requestBuild = RestfulHudsonClient.BuildId.LAST.getBuild();
        }
        else
        {
          requestBuild = new HudsonModelBuild();
          requestBuild.setNumber(Integer.parseInt((String)request.getIds().iterator().next()));
        }
        HudsonModelBuild hudsonBuild = client.getBuild(job, requestBuild, monitor);
        IBuild build = parseBuild(job, hudsonBuild);
        try
        {
          hudsonTestReport = client.getTestReport(job, hudsonBuild, monitor);
          ITestResult testResult;
          ITestResult testResult;
          if (hudsonTestReport.getJunitResult() != null) {
            testResult = parseTestResult(hudsonTestReport.getJunitResult());
          } else {
            testResult = parseTestResult(hudsonTestReport.getAggregatedResult());
          }
          testResult.setBuild(build);
          build.setTestResult(testResult);
        }
        catch (HudsonResourceNotFoundException localHudsonResourceNotFoundException1) {}
        return Collections.singletonList(build);
      }
      if ((request.getKind() == GetBuildsRequest.Kind.ALL) && (request.getScope() == GetBuildsRequest.Scope.HISTORY))
      {
        HudsonModelJob job = createJobParameter(request.getPlan());
        List<HudsonModelRun> hudsonBuilds = client.getBuilds(job, monitor);
        ArrayList<IBuild> builds = new ArrayList(hudsonBuilds.size());
        for (HudsonModelRun hudsonBuild : hudsonBuilds) {
          builds.add(parseBuild(job, hudsonBuild));
        }
        return builds;
      }
    }
    catch (HudsonResourceNotFoundException localHudsonResourceNotFoundException2)
    {
      return null;
    }
    catch (HudsonException e)
    {
      throw HudsonCorePlugin.toCoreException(e);
    }
    throw new UnsupportedOperationException("Unsupported request kind and scope combination: kind=" + 
      request.getKind() + ",scope=" + request.getScope());
  }
  
  public BuildServerConfiguration getConfiguration()
  {
    Map<String, String> jobNameById = client.getConfiguration().jobNameById;
    List<IBuildPlan> plans = new ArrayList(jobNameById.size());
    for (Map.Entry<String, String> entry : jobNameById.entrySet())
    {
      IBuildPlan plan = createBuildPlan();
      plan.setId((String)entry.getKey());
      plan.setName((String)entry.getValue());
      plans.add(plan);
    }
    return new BuildServerConfiguration(plans);
  }
  
  public Reader getConsole(IBuild build, IOperationMonitor monitor)
    throws CoreException
  {
    try
    {
      HudsonModelJob job = createJobParameter(build.getPlan());
      HudsonModelBuild hudsonBuild = createBuildParameter(build);
      return client.getConsole(job, hudsonBuild, monitor);
    }
    catch (HudsonException e)
    {
      throw HudsonCorePlugin.toCoreException(e);
    }
  }
  
  private String getDefaultValue(Element element)
    throws HudsonException
  {
    String value = getElementContent(element, "defaultValue", false);
    if (value != null) {
      return value;
    }
    NodeList nodes = element.getElementsByTagName("defaultParameterValue");
    if (nodes.getLength() == 1)
    {
      NodeList children = nodes.item(0).getChildNodes();
      for (int i = 0; i < children.getLength(); i++)
      {
        Element child = (Element)children.item(i);
        String tagName = child.getTagName();
        if ("value".equals(tagName)) {
          return child.getTextContent();
        }
      }
    }
    return null;
  }
  
  private String getElementContent(Element element, String name, boolean required)
    throws HudsonException
  {
    NodeList elements = element.getElementsByTagName(name);
    if (elements.getLength() == 0)
    {
      if (required) {
        throw new HudsonException("No " + name + " element");
      }
      return null;
    }
    if (elements.getLength() > 1) {
      throw new HudsonException("More than one " + name + " element");
    }
    return ((Element)elements.item(0)).getTextContent();
  }
  
  public List<IBuildPlan> getPlans(BuildPlanRequest request, IOperationMonitor monitor)
    throws CoreException
  {
    try
    {
      List<HudsonModelJob> jobs = client.getJobs(request.getPlanIds(), monitor);
      List<IBuildPlan> plans = new ArrayList(jobs.size());
      for (HudsonModelJob job : jobs)
      {
        IBuildPlan plan = parseJob(job);
        plans.add(plan);
      }
      return plans;
    }
    catch (HudsonException e)
    {
      throw HudsonCorePlugin.toCoreException(e);
    }
  }
  
  private IArtifact parseArtifact(HudsonModelRunArtifact hudsonArtifact)
  {
    IArtifact artifact = createArtifact();
    artifact.setName(hudsonArtifact.getFileName());
    artifact.setRelativePath(hudsonArtifact.getRelativePath());
    return artifact;
  }
  
  private IBuild parseBuild(HudsonModelJob hudsonJob, HudsonModelRun hudsonBuild)
  {
    IBuild build = createBuild();
    build.setId(hudsonBuild.getId());
    build.setName(hudsonBuild.getFullDisplayName());
    build.setBuildNumber(hudsonBuild.getNumber());
    build.setLabel(hudsonBuild.getNumber());
    build.setDuration(hudsonBuild.getDuration());
    build.setTimestamp(hudsonBuild.getTimestamp().longValue());
    build.setUrl(hudsonBuild.getUrl());
    build.setState(hudsonBuild.isBuilding() ? BuildState.RUNNING : BuildState.STOPPED);
    build.setStatus(parseResult((Node)hudsonBuild.getResult()));
    build.setSummary(parseActions(build.getCause(), hudsonBuild.getAction()));
    if ((hudsonBuild instanceof HudsonModelAbstractBuild)) {
      for (HudsonModelUser hudsonUser : ((HudsonModelAbstractBuild)hudsonBuild).getCulprit()) {
        build.getCulprits().add(parseUser(hudsonUser));
      }
    }
    for (HudsonModelRunArtifact hudsonArtifact : hudsonBuild.getArtifact())
    {
      IArtifact artifact = parseArtifact(hudsonArtifact);
      try
      {
        artifact.setUrl(client.getArtifactUrl(hudsonJob, hudsonBuild, hudsonArtifact));
      }
      catch (HudsonException localHudsonException) {}
      build.getArtifacts().add(artifact);
    }
    if ((hudsonBuild instanceof HudsonModelAbstractBuild)) {
      build.setChangeSet(parseChangeSet(((HudsonModelAbstractBuild)hudsonBuild).getChangeSet()));
    }
    return build;
  }
  
  private String parseActions(List<IBuildCause> causes, List<Object> actions)
  {
    int failCount = 0;
    int skipCount = 0;
    int totalCount = 0;
    Set<String> causeDescriptions = new LinkedHashSet();
    Node node;
    NodeList children;
    int i;
    for (Iterator localIterator = actions.iterator(); localIterator.hasNext(); i < children.getLength())
    {
      Object action = localIterator.next();
      node = (Node)action;
      children = node.getChildNodes();
      i = 0; continue;
      Element child = (Element)children.item(i);
      String tagName = child.getTagName();
      try
      {
        if ("cause".equals(tagName))
        {
          IBuildCause cause = parseCause(child);
          causes.add(cause);
          if (cause.getDescription() != null) {
            causeDescriptions.add(cause.getDescription());
          }
        }
        else if ("failCount".equals(tagName))
        {
          failCount = Integer.parseInt(child.getTextContent());
        }
        else if ("skipCount".equals(tagName))
        {
          skipCount = Integer.parseInt(child.getTextContent());
        }
        else if ("totalCount".equals(tagName))
        {
          totalCount = Integer.parseInt(child.getTextContent());
        }
      }
      catch (NumberFormatException localNumberFormatException) {}
      i++;
    }
    StringBuilder sb = new StringBuilder();
    for (String string : causeDescriptions) {
      append(sb, string);
    }
    if ((failCount != 0) || (totalCount != 0) || (skipCount != 0)) {
      append(sb, 
        NLS.bind("{0} tests: {1} failed, {2} skipped", new Object[] { Integer.valueOf(totalCount), Integer.valueOf(failCount), Integer.valueOf(skipCount) }));
    }
    if (sb.length() > 0) {
      return sb.toString();
    }
    return null;
  }
  
  private void append(StringBuilder sb, String text)
  {
    if (text != null)
    {
      if (sb.length() > 0) {
        sb.append(", ");
      }
      sb.append(text);
    }
  }
  
  private IBuildCause parseCause(Node node)
  {
    IBuildCause cause = createBuildCause();
    String userName = null;
    String upstreamBuild = null;
    String upstreamProject = null;
    NodeList children = node.getChildNodes();
    for (int i = 0; i < children.getLength(); i++)
    {
      Element child = (Element)children.item(i);
      String tagName = child.getTagName();
      if ("shortDescription".equals(tagName)) {
        cause.setDescription(child.getTextContent());
      } else if ("userName".equals(tagName)) {
        userName = child.getTextContent();
      } else if ("upstreamProject".equals(tagName)) {
        upstreamProject = child.getTextContent();
      } else if ("upstreamBuild".equals(tagName)) {
        upstreamBuild = child.getTextContent();
      }
    }
    if (userName != null)
    {
      IUser user = createUser();
      user.setId(userName);
      cause.setUser(user);
    }
    if ((upstreamProject != null) && (upstreamBuild != null))
    {
      IBuildReference reference = createBuildReference();
      reference.setPlan(upstreamProject);
      reference.setBuild(upstreamBuild);
      cause.setBuild(reference);
    }
    return cause;
  }
  
  private IChange parseChange(Node node)
  {
    IChange change = createChange();
    NodeList children = node.getChildNodes();
    for (int i = 0; i < children.getLength(); i++)
    {
      Element child = (Element)children.item(i);
      String tagName = child.getTagName();
      if ("addedPath".equals(tagName))
      {
        IChangeArtifact artifact = createChangeArtifact();
        artifact.setFile(child.getTextContent());
        artifact.setEditType(EditType.ADD);
        change.getArtifacts().add(artifact);
      }
      else if ("author".equals(tagName))
      {
        change.setAuthor(parseUser(child));
      }
      else if ("comment".equals(tagName))
      {
        change.setMessage(child.getTextContent());
      }
      else if ("date".equals(tagName))
      {
        change.setDate(parseDate(child));
      }
      else if ("file".equals(tagName))
      {
        change.getArtifacts().add(parseArtifact(child));
      }
      else if ("id".equals(tagName))
      {
        change.setRevision(child.getTextContent());
      }
      else if ("modifiedPath".equals(tagName))
      {
        IChangeArtifact artifact = createChangeArtifact();
        artifact.setFile(child.getTextContent());
        artifact.setEditType(EditType.EDIT);
        change.getArtifacts().add(artifact);
      }
      else if ("msg".equals(tagName))
      {
        if (change.getMessage() == null) {
          change.setMessage(child.getTextContent());
        }
      }
      else if ("node".equals(tagName))
      {
        change.setRevision(child.getTextContent());
      }
      else if ("rev".equals(tagName))
      {
        change.setRevision(child.getTextContent());
      }
      else if ("path".equals(tagName))
      {
        change.getArtifacts().add(parseArtifact(child));
      }
      else if ("revision".equals(tagName))
      {
        change.setRevision(child.getTextContent());
      }
      else if (("user".equals(tagName)) && (change.getAuthor() == null))
      {
        IUser user = createUser();
        user.setId(child.getTextContent());
        change.setAuthor(user);
      }
    }
    return change;
  }
  
  private IUser parseUser(Node node)
  {
    if (node != null)
    {
      IUser user = createUser();
      NodeList children = node.getChildNodes();
      for (int i = 0; i < children.getLength(); i++)
      {
        Element child = (Element)children.item(i);
        String tagName = child.getTagName();
        if ("absoluteUrl".equals(tagName))
        {
          user.setUrl(child.getTextContent());
        }
        else if ("fullName".equals(tagName))
        {
          user.setName(child.getTextContent());
          user.setId(child.getTextContent());
        }
      }
      return user;
    }
    return null;
  }
  
  private IChangeArtifact parseArtifact(Node node)
  {
    IChangeArtifact artifact = createChangeArtifact();
    NodeList children = node.getChildNodes();
    for (int i = 0; i < children.getLength(); i++)
    {
      Element child = (Element)children.item(i);
      String tagName = child.getTagName();
      if ("editType".equals(tagName)) {
        artifact.setEditType(parseEditType(child));
      } else if ("file".equals(tagName)) {
        artifact.setFile(child.getTextContent());
      } else if ("fullName".equals(tagName)) {
        artifact.setFile(child.getTextContent());
      } else if ("prevrevision".equals(tagName)) {
        artifact.setPrevRevision(child.getTextContent());
      } else if ("revision".equals(tagName)) {
        artifact.setRevision(child.getTextContent());
      }
    }
    return artifact;
  }
  
  private EditType parseEditType(Element node)
  {
    if (node != null)
    {
      String text = node.getTextContent();
      if ("add".equals(text)) {
        return EditType.ADD;
      }
      if ("edit".equals(text)) {
        return EditType.EDIT;
      }
      if ("delete".equals(text)) {
        return EditType.DELETE;
      }
    }
    return null;
  }
  
  private long parseDate(Element node)
  {
    if (node != null)
    {
      String[] patterns = {
        "yyyy-MM-dd", 
        "yyyy-MM-dd HH:mm:ss Z", 
        
        "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" };
      
      String text = node.getTextContent();
      String[] arrayOfString1;
      int j = (arrayOfString1 = patterns).length;
      for (int i = 0; i < j; i++)
      {
        String pattern = arrayOfString1[i];
        try
        {
          return new SimpleDateFormat(pattern).parse(text).getTime();
        }
        catch (ParseException localParseException) {}
      }
    }
    return 0L;
  }
  
  private IChangeSet parseChangeSet(HudsonScmChangeLogSet hudsonChangeSet)
  {
    IChangeSet changeSet = createChangeSet();
    
    changeSet.setKind(hudsonChangeSet.getKind());
    for (Object item : hudsonChangeSet.getItem()) {
      changeSet.getChanges().add(parseChange((Node)item));
    }
    return changeSet;
  }
  
  private long parseDuration(Node node)
  {
    if (node != null)
    {
      String text = node.getTextContent();
      try
      {
        return (Double.parseDouble(text) * 1000.0D);
      }
      catch (NumberFormatException localNumberFormatException) {}
    }
    return -1L;
  }
  
  private IHealthReport parseHealthReport(HudsonModelHealthReport hudsonHealthReport)
  {
    IHealthReport healthReport = createHealthReport();
    healthReport.setHealth(hudsonHealthReport.getScore());
    healthReport.setDescription(hudsonHealthReport.getDescription());
    return healthReport;
  }
  
  public IBuildPlan parseJob(HudsonModelJob job)
  {
    IBuildPlan plan = createBuildPlan();
    plan.setId(job.getName());
    if ((job.getDisplayName() != null) && (job.getDisplayName().length() > 0)) {
      plan.setName(job.getDisplayName());
    } else {
      plan.setName(job.getName());
    }
    plan.setDescription(job.getDescription());
    plan.setUrl(job.getUrl());
    updateStateAndStatus(job, plan);
    updateHealth(job, plan);
    if (job.getLastBuild() != null)
    {
      IBuild build = createBuild();
      build.setId(job.getLastBuild().getNumber());
      build.setLabel(job.getLastBuild().getNumber());
      build.setBuildNumber(job.getLastBuild().getNumber());
      build.setUrl(job.getLastBuild().getUrl());
      plan.setLastBuild(build);
    }
    parseJobActions(plan.getParameterDefinitions(), job.getAction());
    
    return plan;
  }
  
  private void parseJobActions(List<IParameterDefinition> parameterDefinitions, List<Object> actions)
  {
    NodeList children;
    int i;
    for (Iterator localIterator = actions.iterator(); localIterator.hasNext(); i < children.getLength())
    {
      Object action = localIterator.next();
      Node node = (Node)action;
      children = node.getChildNodes();
      i = 0; continue;
      Element child = (Element)children.item(i);
      String tagName = child.getTagName();
      if ("parameterDefinition".equals(tagName)) {
        try
        {
          IParameterDefinition parameterDefinition = parseParameter(child);
          parameterDefinitions.add(parameterDefinition);
        }
        catch (HudsonException localHudsonException) {}
      }
      i++;
    }
  }
  
  private IParameterDefinition parseParameter(Element element)
    throws HudsonException
  {
    String tagName = element.getTagName();
    if (("hudson.model.ChoiceParameterDefinition".equals(tagName)) || ("ChoiceParameterDefinition".equals(getElementContent(element, "type", false))))
    {
      IChoiceParameterDefinition definition = BuildFactory.eINSTANCE.createChoiceParameterDefinition();
      definition.setName(getElementContent(element, "name", true));
      definition.setDescription(getElementContent(element, "description", false));
      
      NodeList options = element.getElementsByTagName("string");
      for (int i = 0; i < options.getLength(); i++)
      {
        Element option = (Element)options.item(i);
        definition.getOptions().add(option.getTextContent());
      }
      options = element.getElementsByTagName("choice");
      for (int i = 0; i < options.getLength(); i++)
      {
        Element option = (Element)options.item(i);
        definition.getOptions().add(option.getTextContent());
      }
      definition.setDefaultValue(getDefaultValue(element));
      return definition;
    }
    if (("hudson.model.BooleanParameterDefinition".equals(tagName)) || ("BooleanParameterDefinition".equals(getElementContent(element, "type", false))))
    {
      IBooleanParameterDefinition definition = IBuildFactory.INSTANCE.createBooleanParameterDefinition();
      definition.setName(getElementContent(element, "name", true));
      definition.setDescription(getElementContent(element, "description", false));
      String defaultValue = getDefaultValue(element);
      if (defaultValue != null) {
        definition.setDefaultValue(Boolean.parseBoolean(defaultValue));
      }
      return definition;
    }
    if (("hudson.model.StringParameterDefinition".equals(tagName)) || ("StringParameterDefinition".equals(getElementContent(element, "type", false))))
    {
      IStringParameterDefinition definition = IBuildFactory.INSTANCE.createStringParameterDefinition();
      definition.setName(getElementContent(element, "name", true));
      definition.setDescription(getElementContent(element, "description", false));
      definition.setDefaultValue(getDefaultValue(element));
      return definition;
    }
    if (("hudson.model.PasswordParameterDefinition".equals(tagName)) || ("PasswordParameterDefinition".equals(getElementContent(element, "type", false))))
    {
      IPasswordParameterDefinition definition = IBuildFactory.INSTANCE.createPasswordParameterDefinition();
      definition.setName(getElementContent(element, "name", true));
      definition.setDescription(getElementContent(element, "description", false));
      definition.setDefaultValue(getDefaultValue(element));
      return definition;
    }
    if (("hudson.model.RunParameterDefinition".equals(tagName)) || ("RunParameterDefinition".equals(getElementContent(element, "type", false))))
    {
      IBuildParameterDefinition definition = IBuildFactory.INSTANCE.createBuildParameterDefinition();
      definition.setName(getElementContent(element, "name", true));
      definition.setDescription(getElementContent(element, "description", false));
      definition.setBuildPlanId(getElementContent(element, "projectName", false));
      return definition;
    }
    if (("hudson.model.FileParameterDefinition".equals(tagName)) || ("FileParameterDefinition".equals(getElementContent(element, "type", false))))
    {
      IFileParameterDefinition definition = IBuildFactory.INSTANCE.createFileParameterDefinition();
      definition.setName(getElementContent(element, "name", true));
      definition.setDescription(getElementContent(element, "description", false));
      return definition;
    }
    throw new HudsonException(NLS.bind("Unexpected parameter ''{0}'' with type ''{1}''", tagName, 
      getElementContent(element, "type", false)));
  }
  
  private BuildStatus parseResult(Node node)
  {
    if (node != null)
    {
      String text = node.getTextContent();
      if ("FAILURE".equals(text)) {
        return BuildStatus.FAILED;
      }
      try
      {
        return BuildStatus.valueOf(text);
      }
      catch (IllegalArgumentException localIllegalArgumentException) {}
    }
    return null;
  }
  
  private ITestResult parseTestResult(HudsonTasksJunitTestResult hudsonTestReport)
  {
    ITestResult testResult = createTestResult();
    testResult.setFailCount(hudsonTestReport.getFailCount());
    testResult.setIgnoredCount(hudsonTestReport.getSkipCount());
    testResult.setPassCount(hudsonTestReport.getPassCount());
    testResult.setDuration(parseDuration((Node)hudsonTestReport.getDuration()));
    for (HudsonTasksJunitSuiteResult hudsonSuite : hudsonTestReport.getSuite())
    {
      ITestSuite testSuite = createTestSuite();
      testSuite.setLabel(hudsonSuite.getName());
      testSuite.setDuration(parseDuration((Node)hudsonSuite.getDuration()));
      testSuite.setOutput(hudsonSuite.getStdout());
      testSuite.setErrorOutput(hudsonSuite.getStderr());
      for (HudsonTasksJunitCaseResult hudsonCase : hudsonSuite.getCase())
      {
        ITestCase testCase = createTestCase();
        testCase.setLabel(hudsonCase.getName());
        testCase.setClassName(hudsonCase.getClassName());
        testCase.setDuration(parseDuration((Node)hudsonCase.getDuration()));
        testCase.setSkipped(hudsonCase.isSkipped());
        
        testCase.setMessage(hudsonCase.getErrorDetails());
        testCase.setStackTrace(hudsonCase.getErrorStackTrace());
        switch (hudsonCase.getStatus())
        {
        case FAILED: 
          testCase.setStatus(TestCaseResult.PASSED);
          break;
        case FIXED: 
          testCase.setStatus(TestCaseResult.SKIPPED);
          break;
        case PASSED: 
          testCase.setStatus(TestCaseResult.FAILED);
          break;
        case REGRESSION: 
          testCase.setStatus(TestCaseResult.FIXED);
          break;
        case SKIPPED: 
          testCase.setStatus(TestCaseResult.REGRESSION);
        }
        testCase.setSuite(testSuite);
      }
      testSuite.setResult(testResult);
    }
    return testResult;
  }
  
  private ITestResult parseTestResult(HudsonTasksTestAggregatedTestResultAction hudsonTestReport)
  {
    ITestResult testResult = createTestResult();
    testResult.setFailCount(hudsonTestReport.getFailCount());
    testResult.setIgnoredCount(hudsonTestReport.getSkipCount());
    testResult.setPassCount(hudsonTestReport.getTotalCount() - hudsonTestReport.getFailCount() - 
      hudsonTestReport.getSkipCount());
    for (HudsonTasksTestAggregatedTestResultActionChildReport child : hudsonTestReport.getChildReport())
    {
      ITestResult childResult = parseTestResult((HudsonTasksJunitTestResult)child.getResult());
      testResult.getSuites().addAll(childResult.getSuites());
    }
    return testResult;
  }
  
  private IUser parseUser(HudsonModelUser hudsonUser)
  {
    IUser user = createUser();
    user.setId(hudsonUser.getId());
    user.setName(hudsonUser.getFullName());
    user.setUrl(hudsonUser.getAbsoluteUrl());
    return user;
  }
  
  public BuildServerConfiguration refreshConfiguration(IOperationMonitor monitor)
    throws CoreException
  {
    try
    {
      client.getJobs(null, monitor);
    }
    catch (HudsonException e)
    {
      throw HudsonCorePlugin.toCoreException(e);
    }
    return getConfiguration();
  }
  
  public void runBuild(RunBuildRequest request, IOperationMonitor monitor)
    throws CoreException
  {
    try
    {
      HudsonModelJob job = createJobParameter(request.getPlan());
      client.runBuild(job, request.getParameters(), monitor);
    }
    catch (HudsonException e)
    {
      throw HudsonCorePlugin.toCoreException(e);
    }
  }
  
  protected void updateHealth(HudsonModelJob job, IBuildPlan plan)
  {
    String testResult = null;
    String buildResult = null;
    String result = null;
    List<HudsonModelHealthReport> husonHealthReports = job.getHealthReport();
    if (husonHealthReports.size() > 0)
    {
      plan.setHealth(((HudsonModelHealthReport)husonHealthReports.get(0)).getScore());
      for (HudsonModelHealthReport hudsonHealthReport : husonHealthReports)
      {
        plan.getHealthReports().add(parseHealthReport(hudsonHealthReport));
        if (hudsonHealthReport.getScore() < plan.getHealth()) {
          plan.setHealth(hudsonHealthReport.getScore());
        }
        String description = hudsonHealthReport.getDescription();
        if (description != null) {
          if (hudsonHealthReport.getDescription().startsWith("Test Result: "))
          {
            if (testResult == null) {
              testResult = description.substring(13);
            }
          }
          else if (hudsonHealthReport.getDescription().startsWith("Build stability: "))
          {
            if (buildResult == null) {
              buildResult = description.substring(17);
            }
          }
          else if (result == null)
          {
            int i = description.indexOf(": ");
            if (i != -1) {
              result = description.substring(i + 2);
            } else {
              result = description;
            }
          }
        }
      }
      if (testResult != null) {
        plan.setSummary(testResult);
      } else if (buildResult != null) {
        plan.setSummary(buildResult);
      } else {
        plan.setSummary(result);
      }
    }
    else
    {
      plan.setHealth(-1);
    }
  }
  
  protected void updateStateAndStatus(HudsonModelJob job, IBuildPlan plan)
  {
    if (job.getColor().equals(HudsonModelBallColor.BLUE))
    {
      plan.setStatus(BuildStatus.SUCCESS);
      plan.setState(BuildState.STOPPED);
    }
    else if (job.getColor().equals(HudsonModelBallColor.BLUE_ANIME))
    {
      plan.setStatus(BuildStatus.SUCCESS);
      plan.setState(BuildState.RUNNING);
    }
    else if (job.getColor().equals(HudsonModelBallColor.RED))
    {
      plan.setStatus(BuildStatus.FAILED);
      plan.setState(BuildState.STOPPED);
    }
    else if (job.getColor().equals(HudsonModelBallColor.RED_ANIME))
    {
      plan.setStatus(BuildStatus.FAILED);
      plan.setState(BuildState.RUNNING);
    }
    else if (job.getColor().equals(HudsonModelBallColor.YELLOW))
    {
      plan.setStatus(BuildStatus.UNSTABLE);
      plan.setState(BuildState.STOPPED);
    }
    else if (job.getColor().equals(HudsonModelBallColor.YELLOW_ANIME))
    {
      plan.setStatus(BuildStatus.UNSTABLE);
      plan.setState(BuildState.RUNNING);
    }
    else if (job.getColor().equals(HudsonModelBallColor.GREY))
    {
      plan.setStatus(BuildStatus.DISABLED);
      plan.setState(BuildState.STOPPED);
    }
    else if (job.getColor().equals(HudsonModelBallColor.GREY_ANIME))
    {
      plan.setStatus(BuildStatus.DISABLED);
      plan.setState(BuildState.RUNNING);
    }
    else if (job.getColor().equals(HudsonModelBallColor.DISABLED))
    {
      plan.setStatus(BuildStatus.DISABLED);
      plan.setState(BuildState.STOPPED);
    }
    else if (job.getColor().equals(HudsonModelBallColor.DISABLED_ANIME))
    {
      plan.setStatus(BuildStatus.DISABLED);
      plan.setState(BuildState.RUNNING);
    }
    else if (job.getColor().equals(HudsonModelBallColor.ABORTED))
    {
      plan.setStatus(BuildStatus.ABORTED);
      plan.setState(BuildState.STOPPED);
    }
    else if (job.getColor().equals(HudsonModelBallColor.ABORTED_ANIME))
    {
      plan.setStatus(BuildStatus.ABORTED);
      plan.setState(BuildState.RUNNING);
    }
    else
    {
      plan.setStatus(null);
      plan.setState(null);
    }
    EnumSet<BuildState> flags = EnumSet.noneOf(BuildState.class);
    if (plan.getState() != null) {
      flags.add(plan.getState());
    }
    if (job.isInQueue()) {
      flags.add(BuildState.QUEUED);
    }
    if (job.isBuildable()) {
      flags.add(BuildState.BUILDABLE);
    }
    plan.getFlags().addAll(flags);
  }
  
  public IStatus validate(IOperationMonitor monitor)
    throws CoreException
  {
    try
    {
      HudsonServerInfo info = client.validate(monitor);
      HudsonStatus status = new HudsonStatus(0, "org.eclipse.mylyn.hudson.core", NLS.bind(
        "Validation succesful: Hudson version {0} found", info.getVersion()));
      status.setInfo(info);
      return status;
    }
    catch (HudsonException e)
    {
      throw HudsonCorePlugin.toCoreException(e);
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.internal.hudson.core.HudsonServerBehaviour
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.hudson.core;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Status;
import org.eclipse.mylyn.internal.hudson.core.client.HudsonException;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

public class HudsonCorePlugin
  implements BundleActivator
{
  public static final String ID_PLUGIN = "org.eclipse.mylyn.hudson.core";
  public static final String CONNECTOR_KIND = "org.eclipse.mylyn.hudson";
  private static HudsonCorePlugin plugin;
  private HudsonConnector connector;
  
  public void start(BundleContext context)
    throws Exception
  {
    plugin = this;
  }
  
  public void stop(BundleContext context)
    throws Exception
  {
    plugin = null;
  }
  
  public static HudsonCorePlugin getDefault()
  {
    return plugin;
  }
  
  public HudsonConnector getConnector()
  {
    if (connector == null) {
      connector = new HudsonConnector();
    }
    return connector;
  }
  
  void setConnector(HudsonConnector connector)
  {
    this.connector = connector;
  }
  
  public static CoreException toCoreException(HudsonException e)
  {
    return new CoreException(new Status(4, "org.eclipse.mylyn.hudson.core", "Unexpected error: " + e.getMessage(), e));
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.internal.hudson.core.HudsonCorePlugin
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.hudson.core.client;

public class HudsonResourceNotFoundException
  extends HudsonException
{
  private static final long serialVersionUID = -5377178546833428956L;
  
  public HudsonResourceNotFoundException() {}
  
  public HudsonResourceNotFoundException(String message)
  {
    super(message);
  }
  
  public HudsonResourceNotFoundException(Throwable cause)
  {
    super(cause);
  }
  
  public HudsonResourceNotFoundException(String message, Throwable cause)
  {
    super(message, cause);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.internal.hudson.core.client.HudsonResourceNotFoundException
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.hudson.core.client;

import java.io.IOException;
import java.util.Map;
import java.util.Map.Entry;
import javax.xml.bind.JAXBException;
import org.apache.http.client.methods.HttpPost;
import org.eclipse.mylyn.commons.core.operations.IOperationMonitor;
import org.eclipse.mylyn.commons.repositories.http.core.CommonHttpClient;
import org.eclipse.mylyn.commons.repositories.http.core.CommonHttpResponse;
import org.eclipse.mylyn.internal.hudson.model.HudsonModelJob;

class RestfulHudsonClient$7
  extends HudsonOperation<Object>
{
  RestfulHudsonClient$7(RestfulHudsonClient paramRestfulHudsonClient, CommonHttpClient $anonymous0, HudsonModelJob paramHudsonModelJob, Map paramMap, IOperationMonitor paramIOperationMonitor)
  {
    super($anonymous0);
  }
  
  public Object execute()
    throws IOException, HudsonException, JAXBException
  {
    HttpPost request = createPostRequest(this$0.getJobUrl(val$job) + "/build");
    if (val$parameters != null)
    {
      HudsonRunBuildForm form = new HudsonRunBuildForm();
      for (Map.Entry<String, String> entry : val$parameters.entrySet()) {
        form.add((String)entry.getKey(), (String)entry.getValue());
      }
      request.setEntity(form.createEntity());
    }
    CommonHttpResponse response = execute(request, val$monitor);
    return processAndRelease(response, val$monitor);
  }
  
  protected void doValidate(CommonHttpResponse response, IOperationMonitor monitor)
    throws IOException, HudsonException
  {
    validate(response, 302, monitor);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.internal.hudson.core.client.RestfulHudsonClient.7
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.hudson.core.client;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.xml.bind.JAXBException;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.CookieStore;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.cookie.Cookie;
import org.apache.http.impl.client.AbstractHttpClient;
import org.apache.http.protocol.HttpContext;
import org.eclipse.mylyn.commons.core.operations.IOperationMonitor;
import org.eclipse.mylyn.commons.repositories.core.RepositoryLocation;
import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationException;
import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationRequest;
import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationType;
import org.eclips
1 2 3 4 5

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd