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

data.repository.simpleRepository", source != null ? source.getProperties() : null);
        if ((toInit.isCompressed()) && (!result.getProperties().containsKey("p2.compressed"))) {
          result.setProperty("p2.compressed", "true");
        }
        return (IMetadataRepository)RepositoryHelper.validDestinationRepository(result);
      }
      catch (UnsupportedOperationException e)
      {
        throw new ProvisionException(NLS.bind(Messages.exception_invalidDestination, toInit.getRepoLocation()), e.getCause());
      }
    }
  }
  
  protected IArtifactRepository initializeDestination(RepositoryDescriptor toInit, IArtifactRepositoryManager mgr)
    throws ProvisionException
  {
    try
    {
      IArtifactRepository repository = addRepository(mgr, toInit.getRepoLocation(), 1, null);
      if (initDestinationRepository(repository, toInit)) {
        return repository;
      }
    }
    catch (ProvisionException localProvisionException1)
    {
      IArtifactRepository source = null;
      try
      {
        if (toInit.getFormat() != null) {
          source = mgr.loadRepository(toInit.getFormat(), 0, null);
        }
      }
      catch (ProvisionException localProvisionException2) {}
      try
      {
        IArtifactRepository result = mgr.createRepository(toInit.getRepoLocation(), source != null ? source.getName() : toInit.getName() != null ? toInit.getName() : toInit.getRepoLocation().toString(), "org.eclipse.equinox.p2.artifact.repository.simpleRepository", source != null ? source.getProperties() : null);
        if ((toInit.isCompressed()) && (!result.getProperties().containsKey("p2.compressed"))) {
          result.setProperty("p2.compressed", "true");
        }
        return (IArtifactRepository)RepositoryHelper.validDestinationRepository(result);
      }
      catch (UnsupportedOperationException e)
      {
        throw new ProvisionException(NLS.bind(Messages.exception_invalidDestination, toInit.getRepoLocation()), e.getCause());
      }
    }
  }
  
  protected boolean initDestinationRepository(IRepository<?> repository, RepositoryDescriptor descriptor)
  {
    if ((repository != null) && (repository.isModifiable()))
    {
      if (descriptor.getName() != null) {
        repository.setProperty("name", descriptor.getName());
      }
      if (((repository instanceof ICompositeRepository)) && (!descriptor.isAppend())) {
        ((ICompositeRepository)repository).removeAllChildren();
      } else if (((repository instanceof IMetadataRepository)) && (!descriptor.isAppend())) {
        ((IMetadataRepository)repository).removeAll();
      } else if (((repository instanceof IArtifactRepository)) && (!descriptor.isAppend())) {
        ((IArtifactRepository)repository).removeAll();
      }
      return true;
    }
    return false;
  }
  
  public IMetadataRepository getCompositeMetadataRepository()
  {
    if (compositeMetadataRepository == null)
    {
      compositeMetadataRepository = CompositeMetadataRepository.createMemoryComposite(agent);
      for (Iterator localIterator = sourceRepositories.iterator(); localIterator.hasNext();)
      {
        RepositoryDescriptor repo = (RepositoryDescriptor)localIterator.next();
        if (repo.isMetadata()) {
          compositeMetadataRepository.addChild(repo.getRepoLocation());
        }
      }
    }
    return compositeMetadataRepository;
  }
  
  public IArtifactRepository getCompositeArtifactRepository()
  {
    if (compositeArtifactRepository == null)
    {
      compositeArtifactRepository = CompositeArtifactRepository.createMemoryComposite(agent);
      for (Iterator localIterator = sourceRepositories.iterator(); localIterator.hasNext();)
      {
        RepositoryDescriptor repo = (RepositoryDescriptor)localIterator.next();
        if (repo.isArtifact()) {
          compositeArtifactRepository.addChild(repo.getRepoLocation());
        }
      }
    }
    return compositeArtifactRepository;
  }
  
  public boolean hasArtifactSources()
  {
    return ((ICompositeRepository)getCompositeArtifactRepository()).getChildren().size() > 0;
  }
  
  public boolean hasMetadataSources()
  {
    return ((ICompositeRepository)getCompositeMetadataRepository()).getChildren().size() > 0;
  }
  
  public abstract IStatus run(IProgressMonitor paramIProgressMonitor)
    throws ProvisionException;
  
  public void addDestination(RepositoryDescriptor descriptor)
  {
    destinationRepos.add(descriptor);
  }
  
  public void addSource(RepositoryDescriptor repo)
  {
    sourceRepositories.add(repo);
  }
}

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

import java.net.URI;
import java.net.URISyntaxException;
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.core.helpers.ServiceHelper;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.engine.IProfileRegistry;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
import org.eclipse.osgi.util.NLS;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

public class Activator
  implements BundleActivator
{
  public static final String ID = "org.eclipse.equinox.p2.transformer";
  private static BundleContext bundleContext;
  
  public static BundleContext getBundleContext()
  {
    return bundleContext;
  }
  
  public void start(BundleContext context)
    throws Exception
  {
    bundleContext = context;
  }
  
  public void stop(BundleContext context)
    throws Exception
  {
    bundleContext = null;
  }
  
  public static URI getURI(String spec)
  {
    if (spec == null) {
      return null;
    }
    try
    {
      return URIUtil.fromString(spec);
    }
    catch (URISyntaxException e)
    {
      LogHelper.log(new Status(2, "org.eclipse.equinox.p2.transformer", NLS.bind(Messages.unable_to_process_uri, spec), e));
    }
    return null;
  }
  
  public static IProvisioningAgent getAgent()
    throws ProvisionException
  {
    IProvisioningAgent agent = (IProvisioningAgent)ServiceHelper.getService(getBundleContext(), IProvisioningAgent.SERVICE_NAME);
    if (agent == null) {
      throw new ProvisionException(Messages.no_provisioning_agent);
    }
    return agent;
  }
  
  public static IArtifactRepositoryManager getArtifactRepositoryManager()
    throws ProvisionException
  {
    IArtifactRepositoryManager manager = (IArtifactRepositoryManager)getAgent().getService(IArtifactRepositoryManager.SERVICE_NAME);
    if (manager == null) {
      throw new ProvisionException(Messages.no_artifactRepo_manager);
    }
    return manager;
  }
  
  static IProfileRegistry getProfileRegistry()
    throws ProvisionException
  {
    IProfileRegistry registry = (IProfileRegistry)getAgent().getService(IProfileRegistry.SERVICE_NAME);
    if (registry == null) {
      throw new ProvisionException(Messages.no_profile_registry);
    }
    return registry;
  }
  
  public static IMetadataRepositoryManager getMetadataRepositoryManager()
    throws ProvisionException
  {
    IMetadataRepositoryManager manager = (IMetadataRepositoryManager)getAgent().getService(IMetadataRepositoryManager.SERVICE_NAME);
    if (manager == null) {
      throw new ProvisionException(Messages.no_metadataRepo_manager);
    }
    return manager;
  }
}

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

import java.util.Iterator;
import java.util.List;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository;
import org.eclipse.equinox.p2.core.ProvisionException;
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.IArtifactDescriptor;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;
import org.eclipse.equinox.p2.repository.tools.comparator.ArtifactComparatorFactory;
import org.eclipse.equinox.p2.repository.tools.comparator.IArtifactComparator;

public class ArtifactRepositoryValidator
{
  private IArtifactComparator comparator;
  
  public ArtifactRepositoryValidator(String comparatorId)
    throws ProvisionException
  {
    comparator = ArtifactComparatorFactory.getArtifactComparator(comparatorId);
    if (comparatorId == null) {
      throw new ProvisionException(Messages.invalidComparatorId);
    }
  }
  
  public IStatus validateRepository(IArtifactRepository repository)
  {
    if ((repository instanceof CompositeArtifactRepository)) {
      return validateComposite((CompositeArtifactRepository)repository);
    }
    IQueryResult<IArtifactKey> queryResult = repository.query(ArtifactKeyQuery.ALL_KEYS, new NullProgressMonitor());
    IArtifactDescriptor[] descriptors;
    int i;
    for (Iterator<IArtifactKey> iterator = queryResult.iterator(); iterator.hasNext(); i < descriptors.length - 2)
    {
      descriptors = repository.getArtifactDescriptors((IArtifactKey)iterator.next());
      i = 0; continue;
      IStatus compareResult = comparator.compare(repository, descriptors[i], repository, descriptors[(i + 1)]);
      if (!compareResult.isOK()) {
        return compareResult;
      }
      i++;
    }
    return Status.OK_STATUS;
  }
  
  public IStatus validateComposite(CompositeArtifactRepository repository)
  {
    List<IArtifactRepository> repos = repository.getLoadedChildren();
    IQueryResult<IArtifactKey> queryResult = repository.query(ArtifactKeyQuery.ALL_KEYS, new NullProgressMonitor());
    Iterator localIterator;
    for (Iterator<IArtifactKey> iterator = queryResult.iterator(); iterator.hasNext(); localIterator.hasNext())
    {
      IArtifactKey key = (IArtifactKey)iterator.next();
      IArtifactRepository firstRepo = null;
      localIterator = repos.iterator(); continue;IArtifactRepository child = (IArtifactRepository)localIterator.next();
      if (child.contains(key)) {
        if (firstRepo == null)
        {
          firstRepo = child;
        }
        else
        {
          IArtifactDescriptor[] d1 = firstRepo.getArtifactDescriptors(key);
          IArtifactDescriptor[] d2 = child.getArtifactDescriptors(key);
          
          IStatus compareResult = comparator.compare(firstRepo, d1[0], child, d2[0]);
          if (!compareResult.isOK()) {
            return compareResult;
          }
        }
      }
    }
    return Status.OK_STATUS;
  }
  
  public IStatus validateComposite(CompositeArtifactRepository composite, IArtifactRepository repository)
  {
    IQueryResult<IArtifactKey> queryResult = repository.query(ArtifactKeyQuery.ALL_KEYS, new NullProgressMonitor());
    for (Iterator<IArtifactKey> iterator = queryResult.iterator(); iterator.hasNext();)
    {
      IArtifactKey key = (IArtifactKey)iterator.next();
      if (composite.contains(key))
      {
        IArtifactDescriptor[] d1 = composite.getArtifactDescriptors(key);
        IArtifactDescriptor[] d2 = repository.getArtifactDescriptors(key);
        
        IStatus compareResult = comparator.compare(composite, d1[0], repository, d2[0]);
        if (!compareResult.isOK()) {
          return compareResult;
        }
      }
    }
    return Status.OK_STATUS;
  }
}

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

import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository;
import org.eclipse.equinox.internal.p2.repository.helpers.RepositoryHelper;
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.repository.ICompositeRepository;
import org.eclipse.equinox.p2.repository.IRepository;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
import org.eclipse.osgi.util.NLS;

public class CompositeRepositoryApplication
  extends AbstractApplication
{
  private List<RepositoryDescriptor> childrenToAdd = new ArrayList();
  private List<RepositoryDescriptor> childrenToRemove = new ArrayList();
  private boolean removeAllChildren = false;
  private boolean failOnExists = false;
  private String comparatorID = null;
  
  public IStatus run(IProgressMonitor monitor)
    throws ProvisionException
  {
    try
    {
      initializeRepos(new NullProgressMonitor());
      
      ICompositeRepository<IInstallableUnit> metadataRepo = (ICompositeRepository)destinationMetadataRepository;
      CompositeArtifactRepository artifactRepo = (CompositeArtifactRepository)destinationArtifactRepository;
      if (removeAllChildren)
      {
        if (artifactRepo != null) {
          artifactRepo.removeAllChildren();
        }
        if (metadataRepo != null) {
          metadataRepo.removeAllChildren();
        }
      }
      else
      {
        for (localIterator = childrenToRemove.iterator(); localIterator.hasNext();)
        {
          RepositoryDescriptor child = (RepositoryDescriptor)localIterator.next();
          if ((child.isArtifact()) && (artifactRepo != null)) {
            artifactRepo.removeChild(child.getOriginalRepoLocation());
          }
          if ((child.isMetadata()) && (metadataRepo != null)) {
            metadataRepo.removeChild(child.getOriginalRepoLocation());
          }
        }
      }
      for (Iterator localIterator = childrenToAdd.iterator(); localIterator.hasNext();)
      {
        RepositoryDescriptor child = (RepositoryDescriptor)localIterator.next();
        if ((child.isArtifact()) && (artifactRepo != null)) {
          artifactRepo.addChild(child.getOriginalRepoLocation());
        }
        if ((child.isMetadata()) && (metadataRepo != null)) {
          metadataRepo.addChild(child.getOriginalRepoLocation());
        }
      }
      IStatus localIStatus;
      if (comparatorID != null)
      {
        ArtifactRepositoryValidator validator = new ArtifactRepositoryValidator(comparatorID);
        return validator.validateComposite(artifactRepo);
      }
      return Status.OK_STATUS;
    }
    finally
    {
      finalizeRepositories();
    }
  }
  
  public void addChild(RepositoryDescriptor child)
  {
    childrenToAdd.add(child);
  }
  
  public void removeChild(RepositoryDescriptor child)
  {
    childrenToRemove.add(child);
  }
  
  public void setRemoveAll(boolean all)
  {
    removeAllChildren = all;
  }
  
  public void setFailOnExists(boolean value)
  {
    failOnExists = value;
  }
  
  protected IArtifactRepository initializeDestination(RepositoryDescriptor toInit, IArtifactRepositoryManager mgr)
    throws ProvisionException
  {
    mgr.removeRepository(toInit.getRepoLocation());
    try
    {
      IArtifactRepository repository = mgr.loadRepository(toInit.getRepoLocation(), null);
      if ((validRepositoryLocation(repository)) && (initDestinationRepository(repository, toInit))) {
        return repository;
      }
      throw new ProvisionException(new Status(1, "org.eclipse.equinox.p2.transformer", NLS.bind(Messages.CompositeRepository_composite_repository_exists, toInit.getRepoLocation())));
    }
    catch (ProvisionException e)
    {
      if (e.getStatus().getCode() != 1000)
      {
        if ((e.getCause() instanceof MalformedURLException)) {
          throw new ProvisionException(NLS.bind(Messages.exception_invalidDestination, toInit.getRepoLocation()), e.getCause());
        }
        throw e;
      }
      IArtifactRepository source = null;
      try
      {
        if (toInit.getFormat() != null) {
          source = mgr.loadRepository(toInit.getFormat(), 0, null);
        }
      }
      catch (ProvisionException localProvisionException1) {}
      try
      {
        IArtifactRepository repo = mgr.createRepository(toInit.getRepoLocation(), source != null ? source.getName() : toInit.getName() != null ? toInit.getName() : Messages.CompositeRepository_default_artifactRepo_name, "org.eclipse.equinox.p2.artifact.repository.compositeRepository", source != null ? source.getProperties() : null);
        initRepository(repo, toInit);
        if (toInit.getAtomic() != null) {
          repo.setProperty("p2.atomic.composite.loading", Boolean.toString(Boolean.valueOf(toInit.getAtomic()).booleanValue()));
        }
        return repo;
      }
      catch (IllegalStateException e)
      {
        mgr.removeRepository(toInit.getRepoLocation());
        throw e;
      }
    }
  }
  
  protected IMetadataRepository initializeDestination(RepositoryDescriptor toInit, IMetadataRepositoryManager mgr)
    throws ProvisionException
  {
    mgr.removeRepository(toInit.getRepoLocation());
    try
    {
      IMetadataRepository repository = mgr.loadRepository(toInit.getRepoLocation(), null);
      if ((!validRepositoryLocation(repository)) && (initDestinationRepository(repository, toInit))) {
        throw new ProvisionException(new Status(1, "org.eclipse.equinox.p2.transformer", NLS.bind(Messages.CompositeRepository_composite_repository_exists, toInit.getRepoLocation())));
      }
      return repository;
    }
    catch (ProvisionException e)
    {
      if (e.getStatus().getCode() != 1000)
      {
        if ((e.getCause() instanceof MalformedURLException)) {
          throw new ProvisionException(NLS.bind(Messages.exception_invalidDestination, toInit.getRepoLocation()), e.getCause());
        }
        throw e;
      }
      IMetadataRepository source = null;
      try
      {
        if (toInit.getFormat() != null) {
          source = mgr.loadRepository(toInit.getFormat(), 0, null);
        }
      }
      catch (ProvisionException localProvisionException1) {}
      try
      {
        IMetadataRepository repo = mgr.createRepository(toInit.getRepoLocation(), source != null ? source.getName() : toInit.getName() != null ? toInit.getName() : Messages.CompositeRepository_default_metadataRepo_name, "org.eclipse.equinox.p2.metadata.repository.compositeRepository", source != null ? source.getProperties() : null);
        initRepository(repo, toInit);
        if (toInit.getAtomic() != null) {
          repo.setProperty("p2.atomic.composite.loading", Boolean.toString(Boolean.valueOf(toInit.getAtomic()).booleanValue()));
        }
        return repo;
      }
      catch (IllegalStateException e)
      {
        mgr.removeRepository(toInit.getRepoLocation());
        throw e;
      }
    }
  }
  
  private boolean validRepositoryLocation(IRepository<?> repository)
    throws ProvisionException
  {
    if ((repository instanceof ICompositeRepository))
    {
      if (failOnExists) {
        throw new ProvisionException(NLS.bind(Messages.CompositeRepository_composite_repository_exists, repository.getLocation()));
      }
      RepositoryHelper.validDestinationRepository(repository);
      return true;
    }
    return true;
  }
  
  private void initRepository(IRepository<?> repository, RepositoryDescriptor desc)
  {
    RepositoryHelper.validDestinationRepository(repository);
    if ((desc.isCompressed()) && (!repository.getProperties().containsKey("p2.compressed"))) {
      repository.setProperty("p2.compressed", String.valueOf(true));
    }
  }
  
  public void setComparator(String value)
  {
    comparatorID = value;
  }
}

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

import org.eclipse.osgi.util.NLS;

public class Messages
  extends NLS
{
  private static final String BUNDLE_NAME = "org.eclipse.equinox.p2.internal.repository.tools.messages";
  public static String exception_destinationNotModifiable;
  public static String exception_unableToRemoveRepo;
  public static String exception_notLocalFileRepo;
  public static String exception_noEngineService;
  public static String exception_noPlannerService;
  public static String exception_needIUsOrNonEmptyRepo;
  public static String exception_needDestinationRepo;
  public static String exception_onlyOneComparator;
  public static String exception_loadingRepository;
  public static String AbstractApplication_no_valid_destinations;
  public static String AbstractRepositoryTask_unableToFind;
  public static String CompositeRepository_composite_repository_exists;
  public static String CompositeRepository_default_artifactRepo_name;
  public static String CompositeRepository_default_metadataRepo_name;
  public static String no_artifactRepo_manager;
  public static String no_metadataRepo_manager;
  public static String no_profile_registry;
  public static String no_provisioning_agent;
  public static String unable_to_process_uri;
  public static String unknown_repository_type;
  public static String MirrorApplication_artifactDestinationNoSource;
  public static String MirrorApplication_metadataDestinationNoSource;
  public static String MirrorApplication_no_IUs;
  public static String MirrorApplication_set_source_repositories;
  public static String ProcessRepo_location_not_url;
  public static String ProcessRepo_must_be_local;
  public static String SlicingOption_invalid_platform;
  public static String exception_invalidDestination;
  public static String exception_invalidSource;
  public static String Repo2RunnableTask_errorTransforming;
  public static String SlicingOption_invalidFilterFormat;
  public static String skippingInvalidFilter;
  public static String message_mirroringStatus;
  public static String mirror_alreadyExists;
  public static String Mirroring_noMatchingDescriptor;
  public static String Mirroring_ValidationError;
  public static String Mirroring_missingDescriptor;
  public static String Mirroring_differentDescriptorProperty;
  public static String invalidComparatorId;
  public static String info_noMD5Infomation;
  public static String info_noMD5InRepository;
  public static String warning_differentMD5;
  
  static
  {
    NLS.initializeMessages("org.eclipse.equinox.p2.internal.repository.tools.messages", Messages.class);
  }
}

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

import java.io.File;
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.StringTokenizer;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExecutableExtension;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.URIUtil;
import org.eclipse.equinox.app.IApplication;
import org.eclipse.equinox.app.IApplicationContext;
import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
import org.eclipse.equinox.internal.p2.director.PermissiveSlicer;
import org.eclipse.equinox.internal.p2.repository.Transport;
import org.eclipse.equinox.internal.p2.repository.helpers.RepositoryHelper;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.engine.IProfile;
import org.eclipse.equinox.p2.engine.IProfileRegistry;
import org.eclipse.equinox.p2.engine.IProvisioningPlan;
import org.eclipse.equinox.p2.internal.repository.mirroring.FileMirrorLog;
import org.eclipse.equinox.p2.internal.repository.mirroring.IArtifactMirrorLog;
import org.eclipse.equinox.p2.internal.repository.mirroring.Mirroring;
import org.eclipse.equinox.p2.internal.repository.mirroring.XMLMirrorLog;
import org.eclipse.equinox.p2.metadata.IArtifactKey;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.VersionRange;
import org.eclipse.equinox.p2.planner.IPlanner;
import org.eclipse.equinox.p2.planner.IProfileChangeRequest;
import org.eclipse.equinox.p2.query.CompoundQueryable;
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.artifact.IArtifactDescriptor;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
import org.eclipse.osgi.util.NLS;

public class MirrorApplication
  extends AbstractApplication
  implements IApplication, IExecutableExtension
{
  private static final String LOG_ROOT = "p2.mirror";
  private static final String MIRROR_MODE = "metadataOrArtifacts";
  protected SlicingOptions slicingOptions = new SlicingOptions();
  private URI baseline;
  private String comparatorID;
  private IQuery<IArtifactDescriptor> compareExclusions = null;
  private boolean compare = false;
  private boolean failOnError = true;
  private boolean raw = true;
  private boolean verbose = false;
  private boolean validate = false;
  private boolean mirrorReferences = false;
  private String metadataOrArtifacts = null;
  private String[] rootIUs = null;
  private File mirrorLogFile;
  private File comparatorLogFile;
  private IArtifactMirrorLog mirrorLog;
  private IArtifactMirrorLog comparatorLog;
  
  public static String[] getArrayArgsFromString(String list, String separator)
  {
    if ((list == null) || (list.trim().equals(""))) {
      return new String[0];
    }
    List<String> result = new ArrayList();
    for (StringTokenizer tokens = new StringTokenizer(list, separator); tokens.hasMoreTokens();)
    {
      String token = tokens.nextToken().trim();
      if (!token.equals("")) {
        if (((token.indexOf('[') >= 0) || (token.indexOf('(') >= 0)) && (tokens.hasMoreTokens())) {
          result.add(token + separator + tokens.nextToken());
        } else {
          result.add(token);
        }
      }
    }
    return (String[])result.toArray(new String[result.size()]);
  }
  
  public Object start(IApplicationContext context)
    throws Exception
  {
    Map<?, ?> args = context.getArguments();
    initializeFromArguments((String[])args.get("application.args"));
    run(null);
    return IApplication.EXIT_OK;
  }
  
  public void stop() {}
  
  public void setInitializationData(IConfigurationElement config, String propertyName, Object data)
  {
    if (((data instanceof Map)) && (((Map)data).containsKey("metadataOrArtifacts"))) {
      metadataOrArtifacts = ((String)((Map)data).get("metadataOrArtifacts"));
    }
  }
  
  public void initializeFromArguments(String[] args)
    throws Exception
  {
    if (args == null) {
      return;
    }
    File comparatorLogLocation = null;
    File mirrorLogLocation = null;
    
    RepositoryDescriptor destination = new RepositoryDescriptor();
    RepositoryDescriptor sourceRepo = new RepositoryDescriptor();
    if (metadataOrArtifacts != null)
    {
      destination.setKind(metadataOrArtifacts);
      sourceRepo.setKind(metadataOrArtifacts);
    }
    addDestination(destination);
    addSource(sourceRepo);
    for (int i = 0; i < args.length; i++)
    {
      if (args[i].equalsIgnoreCase("-raw")) {
        raw = true;
      } else if (args[i].equalsIgnoreCase("-ignoreErrors")) {
        failOnError = false;
      } else if (args[i].equalsIgnoreCase("-verbose")) {
        verbose = true;
      } else if (args[i].equalsIgnoreCase("-compare")) {
        compare = true;
      } else if (args[i].equalsIgnoreCase("-validate")) {
        validate = true;
      } else if (args[i].equalsIgnoreCase("-references")) {
        mirrorReferences = true;
      }
      if ((i != args.length - 1) && (!args[(i + 1)].startsWith("-")))
      {
        String arg = args[(++i)];
        if (args[(i - 1)].equalsIgnoreCase("-comparator")) {
          comparatorID = arg;
        } else if (args[(i - 1)].equalsIgnoreCase("-comparatorLog")) {
          comparatorLogLocation = new File(arg);
        } else if (args[(i - 1)].equalsIgnoreCase("-destinationName")) {
          destination.setName(arg);
        } else if (args[(i - 1)].equalsIgnoreCase("-writeMode"))
        {
          if (args[i].equalsIgnoreCase("clean")) {
            destination.setAppend(false);
          }
        }
        else if (args[(i - 1)].equalsIgnoreCase("-log")) {
          mirrorLogLocation = new File(arg);
        } else if (args[(i - 1)].equalsIgnoreCase("-roots")) {
          rootIUs = getArrayArgsFromString(arg, ",");
        } else {
          try
          {
            if (args[(i - 1)].equalsIgnoreCase("-source"))
            {
              URI uri = RepositoryHelper.localRepoURIHelper(URIUtil.fromString(arg));
              sourceRepo.setLocation(uri);
              destination.setFormat(uri);
            }
            else if (args[(i - 1)].equalsIgnoreCase("-destination"))
            {
              destination.setLocation(RepositoryHelper.localRepoURIHelper(URIUtil.fromString(arg)));
            }
            else if (args[(i - 1)].equalsIgnoreCase("-compareAgainst"))
            {
              baseline = RepositoryHelper.localRepoURIHelper(URIUtil.fromString(arg));
              compare = true;
            }
          }
          catch (URISyntaxException localURISyntaxException)
          {
            throw new IllegalArgumentException(NLS.bind(Messages.ProcessRepo_location_not_url, arg));
          }
        }
      }
    }
    if (mirrorLogLocation != null) {
      mirrorLog = getLog(mirrorLogLocation, "p2.artifact.mirror");
    }
    if ((comparatorLogLocation != null) && (comparatorID != null)) {
      comparatorLog = getLog(comparatorLogLocation, comparatorID);
    }
  }
  
  public IStatus run(IProgressMonitor monitor)
    throws ProvisionException
  {
    IStatus mirrorStatus = Status.OK_STATUS;
    try
    {
      initializeRepos(new NullProgressMonitor());
      initializeLogs();
      validate();
      initializeIUs();
      IQueryable<IInstallableUnit> slice = slice(new NullProgressMonitor());
      if (destinationArtifactRepository != null)
      {
        mirrorStatus = mirrorArtifacts(slice, new NullProgressMonitor());
        if ((failOnError) && (mirrorStatus.getSeverity() == 4)) {
          return mirrorStatus;
        }
      }
      if (destinationMetadataRepository != null) {
        mirrorMetadata(slice, new NullProgressMonitor());
      }
    }
    finally
    {
      finalizeRepositories();
      finalizeLogs();
    }
    finalizeRepositories();
    finalizeLogs();
    if (mirrorStatus.isOK()) {
      return Status.OK_STATUS;
    }
    return mirrorStatus;
  }
  
  private IStatus mirrorArtifacts(IQueryable<IInstallableUnit> slice, IProgressMonitor monitor)
  {
    IQueryResult<IInstallableUnit> ius = slice.query(QueryUtil.createIUAnyQuery(), monitor);
    ArrayList<IArtifactKey> keys = new ArrayList();
    for (Iterator<IInstallableUnit> iterator = ius.iterator(); iterator.hasNext();)
    {
      IInstallableUnit iu = (IInstallableUnit)iterator.next();
      keys.addAll(iu.getArtifacts());
    }
    Mirroring mirror = new Mirroring(getCompositeArtifactRepository(), destinationArtifactRepository, raw);
    mirror.setCompare(compare);
    mirror.setComparatorId(comparatorID);
    mirror.setBaseline(initializeBaseline());
    mirror.setValidate(validate);
    mirror.setCompareExclusions(compareExclusions);
    mirror.setTransport((Transport)agent.getService(Transport.SERVICE_NAME));
    if (keys.size() > 0) {
      mirror.setArtifactKeys((IArtifactKey[])keys.toArray(new IArtifactKey[keys.size()]));
    }
    if (comparatorLog != null) {
      mirror.setComparatorLog(comparatorLog);
    }
    IStatus result = mirror.run(failOnError, verbose);
    if (mirrorLog != null) {
      mirrorLog.log(result);
    } else {
      LogHelper.log(result);
    }
    return result;
  }
  
  private IArtifactRepository initializeBaseline()
  {
    if (baseline == null) {
      return null;
    }
    try
    {
      return addRepository(getArtifactRepositoryManager(), baseline, 0, null);
    }
    catch (ProvisionException e)
    {
      if ((mirrorLog != null) && (e.getStatus() != null)) {
        mirrorLog.log(e.getStatus());
      }
    }
    return null;
  }
  
  private void mirrorMetadata(IQueryable<IInstallableUnit> slice, IProgressMonitor monitor)
  {
    IQueryResult<IInstallableUnit> allIUs = slice.query(QueryUtil.createIUAnyQuery(), monitor);
    destinationMetadataRepository.addInstallableUnits(allIUs.toUnmodifiableSet());
    if (mirrorReferences) {
      destinationMetadataRepository.addReferences(getCompositeMetadataRepository().getReferences());
    }
  }
  
  private void validate()
    throws ProvisionException
  {
    if (sourceRepositories.isEmpty()) {
      throw new ProvisionException(Messages.MirrorApplication_set_source_repositories);
    }
    if ((!hasArtifactSources()) && (destinationArtifactRepository != null)) {
      throw new ProvisionException(Messages.MirrorApplication_artifactDestinationNoSource);
    }
    if ((!hasMetadataSources()) && (destinationMetadataRepository != null)) {
      throw new ProvisionException(Messages.MirrorApplication_metadataDestinationNoSource);
    }
  }
  
  private void initializeIUs()
    throws ProvisionException
  {
    IMetadataRepository metadataRepo = getCompositeMetadataRepository();
    if (rootIUs != null)
    {
      sourceIUs = new ArrayList();
      for (int i = 0; i < rootIUs.length; i++)
      {
        String[] segments = getArrayArgsFromString(rootIUs[i], "/");
        VersionRange range = segments.length > 1 ? new VersionRange(segments[1]) : null;
        Iterator<IInstallableUnit> queryResult = metadataRepo.query(QueryUtil.createIUQuery(segments[0], range), null).iterator();
        while (queryResult.hasNext()) {
          sourceIUs.add((IInstallableUnit)queryResult.next());
        }
      }
    }
    else if ((sourceIUs == null) || (sourceIUs.isEmpty()))
    {
      sourceIUs = new ArrayList();
      Iterator<IInstallableUnit> queryResult = metadataRepo.query(QueryUtil.createIUAnyQuery(), null).iterator();
      while (queryResult.hasNext()) {
        sourceIUs.add((IInstallableUnit)queryResult.next());
      }
      if ((sourceIUs.size() == 0) && (destinationMetadataRepository != null) && (metadataOrArtifacts == null)) {
        throw new ProvisionException(Messages.MirrorApplication_no_IUs);
      }
    }
  }
  
  private void initializeLogs()
  {
    if ((compare) && (comparatorLogFile != null)) {
      comparatorLog = getLog(comparatorLogFile, comparatorID);
    }
    if ((mirrorLog == null) && (mirrorLogFile != null)) {
      mirrorLog = getLog(mirrorLogFile, "p2.mirror");
    }
  }
  
  private void finalizeLogs()
  {
    if (comparatorLog != null) {
      comparatorLog.close();
    }
    if (mirrorLog != null) {
      mirrorLog.close();
    }
  }
  
  private IArtifactMirrorLog getLog(File location, String root)
  {
    String absolutePath = location.getAbsolutePath();
    if (absolutePath.toLowerCase().endsWith(".xml")) {
      return new XMLMirrorLog(absolutePath, 0, root);
    }
    return new FileMirrorLog(absolutePath, 0, root);
  }
  
  private IQueryable<IInstallableUnit> performResolution(IProgressMonitor monitor)
    throws ProvisionException
  {
    IProfileRegistry registry = Activator.getProfileRegistry();
    String profileId = "MirrorApplication-" + System.currentTimeMillis();
    IProfile profile = registry.addProfile(profileId, slicingOptions.getFilter());
    IPlanner planner = (IPlanner)Activator.getAgent().getService(IPlanner.SERVICE_NAME);
    if (planner == null) {
      throw new IllegalStateException();
    }
    IProfileChangeRequest pcr = planner.createChangeRequest(profile);
    pcr.addAll(sourceIUs);
    IProvisioningPlan plan = planner.getProvisioningPlan(pcr, null, monitor);
    registry.removeProfile(profileId);
    
    IQueryable[] arr = new IQueryable[plan.getInstallerPlan() == null ? 1 : 2];
    arr[0] = plan.getAdditions();
    if (plan.getInstallerPlan() != null) {
      arr[1] = plan.getInstallerPlan().getAdditions();
    }
    return new CompoundQueryable(arr);
  }
  
  private IQueryable<IInstallableUnit> slice(IProgressMonitor monitor)
    throws ProvisionException
  {
    if (slicingOptions == null) {
      slicingOptions = new SlicingOptions();
    }
    if (slicingOptions.getInstallTimeLikeResolution()) {
      return performResolution(monitor);
    }
    PermissiveSlicer slicer = new PermissiveSlicer(getCompositeMetadataRepository(), slicingOptions.getFilter(), slicingOptions.includeOptionalDependencies(), slicingOptions.isEverythingGreedy(), slicingOptions.forceFilterTo(), slicingOptions.considerStrictDependencyOnly(), slicingOptions.followOnlyFilteredRequirements());
    IQueryable<IInstallableUnit> slice = slicer.slice((IInstallableUnit[])sourceIUs.toArray(new IInstallableUnit[sourceIUs.size()]), monitor);
    if ((slice != null) && (slicingOptions.latestVersionOnly()))
    {
      IQueryResult<IInstallableUnit> queryResult = slice.query(QueryUtil.createLatestIUQuery(), monitor);
      slice = queryResult;
    }
    if ((slicer.getStatus().getSeverity() != 0) && (mirrorLog != null)) {
      mirrorLog.log(slicer.getStatus());
    }
    if (slice == null) {
      throw new ProvisionException(slicer.getStatus());
    }
    return slice;
  }
  
  public void setSlicingOptions(SlicingOptions options)
  {
    slicingOptions = options;
  }
  
  public void setBaseline(URI baseline)
  {
    this.baseline = baseline;
    compare = true;
  }
  
  public void setComparatorID(String value)
  {
    comparatorID = value;
    compare = true;
  }
  
  public void setCompare(boolean value)
  {
    compare = value;
  }
  
  public void setIgnoreErrors(boolean value)
  {
    failOnError = (!value);
  }
  
  public void setRaw(boolean value)
  {
    raw = value;
  }
  
  public void setVerbose(boolean value)
  {
    verbose = value;
  }
  
  public void setComparatorLog(File comparatorLog)
  {
    comparatorLogFile = comparatorLog;
  }
  
  public void setLog(File mirrorLog)
  {
    mirrorLogFile = mirrorLog;
  }
  
  public void setLog(IArtifactMirrorLog log)
  {
    mirrorLog = log;
  }
  
  public void setValidate(boolean value)
  {
    validate = value;
  }
  
  public void setReferences(boolean flag)
  {
    mirrorReferences = flag;
  }
  
  public void setComparatorExclusions(IQuery<IArtifactDescriptor> exclusions)
  {
    compareExclusions = exclusions;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.p2.internal.repository.tools.MirrorApplication
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
1 2 3 4 5 6 7 8 9 10 11 12

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2019. Infinite Loop Ltd