Spring Dynamic Modules with Maven2: Um exemplo prático
Como prometido estou postando um dos testes que fiz com Spring e Osgi. Faz uns 30 dias que eu tinha feito esses testes porem não tive tempo de postar. Em sua postagem recente Carlos E. Perez fez suas apostas para as 5 tecnologias que iriam bombar em 2008, concordo com a maioria delas. O que chama atenção no post de carlos: Top Five Java Technologies that Didn't Make the List and Why é que Osgi aparece na lista dele, claro, na lista das tecnologias que você veria estudar. Isso não é por acaso em 6 de fevereiro Mark New do JBoss confirma através de entrevista que o JBoss ira criar sua implementação de Osgi para o container. Claro que além disso tudo existe o projeto Spring Dynamic Module que é um projeto de integração do Spring com Osgi.
Agora vamos ver um exemplo simples de Spring DM com Maven2, maven é um framework da apache para facilitar a gerencia de configurações e ciclo de build de um projeto. Foi escolhido por que facilita os meus testes com Osgi e além disso o Spring DM possui facilidades para usuario do Maven2 que é o meu caso. :)
Vamos criar dois projetos, eu fiz com o eclipse ide porem poderia ser com qualquer ide, eu utilizei o plugin Archetype do maven para criar a estrutura básica do POM e o projeto do eclipse.
São dois projetos:
Projeto Spring-DM-Simple-Bundle:
Crie o package: org.diegopacheco.springdm.simplebundle.service você deve criar esse package na estrutura padrão do maven para fontes java que é: src/main/java. Dentro desse pacote vamos ter dois artefatos são eles:
DataServicepackage org.diegopacheco.springdm.simplebundle.service;
public interface DataService {
public String getCurrentTime();
}
DataServiceImpl
package org.diegopacheco.springdm.simplebundle.service;
import java.util.Calendar;
public class DataServiceImpl implements DataService{
@Override
public String getCurrentTime() {
Calendar cal = Calendar.getInstance();
return cal.get(Calendar.DAY_OF_MONTH) + "/" +
cal.get(Calendar.MONTH) + "/" +
cal.get(Calendar.YEAR);
}
}
Dentro da estrutura padrão do maven para arquivos de configurações que é src/main/resources crie a pasta: META-INF e crie o artefato MANIFEST.MF com o seguinte conteudo:
Bundle-Version: 1.0
Bundle-Name: SpringDM-Simple-Bundle
Bundle-SymbolicName: org.diegopacheco.simple.bundle
Bundle-Vendor: Diego Pacheco
Export-Package: org.diegopacheco.springdm.simplebundle.service
Bundle-ManifestVersion: 2
ainda no path /src/main/resources/META-INF crie a pasta spring e adicione dois arquivos:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:osgi="http://www.springframework.org/schema/osgi"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/osgi
http://www.springframework.org/schema/osgi/spring-osgi.xsd"
>
<bean
id="dataServiceImpl"
class="org.diegopacheco.springdm.simplebundle.service.DataServiceImpl"
/>
</beans>
O legal do Spring Osgi é que ele faz discovery automático de qualquer xml de beans do Spring. Agora o arquivo spring-osgi-beans.xml contem os beans osgi. Segue o arquivo:
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/osgi"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/osgi
http://www.springframework.org/schema/osgi/spring-osgi.xsd"
>
<reference
id="pkgAdminService"
interface="org.osgi.service.packageadmin.PackageAdmin"
/>
<service
id="dataServiceOsgi"
ref="dataServiceImpl"
auto-export="interfaces"
/>
</beans:beans>
Aqui estamos registrando o bean pkgAdminService que é um bean do Osgi que tem seu próprio Bundle, isso mesmo um Bundle de gerenciamento de Bundles.
Também encontramos a exportação do nosso serviço de datas onde informamos o id-osgi e no atributo ref fazemos a referencia ao bean do Spring DataServiceImpl. Na propriedade auto-export definimos a estrategista de como vamos exportar o recurso do nosso serviço de datas.
Por ultimo mas não menos importante vem o POM.XML:
<project>
<parent>
<artifactId>Spring-DM-Simple-Bundle-Master</artifactId>
<groupId>Spring-DM-Simple-Bundle-Master</groupId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>Spring-DM-Simple-Bundle</groupId>
<artifactId>Spring-DM-Simple-Bundle</artifactId>
<packaging>jar</packaging>
<version>1.0.0</version>
<description>Teste de um Bunde SpringDM simples.</description>
<url>http://maven.apache.org</url>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestFile>
src/main/resources/META-INF/MANIFEST.MF
</manifestFile>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
Agora você deve instalar esse Bundle no seu repositório local do Maven podemos fazer isso através do comando: mvn install ao rodar esse comando vamos ter um log semelhante a esse:
[INFO] Scanning for projects...
[INFO] ----------------------------------------------------------------------------
[INFO] Building Unnamed - Spring-DM-Simple-Bundle:Spring-DM-Simple-Bundle:jar:1.0.0
[INFO] task-segment: [install]
[INFO] ----------------------------------------------------------------------------
[INFO] resources:resources
[INFO] Using default encoding to copy filtered resources.
[INFO] compiler:compile
[INFO] Nothing to compile - all classes are up to date
[INFO] resources:testResources
[INFO] Using default encoding to copy filtered resources.
[INFO] compiler:testCompile
[INFO] No sources to compile
[INFO] surefire:test
[INFO] No tests to run.
[INFO] jar:jar
[INFO] Building jar: D:\Diego\Info\Programacao\Java\eclipse\eclipse_workspace\Spring-DM-Bundle-Mater\Spring-DM-Simple-Bundle\target\Spring-DM-Simple-Bundle-1.0.0.jar
[INFO] install:install
[INFO] Installing D:\Diego\Info\Programacao\Java\eclipse\eclipse_workspace\Spring-DM-Bundle-Mater\Spring-DM-Simple-Bundle\target\Spring-DM-Simple-Bundle-1.0.0.jar to C:\Users\Diego Pacheco\.m2\repository\Spring-DM-Simple-Bundle\Spring-DM-Simple-Bundle\1.0.0\Spring-DM-Simple-Bundle-1.0.0.jar
[INFO] ----------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL Spring-DM-Simple-Bundle:Spring-DM-Simple-Bundle:jar:1.0.0 ( task-segment: [install] )
[INFO] ----------------------------------------------------------------------------
[INFO] Total time: 3 second
[INFO] Finished at: Sat Feb 16 23:32:34 BRST 2008
[INFO] Memory 2M/10M
[INFO] ----------------------------------------------------------------------------
Agora vamos ao outro projeto o Spring-DM-Simple-Bundle-Tester. Nesse projeto no path src/main/test vamos criar o package: org.diegopacheco.springdm.simplebundle.test nesse package o artefato: TesteIntegrado.java
package org.diegopacheco.springdm.simplebundle.test;
import org.diegopacheco.springdm.simplebundle.service.DataService;
import org.osgi.framework.ServiceReference;
import org.springframework.osgi.test.AbstractConfigurableBundleCreatorTests;
public class TesteIntegrado extends AbstractConfigurableBundleCreatorTests {
public void testFull() throws Exception {
System.out.println("BundleContext: " + bundleContext);
ServiceReference ref = bundleContext.getServiceReference("org.diegopacheco.springdm.simplebundle.service.DataService");
System.out.println("DataService ref: " + ref);
DataService ds = (DataService)bundleContext.getService(ref);
System.out.println("DataService: " + ds);
System.out.println("Data via Spring Osgi: " + ds.getCurrentTime());
}
protected String[] getTestBundlesNames() {
return new String[] { "Spring-DM-Simple-Bundle," +
"Spring-DM-Simple-Bundle," +
"1.0.0"};
}
}
Essa classe de testes estende a classe do Spring DM AbstractConfigurableBundleCreatorTests que prove facilidades para subir a plataforma Osgi.
O método getTestBundlesNames() serve para nos informarmos na ordem: artfactId,groupId e version do jar que o maven gerou no nosso repositório local.
através da variável de instância bundleContext nos acessamos o contexto do Osgi e através do metodo getServiceReference("id_bundle") recuperamos um bundle(modulo osgi). Esse metodo irá retornar um objeto do tipo ServiceReference que representa o nosso service do Spring agora podemos fazer: bundleContext.getService(serviceReference) para obter o serviço de fato. Após isso usamos de forma normal.
No path src/main/resources crie o arquivo log4j.properties com o conteúdo a baixo:
log4j.rootCategory=info, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout.ConversionPattern=%t %p [%c] - %m%n
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.threshold=TRACE
log4j.logger.org.springframework=INFO
log4j.logger.org.springframework.osgi.test=INFO
Crie também o package: org.diegopacheco.springdm.simplebundle.test e dentro o arquivo MANIFEST.MF com o seguinte conteudo:
Manifest-Version: 1.0
Bundle-Name: SpringDM-Simple-Bundle-Tester
Bundle-SymbolicName: org.diegopacheco.simple.bundle.tester
Bundle-Vendor: Diego Pacheco
Bundle-Activator: org.springframework.osgi.test.JUnitTestActivator
Import-Package: junit.framework,
org.osgi.framework;specification-version="1.3.0",
org.springframework.core.io,
org.springframework.osgi.test,
org.springframework.osgi.samples.simpleservice
Por ultimo mas não menos importante o POM.xml desse projeto:
<project>
<parent>
<artifactId>Spring-DM-Simple-Bundle-Master</artifactId>
<groupId>Spring-DM-Simple-Bundle-Master</groupId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>Spring-DM-Simple-Bundle-Tester</groupId>
<artifactId>Spring-DM-Simple-Bundle-Tester</artifactId>
<packaging>jar</packaging>
<version>1.0.0</version>
<description>
aplicao de teste para o Spring-DM-Simple-Bundle uasndo o
mecanismo osgi do Spring dm
</description>
<dependencies>
<!-- Dependencia para o outro projeto que eu fiz o Spring-DM-Simple-Bundle
Rodar anteso mvn package -->
<dependency>
<groupId>Spring-DM-Simple-Bundle</groupId>
<artifactId>Spring-DM-Simple-Bundle</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.springframework.osgi</groupId>
<artifactId>spring-osgi-core</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.springframework.osgi</groupId>
<artifactId>spring-osgi-test</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.springframework.osgi</groupId>
<artifactId>spring-osgi-annotation</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl104-over-slf4j</artifactId>
<version>1.4.3</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.4.3</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.4.3</version>
<exclusions>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.osgi</groupId>
<artifactId>log4j.osgi</artifactId>
<version>1.2.15-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.osgi</groupId>
<artifactId>junit.osgi</artifactId>
<version>3.8.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.osgi</groupId>
<artifactId>aopalliance.osgi</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.eclipse.osgi</groupId>
<artifactId>org.eclipse.osgi</artifactId>
<version>3.2.2</version>
<type>jar</type>
</dependency>
</dependencies>
<repositories>
<repository>
<id>central</id>
<url>http://localhost:8080/artifactory/repo</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>snapshots</id>
<url>http://localhost:8080/artifactory/repo</url>
<releases>
<enabled>false</enabled>
</releases>
</repository>
<repository>
<id>spring-ext</id>
<name>Spring External Dependencies Repository</name>
<url>
http://springframework.svn.sourceforge.net/svnroot/springframework/repos/repo-ext/
</url>
</repository>
<repository>
<id>spring-osgi-artifacts</id>
<name>Spring Portfolio OSGi Artifacts Repository</name>
<snapshots>
<enabled>true</enabled>
</snapshots>
<url>
http://s3.amazonaws.com/maven.springframework.org/osgi
</url>
</repository>
</repositories>
<build>
<resources>
<resource>
<targetPath>
../org/diegopacheco/springdm/simplebundle/test
</targetPath>
<filtering>true</filtering>
<includes>
<include>MANIFEST.MF</include>
</includes>
<directory>
src/test/java/org/diegopacheco/springdm/simplebundle/test
</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
<executions>
<execution>
<id>default</id>
<phase>test</phase>
<goals></goals>
</execution>
<execution>
<id>integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
<forkMode>pertest</forkMode>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Agora podemos rodar a classe de testes. Agora vamos fazer isso através do Maven por que o Maven já roda os testes para nos no seu ciclo de build. vamos fazer isso com o comando: mvn install e você vera algo semelhante a isso:
[INFO] Scanning for projects...
[INFO] ----------------------------------------------------------------------------
[INFO] Building Unnamed - Spring-DM-Simple-Bundle-Tester:Spring-DM-Simple-Bundle-Tester:jar:1.0.0
[INFO] task-segment: [install]
[INFO] ----------------------------------------------------------------------------
[INFO] resources:resources
[INFO] Using default encoding to copy filtered resources.
[WARN] Cannot find parent POM: Spring-DM-Simple-Bundle-Master:Spring-DM-Simple-Bundle-Master::1.0.0 for child: Spring-DM-Simple-Bundle:Spring-DM-Simple-Bundle:jar:1.0.0. Using stub model instead.
[WARN] Deprecated expression: ${artifactId} - missing prefix. Use ${pom.artifactId} (model: org.springframework.osgi:junit.osgi:bundle:3.8.2-SNAPSHOT)
[WARN] Deprecated expression: ${artifactId} - missing prefix. Use ${pom.artifactId} (model: org.springframework.osgi:asm.osgi:bundle:2.2.3-SNAPSHOT)
[WARN] Deprecated expression: ${artifactId} - missing prefix. Use ${pom.artifactId} (model: org.springframework.osgi:log4j.osgi:bundle:1.2.15-SNAPSHOT)
[WARN] Deprecated expression: ${artifactId} - missing prefix. Use ${pom.artifactId} (model: org.springframework.osgi:aopalliance.osgi:bundle:1.0-SNAPSHOT)
[INFO] snapshot org.springframework.osgi:asm.osgi:2.2.3-SNAPSHOT: checking for updates from eclipse-repository
[INFO] snapshot org.springframework.osgi:asm.osgi:2.2.3-SNAPSHOT: checking for updates from safehaus-repository
[INFO] snapshot org.springframework.osgi:asm.osgi:2.2.3-SNAPSHOT: checking for updates from spring-release
[INFO] snapshot org.springframework.osgi:asm.osgi:2.2.3-SNAPSHOT: checking for updates from spring-external
[INFO] snapshot org.springframework.osgi:asm.osgi:2.2.3-SNAPSHOT: checking for updates from spring-milestone
[INFO] compiler:compile
[INFO] No sources to compile
[INFO] resources:testResources
[INFO] Using default encoding to copy filtered resources.
[WARN] Deprecated expression: ${artifactId} - missing prefix. Use ${pom.artifactId} (model: org.springframework.osgi:log4j.osgi:bundle:1.2.15-SNAPSHOT)
[WARN] Deprecated expression: ${artifactId} - missing prefix. Use ${pom.artifactId} (model: org.springframework.osgi:junit.osgi:bundle:3.8.2-SNAPSHOT)
[WARN] Deprecated expression: ${artifactId} - missing prefix. Use ${pom.artifactId} (model: org.springframework.osgi:aopalliance.osgi:bundle:1.0-SNAPSHOT)
[INFO] snapshot org.springframework.osgi:asm.osgi:2.2.3-SNAPSHOT: checking for updates from eclipse-repository
[INFO] snapshot org.springframework.osgi:asm.osgi:2.2.3-SNAPSHOT: checking for updates from safehaus-repository
[INFO] snapshot org.springframework.osgi:asm.osgi:2.2.3-SNAPSHOT: checking for updates from spring-release
[INFO] snapshot org.springframework.osgi:asm.osgi:2.2.3-SNAPSHOT: checking for updates from spring-external
[INFO] snapshot org.springframework.osgi:asm.osgi:2.2.3-SNAPSHOT: checking for updates from spring-milestone
[INFO] compiler:testCompile
[INFO] Compiling 1 source file to D:\Diego\Info\Programacao\Java\eclipse\eclipse_workspace\Spring-DM-Bundle-Mater\Spring-DM-Simple-Bundle-Tester\target\test-classes
[WARN] Deprecated expression: ${artifactId} - missing prefix. Use ${pom.artifactId} (model: org.springframework.osgi:log4j.osgi:bundle:1.2.15-SNAPSHOT)
[WARN] Deprecated expression: ${artifactId} - missing prefix. Use ${pom.artifactId} (model: org.springframework.osgi:aopalliance.osgi:bundle:1.0-SNAPSHOT)
[INFO] snapshot org.springframework.osgi:asm.osgi:2.2.3-SNAPSHOT: checking for updates from eclipse-repository
[INFO] snapshot org.springframework.osgi:asm.osgi:2.2.3-SNAPSHOT: checking for updates from safehaus-repository
[INFO] snapshot org.springframework.osgi:asm.osgi:2.2.3-SNAPSHOT: checking for updates from spring-release
[INFO] snapshot org.springframework.osgi:asm.osgi:2.2.3-SNAPSHOT: checking for updates from spring-external
[INFO] snapshot org.springframework.osgi:asm.osgi:2.2.3-SNAPSHOT: checking for updates from spring-milestone
[INFO] surefire:test
[INFO] Tests are skipped.
[INFO] jar:jar
[INFO] Building jar: D:\Diego\Info\Programacao\Java\eclipse\eclipse_workspace\Spring-DM-Bundle-Mater\Spring-DM-Simple-Bundle-Tester\target\Spring-DM-Simple-Bundle-Tester-1.0.0.jar
[WARN] Deprecated expression: ${artifactId} - missing prefix. Use ${pom.artifactId} (model: org.springframework.osgi:log4j.osgi:bundle:1.2.15-SNAPSHOT)
[WARN] Deprecated expression: ${artifactId} - missing prefix. Use ${pom.artifactId} (model: org.springframework.osgi:aopalliance.osgi:bundle:1.0-SNAPSHOT)
[INFO] snapshot org.springframework.osgi:asm.osgi:2.2.3-SNAPSHOT: checking for updates from eclipse-repository
[INFO] snapshot org.springframework.osgi:asm.osgi:2.2.3-SNAPSHOT: checking for updates from safehaus-repository
[INFO] snapshot org.springframework.osgi:asm.osgi:2.2.3-SNAPSHOT: checking for updates from spring-release
[INFO] snapshot org.springframework.osgi:asm.osgi:2.2.3-SNAPSHOT: checking for updates from spring-external
[INFO] snapshot org.springframework.osgi:asm.osgi:2.2.3-SNAPSHOT: checking for updates from spring-milestone
[INFO] surefire:test
[INFO] Surefire report directory: D:\Diego\Info\Programacao\Java\eclipse\eclipse_workspace\Spring-DM-Bundle-Mater\Spring-DM-Simple-Bundle-Tester\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running org.diegopacheco.springdm.simplebundle.test.TesteIntegrado
main INFO [org.diegopacheco.springdm.simplebundle.test.TesteIntegrado] - Equinox OSGi Platform [3.2.2.R32x_v20070118] started
main INFO [org.springframework.osgi.test.provisioning.internal.LocalFileSystemMavenRepository] - local Maven2 repository used: [C:\Users\Diego Pacheco\.m2\repository]
main INFO [org.springframework.osgi.extender.internal.ContextLoaderListener] - Starting org.springframework.osgi.extender bundle v.[1.0.0]
main INFO [org.springframework.osgi.extender.internal.ContextLoaderListener] - disabled automatic Spring-DM annotation processing; [ org.springframework.osgi.extender.annotation.auto.processing=null]
main INFO [org.diegopacheco.springdm.simplebundle.test.TesteIntegrado] - org/diegopacheco/springdm/simplebundle/test/TesteIntegrado-bundle.properties was not found; using defaults
SpringOsgiExtenderThread-1 INFO [org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext] - Refreshing org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext@b754b2: display name [OsgiBundleXmlApplicationContext(bundle=org.diegopacheco.simple.bundle, config=osgibundle:/META-INF/spring/*.xml)]; startup date [Sat Feb 16 23:00:22 BRT 2008]; root of context hierarchy
main INFO [org.diegopacheco.springdm.simplebundle.test.TesteIntegrado] - automatically creating Manifest for the test bundle
SpringOsgiExtenderThread-1 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - Loading XML bean definitions from URL [bundleentry://18/META-INF/spring/spring-beans.xml]
SpringOsgiExtenderThread-1 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - Loading XML bean definitions from URL [bundleentry://18/META-INF/spring/spring-osgi-beans.xml]
SpringOsgiExtenderThread-1 INFO [org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext] - Bean factory for application context [org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext@b754b2]: org.springframework.beans.factory.support.DefaultListableBeanFactory@118278a
SpringOsgiExtenderThread-2 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@118278a: defining beans [dataServiceImpl,pkgAdminService,dataServiceOsgi]; root of factory hierarchy
SpringOsgiExtenderThread-2 INFO [org.springframework.osgi.service.exporter.support.OsgiServiceFactoryBean] - Publishing service under classes [{org.diegopacheco.springdm.simplebundle.service.DataService}]
SpringOsgiExtenderThread-2 INFO [org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext] - Publishing application context with properties (org.springframework.context.service.name=org.diegopacheco.simple.bundle)
main INFO [org.diegopacheco.springdm.simplebundle.test.TesteIntegrado] - Loading context for locations:
main INFO [org.springframework.osgi.test.AbstractOptionalDependencyInjectionTests$EmptyOsgiApplicationContext] - Refreshing org.springframework.osgi.test.AbstractOptionalDependencyInjectionTests$EmptyOsgiApplicationContext@e33e18: display name [AbstractOptionalDependencyInjectionTests.EmptyOsgiApplicationContext(bundle=TestBundle-testFull-org.diegopacheco.springdm.simplebundle.test.TesteIntegrado, config=)]; startup date [Sat Feb 16 23:00:22 BRT 2008]; root of context hierarchy
main INFO [org.springframework.osgi.test.AbstractOptionalDependencyInjectionTests$EmptyOsgiApplicationContext] - Bean factory for application context [org.springframework.osgi.test.AbstractOptionalDependencyInjectionTests$EmptyOsgiApplicationContext@e33e18]: org.springframework.beans.factory.support.DefaultListableBeanFactory@101ac93
main INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@101ac93: defining beans []; root of factory hierarchy
main INFO [org.springframework.osgi.test.AbstractOptionalDependencyInjectionTests$EmptyOsgiApplicationContext] - Publishing application context with properties (org.springframework.context.service.name=TestBundle-testFull-org.diegopacheco.springdm.simplebundle.test.TesteIntegrado)
BundleContext: org.eclipse.osgi.framework.internal.core.BundleContextImpl@76e8a7
DataService ref: {org.diegopacheco.springdm.simplebundle.service.DataService}={org.springframework.osgi.bean.name=dataServiceImpl, Bundle-SymbolicName=org.diegopacheco.simple.bundle, Bundle-Version=1.0, service.id=23}
DataService: org.diegopacheco.springdm.simplebundle.service.DataServiceImpl@682406
Data via Spring Osgi: 16/1/2008
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.264 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
Thread-0 INFO [org.diegopacheco.springdm.simplebundle.test.TesteIntegrado] - shutting down OSGi platform
Thread-0 INFO [org.springframework.osgi.extender.internal.ContextLoaderListener] - Stopping org.springframework.osgi.extender bundle
Thread-2 INFO [org.springframework.osgi.test.AbstractOptionalDependencyInjectionTests$EmptyOsgiApplicationContext] - Closing org.springframework.osgi.test.AbstractOptionalDependencyInjectionTests$EmptyOsgiApplicationContext@e33e18: display name [AbstractOptionalDependencyInjectionTests.EmptyOsgiApplicationContext(bundle=TestBundle-testFull-org.diegopacheco.springdm.simplebundle.test.TesteIntegrado, config=)]; startup date [Sat Feb 16 23:00:22 BRT 2008]; root of context hierarchy
Thread-2 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@101ac93: defining beans []; root of factory hierarchy
Thread-3 INFO [org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext] - Closing org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext@b754b2: display name [OsgiBundleXmlApplicationContext(bundle=org.diegopacheco.simple.bundle, config=osgibundle:/META-INF/spring/*.xml)]; startup date [Sat Feb 16 23:00:22 BRT 2008]; root of context hierarchy
Thread-3 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@118278a: defining beans [dataServiceImpl,pkgAdminService,dataServiceOsgi]; root of factory hierarchy
Thread-3 INFO [org.springframework.osgi.service.exporter.support.OsgiServiceFactoryBean] - Unregistered service [ServiceWrapper for {org.diegopacheco.springdm.simplebundle.service.DataService}={org.springframework.osgi.bean.name=dataServiceImpl, Bundle-SymbolicName=org.diegopacheco.simple.bundle, Bundle-Version=1.0, service.id=23}]
[INFO] install:install
[INFO] Installing D:\Diego\Info\Programacao\Java\eclipse\eclipse_workspace\Spring-DM-Bundle-Mater\Spring-DM-Simple-Bundle-Tester\target\Spring-DM-Simple-Bundle-Tester-1.0.0.jar to C:\Users\Diego Pacheco\.m2\repository\Spring-DM-Simple-Bundle-Tester\Spring-DM-Simple-Bundle-Tester\1.0.0\Spring-DM-Simple-Bundle-Tester-1.0.0.jar
[INFO] ----------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL Spring-DM-Simple-Bundle-Tester:Spring-DM-Simple-Bundle-Tester:jar:1.0.0 ( task-segment: [install] )
[INFO] ----------------------------------------------------------------------------
[INFO] Total time: 19 second
[INFO] Finished at: Sat Feb 16 23:00:23 BRT 2008
[INFO] Memory 16M/47M
[INFO] ----------------------------------------------------------------------------
Como podemos ver funcionou. Até a proxima pessoal.
Agora vamos ver um exemplo simples de Spring DM com Maven2, maven é um framework da apache para facilitar a gerencia de configurações e ciclo de build de um projeto. Foi escolhido por que facilita os meus testes com Osgi e além disso o Spring DM possui facilidades para usuario do Maven2 que é o meu caso. :)
Vamos criar dois projetos, eu fiz com o eclipse ide porem poderia ser com qualquer ide, eu utilizei o plugin Archetype do maven para criar a estrutura básica do POM e o projeto do eclipse.
São dois projetos:
- Spring-DM-Simple-Bundle
- Spring-DM-Simple-Bundle-Tester
Projeto Spring-DM-Simple-Bundle:
Crie o package: org.diegopacheco.springdm.simplebundle.service você deve criar esse package na estrutura padrão do maven para fontes java que é: src/main/java. Dentro desse pacote vamos ter dois artefatos são eles:
- DataService
- DataServiceImpl
DataServicepackage org.diegopacheco.springdm.simplebundle.service;
public interface DataService {
public String getCurrentTime();
}
DataServiceImpl
package org.diegopacheco.springdm.simplebundle.service;
import java.util.Calendar;
public class DataServiceImpl implements DataService{
@Override
public String getCurrentTime() {
Calendar cal = Calendar.getInstance();
return cal.get(Calendar.DAY_OF_MONTH) + "/" +
cal.get(Calendar.MONTH) + "/" +
cal.get(Calendar.YEAR);
}
}
Dentro da estrutura padrão do maven para arquivos de configurações que é src/main/resources crie a pasta: META-INF e crie o artefato MANIFEST.MF com o seguinte conteudo:
Bundle-Version: 1.0
Bundle-Name: SpringDM-Simple-Bundle
Bundle-SymbolicName: org.diegopacheco.simple.bundle
Bundle-Vendor: Diego Pacheco
Export-Package: org.diegopacheco.springdm.simplebundle.service
Bundle-ManifestVersion: 2
ainda no path /src/main/resources/META-INF crie a pasta spring e adicione dois arquivos:
- spring-beans.xml
- spring-osgi-beans.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:osgi="http://www.springframework.org/schema/osgi"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/osgi
http://www.springframework.org/schema/osgi/spring-osgi.xsd"
>
<bean
id="dataServiceImpl"
class="org.diegopacheco.springdm.simplebundle.service.DataServiceImpl"
/>
</beans>
O legal do Spring Osgi é que ele faz discovery automático de qualquer xml de beans do Spring. Agora o arquivo spring-osgi-beans.xml contem os beans osgi. Segue o arquivo:
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/osgi"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/osgi
http://www.springframework.org/schema/osgi/spring-osgi.xsd"
>
<reference
id="pkgAdminService"
interface="org.osgi.service.packageadmin.PackageAdmin"
/>
<service
id="dataServiceOsgi"
ref="dataServiceImpl"
auto-export="interfaces"
/>
</beans:beans>
Aqui estamos registrando o bean pkgAdminService que é um bean do Osgi que tem seu próprio Bundle, isso mesmo um Bundle de gerenciamento de Bundles.
Também encontramos a exportação do nosso serviço de datas onde informamos o id-osgi e no atributo ref fazemos a referencia ao bean do Spring DataServiceImpl. Na propriedade auto-export definimos a estrategista de como vamos exportar o recurso do nosso serviço de datas.
Por ultimo mas não menos importante vem o POM.XML:
<project>
<parent>
<artifactId>Spring-DM-Simple-Bundle-Master</artifactId>
<groupId>Spring-DM-Simple-Bundle-Master</groupId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>Spring-DM-Simple-Bundle</groupId>
<artifactId>Spring-DM-Simple-Bundle</artifactId>
<packaging>jar</packaging>
<version>1.0.0</version>
<description>Teste de um Bunde SpringDM simples.</description>
<url>http://maven.apache.org</url>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestFile>
src/main/resources/META-INF/MANIFEST.MF
</manifestFile>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
Agora você deve instalar esse Bundle no seu repositório local do Maven podemos fazer isso através do comando: mvn install ao rodar esse comando vamos ter um log semelhante a esse:
[INFO] Scanning for projects...
[INFO] ----------------------------------------------------------------------------
[INFO] Building Unnamed - Spring-DM-Simple-Bundle:Spring-DM-Simple-Bundle:jar:1.0.0
[INFO] task-segment: [install]
[INFO] ----------------------------------------------------------------------------
[INFO] resources:resources
[INFO] Using default encoding to copy filtered resources.
[INFO] compiler:compile
[INFO] Nothing to compile - all classes are up to date
[INFO] resources:testResources
[INFO] Using default encoding to copy filtered resources.
[INFO] compiler:testCompile
[INFO] No sources to compile
[INFO] surefire:test
[INFO] No tests to run.
[INFO] jar:jar
[INFO] Building jar: D:\Diego\Info\Programacao\Java\eclipse\eclipse_workspace\Spring-DM-Bundle-Mater\Spring-DM-Simple-Bundle\target\Spring-DM-Simple-Bundle-1.0.0.jar
[INFO] install:install
[INFO] Installing D:\Diego\Info\Programacao\Java\eclipse\eclipse_workspace\Spring-DM-Bundle-Mater\Spring-DM-Simple-Bundle\target\Spring-DM-Simple-Bundle-1.0.0.jar to C:\Users\Diego Pacheco\.m2\repository\Spring-DM-Simple-Bundle\Spring-DM-Simple-Bundle\1.0.0\Spring-DM-Simple-Bundle-1.0.0.jar
[INFO] ----------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL Spring-DM-Simple-Bundle:Spring-DM-Simple-Bundle:jar:1.0.0 ( task-segment: [install] )
[INFO] ----------------------------------------------------------------------------
[INFO] Total time: 3 second
[INFO] Finished at: Sat Feb 16 23:32:34 BRST 2008
[INFO] Memory 2M/10M
[INFO] ----------------------------------------------------------------------------
Agora vamos ao outro projeto o Spring-DM-Simple-Bundle-Tester. Nesse projeto no path src/main/test vamos criar o package: org.diegopacheco.springdm.simplebundle.test nesse package o artefato: TesteIntegrado.java
package org.diegopacheco.springdm.simplebundle.test;
import org.diegopacheco.springdm.simplebundle.service.DataService;
import org.osgi.framework.ServiceReference;
import org.springframework.osgi.test.AbstractConfigurableBundleCreatorTests;
public class TesteIntegrado extends AbstractConfigurableBundleCreatorTests {
public void testFull() throws Exception {
System.out.println("BundleContext: " + bundleContext);
ServiceReference ref = bundleContext.getServiceReference("org.diegopacheco.springdm.simplebundle.service.DataService");
System.out.println("DataService ref: " + ref);
DataService ds = (DataService)bundleContext.getService(ref);
System.out.println("DataService: " + ds);
System.out.println("Data via Spring Osgi: " + ds.getCurrentTime());
}
protected String[] getTestBundlesNames() {
return new String[] { "Spring-DM-Simple-Bundle," +
"Spring-DM-Simple-Bundle," +
"1.0.0"};
}
}
Essa classe de testes estende a classe do Spring DM AbstractConfigurableBundleCreatorTests que prove facilidades para subir a plataforma Osgi.
O método getTestBundlesNames() serve para nos informarmos na ordem: artfactId,groupId e version do jar que o maven gerou no nosso repositório local.
através da variável de instância bundleContext nos acessamos o contexto do Osgi e através do metodo getServiceReference("id_bundle") recuperamos um bundle(modulo osgi). Esse metodo irá retornar um objeto do tipo ServiceReference que representa o nosso service do Spring agora podemos fazer: bundleContext.getService(serviceReference) para obter o serviço de fato. Após isso usamos de forma normal.
No path src/main/resources crie o arquivo log4j.properties com o conteúdo a baixo:
log4j.rootCategory=info, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout.ConversionPattern=%t %p [%c] - %m%n
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.threshold=TRACE
log4j.logger.org.springframework=INFO
log4j.logger.org.springframework.osgi.test=INFO
Crie também o package: org.diegopacheco.springdm.simplebundle.test e dentro o arquivo MANIFEST.MF com o seguinte conteudo:
Manifest-Version: 1.0
Bundle-Name: SpringDM-Simple-Bundle-Tester
Bundle-SymbolicName: org.diegopacheco.simple.bundle.tester
Bundle-Vendor: Diego Pacheco
Bundle-Activator: org.springframework.osgi.test.JUnitTestActivator
Import-Package: junit.framework,
org.osgi.framework;specification-version="1.3.0",
org.springframework.core.io,
org.springframework.osgi.test,
org.springframework.osgi.samples.simpleservice
Por ultimo mas não menos importante o POM.xml desse projeto:
<project>
<parent>
<artifactId>Spring-DM-Simple-Bundle-Master</artifactId>
<groupId>Spring-DM-Simple-Bundle-Master</groupId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>Spring-DM-Simple-Bundle-Tester</groupId>
<artifactId>Spring-DM-Simple-Bundle-Tester</artifactId>
<packaging>jar</packaging>
<version>1.0.0</version>
<description>
aplicao de teste para o Spring-DM-Simple-Bundle uasndo o
mecanismo osgi do Spring dm
</description>
<dependencies>
<!-- Dependencia para o outro projeto que eu fiz o Spring-DM-Simple-Bundle
Rodar anteso mvn package -->
<dependency>
<groupId>Spring-DM-Simple-Bundle</groupId>
<artifactId>Spring-DM-Simple-Bundle</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.springframework.osgi</groupId>
<artifactId>spring-osgi-core</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.springframework.osgi</groupId>
<artifactId>spring-osgi-test</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.springframework.osgi</groupId>
<artifactId>spring-osgi-annotation</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl104-over-slf4j</artifactId>
<version>1.4.3</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.4.3</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.4.3</version>
<exclusions>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.osgi</groupId>
<artifactId>log4j.osgi</artifactId>
<version>1.2.15-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.osgi</groupId>
<artifactId>junit.osgi</artifactId>
<version>3.8.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.osgi</groupId>
<artifactId>aopalliance.osgi</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.eclipse.osgi</groupId>
<artifactId>org.eclipse.osgi</artifactId>
<version>3.2.2</version>
<type>jar</type>
</dependency>
</dependencies>
<repositories>
<repository>
<id>central</id>
<url>http://localhost:8080/artifactory/repo</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>snapshots</id>
<url>http://localhost:8080/artifactory/repo</url>
<releases>
<enabled>false</enabled>
</releases>
</repository>
<repository>
<id>spring-ext</id>
<name>Spring External Dependencies Repository</name>
<url>
http://springframework.svn.sourceforge.net/svnroot/springframework/repos/repo-ext/
</url>
</repository>
<repository>
<id>spring-osgi-artifacts</id>
<name>Spring Portfolio OSGi Artifacts Repository</name>
<snapshots>
<enabled>true</enabled>
</snapshots>
<url>
http://s3.amazonaws.com/maven.springframework.org/osgi
</url>
</repository>
</repositories>
<build>
<resources>
<resource>
<targetPath>
../org/diegopacheco/springdm/simplebundle/test
</targetPath>
<filtering>true</filtering>
<includes>
<include>MANIFEST.MF</include>
</includes>
<directory>
src/test/java/org/diegopacheco/springdm/simplebundle/test
</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
<executions>
<execution>
<id>default</id>
<phase>test</phase>
<goals></goals>
</execution>
<execution>
<id>integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
<forkMode>pertest</forkMode>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
[INFO] Scanning for projects...
[INFO] ----------------------------------------------------------------------------
[INFO] Building Unnamed - Spring-DM-Simple-Bundle-Tester:Spring-DM-Simple-Bundle-Tester:jar:1.0.0
[INFO] task-segment: [install]
[INFO] ----------------------------------------------------------------------------
[INFO] resources:resources
[INFO] Using default encoding to copy filtered resources.
[WARN] Cannot find parent POM: Spring-DM-Simple-Bundle-Master:Spring-DM-Simple-Bundle-Master::1.0.0 for child: Spring-DM-Simple-Bundle:Spring-DM-Simple-Bundle:jar:1.0.0. Using stub model instead.
[WARN] Deprecated expression: ${artifactId} - missing prefix. Use ${pom.artifactId} (model: org.springframework.osgi:junit.osgi:bundle:3.8.2-SNAPSHOT)
[WARN] Deprecated expression: ${artifactId} - missing prefix. Use ${pom.artifactId} (model: org.springframework.osgi:asm.osgi:bundle:2.2.3-SNAPSHOT)
[WARN] Deprecated expression: ${artifactId} - missing prefix. Use ${pom.artifactId} (model: org.springframework.osgi:log4j.osgi:bundle:1.2.15-SNAPSHOT)
[WARN] Deprecated expression: ${artifactId} - missing prefix. Use ${pom.artifactId} (model: org.springframework.osgi:aopalliance.osgi:bundle:1.0-SNAPSHOT)
[INFO] snapshot org.springframework.osgi:asm.osgi:2.2.3-SNAPSHOT: checking for updates from eclipse-repository
[INFO] snapshot org.springframework.osgi:asm.osgi:2.2.3-SNAPSHOT: checking for updates from safehaus-repository
[INFO] snapshot org.springframework.osgi:asm.osgi:2.2.3-SNAPSHOT: checking for updates from spring-release
[INFO] snapshot org.springframework.osgi:asm.osgi:2.2.3-SNAPSHOT: checking for updates from spring-external
[INFO] snapshot org.springframework.osgi:asm.osgi:2.2.3-SNAPSHOT: checking for updates from spring-milestone
[INFO] compiler:compile
[INFO] No sources to compile
[INFO] resources:testResources
[INFO] Using default encoding to copy filtered resources.
[WARN] Deprecated expression: ${artifactId} - missing prefix. Use ${pom.artifactId} (model: org.springframework.osgi:log4j.osgi:bundle:1.2.15-SNAPSHOT)
[WARN] Deprecated expression: ${artifactId} - missing prefix. Use ${pom.artifactId} (model: org.springframework.osgi:junit.osgi:bundle:3.8.2-SNAPSHOT)
[WARN] Deprecated expression: ${artifactId} - missing prefix. Use ${pom.artifactId} (model: org.springframework.osgi:aopalliance.osgi:bundle:1.0-SNAPSHOT)
[INFO] snapshot org.springframework.osgi:asm.osgi:2.2.3-SNAPSHOT: checking for updates from eclipse-repository
[INFO] snapshot org.springframework.osgi:asm.osgi:2.2.3-SNAPSHOT: checking for updates from safehaus-repository
[INFO] snapshot org.springframework.osgi:asm.osgi:2.2.3-SNAPSHOT: checking for updates from spring-release
[INFO] snapshot org.springframework.osgi:asm.osgi:2.2.3-SNAPSHOT: checking for updates from spring-external
[INFO] snapshot org.springframework.osgi:asm.osgi:2.2.3-SNAPSHOT: checking for updates from spring-milestone
[INFO] compiler:testCompile
[INFO] Compiling 1 source file to D:\Diego\Info\Programacao\Java\eclipse\eclipse_workspace\Spring-DM-Bundle-Mater\Spring-DM-Simple-Bundle-Tester\target\test-classes
[WARN] Deprecated expression: ${artifactId} - missing prefix. Use ${pom.artifactId} (model: org.springframework.osgi:log4j.osgi:bundle:1.2.15-SNAPSHOT)
[WARN] Deprecated expression: ${artifactId} - missing prefix. Use ${pom.artifactId} (model: org.springframework.osgi:aopalliance.osgi:bundle:1.0-SNAPSHOT)
[INFO] snapshot org.springframework.osgi:asm.osgi:2.2.3-SNAPSHOT: checking for updates from eclipse-repository
[INFO] snapshot org.springframework.osgi:asm.osgi:2.2.3-SNAPSHOT: checking for updates from safehaus-repository
[INFO] snapshot org.springframework.osgi:asm.osgi:2.2.3-SNAPSHOT: checking for updates from spring-release
[INFO] snapshot org.springframework.osgi:asm.osgi:2.2.3-SNAPSHOT: checking for updates from spring-external
[INFO] snapshot org.springframework.osgi:asm.osgi:2.2.3-SNAPSHOT: checking for updates from spring-milestone
[INFO] surefire:test
[INFO] Tests are skipped.
[INFO] jar:jar
[INFO] Building jar: D:\Diego\Info\Programacao\Java\eclipse\eclipse_workspace\Spring-DM-Bundle-Mater\Spring-DM-Simple-Bundle-Tester\target\Spring-DM-Simple-Bundle-Tester-1.0.0.jar
[WARN] Deprecated expression: ${artifactId} - missing prefix. Use ${pom.artifactId} (model: org.springframework.osgi:log4j.osgi:bundle:1.2.15-SNAPSHOT)
[WARN] Deprecated expression: ${artifactId} - missing prefix. Use ${pom.artifactId} (model: org.springframework.osgi:aopalliance.osgi:bundle:1.0-SNAPSHOT)
[INFO] snapshot org.springframework.osgi:asm.osgi:2.2.3-SNAPSHOT: checking for updates from eclipse-repository
[INFO] snapshot org.springframework.osgi:asm.osgi:2.2.3-SNAPSHOT: checking for updates from safehaus-repository
[INFO] snapshot org.springframework.osgi:asm.osgi:2.2.3-SNAPSHOT: checking for updates from spring-release
[INFO] snapshot org.springframework.osgi:asm.osgi:2.2.3-SNAPSHOT: checking for updates from spring-external
[INFO] snapshot org.springframework.osgi:asm.osgi:2.2.3-SNAPSHOT: checking for updates from spring-milestone
[INFO] surefire:test
[INFO] Surefire report directory: D:\Diego\Info\Programacao\Java\eclipse\eclipse_workspace\Spring-DM-Bundle-Mater\Spring-DM-Simple-Bundle-Tester\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running org.diegopacheco.springdm.simplebundle.test.TesteIntegrado
main INFO [org.diegopacheco.springdm.simplebundle.test.TesteIntegrado] - Equinox OSGi Platform [3.2.2.R32x_v20070118] started
main INFO [org.springframework.osgi.test.provisioning.internal.LocalFileSystemMavenRepository] - local Maven2 repository used: [C:\Users\Diego Pacheco\.m2\repository]
main INFO [org.springframework.osgi.extender.internal.ContextLoaderListener] - Starting org.springframework.osgi.extender bundle v.[1.0.0]
main INFO [org.springframework.osgi.extender.internal.ContextLoaderListener] - disabled automatic Spring-DM annotation processing; [ org.springframework.osgi.extender.annotation.auto.processing=null]
main INFO [org.diegopacheco.springdm.simplebundle.test.TesteIntegrado] - org/diegopacheco/springdm/simplebundle/test/TesteIntegrado-bundle.properties was not found; using defaults
SpringOsgiExtenderThread-1 INFO [org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext] - Refreshing org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext@b754b2: display name [OsgiBundleXmlApplicationContext(bundle=org.diegopacheco.simple.bundle, config=osgibundle:/META-INF/spring/*.xml)]; startup date [Sat Feb 16 23:00:22 BRT 2008]; root of context hierarchy
main INFO [org.diegopacheco.springdm.simplebundle.test.TesteIntegrado] - automatically creating Manifest for the test bundle
SpringOsgiExtenderThread-1 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - Loading XML bean definitions from URL [bundleentry://18/META-INF/spring/spring-beans.xml]
SpringOsgiExtenderThread-1 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - Loading XML bean definitions from URL [bundleentry://18/META-INF/spring/spring-osgi-beans.xml]
SpringOsgiExtenderThread-1 INFO [org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext] - Bean factory for application context [org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext@b754b2]: org.springframework.beans.factory.support.DefaultListableBeanFactory@118278a
SpringOsgiExtenderThread-2 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@118278a: defining beans [dataServiceImpl,pkgAdminService,dataServiceOsgi]; root of factory hierarchy
SpringOsgiExtenderThread-2 INFO [org.springframework.osgi.service.exporter.support.OsgiServiceFactoryBean] - Publishing service under classes [{org.diegopacheco.springdm.simplebundle.service.DataService}]
SpringOsgiExtenderThread-2 INFO [org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext] - Publishing application context with properties (org.springframework.context.service.name=org.diegopacheco.simple.bundle)
main INFO [org.diegopacheco.springdm.simplebundle.test.TesteIntegrado] - Loading context for locations:
main INFO [org.springframework.osgi.test.AbstractOptionalDependencyInjectionTests$EmptyOsgiApplicationContext] - Refreshing org.springframework.osgi.test.AbstractOptionalDependencyInjectionTests$EmptyOsgiApplicationContext@e33e18: display name [AbstractOptionalDependencyInjectionTests.EmptyOsgiApplicationContext(bundle=TestBundle-testFull-org.diegopacheco.springdm.simplebundle.test.TesteIntegrado, config=)]; startup date [Sat Feb 16 23:00:22 BRT 2008]; root of context hierarchy
main INFO [org.springframework.osgi.test.AbstractOptionalDependencyInjectionTests$EmptyOsgiApplicationContext] - Bean factory for application context [org.springframework.osgi.test.AbstractOptionalDependencyInjectionTests$EmptyOsgiApplicationContext@e33e18]: org.springframework.beans.factory.support.DefaultListableBeanFactory@101ac93
main INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@101ac93: defining beans []; root of factory hierarchy
main INFO [org.springframework.osgi.test.AbstractOptionalDependencyInjectionTests$EmptyOsgiApplicationContext] - Publishing application context with properties (org.springframework.context.service.name=TestBundle-testFull-org.diegopacheco.springdm.simplebundle.test.TesteIntegrado)
BundleContext: org.eclipse.osgi.framework.internal.core.BundleContextImpl@76e8a7
DataService ref: {org.diegopacheco.springdm.simplebundle.service.DataService}={org.springframework.osgi.bean.name=dataServiceImpl, Bundle-SymbolicName=org.diegopacheco.simple.bundle, Bundle-Version=1.0, service.id=23}
DataService: org.diegopacheco.springdm.simplebundle.service.DataServiceImpl@682406
Data via Spring Osgi: 16/1/2008
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.264 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
Thread-0 INFO [org.diegopacheco.springdm.simplebundle.test.TesteIntegrado] - shutting down OSGi platform
Thread-0 INFO [org.springframework.osgi.extender.internal.ContextLoaderListener] - Stopping org.springframework.osgi.extender bundle
Thread-2 INFO [org.springframework.osgi.test.AbstractOptionalDependencyInjectionTests$EmptyOsgiApplicationContext] - Closing org.springframework.osgi.test.AbstractOptionalDependencyInjectionTests$EmptyOsgiApplicationContext@e33e18: display name [AbstractOptionalDependencyInjectionTests.EmptyOsgiApplicationContext(bundle=TestBundle-testFull-org.diegopacheco.springdm.simplebundle.test.TesteIntegrado, config=)]; startup date [Sat Feb 16 23:00:22 BRT 2008]; root of context hierarchy
Thread-2 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@101ac93: defining beans []; root of factory hierarchy
Thread-3 INFO [org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext] - Closing org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext@b754b2: display name [OsgiBundleXmlApplicationContext(bundle=org.diegopacheco.simple.bundle, config=osgibundle:/META-INF/spring/*.xml)]; startup date [Sat Feb 16 23:00:22 BRT 2008]; root of context hierarchy
Thread-3 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@118278a: defining beans [dataServiceImpl,pkgAdminService,dataServiceOsgi]; root of factory hierarchy
Thread-3 INFO [org.springframework.osgi.service.exporter.support.OsgiServiceFactoryBean] - Unregistered service [ServiceWrapper for {org.diegopacheco.springdm.simplebundle.service.DataService}={org.springframework.osgi.bean.name=dataServiceImpl, Bundle-SymbolicName=org.diegopacheco.simple.bundle, Bundle-Version=1.0, service.id=23}]
[INFO] install:install
[INFO] Installing D:\Diego\Info\Programacao\Java\eclipse\eclipse_workspace\Spring-DM-Bundle-Mater\Spring-DM-Simple-Bundle-Tester\target\Spring-DM-Simple-Bundle-Tester-1.0.0.jar to C:\Users\Diego Pacheco\.m2\repository\Spring-DM-Simple-Bundle-Tester\Spring-DM-Simple-Bundle-Tester\1.0.0\Spring-DM-Simple-Bundle-Tester-1.0.0.jar
[INFO] ----------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL Spring-DM-Simple-Bundle-Tester:Spring-DM-Simple-Bundle-Tester:jar:1.0.0 ( task-segment: [install] )
[INFO] ----------------------------------------------------------------------------
[INFO] Total time: 19 second
[INFO] Finished at: Sat Feb 16 23:00:23 BRT 2008
[INFO] Memory 16M/47M
[INFO] ----------------------------------------------------------------------------
Como podemos ver funcionou. Até a proxima pessoal.