Example #1
0
  /** Ensures that both text fields are set. */
  private void dialogChanged() {
    IResource container =
        ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(getContainerName()));
    String fileName = getFileName();

    if (getContainerName().length() == 0) {
      updateStatus("Project must be specified");
      return;
    }
    if (container == null
        || (container.getType() & (IResource.PROJECT /* | IResource.FOLDER*/)) == 0) {
      updateStatus("Specify existing project, without subfolder(s)");
      return;
    }
    if (!container.isAccessible()) {
      updateStatus("Project must be writable");
      return;
    }
    if (fileName.length() == 0) {
      updateStatus("File name must be specified");
      return;
    }
    if (fileName.replace('\\', '/').indexOf('/', 1) > 0) {
      updateStatus("File name must be valid");
      return;
    }
    if (!fileName.matches("[A-Z][A-Za-z0-9]*")) {
      updateStatus("Use alphanumeric (a-z, A-Z, 0-9) only, starting with uppercase character");
      return;
    }
    updateStatus(null);
  }
  protected boolean checkForClassFileChanges(
      IResourceDelta binaryDelta, ClasspathMultiDirectory md, int segmentCount)
      throws CoreException {
    IResource resource = binaryDelta.getResource();
    // remember that if inclusion & exclusion patterns change then a full build is done
    boolean isExcluded =
        (md.exclusionPatterns != null || md.inclusionPatterns != null)
            && Util.isExcluded(resource, md.inclusionPatterns, md.exclusionPatterns);
    switch (resource.getType()) {
      case IResource.FOLDER:
        if (isExcluded && md.inclusionPatterns == null)
          return true; // no need to go further with this delta since its children cannot be
        // included

        IResourceDelta[] children = binaryDelta.getAffectedChildren();
        for (int i = 0, l = children.length; i < l; i++)
          if (!checkForClassFileChanges(children[i], md, segmentCount)) return false;
        return true;
      case IResource.FILE:
        if (!isExcluded
            && org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(resource.getName())) {
          // perform full build if a managed class file has been changed
          IPath typePath =
              resource.getFullPath().removeFirstSegments(segmentCount).removeFileExtension();
          if (this.newState.isKnownType(typePath.toString())) {
            if (JavaBuilder.DEBUG)
              System.out.println(
                  "MUST DO FULL BUILD. Found change to class file " + typePath); // $NON-NLS-1$
            return false;
          }
          return true;
        }
    }
    return true;
  }
Example #3
0
 /**
  * Returns a status for this library describing any error states
  *
  * @return
  */
 IStatus validate() {
   if (!getSystemLibraryPath().toFile().exists()) {
     return new Status(
         IStatus.ERROR,
         IJavaDebugUIConstants.PLUGIN_ID,
         IJavaDebugUIConstants.INTERNAL_ERROR,
         "System library does not exist: " + getSystemLibraryPath().toOSString(),
         null); //$NON-NLS-1$
   }
   IPath path = getSystemLibrarySourcePath();
   if (!path.isEmpty()) {
     if (!path.toFile().exists()) {
       // check for workspace resource
       IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
       if (resource == null || !resource.exists()) {
         return new Status(
             IStatus.ERROR,
             IJavaDebugUIConstants.PLUGIN_ID,
             IJavaDebugUIConstants.INTERNAL_ERROR,
             "Source attachment does not exist: " + path.toOSString(),
             null); //$NON-NLS-1$
       }
     }
   }
   return Status.OK_STATUS;
 }
  /** Ensures that both text fields are set. */
  private void dialogChanged() {
    IResource container =
        ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(getContainerName()));
    String fileName = getFileName();

    if (getContainerName().length() == 0) {
      updateStatus("File container must be specified");
      return;
    }
    if (container == null || (container.getType() & (IResource.PROJECT | IResource.FOLDER)) == 0) {
      updateStatus("File container must exist");
      return;
    }
    if (!container.isAccessible()) {
      updateStatus("Project must be writable");
      return;
    }
    if (fileName.length() == 0) {
      updateStatus("File name must be specified");
      return;
    }
    if (fileName.replace('\\', '/').indexOf('/', 1) > 0) {
      updateStatus("File name must be valid");
      return;
    }
    //		int dotLoc = fileName.lastIndexOf('.');
    //		if (dotLoc != -1) {
    //			String ext = fileName.substring(dotLoc + 1);
    //			if (ext.equalsIgnoreCase("vtdl") == false) {
    //				updateStatus("File extension must be \"vtdl\"");
    //				return;
    //			}
    //		}
    updateStatus(null);
  }
 /* (non-Javadoc)
  * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#toggleLineBreakpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
  */
 @Override
 public void toggleLineBreakpoints(IWorkbenchPart part, ISelection selection)
     throws CoreException {
   ITextEditor textEditor = getEditor(part);
   if (textEditor != null) {
     IResource resource = textEditor.getEditorInput().getAdapter(IResource.class);
     ITextSelection textSelection = (ITextSelection) selection;
     int lineNumber = textSelection.getStartLine();
     IBreakpoint[] breakpoints =
         DebugPlugin.getDefault()
             .getBreakpointManager()
             .getBreakpoints(DebugCorePlugin.ID_PDA_DEBUG_MODEL);
     for (int i = 0; i < breakpoints.length; i++) {
       IBreakpoint breakpoint = breakpoints[i];
       if (breakpoint instanceof ILineBreakpoint
           && resource.equals(breakpoint.getMarker().getResource())) {
         if (((ILineBreakpoint) breakpoint).getLineNumber() == (lineNumber + 1)) {
           // remove
           breakpoint.delete();
           return;
         }
       }
     }
     // create line breakpoint (doc line numbers start at 0)
     PDALineBreakpoint lineBreakpoint = new PDALineBreakpoint(resource, lineNumber + 1);
     DebugPlugin.getDefault().getBreakpointManager().addBreakpoint(lineBreakpoint);
   }
 }
  protected ImageDescriptor getErrorTicksFromMarkers(IResource res, int depth)
      throws CoreException {
    if (res == null || !res.isAccessible()) {
      return null;
    }

    int severity = 0;
    //			if (res instanceof IProject) {
    //				severity= res.findMaxProblemSeverity(IJavaModelMarker.BUILDPATH_PROBLEM_MARKER, true,
    // IResource.DEPTH_ZERO);
    //				if (severity == IMarker.SEVERITY_ERROR) {
    //					return ERRORTICK_BUILDPATH_ERROR;
    //				}
    //				severity= res.findMaxProblemSeverity(JavaRuntime.JRE_CONTAINER_MARKER, true,
    // IResource.DEPTH_ZERO);
    //				if (severity == IMarker.SEVERITY_ERROR) {
    //					return ERRORTICK_BUILDPATH_ERROR;
    //				}
    //			}
    severity = res.findMaxProblemSeverity(IMarker.PROBLEM, true, depth);
    if (severity == IMarker.SEVERITY_ERROR) {
      return LangImages.DESC_OVR_ERROR;
    } else if (severity == IMarker.SEVERITY_WARNING) {
      return LangImages.DESC_OVR_WARNING;
    }
    return null;
  }
 @Override
 public void deleteMarkers(IResource resource, boolean includeSubtypes, String type)
     throws CoreException {
   if (resource != null && resource.exists()) {
     resource.deleteMarkers(type, includeSubtypes, IResource.DEPTH_INFINITE);
   }
 }
  /**
   * Returns a VDB editor given a vdb resource if editor is open
   *
   * @param vdb the vdb
   * @return the vdb editor
   */
  public static VdbEditor getVdbEditorForFile(IResource vdb) {
    if (vdb != null && vdb.exists()) {
      IWorkbenchWindow window = UiPlugin.getDefault().getCurrentWorkbenchWindow();

      if (window != null) {
        final IWorkbenchPage page = window.getActivePage();

        if (page != null) {
          // look through the open editors and see if there is one available for this model file.
          IEditorReference[] editors = page.getEditorReferences();
          for (int i = 0; i < editors.length; ++i) {

            IEditorPart editor = editors[i].getEditor(false);
            if (editor != null) {
              IEditorInput input = editor.getEditorInput();
              if (input instanceof IFileEditorInput) {
                if (vdb.equals(((IFileEditorInput) input).getFile())
                    || vdb.getFullPath()
                        .equals(((IFileEditorInput) input).getFile().getFullPath())) {
                  // found it;
                  if (ModelUtil.isVdbArchiveFile(vdb)) {
                    return (VdbEditor) editor;
                  }
                  break;
                }
              }
            }
          }
        }
      }
    }

    return null;
  }
Example #9
0
  public String getStyledText(Object element) {
    if (element instanceof LineElement) return getLineElementLabel((LineElement) element);

    if (!(element instanceof IResource)) return new String();

    IResource resource = (IResource) element;
    if (!resource.exists()) new String(SearchMessages.FileLabelProvider_removed_resource_label);

    String name = BasicElementLabels.getResourceName(resource);
    if (fOrder == SHOW_LABEL) {
      return getColoredLabelWithCounts(resource, new String(name));
    }

    String pathString = BasicElementLabels.getPathLabel(resource.getParent().getFullPath(), false);
    if (fOrder == SHOW_LABEL_PATH) {
      String str = new String(name);
      String decorated = Messages.format(fgSeparatorFormat, new String[] {str, pathString});

      //			decorateColoredString(str, decorated, String.QUALIFIER_STYLER);
      return getColoredLabelWithCounts(resource, str);
    }

    String str = new String(Messages.format(fgSeparatorFormat, new String[] {pathString, name}));
    return getColoredLabelWithCounts(resource, str);
  }
 private long getContainerTimestamp(TypeNameMatch match) {
   try {
     IType type = match.getType();
     IResource resource = type.getResource();
     if (resource != null) {
       URI location = resource.getLocationURI();
       if (location != null) {
         IFileInfo info = EFS.getStore(location).fetchInfo();
         if (info.exists()) {
           // The element could be removed from the build path. So check
           // if the Java element still exists.
           IJavaElement element = JavaCore.create(resource);
           if (element != null && element.exists()) return info.getLastModified();
         }
       }
     } else { // external JAR
       IPackageFragmentRoot root = match.getPackageFragmentRoot();
       if (root.exists()) {
         IFileInfo info = EFS.getLocalFileSystem().getStore(root.getPath()).fetchInfo();
         if (info.exists()) {
           return info.getLastModified();
         }
       }
     }
   } catch (CoreException e) {
     // Fall through
   }
   return IResource.NULL_STAMP;
 }
  public void decorate(Object element, IDecoration decoration) {
    if (!(element instanceof IResource)) return;
    IResource resource = (IResource) element;
    if (!resource.exists()) return;
    IProject project = resource.getProject();
    if (project == null) {
      Log.error(
          Messages.getString("ErrorDecorator.PROJECT_FOR")
              + resource.getName()
              + Messages.getString("ErrorDecorator.IS_NULL"),
          new Throwable()); //$NON-NLS-1$ //$NON-NLS-2$
      return;
    }
    try {
      if (!project.isOpen()) return;
      project.open(null);
      if (project.hasNature(LSLProjectNature.ID)) {
        LSLProjectNature nature = (LSLProjectNature) project.getNature(LSLProjectNature.ID);

        if (nature == null) return;

        IMarker[] m =
            resource.findMarkers("lslforge.problem", true, IResource.DEPTH_INFINITE); // $NON-NLS-1$

        if (m == null || m.length == 0) return;
      } else {
        return;
      }
    } catch (CoreException e) {
      Log.error("exception caught trying to determine project nature!", e); // $NON-NLS-1$
      return;
    }

    decoration.addOverlay(descriptor, IDecoration.BOTTOM_LEFT);
  }
 /**
  * Possible failures:
  *
  * <ul>
  *   <li>NO_ELEMENTS_TO_PROCESS - the root supplied to the operation is <code>null</code>.
  *   <li>INVALID_NAME - the name provided to the operation is <code>null</code> or is not a valid
  *       script folder name.
  *   <li>READ_ONLY - the root provided to this operation is read only.
  *   <li>NAME_COLLISION - there is a pre-existing resource (file) with the same name as a folder
  *       in the script folder's hierarchy.
  *   <li>ELEMENT_NOT_PRESENT - the underlying resource for the root is missing
  * </ul>
  *
  * @see IScriptModelStatus
  * @see ScriptConventions
  */
 @Override
 public IModelStatus verify() {
   if (getParentElement() == null) {
     return new ModelStatus(IModelStatusConstants.NO_ELEMENTS_TO_PROCESS);
   }
   IPath packageName = this.pkgName == null ? null : this.pkgName.append("."); // $NON-NLS-1$
   String packageNameValue = null;
   if (packageName != null) {
     packageNameValue = packageName.toOSString();
   }
   if (this.pkgName == null
       || (this.pkgName.segmentCount() > 0
           && !Util.isValidFolderNameForPackage(
               (IContainer) getParentElement().getResource(), packageName.toString()))) {
     return new ModelStatus(IModelStatusConstants.INVALID_NAME, packageNameValue);
   }
   IProjectFragment root = (IProjectFragment) getParentElement();
   if (root.isReadOnly()) {
     return new ModelStatus(IModelStatusConstants.READ_ONLY, root);
   }
   IContainer parentFolder = (IContainer) root.getResource();
   int i;
   for (i = 0; i < this.pkgName.segmentCount(); i++) {
     IResource subFolder = parentFolder.findMember(this.pkgName.segment(i));
     if (subFolder != null) {
       if (subFolder.getType() != IResource.FOLDER) {
         return new ModelStatus(
             IModelStatusConstants.NAME_COLLISION,
             Messages.bind(Messages.status_nameCollision, subFolder.getFullPath().toString()));
       }
       parentFolder = (IContainer) subFolder;
     }
   }
   return ModelStatus.VERIFIED_OK;
 }
 @Override
 public void exportArtifact(
     List<ArtifactData> artifactList,
     Map<IProject, Map<String, IResource>> resourceProjectList,
     IFolder splitESBResources,
     DependencyData dependencyData,
     Object parent,
     Object self)
     throws Exception {
   IProject resProject = (IProject) parent;
   if (!resourceProjectList.containsKey(resProject)) {
     Map<String, IResource> artifacts = new HashMap<String, IResource>();
     List<IResource> buildProject =
         ExportUtil.buildProject(resProject, dependencyData.getCApptype());
     for (IResource res : buildProject) {
       if (res instanceof IFolder) {
         artifacts.put(res.getName(), res);
       }
     }
     resourceProjectList.put(resProject, artifacts);
   }
   if (resourceProjectList.containsKey(resProject)) {
     Map<String, IResource> artifacts = resourceProjectList.get(resProject);
     if (artifacts.containsKey(getArtifactDir(dependencyData))) {
       ArtifactData artifactData = new ArtifactData();
       artifactData.setDependencyData(dependencyData);
       artifactData.setFile("registry-info.xml");
       artifactData.setResource(artifacts.get(getArtifactDir(dependencyData)));
       artifactList.add(artifactData);
     }
   }
 }
  private GradleProject getContext() {
    IWorkbench wb = PlatformUI.getWorkbench();
    IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
    IWorkbenchPage page = win == null ? null : win.getActivePage();

    if (page != null) {
      ISelection selection = page.getSelection();
      if (selection instanceof IStructuredSelection) {
        IStructuredSelection ss = (IStructuredSelection) selection;
        if (!ss.isEmpty()) {
          Object obj = ss.getFirstElement();
          if (obj instanceof IResource) {
            IResource rsrc = (IResource) obj;
            IProject prj = rsrc.getProject();
            if (prj != null) {
              return GradleCore.create(prj);
            }
          }
        }
      }
      IEditorPart part = page.getActiveEditor();
      if (part != null) {
        IEditorInput input = part.getEditorInput();
        IResource rsrc = (IResource) input.getAdapter(IResource.class);
        if (rsrc != null) {
          IProject prj = rsrc.getProject();
          if (prj != null) {
            return GradleCore.create(prj);
          }
        }
      }
    }
    return null;
  }
  public void addSelectedFilesToTargetList() {
    ISelection selection = sourceFileViewer.getSelection();

    if (isValidSourceFileViewerSelection(selection)) {
      java.util.List list = null;
      if (selection instanceof IStructuredSelection) {
        list = ((IStructuredSelection) selection).toList();

        if (list != null) {
          list = ((IStructuredSelection) selection).toList();
          for (Iterator i = list.iterator(); i.hasNext(); ) {
            IResource resource = (IResource) i.next();
            if (resource instanceof IFile) {
              // Check if its in the list. Don't add it if it is.
              String resourceName = resource.getFullPath().toString();
              if (selectedListBox.indexOf(resourceName) == -1) selectedListBox.add(resourceName);
            }
          }
          setFiles(selectedListBox.getItems());
        }

        setAddButtonEnabled(false);

        if (selectedListBox.getItemCount() > 0) {
          removeAllButton.setEnabled(true);
          if (isFileMandatory) setPageComplete(true);
          if (selectedListBox.getSelectionCount() > 0) setRemoveButtonEnabled(true);
          else setRemoveButtonEnabled(false);
        }
      }
    }
  }
Example #16
0
 /**
  * Notifies this listener that the given breakpoint has been added to the breakpoint manager.
  *
  * @param breakpoint the added breakpoint
  * @since 2.0
  */
 public void breakpointAdded(IBreakpoint breakpoint) {
   if (!isAvailable()) {
     return;
   }
   if (supportsBreakpoint(breakpoint)) {
     try {
       if (breakpoint.isEnabled()) {
         // only add the breakpoint to the debugger when the
         // breakpoint is enabled
         int linenumber = breakpoint.getMarker().getAttribute(IMarker.LINE_NUMBER, -1);
         // TODO: get marker language type or get language from the
         // resource
         IResource r = breakpoint.getMarker().getResource();
         String pRel = r.getProjectRelativePath().toOSString();
         String filename = pRel;
         if (linenumber > 0) {
           // only linenumbers greater than 0 are valid as
           // linenumber is 1-based
           // convert the Eclipse breakpoint to an internal
           // representation of breakpoints
           AbstractBreakPoint bp = createBreakpoint(filename, linenumber);
           if (bp != null) {
             this.getVMContainer().addBreakpoint(bp);
           }
         }
       }
     } catch (CoreException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     }
   }
 }
  /** {@inheritDoc} */
  public void run() {
    IResource resource = (IResource) fSelectedElements.get(0);
    final IScriptProject project = DLTKCore.create(resource.getProject());

    try {
      final IRunnableWithProgress runnable =
          new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor)
                throws InvocationTargetException, InterruptedException {
              try {
                List result = unExclude(fSelectedElements, project, monitor);
                selectAndReveal(new StructuredSelection(result));
              } catch (CoreException e) {
                throw new InvocationTargetException(e);
              }
            }
          };
      PlatformUI.getWorkbench().getProgressService().run(true, false, runnable);
    } catch (final InvocationTargetException e) {
      if (e.getCause() instanceof CoreException) {
        showExceptionDialog((CoreException) e.getCause());
      } else {
        DLTKUIPlugin.log(e);
      }
    } catch (final InterruptedException e) {
    }
  }
Example #18
0
  public IBreakpoint findIBreakpoint(String filename, int lineNumber) {
    IBreakpoint[] breakpoints =
        DebugPlugin.getDefault()
            .getBreakpointManager()
            .getBreakpoints(this.debugServiceFactory.getLIConstants().getDebugModel());
    for (int i = 0; i < breakpoints.length; i++) {
      IBreakpoint breakpoint = breakpoints[i];
      if (supportsBreakpoint(breakpoint)) {

        try {
          if (breakpoint.isEnabled()) {
            // only add the breakpoint to the debugger when the
            // breakpoint is enabled
            int l = breakpoint.getMarker().getAttribute(IMarker.LINE_NUMBER, -1);
            // TODO: get marker language type or get language from
            // the resource
            IResource r = breakpoint.getMarker().getResource();
            String location = r.getProjectRelativePath().toOSString();
            if (l > 0) {
              // only linenumbers greater than 0 are valid as
              // linenumber is 1-based
              if (location.equals(filename) && lineNumber == l) {
                return breakpoint;
              }
            }
          }
        } catch (CoreException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
    }
    return null;
  }
  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;
  }
  public String getText(Object element) {
    if (!(element instanceof IResource)) return null;

    IResource resource = (IResource) element;
    String text = null;

    if (!resource.exists()) text = SearchMessages.FileLabelProvider_removed_resource_label;
    else {
      IPath path = resource.getFullPath().removeLastSegments(1);
      if (path.getDevice() == null) path = path.makeRelative();
      if (fOrder == SHOW_LABEL || fOrder == SHOW_LABEL_PATH) {
        text = fLabelProvider.getText(resource);
        if (path != null && fOrder == SHOW_LABEL_PATH) {
          fArgs[0] = text;
          fArgs[1] = path.toString();
          text = MessageFormat.format(fgSeparatorFormat, fArgs);
        }
      } else {
        if (path != null) text = path.toString();
        else text = ""; // $NON-NLS-1$
        if (fOrder == SHOW_PATH_LABEL) {
          fArgs[0] = text;
          fArgs[1] = fLabelProvider.getText(resource);
          text = MessageFormat.format(fgSeparatorFormat, fArgs);
        }
      }
    }

    int matchCount = 0;
    AbstractTextSearchResult result = fPage.getInput();
    if (result != null) matchCount = result.getMatchCount(element);
    if (matchCount <= 1) return text;
    String format = SearchMessages.FileLabelProvider_count_format;
    return MessageFormat.format(format, new Object[] {text, new Integer(matchCount)});
  }
Example #21
0
  private IMarker addMarker(
      IResource resource,
      String type,
      String message,
      int lineNumber,
      int severity,
      boolean isTransient) {
    IMarker marker = null;
    try {
      if (resource.isAccessible()) {
        if (lineNumber == -1) {
          lineNumber = 1;
        }

        // mkleint: this strongly smells like some sort of workaround for a problem with bad marker
        // cleanup.
        // adding is adding and as such shall always be performed.
        marker = findMarker(resource, type, message, lineNumber, severity, isTransient);
        if (marker != null) {
          // This marker already exists
          return marker;
        }
        marker = resource.createMarker(type);
        marker.setAttribute(IMarker.MESSAGE, message);
        marker.setAttribute(IMarker.SEVERITY, severity);
        marker.setAttribute(IMarker.TRANSIENT, isTransient);

        marker.setAttribute(IMarker.LINE_NUMBER, lineNumber);
        log.debug("Created marker '{}' on resource '{}'.", message, resource.getFullPath());
      }
    } catch (CoreException ex) {
      log.error("Unable to add marker; " + ex.toString(), ex); // $NON-NLS-1$
    }
    return marker;
  }
 @Override
 public synchronized void resourceChanged(IResourceChangeEvent event) {
   IResource res = event.getResource();
   if (!(res instanceof IProject)) return;
   String name = res.getName();
   IResourceDelta delta = event.getDelta();
   if (delta == null) return;
   int kind = delta.getKind();
   if (configs.containsKey(name)) {
     if (kind == IResourceDelta.REMOVED) {
       configs.remove(name);
       tmpConfigs.remove(name);
     } else if (kind == IResourceDelta.CHANGED) {
       int flags = delta.getFlags();
       if ((flags & IResourceDelta.MOVED_TO) != 0) {
         IPath path = delta.getMovedToPath();
         Map<String, IAConfiguration> cfgs = configs.get(name);
         String newName = path.lastSegment();
         configs.remove(name);
         configs.put(newName, cfgs);
         Map<String, IAConfiguration> tmpcfgs = tmpConfigs.get(name);
         tmpConfigs.remove(name);
         tmpConfigs.put(newName, tmpcfgs);
       }
     }
   }
 }
Example #23
0
  /**
   * Creates new symbolic file system link from file or folder on project root to another file
   * system file. The filename can include relative path as a part of the name but the the path has
   * to be present on disk.
   *
   * @param project - project where to create the file.
   * @param linkName - name of the link being created.
   * @param realPath - file or folder on the file system, the target of the link.
   * @return file handle.
   * @throws UnsupportedOperationException on Windows where links are not supported.
   * @throws IOException...
   * @throws CoreException...
   */
  public static IResource createSymbolicLink(IProject project, String linkName, IPath realPath)
      throws IOException, CoreException, UnsupportedOperationException {

    if (!isSymbolicLinkSupported()) {
      throw new UnsupportedOperationException("Windows links .lnk are not supported.");
    }

    Assert.assertTrue(
        "Path for symbolic link does not exist: [" + realPath.toOSString() + "]",
        new File(realPath.toOSString()).exists());

    IPath linkedPath = project.getLocation().append(linkName);
    createSymbolicLink(linkedPath, realPath);

    IResource resource = project.getFile(linkName);
    resource.refreshLocal(IResource.DEPTH_ZERO, null);

    if (!resource.exists()) {
      resource = project.getFolder(linkName);
      resource.refreshLocal(IResource.DEPTH_ZERO, null);
    }
    Assert.assertTrue("Failed to create resource form symbolic link", resource.exists());

    externalFilesCreated.add(linkedPath.toOSString());
    ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, NULL_MONITOR);
    return resource;
  }
 /**
  * Returns the location of the Javadoc.
  *
  * @param element whose Javadoc location has to be found
  * @param isBinary <code>true</code> if the Java element is from a binary container
  * @return the location URL of the Javadoc or <code>null</code> if the location cannot be found
  * @throws JavaModelException thrown when the Java element cannot be accessed
  * @since 3.9
  */
 public static String getBaseURL(IJavaElement element, boolean isBinary)
     throws JavaModelException {
   if (isBinary) {
     // Source attachment usually does not include Javadoc resources
     // => Always use the Javadoc location as base:
     URL baseURL = JavaUI.getJavadocLocation(element, false);
     if (baseURL != null) {
       if (baseURL.getProtocol().equals(JAR_PROTOCOL)) {
         // It's a JarURLConnection, which is not known to the browser widget.
         // Let's start the help web server:
         URL baseURL2 =
             PlatformUI.getWorkbench().getHelpSystem().resolve(baseURL.toExternalForm(), true);
         if (baseURL2 != null) { // can be null if org.eclipse.help.ui is not available
           baseURL = baseURL2;
         }
       }
       return baseURL.toExternalForm();
     }
   } else {
     IResource resource = element.getResource();
     if (resource != null) {
       /*
        * Too bad: Browser widget knows nothing about EFS and custom URL handlers,
        * so IResource#getLocationURI() does not work in all cases.
        * We only support the local file system for now.
        * A solution could be https://bugs.eclipse.org/bugs/show_bug.cgi?id=149022 .
        */
       IPath location = resource.getLocation();
       if (location != null) return location.toFile().toURI().toString();
     }
   }
   return null;
 }
Example #25
0
 private static IProject getCommonProject(List<IResource> resources) throws CoreException {
   IProject project = null;
   for (IResource resource : resources) {
     IProject prj = resource.getProject();
     if (prj == null) {
       throw new CoreException(
           new Status(
               IStatus.ERROR,
               DeployPlugin.PLUGIN_ID,
               DeployPlugin.INVALID_PROJECT_CODE,
               MessageFormat.format(
                   Deploy_Messages.getString("MSG_RESOURCE_NOT_PART_OF_PROJECT"),
                   resource), //$NON-NLS-1$
               null));
     }
     if (project == null) {
       project = prj;
     } else if (project != prj) {
       throw new CoreException(
           new Status(
               IStatus.ERROR,
               DeployPlugin.PLUGIN_ID,
               DeployPlugin.INVALID_PROJECT_CODE,
               Deploy_Messages.getString("MSG_REOURCES_DIFFERENT_PROJECTS"), // $NON-NLS-1$
               null));
     }
   }
   return project;
 }
 @Override
 public String getSourceLocation() {
   IResource sourceResource;
   String sourceLocation = null;
   if (fFileSystemObject.isDirectory()) {
     sourceResource =
         ResourcesPlugin.getWorkspace()
             .getRoot()
             .getContainerForLocation(Path.fromOSString(fFileSystemObject.getAbsolutePath()));
   } else {
     sourceResource =
         ResourcesPlugin.getWorkspace()
             .getRoot()
             .getFileForLocation(Path.fromOSString(fFileSystemObject.getAbsolutePath()));
   }
   if (sourceResource != null && sourceResource.exists()) {
     try {
       sourceLocation = sourceResource.getPersistentProperty(TmfCommonConstants.SOURCE_LOCATION);
     } catch (CoreException e) {
       // Something went wrong with the already existing resource.
       // This is not a problem, we'll assign a new location below.
     }
   }
   if (sourceLocation == null) {
     try {
       sourceLocation = URIUtil.toUnencodedString(fFileSystemObject.getCanonicalFile().toURI());
     } catch (IOException e) {
       // Something went wrong canonicalizing the file. We can still
       // use the URI but there might be extra ../ in it.
       sourceLocation = URIUtil.toUnencodedString(fFileSystemObject.toURI());
     }
   }
   return sourceLocation;
 }
  private boolean initPath(IResource selection) {
    if (!WebAppUtilities.isWebApp(hostPageProject)) {
      return false;
    }

    IFolder container = null;

    try {
      IFolder warFolder = WebAppUtilities.getWarSrc(hostPageProject);

      // If the selection was a subfolder of war, initialize to that
      if (selection.getType() == IResource.FOLDER) {
        if (warFolder.getFullPath().isPrefixOf(selection.getFullPath())) {
          container = (IFolder) selection;
          return true;
        }
      }

      // Otherwise, use the war folder as the default path
      if (warFolder.exists()) {
        container = warFolder;
        return true;
      }

      return false;

    } finally {
      if (container != null) {
        pathField.setText(container.getFullPath().removeFirstSegments(1).toString());
      }
    }
  }
  /**
   * Returns the maximum problem marker severity for the given resource, and, if depth is
   * IResource.DEPTH_INFINITE, its children. The return value will be one of IMarker.SEVERITY_ERROR,
   * IMarker.SEVERITY_WARNING, IMarker.SEVERITY_INFO or 0, indicating that no problem markers exist
   * on the given resource.
   *
   * @param depth TODO
   */
  public static int getMaxProblemMarkerSeverity(IResource res, int depth) {
    if (res == null || !res.isAccessible()) return 0;

    boolean hasWarnings = false; // if resource has errors, will return error image immediately
    IMarker[] markers = null;

    try {
      markers = res.findMarkers(IMarker.PROBLEM, true, depth);
    } catch (CoreException e) {
      e.printStackTrace();
    }
    if (markers == null) return 0; // don't know - say no errors/warnings/infos

    for (int i = 0; i < markers.length; i++) {
      IMarker m = markers[i];
      int priority = m.getAttribute(IMarker.SEVERITY, -1);

      if (priority == IMarker.SEVERITY_WARNING) {
        hasWarnings = true;
      } else if (priority == IMarker.SEVERITY_ERROR) {
        return IMarker.SEVERITY_ERROR;
      }
    }
    return hasWarnings ? IMarker.SEVERITY_WARNING : 0;
  }
 public void run(Object[] selection) {
   final Set elements = new HashSet();
   final Set resources = new HashSet();
   for (int i = 0; i < selection.length; ++i) {
     Object o = selection[i];
     ValidatorUtils.processResourcesToElements(o, elements, resources);
   }
   for (Iterator i = elements.iterator(); i.hasNext(); ) {
     final ISourceModule module = (ISourceModule) i.next();
     final IScriptProject sproject = module.getScriptProject();
     if (sproject != null) {
       final IProject project = sproject.getProject();
       if (project != null) {
         getProjectInfo(project).elements.add(module);
       }
     }
   }
   for (Iterator i = resources.iterator(); i.hasNext(); ) {
     final IResource resource = (IResource) i.next();
     final IProject project = resource.getProject();
     if (project != null) {
       getProjectInfo(project).resources.add(resource);
     }
   }
   setRule(buildSchedulingRule(elements, resources));
   setUser(true);
   schedule();
 }
  @Override
  public void toggleLineBreakpoints(IWorkbenchPart part, ISelection selection)
      throws CoreException {
    AbstractTextEditor editor = getEditor(part);

    if (editor != null) {
      IResource resource = (IResource) editor.getEditorInput().getAdapter(IResource.class);

      ITextSelection textSelection = (ITextSelection) selection;

      int lineNumber = textSelection.getStartLine() + 1;

      IBreakpoint[] breakpoints =
          DebugPlugin.getDefault()
              .getBreakpointManager()
              .getBreakpoints(DartDebugCorePlugin.DEBUG_MODEL_ID);

      for (int i = 0; i < breakpoints.length; i++) {
        IBreakpoint breakpoint = breakpoints[i];

        if (resource.equals(breakpoint.getMarker().getResource())) {
          if (((ILineBreakpoint) breakpoint).getLineNumber() == lineNumber) {
            breakpoint.delete();
            return;
          }
        }
      }

      DartBreakpoint breakpoint = new DartBreakpoint(resource, lineNumber);

      DebugPlugin.getDefault().getBreakpointManager().addBreakpoint(breakpoint);
    }
  }