Joe Almore
Joe Almore

Reputation: 4311

Apache Felix FileInstall won't work

I am trying to setup the FileInstall artifact to my OSGi project but with no success. No bundle is loaded under any folder.

First I run the Felix framework in this location (using the framework.properties file or config file):

org.osgi.framework.storage=./target/osgi-runner

Then I add the FileInstall dir property to the framework configuration, like this:

felix.fileinstall.dir=./deploy
org.osgi.framework.storage=./target/osgi-runner

What the documentation does not say is the relation between the two folders, the ./deploy folder should be where:

|--deploy // here?
|--target
      |--osgi-runner

|--target
      |--osgi-runner
      |--deploy  // here?

|--target
      |--osgi-runner
               |--deploy  //or here?

I tell you, I tried all free and none of them work, no bundle is loaded by this FileInstall artifact. The artifact uses 2 seconds by default to inspect the folder but it does not matter how much you wait, it simply fails to do its work.

I've been also thinking in developing my own version of this artifact, which is in fact not that complicated, but it would be fine to save some time and effort if I can get this thing working.

Somebody, any idea?

Upvotes: 2

Views: 541

Answers (1)

Joe Almore
Joe Almore

Reputation: 4311

I got it finally working. The /deploy folder has to be aside the /osgi-runner. The problem was that as I was running an Arquillian test with this feature and I was not waiting long enough for the artifact to take action, I was using a timer of 4 seconds so increased it to 10 and it started showing a console message Using ServiceTracker: Sun Feb 22 12:11:14 2015 indicating that a bundle has been loaded by the service.

I am using the following test case configuration with Arquillian OSGi:

In the framework.properties I have:

felix.fileinstall.dir=./target/load

And the Test-Case implementation is as follows:

@RunWith(Arquillian.class)
public class GreeterFileCnfTestCase {
    static final String FileInstall = "org.apache.felix.fileinstall-3.4.2.jar";

    @Deployment(name = FileInstall, testable = false)
    public static Archive<?> deploymentD() {
        return ShrinkWrap.create(ZipImporter.class, FileInstall)
                       .importFrom(new File("/path/to/apache.felix.fileinstall/" + FileInstall))
                       .as(JavaArchive.class);
    }

    @ArquillianResource
    BundleContext context;

    @Test
    public void fileConfigServices() throws Exception {
        Bundle fiBundle = context.getBundle(FileInstall);
        assertEquals("Bundle ACTIVE", Bundle.ACTIVE, fiBundle.getState());

        String fileName = "/bundle.test-1.0.0.jar";
        String dstFolder = "target/load";
        new File(dstFolder).mkdir();

        File srcBundle = new File("/path/to/bundle.test-1.0.0" + fileName);
        File dstBundle = new File(dstFolder + fileName);

        FileUtils.copyDirectory(srcBundle, dstBundle);

        TimeUnit.SECONDS.sleep(5);
        Bundle bundleTest = context.getBundle(dstBundle.toURI().toString());
        assertNotNull(bundleTest);
    }
}

Upvotes: 1

Related Questions