001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.eclipse.aether.transfer; 020 021import org.eclipse.aether.RepositoryException; 022import org.eclipse.aether.repository.RemoteRepository; 023 024/** 025 * Thrown when a transfer could not be performed because a remote repository is not accessible in offline mode. 026 */ 027public class RepositoryOfflineException extends RepositoryException { 028 029 private final transient RemoteRepository repository; 030 031 private static String getMessage(RemoteRepository repository) { 032 if (repository == null) { 033 return "Cannot access remote repositories in offline mode"; 034 } else { 035 return "Cannot access " + repository.getId() + " (" + repository.getUrl() + ") in offline mode"; 036 } 037 } 038 039 /** 040 * Creates a new exception with the specified repository. 041 * 042 * @param repository The inaccessible remote repository, may be {@code null}. 043 */ 044 public RepositoryOfflineException(RemoteRepository repository) { 045 super(getMessage(repository)); 046 this.repository = repository; 047 } 048 049 /** 050 * Creates a new exception with the specified repository and detail message. 051 * 052 * @param repository The inaccessible remote repository, may be {@code null}. 053 * @param message The detail message, may be {@code null}. 054 */ 055 public RepositoryOfflineException(RemoteRepository repository, String message) { 056 super(message); 057 this.repository = repository; 058 } 059 060 /** 061 * Gets the remote repository that could not be accessed due to offline mode. 062 * 063 * @return The inaccessible remote repository or {@code null} if unknown. 064 */ 065 public RemoteRepository getRepository() { 066 return repository; 067 } 068}