private void recurse(IContainer container) {
    try {
      for (IResource res : container.members()) {
        if (res instanceof IFile) {
          IFile ifile = (IFile) res;
          String fname = ifile.getName();

          if (fname.endsWith(".ptm")) {
            String templatedir = ifile.getParent().getLocation().toPortableString() + "/";
            PtmParseUnit unit = new PtmParseUnit(templatedir, fname);
            CommonTree tree = unit.getTree();
            Ptm2Xtend xtend = new Ptm2Xtend();
            xtend.clazzname = fname.replaceFirst("\\.ptm", "");
            xtend.node = tree;
            xtend.output = ifile;
            set.add(xtend);
          }
        }
        if (res instanceof IContainer) recurse((IContainer) res);
      }
    } catch (CoreException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
  /**
   * Retrieves all .class files from the output path
   *
   * @return The .class files list
   */
  protected void getAllClassFiles(
      final IContainer aContainer, final List<IResource> aClassFileList) {

    if (aContainer == null) {
      return;
    }

    IResource[] members;

    try {
      members = aContainer.members();
    } catch (final CoreException e) {
      Activator.logError(
          aContainer.getProject(),
          MessageFormat.format(
              "Error listing members in : {0}", aContainer.getFullPath().toOSString()),
          e);
      return;
    }

    for (final IResource member : members) {
      if (member.getType() == IResource.FOLDER) {
        getAllClassFiles((IContainer) member, aClassFileList);

      } else if (member.getType() == IResource.FILE && member.getName().endsWith(".class")) {
        aClassFileList.add(member);
      }
    }
  }
示例#3
0
  /*
   * (non-Javadoc)
   *
   * @see core.resources.ICoreResource#seek(core.resources.IResourceLocationRequestor)
   */
  public void lookup(IResourceAcceptor requestor, LookupDepth depth) {
    String packageName = fRoot.toPackageName(this);
    IPackageFragment[] fragments = fRoot.getAllPackageFragments(packageName);
    for (int i = 0; i < fragments.length; i++) {
      Object[] nonJavaResources = null;
      try {
        if (fragments[i].isReadOnly()) {
          // TODO - is this the correct check for a package in a jar file?
          nonJavaResources = fragments[i].getNonJavaResources();
        } else {
          IContainer container = (IContainer) fragments[i].getUnderlyingResource();
          if (container != null && container.exists()) {
            IResource[] members = container.members(false);
            ArrayList<IResource> resultList = new ArrayList<IResource>();
            for (int j = 0; j < members.length; j++) {
              if (members[j] instanceof IFile) resultList.add(members[j]);
            }
            nonJavaResources = resultList.toArray();
          }
        }
      } catch (CoreException e) {
        TapestryCore.log(e);
      }
      if (nonJavaResources == null) continue;

      for (int j = 0; j < nonJavaResources.length; j++) {
        IStorage storage = (IStorage) nonJavaResources[j];
        ICoreResource loc = new ClasspathResource(fRoot, getPath() + storage.getName());
        if (!requestor.accept(loc)) break;
      }
    }
  }
  /**
   * Set up the selection values for the resources and put them in the selectionMap. If a resource
   * is a file see if it matches one of the selected extensions. If not then check the children.
   */
  private void setupSelectionsBasedOnSelectedTypes(Map selectionMap, IContainer parent) {

    List selections = new ArrayList();
    IResource[] resources;
    boolean hasFiles = false;

    try {
      resources = parent.members();
    } catch (CoreException exception) {
      // Just return if we can't get any info
      return;
    }

    for (int i = 0; i < resources.length; i++) {
      IResource resource = resources[i];
      if (resource.getType() == IResource.FILE) {
        if (hasExportableExtension(resource.getName())) {
          hasFiles = true;
          selections.add(resource);
        }
      } else {
        setupSelectionsBasedOnSelectedTypes(selectionMap, (IContainer) resource);
      }
    }

    // Only add it to the list if there are files in this folder
    if (hasFiles) {
      selectionMap.put(parent, selections);
    }
  }
  // Assert that the two containers have equal contents
  protected void assertEquals(IContainer container1, IContainer container2) throws CoreException {
    assertEquals(container1.getName(), container2.getName());
    List members1 = new ArrayList();
    members1.addAll(Arrays.asList(container1.members()));

    List members2 = new ArrayList();
    members2.addAll(Arrays.asList(container2.members()));

    assertTrue(members1.size() == members2.size());
    for (int i = 0; i < members1.size(); i++) {
      IResource member1 = (IResource) members1.get(i);
      IResource member2 = container2.findMember(member1.getName());
      assertNotNull(member2);
      assertEquals(member1, member2);
    }
  }
 /**
  * Deletes a set of files from the file system, and also their parent folders if those become
  * empty during this process.
  *
  * @param nameSet set of file paths
  * @param monitor progress monitor
  * @throws CoreException if an error occurs
  */
 private void deleteFiles(final Set<IPath> nameSet, IProgressMonitor monitor)
     throws CoreException {
   if (nameSet == null || nameSet.isEmpty()) {
     return;
   }
   Set<IContainer> subFolders = new HashSet<IContainer>();
   for (IPath filePath : nameSet) {
     // Generate new path
     IFile currentFile = project.getFile(filePath);
     if (currentFile.exists()) {
       // Retrieve parent folder and store for deletion
       IContainer folder = currentFile.getParent();
       subFolders.add(folder);
       currentFile.delete(true, monitor);
     }
     monitor.worked(1);
   }
   // Delete parent folders, if they are empty
   for (IContainer folder : subFolders) {
     if (folder.exists() && folder.members().length == 0) {
       folder.delete(true, monitor);
     }
     monitor.worked(1);
   }
 }
 protected void deleteEmptyParent(IProgressMonitor monitor, IContainer container)
     throws CoreException {
   final IContainer parent = container.getParent();
   if (container.members().length == 0) {
     container.delete(true, monitor);
     deleteEmptyParent(monitor, parent);
   }
 }
 protected void getFilesFromContainer(IContainer folder, ArrayList<IFile> files) {
   try {
     IResource[] members = folder.members();
     for (IResource member : members) {
       getFilesFromResouce(member, files);
     }
   } catch (CoreException e) {
     Logger.logException(e);
   }
 }
 private void removeGlobalEiq(IProject project) throws CoreException {
   final IResource globalEiqFile = project.findMember(MigratorConstants.GLOBAL_EIQ_PATH);
   if (globalEiqFile != null) {
     final IProgressMonitor monitor = new NullProgressMonitor();
     final IContainer parent = globalEiqFile.getParent();
     globalEiqFile.delete(true, monitor);
     if (parent.members().length == 0) {
       parent.delete(true, monitor);
     }
   }
 }
示例#10
0
  private List<IResource> filteredMembers(IContainer container) throws CoreException {
    List<IResource> children = new ArrayList<IResource>();

    for (IResource child : container.members()) {
      String name = child.getName();
      if (!(name.startsWith("."))) {
        children.add(child);
      }
    }

    return children;
  }
示例#11
0
 private static void populateResources(
     final Shell shell, final IContainer container, final List<IResource> resources) {
   try {
     for (final IResource resource : container.members()) {
       if (resource instanceof IContainer) {
         populateResources(shell, (IContainer) resource, resources);
       } else {
         resources.add(resource);
       }
     }
   } catch (final Exception e) {
     Activator.error(e);
   }
 }
 private void addMembersToList(IContainer iContainer, List iResources) throws CoreException {
   if (iContainer != null) {
     IResource[] members = iContainer.members();
     for (int i = 0; i != members.length; ++i) {
       IResource member = members[i];
       if (!iResources.contains(member)) {
         iResources.add(member);
       }
       if (member instanceof IContainer) {
         addMembersToList((IContainer) member, iResources);
       }
     }
   }
 }
  protected Object[] getValidChildren(IContainer container) {
    List<IResource> resources = new ArrayList<IResource>();
    try {
      for (IResource child : container.members()) {
        if (isValid(child)) {
          resources.add(child);
        }
      }
    } catch (CoreException ce) {
      Logger.logError("Error while getting children for resource: " + container, ce);
    }

    return resources.toArray();
  }
 protected void collectFiles(IContainer parent, List result) {
   try {
     IResource[] resources = parent.members();
     for (int i = 0; i < resources.length; i++) {
       IResource resource = resources[i];
       if (resource instanceof IFile) {
         result.add(resource);
       } else if (resource instanceof IContainer) {
         collectFiles((IContainer) resource, result);
       }
     }
   } catch (CoreException e) {
     MakeCorePlugin.log(e.getStatus());
   }
 }
 /**
  * @param resource that may contain a META-INF folder
  * @return META-INF folder, if found. Null otherwise
  * @throws CoreException
  */
 protected IFolder getMetaFolder(IResource resource) throws CoreException {
   if (!(resource instanceof IContainer)) {
     return null;
   }
   IContainer folder = (IContainer) resource;
   // Only look for META-INF folder at top-level in the given container.
   IResource[] members = folder.members();
   if (members != null) {
     for (IResource mem : members) {
       if (META_FOLDER_NAME.equals(mem.getName()) && mem instanceof IFolder) {
         return (IFolder) mem;
       }
     }
   }
   return null;
 }
 /**
  * Tries and find a file with the given name under the given container (recursively).
  *
  * @param container The container under which to seek for a file.
  * @param fileName Name of the file we seek.
  * @return The IFile of name <code>fileName</code> under the given <code>container</code>. <code>
  *     null</code> if none could be found.
  */
 private static IFile findChild(IContainer container, String fileName) {
   IFile result = null;
   try {
     final IResource[] members = container.members();
     for (int i = 0; i < members.length && result == null; i++) {
       final IResource child = members[i];
       if (child instanceof IContainer) {
         result = findChild((IContainer) child, fileName);
       } else if (child instanceof IFile && child.getName().equals(fileName)) {
         result = (IFile) child;
       }
     }
   } catch (CoreException e) {
     // FIXME log
   }
   return result;
 }
示例#17
0
  private static void addToZip(
      IPath path, IResource resource, ZipOutputStream zip, boolean adjustGMTOffset)
      throws IOException, CoreException {

    switch (resource.getType()) {
      case IResource.FILE:
        ZipEntry zipEntry = new ZipEntry(path.toString());

        zip.putNextEntry(zipEntry);

        InputStream contents = ((IFile) resource).getContents();

        if (adjustGMTOffset) {
          TimeZone currentTimeZone = TimeZone.getDefault();
          Calendar currentDt = new GregorianCalendar(currentTimeZone, Locale.getDefault());

          // Get the Offset from GMT taking current TZ into account
          int gmtOffset =
              currentTimeZone.getOffset(
                  currentDt.get(Calendar.ERA), currentDt.get(Calendar.YEAR),
                  currentDt.get(Calendar.MONTH), currentDt.get(Calendar.DAY_OF_MONTH),
                  currentDt.get(Calendar.DAY_OF_WEEK), currentDt.get(Calendar.MILLISECOND));

          zipEntry.setTime(System.currentTimeMillis() + (gmtOffset * -1));
        }

        try {
          IOUtils.copy(contents, zip);
        } finally {
          contents.close();
        }

        break;

      case IResource.FOLDER:
      case IResource.PROJECT:
        IContainer container = (IContainer) resource;

        IResource[] members = container.members();

        for (IResource res : members) {
          addToZip(path.append(res.getName()), res, zip, adjustGMTOffset);
        }
    }
  }
示例#18
0
 /**
  * Returns a list of existing member files (that validate the file extension) in this resource.
  *
  * @param iContainer The container to browse for files with the given extension.
  * @param extension The file extension to browse for.
  * @return The List of files of the given extension contained by <code>container</code>.
  * @throws CoreException Thrown if we couldn't retrieve the children of <code>container</code>.
  */
 private List<IFile> members(IContainer iContainer, String extension) throws CoreException {
   List<IFile> output = new ArrayList<IFile>();
   if (iContainer != null) {
     IResource[] children = iContainer.members();
     if (children != null) {
       for (int i = 0; i < children.length; ++i) {
         IResource resource = children[i];
         if (resource instanceof IFile
             && extension.equals(((IFile) resource).getFileExtension())) {
           output.add((IFile) resource);
         } else if (resource instanceof IContainer) {
           output.addAll(members((IContainer) resource, extension));
         }
       }
     }
   }
   return output;
 }
 private void unmarkTeamPrivate(final IContainer p) throws CoreException {
   final IResource[] c;
   c = p.members(IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS);
   if (c != null) {
     for (int k = 0; k < c.length; k++) {
       if (c[k] instanceof IContainer) {
         unmarkTeamPrivate((IContainer) c[k]);
       }
       if (c[k].isTeamPrivateMember()) {
         // TODO is this the right location?
         if (GitTraceLocation.CORE.isActive())
           GitTraceLocation.getTrace()
               .trace(
                   GitTraceLocation.CORE.getLocation(), "notTeamPrivate " + c[k]); // $NON-NLS-1$
         c[k].setTeamPrivateMember(false);
       }
     }
   }
 }
  /**
   * Returns the name of the directory containing the given resource that can be used as root by pub
   * serve. Pub serve uses the directories that are siblings to the pubspec as root.
   *
   * @param container - directory which contains the pubspec.yaml
   * @param resource - the resource to launch
   * @return
   */
  private String getPubserveRootDir(IContainer container, IResource resource) {

    try {
      IResource[] folders = container.members();
      for (IResource folder : folders) {
        if (folder instanceof IFolder
            && !(folder.getName().equals(DartCore.PACKAGES_DIRECTORY_NAME)
                || folder.getName().equals(DartCore.BUILD_DIRECTORY_NAME))) {
          if (resource.getFullPath().toString().startsWith(folder.getFullPath().toString())) {
            return folder.getName();
          }
        }
      }
    } catch (CoreException e) {
      DartCore.logError(e);
    }

    return null;
  }
示例#21
0
文件: PathUtil.java 项目: jylind/pyro
  private static IResource findMember(IContainer container, String path) {
    // even though the filesystem is case-insensitive on Windows, Eclipse's Resource
    // APIs only find files in a case-sensitive manner.  since Robot does not do
    // this at runtime, we'll need to lessen the restriction by doing a more
    // expensive segment-by-segment comparison here
    if (Platform.OS_WIN32.equals(Platform.getOS())) {
      List<String> segments = getPathSegments(path);
      while (!segments.isEmpty()) {
        String nextSegment = segments.remove(0);

        if ("..".equals(nextSegment)) {
          container = container.getParent();
        } else if (".".equals(nextSegment)) {
          continue;
        } else {
          try {
            IResource[] members = container.members();
            for (IResource member : members) {
              if (nextSegment.equalsIgnoreCase(member.getName())) {
                if (member instanceof IContainer) {
                  // found the next folder in the path, continue
                  container = (IContainer) member;
                  break;
                } else if (segments.isEmpty()) {
                  // leaf node, this is the file we're looking for
                  return member;
                }
              }
            }
          } catch (CoreException e) {
            // do nothing, we'll just return a null for this path below
          }
        }
      }

      // error condition - for a malformed or non-existent path we return nothing
      return null;
    } else {
      // non-windows OS - simple Eclipse API works well
      return container.findMember(path);
    }
  }
示例#22
0
  private static void recursivelyFindFilesWithExtension(
      ArrayList<IResource> allFiles, IPath path, IWorkspaceRoot wsRoot, String extension) {
    IContainer container = wsRoot.getContainerForLocation(path);

    try {
      IResource[] resources = container.members();
      for (IResource resource : resources) {
        if (extension.equalsIgnoreCase(resource.getFileExtension())) {
          allFiles.add(resource);
        }
        if (resource.getType() == IResource.FOLDER) {
          IPath tempPath = resource.getLocation();
          recursivelyFindFilesWithExtension(allFiles, tempPath, wsRoot, extension);
        }
      }
    } catch (CoreException e) {
      // eat the exception, but throw it in the console
      e.printStackTrace();
    }
  }
        private boolean hasMatchingChildrenRecursive(IContainer container, final IFilter filter) {
          try {
            IResource[] members = container.members();
            for (IResource member : members) {
              if (resourceMatches(filter, member)) {
                return true;
              }

              if (member instanceof IContainer) {
                boolean has = hasMatchingChildrenRecursive((IContainer) member, filter);
                if (has) {
                  return true;
                }
              }
            }
          } catch (Exception e) {
          }

          return false;
        }
 private void handleContainerSelection(final Object object) {
   IContainer container = (IContainer) object;
   try {
     if (container.isAccessible()) {
       IResource[] resources = container.members();
       for (int i = 0; i < resources.length; i++) {
         IResource resource = resources[i];
         String resourceName = resource.getName();
         boolean hasWarProductExtension =
             resourceName.endsWith("." + WARProductConstants.FILE_EXTENSION); // $NON-NLS-1$
         if (resource instanceof IFile && hasWarProductExtension) {
           IFile file = (IFile) resource;
           loadProductFromFile(file);
         }
       }
     }
   } catch (final CoreException e) {
     MessageDialog.openError(getShell(), Messages.LoadWARProductError, e.getMessage());
   }
 }
  private void setSelection(Map selectionMap, IContainer parent, IFilter filter) {
    try {

      IResource[] resources = parent.members();
      List selections = new ArrayList();

      for (int i = 0; i < resources.length; i++) {
        IResource resource = resources[i];
        if ((resource.getType() & IResource.FILE) > 0) {
          if (filter.accept(resource)) selections.add(resource);
        } else {
          setSelection(selectionMap, (IContainer) resource, filter);
        }
      }

      if (!selections.isEmpty()) selectionMap.put(parent, selections);

    } catch (CoreException x) {
      // Just return if we can't get any info
      return;
    }
  }
  /**
   * Extract service names / methods / screens etc. for faster searches
   *
   * @throws CoreException
   */
  private void scanOfbizProjectOrFolder(IContainer project, UIScanProgressHelper progressHelper)
      throws CoreException {
    List<IResource> resourceList =
        new ArrayList<IResource>(Arrays.asList(project.members(IContainer.EXCLUDE_DERIVED)));

    for (IResource resource : resourceList) {
      checkForCancel();

      if (resource.getType() == IResource.FOLDER) {
        progressHelper.showProgress();
        showStatus(resource);
        scanOfbizProjectOrFolder((IFolder) resource, progressHelper);
      } else if ("xml".equals(resource.getFileExtension())) {

        helper.extractDefinitionsFromXml(
            resource,
            serviceMethodToNameMap,
            serviceNameAndFilePathMap,
            referencedFtlList,
            referencedBshOrGroovyList,
            referencedServiceList,
            referencedViewList,
            viewDefinitionMap,
            referencedScreenList,
            screenNameAndFilePathMap);

      } else if ("ftl".equals(resource.getFileExtension())) {
        ftlList.add(new NonJavaIMember(resource));
        helper.searchForProgrammaticallyRenderedScreen(resource, referencedScreenList);
      } else if ("bsh".equals(resource.getFileExtension())) {
        bshOrGroovyList.add(new NonJavaIMember(resource));
        helper.searchForProgrammaticallyRenderedScreen(resource, referencedScreenList);
      } else if ("bsh".equals(resource.getFileExtension())) {
        helper.searchForProgrammaticallyRenderedScreen(resource, referencedScreenList);
      } else if ("groovy".equals(resource.getFileExtension())) {
        bshOrGroovyList.add(new NonJavaIMember(resource));
      }
    }
  }
    @Override
    public Object[] getElements(final Object element) {
      final List<IResource> elements = new ArrayList<IResource>();

      if (this.roots.size() == 1) {
        final IContainer root = this.roots.get(0);

        try {
          for (IResource child : root.members()) {
            if (child.isAccessible()) {
              elements.add(child);
            }
          }
        } catch (CoreException e) {
          SapphireUiFrameworkPlugin.log(e);
        }
      } else {
        elements.addAll(this.roots);
      }

      return elements.toArray(new IResource[elements.size()]);
    }
示例#28
0
 private void delete(
     IResource resource,
     OutputConfiguration config,
     EclipseResourceFileSystemAccess2 access,
     IProgressMonitor monitor)
     throws CoreException {
   if (monitor.isCanceled()) {
     throw new OperationCanceledException();
   }
   if (resource instanceof IContainer) {
     IContainer container = (IContainer) resource;
     for (IResource child : container.members()) {
       delete(child, config, access, monitor);
     }
     container.delete(IResource.KEEP_HISTORY, monitor);
   } else if (resource instanceof IFile) {
     IFile file = (IFile) resource;
     access.deleteFile(file, config.getName(), monitor);
   } else {
     resource.delete(IResource.KEEP_HISTORY, monitor);
   }
 }
示例#29
0
 /** @since 2.5 */
 protected void cleanOutput(
     IBuildContext ctx,
     OutputConfiguration config,
     EclipseResourceFileSystemAccess2 access,
     IProgressMonitor monitor)
     throws CoreException {
   final IProject project = ctx.getBuiltProject();
   for (IContainer container : getOutputs(project, config)) {
     if (!container.exists()) {
       return;
     }
     if (config.isCanClearOutputDirectory()) {
       for (IResource resource : container.members()) {
         if (!config.isKeepLocalHistory()) {
           resource.delete(IResource.NONE, monitor);
         } else if (access == null) {
           resource.delete(IResource.KEEP_HISTORY, monitor);
         } else {
           delete(resource, config, access, monitor);
         }
       }
     } else if (config.isCleanUpDerivedResources()) {
       List<IFile> resources = derivedResourceMarkers.findDerivedResources(container, null);
       for (IFile iFile : resources) {
         if (monitor.isCanceled()) {
           throw new OperationCanceledException();
         }
         if (access != null) {
           access.deleteFile(iFile, config.getName(), monitor);
         } else {
           iFile.delete(
               config.isKeepLocalHistory() ? IResource.KEEP_HISTORY : IResource.NONE, monitor);
         }
       }
     }
   }
 }
示例#30
0
  /* (non-Javadoc)
   * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
   */
  public Object[] getChildren(Object obj) {
    if (obj instanceof IWorkspaceRoot) {
      try {
        return MakeCorePlugin.getDefault().getTargetManager().getTargetBuilderProjects();
      } catch (CoreException e) {
        MakeCorePlugin.log(e);
      }
    } else if (obj instanceof IContainer) {
      IContainer container = (IContainer) obj;
      ArrayList<Object> children = new ArrayList<Object>();

      boolean isAddingSourceRoots =
          !bFlatten
              && (container instanceof IProject)
              && CCorePlugin.showSourceRootsAtTopOfProject();

      // add source roots if necessary
      if (isAddingSourceRoots) {
        IProject project = (IProject) container;
        ICSourceEntry[] srcEntries = getSourceEntries(project);
        for (ICSourceEntry srcEntry : srcEntries) {
          if (!srcEntry.getFullPath().equals(project.getFullPath())) {
            children.add(new TargetSourceContainer(srcEntry));
          }
        }
      }

      // add regular folders
      try {
        IResource[] resources = container.members();
        for (IResource rc : resources) {
          if (rc instanceof IContainer) {
            if (!(isAddingSourceRoots && isSourceEntry(rc))) {
              children.add(rc);
            }
          }
        }
      } catch (CoreException e) {
        MakeCorePlugin.log(e);
      }

      // finally add targets
      try {
        IMakeTarget[] targets =
            MakeCorePlugin.getDefault().getTargetManager().getTargets(container);
        children.addAll(Arrays.asList(targets));
      } catch (CoreException e) {
        MakeCorePlugin.log(e);
      }
      return children.toArray();

    } else if (obj instanceof TargetSourceContainer) {
      ArrayList<Object> children = new ArrayList<Object>();
      try {
        IContainer container = ((TargetSourceContainer) obj).getContainer();
        IResource[] resources = container.members();
        for (IResource rc : resources) {
          if (rc instanceof IContainer) {
            children.add(rc);
          }
        }
        children.addAll(
            Arrays.asList(MakeCorePlugin.getDefault().getTargetManager().getTargets(container)));
      } catch (CoreException e) {
        MakeCorePlugin.log(e);
      }
      return children.toArray();
    }
    return new Object[0];
  }