/**
   * Attempts to compile the given InputStream into a Groovy script using the given name
   *
   * @param in The InputStream to read the Groovy code from
   * @param name The name of the class to use
   * @param pageName The page name
   * @param metaInfo
   * @return The compiled java.lang.Class, which is an instance of groovy.lang.Script
   */
  private Class<?> compileGroovyPage(
      InputStream in, String name, String pageName, GroovyPageMetaInfo metaInfo) {
    GroovyClassLoader groovyClassLoader = findOrInitGroovyClassLoader();

    // Compile the script into an object
    Class<?> scriptClass;
    try {
      scriptClass = groovyClassLoader.parseClass(DefaultGroovyMethods.getText(in), name);
    } catch (CompilationFailedException e) {
      LOG.error("Compilation error compiling GSP [" + name + "]:" + e.getMessage(), e);

      int lineNumber = GrailsExceptionResolver.extractLineNumber(e);

      final int[] lineMappings = metaInfo.getLineNumbers();
      if (lineNumber > 0 && lineNumber < lineMappings.length) {
        lineNumber = lineMappings[lineNumber - 1];
      }
      throw new GroovyPagesException(
          "Could not parse script [" + name + "]: " + e.getMessage(), e, lineNumber, pageName);
    } catch (IOException e) {
      throw new GroovyPagesException(
          "IO exception parsing script [" + name + "]: " + e.getMessage(), e);
    }
    return scriptClass;
  }
Example #2
0
  public void execute() throws BuildException {
    List<String> packagesToDoc = new ArrayList<String>();
    Path sourceDirs = new Path(getProject());
    Properties properties = new Properties();
    properties.setProperty("windowTitle", windowTitle);
    properties.setProperty("docTitle", docTitle);
    properties.setProperty("footer", footer);
    properties.setProperty("header", header);
    checkScopeProperties(properties);
    properties.setProperty("publicScope", publicScope.toString());
    properties.setProperty("protectedScope", protectedScope.toString());
    properties.setProperty("packageScope", packageScope.toString());
    properties.setProperty("privateScope", privateScope.toString());
    properties.setProperty("author", author.toString());
    properties.setProperty("processScripts", processScripts.toString());
    properties.setProperty("includeMainForScripts", includeMainForScripts.toString());
    properties.setProperty(
        "overviewFile", overviewFile != null ? overviewFile.getAbsolutePath() : "");

    if (sourcePath != null) {
      sourceDirs.addExisting(sourcePath);
    }
    parsePackages(packagesToDoc, sourceDirs);

    GroovyDocTool htmlTool =
        new GroovyDocTool(
            new ClasspathResourceManager(), // we're gonna get the default templates out of the dist
            // jar file
            sourcePath.list(),
            getDocTemplates(),
            getPackageTemplates(),
            getClassTemplates(),
            links,
            properties);

    try {
      htmlTool.add(sourceFilesToDoc);
      FileOutputTool output = new FileOutputTool();
      htmlTool.renderToOutput(
          output, destDir.getCanonicalPath()); // TODO push destDir through APIs?
    } catch (Exception e) {
      e.printStackTrace();
    }
    // try to override the default stylesheet with custom specified one if needed
    if (styleSheetFile != null) {
      try {
        String css = DefaultGroovyMethods.getText(styleSheetFile);
        File outfile = new File(destDir, "stylesheet.css");
        DefaultGroovyMethods.setText(outfile, css);
      } catch (IOException e) {
        System.out.println(
            "Warning: Unable to copy specified stylesheet '"
                + styleSheetFile.getAbsolutePath()
                + "'. Using default stylesheet instead. Due to: "
                + e.getMessage());
      }
    }
  }
 private void initSplashScreenProvider() {
   ClassLoader classLoader = ApplicationClassLoader.get();
   try {
     URL url =
         classLoader.getResource("META-INF/services/" + SplashScreenProvider.class.getName());
     String className = DefaultGroovyMethods.getText(url).trim();
     splashScreenProvider = (SplashScreenProvider) classLoader.loadClass(className).newInstance();
   } catch (Exception e) {
     splashScreenProvider = new DefaultSplashScreenProvider();
   }
 }
 @SuppressWarnings("rawtypes")
 public List evaluateMappings(Resource resource) {
   InputStream inputStream = null;
   try {
     inputStream = resource.getInputStream();
     return evaluateMappings(classLoader.parseClass(DefaultGroovyMethods.getText(inputStream)));
   } catch (IOException e) {
     throw new UrlMappingException(
         "Unable to read mapping file [" + resource.getFilename() + "]: " + e.getMessage(), e);
   } finally {
     IOUtils.closeQuietly(inputStream);
   }
 }