Example usage for org.apache.maven.repository ArtifactTransferListener ArtifactTransferListener

List of usage examples for org.apache.maven.repository ArtifactTransferListener ArtifactTransferListener

Introduction

In this page you can find the example usage for org.apache.maven.repository ArtifactTransferListener ArtifactTransferListener.

Prototype

ArtifactTransferListener

Source Link

Usage

From source file:org.teiid.plugin.maven.GeneratorMojo.java

License:Open Source License

private File getWildflyDist() {
    String artifactId = "teiid"; //$NON-NLS-1$
    String classifier = "wildfly-dist"; //$NON-NLS-1$
    String type = "zip"; //$NON-NLS-1$
    PluginDescriptor plugin = (PluginDescriptor) getPluginContext().get("pluginDescriptor"); //$NON-NLS-1$
    String groupId = plugin.getGroupId();
    String version = plugin.getVersion();
    //        String version = "9.1.0.Alpha2";
    String line = "-";
    String artifact = artifactId + line + version + line + classifier + "." + type;

    ArtifactRepository jbossDeveloper = null;
    for (ArtifactRepository repository : remoteRepositories) {
        if (repository.getUrl().startsWith("https://repository.jboss.org/nexus/content/groups/developer")) { //$NON-NLS-1$
            jbossDeveloper = repository;
            break;
        }// w  ww  . ja v  a  2 s  .co m
    }

    groupId = groupId.replaceAll("\\.", File.separator) + File.separator + artifactId + File.separator; //$NON-NLS-1$
    String remotePath = groupId + version + File.separator + artifact;
    getLog().info("Download " + artifact + " from " + jbossDeveloper.getUrl()); //$NON-NLS-1$ //$NON-NLS-2$
    File destination = null;
    try {
        destination = File.createTempFile(artifactId, "." + type);
        destination.deleteOnExit();
        repoSystem.retrieve(jbossDeveloper, destination, remotePath, new ArtifactTransferListener() {

            @Override
            public boolean isShowChecksumEvents() {
                return false;
            }

            @Override
            public void setShowChecksumEvents(boolean showChecksumEvents) {
            }

            @Override
            public void transferInitiated(ArtifactTransferEvent transferEvent) {
            }

            @Override
            public void transferStarted(ArtifactTransferEvent transferEvent) {
                getLog().info("download start"); //$NON-NLS-1$
            }

            @Override
            public void transferProgress(ArtifactTransferEvent transferEvent) {
            }

            @Override
            public void transferCompleted(ArtifactTransferEvent transferEvent) {
                getLog().info("download completed"); //$NON-NLS-1$
            }
        });
    } catch (IOException | ArtifactTransferFailedException | ArtifactDoesNotExistException e) {
    }

    return destination;
}