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

package org.eclipse.equinox.p2.internal.repository.tools;

import java.io.File;
import java.net.URI;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.URIUtil;
import org.eclipse.equinox.internal.p2.artifact.repository.simple.SimpleArtifactRepository;
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.artifact.IArtifactRepositoryManager;
import org.eclipse.equinox.p2.repository.artifact.IFileArtifactRepository;
import org.eclipse.equinox.p2.repository.artifact.IProcessingStepDescriptor;
import org.eclipse.equinox.p2.repository.artifact.spi.ArtifactDescriptor;
import org.eclipse.equinox.p2.repository.artifact.spi.ProcessingStepDescriptor;
import org.eclipse.osgi.util.NLS;

public class RecreateRepositoryApplication
  extends AbstractApplication
{
  private static final String PUBLISH_PACK_FILES_AS_SIBLINGS = "publishPackFilesAsSiblings";
  private RepositoryDescriptor descriptor;
  private String repoName = null;
  boolean removeArtifactRepo = true;
  private Map<String, String> repoProperties = null;
  private Map<IArtifactKey, IArtifactDescriptor[]> repoMap = null;
  
  /* Error */
  public org.eclipse.core.runtime.IStatus run(IProgressMonitor monitor)
    throws ProvisionException
  {
    // Byte code:
    //   0: aload_0
    //   1: aload_1
    //   2: invokespecial 330	org/eclipse/equinox/p2/internal/repository/tools/RecreateRepositoryApplication:initialize	(Lorg/eclipse/core/runtime/IProgressMonitor;)Lorg/eclipse/equinox/p2/repository/artifact/IArtifactRepository;
    //   5: astore_2
    //   6: aload_0
    //   7: aload_2
    //   8: aload_1
    //   9: invokespecial 329	org/eclipse/equinox/p2/internal/repository/tools/RecreateRepositoryApplication:removeRepository	(Lorg/eclipse/equinox/p2/repository/artifact/IArtifactRepository;Lorg/eclipse/core/runtime/IProgressMonitor;)V
    //   12: aload_0
    //   13: aload_1
    //   14: invokespecial 327	org/eclipse/equinox/p2/internal/repository/tools/RecreateRepositoryApplication:recreateRepository	(Lorg/eclipse/core/runtime/IProgressMonitor;)V
    //   17: goto +34 -> 51
    //   20: astore_3
    //   21: aload_0
    //   22: getfield 300	org/eclipse/equinox/p2/internal/repository/tools/RecreateRepositoryApplication:removeArtifactRepo	Z
    //   25: ifeq +24 -> 49
    //   28: aload_0
    //   29: invokevirtual 328	org/eclipse/equinox/p2/internal/repository/tools/RecreateRepositoryApplication:getArtifactRepositoryManager	()Lorg/eclipse/equinox/p2/repository/artifact/IArtifactRepositoryManager;
    //   32: astore 4
    //   34: aload 4
    //   36: aload_0
    //   37: getfield 304	org/eclipse/equinox/p2/internal/repository/tools/RecreateRepositoryApplication:descriptor	Lorg/eclipse/equinox/p2/internal/repository/tools/RepositoryDescriptor;
    //   40: invokevirtual 332	org/eclipse/equinox/p2/internal/repository/tools/RepositoryDescriptor:getRepoLocation	()Ljava/net/URI;
    //   43: invokeinterface 357 2 0
    //   48: pop
    //   49: aload_3
    //   50: athrow
    //   51: aload_0
    //   52: getfield 300	org/eclipse/equinox/p2/internal/repository/tools/RecreateRepositoryApplication:removeArtifactRepo	Z
    //   55: ifeq +24 -> 79
    //   58: aload_0
    //   59: invokevirtual 328	org/eclipse/equinox/p2/internal/repository/tools/RecreateRepositoryApplication:getArtifactRepositoryManager	()Lorg/eclipse/equinox/p2/repository/artifact/IArtifactRepositoryManager;
    //   62: astore 4
    //   64: aload 4
    //   66: aload_0
    //   67: getfield 304	org/eclipse/equinox/p2/internal/repository/tools/RecreateRepositoryApplication:descriptor	Lorg/eclipse/equinox/p2/internal/repository/tools/RepositoryDescriptor;
    //   70: invokevirtual 332	org/eclipse/equinox/p2/internal/repository/tools/RepositoryDescriptor:getRepoLocation	()Ljava/net/URI;
    //   73: invokeinterface 357 2 0
    //   78: pop
    //   79: getstatic 296	org/eclipse/core/runtime/Status:OK_STATUS	Lorg/eclipse/core/runtime/IStatus;
    //   82: areturn
    // Line number table:
    //   Java source line #40	-> byte code offset #0
    //   Java source line #41	-> byte code offset #6
    //   Java source line #42	-> byte code offset #12
    //   Java source line #43	-> byte code offset #20
    //   Java source line #44	-> byte code offset #21
    //   Java source line #45	-> byte code offset #28
    //   Java source line #46	-> byte code offset #34
    //   Java source line #48	-> byte code offset #49
    //   Java source line #44	-> byte code offset #51
    //   Java source line #45	-> byte code offset #58
    //   Java source line #46	-> byte code offset #64
    //   Java source line #50	-> byte code offset #79
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	83	0	this	RecreateRepositoryApplication
    //   0	83	1	monitor	IProgressMonitor
    //   5	3	2	repository	IArtifactRepository
    //   20	30	3	localObject	Object
    //   32	3	4	repositoryManager	IArtifactRepositoryManager
    //   62	3	4	repositoryManager	IArtifactRepositoryManager
    // Exception table:
    //   from	to	target	type
    //   0	20	20	finally
  }
  
  public void setArtifactRepository(RepositoryDescriptor descriptor)
  {
    this.descriptor = descriptor;
  }
  
  private IArtifactRepository initialize(IProgressMonitor monitor)
    throws ProvisionException
  {
    IArtifactRepositoryManager repositoryManager = getArtifactRepositoryManager();
    removeArtifactRepo = (!repositoryManager.contains(descriptor.getRepoLocation()));
    
    IArtifactRepository repository = repositoryManager.loadRepository(descriptor.getRepoLocation(), 1, monitor);
    if ((repository == null) || (!repository.isModifiable())) {
      throw new ProvisionException(NLS.bind(Messages.exception_destinationNotModifiable, repository.getLocation()));
    }
    if (!(repository instanceof IFileArtifactRepository)) {
      throw new ProvisionException(NLS.bind(Messages.exception_notLocalFileRepo, repository.getLocation()));
    }
    repoName = repository.getName();
    repoProperties = repository.getProperties();
    
    repoMap = new HashMap();
    IQueryResult<IArtifactKey> keys = repository.query(ArtifactKeyQuery.ALL_KEYS, null);
    for (Iterator<IArtifactKey> iterator = keys.iterator(); iterator.hasNext();)
    {
      IArtifactKey key = (IArtifactKey)iterator.next();
      IArtifactDescriptor[] descriptors = repository.getArtifactDescriptors(key);
      repoMap.put(key, descriptors);
    }
    return repository;
  }
  
  private void removeRepository(IArtifactRepository repository, IProgressMonitor monitor)
    throws ProvisionException
  {
    IArtifactRepositoryManager manager = getArtifactRepositoryManager();
    manager.removeRepository(repository.getLocation());
    
    boolean compressed = Boolean.valueOf((String)repoProperties.get("p2.compressed")).booleanValue();
    URI realLocation = SimpleArtifactRepository.getActualLocation(repository.getLocation(), compressed);
    File realFile = URIUtil.toFile(realLocation);
    if ((!realFile.exists()) || (!realFile.delete())) {
      throw new ProvisionException(NLS.bind(Messages.exception_unableToRemoveRepo, realFile.toString()));
    }
  }
  
  private void recreateRepository(IProgressMonitor monitor)
    throws ProvisionException
  {
    IArtifactRepositoryManager manager = getArtifactRepositoryManager();
    
    Map<String, String> newProperties = new HashMap(repoProperties);
    newProperties.put("publishPackFilesAsSiblings", "true");
    IArtifactRepository repository = manager.createRepository(descriptor.getRepoLocation(), repoName, "org.eclipse.equinox.p2.artifact.repository.simpleRepository", newProperties);
    if (!(repository instanceof IFileArtifactRepository)) {
      throw new ProvisionException(NLS.bind(Messages.exception_notLocalFileRepo, repository.getLocation()));
    }
    IFileArtifactRepository simple = (IFileArtifactRepository)repository;
    for (Iterator localIterator = repoMap.keySet().iterator(); localIterator.hasNext();)
    {
      IArtifactKey key = (IArtifactKey)localIterator.next();
      IArtifactDescriptor[] descriptors = (IArtifactDescriptor[])repoMap.get(key);
      
      String unpackedSize = null;
      File packFile = null;
      Set<File> files = new HashSet();
      for (int i = 0; i < descriptors.length; i++)
      {
        File artifactFile = simple.getArtifactFile(descriptors[i]);
        files.add(artifactFile);
        
        String size = Long.toString(artifactFile.length());
        
        ArtifactDescriptor newDescriptor = new ArtifactDescriptor(descriptors[i]);
        newDescriptor.setProperty("artifact.size", size);
        newDescriptor.setProperty("download.size", size);
        
        String md5 = RepositoryUtilities.computeMD5(artifactFile);
        if (md5 != null) {
          newDescriptor.setProperty("download.md5", md5);
        }
        File temp = new File(artifactFile.getParentFile(), artifactFile.getName() + ".pack.gz");
        if (temp.exists())
        {
          packFile = temp;
          unpackedSize = size;
        }
        repository.addDescriptor(newDescriptor, null);
      }
      if ((packFile != null) && (!files.contains(packFile)) && (packFile.length() > 0L))
      {
        ArtifactDescriptor packDescriptor = createPack200ArtifactDescriptor(key, packFile, unpackedSize);
        repository.addDescriptor(packDescriptor, null);
      }
    }
  }
  
  private ArtifactDescriptor createPack200ArtifactDescriptor(IArtifactKey key, File packFile, String installSize)
  {
    if ((packFile != null) && (packFile.exists()))
    {
      ArtifactDescriptor result = new ArtifactDescriptor(key);
      result.setProperty("artifact.size", installSize);
      result.setProperty("download.size", Long.toString(packFile.length()));
      IProcessingStepDescriptor[] steps = { new ProcessingStepDescriptor("org.eclipse.equinox.p2.processing.Pack200Unpacker", null, true) };
      result.setProcessingSteps(steps);
      result.setProperty("format", "packed");
      return result;
    }
    return null;
  }
}

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

import org.eclipse.equinox.internal.p2.engine.Phase;
import org.eclipse.equinox.internal.p2.engine.PhaseSet;

class Repo2Runnable$1
  extends PhaseSet
{
  final Repo2Runnable this$0;
  
  Repo2Runnable$1(Repo2Runnable paramRepo2Runnable, Phase[] $anonymous0)
  {
    super($anonymous0);
  }
}

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

import org.eclipse.equinox.internal.p2.engine.Phase;
import org.eclipse.equinox.internal.p2.engine.PhaseSet;

class Repo2Runnable$2
  extends PhaseSet
{
  final Repo2Runnable this$0;
  
  Repo2Runnable$2(Repo2Runnable paramRepo2Runnable, Phase[] $anonymous0)
  {
    super($anonymous0);
  }
}

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

import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.internal.p2.engine.InstallableUnitOperand;
import org.eclipse.equinox.p2.engine.spi.ProvisioningAction;
import org.eclipse.equinox.p2.metadata.IArtifactKey;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRequest;

public class Repo2Runnable$CollectNativesAction
  extends ProvisioningAction
{
  final Repo2Runnable this$0;
  
  protected Repo2Runnable$CollectNativesAction(Repo2Runnable paramRepo2Runnable) {}
  
  public IStatus execute(Map<String, Object> parameters)
  {
    InstallableUnitOperand operand = (InstallableUnitOperand)parameters.get("operand");
    IInstallableUnit installableUnit = operand.second();
    
    IArtifactRepositoryManager manager = this$0.getArtifactRepositoryManager();
    Collection<IArtifactKey> toDownload = installableUnit.getArtifacts();
    if (toDownload == null) {
      return Status.OK_STATUS;
    }
    List<IArtifactRequest> artifactRequests = (List)parameters.get("nativeArtifacts");
    for (Iterator localIterator = toDownload.iterator(); localIterator.hasNext();)
    {
      IArtifactKey keyToDownload = (IArtifactKey)localIterator.next();
      IArtifactRequest request = manager.createMirrorRequest(keyToDownload, this$0.destinationArtifactRepository, null, null);
      artifactRequests.add(request);
    }
    return Status.OK_STATUS;
  }
  
  public IStatus undo(Map<String, Object> parameters)
  {
    return Status.OK_STATUS;
  }
}

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

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.equinox.internal.p2.engine.DownloadManager;
import org.eclipse.equinox.internal.p2.engine.InstallableUnitOperand;
import org.eclipse.equinox.internal.p2.engine.InstallableUnitPhase;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.engine.IProfile;
import org.eclipse.equinox.p2.engine.ProvisioningContext;
import org.eclipse.equinox.p2.engine.spi.ProvisioningAction;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.ITouchpointType;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRequest;

public class Repo2Runnable$CollectNativesPhase
  extends InstallableUnitPhase
{
  final Repo2Runnable this$0;
  
  public Repo2Runnable$CollectNativesPhase(Repo2Runnable paramRepo2Runnable, int weight)
  {
    super("nativeArtifacts", weight);
  }
  
  protected List<ProvisioningAction> getActions(InstallableUnitOperand operand)
  {
    IInstallableUnit unit = operand.second();
    if (unit.getTouchpointType().getId().equals("org.eclipse.equinox.p2.native")) {
      return Collections.singletonList(new Repo2Runnable.CollectNativesAction(this$0));
    }
    return null;
  }
  
  protected IStatus initializePhase(IProgressMonitor monitor, IProfile profile, Map<String, Object> parameters)
  {
    parameters.put("nativeArtifacts", new ArrayList());
    return null;
  }
  
  protected IStatus completePhase(IProgressMonitor monitor, IProfile profile, Map<String, Object> parameters)
  {
    List<IArtifactRequest> artifactRequests = (List)parameters.get("nativeArtifacts");
    ProvisioningContext context = (ProvisioningContext)parameters.get("context");
    IProvisioningAgent agent = (IProvisioningAgent)parameters.get("agent");
    DownloadManager dm = new DownloadManager(context, agent);
    for (Iterator localIterator = artifactRequests.iterator(); localIterator.hasNext();)
    {
      IArtifactRequest request = (IArtifactRequest)localIterator.next();
      dm.add(request);
    }
    return dm.start(monitor);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.p2.internal.repository.tools.Repo2Runnable.CollectNativesPhase
 * 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.Collection;
import java.util.Collections;
import java.util.HashMap;
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.Status;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.URIUtil;
import org.eclipse.equinox.app.IApplication;
import org.eclipse.equinox.app.IApplicationContext;
import org.eclipse.equinox.internal.p2.engine.DownloadManager;
import org.eclipse.equinox.internal.p2.engine.InstallableUnitOperand;
import org.eclipse.equinox.internal.p2.engine.InstallableUnitPhase;
import org.eclipse.equinox.internal.p2.engine.Phase;
import org.eclipse.equinox.internal.p2.engine.PhaseSet;
import org.eclipse.equinox.internal.p2.engine.phases.Collect;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.engine.IEngine;
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.engine.ProvisioningContext;
import org.eclipse.equinox.p2.engine.spi.ProvisioningAction;
import org.eclipse.equinox.p2.metadata.IArtifactKey;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.ITouchpointType;
import org.eclipse.equinox.p2.query.IQueryResult;
import org.eclipse.equinox.p2.query.QueryUtil;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRequest;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;

public class Repo2Runnable
  extends AbstractApplication
  implements IApplication
{
  private static final String NATIVE_ARTIFACTS = "nativeArtifacts";
  private static final String NATIVE_TYPE = "org.eclipse.equinox.p2.native";
  private static final String PARM_OPERAND = "operand";
  
  protected class CollectNativesAction
    extends ProvisioningAction
  {
    protected CollectNativesAction() {}
    
    public IStatus execute(Map<String, Object> parameters)
    {
      InstallableUnitOperand operand = (InstallableUnitOperand)parameters.get("operand");
      IInstallableUnit installableUnit = operand.second();
      
      IArtifactRepositoryManager manager = getArtifactRepositoryManager();
      Collection<IArtifactKey> toDownload = installableUnit.getArtifacts();
      if (toDownload == null) {
        return Status.OK_STATUS;
      }
      List<IArtifactRequest> artifactRequests = (List)parameters.get("nativeArtifacts");
      for (Iterator localIterator = toDownload.iterator(); localIterator.hasNext();)
      {
        IArtifactKey keyToDownload = (IArtifactKey)localIterator.next();
        IArtifactRequest request = manager.createMirrorRequest(keyToDownload, destinationArtifactRepository, null, null);
        artifactRequests.add(request);
      }
      return Status.OK_STATUS;
    }
    
    public IStatus undo(Map<String, Object> parameters)
    {
      return Status.OK_STATUS;
    }
  }
  
  protected class CollectNativesPhase
    extends InstallableUnitPhase
  {
    public CollectNativesPhase(int weight)
    {
      super(weight);
    }
    
    protected List<ProvisioningAction> getActions(InstallableUnitOperand operand)
    {
      IInstallableUnit unit = operand.second();
      if (unit.getTouchpointType().getId().equals("org.eclipse.equinox.p2.native")) {
        return Collections.singletonList(new Repo2Runnable.CollectNativesAction(Repo2Runnable.this));
      }
      return null;
    }
    
    protected IStatus initializePhase(IProgressMonitor monitor, IProfile profile, Map<String, Object> parameters)
    {
      parameters.put("nativeArtifacts", new ArrayList());
      return null;
    }
    
    protected IStatus completePhase(IProgressMonitor monitor, IProfile profile, Map<String, Object> parameters)
    {
      List<IArtifactRequest> artifactRequests = (List)parameters.get("nativeArtifacts");
      ProvisioningContext context = (ProvisioningContext)parameters.get("context");
      IProvisioningAgent agent = (IProvisioningAgent)parameters.get("agent");
      DownloadManager dm = new DownloadManager(context, agent);
      for (Iterator localIterator = artifactRequests.iterator(); localIterator.hasNext();)
      {
        IArtifactRequest request = (IArtifactRequest)localIterator.next();
        dm.add(request);
      }
      return dm.start(monitor);
    }
  }
  
  private Collection<IInstallableUnit> processedIUs = new ArrayList();
  
  public IStatus run(IProgressMonitor monitor)
    throws ProvisionException
  {
    SubMonitor progress = SubMonitor.convert(monitor, 5);
    
    initializeRepos(progress);
    
    validate();
    
    collectIUs(progress.newChild(1));
    
    IProfile profile = createProfile();
    try
    {
      IEngine engine = (IEngine)agent.getService(IEngine.SERVICE_NAME);
      if (engine == null) {
        throw new ProvisionException(Messages.exception_noEngineService);
      }
      ProvisioningContext context = new ProvisioningContext(agent);
      context.setMetadataRepositories(getRepositories(true));
      context.setArtifactRepositories(getRepositories(false));
      IProvisioningPlan plan = engine.createPlan(profile, context);
      for (Iterator<IInstallableUnit> iterator = processedIUs.iterator(); iterator.hasNext();) {
        plan.addInstallableUnit((IInstallableUnit)iterator.next());
      }
      IStatus result = engine.perform(plan, getPhaseSet(), progress.newChild(1));
      PhaseSet nativeSet = getNativePhase();
      if (nativeSet != null) {
        engine.perform(plan, nativeSet, progress.newChild(1));
      }
      publishMetadata(progress.newChild(1));
      
      return result;
    }
    finally
    {
      removeProfile(profile);
      finalizeRepositories();
    }
  }
  
  protected URI[] getRepositories(boolean metadata)
  {
    List<URI> repos = new ArrayList();
    for (Iterator localIterator = sourceRepositories.iterator(); localIterator.hasNext();)
    {
      RepositoryDescriptor repo = (RepositoryDescriptor)localIterator.next();
      if (metadata ? repo.isMetadata() : repo.isArtifact()) {
        repos.add(repo.getRepoLocation());
      }
    }
    return (URI[])repos.toArray(new URI[repos.size()]);
  }
  
  protected PhaseSet getPhaseSet()
  {
    new PhaseSet(new Phase[] { new Collect(100) }) {};
  }
  
  protected PhaseSet getNativePhase()
  {
    new PhaseSet(new Phase[] { new CollectNativesPhase(100) }) {};
  }
  
  private void collectIUs(IProgressMonitor monitor)
    throws ProvisionException
  {
    if ((sourceIUs != null) && (!sourceIUs.isEmpty()))
    {
      processedIUs = sourceIUs;
      return;
    }
    if (!hasMetadataSources()) {
      throw new ProvisionException(Messages.exception_needIUsOrNonEmptyRepo);
    }
    Iterator<IInstallableUnit> itor = getAllIUs(getCompositeMetadataRepository(), monitor).iterator();
    while (itor.hasNext()) {
      processedIUs.add((IInstallableUnit)itor.next());
    }
    if (processedIUs.isEmpty()) {
      throw new ProvisionException(Messages.exception_needIUsOrNonEmptyRepo);
    }
  }
  
  private void publishMetadata(IProgressMonitor monitor)
  {
    if (destinationMetadataRepository == null) {
      return;
    }
    destinationMetadataRepository.addInstallableUnits(processedIUs);
  }
  
  private IQueryResult<IInstallableUnit> getAllIUs(IMetadataRepository repository, IProgressMonitor monitor)
  {
    SubMonitor progress = SubMonitor.convert(monitor, 2);
    try
    {
      return repository.query(QueryUtil.createIUAnyQuery(), progress.newChild(1));
    }
    finally
    {
      progress.done();
    }
  }
  
  private void removeProfile(IProfile profile)
    throws ProvisionException
  {
    IProfileRegistry registry = Activator.getProfileRegistry();
    registry.removeProfile(profile.getProfileId());
  }
  
  private IProfile createProfile()
    throws ProvisionException
  {
    Map<String, String> properties = new HashMap();
    properties.put("org.eclipse.equinox.p2.cache", URIUtil.toFile(destinationArtifactRepository.getLocation()).getAbsolutePath());
    properties.put("org.eclipse.equinox.p2.installFolder", URIUtil.toFile(destinationArtifactRepository.getLocation()).getAbsolutePath());
    IProfileRegistry registry = Activator.getProfileRegistry();
    return registry.addProfile(System.currentTimeMillis() + "-" + Math.random(), properties);
  }
  
  public Object start(IApplicationContext context)
    throws Exception
  {
    String[] args = (String[])context.getArguments().get("application.args");
    processCommandLineArgs(args);
    
    run(null);
    return IApplication.EXIT_OK;
  }
  
  private void processCommandLineArgs(String[] args)
    throws URISyntaxException
  {
    if (args == null) {
      return;
    }
    for (int i = 0; i < args.length; i++)
    {
      String option = args[i];
      if ((i != args.length - 1) && (!args[(i + 1)].startsWith("-")))
      {
        String arg = args[(++i)];
        if (option.equalsIgnoreCase("-source"))
        {
          RepositoryDescriptor source = new RepositoryDescriptor();
          source.setLocation(URIUtil.fromString(arg));
          addSource(source);
        }
        if (option.equalsIgnoreCase("-destination"))
        {
          RepositoryDescriptor destination = new RepositoryDescriptor();
          destination.setLocation(URIUtil.fromString(arg));
          addDestination(destination);
        }
      }
    }
  }
  
  private void validate()
    throws ProvisionException
  {
    if ((!hasMetadataSources()) && (sourceIUs == null)) {
      throw new ProvisionException(Messages.exception_needIUsOrNonEmptyRepo);
    }
    if (destinationArtifactRepository == null) {
      throw new ProvisionException(Messages.exception_needDestinationRepo);
    }
  }
  
  public void stop() {}
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.p2.internal.repository.tools.Repo2Runnable
 * 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 org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.RegistryFactory;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.query.IQueryResult;
import org.eclipse.equinox.p2.query.QueryUtil;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
import org.eclipse.equinox.p2.repository.tools.analyzer.IIUAnalyzer;
import org.eclipse.equinox.p2.repository.tools.analyzer.IUAnalyzer;

public class RepositoryAnalyzer
{
  private final IMetadataRepository[] repositories;
  
  public RepositoryAnalyzer(IMetadataRepository[] repositories)
  {
    this.repositories = repositories;
  }
  
  public IStatus analyze(IProgressMonitor monitor)
  {
    MultiStatus result = new MultiStatus("org.eclipse.equinox.p2.transformer", 0, null, null);
    
    SubMonitor sub = SubMonitor.convert(monitor, repositories.length * 2);
    IConfigurationElement[] config = RegistryFactory.getRegistry().getConfigurationElementsFor("org.eclipse.equinox.p2.repository.tools.verifier");
    for (int i = 0; i < repositories.length; i++)
    {
      IQueryResult<IInstallableUnit> queryResult = repositories[i].query(QueryUtil.createIUAnyQuery(), sub);
      
      SubMonitor repositoryMonitor = SubMonitor.convert(sub, -1);
      for (int j = 0; j < config.length; j++) {
        try
        {
          IIUAnalyzer verifier = (IIUAnalyzer)config[j].createExecutableExtension("class");
          String analyizerName = config[j].getAttribute("name");
          if ((verifier instanceof IUAnalyzer)) {
            ((IUAnalyzer)verifier).setName(analyizerName);
          }
          verifier.preAnalysis(repositories[i]);
          Iterator<IInstallableUnit> iter = queryResult.iterator();
          while (iter.hasNext())
          {
            IInstallableUnit iu = (IInstallableUnit)iter.next();
            verifier.analyzeIU(iu);
          }
          IStatus postAnalysisResult = verifier.postAnalysis();
          if (postAnalysisResult == null) {
            postAnalysisResult = new Status(0, "org.eclipse.equinox.p2.transformer", analyizerName);
          }
          if ((postAnalysisResult.isOK()) && (!postAnalysisResult.isMultiStatus())) {
            postAnalysisResult = new Status(0, "org.eclipse.equinox.p2.transformer", analyizerName);
          }
          result.add(postAnalysisResult);
        }
        catch (CoreException e)
        {
          if ((e.getCause() instanceof ClassNotFoundException)) {
            result.add(new Status(4, "org.eclipse.equinox.p2.transformer", "Cannot find: " + config[j].getAttribute("class")));
          } else {
            e.printStackTrace();
          }
        }
      }
      repositoryMonitor.done();
    }
    sub.done();
    return result;
  }
}

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

import java.io.PrintStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Map;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.app.IApplication;
import org.eclipse.equinox.app.IApplicationContext;
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;

public class RepositoryAnalyzerApplication
  implements IApplication
{
  private URI uri = null;
  
  public Object start(IApplicationContext context)
    throws Exception
  {
    long start = System.currentTimeMillis();
    processArguments((String[])context.getArguments().get("application.args"));
    IProvisioningAgent agent = (IProvisioningAgent)ServiceHelper.getService(Activator.getBundleContext(), IProvisioningAgent.SERVICE_NAME);
    IMetadataRepositoryManager manager = (IMetadataRepositoryManager)agent.getService(IMetadataRepositoryManager.SERVICE_NAME);
    IMetadataRepository repository = manager.loadRepository(uri, new NullProgressMonitor());
    RepositoryAnalyzer repositoryAnalyzer = new RepositoryAnalyzer(new IMetadataRepository[] { repository });
    IStatus status = repositoryAnalyzer.analyze(new NullProgressMonitor());
    IStatus[] children = status.getChildren();
    long time = System.currentTimeMillis() - start;
    if (status.isOK()) {
      System.out.println("Repository Analyzer Finished succesfuly in " + time + " ms.");
    } else {
      System.out.println("Repository Analyzer Finished in " + time + " ms with status with errors.");
    }
    for (int i = 0; i < children.length; i++)
    {
      if (children[i].isOK()) {
        System.out.print("[OK] ");
      } else {
        System.out.print("[Error] ");
      }
      System.out.println(children[i].getMessage());
      if ((children[i].isMultiStatus()) && (children[i].getChildren() != null) && (children[i].getChildren().length > 0))
      {
        IStatus[] subChildren = children[i].getChildren();
        for (int j = 0; j < subChildren.length; j++) {
          System.out.println("   " + subChildren[j].getMessage());
        }
      }
    }
    return IApplication.EXIT_OK;
  }
  
  private void processArguments(String[] args)
    throws CoreException, URISyntaxException
  {
    for (int i = 0; i < args.length; i++) {
      if ((("-m".equals(args[i])) || ("-metadataRepository".equals(args[i]))) && 
        (i + 1 < args.length)) {
        uri = new URI(args[(i + 1)]);
      }
    }
    validateLaunch();
  }
  
  private void validateLaunch()
    throws CoreException
  {
    if (uri == null) {
      throw new CoreException(new Status(4, "org.eclipse.equinox.p2.transformer", "-metadataRepository <metadataURI> must be specified"));
    }
  }
  
  public void stop() {}
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.p2.internal.repository.tools.RepositoryAnalyzerApplication
 * 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 org.eclipse.equinox.internal.p2.repository.helpers.RepositoryHelper;
import org.eclipse.osgi.util.NLS;

public class RepositoryDescriptor
{
  public static final int TYPE_BOTH = -1;
  public static final String KIND_ARTIFACT = "A";
  public static final String KIND_METADATA = "M";
  private boolean compressed = true;
  private boolean append = true;
  private String name = null;
  private URI location = null;
  private URI format = null;
  private int kind = -1;
  private URI originalLocation = null;
  private boolean optional = false;
  private String atomic = null;
  
  public void setCompressed(boolean compress)
  {
    compressed = compress;
  }
  
  public void setName(String repoName)
  {
    name = repoName;
  }
  
  public void setOptional(boolean optional)
  {
    this.optional = optional;
  }
  
  public boolean isOptional()
  {
    return optional;
  }
  
  public void setLocation(URI repoLocation)
  {
    originalLocation = repoLocation;
    location = RepositoryHelper.localRepoURIHelper(repoLocation);
  }
  
  public void setFormat(URI format)
  {
    this.format = RepositoryHelper.localRepoURIHelper(format);
  }
  
  public void setAppend(boolean appendMode)
  {
    append = appendMode;
  }
  
  public boolean isCompressed()
  {
    return compressed;
  }
  
  public boolean isAppend()
  {
    return append;
  }
  
  public String getName()
  {
    return name;
  }
  
  public URI getRepoLocation()
  {
    return location;
  }
  
  public URI getOriginalRepoLocation()
  {
    return originalLocation;
  }
  
  public URI getFormat()
  {
    return format;
  }
  
  public int getKind()
  {
    return kind;
  }
  
  public boolean isBoth()
  {
    return kind == -1;
  }
  
  public boolean isArtifact()
  {
    return (kind == -1) || (kind == 1);
  }
  
  public boolean isMetadata()
  {
    return (kind == -1) || (kind == 0);
  }
  
  public void setKind(String repoKind)
  {
    kind = determineKind(repoKind);
  }
  
  public void setAtomic(String booleanForAtomic)
  {
    atomic = booleanForAtomic;
  }
  
  public String getAtomic()
  {
    return atomic;
  }
  
  public static int determineKind(String repoKind)
  {
    if (kindMatches(repoKind, "M")) {
      return 0;
    }
    if (kindMatches(repoKind, "A")) {
      return 1;
    }
    throw new IllegalArgumentException(NLS.bind(Messages.unknown_repository_type, repoKind));
  }
  
  public static boolean kindMatches(String repoKind, String kindIdentifier)
  {
    return (repoKind.startsWith(kindIdentifier)) || (repoKind.startsWith(kindIdentifier.toLowerCase()));
  }
}

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

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class RepositoryUtilities
{
  public static String computeMD5(File file)
  {
    if ((file == null) || (file.isDirectory()) || (!file.exists())) {
      return null;
    }
    try
    {
      md5Checker = MessageDigest.getInstance("MD5");
    }
    catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
    {
      MessageDigest md5Checker;
      return null;
    }
    MessageDigest md5Checker;
    InputStream fis = null;
    try
    {
      fis = new BufferedInputStream(new FileInputStream(file));
      int read = -1;
      while ((read = fis.read()) != -1) {
        md5Checker.update((byte)read);
      }
      byte[] digest = md5Checker.digest();
      StringBuffer buf = new StringBuffer();
      for (int i = 0; i < digest.length; i++)
      {
        if ((digest[i] & 0xFF) < 16) {
          buf.append('0');
        }
        buf.append(Integer.toHexString(digest[i] & 0xFF));
      }
      return buf.toString();
    }
    catch (FileNotFoundException localFileNotFoundException)
    {
      return null;
    }
    catch (IOException localIOException3)
    {
      return null;
    }
    finally
    {
      if (fis != null) {
        try
        {
          fis.close();
        }
        catch (IOException localIOException5) {}
      }
    }
  }
}

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

import java.util.Hashtable;
import java.util.Map;

public class SlicingOptions
{
  private boolean includeOptionalDependencies = true;
  private boolean everythingGreedy = true;
  private boolean forceFilterTo = true;
  private boolean considerStrictDependencyOnly = false;
  private boolean followOnlyFilteredRequirements = false;
  private boolean latestVersion = false;
  private boolean resolve = false;
  private Map<String, String> filter = null;
  
  public boolean includeOptionalDependencies()
  {
    return includeOptionalDependencies;
  }
  
  public void includeOptionalDependencies(boolean optional)
  {
    includeOptionalDependencies = optional;
  }
  
  public boolean isEverythingGreedy()
  {
    return everythingGreedy;
  }
  
  public void everythingGreedy(boolean greedy)
  {
    everythingGreedy = greedy;
  }
  
  public boolean forceFilterTo()
  {
    return forceFilterTo;
  }
  
  public void forceFilterTo(boolean forcedTo)
  {
    forceFilterTo = forcedTo;
  }
  
  public boolean considerStrictDependencyOnly()
  {
    return considerStrictDependencyOnly;
  }
  
  public void considerStrictDependencyOnly(boolean strict)
  {
    considerStrictDependencyOnly = strict;
  }
  
  public Map<String, String> getFilter()
  {
    if (filter == null) {
      filter = new Hashtable();
    }
    return filter;
  }
  
  public void setFilter(Map<String, String> filter)
  {
    this.filter = filter;
  }
  
  public void followOnlyFilteredRequirements(boolean onlyFiltered)
  {
    followOnlyFilteredRequirements = onlyFiltered;
  }
  
  public boolean followOnlyFilteredRequirements()
  {
    return followOnlyFilteredRequirements;
  }
  
  public boolean latestVersionOnly()
  {
    return latestVersion;
  }
  
  public void latestVersionOnly(boolean latest)
  {
    latestVersion = latest;
  }
  
  public void installTimeLikeResolution(boolean resolve)
  {
    this.resolve = resolve;
  }
  
  public boolean getInstallTimeLikeResolution()
  {
    return resolve;
  }
}

/* Location:
 * Qualified Nam
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