/**
  * Reads and returns the VM arguments specified in the running platform's .ini file, or am empty
  * string if none.
  *
  * @return VM arguments specified in the running platform's .ini file
  */
 public static String getIniVMArgs() {
   File installDirectory = new File(Platform.getInstallLocation().getURL().getFile());
   if (Platform.getOS().equals(Platform.OS_MACOSX))
     installDirectory = new File(installDirectory, "Eclipse.app/Contents/MacOS"); // $NON-NLS-1$
   File eclipseIniFile = new File(installDirectory, "eclipse.ini"); // $NON-NLS-1$
   BufferedReader in = null;
   StringBuffer result = new StringBuffer();
   if (eclipseIniFile.exists()) {
     try {
       in = new BufferedReader(new FileReader(eclipseIniFile));
       String str;
       boolean vmargs = false;
       while ((str = in.readLine()) != null) {
         if (vmargs) {
           if (result.length() > 0) result.append(" "); // $NON-NLS-1$
           result.append(str);
         }
         // start concat'ng if we have vmargs
         if (vmargs == false && str.equals("-vmargs")) // $NON-NLS-1$
         vmargs = true;
       }
     } catch (IOException e) {
       MDECore.log(e);
     } finally {
       if (in != null)
         try {
           in.close();
         } catch (IOException e) {
           MDECore.log(e);
         }
     }
   }
   return result.toString();
 }
 /**
  * create the LD_LIBRARY_PATH information
  *
  * @param exePath the path to put into LD_LIBRARY_PATH
  * @return environment string
  */
 private String getLibraryPath(IPath exePath) {
   // TODO: Should append if already present
   StringBuffer buf = new StringBuffer();
   buf.append("LD_LIBRARY_PATH"); // $NON-NLS-1$
   buf.append('=');
   exePath = exePath.removeLastSegments(1);
   buf.append(exePath.toOSString());
   return buf.toString();
 }
 private String join(String delimiter, String[] parts, int offset, int n) {
   StringBuffer builder = new StringBuffer();
   for (int i = offset; i < n; i++) {
     builder.append(parts[i]);
     if (i < parts.length - 1) {
       builder.append(delimiter);
     }
   }
   return builder.toString();
 }
Exemple #4
0
 protected String getFormattedPackageName(String id) {
   StringBuffer buffer = new StringBuffer();
   for (int i = 0; i < id.length(); i++) {
     char ch = id.charAt(i);
     if (buffer.length() == 0) {
       if (Character.isJavaIdentifierStart(ch)) buffer.append(Character.toLowerCase(ch));
     } else {
       if (Character.isJavaIdentifierPart(ch) || ch == '.') buffer.append(ch);
     }
   }
   return buffer.toString().toLowerCase(Locale.ENGLISH);
 }
Exemple #5
0
  public void setTask(int template, String task[]) {
    if (m_monitor != null) {
      switch (template) {
        case TASK_CONNECT:
          m_monitor.setTaskName("Connecting to SFTP Site");
          break;

        case TASK_SCANNING:
          m_monitor.setTaskName("Scanning directories");
          break;

        case TASK_TRANSFER:
          if (task.length == 2) {
            m_monitor.setTaskName(task[0] + ":\t" + task[1]);
          }
          break;

        case TASK_COMPLETE:
          m_monitor.setTaskName("Transfer completed");
          break;

        case TASK_ERROR:
          if (task.length >= 1) {
            m_monitor.setTaskName("ERROR: " + task[0]);
            for (int a = 0; a < task.length; a++) {
              m_output.append(task[a] + "\n");
              System.out.println(task[a]);
            }
          }
          break;
      }
    }
  }
  private String getBundles(boolean defaultAuto) {
    StringBuffer buffer = new StringBuffer();
    Iterator iter = fModels.keySet().iterator();
    while (iter.hasNext()) {
      IMonitorModelBase model = (IMonitorModelBase) iter.next();
      String id = model.getMonitorBase().getId();
      if (!IPDEBuildConstants.BUNDLE_OSGI.equals(id)) {
        if (buffer.length() > 0) buffer.append(","); // $NON-NLS-1$
        buffer.append(LaunchConfigurationHelper.getBundleURL(model, true));

        // fragments must not be started or have a start level
        if (model instanceof IFragmentModel) continue;

        String data = fModels.get(model).toString();
        appendStartData(buffer, data, defaultAuto);
      }
    }
    return buffer.toString();
  }
  /**
   * Convenience method to parses the startData ("startLevel:autoStart"), convert it to the format
   * expected by the OSGi bundles property, and append to a StringBuffer.
   *
   * @param buffer buffer to append the data to
   * @param startData data to parse ("startLevel:autoStart")
   * @param defaultAuto default auto start setting
   */
  private void appendStartData(StringBuffer buffer, String startData, boolean defaultAuto) {
    int index = startData.indexOf(':');
    String level = index > 0 ? startData.substring(0, index) : "default"; // $NON-NLS-1$
    String auto =
        index > 0 && index < startData.length() - 1
            ? startData.substring(index + 1)
            : "default"; //$NON-NLS-1$
    if ("default".equals(auto)) // $NON-NLS-1$
    auto = Boolean.toString(defaultAuto);
    if (!level.equals("default") || "true".equals(auto)) // $NON-NLS-1$ //$NON-NLS-2$
    buffer.append("@"); // $NON-NLS-1$

    if (!level.equals("default")) { // $NON-NLS-1$
      buffer.append(level);
      if ("true".equals(auto)) // $NON-NLS-1$
      buffer.append(":"); // $NON-NLS-1$
    }
    if ("true".equals(auto)) { // $NON-NLS-1$
      buffer.append("start"); // $NON-NLS-1$
    }
  }
  /** Returns the name of the Eclipse application launcher. */
  private static String getLauncherName(String name, String os, File installFolder) {
    if (os == null) {
      EnvironmentInfo info =
          (EnvironmentInfo)
              ServiceHelper.getService(Activator.getContext(), EnvironmentInfo.class.getName());
      if (info == null) return null;
      os = info.getOS();
    }

    if (os.equals(org.eclipse.osgi.service.environment.Constants.OS_WIN32)) {
      IPath path = new Path(name);
      if ("exe".equals(path.getFileExtension())) // $NON-NLS-1$
      return name;
      return name + ".exe"; // $NON-NLS-1$
    }
    if (os.equals(Constants.MACOSX_BUNDLED)) {
      return "/Contents/MacOS/" + name; // $NON-NLS-1$
    }

    if (os.equals(org.eclipse.osgi.service.environment.Constants.OS_MACOSX)) {
      IPath path = new Path(name);
      if (path.segment(0).endsWith(".app")) // $NON-NLS-1$
      return name;

      String appName = null;
      if (installFolder != null) {
        File appFolder = new File(installFolder, name + ".app"); // $NON-NLS-1$
        if (appFolder.exists()) {
          try {
            appName = appFolder.getCanonicalFile().getName();
          } catch (IOException e) {
            appName = appFolder.getName();
          }
        }
      }

      StringBuffer buffer = new StringBuffer();
      if (appName != null) {
        buffer.append(appName);
      } else {
        buffer.append(name.substring(0, 1).toUpperCase());
        buffer.append(name.substring(1));
        buffer.append(".app"); // $NON-NLS-1$
      }
      buffer.append("/Contents/MacOS/"); // $NON-NLS-1$
      buffer.append(name);
      return buffer.toString();
    }
    return name;
  }
  private byte[] readMultiPartChunk(ServletInputStream requestStream, String contentType)
      throws IOException {
    // fast forward stream past multi-part header
    int boundaryOff = contentType.indexOf("boundary="); // $NON-NLS-1$
    String boundary = contentType.substring(boundaryOff + 9);
    BufferedReader reader =
        new BufferedReader(new InputStreamReader(requestStream, "ISO-8859-1")); // $NON-NLS-1$
    StringBuffer out = new StringBuffer();
    // skip headers up to the first blank line
    String line = reader.readLine();
    while (line != null && line.length() > 0) line = reader.readLine();
    // now process the file

    char[] buf = new char[1000];
    int read;
    while ((read = reader.read(buf)) > 0) {
      out.append(buf, 0, read);
    }
    // remove the boundary from the output (end of input is \r\n--<boundary>--\r\n)
    out.setLength(out.length() - (boundary.length() + 8));
    return out.toString().getBytes("ISO-8859-1"); // $NON-NLS-1$
  }
 /** For debugging purposes. */
 public String toString() {
   StringBuffer buf = new StringBuffer("CheatSheetCollection, "); // $NON-NLS-1$
   buf.append(childCollections.size());
   buf.append(" children, "); // $NON-NLS-1$
   buf.append(cheatsheets.size());
   buf.append(" cheatsheets"); // $NON-NLS-1$
   return buf.toString();
 }
 /** @return the default list of bundles to use in the osgi.bundles property */
 public static String getDefaultBundleList() {
   StringBuffer buffer = new StringBuffer();
   if (getTargetVersion() > 3.1) {
     buffer.append("org.eclipse.equinox.common@2:start,"); // $NON-NLS-1$
     buffer.append("org.eclipse.update.configurator@3:start,"); // $NON-NLS-1$
     buffer.append("org.eclipse.core.runtime@start"); // $NON-NLS-1$
   } else {
     buffer.append("org.eclipse.core.runtime@2:start,"); // $NON-NLS-1$
     buffer.append("org.eclipse.update.configurator@3:start"); // $NON-NLS-1$
   }
   return buffer.toString();
 }
 // Fully read the file pointed to by the given path
 private String read(String path) {
   File file = new File(path);
   if (!file.exists()) return null;
   StringBuffer buffer = new StringBuffer();
   BufferedReader reader = null;
   try {
     reader = new BufferedReader(new FileReader(file));
     for (String line = reader.readLine(); line != null; line = reader.readLine()) {
       buffer.append(line);
       buffer.append('\n');
     }
   } catch (IOException e) {
     // TODO
   } finally {
     if (reader != null)
       try {
         reader.close();
       } catch (IOException e) {
         // ignore
       }
   }
   return buffer.toString();
 }
  /**
   * Removes path information from the given string containing one or more comma separated osgi
   * bundles. Replaces escaped '\:' with ':'. Removes, reference, platform and file prefixes.
   * Removes any other path information converting the location or the last segment to a bundle id.
   *
   * @param osgiBundles list of bundles to strip path information from (commma separated)
   * @return list of bundles with path information stripped
   */
  public static String stripPathInformation(String osgiBundles) {
    StringBuffer result = new StringBuffer();
    StringTokenizer tokenizer = new StringTokenizer(osgiBundles, ","); // $NON-NLS-1$
    while (tokenizer.hasMoreElements()) {
      String token = tokenizer.nextToken();
      token = token.replaceAll("\\\\:|/:", ":"); // $NON-NLS-1$ //$NON-NLS-2$

      // read up until the first @, if there
      int atIndex = token.indexOf('@');
      String bundle = atIndex > 0 ? token.substring(0, atIndex) : token;
      bundle = bundle.trim();

      // strip [reference:][platform:][file:] prefixes if any
      if (bundle.startsWith(REFERENCE_PREFIX) && bundle.length() > REFERENCE_PREFIX.length())
        bundle = bundle.substring(REFERENCE_PREFIX.length());
      if (bundle.startsWith(PLATFORM_PREFIX) && bundle.length() > PLATFORM_PREFIX.length())
        bundle = bundle.substring(PLATFORM_PREFIX.length());
      if (bundle.startsWith(FILE_URL_PREFIX) && bundle.length() > FILE_URL_PREFIX.length())
        bundle = bundle.substring(FILE_URL_PREFIX.length());

      // if the path is relative, the last segment is the bundle symbolic name
      // Otherwise, we need to retrieve the bundle symbolic name ourselves
      IPath path = new Path(bundle);
      String id = null;
      if (path.isAbsolute()) {
        id = getSymbolicName(bundle);
      }
      if (id == null) {
        id = path.lastSegment();
      }
      if (id != null) {
        int underscoreIndex = id.indexOf('_');
        if (underscoreIndex >= 0) {
          id = id.substring(0, underscoreIndex);
        }
        if (id.endsWith(JAR_EXTENSION)) {
          id = id.substring(0, id.length() - 4);
        }
      }
      if (result.length() > 0) result.append(","); // $NON-NLS-1$
      result.append(id != null ? id : bundle);
      if (atIndex > -1) result.append(token.substring(atIndex).trim());
    }
    return result.toString();
  }
  private IStatus calculateStatus(IRefreshEvent event) {
    StringBuffer text = new StringBuffer();
    int code = IStatus.OK;
    int changeCount = event.getChangeDescription().getChangeCount();
    int numChanges = getChangeCount();
    if (numChanges > 0) {
      code = IRefreshEvent.STATUS_CHANGES;

      int incomingChanges = getIncomingChangeCount();
      String numIncomingChanges =
          incomingChanges == 0
              ? "" //$NON-NLS-1$
              : NLS.bind(
                  TeamUIMessages.RefreshCompleteDialog_incomingChanges,
                  Integer.toString(incomingChanges));

      int outgoingChanges = getOutgoingChangeCount();
      String numOutgoingChanges =
          outgoingChanges == 0
              ? "" //$NON-NLS-1$
              : NLS.bind(
                  TeamUIMessages.RefreshCompleteDialog_outgoingChanges,
                  Integer.toString(outgoingChanges));

      String sep =
          incomingChanges > 0 && outgoingChanges > 0 ? "; " : ""; // $NON-NLS-1$ //$NON-NLS-2$

      if (changeCount > 0) {
        // New changes found
        code = IRefreshEvent.STATUS_NEW_CHANGES;
        String numNewChanges = Integer.toString(changeCount);
        if (changeCount == 1) {
          text.append(
              NLS.bind(
                  TeamUIMessages.RefreshCompleteDialog_newChangesSingular,
                  (new Object[] {
                    getName(), numNewChanges, numIncomingChanges, sep, numOutgoingChanges
                  })));
        } else {
          text.append(
              NLS.bind(
                  TeamUIMessages.RefreshCompleteDialog_newChangesPlural,
                  (new Object[] {
                    getName(), numNewChanges, numIncomingChanges, sep, numOutgoingChanges
                  })));
        }
      } else {
        // Refreshed resources contain changes
        if (numChanges == 1) {
          text.append(
              NLS.bind(
                  TeamUIMessages.RefreshCompleteDialog_changesSingular,
                  (new Object[] {
                    getName(), new Integer(numChanges), numIncomingChanges, sep, numOutgoingChanges
                  })));
        } else {
          text.append(
              NLS.bind(
                  TeamUIMessages.RefreshCompleteDialog_changesPlural,
                  (new Object[] {
                    getName(), new Integer(numChanges), numIncomingChanges, sep, numOutgoingChanges
                  })));
        }
      }
    } else {
      // No changes found
      code = IRefreshEvent.STATUS_NO_CHANGES;
      text.append(NLS.bind(TeamUIMessages.RefreshCompleteDialog_6, new String[] {getName()}));
    }
    return new Status(IStatus.OK, TeamUIPlugin.ID, code, text.toString(), null);
  }
  private void saveConfigurationFile(ILaunchConfiguration configuration) throws CoreException {
    Properties properties = new Properties();
    properties.setProperty(
        "osgi.install.area", "file:" + TargetPlatform.getLocation()); // $NON-NLS-1$ //$NON-NLS-2$
    properties.setProperty("osgi.configuration.cascaded", "false"); // $NON-NLS-1$ //$NON-NLS-2$
    properties.put(
        "osgi.framework",
        LaunchConfigurationHelper.getBundleURL(
            IPDEBuildConstants.BUNDLE_OSGI, fAllBundles, false)); // $NON-NLS-1$
    int start = configuration.getAttribute(IPDELauncherConstants.DEFAULT_START_LEVEL, 4);
    properties.put("osgi.bundles.defaultStartLevel", Integer.toString(start)); // $NON-NLS-1$
    boolean autostart = configuration.getAttribute(IPDELauncherConstants.DEFAULT_AUTO_START, true);

    String bundles = null;
    if (fAllBundles.containsKey(IPDEBuildConstants.BUNDLE_SIMPLE_CONFIGURATOR)) {

      // If update configurator is set to its default start level, override it as simple/update
      // configurators should not be autostarted together
      Object updateConfiguratorBundle =
          fAllBundles.get(IPDEBuildConstants.BUNDLE_UPDATE_CONFIGURATOR);
      if (updateConfiguratorBundle != null) {
        String startLevel = (String) fModels.get(updateConfiguratorBundle);
        if (startLevel != null
            && startLevel.equals(BundleLauncherHelper.DEFAULT_UPDATE_CONFIGURATOR_START_LEVEL)) {
          fModels.put(updateConfiguratorBundle, "4:false"); // $NON-NLS-1$
        }
      }

      // If simple configurator is being used, we need to write out the bundles.txt instead of
      // writing out the list in the config.ini
      URL bundlesTxt =
          P2Utils.writeBundlesTxt(fModels, start, autostart, getConfigDir(configuration), null);
      if (bundlesTxt != null) {
        properties.setProperty(
            "org.eclipse.equinox.simpleconfigurator.configUrl",
            bundlesTxt.toString()); // $NON-NLS-1$
        if (fAllBundles.get(IPDEBuildConstants.BUNDLE_UPDATE_CONFIGURATOR) != null) {
          properties.setProperty(
              "org.eclipse.update.reconcile", "false"); // $NON-NLS-1$ //$NON-NLS-2$
        }
      }
      StringBuffer buffer = new StringBuffer();
      IMonitorModelBase model =
          (IMonitorModelBase) fAllBundles.get(IPDEBuildConstants.BUNDLE_SIMPLE_CONFIGURATOR);
      buffer.append(LaunchConfigurationHelper.getBundleURL(model, true));
      appendStartData(buffer, (String) fModels.get(model), autostart);
      bundles = buffer.toString();
    } else {
      bundles = getBundles(autostart);
    }
    if (bundles.length() > 0) properties.put("osgi.bundles", bundles); // $NON-NLS-1$

    if (!"3.3"
        .equals(
            configuration.getAttribute(
                IPDEConstants.LAUNCHER_PDE_VERSION, ""))) { // $NON-NLS-1$ //$NON-NLS-2$
      properties.put("eclipse.ignoreApp", "true"); // $NON-NLS-1$ //$NON-NLS-2$
      properties.put("osgi.noShutdown", "true"); // $NON-NLS-1$ //$NON-NLS-2$
    }

    LaunchConfigurationHelper.save(
        new File(getConfigDir(configuration), "config.ini"), properties); // $NON-NLS-1$
  }
Exemple #16
0
 public String getTransferOuput() {
   return m_output.toString();
 }
  /*
   * Return a file handle pointing to the platform binary zip. Method never returns null because
   * it will fail an assert before that.
   */
  private File getPlatformZip() {
    String property = null;
    File file = null;
    if (propertyToPlatformArchive != null) {
      property = getValueFor(propertyToPlatformArchive);
      String message =
          "Need to set the "
              + "\""
              + propertyToPlatformArchive
              + "\" system property with a valid path to the platform binary drop or copy the archive to be a sibling of the install folder.";
      if (property == null) {
        fail(message);
      }
      file = new File(property);
      assertNotNull(message, file);
      assertTrue(message, file.exists());
      assertTrue("File is zero length: " + file.getAbsolutePath(), file.length() > 0);
      return file;
    }

    property = getValueFor("org.eclipse.equinox.p2.reconciler.tests.platform.archive");
    if (property == null) {
      // the releng test framework copies the zip so let's look for it...
      // it will be a sibling of the eclipse/ folder that we are running
      File installLocation = getInstallLocation();
      if (Platform.getWS().equals(Platform.WS_COCOA))
        installLocation = installLocation.getParentFile().getParentFile();

      if (installLocation != null) {
        // parent will be "eclipse" and the parent's parent will be "eclipse-testing"
        File parent = installLocation.getParentFile();
        if (parent != null) {
          parent = parent.getParentFile();
          if (parent != null) {
            File[] children =
                parent.listFiles(
                    new FileFilter() {
                      public boolean accept(File pathname) {
                        String name = pathname.getName();
                        return name.startsWith("eclipse-platform-");
                      }
                    });
            if (children != null && children.length == 1) file = children[0];
          }
        }
      }
    } else {
      file = new File(property);
    }
    StringBuffer detailedMessage = new StringBuffer(600);
    detailedMessage
        .append(" propertyToPlatformArchive was ")
        .append(propertyToPlatformArchive == null ? " not set " : propertyToPlatformArchive)
        .append('\n');
    detailedMessage
        .append(" org.eclipse.equinox.p2.reconciler.tests.platform.archive was ")
        .append(property == null ? " not set " : property)
        .append('\n');
    detailedMessage.append(" install location is ").append(getInstallLocation()).append('\n');
    String message =
        "Need to set the \"org.eclipse.equinox.p2.reconciler.tests.platform.archive\" system property with a valid path to the platform binary drop or copy the archive to be a sibling of the install folder.";
    assertNotNull(message + "\n" + detailedMessage, file);
    assertTrue(message, file.exists());
    assertTrue("File is zero length: " + file.getAbsolutePath(), file.length() > 0);
    return file;
  }