[maven-debian-helper] 05/05: Simplified DebianDependency and added some documentation
Emmanuel Bourg
ebourg-guest at alioth.debian.org
Mon Sep 2 17:10:35 UTC 2013
This is an automated email from the git hooks/post-receive script.
ebourg-guest pushed a commit to branch master
in repository maven-debian-helper.
commit 9dc97ae73ef43d3884d18f235e1b31a1d5947a00
Author: Emmanuel Bourg <ebourg at apache.org>
Date: Mon Sep 2 19:10:07 2013 +0200
Simplified DebianDependency and added some documentation
---
.../debian/maven/packager/DebianDependency.java | 80 +++++++++++++------
.../maven/packager/DebianDependencyTest.java | 84 +++++++++++++-------
2 files changed, 112 insertions(+), 52 deletions(-)
diff --git a/maven-packager-utils/src/main/java/org/debian/maven/packager/DebianDependency.java b/maven-packager-utils/src/main/java/org/debian/maven/packager/DebianDependency.java
index 8b1edcd..0ee1e9e 100644
--- a/maven-packager-utils/src/main/java/org/debian/maven/packager/DebianDependency.java
+++ b/maven-packager-utils/src/main/java/org/debian/maven/packager/DebianDependency.java
@@ -2,48 +2,78 @@ package org.debian.maven.packager;
import java.util.regex.Pattern;
-import static org.debian.maven.util.Preconditions.*;
-
+/**
+ * A dependency on a Debian package, with an optional minimum version.
+ *
+ * @since 1.8
+ */
public class DebianDependency implements Comparable<DebianDependency> {
- private static final Pattern VALID_DEBIAN_PACKAGE_NAME = Pattern.compile("^[a-z0-9][a-z0-9+-.]+$");
+ /**
+ * Pattern for valid package names according to the Debian Policy 5.6.1.
+ *
+ * Package names must consist only of lower case letters (a-z), digits
+ * (0-9), plus (+) and minus (-) signs, and periods (.). They must be at
+ * least two characters long and must start with an alphanumeric character.
+ */
+ private static final Pattern DEBIAN_PACKAGE_NAME_PATTERN = Pattern.compile("^[a-z0-9][a-z0-9+-.]+$");
+ /** The name of the Debian package */
private final String packageName;
+
+ /** The minimum version required (blank if not specified) */
private final String minimumVersion;
- public DebianDependency(String packageName, String minimumVersion) {
- this.packageName = checkPackageName(packageName);
- this.minimumVersion = checkNotNull(minimumVersion);
+ /**
+ * Creates a dependency on the specified package.
+ *
+ * @param packageName the name of the Debian package
+ * @param minimumVersion the minimum version required, empty if none
+ * @throws IllegalArgumentException if the package name or the minimum version is not valid
+ */
+ public DebianDependency(String packageName, String minimumVersion) throws IllegalArgumentException {
+ // check the validity of the package name
+ if (packageName == null || !DEBIAN_PACKAGE_NAME_PATTERN.matcher(packageName).matches()) {
+ throw new IllegalArgumentException("Invalid package name: " + packageName);
+ }
+
+ if (minimumVersion == null) {
+ throw new IllegalArgumentException("Invalid minimum version: " + minimumVersion);
+ }
+
+ this.packageName = packageName;
+ this.minimumVersion = minimumVersion;
}
- public DebianDependency(String packageName) {
+ /**
+ * Creates a non version dependency on the specified package.
+ *
+ * @param packageName the name of the Debian package
+ * @throws IllegalArgumentException if the package name is not valid
+ */
+ public DebianDependency(String packageName) throws IllegalArgumentException {
this(packageName, "");
}
- public String toString() {
- return minimumVersion.isEmpty() ? packageName : packageName + " (>= " + minimumVersion + ")";
- }
-
+ /**
+ * Returns the name of the Debian package.
+ */
public String getPackageName() {
return packageName;
}
/**
- * Check whether packageName is valid according to the Debian Policy 5.6.1.
+ * Returns the string representation of the dependency using the syntax
+ * of the Debian control files:
*
- * Package names must consist only of lower case letters (a-z), digits
- * (0-9), plus (+) and minus (-) signs, and periods (.). They must be at
- * least two characters long and must start with an alphanumeric character.
+ * <pre>
+ * foo (>= 1.0)
+ * </pre>
+ *
+ * @return
*/
- static boolean isValidDebianPackageName(String packageName) {
- return VALID_DEBIAN_PACKAGE_NAME.matcher(packageName).matches();
- }
-
- static String checkPackageName(String packageName) {
- if (packageName == null || !isValidDebianPackageName(checkNotEmpty(packageName))) {
- throw new IllegalArgumentException("Invalid package name: " + packageName);
- }
- return packageName;
+ public String toString() {
+ return minimumVersion.isEmpty() ? packageName : packageName + " (>= " + minimumVersion + ")";
}
@Override
@@ -80,4 +110,4 @@ public class DebianDependency implements Comparable<DebianDependency> {
return toString().compareTo(other.toString());
}
-}
\ No newline at end of file
+}
diff --git a/maven-packager-utils/src/test/java/org/debian/maven/packager/DebianDependencyTest.java b/maven-packager-utils/src/test/java/org/debian/maven/packager/DebianDependencyTest.java
index 3a6ea5a..c9fca4f 100644
--- a/maven-packager-utils/src/test/java/org/debian/maven/packager/DebianDependencyTest.java
+++ b/maven-packager-utils/src/test/java/org/debian/maven/packager/DebianDependencyTest.java
@@ -4,36 +4,66 @@ import static org.junit.Assert.*;
import org.junit.Test;
-import static org.debian.maven.packager.DebianDependency.checkPackageName;
-import static org.debian.maven.packager.DebianDependency.isValidDebianPackageName;
-
public class DebianDependencyTest {
@Test
- public void testIsValidDebianPackageName() {
- assertTrue(isValidDebianPackageName("a-"));
- assertTrue(isValidDebianPackageName("1-"));
- assertTrue(isValidDebianPackageName("allthecharacters-+.0123456789"));
- assertTrue(isValidDebianPackageName("a-b"));
-
- assertFalse(isValidDebianPackageName("aaA")); // no uppercase
- assertFalse(isValidDebianPackageName("aa a")); // no space
- assertFalse(isValidDebianPackageName("a")); // minimum 2 characters
- assertFalse(isValidDebianPackageName(""));
- assertFalse(isValidDebianPackageName("-aa")); // must start with alphanumeric
- assertFalse(isValidDebianPackageName("aaß")); // only basic ascii alphabet
- assertFalse(isValidDebianPackageName("a_a")); // no underscores
+ public void testValidDebianPackageName() {
+ new DebianDependency("a-");
+ new DebianDependency("1-");
+ new DebianDependency("allthecharacters-+.0123456789");
+ new DebianDependency("a-b");
}
- @Test
- public void testCheckPackageNameReturnsInput() {
- String packageName = "input-name+with.weird5name";
- assertEquals(packageName, checkPackageName(packageName));
+ @Test(expected=IllegalArgumentException.class)
+ public void testNullDebianPackageName() {
+ new DebianDependency(null);
+ }
+
+ @Test(expected=IllegalArgumentException.class)
+ public void testEmptyDebianPackageName() {
+ new DebianDependency("");
+ }
+
+ @Test(expected=IllegalArgumentException.class)
+ public void testDebianPackageNameWithUppercase() {
+ new DebianDependency("aaA"); // no uppercase
}
@Test(expected=IllegalArgumentException.class)
- public void testCheckPackageNameDoesNotAcceptNull() {
- checkPackageName(null);
+ public void testDebianPackageNameWithSpace() {
+ new DebianDependency("aa a"); // no space
+ }
+
+ @Test(expected=IllegalArgumentException.class)
+ public void testTooShortDebianPackageName() {
+ new DebianDependency("a"); // minimum 2 characters
+ }
+
+ @Test(expected=IllegalArgumentException.class)
+ public void testDebianPackageNameWithNonAlphanumericFirstChar() {
+ new DebianDependency("-aa"); // must start with alphanumeric
+ }
+
+ @Test(expected=IllegalArgumentException.class)
+ public void testDebianPackageNameWithNonAscii() {
+ new DebianDependency("aaß"); // only basic ascii alphabet
+ }
+
+ @Test(expected=IllegalArgumentException.class)
+ public void testDebianPackageNameWithUnderscore() {
+ new DebianDependency("a_a"); // no underscores
+ }
+
+ @Test(expected=IllegalArgumentException.class)
+ public void testDebianPackageNameWithNullVersion() {
+ new DebianDependency("foo", null);
+ }
+
+ @Test
+ public void testGetPackageName() {
+ String name = "input-name+with.weird5name";
+ DebianDependency dependency = new DebianDependency(name);
+ assertEquals(name, dependency.getPackageName());
}
@Test
@@ -43,11 +73,11 @@ public class DebianDependencyTest {
DebianDependency dep3 = new DebianDependency("maven-repo-helper", "1.0");
DebianDependency dep4 = new DebianDependency("maven-repo-helper", "2.0");
- assertFalse(dep1.equals(""));
- assertTrue(dep1.equals(dep1));
- assertTrue(dep1.equals(dep2));
- assertFalse(dep2.equals(dep3));
- assertFalse(dep3.equals(dep4));
+ assertFalse(dep1.equals("")); // different class
+ assertTrue(dep1.equals(dep1)); // same instance
+ assertTrue(dep1.equals(dep2)); // same dependency, different instances
+ assertFalse(dep2.equals(dep3)); // different dependencies
+ assertFalse(dep3.equals(dep4)); // same dependency, different versions
}
@Test
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/maven-debian-helper.git
More information about the pkg-java-commits
mailing list