/** * Initializes default class loader. It inherits from classloader, which was used to load this * task, therefore build-in classes and resources are loaded automatically. * * <p>Notice: task's classpath has priority over default classpath, therefore we are able to * easily override resources (templates) */ protected void initClassloader() { // NOTICE: we should use the same classloader, which was used to load this task // otherwise we won't be able to cast instances // (that were loaded via different class loaders) // we are introducting workaround, // that tries to add classpath for current task to original class loader // and stores original classpath // after the task is executed, classpath is restored ClassLoader classLoader = getClass().getClassLoader(); if (classLoader instanceof AntClassLoader) { // add defined classpath AntClassLoader antClassLoader = (AntClassLoader) classLoader; antClassLoader.setParentFirst(false); antClassLoader.setProject(getProject()); savedClasspath = antClassLoader.getClasspath(); Path cp = getClasspath(); // add defined classpath to original path cp.add(new Path(getProject(), savedClasspath)); antClassLoader.setClassPath(cp); } else { // create new class loader classLoader = new AntClassLoader(getClass().getClassLoader(), getProject(), getClasspath(), false); } // set this class loader as new class loader for whole thread // ContextClassLoader is used in StringTemplate's PathGroupLoader and other classes Thread.currentThread().setContextClassLoader(classLoader); }
protected void addToPath(Path path, File f) throws Exception { if (!osgi || !f.isDirectory()) { path.createPathElement().setLocation(f); return; } File manifest = new File(f, "META-INF/MANIFEST.MF"); if (!manifest.exists()) { path.createPathElement().setLocation(f); return; } BundleInfo bundleInfo = ManifestParser.parseManifest(manifest); List /* <String> */ cp = bundleInfo.getClasspath(); if (cp == null) { path.createPathElement().setLocation(f); return; } for (int i = 0; i < cp.size(); i++) { String p = (String) cp.get(i); if (p.equals(".")) { path.createPathElement().setLocation(f); } else { path.createPathElement().setLocation(new File(f, p)); } } }
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 : ""); 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 = 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()); } } }
/** * Get the classpath for dependency checking. * * <p>This method removes the dest dirs if it is given from the dependency classpath */ private Path getCheckClassPath() { if (dependClasspath == null) { return null; } String[] destPathElements = destPath.list(); String[] classpathElements = dependClasspath.list(); String checkPath = ""; for (int i = 0; i < classpathElements.length; ++i) { String element = classpathElements[i]; boolean inDestPath = false; for (int j = 0; j < destPathElements.length && !inDestPath; ++j) { inDestPath = destPathElements[j].equals(element); } if (!inDestPath) { if (checkPath.length() == 0) { checkPath = element; } else { checkPath += ":" + element; } } } if (checkPath.length() == 0) { return null; } return new Path(getProject(), checkPath); }
/** * Adds a nested path * * @param path a <code>Path</code> to be added to the path * @throws BuildException on error * @since Ant 1.6 */ public void add(Path path) throws BuildException { if (path == this) { throw circularReference(); } if (path.getProject() == null) { path.setProject(getProject()); } add((ResourceCollection) path); }
/** * Clone this Path. * * @return Path with shallowly cloned Resource children. */ public Object clone() { try { Path result = (Path) super.clone(); result.union = union == null ? union : (Union) union.clone(); return result; } catch (CloneNotSupportedException e) { throw new BuildException(e); } }
/** {@inheritDoc} */ public final Path convertToPath(File[] entries) { Assure.notNull("entries", entries); Path antPath = new Path(getAntProject()); for (File entry : entries) { // TODO getPath() vs. getAbsolutePath() antPath.append(new Path(getAntProject(), entry.getPath())); } return antPath; }
/** * Test the layout of a directory against the sieve. * * @param dir the directory to test * @return true if the directory structure matches the sieve's configuration. */ public boolean matches(File dir) { for (String str : includes) { File f = new File(dir, Path.translateFile(str)); if (!f.exists()) return false; } for (String str : excludes) { File f = new File(dir, Path.translateFile(str)); if (f.exists()) return false; } return true; }
public void setClasspath(String value) { Path p = (Path) getProject().getReference(value); if (p == null) addAll(classpath, value, File.pathSeparator + ","); else { String[] path = p.list(); for (int i = 0; i < path.length; i++) { File f = new File(path[i]); if (f.exists()) classpath.add(f); else messages.NoSuchFile_(f.getAbsoluteFile()); } } classpathDirectlySet = true; }
public void setClassPath(final Path classpath) { this.pathComponents.removeAllElements(); if (classpath != null) { final Path actualClasspath = classpath.concatSystemClasspath("ignore"); final String[] pathElements = actualClasspath.list(); for (int i = 0; i < pathElements.length; ++i) { try { this.addPathElement(pathElements[i]); } catch (BuildException ex) { } } } }
@Override public boolean matches(final Object argument) { final Path argPath = (Path) argument; final String[] paths = argPath.toString().split(File.pathSeparator); final boolean matches = paths.length == this.expectedPaths.length; if (matches) { for (final String expectedPathElement : this.expectedPaths) { if (isNotPresent(paths, expectedPathElement)) { return false; } } } return matches; }
private void addSourcePath(Resource resource, Javadoc javadoc, Path source) { // // handle the target resource // if (null != resource.getBaseDir()) { File src = new File(resource.getBaseDir(), "target/build/main"); if (src.exists()) { log("Adding src path: " + src); source.createPathElement().setLocation(src); final DirSet packages = new DirSet(); packages.setDir(src); packages.setIncludes("**/*"); String excludes = getPackageExcludes(resource); if (null != excludes) { packages.setExcludes(excludes); } javadoc.addPackageset(packages); } } // add providers String path = resource.getResourcePath(); Resource[] providers = resource.getAggregatedProviders(Scope.RUNTIME, true, false); for (int i = 0; i < providers.length; i++) { Resource provider = providers[i]; if (provider.getResourcePath().startsWith(path)) { String flag = provider.getProperty("project.javadoc.exclude", "false"); if ("false".equals(flag)) { File basedir = provider.getBaseDir(); if (null != basedir) { File src = new File(basedir, "target/build/main"); if (src.exists()) { log("Adding src path: " + src); source.createPathElement().setLocation(src); final DirSet packages = new DirSet(); packages.setDir(src); packages.setIncludes("**/**"); String excludes = getPackageExcludes(provider); if (null != excludes) { packages.setExcludes(excludes); } javadoc.addPackageset(packages); } } } } } }
private void doForkCommandLineList( List<String> commandLineList, Path classpath, String separator) { if (!fork) return; if (includeAntRuntime) { classpath.addExisting((new Path(getProject())).concatSystemClasspath("last")); } if (includeJavaRuntime) { classpath.addJavaRuntime(); } if (forkedExecutable != null && !forkedExecutable.equals("")) { commandLineList.add(forkedExecutable); } else { String javaHome; if (forkJavaHome != null) { javaHome = forkJavaHome.getPath(); } else { javaHome = System.getProperty("java.home"); } commandLineList.add(javaHome + separator + "bin" + separator + "java"); } commandLineList.add("-classpath"); commandLineList.add(classpath.toString()); final String fileEncodingProp = System.getProperty("file.encoding"); if ((fileEncodingProp != null) && !fileEncodingProp.equals("")) { commandLineList.add("-Dfile.encoding=" + fileEncodingProp); } if (targetBytecode != null) { commandLineList.add("-Dgroovy.target.bytecode=" + targetBytecode); } if ((memoryInitialSize != null) && !memoryInitialSize.equals("")) { commandLineList.add("-Xms" + memoryInitialSize); } if ((memoryMaximumSize != null) && !memoryMaximumSize.equals("")) { commandLineList.add("-Xmx" + memoryMaximumSize); } if (!"*.groovy".equals(getScriptExtension())) { String tmpExtension = getScriptExtension(); if (tmpExtension.startsWith("*.")) tmpExtension = tmpExtension.substring(1); commandLineList.add("-Dgroovy.default.scriptExtension=" + tmpExtension); } commandLineList.add(FileSystemCompilerFacade.class.getName()); if (forceLookupUnnamedFiles) { commandLineList.add("--forceLookupUnnamedFiles"); } }
public org.apache.tools.ant.types.Path toAntPath(List artifacts) { org.apache.tools.ant.types.Path path = new org.apache.tools.ant.types.Path(antProject); for (Iterator i = artifacts.iterator(); i.hasNext(); ) { RepoArtifact artifact = (RepoArtifact) i.next(); if (artifact.getLocalCopy() != null) { // Possible for "paths" type path.add( new org.apache.tools.ant.types.Path( antProject, artifact.getLocalCopy().getAbsolutePath())); } } return path; }
/** * Adds a path for decompilation source. * * @return source path */ public Path createSrc() { if (src == null) { src = new Path(getProject()); } return src.createPath(); }
/** Scans the source directories looking for source files to be decompiled. */ protected void scanSrc() throws BuildException { for (@SuppressWarnings("unchecked") Iterator<Resource> it = src.iterator(); it.hasNext(); ) { Resource resource = it.next(); FileResource fileResource = resource instanceof FileResource ? (FileResource) resource : null; if (fileResource != null) { File file = fileResource.getFile(); if (file.isDirectory()) { DirectoryScanner ds = getDirectoryScanner(file); String[] files = ds.getIncludedFiles(); scanDir(file, destdir != null ? destdir : file, files); } else { String[] files = new String[] {fileResource.getName()}; scanDir( fileResource.getBaseDir(), destdir != null ? destdir : fileResource.getBaseDir(), files); } } // else // { // //FIXME what to do? // } } }
/** * Sets the source directories to find the compiled report design files. * * @param srcdir source path */ public void setSrcdir(Path srcdir) { if (src == null) { src = srcdir; } else { src.append(srcdir); } }
/** * Specify where to find source file * * @param src a Path instance containing the various source directories. */ public void setSourcepath(Path src) { if (sourcePath == null) { sourcePath = src; } else { sourcePath.append(src); } }
/** * Adds a path to the classpath. * * @return classpath to use when decompiling the report */ public Path createClasspath() { if (classpath == null) { classpath = new Path(getProject()); } return classpath.createPath(); }
@Override public void execute() throws BuildException { if (classpath == null) { throw new BuildException("The classpath is not defined"); } if (wadlFile == null) { throw new BuildException("destfile attribute required", getLocation()); } if (baseUri == null || baseUri.length() == 0) { throw new BuildException("baseUri attribute required", getLocation()); } try { Application a = createApplication(classpath.list()); a.getResources().setBase(baseUri); JAXBContext c = JAXBContext.newInstance("com.sun.research.ws.wadl", this.getClass().getClassLoader()); Marshaller m = c.createMarshaller(); OutputStream out = new BufferedOutputStream(new FileOutputStream(wadlFile)); m.marshal(a, out); out.close(); } catch (Exception e) { throw new BuildException(e); } }
/** * Set the classpath to be used for this dependency check. * * @param classpath the classpath to be used when checking for dependencies on elements in the * classpath */ public void setClasspath(Path classpath) { if (dependClasspath == null) { dependClasspath = classpath; } else { dependClasspath.append(classpath); } }
/** * Set the classpath to be used for this compilation. * * @param classpath an Ant Path object containing the compilation classpath. */ public void setClasspath(Path classpath) { if (compileClasspath == null) { compileClasspath = classpath; } else { compileClasspath.append(classpath); } }
/** * Executes the task. * * @throws BuildException if an error occurs */ public void execute() throws BuildException { checkParameters(); resetFileLists(); loadRegisteredScriptExtensions(); if (javac != null) jointCompilation = true; // scan source directories and dest directory to build up // compile lists String[] list = src.list(); for (String filename : list) { File file = getProject().resolveFile(filename); if (!file.exists()) { throw new BuildException( "srcdir \"" + file.getPath() + "\" does not exist!", getLocation()); } DirectoryScanner ds = this.getDirectoryScanner(file); String[] files = ds.getIncludedFiles(); scanDir(file, destDir != null ? destDir : file, files); } compile(); if (updatedProperty != null && taskSuccess && compileList.length != 0) { getProject().setNewProperty(updatedProperty, "true"); } }
private void loadRegisteredScriptExtensions() { if (scriptExtensions.isEmpty()) { scriptExtensions.add( getScriptExtension() .substring(2)); // first extension will be the one set explicitly on <groovyc> Path classpath = getClasspath() != null ? getClasspath() : new Path(getProject()); final String[] pe = classpath.list(); final GroovyClassLoader loader = new GroovyClassLoader(getClass().getClassLoader()); for (String file : pe) { loader.addClasspath(file); } scriptExtensions.addAll(SourceExtensionHandler.getRegisteredExtensions(loader)); } }
/** * Set the sourcepath to be used for this compilation. * * @param sourcepath the source path */ public void setSourcepath(Path sourcepath) { if (compileSourcepath == null) { compileSourcepath = sourcepath; } else { compileSourcepath.append(sourcepath); } }
/** * Add "groovyc" parameters to the commandLineList, based on the ant configuration. * * @param commandLineList * @param jointOptions * @param classpath */ private void doNormalCommandLineList( List<String> commandLineList, List<String> jointOptions, Path classpath) { commandLineList.add("--classpath"); commandLineList.add(classpath.toString()); if (jointCompilation) { commandLineList.add("-j"); commandLineList.addAll(jointOptions); } if (destDir != null) { commandLineList.add("-d"); commandLineList.add(destDir.getPath()); } if (encoding != null) { commandLineList.add("--encoding"); commandLineList.add(encoding); } if (stacktrace) { commandLineList.add("-e"); } if (parameters) { commandLineList.add("--parameters"); } if (useIndy) { commandLineList.add("--indy"); } if (scriptBaseClass != null) { commandLineList.add("-b"); commandLineList.add(scriptBaseClass); } if (configscript != null) { commandLineList.add("--configscript"); commandLineList.add(configscript); } }
private void addFilesFrom(Path path, List<File> files) { for (String fileName : path.list()) { File f = new File(fileName.replace('\\', '/')); if (f.exists()) files.add(f); else messages.NoSuchFile_(f.getAbsoluteFile()); } }
/** * Support nested <code>classpath</code> elements * * @return */ public Path createClasspath() { // return this.cpDelegate.createClasspath(); if (classpath == null) { classpath = new Path(this.getProject()); } return classpath.createPath(); }
/** * Add a source path to the source path used by this analyzer. The elements in the given path * contain the source files for the classes being analyzed. Not all analyzers will use this * information. * * @param sourcePath The Path instance specifying the source path elements. */ public void addSourcePath(Path sourcePath) { if (sourcePath == null) { return; } this.sourcePath.append(sourcePath); this.sourcePath.setProject(sourcePath.getProject()); }
/** * Same as addExisting, but support classpath behavior if tryUserDir is true. Classpaths are * relative to user dir, not the project base. That used to break jspc test * * @param source the source path * @param tryUserDir if true try the user directory if the file is not present */ public void addExisting(Path source, boolean tryUserDir) { String[] list = source.list(); File userDir = (tryUserDir) ? new File(System.getProperty("user.dir")) : null; for (int i = 0; i < list.length; i++) { File f = resolveFile(getProject(), list[i]); // probably not the best choice, but it solves the problem of // relative paths in CLASSPATH if (tryUserDir && !f.exists()) { f = new File(userDir, list[i]); } if (f.exists()) { setLocation(f); } else if (f.getParentFile() != null && f.getParentFile().exists() && containsWildcards(f.getName())) { setLocation(f); log( "adding " + f + " which contains wildcards and may not" + " do what you intend it to do depending on your OS or" + " version of Java", Project.MSG_VERBOSE); } else { log("dropping " + f + " from path as it doesn't exist", Project.MSG_VERBOSE); } } }