Search in sources :

Example 1 with Target

use of org.wso2.carbon.apimgt.common.analytics.publishers.dto.Target 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.");
    }
}
Also used : DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException) MavenProject(org.apache.maven.project.MavenProject) NamespaceMetaData(org.wso2.siddhi.doc.gen.commons.metadata.NamespaceMetaData) MojoFailureException(org.apache.maven.plugin.MojoFailureException) FileNotFoundException(java.io.FileNotFoundException) Scm(org.apache.maven.model.Scm) File(java.io.File)

Example 2 with Target

use of org.wso2.carbon.apimgt.common.analytics.publishers.dto.Target 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
 * @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) throws MojoFailureException, MojoExecutionException {
    List<NamespaceMetaData> namespaceMetaDataList = new ArrayList<NamespaceMetaData>();
    // +1 to include the module's target/classes folder
    int urlCount = runtimeClasspathElements.size() + 1;
    // Creating a list of URLs with all project dependencies
    URL[] urls = new URL[urlCount];
    for (int i = 0; i < runtimeClasspathElements.size(); i++) {
        try {
            urls[i] = new File(runtimeClasspathElements.get(i)).toURI().toURL();
        } catch (MalformedURLException e) {
            throw new MojoFailureException("Unable to access project dependency: " + runtimeClasspathElements.get(i), e);
        }
    }
    File classesDirectory = new File(targetDirectoryPath + File.separator + Constants.CLASSES_DIRECTORY);
    try {
        // Adding the generated classes to the class loader
        urls[urlCount - 1] = classesDirectory.toURI().toURL();
        ClassLoader urlClassLoader = AccessController.doPrivileged((PrivilegedAction<ClassLoader>) () -> new URLClassLoader(urls, Thread.currentThread().getContextClassLoader()));
        // Getting extensions from all the class files in the classes directory
        addExtensionInDirectory(classesDirectory, classesDirectory.getAbsolutePath(), urlClassLoader, namespaceMetaDataList, logger);
    } catch (MalformedURLException e) {
        throw new MojoExecutionException("Invalid classes directory: " + classesDirectory.getAbsolutePath(), e);
    }
    for (NamespaceMetaData aNamespaceMetaData : namespaceMetaDataList) {
        for (List<ExtensionMetaData> extensionMetaData : aNamespaceMetaData.getExtensionMap().values()) {
            Collections.sort(extensionMetaData);
        }
    }
    Collections.sort(namespaceMetaDataList);
    return namespaceMetaDataList;
}
Also used : MalformedURLException(java.net.MalformedURLException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) NamespaceMetaData(org.wso2.siddhi.doc.gen.commons.metadata.NamespaceMetaData) ArrayList(java.util.ArrayList) MojoFailureException(org.apache.maven.plugin.MojoFailureException) URL(java.net.URL) URLClassLoader(java.net.URLClassLoader) ExtensionMetaData(org.wso2.siddhi.doc.gen.commons.metadata.ExtensionMetaData) URLClassLoader(java.net.URLClassLoader) File(java.io.File)

Example 3 with Target

use of org.wso2.carbon.apimgt.common.analytics.publishers.dto.Target in project carbon-apimgt by wso2.

the class APIExecutor method execute.

/**
 * This method will be called when the invoke() method of the default lifecycle implementation is called.
 * Execution logic should reside in this method since the default lifecycle implementation will determine
 * the execution output by looking at the output of this method.
 *
 * @param resource     The resource in which the lifecycle state is changed.
 * @param currentState Current lifecycle state.
 * @param targetState  The target lifecycle state.
 * @throws LifecycleException If exception occurs while running the executor.
 */
@Override
public void execute(Object resource, String currentState, String targetState) throws LifecycleException {
    API api = (API) resource;
    if (!currentState.equals(targetState)) {
        // todo:This place need to write how to handle Gateway publishing
        try {
            ApiDAO apiDAO = DAOFactory.getApiDAO();
            apiDAO.changeLifeCycleStatus(api.getId(), targetState);
        } catch (APIMgtDAOException e) {
            throw new LifecycleException("Couldn't create APIPublisher from user", e);
        }
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) LifecycleException(org.wso2.carbon.lcm.core.exception.LifecycleException) API(org.wso2.carbon.apimgt.core.models.API) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO)

Example 4 with Target

use of org.wso2.carbon.apimgt.common.analytics.publishers.dto.Target in project wso2-synapse by wso2.

the class VFSTransportListenerTest method testVFSTransportListenerBasics.

/**
 * Testcase to test basic functionality of {@link VFSTransportListener}
 * @throws Exception
 */
public void testVFSTransportListenerBasics() throws Exception {
    MockFileHolder.getInstance().clear();
    String fileUri = "test1:///foo/bar/test-" + System.currentTimeMillis() + "/DIR/IN/";
    String moveAfterFailure = "test1:///foo/bar/test-" + System.currentTimeMillis() + "/DIR/FAIL/";
    AxisService axisService = new AxisService("testVFSService");
    axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_FILE_FILE_URI, fileUri));
    axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_FILE_CONTENT_TYPE, "text/xml"));
    axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_FILE_FILE_NAME_PATTERN, ".*\\.txt"));
    axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_FILE_ACTION_AFTER_PROCESS, VFSTransportListener.MOVE));
    axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_FILE_ACTION_AFTER_FAILURE, VFSTransportListener.MOVE));
    axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_FILE_MOVE_AFTER_FAILURE, moveAfterFailure));
    axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_FILE_MOVE_AFTER_FAILED_MOVE, moveAfterFailure));
    axisService.addParameter(new Parameter(VFSConstants.STREAMING, "false"));
    axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_FILE_LOCKING, VFSConstants.TRANSPORT_FILE_LOCKING_ENABLED));
    axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_FILE_INTERVAL, "1000"));
    axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_FILE_COUNT, "1"));
    axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_AUTO_LOCK_RELEASE, "true"));
    axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_AUTO_LOCK_RELEASE_INTERVAL, "20000"));
    axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_AUTO_LOCK_RELEASE_SAME_NODE, "true"));
    axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_DISTRIBUTED_LOCK, "true"));
    axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_DISTRIBUTED_LOCK_TIMEOUT, "20000"));
    axisService.addParameter(new Parameter(VFSConstants.FILE_SORT_PARAM, VFSConstants.FILE_SORT_VALUE_NAME));
    axisService.addParameter(new Parameter(VFSConstants.FILE_SORT_ORDER, "true"));
    TransportDescriptionFactory transportDescriptionFactory = new VFSTransportDescriptionFactory();
    TransportInDescription transportInDescription = null;
    try {
        transportInDescription = transportDescriptionFactory.createTransportInDescription();
    } catch (Exception e) {
        Assert.fail("Error occurred while creating transport in description");
    }
    VFSTransportListener vfsTransportListener = getListener(transportInDescription);
    // initialize listener
    vfsTransportListener.init(new ConfigurationContext(new AxisConfiguration()), transportInDescription);
    // Initialize VFSTransportListener
    vfsTransportListener.doInit();
    // Start listener
    vfsTransportListener.start();
    // Create poll entry
    PollTableEntry pollTableEntry = vfsTransportListener.createEndpoint();
    Assert.assertTrue("Global file locking not applied to created poll entry", pollTableEntry.isFileLockingEnabled());
    // Load configuration of poll entry
    pollTableEntry.loadConfiguration(axisService);
    populatePollTableEntry(pollTableEntry, axisService, vfsTransportListener);
    vfsTransportListener.poll(pollTableEntry);
    MockFile targetDir = MockFileHolder.getInstance().getFile(fileUri);
    Assert.assertNotNull("Failed target directory creation", targetDir);
    Assert.assertEquals("Created target directory is not Folder type", targetDir.getName().getType(), FileType.FOLDER);
    MockFile failDir = MockFileHolder.getInstance().getFile(moveAfterFailure);
    Assert.assertNotNull("Fail to create expected directory to move files when failure", failDir);
    MockFileHolder.getInstance().clear();
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) MockFile(org.wso2.carbon.inbound.endpoint.protocol.file.MockFile) AxisService(org.apache.axis2.description.AxisService) Parameter(org.apache.axis2.description.Parameter) TransportInDescription(org.apache.axis2.description.TransportInDescription) TransportDescriptionFactory(org.apache.axis2.transport.testkit.axis2.TransportDescriptionFactory)

Example 5 with Target

use of org.wso2.carbon.apimgt.common.analytics.publishers.dto.Target in project carbon-business-process by wso2.

the class XMLDocument method set.

/**
 * Function to set/replace/update an object (String / Element) to matching the xPath provided. (In case new element
 * is added, this api will clone it and merge the new node to the target location pointed by xPath and return the new cloned node)
 *
 * @param xPathStr xPath to the location object need to set
 * @param obj      String or Node
 * @return returns the node get updated when the set object is String, or returns newly added Node in case object is Element
 * @throws XPathExpressionException If expression cannot be evaluated
 * @throws BPMNXmlException         is thrown due to : Provided XPath and object does not match, provided object is not a Node or String
 *                                  result is NodeList, not a Text node or Element
 */
public Node set(String xPathStr, Object obj) throws XPathExpressionException, BPMNXmlException {
    NodeList evalResult = (NodeList) Utils.evaluateXPath(this.doc, xPathStr, XPathConstants.NODESET);
    if (evalResult.getLength() == 1) {
        Node targetNode = evalResult.item(0);
        if (obj instanceof String && targetNode instanceof Text) {
            // if string is provided, assume that user
            // need to replace the node value
            targetNode.setNodeValue((String) obj);
            // return updated Text Node
            return targetNode;
        } else if ((obj instanceof Integer || obj instanceof Byte || obj instanceof Character || obj instanceof Short || obj instanceof Long || obj instanceof Float || obj instanceof Double || obj instanceof Boolean) && targetNode instanceof Text) {
            // need to replace the node value
            targetNode.setNodeValue(obj.toString());
            // return updated Text Node
            return targetNode;
        } else if (obj instanceof Element && targetNode instanceof Element && targetNode.getParentNode() != null) {
            // if the user provides Node object,
            // assume that need to replace the target node
            Node targetParent = targetNode.getParentNode();
            Node nextSibling = targetNode.getNextSibling();
            // remove the target node
            targetParent.removeChild(targetNode);
            // add new node
            Node newNode = doc.importNode((Node) obj, true);
            if (nextSibling != null) {
                // If next sibling exists we have to put the new node before it
                targetParent.insertBefore(newNode, nextSibling);
            } else {
                targetParent.appendChild(newNode);
            }
            // return new node
            return newNode;
        } else {
            // provided XPath and object to set does not match
            throw new BPMNXmlException("Provided XPath and provided object does not match");
        }
    } else if (evalResult.getLength() > 0) {
        throw new BPMNXmlException("Error in provided xPath. Evaluation result is NodeList, not a Text node or Element");
    } else {
        throw new BPMNXmlException("Error in provided xPath. Evaluation result is not a Text node or Element");
    }
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) Text(org.w3c.dom.Text) BPMNXmlException(org.wso2.carbon.bpmn.core.types.datatypes.xml.BPMNXmlException)

Aggregations

BLangAssignment (org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment)11 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)11 ArrayList (java.util.ArrayList)9 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)8 File (java.io.File)7 IOException (java.io.IOException)7 Element (org.w3c.dom.Element)6 BLangBinaryExpr (org.wso2.ballerinalang.compiler.tree.expressions.BLangBinaryExpr)5 Target (org.wso2.carbon.apimgt.common.analytics.publishers.dto.Target)5 Gson (com.google.gson.Gson)4 List (java.util.List)4 Map (java.util.Map)4 OMElement (org.apache.axiom.om.OMElement)4 NodeList (org.w3c.dom.NodeList)4 BLangIndexBasedAccess (org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess)4 JsonElement (com.google.gson.JsonElement)3 FileOutputStream (java.io.FileOutputStream)3 HashMap (java.util.HashMap)3 Iterator (java.util.Iterator)3 Set (java.util.Set)3