Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty qualifier is represented by an empty string, to avoid nullpointer ... #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class MavenRepositoryClient {
private static final String FILES_TO_IGNORE = "^maven-metadata.*$|^archetype-catalog.*$";
private static final String NONE = "";
private static final Pattern PATTERN = Pattern.compile(
"href=[\n\r ]*\"([^\"]*)\"", Pattern.CASE_INSENSITIVE);
"<a\\b[^>]*href=[\n\r ]*\"([^\"]*)\"", Pattern.CASE_INSENSITIVE);

private static final Logger logger = Logger
.getLogger(RepositoryClientParameterDefinition.class);
Expand Down Expand Up @@ -306,10 +306,11 @@ private static void parseHtml(String responseBody, List<String> matches) {
// extract the version only
if (match.toLowerCase().startsWith("http")) {
int idx = match.lastIndexOf('/');
match = match.substring(0, idx);
match = match.substring(idx + 1);
}
if (!"..".equals(match)
&& !match.toLowerCase().startsWith("http")) {
&& !match.toLowerCase().startsWith("http")
&& !match.matches(FILES_TO_IGNORE)) {
matches.add(match);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public int compareTo(Version ver) {
}
}
if (result == 0) {
result = Collator.getInstance().compare(qualifier,
result = Collator.getInstance().compare(getQualifier(),
ver.getQualifier());
}
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,22 @@ public void testCompareBugfix() {
assertTrue(v1.compareTo(v2) == -1);
}

@Test
public void testCompareNullPointer() {
Version v1 = new Version("1.2.3.4.foo");
Version v2 = new Version("1.2.3.4");
assertEquals(1, v1.compareTo(v2));
assertEquals(-1, v2.compareTo(v1));
assertEquals(0, v2.compareTo(v2));
assertEquals(0, v1.compareTo(v1));
}

@Test
public void testCompareNullPointer2() {
Version v1 = new Version("1");
assertEquals(0, v1.compareTo(v1));
}

@Test
public void testCompareMinor() {
Version v1 = new Version("1.0.0.0.yyy.xxx.qualifier");
Expand Down Expand Up @@ -207,6 +223,18 @@ public void testEqual() {
assertEquals("Versions are not equal", v, v);
}

@Test
public void testEqual2() {
Version v = new Version("1.2.3.4.yyy.xxx");
assertEquals("Versions are not equal", v, v);
}

@Test
public void testEqual3() {
Version v = new Version("1.2.3");
assertEquals("Versions are not equal", v, v);
}

@Test
public void testNotEqual() {
Version v1 = new Version("1.2.3.4.yyy.xxx.qualifier");
Expand Down