Package org.osgi.service.deploymentadmin

Examples of org.osgi.service.deploymentadmin.DeploymentException


    private void verifyEntryName(String name) throws DeploymentException {
        byte[] bytes = name.getBytes();
        boolean delimiterSeen = false;
        for (int j = 0; j < bytes.length; j++) {
            if (!VALID_RESOURCE_PATH_CHARS.get(bytes[j])) {
                throw new DeploymentException(CODE_BAD_HEADER, "Resource ID '" + name + "' contains invalid character(s)");
            }
            if (bytes[j] == '/') {
                if (delimiterSeen) {
                    throw new DeploymentException(CODE_BAD_HEADER, "Resource ID '" + name + "' contains multiple consequetive path seperators");
                }
                else {
                    delimiterSeen = true;
                }
            }
View Full Code Here


            }
            else if ("false".equals(value)) {
                return false;
            }
            else {
                throw new DeploymentException(CODE_BAD_HEADER, "Invalid '" + header + "' header for manifest " + "entry '" + getPath() + "' header, should be either 'true' or 'false' or not present");
            }
        }
        return false;
    }
View Full Code Here

        for (int i = 0; i < m_bundleInfos.length; i++) {
            String bsn = m_bundleInfos[i].getSymbolicName();
            if (m_nameToBundleInfo.put(bsn, m_bundleInfos[i]) != null) {
                // FELIX-4463: make sure that the DP is consistent...
                throw new DeploymentException(CODE_OTHER_ERROR, "Duplicate bundle present in deployment package: " + bsn);
            }

            String path = m_bundleInfos[i].getPath();
            if (m_pathToEntry.put(path, m_bundleInfos[i]) != null) {
                // FELIX-4463: make sure that the DP is consistent...
                throw new DeploymentException(CODE_OTHER_ERROR, "Non-unique path present in deployment package: " + path);
            }
        }

        List resourceInfos = m_manifest.getResourceInfos();
        m_resourceInfos = (ResourceInfoImpl[]) resourceInfos.toArray(new ResourceInfoImpl[resourceInfos.size()]);

        for (int i = 0; i < m_resourceInfos.length; i++) {
            String path = m_resourceInfos[i].getPath();
            if (m_pathToEntry.put(path, m_resourceInfos[i]) != null) {
                // FELIX-4463: make sure that the DP is consistent...
                throw new DeploymentException(CODE_OTHER_ERROR, "Non-unique path present in deployment package: " + path);
            }
        }
        m_resourcePaths = (String[]) m_pathToEntry.keySet().toArray(new String[m_pathToEntry.size()]);
    }
View Full Code Here

    public BundleInfoImpl(String path, Attributes attributes) throws DeploymentException {
        super(path, attributes);

        String bundleSymbolicName = attributes.getValue(BUNDLE_SYMBOLICNAME);
        if (bundleSymbolicName == null) {
            throw new DeploymentException(CODE_MISSING_HEADER, "Missing '" + BUNDLE_SYMBOLICNAME + "' header for manifest entry '" + getPath() + "'");
        }
        else if (bundleSymbolicName.trim().equals("")) {
            throw new DeploymentException(CODE_BAD_HEADER, "Invalid '" + BUNDLE_SYMBOLICNAME + "' header for manifest entry '" + getPath() + "'");
        }
        else {
            m_symbolicName = parseSymbolicName(bundleSymbolicName);
        }

        String version = attributes.getValue(BUNDLE_VERSION);
        if (version == null || version == "") {
            throw new DeploymentException(CODE_BAD_HEADER, "Invalid '" + BUNDLE_VERSION + "' header for manifest entry '" + getPath() + "'");
        }
        try {
            m_version = Version.parseVersion(version);
        }
        catch (IllegalArgumentException e) {
            throw new DeploymentException(CODE_BAD_HEADER, "Invalid '" + BUNDLE_VERSION + "' header for manifest entry '" + getPath() + "'");
        }

        m_customizer = parseBooleanHeader(attributes, DEPLOYMENTPACKAGE_CUSTOMIZER);
    }
View Full Code Here

            throw new IllegalArgumentException("Inputstream may not be null");
        }

        try {
            if (!m_semaphore.tryAcquire(TIMEOUT)) {
                throw new DeploymentException(CODE_TIMEOUT, "Timeout exceeded while waiting to install deployment package (" + TIMEOUT + " ms)");
            }
        }
        catch (InterruptedException ie) {
            throw new DeploymentException(CODE_TIMEOUT, "Thread interrupted");
        }

        File tempPackage = null;
        StreamDeploymentPackage source = null;
        AbstractDeploymentPackage target = null;
        boolean succeeded = false;

        try {
            JarInputStream jarInput = null;
            File tempIndex = null;
            File tempContents = null;
            try {
                File tempDir = m_context.getDataFile(TEMP_DIR);
                tempDir.mkdirs();
                tempPackage = File.createTempFile(TEMP_PREFIX, TEMP_POSTFIX, tempDir);
                tempPackage.delete();
                tempPackage.mkdirs();
                tempIndex = new File(tempPackage, PACKAGEINDEX_FILE);
                tempContents = new File(tempPackage, PACKAGECONTENTS_DIR);
                tempContents.mkdirs();
            }
            catch (IOException e) {
                m_log.log(LogService.LOG_ERROR, "Error writing package to disk", e);
                throw new DeploymentException(CODE_OTHER_ERROR, "Error writing package to disk", e);
            }

            try {
                jarInput = new ContentCopyingJarInputStream(sourceInput, tempIndex, tempContents);

                if (jarInput.getManifest() == null) {
                    m_log.log(LogService.LOG_ERROR, "Stream does not contain a valid deployment package: missing manifest!");
                    throw new DeploymentException(CODE_MISSING_HEADER, "No manifest present in deployment package!");
                }
            }
            catch (IOException e) {
                m_log.log(LogService.LOG_ERROR, "Stream does not contain a valid Jar", e);
                throw new DeploymentException(CODE_NOT_A_JAR, "Stream does not contain a valid Jar", e);
            }

            source = new StreamDeploymentPackage(jarInput, m_context, this);
            String dpSymbolicName = source.getName();

            target = getExistingOrEmptyDeploymentPackage(dpSymbolicName);

            // Fire an event that we're about to install a new package
            sendStartedEvent(source, target);

            // Assert that:
            // the source has no bundles that exists in other packages than the target.
            verifyNoResourcesShared(source, target);

            if (source.isFixPackage()) {
                // Assert that:
                // a. the version of the target matches the required fix-package range;
                // b. all missing source bundles are present in the target.
                verifyFixPackage(source, target);
            }
            else {
                // Assert that:
                // no missing resources or bundles are declared.
                verifySourcePackage(source);
            }

            try {
                m_session = new DeploymentSessionImpl(source, target, createInstallCommandChain(), this);
                m_session.call(false /* ignoreExceptions */);
            }
            catch (DeploymentException de) {
                throw de;
            }

            String dpInstallBaseDirectory = PACKAGE_DIR + File.separator + dpSymbolicName;

            File targetContents = m_context.getDataFile(dpInstallBaseDirectory + File.separator + PACKAGECONTENTS_DIR);
            File targetIndex = m_context.getDataFile(dpInstallBaseDirectory + File.separator + PACKAGEINDEX_FILE);

            if (source.isFixPackage()) {
                try {
                    Utils.merge(targetIndex, targetContents, tempIndex, tempContents);
                }
                catch (IOException e) {
                    m_log.log(LogService.LOG_ERROR, "Could not merge source fix package with target deployment package", e);
                    throw new DeploymentException(CODE_OTHER_ERROR, "Could not merge source fix package with target deployment package", e);
                }
            }
            else {
                File targetPackage = m_context.getDataFile(dpInstallBaseDirectory);
                targetPackage.mkdirs();
                if (!Utils.replace(targetPackage, tempPackage)) {
                    throw new DeploymentException(CODE_OTHER_ERROR, "Could not replace " + targetPackage + " with " + tempPackage);
                }
            }

            FileDeploymentPackage fileDeploymentPackage = null;
            try {
                fileDeploymentPackage = new FileDeploymentPackage(targetIndex, targetContents, m_context, this);
                m_packages.put(dpSymbolicName, fileDeploymentPackage);
            }
            catch (IOException e) {
                m_log.log(LogService.LOG_ERROR, "Could not create installed deployment package from disk", e);
                throw new DeploymentException(CODE_OTHER_ERROR, "Could not create installed deployment package from disk", e);
            }

            // Since we're here, it means everything went OK, so we might as well raise our success flag...
            succeeded = true;

View Full Code Here

        // Create a default configuration...
        m_config = new DeploymentAdminConfig(m_context);

        File packageDir = m_context.getDataFile(PACKAGE_DIR);
        if (packageDir == null) {
            throw new DeploymentException(CODE_OTHER_ERROR, "Could not create directories needed for deployment package persistence");
        }
        else if (packageDir.isDirectory()) {
            File[] dpPackages = packageDir.listFiles();
            for (int i = 0; i < dpPackages.length; i++) {
                File dpPackageDir = dpPackages[i];
View Full Code Here

     * @throws DeploymentException in case the uninstall failed.
     */
    public void uninstallDeploymentPackage(DeploymentPackage dp, boolean forced) throws DeploymentException {
        try {
            if (!m_semaphore.tryAcquire(TIMEOUT)) {
                throw new DeploymentException(CODE_TIMEOUT, "Timeout exceeded while waiting to uninstall deployment package (" + TIMEOUT + " ms)");
            }
        }
        catch (InterruptedException ie) {
            throw new DeploymentException(CODE_TIMEOUT, "Thread interrupted");
        }

        boolean succeeded = false;
        AbstractDeploymentPackage source = AbstractDeploymentPackage.EMPTY_PACKAGE;
        AbstractDeploymentPackage target = (AbstractDeploymentPackage) dp;

        // Notify listeners that we've about to uninstall the deployment package...
        sendUninstallEvent(source, target);

        try {
            try {
                m_session = new DeploymentSessionImpl(source, target, createUninstallCommandChain(), this);
                m_session.call(forced /* ignoreExceptions */);
            }
            catch (DeploymentException de) {
                throw de;
            }

            File targetPackage = m_context.getDataFile(PACKAGE_DIR + File.separator + source.getName());
            if (!Utils.delete(targetPackage, true)) {
                m_log.log(LogService.LOG_ERROR, "Could not delete deployment package from disk");
                throw new DeploymentException(CODE_OTHER_ERROR, "Could not delete deployment package from disk");
            }

            m_packages.remove(dp.getName());

            succeeded = true;
View Full Code Here

        boolean newPackage = target.isNew();

        // Verify whether the target package exists, and if so, falls in the requested fix-package range...
        if (newPackage || (!source.getVersionRange().isInRange(target.getVersion()))) {
            m_log.log(LogService.LOG_ERROR, "Target package version '" + target.getVersion() + "' is not in source range '" + source.getVersionRange() + "'");
            throw new DeploymentException(CODE_MISSING_FIXPACK_TARGET, "Target package version '" + target.getVersion() + "' is not in source range '" + source.getVersionRange() + "'");
        }

        // Verify whether all missing bundles are available in the target package...
        BundleInfoImpl[] bundleInfos = source.getBundleInfoImpls();
        for (int i = 0; i < bundleInfos.length; i++) {
            if (bundleInfos[i].isMissing()) {
                // Check whether the bundle exists in the target package...
                BundleInfoImpl targetBundleInfo = target.getBundleInfoByPath(bundleInfos[i].getPath());
                if (targetBundleInfo == null) {
                    m_log.log(LogService.LOG_ERROR, "Missing bundle '" + bundleInfos[i].getSymbolicName() + "/" + bundleInfos[i].getVersion() + " does not exist in target package!");
                    throw new DeploymentException(CODE_MISSING_BUNDLE, "Missing bundle '" + bundleInfos[i].getSymbolicName() + "/" + bundleInfos[i].getVersion() + " does not exist in target package!");
                }
            }
        }

        // Verify whether all missing resources are available in the target package...
        ResourceInfoImpl[] resourceInfos = source.getResourceInfos();
        for (int i = 0; i < resourceInfos.length; i++) {
            if (resourceInfos[i].isMissing()) {
                // Check whether the resource exists in the target package...
                ResourceInfoImpl targetResourceInfo = target.getResourceInfoByPath(resourceInfos[i].getPath());
                if (targetResourceInfo == null) {
                    m_log.log(LogService.LOG_ERROR, "Missing resource '" + resourceInfos[i].getPath() + " does not exist in target package!");
                    throw new DeploymentException(CODE_MISSING_RESOURCE, "Missing resource '" + resourceInfos[i].getPath() + " does not exist in target package!");
                }
            }
        }
    }
View Full Code Here

            DeploymentPackage targetPackage = getDeploymentPackageContainingBundleWithSymbolicName(symbolicName);
            // If found, it should match the given target DP; not found is also ok...
            if ((targetPackage != null) && !targetPackage.equals(target)) {
                m_log.log(LogService.LOG_ERROR, "Bundle '" + symbolicName + "/" + version + " already present in other deployment packages!");
                throw new DeploymentException(CODE_BUNDLE_SHARING_VIOLATION, "Bundle '" + symbolicName + "/" + version + " already present in other deployment packages!");
            }

            if (targetPackage == null) {
                // Maybe the bundle is installed without deployment admin...
                for (int j = 0; j < foreignBundles.length; j++) {
                    if (symbolicName.equals(foreignBundles[j].getSymbolicName()) && version.equals(foreignBundles[j].getVersion())) {
                        m_log.log(LogService.LOG_ERROR, "Bundle '" + symbolicName + "/" + version + " already present!");
                        throw new DeploymentException(CODE_BUNDLE_SHARING_VIOLATION, "Bundle '" + symbolicName + "/" + version + " already present!");
                    }
                }
            }
        }
View Full Code Here

     * @param manifest The manifest file to be used as deployment manifest
     * @throws DeploymentException If the specified manifest is not a valid deployment package manifest file.
     */
    public DeploymentPackageManifest(Manifest manifest) throws DeploymentException {
        if ((manifest == null) || (manifest.getMainAttributes() == null)) {
            throw new DeploymentException(CODE_BAD_HEADER);
        }
        m_manifest = manifest;

        Attributes mainAttributes = m_manifest.getMainAttributes();

        // TODO: verify symbolic name and entry-names for valid format/chars
        m_symbolicName = getNonNullHeader(mainAttributes.getValue(DEPLOYMENTPACKAGE_SYMBOLICMAME));

        String version = getNonNullHeader(mainAttributes.getValue(DEPLOYMENTPACKAGE_VERSION));
        try {
            m_version = new Version(version);
        }
        catch (IllegalArgumentException e) {
            throw new DeploymentException(CODE_BAD_HEADER);
        }

        String fixPackage = mainAttributes.getValue(DEPLOYMENTPACKAGE_FIXPACK);
        if (fixPackage != null) {
            try {
                m_fixPackage = VersionRange.parse(fixPackage);
            }
            catch (IllegalArgumentException iae) {
                throw new DeploymentException(CODE_BAD_HEADER, "Invalid version range for header: " + DEPLOYMENTPACKAGE_FIXPACK);
            }
        }
        else {
            m_fixPackage = null;
        }
View Full Code Here

TOP

Related Classes of org.osgi.service.deploymentadmin.DeploymentException

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.