/** * Resolve the file relative to the project's basedir and return it as a * FileResource. * @param name the name of the file to resolve. * @return the file resource. * @since Ant 1.7 */ @Override public Resource getResource(final String name) { return new FileResource(getBaseDir(), name); } }
private String getDefaultOutputDirectory() { return getProject().getBaseDir().getAbsolutePath().replace('\\', '/'); }
/** * Set the file which must be present in the file system to set the given * property. * * @param file the name of the file which is required. */ public void setFile(File file) { this.file = file; this.filename = FILE_UTILS.removeLeadingPath(getProject().getBaseDir(), file); }
/** * Let project resolve the file - or do it ourselves if * rootDirectory has been set. */ private File resolveFile(String fileName) { return FILE_UTILS.resolveFile(rootDirectory == null ? getProject().getBaseDir() : rootDirectory, fileName); }
/** * Resolve a filename with Project's help - if we know one that is. */ private static File resolveFile(Project project, String relativeName) { return FileUtils.getFileUtils().resolveFile( (project == null) ? null : project.getBaseDir(), relativeName); }
/** * Set the working dir of the new process. * @param exe executable. * @throws BuildException if the dir doesn't exist. */ private void setupWorkingDir(Execute exe) { if (dir == null) { dir = getProject().getBaseDir(); } else if (!dir.isDirectory()) { throw new BuildException(dir.getAbsolutePath() + " is not a valid directory", getLocation()); } exe.setWorkingDirectory(dir); }
@Before public void setUp() throws IOException { validatePostConstruct(); // initialize Ant buildRule.configureProject(pathToTestScript + separator + antTestScriptFilename); // Each test case gets one temp file name, accessible with ${tmpfile} final File newFile = tempFolder.newFile(); newFile.delete(); // It shouldn't exist yet, but we want a unique name buildRule.getProject().setProperty("tmpfile", newFile.getAbsolutePath()); Project project = buildRule.getProject(); if (!project.getBaseDir().toString().endsWith(mvnWorkaround)) { // when running from maven, the path needs to be adapted... // FIXME: this is more a workaround than a good solution... project.setBasedir(project.getBaseDir().toString() + separator + pathToTestScript); } }
private void collectFileListFromModulePath() { final FileUtils fu = FileUtils.getFileUtils(); for (String pathElement : moduleSourcepath.list()) { boolean valid = false; for (Map.Entry<String, Collection<File>> modules : resolveModuleSourcePathElement( getProject().getBaseDir(), pathElement).entrySet()) { final String moduleName = modules.getKey(); for (File srcDir : modules.getValue()) { if (srcDir.exists()) { valid = true; final DirectoryScanner ds = getDirectoryScanner(srcDir); final String[] files = ds.getIncludedFiles(); scanDir(srcDir, fu.resolveFile(destDir, moduleName), files); } } } if (!valid) { throw new BuildException("modulesourcepath \"" + pathElement + "\" does not exist!", getLocation()); } } }
/** * {@inheritDoc} * * @param event An event with any relevant extra information. Must not be <code>null</code>. */ public void subBuildStarted(BuildEvent event) { Project project = event.getProject(); String path = (project == null) ? "With no base directory" : "In " + project.getBaseDir().getAbsolutePath(); printMessage(String.format("%n%s%nEntering project %s%n%s%n%s", getHeader(), extractNameOrDefault(event), path, getFooter()), out, event.getPriority()); }
private ResourceLoader setupResourceLoader() { if (classpath == null) { classpath = new Path(project); } /* * 'basedir' is added to the path to make sure that relative paths such * as "<ruleset>resources/custom_ruleset.xml</ruleset>" still work when * ant is invoked from a different directory using "-f" */ classpath.add(new Path(null, project.getBaseDir().toString())); project.log("Using the AntClassLoader: " + classpath, Project.MSG_VERBOSE); // must be true, otherwise you'll get ClassCastExceptions as classes // are loaded twice // and exist in multiple class loaders final boolean parentFirst = true; return new ResourceLoader(new AntClassLoader(Thread.currentThread().getContextClassLoader(), project, classpath, parentFirst)); }
/** * @return Factory method to create new Project instances */ @SuppressWarnings("unchecked") protected static Project createAntProject() { final Project project = new Project(); final ProjectHelper helper = ProjectHelper.getProjectHelper(); project.addReference(ProjectHelper.PROJECTHELPER_REFERENCE, helper); helper.getImportStack().addElement("AntBuilder"); // import checks that stack is not empty addMicronautConsoleBuildListener(project); project.init(); project.getBaseDir(); return project; }
/** * Evaluate the selector with the file. * @return true if the file is selected by the embedded selector. */ public boolean eval() { if (file == null) { throw new BuildException("file attribute not set"); } validate(); File myBaseDir = baseDir; if (myBaseDir == null) { myBaseDir = getProject().getBaseDir(); } FileSelector f = getSelectors(getProject())[0]; return f.isSelected( myBaseDir, FILE_UTILS.removeLeadingPath(myBaseDir, file), file); } }
@Override public void execute() { this.log("Scanning all template files from " + this.templateDirectory); final boolean[] error = new boolean[1]; GsCollectionsCodeGenerator.ErrorListener errorListener = new GsCollectionsCodeGenerator.ErrorListener() { public void error(String string) { GsCollectionsCodeGeneratorTask.this.log(string, LogLevel.ERR.getLevel()); error[0] = true; } }; GsCollectionsCodeGenerator gsCollectionsCodeGenerator = new GsCollectionsCodeGenerator(this.templateDirectory, this.getProject().getBaseDir(), this.getClassPathURLs(), errorListener); int numFilesWritten = gsCollectionsCodeGenerator.generateFiles(); this.log("Generated " + numFilesWritten + " files."); if (error[0]) { throw new BuildException("Error(s) during code generation."); } }
/** * Run the command. * @param cmd the command line to use. * @param out the output stream handler to use. * @return the exit code of the command. */ protected int runCmd(Commandline cmd, ExecuteStreamHandler out) { try { Project aProj = getProject(); Execute exe = new Execute(out); exe.setAntRun(aProj); exe.setWorkingDirectory(aProj.getBaseDir()); exe.setCommandline(cmd.getCommandline()); return exe.execute(); } catch (IOException e) { String msg = "Failed executing: " + cmd.toString() + ". Exception: " + e.getMessage(); throw new BuildException(msg, getLocation()); } }
/** * @return Factory method to create new Project instances */ protected static Project createProject() { final Project project = new Project(); final ProjectHelper helper = ProjectHelper.getProjectHelper(); project.addReference(ProjectHelper.PROJECTHELPER_REFERENCE, helper); helper.getImportStack().addElement("AntBuilder"); // import checks that stack is not empty final BuildLogger logger = new NoBannerLogger(); logger.setMessageOutputLevel(org.apache.tools.ant.Project.MSG_INFO); logger.setOutputPrintStream(System.out); logger.setErrorPrintStream(System.err); project.addBuildListener(logger); project.init(); project.getBaseDir(); return project; }
/** * Run the command. * @param cmd the command line * @param handler an execute stream handler * @return the exit status of the command */ protected int run(Commandline cmd, ExecuteStreamHandler handler) { try { Execute exe = new Execute(handler); exe.setAntRun(getProject()); exe.setWorkingDirectory(getProject().getBaseDir()); exe.setCommandline(cmd.getCommandline()); return exe.execute(); } catch (IOException e) { throw new BuildException(e, getLocation()); } }
private void runForked(String[] commandLine) { final Execute executor = new Execute(); executor.setAntRun(getProject()); executor.setWorkingDirectory(getProject().getBaseDir()); executor.setCommandline(commandLine); try { executor.execute(); } catch (final IOException ioe) { throw new BuildException("Error running forked groovyc.", ioe); } final int returnCode = executor.getExitValue(); if (returnCode != 0) { taskSuccess = false; if (errorProperty != null) { getProject().setNewProperty(errorProperty, "true"); } if (failOnError) { throw new BuildException("Forked groovyc returned error code: " + returnCode); } else { log.error("Forked groovyc returned error code: " + returnCode); } } }
/** * Get the execute object. * @param toExecute the command line to use. * @param streamhandler the stream handler to use. * @return the execute object. * @since Ant 1.6.3 */ protected Execute getExecute(Commandline toExecute, ExecuteStreamHandler streamhandler) { Execute exe = new Execute(streamhandler, null); exe.setAntRun(getProject()); if (topDir == null) { topDir = getProject().getBaseDir(); } exe.setWorkingDirectory(topDir); exe.setCommandline(toExecute.getCommandline()); return exe; } }
/** * Execute the given command are return success or failure * @param cmd command line to execute * @return the exit status of the subprocess or <code>INVALID</code> */ protected int run(Commandline cmd) { try { Project aProj = getProject(); Execute exe = new Execute( new LogStreamHandler(this, Project.MSG_INFO, Project.MSG_WARN)); exe.setAntRun(aProj); exe.setWorkingDirectory(aProj.getBaseDir()); exe.setCommandline(cmd.getCommandline()); return exe.execute(); } catch (IOException e) { throw new BuildException(e, getLocation()); } }
/** * Execute the created command line. * * @param cmd The command line to run. * @return int the exit code. * @throws BuildException if something goes wrong */ protected int run(Commandline cmd) { try { Execute exe = new Execute(new LogStreamHandler(this, Project.MSG_INFO, Project.MSG_WARN)); exe.setAntRun(getProject()); exe.setWorkingDirectory(getProject().getBaseDir()); exe.setCommandline(cmd.getCommandline()); exe.setVMLauncher(false); // Use the OS VM launcher so we get environment variables return exe.execute(); } catch (java.io.IOException e) { throw new BuildException(e, getLocation()); } }