new manipulator structure - deleting the iPOJO BND ipojo plugin
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1209859 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/bnd-ipojo-plugin/.classpath b/ipojo/bnd-ipojo-plugin/.classpath
deleted file mode 100644
index f9479ba..0000000
--- a/ipojo/bnd-ipojo-plugin/.classpath
+++ /dev/null
@@ -1,7 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="src" output="target/classes" path="src/main/java"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
- <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
- <classpathentry kind="output" path="target/classes"/>
-</classpath>
diff --git a/ipojo/bnd-ipojo-plugin/.project b/ipojo/bnd-ipojo-plugin/.project
deleted file mode 100644
index f064da4..0000000
--- a/ipojo/bnd-ipojo-plugin/.project
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>bnd-ipojo-plugin</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.m2e.core.maven2Builder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.jdt.core.javanature</nature>
- <nature>org.eclipse.m2e.core.maven2Nature</nature>
- </natures>
-</projectDescription>
diff --git a/ipojo/bnd-ipojo-plugin/.settings/org.eclipse.jdt.core.prefs b/ipojo/bnd-ipojo-plugin/.settings/org.eclipse.jdt.core.prefs
deleted file mode 100644
index b12d728..0000000
--- a/ipojo/bnd-ipojo-plugin/.settings/org.eclipse.jdt.core.prefs
+++ /dev/null
@@ -1,6 +0,0 @@
-#Sat Aug 20 14:54:18 CEST 2011
-eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
-org.eclipse.jdt.core.compiler.compliance=1.5
-org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
-org.eclipse.jdt.core.compiler.source=1.5
diff --git a/ipojo/bnd-ipojo-plugin/.settings/org.eclipse.m2e.core.prefs b/ipojo/bnd-ipojo-plugin/.settings/org.eclipse.m2e.core.prefs
deleted file mode 100644
index 7fe79be..0000000
--- a/ipojo/bnd-ipojo-plugin/.settings/org.eclipse.m2e.core.prefs
+++ /dev/null
@@ -1,5 +0,0 @@
-#Sat Aug 20 14:54:08 CEST 2011
-activeProfiles=
-eclipse.preferences.version=1
-resolveWorkspaceProjects=true
-version=1
diff --git a/ipojo/bnd-ipojo-plugin/pom.xml b/ipojo/bnd-ipojo-plugin/pom.xml
deleted file mode 100644
index 0473175..0000000
--- a/ipojo/bnd-ipojo-plugin/pom.xml
+++ /dev/null
@@ -1,72 +0,0 @@
-<?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/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.felix</groupId>
- <artifactId>felix-parent</artifactId>
- <version>1.2.1</version>
- <relativePath>../../pom/pom.xml</relativePath>
- </parent>
-
- <artifactId>bnd-ipojo-plugin</artifactId>
- <version>1.0.0-SNAPSHOT</version>
- <name>Apache Felix iPOJO Bnd Plugin</name>
-
- <dependencies>
- <dependency>
- <groupId>biz.aQute</groupId>
- <artifactId>bndlib</artifactId>
- <version>1.43.0</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.ipojo.manipulator</artifactId>
- <version>1.9.0-SNAPSHOT</version>
- </dependency>
- <dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.ipojo.annotations</artifactId>
- <version>1.8.0</version>
- </dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-all</artifactId>
- <version>1.8.5</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>1.5</source>
- <target>1.5</target>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
-</project>
\ No newline at end of file
diff --git a/ipojo/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/BndJarResourceStore.java b/ipojo/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/BndJarResourceStore.java
deleted file mode 100644
index 24e1305..0000000
--- a/ipojo/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/BndJarResourceStore.java
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * 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.
- */
-package org.apache.felix.ipojo.bnd;
-
-import aQute.lib.osgi.Analyzer;
-import aQute.lib.osgi.Clazz;
-import aQute.lib.osgi.Jar;
-import aQute.lib.osgi.Resource;
-import aQute.libg.reporter.Reporter;
-import org.apache.felix.ipojo.annotations.Component;
-import org.apache.felix.ipojo.annotations.Handler;
-import org.apache.felix.ipojo.manipulator.Pojoization;
-import org.apache.felix.ipojo.manipulator.ResourceStore;
-import org.apache.felix.ipojo.manipulator.ResourceVisitor;
-import org.apache.felix.ipojo.manipulator.render.MetadataRenderer;
-import org.apache.felix.ipojo.manipulator.util.Metadatas;
-import org.apache.felix.ipojo.manipulator.util.Streams;
-import org.apache.felix.ipojo.metadata.Element;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.*;
-
-public class BndJarResourceStore implements ResourceStore {
-
- private Analyzer m_analyzer;
- private Reporter m_reporter;
-
- private MetadataRenderer m_renderer = new MetadataRenderer();
-
- private List<Element> m_metadata;
-
- public BndJarResourceStore(Analyzer analyzer, Reporter reporter) {
- m_metadata = new ArrayList<Element>();
- m_analyzer = analyzer;
- m_reporter = reporter;
- }
-
- public byte[] read(String path) throws IOException {
- Resource resource = m_analyzer.getJar().getResource(path);
- InputStream is = null;
- try {
- is = resource.openInputStream();
- } catch (Exception e) {
- throw new IOException("Cannot read " + path);
- }
- return Streams.readBytes(is);
- }
-
- public void accept(ResourceVisitor visitor) {
-
- try {
- // Only visit classes annotated with @Component or @Handler
- String annotations = Component.class.getName() + "|" + Handler.class.getName();
-
- Collection<Clazz> classes = m_analyzer.getClasses("",
- Clazz.QUERY.ANNOTATION.name(), annotations,
- Clazz.QUERY.NAMED.name(), "*");
-
- // Iterates over discovered resources
- for (Clazz clazz : classes) {
- visitor.visit(clazz.getPath());
- }
- } catch (Exception e) {
- m_reporter.error("Cannot find iPOJO annotated types: " + e.getMessage());
- }
- }
-
- public void open() throws IOException {
- // nothing to do
- }
-
- public void writeMetadata(Element metadata) {
- m_metadata.add(metadata);
-
- // Find referred packages and add them into Bnd
- for (String referred : Metadatas.findReferredPackages(metadata)) {
- if (m_analyzer.getReferred().get(referred) == null) {
- // The given package is not referred ATM
- m_analyzer.getReferred().put(referred, new HashMap<String, String>());
- }
- }
-
- // IPOJO-Components will be written during the close method.
- }
-
- public void write(String resourcePath, byte[] resource) throws IOException {
- Jar jar = m_analyzer.getJar();
- jar.putResource(resourcePath, new ByteArrayResource(resource));
- }
-
- public void close() throws IOException {
- // Write the iPOJO header (including manipulation metadata)
- StringBuilder builder = new StringBuilder();
- for (Element metadata : m_metadata) {
- builder.append(m_renderer.render(metadata));
- }
-
- if (builder.length() != 0) {
- m_analyzer.setProperty("IPOJO-Components", builder.toString());
- }
-
- // Add some mandatory imported packages
- Map<String, String> version = new TreeMap<String, String>();
- version.put("version", Pojoization.IPOJO_PACKAGE_VERSION);
-
- if (m_analyzer.getReferred().get("org.apache.felix.ipojo") == null) {
- m_analyzer.getReferred().put("org.apache.felix.ipojo", version);
- }
- if (m_analyzer.getReferred().get("org.apache.felix.ipojo.architecture") == null) {
- m_analyzer.getReferred().put("org.apache.felix.ipojo.architecture", version);
- }
- if (m_analyzer.getReferred().get("org.osgi.service.cm") == null) {
- Map<String, String> cm = new TreeMap<String, String>();
- cm.put("version", "1.2");
- m_analyzer.getReferred().put("org.osgi.service.cm", cm);
- }
- if (m_analyzer.getReferred().get("org.osgi.service.log") == null) {
- Map<String, String> log = new TreeMap<String, String>();
- log.put("version", "1.3");
- m_analyzer.getReferred().put("org.osgi.service.log", log);
- }
-
-
- }
-}
diff --git a/ipojo/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/BndReporter.java b/ipojo/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/BndReporter.java
deleted file mode 100644
index 8625853..0000000
--- a/ipojo/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/BndReporter.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * 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.
- */
-
-package org.apache.felix.ipojo.bnd;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import aQute.libg.reporter.Reporter;
-import org.apache.felix.ipojo.manipulator.reporter.EmptyReporter;
-
-/**
- * A {@code BndReporter} knows how to wrap a Bnd Reporter into an iPOJO Reporter.
- *
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-public class BndReporter extends EmptyReporter {
-
- /**
- * Bnd reporter.
- */
- private Reporter m_reporter;
-
- /**
- * Errors which occur during the manipulation.
- */
- private List<String> m_errors = new ArrayList<String>();
-
- /**
- * Warnings which occur during the manipulation.
- */
- private List<String> m_warnings = new ArrayList<String>();
-
- public BndReporter(aQute.libg.reporter.Reporter reporter) {
- m_reporter = reporter;
- }
-
- public List<String> getErrors() {
- return m_errors;
- }
-
- public List<String> getWarnings() {
- return m_warnings;
- }
-
- @Override
- public void trace(String message, Object... args) {
- m_reporter.trace(message, args);
- }
-
- @Override
- public void info(String message, Object... args) {
- m_reporter.progress(message, args);
- }
-
- @Override
- public void warn(String message, Object... args) {
- m_reporter.warning(message, args);
- m_warnings.add(String.format(message, args));
- }
-
- @Override
- public void error(String message, Object... args) {
- m_reporter.error(message, args);
- m_errors.add(String.format(message, args));
- }
-}
diff --git a/ipojo/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/ByteArrayResource.java b/ipojo/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/ByteArrayResource.java
deleted file mode 100644
index d97bc39..0000000
--- a/ipojo/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/ByteArrayResource.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * 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.
- */
-package org.apache.felix.ipojo.bnd;
-
-import aQute.lib.osgi.AbstractResource;
-
-/**
- * A {@code ByteArrayResource} is ...
- *
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-public class ByteArrayResource extends AbstractResource {
-
- private byte[] m_content;
-
- public ByteArrayResource(byte[] content) {
- super(System.currentTimeMillis());
- m_content = content;
- }
-
- @Override
- protected byte[] getBytes() throws Exception {
- return m_content;
- }
-}
diff --git a/ipojo/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/PojoizationPlugin.java b/ipojo/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/PojoizationPlugin.java
deleted file mode 100644
index ed359c6..0000000
--- a/ipojo/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/PojoizationPlugin.java
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * 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.
- */
-package org.apache.felix.ipojo.bnd;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import aQute.bnd.service.AnalyzerPlugin;
-import aQute.bnd.service.Plugin;
-import aQute.lib.osgi.Analyzer;
-import aQute.lib.osgi.Resource;
-import aQute.libg.reporter.Reporter;
-import org.apache.felix.ipojo.manipulator.ManipulationVisitor;
-import org.apache.felix.ipojo.manipulator.Pojoization;
-import org.apache.felix.ipojo.manipulator.ResourceStore;
-import org.apache.felix.ipojo.manipulator.metadata.AnnotationMetadataProvider;
-import org.apache.felix.ipojo.manipulator.metadata.CacheableMetadataProvider;
-import org.apache.felix.ipojo.manipulator.metadata.CompositeMetadataProvider;
-import org.apache.felix.ipojo.manipulator.metadata.FileMetadataProvider;
-import org.apache.felix.ipojo.manipulator.visitor.check.CheckFieldConsistencyVisitor;
-import org.apache.felix.ipojo.manipulator.visitor.writer.ManipulatedResourcesWriter;
-import org.apache.felix.ipojo.metadata.Element;
-
-/**
- * A {@code BndIpojoPlugin} is ...
- *
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-public class PojoizationPlugin implements Plugin, AnalyzerPlugin {
-
- private static final String PROPERTY_METADATA = "metadata";
- private static final String PROPERTY_USE_LOCAL_SCHEMAS = "use-local-schemas";
-
- private static final String DEFAULT_METADATA = "META-INF/metadata.xml";
- private static final boolean DEFAULT_USE_LOCAL_SCHEMAS = false;
-
- private String m_metadata = DEFAULT_METADATA;
- private boolean m_useLocalSchemas = DEFAULT_USE_LOCAL_SCHEMAS;
-
- private Reporter m_reporter;
-
- public void setProperties(Map<String, String> configuration) {
-
- // Use metadata file if any
- if (configuration.containsKey(PROPERTY_METADATA)) {
- m_metadata = configuration.get(PROPERTY_METADATA);
- }
-
- // Use local schemas ?
- if (configuration.containsKey(PROPERTY_USE_LOCAL_SCHEMAS)) {
- m_useLocalSchemas = true;
- }
- }
-
- public void setReporter(Reporter reporter) {
- m_reporter = reporter;
- }
-
- public boolean analyzeJar(Analyzer analyzer) throws Exception {
-
- long start = System.currentTimeMillis();
-
- // Wraps the Bnd Reporter
- BndReporter reporter = new BndReporter(this.m_reporter);
-
- // Build ResourceStore
- BndJarResourceStore store = new BndJarResourceStore(analyzer, this.m_reporter);
-
- // Build MetadataProvider
- CompositeMetadataProvider provider = new CompositeMetadataProvider(reporter);
-
- File file = new File(m_metadata);
- if (file.exists()) {
- // Absolute file system resource
- FileMetadataProvider fmp = new FileMetadataProvider(file, reporter);
- fmp.setValidateUsingLocalSchemas(m_useLocalSchemas);
- provider.addMetadataProvider(fmp);
- } else {
- // In archive resource
- Resource resource = analyzer.getJar().getResource(m_metadata);
- if (resource != null) {
- ResourceMetadataProvider rmp = new ResourceMetadataProvider(resource, reporter);
- rmp.setValidateUsingLocalSchemas(m_useLocalSchemas);
- provider.addMetadataProvider(rmp);
- }
- }
- provider.addMetadataProvider(new AnnotationMetadataProvider(store, reporter));
-
- CacheableMetadataProvider cache = new CacheableMetadataProvider(provider);
- if (cache.getMetadatas().isEmpty()) {
- return false;
- }
-
- Pojoization pojoization = new Pojoization(reporter);
- if (m_useLocalSchemas) {
- pojoization.setUseLocalXSD();
- }
-
- pojoization.pojoization(store, cache, createVisitor(store, reporter));
-
- int nbComponents = findElements(cache.getMetadatas(), "component").size();
- int nbHandlers = findElements(cache.getMetadatas(), "handler").size();
- this.m_reporter.progress("iPOJO manipulation performed performed in %s ms (%d components, %d handlers).",
- (System.currentTimeMillis() - start),
- nbComponents,
- nbHandlers);
-
- // Return true if a new run should be performed after the analyze
- return false;
- }
-
- private List<Element> findElements(List<Element> metadatas, String name) {
- List<Element> found = new ArrayList<Element>();
- for (Element element : metadatas) {
- if (name.equalsIgnoreCase(element.getName())) {
- found.add(element);
- }
- }
- return found;
- }
-
- private ManipulationVisitor createVisitor(ResourceStore store, BndReporter reporter) {
- ManipulatedResourcesWriter writer = new ManipulatedResourcesWriter();
- writer.setReporter(reporter);
- writer.setResourceStore(store);
-
- CheckFieldConsistencyVisitor checkFieldConsistencyVisitor = new CheckFieldConsistencyVisitor(writer);
- checkFieldConsistencyVisitor.setReporter(reporter);
- return checkFieldConsistencyVisitor;
-
- }
-
-}
diff --git a/ipojo/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/ResourceMetadataProvider.java b/ipojo/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/ResourceMetadataProvider.java
deleted file mode 100644
index f40e681..0000000
--- a/ipojo/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/ResourceMetadataProvider.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * 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.
- */
-package org.apache.felix.ipojo.bnd;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
-
-import aQute.lib.osgi.Resource;
-import org.apache.felix.ipojo.manipulator.MetadataProvider;
-import org.apache.felix.ipojo.manipulator.Reporter;
-import org.apache.felix.ipojo.manipulator.metadata.StreamMetadataProvider;
-import org.apache.felix.ipojo.metadata.Element;
-
-/**
- * A {@code ResourceMetadataProvider} is ...
- *
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-public class ResourceMetadataProvider implements MetadataProvider {
-
- private Resource m_resource;
-
- private List<Element> m_cached;
-
- private boolean m_validateUsingLocalSchemas = false;
-
- private Reporter m_reporter;
-
- public ResourceMetadataProvider(Resource resource, Reporter reporter) {
- m_resource = resource;
- m_reporter = reporter;
- }
-
- public void setValidateUsingLocalSchemas(boolean validateUsingLocalSchemas) {
- this.m_validateUsingLocalSchemas = validateUsingLocalSchemas;
- }
-
- public List<Element> getMetadatas() throws IOException {
- if (m_cached == null) {
- m_cached = new ArrayList<Element>();
- InputStream stream = null;
- try {
- stream = m_resource.openInputStream();
- } catch (Exception e) {
- m_reporter.error(e.getMessage());
- throw new IOException("Cannot read metadata");
- }
- StreamMetadataProvider provider = new StreamMetadataProvider(stream, m_reporter);
- provider.setValidateUsingLocalSchemas(m_validateUsingLocalSchemas);
- m_cached.addAll(provider.getMetadatas());
- }
-
- return m_cached;
- }
-}
diff --git a/ipojo/bnd-ipojo-plugin/src/test/java/org/apache/felix/ipojo/bnd/PojoizationPluginTestCase.java b/ipojo/bnd-ipojo-plugin/src/test/java/org/apache/felix/ipojo/bnd/PojoizationPluginTestCase.java
deleted file mode 100644
index 0ad3002..0000000
--- a/ipojo/bnd-ipojo-plugin/src/test/java/org/apache/felix/ipojo/bnd/PojoizationPluginTestCase.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * 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.
- */
-package org.apache.felix.ipojo.bnd;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import aQute.lib.osgi.Analyzer;
-import aQute.lib.osgi.Jar;
-import aQute.lib.osgi.Resource;
-import aQute.lib.osgi.URLResource;
-import aQute.libg.reporter.Reporter;
-import junit.framework.TestCase;
-import org.easymock.EasyMock;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.mockito.Spy;
-
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyZeroInteractions;
-import static org.mockito.Mockito.when;
-
-public class PojoizationPluginTestCase extends TestCase {
-
- @Mock
- private Reporter reporter;
-
- @Spy
- private Analyzer analyzer = new Analyzer();
-
- @Spy
- private Jar jar = new Jar("mock.jar");
-
- @Override
- public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
- }
-
- public void testAnalysisWithComponentOnlyMetadataXml() throws Exception {
- PojoizationPlugin plugin = new PojoizationPlugin();
-
- Map<String, String> props = new HashMap<String, String>();
-
- Resource resource = new URLResource(getClass().getResource("/metadata-components-only.xml"));
- doReturn(jar).when(analyzer).getJar();
- doReturn(resource).when(jar).getResource(eq("META-INF/metadata.xml"));
-
- plugin.setReporter(reporter);
- plugin.setProperties(props);
-
- plugin.analyzeJar(analyzer);
-
- assertEquals("component { $class=\"com.acme.Thermometer\" }",
- analyzer.getProperty("IPOJO-Components"));
- }
-
- public void testAnalysisWithInstanceOnlyMetadataXml() throws Exception {
- PojoizationPlugin plugin = new PojoizationPlugin();
-
- Map<String, String> props = new HashMap<String, String>();
-
- Resource resource = new URLResource(getClass().getResource("/metadata-instances-only.xml"));
- doReturn(jar).when(analyzer).getJar();
- doReturn(resource).when(jar).getResource(eq("META-INF/metadata.xml"));
-
- plugin.setReporter(reporter);
- plugin.setProperties(props);
-
- plugin.analyzeJar(analyzer);
-
- assertEquals("instance { $component=\"com.acme.Thermometer\" }",
- analyzer.getProperty("IPOJO-Components"));
- }
-
- public void testAnalysisWithComponentsAndInstancesMetadataXml() throws Exception {
- PojoizationPlugin plugin = new PojoizationPlugin();
-
- Map<String, String> props = new HashMap<String, String>();
-
- Resource resource = new URLResource(getClass().getResource("/metadata-components-and-instances.xml"));
- doReturn(jar).when(analyzer).getJar();
- doReturn(resource).when(jar).getResource(eq("META-INF/metadata.xml"));
-
- plugin.setReporter(reporter);
- plugin.setProperties(props);
-
- plugin.analyzeJar(analyzer);
-
- assertEquals("component { $class=\"com.acme.Thermometer\" }" +
- "instance { $component=\"com.acme.Thermometer\" }" +
- "instance { $component=\"com.acme.Thermometer\" }",
- analyzer.getProperty("IPOJO-Components"));
- }
-}
diff --git a/ipojo/bnd-ipojo-plugin/src/test/resources/metadata-components-and-instances.xml b/ipojo/bnd-ipojo-plugin/src/test/resources/metadata-components-and-instances.xml
deleted file mode 100644
index 19bc3d4..0000000
--- a/ipojo/bnd-ipojo-plugin/src/test/resources/metadata-components-and-instances.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<ipojo>
- <component class="com.acme.Thermometer" />
- <instance component="com.acme.Thermometer" />
- <instance component="com.acme.Thermometer" />
-</ipojo>
diff --git a/ipojo/bnd-ipojo-plugin/src/test/resources/metadata-components-only.xml b/ipojo/bnd-ipojo-plugin/src/test/resources/metadata-components-only.xml
deleted file mode 100644
index cc913fe..0000000
--- a/ipojo/bnd-ipojo-plugin/src/test/resources/metadata-components-only.xml
+++ /dev/null
@@ -1,3 +0,0 @@
-<ipojo>
- <component class="com.acme.Thermometer"/>
-</ipojo>
diff --git a/ipojo/bnd-ipojo-plugin/src/test/resources/metadata-instances-only.xml b/ipojo/bnd-ipojo-plugin/src/test/resources/metadata-instances-only.xml
deleted file mode 100644
index 56aa63a..0000000
--- a/ipojo/bnd-ipojo-plugin/src/test/resources/metadata-instances-only.xml
+++ /dev/null
@@ -1,3 +0,0 @@
-<ipojo>
- <instance component="com.acme.Thermometer"/>
-</ipojo>
\ No newline at end of file