use of io.siddhi.doc.gen.metadata.NamespaceMetaData in project siddhi by wso2.
the class MkdocsGitHubPagesDeployMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
// Finding the root maven project
MavenProject rootMavenProject = mavenProject;
while (rootMavenProject.getParent() != null && rootMavenProject.getParent().getBasedir() != null) {
rootMavenProject = rootMavenProject.getParent();
}
// Setting the relevant modules target directory if not set by user
String moduleTargetPath;
if (moduleTargetDirectory != null) {
moduleTargetPath = moduleTargetDirectory.getAbsolutePath();
} else {
moduleTargetPath = mavenProject.getBuild().getDirectory();
}
// Setting the mkdocs config file path if not set by user
if (mkdocsConfigFile == null) {
mkdocsConfigFile = new File(rootMavenProject.getBasedir() + File.separator + Constants.MKDOCS_CONFIG_FILE_NAME + Constants.YAML_FILE_EXTENSION);
}
// Setting the documentation output directory if not set by user
String docGenBasePath;
if (docGenBaseDirectory != null) {
docGenBasePath = docGenBaseDirectory.getAbsolutePath();
} else {
docGenBasePath = rootMavenProject.getBasedir() + File.separator + Constants.DOCS_DIRECTORY;
}
// Setting the home page file name if not set by user
File homePageFile;
if (homePageFileName == null) {
homePageFile = new File(docGenBasePath + File.separator + Constants.HOMEPAGE_FILE_NAME + Constants.MARKDOWN_FILE_EXTENSION);
} else {
homePageFile = new File(docGenBasePath + File.separator + homePageFileName);
}
// Setting the readme file name if not set by user
if (readmeFile == null) {
readmeFile = new File(rootMavenProject.getBasedir() + File.separator + Constants.README_FILE_NAME + Constants.MARKDOWN_FILE_EXTENSION);
}
// Setting the home page template file path if not set by user
if (homePageTemplateFile == null) {
homePageTemplateFile = new File(rootMavenProject.getBasedir() + File.separator + Constants.README_FILE_NAME + Constants.MARKDOWN_FILE_EXTENSION);
}
// Retrieving metadata
List<NamespaceMetaData> namespaceMetaDataList;
try {
namespaceMetaDataList = DocumentationUtils.getExtensionMetaData(moduleTargetPath, mavenProject.getRuntimeClasspathElements(), getLog(), includeOrigin, loadFromAllJars);
} catch (DependencyResolutionRequiredException e) {
throw new MojoFailureException("Unable to resolve dependencies of the project", e);
}
// Generating the documentation
if (namespaceMetaDataList.size() > 0) {
DocumentationUtils.generateDocumentation(namespaceMetaDataList, docGenBasePath, mavenProject.getVersion(), getLog(), siddhiVersion, mavenProject.getGroupId());
}
// Delete snapshot files
DocumentationUtils.removeSnapshotAPIDocs(mkdocsConfigFile, docGenBasePath, getLog());
// Updating the links in the home page to the mkdocs config
String latestVersion = mavenProject.getVersion();
try {
latestVersion = updateAPIPagesInMkdocsConfig(mkdocsConfigFile, docGenBasePath);
} catch (FileNotFoundException e) {
getLog().warn("Unable to find mkdocs configuration file: " + mkdocsConfigFile.getAbsolutePath() + ". Mkdocs configuration file not updated.");
}
// Generating the documentation
if (namespaceMetaDataList.size() > 0) {
DocumentationUtils.updateHeadingsInMarkdownFile(homePageTemplateFile, homePageFile, rootMavenProject.getArtifactId(), latestVersion, namespaceMetaDataList, rootMavenProject.getGroupId(), siddhiVersion);
DocumentationUtils.updateHeadingsInMarkdownFile(readmeFile, readmeFile, rootMavenProject.getArtifactId(), latestVersion, namespaceMetaDataList, rootMavenProject.getGroupId(), siddhiVersion);
}
// copy to latest file
File newVersionFile = new File(docGenBasePath + File.separator + Constants.API_SUB_DIRECTORY + File.separator + latestVersion + Constants.MARKDOWN_FILE_EXTENSION);
File latestLabelFile = new File(docGenBasePath + File.separator + Constants.API_SUB_DIRECTORY + File.separator + Constants.LATEST_FILE_NAME + Constants.MARKDOWN_FILE_EXTENSION);
try {
Files.copy(newVersionFile, latestLabelFile);
} catch (IOException e) {
getLog().warn("Failed to generate latest.md file", e);
}
// Deploying the documentation
if (DocumentationUtils.generateMkdocsSite(mkdocsConfigFile, getLog())) {
if (deployDocs) {
deployDocumentation(rootMavenProject, docGenBasePath);
}
} else {
getLog().warn("Unable to generate documentation. Skipping documentation deployment.");
}
}
use of io.siddhi.doc.gen.metadata.NamespaceMetaData in project siddhi by wso2.
the class DocumentationUtils method addExtensionMetaDataIntoNamespaceList.
/**
* Generate extension meta data from the annotated data in the class
*
* @param namespaceList The list of namespaces to which the new extension will be added
* @param extensionClass Class from which meta data should be extracted from
* @param logger The maven plugin logger
* @param includeOrigin Add origin to the docs
*/
private static void addExtensionMetaDataIntoNamespaceList(List<NamespaceMetaData> namespaceList, Class<?> extensionClass, Log logger, boolean includeOrigin) {
Extension extensionAnnotation = extensionClass.getAnnotation(Extension.class);
if (extensionAnnotation != null) {
// Discarding extension classes without annotation
ExtensionMetaData extensionMetaData = new ExtensionMetaData();
// Finding extension type
String extensionType = null;
for (Map.Entry<ExtensionType, Class<?>> entry : ExtensionType.getSuperClassMap().entrySet()) {
Class<?> superClass = entry.getValue();
if (superClass.isAssignableFrom(extensionClass) && superClass != extensionClass) {
extensionType = entry.getKey().getValue();
break;
}
}
// Discarding the extension if it belongs to an unknown type
if (extensionType == null) {
logger.warn("Discarding extension (belonging to an unknown extension type): " + extensionClass.getCanonicalName());
return;
}
extensionMetaData.setName(extensionAnnotation.name());
extensionMetaData.setDescription(extensionAnnotation.description());
extensionMetaData.setDeprecated(extensionAnnotation.deprecated());
if (includeOrigin) {
Manifest manifest = getManifest(extensionClass);
Attributes attributes = manifest.getMainAttributes();
extensionMetaData.setOriginName(attributes.getValue("Bundle-Name"));
extensionMetaData.setOriginVersion(attributes.getValue("Bundle-Version"));
}
// Adding query parameters
ParameterMetaData[] parameters = new ParameterMetaData[extensionAnnotation.parameters().length];
Map<String, ParameterMetaData> parameterMap = new HashMap<>();
for (int i = 0; i < extensionAnnotation.parameters().length; i++) {
Parameter parameterAnnotation = extensionAnnotation.parameters()[i];
ParameterMetaData parameter = new ParameterMetaData();
parameter.setName(parameterAnnotation.name());
parameter.setType(Arrays.asList(parameterAnnotation.type()));
parameter.setDescription(parameterAnnotation.description());
parameter.setOptional(parameterAnnotation.optional());
parameter.setDynamic(parameterAnnotation.dynamic());
parameter.setDefaultValue(parameterAnnotation.defaultValue());
parameterMap.put(parameter.getName(), parameter);
parameters[i] = parameter;
}
extensionMetaData.setParameters(Arrays.asList(parameters));
// Adding parameter overloads
if (extensionAnnotation.parameterOverloads().length > 0) {
ParameterOverloadMetaData[] parameterOverloads = new ParameterOverloadMetaData[extensionAnnotation.parameterOverloads().length];
for (int i = 0; i < extensionAnnotation.parameterOverloads().length; i++) {
ParameterOverload parameterOverloadAnnotation = extensionAnnotation.parameterOverloads()[i];
ParameterOverloadMetaData parameterOverload = new ParameterOverloadMetaData();
ParameterMetaData[] overloadParameters = new ParameterMetaData[parameterOverloadAnnotation.parameterNames().length];
for (int j = 0; j < parameterOverloadAnnotation.parameterNames().length; j++) {
ParameterMetaData parameterMetaData = parameterMap.get(parameterOverloadAnnotation.parameterNames()[j]);
if (parameterMetaData != null) {
overloadParameters[j] = parameterMetaData;
} else if (parameterOverloadAnnotation.parameterNames()[j].equals(SiddhiConstants.REPETITIVE_PARAMETER_NOTATION)) {
ParameterMetaData repetitiveParamMetaData = new ParameterMetaData();
ParameterMetaData previousParameterMetaData = parameterMap.get(parameterOverloadAnnotation.parameterNames()[j - 1]);
repetitiveParamMetaData.setName(SiddhiConstants.REPETITIVE_PARAMETER_NOTATION);
repetitiveParamMetaData.setType(previousParameterMetaData.getType());
repetitiveParamMetaData.setDescription(previousParameterMetaData.getDescription());
repetitiveParamMetaData.setOptional(previousParameterMetaData.isOptional());
repetitiveParamMetaData.setDynamic(previousParameterMetaData.isDynamic());
repetitiveParamMetaData.setDefaultValue(previousParameterMetaData.getDefaultValue());
overloadParameters[j] = repetitiveParamMetaData;
}
}
parameterOverload.setParameters(Arrays.asList(overloadParameters));
parameterOverloads[i] = parameterOverload;
}
extensionMetaData.setParameterOverloads(Arrays.asList(parameterOverloads));
}
// Adding system parameters
SystemParameterMetaData[] systemParameters = new SystemParameterMetaData[extensionAnnotation.systemParameter().length];
for (int i = 0; i < extensionAnnotation.systemParameter().length; i++) {
SystemParameter systemParameterAnnotation = extensionAnnotation.systemParameter()[i];
SystemParameterMetaData systemParameter = new SystemParameterMetaData();
systemParameter.setName(systemParameterAnnotation.name());
systemParameter.setDescription(systemParameterAnnotation.description());
systemParameter.setDefaultValue(systemParameterAnnotation.defaultValue());
systemParameter.setPossibleParameters(Arrays.asList(systemParameterAnnotation.possibleParameters()));
systemParameters[i] = systemParameter;
}
extensionMetaData.setSystemParameters(Arrays.asList(systemParameters));
// Adding return attributes
ReturnAttributeMetaData[] returnAttributes = new ReturnAttributeMetaData[extensionAnnotation.returnAttributes().length];
for (int i = 0; i < extensionAnnotation.returnAttributes().length; i++) {
ReturnAttribute parameterAnnotation = extensionAnnotation.returnAttributes()[i];
ReturnAttributeMetaData returnAttribute = new ReturnAttributeMetaData();
returnAttribute.setName(parameterAnnotation.name());
returnAttribute.setType(Arrays.asList(parameterAnnotation.type()));
returnAttribute.setDescription(parameterAnnotation.description());
returnAttributes[i] = returnAttribute;
}
extensionMetaData.setReturnAttributes(Arrays.asList(returnAttributes));
// Adding examples
ExampleMetaData[] examples = new ExampleMetaData[extensionAnnotation.examples().length];
for (int i = 0; i < extensionAnnotation.examples().length; i++) {
Example exampleAnnotation = extensionAnnotation.examples()[i];
ExampleMetaData exampleMetaData = new ExampleMetaData();
exampleMetaData.setSyntax(exampleAnnotation.syntax());
exampleMetaData.setDescription(exampleAnnotation.description());
examples[i] = exampleMetaData;
}
extensionMetaData.setExamples(Arrays.asList(examples));
// Finding the namespace
String namespaceName = extensionAnnotation.namespace();
if (Objects.equals(namespaceName, "")) {
namespaceName = Constants.CORE_NAMESPACE;
}
// Finding the relevant namespace in the namespace list
NamespaceMetaData namespace = null;
for (NamespaceMetaData existingNamespace : namespaceList) {
if (Objects.equals(existingNamespace.getName(), namespaceName)) {
namespace = existingNamespace;
break;
}
}
// Creating namespace if it doesn't exist
if (namespace == null) {
namespace = new NamespaceMetaData();
namespace.setName(namespaceName);
namespace.setExtensionMap(new TreeMap<>());
namespaceList.add(namespace);
}
// Adding to the relevant extension metadata list in the namespace
List<ExtensionMetaData> extensionMetaDataList = namespace.getExtensionMap().computeIfAbsent(extensionType, k -> new ArrayList<>());
extensionMetaDataList.add(extensionMetaData);
}
}
use of io.siddhi.doc.gen.metadata.NamespaceMetaData in project siddhi by wso2.
the class DocumentationUtils method getExtensionMetaData.
/**
* Returns the extension extension meta data
* Gets the meta data from the siddhi manager
*
* @param targetDirectoryPath The path of the target directory of the maven module containing extensions
* @param logger The maven plugin logger
* @param includeOrigin
* @param loadFromAllJars
* @return NamespaceMetaData namespace meta data list
* @throws MojoFailureException If this fails to access project dependencies
* @throws MojoExecutionException If the classes directory from which classes are loaded is invalid
*/
public static List<NamespaceMetaData> getExtensionMetaData(String targetDirectoryPath, List<String> runtimeClasspathElements, Log logger, boolean includeOrigin, boolean loadFromAllJars) throws MojoFailureException, MojoExecutionException {
List<NamespaceMetaData> namespaceMetaDataList = new ArrayList<>();
File targetDirectory = null;
try {
if (loadFromAllJars) {
targetDirectory = new File(targetDirectoryPath);
addExtensionMetaFromAllFiles(targetDirectory, runtimeClasspathElements, logger, includeOrigin, namespaceMetaDataList);
} else {
targetDirectory = new File(targetDirectoryPath + File.separator + Constants.CLASSES_DIRECTORY);
addExtensionMetaFromClassFiles(targetDirectory, runtimeClasspathElements, logger, includeOrigin, namespaceMetaDataList);
}
} catch (MalformedURLException e) {
throw new MojoExecutionException("Invalid classes directory: " + targetDirectory.getAbsolutePath(), e);
}
for (NamespaceMetaData aNamespaceMetaData : namespaceMetaDataList) {
for (List<ExtensionMetaData> extensionMetaData : aNamespaceMetaData.getExtensionMap().values()) {
Collections.sort(extensionMetaData);
}
}
Collections.sort(namespaceMetaDataList);
return namespaceMetaDataList;
}
use of io.siddhi.doc.gen.metadata.NamespaceMetaData in project siddhi by wso2.
the class MarkdownDocumentationGenerationMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
// Finding the root maven project
MavenProject rootMavenProject = mavenProject;
if (loadFromAllJars) {
siddhiVersion = null;
}
while (rootMavenProject.getParent() != null && rootMavenProject.getParent().getBasedir() != null) {
rootMavenProject = rootMavenProject.getParent();
}
// Setting the relevant modules target directory if not set by user
String moduleTargetPath;
if (moduleTargetDirectory != null) {
moduleTargetPath = moduleTargetDirectory.getAbsolutePath();
} else {
moduleTargetPath = mavenProject.getBuild().getDirectory();
}
// Setting the documentation output directory if not set by user
String docGenBasePath;
if (docGenBaseDirectory != null) {
docGenBasePath = docGenBaseDirectory.getAbsolutePath();
} else {
docGenBasePath = rootMavenProject.getBasedir() + File.separator + Constants.DOCS_DIRECTORY;
}
// Setting the mkdocs config file path if not set by user
if (mkdocsConfigFile == null) {
mkdocsConfigFile = new File(rootMavenProject.getBasedir() + File.separator + Constants.MKDOCS_CONFIG_FILE_NAME + Constants.YAML_FILE_EXTENSION);
}
// Retrieving metadata
List<NamespaceMetaData> namespaceMetaDataList;
try {
namespaceMetaDataList = DocumentationUtils.getExtensionMetaData(moduleTargetPath, mavenProject.getRuntimeClasspathElements(), getLog(), includeOrigin, loadFromAllJars);
} catch (DependencyResolutionRequiredException e) {
throw new MojoFailureException("Unable to resolve dependencies of the project", e);
}
// Generating the documentation
if (namespaceMetaDataList.size() > 0) {
DocumentationUtils.generateDocumentation(namespaceMetaDataList, docGenBasePath, mavenProject.getVersion(), getLog(), siddhiVersion, mavenProject.getGroupId());
}
}
Aggregations