Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
MavenRootArtifact |
|
| 2.0;2 | ||||
MavenRootArtifact$AjcClosure1 |
|
| 2.0;2 |
1 | 2 | /** |
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 com.jcabi.aspects.Cacheable; | |
33 | import com.jcabi.log.Logger; | |
34 | import java.util.Collection; | |
35 | import java.util.List; | |
36 | import javax.validation.constraints.NotNull; | |
37 | import lombok.EqualsAndHashCode; | |
38 | import org.apache.maven.artifact.Artifact; | |
39 | import org.apache.maven.model.Exclusion; | |
40 | ||
41 | /** | |
42 | * One root artifact found in the project. | |
43 | * | |
44 | * @author Yegor Bugayenko (yegor@tpc2.com) | |
45 | * @version $Id$ | |
46 | * @since 0.7.16 | |
47 | */ | |
48 | 25 | @EqualsAndHashCode(of = { "art", "exclusions" }) |
49 | final class MavenRootArtifact { | |
50 | ||
51 | /** | |
52 | * The artifact. | |
53 | */ | |
54 | @NotNull | |
55 | private final transient Artifact art; | |
56 | ||
57 | /** | |
58 | * Exclusions. | |
59 | */ | |
60 | @NotNull | |
61 | private final transient Collection<Exclusion> exclusions; | |
62 | ||
63 | /** | |
64 | * This artifact child artifacts. | |
65 | */ | |
66 | @NotNull | |
67 | private final transient Collection<Artifact> chldrn; | |
68 | ||
69 | /** | |
70 | * Ctor. | |
71 | * @param artifact The artifact | |
72 | * @param excl Exclusions | |
73 | * @param chld Child artifacts | |
74 | */ | |
75 | protected MavenRootArtifact(@NotNull final Artifact artifact, | |
76 | @NotNull final List<Exclusion> excl, | |
77 | 2 | @NotNull final Collection<Artifact> chld) { |
78 | 2 | this.art = artifact; |
79 | 2 | this.exclusions = excl; |
80 | 2 | this.chldrn = chld; |
81 | 2 | } |
82 | ||
83 | /** | |
84 | * {@inheritDoc} | |
85 | */ | |
86 | @Override | |
87 | public String toString() { | |
88 | 2 | final StringBuilder text = new StringBuilder(); |
89 | 2 | text.append( |
90 | Logger.format( | |
91 | "%s:%s:%s:%d", | |
92 | this.art.getGroupId(), | |
93 | this.art.getArtifactId(), | |
94 | this.art.getVersion(), | |
95 | this.exclusions.size() | |
96 | ) | |
97 | ); | |
98 | 2 | for (final Artifact child : this.children()) { |
99 | 1 | text.append("\n ").append(child); |
100 | 1 | if (this.excluded(child)) { |
101 | 0 | text.append(" (excluded)"); |
102 | } | |
103 | 1 | } |
104 | 2 | return text.toString(); |
105 | } | |
106 | ||
107 | /** | |
108 | * Get artifact. | |
109 | * @return The artifact | |
110 | */ | |
111 | public Artifact artifact() { | |
112 | 0 | return this.art; |
113 | } | |
114 | ||
115 | /** | |
116 | * Get all dependencies of this root artifact. | |
117 | * @return The list of artifacts | |
118 | */ | |
119 | @Cacheable(forever = true) | |
120 | @SuppressWarnings("unchecked") | |
121 | public Collection<Artifact> children() { | |
122 | 5 | return this.chldrn; |
123 | } | |
124 | ||
125 | /** | |
126 | * Is this one should be excluded? | |
127 | * @param artifact The artifact to check | |
128 | * @return TRUE if it should be excluded | |
129 | */ | |
130 | public boolean excluded(@NotNull final Artifact artifact) { | |
131 | 1 | boolean excluded = false; |
132 | 1 | for (final Exclusion exclusion : this.exclusions) { |
133 | 0 | if (exclusion.getArtifactId().equals(artifact.getArtifactId()) |
134 | && exclusion.getGroupId().equals(artifact.getGroupId())) { | |
135 | 0 | excluded = true; |
136 | 0 | break; |
137 | } | |
138 | 0 | } |
139 | 1 | return excluded; |
140 | } | |
141 | ||
142 | } |