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;
}
}
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;
}
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());
}
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();
}
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);
}
Aggregations