View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.internal.aether;
20  
21  import java.io.FileNotFoundException;
22  
23  import org.eclipse.aether.AbstractRepositoryListener;
24  import org.eclipse.aether.RepositoryEvent;
25  import org.eclipse.aether.transfer.MetadataNotFoundException;
26  import org.slf4j.Logger;
27  
28  /**
29   */
30  class LoggingRepositoryListener extends AbstractRepositoryListener {
31  
32      private final Logger logger;
33  
34      LoggingRepositoryListener(Logger logger) {
35          this.logger = logger;
36      }
37  
38      @Override
39      public void artifactInstalling(RepositoryEvent event) {
40          logger.info("Installing {} to {}", event.getArtifact().getFile(), event.getFile());
41      }
42  
43      @Override
44      public void metadataInstalling(RepositoryEvent event) {
45          logger.debug("Installing {} to {}", event.getMetadata(), event.getFile());
46      }
47  
48      @Override
49      public void metadataResolved(RepositoryEvent event) {
50          Exception e = event.getException();
51          if (e != null) {
52              if (e instanceof MetadataNotFoundException) {
53                  logger.debug(e.getMessage());
54              } else if (logger.isDebugEnabled()) {
55                  logger.warn(e.getMessage(), e);
56              } else {
57                  logger.warn(e.getMessage());
58              }
59          }
60      }
61  
62      @Override
63      public void metadataInvalid(RepositoryEvent event) {
64          Exception exception = event.getException();
65  
66          Object metadata;
67          if (event.getMetadata().getFile() != null) {
68              metadata = event.getMetadata().getFile();
69          } else {
70              metadata = event.getMetadata();
71          }
72  
73          String errorType = " is invalid";
74          if (exception instanceof FileNotFoundException) {
75              errorType = " is inaccessible";
76          }
77  
78          String msg = "";
79          if (exception != null) {
80              msg = ": " + exception.getMessage();
81          }
82  
83          if (logger.isDebugEnabled()) {
84              logger.warn("The metadata {} {}{}", metadata, errorType, msg, exception);
85          } else {
86              logger.warn("The metadata {} {}{}", metadata, errorType, msg);
87          }
88      }
89  
90      @Override
91      public void artifactDescriptorInvalid(RepositoryEvent event) {
92          // The exception stack trace is not really interesting here
93          logger.warn(
94                  "The POM for {} is invalid, transitive dependencies (if any) will not be available: {}",
95                  event.getArtifact(),
96                  event.getException().getMessage());
97      }
98  
99      @Override
100     public void artifactDescriptorMissing(RepositoryEvent event) {
101         logger.warn("The POM for {} is missing, no dependency information available", event.getArtifact());
102     }
103 }