예제 #1
0
  @Test
  public void createSettings() {
    final File expectedSettingsDir = new File("settingsDir");
    ScriptSource expectedScriptSource = context.mock(ScriptSource.class);
    Map<String, String> expectedGradleProperties = WrapUtil.toMap("key", "myvalue");
    IProjectDescriptorRegistry expectedProjectDescriptorRegistry =
        new DefaultProjectDescriptorRegistry();
    StartParameter expectedStartParameter = new StartParameter();
    final ServiceRegistryFactory serviceRegistryFactory =
        context.mock(ServiceRegistryFactory.class);
    final SettingsInternallServiceRegistry settingsInternallServiceRegistry =
        context.mock(SettingsInternallServiceRegistry.class);
    context.checking(
        new Expectations() {
          {
            one(serviceRegistryFactory).createFor(with(any(Settings.class)));
            will(returnValue(settingsInternallServiceRegistry));
          }
        });

    SettingsFactory settingsFactory =
        new SettingsFactory(
            expectedProjectDescriptorRegistry,
            ThreadGlobalInstantiator.getOrCreate(),
            serviceRegistryFactory);
    final URLClassLoader urlClassLoader = new URLClassLoader(new URL[0]);
    GradleInternal gradle = context.mock(GradleInternal.class);

    DefaultSettings settings =
        (DefaultSettings)
            settingsFactory.createSettings(
                gradle,
                expectedSettingsDir,
                expectedScriptSource,
                expectedGradleProperties,
                expectedStartParameter,
                urlClassLoader);

    assertSame(gradle, settings.getGradle());
    assertSame(expectedProjectDescriptorRegistry, settings.getProjectDescriptorRegistry());
    for (Map.Entry<String, String> entry : expectedGradleProperties.entrySet()) {
      assertEquals(
          entry.getValue(),
          ((DynamicObjectAware) settings).getAsDynamicObject().getProperty(entry.getKey()));
    }

    assertSame(expectedSettingsDir, settings.getSettingsDir());
    assertSame(expectedScriptSource, settings.getSettingsScript());
    assertSame(expectedStartParameter, settings.getStartParameter());
  }
예제 #2
0
 /** Revert all settings to their default value */
 public boolean revertToDefault() {
   if (FACTORY.revertToDefault()) {
     fireSettingsEvent(EventType.REVERT_TO_DEFAULT);
     return true;
   }
   return false;
 }
예제 #3
0
 /** Save property settings to the property file */
 public boolean save() {
   if (getShouldSave()) {
     FACTORY.save();
     fireSettingsEvent(EventType.SAVE);
     return true;
   }
   return false;
 }
예제 #4
0
 @Override
 public String toString() {
   return FACTORY.toString();
 }
예제 #5
0
 /** reload settings from both the property and configuration files */
 public void reload() {
   FACTORY.reload();
   fireSettingsEvent(EventType.RELOAD);
 }
예제 #6
0
 /**
  * Returns the <tt>Properties</tt> instance that stores all settings.
  *
  * @return the <tt>Properties</tt> instance for storing settings
  */
 public Properties getProperties() {
   return FACTORY.getProperties();
 }