org.eclipse.equinox.p2.metadata.repository_1.2.0.v20110815-1419

16:44:15.015 INFO  jd.cli.Main - Decompiling org.eclipse.equinox.p2.metadata.repository_1.2.0.v20110815-1419.jar
package org.eclipse.equinox.internal.p2.metadata.repository;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

public class Activator
  implements BundleActivator
{
  public static final String ID = "org.eclipse.equinox.p2.metadata.repository";
  public static final String REPO_PROVIDER_XPT = "org.eclipse.equinox.p2.metadata.repository.metadataRepositories";
  private static BundleContext bundleContext;
  
  public static BundleContext getContext()
  {
    return bundleContext;
  }
  
  public void start(BundleContext aContext)
    throws Exception
  {
    bundleContext = aContext;
  }
  
  public void stop(BundleContext aContext)
    throws Exception
  {
    bundleContext = null;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.p2.metadata.repository.Activator
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.p2.metadata.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.Collection;
import java.util.Collections;
import java.util.HashSet;
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.NullProgressMonitor;
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.IPool;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.core.WeakPool;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.Version;
import org.eclipse.equinox.p2.metadata.index.IIndex;
import org.eclipse.equinox.p2.metadata.index.IIndexProvider;
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.IRepositoryReference;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
import org.eclipse.equinox.p2.repository.metadata.spi.AbstractMetadataRepository;
import org.eclipse.equinox.p2.repository.metadata.spi.AbstractMetadataRepository.RepositoryState;
import org.eclipse.osgi.util.NLS;

public class CompositeMetadataRepository
  extends AbstractMetadataRepository
  implements ICompositeRepository<IInstallableUnit>, IIndexProvider<IInstallableUnit>
{
  public static final String REPOSITORY_TYPE = CompositeMetadataRepository.class.getName();
  public static final String PI_REPOSITORY_TYPE = "compositeMetadataRepository";
  public static final String PROP_ATOMIC_LOADING = "p2.atomic.composite.loading";
  public static final boolean ATOMIC_LOADING_DEFAULT = false;
  private static final Integer REPOSITORY_VERSION = new Integer(1);
  public static final String XML_EXTENSION = ".xml";
  private static final String JAR_EXTENSION = ".jar";
  private List<URI> childrenURIs = new ArrayList();
  private List<IMetadataRepository> loadedRepos = new ArrayList();
  private IMetadataRepositoryManager manager;
  private IPool<IInstallableUnit> iuPool = new WeakPool();
  
  public static CompositeMetadataRepository createMemoryComposite(IProvisioningAgent agent)
  {
    if (agent == null) {
      return null;
    }
    IMetadataRepositoryManager repoManager = (IMetadataRepositoryManager)agent.getService(IMetadataRepositoryManager.SERVICE_NAME);
    if (repoManager == null) {
      return null;
    }
    try
    {
      long time = System.currentTimeMillis();
      URI repositoryURI = new URI("memory:" + String.valueOf(time));
      while (repoManager.contains(repositoryURI)) {
        repositoryURI = new URI("memory:" + String.valueOf(++time));
      }
      CompositeMetadataRepository result = (CompositeMetadataRepository)repoManager.createRepository(repositoryURI, repositoryURI.toString(), "org.eclipse.equinox.p2.metadata.repository.compositeRepository", null);
      repoManager.removeRepository(repositoryURI);
      return result;
    }
    catch (ProvisionException e)
    {
      LogHelper.log(e);
    }
    catch (URISyntaxException localURISyntaxException) {}
    return null;
  }
  
  private IMetadataRepositoryManager getManager()
  {
    return manager;
  }
  
  private boolean isLocal()
  {
    return "file".equalsIgnoreCase(getLocation().getScheme());
  }
  
  public boolean isModifiable()
  {
    return isLocal();
  }
  
  CompositeMetadataRepository(IMetadataRepositoryManager 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);
    }
  }
  
  CompositeMetadataRepository(IMetadataRepositoryManager manager, URI location, String name, Map<String, String> properties)
  {
    super(manager.getAgent(), name == null ? "" : location != null ? location.toString() : name, 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;
  }
  
  public IQueryResult<IInstallableUnit> query(IQuery<IInstallableUnit> query, IProgressMonitor monitor)
  {
    if (monitor == null) {
      monitor = new NullProgressMonitor();
    }
    try
    {
      IQueryable<IInstallableUnit> queryable = QueryUtil.compoundQueryable(loadedRepos);
      return queryable.query(query, monitor);
    }
    finally
    {
      if (monitor != null) {
        monitor.done();
      }
    }
  }
  
  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);
      IMetadataRepository currentRepo = getManager().loadRepository(absolute, sub);
      if (!currentLoaded)
      {
        getManager().setEnabled(absolute, false);
        
        getManager().setRepositoryProperty(absolute, "p2.system", String.valueOf(true));
        if (propagateException) {
          repositoriesToBeRemovedOnFailure.add(absolute);
        }
      }
      currentRepo.compress(iuPool);
      
      loadedRepos.add(currentRepo);
    }
    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.metadata.repository", 1002, msg, e));
      }
    }
  }
  
  public void addChild(URI childURI)
  {
    try
    {
      addChild(childURI, true, null, false, null);
    }
    catch (ProvisionException localProvisionException) {}
  }
  
  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)
    {
      IMetadataRepository found = null;
      for (Iterator localIterator = loadedRepos.iterator(); localIterator.hasNext();)
      {
        IMetadataRepository current = (IMetadataRepository)localIterator.next();
        URI repoLocation = current.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 void addInstallableUnits(Collection<IInstallableUnit> installableUnits)
  {
    throw new UnsupportedOperationException("Cannot add IUs to a composite repository");
  }
  
  public synchronized void removeAll()
  {
    throw new UnsupportedOperationException("Cannot remove IUs from a composite repository");
  }
  
  public boolean removeInstallableUnits(Collection<IInstallableUnit> installableUnits)
  {
    throw new UnsupportedOperationException("Cannot remove IUs from a composite repository");
  }
  
  private static File getActualLocation(URI location, String extension)
  {
    File spec = URIUtil.toFile(location);
    String path = spec.getAbsolutePath();
    if (path.endsWith("compositeContent" + extension)) {
      return spec;
    }
    if (path.endsWith("/")) {
      path = path + "compositeContent";
    } else {
      path = path + "/compositeContent";
    }
    return new File(path + extension);
  }
  
  public static File getActualLocation(URI location)
  {
    return getActualLocation(location, ".xml");
  }
  
  public synchronized void addReferences(Collection<? extends IRepositoryReference> references)
  {
    throw new UnsupportedOperationException("Cannot add References to a composite repository");
  }
  
  public Collection<IRepositoryReference> getReferences()
  {
    HashSet<IRepositoryReference> allRefs = new HashSet();
    for (Iterator localIterator = loadedRepos.iterator(); localIterator.hasNext();)
    {
      IMetadataRepository child = (IMetadataRepository)localIterator.next();
      allRefs.addAll(child.getReferences());
    }
    return allRefs;
  }
  
  private void save()
  {
    if (!isModifiable()) {
      return;
    }
    File file = getActualLocation(getLocation());
    File jarFile = getActualLocation(getLocation(), ".jar");
    boolean compress = "true".equalsIgnoreCase(getProperty("p2.compressed"));
    try
    {
      OutputStream output = null;
      if (!compress)
      {
        if (jarFile.exists()) {
          jarFile.delete();
        }
        if (!file.exists())
        {
          if (!file.getParentFile().exists()) {
            file.getParentFile().mkdirs();
          }
          file.createNewFile();
        }
        output = new FileOutputStream(file);
      }
      else
      {
        if (file.exists()) {
          file.delete();
        }
        if (!jarFile.exists())
        {
          if (!jarFile.getParentFile().exists()) {
            jarFile.getParentFile().mkdirs();
          }
          jarFile.createNewFile();
        }
        JarEntry jarEntry = new JarEntry(file.getName());
        JarOutputStream jOutput = new JarOutputStream(new FileOutputStream(jarFile));
        jOutput.putNextEntry(jarEntry);
        output = jOutput;
      }
      super.setProperty("p2.timestamp", Long.toString(System.currentTimeMillis()));
      new CompositeRepositoryIO().write(toState(), output, "compositeMetadataRepository");
    }
    catch (IOException e)
    {
      LogHelper.log(new Status(4, "org.eclipse.equinox.p2.metadata.repository", 1003, NLS.bind(Messages.io_failedWrite, getLocation()), e));
    }
  }
  
  public List<URI> getChildren()
  {
    List<URI> result = new ArrayList();
    for (Iterator localIterator = childrenURIs.iterator(); localIterator.hasNext();)
    {
      URI childURI = (URI)localIterator.next();
      result.add(URIUtil.makeAbsolute(childURI, getLocation()));
    }
    return result;
  }
  
  public static URI getActualLocationURI(URI base, String extension)
  {
    if (extension == null) {
      extension = ".xml";
    }
    return URIUtil.append(base, "compositeContent" + extension);
  }
  
  public void initialize(AbstractMetadataRepository.RepositoryState state)
  {
    setName(Name);
    setType(Type);
    setVersion(Version.toString());
    setProvider(Provider);
    setDescription(Description);
    setLocation(Location);
    setProperties(Properties);
  }
  
  public IIndex<IInstallableUnit> getIndex(String memberName)
  {
    IQueryable<IInstallableUnit> queryable = QueryUtil.compoundQueryable(loadedRepos);
    if ((queryable instanceof IIndexProvider)) {
      return ((IIndexProvider)queryable).getIndex(memberName);
    }
    return null;
  }
  
  public Iterator<IInstallableUnit> everything()
  {
    IQueryable<IInstallableUnit> queryable = QueryUtil.compoundQueryable(loadedRepos);
    if ((queryable instanceof IIndexProvider)) {
      return ((IIndexProvider)queryable).everything();
    }
    return Collections.EMPTY_LIST.iterator();
  }
  
  public Object getManagedProperty(Object client, String memberName, Object key)
  {
    IQueryable<IInstallableUnit> queryable = QueryUtil.compoundQueryable(loadedRepos);
    if ((queryable instanceof IIndexProvider)) {
      return ((IIndexProvider)queryable).getManagedProperty(client, memberName, key);
    }
    return null;
  }
  
  private void removeFromRepoManager(List<URI> currentLoadedRepositories)
  {
    if (currentLoadedRepositories == null) {
      return;
    }
    for (Iterator localIterator = currentLoadedRepositories.iterator(); localIterator.hasNext();)
    {
      URI loadedChild = (URI)localIterator.next();
      manager.removeRepository(loadedChild);
    }
  }
  
  private boolean shouldFailOnChildFailure(CompositeRepositoryState state)
  {
    Map<String, String> repoProperties = state.getProperties();
    boolean failOnChildFailure = false;
    if (repoProperties != null)
    {
      String value = (String)repoProperties.get("p2.atomic.composite.loading");
      if (value != null) {
        failOnChildFailure = Boolean.valueOf(value).booleanValue();
      }
    }
    return failOnChildFailure;
  }
}

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

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.util.Map;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.URIUtil;
import org.eclipse.equinox.internal.p2.repository.CacheManager;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
import org.eclipse.equinox.p2.repository.metadata.spi.MetadataRepositoryFactory;
import org.eclipse.osgi.util.NLS;

public class CompositeMetadataRepositoryFactory
  extends MetadataRepositoryFactory
{
  private static final String JAR_EXTENSION = ".jar";
  private static final String XML_EXTENSION = ".xml";
  private static final String PROTOCOL_FILE = "file";
  public static final String CONTENT_FILENAME = "compositeContent";
  
  public IMetadataRepository create(URI location, String name, String type, Map<String, String> properties)
  {
    return new CompositeMetadataRepository(getManager(), location, name, properties);
  }
  
  private IMetadataRepositoryManager getManager()
  {
    if (getAgent() != null) {
      return (IMetadataRepositoryManager)getAgent().getService(IMetadataRepositoryManager.SERVICE_NAME);
    }
    return null;
  }
  
  private File getLocalFile(URI location, IProgressMonitor monitor)
    throws IOException, ProvisionException
  {
    File localFile = null;
    URI jarLocation = CompositeMetadataRepository.getActualLocationURI(location, ".jar");
    URI xmlLocation = CompositeMetadataRepository.getActualLocationURI(location, ".xml");
    if ("file".equals(xmlLocation.getScheme()))
    {
      localFile = URIUtil.toFile(jarLocation);
      if (localFile.exists()) {
        return localFile;
      }
      localFile = URIUtil.toFile(xmlLocation);
      if (localFile.exists()) {
        return localFile;
      }
      String msg = NLS.bind(Messages.io_failedRead, location);
      throw new ProvisionException(new Status(4, "org.eclipse.equinox.p2.metadata.repository", 1000, msg, null));
    }
    CacheManager cache = (CacheManager)getAgent().getService(CacheManager.SERVICE_NAME);
    if (cache == null) {
      throw new IllegalArgumentException("Cache manager service not available");
    }
    localFile = cache.createCache(location, "compositeContent", monitor);
    if (localFile == null)
    {
      String msg = NLS.bind(Messages.io_failedRead, location);
      throw new ProvisionException(new Status(4, "org.eclipse.equinox.p2.metadata.repository", 1000, msg, null));
    }
    return localFile;
  }
  
  /* Error */
  public IMetadataRepository load(URI location, int flags, IProgressMonitor monitor)
    throws ProvisionException
  {
    // Byte code:
    //   0: lconst_0
    //   1: lstore 4
    //   3: getstatic 238	org/eclipse/equinox/internal/p2/core/helpers/Tracing:DEBUG_METADATA_PARSING	Z
    //   6: ifeq +28 -> 34
    //   9: new 128	java/lang/StringBuffer
    //   12: dup
    //   13: ldc 4
    //   15: invokespecial 254	java/lang/StringBuffer:<init>	(Ljava/lang/String;)V
    //   18: aload_1
    //   19: invokevirtual 256	java/lang/StringBuffer:append	(Ljava/lang/Object;)Ljava/lang/StringBuffer;
    //   22: invokevirtual 253	java/lang/StringBuffer:toString	()Ljava/lang/String;
    //   25: invokestatic 267	org/eclipse/equinox/internal/p2/core/helpers/Tracing:debug	(Ljava/lang/String;)V
    //   28: invokestatic 257	java/lang/System:currentTimeMillis	()J
    //   31: lneg
    //   32: lstore 4
    //   34: aload_3
    //   35: sipush 400
    //   38: invokestatic 265	org/eclipse/core/runtime/SubMonitor:convert	(Lorg/eclipse/core/runtime/IProgressMonitor;I)Lorg/eclipse/core/runtime/SubMonitor;
    //   41: astore 6
    //   43: ldc 9
    //   45: aload_1
    //   46: invokevirtual 258	java/net/URI:getScheme	()Ljava/lang/String;
    //   49: invokevirtual 251	java/lang/String:equals	(Ljava/lang/Object;)Z
    //   52: ifne +21 -> 73
    //   55: iload_2
    //   56: iconst_1
    //   57: iand
    //   58: ifle +15 -> 73
    //   61: aload_3
    //   62: ifnull +9 -> 71
    //   65: aload_3
    //   66: invokeinterface 283 1 0
    //   71: aconst_null
    //   72: areturn
    //   73: aload_0
    //   74: aload_1
    //   75: aload 6
    //   77: bipush 100
    //   79: invokevirtual 263	org/eclipse/core/runtime/SubMonitor:newChild	(I)Lorg/eclipse/core/runtime/SubMonitor;
    //   82: invokespecial 274	org/eclipse/equinox/internal/p2/metadata/repository/CompositeMetadataRepositoryFactory:getLocalFile	(Ljava/net/URI;Lorg/eclipse/core/runtime/IProgressMonitor;)Ljava/io/File;
    //   85: astore 7
    //   87: new 120	java/io/BufferedInputStream
    //   90: dup
    //   91: new 122	java/io/FileInputStream
    //   94: dup
    //   95: aload 7
    //   97: invokespecial 247	java/io/FileInputStream:<init>	(Ljava/io/File;)V
    //   100: invokespecial 243	java/io/BufferedInputStream:<init>	(Ljava/io/InputStream;)V
    //   103: astore 8
    //   105: aconst_null
    //   106: astore 9
    //   108: aload 7
    //   110: invokevirtual 245	java/io/File:getAbsolutePath	()Ljava/lang/String;
    //   113: ldc 1
    //   115: invokevirtual 252	java/lang/String:endsWith	(Ljava/lang/String;)Z
    //   118: ifeq +73 -> 191
    //   121: new 132	java/util/jar/JarInputStream
    //   124: dup
    //   125: aload 8
    //   127: invokespecial 260	java/util/jar/JarInputStream:<init>	(Ljava/io/InputStream;)V
    //   130: astore 9
    //   132: aload 9
    //   134: invokevirtual 261	java/util/jar/JarInputStream:getNextJarEntry	()Ljava/util/jar/JarEntry;
    //   137: astore 10
    //   139: ldc 7
    //   141: astore 11
    //   143: goto +10 -> 153
    //   146: aload 9
    //   148: invokevirtual 261	java/util/jar/JarInputStream:getNextJarEntry	()Ljava/util/jar/JarEntry;
    //   151: astore 10
    //   153: aload 10
    //   155: ifnull +16 -> 171
    //   158: aload 11
    //   160: aload 10
    //   162: invokevirtual 259	java/util/jar/JarEntry:getName	()Ljava/lang/String;
    //   165: invokevirtual 251	java/lang/String:equals	(Ljava/lang/Object;)Z
    //   168: ifeq -22 -> 146
    //   171: aload 10
    //   173: ifnonnull +18 -> 191
    //   176: new 124	java/io/IOException
    //   179: dup
    //   180: getstatic 240	org/eclipse/equinox/internal/p2/metadata/repository/Messages:repoMan_invalidLocation	Ljava/lang/String;
    //   183: aload_1
    //   184: invokestatic 282	org/eclipse/osgi/util/NLS:bind	(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/String;
    //   187: invokespecial 248	java/io/IOException:<init>	(Ljava/lang/String;)V
    //   190: athrow
    //   191: aload 6
    //   193: sipush 300
    //   196: invokevirtual 264	org/eclipse/core/runtime/SubMonitor:setWorkRemaining	(I)Lorg/eclipse/core/runtime/SubMonitor;
    //   199: pop
    //   200: aload 9
    //   202: ifnull +8 -> 210
    //   205: aload 9
    //   207: goto +5 -> 212
    //   210: aload 8
    //   212: astore 10
    //   214: new 141	org/eclipse/equinox/internal/p2/persistence/CompositeRepositoryIO
    //   217: dup
    //   218: invokespecial 275	org/eclipse/equinox/internal/p2/persistence/CompositeRepositoryIO:<init>	()V
    //   221: astore 11
    //   223: aload 11
    //   225: aload 7
    //   227: invokevirtual 246	java/io/File:toURL	()Ljava/net/URL;
    //   230: aload 10
    //   232: ldc 8
    //   234: aload 6
    //   236: bipush 100
    //   238: invokevirtual 263	org/eclipse/core/runtime/SubMonitor:newChild	(I)Lorg/eclipse/core/runtime/SubMonitor;
    //   241: invokevirtual 276	org/eclipse/equinox/internal/p2/persistence/CompositeRepositoryIO:read	(Ljava/net/URL;Ljava/io/InputStream;Ljava/lang/String;Lorg/eclipse/core/runtime/IProgressMonitor;)Lorg/eclipse/equinox/internal/p2/persistence/CompositeRepositoryState;
    //   244: astore 12
    //   246: aload 12
    //   248: invokevirtual 277	org/eclipse/equinox/internal/p2/persistence/CompositeRepositoryState:getLocation	()Ljava/net/URI;
    //   251: ifnonnull +9 -> 260
    //   254: aload 12
    //   256: aload_1
    //   257: invokevirtual 278	org/eclipse/equinox/internal/p2/persistence/CompositeRepositoryState:setLocation	(Ljava/net/URI;)V
    //   260: new 138	org/eclipse/equinox/internal/p2/metadata/repository/CompositeMetadataRepository
    //   263: dup
    //   264: aload_0
    //   265: invokespecial 273	org/eclipse/equinox/internal/p2/metadata/repository/CompositeMetadataRepositoryFactory:getManager	()Lorg/eclipse/equinox/p2/repository/metadata/IMetadataRepositoryManager;
    //   268: aload 12
    //   270: aload 6
    //   272: sipush 200
    //   275: invokevirtual 263	org/eclipse/core/runtime/SubMonitor:newChild	(I)Lorg/eclipse/core/runtime/SubMonitor;
    //   278: invokespecial 269	org/eclipse/equinox/internal/p2/metadata/repository/CompositeMetadataRepository:<init>	(Lorg/eclipse/equinox/p2/repository/metadata/IMetadataRepositoryManager;Lorg/eclipse/equinox/internal/p2/persistence/CompositeRepositoryState;Lorg/eclipse/core/runtime/IProgressMonitor;)V
    //   281: astore 13
    //   283: getstatic 238	org/eclipse/equinox/internal/p2/core/helpers/Tracing:DEBUG_METADATA_PARSING	Z
    //   286: ifeq +31 -> 317
    //   289: lload 4
    //   291: invokestatic 257	java/lang/System:currentTimeMillis	()J
    //   294: ladd
    //   295: lstore 4
    //   297: new 128	java/lang/StringBuffer
    //   300: dup
    //   301: ldc 5
    //   303: invokespecial 254	java/lang/StringBuffer:<init>	(Ljava/lang/String;)V
    //   306: lload 4
    //   308: invokevirtual 255	java/lang/StringBuffer:append	(J)Ljava/lang/StringBuffer;
    //   311: invokevirtual 253	java/lang/StringBuffer:toString	()Ljava/lang/String;
    //   314: invokestatic 267	org/eclipse/equinox/internal/p2/core/helpers/Tracing:debug	(Ljava/lang/String;)V
    //   317: aload 13
    //   319: astore 15
    //   321: aload_0
    //   322: aload 9
    //   324: invokespecial 271	org/eclipse/equinox/internal/p2/metadata/repository/CompositeMetadataRepositoryFactory:safeClose	(Ljava/io/InputStream;)V
    //   327: aload_0
    //   328: aload 8
    //   330: invokespecial 271	org/eclipse/equinox/internal/p2/metadata/repository/CompositeMetadataRepositoryFactory:safeClose	(Ljava/io/InputStream;)V
    //   333: aload_3
    //   334: ifnull +9 -> 343
    //   337: aload_3
    //   338: invokeinterface 283 1 0
    //   343: aload 15
    //   345: areturn
    //   346: astore 14
    //   348: aload_0
    //   349: aload 9
    //   351: invokespecial 271	org/eclipse/equinox/internal/p2/metadata/repository/CompositeMetadataRepositoryFactory:safeClose	(Ljava/io/InputStream;)V
    //   354: aload_0
    //   355: aload 8
    //   357: invokespecial 271	org/eclipse/equinox/internal/p2/metadata/repository/CompositeMetadataRepositoryFactory:safeClose	(Ljava/io/InputStream;)V
    //   360: aload 14
    //   362: athrow
    //   363: astore 7
    //   365: getstatic 239	org/eclipse/equinox/internal/p2/metadata/repository/Messages:io_failedRead	Ljava/lang/String;
    //   368: aload_1
    //   369: invokestatic 282	org/eclipse/osgi/util/NLS:bind	(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/String;
    //   372: astore 8
    //   374: new 145	org/eclipse/equinox/p2/core/ProvisionException
    //   377: dup
    //   378: new 134	org/eclipse/core/runtime/Status
    //   381: dup
    //   382: iconst_4
    //   383: ldc 10
    //   385: sipush 1000
    //   388: aload 8
    //   390: aload 7
    //   392: invokespecial 262	org/eclipse/core/runtime/Status:<init>	(ILjava/lang/String;ILjava/lang/String;Ljava/lang/Throwable;)V
    //   395: invokespecial 280	org/eclipse/equinox/p2/core/ProvisionException:<init>	(Lorg/eclipse/core/runtime/IStatus;)V
    //   398: athrow
    //   399: astore 7
    //   401: getstatic 239	org/eclipse/equinox/internal/p2/metadata/repository/Messages:io_failedRead	Ljava/lang/String;
    //   404: aload_1
    //   405: invokestatic 282	org/eclipse/osgi/util/NLS:bind	(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/String;
    //   408: astore 8
    //   410: new 145	org/eclipse/equinox/p2/core/ProvisionException
    //   413: dup
    //   414: new 134	org/eclipse/core/runtime/Status
    //   417: dup
    //   418: iconst_4
    //   419: ldc 10
    //   421: sipush 1002
    //   424: aload 8
    //   426: aload 7
    //   428: invokespecial 262	org/eclipse/core/runtime/Status:<init>	(ILjava/lang/String;ILjava/lang/String;Ljava/lang/Throwable;)V
    //   431: invokespecial 280	org/eclipse/equinox/p2/core/ProvisionException:<init>	(Lorg/eclipse/core/runtime/IStatus;)V
    //   434: athrow
    //   435: astore 16
    //   437: aload_3
    //   438: ifnull +9 -> 447
    //   441: aload_3
    //   442: invokeinterface 283 1 0
    //   447: aload 16
    //   449: athrow
    // Line number table:
    //   Java source line #86	-> byte code offset #0
    //   Java source line #88	-> byte code offset #3
    //   Java source line #89	-> byte code offset #9
    //   Java source line #90	-> byte code offset #28
    //   Java source line #92	-> byte code offset #34
    //   Java source line #95	-> byte code offset #43
    //   Java source line #139	-> byte code offset #61
    //   Java source line #140	-> byte code offset #65
    //   Java source line #96	-> byte code offset #71
    //   Java source line #98	-> byte code offset #73
    //   Java source line #99	-> byte code offset #87
    //   Java source line #100	-> byte code offset #105
    //   Java source line #103	-> byte code offset #108
    //   Java source line #104	-> byte code offset #121
    //   Java source line #105	-> byte code offset #132
    //   Java source line #106	-> byte code offset #139
    //   Java source line #107	-> byte code offset #143
    //   Java source line #108	-> byte code offset #146
    //   Java source line #107	-> byte code offset #153
    //   Java source line #111	-> byte code offset #171
    //   Java source line #112	-> byte code offset #176
    //   Java source line #115	-> byte code offset #191
    //   Java source line #116	-> byte code offset #200
    //   Java source line #117	-> byte code offset #214
    //   Java source line #118	-> byte code offset #223
    //   Java source line #119	-> byte code offset #246
    //   Java source line #120	-> byte code offset #254
    //   Java source line #122	-> byte code offset #260
    //   Java source line #123	-> byte code offset #283
    //   Java source line #124	-> byte code offset #289
    //   Java source line #125	-> byte code offset #297
    //   Java source line #127	-> byte code offset #317
    //   Java source line #129	-> byte code offset #321
    //   Java source line #130	-> byte code offset #327
    //   Java source line #139	-> byte code offset #333
    //   Java source line #140	-> byte code offset #337
    //   Java source line #127	-> byte code offset #343
    //   Java source line #128	-> byte code offset #346
    //   Java source line #129	-> byte code offset #348
    //   Java source line #130	-> byte code offset #354
    //   Java source line #131	-> byte code offset #360
    //   Java source line #132	-> byte code offset #363
    //   Java source line #133	-> byte code offset #365
    //   Java source line #134	-> byte code offset #374
    //   Java source line #135	-> byte code offset #399
    //   Java source line #136	-> byte code offset #401
    //   Java source line #137	-> byte code offset #410
    //   Java source line #138	-> byte code offset #435
    //   Java source line #139	-> byte code offset #437
    //   Java source line #140	-> byte code offset #441
    //   Java source line #141	-> byte code offset #447
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	450	0	this	CompositeMetadataRepositoryFactory
    //   0	450	1	location	URI
    //   0	450	2	flags	int
    //   0	450	3	monitor	IProgressMonitor
    //   1	306	4	time	long
    //   41	230	6	sub	org.eclipse.core.runtime.SubMonitor
    //   85	141	7	localFile	File
    //   346	1	7	localFile	File
    //   363	28	7	e	java.io.FileNotFoundException
    //   399	28	7	e	IOException
    //   103	226	8	inStream	InputStream
    //   346	10	8	inStream	InputStream
    //   372	17	8	msg	String
    //   408	17	8	msg	String
    //   106	217	9	jarStream	java.util.jar.JarInputStream
    //   346	4	9	jarStream	java.util.jar.JarInputStream
    //   137	35	10	jarEntry	java.util.jar.JarEntry
    //   212	19	10	descriptorStream	InputStream
    //   141	18	11	entryName	String
    //   221	3	11	io	org.eclipse.equinox.internal.p2.persistence.CompositeRepositoryIO
    //   244	25	12	resultState	org.eclipse.equinox.internal.p2.persistence.CompositeRepositoryState
    //   281	37	13	result	CompositeMetadataRepository
    //   346	15	14	localObject1	Object
    //   319	25	15	localCompositeMetadataRepository1	CompositeMetadataRepository
    //   435	13	16	localObject2	Object
    // Exception table:
    //   from	to	target	type
    //   108	321	346	finally
    //   43	61	363	java/io/FileNotFoundException
    //   73	333	363	java/io/FileNotFoundException
    //   346	363	363	java/io/FileNotFoundException
    //   43	61	399	java/io/IOException
    //   73	333	399	java/io/IOException
    //   346	363	399	java/io/IOException
    //   43	61	435	finally
    //   73	333	435	finally
    //   346	435	435	finally
  }
  
  private void safeClose(InputStream stream)
  {
    if (stream == null) {
      return;
    }
    try
    {
      stream.close();
    }
    catch (IOException localIOException) {}
  }
}

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

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
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.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.URIUtil;
import org.eclipse.equinox.internal.p2.core.helpers.CollectionUtils;
import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
import org.eclipse.equinox.internal.p2.metadata.IUMap;
import org.eclipse.equinox.internal.p2.metadata.TranslationSupport;
import org.eclipse.equinox.internal.p2.metadata.index.CapabilityIndex;
import org.eclipse.equinox.internal.p2.metadata.index.IdIndex;
import org.eclipse.equinox.internal.p2.metadata.index.IndexProvider;
import org.eclipse.equinox.internal.provisional.p2.core.eventbus.IProvisioningEventBus;
import org.eclipse.equinox.internal.provisional.p2.repository.RepositoryEvent;
import org.eclipse.equinox.p2.core.IPool;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.KeyWithLocale;
import org.eclipse.equinox.p2.metadata.Version;
import org.eclipse.equinox.p2.metadata.index.IIndex;
import org.eclipse.equinox.p2.metadata.index.IIndexProvider;
import org.eclipse.equinox.p2.query.IQuery;
import org.eclipse.equinox.p2.query.IQueryResult;
import org.eclipse.equinox.p2.repository.IRepositoryReference;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
import org.eclipse.equinox.p2.repository.metadata.spi.AbstractMetadataRepository;
import org.eclipse.equinox.p2.repository.metadata.spi.AbstractMetadataRepository.RepositoryState;

public class LocalMetadataRepository
  extends AbstractMetadataRepository
  implements IIndexProvider<IInstallableUnit>
{
  private static final String CONTENT_FILENAME = "content";
  private static final String REPOSITORY_TYPE = LocalMetadataRepository.class.getName();
  private static final Integer REPOSITORY_VERSION = new Integer(1);
  private static final String JAR_EXTENSION = ".jar";
  private static final String XML_EXTENSION = ".xml";
  protected IUMap units = new IUMap();
  protected HashSet<IRepositoryReference> repositories = new HashSet();
  private IIndex<IInstallableUnit> idIndex;
  private IIndex<IInstallableUnit> capabilityIndex;
  private TranslationSupport translationSupport;
  private boolean snapshotNeeded = false;
  private boolean disableSave = false;
  
  private static File getActualLocation(URI location, String extension)
  {
    File spec = URIUtil.toFile(location);
    String path = spec.getAbsolutePath();
    if (path.endsWith("content" + extension)) {
      return spec;
    }
    if (path.endsWith("/")) {
      path = path + "content";
    } else {
      path = path + "/content";
    }
    return new File(path + extension);
  }
  
  public static File getActualLocation(URI location)
  {
    return getActualLocation(location, ".xml");
  }
  
  public LocalMetadataRepository(IProvisioningAgent agent)
  {
    super(agent);
  }
  
  public LocalMetadataRepository(IProvisioningAgent agent, URI location, String name, Map<String, String> properties)
  {
    super(agent, name == null ? "" : location != null ? location.toString() : name, REPOSITORY_TYPE, REPOSITORY_VERSION.toString(), location, null, null, properties);
    if (!location.getScheme().equals("file")) {
      throw new IllegalArgumentException("Invalid local repository location: " + location);
    }
    save();
  }
  
  public synchronized void addInstallableUnits(Collection<IInstallableUnit> installableUnits)
  {
    if ((installableUnits == null) || (installableUnits.isEmpty())) {
      return;
    }
    if (snapshotNeeded)
    {
      units = units.clone();
      idIndex = null;
      snapshotNeeded = false;
    }
    units.addAll(installableUnits);
    capabilityIndex = null;
    save();
  }
  
  public void addReferences(Collection<? extends IRepositoryReference> references)
  {
    assertModifiable();
    if (repositories.addAll(references)) {
      save();
    }
  }
  
  public Collection<IRepositoryReference> getReferences()
  {
    return Collections.unmodifiableCollection(repositories);
  }
  
  public synchronized IIndex<IInstallableUnit> getIndex(String memberName)
  {
    if ("id".equals(memberName))
    {
      snapshotNeeded = true;
      if (idIndex == null) {
        idIndex = new IdIndex(units);
      }
      return idIndex;
    }
    if ("providedCapabilities".equals(memberName))
    {
      snapshotNeeded = true;
      if (capabilityIndex == null) {
        capabilityIndex = new CapabilityIndex(units.iterator());
      }
      return capabilityIndex;
    }
    return null;
  }
  
  public synchronized Object getManagedProperty(Object client, String memberName, Object key)
  {
    if (!(client instanceof IInstallableUnit)) {
      return null;
    }
    IInstallableUnit iu = (IInstallableUnit)client;
    if ("translatedProperties".equals(memberName))
    {
      if (translationSupport == null) {
        translationSupport = new TranslationSupport(this);
      }
      return (key instanceof KeyWithLocale) ? translationSupport.getIUProperty(iu, (KeyWithLocale)key) : translationSupport.getIUProperty(iu, key.toString());
    }
    return null;
  }
  
  public void initialize(AbstractMetadataRepository.RepositoryState state)
  {
    synchronized (this)
    {
      setName(Name);
      setType(Type);
      setVersion(Version.toString());
      setProvider(Provider);
      setDescription(Description);
      setLocation(Location);
      setProperties(Properties);
      units.addAll(Units);
      repositories.addAll(Arrays.asList(Repositories));
    }
    publishRepositoryReferences();
  }
  
  public void publishRepositoryReferences()
  {
    IProvisioningEventBus bus = (IProvisioningEventBus)getProvisioningAgent().getService(IProvisioningEventBus.SERVICE_NAME);
    if (bus == null) {
      return;
    }
    List<IRepositoryReference> reposit
1 2 3 4 5 6 7

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