org.apache.tools.ant.Task Java Examples

The following examples show how to use org.apache.tools.ant.Task. 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: AntBuilder.java    From groovy with Apache License 2.0 6 votes vote down vote up
public AntBuilder(final Task parentTask) {
    this(parentTask.getProject(), parentTask.getOwningTarget());

    // define "owning" task as wrapper to avoid having tasks added to the target
    // but it needs to be an UnknownElement and no access is available from
    // task to its original UnknownElement 
    final UnknownElement ue = new UnknownElement(parentTask.getTaskName());
    ue.setProject(parentTask.getProject());
    ue.setTaskType(parentTask.getTaskType());
    ue.setTaskName(parentTask.getTaskName());
    ue.setLocation(parentTask.getLocation());
    ue.setOwningTarget(parentTask.getOwningTarget());
    ue.setRuntimeConfigurableWrapper(parentTask.getRuntimeConfigurableWrapper());
    parentTask.getRuntimeConfigurableWrapper().setProxy(ue);
    antXmlContext.pushWrapper(parentTask.getRuntimeConfigurableWrapper());
}
 
Example #2
Source File: NbBuildLogger.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public @Override String getTaskName() {
    verifyRunning();
    if (e == null) {
        return null;
    }
    Task task = e.getTask();
    if (task != null) {
        return task.getRuntimeConfigurableWrapper().getElementTag();
    }
    // #49464: guess at task.
    Task lastTask = getLastTask();
    if (lastTask != null) {
        return lastTask.getRuntimeConfigurableWrapper().getElementTag();
    }
    return null;
}
 
Example #3
Source File: MakeOSGi.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static void scanClasses(JarFile module, Set<String> importedPackages, Set<String> availablePackages, Task task) throws Exception {
    Map<String, byte[]> classfiles = new TreeMap<>();
    VerifyClassLinkage.read(module, classfiles, new HashSet<>(Collections.singleton(new File(module.getName()))), task, null);
    for (Map.Entry<String,byte[]> entry : classfiles.entrySet()) {
        String available = entry.getKey();
        int idx = available.lastIndexOf('.');
        if (idx != -1) {
            availablePackages.add(available.substring(0, idx));
        }
        for (String clazz : VerifyClassLinkage.dependencies(entry.getValue())) {
            if (classfiles.containsKey(clazz)) {
                // Part of the same module; probably not an external import.
                continue;
            }
            if (clazz.startsWith("java.")) {
                // No need to declare as an import.
                continue;
            }
            idx = clazz.lastIndexOf('.');
            if (idx != -1) {
                importedPackages.add(clazz.substring(0, idx));
            }
        }
    }
}
 
Example #4
Source File: MakeNBM.java    From netbeans with Apache License 2.0 6 votes vote down vote up
static void validateAgainstAUDTDs(InputSource input, final Path updaterJar, final Task task) throws IOException, SAXException {
    XMLUtil.parse(input, true, false, XMLUtil.rethrowHandler(), new EntityResolver() {
        ClassLoader loader = new AntClassLoader(task.getProject(), updaterJar);
        public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
            String remote = "http://www.netbeans.org/dtds/";
            if (systemId.startsWith(remote)) {
                String rsrc = "org/netbeans/updater/resources/" + systemId.substring(remote.length());
                URL u = loader.getResource(rsrc);
                if (u != null) {
                    return new InputSource(u.toString());
                } else {
                    task.log(rsrc + " not found in " + updaterJar, Project.MSG_WARN);
                }
            }
            return null;
        }
    });
}
 
Example #5
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 #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: MakeOSGiTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testPrescan() throws Exception {
    File j = new File(getWorkDir(), "x.jar");
    try (OutputStream os = new FileOutputStream(j)) {
        JarOutputStream jos = new JarOutputStream(os, new Manifest(new ByteArrayInputStream("Manifest-Version: 1.0\nBundle-SymbolicName: org.eclipse.mylyn.bugzilla.core;singleton:=true\nExport-Package: org.eclipse.mylyn.internal.bugzilla.core;x-friends:=\"org.eclipse.mylyn.bugzilla.ide,org.eclipse.mylyn.bugzilla.ui\",org.eclipse.mylyn.internal.bugzilla.core.history;x-friends:=\"org.eclipse.mylyn.bugzilla.ide,org.eclipse.mylyn.bugzilla.ui\",org.eclipse.mylyn.internal.bugzilla.core.service;x-internal:=true\n".getBytes())));
        jos.flush();
        jos.close();
    }
    Info info = new MakeOSGi.Info();
    JarFile jf = new JarFile(j);
    try {
        assertEquals("org.eclipse.mylyn.bugzilla.core", MakeOSGi.prescan(jf, info, new Task() {}));
    } finally {
        jf.close();
    }
    assertEquals("[org.eclipse.mylyn.internal.bugzilla.core, org.eclipse.mylyn.internal.bugzilla.core.history, org.eclipse.mylyn.internal.bugzilla.core.service]", info.exportedPackages.toString());
}
 
Example #8
Source File: ResourceCpResolver.java    From yGuard with MIT License 6 votes vote down vote up
public ResourceCpResolver(final Path resources, final Task target) {
  this.resource = resources;
  final String[] list = resources.list();
  final List listUrls = new ArrayList();
  for ( int i = 0; i < list.length; i++ ) {
    try {
      final URL url = new File( list[ i ] ).toURL();
      listUrls.add( url );
    } catch ( MalformedURLException mfue ) {
      Logger.err( "Could not resolve resource: " + mfue );
      target.getProject().log( target, "Could not resolve resource: " + mfue, Project.MSG_WARN );
    }
  }
  final URL[] urls = new URL[listUrls.size()];
  listUrls.toArray( urls );
  urlClassLoader = URLClassLoader.newInstance( urls, ClassLoader.getSystemClassLoader() );
}
 
Example #9
Source File: ObfuscatorTask.java    From yGuard with MIT License 6 votes vote down vote up
ResourceCpResolver(Path resources, Task target){
  this.resource = resources;
  String[] list = resources.list();
  List listUrls = new ArrayList();
  for (int i = 0; i <list.length; i++){
    try{
      URL url = new File(list[i]).toURL();
      listUrls.add(url);
    } catch (MalformedURLException mfue){
      target.getProject().log(target, "Could not resolve resource: "+mfue, Project.MSG_WARN);
    }
  }
  URL[] urls = new URL[listUrls.size()];
  listUrls.toArray(urls);
  urlClassLoader = URLClassLoader.newInstance(urls, ClassLoader.getSystemClassLoader());
}
 
Example #10
Source File: IncrementalDeploymentTask.java    From aws-ant-tasks with Apache License 2.0 6 votes vote down vote up
/**
 * Deploys all apps in this deployment group, then waits for all the
 * deployments in the group to succeed. Deployments in a group will run
 * in parallel.
 */
public void deployApps() {
    for (Task deployAppTask : deployAppTasks) {
        
        // This is in case of a rare bug that occurs in some JVM implementations
        if (deployAppTask instanceof UnknownElement) {
            deployAppTask.maybeConfigure();
            deployAppTask = ((UnknownElement) deployAppTask).getTask();
        }
        if (!deployAppTask.getTaskName().equals("deploy-opsworks-app")) {
            throw new BuildException(
                    "Only <deploy-opsworks-app> elements are supported");
        }
        deployAppTask.execute();
        deploymentIds.add(deployAppTask.getDescription());
    }

    try {
        waitForDeploymentGroupToSucceed(deploymentIds, client);
    } catch (InterruptedException e) {
        throw new BuildException(e.getMessage(), e);
    }
}
 
Example #11
Source File: PublishArtifactNotationParserFactory.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected PublishArtifact parseType(File file) {
    Module module = metaDataProvider.getModule();
    ArtifactFile artifactFile = new ArtifactFile(file, module.getVersion());
    return instantiator.newInstance(DefaultPublishArtifact.class, artifactFile.getName(), artifactFile.getExtension(),
                                    artifactFile.getExtension() == null? "":artifactFile.getExtension(),
                                    artifactFile.getClassifier(), null, file, new Task[0]);
}
 
Example #12
Source File: ForEach.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the specified property to the given value and executes the children.
 */
private void executeChildren(String value) throws BuildException {
    getProject().setProperty(this.property, value);    
    
    for (Task task: this.children) {
        task.perform();
    }
}
 
Example #13
Source File: YShrinkInvokerImpl.java    From yGuard with MIT License 5 votes vote down vote up
public void setContext(Task task) {
  shrinkTask.setProject(task.getProject());
  shrinkTask.setOwningTarget(task.getOwningTarget());
  shrinkTask.setTaskName(task.getTaskName());
  shrinkTask.setLocation(task.getLocation());
  shrinkTask.setDescription(task.getDescription());
  shrinkTask.init();
}
 
Example #14
Source File: YGuardTask.java    From yGuard with MIT License 5 votes vote down vote up
private void configureSubTask(Task task) {
  task.setProject(getProject());
  task.setOwningTarget(getOwningTarget());
  task.setTaskName(getTaskName());
  task.setLocation(getLocation());
  task.setDescription(getDescription());
  task.init();
}
 
Example #15
Source File: ForEach.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the specified property to the given value and executes the children.
 */
private void executeChildren(String value) throws BuildException {
    getProject().setProperty(this.property, value);
    
    for (Task task: this.children) {
        task.perform();
    }
}
 
Example #16
Source File: TaskLoggerDelegate.java    From doma-gen with Apache License 2.0 5 votes vote down vote up
/**
 * インスタンスを生成します。
 *
 * @param task Antタスク
 */
public TaskLoggerDelegate(Task task) {
  if (task == null) {
    throw new NullPointerException("task");
  }
  this.task = task;
}
 
Example #17
Source File: ForEach.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a new instance of the {@link ForEach} task. It simply sets the
 * default values for the attributes.
 */
public ForEach() {
    separator = DEFAULT_SEPARATOR;
    
    from = DEFAULT_FROM;
    to = DEFAULT_TO;
    increment = DEFAULT_INCREMENT;
    
    children = new LinkedList<Task>();
}
 
Example #18
Source File: SequentialElement.java    From ExpectIt with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 * <p/>
 * Passes the {@code expect} instance to the children tasks that are instanceof
 * {@link net.sf.expectit.ant.matcher.AbstractTaskElement}.
 */
@Override
public void execute() {
    for (Task t : tasks) {
        if (t instanceof UnknownElement) {
            t.maybeConfigure();
            Object proxy = ((UnknownElement) t).getWrapper().getProxy();
            if (proxy instanceof AbstractTaskElement) {
                ((AbstractTaskElement) proxy).setExpect(expect);
            }
        }
    }
    super.execute();
}
 
Example #19
Source File: PublishArtifactNotationParserFactory.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected PublishArtifact parseType(File file) {
    Module module = metaDataProvider.getModule();
    ArtifactFile artifactFile = new ArtifactFile(file, module.getVersion());
    return instantiator.newInstance(DefaultPublishArtifact.class, artifactFile.getName(), artifactFile.getExtension(),
                                    artifactFile.getExtension() == null? "":artifactFile.getExtension(),
                                    artifactFile.getClassifier(), null, file, new Task[0]);
}
 
Example #20
Source File: PublishArtifactNotationParserFactory.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected PublishArtifact parseType(File file) {
    Module module = metaDataProvider.getModule();
    ArtifactFile artifactFile = new ArtifactFile(file, module.getVersion());
    return instantiator.newInstance(DefaultPublishArtifact.class, artifactFile.getName(), artifactFile.getExtension(),
                                    artifactFile.getExtension() == null? "":artifactFile.getExtension(),
                                    artifactFile.getClassifier(), null, file, new Task[0]);
}
 
Example #21
Source File: GitTasks.java    From ant-git-tasks with Apache License 2.0 5 votes vote down vote up
@Override
public void execute() throws BuildException {
        if (directory == null) {
                throw new BuildException("Please specify a directory attribute.");
        }

        for (Task task : tasks) {
                GitTask t = (GitTask) task;
                GitTaskUtils.validateTaskConditions(t);

                if (!GitTaskUtils.isNullOrBlankString(t.getIf())) {
                        if (getProject().getProperty(t.getIf()) == null) {
                                continue;
                        }
                }

                if (!GitTaskUtils.isNullOrBlankString(t.getUnless())) {
                        if (getProject().getProperty(t.getUnless()) != null) {
                                continue;
                        }
                }

                if (!GitTaskUtils.isNullOrBlankString(settingsRef)) {
                        t.setSettingsRef(settingsRef);
                }

                if (verbose) {
                        t.useProgressMonitor(new GitTaskMonitor(t));
                }

                t.setDirectory(directory);

                task.perform();
        }
}
 
Example #22
Source File: NbBuildLogger.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public @Override TaskStructure getTaskStructure() {
    verifyRunning();
    Task task = e.getTask();
    if (task != null) {
        return LoggerTrampoline.TASK_STRUCTURE_CREATOR.makeTaskStructure(new TaskStructureImpl(task.getRuntimeConfigurableWrapper()));
    }
    // #49464: guess at task.
    Task lastTask = getLastTask();
    if (lastTask != null) {
        return LoggerTrampoline.TASK_STRUCTURE_CREATOR.makeTaskStructure(new TaskStructureImpl(lastTask.getRuntimeConfigurableWrapper()));
    }
    return null;
}
 
Example #23
Source File: WriteDataToDatabaseCommand.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Reads a single data file.
 * 
 * @param task     The parent task
 * @param reader   The data reader
 * @param dataFile The schema file
 */
private void readSingleDataFile(Task task, DataReader reader, File dataFile) throws BuildException
{
    if (!dataFile.exists())
    {
        _log.error("Could not find data file " + dataFile.getAbsolutePath());
    }
    else if (!dataFile.isFile())
    {
        _log.error("Path " + dataFile.getAbsolutePath() + " does not denote a data file");
    }
    else if (!dataFile.canRead())
    {
        _log.error("Could not read data file " + dataFile.getAbsolutePath());
    }
    else
    {
        try
        {
            getDataIO().writeDataToDatabase(reader, dataFile.getAbsolutePath());
            _log.info("Written data from file " + dataFile.getAbsolutePath() + " to database");
        }
        catch (Exception ex)
        {
            handleException(ex, "Could not parse or write data file " + dataFile.getAbsolutePath());
        }
    }
}
 
Example #24
Source File: SpoofTaskContainer.java    From groovy with Apache License 2.0 5 votes vote down vote up
public void execute() throws BuildException {
    spoof("begin SpoofTaskContainer execute");
    for (Object task1 : tasks) {
        Task task = (Task) task1;
        task.perform();
    }
    spoof("end SpoofTaskContainer execute");
}
 
Example #25
Source File: SpoofTaskContainer.java    From groovy with Apache License 2.0 5 votes vote down vote up
public void addTask(Task task) {
    // to work with ant 1.6
    spoof("in addTask");
    if (task instanceof UnknownElement) {
        spoof("configuring UnknownElement");
        task.maybeConfigure();
        task = ((UnknownElement) task).getTask();
    }
    tasks.add(task);
}
 
Example #26
Source File: ForEachTask.java    From development with Apache License 2.0 5 votes vote down vote up
@Override
public void execute() throws BuildException {
    final String bak = getProject().getProperty(property);
    for (String token : tokens) {
        getProject().setProperty(property, token);
        for (Task task : tasks) {
            task.maybeConfigure();
            task.execute();
        }
    }
    if (bak != null) {
        getProject().setProperty(property, bak);
    }
}
 
Example #27
Source File: FortressAntLoadTest.java    From directory-fortress-core with Apache License 2.0 5 votes vote down vote up
/**
 * This method is called by {@link FortressAntTask} via reflexion and invokes its JUnit tests to verify loaded
 * data into LDAP against input data.
 */
@Override
public synchronized void execute( Task task )
{
    fortressAntTask = ( FortressAntTask ) task;
    fileName = task.getProject().getName();
    LOG.info( "execute FortressAntLoadTest JUnit tests on file name: " + fileName );
    Result result = JUnitCore.runClasses( FortressAntLoadTest.class );
    for ( Failure failure : result.getFailures() )
    {
        LOG.info( failure.toString() );
    }
    LOG.info( "TEST SUCCESS: " + result.wasSuccessful() );
}
 
Example #28
Source File: GroupAntTest.java    From directory-fortress-core with Apache License 2.0 5 votes vote down vote up
/**
 * This method is called by {@link FortressAntTask} via reflexion and invokes its JUnit tests to verify loaded
 * data into LDAP against input data.
 */
@Override
public synchronized void execute( Task task )
{
    fortressAntTask = ( FortressAntTask ) task;
    fileName = task.getProject().getName();
    LOG.info( "execute GroupAntTest JUnit tests on file name: " + fileName );
    Result result = JUnitCore.runClasses( GroupAntTest.class );
    for ( Failure failure : result.getFailures() )
    {
        LOG.info( failure.toString() );
    }
    LOG.info( "TEST SUCCESS: " + result.wasSuccessful() );
}
 
Example #29
Source File: WriteDataToDatabaseCommand.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Reads a single data file.
 * 
 * @param task     The parent task
 * @param reader   The data reader
 * @param dataFile The schema file
 */
private void readSingleDataFile(Task task, DataReader reader, File dataFile) throws BuildException
{
    if (!dataFile.exists())
    {
        _log.error("Could not find data file " + dataFile.getAbsolutePath());
    }
    else if (!dataFile.isFile())
    {
        _log.error("Path " + dataFile.getAbsolutePath() + " does not denote a data file");
    }
    else if (!dataFile.canRead())
    {
        _log.error("Could not read data file " + dataFile.getAbsolutePath());
    }
    else
    {
        try
        {
            getDataIO().writeDataToDatabase(reader, dataFile.getAbsolutePath());
            _log.info("Written data from file " + dataFile.getAbsolutePath() + " to database");
        }
        catch (Exception ex)
        {
            handleException(ex, "Could not parse or write data file " + dataFile.getAbsolutePath());
        }
    }
}
 
Example #30
Source File: PublishArtifactNotationParserFactory.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected PublishArtifact parseType(File file) {
    Module module = metaDataProvider.getModule();
    ArtifactFile artifactFile = new ArtifactFile(file, module.getVersion());
    return instantiator.newInstance(DefaultPublishArtifact.class, artifactFile.getName(), artifactFile.getExtension(),
                                    artifactFile.getExtension() == null? "":artifactFile.getExtension(),
                                    artifactFile.getClassifier(), null, file, new Task[0]);
}