Skip to content

Commit

Permalink
[WFCORE-6750] Only set the value in the supplier and do the scan if t…
Browse files Browse the repository at this point in the history
…he resource exists.

Otherwise we would end up with scanning at community level too
  • Loading branch information
kabir committed Mar 20, 2024
1 parent 8c9603a commit fe1cd49
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,24 @@ 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));
}
}, OperationContext.Stage.RUNTIME);
}

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<UnstableApiAnnotationService> serviceConsumer = sb.provides(UnstableApiAnnotationService.SERVICE_NAME);
sb.setInstance(new UnstableApiAnnotationService(serviceConsumer, levelEnum));
sb.setInstance(new UnstableApiAnnotationService(serviceConsumer, level));
sb.install();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ private static class UnstableApiAnnotationLevelSupplier implements Supplier<Unst
private volatile UnstableApiAnnotationLevel level;
@Override
public UnstableApiAnnotationLevel get() {
if (level == null) {
throw new IllegalStateException();
}
return level;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.jboss.vfs.VirtualFile;
import org.jboss.vfs.VisitorAttributes;
import org.jboss.vfs.util.SuffixMatchFilter;
import org.wildfly.extension.core.management.UnstableApiAnnotationResourceDefinition;
import org.wildfly.extension.core.management.logging.CoreManagementLogger;
import org.wildfly.unstable.api.annotation.classpath.index.RuntimeIndex;
import org.wildfly.unstable.api.annotation.classpath.runtime.bytecode.ClassInfoScanner;
Expand All @@ -47,25 +48,40 @@
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;

public class ScanUnstableApiAnnotationsProcessor implements DeploymentUnitProcessor {

private final RuntimeIndex runtimeIndex;

// If set we will output some extra information to the logs during testing
// If set we will output some extra information to the logs during testing, so we can verify the number of classes scanned
// This is important for WildFly to make sure that the scanning of nested archives (especially wars and ears) is
// working as expected and to guard against scanning classes multiple times (which happened during the development of this feature)
private final String EXTRA_TEST_OUTPUT_PROPERTY = "org.wildfly.test.unstable-api-annotation.extra-output";

private static final String BASE_MODULE_NAME = "org.wildfly._internal.unstable-api-annotation-index";
private static final String INDEX_FILE = "index.txt";
private final Stability stability;
private final Supplier<UnstableApiAnnotationResourceDefinition.UnstableApiAnnotationLevel> levelSupplier;

private boolean extraTestOutput;

public ScanUnstableApiAnnotationsProcessor(RunningMode runningMode, Stability stability) {
public ScanUnstableApiAnnotationsProcessor(RunningMode runningMode, Stability stability, Supplier<UnstableApiAnnotationResourceDefinition.UnstableApiAnnotationLevel> 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 {
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
Expand Down Expand Up @@ -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<String> 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<String> lines) {
checkLogLine(lines.get(1), "WFLYCM0009", "deployment-with-unstable-annotations.jar");
checkLogLine(lines.get(2), "WFLYCM0010",
Expand Down

0 comments on commit fe1cd49

Please sign in to comment.