private Map promptForOverwrite(List plugins, List locales) {
    Map overwrites = new HashMap();

    if (overwriteWithoutAsking) return overwrites;

    for (Iterator iter = plugins.iterator(); iter.hasNext(); ) {
      IPluginModelBase plugin = (IPluginModelBase) iter.next();
      for (Iterator it = locales.iterator(); it.hasNext(); ) {
        Locale locale = (Locale) it.next();
        IProject project = getNLProject(plugin, locale);

        if (project.exists() && !overwrites.containsKey(project.getName())) {
          boolean overwrite =
              MessageDialog.openConfirm(
                  PDEPlugin.getActiveWorkbenchShell(),
                  PDEUIMessages.InternationalizeWizard_NLSFragmentGenerator_overwriteTitle,
                  NLS.bind(
                      PDEUIMessages.InternationalizeWizard_NLSFragmentGenerator_overwriteMessage,
                      pluginName(plugin, locale)));
          overwrites.put(project.getName(), overwrite ? OVERWRITE : null);
        }
      }
    }

    return overwrites;
  }
  /**
   * Creates an NL fragment project along with the locale specific properties files.
   *
   * @throws CoreException
   * @throws IOException
   * @throws InvocationTargetException
   * @throws InterruptedException
   */
  private void internationalizePlugins(List plugins, List locales, Map overwrites)
      throws CoreException, IOException, InvocationTargetException, InterruptedException {

    Set created = new HashSet();

    for (Iterator it = plugins.iterator(); it.hasNext(); ) {
      IPluginModelBase plugin = (IPluginModelBase) it.next();

      for (Iterator iter = locales.iterator(); iter.hasNext(); ) {
        Locale locale = (Locale) iter.next();

        IProject project = getNLProject(plugin, locale);
        if (created.contains(project)
            || overwriteWithoutAsking
            || !project.exists()
            || OVERWRITE == overwrites.get(project.getName())) {
          if (!created.contains(project) && project.exists()) {
            project.delete(true, getProgressMonitor());
          }

          if (!created.contains(project)) {
            createNLFragment(plugin, project, locale);
            created.add(project);
            project.getFolder(RESOURCE_FOLDER_PARENT).create(false, true, getProgressMonitor());
          }

          project
              .getFolder(RESOURCE_FOLDER_PARENT)
              .getFolder(locale.toString())
              .create(true, true, getProgressMonitor());
          createLocaleSpecificPropertiesFile(project, plugin, locale);
        }
      }
    }
  }
Esempio n. 3
0
 /** A repository root has been added. Notify any listeners. */
 public void rootAdded(ICVSRepositoryLocation root) {
   Iterator it = listeners.iterator();
   while (it.hasNext()) {
     IRepositoryListener listener = (IRepositoryListener) it.next();
     listener.repositoryAdded(root);
   }
 }
Esempio n. 4
0
 private void broadcastRepositoriesChanged(ICVSRepositoryLocation[] roots) {
   if (roots.length == 0) return;
   Iterator it = listeners.iterator();
   while (it.hasNext()) {
     IRepositoryListener listener = (IRepositoryListener) it.next();
     listener.repositoriesChanged(roots);
   }
 }
 private void ensureResourceCovered(IResource resource, List list) {
   IPath path = resource.getFullPath();
   for (Iterator iter = list.iterator(); iter.hasNext(); ) {
     IResource root = (IResource) iter.next();
     if (root.getFullPath().isPrefixOf(path)) {
       return;
     }
   }
   list.add(resource);
 }
  /**
   * Tests that a target definition based on the default target platform restricted to a subset of
   * bundle versions contains the right set.
   *
   * @throws Exception
   */
  public void testVersionRestrictedDefaultTargetPlatform() throws Exception {
    ITargetDefinition definition = getNewTarget();
    ITargetLocation container =
        getTargetService().newProfileLocation(TargetPlatform.getDefaultLocation(), null);
    definition.setTargetLocations(new ITargetLocation[] {container});
    List infos = getAllBundleInfos(definition);
    // find right versions
    String v1 = null;
    String v2 = null;
    Iterator iterator = infos.iterator();
    while (iterator.hasNext() && (v2 == null || v1 == null)) {
      BundleInfo info = (BundleInfo) iterator.next();
      if (info.getSymbolicName().equals("org.eclipse.jdt.launching")) {
        v1 = info.getVersion();
      } else if (info.getSymbolicName().equals("org.eclipse.jdt.debug")) {
        v2 = info.getVersion();
      }
    }
    assertNotNull(v1);
    assertFalse(v1.equals(BundleInfo.EMPTY_VERSION));
    assertNotNull(v2);
    assertFalse(v2.equals(BundleInfo.EMPTY_VERSION));

    NameVersionDescriptor[] restrictions =
        new NameVersionDescriptor[] {
          new NameVersionDescriptor("org.eclipse.jdt.launching", v1),
          new NameVersionDescriptor("org.eclipse.jdt.debug", v2)
        };
    definition.setIncluded(restrictions);
    infos = getAllBundleInfos(definition);

    assertEquals("Wrong number of bundles", 2, infos.size());
    iterator = infos.iterator();
    while (iterator.hasNext()) {
      BundleInfo info = (BundleInfo) iterator.next();
      if (info.getSymbolicName().equals("org.eclipse.jdt.launching")) {
        assertEquals(v1, info.getVersion());
      } else if (info.getSymbolicName().equals("org.eclipse.jdt.debug")) {
        assertEquals(v2, info.getVersion());
      }
    }
  }
 /**
  * Returns a status that represents the exceptions collected. If the collector is empty <code>
  * IStatus.OK</code> is returned. Otherwise a MultiStatus containing all collected exceptions is
  * returned.
  *
  * @return a multistatus containing the exceptions collected or IStatus.OK if the collector is
  *     empty.
  */
 public IStatus getStatus() {
   if (statuses.isEmpty()) {
     return Status.OK_STATUS;
   } else {
     MultiStatus multiStatus = new MultiStatus(pluginId, severity, message, null);
     Iterator it = statuses.iterator();
     while (it.hasNext()) {
       IStatus status = (IStatus) it.next();
       multiStatus.merge(status);
     }
     return multiStatus;
   }
 }
  /**
   * Tests a JDT feature bundle container contains the appropriate bundles for a specific OS.
   *
   * @throws Exception
   */
  public void testMacOSFeatureBundleContainer() throws Exception {
    // extract the feature
    IPath location = extractModifiedFeatures();

    ITargetDefinition definition = getNewTarget();
    definition.setOS(Platform.OS_MACOSX);
    ITargetLocation container =
        getTargetService().newFeatureLocation(location.toOSString(), "org.eclipse.jdt", null);
    container.resolve(definition, null);
    TargetBundle[] bundles = container.getBundles();

    List expected = new ArrayList();
    expected.add("org.eclipse.jdt");
    expected.add("org.eclipse.jdt.launching");
    // 2 versions of JUnit
    expected.add("org.junit");
    expected.add("org.junit");
    expected.add("org.junit4");
    expected.add("org.eclipse.jdt.launching.macosx");

    assertEquals("Wrong number of bundles in JDT feature", expected.size(), bundles.length);
    for (int i = 0; i < bundles.length; i++) {
      String symbolicName = bundles[i].getBundleInfo().getSymbolicName();
      expected.remove(symbolicName);
      if (symbolicName.equals("org.eclipse.jdt.launching.macosx")) {
        // the bundle should be missing unless on Mac
        IStatus status = bundles[i].getStatus();
        if (Platform.getOS().equals(Platform.OS_MACOSX)) {
          assertTrue("Mac bundle should be present", status.isOK());
        } else {
          assertFalse("Mac bundle should be missing", status.isOK());
          assertEquals(
              "Mac bundle should be mssing",
              TargetBundle.STATUS_PLUGIN_DOES_NOT_EXIST,
              status.getCode());
        }
      }
    }
    Iterator iterator = expected.iterator();
    while (iterator.hasNext()) {
      String name = (String) iterator.next();
      System.err.println("Missing: " + name);
    }
    assertTrue("Wrong bundles in JDT feature", expected.isEmpty());

    // should be no source bundles
    for (int i = 0; i < bundles.length; i++) {
      TargetBundle bundle = bundles[i];
      assertFalse("Should be no source bundles", bundle.isSourceBundle());
    }
  }
Esempio n. 9
0
  private List<WizardFragment> getAllWizardFragments() {
    List<WizardFragment> list = new ArrayList<WizardFragment>();
    list.add(rootFragment);
    addSubWizardFragments(rootFragment, list);

    Iterator<WizardFragment> iterator = list.iterator();
    while (iterator.hasNext()) {
      WizardFragment fragment = (WizardFragment) iterator.next();
      if (!wizardModel.equals(fragment.getWizardModel())) {
        fragment.setWizardModel(wizardModel);
      }
    }
    return list;
  }
 /*
  * Iterate over the sites in the given configuration and remove the one which
  * has a url matching the given location.
  */
 public boolean removeSite(Configuration configuration, String location)
     throws IOException, URISyntaxException {
   File left = new File(new URI(location)).getCanonicalFile();
   List sites = configuration.getSites();
   for (Iterator iter = sites.iterator(); iter.hasNext(); ) {
     Site tempSite = (Site) iter.next();
     String siteURL = tempSite.getUrl();
     File right = new File(new URI(siteURL)).getCanonicalFile();
     if (left.equals(right)) {
       return configuration.removeSite(tempSite);
     }
   }
   return false;
 }
  /**
   * Tests setting the target platform to the stored JDT feature test data
   *
   * @throws Exception
   */
  public void testSetTargetPlatformToJdtFeature() throws Exception {
    try {
      // extract the feature
      IPath location = extractModifiedFeatures();
      // org.eclipse.jdt_3.6.0.v20100105-0800-7z8VFR9FMTb52_pOyKHhoek1

      ITargetDefinition target = getNewTarget();
      ITargetLocation container =
          getTargetService()
              .newFeatureLocation(
                  location.toOSString(),
                  "org.eclipse.jdt",
                  "3.6.0.v20100105-0800-7z8VFR9FMTb52_pOyKHhoek1");

      target.setTargetLocations(new ITargetLocation[] {container});

      setTargetPlatform(target);

      List expected = new ArrayList();
      expected.add("org.eclipse.jdt");
      expected.add("org.eclipse.jdt.launching");
      // 2 versions of JUnit
      expected.add("org.junit");
      expected.add("org.junit");
      expected.add("org.junit4");
      if (Platform.getOS().equals(Platform.OS_MACOSX)) {
        expected.add("org.eclipse.jdt.launching.macosx");
      }

      // current platform
      IPluginModelBase[] models = TargetPlatformHelper.getPDEState().getTargetModels();

      assertEquals("Wrong number of bundles in JDT feature", expected.size(), models.length);
      for (int i = 0; i < models.length; i++) {
        expected.remove(models[i].getPluginBase().getId());
        assertTrue(models[i].isEnabled());
      }
      Iterator iterator = expected.iterator();
      while (iterator.hasNext()) {
        String name = (String) iterator.next();
        System.err.println("Missing: " + name);
      }
      assertTrue("Wrong bundles in target platform", expected.isEmpty());
    } finally {
      resetTargetPlatform();
    }
  }
 /*
  * Assert that a feature with the given id exists in the configuration. If
  * a version is specified then match the version, otherwise any version will
  * do.
  */
 public void assertFeatureExists(
     String message, Configuration configuration, String id, String version) {
   List sites = configuration.getSites();
   assertNotNull(message, sites);
   boolean found = false;
   for (Iterator iter = sites.iterator(); iter.hasNext(); ) {
     Site site = (Site) iter.next();
     Feature[] features = site.getFeatures();
     for (int i = 0; features != null && i < features.length; i++) {
       if (id.equals(features[i].getId())) {
         if (version == null) found = true;
         else if (version.equals(features[i].getVersion())) found = true;
       }
     }
   }
   assertTrue(message, found);
 }
    public boolean include(Object object) {
      if (object instanceof IResource) {
        IResource resource = (IResource) object;
        IPath path =
            IResource.FILE == resource.getType()
                ? resource.getFullPath()
                : resource.getFullPath().addTrailingSeparator();
        object = path.toPortableString();
      }

      for (Iterator iter = filters.iterator(); iter.hasNext(); ) {
        Filter filter = (Filter) iter.next();
        if (filter.matches(object)) {
          return filter.inclusive();
        }
      }
      return default_;
    }
 private void determineBestSolutions() {
   int beingInstalledWeight = 0;
   int installationWeight = 0;
   for (Iterator<Remedy> iterator = remedies.iterator(); iterator.hasNext(); ) {
     Remedy remedy = iterator.next();
     if (remedy.getRequest() != null) {
       if (remedy.getBeingInstalledRelaxedWeight() > beingInstalledWeight
           && remedy.getInstallationRelaxedWeight() == 0) {
         bestSolutionChangingTheRequest = remedy;
         beingInstalledWeight = remedy.getBeingInstalledRelaxedWeight();
         continue;
       }
       if (remedy.getInstallationRelaxedWeight() > installationWeight
           && remedy.getBeingInstalledRelaxedWeight() == 0) {
         bestSolutionChangingWhatIsInstalled = remedy;
         installationWeight = remedy.getInstallationRelaxedWeight();
         continue;
       }
     }
   }
 }
 private String mapLocation(String location) {
   Map<String, List<String>> mappings = site.getMappings();
   String bestMatch = "";
   String prefix = null;
   for (Iterator<Entry<String, List<String>>> iterator = mappings.entrySet().iterator();
       iterator.hasNext(); ) {
     Entry<String, List<String>> entry = iterator.next();
     List<String> candidates = entry.getValue();
     for (Iterator<String> candidateIt = candidates.iterator(); candidateIt.hasNext(); ) {
       String candidate = candidateIt.next();
       if (location.startsWith(candidate) && candidate.length() > bestMatch.length()) {
         bestMatch = candidate;
         prefix = entry.getKey();
       }
     }
   }
   if (prefix != null) {
     String reverseMappedPath = prefix + location.substring(bestMatch.length());
     try {
       URI pathlessRequestURI =
           new URI(
               request.getScheme(),
               null,
               request.getServerName(),
               request.getServerPort(),
               null,
               null,
               null);
       return pathlessRequestURI.toString() + reverseMappedPath;
     } catch (URISyntaxException t) {
       // best effort
       System.err.println(t);
     }
   }
   return location;
 }