org.eclipse.equinox.p2.artifact.repository_1.1.200.v20120430-1959

16:44:02.022 INFO  jd.cli.Main - Decompiling org.eclipse.equinox.p2.artifact.repository_1.1.200.v20120430-1959.jar
package org.eclipse.equinox.internal.p2.artifact.processing;

import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import org.eclipse.equinox.internal.p2.core.helpers.FileUtils;
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStep;
import org.eclipse.osgi.util.NLS;

public abstract class AbstractBufferingStep
  extends ProcessingStep
{
  private static final String WORK_DIR_PREFIX = "work";
  private static final String WORK_DIR_SUFFIX = "";
  protected static final String JAR_SUFFIX = ".jar";
  protected static final String INCOMING_ROOT = "p2.optimizers.incoming";
  protected static final String RESULT_ROOT = "p2.optimizers.result";
  protected static final String PREDECESSOR_ROOT = "p2.optimizers.predecessor";
  protected OutputStream incomingStream;
  private File workDir;
  
  public void write(int b)
    throws IOException
  {
    OutputStream stream = getOutputStream();
    stream.write(b);
  }
  
  protected OutputStream getOutputStream()
    throws IOException
  {
    if (incomingStream != null) {
      return incomingStream;
    }
    incomingStream = createIncomingStream();
    return incomingStream;
  }
  
  protected abstract OutputStream createIncomingStream()
    throws IOException;
  
  /* Error */
  public void close()
    throws IOException
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 108	org/eclipse/equinox/internal/p2/artifact/processing/AbstractBufferingStep:incomingStream	Ljava/io/OutputStream;
    //   4: ifnull +38 -> 42
    //   7: aload_0
    //   8: getfield 108	org/eclipse/equinox/internal/p2/artifact/processing/AbstractBufferingStep:incomingStream	Ljava/io/OutputStream;
    //   11: invokevirtual 116	java/io/OutputStream:close	()V
    //   14: aload_0
    //   15: invokevirtual 124	org/eclipse/equinox/internal/p2/artifact/processing/AbstractBufferingStep:getStatus	()Lorg/eclipse/core/runtime/IStatus;
    //   18: ifnull +60 -> 78
    //   21: aload_0
    //   22: invokevirtual 124	org/eclipse/equinox/internal/p2/artifact/processing/AbstractBufferingStep:getStatus	()Lorg/eclipse/core/runtime/IStatus;
    //   25: invokeinterface 130 1 0
    //   30: bipush 8
    //   32: if_icmpeq +46 -> 78
    //   35: aload_0
    //   36: invokevirtual 121	org/eclipse/equinox/internal/p2/artifact/processing/AbstractBufferingStep:performProcessing	()V
    //   39: goto +39 -> 78
    //   42: aload_0
    //   43: new 65	org/eclipse/core/runtime/Status
    //   46: dup
    //   47: iconst_4
    //   48: ldc 2
    //   50: getstatic 111	org/eclipse/equinox/internal/p2/artifact/processing/Messages:Empty_stream	Ljava/lang/String;
    //   53: invokespecial 118	org/eclipse/core/runtime/Status:<init>	(ILjava/lang/String;Ljava/lang/String;)V
    //   56: invokevirtual 125	org/eclipse/equinox/internal/p2/artifact/processing/AbstractBufferingStep:setStatus	(Lorg/eclipse/core/runtime/IStatus;)V
    //   59: goto +19 -> 78
    //   62: astore_1
    //   63: aload_0
    //   64: aconst_null
    //   65: putfield 108	org/eclipse/equinox/internal/p2/artifact/processing/AbstractBufferingStep:incomingStream	Ljava/io/OutputStream;
    //   68: aload_0
    //   69: invokevirtual 119	org/eclipse/equinox/internal/p2/artifact/processing/AbstractBufferingStep:cleanupTempFiles	()V
    //   72: aload_0
    //   73: invokespecial 120	org/eclipse/equinox/internal/p2/artifact/processing/AbstractBufferingStep:cleanupWorkDir	()V
    //   76: aload_1
    //   77: athrow
    //   78: aload_0
    //   79: aconst_null
    //   80: putfield 108	org/eclipse/equinox/internal/p2/artifact/processing/AbstractBufferingStep:incomingStream	Ljava/io/OutputStream;
    //   83: aload_0
    //   84: invokevirtual 119	org/eclipse/equinox/internal/p2/artifact/processing/AbstractBufferingStep:cleanupTempFiles	()V
    //   87: aload_0
    //   88: invokespecial 120	org/eclipse/equinox/internal/p2/artifact/processing/AbstractBufferingStep:cleanupWorkDir	()V
    //   91: aload_0
    //   92: invokespecial 128	org/eclipse/equinox/internal/provisional/p2/artifact/repository/processing/ProcessingStep:close	()V
    //   95: return
    // Line number table:
    //   Java source line #59	-> byte code offset #0
    //   Java source line #60	-> byte code offset #7
    //   Java source line #62	-> byte code offset #14
    //   Java source line #63	-> byte code offset #35
    //   Java source line #65	-> byte code offset #42
    //   Java source line #67	-> byte code offset #62
    //   Java source line #68	-> byte code offset #63
    //   Java source line #69	-> byte code offset #68
    //   Java source line #70	-> byte code offset #72
    //   Java source line #71	-> byte code offset #76
    //   Java source line #68	-> byte code offset #78
    //   Java source line #69	-> byte code offset #83
    //   Java source line #70	-> byte code offset #87
    //   Java source line #73	-> byte code offset #91
    //   Java source line #77	-> byte code offset #95
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	96	0	this	AbstractBufferingStep
    //   62	15	1	localObject	Object
    // Exception table:
    //   from	to	target	type
    //   0	62	62	finally
  }
  
  protected abstract void performProcessing()
    throws IOException;
  
  protected void cleanupTempFiles() {}
  
  private void cleanupWorkDir()
    throws IOException
  {
    if (workDir != null)
    {
      FileUtils.deleteAll(workDir);
      
      FileUtils.deleteAll(workDir);
    }
  }
  
  protected File getWorkDir()
    throws IOException
  {
    if (workDir != null) {
      return workDir;
    }
    workDir = File.createTempFile("work", "");
    if (!workDir.delete()) {
      throw new IOException(NLS.bind(Messages.Can_not_delete_temp_dir, workDir));
    }
    if (!workDir.mkdirs()) {
      throw new IOException(NLS.bind(Messages.Can_not_create_temp_dir, workDir));
    }
    return workDir;
  }
}

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

import org.eclipse.osgi.util.NLS;

public class Messages
  extends NLS
{
  private static final String BUNDLE_NAME = "org.eclipse.equinox.internal.p2.artifact.processing.messages";
  public static String Can_not_create_temp_dir;
  public static String Can_not_delete_temp_dir;
  public static String Empty_stream;
  
  static
  {
    NLS.initializeMessages("org.eclipse.equinox.internal.p2.artifact.processing.messages", Messages.class);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.p2.artifact.processing.Messages
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.p2.artifact.processors.md5;

import java.io.IOException;
import java.io.OutputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStep;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor;
import org.eclipse.equinox.p2.repository.artifact.IProcessingStepDescriptor;
import org.eclipse.osgi.util.NLS;

public class MD5Verifier
  extends ProcessingStep
{
  protected String expectedMD5;
  private MessageDigest md5;
  
  public MD5Verifier() {}
  
  public MD5Verifier(String expected)
  {
    expectedMD5 = expected;
    basicInitialize(null);
  }
  
  public void initialize(IProvisioningAgent agent, IProcessingStepDescriptor descriptor, IArtifactDescriptor context)
  {
    super.initialize(agent, descriptor, context);
    String data = descriptor.getData();
    if ("download.md5".equals(data)) {
      expectedMD5 = context.getProperty("download.md5");
    } else if ("artifact.md5".equals(data)) {
      expectedMD5 = context.getProperty("artifact.md5");
    } else {
      expectedMD5 = data;
    }
    basicInitialize(descriptor);
  }
  
  private void basicInitialize(IProcessingStepDescriptor descriptor)
  {
    int code = descriptor.isRequired() ? 4 : descriptor == null ? 4 : 1;
    if ((expectedMD5 == null) || (expectedMD5.length() != 32)) {
      setStatus(new Status(code, "org.eclipse.equinox.p2.artifact.repository", NLS.bind(Messages.Error_invalid_hash, expectedMD5)));
    }
    try
    {
      md5 = MessageDigest.getInstance("MD5");
    }
    catch (NoSuchAlgorithmException e)
    {
      setStatus(new Status(code, "org.eclipse.equinox.p2.artifact.repository", Messages.Error_MD5_unavailable, e));
    }
  }
  
  public void write(int b)
    throws IOException
  {
    md5.update((byte)b);
    getDestination().write(b);
  }
  
  public void close()
    throws IOException
  {
    byte[] digest = md5.digest();
    StringBuffer buf = new StringBuffer();
    for (int i = 0; i < digest.length; i++)
    {
      if ((digest[i] & 0xFF) < 16) {
        buf.append('0');
      }
      buf.append(Integer.toHexString(digest[i] & 0xFF));
    }
    if (!buf.toString().equals(expectedMD5)) {
      setStatus(new Status(4, "org.eclipse.equinox.p2.artifact.repository", 1203, NLS.bind(Messages.Error_unexpected_hash, expectedMD5, buf), null));
    }
    super.close();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.p2.artifact.processors.md5.MD5Verifier
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.p2.artifact.processors.md5;

import org.eclipse.osgi.util.NLS;

public class Messages
  extends NLS
{
  private static final String BUNDLE_NAME = "org.eclipse.equinox.internal.p2.artifact.processors.md5.messages";
  public static String Error_invalid_hash;
  public static String Error_MD5_unavailable;
  public static String Error_unexpected_hash;
  public static String warning_differentMD5;
  
  static
  {
    NLS.initializeMessages("org.eclipse.equinox.internal.p2.artifact.processors.md5.messages", Messages.class);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.p2.artifact.processors.md5.Messages
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.p2.artifact.processors.pack200;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.internal.p2.artifact.processing.AbstractBufferingStep;
import org.eclipse.equinox.internal.p2.jarprocessor.UnpackStep;
import org.eclipse.equinox.internal.p2.jarprocessor.Utils;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor;
import org.eclipse.equinox.p2.repository.artifact.IProcessingStepDescriptor;
import org.eclipse.internal.provisional.equinox.p2.jarprocessor.JarProcessorExecutor;
import org.eclipse.internal.provisional.equinox.p2.jarprocessor.JarProcessorExecutor.Options;

public class Pack200ProcessorStep
  extends AbstractBufferingStep
{
  public static final String PACKED_SUFFIX = ".pack.gz";
  private static boolean detailedResult = false;
  private File incoming;
  
  protected OutputStream createIncomingStream()
    throws IOException
  {
    incoming = File.createTempFile("p2.optimizers.incoming", ".jar.pack.gz");
    return new BufferedOutputStream(new FileOutputStream(incoming));
  }
  
  public void initialize(IProvisioningAgent agent, IProcessingStepDescriptor descriptor, IArtifactDescriptor context)
  {
    super.initialize(agent, descriptor, context);
    if (!UnpackStep.canUnpack())
    {
      IStatus status = null;
      if (detailedResult)
      {
        status = new Status(4, "org.eclipse.equinox.p2.artifact.repository", "Unpack facility not configured.");
        detailedResult = true;
      }
      else
      {
        String[] locations = Utils.getPack200Commands("unpack200");
        StringBuffer locationTried = new StringBuffer(100);
        for (int i = 0; i < locations.length; i++) {
          locationTried.append(locations[i]).append(", ");
        }
        status = new Status(4, "org.eclipse.equinox.p2.artifact.repository", "Unpack facility not configured. The locations searched for unpack200 are: " + locationTried);
      }
      setStatus(status);
    }
  }
  
  protected void cleanupTempFiles()
  {
    super.cleanupTempFiles();
    if (incoming != null) {
      incoming.delete();
    }
  }
  
  /* Error */
  protected void performProcessing()
    throws IOException
  {
    // Byte code:
    //   0: aconst_null
    //   1: astore_1
    //   2: aload_0
    //   3: invokevirtual 192	org/eclipse/equinox/internal/p2/artifact/processors/pack200/Pack200ProcessorStep:process	()Ljava/io/File;
    //   6: astore_1
    //   7: aload_1
    //   8: invokevirtual 172	java/io/File:length	()J
    //   11: lconst_0
    //   12: lcmp
    //   13: ifle +33 -> 46
    //   16: new 84	java/io/BufferedInputStream
    //   19: dup
    //   20: new 87	java/io/FileInputStream
    //   23: dup
    //   24: aload_1
    //   25: invokespecial 178	java/io/FileInputStream:<init>	(Ljava/io/File;)V
    //   28: invokespecial 170	java/io/BufferedInputStream:<init>	(Ljava/io/InputStream;)V
    //   31: astore_2
    //   32: aload_2
    //   33: iconst_1
    //   34: aload_0
    //   35: invokevirtual 193	org/eclipse/equinox/internal/p2/artifact/processors/pack200/Pack200ProcessorStep:getDestination	()Ljava/io/OutputStream;
    //   38: iconst_0
    //   39: invokestatic 195	org/eclipse/equinox/internal/p2/core/helpers/FileUtils:copyStream	(Ljava/io/InputStream;ZLjava/io/OutputStream;Z)I
    //   42: pop
    //   43: goto +48 -> 91
    //   46: aload_0
    //   47: new 92	org/eclipse/core/runtime/Status
    //   50: dup
    //   51: iconst_4
    //   52: ldc 7
    //   54: new 91	java/lang/StringBuffer
    //   57: dup
    //   58: ldc 6
    //   60: invokespecial 184	java/lang/StringBuffer:<init>	(Ljava/lang/String;)V
    //   63: aload_1
    //   64: invokevirtual 185	java/lang/StringBuffer:append	(Ljava/lang/Object;)Ljava/lang/StringBuffer;
    //   67: invokevirtual 183	java/lang/StringBuffer:toString	()Ljava/lang/String;
    //   70: invokespecial 187	org/eclipse/core/runtime/Status:<init>	(ILjava/lang/String;Ljava/lang/String;)V
    //   73: invokevirtual 194	org/eclipse/equinox/internal/p2/artifact/processors/pack200/Pack200ProcessorStep:setStatus	(Lorg/eclipse/core/runtime/IStatus;)V
    //   76: goto +15 -> 91
    //   79: astore_3
    //   80: aload_1
    //   81: ifnull +8 -> 89
    //   84: aload_1
    //   85: invokevirtual 173	java/io/File:delete	()Z
    //   88: pop
    //   89: aload_3
    //   90: athrow
    //   91: aload_1
    //   92: ifnull +8 -> 100
    //   95: aload_1
    //   96: invokevirtual 173	java/io/File:delete	()Z
    //   99: pop
    //   100: return
    // Line number table:
    //   Java source line #68	-> byte code offset #0
    //   Java source line #70	-> byte code offset #2
    //   Java source line #72	-> byte code offset #7
    //   Java source line #73	-> byte code offset #16
    //   Java source line #74	-> byte code offset #32
    //   Java source line #76	-> byte code offset #46
    //   Java source line #78	-> byte code offset #79
    //   Java source line #79	-> byte code offset #80
    //   Java source line #80	-> byte code offset #84
    //   Java source line #81	-> byte code offset #89
    //   Java source line #79	-> byte code offset #91
    //   Java source line #80	-> byte code offset #95
    //   Java source line #82	-> byte code offset #100
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	101	0	this	Pack200ProcessorStep
    //   1	95	1	resultFile	File
    //   31	2	2	resultStream	java.io.InputStream
    //   79	11	3	localObject	Object
    // Exception table:
    //   from	to	target	type
    //   2	79	79	finally
  }
  
  protected File process()
    throws IOException
  {
    JarProcessorExecutor.Options options = new JarProcessorExecutor.Options();
    unpack = true;
    
    processAll = false;
    input = incoming;
    outputDir = getWorkDir().getPath();
    verbose = false;
    new JarProcessorExecutor().runJarProcessor(options);
    return new File(getWorkDir(), incoming.getName().substring(0, incoming.getName().length() - ".pack.gz".length()));
  }
}

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

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.runtime.URIUtil;
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
import org.eclipse.osgi.service.datalocation.Location;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

public class Activator
  implements BundleActivator
{
  public static final String ID = "org.eclipse.equinox.p2.artifact.repository";
  public static final String ENABLE_ARTIFACT_LOCKING = "eclipse.p2.internal.simple.artifact.repository.locking";
  public static final String REPO_PROVIDER_XPT = "org.eclipse.equinox.p2.artifact.repository.artifactRepositories";
  private Map<URI, Location> locationCache = null;
  private static BundleContext context;
  private static Activator instance;
  
  public static BundleContext getContext()
  {
    return context;
  }
  
  public void start(BundleContext aContext)
    throws Exception
  {
    context = aContext;
    instance = this;
    locationCache = new HashMap();
  }
  
  public void stop(BundleContext aContext)
    throws Exception
  {
    context = null;
    instance = null;
    locationCache = null;
  }
  
  public static Activator getInstance()
  {
    return instance;
  }
  
  public boolean enableArtifactLocking()
  {
    String property = getContext().getProperty("eclipse.p2.internal.simple.artifact.repository.locking");
    if ((property == null) || (property.length() == 0)) {
      return false;
    }
    Boolean valueOf = Boolean.valueOf(property);
    if (valueOf != null) {
      return valueOf.booleanValue();
    }
    return false;
  }
  
  public synchronized Location getLockLocation(URI repositoryLocation)
    throws IOException
  {
    if (locationCache.containsKey(repositoryLocation)) {
      return (Location)locationCache.get(repositoryLocation);
    }
    Location anyLoc = (Location)ServiceHelper.getService(getContext(), Location.class.getName());
    File repositoryFile = URIUtil.toFile(repositoryLocation);
    Location location = anyLoc.createLocation(null, getLockFile(repositoryLocation).toURL(), isReadOnly(repositoryFile));
    location.set(getLockFile(repositoryLocation).toURL(), false);
    locationCache.put(repositoryLocation, location);
    return location;
  }
  
  private boolean isReadOnly(File file)
  {
    if (file == null) {
      return true;
    }
    if (file.exists()) {
      try
      {
        File tmpTestFile = File.createTempFile(".artifactlocktest", ".dll", file);
        tmpTestFile.delete();
        return false;
      }
      catch (IOException localIOException)
      {
        return true;
      }
    }
    return isReadOnly(file.getParentFile());
  }
  
  private File getLockFile(URI repositoryLocation)
    throws IOException
  {
    if (!URIUtil.isFileURI(repositoryLocation)) {
      throw new IOException("Cannot lock a non file based repository");
    }
    URI result = URIUtil.append(repositoryLocation, ".artifactlock");
    return URIUtil.toFile(result);
  }
}

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

import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.core.spi.IAgentServiceFactory;

public class ArtifactRepositoryComponent
  implements IAgentServiceFactory
{
  public Object createService(IProvisioningAgent agent)
  {
    return new ArtifactRepositoryManager(agent);
  }
}

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

import java.net.URI;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.URIUtil;
import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
import org.eclipse.equinox.internal.p2.repository.helpers.AbstractRepositoryManager;
import org.eclipse.equinox.internal.p2.repository.helpers.LocationProperties;
import org.eclipse.equinox.p2.core.IAgentLocation;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.metadata.IArtifactKey;
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.artifact.IArtifactRequest;
import org.eclipse.equinox.p2.repository.artifact.spi.ArtifactRepositoryFactory;

public class ArtifactRepositoryManager
  extends AbstractRepositoryManager<IArtifactKey>
  implements IArtifactRepositoryManager
{
  public ArtifactRepositoryManager(IProvisioningAgent agent)
  {
    super(agent);
  }
  
  public void addRepository(IArtifactRepository repository)
  {
    super.addRepository(repository, true, null);
  }
  
  public IArtifactRequest createMirrorRequest(IArtifactKey key, IArtifactRepository destination, Map<String, String> destinationDescriptorProperties, Map<String, String> destinationRepositoryProperties)
  {
    return createMirrorRequest(key, destination, destinationDescriptorProperties, destinationRepositoryProperties, null);
  }
  
  public IArtifactRequest createMirrorRequest(IArtifactKey key, IArtifactRepository destination, Map<String, String> destinationDescriptorProperties, Map<String, String> destinationRepositoryProperties, String downloadStatsParameters)
  {
    return new MirrorRequest(key, destination, destinationDescriptorProperties, destinationRepositoryProperties, getTransport(), downloadStatsParameters);
  }
  
  public IArtifactRepository createRepository(URI location, String name, String type, Map<String, String> properties)
    throws ProvisionException
  {
    return (IArtifactRepository)doCreateRepository(location, name, type, properties);
  }
  
  public IArtifactRepository getRepository(URI location)
  {
    return (IArtifactRepository)basicGetRepository(location);
  }
  
  protected IRepository<IArtifactKey> factoryCreate(URI location, String name, String type, Map<String, String> properties, IExtension extension)
    throws ProvisionException
  {
    ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory)createExecutableExtension(extension, "factory");
    if (factory == null) {
      return null;
    }
    factory.setAgent(agent);
    return factory.create(location, name, type, properties);
  }
  
  protected IRepository<IArtifactKey> factoryLoad(URI location, IExtension extension, int flags, SubMonitor monitor)
    throws ProvisionException
  {
    ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory)createExecutableExtension(extension, "factory");
    if (factory == null) {
      return null;
    }
    factory.setAgent(agent);
    return factory.load(location, flags, monitor);
  }
  
  protected String getBundleId()
  {
    return "org.eclipse.equinox.p2.artifact.repository";
  }
  
  protected String getDefaultSuffix()
  {
    return "artifacts.xml";
  }
  
  protected String getRepositoryProviderExtensionPointId()
  {
    return "org.eclipse.equinox.p2.artifact.repository.artifactRepositories";
  }
  
  protected String getRepositorySystemProperty()
  {
    return "eclipse.p2.artifactRepository";
  }
  
  protected int getRepositoryType()
  {
    return 1;
  }
  
  public IArtifactRepository loadRepository(URI location, IProgressMonitor monitor)
    throws ProvisionException
  {
    return loadRepository(location, 0, monitor);
  }
  
  public IArtifactRepository loadRepository(URI location, int flags, IProgressMonitor monitor)
    throws ProvisionException
  {
    return (IArtifactRepository)loadRepository(location, monitor, null, flags);
  }
  
  public IArtifactRepository refreshRepository(URI location, IProgressMonitor monitor)
    throws ProvisionException
  {
    return (IArtifactRepository)basicRefreshRepository(location, monitor);
  }
  
  protected String[] getPreferredRepositorySearchOrder(LocationProperties properties)
  {
    return properties.getArtifactFactorySearchOrder();
  }
  
  protected void restoreSpecialRepositories()
  {
    IAgentLocation location = (IAgentLocation)getAgent().getService(IAgentLocation.SERVICE_NAME);
    if (location == null) {
      return;
    }
    URI cacheLocation = URIUtil.append(location.getDataArea("org.eclipse.equinox.p2.core"), "cache/");
    try
    {
      loadRepository(cacheLocation, null);
      return;
    }
    catch (ProvisionException e)
    {
      if (e.getStatus().getCode() != 1000) {
        LogHelper.log(new Status(4, "org.eclipse.equinox.p2.artifact.repository", "Error occurred while loading download cache.", e));
      }
      try
      {
        Map<String, String> properties = new HashMap(1);
        properties.put("p2.system", Boolean.TRUE.toString());
        createRepository(cacheLocation, "download cache", "org.eclipse.equinox.p2.artifact.repository.simpleRepository", properties);
      }
      catch (ProvisionException e)
      {
        LogHelper.log(e);
      }
    }
  }
}

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

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.internal.p2.repository.Transport;
import org.eclipse.equinox.p2.metadata.IArtifactKey;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRequest;

public abstract class ArtifactRequest
  implements IArtifactRequest
{
  private static final Status DEFAULT_STATUS = new Status(4, "org.eclipse.equinox.p2.artifact.repository", "default");
  protected IArtifactKey artifact;
  protected String resolvedKey;
  protected IArtifactRepository source;
  protected IStatus result = DEFAULT_STATUS;
  protected Transport transport = null;
  
  public ArtifactRequest(IArtifactKey key, Transport transport)
  {
    artifact = key;
    this.transport = transport;
  }
  
  public IArtifactKey getArtifactKey()
  {
    return artifact;
  }
  
  public IStatus getResult()
  {
    if (result == DEFAULT_STATUS) {
      return new Status(4, "org.eclipse.equinox.p2.artifact.repository", "No repository found containing: " + getArtifactKey().toString());
    }
    return result;
  }
  
  protected IArtifactRepository getSourceRepository()
  {
    return source;
  }
  
  public abstract void perform(IArtifactRepository paramIArtifactRepository, IProgressMonitor paramIProgressMonitor);
  
  protected void setResult(IStatus value)
  {
    result = value;
  }
  
  protected void setSourceRepository(IArtifactRepository value)
  {
    source = value;
  }
}

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

import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;

class CompositeArtifactRepository$ChildInfo
{
  IArtifactRepository repo;
  boolean good = true;
  
  CompositeArtifactRepository$ChildInfo(IArtifactRepository IArtifactRepository)
  {
    repo = IArtifactRepository;
  }
  
  void setBad(boolean bad)
  {
    good = (!bad);
  }
  
  boolean isGood()
  {
    return good;
  }
}

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

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.URIUtil;
import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
import org.eclipse.equinox.internal.p2.persistence.CompositeRepositoryIO;
import org.eclipse.equinox.internal.p2.persistence.CompositeRepositoryState;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.core.ProvisionException;
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.query.QueryUtil;
import org.eclipse.equinox.p2.repository.ICompositeRepository;
import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRequest;
import org.eclipse.equinox.p2.repository.artifact.spi.AbstractArtifactRepository;
import org.eclipse.osgi.util.NLS;

public class CompositeArtifactRepository
  extends AbstractArtifactRepository
  implements ICompositeRepository<IArtifactKey>
{
  public static final String REPOSITORY_TYPE = CompositeArtifactRepository.class.getName();
  private static final Integer REPOSITORY_VERSION = new Integer(1);
  public static final String XML_EXTENSION = ".xml";
  public static final String JAR_EXTENSION = ".jar";
  public static final String CONTENT_FILENAME = "compositeArtifacts";
  public static final String PI_REPOSITORY_TYPE = "compositeArtifactRepository";
  public static final String PROP_ATOMIC_LOADING = "p2.atomic.composite.loading";
  public static final boolean ATOMIC_LOADING_DEFAULT = false;
  private List<URI> childrenURIs = new ArrayList();
  private List<ChildInfo> loadedRepos = new ArrayList();
  private IArtifactRepositoryManager manager;
  private boolean disableSave;
  
  public static CompositeArtifactRepository createMemoryComposite(IProvisioningAgent agent)
  {
    if (agent == null) {
      return null;
    }
    IArtifactRepositoryManager manager = (IArtifactRepositoryManager)agent.getService(IArtifactRepositoryManager.SERVICE_NAME);
    if (manager == null) {
      return null;
    }
    try
    {
      long time = System.currentTimeMillis();
      URI repositoryURI = new URI("memory:" + String.valueOf(time));
      while (manager.contains(repositoryURI)) {
        repositoryURI = new URI("memory:" + String.valueOf(++time));
      }
      CompositeArtifactRepository result = (CompositeArtifactRepository)manager.createRepository(repositoryURI, repositoryURI.toString(), "org.eclipse.equinox.p2.artifact.repository.compositeRepository", null);
      manager.removeRepository(repositoryURI);
      return result;
    }
    catch (ProvisionException e)
    {
      LogHelper.log(e);
    }
    catch (URISyntaxException localURISyntaxException) {}
    return null;
  }
  
  private IArtifactRepositoryManager getManager()
  {
    return manager;
  }
  
  CompositeArtifactRepository(IArtifactRepositoryManager manager, CompositeRepositoryState state, IProgressMonitor monitor)
    throws ProvisionException
  {
    super(manager.getAgent(), state.getName(), state.getType(), state.getVersion(), state.getLocation(), state.getDescription(), state.getProvider(), state.getProperties());
    this.manager = manager;
    SubMonitor sub = SubMonitor.convert(monitor, 100 * state.getChildren().length);
    List<URI> repositoriesToBeRemovedOnFailure = new ArrayList();
    boolean failOnChildFailure = shouldFailOnChildFailure(state);
    URI[] arrayOfURI;
    int j = (arrayOfURI = state.getChildren()).length;
    for (int i = 0; i < j; i++)
    {
      URI child = arrayOfURI[i];
      addChild(child, false, sub.newChild(100), failOnChildFailure, repositoriesToBeRemovedOnFailure);
    }
  }
  
  protected CompositeArtifactRepository(IArtifactRepositoryManager manager, URI location, String repositoryName, Map<String, String> properties)
  {
    super(manager.getAgent(), repositoryName, REPOSITORY_TYPE, REPOSITORY_VERSION.toString(), location, null, null, properties);
    this.manager = manager;
    save();
  }
  
  public CompositeRepositoryState toState()
  {
    CompositeRepositoryState result = new CompositeRepositoryState();
    result.setName(getName());
    result.setType(getType());
    result.setVersion(getVersion());
    result.setLocation(getLocation());
    result.setDescription(getDescription());
    result.setProvider(getProvider());
    result.setProperties(getProperties());
    
    result.setChildren((URI[])childrenURIs.toArray(new URI[childrenURIs.size()]));
    return result;
  }
  
  private static <T> boolean add(List<T> list, T obj)
  {
    return list.contains(obj) ? false : list.add(obj);
  }
  
  public static URI getActualLocation(URI base, boolean compress)
  {
    return getActualLocation(base, compress ? ".jar" : ".xml");
  }
  
  private static URI getActualLocation(URI base, String extension)
  {
    return URIUtil.append(base, "compositeArtifacts" + extension);
  }
  
  private boolean isLocal()
  {
    return "file".equalsIgnoreCase(getLocation().getScheme());
  }
  
  public boolean isModifiable()
  {
    return isLocal();
  }
  
  public void addChild(URI childURI)
  {
    try
    {
      addChild(childURI, true, null, false, null);
    }
    catch (ProvisionException localProvisionException) {}
  }
  
  private void addChild(URI childURI, boolean save, IProgressMonitor monitor, boolean propagateException, List<URI> repositoriesToBeRemovedOnFailure)
    throws ProvisionException
  {
    SubMonitor sub = SubMonitor.convert(monitor);
    URI absolute = URIUtil.makeAbsolute(childURI, getLocation());
    if ((childrenURIs.contains(childURI)) || (childrenURIs.contains(absolute)))
    {
      sub.done();
      return;
    }
    childrenURIs.add(childURI);
    if (save) {
      save();
    }
    try
    {
      boolean currentLoaded = getManager().contains(absolute);
      IArtifactRepository repo = load(childURI, sub);
      if ((!currentLoaded) && (propagateException)) {
        repositoriesToBeRemovedOnFailure.add(absolute);
      }
      loadedRepos.add(new ChildInfo(repo));
    }
    catch (ProvisionException e)
    {
      LogHelper.log(e);
      if (propagateException)
      {
        removeFromRepoManager(repositoriesToBeRemovedOnFailure);
        String msg = NLS.bind(Messages.io_failedRead, getLocation());
        throw new ProvisionException(new Status(4, "org.eclipse.equinox.p2.artifact.repository", 1002, msg, e));
      }
    }
  }
  
  public void removeChild(URI childURI)
  {
    boolean removed = childrenURIs.remove(childURI);
    
    URI other = childURI.isAbsolute() ? URIUtil.makeRelative(childURI, getLocation()) : URIUtil.makeAbsolute(childURI, getLocation());
    if (!removed) {
      removed = childrenURIs.remove(other);
    }
    if (removed)
    {
      ChildInfo found = null;
      for (Iterator localIterator = loadedRepos.iterator(); localIterator.hasNext();)
      {
        ChildInfo current = (ChildInfo)localIterator.next();
        URI repoLocation = repo.getLocation();
        if ((URIUtil.sameURI(childURI, repoLocation)) || (URIUtil.sameURI(other, repoLocation)))
        {
          found = current;
          break;
        }
      }
      if (found != null) {
        loadedRepos.remove(found);
      }
      save();
    }
  }
  
  public void removeAllChildren()
  {
    childrenURIs.clear();
    loadedRepos.clear();
    save();
  }
  
  public List<URI> getChildren()
  {
    List<URI> result = new ArrayList();
    for (Iterator localIterator = childrenURIs.iterator(); localIterator.hasNext();)
    {
      URI uri = (URI)localIterator.next();
      result.add(URIUtil.makeAbsolute(uri, getLocation()));
    }
    return result;
  }
  
  public List<IArtifactRepository> getLoadedChildren()
  {
    List<IArtifactRepository> result = new ArrayList(loadedRepos.size());
    for (Iterator localIterator = loadedRepos.iterator(); localIterator.hasNext();)
    {
      ChildInfo info = (ChildInfo)localIterator.next();
      result.add(repo);
    }
    return result;
  }
  
  public synchronized void addDescriptor(IArtifactDescriptor descriptor, IProgressMonitor monitor)
  {
    throw new UnsupportedOperationException(Messages.exception_unsupportedAddToComposite);
  }
  
  public void addDescriptors(IArtifactDescriptor[] descriptors, IProgressMonitor monitor)
  {
    throw new UnsupportedOperationException(Messages.exception_unsupportedAddToComposite);
  }
  
  public void removeDescriptor(IArtifactKey key, IProgressMonitor monitor)
  {
    throw new UnsupportedOperationException(Messages.exception_unsupportedRemoveFromComposite);
  }
  
  public void removeDescriptors(IArtifactKey[] keys, IProgressMonitor monitor)
  {
    throw new UnsupportedOperationException(Messages.exception_unsupportedRemoveFromComposite);
  }
  
  public void removeDescriptor(IArtifactDescriptor descriptor, IProgressMonitor monitor)
  {
    throw new UnsupportedOperationException(Messages.exception_unsupportedRemoveFromComposite);
  }
  
  public void removeDescriptors(IArtifactDescriptor[] descriptors, IProgressMonitor monitor)
  {
    throw new UnsupportedOperationException(Messages.exception_unsupportedRemoveFromComposite);
  }
  
  public synchronized void removeAll(IProgressMonitor monitor)
  {
    throw new UnsupportedOperationException(Messages.exception_unsupportedRemoveFromComposite);
  }
  
  public OutputStream getOutputStream(IArtifactDescriptor descriptor)
  {
    throw new UnsupportedOperationException(Messages.exception_unsupportedGetOutputStream);
  }
  
  public boolean contains(IArtifactKey key)
  {
    for (Iterator localIterator = loadedRepos.iterator(); localIterator.hasNext();)
    {
      ChildInfo current = (ChildInfo)localIterator.next();
      if ((current.isGood()) && (repo.contains(key))) {
        return true;
      }
    }
    return false;
  }
  
  public boolean contains(IArtifactDescriptor descriptor)
  {
    for (Iterator localIterator = loadedRepos.iterator(); localIterator.hasNext();)
    {
      ChildInfo current = (ChildInfo)localIterator.next();
      if ((current.isGood()) && (repo.contains(descriptor))) {
        return true;
      }
   
1 2 3 4 5 6 7 8 9 10

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