org.eclipse.equinox.p2.repository.tools_2.0.100.v20110815-1438

se '!': 
      return scanCaptureTypeSignature(string, start);
    case '+': 
    case '-': 
      return scanTypeBoundSignature(string, start);
    case 'L': 
    case 'Q': 
      return scanClassTypeSignature(string, start);
    case 'T': 
      return scanTypeVariableSignature(string, start);
    case '[': 
      return scanArrayTypeSignature(string, start);
    case '*': 
      return start;
    }
    throw new IllegalArgumentException();
  }
  
  public static int scanTypeArgumentSignatures(char[] string, int start)
  {
    if (start >= string.length - 1) {
      throw new IllegalArgumentException();
    }
    char c = string[start];
    if (c != '<') {
      throw new IllegalArgumentException();
    }
    int p = start + 1;
    for (;;)
    {
      if (p >= string.length) {
        throw new IllegalArgumentException();
      }
      c = string[p];
      if (c == '>') {
        return p;
      }
      int e = scanTypeArgumentSignature(string, p);
      p = e + 1;
    }
  }
  
  public static int scanTypeArgumentSignature(char[] string, int start)
  {
    if (start >= string.length) {
      throw new IllegalArgumentException();
    }
    char c = string[start];
    switch (c)
    {
    case '*': 
      return start;
    case '+': 
    case '-': 
      return scanTypeBoundSignature(string, start);
    }
    return scanTypeSignature(string, start);
  }
  
  static void appendTypeSignature(char[] string, int start, StringBuffer buffer, boolean compact)
  {
    char c = string[start];
    switch (c)
    {
    case '[': 
      appendArrayTypeSignature(string, start, buffer, compact);
      break;
    case 'L': 
      appendClassTypeSignature(string, start, buffer, compact);
      break;
    case 'T': 
      int e = scanTypeVariableSignature(string, start);
      buffer.append(string, start + 1, e - start - 1);
      break;
    case 'Z': 
      buffer.append(BOOLEAN);
      break;
    case 'B': 
      buffer.append(BYTE);
      break;
    case 'C': 
      buffer.append(CHAR);
      break;
    case 'D': 
      buffer.append(DOUBLE);
      break;
    case 'F': 
      buffer.append(FLOAT);
      break;
    case 'I': 
      buffer.append(INT);
      break;
    case 'J': 
      buffer.append(LONG);
      break;
    case 'S': 
      buffer.append(SHORT);
      break;
    case 'V': 
      buffer.append(VOID);
    }
  }
  
  private static void appendArrayTypeSignature(char[] string, int start, StringBuffer buffer, boolean compact)
  {
    int length = string.length;
    if (start >= length - 1) {
      throw new IllegalArgumentException();
    }
    char c = string[start];
    if (c != '[') {
      throw new IllegalArgumentException();
    }
    int index = start;
    c = string[(++index)];
    while (c == '[')
    {
      if (index >= length - 1) {
        throw new IllegalArgumentException();
      }
      c = string[(++index)];
    }
    appendTypeSignature(string, index, buffer, compact);
    
    int i = 0;
    for (int dims = index - start; i < dims; i++) {
      buffer.append('[').append(']');
    }
  }
  
  private static void appendClassTypeSignature(char[] string, int start, StringBuffer buffer, boolean compact)
  {
    char c = string[start];
    if (c != 'L') {
      return;
    }
    int p = start + 1;
    int checkpoint = buffer.length();
    for (;;)
    {
      c = string[p];
      switch (c)
      {
      case ';': 
        return;
      case '.': 
      case '/': 
        if (compact) {
          buffer.setLength(checkpoint);
        } else {
          buffer.append('.');
        }
        break;
      case '$': 
        buffer.append('.');
        break;
      default: 
        buffer.append(c);
      }
      p++;
    }
  }
  
  public static String toString(char[] declaringClass, char[] methodName, char[] methodSignature, boolean includeReturnType, boolean compact)
  {
    boolean isConstructor = Arrays.equals(methodName, INIT);
    int firstParen = CharOperation.indexOf('(', methodSignature);
    if (firstParen == -1) {
      return "";
    }
    StringBuffer buffer = new StringBuffer(methodSignature.length + 10);
    if (declaringClass.length > 0)
    {
      char[] declaringClassSignature = (char[])null;
      if (declaringClass[0] == '[')
      {
        CharOperation.replace(declaringClass, '/', '.');
        declaringClassSignature = Signature.toCharArray(declaringClass);
      }
      else
      {
        CharOperation.replace(declaringClass, '/', '.');
        declaringClassSignature = declaringClass;
      }
      int lastIndexOfSlash = CharOperation.lastIndexOf('.', declaringClassSignature);
      if ((compact) && (lastIndexOfSlash != -1)) {
        buffer.append(declaringClassSignature, lastIndexOfSlash + 1, declaringClassSignature.length - lastIndexOfSlash - 1);
      } else {
        buffer.append(declaringClassSignature);
      }
    }
    if (!isConstructor)
    {
      buffer.append('.');
      if (methodName != null) {
        buffer.append(methodName);
      }
    }
    buffer.append('(');
    char[][] pts = Signature.getParameterTypes(methodSignature);
    int i = 0;
    for (int max = pts.length; i < max; i++)
    {
      appendTypeSignature(pts[i], 0, buffer, compact);
      if (i != pts.length - 1)
      {
        buffer.append(',');
        buffer.append(' ');
      }
    }
    buffer.append(')');
    if (!isConstructor)
    {
      buffer.append(" : ");
      if (includeReturnType)
      {
        char[] rts = Signature.getReturnType(methodSignature);
        appendTypeSignature(rts, 0, buffer, compact);
      }
    }
    return String.valueOf(buffer);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.p2.internal.repository.comparator.java.Utility
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.p2.internal.repository.mirroring;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Date;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.equinox.internal.p2.artifact.repository.Messages;
import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor;

public class FileMirrorLog
  implements IArtifactMirrorLog
{
  private static final String INDENT = "\t";
  private static final String SEPARATOR = System.getProperty("line.separator");
  private BufferedWriter out;
  private boolean consoleMessage = false;
  private int minSeverity = 0;
  private boolean hasRoot = false;
  
  public FileMirrorLog(String location, int minSeverity, String root)
  {
    this.minSeverity = minSeverity;
    try
    {
      File log = new File(location);
      if ((log.getParentFile().exists()) || (log.getParentFile().mkdirs()))
      {
        out = new BufferedWriter(new FileWriter(log, true));
        if (root != null)
        {
          log(root + " - " + new Date());
          hasRoot = true;
        }
      }
      else
      {
        throw new IOException(Messages.exception_unableToCreateParentDir);
      }
    }
    catch (IOException e)
    {
      exceptionOccurred(null, e);
    }
  }
  
  public void log(IArtifactDescriptor descriptor, IStatus status)
  {
    if (status.getSeverity() >= minSeverity)
    {
      log(descriptor.toString());
      log(status, "\t");
    }
  }
  
  public void log(IStatus status)
  {
    log(status, "");
  }
  
  private void log(IStatus status, String prefix)
  {
    if (status.getSeverity() >= minSeverity)
    {
      log(prefix + status.getMessage());
      
      String exceptionMessage = status.getException() != null ? status.getException().getMessage() : null;
      if (exceptionMessage != null) {
        log(prefix + exceptionMessage);
      }
      IStatus[] nestedStatus = status.getChildren();
      if (nestedStatus != null) {
        for (int i = 0; i < nestedStatus.length; i++) {
          log(nestedStatus[i], prefix + "\t");
        }
      }
    }
  }
  
  private void log(String message)
  {
    try
    {
      out.write((hasRoot ? "\t" : "") + message + SEPARATOR);
    }
    catch (IOException e)
    {
      exceptionOccurred((hasRoot ? "\t" : "") + message, e);
    }
  }
  
  public void close()
  {
    try
    {
      if (out != null) {
        out.close();
      }
    }
    catch (IOException e)
    {
      exceptionOccurred(null, e);
    }
  }
  
  private void exceptionOccurred(String message, Exception e)
  {
    if (!consoleMessage)
    {
      System.err.println(Messages.MirrorLog_Exception_Occurred);
      e.printStackTrace(System.err);
      System.err.println(Messages.MirrorLog_Console_Log);
      consoleMessage = true;
    }
    if (message != null) {
      System.out.println(message);
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.p2.internal.repository.mirroring.FileMirrorLog
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.p2.internal.repository.mirroring;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor;

public abstract interface IArtifactMirrorLog
{
  public abstract void log(IArtifactDescriptor paramIArtifactDescriptor, IStatus paramIStatus);
  
  public abstract void log(IStatus paramIStatus);
  
  public abstract void close();
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.p2.internal.repository.mirroring.IArtifactMirrorLog
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.p2.internal.repository.mirroring;

import java.util.Comparator;
import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor;

public class Mirroring$ArtifactDescriptorComparator
  implements Comparator<IArtifactDescriptor>
{
  final Mirroring this$0;
  
  protected Mirroring$ArtifactDescriptorComparator(Mirroring paramMirroring) {}
  
  public int compare(IArtifactDescriptor arg0, IArtifactDescriptor arg1)
  {
    if ((arg0 != null) && (arg1 != null)) {
      return arg0.toString().compareTo(arg1.toString());
    }
    if ((arg1 == null) && (arg0 == null)) {
      return 0;
    }
    if (arg1 == null) {
      return 1;
    }
    return -1;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.p2.internal.repository.mirroring.Mirroring.ArtifactDescriptorComparator
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.p2.internal.repository.mirroring;

import java.io.PrintStream;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.internal.p2.artifact.repository.RawMirrorRequest;
import org.eclipse.equinox.internal.p2.core.helpers.CollectionUtils;
import org.eclipse.equinox.internal.p2.repository.Transport;
import org.eclipse.equinox.p2.internal.repository.tools.Messages;
import org.eclipse.equinox.p2.metadata.IArtifactKey;
import org.eclipse.equinox.p2.query.IQuery;
import org.eclipse.equinox.p2.query.IQueryResult;
import org.eclipse.equinox.p2.query.IQueryable;
import org.eclipse.equinox.p2.repository.artifact.ArtifactKeyQuery;
import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;
import org.eclipse.equinox.p2.repository.artifact.spi.ArtifactDescriptor;
import org.eclipse.equinox.p2.repository.tools.comparator.ArtifactComparatorFactory;
import org.eclipse.equinox.p2.repository.tools.comparator.IArtifactComparator;
import org.eclipse.osgi.util.NLS;

public class Mirroring
{
  private IArtifactRepository source;
  private IArtifactRepository destination;
  private IArtifactRepository baseline;
  private boolean raw;
  private boolean compare = false;
  private boolean validate = false;
  private IArtifactComparator comparator;
  private IQuery<IArtifactDescriptor> compareExclusionQuery = null;
  private Set<IArtifactDescriptor> compareExclusions = CollectionUtils.emptySet();
  private String comparatorID;
  private List<IArtifactKey> keysToMirror;
  private IArtifactMirrorLog comparatorLog;
  private Transport transport;
  
  private IArtifactComparator getComparator()
  {
    if (comparator == null) {
      comparator = ArtifactComparatorFactory.getArtifactComparator(comparatorID);
    }
    return comparator;
  }
  
  public Mirroring(IArtifactRepository source, IArtifactRepository destination, boolean raw)
  {
    this.source = source;
    this.destination = destination;
    this.raw = raw;
  }
  
  public void setCompare(boolean compare)
  {
    this.compare = compare;
  }
  
  public void setComparatorId(String id)
  {
    comparatorID = id;
  }
  
  public void setComparatorLog(IArtifactMirrorLog comparatorLog)
  {
    this.comparatorLog = comparatorLog;
  }
  
  public void setBaseline(IArtifactRepository baseline)
  {
    this.baseline = baseline;
  }
  
  public void setValidate(boolean validate)
  {
    this.validate = validate;
  }
  
  public MultiStatus run(boolean failOnError, boolean verbose)
  {
    if (!destination.isModifiable()) {
      throw new IllegalStateException(NLS.bind(Messages.exception_destinationNotModifiable, destination.getLocation()));
    }
    if (compare) {
      getComparator();
    }
    MultiStatus multiStatus = new MultiStatus("org.eclipse.equinox.p2.transformer", 0, Messages.message_mirroringStatus, null);
    Iterator<IArtifactKey> keys = null;
    if (keysToMirror != null)
    {
      keys = keysToMirror.iterator();
    }
    else
    {
      IQueryResult<IArtifactKey> result = source.query(ArtifactKeyQuery.ALL_KEYS, null);
      keys = result.iterator();
    }
    if (compareExclusionQuery != null)
    {
      IQueryResult<IArtifactDescriptor> exclusions = source.descriptorQueryable().query(compareExclusionQuery, null);
      compareExclusions = exclusions.toUnmodifiableSet();
    }
    IArtifactDescriptor[] descriptors;
    int j;
    for (; keys.hasNext(); j < descriptors.length)
    {
      IArtifactKey key = (IArtifactKey)keys.next();
      descriptors = source.getArtifactDescriptors(key);
      j = 0; continue;
      IStatus result = mirror(descriptors[j], verbose);
      if ((!result.isOK()) && ((verbose) || (result.getSeverity() == 4))) {
        multiStatus.add(result);
      }
      if ((failOnError) && (multiStatus.getSeverity() == 4)) {
        return multiStatus;
      }
      j++;
    }
    if (validate)
    {
      IStatus validation = validateMirror(verbose);
      if ((!validation.isOK()) && ((verbose) || (validation.getSeverity() == 4))) {
        multiStatus.add(validation);
      }
    }
    return multiStatus;
  }
  
  private IStatus mirror(IArtifactDescriptor sourceDescriptor, boolean verbose)
  {
    IArtifactDescriptor targetDescriptor = raw ? sourceDescriptor : new ArtifactDescriptor(sourceDescriptor);
    IArtifactDescriptor baselineDescriptor = getBaselineDescriptor(sourceDescriptor);
    if (verbose) {
      System.out.println("Mirroring: " + sourceDescriptor.getArtifactKey() + " (Descriptor: " + sourceDescriptor + ")");
    }
    MultiStatus compareStatus = new MultiStatus("org.eclipse.equinox.p2.transformer", 0, null, null);
    boolean comparing = (compare) && (!compareExclusions.contains(sourceDescriptor));
    if (comparing) {
      if (baselineDescriptor != null)
      {
        compareStatus.add(compare(baseline, baselineDescriptor, source, sourceDescriptor));
        if (destination.contains(baselineDescriptor))
        {
          compareStatus.add(compareToDestination(baselineDescriptor));
          return compareStatus;
        }
      }
      else if (destination.contains(targetDescriptor))
      {
        compareStatus.add(compareToDestination(sourceDescriptor));
        return compareStatus;
      }
    }
    IArtifactRepository sourceRepository = baselineDescriptor != null ? baseline : source;
    sourceDescriptor = baselineDescriptor != null ? baselineDescriptor : sourceDescriptor;
    targetDescriptor = baselineDescriptor != null ? baselineDescriptor : targetDescriptor;
    IStatus status = null;
    if (!destination.contains(targetDescriptor))
    {
      status = downloadArtifact(sourceRepository, targetDescriptor, sourceDescriptor);
    }
    else
    {
      String message = NLS.bind(Messages.mirror_alreadyExists, sourceDescriptor, destination);
      status = new Status(1, "org.eclipse.equinox.p2.transformer", 1201, message, null);
    }
    if (comparing)
    {
      compareStatus.add(status);
      return compareStatus;
    }
    return status;
  }
  
  private IStatus compareToDestination(IArtifactDescriptor descriptor)
  {
    IArtifactDescriptor[] destDescriptors = destination.getArtifactDescriptors(descriptor.getArtifactKey());
    IArtifactDescriptor destDescriptor = null;
    for (int i = 0; (destDescriptor == null) && (i < destDescriptors.length); i++) {
      if (destDescriptors[i].equals(descriptor)) {
        destDescriptor = destDescriptors[i];
      }
    }
    if (destDescriptor == null) {
      return new Status(1, "org.eclipse.equinox.p2.transformer", 1201, Messages.Mirroring_noMatchingDescriptor, null);
    }
    return compare(source, descriptor, destination, destDescriptor);
  }
  
  private IStatus compare(IArtifactRepository sourceRepository, IArtifactDescriptor sourceDescriptor, IArtifactRepository destRepository, IArtifactDescriptor destDescriptor)
  {
    IStatus comparison = getComparator().compare(sourceRepository, sourceDescriptor, destRepository, destDescriptor);
    if ((comparatorLog != null) && (!comparison.isOK())) {
      comparatorLog.log(sourceDescriptor, comparison);
    }
    return comparison;
  }
  
  private IStatus downloadArtifact(IArtifactRepository sourceRepo, IArtifactDescriptor destDescriptor, IArtifactDescriptor srcDescriptor)
  {
    RawMirrorRequest request = new RawMirrorRequest(srcDescriptor, destDescriptor, destination, transport);
    request.perform(sourceRepo, new NullProgressMonitor());
    
    return request.getResult();
  }
  
  public void setArtifactKeys(IArtifactKey[] keys)
  {
    keysToMirror = Arrays.asList(keys);
  }
  
  private IArtifactDescriptor getBaselineDescriptor(IArtifactDescriptor descriptor)
  {
    if ((baseline == null) || (!baseline.contains(descriptor))) {
      return null;
    }
    IArtifactDescriptor[] baselineDescriptors = baseline.getArtifactDescriptors(descriptor.getArtifactKey());
    for (int i = 0; i < baselineDescriptors.length; i++) {
      if (baselineDescriptors[i].equals(descriptor)) {
        return baselineDescriptors[i];
      }
    }
    return null;
  }
  
  private IStatus validateMirror(boolean verbose)
  {
    MultiStatus status = new MultiStatus("org.eclipse.equinox.p2.transformer", 0, Messages.Mirroring_ValidationError, null);
    
    Iterator<IArtifactKey> keys = null;
    if (keysToMirror != null)
    {
      keys = keysToMirror.iterator();
    }
    else
    {
      IQueryResult<IArtifactKey> result = source.query(ArtifactKeyQuery.ALL_KEYS, null);
      keys = result.iterator();
    }
    IArtifactDescriptor[] srcDescriptors;
    int src;
    for (; keys.hasNext(); src < srcDescriptors.length)
    {
      IArtifactKey artifactKey = (IArtifactKey)keys.next();
      srcDescriptors = source.getArtifactDescriptors(artifactKey);
      IArtifactDescriptor[] destDescriptors = destination.getArtifactDescriptors(artifactKey);
      
      Arrays.sort(srcDescriptors, new ArtifactDescriptorComparator());
      Arrays.sort(destDescriptors, new ArtifactDescriptorComparator());
      
      src = 0;
      int dest = 0;
      do
      {
        if (!destDescriptors[dest].equals(srcDescriptors[src]))
        {
          if (destDescriptors[dest].toString().compareTo(srcDescriptors[src].toString()) > 0)
          {
            if (verbose) {
              System.out.println(NLS.bind(Messages.Mirroring_missingDescriptor, srcDescriptors[src]));
            }
            status.add(new Status(4, "org.eclipse.equinox.p2.transformer", NLS.bind(Messages.Mirroring_missingDescriptor, srcDescriptors[(src++)])));
          }
          else
          {
            dest++;
          }
        }
        else
        {
          Map<String, String> destMap = destDescriptors[dest].getProperties();
          Map<String, String> srcProperties = null;
          if (baseline != null)
          {
            IArtifactDescriptor baselineDescriptor = getBaselineDescriptor(destDescriptors[dest]);
            if (baselineDescriptor != null) {
              srcProperties = baselineDescriptor.getProperties();
            }
          }
          if (srcProperties == null) {
            srcProperties = srcDescriptors[src].getProperties();
          }
          for (Iterator localIterator = srcProperties.keySet().iterator(); localIterator.hasNext();)
          {
            String key = (String)localIterator.next();
            if (!((String)srcProperties.get(key)).equals(destMap.get(key)))
            {
              if (verbose) {
                System.out.println(NLS.bind(Messages.Mirroring_differentDescriptorProperty, new Object[] { destDescriptors[dest], key, srcProperties.get(key), destMap.get(key) }));
              }
              status.add(new Status(2, "org.eclipse.equinox.p2.transformer", NLS.bind(Messages.Mirroring_differentDescriptorProperty, new Object[] { destDescriptors[dest], key, srcProperties.get(key), destMap.get(key) })));
            }
          }
          src++;
          dest++;
        }
        if (src >= srcDescriptors.length) {
          break;
        }
      } while (dest < destDescriptors.length);
      continue;
      if (verbose) {
        System.out.println(NLS.bind(Messages.Mirroring_missingDescriptor, srcDescriptors[src]));
      }
      status.add(new Status(4, "org.eclipse.equinox.p2.transformer", NLS.bind(Messages.Mirroring_missingDescriptor, srcDescriptors[(src++)])));
    }
    return status;
  }
  
  protected class ArtifactDescriptorComparator
    implements Comparator<IArtifactDescriptor>
  {
    protected ArtifactDescriptorComparator() {}
    
    public int compare(IArtifactDescriptor arg0, IArtifactDescriptor arg1)
    {
      if ((arg0 != null) && (arg1 != null)) {
        return arg0.toString().compareTo(arg1.toString());
      }
      if ((arg1 == null) && (arg0 == null)) {
        return 0;
      }
      if (arg1 == null) {
        return 1;
      }
      return -1;
    }
  }
  
  public void setCompareExclusions(IQuery<IArtifactDescriptor> excludedKeys)
  {
    compareExclusionQuery = excludedKeys;
  }
  
  public void setTransport(Transport transport)
  {
    this.transport = transport;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.p2.internal.repository.mirroring.Mirroring
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.p2.internal.repository.mirroring;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.util.Date;
import java.util.Map;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.equinox.internal.p2.artifact.repository.Messages;
import org.eclipse.equinox.internal.p2.persistence.XMLWriter;
import org.eclipse.equinox.p2.metadata.IArtifactKey;
import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor;

public class XMLMirrorLog
  implements IArtifactMirrorLog
{
  private static final String DEFAULT_FORMAT = "canonical";
  private static final String LOG = "log";
  private static final String TIME_ATTRIBUTE = "time";
  private static final String DESCRIPTOR_ELEMENT = "descriptor";
  private static final String DESCRIPTOR_CLASSIFIER_ATTRIBUTE = "classifier";
  private static final String DESCRIPTOR_FORMAT_ATTRIBUTE = "format";
  private static final String DESCRIPTOR_ID_ATTRIBUTE = "id";
  private static final String DESCRIPTOR_VERSION_ATTRIBUTE = "version";
  private static final String STATUS_ELEMENT = "status";
  private static final String STATUS_SEVERITY_ATTRIBUTE = "severity";
  private static final String STATUS_MESSAGE_ATTRIBUTE = "message";
  private int minStatus = 0;
  private XMLWriter writer;
  private OutputStream outputStream;
  private boolean consoleMessage = false;
  
  public XMLMirrorLog(String location, int minStatus, String root)
  {
    this.minStatus = minStatus;
    try
    {
      outputStream = new FileOutputStream(location);
      writer = new XMLWriter(outputStream, null);
      if (root != null) {
        writer.start(root.toLowerCase());
      } else {
        writer.start("log");
      }
      writer.attribute("time", new Date());
    }
    catch (UnsupportedEncodingException e)
    {
      exceptionOccurred(e);
    }
    catch (FileNotFoundException e)
    {
      exceptionOccurred(e);
    }
  }
  
  public void log(IArtifactDescriptor descriptor, IStatus status)
  {
    if (status.getSeverity() < minStatus) {
      return;
    }
    if (writer != null)
    {
      writer.start("descriptor");
      writer.attribute("id", descriptor.getArtifactKey().getId());
      writer.attribute("classifier", descriptor.getArtifactKey().getClassifier());
      writer.attribute("version", descriptor.getArtifactKey().getVersion());
      if (descriptor.getProperties().get("format") != null) {
        writer.attribute("format", descriptor.getProperties().get("format"));
      } else {
        writer.attribute("format", "canonical");
      }
    }
    else
    {
      System.out.println(descriptor);
    }
    log(status);
    if (writer != null) {
      writer.end();
    }
  }
  
  public void log(IStatus status)
  {
    if (status.getSeverity() < minStatus) {
      return;
    }
    if (writer != null)
    {
      writer.start("status");
      switch (status.getSeverity())
      {
      case 0: 
        writer.attribute("severity", "OK");
        break;
      case 1: 
        writer.attribute("severity", "INFO");
        break;
      case 2: 
        writer.attribute("severity", "WARNING");
        break;
      case 4: 
        writer.attribute("severity", "ERROR");
        break;
      case 8: 
        writer.attribute("severity", "CANCEL");
        break;
      case 3: 
      case 5: 
      case 6: 
      case 7: 
      default: 
        writer.attribute("severity", status.getSeverity());
      }
      writer.attribute("message", status.getMessage());
    }
    else
    {
      System.out.println(status);
    }
    IStatus[] nestedStatus = status.getChildren();
    if (nestedStatus != null) {
      for (int i = 0; i < nestedStatus.length; i++) {
        log(nestedStatus[i]);
      }
    }
    if (writer != null) {
      writer.end();
    }
  }
  
  /* Error */
  public void close()
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 194	org/eclipse/equinox/p2/internal/repository/mirroring/XMLMirrorLog:writer	Lorg/eclipse/equinox/internal/p2/persistence/XMLWriter;
    //   4: ifnull +46 -> 50
    //   7: aload_0
    //   8: getfield 194	org/eclipse/equinox/p2/internal/repository/mirroring/XMLMirrorLog:writer	Lorg/eclipse/equinox/internal/p2/persistence/XMLWriter;
    //   11: invokevirtual 203	org/eclipse/equinox/internal/p2/persistence/XMLWriter:end	()V
    //   14: aload_0
    //   15: getfield 194	org/eclipse/equinox/p2/internal/repository/mirroring/XMLMirrorLog:writer	Lorg/eclipse/equinox/internal/p2/persistence/XMLWriter;
    //   18: invokevirtual 204	org/eclipse/equinox/internal/p2/persistence/XMLWriter:flush	()V
    //   21: goto +29 -> 50
    //   24: astore_1
    //   25: aload_0
    //   26: getfield 193	org/eclipse/equinox/p2/internal/repository/mirroring/XMLMirrorLog:outputStream	Ljava/io/OutputStream;
    //   29: ifnull +19 -> 48
    //   32: aload_0
    //   33: getfield 193	org/eclipse/equinox/p2/internal/repository/mirroring/XMLMirrorLog:outputStream	Ljava/io/OutputStream;
    //   36: invokevirtual 196	java/io/OutputStream:close	()V
    //   39: goto +9 -> 48
    //   42: astore_2
    //   43: aload_0
    //   44: aload_2
    //   45: invokespecial 209	org/eclipse/equinox/p2/internal/repository/mirroring/XMLMirrorLog:exceptionOccurred	(Ljava/lang/Exception;)V
    //   48: aload_1
    //   49: athrow
    //   50: aload_0
    //   51: getfield 193	org/eclipse/equinox/p2/internal/repository/mirroring/XMLMirrorLog:outputStream	Ljava/io/OutputStream;
    //   54: ifnull +19 -> 73
    //   57: aload_0
    //   58: getfield 193	org/eclipse/equinox/p2/internal/repository/mirroring/XMLMirrorLog:outputStream	Ljava/io/OutputStream;
    //   61: invokevirtual 196	java/io/OutputStream:close	()V
    //   64: goto +9 -> 73
    //   67: astore_2
    //   68: aload_0
    //   69: aload_2
    //   70: invokespecial 209	org/eclipse/equinox/p2/internal/repository/mirroring/XMLMirrorLog:exceptionOccurred	(Ljava/lang/Exception;)V
    //   73: return
    // Line number table:
    //   Java source line #139	-> byte code offset #0
    //   Java source line #141	-> byte code offset #7
    //   Java source line #142	-> byte code offset #14
    //   Java source line #144	-> byte code offset #24
    //   Java source line #145	-> byte code offset #25
    //   Java source line #148	-> byte code offset #32
    //   Java source line #149	-> byte code offset #42
    //   Java source line #150	-> byte code offset #43
    //   Java source line #152	-> byte code offset #48
    //   Java source line #145	-> byte code offset #50
    //   Java source line #148	-> byte code offset #57
    //   Java source line #149	-> byte code offset #67
    //   Java source line #150	-> byte code offset #68
    //   Java source line #153	-> byte code offset #73
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	74	0	this	XMLMirrorLog
    //   24	25	1	localObject	Object
    //   42	3	2	e	java.io.IOException
    //   67	3	2	e	java.io.IOException
    // Exception table:
    //   from	to	target	type
    //   0	24	24	finally
    //   32	39	42	java/io/IOException
    //   57	64	67	java/io/IOException
  }
  
  private void exceptionOccurred(Exception e)
  {
    if (!consoleMessage)
    {
      System.err.println(Messages.MirrorLog_Exception_Occurred);
      e.printStackTrace(System.err);
      System.err.println(Messages.MirrorLog_Console_Log);
      consoleMessage = true;
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.p2.internal.repository.mirroring.XMLMirrorLog
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.p2.internal.repository.tools;

import java.net.MalformedURLException;
import java.net.URI;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository;
import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
import org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepository;
import org.eclipse.equinox.internal.p2.repository.helpers.RepositoryHelper;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.core.IProvisioningAgentProvider;
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.repository.ICompositeRepository;
import org.eclipse.equinox.p2.repository.IRepository;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
import org.eclipse.osgi.util.NLS;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;

public abstract class AbstractApplication
{
  protected boolean removeAddedRepositories = true;
  protected List<RepositoryDescriptor> sourceRepositories = new ArrayList();
  protected List<URI> artifactReposToRemove = new ArrayList();
  protected List<URI> metadataReposToRemove = new ArrayList();
  protected List<IInstallableUnit> sourceIUs = new ArrayList();
  private List<RepositoryDescriptor> destinationRepos = new ArrayList();
  protected IArtifactRepository destinationArtifactRepository = null;
  protected IMetadataRepository destinationMetadataRepository = null;
  private CompositeMetadataRepository compositeMetadataRepository = null;
  private CompositeArtifactRepository compositeArtifactRepository = null;
  protected IProvisioningAgent agent;
  
  public AbstractApplication()
  {
    try
    {
      setupAgent();
    }
    catch (ProvisionException e)
    {
      LogHelper.log(e);
    }
  }
  
  private void setupAgent()
    throws ProvisionException
  {
    ServiceReference<IProvisioningAgent> agentRef = Activator.getBundleContext().getServiceReference(IProvisioningAgent.class);
    if (agentRef != null)
    {
      agent = ((IProvisioningAgent)Activator.getBundleContext().getService(agentRef));
      if (agent != null) {
        return;
      }
    }
    ServiceReference<IProvisioningAgentProvider> providerRef = Activator.getBundleContext().getServiceReference(IProvisioningAgentProvider.class);
    if (providerRef == null) {
      throw new RuntimeException("No provisioning agent provider is available");
    }
    IProvisioningAgentProvider provider = (IProvisioningAgentProvider)Activator.getBundleContext().getService(providerRef);
    if (provider == null) {
      throw new RuntimeException("No provisioning agent provider is available");
    }
    agent = provider.createAgent(null);
    Activator.getBundleContext().ungetService(providerRef);
  }
  
  public void setSourceIUs(List<IInstallableUnit> ius)
  {
    sourceIUs = ius;
  }
  
  protected void finalizeRepositories()
  {
    if (removeAddedRepositories)
    {
      IArtifactRepositoryManager artifactRepositoryManager = getArtifactRepositoryManager();
      for (Iterator localIterator1 = artifactReposToRemove.iterator(); localIterator1.hasNext();)
      {
        URI uri = (URI)localIterator1.next();
        artifactRepositoryManager.removeRepository(uri);
      }
      IMetadataRepositoryManager metadataRepositoryManager = getMetadataRepositoryManager();
      for (Iterator localIterator2 = metadataReposToRemove.iterator(); localIterator2.hasNext();)
      {
        URI uri = (URI)localIterator2.next();
        metadataRepositoryManager.removeRepository(uri);
      }
    }
    metadataReposToRemove = null;
    artifactReposToRemove = null;
    compositeArtifactRepository = null;
    compositeMetadataRepository = null;
    destinationArtifactRepository = null;
    destinationMetadataRepository = null;
  }
  
  protected IMetadataRepositoryManager getMetadataRepositoryManager()
  {
    return (IMetadataRepositoryManager)agent.getService(IMetadataRepositoryManager.SERVICE_NAME);
  }
  
  protected IArtifactRepositoryManager getArtifactRepositoryManager()
  {
    return (IArtifactRepositoryManager)agent.getService(IArtifactRepositoryManager.SERVICE_NAME);
  }
  
  public void initializeRepos(IProgressMonitor progress)
    throws ProvisionException
  {
    IArtifactRepositoryManager artifactRepositoryManager = getArtifactRepositoryManager();
    IMetadataRepositoryManager metadataRepositoryManager = getMetadataRepositoryManager();
    URI curLocation = null;
    for (Iterator localIterator = sourceRepositories.iterator(); localIterator.hasNext();)
    {
      RepositoryDescriptor repo = (RepositoryDescriptor)localIterator.next();
      try
      {
        curLocation = repo.getRepoLocation();
        if (repo.isBoth())
        {
          addRepository(artifactRepositoryManager, curLocation, 0, progress);
          addRepository(metadataRepositoryManager, curLocation, 0, progress);
        }
        else if (repo.isArtifact())
        {
          addRepository(artifactRepositoryManager, curLocation, 0, progress);
        }
        else if (repo.isMetadata())
        {
          addRepository(metadataRepositoryManager, curLocation, 0, progress);
        }
        else
        {
          throw new ProvisionException(NLS.bind(Messages.unknown_repository_type, repo.getRepoLocation()));
        }
      }
      catch (ProvisionException e)
      {
        if ((e.getCause() instanceof MalformedURLException)) {
          throw new ProvisionException(NLS.bind(Messages.exception_invalidSource, curLocation), e);
        }
        if ((e.getStatus().getCode() != 1000) || (!repo.isOptional())) {
          throw e;
        }
      }
    }
    processDestinationRepos(artifactRepositoryManager, metadataRepositoryManager);
  }
  
  protected IMetadataRepository addRepository(IMetadataRepositoryManager manager, URI location, int flags, IProgressMonitor monitor)
    throws ProvisionException
  {
    if (!manager.contains(location)) {
      metadataReposToRemove.add(location);
    }
    return manager.loadRepository(location, flags, monitor);
  }
  
  protected IArtifactRepository addRepository(IArtifactRepositoryManager manager, URI location, int flags, IProgressMonitor monitor)
    throws ProvisionException
  {
    if (!manager.contains(location)) {
      artifactReposToRemove.add(location);
    }
    return manager.loadRepository(location, flags, monitor);
  }
  
  private void processDestinationRepos(IArtifactRepositoryManager artifactRepositoryManager, IMetadataRepositoryManager metadataRepositoryManager)
    throws ProvisionException
  {
    RepositoryDescriptor artifactRepoDescriptor = null;
    RepositoryDescriptor metadataRepoDescriptor = null;
    
    Iterator<RepositoryDescriptor> iter = destinationRepos.iterator();
    while ((iter.hasNext()) && ((artifactRepoDescriptor == null) || (metadataRepoDescriptor == null)))
    {
      RepositoryDescriptor repo = (RepositoryDescriptor)iter.next();
      if ((repo.isArtifact()) && (artifactRepoDescriptor == null)) {
        artifactRepoDescriptor = repo;
      }
      if ((repo.isMetadata()) && (metadataRepoDescriptor == null)) {
        metadataRepoDescriptor = repo;
      }
    }
    if (artifactRepoDescriptor != null) {
      destinationArtifactRepository = initializeDestination(artifactRepoDescriptor, artifactRepositoryManager);
    }
    if (metadataRepoDescriptor != null) {
      destinationMetadataRepository = initializeDestination(metadataRepoDescriptor, metadataRepositoryManager);
    }
    if ((destinationMetadataRepository == null) && (destinationArtifactRepository == null)) {
      throw new ProvisionException(Messages.AbstractApplication_no_valid_destinations);
    }
  }
  
  public IMetadataRepository getDestinationMetadataRepository()
  {
    return destinationMetadataRepository;
  }
  
  public IArtifactRepository getDestinationArtifactRepository()
  {
    return destinationArtifactRepository;
  }
  
  protected IMetadataRepository initializeDestination(RepositoryDescriptor toInit, IMetadataRepositoryManager mgr)
    throws ProvisionException
  {
    try
    {
      IMetadataRepository repository = addRepository(mgr, toInit.getRepoLocation(), 1, null);
      if (initDestinationRepository(repository, toInit)) {
        return repository;
      }
    }
    catch (ProvisionException localProvisionException1)
    {
      IMetadataRepository source = null;
      try
      {
        if (toInit.getFormat() != null) {
          source = mgr.loadRepository(toInit.getFormat(), 0, null);
        }
      }
      catch (ProvisionException localProvisionException2) {}
      try
      {
        IMetadataRepository result = mgr.createRepository(toInit.getRepoLocation(), source != null ? source.getName() : toInit.getName() != null ? toInit.getName() : toInit.getRepoLocation().toString(), "org.eclipse.equinox.p2.meta
1 2 3 4 5 6 7 8 9 10 11 12

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-2019. Infinite Loop Ltd