Browse Source

Allow matching group prefix

tags/v1.5.0
parent
commit
ba792ed19a
5 changed files with 41 additions and 7 deletions
  1. +1
    -1
      pom.xml
  2. +14
    -1
      src/main/java/org/perfectable/repositable/configuration/GroupFilterConfiguration.java
  3. +6
    -4
      src/main/java/org/perfectable/repositable/filter/GroupFilter.java
  4. +18
    -0
      src/main/java/org/perfectable/repositable/filter/MatchMode.java
  5. +2
    -1
      src/test/java/org/perfectable/repositable/GroupFilterTest.java

+ 1
- 1
pom.xml View File

@@ -9,7 +9,7 @@
</parent>

<artifactId>repositable</artifactId>
<version>1.4.1-SNAPSHOT</version>
<version>1.5.0-SNAPSHOT</version>

<name>Repositable</name>
<description>Minimalistic Maven repository manager</description>


+ 14
- 1
src/main/java/org/perfectable/repositable/configuration/GroupFilterConfiguration.java View File

@@ -2,6 +2,7 @@ package org.perfectable.repositable.configuration;

import org.perfectable.repositable.Filter;
import org.perfectable.repositable.filter.GroupFilter;
import org.perfectable.repositable.filter.MatchMode;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
@@ -13,11 +14,23 @@ import javax.xml.bind.annotation.XmlValue;
public class GroupFilterConfiguration implements FilterConfiguration {
private static final long serialVersionUID = 7656652143149815026L;

public static final String MATCH_ALL = "*";

@XmlValue
private String groupId;

@Override
public Filter build() {
return GroupFilter.of(groupId);
MatchMode matchMode;
String expression;
if (groupId.endsWith(MATCH_ALL)) {
matchMode = MatchMode.PREFIX;
expression = groupId.substring(0, groupId.length() - 1);
}
else {
matchMode = MatchMode.EXACT;
expression = groupId;
}
return GroupFilter.of(expression, matchMode);
}
}

+ 6
- 4
src/main/java/org/perfectable/repositable/filter/GroupFilter.java View File

@@ -10,18 +10,20 @@ import java.util.Optional;

public final class GroupFilter implements Filter {
private final String acceptedGroupId;
private final MatchMode matchMode;

public static GroupFilter of(String acceptedGroupId) {
return new GroupFilter(acceptedGroupId);
public static GroupFilter of(String acceptedGroupId, MatchMode matchMode) {
return new GroupFilter(acceptedGroupId, matchMode);
}

private GroupFilter(String acceptedGroupId) {
private GroupFilter(String acceptedGroupId, MatchMode matchMode) {
this.acceptedGroupId = acceptedGroupId;
this.matchMode = matchMode;
}

@Override
public boolean matchesModule(String groupId, String artifactId) {
return groupId.equals(this.acceptedGroupId);
return matchMode.matches(acceptedGroupId, groupId);
}

@Override


+ 18
- 0
src/main/java/org/perfectable/repositable/filter/MatchMode.java View File

@@ -0,0 +1,18 @@
package org.perfectable.repositable.filter;

public enum MatchMode {
EXACT {
@Override
public boolean matches(String expression, String value) {
return expression.equals(value);
}
},
PREFIX {
@Override
public boolean matches(String expression, String value) {
return value.startsWith(expression);
}
};

public abstract boolean matches(String expression, String value);
}

+ 2
- 1
src/test/java/org/perfectable/repositable/GroupFilterTest.java View File

@@ -3,6 +3,7 @@ package org.perfectable.repositable;
import org.perfectable.repositable.authorization.Group;
import org.perfectable.repositable.authorization.User;
import org.perfectable.repositable.filter.GroupFilter;
import org.perfectable.repositable.filter.MatchMode;
import org.perfectable.repositable.repository.FileRepository;
import org.perfectable.repositable.repository.Repositories;
import org.perfectable.testable.resources.LoadResourcesWith;
@@ -31,7 +32,7 @@ public class GroupFilterTest extends AbstractServerTest {
Group uploaders = Group.create().join(uploader);
Repository repository =
FileRepository.create(repositoryBase)
.filtered(GroupFilter.of("org.perfectable.allowed"))
.filtered(GroupFilter.of("org.perfectable.allowed", MatchMode.PREFIX))
.restrictUploaders(uploaders);
Repositories repositories = Repositories.create()
.withAdditional("test-repository", repository);


Loading…
Cancel
Save