/**
   * Tests that the UnwovenClassFiles have the correct path when there is no outputDir but there is
   * an OutputLocationManager. Is a simple project that has no inpath setting
   */
  public void testCorrectInfoWhenNoOutputPath() {
    build("inpathTesting");
    AjState state = getState();

    Map classNameToFileMap = state.getClassNameToFileMap();
    assertFalse("expected there to be classes ", classNameToFileMap.isEmpty());
    Set entrySet = classNameToFileMap.entrySet();
    for (Iterator iterator = entrySet.iterator(); iterator.hasNext(); ) {
      Map.Entry entry = (Map.Entry) iterator.next();
      String className = (String) entry.getKey();
      String fullClassName =
          expectedOutputDir
              + File.separator
              + className.replace('.', File.separatorChar)
              + ".class";
      File file = (File) entry.getValue();
      assertEquals(
          "expected file to have path \n"
              + fullClassName
              + ", but"
              + " found path \n"
              + file.getAbsolutePath(),
          fullClassName,
          file.getAbsolutePath());
    }
  }
  /**
   * Tests that the UnwovenClassFiles corresponding to jars on the inpath have the correct class
   * name when there is no output path (ultimately tests AjBuildManager.initBcelWorld() when there
   * is a jar on the inpath). Only does one build.
   */
  public void testPathResolutionWithInpathJarAndNoOutputPath() {
    String inpathDir = inpathTestingDir + File.separator + "inpathJar.jar";
    addInpathEntry(inpathDir);
    build("inpathTesting");
    // expect to compile the aspect in 'inpathTesting' project and weave
    // both the aspect and the class in the jar on the inpath.
    checkCompileWeaveCount("inpathTesting", 1, 2);

    AjState state = getState();

    // tests AjState.createUnwovenClassFile(BinarySourceFile)
    Map binarySources = state.getAjBuildManager().getBinarySourcesForThisWeave();
    assertFalse(
        "expected there to be binary sources from the inpath setting but didn't find any",
        binarySources.isEmpty());

    List unwovenClassFiles = (List) binarySources.get(inpathDir);
    List fileNames = new ArrayList();

    for (Iterator iterator = unwovenClassFiles.iterator(); iterator.hasNext(); ) {
      UnwovenClassFile ucf = (UnwovenClassFile) iterator.next();
      if (ucf.getFilename().indexOf(expectedOutputDir) == -1) {
        fileNames.add(ucf.getFilename());
      }
    }
    assertTrue(
        "expected to find UnwovenClassFile from directory\n"
            + expectedOutputDir
            + ", \n but found files "
            + fileNames,
        fileNames.isEmpty());
  }
 public void testAspectsRecordedOnlyOnceInState() {
   configureNonStandardCompileOptions("inpathTesting", "-outxml");
   build("inpathTesting");
   AjState state = getState();
   Map m = state.getAspectNamesToFileNameMap();
   assertEquals(
       "Expected only one aspect recored in the state but found " + m.size(), 1, m.size());
   build("inpathTesting");
   m = state.getAspectNamesToFileNameMap();
   assertEquals(
       "Expected only one aspect recored in the state but found " + m.size(), 1, m.size());
 }
  /**
   * Tests that the UnwovenClassFiles corresponding to classes on the inpath have the correct class
   * name when there is no output directory (ultimately tests
   * AjState.createUnwovenClassFile(BinarySourceFile) and ensures the unwovenClassFile has the
   * correct name. Makes a change to a class file on the inpath to ensure we enter this method
   * (there is a check that says are we the first build))
   */
  public void testPathResolutionAfterChangeInClassOnInpath() throws Exception {
    String inpathDir = inpathTestingDir + File.separator + "injarBin" + File.separator + "pkg";
    addInpathEntry(inpathDir);
    build("inpathTesting");

    // build again so that we enter
    // AjState.createUnwovenClassFile(BinarySourceFile)
    File from =
        new File(
            testdataSrcDir
                + File.separatorChar
                + "inpathTesting"
                + File.separatorChar
                + "newInpathClass"
                + File.separatorChar
                + "InpathClass.class");
    File destination = new File(inpathDir + File.separatorChar + "InpathClass.class");
    FileUtil.copyFile(from, destination);

    // get hold of the state for this project - expect to find one
    AjState state = getState();
    AjBuildConfig buildConfig = state.getBuildConfig();
    state.prepareForNextBuild(buildConfig);

    Map binarySources = state.getBinaryFilesToCompile(true);
    assertFalse(
        "expected there to be binary sources from the inpath setting but didn't find any",
        binarySources.isEmpty());

    List unwovenClassFiles =
        (List) binarySources.get(inpathDir + File.separator + "InpathClass.class");
    List fileNames = new ArrayList();
    // the unwovenClassFiles should have filenames that point to the output dir
    // (which in this case is the sandbox dir) and not where they came from.
    for (Iterator iterator = unwovenClassFiles.iterator(); iterator.hasNext(); ) {
      UnwovenClassFile ucf = (UnwovenClassFile) iterator.next();
      if (ucf.getFilename().indexOf(expectedOutputDir) == -1) {
        fileNames.add(ucf.getFilename());
      }
    }
    assertTrue(
        "expected to find UnwovenClassFile from directory\n"
            + expectedOutputDir
            + ", \n but found files "
            + fileNames,
        fileNames.isEmpty());
  }
  /**
   * Tests that the UnwovenClassFiles corresponding to classes on the inpath have the correct class
   * name when there is no output directory (ultimately tests AjBuildManager.initBcelWorld() when
   * there is a jar on the inpath). Only does one build.
   */
  public void testPathResolutionWithInpathDirAndNoOutputPath() {
    String inpathDir = inpathTestingDir + File.separator + "injarBin" + File.separator + "pkg";
    addInpathEntry(inpathDir);
    build("inpathTesting");

    // expect to compile the aspect in 'inpathTesting' project and weave
    // both the aspect and the class on the inpath.
    checkCompileWeaveCount("inpathTesting", 1, 2);

    // get hold of the state for this project - expect to find one
    AjState state = getState();

    // the classes onthe inpath are recorded against the AjBuildManager
    // (they are deleted from the ajstate whilst cleaning up after a build)
    Map binarySources = state.getAjBuildManager().getBinarySourcesForThisWeave();
    assertFalse(
        "expected there to be binary sources from the inpath setting but didn't find any",
        binarySources.isEmpty());

    List unwovenClassFiles =
        (List) binarySources.get(inpathDir + File.separator + "InpathClass.class");
    List fileNames = new ArrayList();
    // the unwovenClassFiles should have filenames that point to the output dir
    // (which in this case is the sandbox dir) and not where they came from.
    for (Iterator iterator = unwovenClassFiles.iterator(); iterator.hasNext(); ) {
      UnwovenClassFile ucf = (UnwovenClassFile) iterator.next();
      if (ucf.getFilename().indexOf(expectedOutputDir) == -1) {
        fileNames.add(ucf.getFilename());
      }
    }
    assertTrue(
        "expected to find UnwovenClassFile from directory\n"
            + expectedOutputDir
            + ", \n but found files "
            + fileNames,
        fileNames.isEmpty());
  }