Skip to content

Commit

Permalink
Merge pull request #28 from jfdenise/main
Browse files Browse the repository at this point in the history
Rule description contains only rule classes. Split documentation between repositories first step
  • Loading branch information
jfdenise authored Nov 29, 2023
2 parents a4a7011 + 696abbd commit 805a12d
Show file tree
Hide file tree
Showing 8 changed files with 334 additions and 266 deletions.
10 changes: 6 additions & 4 deletions core/src/main/java/org/wildfly/glow/FeaturePacks.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public class FeaturePacks {
private static final String PROVISIONING_FILE_RADICAL = "/provisioning-";
private static final String TECH_PREVIEW = "/tech-preview/";

public static final String URL_PROPERTY = "wildfly-glow-galleon-feature-packs-url";

public static Path getFeaturePacks(String version, String context, boolean techPreview) throws Exception {
try {
String rootURL = getFeaturePacksURL();
Expand All @@ -61,11 +63,11 @@ public static Path getFeaturePacks(String version, String context, boolean techP
}

public static String getFeaturePacksURL() throws Exception {
String rootURL = Utils.getConfigEntry("wildfly-glow-galleon-feature-packs-url");
if(rootURL == null) {
throw new Exception("No wildfly-glow-galleon-feature-packs-url entry found");
String rootURL = Utils.getConfigEntry(URL_PROPERTY);
if (rootURL == null) {
throw new Exception("No " + URL_PROPERTY + " entry found");
}
if(!rootURL.endsWith("/")) {
if (!rootURL.endsWith("/")) {
rootURL = rootURL + "/";
}
return rootURL;
Expand Down
115 changes: 93 additions & 22 deletions core/src/main/java/org/wildfly/glow/LayerMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,101 @@
*/
package org.wildfly.glow;

import java.util.Set;
import java.util.TreeSet;

/**
*
* @author jdenise
*/
public interface LayerMetadata {
String PREFIX = "org.wildfly.rule.";

String ADD_ON = PREFIX + "add-on";
String ADD_ON_CARDINALITY = PREFIX + "add-on-cardinality";
String ADD_ON_DEPENDS_ON = PREFIX + "add-on-depends-on";
String ADD_ON_DESCRIPTION = PREFIX + "add-on-description";
String ADD_ON_FIX = PREFIX + "add-on-fix-";
String ANNOTATIONS = PREFIX + "annotations";
String BRING_DATASOURCE = PREFIX + "bring-datasource";
String CLASS = PREFIX + "class";
String CONFIGURATION = PREFIX + "configuration";
String EXPECT_ADD_ON_FAMILY = PREFIX + "expect-add-on-family";
String EXPECTED_FILE = PREFIX + "expected-file";
String HIDDEN_IF = PREFIX + "hidden-if";
String INCLUSION_MODE = PREFIX + "inclusion-mode";
String KIND = PREFIX + "kind";
String NO_CONFIGURATION_IF = PREFIX + "no-configuration-if";
String NOT_EXPECTED_FILE = PREFIX + "not-expected-file";
String PROFILE = PREFIX + "profile-";
String PROPERTIES_FILE_MATCH = PREFIX + "properties-file-match";
String XML_PATH = PREFIX + "xml-path";
public abstract class LayerMetadata {

public static final String PREFIX = "org.wildfly.rule.";

public static final String ADD_ON = PREFIX + "add-on";
public static final String ADD_ON_CARDINALITY = PREFIX + "add-on-cardinality";
public static final String ADD_ON_DEPENDS_ON = PREFIX + "add-on-depends-on";
public static final String ADD_ON_DESCRIPTION = PREFIX + "add-on-description";
public static final String ADD_ON_FIX = PREFIX + "add-on-fix-";
public static final String ANNOTATIONS = PREFIX + "annotations";
public static final String BRING_DATASOURCE = PREFIX + "bring-datasource";
public static final String CLASS = PREFIX + "class";
public static final String CONFIGURATION = PREFIX + "configuration";
public static final String EXPECT_ADD_ON_FAMILY = PREFIX + "expect-add-on-family";
public static final String EXPECTED_FILE = PREFIX + "expected-file";
public static final String HIDDEN_IF = PREFIX + "hidden-if";
public static final String INCLUSION_MODE = PREFIX + "inclusion-mode";
public static final String KIND = PREFIX + "kind";
public static final String NO_CONFIGURATION_IF = PREFIX + "no-configuration-if";
public static final String NOT_EXPECTED_FILE = PREFIX + "not-expected-file";
public static final String PROFILE = PREFIX + "profile-";
public static final String PROPERTIES_FILE_MATCH = PREFIX + "properties-file-match";
public static final String XML_PATH = PREFIX + "xml-path";
private static final Set<String> ALL_RULES = new TreeSet<>();
private static final Set<String> FULLY_NAMED_RULES = new TreeSet<>();
private static final Set<String> RULES_WITH_SUFFIX = new TreeSet<>();
private static final Set<String> CONDITION_RULES = new TreeSet<>();

static {
FULLY_NAMED_RULES.add(ADD_ON);
FULLY_NAMED_RULES.add(ADD_ON_CARDINALITY);
FULLY_NAMED_RULES.add(ADD_ON_DEPENDS_ON);
FULLY_NAMED_RULES.add(ADD_ON_DESCRIPTION);

FULLY_NAMED_RULES.add(ANNOTATIONS);
FULLY_NAMED_RULES.add(BRING_DATASOURCE);
FULLY_NAMED_RULES.add(CLASS);
FULLY_NAMED_RULES.add(CONFIGURATION);
FULLY_NAMED_RULES.add(EXPECT_ADD_ON_FAMILY);
FULLY_NAMED_RULES.add(INCLUSION_MODE);
FULLY_NAMED_RULES.add(KIND);

RULES_WITH_SUFFIX.add(ADD_ON_FIX);
RULES_WITH_SUFFIX.add(EXPECTED_FILE);
RULES_WITH_SUFFIX.add(NOT_EXPECTED_FILE);
RULES_WITH_SUFFIX.add(PROFILE);
RULES_WITH_SUFFIX.add(PROPERTIES_FILE_MATCH);
RULES_WITH_SUFFIX.add(XML_PATH);

CONDITION_RULES.add(HIDDEN_IF);
CONDITION_RULES.add(NO_CONFIGURATION_IF);

ALL_RULES.addAll(FULLY_NAMED_RULES);
ALL_RULES.addAll(RULES_WITH_SUFFIX);
ALL_RULES.addAll(CONDITION_RULES);

}

public static Set<String> getAllRules() {
return ALL_RULES;
}

public static Set<String> getFullyNamedRules() {
return FULLY_NAMED_RULES;
}

public static Set<String> getRadicalOnlyNamedRules() {
return RULES_WITH_SUFFIX;
}

public static Set<String> getConditionRules() {
return CONDITION_RULES;
}

public static String getRuleClass(String k) {
if (FULLY_NAMED_RULES.contains(k)) {
return k;
}
for (String c : CONDITION_RULES) {
if (k.startsWith(c)) {
return c;
}
}
for (String c : RULES_WITH_SUFFIX) {
if (k.startsWith(c)) {
return c;
}
}
return null;
}
}
127 changes: 76 additions & 51 deletions doc-plugin/src/main/java/org/wildfly/glow/plugin/doc/ScanDocMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import java.util.Properties;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
import org.jboss.galleon.config.FeaturePackConfig;
import org.jboss.galleon.config.ProvisioningConfig;
import org.jboss.galleon.layout.FeaturePackLayout;
Expand All @@ -53,6 +52,7 @@
import org.jboss.galleon.universe.maven.repo.MavenRepoManager;
import org.jboss.galleon.xml.ProvisioningXmlParser;
import org.wildfly.glow.FeaturePacks;
import org.wildfly.glow.LayerMetadata;
import org.wildfly.glow.Utils;

/**
Expand All @@ -76,62 +76,87 @@ public class ScanDocMojo extends AbstractMojo {
@Parameter(defaultValue = "${project.remoteProjectRepositories}", readonly = true, required = true)
List<RemoteRepository> repositories;

@Parameter(defaultValue = "${project.build.directory}/rules.adoc")
@Parameter(defaultValue = "rules.adoc")
String generatedFile;

@Parameter(required = true)
@Parameter(defaultValue = "${project.build.directory}")
String targetDir;

@Parameter(required = false)
String rulesPropertiesFile;

@Parameter(required = false, defaultValue = "true")
boolean generateRuleDescriptions;

@Parameter(required = false, defaultValue = "true")
boolean generateKnownFeaturePacks;

@Parameter(required = false)
String repoPath;

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
try {

//Typically under target
Path outputFolder = Paths.get(project.getBuild().getDirectory());
MavenRepoManager artifactResolver = new MavenArtifactRepositoryManager(repoSystem, repoSession, repositories);
UniverseResolver universeResolver = UniverseResolver.builder().addArtifactResolver(artifactResolver).build();
Map<Layer, Map<String, String>> rules = new TreeMap<>();
Set<String> ruleDescriptions = new TreeSet<>();
StringBuilder rulesBuilder = new StringBuilder();
Properties properties = new Properties();
try (FileInputStream in = new FileInputStream(Paths.get(rulesPropertiesFile).toFile())) {
properties.load(in);
}

getRules("bare-metal", universeResolver, rules, ruleDescriptions);
Map<Layer, Map<String, String>> cloudRules = new TreeMap<>();
getRules("cloud", universeResolver, cloudRules, ruleDescriptions);

rulesBuilder.append("== [[glow.table.rules]]Rules descriptions\n");
rulesBuilder.append("[cols=\"1,2,1\"]\n");
rulesBuilder.append("|===\n");
rulesBuilder.append("|Rule |Description |Value\n");
for (String k : ruleDescriptions) {
rulesBuilder.append("|[[glow." + k + "]]" + k + "\n");
String desc = properties.getProperty(k);
String val = properties.getProperty(k + ".value");
if (desc == null) {
throw new Exception("Missing rule description for " + k + " in " + rulesPropertiesFile);
if (generateRuleDescriptions) {
Properties properties = new Properties();
try (FileInputStream in = new FileInputStream(Paths.get(rulesPropertiesFile).toFile())) {
properties.load(in);
}
if (val == null) {
throw new Exception("Missing rule example value for " + k + " in " + rulesPropertiesFile);

rulesBuilder.append("== [[glow.table.rules]]Rules descriptions\n");
rulesBuilder.append("[cols=\"1,2,1\"]\n");
rulesBuilder.append("|===\n");
rulesBuilder.append("|Rule |Description |Value\n");
for (String k : LayerMetadata.getAllRules()) {
rulesBuilder.append("|[[glow." + k + "]]" + k + "\n");
String desc = properties.getProperty(k);
String val = properties.getProperty(k + ".value");
if (desc == null) {
throw new Exception("Missing rule description for " + k + " in " + rulesPropertiesFile);
}
if (val == null) {
throw new Exception("Missing rule example value for " + k + " in " + rulesPropertiesFile);
}
rulesBuilder.append("|" + desc + "\n");
rulesBuilder.append("|" + val + "\n");
}
rulesBuilder.append("|" + desc + "\n");
rulesBuilder.append("|" + val + "\n");
rulesBuilder.append("|===\n");
}
rulesBuilder.append("|===\n");

rulesBuilder.append("## Support for WildFly " + FeaturePacks.getLatestVersion() + "\n\n");

rulesBuilder.append(buildTable("bare-metal", rules, false));
rulesBuilder.append(buildTable("cloud", cloudRules, false));

rulesBuilder.append("## Support for WildFly Preview " + FeaturePacks.getLatestVersion() + "\n\n");

rulesBuilder.append(buildTable("bare-metal", rules, true));
rulesBuilder.append(buildTable("cloud", cloudRules, true));

Files.writeString(Paths.get(generatedFile), rulesBuilder.toString());
if (generateKnownFeaturePacks) {
if (repoPath != null) {
Path p = Paths.get(repoPath);
String repoUrl = "file://" + p.toAbsolutePath();
System.out.println("Using repo url " + repoUrl);
System.setProperty(FeaturePacks.URL_PROPERTY, repoUrl);
}
try {
//Typically under target
Path outputFolder = Paths.get(project.getBuild().getDirectory());
MavenRepoManager artifactResolver = new MavenArtifactRepositoryManager(repoSystem, repoSession, repositories);
UniverseResolver universeResolver = UniverseResolver.builder().addArtifactResolver(artifactResolver).build();
Map<Layer, Map<String, String>> rules = new TreeMap<>();

getRules("bare-metal", universeResolver, rules);
Map<Layer, Map<String, String>> cloudRules = new TreeMap<>();
getRules("cloud", universeResolver, cloudRules);
rulesBuilder.append("## Support for WildFly " + FeaturePacks.getLatestVersion() + "\n\n");

rulesBuilder.append(buildTable("bare-metal", rules, false));
rulesBuilder.append(buildTable("cloud", cloudRules, false));

rulesBuilder.append("## Support for WildFly Preview " + FeaturePacks.getLatestVersion() + "\n\n");

rulesBuilder.append(buildTable("bare-metal", rules, true));
rulesBuilder.append(buildTable("cloud", cloudRules, true));
} finally {
System.clearProperty(FeaturePacks.URL_PROPERTY);
}
}
Path dir = Paths.get(targetDir);
Files.createDirectories(dir);
Files.writeString(dir.resolve(generatedFile), rulesBuilder.toString());
} catch (Exception ex) {
throw new MojoExecutionException(ex);
}
Expand All @@ -156,7 +181,11 @@ private String buildTable(String context, Map<Layer, Map<String, String>> rules,
rulesBuilder.append("|\n");
Map<String, String> local = rules.get(l);
for (String k : local.keySet()) {
rulesBuilder.append("link:#glow." + k + "[" + k + "]" + "=" + local.get(k)).append(" +\n");
String ruleClass = LayerMetadata.getRuleClass(k);
if (ruleClass == null) {
throw new Exception("Unknown rule " + k);
}
rulesBuilder.append("link:#glow." + ruleClass + "[" + k + "]" + "=" + local.get(k)).append(" +\n");
}
rulesBuilder.append("l|\n");
for (FeaturePackLocation.FPID id : l.getFeaturePacks()) {
Expand All @@ -168,8 +197,7 @@ private String buildTable(String context, Map<Layer, Map<String, String>> rules,
}

private void getRules(String context, UniverseResolver universeResolver,
Map<Layer, Map<String, String>> rules,
Set<String> ruleDescriptions) throws Exception {
Map<Layer, Map<String, String>> rules) throws Exception {
try (ProvisioningLayout<FeaturePackLayout> layout = Utils.buildLayout(context,
null, null, GlowMessageWriter.DEFAULT, false)) {
Map<String, Layer> all;
Expand All @@ -184,9 +212,6 @@ private void getRules(String context, UniverseResolver universeResolver,
if (!l.getProperties().isEmpty()) {
Map<String, String> props = rules.computeIfAbsent(l, (value) -> new TreeMap<>());
props.putAll(l.getProperties());
for (String k : l.getProperties().keySet()) {
ruleDescriptions.add(k);
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion docs/guide/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ Jean-Francois Denise
include::intro/index.adoc[]
include::cli/index.adoc[]
include::test-maven-plugin/index.adoc[]
include::rules.adoc[]
include::rules.adoc[]
include::server/index.adoc[]
8 changes: 8 additions & 0 deletions docs/guide/server/index.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[[glow_server]]
## Support for latest WildFly

The following documentation is defined by the link:https://github.com/wildfly/wildfly-galleon-feature-packs[WildFly Galleon feature-packs repository].
It contains the known WildFly (and WildFly Preview) feature-packs and layers for the various execution contexts (`cloud` and `bare-metal`).

* link:wildfly-galleon-feature-packs[Known feature-packs and layers]
Loading

0 comments on commit 805a12d

Please sign in to comment.