Example #1
0
  /**
   * @param projectArtifact the main artifact of the project we're verifying (this is considered the
   *     entry point for reachability)
   * @param artifactsToCheck all artifacts that are on the runtime classpath
   * @param allArtifacts all artifacts, including implicit artifacts (runtime provided artifacts)
   * @return a list of conflicts
   */
  public ImmutableList<Conflict> check(
      Artifact projectArtifact, List<Artifact> artifactsToCheck, List<Artifact> allArtifacts) {

    final CheckerStateBuilder stateBuilder = new CheckerStateBuilder();

    createCanonicalClassMapping(stateBuilder, allArtifacts);
    CheckerState state = stateBuilder.build();

    // brute-force reachability analysis
    Set<TypeDescriptor> reachableClasses =
        reachableFrom(projectArtifact.classes().values(), state.knownClasses());

    final ImmutableList.Builder<Conflict> builder = ImmutableList.builder();

    // Then go through everything in the classpath to make sure all the method calls / field
    // references
    // are satisfied.
    for (Artifact artifact : artifactsToCheck) {
      for (DeclaredClass clazz : artifact.classes().values()) {
        if (!reachableClasses.contains(clazz.className())) {
          continue;
        }

        for (DeclaredMethod method : clazz.methods().values()) {
          checkForBrokenMethodCalls(state, artifact, clazz, method, builder);
          checkForBrokenFieldAccess(state, artifact, clazz, method, builder);
        }
      }
    }
    return builder.build();
  }
Example #2
0
 /**
  * Create a canonical mapping of which classes are kept. First come first serve in the classpath
  *
  * @param stateBuilder conflict checker state we're populating
  * @param allArtifacts maven artifacts to populate checker state with
  */
 private void createCanonicalClassMapping(
     CheckerStateBuilder stateBuilder, List<Artifact> allArtifacts) {
   for (Artifact artifact : allArtifacts) {
     for (DeclaredClass clazz : artifact.classes().values()) {
       if (stateBuilder.knownClasses().putIfAbsent(clazz.className(), clazz) == null) {
         stateBuilder.putSourceMapping(clazz.className(), artifact.name());
       }
     }
   }
 }