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

[WFCORE-6750] Iterate resources rather than writing to a shared index… #6049

Merged
merged 1 commit into from
Jun 26, 2024
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
@@ -0,0 +1 @@
Feature packs should add their indices to this folder

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@

package org.wildfly.extension.core.management.deployment;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.jboss.as.controller.RunningMode;
Expand All @@ -27,6 +26,7 @@
import org.jboss.modules.ModuleClassLoader;
import org.jboss.modules.ModuleLoadException;
import org.jboss.modules.ModuleLoader;
import org.jboss.modules.Resource;
import org.jboss.vfs.VirtualFile;
import org.jboss.vfs.VisitorAttributes;
import org.jboss.vfs.util.SuffixMatchFilter;
Expand All @@ -45,7 +45,8 @@ public class ScanUnstableApiAnnotationsProcessor implements DeploymentUnitProces
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 static final String README_TXT = "README.txt";
private final Stability stability;
private final UnstableApiAnnotationResourceDefinition.UnstableApiAnnotationLevel level;

Expand All @@ -59,9 +60,8 @@ public ScanUnstableApiAnnotationsProcessor(RunningMode runningMode, Stability st
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
} else if (!stability.enables(UnstableApiAnnotationResourceDefinition.STABILITY)) {
// We need to be at the level where the feature is enabled or lower
enableScanning = false;
}

Expand All @@ -72,26 +72,30 @@ public ScanUnstableApiAnnotationsProcessor(RunningMode runningMode, Stability st
try {
module = moduleLoader.loadModule(BASE_MODULE_NAME);
} catch (ModuleLoadException e) {
// TODO make this module part of core so it is always there
// We might not have provisioned the module in future
}

if (module != null) {
URL url = module.getExportedResource(INDEX_FILE);

List<URL> urls = new ArrayList<>();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()))) {
String fileName = reader.readLine();
while (fileName != null) {
fileName = fileName.trim();
if (!fileName.isEmpty() && !fileName.startsWith("#")) {
urls.add(module.getExportedResource(fileName));
try {
for (Iterator<Resource> it = module.globResources("**/*"); it.hasNext(); ) {
Resource resource = it.next();
URL url = resource.getURL();
if (!url.getFile().equals(README_TXT)) {
urls.add(resource.getURL());
}
fileName = reader.readLine();
}
} catch (ModuleLoadException e) {
throw new RuntimeException(e);
}

if (!urls.isEmpty()) {
if (!urls.isEmpty()) {
try {
runtimeIndex = RuntimeIndex.load(urls);
} catch(IOException e){
throw new RuntimeException(e);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,5 @@
-->

<tasks xmlns="urn:wildfly:wildfly-feature-pack-tasks:3.1">
<append-file
target="modules/system/layers/base/org/wildfly/_internal/unstable-api-annotation-index/main/content/index.txt"
ignore="true">
<line>wildfly-core-testsuite-unstable-api-annotation-feature-pack.zip</line>
</append-file>
<copy-path src="wildfly-core-testsuite-unstable-api-annotation-feature-pack.zip" relative-to="content" target="modules/system/layers/base/org/wildfly/_internal/unstable-api-annotation-index/main/content/wildfly-core-testsuite-unstable-api-annotation-feature-pack.zip"/>
</tasks>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,23 @@

package org.wildfly.core.test.unstable.api.annotation.reporter;

import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.FAILURE_DESCRIPTION;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SYSTEM_PROPERTY;

import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import jakarta.inject.Inject;

import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.client.ModelControllerClient;
import org.jboss.as.controller.client.Operation;
Expand Down Expand Up @@ -39,21 +55,6 @@
import org.wildfly.extension.core.management.UnstableApiAnnotationResourceDefinition;
import org.wildfly.test.stability.StabilityServerSetupSnapshotRestoreTasks;

import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.FAILURE_DESCRIPTION;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SYSTEM_PROPERTY;

@RunWith(WildFlyRunner.class)
@ServerSetup({UnstableApiAnnotationScannerTestCase.AddUnstableApiAnnotationResourceSetupTask.class, UnstableApiAnnotationScannerTestCase.SystemPropertyServerSetupTask.class})
public class UnstableApiAnnotationScannerTestCase {
Expand All @@ -64,9 +65,9 @@ public class UnstableApiAnnotationScannerTestCase {
private static final String INDEX_MODULE_DIR =
"system/layers/base/org/wildfly/_internal/unstable-api-annotation-index/main";

private static final String CONTENT = "content";
private static final String INDEX_INDEX_FILE = "index.txt";
private static final String README_TXT = "README.txt";

private static final String CONTENT = "content";
private static final String TEST_FEATURE_PACK_INDEX = "wildfly-core-testsuite-unstable-api-annotation-feature-pack.zip";

@Test
Expand All @@ -85,21 +86,10 @@ public void testIndexExists() throws Exception {
Path indexContentDir = indexModulePath.resolve(CONTENT);
Assert.assertTrue(Files.exists(indexContentDir));

Path mainIndexFile = indexContentDir.resolve(INDEX_INDEX_FILE);
Assert.assertTrue(Files.exists(mainIndexFile));

List<String> mainIndexFileList = Files.readAllLines(mainIndexFile)
.stream()
.filter(s -> !s.isEmpty())
.filter(s -> !s.startsWith("#"))
.collect(Collectors.toList());

Assert.assertEquals(1, mainIndexFileList.size());
Assert.assertTrue(mainIndexFileList.contains(TEST_FEATURE_PACK_INDEX));

Set<String> indices = Files.list(indexContentDir)
.filter(p -> !p.getFileName().toString().equals(INDEX_INDEX_FILE))
.map(p -> p.getFileName().toString())
.filter(f -> !f.equals(README_TXT))
.collect(Collectors.toSet());

Assert.assertEquals(1, indices.size());
Expand Down