You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2020/03/24 16:33:05 UTC
[camel-karaf] 02/02: CAMEL-14776: Move main out of
camel-test-blueprint so it can be used outside and with camel:run maven
goal.
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-karaf.git
commit 0791d5e435c143cfc462e2d72b87968640892fe0
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Mar 24 17:32:44 2020 +0100
CAMEL-14776: Move main out of camel-test-blueprint so it can be used outside and with camel:run maven goal.
---
components/camel-blueprint-main/pom.xml | 35 ++++++++++-
.../camel}/blueprint/CamelBlueprintHelper.java | 69 ++++++++++++++++++++--
.../main/java/org/apache/camel/blueprint/Main.java | 1 -
components/camel-test-blueprint/pom.xml | 10 +++-
.../test/blueprint/CamelBlueprintTestSupport.java | 1 +
.../test/blueprint/BlueprintPropertiesTest.java | 1 +
components/pom.xml | 2 +-
7 files changed, 106 insertions(+), 13 deletions(-)
diff --git a/components/camel-blueprint-main/pom.xml b/components/camel-blueprint-main/pom.xml
index 9bf6849..8feed56 100644
--- a/components/camel-blueprint-main/pom.xml
+++ b/components/camel-blueprint-main/pom.xml
@@ -45,9 +45,9 @@
</dependency>
<dependency>
- <groupId>org.apache.camel.karaf</groupId>
- <artifactId>camel-test-blueprint</artifactId>
- <version>${project.version}</version>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ <scope>test</scope>
</dependency>
<dependency>
@@ -103,6 +103,35 @@
</exclusions>
</dependency>
<dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.configadmin</artifactId>
+ <!-- exclude the following dependency which otherwise would pop up a lot of compilation
+ errors both by this and the camel-maven-plugin modules under eclipse. -->
+ <exclusions>
+ <exclusion>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.osgi.foundation</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>osgi.core</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>osgi.cmpn</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.swissbox</groupId>
+ <artifactId>pax-swissbox-tinybundles</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
diff --git a/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintHelper.java b/components/camel-blueprint-main/src/main/java/org/apache/camel/blueprint/CamelBlueprintHelper.java
similarity index 93%
rename from components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintHelper.java
rename to components/camel-blueprint-main/src/main/java/org/apache/camel/blueprint/CamelBlueprintHelper.java
index 08f742d..a716201 100644
--- a/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintHelper.java
+++ b/components/camel-blueprint-main/src/main/java/org/apache/camel/blueprint/CamelBlueprintHelper.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.test.blueprint;
+package org.apache.camel.blueprint;
import java.io.File;
import java.io.FileInputStream;
@@ -79,9 +79,6 @@ import org.osgi.util.tracker.ServiceTracker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import static org.apache.camel.test.junit4.TestSupport.createDirectory;
-import static org.apache.camel.test.junit4.TestSupport.deleteDirectory;
-
/**
* Helper for using Blueprint with Camel.
*/
@@ -429,6 +426,68 @@ public final class CamelBlueprintHelper {
}
/**
+ * create the directory
+ *
+ * @param file the directory to be created
+ */
+ public static void createDirectory(String file) {
+ File dir = new File(file);
+ dir.mkdirs();
+ }
+
+ /**
+ * Recursively delete a directory, useful to zapping test data
+ *
+ * @param file the directory to be deleted
+ * @return <tt>false</tt> if error deleting directory
+ */
+ public static boolean deleteDirectory(String file) {
+ return deleteDirectory(new File(file));
+ }
+
+ /**
+ * Recursively delete a directory, useful to zapping test data
+ *
+ * @param file the directory to be deleted
+ * @return <tt>false</tt> if error deleting directory
+ */
+ public static boolean deleteDirectory(File file) {
+ int tries = 0;
+ int maxTries = 5;
+ boolean exists = true;
+ while (exists && (tries < maxTries)) {
+ recursivelyDeleteDirectory(file);
+ tries++;
+ exists = file.exists();
+ if (exists) {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ // Ignore
+ }
+ }
+ }
+ return !exists;
+ }
+
+ private static void recursivelyDeleteDirectory(File file) {
+ if (!file.exists()) {
+ return;
+ }
+
+ if (file.isDirectory()) {
+ File[] files = file.listFiles();
+ for (File child : files) {
+ recursivelyDeleteDirectory(child);
+ }
+ }
+ boolean success = file.delete();
+ if (!success) {
+ LOG.warn("Deletion of file: " + file.getAbsolutePath() + " failed");
+ }
+ }
+
+ /**
* Provides an iterable collection of references, even if the original array is <code>null</code>.
*/
private static Collection<ServiceReference> asCollection(ServiceReference[] references) {
@@ -453,7 +512,7 @@ public final class CamelBlueprintHelper {
* @return the bundle descriptors.
* @throws FileNotFoundException is thrown if a bundle descriptor cannot be found
*/
- protected static Collection<URL> getBlueprintDescriptors(String descriptors) throws FileNotFoundException, MalformedURLException {
+ public static Collection<URL> getBlueprintDescriptors(String descriptors) throws FileNotFoundException, MalformedURLException {
List<URL> answer = new ArrayList<>();
if (descriptors != null) {
// there may be more resources separated by comma
diff --git a/components/camel-blueprint-main/src/main/java/org/apache/camel/blueprint/Main.java b/components/camel-blueprint-main/src/main/java/org/apache/camel/blueprint/Main.java
index 4ae86e3..283626c 100644
--- a/components/camel-blueprint-main/src/main/java/org/apache/camel/blueprint/Main.java
+++ b/components/camel-blueprint-main/src/main/java/org/apache/camel/blueprint/Main.java
@@ -20,7 +20,6 @@ import java.util.LinkedList;
import org.apache.camel.CamelContext;
import org.apache.camel.ProducerTemplate;
-import org.apache.camel.test.blueprint.CamelBlueprintHelper;
import org.apache.camel.main.MainCommandLineSupport;
import org.osgi.framework.BundleContext;
diff --git a/components/camel-test-blueprint/pom.xml b/components/camel-test-blueprint/pom.xml
index 54e4373..8bc54e5 100644
--- a/components/camel-test-blueprint/pom.xml
+++ b/components/camel-test-blueprint/pom.xml
@@ -43,14 +43,18 @@
</properties>
<dependencies>
+
<dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-test</artifactId>
+ <groupId>org.apache.camel.karaf</groupId>
+ <artifactId>camel-blueprint-main</artifactId>
+ <version>${project.version}</version>
</dependency>
+
<dependency>
<groupId>org.apache.camel</groupId>
- <artifactId>camel-main</artifactId>
+ <artifactId>camel-test</artifactId>
</dependency>
+
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
diff --git a/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java b/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java
index c691415..fd56e92 100644
--- a/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java
+++ b/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java
@@ -44,6 +44,7 @@ import org.w3c.dom.NodeList;
import org.apache.aries.blueprint.compendium.cm.CmNamespaceHandler;
import org.apache.camel.CamelContext;
+import org.apache.camel.blueprint.CamelBlueprintHelper;
import org.apache.camel.component.properties.PropertiesComponent;
import org.apache.camel.model.ModelCamelContext;
import org.apache.camel.test.junit4.CamelTestSupport;
diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/BlueprintPropertiesTest.java b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/BlueprintPropertiesTest.java
index fa8b2cb..e8a68da 100644
--- a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/BlueprintPropertiesTest.java
+++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/BlueprintPropertiesTest.java
@@ -16,6 +16,7 @@
*/
package org.apache.camel.test.blueprint;
+import org.apache.camel.blueprint.CamelBlueprintHelper;
import org.junit.Test;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
diff --git a/components/pom.xml b/components/pom.xml
index b809dbb..a02240d 100644
--- a/components/pom.xml
+++ b/components/pom.xml
@@ -33,8 +33,8 @@
<modules>
<module>camel-blueprint</module>
- <module>camel-test-blueprint</module>
<module>camel-blueprint-main</module>
+ <module>camel-test-blueprint</module>
<module>camel-cxf-blueprint</module>
<module>camel-cxf-transport-blueprint</module>
<module>camel-kura</module>