mirror of
https://github.com/jlengrand/quarkus.git
synced 2026-03-10 08:41:22 +00:00
Add short names for smallrye dependencies in the extension list
Disable the label match by default
This commit is contained in:
committed by
Guillaume Smet
parent
c492fa9c17
commit
44f2c375af
@@ -293,6 +293,7 @@
|
||||
},
|
||||
{
|
||||
"name": "SmallRye Context Propagation",
|
||||
"shortName": "context propagation",
|
||||
"labels": [
|
||||
"smallrye-context-propagation",
|
||||
"microprofile-context-propagation",
|
||||
@@ -317,6 +318,7 @@
|
||||
},
|
||||
{
|
||||
"name": "SmallRye Health",
|
||||
"shortName": "health",
|
||||
"labels": [
|
||||
"smallrye-health",
|
||||
"health-check",
|
||||
@@ -342,6 +344,7 @@
|
||||
},
|
||||
{
|
||||
"name": "SmallRye Metrics",
|
||||
"shortName": "metrics",
|
||||
"labels": [
|
||||
"smallrye-metrics",
|
||||
"metrics",
|
||||
@@ -379,6 +382,7 @@
|
||||
},
|
||||
{
|
||||
"name": "SmallRye Reactive Streams Operators",
|
||||
"shortName": "reactive streams",
|
||||
"labels": [
|
||||
"smallrye-reactive-streams-operators",
|
||||
"smallrye-reactive-streams",
|
||||
|
||||
@@ -6,6 +6,7 @@ import static io.quarkus.maven.utilities.MojoUtils.readPom;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -38,9 +39,11 @@ public class AddExtensions {
|
||||
*
|
||||
* @param query the query
|
||||
* @param extensions the extension list
|
||||
* @param labelLookup whether or not the query must be tested against the labels of the extensions. Should
|
||||
* be {@code false} by default.
|
||||
* @return the list of matching candidates and whether or not a match has been found.
|
||||
*/
|
||||
static SelectionResult select(String query, List<Extension> extensions) {
|
||||
static SelectionResult select(String query, List<Extension> extensions, boolean labelLookup) {
|
||||
String q = query.trim().toLowerCase();
|
||||
|
||||
// Try exact matches
|
||||
@@ -70,8 +73,13 @@ public class AddExtensions {
|
||||
}
|
||||
|
||||
// find by labels
|
||||
List<Extension> matchesLabels = extensions.stream()
|
||||
.filter(extension -> extension.labels().contains(q)).collect(Collectors.toList());
|
||||
List<Extension> matchesLabels;
|
||||
if (labelLookup) {
|
||||
matchesLabels = extensions.stream()
|
||||
.filter(extension -> extension.labels().contains(q)).collect(Collectors.toList());
|
||||
} else {
|
||||
matchesLabels = new ArrayList<>();
|
||||
}
|
||||
|
||||
Set<Extension> candidates = new LinkedHashSet<>();
|
||||
candidates.addAll(matchesNameOrArtifactId);
|
||||
@@ -86,9 +94,8 @@ public class AddExtensions {
|
||||
}
|
||||
|
||||
private static boolean matchesArtifactId(String artifactId, String q) {
|
||||
return (artifactId.equalsIgnoreCase(q) ||
|
||||
artifactId.equalsIgnoreCase("quarkus-" + q) ||
|
||||
artifactId.equalsIgnoreCase("quarkus-smallrye-" + q));
|
||||
return artifactId.equalsIgnoreCase(q) ||
|
||||
artifactId.equalsIgnoreCase("quarkus-" + q);
|
||||
}
|
||||
|
||||
public AddExtensionResult addExtensions(final Set<String> extensions) throws IOException {
|
||||
@@ -107,7 +114,7 @@ public class AddExtensions {
|
||||
// GAV case.
|
||||
updated = addExtensionAsGAV(query) || updated;
|
||||
} else {
|
||||
SelectionResult result = select(query, registry);
|
||||
SelectionResult result = select(query, registry, false);
|
||||
if (!result.matches()) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
// We have 3 cases, we can still have a single candidate, but the match is on label
|
||||
@@ -117,14 +124,6 @@ public class AddExtensions {
|
||||
// No matches at all.
|
||||
print(NOK + " Cannot find a dependency matching '" + query + "', maybe a typo?");
|
||||
success = false;
|
||||
} else if (candidates.size() == 1) {
|
||||
sb.append(NOK).append(" One extension matching '").append(query).append("'");
|
||||
sb.append(System.lineSeparator()).append(" * ")
|
||||
.append(candidates.iterator().next().managementKey());
|
||||
sb.append(System.lineSeparator())
|
||||
.append(" Use the exact name or the full GAV to add the extension");
|
||||
print(sb.toString());
|
||||
success = false;
|
||||
} else {
|
||||
sb.append(NOK).append(" Multiple extensions matching '").append(query).append("'");
|
||||
result.getExtensions()
|
||||
|
||||
@@ -209,9 +209,13 @@ class AddExtensionsTest {
|
||||
|
||||
List<Extension> extensions = asList(e1, e2, e3);
|
||||
Collections.shuffle(extensions);
|
||||
SelectionResult matches = AddExtensions.select("foo", extensions);
|
||||
SelectionResult matches = AddExtensions.select("foo", extensions, true);
|
||||
Assertions.assertFalse(matches.matches());
|
||||
Assertions.assertEquals(2, matches.getExtensions().size());
|
||||
|
||||
matches = AddExtensions.select("foo", extensions, false);
|
||||
Assertions.assertFalse(matches.matches());
|
||||
Assertions.assertEquals(0, matches.getExtensions().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -225,7 +229,7 @@ class AddExtensionsTest {
|
||||
|
||||
List<Extension> extensions = asList(e1, e2);
|
||||
Collections.shuffle(extensions);
|
||||
SelectionResult matches = AddExtensions.select("foo", extensions);
|
||||
SelectionResult matches = AddExtensions.select("foo", extensions, true);
|
||||
Assertions.assertFalse(matches.matches());
|
||||
Assertions.assertEquals(1, matches.getExtensions().size());
|
||||
}
|
||||
@@ -244,7 +248,11 @@ class AddExtensionsTest {
|
||||
|
||||
List<Extension> extensions = asList(e1, e2, e3);
|
||||
Collections.shuffle(extensions);
|
||||
SelectionResult matches = AddExtensions.select("foo", extensions);
|
||||
SelectionResult matches = AddExtensions.select("foo", extensions, false);
|
||||
Assertions.assertFalse(matches.matches());
|
||||
Assertions.assertEquals(2, matches.getExtensions().size());
|
||||
|
||||
matches = AddExtensions.select("foo", extensions, true);
|
||||
Assertions.assertFalse(matches.matches());
|
||||
Assertions.assertEquals(3, matches.getExtensions().size());
|
||||
|
||||
@@ -265,7 +273,7 @@ class AddExtensionsTest {
|
||||
|
||||
List<Extension> extensions = asList(e1, e2, e3);
|
||||
Collections.shuffle(extensions);
|
||||
SelectionResult matches = AddExtensions.select("foo", extensions);
|
||||
SelectionResult matches = AddExtensions.select("foo", extensions, false);
|
||||
Assertions.assertTrue(matches.matches());
|
||||
Assertions.assertEquals(1, matches.getExtensions().size());
|
||||
Assertions.assertNotNull(matches.getMatch());
|
||||
@@ -287,33 +295,12 @@ class AddExtensionsTest {
|
||||
|
||||
List<Extension> extensions = asList(e1, e2, e3);
|
||||
Collections.shuffle(extensions);
|
||||
SelectionResult matches = AddExtensions.select("foo", extensions);
|
||||
SelectionResult matches = AddExtensions.select("foo", extensions, false);
|
||||
Assertions.assertEquals(1, matches.getExtensions().size());
|
||||
Assertions.assertNotNull(matches.getMatch());
|
||||
Assertions.assertTrue(matches.getMatch().getArtifactId().equalsIgnoreCase("quarkus-foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testArtifactIdSelectionWithQuarkusSmallRyePrefix() {
|
||||
Extension e1 = new Extension("org.acme", "quarkus-smallrye-foo", "1.0")
|
||||
.setName("some complex seo unaware name")
|
||||
.setShortName("foo")
|
||||
.setLabels(new String[] { "foo", "bar" });
|
||||
Extension e2 = new Extension("org.acme", "quarkus-foo-bar", "1.0")
|
||||
.setName("some foo bar")
|
||||
.setLabels(new String[] { "foo", "bar", "baz" });
|
||||
Extension e3 = new Extension("org.acme", "quarkus-unrelated", "1.0")
|
||||
.setName("unrelated")
|
||||
.setLabels(new String[] { "foo" });
|
||||
|
||||
List<Extension> extensions = asList(e1, e2, e3);
|
||||
Collections.shuffle(extensions);
|
||||
SelectionResult matches = AddExtensions.select("foo", extensions);
|
||||
Assertions.assertEquals(1, matches.getExtensions().size());
|
||||
Assertions.assertNotNull(matches.getMatch());
|
||||
Assertions.assertTrue(matches.getMatch().getArtifactId().equalsIgnoreCase("quarkus-smallrye-foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void addDuplicatedExtension() throws IOException {
|
||||
final File pom = new File("target/extensions-test", "pom.xml");
|
||||
|
||||
Reference in New Issue
Block a user