On 2012/07/06 17:43, Jukka Zitting wrote:
You'll want to make sure that both the tika-bundle and tika-core bundles are actually started/activated by the OSGi environment, as otherwise the relevant Activators that Tika uses to hook up with the available services won't get started.
Bingo, having spent much time on why the Parsers were not behaving, it's actually the tika-core bunde that is not activating. Eclipse is a finicky beast, even if a bundle has an Activator it won't be activated if the Bundle-ActivationPolicy is not set, unless the product is modified to explicitly auto start the bundle.

Ideally, it would be preferable to set the Bundle-ActivationPolicy to lazy to allow Eclipse (and others?) to do the right thing without needless complication.

I've tested this by modifying the tika-core/pom.xml (see attached), and adding the following line:

            <Bundle-Activator>
              org.apache.tika.config.TikaActivator
            </Bundle-Activator>
+ <Bundle-ActivationPolicy>lazy</Bundle-ActivationPolicy>

Any chance of this for the 1.2 release?

Thanks for the help.
Kevin.

p.s. an alternative method of obtaining access to the Detector and Parser involves something like this in your own bundles activator:

import org.apache.tika.detect.Detector;
import org.apache.tika.parser.Parser;
...
    @Override
    public void start(BundleContext context) throws Exception {
        super.start(context);
detector = (Detector) context.getService(context.getServiceReference(Detector.class.getName())); parser = (Parser) context.getService(context.getServiceReference(Parser.class.getName()));
    }

<?xml version="1.0" encoding="UTF-8"?>

<!--
  Licensed to the Apache Software Foundation (ASF) under one
  or more contributor license agreements.  See the NOTICE file
  distributed with this work for additional information
  regarding copyright ownership.  The ASF licenses this file
  to you under the Apache License, Version 2.0 (the
  "License"); you may not use this file except in compliance
  with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an
  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  KIND, either express or implied.  See the License for the
  specific language governing permissions and limitations
  under the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd";>
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>org.apache.tika</groupId>
    <artifactId>tika-parent</artifactId>
    <version>1.2-SNAPSHOT</version>
    <relativePath>../tika-parent/pom.xml</relativePath>
  </parent>

  <artifactId>tika-core</artifactId>
  <packaging>bundle</packaging>
  <name>Apache Tika core</name>
  <url>http://tika.apache.org/</url>

  <dependencies>
    <!-- Optional OSGi dependencies, used only when running within OSGi -->
    <dependency>
      <groupId>org.osgi</groupId>
      <artifactId>org.osgi.core</artifactId>
      <version>4.0.0</version>
      <scope>provided</scope>
      <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>org.osgi</groupId>
      <artifactId>org.osgi.compendium</artifactId>
      <version>4.0.0</version>
      <scope>provided</scope>
      <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>biz.aQute</groupId>
      <artifactId>bndlib</artifactId>
      <scope>provided</scope>
    </dependency>

    <!-- Test dependencies -->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <extensions>true</extensions>
        <configuration>
          <instructions>
            <Bundle-DocURL>${project.url}</Bundle-DocURL>
            <Bundle-Activator>
              org.apache.tika.config.TikaActivator
            </Bundle-Activator>
            <Bundle-ActivationPolicy>lazy</Bundle-ActivationPolicy>
          </instructions>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.rat</groupId>
        <artifactId>apache-rat-plugin</artifactId>
        <configuration>
          <excludes>
            <exclude>src/test/resources/org/apache/tika/**</exclude>
          </excludes>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>clirr-maven-plugin</artifactId>
        <executions>
          <execution>
            <phase>verify</phase>
            <goals>
              <goal>check</goal>
            </goals>
            <configuration>
              <excludes>
                <exlude>org/apache/tika/config/TikaActivator</exlude>
                <exlude>org/apache/tika/metadata/Property$PropertyType</exlude>
                <exlude>org/apache/tika/metadata/Property$ValueType</exlude>
                <exlude>org/apache/tika/metadata/DublinCore</exlude>
                <exlude>org/apache/tika/metadata/Metadata</exlude>
                <exlude>org/apache/tika/metadata/MSOffice</exlude>
                <exlude>org/apache/tika/parser/EmptyParser</exlude>
              </excludes>
              <comparisonArtifacts>
                <comparisonArtifact>
                  <groupId>org.apache.tika</groupId>
                  <artifactId>tika-core</artifactId>
                  <version>1.0</version>
                  <type>jar</type>
                </comparisonArtifact>
              </comparisonArtifacts>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-failsafe-plugin</artifactId>
        <version>2.10</version>
        <configuration>
          <additionalClasspathElements>
            <additionalClasspathElement>
              ${project.build.directory}/${project.build.finalName}.jar
            </additionalClasspathElement>
          </additionalClasspathElements>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>integration-test</goal>
              <goal>verify</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

</project>

Reply via email to