Пример #1
0
  private void check(IResource resource, Architecture architecture, boolean reextractDependencies)
      throws CoreException {
    if (resource instanceof IFile && resource.getName().endsWith(".java")) {
      final IFile file = (IFile) resource;
      MarkerUtils.deleteMarkers(file);

      final ICompilationUnit unit = ((ICompilationUnit) JavaCore.create((IFile) resource));

      /* We only consider the units linked to source-folders */
      if (!unit.isOpen()) {
        return;
      }

      final String className = DCLUtil.getClassName(unit);

      /* We only consider the units without compilation errors*/
      if (file.findMaxProblemSeverity(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE)
          == IMarker.SEVERITY_ERROR) {
        // MarkerUtils.addErrorMarker(this.getProject(), "DCLcheck has not verified class " +
        // className + " because it contains compilation errors.");
        return;
      }

      try {
        final Collection<Dependency> dependencies;
        if (reextractDependencies) {
          dependencies = DCLUtil.getDependenciesUsingAST(unit);
          architecture.updateDependencies(className, dependencies);
          DCLPersistence.persist(this.getProject(), className, dependencies);
        } else {
          dependencies = architecture.getDependencies(className);
        }

        for (DependencyConstraint dc : architecture.getDependencyConstraints()) {
          Collection<ArchitecturalDrift> result =
              dc.validate(
                  className,
                  architecture.getModules(),
                  architecture.getProjectClasses(),
                  dependencies,
                  this.getProject());
          if (result != null && !result.isEmpty()) {
            for (ArchitecturalDrift ad : result) {
              MarkerUtils.addMarker(file, ad);
            }
          }
        }
      } catch (Exception e) {
        MarkerUtils.addErrorMarker(
            this.getProject(), "There was a problem in extracting dependencies from " + className);
        CoreException ce = new CoreException(Status.CANCEL_STATUS);
        ce.setStackTrace(e.getStackTrace());
        throw ce;
      }
    }
  }
Пример #2
0
 @Override
 @SuppressWarnings("rawtypes")
 protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException {
   try {
     if (kind == FULL_BUILD || !DCLPersistence.existsDCLFolder(this.getProject())) {
       fullBuild(monitor);
     } else {
       IResourceDelta delta = getDelta(this.getProject());
       if (delta == null) {
         fullBuild(monitor);
       } else {
         /* If the architecture has not been initialized yet */
         if (!ArchitectureUtils.hasArchitectureInitialized(getProject())) {
           fullLoad(monitor);
         }
         incrementalBuild(delta, monitor);
       }
     }
     MarkerUtils.deleteErrorMarker(this.getProject());
   } catch (ParseException e) {
     this.clean(monitor);
     final IFile dcFile = this.getProject().getFile(DCLUtil.DC_FILENAME);
     MarkerUtils.addErrorMarker(
         dcFile, "Syntax error on token \"" + e.getBody() + "\"", e.getLineNumber());
   } catch (Throwable e) {
     this.clean(monitor);
     final String logFileName = DCLUtil.logError(this.getProject(), e);
     MarkerUtils.addErrorMarker(
         this.getProject(),
         "The dclcheck conformance tool has crashed. (see " + logFileName + ")");
   }
   return null;
 }
Пример #3
0
  private void delete(IResource resource) throws CoreException {
    if (resource instanceof IFile && resource.getName().endsWith(".java")) {
      final IFile file = (IFile) resource;
      MarkerUtils.deleteMarkers(file);

      final ICompilationUnit unit = ((ICompilationUnit) JavaCore.create((IFile) resource));
      final String className = DCLUtil.getClassName(unit);

      DCLPersistence.delete(this.getProject(), className);
    }
  }