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