コード例 #1
0
  /** Returns a list of all the executable Gant scripts available to this application. */
  public List<File> getAvailableScripts() {
    List<File> scripts = new ArrayList<File>();
    if (settings.getGrailsHome() != null) {
      addCommandScripts(new File(settings.getGrailsHome(), "scripts"), scripts);
      addCommandScripts(
          new File(settings.getGrailsHome(), "grails-scripts/src/main/scripts"), scripts);
    }
    addCommandScripts(new File(settings.getBaseDir(), "scripts"), scripts);
    addCommandScripts(new File(settings.getUserHome(), ".grails/scripts"), scripts);

    for (File dir : pluginPathSupport.listKnownPluginDirs()) {
      addPluginScripts(dir, scripts);
    }

    PathMatchingResourcePatternResolver resolver =
        new PathMatchingResourcePatternResolver(settings.getRootLoader());
    try {
      final Resource[] resources = resolver.getResources("classpath*:META-INF/scripts/*.groovy");
      for (Resource resource : resources) {
        scripts.add(resource.getFile());
      }
    } catch (IOException e) {
      // ignore
    }
    return scripts;
  }
コード例 #2
0
 /** Reads a plugin.xml descriptor for the given plugin name */
 public GPathResult readPluginXmlMetadata(String pluginName) throws Exception {
   Resource pluginResource = pluginSettings.getPluginDirForName(pluginName);
   if (pluginResource != null) {
     File pluginDir = pluginResource.getFile();
     return new XmlSlurper().parse(new File(pluginDir, "plugin.xml"));
   }
   return null;
 }
コード例 #3
0
 /** Reads all installed plugin descriptors returning a list */
 public List<GPathResult> readAllPluginXmlMetadata() throws Exception {
   Resource[] allFiles = pluginSettings.getPluginXmlMetadata();
   List<GPathResult> results = new ArrayList<GPathResult>();
   for (Resource resource : allFiles) {
     if (resource.exists()) {
       results.add(new XmlSlurper().parse(resource.getFile()));
     }
   }
   return results;
 }
コード例 #4
0
 // Copies a set of resources to a given directory. The set is specified
 // by an Ant-style path-matching pattern.
 public void copyGrailsResources(Object destDir, Object pattern, boolean overwrite)
     throws FileNotFoundException, IOException {
   new File(destDir.toString()).mkdirs();
   Resource[] resources = resolveResources("classpath:" + pattern);
   for (Resource resource : resources) {
     if (resource.isReadable()) {
       copyGrailsResource(destDir + "/" + resource.getFilename(), resource, overwrite);
     }
   }
 }
コード例 #5
0
 public void copyGrailsResource(Object targetFile, Resource resource, boolean overwrite)
     throws FileNotFoundException, IOException {
   File file = new File(targetFile.toString());
   if (overwrite || !file.exists()) {
     IOUtils.copy(resource.getInputStream(), new FileOutputStream(file));
   }
 }
コード例 #6
0
  protected void loadEventHooks(@SuppressWarnings("hiding") BuildSettings buildSettings) {
    if (buildSettings == null) {
      return;
    }

    loadEventsScript(findEventsScript(new File(buildSettings.getUserHome(), ".grails/scripts")));
    loadEventsScript(findEventsScript(new File(buildSettings.getBaseDir(), "scripts")));

    PluginBuildSettings pluginSettings =
        (PluginBuildSettings) binding.getVariable("pluginSettings");
    for (Resource pluginBase : pluginSettings.getPluginDirectories()) {
      try {
        loadEventsScript(findEventsScript(new File(pluginBase.getFile(), "scripts")));
      } catch (IOException ex) {
        throw new RuntimeException(ex);
      }
    }
  }
コード例 #7
0
  /**
   * Loads a GrailsApplication using the given ResourceLocator instance which will search for
   * appropriate class names
   */
  public DefaultGrailsApplication(org.codehaus.groovy.grails.io.support.Resource[] resources) {
    this();
    for (org.codehaus.groovy.grails.io.support.Resource resource : resources) {

      Class<?> aClass;
      try {
        aClass =
            cl.loadClass(
                org.codehaus.groovy.grails.io.support.GrailsResourceUtils.getClassName(
                    resource.getFile().getAbsolutePath()));
      } catch (ClassNotFoundException e) {
        throw new GrailsConfigurationException(
            "Class not found loading Grails application: " + e.getMessage(), e);
      } catch (IOException e) {
        throw new GrailsConfigurationException(
            "Class not found loading Grails application: " + e.getMessage(), e);
      }
      loadedClasses.add(aClass);
    }
  }