Search in sources :

Example 1 with BuildEvent

use of org.apache.tools.ant.BuildEvent in project ant by apache.

the class JUnitLauncherTaskTest method setUp.

/**
 * The JUnit setup method.
 */
@Before
public void setUp() {
    File antFile = new File(System.getProperty("root"), "src/etc/testcases/taskdefs/optional/junitlauncher.xml");
    this.project = new Project();
    this.project.init();
    ProjectHelper.configureProject(project, antFile);
    project.addBuildListener(new BuildListener() {

        @Override
        public void buildStarted(final BuildEvent event) {
        }

        @Override
        public void buildFinished(final BuildEvent event) {
        }

        @Override
        public void targetStarted(final BuildEvent event) {
        }

        @Override
        public void targetFinished(final BuildEvent event) {
        }

        @Override
        public void taskStarted(final BuildEvent event) {
        }

        @Override
        public void taskFinished(final BuildEvent event) {
        }

        @Override
        public void messageLogged(final BuildEvent event) {
            if (event.getPriority() <= Project.MSG_INFO) {
                System.out.println(event.getMessage());
            }
        }
    });
}
Also used : Project(org.apache.tools.ant.Project) BuildListener(org.apache.tools.ant.BuildListener) BuildEvent(org.apache.tools.ant.BuildEvent) File(java.io.File) Before(org.junit.Before)

Example 2 with BuildEvent

use of org.apache.tools.ant.BuildEvent in project ceylon by eclipse.

the class Util method getCeylonClassLoaderCachedInProject.

public static CeylonClassLoader getCeylonClassLoaderCachedInProject(final Project project) throws ClassLoaderSetupException {
    Object classLoader = project.getReference(CEYLON_CLASSLOADER_REFERENCE);
    if (classLoader != null) {
        CeylonClassLoader oldLoader = (CeylonClassLoader) classLoader;
        // make sure it's still valid
        try {
            List<File> classPath = CeylonClassLoader.getClassPath();
            if (oldLoader.hasSignature(CeylonClassLoader.getClassPathSignature(classPath))) {
                // compatible
                return oldLoader;
            } else {
                project.log("Needs a new class loader: cp changed!", Project.MSG_VERBOSE);
                CeylonClassLoader loader = CeylonClassLoader.newInstance(classPath);
                project.addReference(CEYLON_CLASSLOADER_REFERENCE, loader);
                return loader;
            }
        } catch (FileNotFoundException x) {
            throw new ClassLoaderSetupException(x);
        } catch (URISyntaxException x) {
            throw new ClassLoaderSetupException(x);
        } catch (MalformedURLException x) {
            throw new ClassLoaderSetupException(x);
        }
    }
    CeylonClassLoader loader = Launcher.getClassLoader();
    project.addReference(CEYLON_CLASSLOADER_REFERENCE, loader);
    // only add the build listed once, even if we change the class loader later
    project.addBuildListener(new BuildListener() {

        @Override
        public void buildFinished(BuildEvent arg0) {
            project.log("Build done, cleaning up Ceylon class loader", Project.MSG_VERBOSE);
            // make sure we get the latest one
            Object reference = project.getReference(CEYLON_CLASSLOADER_REFERENCE);
            project.getReferences().remove(CEYLON_CLASSLOADER_REFERENCE);
            if (reference instanceof CeylonClassLoader) {
                try {
                    ((CeylonClassLoader) reference).close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }

        @Override
        public void buildStarted(BuildEvent arg0) {
        }

        @Override
        public void messageLogged(BuildEvent arg0) {
        }

        @Override
        public void targetFinished(BuildEvent arg0) {
        }

        @Override
        public void targetStarted(BuildEvent arg0) {
        }

        @Override
        public void taskFinished(BuildEvent arg0) {
        }

        @Override
        public void taskStarted(BuildEvent arg0) {
        }
    });
    return loader;
}
Also used : MalformedURLException(java.net.MalformedURLException) CeylonClassLoader(org.eclipse.ceylon.launcher.CeylonClassLoader) FileNotFoundException(java.io.FileNotFoundException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) ClassLoaderSetupException(org.eclipse.ceylon.launcher.ClassLoaderSetupException) BuildListener(org.apache.tools.ant.BuildListener) BuildEvent(org.apache.tools.ant.BuildEvent) File(java.io.File)

Example 3 with BuildEvent

use of org.apache.tools.ant.BuildEvent in project ant-ivy by apache.

the class AntMessageLogger method register.

/**
 * Creates and register an {@link AntMessageLogger} for the given {@link Task}, with the given
 * {@link Ivy} instance.
 * <p>
 * The created instance will automatically be unregistered from the Ivy instance when the task
 * finishes.
 * </p>
 *
 * @param task
 *            the task the logger should use for logging
 * @param ivy
 *            the ivy instance on which the logger should be registered
 */
public static void register(ProjectComponent task, final Ivy ivy) {
    MessageLogger current = ivy.getLoggerEngine().peekLogger();
    if (current instanceof AntMessageLogger && task instanceof Task && ((AntMessageLogger) current).task instanceof Task) {
        Task currentTask = (Task) ((AntMessageLogger) current).task;
        if (currentTask.getTaskName() != null && currentTask.getTaskName().equals(((Task) task).getTaskName())) {
            // prefix as the given task. So we shouldn't do anything...
            return;
        }
    }
    AntMessageLogger logger = new AntMessageLogger(task);
    ivy.getLoggerEngine().pushLogger(logger);
    task.getProject().addBuildListener(new BuildListener() {

        private int stackDepth = 0;

        public void buildFinished(BuildEvent event) {
        }

        public void buildStarted(BuildEvent event) {
        }

        public void targetStarted(BuildEvent event) {
        }

        public void targetFinished(BuildEvent event) {
        }

        public void taskStarted(BuildEvent event) {
            stackDepth++;
        }

        public void taskFinished(BuildEvent event) {
            // NB: There is sometimes task created by an other task
            // in that case, we should not uninit Message. The log should stay associated
            // with the initial task, except if it was an antcall, ant or subant target
            // NB2 : Testing the identity of the task is not enough, event.getTask() return
            // an instance of UnknownElement is wrapping the concrete instance
            stackDepth--;
            if (stackDepth == -1) {
                ivy.getLoggerEngine().popLogger();
                event.getProject().removeBuildListener(this);
            }
        }

        public void messageLogged(BuildEvent event) {
        }
    });
}
Also used : BuildListener(org.apache.tools.ant.BuildListener) Task(org.apache.tools.ant.Task) AbstractMessageLogger(org.apache.ivy.util.AbstractMessageLogger) MessageLogger(org.apache.ivy.util.MessageLogger) BuildEvent(org.apache.tools.ant.BuildEvent)

Example 4 with BuildEvent

use of org.apache.tools.ant.BuildEvent in project mdw-designer by CenturyLinkCloud.

the class AntBuilder method fireBuildStarted.

/*
     * We only have to do this because Project.fireBuildStarted is protected. If
     * it becomes public we should remove this and call the appropriate method.
     */
@SuppressWarnings("rawtypes")
private void fireBuildStarted(Project project) {
    BuildEvent event = new BuildEvent(project);
    for (Iterator i = project.getBuildListeners().iterator(); i.hasNext(); ) {
        BuildListener listener = (BuildListener) i.next();
        listener.buildStarted(event);
    }
}
Also used : BuildListener(org.apache.tools.ant.BuildListener) BuildEvent(org.apache.tools.ant.BuildEvent) Iterator(java.util.Iterator)

Example 5 with BuildEvent

use of org.apache.tools.ant.BuildEvent in project ceylon-compiler by ceylon.

the class Util method getCeylonClassLoaderCachedInProject.

public static CeylonClassLoader getCeylonClassLoaderCachedInProject(final Project project) throws ClassLoaderSetupException {
    Object classLoader = project.getReference(CEYLON_CLASSLOADER_REFERENCE);
    if (classLoader != null) {
        CeylonClassLoader oldLoader = (CeylonClassLoader) classLoader;
        // make sure it's still valid
        try {
            List<File> classPath = CeylonClassLoader.getClassPath();
            if (oldLoader.hasSignature(CeylonClassLoader.getClassPathSignature(classPath))) {
                // compatible
                return oldLoader;
            } else {
                project.log("Needs a new class loader: cp changed!", Project.MSG_VERBOSE);
                CeylonClassLoader loader = CeylonClassLoader.newInstance(classPath);
                project.addReference(CEYLON_CLASSLOADER_REFERENCE, loader);
                return loader;
            }
        } catch (FileNotFoundException x) {
            throw new ClassLoaderSetupException(x);
        } catch (URISyntaxException x) {
            throw new ClassLoaderSetupException(x);
        } catch (MalformedURLException x) {
            throw new ClassLoaderSetupException(x);
        }
    }
    CeylonClassLoader loader = Launcher.getClassLoader();
    project.addReference(CEYLON_CLASSLOADER_REFERENCE, loader);
    // only add the build listed once, even if we change the class loader later
    project.addBuildListener(new BuildListener() {

        @Override
        public void buildFinished(BuildEvent arg0) {
            project.log("Build done, cleaning up Ceylon class loader", Project.MSG_VERBOSE);
            // make sure we get the latest one
            Object reference = project.getReference(CEYLON_CLASSLOADER_REFERENCE);
            project.getReferences().remove(CEYLON_CLASSLOADER_REFERENCE);
            if (reference instanceof CeylonClassLoader) {
                ((CeylonClassLoader) reference).clearCache();
            }
        }

        @Override
        public void buildStarted(BuildEvent arg0) {
        }

        @Override
        public void messageLogged(BuildEvent arg0) {
        }

        @Override
        public void targetFinished(BuildEvent arg0) {
        }

        @Override
        public void targetStarted(BuildEvent arg0) {
        }

        @Override
        public void taskFinished(BuildEvent arg0) {
        }

        @Override
        public void taskStarted(BuildEvent arg0) {
        }
    });
    return loader;
}
Also used : BuildListener(org.apache.tools.ant.BuildListener) MalformedURLException(java.net.MalformedURLException) BuildEvent(org.apache.tools.ant.BuildEvent) CeylonClassLoader(com.redhat.ceylon.launcher.CeylonClassLoader) FileNotFoundException(java.io.FileNotFoundException) URISyntaxException(java.net.URISyntaxException) ClassLoaderSetupException(com.redhat.ceylon.launcher.ClassLoaderSetupException) File(java.io.File)

Aggregations

BuildEvent (org.apache.tools.ant.BuildEvent)5 BuildListener (org.apache.tools.ant.BuildListener)5 File (java.io.File)3 FileNotFoundException (java.io.FileNotFoundException)2 MalformedURLException (java.net.MalformedURLException)2 URISyntaxException (java.net.URISyntaxException)2 CeylonClassLoader (com.redhat.ceylon.launcher.CeylonClassLoader)1 ClassLoaderSetupException (com.redhat.ceylon.launcher.ClassLoaderSetupException)1 IOException (java.io.IOException)1 Iterator (java.util.Iterator)1 AbstractMessageLogger (org.apache.ivy.util.AbstractMessageLogger)1 MessageLogger (org.apache.ivy.util.MessageLogger)1 Project (org.apache.tools.ant.Project)1 Task (org.apache.tools.ant.Task)1 CeylonClassLoader (org.eclipse.ceylon.launcher.CeylonClassLoader)1 ClassLoaderSetupException (org.eclipse.ceylon.launcher.ClassLoaderSetupException)1 Before (org.junit.Before)1