Fixed doc generation
This commit is contained in:
parent
f06dbb302c
commit
2975b5d613
7
pom.xml
7
pom.xml
|
@ -56,6 +56,13 @@
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-api</artifactId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- https://mvnrepository.com/artifact/org.nuiton.jrst/jrst -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.nuiton.jrst</groupId>
|
||||||
|
<artifactId>jrst</artifactId>
|
||||||
|
<version>2.4</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- Test Dependencies -->
|
<!-- Test Dependencies -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package org.gcube.informationsystem.utils.documentation.generator;
|
package org.gcube.informationsystem.utils.documentation.generator;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.ServiceLoader;
|
import java.util.ServiceLoader;
|
||||||
|
@ -24,7 +23,7 @@ public class ClassesDiscoveryGenerator extends Generator {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected List<Package> getPackages(){
|
public List<Package> getPackages(){
|
||||||
|
|
||||||
List<Package> packages = new ArrayList<Package>();
|
List<Package> packages = new ArrayList<Package>();
|
||||||
|
|
||||||
|
@ -38,25 +37,32 @@ public class ClassesDiscoveryGenerator extends Generator {
|
||||||
Class<Element> clz = accessType.getTypeClass();
|
Class<Element> clz = accessType.getTypeClass();
|
||||||
packages.add(clz.getPackage());
|
packages.add(clz.getPackage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return packages;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Package> getExtensionsPackages(){
|
||||||
|
List<Package> packages = new ArrayList<Package>();
|
||||||
ServiceLoader<? extends RegistrationProvider> regsitrationProviders = ServiceLoader
|
ServiceLoader<? extends RegistrationProvider> regsitrationProviders = ServiceLoader
|
||||||
.load(RegistrationProvider.class);
|
.load(RegistrationProvider.class);
|
||||||
for(RegistrationProvider registrationProvider : regsitrationProviders) {
|
for(RegistrationProvider registrationProvider : regsitrationProviders) {
|
||||||
packages.addAll(registrationProvider.getPackagesToRegister());
|
packages.addAll(registrationProvider.getPackagesToRegister());
|
||||||
}
|
}
|
||||||
|
|
||||||
return packages;
|
return packages;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void generate() throws Exception {
|
public void generate() throws Exception {
|
||||||
List<Package> pkgs = getPackages();
|
List<Package> packages = getPackages();
|
||||||
generate(pkgs.toArray(new Package[pkgs.size()]));
|
packages.addAll(getExtensionsPackages());
|
||||||
|
generate(packages);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected <E extends Element> void discover(AccessType at, Package[] packages) throws Exception {
|
protected <E extends Element> void discover(AccessType at, List<Package> packages) throws Exception {
|
||||||
ElementSpecilizationDiscovery<E> discovery = new ElementSpecilizationDiscovery<>(at.getTypeClass(), false);
|
ElementSpecilizationDiscovery<E> discovery = new ElementSpecilizationDiscovery<>(at.getTypeClass(), false);
|
||||||
if(Objects.nonNull(packages)) {
|
if(Objects.nonNull(packages)) {
|
||||||
Arrays.stream(packages).forEach(p -> discovery.addPackage(p));
|
for(Package p : packages) {
|
||||||
|
discovery.addPackage(p);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
discovery.discover();
|
discovery.discover();
|
||||||
|
|
||||||
|
@ -66,7 +72,7 @@ public class ClassesDiscoveryGenerator extends Generator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void generate(Package[] packages) throws Exception {
|
public void generate(List<Package> packages) throws Exception {
|
||||||
treeGenerator = new TreeGenerator();
|
treeGenerator = new TreeGenerator();
|
||||||
AccessType[] types = new AccessType[] {
|
AccessType[] types = new AccessType[] {
|
||||||
AccessType.PROPERTY,
|
AccessType.PROPERTY,
|
||||||
|
|
|
@ -30,6 +30,16 @@ public abstract class DocumentationGenerator {
|
||||||
public static final String NO_ADDITIONAL_ATTRIBUTE = "This type does not define any additional attributes.";
|
public static final String NO_ADDITIONAL_ATTRIBUTE = "This type does not define any additional attributes.";
|
||||||
public static final String NO_SPECIFIC_KNOWN_USAGE = "No specific known usage for this type.";
|
public static final String NO_SPECIFIC_KNOWN_USAGE = "No specific known usage for this type.";
|
||||||
|
|
||||||
|
protected static int defaultOffsetLevel = 0;
|
||||||
|
|
||||||
|
public static int getDefaultOffsetLevel() {
|
||||||
|
return defaultOffsetLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setDefaultOffsetLevel(int defaultOffsetLevel) {
|
||||||
|
DocumentationGenerator.defaultOffsetLevel = defaultOffsetLevel;
|
||||||
|
}
|
||||||
|
|
||||||
protected final Type type;
|
protected final Type type;
|
||||||
protected final AccessType requiredType;
|
protected final AccessType requiredType;
|
||||||
protected String superClassToBeExcluded;
|
protected String superClassToBeExcluded;
|
||||||
|
@ -46,7 +56,7 @@ public abstract class DocumentationGenerator {
|
||||||
}
|
}
|
||||||
this.requiredNumberOfColumns = DEFAULT_NUMBER_OF_COLUMNS;
|
this.requiredNumberOfColumns = DEFAULT_NUMBER_OF_COLUMNS;
|
||||||
this.superClassToBeExcluded = null;
|
this.superClassToBeExcluded = null;
|
||||||
this.offsetLevel = 0;
|
this.offsetLevel = DocumentationGenerator.defaultOffsetLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLevel(int level) {
|
public void setLevel(int level) {
|
||||||
|
@ -338,7 +348,7 @@ public abstract class DocumentationGenerator {
|
||||||
Section section = new Section();
|
Section section = new Section();
|
||||||
int sectionLevel = level+offsetLevel;
|
int sectionLevel = level+offsetLevel;
|
||||||
SectionType[] sectionTypes = SectionType.values();
|
SectionType[] sectionTypes = SectionType.values();
|
||||||
int maxSectionLevel = sectionTypes.length;
|
int maxSectionLevel = sectionTypes.length-1;
|
||||||
sectionLevel = sectionLevel>=maxSectionLevel ? maxSectionLevel : sectionLevel;
|
sectionLevel = sectionLevel>=maxSectionLevel ? maxSectionLevel : sectionLevel;
|
||||||
SectionType sectionType = SectionType.values()[sectionLevel];
|
SectionType sectionType = SectionType.values()[sectionLevel];
|
||||||
section.setSectionType(sectionType);
|
section.setSectionType(sectionType);
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package org.gcube.informationsystem.utils.documentation;
|
package org.gcube.informationsystem.utils.documentation;
|
||||||
|
|
||||||
import org.gcube.informationsystem.utils.documentation.generator.ClassesDiscoveryGenerator;
|
import org.gcube.informationsystem.utils.documentation.generator.ClassesDiscoveryGenerator;
|
||||||
|
import org.gcube.informationsystem.utils.documentation.model.DocumentationGenerator;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -10,7 +11,9 @@ public class GenerateTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDocGeneration() throws Exception {
|
public void testDocGeneration() throws Exception {
|
||||||
|
DocumentationGenerator.setDefaultOffsetLevel(2);
|
||||||
ClassesDiscoveryGenerator documentationGenerator = new ClassesDiscoveryGenerator();
|
ClassesDiscoveryGenerator documentationGenerator = new ClassesDiscoveryGenerator();
|
||||||
documentationGenerator.generate();
|
documentationGenerator.generate();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue