org.eclipse.equinox.p2.extensionlocation_1.2.100.v20110815-1419

16:44:11.856 INFO  jd.cli.Main - Decompiling org.eclipse.equinox.p2.extensionlocation_1.2.100.v20110815-1419.jar
package org.eclipse.equinox.internal.p2.extensionlocation;

import java.io.File;
import java.net.URI;
import java.net.URL;
import org.eclipse.core.runtime.URIUtil;
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
import org.eclipse.equinox.internal.p2.core.helpers.URLUtil;
import org.eclipse.equinox.internal.p2.touchpoint.eclipse.Util;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.engine.IProfile;
import org.eclipse.equinox.p2.engine.IProfileRegistry;
import org.eclipse.equinox.p2.repository.artifact.IFileArtifactRepository;
import org.eclipse.osgi.service.datalocation.Location;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;

public class Activator
  implements BundleActivator
{
  public static final String ID = "org.eclipse.equinox.p2.extensionlocation";
  private static volatile BundleContext bundleContext;
  
  public void start(BundleContext context)
    throws Exception
  {
    bundleContext = context;
  }
  
  public void stop(BundleContext context)
    throws Exception
  {
    bundleContext = null;
  }
  
  public static BundleContext getContext()
  {
    return bundleContext;
  }
  
  public static File getConfigurationLocation()
  {
    Location configurationLocation = (Location)ServiceHelper.getService(getContext(), Location.class.getName(), Location.CONFIGURATION_FILTER);
    if ((configurationLocation == null) || (!configurationLocation.isSet())) {
      return null;
    }
    URL url = configurationLocation.getURL();
    if (url == null) {
      return null;
    }
    return URLUtil.toFile(url);
  }
  
  public static IProfile getCurrentProfile()
  {
    IProfileRegistry profileRegistry = (IProfileRegistry)getCurrentAgent().getService(IProfileRegistry.SERVICE_NAME);
    return profileRegistry.getProfile("_SELF_");
  }
  
  public static IProvisioningAgent getCurrentAgent()
  {
    ServiceReference<IProvisioningAgent> reference = bundleContext.getServiceReference(IProvisioningAgent.class);
    if (reference == null) {
      return null;
    }
    return (IProvisioningAgent)bundleContext.getService(reference);
  }
  
  public static IFileArtifactRepository getBundlePoolRepository()
  {
    IProfile profile = getCurrentProfile();
    IProvisioningAgent agent = getCurrentAgent();
    if ((profile == null) || (agent == null)) {
      return null;
    }
    return Util.getAggregatedBundleRepository(agent, profile, 3);
  }
  
  public static String getRepositoryName(URI location)
  {
    File file = URIUtil.toFile(location);
    return file == null ? location.toString() : file.getAbsolutePath();
  }
}

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

import java.io.File;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import org.eclipse.equinox.internal.provisional.p2.directorywatcher.DirectoryChangeListener;
import org.eclipse.equinox.p2.metadata.IArtifactKey;
import org.eclipse.equinox.p2.query.IQueryResult;
import org.eclipse.equinox.p2.repository.artifact.ArtifactKeyQuery;
import org.eclipse.equinox.p2.repository.artifact.IFileArtifactRepository;

public class BundlePoolFilteredListener
  extends DirectoryChangeListener
{
  private DirectoryChangeListener delegate;
  private Set<File> bundlePoolFiles = new HashSet();
  
  public BundlePoolFilteredListener(DirectoryChangeListener listener)
  {
    delegate = listener;
    IFileArtifactRepository bundlePool = Activator.getBundlePoolRepository();
    if (bundlePool != null)
    {
      IQueryResult<IArtifactKey> keys = bundlePool.query(ArtifactKeyQuery.ALL_KEYS, null);
      for (Iterator<IArtifactKey> iterator = keys.iterator(); iterator.hasNext();)
      {
        IArtifactKey key = (IArtifactKey)iterator.next();
        File artifactFile = bundlePool.getArtifactFile(key);
        if (artifactFile != null) {
          bundlePoolFiles.add(artifactFile);
        }
      }
    }
  }
  
  public boolean added(File file)
  {
    return delegate.added(file);
  }
  
  public boolean changed(File file)
  {
    return delegate.changed(file);
  }
  
  public Long getSeenFile(File file)
  {
    return delegate.getSeenFile(file);
  }
  
  public boolean isInterested(File file)
  {
    if (bundlePoolFiles.contains(file)) {
      return false;
    }
    return delegate.isInterested(file);
  }
  
  public boolean removed(File file)
  {
    return delegate.removed(file);
  }
  
  public void startPoll()
  {
    delegate.startPoll();
  }
  
  public void stopPoll()
  {
    delegate.stopPoll();
  }
}

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

public abstract interface Constants
{
  public static final String ECLIPSE = "eclipse";
  public static final String EXTENSION_LOCATION = ".eclipseextension";
  public static final String FEATURES = "features";
  public static final String FILE = "file";
  public static final String PLUGINS = "plugins";
  public static final String SITE_XML = "site.xml";
  public static final String SITE = "site";
  public static final String DOT_XML = ".xml";
}

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

import java.io.File;
import java.io.FilenameFilter;
import java.util.List;

class ExtensionLocationArtifactRepository$1
  implements FilenameFilter
{
  public boolean accept(File dir, String name)
  {
    return ExtensionLocationArtifactRepository.STANDARD_P2_REPOSITORY_FILE_NAMES.contains(name);
  }
}

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

import java.io.File;
import java.io.FilenameFilter;
import java.io.OutputStream;
import java.net.URI;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.URIUtil;
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.metadata.Version;
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.IRunnableWithProgress;
import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRequest;
import org.eclipse.equinox.p2.repository.artifact.IFileArtifactRepository;
import org.eclipse.equinox.p2.repository.spi.AbstractRepository;
import org.eclipse.osgi.util.NLS;
import org.osgi.framework.BundleContext;

public class ExtensionLocationArtifactRepository
  extends AbstractRepository<IArtifactKey>
  implements IFileArtifactRepository, Constants
{
  public static final String TYPE = "org.eclipse.equinox.p2.extensionlocation.artifactRepository";
  public static final Integer VERSION = new Integer(1);
  public static final List<String> STANDARD_P2_REPOSITORY_FILE_NAMES = Arrays.asList(new String[] { "artifacts.xml", "content.xml", "compositeArtifacts.xml", "compositeContent.xml" });
  IFileArtifactRepository artifactRepository;
  private File base;
  private Object state = SiteListener.UNINITIALIZED;
  
  public static URI getLocalRepositoryLocation(URI location)
  {
    BundleContext context = Activator.getContext();
    String stateDirName = Integer.toString(location.toString().hashCode());
    File bundleData = context.getDataFile(null);
    File stateDir = new File(bundleData, stateDirName);
    return stateDir.toURI();
  }
  
  public ExtensionLocationArtifactRepository(IProvisioningAgent agent, URI location, IFileArtifactRepository repository, IProgressMonitor monitor)
    throws ProvisionException
  {
    super(agent, Activator.getRepositoryName(location), "org.eclipse.equinox.p2.extensionlocation.artifactRepository", VERSION.toString(), location, null, null, null);
    artifactRepository = repository;
    base = getBaseDirectory(location);
  }
  
  public synchronized void ensureInitialized()
  {
    if ((state == SiteListener.INITIALIZED) || (state == SiteListener.INITIALIZING)) {
      return;
    }
    SiteListener.synchronizeRepositories(null, this, base);
  }
  
  void reload()
  {
    try
    {
      ExtensionLocationArtifactRepositoryFactory factory = new ExtensionLocationArtifactRepositoryFactory();
      factory.setAgent(getProvisioningAgent());
      ExtensionLocationArtifactRepository repo = (ExtensionLocationArtifactRepository)factory.load(getLocation(), 0, null);
      artifactRepository = artifactRepository;
      base = base;
    }
    catch (ProvisionException e)
    {
      e.printStackTrace();
      throw new IllegalStateException(e.getMessage());
    }
  }
  
  void state(Object value)
  {
    state = value;
  }
  
  public static void validate(URI location, IProgressMonitor monitor)
    throws ProvisionException
  {
    File base = getBaseDirectory(location);
    if ((new File(base, ".eclipseextension").exists()) || (location.getPath().endsWith(".eclipseextension"))) {
      return;
    }
    if (containsUpdateSiteFile(base))
    {
      String message = NLS.bind(Messages.error_update_site, location.toString());
      throw new ProvisionException(new Status(4, "org.eclipse.equinox.p2.extensionlocation", 1000, message, null));
    }
    if (containsStandardP2Repository(base))
    {
      String message = NLS.bind(Messages.error_p2_repository, location.toString());
      throw new ProvisionException(new Status(4, "org.eclipse.equinox.p2.extensionlocation", 1000, message, null));
    }
  }
  
  private static boolean containsStandardP2Repository(File base)
  {
    File[] foundRepos = base.listFiles(new FilenameFilter()
    {
      public boolean accept(File dir, String name)
      {
        return ExtensionLocationArtifactRepository.STANDARD_P2_REPOSITORY_FILE_NAMES.contains(name);
      }
    });
    return foundRepos.length > 0;
  }
  
  private static boolean containsUpdateSiteFile(File base)
  {
    String[] fileNames = base.list();
    if (fileNames == null) {
      return false;
    }
    for (int i = 0; i < fileNames.length; i++) {
      if ((fileNames[i].endsWith(".xml")) && (fileNames[i].indexOf("site") != -1)) {
        return true;
      }
    }
    return false;
  }
  
  public static File getBaseDirectory(URI uri)
    throws ProvisionException
  {
    if (!"file".equals(uri.getScheme())) {
      throw new ProvisionException(new Status(4, "org.eclipse.equinox.p2.extensionlocation", 1000, Messages.not_file_protocol, null));
    }
    String path = URIUtil.toFile(uri).getAbsolutePath();
    if (path.endsWith(".eclipseextension")) {
      path = path.substring(0, path.length() - ".eclipseextension".length());
    }
    File base = new File(path);
    if (!base.isDirectory()) {
      throw new ProvisionException(new Status(4, "org.eclipse.equinox.p2.extensionlocation", 1000, NLS.bind(Messages.not_directory, uri.toString()), null));
    }
    if (isBaseDirectory(base)) {
      return base;
    }
    File eclipseBase = new File(base, "eclipse");
    if (isBaseDirectory(eclipseBase)) {
      return eclipseBase;
    }
    throw new ProvisionException(new Status(4, "org.eclipse.equinox.p2.extensionlocation", 1000, NLS.bind(Messages.not_eclipse_extension, uri.toString()), null));
  }
  
  private static boolean isBaseDirectory(File base)
  {
    File plugins = new File(base, "plugins");
    File features = new File(base, "features");
    
    return (plugins.isDirectory()) || (features.isDirectory());
  }
  
  public void addDescriptor(IArtifactDescriptor descriptor, IProgressMonitor monitor)
  {
    throw new UnsupportedOperationException();
  }
  
  @Deprecated
  public void addDescriptor(IArtifactDescriptor descriptor)
  {
    throw new UnsupportedOperationException();
  }
  
  public void addDescriptors(IArtifactDescriptor[] descriptors, IProgressMonitor monitor)
  {
    throw new UnsupportedOperationException();
  }
  
  @Deprecated
  public void addDescriptors(IArtifactDescriptor[] descriptors)
  {
    throw new UnsupportedOperationException();
  }
  
  public void removeAll(IProgressMonitor monitor)
  {
    throw new UnsupportedOperationException();
  }
  
  @Deprecated
  public void removeAll()
  {
    throw new UnsupportedOperationException();
  }
  
  public void removeDescriptor(IArtifactDescriptor descriptor, IProgressMonitor monitor)
  {
    throw new UnsupportedOperationException();
  }
  
  @Deprecated
  public void removeDescriptor(IArtifactDescriptor descriptor)
  {
    throw new UnsupportedOperationException();
  }
  
  public void removeDescriptor(IArtifactKey key, IProgressMonitor monitor)
  {
    throw new UnsupportedOperationException();
  }
  
  @Deprecated
  public void removeDescriptor(IArtifactKey key)
  {
    throw new UnsupportedOperationException();
  }
  
  public void removeDescriptors(IArtifactDescriptor[] descriptors, IProgressMonitor monitor)
  {
    throw new UnsupportedOperationException();
  }
  
  @Deprecated
  public void removeDescriptors(IArtifactDescriptor[] descriptors)
  {
    throw new UnsupportedOperationException();
  }
  
  public void removeDescriptors(IArtifactKey[] keys, IProgressMonitor monitor)
  {
    throw new UnsupportedOperationException();
  }
  
  @Deprecated
  public void removeDescriptors(IArtifactKey[] keys)
  {
    throw new UnsupportedOperationException();
  }
  
  public boolean contains(IArtifactDescriptor descriptor)
  {
    ensureInitialized();
    return artifactRepository.contains(descriptor);
  }
  
  public boolean contains(IArtifactKey key)
  {
    ensureInitialized();
    return artifactRepository.contains(key);
  }
  
  public IStatus getArtifact(IArtifactDescriptor descriptor, OutputStream destination, IProgressMonitor monitor)
  {
    ensureInitialized();
    return artifactRepository.getArtifact(descriptor, destination, monitor);
  }
  
  public IStatus getRawArtifact(IArtifactDescriptor descriptor, OutputStream destination, IProgressMonitor monitor)
  {
    ensureInitialized();
    return artifactRepository.getRawArtifact(descriptor, destination, monitor);
  }
  
  public IArtifactDescriptor[] getArtifactDescriptors(IArtifactKey key)
  {
    ensureInitialized();
    return artifactRepository.getArtifactDescriptors(key);
  }
  
  public IStatus getArtifacts(IArtifactRequest[] requests, IProgressMonitor monitor)
  {
    ensureInitialized();
    return artifactRepository.getArtifacts(requests, monitor);
  }
  
  public OutputStream getOutputStream(IArtifactDescriptor descriptor)
    throws ProvisionException
  {
    ensureInitialized();
    return artifactRepository.getOutputStream(descriptor);
  }
  
  public File getArtifactFile(IArtifactKey key)
  {
    ensureInitialized();
    return artifactRepository.getArtifactFile(key);
  }
  
  public File getArtifactFile(IArtifactDescriptor descriptor)
  {
    ensureInitialized();
    return artifactRepository.getArtifactFile(descriptor);
  }
  
  public Map<String, String> getProperties()
  {
    ensureInitialized();
    return artifactRepository.getProperties();
  }
  
  public String setProperty(String key, String value, IProgressMonitor monitor)
  {
    try
    {
      ensureInitialized();
      String oldValue = artifactRepository.setProperty(key, value);
      String str1;
      if ((oldValue == value) || ((oldValue != null) && (oldValue.equals(value)))) {
        return oldValue;
      }
      String oldValue;
      if ((!"org.eclipse.update.site.list".equals(key)) && (!"org.eclipse.update.site.policy".equals(key))) {
        return oldValue;
      }
      String oldValue;
      state = SiteListener.UNINITIALIZED;
      ensureInitialized();
      return oldValue;
    }
    finally
    {
      if (monitor != null) {
        monitor.done();
      }
    }
  }
  
  public IArtifactDescriptor createArtifactDescriptor(IArtifactKey key)
  {
    return artifactRepository.createArtifactDescriptor(key);
  }
  
  public IArtifactKey createArtifactKey(String classifier, String id, Version version)
  {
    return artifactRepository.createArtifactKey(classifier, id, version);
  }
  
  public IQueryable<IArtifactDescriptor> descriptorQueryable()
  {
    ensureInitialized();
    return artifactRepository.descriptorQueryable();
  }
  
  public IQueryResult<IArtifactKey> query(IQuery<IArtifactKey> query, IProgressMonitor monitor)
  {
    ensureInitialized();
    return artifactRepository.query(query, monitor);
  }
  
  public IStatus executeBatch(IRunnableWithProgress runnable, IProgressMonitor monitor)
  {
    try
    {
      runnable.run(monitor);
    }
    catch (OperationCanceledException oce)
    {
      return new Status(8, "org.eclipse.equinox.p2.extensionlocation", oce.getMessage(), oce);
    }
    catch (Exception e)
    {
      return new Status(4, "org.eclipse.equinox.p2.extensionlocation", e.getMessage(), e);
    }
    return Status.OK_STATUS;
  }
}

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

import java.net.URI;
import java.util.Map;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.internal.p2.artifact.repository.simple.SimpleArtifactRepositoryFactory;
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;
import org.eclipse.equinox.p2.repository.artifact.IFileArtifactRepository;
import org.eclipse.equinox.p2.repository.artifact.spi.ArtifactRepositoryFactory;
import org.eclipse.osgi.util.NLS;

public class ExtensionLocationArtifactRepositoryFactory
  extends ArtifactRepositoryFactory
{
  public IArtifactRepository create(URI location, String name, String type, Map<String, String> properties)
    throws ProvisionException
  {
    IStatus status = validate(location, null);
    if (!status.isOK()) {
      throw new ProvisionException(status);
    }
    URI repoLocation = ExtensionLocationArtifactRepository.getLocalRepositoryLocation(location);
    if (repoLocation == null) {
      throw new ProvisionException(new Status(4, "org.eclipse.equinox.p2.extensionlocation", Messages.failed_create_local_artifact_repository));
    }
    boolean failed = false;
    SimpleArtifactRepositoryFactory simpleFactory = new SimpleArtifactRepositoryFactory();
    simpleFactory.setAgent(getAgent());
    try
    {
      simpleFactory.load(repoLocation, 0, null);
      failed = true;
    }
    catch (ProvisionException localProvisionException) {}
    if (failed)
    {
      String msg = NLS.bind(Messages.repo_already_exists, location);
      throw new ProvisionException(new Status(4, "org.eclipse.equinox.p2.extensionlocation", 1001, msg, null));
    }
    IFileArtifactRepository repo = (IFileArtifactRepository)simpleFactory.create(repoLocation, name, type, properties);
    return new ExtensionLocationArtifactRepository(getAgent(), location, repo, null);
  }
  
  public IArtifactRepository load(URI location, int flags, IProgressMonitor monitor)
    throws ProvisionException
  {
    if ((flags & 0x1) > 0) {
      return null;
    }
    IStatus status = validate(location, null);
    if (!status.isOK()) {
      throw new ProvisionException(status);
    }
    URI repoLocation = ExtensionLocationArtifactRepository.getLocalRepositoryLocation(location);
    if (repoLocation == null) {
      throw new ProvisionException(new Status(4, "org.eclipse.equinox.p2.extensionlocation", Messages.failed_create_local_artifact_repository));
    }
    try
    {
      SimpleArtifactRepositoryFactory simpleFactory = new SimpleArtifactRepositoryFactory();
      simpleFactory.setAgent(getAgent());
      IFileArtifactRepository repo = (IFileArtifactRepository)simpleFactory.load(repoLocation, flags, null);
      return new ExtensionLocationArtifactRepository(getAgent(), location, repo, monitor);
    }
    catch (ProvisionException localProvisionException) {}
    return create(location, Activator.getRepositoryName(location), "org.eclipse.equinox.p2.extensionlocation.artifactRepository", null);
  }
  
  public IStatus validate(URI location, IProgressMonitor monitor)
  {
    try
    {
      ExtensionLocationArtifactRepository.validate(location, monitor);
    }
    catch (ProvisionException e)
    {
      return e.getStatus();
    }
    return Status.OK_STATUS;
  }
}

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

import java.io.File;
import java.io.FilenameFilter;
import java.util.List;

class ExtensionLocationMetadataRepository$1
  implements FilenameFilter
{
  public boolean accept(File dir, String name)
  {
    return ExtensionLocationMetadataRepository.STANDARD_P2_REPOSITORY_FILE_NAMES.contains(name);
  }
}

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

import java.io.File;
import java.io.FilenameFilter;
import java.net.URI;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
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.core.helpers.CollectionUtils;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
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.IMetadataRepository;
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;
import org.osgi.framework.BundleContext;

public class ExtensionLocationMetadataRepository
  extends AbstractMetadataRepository
  implements Constants
{
  public static final String TYPE = "org.eclipse.equinox.p2.extensionlocation.metadataRepository";
  public static final Integer VERSION = new Integer(1);
  public static final List<String> STANDARD_P2_REPOSITORY_FILE_NAMES = Arrays.asList(new String[] { "artifacts.xml", "content.xml", "compositeArtifacts.xml", "compositeContent.xml" });
  IMetadataRepository metadataRepository;
  private File base;
  private Object state = SiteListener.UNINITIALIZED;
  
  public static URI getLocalRepositoryLocation(URI location)
  {
    BundleContext context = Activator.getContext();
    String stateDirName = Integer.toString(location.toString().hashCode());
    File bundleData = context.getDataFile(null);
    return new File(bundleData, stateDirName).toURI();
  }
  
  public ExtensionLocationMetadataRepository(IProvisioningAgent agent, URI location, IMetadataRepository repository, IProgressMonitor monitor)
    throws ProvisionException
  {
    super(agent, Activator.getRepositoryName(location), "org.eclipse.equinox.p2.extensionlocation.metadataRepository", VERSION.toString(), location, null, null, null);
    metadataRepository = repository;
    base = getBaseDirectory(location);
  }
  
  public synchronized void ensureInitialized()
  {
    if ((state == SiteListener.INITIALIZED) || (state == SiteListener.INITIALIZING)) {
      return;
    }
    SiteListener.synchronizeRepositories(this, null, base);
  }
  
  void reload()
  {
    try
    {
      ExtensionLocationMetadataRepositoryFactory factory = new ExtensionLocationMetadataRepositoryFactory();
      factory.setAgent(getProvisioningAgent());
      ExtensionLocationMetadataRepository repo = (ExtensionLocationMetadataRepository)factory.load(getLocation(), 0, null);
      metadataRepository = metadataRepository;
      base = base;
    }
    catch (ProvisionException e)
    {
      e.printStackTrace();
      throw new IllegalStateException(e.getMessage());
    }
  }
  
  void state(Object value)
  {
    state = value;
  }
  
  public Collection<IRepositoryReference> getReferences()
  {
    return CollectionUtils.emptyList();
  }
  
  public void addInstallableUnits(Collection<IInstallableUnit> installableUnits)
  {
    throw new UnsupportedOperationException();
  }
  
  public void removeAll()
  {
    throw new UnsupportedOperationException();
  }
  
  public boolean removeInstallableUnits(Collection<IInstallableUnit> installableUnits)
  {
    throw new UnsupportedOperationException();
  }
  
  public IQueryResult<IInstallableUnit> query(IQuery<IInstallableUnit> query, IProgressMonitor monitor)
  {
    ensureInitialized();
    return metadataRepository.query(query, monitor);
  }
  
  public static void validate(URI location, IProgressMonitor monitor)
    throws ProvisionException
  {
    File base = getBaseDirectory(location);
    if ((new File(base, ".eclipseextension").exists()) || (location.getPath().endsWith(".eclipseextension"))) {
      return;
    }
    if (containsUpdateSiteFile(base))
    {
      String message = NLS.bind(Messages.error_update_site, location.toString());
      throw new ProvisionException(new Status(4, "org.eclipse.equinox.p2.extensionlocation", 1000, message, null));
    }
    if (containsStandardP2Repository(base))
    {
      String message = NLS.bind(Messages.error_p2_repository, location.toString());
      throw new ProvisionException(new Status(4, "org.eclipse.equinox.p2.extensionlocation", 1000, message, null));
    }
  }
  
  private static boolean containsStandardP2Repository(File base)
  {
    File[] foundRepos = base.listFiles(new FilenameFilter()
    {
      public boolean accept(File dir, String name)
      {
        return ExtensionLocationMetadataRepository.STANDARD_P2_REPOSITORY_FILE_NAMES.contains(name);
      }
    });
    return foundRepos.length > 0;
  }
  
  private static boolean containsUpdateSiteFile(File base)
  {
    String[] fileNames = base.list();
    if (fileNames == null) {
      return false;
    }
    for (int i = 0; i < fileNames.length; i++) {
      if ((fileNames[i].endsWith(".xml")) && (fileNames[i].indexOf("site") != -1)) {
        return true;
      }
    }
    return false;
  }
  
  public static File getBaseDirectory(URI uri)
    throws ProvisionException
  {
    if (!"file".equals(uri.getScheme())) {
      throw new ProvisionException(new Status(4, "org.eclipse.equinox.p2.extensionlocation", 1000, Messages.not_file_protocol, null));
    }
    File base = URIUtil.toFile(uri);
    String path = base.getAbsolutePath();
    if (path.endsWith(".eclipseextension")) {
      base = new File(path.substring(0, path.length() - ".eclipseextension".length()));
    }
    if (!base.isDirectory()) {
      throw new ProvisionException(new Status(4, "org.eclipse.equinox.p2.extensionlocation", 1000, NLS.bind(Messages.not_directory, uri.toString()), null));
    }
    if (isBaseDirectory(base)) {
      return base;
    }
    File eclipseBase = new File(base, "eclipse");
    if (isBaseDirectory(eclipseBase)) {
      return eclipseBase;
    }
    throw new ProvisionException(new Status(4, "org.eclipse.equinox.p2.extensionlocation", 1000, NLS.bind(Messages.not_eclipse_extension, uri.toString()), null));
  }
  
  private static boolean isBaseDirectory(File base)
  {
    File plugins = new File(base, "plugins");
    File features = new File(base, "features");
    
    return (plugins.isDirectory()) || (features.isDirectory());
  }
  
  public Map<String, String> getProperties()
  {
    ensureInitialized();
    return metadataRepository.getProperties();
  }
  
  public void initialize(AbstractMetadataRepository.RepositoryState repositoryState) {}
  
  public String setProperty(String key, String value, IProgressMonitor monitor)
  {
    try
    {
      ensureInitialized();
      String oldValue = metadataRepository.setProperty(key, value);
      String str1;
      if ((oldValue == value) || ((oldValue != null) && (oldValue.equals(value)))) {
        return oldValue;
      }
      String oldValue;
      if ((!"org.eclipse.update.site.list".equals(key)) && (!"org.eclipse.update.site.policy".equals(key))) {
        return oldValue;
      }
      String oldValue;
      state = SiteListener.UNINITIALIZED;
      ensureInitialized();
      return oldValue;
    }
    finally
    {
      if (monitor != null) {
        monitor.done();
      }
    }
  }
}

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

import java.net.URI;
import java.util.Map;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.internal.p2.metadata.repository.SimpleMetadataRepositoryFactory;
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
import org.eclipse.equinox.p2.repository.metadata.spi.MetadataRepositoryFactory;
import org.eclipse.osgi.util.NLS;

public class ExtensionLocationMetadataRepositoryFactory
  extends MetadataRepositoryFactory
{
  public IMetadataRepository create(URI location, String name, String type, Map<String, String> properties)
    throws ProvisionException
  {
    IStatus status = validate(location, null);
    if (!status.isOK()) {
      throw new ProvisionException(status);
    }
    URI repoLocation = ExtensionLocationMetadataRepository.getLocalRepositoryLocation(location);
    if (repoLocation == null) {
      throw new ProvisionException(new Status(4, "org.eclipse.equinox.p2.extensionlocation", Messages.failed_create_local_artifact_repository));
    }
    boolean failed = false;
    SimpleMetadataRepositoryFactory simpleFactory = new SimpleMetadataRepositoryFactory();
    simpleFactory.setAgent(getAgent());
    try
    {
      simpleFactory.load(repoLocation, 0, null);
      failed = true;
    }
    catch (ProvisionException localProvisionException) {}
    if (failed)
    {
      String msg = NLS.bind(Messages.repo_already_exists, location.toString());
      throw new ProvisionException(new Status(4, "org.eclipse.equinox.p2.extensionlocation", 1001, msg, null));
    }
    IMetadataRepository repository = simpleFactory.create(repoLocation, name, null, properties);
    return new ExtensionLocationMetadataRepository(getAgent(), location, repository, null);
  }
  
  public IMetadataRepository load(URI location, int flags, IProgressMonitor monitor)
    throws ProvisionException
  {
    if ((flags & 0x1) > 0) {
      return null;
    }
    IStatus status = validate(location, null);
    if (!status.isOK()) {
      throw new ProvisionException(status);
    }
    URI repoLocation = ExtensionLocationMetadataRepository.getLocalRepositoryLocation(location);
    if (repoLocation == null) {
      throw new ProvisionException(new Status(4, "org.eclipse.equinox.p2.extensionlocation", Messages.failed_create_local_artifact_repository));
    }
    try
    {
      SimpleMetadataRepositoryFactory simpleFactory = new SimpleMetadataRepositoryFactory();
      simpleFactory.setAgent(getAgent());
      IMetadataRepository repository = simpleFactory.load(repoLocation, flags, null);
      return new ExtensionLocationMetadataRepository(getAgent(), location, repository, monitor);
    }
    catch (ProvisionException localProvisionException) {}
    return create(location, Activator.getRepositoryName(location), "org.eclipse.equinox.p2.extensionlocation.metadataRepository", null);
  }
  
  public IStatus validate(URI location, IProgressMonitor monitor)
  {
    try
    {
      ExtensionLocationMetadataRepository.validate(location, monitor);
    }
    catch (ProvisionException e)
    {
      return e.getStatus();
    }
    return Status.OK_STATUS;
  }
}

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

import org.eclipse.osgi.util.NLS;

public class Messages
  extends NLS
{
  private static final String BUNDLE_NAME = "org.eclipse.equinox.internal.p2.extensionlocation.messages";
  public static String error_update_site;
  public static String failed_create_local_artifact_repository;
  public static String not_directory;
  public static String not_eclipse_extension;
  public static String not_file_protocol;
  public static String repo_already_exists;
  public static String error_p2_repository;
  
  static
  {
    NLS.initializeMessages("org.eclipse.equinox.internal.p2.extensionlocation.messages", Messages.class);
  }
}

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

import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.URIUtil;
import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
import org.eclipse.equinox.internal.p2.publisher.eclipse.FeatureParser;
import org.eclipse.equinox.internal.provisional.p2.directorywatcher.DirectoryChangeListener;
import org.eclipse.equinox.internal.provisional.p2.directorywatcher.DirectoryWatcher;
import org.eclipse.equinox.internal.provisional.p2.directorywatcher.RepositoryListener;
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.publisher.eclipse.BundlesAction;
import org.eclipse.equinox.p2.publisher.eclipse.Feature;
import org.eclipse.equinox.p2.publisher.eclipse.FeatureEntry;
import org.eclipse.osgi.service.resolver.BundleDescription;
import org.osgi.framework.Version;

public class SiteListener
  extends DirectoryChangeListener
{
  public static final String SITE_POLICY = "org.eclipse.update.site.policy";
  public static final String SITE_LIST = "org.eclipse.update.site.list";
  private static final String FEATURES = "features";
  private static final String PLUGINS = "plugins";
  private static final String FEATURE_MANIFEST = "feature.xml";
  public static final Object UNINITIALIZED = "uninitialized";
  public static final Object INITIALIZING = "initializing";
  public static final Object INITIALIZED = "initialized";
  private String policy;
  private String[] list;
  private String siteLocation;
  private DirectoryChangeListener delegate;
  private String[] managedFiles;
  private String[] toBeRemoved;
  
  private static boolean contains(String[] plugins, File file)
  {
    String filename = file.getAbsolutePath();
    for (int i = 0; i < plugins.length; i++) {
      if (filename.endsWith(plugins[i])) {
        return true;
      }
    }
    return false;
  }
  
  private String[] normalize(String[] filenames)
  {
    for (int i = 0; i < filenames.length; i++) {
      filenames[i] = new File(filenames[i]).toString();
    }
    return filenames;
  }
  
  public static synchronized void synchronizeRepositories(ExtensionLocationMetadataRepository metadataRepository, ExtensionLocationArtifactRepository artifactRepository, File base)
  {
    try
    {
      if (metadataRepository == null)
      {
        artifactRepository.reload();
        ExtensionLocationMetadataRepositoryFactory factory = new ExtensionLocationMetadataRepositoryFactory();
        factory.setAgent(artifactRepository.getProvisioningAgent());
        metadataRepository = (ExtensionLocationMetadataRepository)factory.load(artifactRepository.getLocation(), 0, null);
      }
      else if (artifactRepository == null)
      {
        metadataRepository.reload();
        ExtensionLocationArtifactRepositoryFactory factory = new ExtensionLocationArtifactRepositoryFactory();
        factory.setAgent(metadataRepository.getProvisioningAgent());
        artifactRepository = (ExtensionLocationArtifactRepository)factory.load(metadataRepository.getLocation(), 0, null);
      }
    }
    catch (ProvisionException e)
    {
      e.printStackTrace();
      return;
    }
    artifactRepository.state(INITIALIZING);
    metadataRepository.state(INITIALIZING);
    File plugins = new File(base, "plugins");
    File features = new File(base, "features");
    DirectoryWatcher watcher = new DirectoryWatcher(new File[] { plugins, features });
    
    DirectoryChangeListener listener = new RepositoryListener(metadataRepository.metadataRepository, artifactRepository);
    if (metadataRepository.getProperties().get("org.eclipse.update.site.policy") != null) {
      listener = new SiteListener(metadataRepository.getProperties(), metadataRepository.getLocation().toString(), new BundlePoolFilteredListener(listener));
    }
    watcher.addListener(listener);
    watcher.poll();
    artifactRepository.state(INITIALIZED);
    metadataRepository.state(INITIALIZED);
  }
  
  public SiteListener(Map<String, String> properties, String url, DirectoryChangeListener delegate)
  {
    siteLocation = url;
    this.delegate = delegate;
    policy = ((String)properties.get("org.eclipse.update.site.policy"));
    Collection<String> listCollection = new HashSet();
    String listString = (String)properties.get("org.eclipse.update.site.list");
    if (listString != null) {
      for (StringTokenizer tokenizer = new StringTokenizer(listString, ","); tokenizer.hasMoreTokens();) {
        listCollection.add(tokenizer.nextToken());
      }
    }
    list = normalize((String[])listCollection.toArray(new String[listCollection.size()]));
  }
  
  public boolean isInterested(File file)
  {
    if (!delegate.isInterested(file)) {
      return false;
    }
    if ("MANAGED-ONLY".equals(policy)) {
      return contains(getManagedFiles(), file);
    }
    if ("USER-EXCLUDE".equals(policy))
    {
      if (contains(list, file)) {
        return false;
      }
    }
    else if ("USER-INCLUDE".equals(policy))
    {
      if (!contains(list, file)) {
        return false;
      }
    }
    else {
      return false;
    }
    return !isToBeRemoved(file);
  }
  
  private boolean isToBeRemoved(File file)
  {
    String[] removed = getToBeRemoved();
    if (removed.length == 0) {
      return false;
    }
    Feature feature = getFeature(file);
    if (feature == null) {
      return false;
    }
    for (int i = 0; i < re
1 2

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