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

Unlist unlisted in list-extensions #5039

Merged
merged 1 commit into from
Oct 31, 2019
Merged
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 @@ -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");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and value true I guess.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just that technically i can be both true (boolean) or a string 'true'. but sure let me add that together while making add honor it too.

}

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 @@ -294,10 +294,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;
}
}