Search in sources :

Example 1 with LibraryArtifact

use of org.apache.synapse.libraries.model.LibraryArtifact in project wso2-synapse by wso2.

the class LibDeployerUtils method populateLibraryArtifact.

/**
 * Builds the Artifact object when an root artifact element is given . Schema for artifact.xml
 * is as follows
 * <artifact name="templates1" type="synapse/template" >
 *
 *        <subArtifacts>
 *            <artifact name="greet_func1" >
 *                    <file>templ1_ns1.xml</file>
 *                    <description>sample synapse library artifact Description</description> ?
 *            </artifact> *
 *        </subArtifacts> *
 *
 *        <description>sample synapse library artifact Description</description> ?
 *    </artifact>
 *
 * @param artifactEle - artifact OMElement
 * @return created Artifact object
 */
private static LibraryArtifact populateLibraryArtifact(OMElement artifactEle, String artifactPath, LibraryArtifact parent, SynapseLibrary library) {
    if (artifactEle == null || artifactPath == null) {
        return null;
    }
    LibraryArtifact artifact = new LibraryArtifact(readAttribute(artifactEle, LibDeployerConstants.NAME));
    artifact.setParent(parent);
    artifact.setType(readAttribute(artifactEle, LibDeployerConstants.TYPE));
    artifact.setPath(artifactPath);
    artifact.setDescription(readChildText(artifactEle, LibDeployerConstants.DESCRIPTION_ELEMENT));
    // add a description of this artifact(if availalbe) to Synapse Library
    library.addArtifactDescription(artifact);
    // read the subArtifacts
    OMElement subArtifactsElement = artifactEle.getFirstChildWithName(new QName(LibDeployerConstants.SUB_ARTIFACTS));
    if (subArtifactsElement != null) {
        Iterator subArtItr = subArtifactsElement.getChildrenWithLocalName(LibDeployerConstants.ARTIFACT);
        while (subArtItr.hasNext()) {
            // as this is also an artifact, use recursion
            LibraryArtifact subArtifact = populateLibraryArtifact((OMElement) subArtItr.next(), artifactPath, artifact, library);
            artifact.addSubArtifact(subArtifact);
        }
    }
    // read and check for files
    Iterator fileItr = artifactEle.getChildrenWithLocalName(LibDeployerConstants.FILE);
    while (fileItr.hasNext()) {
        OMElement fileElement = (OMElement) fileItr.next();
        artifact.setupFile(fileElement.getText());
    }
    return artifact;
}
Also used : QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement) LibraryArtifact(org.apache.synapse.libraries.model.LibraryArtifact)

Example 2 with LibraryArtifact

use of org.apache.synapse.libraries.model.LibraryArtifact in project wso2-synapse by wso2.

the class LibDeployerUtils method searchAndResolveDependencies.

/**
 * Deploys all artifacts under a root artifact..
 *
 * @param rootDirPath - root dir of the extracted artifact
 * @param library     - lib instance
 */
private static void searchAndResolveDependencies(String rootDirPath, SynapseLibrary library) {
    List<LibraryArtifact> libraryArtifacts = new ArrayList<LibraryArtifact>();
    File extractedDir = new File(rootDirPath);
    File[] allFiles = extractedDir.listFiles();
    if (allFiles == null) {
        return;
    }
    // search for all directories under the extracted path
    for (File artifactDirectory : allFiles) {
        if (!artifactDirectory.isDirectory()) {
            continue;
        }
        String directoryPath = artifactDirectory.getAbsolutePath();
        String artifactXmlPath = directoryPath + File.separator + LibDeployerConstants.ARTIFACT_XML;
        File f = new File(artifactXmlPath);
        // if the artifact.xml not found, ignore this dir
        if (!f.exists()) {
            continue;
        }
        LibraryArtifact artifact = null;
        InputStream xmlInputStream = null;
        try {
            xmlInputStream = new FileInputStream(f);
            artifact = buildArtifact(library, xmlInputStream, directoryPath);
        } catch (FileNotFoundException e) {
            log.warn("Error while resolving synapse lib dir :" + artifactDirectory.getName() + " artifacts.xml File cannot be loaded " + "from " + artifactXmlPath, e);
        } catch (Exception e) {
            log.warn("Error ocurred while resolving synapse lib dir :" + artifactDirectory.getName() + " for artifacts.xml path" + artifactXmlPath, e);
        } finally {
            if (xmlInputStream != null) {
                try {
                    xmlInputStream.close();
                } catch (IOException e) {
                    log.error("Error while closing input stream.", e);
                }
            }
        }
        if (artifact == null) {
            log.warn("Could not build lib artifact for path : " + directoryPath + " Synapse Library :" + library.getQName() + ". Continue searching for other lib artifacts");
            continue;
        }
        libraryArtifacts.add(artifact);
    }
    boolean isDepsResolved = library.resolveDependencies(libraryArtifacts);
    if (!isDepsResolved) {
        throw new SynapseArtifactDeploymentException("Error when resolving Dependencies for lib : " + library.toString());
    }
}
Also used : SynapseException(org.apache.synapse.SynapseException) SynapseArtifactDeploymentException(org.apache.synapse.deployers.SynapseArtifactDeploymentException) XMLStreamException(javax.xml.stream.XMLStreamException) DeploymentException(org.apache.axis2.deployment.DeploymentException) SynapseArtifactDeploymentException(org.apache.synapse.deployers.SynapseArtifactDeploymentException) LibraryArtifact(org.apache.synapse.libraries.model.LibraryArtifact) ZipFile(java.util.zip.ZipFile)

Aggregations

LibraryArtifact (org.apache.synapse.libraries.model.LibraryArtifact)2 ZipFile (java.util.zip.ZipFile)1 QName (javax.xml.namespace.QName)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 OMElement (org.apache.axiom.om.OMElement)1 DeploymentException (org.apache.axis2.deployment.DeploymentException)1 SynapseException (org.apache.synapse.SynapseException)1 SynapseArtifactDeploymentException (org.apache.synapse.deployers.SynapseArtifactDeploymentException)1