Search in sources :

Example 1 with IvyListener

use of org.apache.ivy.core.event.IvyListener 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());
}
Also used : IvyListener(org.apache.ivy.core.event.IvyListener) EndRetrieveEvent(org.apache.ivy.core.event.retrieve.EndRetrieveEvent) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) ResolveReport(org.apache.ivy.core.report.ResolveReport) ArrayList(java.util.ArrayList) StartRetrieveArtifactEvent(org.apache.ivy.core.event.retrieve.StartRetrieveArtifactEvent) StartRetrieveEvent(org.apache.ivy.core.event.retrieve.StartRetrieveEvent) EndRetrieveArtifactEvent(org.apache.ivy.core.event.retrieve.EndRetrieveArtifactEvent) File(java.io.File) IvyEvent(org.apache.ivy.core.event.IvyEvent) Test(org.junit.Test)

Example 2 with IvyListener

use of org.apache.ivy.core.event.IvyListener 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());
    }
}
Also used : IvyThread(org.apache.ivy.core.IvyThread) IvyListener(org.apache.ivy.core.event.IvyListener) IOException(java.io.IOException) IvyEvent(org.apache.ivy.core.event.IvyEvent)

Aggregations

IvyEvent (org.apache.ivy.core.event.IvyEvent)2 IvyListener (org.apache.ivy.core.event.IvyListener)2 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 IvyThread (org.apache.ivy.core.IvyThread)1 EndRetrieveArtifactEvent (org.apache.ivy.core.event.retrieve.EndRetrieveArtifactEvent)1 EndRetrieveEvent (org.apache.ivy.core.event.retrieve.EndRetrieveEvent)1 StartRetrieveArtifactEvent (org.apache.ivy.core.event.retrieve.StartRetrieveArtifactEvent)1 StartRetrieveEvent (org.apache.ivy.core.event.retrieve.StartRetrieveEvent)1 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)1 ResolveReport (org.apache.ivy.core.report.ResolveReport)1 Test (org.junit.Test)1