Package org.wso2.carbon.application.deployer.config

Examples of org.wso2.carbon.application.deployer.config.Artifact$Dependency


                getApplicationArtifact().getDependencies();
        // package list to return
        List<WarCappMetadata> webappList = new ArrayList<WarCappMetadata>();

        for (Artifact.Dependency dep : deps) {
            Artifact artifact = dep.getArtifact();
            if (WARCappDeployer.WAR_TYPE.equals(artifact.getType())) {
                // war artifact can have only one file (a .war file). Try to find a webapp
                // which is already deployed and has the same file name
                webappList.add(getWebappMetadata(artifact.getFiles().get(0).getName()));
            }
        }
        // convert the List into an array and return
        return webappList.toArray(new WarCappMetadata[webappList.size()]);
    }
View Full Code Here


            // if the artifact.xml not found, ignore this dir
            if (!f.exists()) {
                continue;
            }

            Artifact artifact = null;
            InputStream xmlInputStream = null;
            try {
                xmlInputStream = new FileInputStream(f);
                artifact = this.buildAppArtifact(parentApp, xmlInputStream);
            } catch (FileNotFoundException e) {
                handleException("artifacts.xml File cannot be loaded from " + artifactXmlPath, e);
            } finally {
                if (xmlInputStream != null) {
                    try {
                        xmlInputStream.close();
                    } catch (IOException e) {
                        log.error("Error while closing input stream.", e);
                    }
                }
            }

            if (artifact == null) {
                return;
            }
            artifact.setExtractedPath(directoryPath);
//            searchArtifacts(directoryPath, parentApp);
            allArtifacts.add(artifact);
        }
        Artifact appArtifact = parentApp.getAppConfig().getApplicationArtifact();
        buildDependencyTree(appArtifact, allArtifacts);
    }
View Full Code Here

     * @return - Artifact instance if successfull. otherwise null..
     * @throws CarbonException - error while building
     */
    public Artifact buildAppArtifact(CarbonApplication parentApp, InputStream artifactXmlStream)
            throws CarbonException {
        Artifact artifact = null;
        try {
            OMElement artElement = new StAXOMBuilder(artifactXmlStream).getDocumentElement();

            if (Artifact.ARTIFACT.equals(artElement.getLocalName())) {
                artifact = AppDeployerUtils.populateArtifact(artElement);
            } else {
                log.error("artifact.xml is invalid. Parent Application : "
                        + parentApp.getAppName());
                return null;
            }
        } catch (XMLStreamException e) {
            handleException("Error while parsing the artifact.xml file ", e);
        }

        if (artifact == null || artifact.getName() == null) {
            log.error("Invalid artifact found in Carbon Application : " + parentApp.getAppName());
            return null;
        }
        return artifact;
    }
View Full Code Here

                                     AxisConfiguration axisConfig) {
        String artifactPath, destPath;
        String repo = axisConfig.getRepository().getPath();

        for (Artifact.Dependency dependency : deps) {
            Artifact artifact = dependency.getArtifact();
            if (artifact == null) {
                continue;
            }
            if (DefaultAppDeployer.AAR_TYPE.equals(artifact.getType())) {
                destPath = repo + File.separator + axisConfig
                        .getParameter(DeploymentConstants.SERVICE_DIR_PATH).getValue().toString();
            } else if (DefaultAppDeployer.JAXWS_TYPE.equals(artifact.getType())) {
                destPath = repo + File.separator + DefaultAppDeployer.JAXWS_DIR;
            } else if (DefaultAppDeployer.DS_TYPE.equals(artifact.getType())) {
                destPath = repo + File.separator + DefaultAppDeployer.DS_DIR;
            } else if (AppDeployerConstants.CARBON_APP_TYPE.equals(artifact.getType())) {
                destPath = repo + File.separator + AppDeployerConstants.CARBON_APPS;
            } else if (artifact.getType() != null && (artifact.getType().startsWith("lib/") ||
                    DefaultAppDeployer.BUNDLE_TYPE.equals(artifact.getType())) &&
                    AppDeployerUtils.getTenantId(axisConfig) == MultitenantConstants
                            .SUPER_TENANT_ID) {
                // library un-installation is only allowed for teh super tenant
                destPath = CarbonUtils.getCarbonOSGiDropinsDir();
            } else {
                continue;
            }

            List<CappFile> files = artifact.getFiles();
            if (files.size() != 1) {
                log.error(artifact.getType() + " type must have a single file. But " +
                        files.size() + " files found.");
                continue;
            }
            String fileName = artifact.getFiles().get(0).getName();
            artifactPath = destPath + File.separator + fileName;
            File artifactFile = new File(artifactPath);
            if (artifactFile.exists() && !artifactFile.delete()) {
                log.warn("Couldn't delete App artifact file : " + artifactPath);
            }

            undeployRecursively(artifact.getDependencies(), axisConfig);
        }
    }
View Full Code Here

                    for (String depPath : dependencies.getChildren()) {
                        Resource artifactResource = configRegistry.get(depPath +
                                AppDeployerConstants.ARTIFACT_XML);
                        InputStream xmlStream = artifactResource.getContentStream();
                        Artifact artifact = null;
                        if (xmlStream != null) {
                            artifact = appManager.buildAppArtifact(carbonApp, xmlStream);
                        }
                        if (artifact != null) {
                            Collection artCollection = (Collection) configRegistry.get(depPath);
                            artifact.setRuntimeObjectName(artCollection
                                    .getProperty(AppDeployerConstants.RUNTIME_OBJECT_NAME));
                            allArtifacts.add(artifact);
                        }
                    }
                }
                Artifact appArtifact = carbonApp.getAppConfig().getApplicationArtifact();
                appManager.buildDependencyTree(appArtifact, allArtifacts);
                appManager.addCarbonApp(tenantId, carbonApp);
            }
        } catch (RegistryException e) {
            String msg = "Unable to load Applications. Registry transactions failed.";
View Full Code Here

     * @throws RegistryException - on registry errors
     */
    private void persistArtifactList(List<Artifact.Dependency> depList,
                                    String artifactPath) throws Exception {
        for (Artifact.Dependency dep : depList) {
            Artifact artifact = dep.getArtifact();
            if (artifact == null) {
                continue;
            }
            // create the artifact collection
            Collection artifactCollection = configRegistry.newCollection();
            artifactCollection.setProperty(AppDeployerConstants.RUNTIME_OBJECT_NAME,
                    artifact.getRuntimeObjectName());
            configRegistry.put(artifactPath + artifact.getName(), artifactCollection);

            // persist artifact.xml
            Resource resource = configRegistry.newResource();
            File artifactXml = new File(artifact.getExtractedPath() +
                    File.separator + Artifact.ARTIFACT_XML);
            resource.setContentStream(new FileInputStream(artifactXml));
            configRegistry.put(artifactPath + artifact.getName() +
                    AppDeployerConstants.ARTIFACT_XML, resource);
        }
    }
View Full Code Here

    public static Artifact populateArtifact(OMElement artifactEle) {
        if (artifactEle == null) {
            return null;
        }

        Artifact artifact = new Artifact();
        // read top level attributes
        artifact.setName(readAttribute(artifactEle, Artifact.NAME));
        artifact.setVersion(readAttribute(artifactEle, Artifact.VERSION));
        artifact.setType(readAttribute(artifactEle, Artifact.TYPE));
        artifact.setServerRole(readAttribute(artifactEle, Artifact.SERVER_ROLE));

        // read the dependencies
        Iterator itr = artifactEle.getChildrenWithLocalName(Artifact.DEPENDENCY);
        while (itr.hasNext()) {
            OMElement depElement = (OMElement) itr.next();
            // create an artifact for each dependency and add to the root artifact
            Artifact.Dependency dep = new Artifact.Dependency();
            dep.setServerRole(readAttribute(depElement, Artifact.SERVER_ROLE));
            dep.setName(readAttribute(depElement, Artifact.ARTIFACT));
            dep.setVersion(readAttribute(depElement, Artifact.VERSION));
            artifact.addDependency(dep);
        }

        // read the subArtifacts
        OMElement subArtifactsElement = artifactEle
                .getFirstChildWithName(new QName(Artifact.SUB_ARTIFACTS));
        if (subArtifactsElement != null) {
            Iterator subArtItr = subArtifactsElement.getChildrenWithLocalName(Artifact.ARTIFACT);
            while (subArtItr.hasNext()) {
                // as this is also an artifact, use recursion
                Artifact subArtifact = populateArtifact((OMElement) subArtItr.next());
                artifact.addSubArtifact(subArtifact);
            }
        }

        // read the files
View Full Code Here

                                                int tenantId) {
        if (fileName == null || artifactType == null || tenantId == -1) {
            return;
        }
        ApplicationManager appManager = ApplicationManager.getInstance();
        Artifact appArtifact;
        for (CarbonApplication carbonApp : appManager.getCarbonApps(String.valueOf(tenantId))) {
            appArtifact = carbonApp.getAppConfig().getApplicationArtifact();
            for (Artifact.Dependency dep : appArtifact.getDependencies()) {
                if (dep.getArtifact() != null) {
                    Artifact depArtifact = dep.getArtifact();
                    for (CappFile file : depArtifact.getFiles()) {
                        if (file.getName().equals(fileName) &&
                                depArtifact.getType().equals(artifactType)) {
                            depArtifact.setRuntimeObjectName(runtimeObjectName);
                        }
                    }
                }
            }
        }
View Full Code Here

     * @param deps - list of dependencies
     * @return - true if found..
     */
    public static boolean hasLibs(List<Artifact.Dependency> deps) {
        for (Artifact.Dependency dep : deps) {
            Artifact artifact = dep.getArtifact();
            if (artifact != null) {
                if (artifact.getType().startsWith("lib/")) {
                    return true;
                } else {
                    if(hasLibs(artifact.getDependencies())) {
                        return true;
                    }
                }
            }
        }
View Full Code Here

    private void deployRecursively(List<Artifact.Dependency> deps, AxisConfiguration axisConfig) {
        String artifactPath, destPath;
        String repo = axisConfig.getRepository().getPath();
       
        for (Artifact.Dependency dependency : deps) {
            Artifact artifact = dependency.getArtifact();
            if (artifact == null) {
                continue;
            }

            if (!isAccepted(artifact.getType())) {
                log.warn("Can't deploy artifact : " + artifact.getName() + " of type : " +
                        artifact.getType() + ". Required features are not installed in the system");
                continue;
            }

            if (AAR_TYPE.equals(artifact.getType())) {
                destPath = repo + File.separator + axisConfig
                        .getParameter(DeploymentConstants.SERVICE_DIR_PATH).getValue().toString();
            } else if (JAXWS_TYPE.equals(artifact.getType())) {
                destPath = repo + File.separator + JAXWS_DIR;
            } else if (DS_TYPE.equals(artifact.getType())) {
                destPath = repo + File.separator + DS_DIR;
            } else if (AppDeployerConstants.CARBON_APP_TYPE.equals(artifact.getType())) {
                destPath = repo + File.separator + AppDeployerConstants.CARBON_APPS;
            } else if (artifact.getType().startsWith("lib/") && AppDeployerUtils
                    .getTenantId(axisConfig) == MultitenantConstants.SUPER_TENANT_ID) {
                // library installation is only allowed for teh super tenant
                destPath = CarbonUtils.getCarbonOSGiDropinsDir();
            } else {
                continue;
            }

            List<CappFile> files = artifact.getFiles();
            if (files.size() != 1) {
                log.error(artifact.getType() + " type must have a single file to " +
                        "be deployed. But " + files.size() + " files found.");
                continue;
            }
            String fileName = artifact.getFiles().get(0).getName();
            artifactPath = artifact.getExtractedPath() + File.separator + fileName;
            AppDeployerUtils.createDir(destPath);

            String destFilePath = destPath + File.separator + fileName;
            AppDeployerUtils.copyFile(artifactPath, destFilePath);

            /**
             * if the current artifact is a lib or bundle, we have to manually install it into the
             * OSGi environment for the usage of the lib before the first restart..
             * Important : This OSGi library installation is only allowed for the super tenant
             */
            if ((artifact.getType().startsWith("lib/") || BUNDLE_TYPE.equals(artifact.getType()))
                    && AppDeployerUtils.getTenantId(axisConfig) ==
                    MultitenantConstants.SUPER_TENANT_ID) {
                installBundle(destFilePath);
                artifact.setRuntimeObjectName(fileName);
            }
            deployRecursively(artifact.getDependencies(), axisConfig);
        }
    }
View Full Code Here

TOP

Related Classes of org.wso2.carbon.application.deployer.config.Artifact$Dependency

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.