diff --git a/core-management/core-management-subsystem/src/main/java/org/wildfly/extension/core/management/CoreManagementRootResourceDefinition.java b/core-management/core-management-subsystem/src/main/java/org/wildfly/extension/core/management/CoreManagementRootResourceDefinition.java index 56f49ae06b9..643e09658b2 100644 --- a/core-management/core-management-subsystem/src/main/java/org/wildfly/extension/core/management/CoreManagementRootResourceDefinition.java +++ b/core-management/core-management-subsystem/src/main/java/org/wildfly/extension/core/management/CoreManagementRootResourceDefinition.java @@ -69,7 +69,7 @@ protected void performBoottime(OperationContext context, ModelNode operation, Re @Override protected void execute(DeploymentProcessorTarget processorTarget) { processorTarget.addDeploymentProcessor(SUBSYSTEM_NAME, PARSE, PARSE_SCAN_EXPERIMENTAL_ANNOTATIONS, - new ScanUnstableApiAnnotationsProcessor(context.getRunningMode(), context.getStability())); + new ScanUnstableApiAnnotationsProcessor(context.getRunningMode(), context.getStability(), UnstableApiAnnotationService.LEVEL_SUPPLIER)); processorTarget.addDeploymentProcessor(SUBSYSTEM_NAME, PARSE, PARSE_REPORT_EXPERIMENTAL_ANNOTATIONS, new ReportUnstableApiAnnotationsProcessor(UnstableApiAnnotationService.LEVEL_SUPPLIER)); } @@ -77,16 +77,16 @@ protected void execute(DeploymentProcessorTarget processorTarget) { } Resource unstableApiResource = resource.getChild(UnstableApiAnnotationResourceDefinition.PATH); - String level = UnstableApiAnnotationResourceDefinition.LEVEL.getDefaultValue().asString(); + UnstableApiAnnotationLevel level = null; if (unstableApiResource != null) { ModelNode model = unstableApiResource.getModel(); - level = UnstableApiAnnotationResourceDefinition.LEVEL.resolveModelAttribute(context, model).asString(); + String levelValue = UnstableApiAnnotationResourceDefinition.LEVEL.resolveModelAttribute(context, model).asString(); + level = UnstableApiAnnotationLevel.valueOf(levelValue); } - UnstableApiAnnotationLevel levelEnum = UnstableApiAnnotationLevel.valueOf(level); ServiceBuilder sb = context.getCapabilityServiceTarget().addService(); Consumer serviceConsumer = sb.provides(UnstableApiAnnotationService.SERVICE_NAME); - sb.setInstance(new UnstableApiAnnotationService(serviceConsumer, levelEnum)); + sb.setInstance(new UnstableApiAnnotationService(serviceConsumer, level)); sb.install(); } } diff --git a/core-management/core-management-subsystem/src/main/java/org/wildfly/extension/core/management/UnstableApiAnnotationResourceDefinition.java b/core-management/core-management-subsystem/src/main/java/org/wildfly/extension/core/management/UnstableApiAnnotationResourceDefinition.java index 6c41cd47e9b..458a2fdaed6 100644 --- a/core-management/core-management-subsystem/src/main/java/org/wildfly/extension/core/management/UnstableApiAnnotationResourceDefinition.java +++ b/core-management/core-management-subsystem/src/main/java/org/wildfly/extension/core/management/UnstableApiAnnotationResourceDefinition.java @@ -33,7 +33,7 @@ */ public class UnstableApiAnnotationResourceDefinition extends PersistentResourceDefinition { - private static final Stability STABILITY = Stability.PREVIEW; + public static final Stability STABILITY = Stability.PREVIEW; public static final SimpleAttributeDefinition LEVEL = SimpleAttributeDefinitionBuilder.create( ModelDescriptionConstants.LEVEL, ModelType.STRING, true) .setValidator(EnumValidator.create(UnstableApiAnnotationLevel.class)) diff --git a/core-management/core-management-subsystem/src/main/java/org/wildfly/extension/core/management/UnstableApiAnnotationService.java b/core-management/core-management-subsystem/src/main/java/org/wildfly/extension/core/management/UnstableApiAnnotationService.java index 2061d62ed34..3299d829607 100644 --- a/core-management/core-management-subsystem/src/main/java/org/wildfly/extension/core/management/UnstableApiAnnotationService.java +++ b/core-management/core-management-subsystem/src/main/java/org/wildfly/extension/core/management/UnstableApiAnnotationService.java @@ -61,9 +61,6 @@ private static class UnstableApiAnnotationLevelSupplier implements Supplier levelSupplier; private boolean extraTestOutput; - public ScanUnstableApiAnnotationsProcessor(RunningMode runningMode, Stability stability) { + public ScanUnstableApiAnnotationsProcessor(RunningMode runningMode, Stability stability, Supplier levelSupplier) { this.stability = stability; - RuntimeIndex runtimeIndex = null; + this.levelSupplier = levelSupplier; extraTestOutput = System.getProperties().containsKey(EXTRA_TEST_OUTPUT_PROPERTY); - if (runningMode != RunningMode.ADMIN_ONLY) { + + boolean enableScanning = true; + if (runningMode == RunningMode.ADMIN_ONLY) { + enableScanning = false; + } else if (stability.enables(Stability.EXPERIMENTAL) || !stability.enables(UnstableApiAnnotationResourceDefinition.STABILITY)) { + // We don't care about scanning at the experimental level. + // Also, we need to be at the level where the feature is enabled or lower + enableScanning = false; + } + + RuntimeIndex runtimeIndex = null; + if (enableScanning) { ModuleLoader moduleLoader = ((ModuleClassLoader) this.getClass().getClassLoader()).getModule().getModuleLoader(); Module module = null; try { @@ -108,11 +124,9 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro if (runtimeIndex == null) { return; } - if (stability.enables(Stability.EXPERIMENTAL)) { - // If running with Stability.EXPERIMENTAL we don't care if the user is using experimental annotations + if (levelSupplier.get() == null) { return; } - final DeploymentUnit du = phaseContext.getDeploymentUnit(); DeploymentUnit top = DeploymentUtils.getTopDeploymentUnit(du); diff --git a/testsuite/unstable-api-annotation/tests/src/test/java/org/wildfly/core/test/unstable/api/annotation/reporter/UnstableApiAnnotationScannerTestCase.java b/testsuite/unstable-api-annotation/tests/src/test/java/org/wildfly/core/test/unstable/api/annotation/reporter/UnstableApiAnnotationScannerTestCase.java index 7751582582e..b7d233341b7 100644 --- a/testsuite/unstable-api-annotation/tests/src/test/java/org/wildfly/core/test/unstable/api/annotation/reporter/UnstableApiAnnotationScannerTestCase.java +++ b/testsuite/unstable-api-annotation/tests/src/test/java/org/wildfly/core/test/unstable/api/annotation/reporter/UnstableApiAnnotationScannerTestCase.java @@ -140,7 +140,6 @@ public void testDeploymentWarning() throws Exception { checkLogOrErrorLines(newLogEntries); } finally { ManagementOperations.executeOperation(mcc, Util.createRemoveOperation(PathAddress.pathAddress("deployment", deployment.getName()))); - //ServerReload.executeReloadAndWaitForCompletion(mcc); } } @@ -188,6 +187,39 @@ public void testDeploymentError() throws Exception{ // Check that the log contains the expected warning } + @Test + public void testNoWarmingIfUnstableApiAnnotationResourceIsNotDefined() throws Exception { + + + PathAddress address = PathAddress.pathAddress(CoreManagementExtension.SUBSYSTEM_PATH) + .append(UnstableApiAnnotationResourceDefinition.PATH); + ModelNode removeOp = Util.createRemoveOperation(address); + ManagementOperations.executeOperation(managementClient.getControllerClient(), removeOp); + try { + ServerReload.executeReloadAndWaitForCompletion(managementClient.getControllerClient()); + + LogDiffer logDiffer = new LogDiffer(); + logDiffer.takeSnapshot(); + + JavaArchive deployment = createDeploymentWithUnstableAnnotations(); + ModelControllerClient mcc = managementClient.getControllerClient(); + Operation deploymentOp = createDeploymentOp(deployment); + + try { + ManagementOperations.executeOperation(mcc, deploymentOp); + List newLogEntries = logDiffer.getNewLogEntries(); + Assert.assertTrue(newLogEntries.isEmpty()); + } finally { + ManagementOperations.executeOperation(mcc, Util.createRemoveOperation(PathAddress.pathAddress("deployment", deployment.getName()))); + } + + } finally { + ModelNode addOp = Util.createAddOperation(address); + ManagementOperations.executeOperation(managementClient.getControllerClient(), addOp); + ServerReload.executeReloadAndWaitForCompletion(managementClient.getControllerClient()); + } + } + private void checkLogOrErrorLines(List lines) { checkLogLine(lines.get(1), "WFLYCM0009", "deployment-with-unstable-annotations.jar"); checkLogLine(lines.get(2), "WFLYCM0010",