private int executeCommand(CommandLine commandLine, String scriptName, String env) {
    @SuppressWarnings("hiding")
    GrailsConsole console = GrailsConsole.getInstance();
    // Load the BuildSettings file for this project if it exists. Note
    // that this does not load any environment-specific settings.
    try {
      System.setProperty("disable.grails.plugin.transform", "true");

      console.updateStatus("Loading Grails " + settings.getGrailsVersion());
      settings.loadConfig();

      System.setProperty(
          "springloaded.directoriesContainingReloadableCode",
          settings.getClassesDir().getAbsolutePath()
              + ','
              + settings.getPluginClassesDir().getAbsolutePath());
    } catch (Exception e) {
      console.error("There was an error loading the BuildConfig: " + e.getMessage(), e);
      System.exit(1);
    } finally {
      System.setProperty("disable.grails.plugin.transform", "false");
    }

    // Add some extra binding variables that are now available.
    // settings.setGrailsEnv(env);
    // settings.setDefaultEnv(useDefaultEnv);

    BuildSettingsHolder.setSettings(settings);

    return callPluginOrGrailsScript(commandLine, scriptName, env);
  }
  @Override
  public void setResourceLoader(ResourceLoader resourceLoader) {
    if (Metadata.getCurrent().isWarDeployed()) {
      localResourceLoader = resourceLoader;
    } else {
      // The "settings" may be null in some of the Grails unit tests.
      BuildSettings settings = BuildSettingsHolder.getSettings();

      String location = null;
      if (settings != null) {
        location = settings.getResourcesDir().getPath();
      } else if (Environment.getCurrent().isReloadEnabled()) {
        location = Environment.getCurrent().getReloadLocation();
      }

      if (location != null) {
        localResourceLoader = new DevelopmentResourceLoader(application, location);
      } else {
        localResourceLoader = resourceLoader;
      }
    }
    super.setResourceLoader(localResourceLoader);

    if (resourceResolver == null) {
      resourceResolver = new PathMatchingResourcePatternResolver(localResourceLoader);
    }
  }
 private void initBuildSettings() {
   final File basedir = findBaseDir();
   final File grailsHome = findGrailsHome();
   System.setProperty(BuildSettings.APP_BASE_DIR, basedir.getPath());
   grailsSettings = new BuildSettings(grailsHome, basedir);
   customizeBuildSettings(grailsSettings);
   BuildSettingsHolder.setSettings(grailsSettings);
 }
 @Override
 protected void setUp() {
   BuildSettings buildSettings = new BuildSettings(new File("."));
   BuildSettingsHolder.setSettings(buildSettings);
   MockGrailsPluginManager pluginManager = new MockGrailsPluginManager();
   PluginManagerHolder.setPluginManager(pluginManager);
   pluginManager.registerMockPlugin(DefaultGrailsTemplateGeneratorTests.fakeHibernatePlugin);
 }
  public ResourceLocator getResourceLocator() {
    if (resourceLocator == null) {
      resourceLocator = new DefaultResourceLocator();
      BuildSettings buildSettings = BuildSettingsHolder.getSettings();
      String basedir;
      if (buildSettings != null) {
        basedir = buildSettings.getBaseDir().getAbsolutePath();
      } else {
        basedir = ".";
      }

      resourceLocator.setSearchLocation(basedir);
    }
    return resourceLocator;
  }
 @Override
 protected void tearDown() {
   BuildSettingsHolder.setSettings(null);
   PluginManagerHolder.setPluginManager(null);
 }