org.eclipse.equinox.p2.touchpoint.natives_1.0.300.v20110815-1419

16:44:29.597 INFO  jd.cli.Main - Decompiling org.eclipse.equinox.p2.touchpoint.natives_1.0.300.v20110815-1419.jar
package org.eclipse.equinox.internal.p2.touchpoint.natives;

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

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

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

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.UnknownHostException;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Random;
import java.util.Set;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
import org.eclipse.osgi.util.NLS;

public class BackupStore
  implements IBackupStore
{
  private static final String ROOTCHAR = "_";
  private final File backupRoot;
  private String backupName;
  private String dummyName;
  private ServerSocket socket = null;
  private long backupCounter;
  private long restoreCounter;
  private boolean closed;
  
  public BackupStore()
  {
    this(null, ".p2bu");
  }
  
  public BackupStore(File buParentDirectory, String prefix)
  {
    if (buParentDirectory == null) {
      buParentDirectory = new File(System.getProperty("java.io.tmpdir"));
    }
    backupRoot = buParentDirectory;
    
    String unique = genUnique();
    dummyName = (prefix + "d_" + unique);
    backupName = (prefix + "_" + unique);
    backupCounter = 0L;
    restoreCounter = 0L;
    closed = false;
  }
  
  /* Error */
  protected void finalize()
    throws java.lang.Throwable
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 365	org/eclipse/equinox/internal/p2/touchpoint/natives/BackupStore:socket	Ljava/net/ServerSocket;
    //   4: ifnull +30 -> 34
    //   7: aload_0
    //   8: getfield 365	org/eclipse/equinox/internal/p2/touchpoint/natives/BackupStore:socket	Ljava/net/ServerSocket;
    //   11: invokevirtual 428	java/net/ServerSocket:isClosed	()Z
    //   14: ifne +20 -> 34
    //   17: aload_0
    //   18: getfield 365	org/eclipse/equinox/internal/p2/touchpoint/natives/BackupStore:socket	Ljava/net/ServerSocket;
    //   21: invokevirtual 427	java/net/ServerSocket:close	()V
    //   24: goto +10 -> 34
    //   27: astore_1
    //   28: aload_0
    //   29: invokespecial 411	java/lang/Object:finalize	()V
    //   32: aload_1
    //   33: athrow
    //   34: aload_0
    //   35: invokespecial 411	java/lang/Object:finalize	()V
    //   38: return
    // Line number table:
    //   Java source line #180	-> byte code offset #0
    //   Java source line #181	-> byte code offset #17
    //   Java source line #182	-> byte code offset #27
    //   Java source line #183	-> byte code offset #28
    //   Java source line #184	-> byte code offset #32
    //   Java source line #183	-> byte code offset #34
    //   Java source line #185	-> byte code offset #38
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	39	0	this	BackupStore
    //   27	6	1	localObject	Object
    // Exception table:
    //   from	to	target	type
    //   0	27	27	finally
  }
  
  public String getBackupName()
  {
    return backupName;
  }
  
  public File getBackupRoot()
  {
    return backupRoot;
  }
  
  public boolean backup(File file)
    throws IOException
  {
    if (closed) {
      throw new ClosedBackupStoreException("Can not perform backup()");
    }
    if (!file.exists()) {
      throw new IOException(NLS.bind(Messages.BackupStore_file_not_found, file.getAbsolutePath()));
    }
    if (file.isDirectory()) {
      return backupDirectory(file);
    }
    file = makeParentCanonical(file);
    File buFile = getBackupFile(file);
    if (buFile.isDirectory()) {
      throw new IllegalArgumentException(NLS.bind(Messages.BackupStore_directory_file_mismatch, buFile.getAbsolutePath()));
    }
    if (buFile.exists())
    {
      if ((file.exists()) && (!file.delete())) {
        throw new IOException(NLS.bind(Messages.BackupStore_can_not_remove, file.getAbsolutePath()));
      }
      return false;
    }
    moveToBackup(file, buFile);
    
    return true;
  }
  
  private void moveToBackup(File file, File buFile)
    throws IOException
  {
    buFile.getParentFile().mkdirs();
    if ((buFile.getParentFile().exists()) && (!buFile.getParentFile().isDirectory())) {
      throw new IllegalArgumentException(NLS.bind(Messages.BackupStore_file_directory_mismatch, buFile.getParentFile().getAbsolutePath()));
    }
    if (file.renameTo(buFile))
    {
      backupCounter += 1L;
      return;
    }
    Util.copyStream(new FileInputStream(file), true, new FileOutputStream(buFile), true);
    backupCounter += 1L;
    if (!file.delete()) {
      throw new IOException(NLS.bind(Messages.BackupStore_can_not_delete_after_copy_0, file));
    }
  }
  
  private File getBackupFile(File file)
  {
    File buRoot = backupRoot;
    File buDir = new File(buRoot, backupName);
    
    File buFile = new File(buDir, makeRelativeFromRoot(file).getPath());
    return buFile;
  }
  
  public void backupAll(File file)
    throws IOException
  {
    if (!file.exists()) {
      return;
    }
    file = makeParentCanonical(file);
    if (file.isDirectory())
    {
      File[] files = file.listFiles();
      if (files != null) {
        for (int i = 0; i < files.length; i++) {
          backupAll(files[i]);
        }
      }
    }
    backup(file);
  }
  
  public void backupCopyAll(File file)
    throws IOException
  {
    if (!file.exists()) {
      return;
    }
    file = makeParentCanonical(file);
    if (file.isDirectory())
    {
      File[] files = file.listFiles();
      if (files != null) {
        for (int i = 0; i < files.length; i++) {
          backupCopyAll(files[i]);
        }
      }
      if ((files == null) || (files.length == 0))
      {
        backupDirectory(file);
        file.mkdir();
      }
    }
    else
    {
      backupCopy(file);
    }
  }
  
  public boolean backupCopy(File file)
    throws IOException
  {
    if (closed) {
      throw new ClosedBackupStoreException(Messages.BackupStore_backupCopy_closed_store);
    }
    if (!file.exists()) {
      throw new IOException(NLS.bind(Messages.BackupStore_file_not_found, file.getAbsolutePath()));
    }
    if (file.isDirectory()) {
      throw new IllegalArgumentException(NLS.bind(Messages.BackupStore_can_not_copy_directory, file.getAbsolutePath()));
    }
    file = makeParentCanonical(file);
    
    File buDir = new File(backupRoot, backupName);
    
    File buFile = new File(buDir, makeRelativeFromRoot(file).getPath());
    if (buFile.isDirectory()) {
      throw new IllegalArgumentException(NLS.bind(Messages.BackupStore_directory_file_mismatch, buFile.getAbsolutePath()));
    }
    if (buFile.exists()) {
      return false;
    }
    buFile.getParentFile().getCanonicalFile().mkdirs();
    if ((buFile.getParentFile().exists()) && (!buFile.getParentFile().isDirectory())) {
      throw new IllegalArgumentException(NLS.bind(Messages.BackupStore_file_directory_mismatch, buFile.getParentFile().getAbsolutePath()));
    }
    Util.copyStream(new FileInputStream(file), true, new FileOutputStream(buFile), true);
    backupCounter += 1L;
    return true;
  }
  
  public boolean backupDirectory(File file)
    throws IOException
  {
    if (!file.isDirectory()) {
      throw new IllegalArgumentException(NLS.bind(Messages.BackupStore_not_a_directory, file.getAbsolutePath()));
    }
    file = makeParentCanonical(file);
    if (file.list().length != 0) {
      throw new IllegalArgumentException(NLS.bind(Messages.BackupStore_directory_not_empty, file.getAbsolutePath()));
    }
    File dummy = new File(file, dummyName);
    dummy = makeParentCanonical(dummy);
    File buFile = getBackupFile(dummy);
    boolean backedUp = buFile.exists();
    if (!backedUp)
    {
      if (closed) {
        throw new ClosedBackupStoreException("Can not perform backup()");
      }
      if (!dummy.createNewFile()) {
        throw new IOException(NLS.bind(Messages.BackupStore_can_not_create_dummy, dummy.getAbsolutePath()));
      }
      moveToBackup(dummy, buFile);
    }
    if (!file.delete()) {
      throw new IOException(NLS.bind(Messages.BackupStore_can_not_remove, dummy.getAbsolutePath()));
    }
    return !backedUp;
  }
  
  public void restore()
    throws IOException
  {
    if (closed) {
      throw new ClosedBackupStoreException(Messages.BackupStore_restore_closed_store);
    }
    Set<File> unrestorable = new HashSet();
    boolean restored = true;
    if (!backupRoot.exists())
    {
      logError(NLS.bind(Messages.BackupStore_missing_backup_directory, backupRoot.getAbsolutePath()));
      restored = false;
    }
    else
    {
      restoreRoots(new File(backupRoot, backupName), unrestorable);
    }
    logUnrestorables(unrestorable);
    if (unrestorable.size() > 0) {
      restored = false;
    }
    close(restored);
    closed = true;
  }
  
  private void logUnrestorables(Set<File> unrestorable)
  {
    if ((unrestorable != null) && (unrestorable.size() > 0)) {
      for (Iterator localIterator = unrestorable.iterator(); localIterator.hasNext();)
      {
        File file = (File)localIterator.next();
        logError(NLS.bind(Messages.BackupStore_manual_restore_needed, file.getAbsolutePath()));
      }
    }
  }
  
  public void discard()
  {
    if (closed) {
      return;
    }
    closeSocket();
    removeBackups();
    closed = true;
  }
  
  private void close(boolean fullyRestored)
    throws IOException
  {
    closeSocket();
    if (backupCounter != restoreCounter) {
      if (!fullyRestored)
      {
        logError(NLS.bind(Messages.BackupStore_0_of_1_items_restored, new Long(restoreCounter), new Long(backupCounter)));
      }
      else
      {
        logError(NLS.bind(Messages.BackupStore_externally_modified_0_of_1_restored, new Long(restoreCounter), new Long(backupCounter)));
        fullyRestored = false;
      }
    }
    if (!fullyRestored) {
      throw new IOException(Messages.BackupStore_errors_while_restoring_see_log);
    }
    removeBackups();
  }
  
  private void closeSocket()
  {
    if ((socket != null) && (!socket.isClosed())) {
      try
      {
        socket.close();
      }
      catch (IOException localIOException)
      {
        logWarning(NLS.bind(Messages.BackupStore_can_not_close_tcp_port, new Integer(socket.getLocalPort())));
      }
    }
  }
  
  private void removeBackups()
  {
    File buRoot = new File(backupRoot, backupName);
    if (!fullyDelete(buRoot)) {
      logWarning(NLS.bind(Messages.BackupStore_can_not_remove_bu_directory, buRoot.getAbsolutePath()));
    }
  }
  
  private static void logWarning(String message)
  {
    LogHelper.log(createWarning(message));
  }
  
  private static IStatus createWarning(String message)
  {
    return new Status(2, "org.eclipse.equinox.p2.touchpoint.natives", message);
  }
  
  private static void logError(String message)
  {
    LogHelper.log(createError(message));
  }
  
  private static IStatus createError(String message)
  {
    return new Status(4, "org.eclipse.equinox.p2.touchpoint.natives", message);
  }
  
  private boolean fullyDelete(File file)
  {
    if (!file.exists()) {
      return true;
    }
    if (file.isDirectory())
    {
      File[] children = file.listFiles();
      if (children == null) {
        return false;
      }
      for (int i = 0; i < children.length; i++) {
        if (!fullyDelete(new File(file, children[i].getName()))) {
          return false;
        }
      }
    }
    return file.delete();
  }
  
  private void restore(File root, File buRoot, Set<File> unrestorable)
  {
    File[] children = buRoot.listFiles();
    if (children == null)
    {
      unrestorable.add(buRoot);
      return;
    }
    for (int i = 0; i < children.length; i++)
    {
      File bu = new File(buRoot, children[i].getName());
      File target = new File(root, bu.getName());
      if (bu.isDirectory())
      {
        if ((!target.exists()) && (!target.mkdir()))
        {
          unrestorable.add(bu);
        }
        else
        {
          if ((target.exists()) && (!target.isDirectory()))
          {
            target.delete();
            if (!target.mkdir())
            {
              unrestorable.add(bu);
              continue;
            }
          }
          restore(target, bu, unrestorable);
        }
      }
      else if (bu.getName().equals(dummyName))
      {
        restoreCounter += 1L;
      }
      else
      {
        if (target.exists()) {
          fullyDelete(target);
        }
        if (!bu.renameTo(target))
        {
          try
          {
            Util.copyStream(new FileInputStream(bu), true, new FileOutputStream(target), true);
            restoreCounter += 1L;
          }
          catch (FileNotFoundException localFileNotFoundException)
          {
            unrestorable.add(bu);
            continue;
          }
          catch (IOException localIOException)
          {
            unrestorable.add(bu);
            continue;
          }
          if (!bu.delete()) {
            logWarning(NLS.bind(Messages.BackupStore_can_not_delete_tmp_file, bu.getAbsolutePath()));
          }
        }
        else
        {
          restoreCounter += 1L;
        }
      }
    }
  }
  
  private void restoreRoots(File buRoot, Set<File> unrestorable)
  {
    File[] children = buRoot.listFiles();
    if (children == null)
    {
      unrestorable.add(buRoot);
      return;
    }
    for (int i = 0; i < children.length; i++)
    {
      String name = children[i].getName();
      String rName = name;
      String prefix = "";
      while (rName.startsWith("_"))
      {
        prefix = prefix + File.separator;
        rName = rName.substring(1);
      }
      if (prefix.length() < 1) {
        rName = rName + ":" + File.separator;
      } else {
        rName = prefix + rName;
      }
      File bu = new File(buRoot, name);
      File target = new File(rName);
      if (!bu.isDirectory()) {
        unrestorable.add(bu);
      } else if ((!target.exists()) || (!target.isDirectory())) {
        unrestorable.add(bu);
      } else {
        restore(target, bu, unrestorable);
      }
    }
  }
  
  private static long msCounter = 0L;
  
  private String genUnique()
  {
    long timePart = System.currentTimeMillis() << 5 | msCounter++ & 0x1F;
    
    long ipPart = 0L;
    try
    {
      byte[] address = InetAddress.getLocalHost().getAddress();
      for (int i = 0; i < address.length; i++) {
        ipPart = ipPart << 8 | address[i] & 0xFF;
      }
    }
    catch (UnknownHostException localUnknownHostException) {}
    int port = 0;
    try
    {
      socket = new ServerSocket(0);
      port = socket.getLocalPort();
    }
    catch (IOException localIOException1)
    {
      try
      {
        if (socket != null) {
          socket.close();
        }
      }
      catch (IOException localIOException2) {}
      port = new Random().nextInt() & 0xFFFF;
    }
    long aPart = ipPart << 16 | port & 0xFFFF;
    return Long.toHexString(timePart) + "_" + Long.toHexString(aPart);
  }
  
  private File makeRelativeFromRoot(File file)
  {
    File absolute = file.getAbsoluteFile();
    String path = absolute.getPath();
    String prefix = "";
    while (path.startsWith(File.separator))
    {
      prefix = prefix + "_";
      path = path.substring(1);
    }
    if (prefix.length() > 0)
    {
      path = prefix + File.separator + path;
      return new File(path);
    }
    int idx = path.indexOf(":");
    if (idx < 1) {
      throw new InternalError("File is neither absolute nor has a drive name: " + path);
    }
    path = path.substring(0, idx) + path.substring(idx + 1);
    
    return new File(path);
  }
  
  private File makeParentCanonical(File file)
    throws IOException
  {
    return new File(file.getParentFile().getCanonicalFile(), file.getName());
  }
}

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

public class ClosedBackupStoreException
  extends IllegalStateException
{
  private static final long serialVersionUID = -5030940685029643678L;
  
  public ClosedBackupStoreException() {}
  
  public ClosedBackupStoreException(String message)
  {
    super(message);
  }
}

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

import java.io.File;
import java.io.IOException;

public abstract interface IBackupStore
{
  public abstract boolean backup(File paramFile)
    throws IOException;
  
  public abstract boolean backupCopy(File paramFile)
    throws IOException;
  
  public abstract boolean backupDirectory(File paramFile)
    throws IOException;
  
  public abstract void discard();
  
  public abstract void restore()
    throws IOException;
  
  public abstract String getBackupName();
  
  public abstract void backupAll(File paramFile)
    throws IOException;
  
  public abstract void backupCopyAll(File paramFile)
    throws IOException;
}

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

import java.io.File;
import java.io.IOException;

public class LazyBackupStore
  implements IBackupStore
{
  private BackupStore delegate;
  private final String prefix;
  
  public LazyBackupStore(String prefix)
  {
    this.prefix = prefix;
  }
  
  public boolean backup(File file)
    throws IOException
  {
    loadDelegate();
    return delegate.backup(file);
  }
  
  public boolean backupDirectory(File file)
    throws IOException
  {
    loadDelegate();
    return delegate.backupDirectory(file);
  }
  
  public void discard()
  {
    if (delegate == null) {
      return;
    }
    delegate.discard();
  }
  
  public void restore()
    throws IOException
  {
    if (delegate == null) {
      return;
    }
    delegate.restore();
  }
  
  private void loadDelegate()
  {
    if (delegate != null) {
      return;
    }
    delegate = new BackupStore(null, prefix);
  }
  
  public String getBackupName()
  {
    loadDelegate();
    return delegate.getBackupName();
  }
  
  public boolean backupCopy(File file)
    throws IOException
  {
    loadDelegate();
    return delegate.backupCopy(file);
  }
  
  public void backupCopyAll(File file)
    throws IOException
  {
    loadDelegate();
    delegate.backupCopyAll(file);
  }
  
  public void backupAll(File file)
    throws IOException
  {
    loadDelegate();
    delegate.backupAll(file);
  }
}

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

import org.eclipse.osgi.util.NLS;

public class Messages
  extends NLS
{
  private static final String BUNDLE_NAME = "org.eclipse.equinox.internal.p2.touchpoint.natives.messages";
  public static String BackupStore_0_of_1_items_restored;
  public static String BackupStore_backupCopy_closed_store;
  public static String BackupStore_can_not_close_tcp_port;
  public static String BackupStore_can_not_copy_directory;
  public static String BackupStore_can_not_create_dummy;
  public static String BackupStore_can_not_delete_after_copy_0;
  public static String BackupStore_can_not_delete_tmp_file;
  public static String BackupStore_can_not_remove;
  public static String BackupStore_can_not_remove_bu_directory;
  public static String BackupStore_directory_file_mismatch;
  public static String BackupStore_directory_not_empty;
  public static String BackupStore_errors_while_restoring_see_log;
  public static String BackupStore_externally_modified_0_of_1_restored;
  public static String BackupStore_file_directory_mismatch;
  public static String BackupStore_file_not_found;
  public static String BackupStore_manual_restore_needed;
  public static String BackupStore_missing_backup_directory;
  public static String BackupStore_not_a_directory;
  public static String BackupStore_restore_closed_store;
  public static String action_0_failed_file_1_doesNotExist;
  public static String artifact_not_available;
  public static String artifact_repo_not_found;
  public static String could_not_obtain_download_cache;
  public static String download_cache_not_writeable;
  public static String unzipping;
  public static String param_not_set;
  public static String copy_failed;
  public static String failed_backup_restore;
  public static String backup_file_failed;
  public static String Error_list_children_0;
  public static String link_failed;
  public static String mkdir_failed;
  public static String rmdir_failed;
  public static String Util_Invalid_Zip_File_Format;
  public static String Util_Error_Unzipping;
  
  static
  {
    NLS.initializeMessages("org.eclipse.equinox.internal.p2.touchpoint.natives.messages", Messages.class);
  }
}

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

import java.io.File;
import java.io.IOException;
import java.util.Map;
import java.util.WeakHashMap;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
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.spi.Touchpoint;
import org.eclipse.equinox.p2.metadata.IArtifactKey;
import org.eclipse.equinox.p2.repository.artifact.IFileArtifactRepository;
import org.eclipse.osgi.util.NLS;

public class NativeTouchpoint
  extends Touchpoint
{
  public static final String PARM_BACKUP = "backup";
  public static final String PARM_ARTIFACT = "artifact";
  public static final String PARM_ARTIFACT_LOCATION = "artifact.location";
  private static Map<IProfile, IBackupStore> backups = new WeakHashMap();
  
  public IStatus initializeOperand(IProfile profile, Map<String, Object> parameters)
  {
    IProvisioningAgent agent = (IProvisioningAgent)parameters.get("agent");
    IArtifactKey artifactKey = (IArtifactKey)parameters.get("artifact");
    if ((!parameters.containsKey("artifact.location")) && (artifactKey != null)) {
      try
      {
        IFileArtifactRepository downloadCache = Util.getDownloadCacheRepo(agent);
        File fileLocation = downloadCache.getArtifactFile(artifactKey);
        if ((fileLocation != null) && (fileLocation.exists())) {
          parameters.put("artifact.location", fileLocation.getAbsolutePath());
        }
      }
      catch (ProvisionException e)
      {
        return e.getStatus();
      }
    }
    return Status.OK_STATUS;
  }
  
  public IStatus initializePhase(IProgressMonitor monitor, IProfile profile, String phaseId, Map<String, Object> touchpointParameters)
  {
    touchpointParameters.put("backup", getBackupStore(profile));
    return null;
  }
  
  public String qualifyAction(String actionId)
  {
    return "org.eclipse.equinox.p2.touchpoint.natives." + actionId;
  }
  
  public IStatus prepare(IProfile profile)
  {
    return super.prepare(profile);
  }
  
  public IStatus commit(IProfile profile)
  {
    IBackupStore store = getBackupStore(profile);
    store.discard();
    clearProfileState(profile);
    return Status.OK_STATUS;
  }
  
  public static String escape(String toEscape)
  {
    StringBuffer buffer = new StringBuffer();
    int length = toEscape.length();
    for (int i = 0; i < length; i++)
    {
      char ch = toEscape.charAt(i);
      switch (ch)
      {
      case '"': 
      case '%': 
      case '*': 
      case '/': 
      case ':': 
      case '<': 
      case '>': 
      case '?': 
      case '\\': 
      case '|': 
        buffer.append("%" + ch + ";");
        break;
      default: 
        buffer.append(ch);
      }
    }
    return buffer.toString();
  }
  
  public IStatus rollback(IProfile profile)
  {
    IStatus returnStatus = Status.OK_STATUS;
    IBackupStore store = getBackupStore(profile);
    try
    {
      store.restore();
    }
    catch (IOException e)
    {
      returnStatus = new Status(4, "org.eclipse.equinox.p2.touchpoint.natives", NLS.bind(Messages.failed_backup_restore, store.getBackupName()), e);
    }
    catch (ClosedBackupStoreException e)
    {
      returnStatus = new Status(4, "org.eclipse.equinox.p2.touchpoint.natives", NLS.bind(Messages.failed_backup_restore, store.getBackupName()), e);
    }
    clearProfileState(profile);
    return returnStatus;
  }
  
  private static synchronized void clearProfileState(IProfile profile)
  {
    backups.remove(profile);
  }
  
  private static synchronized IBackupStore getBackupStore(IProfile profile)
  {
    IBackupStore store = (IBackupStore)backups.get(profile);
    if (store == null)
    {
      store = new LazyBackupStore(escape(profile.getProfileId()));
      backups.put(profile, store);
    }
    return store;
  }
}

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

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
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.p2.core.IAgentLocation;
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.repository.artifact.IArtifactRepository;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager;
import org.eclipse.equinox.p2.repository.artifact.IFileArtifactRepository;
import org.eclipse.osgi.util.NLS;

public class Util
{
  public static void log(String message)
  {
    LogHelper.log(createError(message));
  }
  
  public static IStatus createError(String message)
  {
    return new Status(4, "org.eclipse.equinox.p2.touchpoint.natives", message);
  }
  
  public static String getInstallFolder(IProfile profile)
  {
    return profile.getProperty("org.eclipse.equinox.p2.installFolder");
  }
  
  private static IAgentLocation getAgentLocation(IProvisioningAgent agent)
  {
    return (IAgentLocation)agent.getService(IAgentLocation.SERVICE_NAME);
  }
  
  public static IArtifactRepositoryManager getArtifactRepositoryManager(IProvisioningAgent agent)
  {
    return (IArtifactRepositoryManager)agent.getService(IArtifactRepositoryManager.SERVICE_NAME);
  }
  
  public static IFileArtifactRepository getDownloadCacheRepo(IProvisioningAgent agent)
    throws ProvisionException
  {
    URI location = getDownloadCacheLocation(agent);
    if (location == null) {
      throw new IllegalStateException(Messages.could_not_obtain_download_cache);
    }
    IArtifactRepositoryManager manager = getArtifactRepositoryManager(agent);
    if (manager == null) {
      throw new IllegalStateException(Messages.artifact_repo_not_found);
    }
    IArtifactRepository repository;
    try
    {
      repository = manager.loadRepository(location, null);
    }
    catch (ProvisionException localProvisionException)
    {
      IArtifactRepository repository;
      String repositoryName = location + " - Agent download cache";
      Map<String, String> properties = new HashMap(1);
      properties.put("p2.system", Boolean.TRUE.toString());
      repository = manager.createRepository(location, repositoryName, "org.eclipse.equinox.p2.artifact.repository.simpleRepository", properties);
    }
    IFileArtifactRepository downloadCache = (IFileArtifactRepository)repository.getAdapter(IFileArtifactRepository.class);
    if (downloadCache == null) {
      throw new ProvisionException(NLS.bind(Messages.download_cache_not_writeable, location));
    }
    return downloadCache;
  }
  
  private static URI getDownloadCacheLocation(IProvisioningAgent agent)
  {
    IAgentLocation location = getAgentLocation(agent);
    if (location == null) {
      return null;
    }
    return URIUtil.append(location.getDataArea("org.eclipse.equinox.p2.core"), "cache/");
  }
  
  public static File[] unzipFile(File zipFile, File outputDir, IBackupStore store, String taskName, IProgressMonitor monitor)
    throws IOException
  {
    InputStream in = new FileInputStream(zipFile);
    try
    {
      return unzipStream(in, zipFile.length(), outputDir, store, taskName, monitor);
    }
    catch (IOException e)
    {
      throw new IOException(NLS.bind(Messages.Util_Error_Unzipping, zipFile, e.getMessage()));
    }
    finally
    {
      in.close();
    }
  }
  
  public static File[] unzipStream(InputStream stream, long size, File outputDir, IBackupStore store, String taskName, IProgressMonitor monitor)
    throws IOException
  {
    InputStream is = monitor == null ? stream : stream;
    ZipInputStream in = new ZipInputStream(new BufferedInputStream(is));
    ZipEntry ze = in.getNextEntry();
    if (ze == null)
    {
      in.close();
      throw new IOException(Messages.Util_Invalid_Zip_File_Format);
    }
    ArrayList<File> unzippedFiles = new ArrayList();
    do
    {
      File outFile = new File(outputDir, ze.getName());
      unzippedFiles.add(outFile);
      if (ze.isDirectory())
      {
        outFile.mkdirs();
      }
      else
      {
        if (outFile.exists())
        {
          if (store != null) {
            store.backup(outFile);
          } else {
            outFile.delete();
          }
        }
        else {
          outFile.getParentFile().mkdirs();
        }
        try
        {
          copyStream(in, false, new FileOutputStream(outFile), true);
        }
        catch (FileNotFoundException localFileNotFoundException) {}
        outFile.setLastModified(ze.getTime());
      }
      in.closeEntry();
    } while ((ze = in.getNextEntry()) != null);
    in.close();
    
    return (File[])unzippedFiles.toArray(new File[unzippedFiles.size()]);
  }
  
  /* Error */
  public static int copyStream(InputStream in, boolean closeIn, java.io.OutputStream out, boolean closeOut)
    throws IOException
  {
    // Byte code:
    //   0: iconst_0
    //   1: istore 4
    //   3: sipush 16384
    //   6: newarray <illegal type>
    //   8: astore 5
    //   10: goto +19 -> 29
    //   13: aload_2
    //   14: aload 5
    //   16: iconst_0
    //   17: iload 6
    //   19: invokevirtual 315	java/io/OutputStream:write	([BII)V
    //   22: iload 4
    //   24: iload 6
    //   26: iadd
    //   27: istore 4
    //   29: aload_0
    //   30: aload 5
    //   32: invokevirtual 313	java/io/InputStream:read	([B)I
    //   35: dup
    //   36: istore 6
    //   38: iconst_m1
    //   39: if_icmpne -26 -> 13
    //   42: iload 4
    //   44: istore 8
    //   46: iload_1
    //   47: ifeq +23 -> 70
    //   50: aload_0
    //   51: invokevirtual 312	java/io/InputStream:close	()V
    //   54: goto +16 -> 70
    //   57: astore 9
    //   59: iload_3
    //   60: ifeq +7 -> 67
    //   63: aload_2
    //   64: invokevirtual 314	java/io/OutputStream:close	()V
    //   67: aload 9
    //   69: athrow
    //   70: iload_3
    //   71: ifeq +7 -> 78
    //   74: aload_2
    //   75: invokevirtual 314	java/io/OutputStream:close	()V
    //   78: iload 8
    //   80: ireturn
    //   81: astore 7
    //   83: iload_1
    //   84: ifeq +23 -> 107
    //   87: aload_0
    //   88: invokevirtual 312	java/io/InputStream:close	()V
    //   91: goto +16 -> 107
    //   94: astore 9
    //   96: iload_3
    //   97: ifeq +7 -> 104
    //   100: aload_2
    //   101: invokevirtual 314	java/io/OutputStream:close	()V
    //   104: aload 9
    //   106: athrow
    //   107: iload_3
    //   108: ifeq +7 -> 115
    //   111: aload_2
    //   112: invokevirtual 314	java/io/OutputStream:close	()V
    //   115: aload 7
    //   117: athrow
    // Line number table:
    //   Java source line #146	-> byte code offset #0
    //   Java source line #147	-> byte code offset #3
    //   Java source line #149	-> byte code offset #10
    //   Java source line #150	-> byte code offset #13
    //   Java source line #151	-> byte code offset #22
    //   Java source line #149	-> byte code offset #29
    //   Java source line #153	-> byte code offset #42
    //   Java source line #156	-> byte code offset #46
    //   Java source line #157	-> byte code offset #50
    //   Java source line #159	-> byte code offset #57
    //   Java source line #160	-> byte code offset #59
    //   Java source line #161	-> byte code offset #63
    //   Java source line #163	-> byte code offset #67
    //   Java source line #160	-> byte code offset #70
    //   Java source line #161	-> byte code offset #74
    //   Java source line #153	-> byte code offset #78
    //   Java source line #154	-> byte code offset #81
    //   Java source line #156	-> byte code offset #83
    //   Java source line #157	-> byte code offset #87
    //   Java source line #159	-> byte code offset #94
    //   Java source line #160	-> byte code offset #96
    //   Java source line #161	-> byte code offset #100
    //   Java source line #163	-> byte code offset #104
    //   Java source line #160	-> byte code offset #107
    //   Java source line #161	-> byte code offset #111
    //   Java source line #164	-> byte code offset #115
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	118	0	in	InputStream
    //   0	118	1	closeIn	boolean
    //   0	118	2	out	java.io.OutputStream
    //   0	118	3	closeOut	boolean
    //   1	42	4	written	int
    //   8	23	5	buffer	byte[]
    //   13	12	6	len	int
    //   36	3	6	len	int
    //   81	35	7	localObject1	Object
    //   44	35	8	i	int
    //   57	11	9	localObject2	Object
    //   94	11	9	localObject3	Object
    // Exception table:
    //   from	to	target	type
    //   46	57	57	finally
    //   0	46	81	finally
    //   83	94	94	finally
  }
}

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

public class ActionConstants
{
  public static final String PARM_AGENT = "agent";
  public static final String PARM_PATH = "path";
  public static final String PARM_TARGET_FILE = "targetFile";
  public static final String PARM_PERMISSIONS = "permissions";
  public static final String PARM_TARGET_DIR = "targetDir";
  public static final String PARM_TARGET = "target";
  public static final String PARM_SOURCE = "source";
  public static final String PARM_IU = "iu";
  public static final String PIPE = "|";
  public static final String PARM_AT_ARTIFACT = "@artifact";
  public static final String PARM_ARTIFACT_REQUESTS = "artifactRequests";
  public static final String PARM_PROFILE = "profile";
  public static final String PARM_LINK_NAME = "linkName";
  public static final String PARM_LINK_TARGET = "linkTarget";
  public static final String PARM_LINK_FORCE = "force";
  public static final String PARM_COPY_TARGET = "target";
  public static final String PARM_COPY_SOURCE = "source";
  public static final String PARM_COPY_OVERWRITE = "overwrite";
  public static final String PARM_OPTIONS = "options";
}

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

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Map;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.internal.p2.touchpoint.natives.Messages;
import org.eclipse.equinox.internal.p2.touchpoint.natives.Util;
import org.eclipse.equinox.p2.engine.spi.ProvisioningAction;
import org.eclipse.osgi.util.NLS;

public class ChmodAction
  extends ProvisioningAction
{
  private static final String ACTION_CHMOD = "chmod";
  private static final boolean WINDOWS = File.separatorChar == '\\';
  
  public IStatus execute(Map<String, Object> parameters)
  {
    String targetDir = (String)parameters.get("targetDir");
    if (targetDir == null) {
      return Util.createError(NLS.bind(Messages.param_not_set, "targetDir", "chmod"));
    }
    String targetFile = (String)parameters.get("targetFile");
    if (targetFile == null) {
      return Util.createError(NLS.bind(Messages.param_not_set, "targetFile", "chmod"));
    }
    String permissions = (String)parameters.get("permissions");
    if (permissions == null) {
      return Util.createError(NLS.bind(Messages.param_not_set, "permissions", "chmod"));
    }
    String optionsString = (String)parameters.get("options");
    
    File probe = new File(targetDir + '/' + targetFile);
    if (!probe.exists()) {
      return Util.createError(NLS.bind(Messages.action_0_failed_file_1_doesNotExist, "chmod", probe.toString()));
    }
    String[] options = (String[])null;
    if (optionsString != null)
    {
      ArrayList<String> collect = new ArrayList();
      String r = optionsString.trim();
      while (r.length() > 0)
      {
        int spaceIdx = r.indexOf(' ');
        if (spaceIdx < 0)
        {
          collect.add(r);
          r = "";
        }
        else
        {
          collect.add(r.substring(0, spaceIdx));
          r = r.substring(spaceIdx + 1);
          r = r.trim();
        }
      }
      if (collect.size() > 0)
      {
        options = new String[collect.size()];
        collect.toArray(options);
      }
    }
    chmod(targetDir, targetFile, permissions, options);
    return Status.OK_STATUS;
  }
  
  public IStatus undo(Map<String, Object> parameters)
  {
    return Status.OK_STATUS;
  }
  
  public void chmod(String targetDir, String targetFile, String perms, String[] options)
  {
    if (WINDOWS) {
      return;
    }
    Runtime r = Runtime.getRuntime();
    try
    {
      String[] args = new String[3 + (options == null ? 0 : options.length)];
      int i = 0;
      args[(i++)] = "chmod";
      if (options != null) {
        for (int j = 0; j < options.length; j++) {
          args[(i++)] = options[j];
        }
      }
      args[(i++)] = perms;
      args[i] = (targetDir + '/' + targetFile);
  
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