use of org.wso2.carbon.apimgt.persistence.dto.Documentation 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().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());
} 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());
DocumentationUtils.updateHeadingsInMarkdownFile(homePageTemplateFile, homePageFile, rootMavenProject.getArtifactId(), mavenProject.getVersion(), namespaceMetaDataList);
DocumentationUtils.updateHeadingsInMarkdownFile(readmeFile, readmeFile, rootMavenProject.getArtifactId(), mavenProject.getVersion(), namespaceMetaDataList);
}
// Delete snapshot files
DocumentationUtils.removeSnapshotAPIDocs(mkdocsConfigFile, docGenBasePath, getLog());
// Updating the links in the home page to the mkdocs config
try {
updateAPIPagesInMkdocsConfig(mkdocsConfigFile, docGenBasePath);
} catch (FileNotFoundException e) {
getLog().warn("Unable to find mkdocs configuration file: " + mkdocsConfigFile.getAbsolutePath() + ". Mkdocs configuration file not updated.");
}
// Deploying the documentation
if (DocumentationUtils.generateMkdocsSite(mkdocsConfigFile, getLog())) {
// Creating the credential provider fot Git
String scmUsername = System.getenv(Constants.SYSTEM_PROPERTY_SCM_USERNAME_KEY);
String scmPassword = System.getenv(Constants.SYSTEM_PROPERTY_SCM_PASSWORD_KEY);
if (scmUsername == null && scmPassword == null) {
getLog().info("SCM_USERNAME and SCM_PASSWORD not defined!");
}
String url = null;
Scm scm = rootMavenProject.getScm();
if (scm != null) {
url = scm.getUrl();
}
// Deploying documentation
DocumentationUtils.updateDocumentationOnGitHub(docGenBasePath, mkdocsConfigFile, readmeFile, mavenProject.getVersion(), getLog());
DocumentationUtils.deployMkdocsOnGitHubPages(mavenProject.getVersion(), rootMavenProject.getBasedir(), url, scmUsername, scmPassword, getLog());
} else {
getLog().warn("Unable to generate documentation. Skipping documentation deployment.");
}
}
use of org.wso2.carbon.apimgt.persistence.dto.Documentation in project siddhi by wso2.
the class DocumentationUtils method generateDocumentation.
/**
* Generate documentation related files using metadata
*
* @param namespaceMetaDataList Metadata in this repository
* @param documentationBaseDirectory The path of the directory in which the documentation will be generated
* @param documentationVersion The version of the documentation being generated
* @param logger The logger to log errors
* @throws MojoFailureException if the Mojo fails to find template file or create new documentation file
*/
public static void generateDocumentation(List<NamespaceMetaData> namespaceMetaDataList, String documentationBaseDirectory, String documentationVersion, Log logger) throws MojoFailureException {
// Generating data model
Map<String, Object> rootDataModel = new HashMap<>();
rootDataModel.put("metaData", namespaceMetaDataList);
rootDataModel.put("formatDescription", new FormatDescriptionMethod());
rootDataModel.put("latestDocumentationVersion", documentationVersion);
String outputFileRelativePath = Constants.API_SUB_DIRECTORY + File.separator + documentationVersion + Constants.MARKDOWN_FILE_EXTENSION;
generateFileFromTemplate(Constants.MARKDOWN_DOCUMENTATION_TEMPLATE + Constants.MARKDOWN_FILE_EXTENSION + Constants.FREEMARKER_TEMPLATE_FILE_EXTENSION, rootDataModel, documentationBaseDirectory, outputFileRelativePath);
File newVersionFile = new File(documentationBaseDirectory + File.separator + outputFileRelativePath);
File latestLabelFile = new File(documentationBaseDirectory + File.separator + Constants.API_SUB_DIRECTORY + File.separator + Constants.LATEST_FILE_NAME + Constants.MARKDOWN_FILE_EXTENSION);
try {
Files.copy(newVersionFile, latestLabelFile);
} catch (IOException e) {
logger.warn("Failed to generate latest.md file", e);
}
}
use of org.wso2.carbon.apimgt.persistence.dto.Documentation in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testDeleteDocumentation.
@Test(description = "Delete documentation for an API")
public void testDeleteDocumentation() throws Exception {
ApiDAO apiDAO = DAOFactory.getApiDAO();
testAddGetEndpoint();
API api = SampleTestObjectCreator.createDefaultAPI().build();
apiDAO.addAPI(api);
// adding documentation
DocumentInfo documentInfo = SampleTestObjectCreator.createDefaultDocumentationInfo();
String docId = documentInfo.getId();
apiDAO.addDocumentInfo(api.getId(), documentInfo);
// delete documentation
apiDAO.deleteDocument(docId);
DocumentInfo documentInfoFromDB = apiDAO.getDocumentInfo(docId);
Assert.assertNull(documentInfoFromDB);
}
use of org.wso2.carbon.apimgt.persistence.dto.Documentation in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testUploadDocumentationFileException.
@Test(description = "Exception when uploading Documentation File", expectedExceptions = APIManagementException.class)
public void testUploadDocumentationFileException() throws APIManagementException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO);
Mockito.doThrow(new APIMgtDAOException("Unable to add documentation with file")).when(apiDAO).addDocumentFileContent(DOC_ID, null, "text/plain", USER);
apiPublisher.uploadDocumentationFile(DOC_ID, null, "text/plain");
}
use of org.wso2.carbon.apimgt.persistence.dto.Documentation in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testRemoveDocumentationInfoException.
@Test(description = "Exception when removing Documentation Info", expectedExceptions = APIManagementException.class)
public void testRemoveDocumentationInfoException() throws APIManagementException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO);
Mockito.doThrow(new APIMgtDAOException("Unable to add documentation with file")).when(apiDAO).deleteDocument(DOC_ID);
apiPublisher.removeDocumentation(DOC_ID);
}
Aggregations