protected void finishedWith(
      String sourceLocator,
      CompilationResult result,
      char[] mainTypeName,
      ArrayList definedTypeNames,
      ArrayList duplicateTypeNames) {
    char[][] previousTypeNames = this.newState.getDefinedTypeNamesFor(sourceLocator);
    if (previousTypeNames == null) previousTypeNames = new char[][] {mainTypeName};
    IPath packagePath = null;
    next:
    for (int i = 0, l = previousTypeNames.length; i < l; i++) {
      char[] previous = previousTypeNames[i];
      for (int j = 0, m = definedTypeNames.size(); j < m; j++)
        if (CharOperation.equals(previous, (char[]) definedTypeNames.get(j))) continue next;

      SourceFile sourceFile = (SourceFile) result.getCompilationUnit();
      if (packagePath == null) {
        int count = sourceFile.sourceLocation.sourceFolder.getFullPath().segmentCount();
        packagePath =
            sourceFile.resource.getFullPath().removeFirstSegments(count).removeLastSegments(1);
      }
      if (this.secondaryTypesToRemove == null)
        this.secondaryTypesToRemove = new SimpleLookupTable();
      ArrayList types =
          (ArrayList) this.secondaryTypesToRemove.get(sourceFile.sourceLocation.binaryFolder);
      if (types == null) types = new ArrayList(definedTypeNames.size());
      types.add(packagePath.append(new String(previous)));
      this.secondaryTypesToRemove.put(sourceFile.sourceLocation.binaryFolder, types);
    }
    super.finishedWith(sourceLocator, result, mainTypeName, definedTypeNames, duplicateTypeNames);
  }
  private void handleSetImportSelection(ArrayList<Object> newSelectionList) {
    if (newSelectionList.size() == 0) {
      handleRemoveAll();
      pageChanged();
      return;
    }
    TableItem[] items = fImportListViewer.getTable().getItems();
    Object[] oldSelection = new Object[items.length];
    for (int i = 0; i < items.length; i++) {
      oldSelection[i] = items[i].getData();
    }

    // remove items that were in the old selection, but are not in the new one
    List<Object> itemsToRemove = new ArrayList<>();
    for (int i = 0; i < oldSelection.length; i++) {
      if (newSelectionList.contains(oldSelection[i])) {
        newSelectionList.remove(oldSelection[i]);
      } else {
        itemsToRemove.add(oldSelection[i]);
      }
    }
    doRemove(itemsToRemove);

    // add items that were not in the old selection and are in the new one
    doAdd(newSelectionList);

    pageChanged();
  }
 public static IMarker[] getProblemsFor(IResource resource) {
   try {
     if (resource != null && resource.exists()) {
       IMarker[] markers =
           resource.findMarkers(
               IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, false, IResource.DEPTH_INFINITE);
       Set markerTypes =
           JavaModelManager.getJavaModelManager().compilationParticipants.managedMarkerTypes();
       if (markerTypes.isEmpty()) return markers;
       ArrayList markerList = new ArrayList(5);
       for (int i = 0, length = markers.length; i < length; i++) {
         markerList.add(markers[i]);
       }
       Iterator iterator = markerTypes.iterator();
       while (iterator.hasNext()) {
         markers = resource.findMarkers((String) iterator.next(), false, IResource.DEPTH_INFINITE);
         for (int i = 0, length = markers.length; i < length; i++) {
           markerList.add(markers[i]);
         }
       }
       IMarker[] result;
       markerList.toArray(result = new IMarker[markerList.size()]);
       return result;
     }
   } catch (CoreException e) {
     // assume there are no problems
   }
   return new IMarker[0];
 }
  ISourceContainer[] getSourceContainers(String location, String id) throws CoreException {

    ISourceContainer[] containers = (ISourceContainer[]) fSourceContainerMap.get(location);
    if (containers != null) {
      return containers;
    }

    ArrayList result = new ArrayList();
    ModelEntry entry = MonitorRegistry.findEntry(id);

    boolean match = false;

    IMonitorModelBase[] models = entry.getWorkspaceModels();
    for (int i = 0; i < models.length; i++) {
      if (isPerfectMatch(models[i], new Path(location))) {
        IResource resource = models[i].getUnderlyingResource();
        // if the plug-in matches a workspace model,
        // add the project and any libraries not coming via a container
        // to the list of source containers, in that order
        if (resource != null) {
          addProjectSourceContainers(resource.getProject(), result);
        }
        match = true;
        break;
      }
    }

    if (!match) {
      File file = new File(location);
      if (file.isFile()) {
        // in case of linked plug-in projects that map to an external JARd plug-in,
        // use source container that maps to the library in the linked project.
        ISourceContainer container = getArchiveSourceContainer(location);
        if (container != null) {
          containers = new ISourceContainer[] {container};
          fSourceContainerMap.put(location, containers);
          return containers;
        }
      }

      models = entry.getExternalModels();
      for (int i = 0; i < models.length; i++) {
        if (isPerfectMatch(models[i], new Path(location))) {
          // try all source zips found in the source code locations
          IClasspathEntry[] entries = MDEClasspathContainer.getExternalEntries(models[i]);
          for (int j = 0; j < entries.length; j++) {
            IRuntimeClasspathEntry rte = convertClasspathEntry(entries[j]);
            if (rte != null) result.add(rte);
          }
          break;
        }
      }
    }

    IRuntimeClasspathEntry[] entries =
        (IRuntimeClasspathEntry[]) result.toArray(new IRuntimeClasspathEntry[result.size()]);
    containers = JavaRuntime.getSourceContainers(entries);
    fSourceContainerMap.put(location, containers);
    return containers;
  }
 protected void compile(
     SourceFile[] units, SourceFile[] additionalUnits, boolean compilingFirstGroup) {
   if (compilingFirstGroup && additionalUnits != null) {
     // add any source file from additionalUnits to units if it defines secondary types
     // otherwise its possible during testing with MAX_AT_ONCE == 1 that a secondary type
     // can cause an infinite loop as it alternates between not found and defined, see bug 146324
     ArrayList extras = null;
     for (int i = 0, l = additionalUnits.length; i < l; i++) {
       SourceFile unit = additionalUnits[i];
       if (unit != null && this.newState.getDefinedTypeNamesFor(unit.typeLocator()) != null) {
         if (JavaBuilder.DEBUG)
           System.out.println(
               "About to compile file with secondary types " + unit.typeLocator()); // $NON-NLS-1$
         if (extras == null) extras = new ArrayList(3);
         extras.add(unit);
       }
     }
     if (extras != null) {
       int oldLength = units.length;
       int toAdd = extras.size();
       System.arraycopy(units, 0, units = new SourceFile[oldLength + toAdd], 0, oldLength);
       for (int i = 0; i < toAdd; i++) units[oldLength++] = (SourceFile) extras.get(i);
     }
   }
   super.compile(units, additionalUnits, compilingFirstGroup);
 }
Beispiel #6
0
 private String[] getDirectoryCandidates() {
   double version = getTargetVersion();
   ArrayList result = new ArrayList();
   if (version >= 3.6)
     result.add(
         "templates_3.6" + "/" + getSectionId() + "/"); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
   if (version >= 3.5)
     result.add(
         "templates_3.5" + "/" + getSectionId() + "/"); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
   if (version >= 3.4)
     result.add(
         "templates_3.4" + "/" + getSectionId() + "/"); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
   if (version >= 3.3)
     result.add(
         "templates_3.3" + "/" + getSectionId() + "/"); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
   if (version >= 3.2)
     result.add(
         "templates_3.2" + "/" + getSectionId() + "/"); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
   if (version >= 3.1)
     result.add(
         "templates_3.1" + "/" + getSectionId() + "/"); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
   if (version >= 3.0)
     result.add(
         "templates_3.0" + "/" + getSectionId() + "/"); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
   return (String[]) result.toArray(new String[result.size()]);
 }
Beispiel #7
0
  private void createBuildPathChange(IResource[] sourceResources, CompositeChange rootChange)
      throws ModelException {
    IResource[] uniqueSourceResources = removeDuplicateResources(sourceResources);
    for (IResource element : uniqueSourceResources) {
      // only container need handle build/include path.
      if (element instanceof IContainer) {
        IProject project = element.getProject();

        // if moving to another project
        if (RefactoringUtility.getResource(fMainDestinationPath).getProject() != project) {
          removeBuildPath(element, project);
          IPath path = element.getFullPath().removeLastSegments(1);
          RenameBuildAndIcludePathChange biChange =
              new RenameBuildAndIcludePathChange(
                  path,
                  path,
                  element.getName(),
                  "",
                  oldBuildEntries, //$NON-NLS-1$
                  newBuildEntries,
                  oldIncludePath,
                  newIncludePathEntries);

          if (newBuildEntries.size() > 0 || newIncludePathEntries.size() > 0) {
            rootChange.add(biChange);
          }

        } else {
          updateBuildPath(element, project);
          RenameBuildAndIcludePathChange biChange =
              new RenameBuildAndIcludePathChange(
                  element.getFullPath().removeLastSegments(1),
                  fMainDestinationPath,
                  element.getName(),
                  element.getName(),
                  oldBuildEntries,
                  newBuildEntries,
                  oldIncludePath,
                  newIncludePathEntries);
          if (newBuildEntries.size() > 0 || newIncludePathEntries.size() > 0) {
            rootChange.add(biChange);
          }
        }
      }
    }
  }
 public static String[] getFeaturePaths() {
   IFeatureModel[] models = MDECore.getDefault().getFeatureModelManager().getModels();
   ArrayList list = new ArrayList();
   for (int i = 0; i < models.length; i++) {
     String location = models[i].getInstallLocation();
     if (location != null)
       list.add(location + IPath.SEPARATOR + ICoreConstants.FEATURE_FILENAME_DESCRIPTOR);
   }
   return (String[]) list.toArray(new String[list.size()]);
 }
Beispiel #9
0
  private IResource[] removeDuplicateResources(IResource[] sourceResources) {
    // ignore empty array
    if (sourceResources == null || sourceResources.length == 0) {
      return sourceResources;
    }

    ArrayList<IResource> result = new ArrayList<IResource>();

    for (IResource source : sourceResources) {
      if (result.size() == 0) {
        result.add(source);
      } else {
        // check if the resource is parent of any item in the result
        for (IResource existing : result) {
          // if the resource is parent of an existing item in the
          // result.
          // remove the existing item, add the new one.
          if (source.getFullPath().isPrefixOf(existing.getFullPath())) {
            result.remove(existing);
            result.add(source);
          }
        }

        boolean noNeedAdded = false;
        for (IResource existing : result) {
          // if the resource is parent of an existing item in the
          // result.
          // remove the existing item, add the new one.
          if (existing.getFullPath().isPrefixOf(source.getFullPath())) {
            noNeedAdded = true;
          }
        }
        // the source is not in the result after loop
        if (!result.contains(source) && !noNeedAdded) {
          result.add(source);
        }
      }
    }

    IResource[] ret = new IResource[result.size()];

    return result.toArray(ret);
  }
  private void handleSwap() {
    TableItem[] aItems = fAvailableListViewer.getTable().getItems();
    TableItem[] iItems = fImportListViewer.getTable().getItems();

    ArrayList<Object> data = new ArrayList<>();
    for (int i = 0; i < iItems.length; i++) {
      data.add(iItems[i].getData());
    }
    if (data.size() > 0) {
      doRemove(data);
    }

    data.clear();
    for (int i = 0; i < aItems.length; i++) {
      data.add(aItems[i].getData());
    }
    if (data.size() > 0) {
      doAdd(data);
    }
    pageChanged();
  }
  private void handleRemoveAll() {
    TableItem[] items = fImportListViewer.getTable().getItems();

    ArrayList<Object> data = new ArrayList<>();
    for (int i = 0; i < items.length; i++) {
      data.add(items[i].getData());
    }
    if (data.size() > 0) {
      doRemove(data);
      pageChanged(false, true);
    }
  }
  private void handleAddAll() {
    TableItem[] items = fAvailableListViewer.getTable().getItems();

    ArrayList<Object> data = new ArrayList<>();
    for (int i = 0; i < items.length; i++) {
      data.add(items[i].getData());
    }
    if (data.size() > 0) {
      doAdd(data);
      pageChanged(true, false);
    }
  }
  public void build() {
    if (JavaBuilder.DEBUG) System.out.println("FULL build"); // $NON-NLS-1$

    try {
      this.notifier.subTask(
          Messages.bind(Messages.build_cleaningOutput, this.javaBuilder.currentProject.getName()));
      JavaBuilder.removeProblemsAndTasksFor(this.javaBuilder.currentProject);
      cleanOutputFolders(true);
      this.notifier.updateProgressDelta(0.05f);

      this.notifier.subTask(Messages.build_analyzingSources);
      ArrayList sourceFiles = new ArrayList(33);
      addAllSourceFiles(sourceFiles);
      this.notifier.updateProgressDelta(0.10f);

      if (sourceFiles.size() > 0) {
        SourceFile[] allSourceFiles = new SourceFile[sourceFiles.size()];
        sourceFiles.toArray(allSourceFiles);

        this.notifier.setProgressPerCompilationUnit(0.75f / allSourceFiles.length);
        this.workQueue.addAll(allSourceFiles);
        compile(allSourceFiles);

        if (this.typeLocatorsWithUndefinedTypes != null)
          if (this.secondaryTypes != null && !this.secondaryTypes.isEmpty())
            rebuildTypesAffectedBySecondaryTypes();
        if (this.incrementalBuilder != null) this.incrementalBuilder.buildAfterBatchBuild();
      }

      if (this.javaBuilder.javaProject.hasCycleMarker())
        this.javaBuilder.mustPropagateStructuralChanges();
    } catch (CoreException e) {
      throw internalException(e);
    } finally {
      if (JavaBuilder.SHOW_STATS) printStats();
      cleanUp();
    }
  }
  public static Dictionary[] getPlatformProperties(String[] profiles, MinimalState state) {
    if (profiles == null || profiles.length == 0)
      return new Dictionary[] {getTargetEnvironment(state)};

    // add java profiles for those EE's that have a .profile file in the current system bundle
    ArrayList result = new ArrayList(profiles.length);
    for (int i = 0; i < profiles.length; i++) {
      IExecutionEnvironment environment =
          JavaRuntime.getExecutionEnvironmentsManager().getEnvironment(profiles[i]);
      if (environment != null) {
        Properties profileProps = environment.getProfileProperties();
        if (profileProps != null) {
          Dictionary props = TargetPlatformHelper.getTargetEnvironment(state);
          String systemPackages = profileProps.getProperty(Constants.FRAMEWORK_SYSTEMPACKAGES);
          if (systemPackages != null) props.put(Constants.FRAMEWORK_SYSTEMPACKAGES, systemPackages);
          String ee = profileProps.getProperty(Constants.FRAMEWORK_EXECUTIONENVIRONMENT);
          if (ee != null) props.put(Constants.FRAMEWORK_EXECUTIONENVIRONMENT, ee);
          result.add(props);
        }
      }
    }
    if (result.size() > 0) return (Dictionary[]) result.toArray(new Dictionary[result.size()]);
    return new Dictionary[] {TargetPlatformHelper.getTargetEnvironment(state)};
  }
  private void handleAddRequiredPlugins() {
    TableItem[] items = fImportListViewer.getTable().getItems();
    if (items.length == 0) return;
    if (items.length == 1) {
      IPluginModelBase model = (IPluginModelBase) items[0].getData();
      if (model.getPluginBase().getId().equals("org.eclipse.core.boot")) { // $NON-NLS-1$
        return;
      }
    }

    ArrayList<IPluginModelBase> result = new ArrayList<>();
    for (int i = 0; i < items.length; i++) {
      addPluginAndDependencies(
          (IPluginModelBase) items[i].getData(), result, fAddFragmentsButton.getSelection());
    }
    ArrayList<Object> resultObject = new ArrayList<>(result.size());
    resultObject.addAll(result);
    handleSetImportSelection(resultObject);
  }
 protected void removeSecondaryTypes() throws CoreException {
   if (this.secondaryTypesToRemove
       != null) { // delayed deleting secondary types until the end of the compile loop
     Object[] keyTable = this.secondaryTypesToRemove.keyTable;
     Object[] valueTable = this.secondaryTypesToRemove.valueTable;
     for (int i = 0, l = keyTable.length; i < l; i++) {
       IContainer outputFolder = (IContainer) keyTable[i];
       if (outputFolder != null) {
         ArrayList paths = (ArrayList) valueTable[i];
         for (int j = 0, m = paths.size(); j < m; j++)
           removeClassFile((IPath) paths.get(j), outputFolder);
       }
     }
     this.secondaryTypesToRemove = null;
     if (this.previousSourceFiles != null)
       this.previousSourceFiles =
           null; // cannot optimize recompile case when a secondary type is deleted, see 181269
   }
 }
Beispiel #17
0
  /* Return the list of projects for which it requires a resource delta. This builder's project
   * is implicitly included and need not be specified. Builders must re-specify the list
   * of interesting projects every time they are run as this is not carried forward
   * beyond the next build. Missing projects should be specified but will be ignored until
   * they are added to the workspace.
   */
  private IProject[] getRequiredProjects(boolean includeBinaryPrerequisites) {
    if (this.javaProject == null || this.workspaceRoot == null) return new IProject[0];

    ArrayList projects = new ArrayList();
    ExternalFoldersManager externalFoldersManager = JavaModelManager.getExternalManager();
    try {
      IClasspathEntry[] entries = this.javaProject.getExpandedClasspath();
      for (int i = 0, l = entries.length; i < l; i++) {
        IClasspathEntry entry = entries[i];
        IPath path = entry.getPath();
        IProject p = null;
        switch (entry.getEntryKind()) {
          case IClasspathEntry.CPE_PROJECT:
            p =
                this.workspaceRoot.getProject(
                    path.lastSegment()); // missing projects are considered too
            if (((ClasspathEntry) entry).isOptional()
                && !JavaProject.hasJavaNature(p)) // except if entry is optional
            p = null;
            break;
          case IClasspathEntry.CPE_LIBRARY:
            if (includeBinaryPrerequisites && path.segmentCount() > 0) {
              // some binary resources on the class path can come from projects that are not
              // included in the project references
              IResource resource = this.workspaceRoot.findMember(path.segment(0));
              if (resource instanceof IProject) {
                p = (IProject) resource;
              } else {
                resource = externalFoldersManager.getFolder(path);
                if (resource != null) p = resource.getProject();
              }
            }
        }
        if (p != null && !projects.contains(p)) projects.add(p);
      }
    } catch (JavaModelException e) {
      return new IProject[0];
    }
    IProject[] result = new IProject[projects.size()];
    projects.toArray(result);
    return result;
  }
  /*
   * (non-Javadoc)
   * @see org.eclipse.pde.ui.launcher.AbstractPDELaunchConfiguration#getProgramArguments(org.eclipse.debug.core.ILaunchConfiguration)
   */
  public String[] getProgramArguments(ILaunchConfiguration configuration) throws CoreException {
    ArrayList programArgs = new ArrayList();

    programArgs.add("-dev"); // $NON-NLS-1$
    programArgs.add(
        ClasspathHelper.getDevEntriesProperties(
            getConfigDir(configuration).toString() + "/dev.properties",
            fAllBundles)); //$NON-NLS-1$

    saveConfigurationFile(configuration);
    programArgs.add("-configuration"); // $NON-NLS-1$
    programArgs.add(
        "file:"
            + new Path(getConfigDir(configuration).getPath())
                .addTrailingSeparator()
                .toString()); //$NON-NLS-1$

    String[] args = super.getProgramArguments(configuration);
    for (int i = 0; i < args.length; i++) {
      programArgs.add(args[i]);
    }
    return (String[]) programArgs.toArray(new String[programArgs.size()]);
  }
 private void handleAddWorkingSet() {
   IWorkingSetManager manager = PlatformUI.getWorkbench().getWorkingSetManager();
   IWorkingSetSelectionDialog dialog =
       manager.createWorkingSetSelectionDialog(PDEPlugin.getActiveWorkbenchShell(), true);
   if (dialog.open() == Window.OK) {
     IWorkingSet[] workingSets = dialog.getSelection();
     IProduct product = getProduct();
     IProductModelFactory factory = product.getModel().getFactory();
     ArrayList<IProductPlugin> pluginList = new ArrayList<IProductPlugin>();
     for (int i = 0; i < workingSets.length; i++) {
       IAdaptable[] elements = workingSets[i].getElements();
       for (int j = 0; j < elements.length; j++) {
         IPluginModelBase model = findModel(elements[j]);
         if (model != null) {
           IProductPlugin plugin = factory.createPlugin();
           IPluginBase base = model.getPluginBase();
           plugin.setId(base.getId());
           pluginList.add(plugin);
         }
       }
     }
     product.addPlugins(pluginList.toArray(new IProductPlugin[pluginList.size()]));
   }
 }
  private boolean resourceExists(String location) {
    String bundleJar = null;
    IPath path = new Path(location);
    if ("platform:".equals(path.getDevice()) && path.segmentCount() > 2) { // $NON-NLS-1$
      if ("plugin".equals(path.segment(0))) { // $NON-NLS-1$
        String id = path.segment(1);
        IMonitorModelBase model = MonitorRegistry.findModel(id);
        if (model != null && model.isEnabled()) {
          path = path.setDevice(null).removeFirstSegments(2);
          String bundleLocation = model.getInstallLocation();
          if (bundleLocation.endsWith(".jar")) { // $NON-NLS-1$
            bundleJar = bundleLocation;
          } else {
            path = new Path(model.getInstallLocation()).append(path);
          }
          location = path.toString();
        }
      }
    } else if (path.getDevice() == null
        && path.segmentCount() > 3
        && "platform:".equals(path.segment(0))) { // $NON-NLS-1$
      if ("plugin".equals(path.segment(1))) { // $NON-NLS-1$
        String id = path.segment(2);
        IMonitorModelBase model = MonitorRegistry.findModel(id);
        if (model != null && model.isEnabled()) {
          path = path.removeFirstSegments(3);
          String bundleLocation = model.getInstallLocation();
          if (bundleLocation.endsWith(".jar")) { // $NON-NLS-1$
            bundleJar = bundleLocation;
          } else {
            path = new Path(model.getInstallLocation()).append(path);
          }
          location = path.toString();
        }
      }
    }

    ArrayList paths = new ArrayList();
    if (location.indexOf("$nl$") != -1) { // $NON-NLS-1$
      StringTokenizer tokenizer = new StringTokenizer(TargetPlatform.getNL(), "_"); // $NON-NLS-1$
      String language = tokenizer.hasMoreTokens() ? tokenizer.nextToken() : null;
      String country = tokenizer.hasMoreTokens() ? tokenizer.nextToken() : null;
      if (language != null && country != null)
        paths.add(
            location.replaceAll(
                "\\$nl\\$",
                "nl"
                    + IPath.SEPARATOR
                    + language
                    + IPath.SEPARATOR
                    + country)); //$NON-NLS-1$ //$NON-NLS-2$
      if (language != null)
        paths.add(
            location.replaceAll(
                "\\$nl\\$", "nl" + IPath.SEPARATOR + language)); // $NON-NLS-1$ //$NON-NLS-2$
      paths.add(location.replaceAll("\\$nl\\$", "")); // $NON-NLS-1$ //$NON-NLS-2$
    } else {
      paths.add(location);
    }

    for (int i = 0; i < paths.size(); i++) {
      if (bundleJar == null) {
        IPath currPath = new Path(paths.get(i).toString());
        if (currPath.isAbsolute() && currPath.toFile().exists()) return true;
        if (PDEProject.getBundleRoot(fFile.getProject()).findMember(currPath) != null) return true;
        if (fBuildModel != null
            && fBuildModel.getEntry("source." + paths.get(i)) != null) // $NON-NLS-1$
        return true;
      } else {
        if (CoreUtility.jarContainsResource(new File(bundleJar), paths.get(i).toString(), false))
          return true;
      }
    }

    return false;
  }