
com.ning.maven.plugins.dependencyversionscheck.version.VersionElement Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of maven-dependency-versions-check-plugin Show documentation
Show all versions of maven-dependency-versions-check-plugin Show documentation
The maven-dependency-versions-check-plugin is a Maven plugin
that verifies that the resolved versions of dependencies are at
least the versions specified by the dependencies (or their
dependencies etc.) if not higher.
More specifically, it will check that
* The resolved version of every dependency declared explicitly
in the current POM is the same or a newer one than what was
stated. If the resolved version has a higher major version
number than the declared version, then the plugin will issue
a warning if configured to do so.
Note that enforced declared versions are ignored by the plugin.
* For every explicitly declared dependency in the current POM, all
its dependency versions are met. I.e. the resolved versions for
all dependencies in that dependency's POM are the same or higher
than the one stated in that dependency's POM. This is basically
the same check as the one above, but using the dependency's POM!
Also, if the current POM has exclusions specified for the
dependency, then these transitive dependencies are ignored
when checking this particular dependency.
/*
* Copyright (C) 2011 Henning Schmiedehausen
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package com.ning.maven.plugins.dependencyversionscheck.version;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
/**
* Represents a single element of a version number.
*/
public final class VersionElement
{
/** The raw value of the element. */
private final String element;
/** OR'ed list of Flags in Version. */
private final long flags;
/** OR'ed list of Divider flags in Version. */
private final long divider;
/** The raw value of the divider char (the character immediately following the version element) or 0 if there is no divider char. */
private final char dividerChar;
public VersionElement(final String element, final long flags, final long divider, final char dividerChar)
{
this.element = element;
this.flags = flags;
this.divider = divider;
this.dividerChar = dividerChar;
}
public String getElement()
{
return element;
}
public long getFlags()
{
return flags;
}
public long getDivider()
{
return divider;
}
public char getDividerChar()
{
return dividerChar;
}
public boolean hasNumbers()
{
return (flags & Version.NUMBERS) != 0;
}
public boolean isNumber()
{
return (flags & Version.ALL_NUMBERS) != 0;
}
public boolean hasLetters()
{
return (flags & Version.LETTERS) != 0;
}
public boolean hasDot()
{
return (divider & Version.DOT_DIVIDER) != 0;
}
public boolean hasEndOfVersion()
{
return (divider & Version.END_OF_VERSION) != 0;
}
public int getNumber()
{
if (!hasNumbers()) {
return 0;
}
else {
final String result;
if (isNumber()) {
result = element;
}
else {
final StringBuilder sb = new StringBuilder();
for (int i = 0 ; i < element.length(); i++) {
if (Character.isDigit(element.charAt(i))) {
sb.append(element.charAt(i));
}
}
result = sb.toString();
}
return Integer.parseInt(result, 10);
}
}
public String toString()
{
final StringBuilder sb = new StringBuilder();
sb.append(element);
if ((flags & Version.END_OF_VERSION) == 0) {
sb.append(dividerChar);
}
return sb.toString();
}
public boolean equals(final Object other)
{
if (!(other instanceof VersionElement))
return false;
VersionElement castOther = (VersionElement) other;
return new EqualsBuilder().append(element, castOther.element).append(flags, castOther.flags).append(divider, castOther.divider).append(dividerChar, castOther.dividerChar).isEquals();
}
private transient int hashCode;
public int hashCode()
{
if (hashCode == 0) {
hashCode = new HashCodeBuilder().append(element).append(flags).append(divider).append(dividerChar).toHashCode();
}
return hashCode;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy