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.eclipse.aether.repository;
20  
21  import org.eclipse.aether.RepositoryException;
22  
23  /**
24   * Thrown in case of an unsupported local repository type.
25   */
26  public class NoLocalRepositoryManagerException extends RepositoryException {
27  
28      private final transient LocalRepository repository;
29  
30      /**
31       * Creates a new exception with the specified repository.
32       *
33       * @param repository The local repository for which no support is available, may be {@code null}.
34       */
35      public NoLocalRepositoryManagerException(LocalRepository repository) {
36          this(repository, toMessage(repository));
37      }
38  
39      /**
40       * Creates a new exception with the specified repository and detail message.
41       *
42       * @param repository The local repository for which no support is available, may be {@code null}.
43       * @param message The detail message, may be {@code null}.
44       */
45      public NoLocalRepositoryManagerException(LocalRepository repository, String message) {
46          super(message);
47          this.repository = repository;
48      }
49  
50      /**
51       * Creates a new exception with the specified repository and cause.
52       *
53       * @param repository The local repository for which no support is available, may be {@code null}.
54       * @param cause The exception that caused this one, may be {@code null}.
55       */
56      public NoLocalRepositoryManagerException(LocalRepository repository, Throwable cause) {
57          this(repository, toMessage(repository), cause);
58      }
59  
60      /**
61       * Creates a new exception with the specified repository, detail message and cause.
62       *
63       * @param repository The local repository for which no support is available, may be {@code null}.
64       * @param message The detail message, may be {@code null}.
65       * @param cause The exception that caused this one, may be {@code null}.
66       */
67      public NoLocalRepositoryManagerException(LocalRepository repository, String message, Throwable cause) {
68          super(message, cause);
69          this.repository = repository;
70      }
71  
72      private static String toMessage(LocalRepository repository) {
73          if (repository != null) {
74              return "No manager available for local repository ("
75                      + repository.getBasedir().getAbsolutePath() + ") of type " + repository.getContentType();
76          } else {
77              return "No manager available for local repository";
78          }
79      }
80  
81      /**
82       * Gets the local repository whose content type is not supported.
83       *
84       * @return The unsupported local repository or {@code null} if unknown.
85       */
86      public LocalRepository getRepository() {
87          return repository;
88      }
89  }