Skip to content

Commit

Permalink
Merge pull request quarkusio#5039 from maxandersen/honorunlisted
Browse files Browse the repository at this point in the history
unlist unlisted in listextensions
  • Loading branch information
maxandersen committed Oct 31, 2019
2 parents 5ddb54e + 9fc6311 commit 633791f
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.maven.model.Dependency;

Expand Down Expand Up @@ -55,7 +56,9 @@ static SelectionResult select(String query, List<Extension> extensions, boolean
if (matchesNameOrArtifactId.size() == 1) {
return new SelectionResult(matchesNameOrArtifactId, true);
}


extensions = extensions.stream().filter(e -> !e.isUnlisted()).collect(Collectors.toList());

// Try short names
Set<Extension> matchesShortName = extensions.stream().filter(extension -> matchesShortName(extension, q))
.collect(Collectors.toSet());
Expand Down Expand Up @@ -192,6 +195,7 @@ public AddExtensionResult addExtensions(final Set<String> extensions) throws IOE
List<Dependency> dependenciesFromBom = getDependenciesFromBom();

List<Extension> registry = MojoUtils.loadExtensions();

for (String query : extensions) {

if (query.contains(":")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public void listExtensions(boolean all, String format, String search) throws IOE
final Map<String, Dependency> installed = findInstalled();

Stream<Extension> extensionsStream = loadExtensions().stream();
extensionsStream = extensionsStream.filter(e -> filterUnlisted(e));
if (search != null && !"*".equalsIgnoreCase(search)) {
final Pattern searchPattern = Pattern.compile(".*" + search + ".*", Pattern.CASE_INSENSITIVE);
extensionsStream = extensionsStream.filter(e -> filterBySearch(searchPattern, e));
Expand Down Expand Up @@ -83,6 +84,10 @@ public void listExtensions(boolean all, String format, String search) throws IOE
}
}

private boolean filterUnlisted(Extension e) {
return !e.getMetadata().containsKey("unlisted");
}

public Map<String, Dependency> findInstalled() throws IOException {
if (buildFile != null) {
return buildFile.findInstalled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,29 @@ void testArtifactIdSelectionWithQuarkusPrefix() {
Assertions.assertTrue(matches.iterator().next().getArtifactId().equalsIgnoreCase("quarkus-foo"));
}

@Test
void testListedVsUnlisted() {
Extension e1 = new Extension("org.acme", "quarkus-foo-unlisted", "1.0")
.setName("some complex seo unaware name")
.setShortName("foo")
.setKeywords(new String[] { "foo", "bar" }).addMetadata("unlisted", "true");

Extension e2 = new Extension("org.acme", "quarkus-foo-bar", "1.0")
.setName("some foo bar")
.setKeywords(new String[] { "foo", "bar", "baz" }).addMetadata("unlisted", "false");
Extension e3 = new Extension("org.acme", "quarkus-foo-baz", "1.0")
.setName("unrelated")
.setKeywords(new String[] { "foo" });

List<Extension> extensions = asList(e1, e2, e3);
Collections.shuffle(extensions);
SelectionResult matches = AddExtensions.select("quarkus-foo", extensions, true);
Assertions.assertEquals(2, matches.getExtensions().size());

matches = AddExtensions.select("quarkus-foo-unlisted", extensions, true);
Assertions.assertEquals(1, matches.getExtensions().size());

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,30 @@ public Extension setShortName(String shortName) {
}

public boolean isUnlisted() {
return (boolean) getMetadata().get(MD_UNLISTED);
}
Object val = getMetadata().get(MD_UNLISTED);
if (val==null) {
return false;
} else if (val instanceof Boolean) {
return ((Boolean) val).booleanValue();
} else if (val instanceof String) {
return Boolean.valueOf((String)val);
}

return false;
}

public void setUnlisted(boolean unlisted) {
getMetadata().put(MD_UNLISTED, Boolean.valueOf(unlisted));
}

public Extension addMetadata(String key, Object value) {
getMetadata().put(key,value);
return this;

}

public Extension removeMetadata(String key) {
getMetadata().remove(key);
return this;
}
}

0 comments on commit 633791f

Please sign in to comment.