use of org.apache.ivy.core.event.IvyEvent in project ant-ivy by apache.
the class RetrieveTest method testEvent.
@Test
public void testEvent() throws Exception {
ResolveReport report = ivy.resolve(new File("test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURI().toURL(), getResolveOptions(new String[] { "*" }));
final List<IvyEvent> events = new ArrayList<>();
ivy.getEventManager().addIvyListener(new IvyListener() {
public void progress(IvyEvent event) {
events.add(event);
}
});
ModuleDescriptor md = report.getModuleDescriptor();
String pattern = "build/test/retrieve/[module]/[conf]/[artifact]-[revision].[ext]";
ivy.retrieve(md.getModuleRevisionId(), getRetrieveOptions().setDestArtifactPattern(pattern));
assertEquals(4, events.size());
assertTrue(events.get(0) instanceof StartRetrieveEvent);
assertTrue(events.get(1) instanceof StartRetrieveArtifactEvent);
assertTrue(events.get(2) instanceof EndRetrieveArtifactEvent);
assertTrue(events.get(3) instanceof EndRetrieveEvent);
EndRetrieveEvent ev = (EndRetrieveEvent) events.get(3);
assertEquals(1, ev.getNbCopied());
assertEquals(0, ev.getNbUpToDate());
events.clear();
ivy.retrieve(md.getModuleRevisionId(), getRetrieveOptions().setDestArtifactPattern(pattern));
assertEquals(2, events.size());
assertTrue(events.get(0) instanceof StartRetrieveEvent);
assertTrue(events.get(1) instanceof EndRetrieveEvent);
ev = (EndRetrieveEvent) events.get(1);
assertEquals(0, ev.getNbCopied());
assertEquals(1, ev.getNbUpToDate());
}
use of org.apache.ivy.core.event.IvyEvent in project ant-ivy by apache.
the class VsftpRepository method ensureConnectionOpened.
protected synchronized void ensureConnectionOpened() throws IOException {
if (in == null) {
Message.verbose("connecting to " + getUsername() + "@" + getHost() + "... ");
String connectionCommand = getConnectionCommand();
exec(connectionCommand);
try {
// waits for first prompt
readResponse(false);
if (reuseConnection > 0) {
connectionCleaner = new IvyThread() {
public void run() {
initContext();
try {
long sleep = REUSE_CONNECTION_SLEEP_TIME;
while (in != null && sleep > 0) {
sleep(sleep);
sleep = reuseConnection - (System.currentTimeMillis() - lastCommand);
if (inCommand && sleep <= 0) {
sleep = reuseConnection;
}
}
} catch (InterruptedException e) {
// nothing to do
}
disconnect();
}
};
connectionCleaner.start();
}
if (ivy != null) {
ivy.getEventManager().addIvyListener(new IvyListener() {
public void progress(IvyEvent event) {
disconnect();
event.getSource().removeIvyListener(this);
}
}, EndResolveEvent.NAME);
}
} catch (IOException ex) {
closeConnection();
throw new IOException("impossible to connect to " + getUsername() + "@" + getHost() + " using " + getAuthentication() + ": " + ex.getMessage());
}
Message.verbose("connected to " + getHost());
}
}
Aggregations