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;
 }
Example #2
0
 /**
  * Returns the location of the given resource. For local resources this is the OS path in the
  * local file system. For remote resource this is the URI.
  *
  * @param resource the resource
  * @return the location string or <code>null</code> if the location URI of the resource is <code>
  *     null</code>
  */
 public static String getLocationString(IResource resource) {
   URI uri = resource.getLocationURI();
   if (uri == null) return null;
   return EFS.SCHEME_FILE.equalsIgnoreCase(uri.getScheme())
       ? new File(uri).getAbsolutePath()
       : uri.toString();
 }
 private IPath getPathForResource(IResource resource) {
   // TODO: when the file system utility stuff is in, this will have to call it to get the path
   // for now, get the path from the URI
   URI locationURI = resource.getLocationURI();
   IPath path = new Path(locationURI.getPath());
   return path;
 }
Example #4
0
  /**
   * The <code>CopyAction</code> implementation of this <code>SelectionListenerAction</code> method
   * enables this action if one or more resources of compatible types are selected.
   */
  @Override
  protected boolean updateSelection(IStructuredSelection selection) {
    if (!super.updateSelection(selection)) return false;

    if (getSelectedNonResources().size() > 0) return false;

    List<?> selectedResources = getSelectedResources();
    if (selectedResources.size() == 0) return false;

    boolean projSelected = selectionIsOfType(IResource.PROJECT);
    boolean fileFoldersSelected = selectionIsOfType(IResource.FILE | IResource.FOLDER);
    if (!projSelected && !fileFoldersSelected) return false;

    // selection must be homogeneous
    if (projSelected && fileFoldersSelected) return false;

    // must have a common parent
    IContainer firstParent = ((IResource) selectedResources.get(0)).getParent();
    if (firstParent == null) return false;

    Iterator<?> resourcesEnum = selectedResources.iterator();
    while (resourcesEnum.hasNext()) {
      IResource currentResource = (IResource) resourcesEnum.next();
      if (!currentResource.getParent().equals(firstParent)) return false;
      // resource location must exist
      if (currentResource.getLocationURI() == null) return false;
    }

    return true;
  }
 /**
  * Get the path for a resource. In the case of a moved or deleted resource, resource.getLocation()
  * returns null since it does not exist in the workspace. The workaround is below.
  *
  * @param resource the resource.
  * @return the path for a resource.
  */
 private String getAbsolutePath(IResource resource) {
   URI locationURI = resource.getLocationURI();
   if (locationURI == null) {
     return resource.getFullPath().toString();
   } else {
     return locationURI.toString();
   }
 }
Example #6
0
  /**
   * Parse the source for the specified compilation unit and resolve any elements found in it. Any
   * exceptions thrown by the {@link DartParser} will be added to the given collection.
   *
   * @param compilationUnit the compilation unit (not <code>null</code>)
   * @param parseErrors a collection to which parse errors are added or <code>null</code> if parse
   *     errors should be ignored
   * @return the parse result
   */
  public static DartUnit resolveUnit(
      CompilationUnit compilationUnit, Collection<DartCompilationError> parseErrors)
      throws DartModelException {

    long start = System.currentTimeMillis();

    DartLibraryImpl library = (DartLibraryImpl) compilationUnit.getLibrary();
    if (library == null) {
      // If we cannot get the library, we cannot resolve any elements so we
      // revert to simply parsing the compilation unit.
      DartUnit ret = parseUnit(compilationUnit, parseErrors);

      long elapsed = System.currentTimeMillis() - start;
      Instrumentation.metric("DartCompilerUtils-resolveUnit", elapsed)
          .with("ParseOnlyFallback", "true")
          .log();

      Instrumentation.operation("DartCompilerUtils-resolveUnit", elapsed)
          .with("ParseOnlyFallback", "true")
          .with("CompilaitonUnit-ElementName", compilationUnit.getElementName())
          .log();

      return ret;
    }
    IResource resource = compilationUnit.getResource();
    URI unitUri = null;
    if (resource != null) {
      unitUri = resource.getLocationURI();
    }
    if (unitUri == null && compilationUnit instanceof ExternalCompilationUnitImpl) {
      unitUri = ((ExternalCompilationUnitImpl) compilationUnit).getUri();
    }
    if (unitUri == null) {
      unitUri = ((CompilationUnitImpl) compilationUnit).getSourceRef().getUri();
    }
    String unitSource = compilationUnit.getSource();
    Map<URI, String> suppliedSources = new HashMap<URI, String>();
    if (unitSource != null) {
      suppliedSources.put(unitUri, unitSource);
    }
    DartUnit ret =
        resolveUnit(library.getLibrarySourceFile(), unitUri, suppliedSources, parseErrors);

    long elapsed = System.currentTimeMillis() - start;
    Instrumentation.metric("DartCompilerUtils-resolveUnit", elapsed)
        .with("ParseOnlyFallback", "false")
        .log();

    Instrumentation.operation("DartCompilerUtils-resolveUnit", elapsed)
        .with("ParseOnlyFallback", "false")
        .with("CompilaitonUnit-ElementName", compilationUnit.getElementName())
        .with("compilationUnit.LastModified", compilationUnit.getModificationStamp())
        .log();

    return ret;
  }
 public static IPath toFullPath(IResource resource) {
   if (resource == null) {
     return null;
   }
   IProject project = resource.getProject();
   if (!project.equals(MANAGER.getExternalSourceArchivesProject())) {
     return null;
   }
   return new Path(resource.getLocationURI().getPath());
 }
Example #8
0
 private boolean isVirtualTypeResource(IResource fileSystemLoc) {
   IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
   IResource resource = root.findMember(fileSystemLoc.getFullPath());
   if (resource != null) {
     URI location = resource.getLocationURI();
     if (location != null) {
       if (location.getScheme().equals("typespace")) {
         return true;
       }
     }
   }
   return false;
 }
Example #9
0
  protected ChangedFile getChangedFileForResource(IResource resource) {
    if (resource == null || resource.getLocationURI() == null) {
      return null;
    }

    IPath resourcePath = resource.getLocation();
    List<ChangedFile> changedFiles = changedFiles();
    if (!CollectionsUtil.isEmpty(changedFiles)) {
      for (ChangedFile changedFile : changedFiles) {
        IPath fullPath = workingDirectory().append(changedFile.getPath());
        if (resourcePath.equals(fullPath)) {
          return changedFile;
        }
      }
    }
    return null;
  }
Example #10
0
  public static boolean projectHasCamelResource(final IProject project) {
    try {
      ArrayList<IResource> xmlResources = getAllXMLFilesInProject(project);
      for (Iterator<IResource> iterator = xmlResources.iterator(); iterator.hasNext(); ) {
        IResource item = iterator.next();
        File testFile = new File(item.getLocationURI());
        if (testFile.exists()) {
          boolean isValidCamel =
              CamelFileTypeHelper.isSupportedCamelFile(
                  project, item.getProjectRelativePath().toPortableString());
          if (isValidCamel) {
            return true;
          }
        }
      }
    } catch (final Exception e) {
      // ignore
    }

    return false;
  }
 private Map<IPath, IResource> getSourceArchives() {
   if (archives == null) {
     Map<IPath, IResource> tempSourceArchives = new HashMap<>();
     IProject project = getExternalSourceArchivesProject();
     try {
       if (!project.isAccessible()) {
         if (project.exists()) {
           // workspace was moved
           openExternalSourceArchivesProject(project, null /*no progress*/);
         } else {
           // if project doesn't exist, do not open and recreate it as it means that there are no
           // external source archives
           return archives = Collections.synchronizedMap(tempSourceArchives);
         }
       }
       IResource[] members = project.members();
       for (int i = 0, length = members.length; i < length; i++) {
         IResource member = members[i];
         if (member.getType() == IResource.FOLDER
             && member.isLinked()
             && member.getName().startsWith(LINKED_FOLDER_NAME)) {
           String path = member.getLocationURI().getPath();
           if (path != null) {
             if (path.endsWith(CeylonArchiveFileSystem.JAR_SUFFIX)) {
               path = path.substring(0, path.length() - 2);
             }
             IPath externalSourceArchivePath = new Path(path);
             tempSourceArchives.put(externalSourceArchivePath, member);
           }
         }
       }
     } catch (CoreException e) {
       Util.log(e, "Exception while initializing external folders");
     }
     archives = Collections.synchronizedMap(tempSourceArchives);
   }
   return archives;
 }
  protected String resolveLaunchUrl(
      IResourceResolver resourceResolver, SDBGLaunchConfigWrapper launchConfig)
      throws CoreException {
    String url;

    if (launchConfig.getShouldLaunchFile()) {
      IResource resource = launchConfig.getApplicationResource();
      if (resource == null) {
        throw new CoreException(
            new Status(
                IStatus.ERROR, SDBGDebugCorePlugin.PLUGIN_ID, "HTML file could not be found"));
      }

      if (resource instanceof IFile) {
        url = resourceResolver.getUrlForResource(resource);
      } else {
        url = resource.getLocationURI().toString();
      }
    } else {
      url = launchConfig.getUrl();
    }

    return launchConfig.appendQueryParams(url);
  }
  @Override
  public boolean visit(final IResource resource) {
    if (resource == null || !resource.isAccessible()) {
      return false;
    }

    final URI resourceLocation = resource.getLocationURI();
    resourcename = resource.getName();
    if (resourcename == null || resourcename.startsWith(DOT)) {
      return false;
    }

    try {
      URI resolved = resource.getWorkspace().getPathVariableManager().resolveURI(resourceLocation);
      IFileStore store = EFS.getStore(resolved);
      IFileInfo fileInfo = store.fetchInfo();
      if (!fileInfo.exists()) {
        ErrorReporter.logError(
            "The resource `" + resource.getFullPath() + "' points to a non-existing location.");
        return false;
      }
    } catch (CoreException e) {
      ErrorReporter.logExceptionStackTrace(e);
      return false;
    }

    switch (resource.getType()) {
      case IResource.FILE:
        if (!ResourceExclusionHelper.isDirectlyExcluded((IFile) resource)
            && !helper.isExcludedByRegexp(resourcename)) {
          boolean inExcluded = false;
          IPath resourceFullPath = resource.getFullPath();
          for (int i = 0; i < excludedFolders.size(); i++) {
            IPath excludedFolder = excludedFolders.get(i);
            if (excludedFolder.isPrefixOf(resourceFullPath)) {
              inExcluded = true;
              break;
            }
          }

          IFile file = (IFile) resource;
          if (inExcluded) {
            excludedFiles.put(resource.getName(), file);
            return false;
          }

          boolean inCentralStorage = false;
          for (int i = 0; i < centralStorages.size(); i++) {
            URI centralFolder = centralStorages.get(i);
            if (centralFolder.getHost() == resourceLocation.getHost()
                && resourceLocation.getPath().startsWith(centralFolder.getPath())) {
              inCentralStorage = true;
              break;
            }
          }
          file = (IFile) resource;
          if (inCentralStorage) {
            if (file.getLocation() == null) {
              centralStorageFiles.put(file.getName(), file);
            } else {
              centralStorageFiles.put(file.getLocation().toOSString(), file);
            }
          } else {
            files.put(resourcename, file);
          }
        }
        return false;
      case IResource.FOLDER:
        for (IContainer workingDirectory : workingDirectories) {
          if (workingDirectory.equals(resource)) {
            return false;
          }
        }

        try {
          if (ResourceExclusionHelper.isDirectlyExcluded((IFolder) resource)
              || helper.isExcludedByRegexp(resourcename)) {
            excludedFolders.add(resource.getFullPath());
          }

          if (TRUE.equals(
              resource.getPersistentProperty(
                  new QualifiedName(
                      FolderBuildPropertyData.QUALIFIER,
                      FolderBuildPropertyData.CENTRAL_STORAGE_PROPERTY)))) {
            centralStorages.add(resourceLocation);
          }
        } catch (CoreException e) {
          return false;
        }
        break;
      default:
    }
    return true;
  }
Example #14
0
 protected BuildResource(BuildDescription info, IResource rc) {
   this(info, info.calcResourceLocation(rc), rc.getLocationURI());
 }
Example #15
0
  private boolean doBuild(
      OpenableElementInfo info,
      IProgressMonitor progressMonitor,
      Map newElements,
      IResource underlyingResource)
      throws ModelException {
    try {

      final JSSourceModuleElementInfo moduleInfo = (JSSourceModuleElementInfo) info;

      IBuffer buffer = null;
      // ensure buffer is opened
      if (hasBuffer()) {
        buffer = getBufferManager().getBuffer(this);
        if (buffer == null) {
          buffer = openBuffer(progressMonitor, moduleInfo);
        }
      }

      final char[] contents = (buffer == null) ? null : buffer.getCharacters();

      // generate structure and compute syntax problems if needed
      final VjoSourceModuleStructureRequestor requestor =
          new VjoSourceModuleStructureRequestor(this, moduleInfo, newElements);

      // System.out.println("==> Parsing: " + resource.getName());
      final String natureId = getNatureId();
      if (natureId == null) {
        throw new ModelException(new ModelStatus(ModelStatus.INVALID_NAME));
      }

      SourceTypeName stName = getTypeName();
      IResource resource = getResource();
      // it is not a workspace file
      // if ("".equals(stName.groupName().trim()) && (resource == null ||
      // !resource.exists())) {
      // jstType = CodeassistUtils.findNativeJstType(stName.typeName());
      // } else {
      // processType(contents);
      // }
      final VjoSourceElementParser parser =
          (VjoSourceElementParser) getSourceElementParser(natureId);
      if (!isReadOnly()) {
        ((ISourceElementParserExtension) parser).setScriptProject(this.getScriptProject());
      }

      parser.setRequestor(requestor);
      final AccumulatingProblemReporter problemReporter = getAccumulatingProblemReporter();
      parser.setReporter(problemReporter);

      boolean reparsed = false;
      if (problemReporter != null) {
        if (!problemReporter.hasErrors()) {
          StructureBuilder.build(natureId, this, problemReporter);
          reparsed = true;
        }
        problemReporter.reportToRequestor();
      }

      if (jstType == null && isVirtualTypeResource(resource)) {

        IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
        IResource typespaceresource = root.findMember(resource.getFullPath());
        if (typespaceresource != null) {
          URI location = typespaceresource.getLocationURI();
          String typeName = location.getPath().replace("/", ".");
          String groupName = location.getHost();
          if (typeName.indexOf(".") == 0) {
            typeName = typeName.substring(1, typeName.length());
          }
          typeName = typeName.replace(".js", "");

          jstType = CodeassistUtils.findJstType(groupName, typeName);
        }
      } else if (jstType == null || !reparsed) {
        if ("".equals(stName.groupName().trim()) && (resource == null || !resource.exists())) {
          jstType = CodeassistUtils.findNativeJstType(stName.typeName());
        } else {
          processType(contents);
        }
      }

      // parse source module after getting the JstType
      //
      SourceParserUtil.parseSourceModule(this, parser);

      if (DLTKCore.DEBUG_PRINT_MODEL) {
        System.out.println("Source Module Debug print:"); // $NON-NLS-1$

        CorePrinter printer = new CorePrinter(System.out);
        printNode(printer);
        printer.flush();
      }

      // update timestamp (might be IResource.NULL_STAMP if original does
      // not exist)
      if (underlyingResource == null) {
        underlyingResource = getResource();
      }
      // underlying resource is null in the case of a working copy out of
      // workspace
      if (underlyingResource != null) {
        moduleInfo.setTimestamp(((IFile) underlyingResource).getModificationStamp());
      }

      isConsistent = true;

      return moduleInfo.isStructureKnown();
    } catch (CoreException e) {
      throw new ModelException(e);
    }
  }