Java Code Examples for org.apache.tools.ant.ProjectHelper#configureProject()
The following examples show how to use
org.apache.tools.ant.ProjectHelper#configureProject() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultAntBuilder.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
public void importBuild(Object antBuildFile, Transformer<? extends String, ? super String> taskNamer) { File file = gradleProject.file(antBuildFile); final File baseDir = file.getParentFile(); Set<String> existingAntTargets = new HashSet<String>(getAntProject().getTargets().keySet()); File oldBaseDir = getAntProject().getBaseDir(); getAntProject().setBaseDir(baseDir); try { getAntProject().setUserProperty(MagicNames.ANT_FILE, file.getAbsolutePath()); ProjectHelper.configureProject(getAntProject(), file); } catch (Exception e) { throw new GradleException("Could not import Ant build file '" + String.valueOf(file) + "'.", e); } finally { getAntProject().setBaseDir(oldBaseDir); } // Chuck away the implicit target. It has already been executed getAntProject().getTargets().remove(""); // Add an adapter for each newly added target Set<String> newAntTargets = new HashSet<String>(getAntProject().getTargets().keySet()); newAntTargets.removeAll(existingAntTargets); for (String name : newAntTargets) { final Target target = getAntProject().getTargets().get(name); String taskName = taskNamer.transform(target.getName()); final AntTarget task = gradleProject.getTasks().create(taskName, AntTarget.class); configureTask(target, task, baseDir, taskNamer); } }
Example 2
Source File: DefaultAntBuilder.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
public void importBuild(Object antBuildFile) { File file = gradleProject.file(antBuildFile); final File baseDir = file.getParentFile(); Set<String> existingAntTargets = new HashSet<String>(getAntProject().getTargets().keySet()); File oldBaseDir = getAntProject().getBaseDir(); getAntProject().setBaseDir(baseDir); try { getAntProject().setUserProperty(MagicNames.ANT_FILE, file.getAbsolutePath()); ProjectHelper.configureProject(getAntProject(), file); } catch (Exception e) { throw new GradleException("Could not import Ant build file '" + String.valueOf(file) + "'.", e); } finally { getAntProject().setBaseDir(oldBaseDir); } // Chuck away the implicit target. It has already been executed getAntProject().getTargets().remove(""); // Add an adapter for each newly added target Set<String> newAntTargets = new HashSet<String>(getAntProject().getTargets().keySet()); newAntTargets.removeAll(existingAntTargets); for (String name : newAntTargets) { Target target = getAntProject().getTargets().get(name); AntTarget task = gradleProject.getTasks().create(target.getName(), AntTarget.class); task.setTarget(target); task.setBaseDir(baseDir); addDependencyOrdering(target.getDependencies()); } }
Example 3
Source File: XtendCompilerAntTaskTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
/** * Sets up to run the named project * * @param filename * name of project file to run */ protected void configureProject(String filename) throws BuildException { project = new Project(); project.init(); File antFile = new File(System.getProperty("root"), filename); File depsFolder = new File(System.getProperty("root"), "target/antDeps"); project.setUserProperty("deps.dir", depsFolder.getAbsolutePath()); project.setUserProperty("ant.file", antFile.getAbsolutePath()); antTestListener = new AntTestListener(Project.MSG_ERR); project.addBuildListener(antTestListener); ProjectHelper.configureProject(project, antFile); }
Example 4
Source File: DefaultAntBuilder.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
public void importBuild(Object antBuildFile, Transformer<? extends String, ? super String> taskNamer) { File file = gradleProject.file(antBuildFile); final File baseDir = file.getParentFile(); Set<String> existingAntTargets = new HashSet<String>(getAntProject().getTargets().keySet()); File oldBaseDir = getAntProject().getBaseDir(); getAntProject().setBaseDir(baseDir); try { getAntProject().setUserProperty(MagicNames.ANT_FILE, file.getAbsolutePath()); ProjectHelper.configureProject(getAntProject(), file); } catch (Exception e) { throw new GradleException("Could not import Ant build file '" + String.valueOf(file) + "'.", e); } finally { getAntProject().setBaseDir(oldBaseDir); } // Chuck away the implicit target. It has already been executed getAntProject().getTargets().remove(""); // Add an adapter for each newly added target Set<String> newAntTargets = new HashSet<String>(getAntProject().getTargets().keySet()); newAntTargets.removeAll(existingAntTargets); for (String name : newAntTargets) { final Target target = getAntProject().getTargets().get(name); String taskName = taskNamer.transform(target.getName()); final AntTarget task = gradleProject.getTasks().create(taskName, AntTarget.class); configureTask(target, task, baseDir, taskNamer); } }
Example 5
Source File: DefaultAntBuilder.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
public void importBuild(Object antBuildFile) { File file = gradleProject.file(antBuildFile); final File baseDir = file.getParentFile(); Set<String> existingAntTargets = new HashSet<String>(getAntProject().getTargets().keySet()); File oldBaseDir = getAntProject().getBaseDir(); getAntProject().setBaseDir(baseDir); try { getAntProject().setUserProperty(MagicNames.ANT_FILE, file.getAbsolutePath()); ProjectHelper.configureProject(getAntProject(), file); } catch (Exception e) { throw new GradleException("Could not import Ant build file '" + String.valueOf(file) + "'.", e); } finally { getAntProject().setBaseDir(oldBaseDir); } // Chuck away the implicit target. It has already been executed getAntProject().getTargets().remove(""); // Add an adapter for each newly added target Set<String> newAntTargets = new HashSet<String>(getAntProject().getTargets().keySet()); newAntTargets.removeAll(existingAntTargets); for (String name : newAntTargets) { Target target = getAntProject().getTargets().get(name); AntTarget task = gradleProject.getTasks().create(target.getName(), AntTarget.class); task.setTarget(target); task.setBaseDir(baseDir); addDependencyOrdering(target.getDependencies()); } }
Example 6
Source File: MyBuildFileRule.java From ph-schematron with Apache License 2.0 | 5 votes |
/** * Sets up to run the named project * * @param filename * name of project file to run * @param logLevel * Log level * @throws BuildException * on error */ public void configureProject (final String filename, final int logLevel) throws BuildException { logBuffer = new StringBuffer (); fullLogBuffer = new StringBuffer (); project = new Project (); project.init (); final File antFile = new File (System.getProperty ("root"), filename); project.setProperty ("ant.processid", ProcessUtil.getProcessId ("<Process>")); project.setProperty ("ant.threadname", Thread.currentThread ().getName ()); project.setUserProperty ("ant.file", antFile.getAbsolutePath ()); project.addBuildListener (new AntTestListener (logLevel)); ProjectHelper.configureProject (project, antFile); }
Example 7
Source File: PackagerCacheEntry.java From ant-ivy with Apache License 2.0 | 4 votes |
/** * Attempt to build this entry. * * @param packagerResource * packager metadata resource * @param properties * a map of properties to pass to the child Ant build responsible for dependency * packaging * * @throws IOException * if this entry has already been built */ public synchronized void build(Resource packagerResource, Map<String, String> properties) throws IOException { // Sanity check if (this.built) { throw new IllegalStateException("build in directory `" + this.dir + "' already completed"); } // Remove work directory if it exists (e.g. left over from last time) if (this.dir.exists()) { if (!cleanup()) { throw new IOException("can't remove directory `" + this.dir + "'"); } } // Create work directory if (!this.dir.mkdirs()) { throw new IOException("can't create directory `" + this.dir + "'"); } // Write out packager XML InputStream packagerXML = packagerResource.openStream(); saveFile("packager.xml", packagerXML); // Write packager XSLT saveFile("packager.xsl"); // Write packager XSD saveFile("packager-1.0.xsd"); // Write master Ant build file saveFile("build.xml"); // Execute the Ant build file Project project = new Project(); project.init(); project.setUserProperty("ant.file", new File(dir, "build.xml").getAbsolutePath()); ProjectHelper.configureProject(project, new File(dir, "build.xml")); project.setBaseDir(dir); // Configure logging verbosity BuildLogger logger = new DefaultLogger(); logger.setMessageOutputLevel(this.verbose ? Project.MSG_VERBOSE : this.quiet ? Project.MSG_WARN : Project.MSG_INFO); logger.setOutputPrintStream(System.out); logger.setErrorPrintStream(System.err); project.addBuildListener(logger); // Set properties project.setUserProperty("ivy.packager.organisation", "" + this.mr.getModuleId().getOrganisation()); project.setUserProperty("ivy.packager.module", "" + this.mr.getModuleId().getName()); project.setUserProperty("ivy.packager.revision", "" + this.mr.getRevision()); project.setUserProperty("ivy.packager.branch", "" + this.mr.getBranch()); if (this.resourceCache != null) { project.setUserProperty("ivy.packager.resourceCache", "" + this.resourceCache.getCanonicalPath()); } if (this.resourceURL != null) { project.setUserProperty("ivy.packager.resourceURL", "" + getResourceURL()); } if (this.validate) { project.setUserProperty("ivy.packager.validate", "true"); } project.setUserProperty("ivy.packager.restricted", "" + this.restricted); project.setUserProperty("ivy.packager.quiet", String.valueOf(quiet)); if (properties != null) { for (Map.Entry<String, String> entry : properties.entrySet()) { project.setUserProperty(entry.getKey(), entry.getValue()); } } // Execute task Message.verbose("performing packager resolver build in " + this.dir); try { project.executeTarget("build"); this.built = true; } catch (BuildException e) { Message.verbose("packager resolver build failed: " + e); throw e; } }
Example 8
Source File: AntCallTriggerTest.java From ant-ivy with Apache License 2.0 | 4 votes |
private void runBuild(File buildFile, Vector<String> targets, int messageLevel) throws BuildException { final Project project = new Project(); project.setCoreLoader(null); Throwable error = null; try { addBuildListeners(project, messageLevel); addInputHandler(project, null); PrintStream err = System.err; PrintStream out = System.out; InputStream in = System.in; // use a system manager that prevents from System.exit() SecurityManager oldsm = null; oldsm = System.getSecurityManager(); // SecurityManager can not be installed here for backwards // compatibility reasons (PD). Needs to be loaded prior to // ant class if we are going to implement it. // System.setSecurityManager(new NoExitSecurityManager()); try { project.setDefaultInputStream(System.in); System.setIn(new DemuxInputStream(project)); System.setOut(new PrintStream(new DemuxOutputStream(project, false))); System.setErr(new PrintStream(new DemuxOutputStream(project, true))); project.fireBuildStarted(); project.init(); project.setUserProperty("ant.version", Main.getAntVersion()); project.setUserProperty("ant.file", buildFile.getAbsolutePath()); ProjectHelper.configureProject(project, buildFile); // make sure that we have a target to execute if (targets.size() == 0 && project.getDefaultTarget() != null) { targets.addElement(project.getDefaultTarget()); } project.executeTargets(targets); } finally { // put back the original security manager // The following will never eval to true. (PD) if (oldsm != null) { System.setSecurityManager(oldsm); } System.setOut(out); System.setErr(err); System.setIn(in); } } catch (RuntimeException | Error exc) { error = exc; throw exc; } finally { project.fireBuildFinished(error); } }