org.apache.tools.ant.ProjectHelper Java Examples
The following examples show how to use
org.apache.tools.ant.ProjectHelper.
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: AntHarnessTest.java From ExpectIt with Apache License 2.0 | 6 votes |
private static Project newProject() throws IOException { setupBuildFile(); Project project = new Project(); project.setUserProperty("ant.file", buildFile.getAbsolutePath()); project.init(); DefaultLogger listener = new DefaultLogger(); listener.setErrorPrintStream(System.err); listener.setOutputPrintStream(System.out); listener.setMessageOutputLevel(Project.MSG_INFO); ProjectHelper helper = ProjectHelper.getProjectHelper(); project.addReference("ant.projectHelper", helper); project.setProperty("ftp.port", String.valueOf(ftpPort)); project.setProperty("ssh.port", String.valueOf(sshPort)); helper.parse(project, buildFile); project.addBuildListener(listener); return project; }
Example #2
Source File: ShuffleModel.java From Shuffle-Move with GNU General Public License v3.0 | 6 votes |
/** * Constructs the Project and returns it. * * @return The Project * @throws Exception * If anything goes wrong. */ private Project getErrorProject() throws Exception { Path buildFilePath = Paths.get(BUILD_REPORT_FILE); LOG.finer("Build file path set to " + String.valueOf(buildFilePath)); Project p = new Project(); p.setSystemProperties(); p.setUserProperty("ant.file", buildFilePath.toAbsolutePath().toString()); LOG.finer("Project ant.file property set."); p.init(); LOG.finer("Project.init() called."); ProjectHelper helper = ProjectHelper.getProjectHelper(); LOG.finer("ProjectHelper created."); p.addReference("ant.projectHelper", helper); LOG.finer("Project ant.projectHelper reference set."); p.addReference("user.dir", System.getProperty("user.dir")); LOG.finer("Project user.dir reference set."); helper.parse(p, buildFilePath.toAbsolutePath().toFile()); LOG.finer("PrjectHelper.parse() called."); errorProject = p; p.addBuildListener(getBuildListener()); LOG.finer("BuildListener added."); return errorProject; }
Example #3
Source File: AntBuilder.java From groovy with Apache License 2.0 | 6 votes |
/** * @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; }
Example #4
Source File: GroovycTest.java From groovy with Apache License 2.0 | 6 votes |
protected void setUp() { project = new Project(); project.init(); ProjectHelper.getProjectHelper().parse(project, antFile); project.executeTarget("clean"); String altJavaHome = System.getProperty("java.home"); if (altJavaHome.lastIndexOf("jre") >= 0) { altJavaHome = altJavaHome.substring(0, altJavaHome.lastIndexOf("jre")); } else { altJavaHome = altJavaHome + File.separator + "jre"; } try { File altFile = new File(altJavaHome); if (altFile.exists()) { project.setProperty("alt.java.home", altJavaHome); } } catch (Exception ignore) { // could be security, io, etc. // End result is as if .exists() returned null } }
Example #5
Source File: AntUtil.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
/** * @return Factory method to create new Project instances */ public 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 project.addBuildListener(new AntLoggingAdapter()); project.init(); project.getBaseDir(); return project; }
Example #6
Source File: AntRunner.java From spoofax with Apache License 2.0 | 5 votes |
public AntRunner(IResourceService resourceService, FileObject antFile, FileObject baseDir, Map<String, String> properties, @SuppressWarnings("unused") @Nullable URL[] classpaths, @Nullable BuildListener listener) { this.antProject = new Project(); final File localAntFile = resourceService.localFile(antFile); final File localBaseDir = resourceService.localPath(baseDir); // TODO: use classpaths antProject.setProperty(MagicNames.ANT_FILE, localAntFile.getPath()); antProject.setBaseDir(localBaseDir); antProject.init(); if(listener != null) { antProject.addBuildListener(listener); } final PropertyHelper propHelper = PropertyHelper.getPropertyHelper(antProject); antProject.addReference(MagicNames.REFID_PROPERTY_HELPER, propHelper); for(Entry<String, String> property : properties.entrySet()) { propHelper.setUserProperty(property.getKey(), property.getValue()); } final ProjectHelper projectHelper = ProjectHelper.getProjectHelper(); antProject.addReference(MagicNames.REFID_PROJECT_HELPER, projectHelper); projectHelper.parse(antProject, localAntFile); }
Example #7
Source File: FileSender.java From iaf with Apache License 2.0 | 5 votes |
private void runAntScript() { Project ant = new Project(); DefaultLogger consoleLogger = new DefaultLogger(); consoleLogger.setErrorPrintStream(System.err); consoleLogger.setOutputPrintStream(System.out); consoleLogger.setMessageOutputLevel(Project.MSG_INFO); ant.addBuildListener(consoleLogger); ant.init(); ProjectHelper helper = new ProjectHelperImpl(); helper.parse(ant, new File(filename)); ant.executeTarget(ant.getDefaultTarget()); }
Example #8
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 #9
Source File: AntUtil.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
/** * @return Factory method to create new Project instances */ public 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 project.addBuildListener(new AntLoggingAdapter()); project.init(); project.getBaseDir(); return project; }
Example #10
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 #11
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 #12
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 #13
Source File: GroovyTest.java From groovy with Apache License 2.0 | 5 votes |
protected void setUp() throws Exception { super.setUp(); project = new Project(); project.init(); ProjectHelper.getProjectHelper().parse(project, antFile); FLAG = null; }
Example #14
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 #15
Source File: AntUtil.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
/** * @return Factory method to create new Project instances */ public 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 project.addBuildListener(new AntLoggingAdapter()); project.init(); project.getBaseDir(); return project; }
Example #16
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 #17
Source File: AntUtil.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
/** * @return Factory method to create new Project instances */ public 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 project.addBuildListener(new AntLoggingAdapter()); project.init(); project.getBaseDir(); return project; }
Example #18
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 #19
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); } }
Example #20
Source File: Main.java From scava with Eclipse Public License 2.0 | 4 votes |
public static void main(String[] args) { Vector<Target> targets = new Vector<Target>(); Target m2mTarget = new Target(); m2mTarget.setName(M2M); Target m2tTarget = new Target(); m2tTarget.setName(M2T); Target setupTarget = new Target(); setupTarget.setName(SETUP); File buildFile = new File(BUILD_XML); Project p = new Project(); p.setUserProperty(ANT_FILE, buildFile.getAbsolutePath()); p.init(); ProjectHelper helper = ProjectHelper.getProjectHelper(); p.addReference(ANT_PROJECT_HELPER, helper); helper.parse(p, buildFile); Scanner scanner = new Scanner(System.in); while (true){ System.out.println("Which transformation would you like to start? (M2M / M2T) : "); String target = scanner.next(); if (target.equals(M2M)){ System.out.println("Select the OpenAPI JSON schema to transform."); try { TimeUnit.MILLISECONDS.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setCurrentDirectory(new File(SCHEMAS_DIR)); chooser.showOpenDialog(null); File selectedFile = chooser.getSelectedFile(); if (selectedFile.isFile() && selectedFile.getName().endsWith(".json")){ System.out.println(selectedFile.getName()); targets.add(m2mTarget); break; } else { chooser = null; System.out.println("Something went wrong"); } //p.executeSortedTargets(targets); } else if (target.equals(M2M)){ //p.executeTarget(p.getDefaultTarget()); break; } else { System.out.println("Invalid"); } } scanner.close(); }
Example #21
Source File: CCGBankConvert.java From openccg with GNU Lesser General Public License v2.1 | 4 votes |
public static void main(String[] args) { File baseDir = new File(System.getProperty("user.dir")); File buildFile = new File(baseDir, "build.xml"); Project project = new Project(); project.init(); project.setBaseDir(baseDir); ProjectHelper helper = ProjectHelper.getProjectHelper(); project.setProjectReference(helper); helper.parse(project, buildFile); DefaultLogger logger = new DefaultLogger(); logger.setErrorPrintStream(System.err); logger.setOutputPrintStream(System.out); project.addBuildListener(logger); project.executeTarget("convert-base"); }