Search in sources :

Example 1 with Path

use of org.apache.tools.ant.types.Path in project gcontracts by andresteingress.

the class ContractGroovyDoc method execute.

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);
    if (classTemplates.size() == 0)
        throw new BuildException("Method getClassTemplates() needs to return at least a single classTemplate String!");
    GroovyDocTool htmlTool = new GroovyDocTool(createResourceManager(), sourcePath.list(), getDocTemplates(), getPackageTemplates(), getClassTemplates(), links, properties);
    try {
        htmlTool.add(sourceFilesToDoc);
        FileOutputTool output = new FileOutputTool();
        // TODO push destDir through APIs?
        htmlTool.renderToOutput(output, destDir.getCanonicalPath());
    } 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());
        }
    }
}
Also used : Path(org.apache.tools.ant.types.Path) BuildException(org.apache.tools.ant.BuildException) IOException(java.io.IOException) File(java.io.File) BuildException(org.apache.tools.ant.BuildException) IOException(java.io.IOException)

Example 2 with Path

use of org.apache.tools.ant.types.Path in project groovy by apache.

the class Groovydoc method execute.

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() : "");
    properties.setProperty("charset", charset != null ? charset : "");
    properties.setProperty("fileEncoding", fileEncoding != null ? fileEncoding : "");
    properties.setProperty("timestamp", Boolean.valueOf(!noTimestamp).toString());
    properties.setProperty("versionStamp", Boolean.valueOf(!noVersionStamp).toString());
    if (sourcePath != null) {
        sourceDirs.addExisting(sourcePath);
    }
    parsePackages(packagesToDoc, sourceDirs);
    GroovyDocTool htmlTool = new GroovyDocTool(// we're gonna get the default templates out of the dist jar file
    new ClasspathResourceManager(), sourcePath.list(), getDocTemplates(), getPackageTemplates(), getClassTemplates(), links, properties);
    try {
        htmlTool.add(sourceFilesToDoc);
        FileOutputTool output = new FileOutputTool();
        // TODO push destDir through APIs?
        htmlTool.renderToOutput(output, destDir.getCanonicalPath());
    } catch (Exception e) {
        e.printStackTrace();
    }
    // try to override the default stylesheet with custom specified one if needed
    if (styleSheetFile != null) {
        try {
            String css = ResourceGroovyMethods.getText(styleSheetFile);
            File outfile = new File(destDir, "stylesheet.css");
            ResourceGroovyMethods.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());
        }
    }
}
Also used : Path(org.apache.tools.ant.types.Path) FileOutputTool(org.codehaus.groovy.tools.groovydoc.FileOutputTool) ClasspathResourceManager(org.codehaus.groovy.tools.groovydoc.ClasspathResourceManager) GroovyDocTool(org.codehaus.groovy.tools.groovydoc.GroovyDocTool) IOException(java.io.IOException) File(java.io.File) BuildException(org.apache.tools.ant.BuildException) IOException(java.io.IOException)

Example 3 with Path

use of org.apache.tools.ant.types.Path in project groovy by apache.

the class Groovy method createClasspathParts.

private void createClasspathParts() {
    Path path;
    if (classpath != null) {
        path = super.createClasspath();
        path.setPath(classpath.toString());
    }
    if (includeAntRuntime) {
        path = super.createClasspath();
        path.setPath(System.getProperty("java.class.path"));
    }
    String groovyHome = null;
    final String[] strings = getSysProperties().getVariables();
    if (strings != null) {
        for (String prop : strings) {
            if (prop.startsWith("-Dgroovy.home=")) {
                groovyHome = prop.substring("-Dgroovy.home=".length());
            }
        }
    }
    if (groovyHome == null) {
        groovyHome = System.getProperty("groovy.home");
    }
    if (groovyHome == null) {
        groovyHome = System.getenv("GROOVY_HOME");
    }
    if (groovyHome == null) {
        throw new IllegalStateException("Neither ${groovy.home} nor GROOVY_HOME defined.");
    }
    File jarDir = new File(groovyHome, "embeddable");
    if (!jarDir.exists()) {
        throw new IllegalStateException("GROOVY_HOME incorrectly defined. No embeddable directory found in: " + groovyHome);
    }
    final File[] files = jarDir.listFiles();
    for (File file : files) {
        try {
            log.debug("Adding jar to classpath: " + file.getCanonicalPath());
        } catch (IOException e) {
        // ignore
        }
        path = super.createClasspath();
        path.setLocation(file);
    }
}
Also used : Path(org.apache.tools.ant.types.Path) IOException(java.io.IOException) File(java.io.File)

Example 4 with Path

use of org.apache.tools.ant.types.Path in project groovy by apache.

the class Groovyc method compile.

protected void compile() {
    if (compileList.length == 0)
        return;
    try {
        log.info("Compiling " + compileList.length + " source file" + (compileList.length == 1 ? "" : "s") + (destDir != null ? " to " + destDir : ""));
        listFiles();
        Path classpath = getClasspath() != null ? getClasspath() : new Path(getProject());
        List<String> jointOptions = extractJointOptions(classpath);
        String separator = System.getProperty("file.separator");
        List<String> commandLineList = new ArrayList<String>();
        doForkCommandLineList(commandLineList, classpath, separator);
        doNormalCommandLineList(commandLineList, jointOptions, classpath);
        addSourceFiles(commandLineList);
        String[] commandLine = makeCommandLine(commandLineList);
        if (fork) {
            runForked(commandLine);
        } else {
            runCompiler(commandLine);
        }
    } finally {
        for (File temporaryFile : temporaryFiles) {
            try {
                FileSystemCompiler.deleteRecursive(temporaryFile);
            } catch (Throwable t) {
                System.err.println("error: could not delete temp files - " + temporaryFile.getPath());
            }
        }
    }
}
Also used : Path(org.apache.tools.ant.types.Path) ArrayList(java.util.ArrayList) File(java.io.File)

Example 5 with Path

use of org.apache.tools.ant.types.Path in project groovy by apache.

the class CompileTaskSupport method createClassLoader.

protected GroovyClassLoader createClassLoader() {
    ClassLoader parent = ClassLoader.getSystemClassLoader();
    GroovyClassLoader gcl = new GroovyClassLoader(parent, config);
    Path path = getClasspath();
    if (path != null) {
        final String[] filePaths = path.list();
        for (int i = 0; i < filePaths.length; i++) {
            String filePath = filePaths[i];
            gcl.addClasspath(filePath);
        }
    }
    return gcl;
}
Also used : GroovyClassLoader(groovy.lang.GroovyClassLoader) Path(org.apache.tools.ant.types.Path) GroovyClassLoader(groovy.lang.GroovyClassLoader)

Aggregations

Path (org.apache.tools.ant.types.Path)174 File (java.io.File)78 BuildException (org.apache.tools.ant.BuildException)55 Test (org.junit.Test)49 Project (org.apache.tools.ant.Project)28 IOException (java.io.IOException)24 Commandline (org.apache.tools.ant.types.Commandline)21 ArrayList (java.util.ArrayList)12 DirectoryScanner (org.apache.tools.ant.DirectoryScanner)10 URL (java.net.URL)8 AntClassLoader (org.apache.tools.ant.AntClassLoader)7 Java (org.apache.tools.ant.taskdefs.Java)7 StringTokenizer (java.util.StringTokenizer)6 FileSet (org.apache.tools.ant.types.FileSet)6 Reference (org.apache.tools.ant.types.Reference)6 Resource (org.apache.tools.ant.types.Resource)6 Test (org.junit.jupiter.api.Test)6 GroovyClassLoader (groovy.lang.GroovyClassLoader)5 Enumeration (java.util.Enumeration)5 Vector (java.util.Vector)5