Search in sources :

Example 1 with EventManager

use of org.apache.ivy.core.event.EventManager in project build-info by JFrogDev.

the class ArtifactoryBuildListener method taskStarted.

@Override
public void taskStarted(BuildEvent event) {
    try {
        Task task = extractIvyTask(event);
        if (task != null) {
            String taskType = task.getTaskType();
            getBuildInfoLog(event).debug("[buildinfo:ant] Received Task of type '" + taskType + "' Started Event");
            // Need only retrieve, resolve, and publish tasks, since needs to give ivy settings a chance (BI-131)
            if (taskType.endsWith("retrieve") || taskType.endsWith("resolve")) {
                getBuildInfoLog(event).debug("[buildinfo:ant] Adding Ivy Resolution Listeners if needed.");
                List<EventManager> eventManagers = getEventManager(task);
                for (EventManager eventManager : eventManagers) {
                    if (!eventManager.hasIvyListener(DEPENDENCY_TRIGGER)) {
                        eventManager.addIvyListener(DEPENDENCY_TRIGGER, DEPENDENCY_TRIGGER.getEventFilter());
                        getBuildInfoLog(event).info("[buildinfo:ant] Added resolution report Ivy Listener.");
                    }
                }
            }
            if (taskType.endsWith("publish")) {
                getBuildInfoLog(event).debug("[buildinfo:ant] Adding Ivy Publish Listeners if needed.");
                List<EventManager> eventManagers = getEventManager(task);
                for (EventManager eventManager : eventManagers) {
                    if (!eventManager.hasIvyListener(PUBLISH_TRIGGER)) {
                        eventManager.addIvyListener(PUBLISH_TRIGGER, PUBLISH_TRIGGER.getEventFilter());
                        getBuildInfoLog(event).info("[buildinfo:ant] Added publish end Ivy Listener to Ivy Engine.");
                    }
                }
            }
        }
    } catch (Exception e) {
        RuntimeException re = new RuntimeException("Fail to add the Ivy listeners for the Artifactory Ivy plugin, due to: " + e.getMessage(), e);
        getBuildInfoLog(event).error(re.getMessage(), e);
        throw re;
    }
}
Also used : IvyTask(org.apache.ivy.ant.IvyTask) EventManager(org.apache.ivy.core.event.EventManager) IOException(java.io.IOException)

Example 2 with EventManager

use of org.apache.ivy.core.event.EventManager in project build-info by JFrogDev.

the class ArtifactoryBuildListener method getEventManager.

/**
 * Retrieves all the event managers of all the ivy settings of the project.
 *
 * @param task the task we need to attach listeners to
 * @return the list of event manager for this task
 */
private List<EventManager> getEventManager(Task task) {
    List<EventManager> results = new ArrayList<EventManager>();
    Project project = task.getProject();
    Enumeration<Object> elements = project.getReferences().elements();
    // Iterate the project elements, search for ivy:settings and return them:
    while (elements.hasMoreElements()) {
        Object element = elements.nextElement();
        if (element instanceof UnknownElement) {
            UnknownElement unknown = (UnknownElement) element;
            element = unknown.getRealThing();
            if (element == null) {
                unknown.maybeConfigure();
                element = unknown.getRealThing();
            }
        }
        if (element instanceof IvyAntSettings) {
            results.add(((IvyAntSettings) element).getConfiguredIvyInstance(task).getResolveEngine().getEventManager());
        }
    }
    // If no ivy:settings were found (the ivy script might not include them), return the resolve engine:
    if (results.isEmpty()) {
        ResolveEngine engine = IvyAntSettings.getDefaultInstance(task).getConfiguredIvyInstance(task).getResolveEngine();
        results.add(engine.getEventManager());
    }
    return results;
}
Also used : ResolveEngine(org.apache.ivy.core.resolve.ResolveEngine) EventManager(org.apache.ivy.core.event.EventManager) IvyAntSettings(org.apache.ivy.ant.IvyAntSettings)

Example 3 with EventManager

use of org.apache.ivy.core.event.EventManager in project ant-ivy by apache.

the class JarResolver method setSettings.

@Override
public void setSettings(ResolverSettings settings) {
    super.setSettings(settings);
    if (url == null) {
        return;
    }
    // let's resolve the url
    ArtifactDownloadReport report;
    EventManager eventManager = getEventManager();
    try {
        if (eventManager != null) {
            getRepository().addTransferListener(eventManager);
        }
        Resource jarResource = new URLResource(url, this.getTimeoutConstraint());
        CacheResourceOptions options = new CacheResourceOptions();
        report = getRepositoryCacheManager().downloadRepositoryResource(jarResource, "jarrepository", "jar", "jar", options, new URLRepository());
    } finally {
        if (eventManager != null) {
            getRepository().removeTransferListener(eventManager);
        }
    }
    if (report.getDownloadStatus() == DownloadStatus.FAILED) {
        throw new RuntimeException("The jar file " + url.toExternalForm() + " could not be downloaded (" + report.getDownloadDetails() + ")");
    }
    setJarFile(report.getLocalFile());
}
Also used : URLResource(org.apache.ivy.plugins.repository.url.URLResource) EventManager(org.apache.ivy.core.event.EventManager) Resource(org.apache.ivy.plugins.repository.Resource) URLResource(org.apache.ivy.plugins.repository.url.URLResource) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) CacheResourceOptions(org.apache.ivy.core.cache.CacheResourceOptions) URLRepository(org.apache.ivy.plugins.repository.url.URLRepository)

Example 4 with EventManager

use of org.apache.ivy.core.event.EventManager in project ant-ivy by apache.

the class FileSystemResolverTest method setUp.

@Before
public void setUp() {
    settings = new IvySettings();
    engine = new ResolveEngine(settings, new EventManager(), new SortEngine(settings));
    cache = new File("build/cache");
    data = new ResolveData(engine, new ResolveOptions());
    cache.mkdirs();
    settings.setDefaultCache(cache);
    cacheManager = (DefaultRepositoryCacheManager) settings.getDefaultRepositoryCacheManager();
}
Also used : ResolveEngine(org.apache.ivy.core.resolve.ResolveEngine) SortEngine(org.apache.ivy.core.sort.SortEngine) ResolveData(org.apache.ivy.core.resolve.ResolveData) EventManager(org.apache.ivy.core.event.EventManager) IvySettings(org.apache.ivy.core.settings.IvySettings) File(java.io.File) ResolveOptions(org.apache.ivy.core.resolve.ResolveOptions) Before(org.junit.Before)

Example 5 with EventManager

use of org.apache.ivy.core.event.EventManager in project ant-ivy by apache.

the class IBiblioResolverTest method setUp.

@Before
public void setUp() {
    settings = new IvySettings();
    engine = new ResolveEngine(settings, new EventManager(), new SortEngine(settings));
    data = new ResolveData(engine, new ResolveOptions());
    TestHelper.createCache();
    settings.setDefaultCache(TestHelper.cache);
}
Also used : ResolveEngine(org.apache.ivy.core.resolve.ResolveEngine) SortEngine(org.apache.ivy.core.sort.SortEngine) ResolveData(org.apache.ivy.core.resolve.ResolveData) EventManager(org.apache.ivy.core.event.EventManager) IvySettings(org.apache.ivy.core.settings.IvySettings) ResolveOptions(org.apache.ivy.core.resolve.ResolveOptions) Before(org.junit.Before)

Aggregations

EventManager (org.apache.ivy.core.event.EventManager)19 ResolveEngine (org.apache.ivy.core.resolve.ResolveEngine)15 IvySettings (org.apache.ivy.core.settings.IvySettings)15 SortEngine (org.apache.ivy.core.sort.SortEngine)14 ResolveData (org.apache.ivy.core.resolve.ResolveData)13 ResolveOptions (org.apache.ivy.core.resolve.ResolveOptions)12 Before (org.junit.Before)12 File (java.io.File)7 IOException (java.io.IOException)2 CacheResourceOptions (org.apache.ivy.core.cache.CacheResourceOptions)2 ArtifactDownloadReport (org.apache.ivy.core.report.ArtifactDownloadReport)2 SearchEngine (org.apache.ivy.core.search.SearchEngine)2 Resource (org.apache.ivy.plugins.repository.Resource)2 URLResource (org.apache.ivy.plugins.repository.url.URLResource)2 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 TestFixture (org.apache.ivy.TestFixture)1 IvyAntSettings (org.apache.ivy.ant.IvyAntSettings)1