Exemplo n.º 1
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;
 }
Exemplo n.º 2
0
 @Override
 protected void clean(IProgressMonitor monitor) throws CoreException {
   super.clean(monitor);
   DCLPersistence.clean(this.getProject());
   MarkerUtils.deleteMarkers(this.getProject());
   MarkerUtils.deleteErrorMarker(this.getProject());
   ArchitectureUtils.cleanArchitecture(getProject());
 }
Exemplo n.º 3
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;
      }
    }
  }
Exemplo n.º 4
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);
    }
  }
Exemplo n.º 5
0
  protected void fullLoad(final IProgressMonitor monitor)
      throws CoreException, IOException, ClassNotFoundException, ParseException {
    monitor.setTaskName("Checking architecture");
    monitor.subTask("loading dependencies");
    final Architecture architecture =
        ArchitectureUtils.getOrInitializeArchitecture(this.getProject());
    monitor.beginTask("Checking architecture", architecture.getProjectClasses().size());

    for (String className : architecture.getProjectClasses()) {
      monitor.subTask(className);
      Collection<Dependency> dependencies = DCLPersistence.load(this.getProject(), className);
      if (dependencies == null) {
        throw new CoreException(null);
      }
      architecture.updateDependencies(className, dependencies);
      monitor.worked(1);
    }
  }