View Javadoc

1   /*
2    * Copyright 2013 smartics, Kronseder & Reiner GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package de.smartics.maven.plugin.jboss.modules.aether;
17  
18  import org.slf4j.Logger;
19  import org.slf4j.LoggerFactory;
20  import org.sonatype.aether.AbstractRepositoryListener;
21  import org.sonatype.aether.RepositoryEvent;
22  
23  /**
24   * Uses the underlying logger to report on repository events.
25   */
26  class RepositoryLogListener extends AbstractRepositoryListener
27  {
28    // ********************************* Fields *********************************
29  
30    // --- constants ------------------------------------------------------------
31  
32    // --- members --------------------------------------------------------------
33  
34    /**
35     * The logger to log to.
36     */
37    private final Logger log;
38  
39    // ****************************** Initializer *******************************
40  
41    // ****************************** Constructors ******************************
42  
43    /**
44     * Convenience constructor to use an internally created logger with the name
45     * of this class.
46     */
47    public RepositoryLogListener()
48    {
49      this(LoggerFactory.getLogger(RepositoryLogListener.class));
50    }
51  
52    /**
53     * Default constructor.
54     */
55    public RepositoryLogListener(final Logger log)
56    {
57      this.log = log;
58    }
59  
60    // ****************************** Inner Classes *****************************
61  
62    // ********************************* Methods ********************************
63  
64    // --- init -----------------------------------------------------------------
65  
66    // --- get&set --------------------------------------------------------------
67  
68    // --- business -------------------------------------------------------------
69  
70    // ... descriptor handling ..................................................
71  
72    /**
73     * {@inheritDoc}
74     * <p>
75     * Logs at warn level.
76     * </p>
77     *
78     * @see org.sonatype.aether.AbstractRepositoryListener#artifactDescriptorMissing(org.sonatype.aether.RepositoryEvent)
79     */
80    public void artifactDescriptorMissing(final RepositoryEvent event)
81    {
82      log.warn("Missing descriptor for artifact '{}'.", event.getArtifact());
83    }
84  
85    /**
86     * {@inheritDoc}
87     * <p>
88     * Logs at warn level.
89     * </p>
90     *
91     * @see org.sonatype.aether.AbstractRepositoryListener#artifactDescriptorInvalid(org.sonatype.aether.RepositoryEvent)
92     */
93    public void artifactDescriptorInvalid(final RepositoryEvent event)
94    {
95      log.warn("Invalid descriptor for artifact '{}': {}", event.getArtifact(),
96          event.getException().getMessage());
97    }
98  
99    // ... meta data resolving ..................................................
100 
101   /**
102    * {@inheritDoc}
103    * <p>
104    * Logs at warn level.
105    * </p>
106    *
107    * @see org.sonatype.aether.AbstractRepositoryListener#metadataInvalid(org.sonatype.aether.RepositoryEvent)
108    */
109   public void metadataInvalid(final RepositoryEvent event)
110   {
111     log.warn("Invalid metadata: {}", event.getMetadata());
112   }
113 
114   /**
115    * {@inheritDoc}
116    * <p>
117    * Logs at debug level.
118    * </p>
119    *
120    * @see org.sonatype.aether.AbstractRepositoryListener#metadataResolving(org.sonatype.aether.RepositoryEvent)
121    */
122   public void metadataResolving(final RepositoryEvent event)
123   {
124     log.debug("Resolving metadata '{}' from '{}'.", event.getMetadata(),
125         event.getRepository());
126   }
127 
128   /**
129    * {@inheritDoc}
130    * <p>
131    * Logs at debug level.
132    * </p>
133    *
134    * @see org.sonatype.aether.AbstractRepositoryListener#metadataResolved(org.sonatype.aether.RepositoryEvent)
135    */
136   public void metadataResolved(final RepositoryEvent event)
137   {
138     log.debug("Resolved metadata '{}' from '{}'.", event.getMetadata(),
139         event.getRepository());
140   }
141 
142   // ... artifact resolving ...................................................
143 
144   /**
145    * {@inheritDoc}
146    * <p>
147    * Logs at debug level.
148    * </p>
149    *
150    * @see org.sonatype.aether.AbstractRepositoryListener#artifactResolving(org.sonatype.aether.RepositoryEvent)
151    */
152   public void artifactResolving(final RepositoryEvent event)
153   {
154     log.debug("Resolving artifact '{}'." + event.getArtifact());
155   }
156 
157   /**
158    * {@inheritDoc}
159    * <p>
160    * Logs at debug level.
161    * </p>
162    *
163    * @see org.sonatype.aether.AbstractRepositoryListener#artifactResolved(org.sonatype.aether.RepositoryEvent)
164    */
165   public void artifactResolved(final RepositoryEvent event)
166   {
167     log.debug("Resolved artifact '{}' from '{}'.", event.getArtifact(),
168         event.getRepository());
169   }
170 
171   // ... artifact downloading .................................................
172 
173   /**
174    * {@inheritDoc}
175    * <p>
176    * Logs at debug level.
177    * </p>
178    *
179    * @see org.sonatype.aether.AbstractRepositoryListener#artifactDownloading(org.sonatype.aether.RepositoryEvent)
180    */
181   public void artifactDownloading(final RepositoryEvent event)
182   {
183     log.debug("Downloading artifact '{}' from '{}'.", event.getArtifact(),
184         event.getRepository());
185   }
186 
187   /**
188    * {@inheritDoc}
189    * <p>
190    * Logs at debug level.
191    * </p>
192    *
193    * @see org.sonatype.aether.AbstractRepositoryListener#artifactDownloaded(org.sonatype.aether.RepositoryEvent)
194    */
195   public void artifactDownloaded(final RepositoryEvent event)
196   {
197     log.debug("Downloaded artifact '{}' from '{}'.", event.getArtifact(),
198         event.getRepository());
199   }
200 
201   // --- object basics --------------------------------------------------------
202 
203 }