本文整理了Java中org.apache.tools.ant.Project.getBaseDir()
方法的一些代码示例,展示了Project.getBaseDir()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Project.getBaseDir()
方法的具体详情如下:
包路径:org.apache.tools.ant.Project
类名称:Project
方法名:getBaseDir
[英]Return the base directory of the project as a file object.
[中]将项目的基本目录作为文件对象返回。
代码示例来源:origin: org.apache.ant/ant
/**
* 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);
}
}
代码示例来源:origin: org.apache.ant/ant
private String getDefaultOutputDirectory() {
return getProject().getBaseDir().getAbsolutePath().replace('\\', '/');
}
代码示例来源:origin: org.apache.ant/ant
/**
* 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);
}
代码示例来源:origin: org.apache.ant/ant
/**
* 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);
}
代码示例来源:origin: org.apache.ant/ant
/**
* 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);
}
代码示例来源:origin: org.apache.ant/ant
/**
* 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);
}
代码示例来源:origin: pmd/pmd
@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);
}
}
代码示例来源:origin: org.apache.ant/ant
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());
}
}
}
代码示例来源:origin: org.apache.ant/ant
/**
* {@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());
}
代码示例来源:origin: pmd/pmd
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));
}
代码示例来源:origin: micronaut-projects/micronaut-core
/**
* @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;
}
代码示例来源:origin: org.apache.ant/ant
/**
* 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);
}
}
代码示例来源:origin: goldmansachs/gs-collections
@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.");
}
}
代码示例来源:origin: org.apache.ant/ant
/**
* 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());
}
}
代码示例来源:origin: apache/groovy
/**
* @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;
}
代码示例来源:origin: org.apache.ant/ant
/**
* 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());
}
}
代码示例来源:origin: apache/groovy
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);
}
}
}
代码示例来源:origin: org.apache.ant/ant
/**
* 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;
}
}
代码示例来源:origin: org.apache.ant/ant
/**
* 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());
}
}
代码示例来源:origin: org.apache.ant/ant
/**
* 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());
}
}
内容来源于网络,如有侵权,请联系作者删除!