Search in sources :

Example 6 with ArtifactInstaller

use of org.apache.felix.fileinstall.ArtifactInstaller in project felix by apache.

the class DirectoryWatcher method update.

private Bundle update(Artifact artifact) {
    Bundle bundle = null;
    try {
        File path = artifact.getPath();
        // If the listener is an installer, ask for an update
        if (artifact.getListener() instanceof ArtifactInstaller) {
            ((ArtifactInstaller) artifact.getListener()).update(path);
        } else // if the listener is an url transformer
        if (artifact.getListener() instanceof ArtifactUrlTransformer) {
            URL transformed = artifact.getTransformedUrl();
            bundle = context.getBundle(artifact.getBundleId());
            if (bundle == null) {
                log(Logger.LOG_WARNING, "Failed to update bundle: " + path + " with ID " + artifact.getBundleId() + ". The bundle has been uninstalled", null);
                return null;
            }
            Util.log(context, Logger.LOG_INFO, "Updating bundle " + bundle.getSymbolicName() + " / " + bundle.getVersion(), null);
            stopTransient(bundle);
            Util.storeChecksum(bundle, artifact.getChecksum(), context);
            InputStream in = (transformed != null) ? transformed.openStream() : new FileInputStream(path);
            try {
                bundle.update(in);
            } finally {
                in.close();
            }
        } else // else we need to ask for an update on the bundle
        if (artifact.getListener() instanceof ArtifactTransformer) {
            File transformed = artifact.getTransformed();
            bundle = context.getBundle(artifact.getBundleId());
            if (bundle == null) {
                log(Logger.LOG_WARNING, "Failed to update bundle: " + path + " with ID " + artifact.getBundleId() + ". The bundle has been uninstalled", null);
                return null;
            }
            Util.log(context, Logger.LOG_INFO, "Updating bundle " + bundle.getSymbolicName() + " / " + bundle.getVersion(), null);
            stopTransient(bundle);
            Util.storeChecksum(bundle, artifact.getChecksum(), context);
            InputStream in = new FileInputStream(transformed != null ? transformed : path);
            try {
                bundle.update(in);
            } finally {
                in.close();
            }
        }
    } catch (Throwable t) {
        log(Logger.LOG_WARNING, "Failed to update artifact " + artifact.getPath(), t);
    }
    return bundle;
}
Also used : ArtifactInstaller(org.apache.felix.fileinstall.ArtifactInstaller) Bundle(org.osgi.framework.Bundle) BufferedInputStream(java.io.BufferedInputStream) JarInputStream(java.util.jar.JarInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArtifactTransformer(org.apache.felix.fileinstall.ArtifactTransformer) ArtifactUrlTransformer(org.apache.felix.fileinstall.ArtifactUrlTransformer) File(java.io.File) URL(java.net.URL) FileInputStream(java.io.FileInputStream)

Aggregations

ArtifactInstaller (org.apache.felix.fileinstall.ArtifactInstaller)6 File (java.io.File)5 Bundle (org.osgi.framework.Bundle)4 BufferedInputStream (java.io.BufferedInputStream)2 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 URISyntaxException (java.net.URISyntaxException)2 URL (java.net.URL)2 ArtifactTransformer (org.apache.felix.fileinstall.ArtifactTransformer)2 ArtifactUrlTransformer (org.apache.felix.fileinstall.ArtifactUrlTransformer)2 InstallableListener (org.apache.felix.fileinstall.plugins.installer.InstallableListener)2 InstallableUnitEvent (org.apache.felix.fileinstall.plugins.installer.InstallableUnitEvent)2 Test (org.junit.Test)2 BundleException (org.osgi.framework.BundleException)2 InputStream (java.io.InputStream)1 Collection (java.util.Collection)1 LinkedList (java.util.LinkedList)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 JarInputStream (java.util.jar.JarInputStream)1