enumClass, String key, T defaultV
throw new IllegalArgumentException( "No enum instance '" + raw + "' in " + enumClass.getName() );
}
+ /**
+ * Orphans are arguments specified without options flags, eg:
+ *
+ * myprogram -o blah orphan1 orphan2
+ *
+ * Would yield a list here of {@code "orphan1"} and {@code "orphan2"}.
+ *
+ * @return list of orphan arguments
+ */
public List orphans()
{
return new ArrayList<>( this.orphans );
}
+ /** @see #orphans() **/
public String[] orphansAsArray()
{
return orphans.toArray( new String[orphans.size()] );
diff --git a/community/kernel/src/main/java/org/neo4j/kernel/configuration/docs/GenerateConfigDocumentation.java b/community/kernel/src/main/java/org/neo4j/kernel/configuration/docs/GenerateConfigDocumentation.java
index 95e164b08cd26..89442c4dd0f26 100644
--- a/community/kernel/src/main/java/org/neo4j/kernel/configuration/docs/GenerateConfigDocumentation.java
+++ b/community/kernel/src/main/java/org/neo4j/kernel/configuration/docs/GenerateConfigDocumentation.java
@@ -20,7 +20,10 @@
package org.neo4j.kernel.configuration.docs;
import java.io.File;
+import java.util.List;
+import java.util.function.Function;
+import org.neo4j.helpers.Args;
import org.neo4j.io.fs.FileUtils;
/**
@@ -28,34 +31,40 @@
*/
public class GenerateConfigDocumentation
{
- public static void main( String[] args ) throws Exception
+ public static void main( String[] argv ) throws Exception
{
- File output = null;
- String bundleName = null;
- if(args.length > 0)
- {
- bundleName = args[0];
-
- if(args.length > 1)
- {
- output = new File(args[1]).getAbsoluteFile();
- }
-
- } else
+ Args arguments = Args.parse( argv );
+
+ File output = arguments.has( "o" ) ? new File(arguments.get("o")) : null;
+ List settingsClasses = arguments.orphans();
+ if(settingsClasses.size() == 0)
{
- System.out.println("Usage: GenerateConfigDocumentation CONFIG_BUNDLE_CLASS [output file]");
+ System.out.println("Usage: GenerateConfigDocumentation [-o output file] SETTINGS_CLASS..");
System.exit(0);
}
- String doc = new SettingsDocumenter().document( Class.forName( bundleName ) );
+ String doc = new SettingsDocumenter()
+ .document( settingsClasses.stream().map( classFromString ) );
if(output != null)
{
- System.out.println("Saving docs for '"+bundleName+"' in '" + output.getAbsolutePath() + "'.");
+ System.out.println("Saving docs in '" + output.getAbsolutePath() + "'.");
FileUtils.writeToFile(output, doc, false);
} else
{
System.out.println(doc);
}
}
+
+ private static Function> classFromString = (Function>) ( className ) -> {
+ try
+ {
+ return Class.forName( className );
+ }
+ catch ( ClassNotFoundException e )
+ {
+ throw new RuntimeException( e );
+ }
+ };
+
}
diff --git a/community/kernel/src/main/java/org/neo4j/kernel/configuration/docs/SettingDescription.java b/community/kernel/src/main/java/org/neo4j/kernel/configuration/docs/SettingDescription.java
index f99ce53c56107..3859818145e49 100644
--- a/community/kernel/src/main/java/org/neo4j/kernel/configuration/docs/SettingDescription.java
+++ b/community/kernel/src/main/java/org/neo4j/kernel/configuration/docs/SettingDescription.java
@@ -38,29 +38,8 @@ public final class SettingDescription
private final boolean isMandatory;
private final boolean hasDefault;
- public SettingDescription( String name, String description, String mandatoryDescription, String deprecationDescription,
- String validationDescription, String defaultValue,
- boolean isDeprecated, boolean isMandatory, boolean hasDefault )
- {
-
- this(
- // {key} is used for documenting group config, and this is not
- // allowed in asciidoc references. Strip out the curlies.
- "config_" + (name.replace( "{", "").replace( "}", "" ) ),
- // And similarly, curlies need to be escaped when used in prose text
- name.replace( "{", "\\{" ).replace( "}", "\\}" ),
-
- description, mandatoryDescription, deprecationDescription,
- validationDescription, defaultValue, isDeprecated, isMandatory, hasDefault );
- }
-
- public SettingDescription( String id, String name, String description )
- {
- this( id, name, description, null, null, null, null, false, false, false );
- }
-
- private SettingDescription( String id, String name, String description,
- String mandatoryDescription, String deprecationDescription,
+ public SettingDescription( String id, String name, String description, String mandatoryDescription, String
+ deprecationDescription,
String validationDescription, String defaultValue,
boolean isDeprecated, boolean isMandatory, boolean hasDefault )
{
@@ -70,12 +49,17 @@ private SettingDescription( String id, String name, String description,
this.validationDescription = validationDescription;
this.defaultValue = defaultValue;
this.isDeprecated = isDeprecated;
- this.name = name;
+ this.name = name.replace( "{", "\\{" ).replace( "}", "\\}" );
this.description = description;
this.isMandatory = isMandatory;
this.hasDefault = hasDefault;
}
+ public SettingDescription( String id, String name, String description )
+ {
+ this( id, name, description, null, null, null, null, false, false, false );
+ }
+
public String id()
{
return id;
diff --git a/community/kernel/src/main/java/org/neo4j/kernel/configuration/docs/SettingsDescription.java b/community/kernel/src/main/java/org/neo4j/kernel/configuration/docs/SettingsDescription.java
index 7d4dcc1231666..61b05460c110f 100644
--- a/community/kernel/src/main/java/org/neo4j/kernel/configuration/docs/SettingsDescription.java
+++ b/community/kernel/src/main/java/org/neo4j/kernel/configuration/docs/SettingsDescription.java
@@ -20,10 +20,10 @@
package org.neo4j.kernel.configuration.docs;
import java.lang.reflect.Field;
+import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
-import java.util.function.Function;
import java.util.stream.Stream;
import org.neo4j.graphdb.config.Setting;
@@ -40,20 +40,19 @@ public class SettingsDescription
/**
* Create a description of a given class.
*/
- public static SettingsDescription describe( Class> settingClass ) throws Exception
+ public static SettingsDescription describe( Class> settingClass )
{
String classDescription = settingClass.isAnnotationPresent( Description.class )
? settingClass.getAnnotation( Description.class ).value()
: "List of configuration settings";
+ String settingsName = settingClass.getName().replace( "$", "-" );
Object instance = null;
for(Class> cls = settingClass; cls != null; cls = cls.getSuperclass() )
{
if( cls.isAnnotationPresent( Group.class ) )
{
- // Group classes are special, we need to instantiate them to read their
- // configuration, this is how the group config DSL works
- instance = settingClass.getConstructor( String.class ).newInstance( "{key}" );
+ instance = groupInstance( settingClass );
break;
}
}
@@ -87,6 +86,7 @@ public static SettingsDescription describe( Class> settingClass ) throws Excep
}
settings.add( new SettingDescription(
+ "config_" + (name.replace( "{", "").replace( "}", "" ) ),
name, description,
mandatoryMessage,
deprecationMessage,
@@ -101,11 +101,25 @@ public static SettingsDescription describe( Class> settingClass ) throws Excep
return new SettingsDescription(
// Nested classes have `$` in the name, which is an asciidoc keyword
- settingClass.getName().replace( "$", "-" ),
+ settingsName,
classDescription,
settings );
}
+ private static Object groupInstance( Class> settingClass )
+ {
+ try
+ {
+ // Group classes are special, we need to instantiate them to read their
+ // configuration, this is how the group config DSL works
+ return settingClass.newInstance();
+ }
+ catch(Exception e)
+ {
+ throw new RuntimeException( e );
+ }
+ }
+
private static Optional> fieldAsSetting( Class> settingClass, Object instance, Field field )
{
Setting> setting;
@@ -162,4 +176,22 @@ public String name()
{
return name;
}
+
+ /**
+ * Combine this description with another one. This is an immutable operation,
+ * meaning it returns a new description that is the combination of this and the
+ * one passed in.
+ *
+ * The name and description is taken from this description, name and setting
+ * from the provided one are discarded.
+ *
+ * @param other another setting description
+ * @return the union of this and the provided settings description
+ */
+ public SettingsDescription union( SettingsDescription other )
+ {
+ ArrayList union = new ArrayList<>( this.settings );
+ union.addAll( other.settings );
+ return new SettingsDescription( name, description, union );
+ }
}
diff --git a/community/kernel/src/main/java/org/neo4j/kernel/configuration/docs/SettingsDocumenter.java b/community/kernel/src/main/java/org/neo4j/kernel/configuration/docs/SettingsDocumenter.java
index 510120b67c19a..fb3fc5060a75b 100644
--- a/community/kernel/src/main/java/org/neo4j/kernel/configuration/docs/SettingsDocumenter.java
+++ b/community/kernel/src/main/java/org/neo4j/kernel/configuration/docs/SettingsDocumenter.java
@@ -27,6 +27,7 @@
import java.util.function.Predicate;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import java.util.stream.Stream;
import static java.util.stream.Collectors.toList;
import static org.neo4j.kernel.configuration.docs.SettingsDescription.describe;
@@ -37,10 +38,10 @@ public class SettingsDocumenter
private static final Predicate DEPRECATED_SETTINGS = SettingDescription::isDeprecated;
private static final Pattern CONFIG_SETTING_PATTERN = Pattern.compile( "[a-z0-9]+((\\.|_)[a-z0-9]+)+" );
- // TODO: This one, and the blacklist below, exist because we try and infer what a config option
- // is from prose text. This is fraught with accidental error. We should instead look into
+ // TODO: This one, and the blacklist below, exist because we try and infer what is a config name
+ // in prose text. This is fraught with accidental error. We should instead look into
// adopting a convention for how we mark references to other config options in the @Description
- // et cetera, for instance "`my.setting`".
+ // et cetera, for instance using back-ticks: "`my.setting`".
private static final Pattern NUMBER_OR_IP = Pattern.compile( "[0-9\\.]+" );
private static final List CONFIG_NAMES_BLACKLIST = Arrays.asList( "round_robin", "keep_all", "keep_last",
"keep_none", "metrics.neo4j", "i.e", "e.g", "fixed_ascending", "fixed_descending" );
@@ -51,6 +52,21 @@ public class SettingsDocumenter
private PrintStream out;
+ /**
+ * Document a set of configuration classes together as a combined asciidoc section.
+ * @param settings one or more settings classes.
+ * @return asciidoc content
+ * @throws Exception
+ */
+ public String document( Stream> settings ) throws Exception
+ {
+ SettingsDescription combinedDescription = settings
+ .map( SettingsDescription::describe )
+ .reduce( SettingsDescription::union )
+ .get();
+ return document( combinedDescription );
+ }
+
public String document( Class> settings ) throws Exception
{
return document( describe( settings ) );
diff --git a/community/kernel/src/test/java/org/neo4j/kernel/configuration/docs/SettingsDocumenterTest.java b/community/kernel/src/test/java/org/neo4j/kernel/configuration/docs/SettingsDocumenterTest.java
index a808c5c22c53f..62d4509707536 100644
--- a/community/kernel/src/test/java/org/neo4j/kernel/configuration/docs/SettingsDocumenterTest.java
+++ b/community/kernel/src/test/java/org/neo4j/kernel/configuration/docs/SettingsDocumenterTest.java
@@ -19,10 +19,10 @@
*/
package org.neo4j.kernel.configuration.docs;
-import java.io.File;
-
import org.junit.Test;
+import java.io.File;
+
import org.neo4j.graphdb.config.Setting;
import org.neo4j.graphdb.factory.Description;
import org.neo4j.kernel.configuration.Group;
@@ -31,7 +31,6 @@
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
-
import static org.neo4j.kernel.configuration.Settings.BOOLEAN;
import static org.neo4j.kernel.configuration.Settings.INTEGER;
import static org.neo4j.kernel.configuration.Settings.NO_DEFAULT;
@@ -279,6 +278,11 @@ public static class Giraffe extends Animal
@Description( "Number of spots this giraffe has, in number." )
public final Setting number_of_spots;
+ public Giraffe()
+ {
+ this("{giraffeKey}");
+ }
+
public Giraffe(String key)
{
super(key, /* type=*/"giraffe");
diff --git a/community/server/pom.xml b/community/server/pom.xml
index ff49061ef7cb4..e7f5f68e79014 100644
--- a/community/server/pom.xml
+++ b/community/server/pom.xml
@@ -511,24 +511,6 @@
run
-
- generate-source-based-config-documentation
- ${generate-config-docs-phase}
-
-
-
-
-
-
-
-
-
-
-
-
- run
-
diff --git a/community/server/src/main/java/org/neo4j/server/configuration/ServerSettings.java b/community/server/src/main/java/org/neo4j/server/configuration/ServerSettings.java
index f17c516160233..13eddf4523661 100644
--- a/community/server/src/main/java/org/neo4j/server/configuration/ServerSettings.java
+++ b/community/server/src/main/java/org/neo4j/server/configuration/ServerSettings.java
@@ -79,6 +79,12 @@ class HttpConnector extends GraphDatabaseSettings.Connector
@Description("Address the connector should bind to")
public final Setting address;
+
+ public HttpConnector()
+ {
+ this( "{http-connector-key}" );
+ }
+
public HttpConnector( String key )
{
super( key, ConnectorType.HTTP.name() );
diff --git a/community/shell/pom.xml b/community/shell/pom.xml
index 8e04fa8c9cb48..3324809adf33c 100644
--- a/community/shell/pom.xml
+++ b/community/shell/pom.xml
@@ -76,25 +76,6 @@ the relevant Commercial Agreement.