org.apache.tools.ant.Target Java Examples

The following examples show how to use org.apache.tools.ant.Target. 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: BasicAntBuilder.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public BasicAntBuilder() {
    // These are used to discard references to tasks so they can be garbage collected
    Field collectorField;
    try {
        nodeField = AntBuilder.class.getDeclaredField("lastCompletedNode");
        nodeField.setAccessible(true);
        collectorField = AntBuilder.class.getDeclaredField("collectorTarget");
        collectorField.setAccessible(true);
        Target target = (Target) collectorField.get(this);
        Field childrenField = Target.class.getDeclaredField("children");
        childrenField.setAccessible(true);
        children = (List) childrenField.get(target);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    getAntProject().addDataTypeDefinition("gradleFileResource", AntFileResource.class);
    getAntProject().addDataTypeDefinition("gradleBaseDirSelector", BaseDirSelector.class);
}
 
Example #2
Source File: BasicAntBuilder.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public BasicAntBuilder() {
    // These are used to discard references to tasks so they can be garbage collected
    Field collectorField;
    try {
        nodeField = AntBuilder.class.getDeclaredField("lastCompletedNode");
        nodeField.setAccessible(true);
        collectorField = AntBuilder.class.getDeclaredField("collectorTarget");
        collectorField.setAccessible(true);
        Target target = (Target) collectorField.get(this);
        Field childrenField = Target.class.getDeclaredField("children");
        childrenField.setAccessible(true);
        children = (List) childrenField.get(target);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    getAntProject().addDataTypeDefinition("gradleFileResource", AntFileResource.class);
    getAntProject().addDataTypeDefinition("gradleBaseDirSelector", BaseDirSelector.class);
}
 
Example #3
Source File: AntBuilder.java    From groovy with Apache License 2.0 6 votes vote down vote up
private Target onStartTarget(final Attributes attrs, String tagName, String ns) {
    try {
        antTargetHandler.onStartElement(ns, tagName, tagName, attrs, antXmlContext);
        final Target newTarget = getProject().getTargets().get(attrs.getValue("name"));

        // execute dependencies (if any)
        final Vector<Target> targets = new Vector<Target>();
        for (final Enumeration<String> deps = newTarget.getDependencies(); deps.hasMoreElements(); ) {
            final String targetName = deps.nextElement();
            targets.add(project.getTargets().get(targetName));
        }
        getProject().executeSortedTargets(targets);

        antXmlContext.setCurrentTarget(newTarget);
        return newTarget;
    } catch (final SAXParseException e) {
        log.log(Level.SEVERE, "Caught: " + e, e);
        return null;
    }
}
 
Example #4
Source File: AntBuilder.java    From groovy with Apache License 2.0 6 votes vote down vote up
public AntBuilder(final Project project, final Target owningTarget) {
    this.project = project;

    /*
     * GROOVY-4524: The following is not needed anymore as an ant Project already by default has inputhandler
     * set to DefaultInputHandler. And if it is again set here, it mistakenly overrides the custom input handler
     * if set using -inputhandler switch.
     */
    //this.project.setInputHandler(new DefaultInputHandler());

    collectorTarget = owningTarget;
    antXmlContext = new AntXMLContext(project);
    collectorTarget.setProject(project);
    antXmlContext.setCurrentTarget(collectorTarget);
    antXmlContext.setLocator(new AntBuilderLocator());
    antXmlContext.setCurrentTargets(new HashMap<String, Target>());

    implicitTarget = new Target();
    implicitTarget.setProject(project);
    implicitTarget.setName("");
    antXmlContext.setImplicitTarget(implicitTarget);

    // FileScanner is a Groovy utility
    project.addDataTypeDefinition("fileScanner", FileScanner.class);
}
 
Example #5
Source File: BasicAntBuilder.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public BasicAntBuilder() {
    // These are used to discard references to tasks so they can be garbage collected
    Field collectorField;
    try {
        nodeField = AntBuilder.class.getDeclaredField("lastCompletedNode");
        nodeField.setAccessible(true);
        collectorField = AntBuilder.class.getDeclaredField("collectorTarget");
        collectorField.setAccessible(true);
        Target target = (Target) collectorField.get(this);
        Field childrenField = Target.class.getDeclaredField("children");
        childrenField.setAccessible(true);
        children = (List) childrenField.get(target);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    getAntProject().addDataTypeDefinition("gradleFileResource", AntFileResource.class);
    getAntProject().addDataTypeDefinition("gradleBaseDirSelector", BaseDirSelector.class);
}
 
Example #6
Source File: InsertModuleAllTargetsTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testInstallAllTargetWithClusters() {
    
    InsertModuleAllTargets insert = new InsertModuleAllTargets();
    insert.setProject(p);
    
    insert.execute();

    Object obj = p.getTargets().get("all-java.source.queries");
    assertNotNull("Target found", obj);
    Target t = (Target)obj;

    Set<String> s = depsToNames(t.getDependencies());
    assertEquals("Five dependencies: " + s, 5, s.size());
    assertEquals(new HashSet<>(Arrays.asList("init", "all-openide.dialogs", "all-openide.util", "all-openide.util.lookup", "all-api.annotations.common")), s);
    
    int callTargets = 0;
    for (Task task : t.getTasks()) {
        if (task instanceof CallTarget) {
            callTargets++;
        }
    }
    assertEquals("No call targes", 0, callTargets);
}
 
Example #7
Source File: InsertModuleAllTargetsTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testInstallAllTargetWithoutClusters() {
    InsertModuleAllTargets insert = new InsertModuleAllTargets();
    insert.setProject(p);
    insert.setUseClusters(false);
    insert.execute();

    Object obj = p.getTargets().get("all-java.source.queries");
    assertNotNull("Target found", obj);
    Target t = (Target)obj;
    
    Set<String> s = depsToNames(t.getDependencies());
    assertEquals("Three dependencies: " + s, 5, s.size());
    assertTrue("on init", s.contains("init"));
    assertTrue("on all-openide.util", s.contains("all-openide.util"));
    assertTrue("on all-openide.util.lookup", s.contains("all-openide.util.lookup"));
    assertTrue("on all-api.annotations.common", s.contains("all-api.annotations.common"));
    assertTrue("on all-openide.dialogs", s.contains("all-openide.dialogs"));
    
    int callTargets = 0;
    for (Task task : t.getTasks()) {
        if (task instanceof CallTarget) {
            callTargets++;
        }
    }
    assertEquals("No call targes", 0, callTargets);
}
 
Example #8
Source File: BasicAntBuilder.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public BasicAntBuilder() {
    // These are used to discard references to tasks so they can be garbage collected
    Field collectorField;
    try {
        nodeField = AntBuilder.class.getDeclaredField("lastCompletedNode");
        nodeField.setAccessible(true);
        collectorField = AntBuilder.class.getDeclaredField("collectorTarget");
        collectorField.setAccessible(true);
        Target target = (Target) collectorField.get(this);
        Field childrenField = Target.class.getDeclaredField("children");
        childrenField.setAccessible(true);
        children = (List) childrenField.get(target);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    getAntProject().addDataTypeDefinition("gradleFileResource", AntFileResource.class);
    getAntProject().addDataTypeDefinition("gradleBaseDirSelector", BaseDirSelector.class);
}
 
Example #9
Source File: AntDecorator.java    From oodt with Apache License 2.0 5 votes vote down vote up
public Untarer() {
    project = new Project();
    project.init();
    taskType = "untar";
    taskName = "untar";
    target = new Target();
}
 
Example #10
Source File: DefaultAntBuilder.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private static List<String> getTaskDependencyNames(Target target, Transformer<? extends String, ? super String> taskNamer) {
    Enumeration<String> dependencies = target.getDependencies();
    List<String> taskDependencyNames = Lists.newLinkedList();
    while (dependencies.hasMoreElements()) {
        String targetName = dependencies.nextElement();
        String taskName = taskNamer.transform(targetName);
        taskDependencyNames.add(taskName);
    }
    return taskDependencyNames;
}
 
Example #11
Source File: DefaultAntBuilder.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private static void configureTask(Target target, AntTarget task, File baseDir, Transformer<? extends String, ? super String> taskNamer) {
    task.setTarget(target);
    task.setBaseDir(baseDir);

    final List<String> taskDependencyNames = getTaskDependencyNames(target, taskNamer);
    task.dependsOn(new AntTargetsTaskDependency(taskDependencyNames));
    addDependencyOrdering(taskDependencyNames, task.getProject().getTasks());
}
 
Example #12
Source File: DefaultAntBuilder.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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: AntBuilder.java    From groovy with Apache License 2.0 5 votes vote down vote up
private Target onDefineTarget(final Attributes attrs, String tagName, String ns) {
    try {
        antTargetHandler.onStartElement(ns, tagName, tagName, attrs, antXmlContext);
        final Target newTarget = getProject().getTargets().get(attrs.getValue("name"));
        antXmlContext.setCurrentTarget(newTarget);
        definingTarget = newTarget;
        return newTarget;
    } catch (final SAXParseException e) {
        log.log(Level.SEVERE, "Caught: " + e, e);
        return null;
    }
}
 
Example #14
Source File: DefaultAntBuilder.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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 #15
Source File: NbBuildLogger.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Try to find the location of an Ant target.
 * @param project if not null, the main project from which this target might have been imported
 */
private Location getLocationOfTarget(Target target, Project project) {
    if (targetGetLocation != null) {
        try {
            return (Location) targetGetLocation.invoke(target);
        } catch (Exception e) {
            LOG.log(Level.WARNING, null, e);
        }
    }
    // For Ant 1.6.2 and earlier, hope we got the right info from the hacks above.
    LOG.log(Level.FINEST, "knownImportedTargets: {0}", knownImportedTargets);
    if (project != null) {
        String file = project.getProperty("ant.file"); // NOI18N
        if (file != null) {
            Map<String,String> targetLocations = knownImportedTargets.get(file);
            if (targetLocations != null) {
                String importedFile = targetLocations.get(target.getName());
                if (importedFile != null) {
                    // Have no line number, note.
                    return new Location(importedFile);
                }
            }
        }
    }
    // Dunno.
    return null;
}
 
Example #16
Source File: DefaultAntBuilder.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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: AntDecorator.java    From oodt with Apache License 2.0 5 votes vote down vote up
public Deleter() {
    project = new Project();
    project.init();
    taskType = "delete";
    taskName = "delete";
    target = new Target();
}
 
Example #18
Source File: AntDecorator.java    From oodt with Apache License 2.0 5 votes vote down vote up
public Chmoder() {
    project = new Project();
    project.init();
    taskType = "chmod";
    taskName = "chmod";
    target = new Target();
}
 
Example #19
Source File: DefaultAntBuilder.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private static List<String> getTaskDependencyNames(Target target, Transformer<? extends String, ? super String> taskNamer) {
    Enumeration<String> dependencies = target.getDependencies();
    List<String> taskDependencyNames = Lists.newLinkedList();
    while (dependencies.hasMoreElements()) {
        String targetName = dependencies.nextElement();
        String taskName = taskNamer.transform(targetName);
        taskDependencyNames.add(taskName);
    }
    return taskDependencyNames;
}
 
Example #20
Source File: DefaultAntBuilder.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private static void configureTask(Target target, AntTarget task, File baseDir, Transformer<? extends String, ? super String> taskNamer) {
    task.setTarget(target);
    task.setBaseDir(baseDir);

    final List<String> taskDependencyNames = getTaskDependencyNames(target, taskNamer);
    task.dependsOn(new AntTargetsTaskDependency(taskDependencyNames));
    addDependencyOrdering(taskDependencyNames, task.getProject().getTasks());
}
 
Example #21
Source File: DefaultAntBuilder.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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 #22
Source File: GrammarDoc.java    From openccg with GNU Lesser General Public License v2.1 4 votes vote down vote up
CommandGrammarDoc(PrintStream out) {
	this.out = out;
	
	setProject(new Project());
	setOwningTarget(new Target());
}
 
Example #23
Source File: AntTarget.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Sets the Ant target to execute.
 */
public void setTarget(Target target) {
    this.target = target;
}
 
Example #24
Source File: AntTarget.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Returns the Ant target to execute.
 */
public Target getTarget() {
    return target;
}
 
Example #25
Source File: AntTarget.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Returns the Ant target to execute.
 */
public Target getTarget() {
    return target;
}
 
Example #26
Source File: AntTarget.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Sets the Ant target to execute.
 */
public void setTarget(Target target) {
    this.target = target;
}
 
Example #27
Source File: AntTarget.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Returns the Ant target to execute.
 */
public Target getTarget() {
    return target;
}
 
Example #28
Source File: AntBuilder.java    From groovy with Apache License 2.0 4 votes vote down vote up
public AntBuilder(final Project project) {
    this(project, new Target());
}
 
Example #29
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 #30
Source File: NbMerge.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Execute targets which can fail _without_ throwing BuildException */
private void modulesBuild() throws BuildException {
    if ( ! failonerror ) {
        // build the rest of modules
        for (String module : buildmodules) {
            dummy = new Target ();
            dummyName = "nbmerge-" + getOwningTarget().getName() + "-" + module;
            while (targets.contains (dummyName))
                dummyName += "-x";
            dummy.setName (dummyName);
            dummy.addDependency (targetprefix + module);
            getProject().addTarget(dummy);
            @SuppressWarnings("unchecked")
            Vector<Target> fullList = getProject().topoSort(dummyName, targets);
            // Now remove earlier ones: already done.
            @SuppressWarnings("unchecked")
            Vector<Target> doneList = getProject().topoSort(getOwningTarget().getName(), targets);
            List<Target> todo = new ArrayList<>(fullList.subList(0, fullList.indexOf(dummy)));
            todo.removeAll(doneList.subList(0, doneList.indexOf(getOwningTarget())));
            
            Iterator<Target> targit = todo.iterator();
            try {
                while (targit.hasNext()) {
                    Target nexttargit = targit.next();
                    String targetname = nexttargit.getName();
                    if ( builttargets.indexOf(targetname) < 0 ) {
                        System.out.println(); System.out.println(targetname + ":");
                        nexttargit.execute();
                        builttargets.addElement(targetname);
                    }
                    
                }
                builtmodules.addElement(module);
            } catch (BuildException BE) {
                    log(BE.toString(), Project.MSG_WARN);
                    BE.printStackTrace();
                    failedmodules.addElement(module);
            }
        }
        log("builtmodules=" + builtmodules, Project.MSG_VERBOSE);
        log("failedmodules=" + failedmodules, Project.MSG_VERBOSE);
    }
}