/**
  * 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;
 }
Ejemplo n.º 2
0
  public static Object[] computeFolderForeignResources(
      ScriptProject project,
      IContainer folder,
      char[][] inclusionPatterns,
      char[][] exclusionPatterns)
      throws ModelException {
    Object[] nonScriptResources = new IResource[5];
    int nonScriptResourcesCounter = 0;
    try {
      IBuildpathEntry[] classpath = project.getResolvedBuildpath();
      IResource[] members = folder.members();
      nextResource:
      for (int i = 0, max = members.length; i < max; i++) {
        IResource member = members[i];
        switch (member.getType()) {
          case IResource.FILE:
            String fileName = member.getName();

            // ignore .java files that are not excluded
            if (Util.isValidSourceModule(project, member)
                && !Util.isExcluded(member, inclusionPatterns, exclusionPatterns))
              continue nextResource;
            // ignore .zip file on buildpath
            if (org.eclipse.dltk.compiler.util.Util.isArchiveFileName(
                    DLTKLanguageManager.getLanguageToolkit(project), fileName)
                && isBuildpathEntry(member.getFullPath(), classpath)) continue nextResource;
            // All other resources should be in folders.
            // continue nextResource;
            break;

          case IResource.FOLDER:
            // ignore valid packages or excluded folders that correspond
            // to a nested pkg fragment root
            if (Util.isValidFolderNameForPackage(folder, member.getName())
                && (!Util.isExcluded(member, inclusionPatterns, exclusionPatterns)
                    || isBuildpathEntry(member.getFullPath(), classpath))) continue nextResource;
            break;
        }
        if (nonScriptResources.length == nonScriptResourcesCounter) {
          // resize
          System.arraycopy(
              nonScriptResources,
              0,
              (nonScriptResources = new IResource[nonScriptResourcesCounter * 2]),
              0,
              nonScriptResourcesCounter);
        }
        nonScriptResources[nonScriptResourcesCounter++] = member;
      }
      if (nonScriptResources.length != nonScriptResourcesCounter) {
        System.arraycopy(
            nonScriptResources,
            0,
            (nonScriptResources = new IResource[nonScriptResourcesCounter]),
            0,
            nonScriptResourcesCounter);
      }
      return nonScriptResources;
    } catch (CoreException e) {
      throw new ModelException(e);
    }
  }