|
| 1 | +/* |
| 2 | + * SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com |
| 3 | + * SPDX-License-Identifier: MIT |
| 4 | + */ |
| 5 | +package org.eolang.maven; |
| 6 | + |
| 7 | +import java.util.function.Supplier; |
| 8 | +import javax.annotation.Nonnull; |
| 9 | +import org.apache.maven.model.Dependency; |
| 10 | + |
| 11 | +/** |
| 12 | + * Wrapped for maven model {@link Dependency}. |
| 13 | + * |
| 14 | + * @since 0.54 |
| 15 | + */ |
| 16 | +final class Dep implements Comparable<Dep>, Supplier<Dependency> { |
| 17 | + |
| 18 | + /** |
| 19 | + * The dependency. |
| 20 | + */ |
| 21 | + private final Dependency dependency; |
| 22 | + |
| 23 | + /** |
| 24 | + * Ctor. |
| 25 | + */ |
| 26 | + Dep() { |
| 27 | + this(new Dependency()); |
| 28 | + } |
| 29 | + |
| 30 | + /** |
| 31 | + * Ctor. |
| 32 | + * @param dep The dependency |
| 33 | + */ |
| 34 | + Dep(final Dependency dep) { |
| 35 | + this.dependency = dep; |
| 36 | + } |
| 37 | + |
| 38 | + @Override |
| 39 | + public String toString() { |
| 40 | + final String ret; |
| 41 | + if (this.dependency.getClassifier() == null || this.dependency.getClassifier().isEmpty()) { |
| 42 | + ret = String.format( |
| 43 | + "%s:%s:%s", |
| 44 | + this.dependency.getGroupId(), |
| 45 | + this.dependency.getArtifactId(), |
| 46 | + this.dependency.getVersion() |
| 47 | + ); |
| 48 | + } else { |
| 49 | + ret = String.format( |
| 50 | + "%s:%s:%s:%s", |
| 51 | + this.dependency.getGroupId(), |
| 52 | + this.dependency.getArtifactId(), |
| 53 | + this.dependency.getClassifier(), |
| 54 | + this.dependency.getVersion() |
| 55 | + ); |
| 56 | + } |
| 57 | + return ret; |
| 58 | + } |
| 59 | + |
| 60 | + @Override |
| 61 | + public int compareTo(@Nonnull final Dep other) { |
| 62 | + return this.toString().compareTo(String.valueOf(other)); |
| 63 | + } |
| 64 | + |
| 65 | + @Override |
| 66 | + public boolean equals(@Nonnull final Object other) { |
| 67 | + return this.toString().equals(String.valueOf(other)); |
| 68 | + } |
| 69 | + |
| 70 | + @Override |
| 71 | + public int hashCode() { |
| 72 | + return this.toString().hashCode(); |
| 73 | + } |
| 74 | + |
| 75 | + @Override |
| 76 | + public Dependency get() { |
| 77 | + return this.dependency; |
| 78 | + } |
| 79 | + |
| 80 | + /** |
| 81 | + * Set group id. |
| 82 | + * @param group Group id |
| 83 | + * @return Self |
| 84 | + */ |
| 85 | + Dep withGroupId(final String group) { |
| 86 | + this.dependency.setGroupId(group); |
| 87 | + return this; |
| 88 | + } |
| 89 | + |
| 90 | + /** |
| 91 | + * Set artifact id. |
| 92 | + * @param artifact Artifact id |
| 93 | + * @return Self |
| 94 | + */ |
| 95 | + Dep withArtifactId(final String artifact) { |
| 96 | + this.dependency.setArtifactId(artifact); |
| 97 | + return this; |
| 98 | + } |
| 99 | + |
| 100 | + /** |
| 101 | + * Set version. |
| 102 | + * @param version Version |
| 103 | + * @return Self |
| 104 | + */ |
| 105 | + Dep withVersion(final String version) { |
| 106 | + this.dependency.setVersion(version); |
| 107 | + return this; |
| 108 | + } |
| 109 | + |
| 110 | + /** |
| 111 | + * Set scope. |
| 112 | + * @param scope Scope |
| 113 | + * @return Self |
| 114 | + */ |
| 115 | + Dep withScope(final String scope) { |
| 116 | + this.dependency.setScope(scope); |
| 117 | + return this; |
| 118 | + } |
| 119 | + |
| 120 | + /** |
| 121 | + * Set classifier id. |
| 122 | + * @param classifier Classifier |
| 123 | + * @return Self |
| 124 | + */ |
| 125 | + Dep withClassifier(final String classifier) { |
| 126 | + this.dependency.setClassifier(classifier); |
| 127 | + return this; |
| 128 | + } |
| 129 | +} |
0 commit comments