Package org.apache.geronimo.system.plugin.model

Examples of org.apache.geronimo.system.plugin.model.PluginArtifactType


    private List<Dependency> getMissingPrerequisites(PluginType plugin) {
        if (plugin.getPluginArtifact().size() != 1) {
            throw new IllegalArgumentException("A plugin configuration must include one plugin artifact, not " + plugin.getPluginArtifact().size());
        }

        PluginArtifactType metadata = plugin.getPluginArtifact().get(0);
        List<PrerequisiteType> prereqs = metadata.getPrerequisite();

        ArrayList<Dependency> missingPrereqs = new ArrayList<Dependency>();
        for (PrerequisiteType prereq : prereqs) {
            Artifact artifact = toArtifact(prereq.getId());
            try {
View Full Code Here


    }

    private void verifyPrerequisites(PluginType plugin) throws MissingDependencyException {
        List<Dependency> missingPrereqs = getMissingPrerequisites(plugin);
        if (!missingPrereqs.isEmpty()) {
            PluginArtifactType metadata = plugin.getPluginArtifact().get(0);
            Artifact moduleId = toArtifact(metadata.getModuleId());
            StringBuffer buf = new StringBuffer();
            buf.append(moduleId.toString()).append(" requires ");
            Iterator<Dependency> iter = missingPrereqs.iterator();
            while (iter.hasNext()) {
                buf.append(iter.next().getArtifact().toString());
View Full Code Here

        } else {
            soFar.add(configID);
        }
        // Download and install the main artifact
        Artifact[] matches = configManager.getArtifactResolver().queryArtifacts(configID);
        PluginArtifactType instance = null;
        if (matches.length == 0) {
            // not present, needs to be downloaded
            monitor.getResults().setCurrentMessage("Downloading " + configID);
            monitor.getResults().setCurrentFilePercent(-1);
            OpenResult result = null;
            for (SourceRepository repository : repos) {
                result = repository.open(configID, monitor);
                if (result != null) {
                    break;
                }
            }
            if (result == null) {
                throw new IllegalArgumentException("Could not find " + configID + " in any repo: " + repos);
            }
            // Check if the result is already in server's repository (maybe the actual configId is not what was expected?)
            if (configManager.getArtifactResolver().queryArtifacts(result.getArtifact()).length > 0) {
                String msg = "Not downloading " + configID + ". Query for " + configID + " resulted in " + result.getArtifact()
                        + " which is already available in server's repository.";
                monitor.getResults().setCurrentMessage(msg);
                log.info(msg);
                result.close();
                return;
            }
            try {
                File tempFile = result.getFile();
                if (tempFile == null) {
                    log.error("Null filehandle was returned for " + configID);
                    throw new IllegalArgumentException("Null filehandle was returned for " + configID);
                }
                PluginType pluginData = metadata.get(configID);
                // Only bother with the hash if we got it from a source other than the download file itself
                HashType hash = pluginData == null ? null : pluginData.getPluginArtifact().get(0).getHash();
                if (hash != null) {
                    String actual = ConfigurationStoreUtil.getActualChecksum(tempFile, hash.getType());
                    if (!actual.equals(hash.getValue())) {
                        log.error("File download incorrect (expected {} hash {} but got {})", new String[]{hash.getType(), hash.getValue(), actual});
                        throw new IOException("File download incorrect (expected " + hash.getType() + " hash " + hash.getValue() + " but got " + actual + ")");
                    }
                }
                // See if the download file has plugin metadata and use it in preference to what is in the catalog.
                try {
                    PluginType realPluginData = GeronimoSourceRepository.extractPluginMetadata(tempFile);
                    if (realPluginData != null) {
                        pluginData = realPluginData;
                    }
                } catch (Exception e) {
                    log.error("Unable to read plugin metadata: {}", e.getMessage());
                    throw (IOException) new IOException("Unable to read plugin metadata: " + e.getMessage()).initCause(e);
                }
                if (pluginData != null) { // it's a plugin, not a plain JAR
                    if (!validatePlugin(pluginData)) {
                        monitor.getResults().addSkippedConfigID(new MissingDependencyException("already installed", configID, (Stack<Artifact>)null));
                        return;
                    }
                    instance = pluginData.getPluginArtifact().get(0);
                }
                monitor.getResults().setCurrentMessage("Copying " + result.getArtifact() + " to the repository");
                result.install(writeableRepo, monitor);
                if (dependency) {
                    monitor.getResults().addDependencyInstalled(configID);
                    configID = result.getArtifact();
                } else {
                    configID = result.getArtifact();
                    monitor.getResults().addInstalledConfigID(configID);
                }
                if (pluginData != null) {
                    log.debug("Installed plugin with moduleId={} and name={}", pluginData.getPluginArtifact().get(0).getModuleId(), pluginData.getName());
                } else {
                    log.debug("Installed artifact={}", configID);
                }
            } finally {
                //todo probably not needede
                result.close();
            }
        } else {
            if (dependency) {
                monitor.getResults().addDependencyPresent(configID);
            } else {
                monitor.getResults().addInstalledConfigID(configID);
            }
        }
        // Download and install the dependencies
        try {
            if (!configID.isResolved()) {
                // See if something's running
                for (int i = matches.length - 1; i >= 0; i--) {
                    Artifact match = matches[i];
                    if (configStore.containsConfiguration(match) && configManager.isRunning(match)) {
                        log.debug("Found required configuration={} and it is running", match);
                        return; // its dependencies must be OK
                    } else {
                        log.debug("Either required configuration={} is not installed or it is not running", match);
                    }
                }
                // Go with something that's installed
                configID = matches[matches.length - 1];
            }
            ConfigurationData data = null;
            if (configStore.containsConfiguration(configID)) {
                if (configManager.isRunning(configID)) {
                    return; // its dependencies must be OK
                }
                log.debug("Loading configuration={}", configID);
                data = configStore.loadConfiguration(configID);
            }
            // Download the dependencies
            parentStack.push(configID);
            if (instance == null) {
                PluginType currentPlugin = getPluginMetadata(configID);
                if (currentPlugin != null) {
                    instance = currentPlugin.getPluginArtifact().get(0);
                }
            }
            if (instance == null) {
                //no plugin metadata, guess with something else
                Dependency[] dependencies = data == null ? getDependencies(writeableRepo, configID) : getDependencies(data);
                for (Dependency dep : dependencies) {
                    Artifact artifact = dep.getArtifact();
                    log.debug("Attempting to download dependency={} for configuration={}", artifact, configID);
                    downloadArtifact(artifact, metadata, repos, username, password, monitor, soFar, parentStack, true, servers, loadOverride);
                }
            } else {
                //rely on plugin metadata if present.
                List<DependencyType> deps = instance.getDependency();
                for (DependencyType dep : deps) {
                    Artifact artifact = toArtifact(dep);
                    log.debug("Attempting to download dependency={} for configuration={}", artifact, configID);
                    downloadArtifact(artifact, metadata, repos, username, password, monitor, soFar, parentStack, true, servers, loadOverride & dep.isStart());
                }
View Full Code Here

            }
        }
        ConfigurationData data = configStore.loadConfiguration(moduleId);

        PluginType meta = new PluginType();
        PluginArtifactType instance = new PluginArtifactType();
        meta.getPluginArtifact().add(instance);
        meta.setName(toArtifactType(moduleId).getArtifactId());
        instance.setModuleId(toArtifactType(moduleId));
        meta.setCategory("Unknown");
        instance.getGeronimoVersion().add(serverInfo.getVersion());
        instance.getObsoletes().add(toArtifactType(new Artifact(moduleId.getGroupId(),
                moduleId.getArtifactId(),
                (Version) null,
                moduleId.getType())));
        List<DependencyType> deps = instance.getDependency();
        addGeronimoDependencies(data, deps, true);
        return meta;
    }
View Full Code Here

    public void renderView(RenderRequest request, RenderResponse response, MultiPageModel model) throws PortletException, IOException {
        String configId = request.getParameter("configId");
        PluginInstaller pluginInstaller = ManagementHelper.getManagementHelper(request).getPluginInstaller();
        Artifact newArtifact = Artifact.create(configId)
        PluginType metadata = pluginInstaller.getPluginMetadata(newArtifact)
        PluginArtifactType instance = metadata.getPluginArtifact().get(0);
        request.setAttribute("configId", PluginInstallerGBean.toArtifact(instance.getModuleId()).toString());
        request.setAttribute("name", metadata.getName());
        request.setAttribute("repository", combine(instance.getSourceRepository()));
        request.setAttribute("category", metadata.getCategory());
        request.setAttribute("url", metadata.getUrl());
        request.setAttribute("author", metadata.getAuthor());
        request.setAttribute("description", metadata.getDescription());
        List<LicenseType> licenses = metadata.getLicense();
        if (licenses != null && licenses.size() > 0) {
            request.setAttribute("license", licenses.get(0).getValue());
            if (licenses.get(0).isOsiApproved()) {
                request.setAttribute("licenseOSI", "true");
            }
            if (licenses.size() > 1) {
                log.warn(
                        "Unable to edit plugin metadata containing more than one license!  Additional license data will not be editable.");
            }
        }
        //Choose the first geronimo-versions element and set the config version element to that version number.
        List<String> gerVers = instance.getGeronimoVersion();
        if (gerVers != null && gerVers.size() > 0) {
            request.setAttribute("geronimoVersion", gerVers.get(0));
        }
        request.setAttribute("jvmVersions", combine(instance.getJvmVersion()));
        request.setAttribute("dependencies", toString(instance.getDependency()));
        request.setAttribute("obsoletes", toString(instance.getObsoletes()));
        List<PrerequisiteType> reqs = instance.getPrerequisite();
        if (reqs != null && reqs.size() > 0) {
            int i = 1;
            for (PrerequisiteType prereq: reqs) {
                String prefix = "prereq" + i;
                request.setAttribute(prefix, PluginInstallerGBean.toArtifact(prereq.getId()).toString());
View Full Code Here

    public String actionAfterView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException {
        String configId = request.getParameter("configId");
        PluginInstaller pluginInstaller = ManagementHelper.getManagementHelper(request).getPluginInstaller();
        PluginType metadata = pluginInstaller.getPluginMetadata(Artifact.create(configId));
        PluginArtifactType instance = metadata.getPluginArtifact().get(0);

        String name = request.getParameter("name");
        metadata.setName(name);
        metadata.setCategory(request.getParameter("category"));
        metadata.setUrl(request.getParameter("url"));
        metadata.setAuthor(request.getParameter("author"));
        metadata.setDescription(request.getParameter("description"));
        String licenseString = request.getParameter("license");
        String osi = request.getParameter("licenseOSI");
        List<LicenseType> licenses = metadata.getLicense();
        if (!licenses.isEmpty()) {
            licenses.remove(0);
        }
        if (licenseString != null && !licenseString.trim().equals("")) {
            LicenseType license = new LicenseType();
            license.setValue(licenseString.trim());
            license.setOsiApproved(osi != null && !osi.equals(""));
            licenses.add(0, license);
        }

        String jvmsString = request.getParameter("jvmVersions");
        split(jvmsString, instance.getJvmVersion());

        String deps = request.getParameter("dependencies");
        toDependencies(split(deps), instance.getDependency());

        String obsoletes = request.getParameter("obsoletes");
        toArtifacts(split(obsoletes), instance.getObsoletes());

        String repo = request.getParameter("repository");
        split(repo, instance.getSourceRepository());

        //TODO this is wrong, we are only supplying one version to the UI
        String version = request.getParameter("geronimoVersion");
        split(version, instance.getGeronimoVersion());

        List<PrerequisiteType> prereqs = instance.getPrerequisite();
        //TODO this is probably wrong if # of prereqs is changed.
        for (int i = 0; i < 3 && !prereqs.isEmpty(); i++) {
            prereqs.remove(0);
        }
        int counter = 1;
View Full Code Here

    }


    private PluginType toPluginType(Artifact artifact) {
        PluginType plugin = new PluginType();
        PluginArtifactType instance = new PluginArtifactType();
        ArtifactType artifactType = PluginInstallerGBean.toArtifactType(artifact);
        instance.setModuleId(artifactType);
        plugin.getPluginArtifact().add(instance);
        return plugin;
    }
View Full Code Here

            defaultRepository = defaultGeronimoRepository;
        }
        pluginListType.getDefaultRepository().add(artifactRepository.getBasedir());
        PluginType pluginType = new PluginType();
        pluginListType.getPlugin().add(pluginType);
        PluginArtifactType instance = new PluginArtifactType();
        pluginType.getPluginArtifact().add(instance);
        ArtifactType artifactType = PluginInstallerGBean.toArtifactType(geronimoArtifact);
        instance.setModuleId(artifactType);

        GeronimoDeploymentManager mgr = getDeploymentManager2();
        Object key = mgr.startInstall(pluginListType, defaultRepository, false, null, null);
//        Object key = mgr.startInstall(artifactFile, defaultRepository, false, null, null);
        waitTillDone(mgr, key);
View Full Code Here

                //filter dependencies file
                filter(dependencyFile, filteredDependencyFile);
                //read dependency types, convert to dependenciees, compare.
                FileReader in = new FileReader(filteredDependencyFile);
                try {
                    PluginArtifactType pluginArtifactType = PluginXmlUtil.loadPluginArtifactMetadata(in);
                    PluginArtifactType removed = new PluginArtifactType();
                    for (DependencyType test: pluginArtifactType.getDependency()) {
                        boolean t1 = added.contains(test);
                        int s1 = added.size();
                        boolean t2 = added.remove(test);
                        int s2 = added.size();
                        if (t1 != t2) {
                            getLogger().warn("dependencies.contains: " + t1 + ", dependencies.remove(test): " + t2);
                        }
                        if (t1 == (s1 == s2)) {
                            getLogger().warn("dependencies.contains: " + t1 + ", size before: " + s1 + ", size after: " + s2);
                        }
                        if (!t2) {
                            removed.getDependency().add(test);
                        }
                    }
                    if (!added.isEmpty() || !removed.getDependency().isEmpty()) {
                        saveDependencyChanges(added, removed);
                        if (overwriteChangedDependencies) {
                            writeDependencies(toPluginArtifactType(dependencies),  dependencyFile);
                        }
                    }
View Full Code Here

    }

    protected void saveDependencyChanges(Collection<DependencyType> dependencies, PluginArtifactType removed)
            throws Exception {
        File addedFile = new File(filteredDependencyFile.getParentFile(), "dependencies.added.xml");
        PluginArtifactType added = toPluginArtifactType(dependencies);
        writeDependencies(added,  addedFile);

        File removedFile = new File(filteredDependencyFile.getParentFile(), "dependencies.removed.xml");
        writeDependencies(removed,  removedFile);
       
        File treeListing = saveTreeListing();
       
        StringWriter out = new StringWriter();
        out.write("Dependencies have changed:\n");
        if (!added.getDependency().isEmpty()) {
            out.write("\tAdded dependencies are saved here: " + addedFile.getAbsolutePath() + "\n");
            if (logDependencyChanges) {
                PluginXmlUtil.writePluginArtifact(added, out);
            }
        }
View Full Code Here

TOP

Related Classes of org.apache.geronimo.system.plugin.model.PluginArtifactType

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.