Search in sources :

Example 1 with CapabilityErrors

use of io.quarkus.bootstrap.model.CapabilityErrors in project quarkus by quarkusio.

the class DevMojoIT method testCapabilitiesMissing.

@Test
public void testCapabilitiesMissing() throws MavenInvocationException, IOException {
    testDir = getTargetDir("projects/capabilities-missing");
    final File runnerPom = new File(testDir, "runner/pom.xml");
    if (!runnerPom.exists()) {
        fail("Failed to locate runner/pom.xml in " + testDir);
    }
    run(true);
    final CapabilityErrors error = new CapabilityErrors();
    error.addMissing("sunshine", "org.acme:acme-quarkus-ext:1.0-SNAPSHOT");
    String response = DevModeTestUtils.getHttpResponse("/hello", true);
    assertThat(response).contains(error.report());
    final StringWriter buf = new StringWriter();
    try (BufferedWriter writer = new BufferedWriter(buf)) {
        writer.write("        <dependency>");
        writer.newLine();
        writer.write("            <groupId>org.acme</groupId>");
        writer.newLine();
        writer.write("            <artifactId>alt-quarkus-ext</artifactId>");
        writer.newLine();
        writer.write("        </dependency>");
        writer.newLine();
    }
    final String acmeDep = buf.toString();
    filter(runnerPom, Collections.singletonMap("<!-- missing -->", acmeDep));
    assertThat(DevModeTestUtils.getHttpResponse("/hello", false)).isEqualTo("hello");
}
Also used : StringWriter(java.io.StringWriter) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ZipFile(java.util.zip.ZipFile) File(java.io.File) CapabilityErrors(io.quarkus.bootstrap.model.CapabilityErrors) BufferedWriter(java.io.BufferedWriter) Test(org.junit.jupiter.api.Test)

Example 2 with CapabilityErrors

use of io.quarkus.bootstrap.model.CapabilityErrors in project quarkus by quarkusio.

the class CapabilityAggregationStep method aggregateCapabilities.

/**
 * Aggregates all the capability build items. Not all the capabilities are configured in the extension descriptors.
 * Many are still produced by build steps directly.
 *
 * @param capabilities capability build items
 * @return aggregated capabilities
 */
@BuildStep
Capabilities aggregateCapabilities(List<CapabilityBuildItem> capabilities, CapabilitiesConfiguredInDescriptorsBuildItem configuredCaps, CurateOutcomeBuildItem curateOutcomeBuildItem) {
    final Map<String, Object> providedCapabilities = new HashMap<>();
    CapabilityErrors capabilityErrors = null;
    Map<String, List<String>> capsProvidedByBuildSteps = Collections.emptyMap();
    for (CapabilityBuildItem capabilityItem : capabilities) {
        final String provider = capabilityItem.getProvider();
        final String capability = capabilityItem.getName();
        final Object previous = providedCapabilities.put(capability, provider);
        if (previous != null) {
            if (previous instanceof String) {
                capabilityErrors = createIfNull(capabilityErrors);
                capabilityErrors.addConflict(capability, previous.toString());
                providedCapabilities.put(capability, capabilityErrors);
            } else {
                capabilityErrors = (CapabilityErrors) previous;
            }
            capabilityErrors.addConflict(capability, provider);
            providedCapabilities.put(capability, capabilityErrors);
        }
        if (!configuredCaps.names.contains(capability)) {
            if (capsProvidedByBuildSteps.isEmpty()) {
                capsProvidedByBuildSteps = new HashMap<>();
            }
            capsProvidedByBuildSteps.computeIfAbsent(provider, k -> new ArrayList<>(1)).add(capability);
        }
    }
    for (ExtensionCapabilities extCap : curateOutcomeBuildItem.getApplicationModel().getExtensionCapabilities()) {
        if (extCap.getRequiresCapabilities().isEmpty()) {
            continue;
        }
        for (String required : extCap.getRequiresCapabilities()) {
            if (!providedCapabilities.containsKey(required)) {
                capabilityErrors = createIfNull(capabilityErrors);
                capabilityErrors.addMissing(required, extCap.getExtension());
            }
        }
    }
    // capabilities are supposed to be configured in the extension descriptors and not produced directly by build steps
    if (!capsProvidedByBuildSteps.isEmpty()) {
        final StringWriter buf = new StringWriter();
        try (BufferedWriter writer = new BufferedWriter(buf)) {
            writer.append("The following capabilities were found to be missing from the processed extension descriptors:");
            for (Map.Entry<String, List<String>> provider : capsProvidedByBuildSteps.entrySet()) {
                for (String capability : provider.getValue()) {
                    writer.newLine();
                    writer.append(" - " + capability + " provided by ").append(provider.getKey());
                }
            }
            writer.newLine();
            writer.append("Please report this issue to the extension maintainers to get it fixed in the future releases.");
        } catch (IOException e) {
        }
        Logger.getLogger(CapabilityAggregationStep.class).warn(buf.toString());
    }
    if (capabilityErrors != null && !capabilityErrors.isEmpty()) {
        throw new IllegalStateException(capabilityErrors.report());
    }
    return new Capabilities(providedCapabilities.keySet());
}
Also used : BooleanSupplierFactoryBuildItem(io.quarkus.deployment.BooleanSupplierFactoryBuildItem) BufferedWriter(java.io.BufferedWriter) StringWriter(java.io.StringWriter) Logger(org.jboss.logging.Logger) Set(java.util.Set) IOException(java.io.IOException) HashMap(java.util.HashMap) SimpleBuildItem(io.quarkus.builder.item.SimpleBuildItem) CurateOutcomeBuildItem(io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem) BuildProducer(io.quarkus.deployment.annotations.BuildProducer) ArrayList(java.util.ArrayList) BooleanSupplier(java.util.function.BooleanSupplier) HashSet(java.util.HashSet) Capabilities(io.quarkus.deployment.Capabilities) ExtensionCapabilities(io.quarkus.bootstrap.model.ExtensionCapabilities) BuildStep(io.quarkus.deployment.annotations.BuildStep) List(java.util.List) ApplicationModel(io.quarkus.bootstrap.model.ApplicationModel) Map(java.util.Map) CapabilityErrors(io.quarkus.bootstrap.model.CapabilityErrors) CapabilityBuildItem(io.quarkus.deployment.builditem.CapabilityBuildItem) Collections(java.util.Collections) HashMap(java.util.HashMap) ExtensionCapabilities(io.quarkus.bootstrap.model.ExtensionCapabilities) ArrayList(java.util.ArrayList) IOException(java.io.IOException) CapabilityErrors(io.quarkus.bootstrap.model.CapabilityErrors) BufferedWriter(java.io.BufferedWriter) StringWriter(java.io.StringWriter) Capabilities(io.quarkus.deployment.Capabilities) ExtensionCapabilities(io.quarkus.bootstrap.model.ExtensionCapabilities) CapabilityBuildItem(io.quarkus.deployment.builditem.CapabilityBuildItem) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 3 with CapabilityErrors

use of io.quarkus.bootstrap.model.CapabilityErrors in project quarkus by quarkusio.

the class DevMojoIT method testCapabilitiesConflict.

@Test
public void testCapabilitiesConflict() throws MavenInvocationException, IOException {
    testDir = getTargetDir("projects/capabilities-conflict");
    final File runnerPom = new File(testDir, "runner/pom.xml");
    if (!runnerPom.exists()) {
        fail("Failed to locate runner/pom.xml in " + testDir);
    }
    run(true);
    final CapabilityErrors error = new CapabilityErrors();
    error.addConflict("sunshine", "org.acme:alt-quarkus-ext:1.0-SNAPSHOT");
    error.addConflict("sunshine", "org.acme:acme-quarkus-ext:1.0-SNAPSHOT");
    String response = DevModeTestUtils.getHttpResponse("/hello", true);
    assertThat(response).contains(error.report());
    final StringWriter buf = new StringWriter();
    try (BufferedWriter writer = new BufferedWriter(buf)) {
        writer.write("        <dependency>");
        writer.newLine();
        writer.write("            <groupId>org.acme</groupId>");
        writer.newLine();
        writer.write("            <artifactId>acme-quarkus-ext</artifactId>");
        writer.newLine();
        writer.write("        </dependency>");
        writer.newLine();
    }
    final String acmeDep = buf.toString();
    filter(runnerPom, Collections.singletonMap(acmeDep, ""));
    assertThat(DevModeTestUtils.getHttpResponse("/hello", false)).isEqualTo("hello");
    buf.getBuffer().setLength(0);
    try (BufferedWriter writer = new BufferedWriter(buf)) {
        writer.write("        <dependency>");
        writer.newLine();
        writer.write("            <groupId>org.acme</groupId>");
        writer.newLine();
        writer.write("            <artifactId>alt-quarkus-ext</artifactId>");
        writer.newLine();
        writer.write("        </dependency>");
        writer.newLine();
    }
    final String altDep = buf.toString();
    filter(runnerPom, Collections.singletonMap(acmeDep, altDep));
    assertThat(DevModeTestUtils.getHttpResponse("/hello", false)).isEqualTo("hello");
}
Also used : StringWriter(java.io.StringWriter) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ZipFile(java.util.zip.ZipFile) File(java.io.File) CapabilityErrors(io.quarkus.bootstrap.model.CapabilityErrors) BufferedWriter(java.io.BufferedWriter) Test(org.junit.jupiter.api.Test)

Aggregations

CapabilityErrors (io.quarkus.bootstrap.model.CapabilityErrors)3 BufferedWriter (java.io.BufferedWriter)3 StringWriter (java.io.StringWriter)3 File (java.io.File)2 ZipFile (java.util.zip.ZipFile)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 Test (org.junit.jupiter.api.Test)2 ApplicationModel (io.quarkus.bootstrap.model.ApplicationModel)1 ExtensionCapabilities (io.quarkus.bootstrap.model.ExtensionCapabilities)1 SimpleBuildItem (io.quarkus.builder.item.SimpleBuildItem)1 BooleanSupplierFactoryBuildItem (io.quarkus.deployment.BooleanSupplierFactoryBuildItem)1 Capabilities (io.quarkus.deployment.Capabilities)1 BuildProducer (io.quarkus.deployment.annotations.BuildProducer)1 BuildStep (io.quarkus.deployment.annotations.BuildStep)1 CapabilityBuildItem (io.quarkus.deployment.builditem.CapabilityBuildItem)1 CurateOutcomeBuildItem (io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1