/*
 * Copyright to the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.rioproject.resolver.aether.util;

import java.io.PrintStream;

import org.sonatype.aether.AbstractRepositoryListener;
import org.sonatype.aether.RepositoryEvent;

/**
 * A simplistic repository listener that logs events to the console.
 */
public class ConsoleRepositoryListener extends AbstractRepositoryListener {
    private PrintStream out;

    public ConsoleRepositoryListener() {
        this(null);
    }

    public ConsoleRepositoryListener(PrintStream out) {
        this.out = (out != null) ? out : System.out;
    }

    public void artifactDeployed(RepositoryEvent event) {
        out.println("Deployed " + event.getArtifact() + " to " + event.getRepository());
    }

    public void artifactDeploying(RepositoryEvent event) {
        //out.println("Deploying " + event.getArtifact() + " to " + event.getRepository());
    }

    public void artifactDescriptorInvalid(RepositoryEvent event) {
        out.println("Invalid artifact descriptor for " + event.getArtifact() + ": "
                    + event.getException().getMessage());
    }

    public void artifactDescriptorMissing(RepositoryEvent event) {
        out.println("Missing artifact descriptor for " + event.getArtifact());
    }

    public void artifactInstalled(RepositoryEvent event) {
        out.println("Installed " + event.getArtifact() + " to " + event.getFile());
    }

    public void artifactInstalling(RepositoryEvent event) {
        //out.println("Installing " + event.getArtifact() + " to " + event.getFile());
    }

    public void artifactResolved(RepositoryEvent event) {
        //out.println("Resolved artifact " + event.getArtifact() + " from " + event.getRepository());
    }

    public void artifactDownloading(RepositoryEvent event) {
        //out.println("Downloading artifact " + event.getArtifact() + " from " + event.getRepository());
    }

    public void artifactDownloaded(RepositoryEvent event) {
        //out.println("Downloaded artifact " + event.getArtifact() + " from " + event.getRepository());
    }

    public void artifactResolving(RepositoryEvent event) {
        //out.println("Resolving artifact " + event.getArtifact());
    }

    public void metadataDeployed(RepositoryEvent event) {
        out.println("Deployed " + event.getMetadata() + " to " + event.getRepository());
    }

    public void metadataDeploying(RepositoryEvent event) {
        //out.println("Deploying " + event.getMetadata() + " to " + event.getRepository());
    }

    public void metadataInstalled(RepositoryEvent event) {
        out.println("Installed " + event.getMetadata() + " to " + event.getFile());
    }

    public void metadataInstalling(RepositoryEvent event) {
        //out.println("Installing " + event.getMetadata() + " to " + event.getFile());
    }

    public void metadataInvalid(RepositoryEvent event) {
        out.println("Invalid metadata " + event.getMetadata());
    }

    public void metadataResolved(RepositoryEvent event) {
        //out.println("Resolved metadata " + event.getMetadata() + " from " + event.getRepository());
    }

    public void metadataResolving(RepositoryEvent event) {
        //out.println("Resolving metadata " + event.getMetadata() + " from " + event.getRepository());
    }

}

@@ -680,16 +680,44 @@
 tStream;
+%0Aimport java.util.logging.*;
 %0A%0Aimport
@@ -991,16 +991,118 @@
 eam out;
+%0A    private final static Logger logger = Logger.getLogger(ConsoleRepositoryListener.class.getName());
 %0A%0A    pu
@@ -2322,34 +2322,80 @@
 vent) %7B%0A        
-//
+if(logger.isLoggable(Level.FINEST))%0A            
 out.println(%22Res
@@ -2538,34 +2538,80 @@
 vent) %7B%0A        
-//
+if(logger.isLoggable(Level.FINEST))%0A            
 out.println(%22Dow
@@ -2756,34 +2756,80 @@
 vent) %7B%0A        
-//
+if(logger.isLoggable(Level.FINEST))%0A            
 out.println(%22Dow
@@ -2972,34 +2972,80 @@
 vent) %7B%0A        
-//
+if(logger.isLoggable(Level.FINEST))%0A            
 out.println(%22Res
@@ -3895,34 +3895,80 @@
 vent) %7B%0A        
-//
+if(logger.isLoggable(Level.FINEST))%0A            
 out.println(%22Res
@@ -4109,34 +4109,80 @@
 vent) %7B%0A        
-//
+if(logger.isLoggable(Level.FINEST))%0A            
 out.println(%22Res

Use Logger.isLoggable() to provide increased output during artifact and metadata resolution