Java Code Examples for org.apache.tools.ant.Project#setUserProperty()

The following examples show how to use org.apache.tools.ant.Project#setUserProperty() . 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: ShuffleModel.java    From Shuffle-Move with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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 2
Source File: AntHarnessTest.java    From ExpectIt with Apache License 2.0 6 votes vote down vote up
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 3
Source File: XtendCompilerAntTaskTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * 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: MyBuildFileRule.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
/**
 * 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 5
Source File: Main.java    From scava with Eclipse Public License 2.0 4 votes vote down vote up
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 6
Source File: PackagerCacheEntry.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
/**
 * 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 7
Source File: AntCallTriggerTest.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
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);
        }
    }