package org.myrobotlab.framework.repo;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

import org.myrobotlab.logging.LoggerFactory;
import org.slf4j.Logger;

public class ServiceDependency implements Serializable, Comparator<ServiceDependency> {

  transient public final static Logger log = LoggerFactory.getLogger(ServiceDependency.class);

  private static final long serialVersionUID = 1L;
  private String groupId;
  private String artifactId;
  private String version;
  private String ext; // ext

  private boolean installed = false;

  private List<ServiceExclude> excludes = new ArrayList<ServiceExclude>();
  private List<ServiceArtifact> artifacts = new ArrayList<ServiceArtifact>();

  public ServiceDependency() {
    this(null, null, null);
  }

  /**
   * constructor with key - of form [org/version]
   * 
   * @param key
   *          k
   */
  public ServiceDependency(String key) {
    String[] split = key.split("/");

    if (split.length == 2) {
      this.groupId = split[0];
      this.version = split[1];
    } else if (split.length == 3) {
      this.groupId = split[0];
      this.artifactId = split[1];
      this.version = split[2];
    } else if (split.length == 4) {
      this.groupId = split[0];
      this.artifactId = split[1];
      this.version = split[2];
      if (!split[3].equals("null")) {
        this.ext = split[3];
      }
    } else {
      String err = String.format("%s not a valid library key", key);
      log.error(err);
      throw new RuntimeException(err);
    }
  }

  public ServiceDependency(String organisation, String artifactId, String version) {
    this.groupId = organisation;
    this.artifactId = artifactId;
    this.version = version;
  }

  public ServiceDependency(String groubId, String artifactId, String version, String ext) {
    this.groupId = groubId;
    this.artifactId = artifactId;
    this.version = version;
    this.ext = ext;
  }

  @Override
  public int compare(ServiceDependency o1, ServiceDependency o2) {
    return o1.getKey().compareTo(o2.getKey());
  }

  public String getOrgId() {
    return groupId;
  }

  public String getArtifactId() {
    return artifactId;
  }

  public String getVersion() {
    return version;
  }

  public String getExt() {
    return ext;
  }

  public boolean isInstalled() {
    return installed;
  }

  public void setRevision(String revision) {
    this.version = revision;
  }

  @Override
  public String toString() {
    // return String.format("%s %b", getKey(), installed);
    return getKey();
  }

  public void setInstalled(boolean installed) {
    this.installed = installed;
  }

  public String getKey() {
    return String.format("%s/%s/%s/%s", groupId, artifactId, version, ext);
  }

  public void add(ServiceExclude serviceExclude) {
    excludes.add(serviceExclude);
  }

  public List<ServiceExclude> getExcludes() {
    return excludes;
  }

  public void add(ServiceArtifact serviceArtifact) {
    artifacts.add(serviceArtifact);
  }

}

@@ -617,24 +617,398 @@
 = false;%0D%0A%0D%0A
+  /**%0D%0A   * Whether this dependency should be packaged%0D%0A   * in the final jar, instead of being fetched%0D%0A   * on-demand at runtime.%0D%0A   */%0D%0A  private boolean includeInOneJar = false;%0D%0A%0D%0A  /**%0D%0A   * Whether this dependency should be skipped. This should only%0D%0A   * be set by a %7B@link Repo%7D when it detects duplicate dependencies%0D%0A   */%0D%0A  private boolean skipped = false;%0D%0A%0D%0A
   private Li
@@ -2410,32 +2410,248 @@
  = ext;%0D%0A  %7D%0D%0A%0D%0A
+  public ServiceDependency(String groubId, String artifactId, String version, String ext, boolean includeInOneJar) %7B%0D%0A    this(groubId, artifactId, version, ext);%0D%0A    this.includeInOneJar = includeInOneJar;%0D%0A  %7D%0D%0A%0D%0A
   @Override%0D%0A  p
@@ -2998,32 +2998,250 @@
 rn ext;%0D%0A  %7D%0D%0A%0D%0A
+  public boolean getIncludeInOneJar() %7B%0D%0A    return includeInOneJar;%0D%0A  %7D%0D%0A%0D%0A  public boolean isSkipped() %7B%0D%0A    return skipped;%0D%0A  %7D%0D%0A%0D%0A  public void setSkipped(boolean skipped) %7B%0D%0A    this.skipped = skipped;%0D%0A  %7D%0D%0A%0D%0A
   public boolean

Add additional fields to ServiceDependency to keep related information together