/**
   * This test ensures that any previously set project settings are not overwritten if say so, but
   * they are as default.
   *
   * @throws Exception
   */
  public void testSetUsingProjectSettings2() throws Exception {

    assertFalse(
        "by default, should not be using project compiler settings", //$NON-NLS-1$
        AspectJPreferences.isUsingProjectSettings(project));

    projectNode.putBoolean(AspectJPreferences.OPTION_XHasMember, true);

    AspectJPreferences.setUsingProjectSettings(project, true, false);
    boolean b1 = projectNode.getBoolean(AspectJPreferences.OPTION_XHasMember, false);
    assertTrue("should not have reset OPTION_XHasMember to default", b1); // $NON-NLS-1$

    AspectJPreferences.setUsingProjectSettings(project, true);
    b1 = projectNode.getBoolean(AspectJPreferences.OPTION_XHasMember, false);
    assertFalse("should have reset OPTION_XHasMember to default", b1); // $NON-NLS-1$

    AspectJPreferences.setUsingProjectSettings(project, false);
    try {
      projectNode.keys();
      projectNode.getBoolean(AspectJPreferences.OPTION_XHasMember, false);
      fail("Should have thrown an exception.  There should be no project settings"); // $NON-NLS-1$
    } catch (IllegalStateException e) {
      // we expect this exception because setting "use project settings" to false
      // should clear all keys and consequently throw this exception.
    }
  }
 public void testIsUsingProjectSettings() throws Exception {
   boolean b1 = AspectJPreferences.isUsingProjectSettings(project);
   assertFalse("by default, should not be using project compiler settings", b1); // $NON-NLS-1$
   projectNode.putBoolean(AspectJPreferences.OPTION_UseProjectSettings, true);
   b1 = AspectJPreferences.isUsingProjectSettings(project);
   assertTrue("project should now be using project compiler settings", b1); // $NON-NLS-1$
   projectNode.putBoolean(AspectJPreferences.OPTION_UseProjectSettings, false);
   b1 = AspectJPreferences.isUsingProjectSettings(project);
   assertFalse("project should now be using workbench compiler settings", b1); // $NON-NLS-1$
 }
 public void testSetUsingProjectSettings() throws Exception {
   assertFalse(
       "by default, should not be using project compiler settings", //$NON-NLS-1$
       AspectJPreferences.isUsingProjectSettings(project));
   AspectJPreferences.setUsingProjectSettings(project, true, true);
   assertTrue(
       "project should now be using project compiler settings", //$NON-NLS-1$
       AspectJPreferences.isUsingProjectSettings(project));
   AspectJPreferences.setUsingProjectSettings(project, false);
   assertFalse(
       "project should no longer be using project compiler settings", //$NON-NLS-1$
       AspectJPreferences.isUsingProjectSettings(project));
 }
 public void testGetCompilerOptions() throws Exception {
   AspectJPreferences.setCompilerOptions(project, "blah"); // $NON-NLS-1$
   String compilerOptions = AspectJPreferences.getCompilerOptions(project);
   assertEquals(
       "should have \"blah\" as compiler options, instead has " + compilerOptions, // $NON-NLS-1$
       "blah", //$NON-NLS-1$
       compilerOptions);
   AspectJPreferences.setCompilerOptions(project, ""); // $NON-NLS-1$
   compilerOptions = AspectJPreferences.getCompilerOptions(project);
   assertEquals(
       "should have \" \" as compiler options, instead has " + compilerOptions, // $NON-NLS-1$
       "", //$NON-NLS-1$
       compilerOptions);
 }
  public void testGetXLintOptions() throws Exception {
    String lint = AspectJPreferences.getLintOptions(project);
    int ind = lint.indexOf("-Xlintfile"); // $NON-NLS-1$
    if (ind == -1) {
      fail(
          "Didn't find -Xlintfile in string returned from AspectJPreferences.getLintOptions(). Got: "
              + lint); //$NON-NLS-1$
    }
    int ind2 = lint.indexOf('\"', ind);
    if (ind2 == -1) {
      fail(
          "Didn't find start quote in string returned from AspectJPreferences.getLintOptions(). Got: "
              + lint); //$NON-NLS-1$
    }
    int ind3 = lint.indexOf('\"', ind2 + 1);
    if (ind3 == -1) {
      fail(
          "Didn't find end quote in string returned from AspectJPreferences.getLintOptions(). Got: "
              + lint); //$NON-NLS-1$
    }
    String fileName = lint.substring(ind2 + 1, ind3);

    // check the file exists
    File file = new File(fileName);
    assertTrue("Xlintfile does not exist: " + file, file.exists()); // $NON-NLS-1$

    // now try to read from it and check for typeNotExposedToWeaver=warning
    boolean gotWarning =
        checkXlintOption(file, "typeNotExposedToWeaver", "warning"); // $NON-NLS-1$ //$NON-NLS-2$
    assertTrue(
        "Did not find typeNotExpostedToWeaver entry set to warning", gotWarning); // $NON-NLS-1$

    boolean isProjectSettings = AspectJPreferences.isUsingProjectSettings(project);
    String original = prefStore.getString(AspectJPreferences.OPTION_ReportTypeNotExposedToWeaver);
    try {
      // change option to ignore
      AspectJPreferences.setUsingProjectSettings(project, false);
      prefStore.setValue(AspectJPreferences.OPTION_ReportTypeNotExposedToWeaver, JavaCore.IGNORE);

      // recheck
      checkXlintOption(file, "typeNotExposedToWeaver", "ignore"); // $NON-NLS-1$ //$NON-NLS-2$
      assertTrue(
          "Did not find typeNotExpostedToWeaver entry set to ignore", gotWarning); // $NON-NLS-1$
    } finally {
      // restore settings
      AspectJPreferences.setUsingProjectSettings(project, isProjectSettings);
      prefStore.setValue(AspectJPreferences.OPTION_ReportTypeNotExposedToWeaver, original);
    }
  }
 public void testSetCompilerOptions() throws Exception {
   assertFalse(
       "project shouldn't have any error markers", //$NON-NLS-1$
       ProjectDependenciesUtils.projectIsMarkedWithError(project, null));
   AspectJPreferences.setCompilerOptions(project, "blah"); // $NON-NLS-1$
   project.build(IncrementalProjectBuilder.FULL_BUILD, null);
   waitForJobsToComplete();
   assertTrue(
       "build should fail because can't understand compiler options", //$NON-NLS-1$
       ProjectDependenciesUtils.projectIsMarkedWithError(project, null));
   AspectJPreferences.setCompilerOptions(project, ""); // $NON-NLS-1$
   project.build(IncrementalProjectBuilder.FULL_BUILD, null);
   waitForJobsToComplete();
   assertFalse(
       "project shouldn't have any error markers", //$NON-NLS-1$
       ProjectDependenciesUtils.projectIsMarkedWithError(project, null));
 }
  public void testGetShowWeaveMessagesOptionViaWorkbenchPreferences() throws Exception {
    assertFalse(
        "default setting is not to show weave info", //$NON-NLS-1$
        AspectJPreferences.getShowWeaveMessagesOption(project));
    // know that when "show weave messages" is selected in the preference
    // page, then set this store value to true because use the
    // getSelection() call on the button to see whether it
    // is selected (weave messages on) or not (weave messages off)
    AspectJPreferences.setShowWeaveMessagesOption(project, true);
    assertTrue(
        "have chosen to show weave info", //$NON-NLS-1$
        AspectJPreferences.getShowWeaveMessagesOption(project));

    AspectJPreferences.setShowWeaveMessagesOption(project, false);
    assertFalse(
        "have chosen not to show weave info", //$NON-NLS-1$
        AspectJPreferences.getShowWeaveMessagesOption(project));
  }
  public void testGetAdvancedOptionViaWorkbenchPreferences() throws Exception {
    assertFalse(
        "should not be using project settings", //$NON-NLS-1$
        AspectJPreferences.isUsingProjectSettings(project));
    assertEquals(
        "should have no advanced options set", //$NON-NLS-1$
        " ",
        AspectJPreferences.getAdvancedOptions(project)); // $NON-NLS-1$

    prefStore.setValue(AspectJPreferences.OPTION_XSerializableAspects, true);
    assertEquals(
        "should have set -XSerializableAspects option", //$NON-NLS-1$
        " -XserializableAspects ", //$NON-NLS-1$
        AspectJPreferences.getAdvancedOptions(project));

    prefStore.setValue(AspectJPreferences.OPTION_XSerializableAspects, false);
    assertEquals(
        "should have no advanced options set", //$NON-NLS-1$
        " ",
        AspectJPreferences.getAdvancedOptions(project)); // $NON-NLS-1$

    prefStore.setValue(AspectJPreferences.OPTION_XNoInline, true);
    assertEquals(
        "should have set -XnoInline e option", //$NON-NLS-1$
        " -XnoInline ", //$NON-NLS-1$
        AspectJPreferences.getAdvancedOptions(project));

    prefStore.setValue(AspectJPreferences.OPTION_XNotReweavable, true);
    assertEquals(
        "should have set -XnotReweavable option", //$NON-NLS-1$
        " -XnoInline -XnotReweavable ", //$NON-NLS-1$
        AspectJPreferences.getAdvancedOptions(project));

    prefStore.setValue(AspectJPreferences.OPTION_XHasMember, true);
    assertEquals(
        "should have set -XhasMember option", //$NON-NLS-1$
        " -XnoInline -XnotReweavable -XhasMember ", //$NON-NLS-1$
        AspectJPreferences.getAdvancedOptions(project));

    prefStore.setValue(AspectJPreferences.OPTION_XHasMember, false);
    prefStore.setValue(AspectJPreferences.OPTION_XNotReweavable, false);
    prefStore.setValue(AspectJPreferences.OPTION_XNoInline, false);
    assertEquals(
        "should have no advanced options set", //$NON-NLS-1$
        " ",
        AspectJPreferences.getAdvancedOptions(project)); // $NON-NLS-1$
  }
  public void testGetShowWeaveMessagesOptionViaProjectPreferences() throws Exception {
    AspectJPreferences.setUsingProjectSettings(project, true, true);

    assertFalse(
        "default setting is not to show weave info", //$NON-NLS-1$
        AspectJPreferences.getShowWeaveMessagesOption(project));
    // know that when "show weave messages" is selected in the preference
    // page, then set this project node value to true because use the
    // following :
    // 		String stringValue = curr.getSelection() ? "true" : "false";
    // to see whether it is selected (weave messages on) or not (weave messages off)
    AspectJPreferences.setShowWeaveMessagesOption(project, true);
    assertTrue(
        "have chosen to show weave info", //$NON-NLS-1$
        AspectJPreferences.getShowWeaveMessagesOption(project));

    AspectJPreferences.setShowWeaveMessagesOption(project, false);
    assertFalse(
        "have chosen not to show weave info", //$NON-NLS-1$
        AspectJPreferences.getShowWeaveMessagesOption(project));
  }
  public void testGetAdvancedOptionViaProjectPreferences() throws Exception {
    AspectJPreferences.setUsingProjectSettings(project, true);
    assertTrue(
        "should be using project settings", //$NON-NLS-1$
        AspectJPreferences.isUsingProjectSettings(project));
    assertEquals(
        "should have no advanced options set", //$NON-NLS-1$
        " ",
        AspectJPreferences.getAdvancedOptions(project)); // $NON-NLS-1$

    projectNode.put(AspectJPreferences.OPTION_XSerializableAspects, "true"); // $NON-NLS-1$
    assertEquals(
        "should have set -XSerializableAspects option", //$NON-NLS-1$
        " -XserializableAspects ", //$NON-NLS-1$
        AspectJPreferences.getAdvancedOptions(project));

    projectNode.put(AspectJPreferences.OPTION_XSerializableAspects, "false"); // $NON-NLS-1$
    assertEquals(
        "should have no advanced options set", //$NON-NLS-1$
        " ",
        AspectJPreferences.getAdvancedOptions(project)); // $NON-NLS-1$

    projectNode.put(AspectJPreferences.OPTION_XNoInline, "true"); // $NON-NLS-1$
    assertEquals(
        "should have set -XnoInline option", //$NON-NLS-1$
        " -XnoInline ", //$NON-NLS-1$
        AspectJPreferences.getAdvancedOptions(project));

    projectNode.put(AspectJPreferences.OPTION_XNotReweavable, "true"); // $NON-NLS-1$
    assertEquals(
        "should have set -XnotReweavable option", //$NON-NLS-1$
        " -XnoInline -XnotReweavable ", //$NON-NLS-1$
        AspectJPreferences.getAdvancedOptions(project));

    projectNode.put(AspectJPreferences.OPTION_XHasMember, "true"); // $NON-NLS-1$
    assertEquals(
        "should have set -XhasMember option", //$NON-NLS-1$
        " -XnoInline -XnotReweavable -XhasMember ", //$NON-NLS-1$
        AspectJPreferences.getAdvancedOptions(project));

    projectNode.put(AspectJPreferences.OPTION_XHasMember, "false"); // $NON-NLS-1$
    projectNode.put(AspectJPreferences.OPTION_XNotReweavable, "false"); // $NON-NLS-1$
    projectNode.put(AspectJPreferences.OPTION_XNoInline, "false"); // $NON-NLS-1$

    assertEquals(
        "should have no advanced options set", //$NON-NLS-1$
        " ",
        AspectJPreferences.getAdvancedOptions(project)); // $NON-NLS-1$
    AspectJPreferences.setUsingProjectSettings(project, false);
    assertFalse(
        "should not be using project settings", //$NON-NLS-1$
        AspectJPreferences.isUsingProjectSettings(project));
    assertEquals(
        "should have no advanced options set", //$NON-NLS-1$
        " ",
        AspectJPreferences.getAdvancedOptions(project)); // $NON-NLS-1$
  }