org.eclipse.equinox.p2.console_1.0.300.v20120429-0125

16:44:03.438 INFO  jd.cli.Main - Decompiling org.eclipse.equinox.p2.console_1.0.300.v20120429-0125.jar
package org.eclipse.equinox.internal.p2.console;

import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
import org.osgi.util.tracker.ServiceTracker;
import org.osgi.util.tracker.ServiceTrackerCustomizer;

public class Activator
  implements BundleActivator, ServiceTrackerCustomizer<IProvisioningAgent, IProvisioningAgent>
{
  public static final String PLUGIN_ID = "org.eclipse.equinox.p2.console";
  private static final String PROVIDER_NAME = "org.eclipse.osgi.framework.console.CommandProvider";
  private static BundleContext context;
  private ServiceTracker<IProvisioningAgent, IProvisioningAgent> agentTracker;
  private ProvCommandProvider provider;
  private ServiceRegistration<?> providerRegistration = null;
  
  public static BundleContext getContext()
  {
    return context;
  }
  
  public void start(BundleContext ctxt)
    throws Exception
  {
    context = ctxt;
    boolean registerCommands = true;
    try
    {
      Class.forName("org.eclipse.osgi.framework.console.CommandProvider");
    }
    catch (ClassNotFoundException localClassNotFoundException1)
    {
      registerCommands = false;
    }
    if (registerCommands)
    {
      agentTracker = new ServiceTracker(context, IProvisioningAgent.class, this);
      agentTracker.open();
    }
  }
  
  public void stop(BundleContext ctxt)
    throws Exception
  {
    agentTracker.close();
    if (providerRegistration != null) {
      providerRegistration.unregister();
    }
    providerRegistration = null;
    context = null;
  }
  
  public IProvisioningAgent addingService(ServiceReference<IProvisioningAgent> reference)
  {
    BundleContext ctxt = getContext();
    IProvisioningAgent agent = (IProvisioningAgent)ctxt.getService(reference);
    provider = new ProvCommandProvider(ctxt.getProperty("eclipse.p2.profile"), agent);
    providerRegistration = ctxt.registerService("org.eclipse.osgi.framework.console.CommandProvider", provider, null);
    return agent;
  }
  
  public void modifiedService(ServiceReference<IProvisioningAgent> reference, IProvisioningAgent service) {}
  
  public void removedService(ServiceReference<IProvisioningAgent> reference, IProvisioningAgent service)
  {
    if (providerRegistration != null) {
      providerRegistration.unregister();
    }
    providerRegistration = null;
  }
}

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

import org.eclipse.osgi.util.NLS;

public class Messages
  extends NLS
{
  private static final String BUNDLE_NAME = "org.eclipse.equinox.internal.p2.console.messages";
  public static String Console_help_header;
  public static String Console_help_repository_header;
  public static String Console_help_provaddrepo_description;
  public static String Console_help_provdelrepo_description;
  public static String Console_help_provaddmetadatarepo_description;
  public static String Console_help_provdelmetadatarepo_description;
  public static String Console_help_provaddartifactrepo_description;
  public static String Console_help_provdelartifactrepo_description;
  public static String Console_help_provlg_description;
  public static String Console_help_provlr_description;
  public static String Console_help_provlar_description;
  public static String Console_help_provliu_description;
  public static String Console_help_provlquery_description;
  public static String Console_help_profile_registry_header;
  public static String Console_help_provaddprofile_description;
  public static String Console_help_provdelprofile_description;
  public static String Console_help_provlp_description;
  public static String Console_help_provlgp_description;
  public static String Console_help_provlpts_description;
  public static String Console_help_provlpquery_description;
  public static String Console_help_install_header;
  public static String Console_help_provinstall_description;
  public static String Console_help_provremove_description;
  public static String Console_help_provrevert_description;
  
  static
  {
    NLS.initializeMessages("org.eclipse.equinox.internal.p2.console.messages", Messages.class);
  }
}

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

import java.util.Comparator;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;

class ProvCommandProvider$1
  implements Comparator<IInstallableUnit>
{
  final ProvCommandProvider this$0;
  
  ProvCommandProvider$1(ProvCommandProvider paramProvCommandProvider) {}
  
  public int compare(IInstallableUnit arg0, IInstallableUnit arg1)
  {
    return arg0.toString().compareTo(arg1.toString());
  }
}

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

import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
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.metadata.IArtifactKey;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.Version;
import org.eclipse.equinox.p2.metadata.VersionRange;
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.ArtifactKeyQuery;
import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;
import org.eclipse.equinox.p2.repository.artifact.IFileArtifactRepository;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
import org.eclipse.osgi.framework.console.CommandInterpreter;
import org.eclipse.osgi.framework.console.CommandProvider;

public class ProvCommandProvider
  implements CommandProvider
{
  private static final String WILDCARD_ANY = "*";
  public static final String NEW_LINE = "\r\n";
  public static final String TAB = "\t";
  private Map<String, String> commandsHelp = null;
  private Map<String, String[]> commandGroups = null;
  private final IProvisioningAgent agent;
  
  public ProvCommandProvider(String profileId, IProvisioningAgent agent)
  {
    this.agent = agent;
  }
  
  public void _provaddrepo(CommandInterpreter interpreter)
  {
    String urlString = interpreter.nextArgument();
    if (urlString == null)
    {
      interpreter.println("Repository location must be provided");
      return;
    }
    URI repoURI = toURI(interpreter, urlString);
    if (repoURI == null) {
      return;
    }
    if (ProvisioningHelper.addMetadataRepository(agent, repoURI) == null) {
      interpreter.println("Unable to add metadata repository: " + repoURI);
    } else if (ProvisioningHelper.addArtifactRepository(agent, repoURI) == null) {
      interpreter.println("Unable to add artifact repository: " + repoURI);
    }
  }
  
  public void _provdelrepo(CommandInterpreter interpreter)
  {
    String urlString = interpreter.nextArgument();
    if (urlString == null)
    {
      interpreter.println("Repository location must be provided");
      return;
    }
    URI repoURI = toURI(interpreter, urlString);
    if (repoURI == null) {
      return;
    }
    ProvisioningHelper.removeMetadataRepository(agent, repoURI);
    ProvisioningHelper.removeArtifactRepository(agent, repoURI);
  }
  
  public void _provaddmetadatarepo(CommandInterpreter interpreter)
  {
    String urlString = interpreter.nextArgument();
    if (urlString == null)
    {
      interpreter.println("Repository location must be provided");
      return;
    }
    URI repoURI = toURI(interpreter, urlString);
    if (repoURI == null) {
      return;
    }
    if (ProvisioningHelper.addMetadataRepository(agent, repoURI) == null) {
      interpreter.println("Unable to add repository: " + repoURI);
    }
  }
  
  public void _provdelmetadatarepo(CommandInterpreter interpreter)
  {
    String urlString = interpreter.nextArgument();
    if (urlString == null)
    {
      interpreter.println("Repository location must be provided");
      return;
    }
    URI repoURI = toURI(interpreter, urlString);
    if (repoURI == null) {
      return;
    }
    ProvisioningHelper.removeMetadataRepository(agent, repoURI);
  }
  
  public void _provaddartifactrepo(CommandInterpreter interpreter)
  {
    String urlString = interpreter.nextArgument();
    if (urlString == null)
    {
      interpreter.println("Repository location must be provided");
      return;
    }
    URI repoURI = toURI(interpreter, urlString);
    if (repoURI == null) {
      return;
    }
    if (ProvisioningHelper.addArtifactRepository(agent, repoURI) == null) {
      interpreter.println("Unable to add repository " + repoURI);
    }
  }
  
  public void _provdelartifactrepo(CommandInterpreter interpreter)
  {
    String urlString = interpreter.nextArgument();
    if (urlString == null)
    {
      interpreter.println("Repository location must be provided");
      return;
    }
    URI repoURI = toURI(interpreter, urlString);
    if (repoURI == null) {
      return;
    }
    ProvisioningHelper.removeArtifactRepository(agent, repoURI);
  }
  
  public void _provinstall(CommandInterpreter interpreter)
  {
    String iu = interpreter.nextArgument();
    String version = interpreter.nextArgument();
    String profileId = interpreter.nextArgument();
    if ((profileId == null) || (profileId.equals("this"))) {
      profileId = "_SELF_";
    }
    if ((iu == null) || (version == null) || (profileId == null))
    {
      interpreter.println("Installable unit id, version, and profileid must be provided");
      return;
    }
    IProfile profile = ProvisioningHelper.getProfile(agent, profileId);
    if (profile == null)
    {
      if (profileId.equals("_SELF_")) {
        interpreter.println("No profile found");
      } else {
        interpreter.println("Profile " + profileId + " not found");
      }
      return;
    }
    IStatus s = null;
    try
    {
      s = ProvisioningHelper.install(agent, iu, version, profile, new NullProgressMonitor());
    }
    catch (ProvisionException e)
    {
      interpreter.println("Installation failed with ProvisionException for " + iu + " " + version);
      interpreter.printStackTrace(e);
      return;
    }
    if (s.isOK())
    {
      interpreter.println("Installation complete for " + iu + " " + version);
    }
    else
    {
      interpreter.println("Installation failed for " + iu + " " + version);
      interpreter.println(flattenStatus(s.getChildren(), "  "));
    }
  }
  
  private String flattenStatus(IStatus[] childs, String indent)
  {
    StringBuffer sb = new StringBuffer();
    for (int i = 0; (childs != null) && (i < childs.length); i++)
    {
      sb.append(indent).append(childs[i].getMessage()).append("\r\n");
      sb.append(flattenStatus(childs[i].getChildren(), indent + "  "));
    }
    return sb.toString();
  }
  
  public void _provaddprofile(CommandInterpreter interpreter)
  {
    String profileId = interpreter.nextArgument();
    String location = interpreter.nextArgument();
    if ((profileId == null) || (location == null))
    {
      interpreter.println("Id and location must be provided");
      return;
    }
    String environments = interpreter.nextArgument();
    Map<String, String> props = new HashMap();
    props.put("org.eclipse.equinox.p2.installFolder", location);
    if (environments != null) {
      props.put("org.eclipse.equinox.p2.environments", environments);
    }
    try
    {
      ProvisioningHelper.addProfile(agent, profileId, props);
    }
    catch (ProvisionException e)
    {
      interpreter.println("Add profile failed.  " + e.getMessage());
      interpreter.printStackTrace(e);
    }
  }
  
  public void _provdelprofile(CommandInterpreter interpreter)
  {
    String profileId = interpreter.nextArgument();
    if (profileId == null)
    {
      interpreter.println("profileid must be provided");
      return;
    }
    ProvisioningHelper.removeProfile(agent, profileId);
  }
  
  public void _provliu(CommandInterpreter interpreter)
  {
    String urlString = processArgument(interpreter.nextArgument());
    String id = processArgument(interpreter.nextArgument());
    String version = processArgument(interpreter.nextArgument());
    URI repoURL = null;
    if ((urlString != null) && (!urlString.equals("*"))) {
      repoURL = toURI(interpreter, urlString);
    }
    IInstallableUnit[] units = sort(ProvisioningHelper.getInstallableUnits(agent, repoURL, QueryUtil.createIUQuery(id, new VersionRange(version)), null));
    for (int i = 0; i < units.length; i++) {
      println(interpreter, units[i]);
    }
  }
  
  public void _provlquery(CommandInterpreter interpreter)
  {
    String urlString = processArgument(interpreter.nextArgument());
    String expression = processArgument(interpreter.nextArgument());
    if (expression == null)
    {
      interpreter.println("Please enter a query");
      return;
    }
    boolean useFull = Boolean.valueOf(processArgument(interpreter.nextArgument())).booleanValue();
    URI repoURL = null;
    if ((urlString != null) && (!urlString.equals("*"))) {
      repoURL = toURI(interpreter, urlString);
    }
    IQuery<IInstallableUnit> query = useFull ? QueryUtil.createQuery(expression, new Object[0]) : QueryUtil.createMatchQuery(expression, new Object[0]);
    IInstallableUnit[] units = sort(ProvisioningHelper.getInstallableUnits(agent, repoURL, query, null));
    if (units.length == 0) {
      interpreter.println("No units found");
    } else {
      for (int i = 0; i < units.length; i++) {
        println(interpreter, units[i]);
      }
    }
  }
  
  public void _provlr(CommandInterpreter interpreter)
  {
    String urlString = processArgument(interpreter.nextArgument());
    String id = processArgument(interpreter.nextArgument());
    String version = processArgument(interpreter.nextArgument());
    if (urlString == null)
    {
      URI[] repositories = ProvisioningHelper.getMetadataRepositories(agent);
      if (repositories != null) {
        for (int i = 0; i < repositories.length; i++) {
          interpreter.println(repositories[i]);
        }
      }
      return;
    }
    URI repoLocation = toURI(interpreter, urlString);
    if (repoLocation == null) {
      return;
    }
    IInstallableUnit[] units = sort(ProvisioningHelper.getInstallableUnits(agent, repoLocation, QueryUtil.createIUQuery(id, new VersionRange(version)), null));
    for (int i = 0; i < units.length; i++) {
      println(interpreter, units[i]);
    }
  }
  
  public void _provlg(CommandInterpreter interpreter)
  {
    String urlString = processArgument(interpreter.nextArgument());
    IQueryable<IInstallableUnit> queryable = null;
    if (urlString == null)
    {
      queryable = (IMetadataRepositoryManager)agent.getService(IMetadataRepositoryManager.SERVICE_NAME);
      if (queryable != null) {}
    }
    else
    {
      URI repoURL = toURI(interpreter, urlString);
      if (repoURL == null) {
        return;
      }
      queryable = ProvisioningHelper.getMetadataRepository(agent, repoURL);
      if (queryable == null) {
        return;
      }
    }
    IInstallableUnit[] units = sort(queryable.query(QueryUtil.createIUGroupQuery(), null));
    for (int i = 0; i < units.length; i++) {
      println(interpreter, units[i]);
    }
  }
  
  public void _provlar(CommandInterpreter interpreter)
  {
    String urlString = processArgument(interpreter.nextArgument());
    if (urlString == null)
    {
      URI[] repositories = ProvisioningHelper.getArtifactRepositories(agent);
      if (repositories == null) {
        return;
      }
      for (int i = 0; i < repositories.length; i++) {
        interpreter.println(repositories[i]);
      }
      return;
    }
    URI repoURL = toURI(interpreter, urlString);
    if (repoURL == null) {
      return;
    }
    IArtifactRepository repo = ProvisioningHelper.getArtifactRepository(agent, repoURL);
    IQueryResult<IArtifactKey> keys = null;
    try
    {
      keys = repo != null ? repo.query(ArtifactKeyQuery.ALL_KEYS, null) : null;
    }
    catch (UnsupportedOperationException localUnsupportedOperationException)
    {
      interpreter.println("Repository does not support queries.");
      return;
    }
    if ((keys == null) || (keys.isEmpty()))
    {
      interpreter.println("Repository has no artifacts");
      return;
    }
    IFileArtifactRepository fileRepo = (IFileArtifactRepository)repo.getAdapter(IFileArtifactRepository.class);
    IArtifactDescriptor[] descriptors;
    int j;
    for (Iterator<IArtifactKey> iterator = keys.iterator(); iterator.hasNext(); j < descriptors.length)
    {
      IArtifactKey key = (IArtifactKey)iterator.next();
      descriptors = repo.getArtifactDescriptors(key);
      j = 0; continue;
      IArtifactDescriptor descriptor = descriptors[j];
      File location = null;
      if (fileRepo != null) {
        location = fileRepo.getArtifactFile(descriptor);
      }
      println(interpreter, key, location);j++;
    }
  }
  
  private URI toURI(CommandInterpreter interpreter, String urlString)
  {
    try
    {
      return new URI(urlString);
    }
    catch (URISyntaxException e)
    {
      interpreter.print(e.getMessage());
      interpreter.println();
    }
    return null;
  }
  
  private String processArgument(String arg)
  {
    if ((arg == null) || (arg.equals("*"))) {
      return null;
    }
    return arg;
  }
  
  public void _provlp(CommandInterpreter interpreter)
  {
    String profileId = processArgument(interpreter.nextArgument());
    String id = processArgument(interpreter.nextArgument());
    String range = processArgument(interpreter.nextArgument());
    if (profileId == null)
    {
      IProfile[] profiles = ProvisioningHelper.getProfiles(agent);
      if (profiles == null)
      {
        interpreter.println("No profile found");
        return;
      }
      for (int i = 0; i < profiles.length; i++) {
        interpreter.println(profiles[i].getProfileId());
      }
      return;
    }
    IProfile target = null;
    if (profileId.equals("this")) {
      profileId = "_SELF_";
    }
    target = ProvisioningHelper.getProfile(agent, profileId);
    if (target == null)
    {
      if (profileId.equals("_SELF_")) {
        interpreter.println("No profile found");
      } else {
        interpreter.println("Profile " + profileId + " not found");
      }
      return;
    }
    IInstallableUnit[] result = sort(target.query(QueryUtil.createIUQuery(id, new VersionRange(range)), null));
    for (int i = 0; i < result.length; i++) {
      interpreter.println(result[i]);
    }
  }
  
  public void _provlpts(CommandInterpreter interpreter)
  {
    String profileId = processArgument(interpreter.nextArgument());
    if ((profileId == null) || (profileId.equals("this"))) {
      profileId = "_SELF_";
    }
    long[] profileTimestamps = ProvisioningHelper.getProfileTimestamps(agent, profileId);
    if ((profileTimestamps == null) || (profileTimestamps.length == 0))
    {
      if (profileId.equals("_SELF_"))
      {
        interpreter.println("No profile found");
      }
      else
      {
        interpreter.print("No timestamps found for profile ");
        interpreter.println(profileId);
      }
      return;
    }
    interpreter.print("Timestamps for profile ");
    interpreter.println(profileId);
    for (int i = 0; i < profileTimestamps.length; i++)
    {
      interpreter.print("\t");
      interpreter.println(new Long(profileTimestamps[i]));
    }
  }
  
  public void _provrevert(CommandInterpreter interpreter)
  {
    String timestamp = interpreter.nextArgument();
    if (timestamp == null)
    {
      interpreter.println("Valid timestamp must be provided.  Timestamps can be retrieved via 'provlpts' command.");
      return;
    }
    Long ts = null;
    try
    {
      ts = new Long(timestamp);
    }
    catch (NumberFormatException localNumberFormatException)
    {
      interpreter.println("Timestamp " + timestamp + " not valid.  Timestamps can be retrieved via 'provlpts' command.");
      return;
    }
    String profileId = interpreter.nextArgument();
    if ((profileId == null) || (profileId.equals("this"))) {
      profileId = "_SELF_";
    }
    IProfile profile = ProvisioningHelper.getProfile(agent, profileId);
    if (profile == null)
    {
      if (profileId.equals("_SELF_")) {
        interpreter.println("No profile found");
      } else {
        interpreter.println("Profile " + profileId + " not found");
      }
      return;
    }
    IStatus s = null;
    try
    {
      s = ProvisioningHelper.revertToPreviousState(agent, profile, ts.longValue());
    }
    catch (ProvisionException e)
    {
      interpreter.println("revert failed ");
      interpreter.printStackTrace(e);
      return;
    }
    if (s.isOK())
    {
      interpreter.println("revert completed");
    }
    else
    {
      interpreter.println("revert failed ");
      printErrorStatus(interpreter, s);
    }
  }
  
  private IInstallableUnit[] sort(IQueryResult<IInstallableUnit> queryResult)
  {
    IInstallableUnit[] units = (IInstallableUnit[])queryResult.toArray(IInstallableUnit.class);
    Arrays.sort(units, new Comparator()
    {
      public int compare(IInstallableUnit arg0, IInstallableUnit arg1)
      {
        return arg0.toString().compareTo(arg1.toString());
      }
    });
    return units;
  }
  
  public void _provlgp(CommandInterpreter interpreter)
  {
    String profileId = processArgument(interpreter.nextArgument());
    if ((profileId == null) || (profileId.equals("this"))) {
      profileId = "_SELF_";
    }
    IProfile profile = ProvisioningHelper.getProfile(agent, profileId);
    if (profile == null)
    {
      if (profileId.equals("_SELF_")) {
        interpreter.println("No profile found");
      } else {
        interpreter.println("Profile " + profileId + " not found");
      }
      return;
    }
    IInstallableUnit[] units = sort(profile.query(QueryUtil.createIUGroupQuery(), new NullProgressMonitor()));
    for (int i = 0; i < units.length; i++) {
      println(interpreter, units[i]);
    }
  }
  
  public void _provlpquery(CommandInterpreter interpreter)
  {
    String profileId = processArgument(interpreter.nextArgument());
    if ((profileId == null) || (profileId.equals("this"))) {
      profileId = "_SELF_";
    }
    String expression = processArgument(interpreter.nextArgument());
    if (expression == null)
    {
      interpreter.println("Please enter a query");
      return;
    }
    boolean useFull = Boolean.valueOf(processArgument(interpreter.nextArgument())).booleanValue();
    IQuery<IInstallableUnit> query = useFull ? QueryUtil.createQuery(expression, new Object[0]) : QueryUtil.createMatchQuery(expression, new Object[0]);
    
    IProfile profile = ProvisioningHelper.getProfile(agent, profileId);
    if (profile == null)
    {
      if (profileId.equals("_SELF_")) {
        interpreter.println("No profile found");
      } else {
        interpreter.println("Profile " + profileId + " not found");
      }
      return;
    }
    IInstallableUnit[] units = sort(profile.query(query, new NullProgressMonitor()));
    if (units.length == 0) {
      interpreter.println("No units found");
    } else {
      for (int i = 0; i < units.length; i++) {
        println(interpreter, units[i]);
      }
    }
  }
  
  public void _provremove(CommandInterpreter interpreter)
  {
    String iu = interpreter.nextArgument();
    String version = interpreter.nextArgument();
    String profileId = interpreter.nextArgument();
    if ((profileId == null) || (profileId.equals("this"))) {
      profileId = "_SELF_";
    }
    if (version == null) {
      version = Version.emptyVersion.toString();
    }
    if (iu == null)
    {
      interpreter.println("Installable unit id must be provided");
      return;
    }
    IProfile profile = ProvisioningHelper.getProfile(agent, profileId);
    if (profile == null)
    {
      if (profileId.equals("_SELF_")) {
        interpreter.println("No profile found");
      } else {
        interpreter.println("Profile " + profileId + " not found");
      }
      return;
    }
    IStatus s = null;
    try
    {
      s = ProvisioningHelper.uninstall(agent, iu, version, profile, new NullProgressMonitor());
    }
    catch (ProvisionException e)
    {
      interpreter.println("Remove failed with ProvisionException for " + iu + " " + version);
      interpreter.printStackTrace(e);
      return;
    }
    if (s.isOK())
    {
      interpreter.println("Remove complete for " + iu + " " + version);
    }
    else
    {
      interpreter.println("Remove failed for " + iu + " " + version);
      printErrorStatus(interpreter, s);
    }
  }
  
  public Object _help(CommandInterpreter intp)
  {
    String commandName = intp.nextArgument();
    if (commandName == null) {
      return new Boolean(false);
    }
    String help = getHelp(commandName);
    
    return help.length() > 0 ? help : new Boolean(false);
  }
  
  private void printErrorStatus(CommandInterpreter interpreter, IStatus status)
  {
    interpreter.print("--Error status ");
    interpreter.print("message=" + status.getMessage());
    interpreter.print(",code=" + status.getCode());
    String severityString = null;
    switch (status.getSeverity())
    {
    case 1: 
      severityString = "INFO";
      break;
    case 8: 
      severityString = "CANCEL";
      break;
    case 2: 
      severityString = "WARNING";
      break;
    case 4: 
      severityString = "ERROR";
    }
    interpreter.print(",severity=" + severityString);
    interpreter.print(",bundle=" + status.getPlugin());
    interpreter.println("--");
    Throwable t = status.getException();
    if (t != null) {
      interpreter.printStackTrace(t);
    }
    IStatus[] children = status.getChildren();
    if ((children != null) && (children.length > 0))
    {
      interpreter.println("Error status children:");
      for (int i = 0; i < children.length; i++) {
        printErrorStatus(interpreter, children[i]);
      }
    }
    interpreter.println("--End Error Status--");
  }
  
  public String getHelp()
  {
    return getHelp(null);
  }
  
  private String getHelp(String commandName)
  {
    StringBuffer help = new StringBuffer();
    if (commandsHelp == null) {
      initializeCommandsHelp();
    }
    if (commandGroups == null) {
      initializeCommandGroups();
    }
    if (commandName != null)
    {
      if (commandsHelp.containsKey(commandName)) {
        addCommand(commandName, (String)commandsHelp.get(commandName), help);
      }
      return help.toString();
    }
    addHeader(Messages.Console_help_header, help);
    int j;
    int i;
    for (Iterator localIterator = commandGroups.entrySet().iterator(); localIterator.hasNext(); i < j)
    {
      Map.Entry<String, String[]> groupEntry = (Map.Entry)localIterator.next();
      addHeader((String)groupEntry.getKey(), help);
      String[] arrayOfString;
      j = (arrayOfString = (String[])groupEntry.getValue()).length;i = 0; continue;String command = arrayOfString[i];
      addCommand(command, (String)commandsHelp.get(command), help);i++;
    }
    return help.toString();
  }
  
  private void addHeader(String header, StringBuffer help)
  {
    help.append("---");
    help.append(header);
    help.append("---");
    help.append("\r\n");
  }
  
  private void addCommand(String command, String description, StringBuffer help)
  {
    help.append("\t");
    help.append(command);
    help.append(" ");
    help.append(description);
    help.append("\r\n");
  }
  
  private void initializeCommandsHelp()
  {
    commandsHelp = new HashMap();
    
    commandsHelp.put("provaddrepo", Messages.Console_help_provaddrepo_description);
    commandsHelp.put("provdelrepo", Messages.Console_help_provdelrepo_description);
    commandsHelp.put("provaddmetadatarepo", Messages.Console_help_provaddmetadatarepo_description);
    commandsHelp.put("provdelmetadatarepo", Messages.Console_help_provdelmetadatarepo_description);
    commandsHelp.put("provaddartifactrepo", Messages.Console_help_provaddartifactrepo_description);
    commandsHelp.put("provdelartifactrepo", Messages.Console_help_provdelartifactrepo_description);
    commandsHelp.put("provlg", Messages.Console_help_provlg_description);
    commandsHelp.put("provlr", Messages.Console_help_provlr_description);
    commandsHelp.put("provlar", Messages.Console_help_provlar_description);
    commandsHelp.put("provliu", Messages.Console_help_provliu_description);
    commandsHelp.put("provlquery", Messages.Console_help_provlquery_description);
    
    commandsHelp.put("provaddprofile", Messages.Console_help_provaddprofile_description);
    commandsHelp.put("provdelprofile", Messages.Console_help_provdelprofile_description);
    commandsHelp.put("provlp", Messages.Console_help_provlp_description);
    commandsHelp.put("provlgp", Messages.Console_help_provlgp_description);
    commandsHelp.put("provlpts", Messages.Console_help_provlpts_description);
    commandsHelp.put("provlpquery", Messages.Console_help_provlpquery_description);
    
    commandsHelp.put("provinstall", Messages.Console_help_provinstall_description);
    commandsHelp.put("provremove", Messages.Console_help_provremove_description);
    commandsHelp.put("provrevert", Messages.Console_help_provrevert_description);
  }
  
  private void initializeCommandGroups()
  {
    commandGroups = new LinkedHashMap();
    commandGroups.put(Messages.Console_help_repository_header, new String[] { "provaddrepo", "provdelrepo", "provaddmetadatarepo", 
      "provdelmetadatarepo", "provaddartifactrepo", "provdelartifactrepo", 
      "provlg", "provlr", "provlar", 
      "provliu", "provlquery" });
    
    commandGroups.put(Messages.Console_help_profile_registry_header, new String[] { "provaddprofile", "provdelprofile", 
      "provlp", "provlgp", "provlpts", "provlpquery" });
    
    commandGroups.put(Messages.Console_help_install_header, new String[] { "provinstall", "provremove", "provrevert" });
  }
  
  public void print(CommandInterpreter interpreter, IInstallableUnit unit)
  {
    interpreter.print(unit.getId() + ' ' + unit.getVersion());
  }
  
  public void println(CommandInterpreter interpreter, IInstallableUnit unit)
  {
    print(interpreter, unit);
    interpreter.println();
  }
  
  private void println(CommandInterpreter interpreter, IArtifactKey artifactKey, File location)
  {
    interpreter.print(artifactKey.toString() + ' ' + location);
    interpreter.println();
  }
}

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

import java.net.URI;
import java.util.HashMap;
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.core.helpers.ServiceHelper;
import org.eclipse.equinox.internal.provisional.p2.director.PlanExecutionHelper;
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.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.Version;
import org.eclipse.equinox.p2.planner.IPlanner;
import org.eclipse.equinox.p2.planner.IProfileChangeRequest;
import org.eclipse.equinox.p2.query.Collector;
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.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.service.environment.EnvironmentInfo;

public class ProvisioningHelper
{
  static IMetadataRepository addMetadataRepository(IProvisioningAgent agent, URI location)
  {
    IMetadataRepositoryManager manager = (IMetadataRepositoryManager)agent.getService(IMetadataRepositoryManager.SERVICE_NAME);
    boolean createRepo = "file".equals(location.getScheme());
    if (manager == null) {
      throw new IllegalStateException("No metadata repository manager found");
    }
    try
    {
      return manager.loadRepository(location, null);
    }
    catch (ProvisionException localProvisionException1)
    {
      if (!createRepo) {
        return null;
      }
      String repositoryName = location + " - metadata";
      try
      {
        return manager.createRepository(location, repositoryName, "org.eclipse.equinox.p2.metadata.repository.simpleRepository", null);
      }
      catch (ProvisionException localProvisionException2) {}
    }
    return null;
  }
  
  static IMetadataRepository getMetadataRepository(IProvisioningAgent agent, URI location)
  {
    IMetadataRepositoryManager manager = (IMetadataRepositoryManager)agent.getService(IMetadataRepositoryManager.SERVICE_NAME);
    if (manager == null) {
      throw new IllegalStateException("No metadata repository manager found");
    }
    try
    {
      return manager.loadRepository(location, null);
    }
    catch (ProvisionException localProvisionException) {}
    return null;
  }
  
  static void removeMetadataRepository(IProvisioningAgent agent, URI location)
  {
    IMetadataRepositoryManager manager = (IMetadataRepositoryManager)agent.getService(IMetadataRepositoryManager.SERVICE_NAME);
    if (manager == null) {
      throw new IllegalStateException("No metadata repository manager found");
    }
    manager.removeRepository(location);
  }
  
  static IArtifactRepository addArtifactRepository(IProvisioningAgent agent, URI location)
  {
    IArtifactRepositoryManager manager = (IArtifactRepositoryManager)agent.getService(IArtifactRepositoryManager.SERVICE_NAME);
    boolean createRepo = "file".equals(location.getScheme());
    if (manager == null) {
      throw new IllegalStateException("No metadata repository manager found");
    }
    try
    {
      return manager.loadRepository(location, null);
    }
    catch (ProvisionException localProvisionException1)
    {
      if (!createRepo) {
        return null;
      }
      String repositoryName = location + " - artifacts";
      try
      {
        return manager.createRepository(location, repositoryName, "org.eclipse.equinox.p2.artifact.repository.simpleRepository", null);
      }
      catch (ProvisionException localProvisionException2) {}
    }
    return null;
  }
  
  static void removeArtifactRepository(IProvisioningAgent agent, URI location)
  {
    IArtifactRepositoryManager manager = (IArtifactRepositoryManager)agent.getService(IArtifactRepositoryManager.SERVICE_NAME);
    if (manager == null) {
      return;
    }
    manager.removeRepository(location);
  }
  
  static IProfile addProfile(IProvisioningAgent agent, String profileId, Map<String, String> properties)
    throws ProvisionException
  {
    IProfileRegistry profileRegistry = (IProfileRegistry)agent.getService(IProfileRegistry.SERVICE_NAME);
    if (profileRegistry == null) {
      return null;
    }
    IProfile profile = profileRegistry.getProfile(profileId);
    if (profile != null) {
      return profile;
    }
    Map<String, String> profileProperties = new HashMap(properties);
    if (profileProperties.get("org.eclipse.equinox.p2.environments") == null)
    {
      EnvironmentInfo info = (EnvironmentInfo)ServiceHelper.getService(Activator.getContext(), EnvironmentInfo.class.getName());
      if (info != null) {
        profileProperties.put("org.eclipse.equinox.p2.environments", "osgi.os=" + info.getOS() + ",osgi.ws=" + info.getWS() + ",osgi.arch=" + info.getOSArch());
      } else {
        profileProperties.put("org.eclipse.equinox.p2.environments", "");
      }
    }
    return profileRegistry.addProfile(profileId, profileProperties);
  }
  
  static void removeProfile(IProvisioningAgent agent, String profileId)
  {
    IProfileRegistry profileRegistry = (IProfileRegistry)agent.getService(IProfileRegistry.SERVICE_NAME);
    if (profileRegistry == null) {
      return;
    }
    profileRegistry.removeProfile(profileId);
  }
  
  static IProfile[] getProfiles(IProvisioningAgent agent)
  {
    IProfileRegistry profileRegistry = (IProfileRegistry)agent.getService(IProfileRegistry.SERVICE_NAME);
    if (profileRegistry == null) {
      return new IProfile[0];
    }
    return profileRegistry.getProfiles();
  }
  
  static IProfile getProfile(IProvisioningAgent agent, String id)
  {
    IProfileRegistry profileRegistry = (IProfileRegistry)agent.getService(IProfileRegistry.SERVICE_NAME);
    if (profileRegistry == null) {
      return null;
    }
    return profileRegistry.getProfile(id);
  }
  
  static IQueryResult<IInstallableUnit> getInstallableUnits(IProvisioningAgent agent, URI location, IQuery<IInstallableUnit> query, IProgressMonitor monitor)
  {
    IQueryable<IInstallableUnit> queryable = null;
    if (location == null) {
      queryable = (IMetadataRepositoryManager)agent.getService(IMetadataRepositoryManager.SERVICE_NAME);
    } else {
      queryable = getMetadataRepository(agent, location);
    }
    if (queryable != null) {
      return queryable.query(query, monitor);
    }
    return Collector.emptyCollector();
  }
  
  static URI[] getMetadataRepositories(IProvisioningAgent agent)
  {
    IMetadataRepositoryManager manager = (IMetadataRepositoryManager)agent.getService(IMetadataRepositoryManager.SERVICE_NAME);
    if (manager == null) {
      return null;
    }
    URI[] repos = manager.getKnownRepositories(0);
    if (repos.length > 0) {
      return repos;
    }
    return null;
  }
  
  static IStatus install(IProvisioningAgent agent, String unitId, String version, IProfile profile, IProgressMonitor progress)
    throws ProvisionException
  {
    if (profile == null) {
      return null;
    }
    IQueryResult<IInstallableUnit> units = getInstallableUnits(agent, null, QueryUtil.createIUQuery(unitId, Version.create(version)), progress);
    if (units.isEmpty())
    {
      StringBuffer error = new StringBuffer();
      error.append("Installable unit not found: " + unitId + ' ' + version + '\n');
      error.append("Repositories searched:\n");
      URI[] repos = getMetadataRepositories(agent);
      if (repos != null) {
        for (int i = 0; i < repos.length; i++) {
          error.append(repos[i] + "\n");
        }
      }
      t
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