protected boolean findSourceFiles(IResourceDelta delta) throws CoreException {
   ArrayList visited =
       this.makeOutputFolderConsistent ? new ArrayList(this.sourceLocations.length) : null;
   for (int i = 0, l = this.sourceLocations.length; i < l; i++) {
     ClasspathMultiDirectory md = this.sourceLocations[i];
     if (this.makeOutputFolderConsistent
         && md.hasIndependentOutputFolder
         && !visited.contains(md.binaryFolder)) {
       // even a project which acts as its own source folder can have an independent/nested output
       // folder
       visited.add(md.binaryFolder);
       IResourceDelta binaryDelta = delta.findMember(md.binaryFolder.getProjectRelativePath());
       if (binaryDelta != null) {
         int segmentCount = binaryDelta.getFullPath().segmentCount();
         IResourceDelta[] children = binaryDelta.getAffectedChildren();
         for (int j = 0, m = children.length; j < m; j++)
           if (!checkForClassFileChanges(children[j], md, segmentCount)) return false;
       }
     }
     if (md.sourceFolder.equals(this.javaBuilder.currentProject)) {
       // skip nested source & output folders when the project is a source folder
       int segmentCount = delta.getFullPath().segmentCount();
       IResourceDelta[] children = delta.getAffectedChildren();
       for (int j = 0, m = children.length; j < m; j++)
         if (!isExcludedFromProject(children[j].getFullPath()))
           if (!findSourceFiles(children[j], md, segmentCount)) return false;
     } else {
       IResourceDelta sourceDelta = delta.findMember(md.sourceFolder.getProjectRelativePath());
       if (sourceDelta != null) {
         if (sourceDelta.getKind() == IResourceDelta.REMOVED) {
           if (JavaBuilder.DEBUG)
             System.out.println(
                 "ABORTING incremental build... found removed source folder"); //$NON-NLS-1$
           return false; // removed source folder should not make it here, but handle anyways
           // (ADDED is supported)
         }
         int segmentCount = sourceDelta.getFullPath().segmentCount();
         IResourceDelta[] children = sourceDelta.getAffectedChildren();
         try {
           for (int j = 0, m = children.length; j < m; j++)
             if (!findSourceFiles(children[j], md, segmentCount)) return false;
         } catch (CoreException e) {
           // catch the case that a package has been renamed and collides on disk with an
           // as-yet-to-be-deleted package
           if (e.getStatus().getCode() == IResourceStatus.CASE_VARIANT_EXISTS) {
             if (JavaBuilder.DEBUG)
               System.out.println(
                   "ABORTING incremental build... found renamed package"); //$NON-NLS-1$
             return false;
           }
           throw e; // rethrow
         }
       }
     }
     this.notifier.checkCancel();
   }
   return true;
 }
Esempio n. 2
0
  private void createInconsistentBuildMarker(CoreException coreException) throws CoreException {
    String message = null;
    IStatus status = coreException.getStatus();
    if (status.isMultiStatus()) {
      IStatus[] children = status.getChildren();
      if (children != null && children.length > 0) message = children[0].getMessage();
    }
    if (message == null) message = coreException.getMessage();

    IMarker marker = this.currentProject.createMarker(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER);
    marker.setAttributes(
        new String[] {
          IMarker.MESSAGE, IMarker.SEVERITY, IJavaModelMarker.CATEGORY_ID, IMarker.SOURCE_ID
        },
        new Object[] {
          Messages.bind(Messages.build_inconsistentProject, message),
          new Integer(IMarker.SEVERITY_ERROR),
          new Integer(CategorizedProblem.CAT_BUILDPATH),
          JavaBuilder.SOURCE_ID
        });
  }
 /**
  * @see
  *     org.eclipse.jdt.internal.core.builder.AbstractImageBuilder#writeClassFileContents(org.eclipse.jdt.internal.compiler.ClassFile,
  *     org.eclipse.core.resources.IFile, java.lang.String, boolean,
  *     org.eclipse.jdt.internal.core.builder.SourceFile)
  */
 protected void writeClassFileContents(
     ClassFile classfile,
     IFile file,
     String qualifiedFileName,
     boolean isTopLevelType,
     SourceFile compilationUnit)
     throws CoreException {
   // Before writing out the class file, compare it to the previous file
   // If structural changes occurred then add dependent source files
   byte[] bytes = classfile.getBytes();
   if (file.exists()) {
     if (writeClassFileCheck(file, qualifiedFileName, bytes)
         || compilationUnit.updateClassFile) { // see 46093
       if (JavaBuilder.DEBUG)
         System.out.println("Writing changed class file " + file.getName()); // $NON-NLS-1$
       if (!file.isDerived()) file.setDerived(true, null);
       file.setContents(new ByteArrayInputStream(bytes), true, false, null);
     } else if (JavaBuilder.DEBUG) {
       System.out.println("Skipped over unchanged class file " + file.getName()); // $NON-NLS-1$
     }
   } else {
     if (isTopLevelType) addDependentsOf(new Path(qualifiedFileName), true); // new type
     if (JavaBuilder.DEBUG)
       System.out.println("Writing new class file " + file.getName()); // $NON-NLS-1$
     try {
       file.create(new ByteArrayInputStream(bytes), IResource.FORCE | IResource.DERIVED, null);
     } catch (CoreException e) {
       if (e.getStatus().getCode() == IResourceStatus.CASE_VARIANT_EXISTS) {
         IStatus status = e.getStatus();
         if (status instanceof IResourceStatus) {
           IPath oldFilePath = ((IResourceStatus) status).getPath();
           char[] oldTypeName = oldFilePath.removeFileExtension().lastSegment().toCharArray();
           char[][] previousTypeNames =
               this.newState.getDefinedTypeNamesFor(compilationUnit.typeLocator());
           boolean fromSameFile = false;
           if (previousTypeNames == null) {
             fromSameFile = CharOperation.equals(compilationUnit.getMainTypeName(), oldTypeName);
           } else {
             for (int i = 0, l = previousTypeNames.length; i < l; i++) {
               if (CharOperation.equals(previousTypeNames[i], oldTypeName)) {
                 fromSameFile = true;
                 break;
               }
             }
           }
           if (fromSameFile) {
             // file is defined by the same compilationUnit, but won't be deleted until later so do
             // it now
             IFile collision = file.getParent().getFile(new Path(oldFilePath.lastSegment()));
             collision.delete(true, false, null);
             boolean success = false;
             try {
               file.create(
                   new ByteArrayInputStream(bytes), IResource.FORCE | IResource.DERIVED, null);
               success = true;
             } catch (CoreException ignored) {
               // ignore the second exception
             }
             if (success) return;
           }
         }
         // catch the case that a type has been renamed and collides on disk with an
         // as-yet-to-be-deleted type
         throw new AbortCompilation(true, new AbortIncrementalBuildException(qualifiedFileName));
       }
       throw e; // rethrow
     }
   }
 }