| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| Repository |
|
| 2.0;2 |
| 1 | /** | |
| 2 | * Copyright (c) 2012-2014, jcabi.com | |
| 3 | * All rights reserved. | |
| 4 | * | |
| 5 | * Redistribution and use in source and binary forms, with or without | |
| 6 | * modification, are permitted provided that the following conditions | |
| 7 | * are met: 1) Redistributions of source code must retain the above | |
| 8 | * copyright notice, this list of conditions and the following | |
| 9 | * disclaimer. 2) Redistributions in binary form must reproduce the above | |
| 10 | * copyright notice, this list of conditions and the following | |
| 11 | * disclaimer in the documentation and/or other materials provided | |
| 12 | * with the distribution. 3) Neither the name of the jcabi.com nor | |
| 13 | * the names of its contributors may be used to endorse or promote | |
| 14 | * products derived from this software without specific prior written | |
| 15 | * permission. | |
| 16 | * | |
| 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 18 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT | |
| 19 | * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | |
| 20 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL | |
| 21 | * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | |
| 22 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
| 23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
| 24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
| 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
| 26 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
| 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | |
| 28 | * OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 29 | */ | |
| 30 | package com.jcabi.aether; | |
| 31 | ||
| 32 | import java.util.Collection; | |
| 33 | import java.util.LinkedList; | |
| 34 | import java.util.List; | |
| 35 | import org.sonatype.aether.repository.Authentication; | |
| 36 | import org.sonatype.aether.repository.Proxy; | |
| 37 | import org.sonatype.aether.repository.RemoteRepository; | |
| 38 | import org.sonatype.aether.repository.RepositoryPolicy; | |
| 39 | ||
| 40 | /** | |
| 41 | * Parameter holder for RemoteRepository. | |
| 42 | * @author Krzysztof Krason (Krzysztof.Krason@gmail.com) | |
| 43 | * @version $Id$ | |
| 44 | */ | |
| 45 | public final class Repository { | |
| 46 | /** | |
| 47 | * Id of repository. | |
| 48 | */ | |
| 49 | private final transient String identifier; | |
| 50 | ||
| 51 | /** | |
| 52 | * Repository content type. | |
| 53 | */ | |
| 54 | private final transient String type; | |
| 55 | ||
| 56 | /** | |
| 57 | * Repository URL. | |
| 58 | */ | |
| 59 | private final transient String url; | |
| 60 | ||
| 61 | /** | |
| 62 | * Repository release policy. | |
| 63 | */ | |
| 64 | private final transient RepositoryPolicy release; | |
| 65 | ||
| 66 | /** | |
| 67 | * Repository snapshot policy. | |
| 68 | */ | |
| 69 | private final transient RepositoryPolicy snapshot; | |
| 70 | ||
| 71 | /** | |
| 72 | * Proxy settings. | |
| 73 | */ | |
| 74 | private final transient Proxy proxy; | |
| 75 | ||
| 76 | /** | |
| 77 | * Authentication settings. | |
| 78 | */ | |
| 79 | private final transient Authentication authentication; | |
| 80 | ||
| 81 | /** | |
| 82 | * Collection of mirrored repisotories. | |
| 83 | */ | |
| 84 | private final transient Collection<Repository> mirrored; | |
| 85 | ||
| 86 | /** | |
| 87 | * Is this a repository manager. | |
| 88 | */ | |
| 89 | private final transient boolean manager; | |
| 90 | ||
| 91 | /** | |
| 92 | * Constructor. | |
| 93 | * @param remote Source of data. | |
| 94 | */ | |
| 95 | @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") | |
| 96 | 31 | public Repository(final RemoteRepository remote) { |
| 97 | 31 | this.identifier = remote.getId(); |
| 98 | 31 | this.type = remote.getContentType(); |
| 99 | 31 | this.url = remote.getUrl(); |
| 100 | 31 | this.release = remote.getPolicy(false); |
| 101 | 31 | this.snapshot = remote.getPolicy(true); |
| 102 | 31 | this.proxy = remote.getProxy(); |
| 103 | 31 | this.authentication = remote.getAuthentication(); |
| 104 | 31 | this.manager = remote.isRepositoryManager(); |
| 105 | 31 | this.mirrored = new LinkedList<Repository>(); |
| 106 | for (final RemoteRepository mremote | |
| 107 | 31 | : remote.getMirroredRepositories()) { |
| 108 | 0 | this.mirrored.add(new Repository(mremote)); |
| 109 | 0 | } |
| 110 | 31 | } |
| 111 | ||
| 112 | /** | |
| 113 | * Get remote repository. | |
| 114 | * @return Remote repository. | |
| 115 | */ | |
| 116 | public RemoteRepository remote() { | |
| 117 | 147 | final RemoteRepository remote = new RemoteRepository(); |
| 118 | 147 | remote.setId(this.identifier); |
| 119 | 147 | remote.setContentType(this.type); |
| 120 | 147 | remote.setUrl(this.url); |
| 121 | 147 | remote.setPolicy(false, this.release); |
| 122 | 147 | remote.setPolicy(true, this.snapshot); |
| 123 | 147 | remote.setProxy(this.proxy); |
| 124 | 147 | remote.setAuthentication(this.authentication); |
| 125 | 147 | remote.setRepositoryManager(this.manager); |
| 126 | 147 | final List<RemoteRepository> remotes = |
| 127 | new LinkedList<RemoteRepository>(); | |
| 128 | 147 | remote.setMirroredRepositories(remotes); |
| 129 | 147 | for (final Repository repo : this.mirrored) { |
| 130 | 0 | remotes.add(repo.remote()); |
| 131 | 0 | } |
| 132 | 147 | return remote; |
| 133 | } | |
| 134 | } |