FELIX-1463: Switch to Felix Fileinstall instead of our own file deployer
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@809481 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/karaf/assembly/pom.xml b/karaf/assembly/pom.xml
index bfa6d31..c3f8ae5 100644
--- a/karaf/assembly/pom.xml
+++ b/karaf/assembly/pom.xml
@@ -44,10 +44,6 @@
</dependency>
<dependency>
<groupId>org.apache.felix.karaf.deployer</groupId>
- <artifactId>org.apache.felix.karaf.deployer.filemonitor</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.felix.karaf.deployer</groupId>
<artifactId>org.apache.felix.karaf.deployer.spring</artifactId>
</dependency>
<dependency>
@@ -159,6 +155,10 @@
<artifactId>org.apache.felix.bundlerepository</artifactId>
</dependency>
<dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.fileinstall</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.apache.mina</groupId>
<artifactId>mina-core</artifactId>
</dependency>
diff --git a/karaf/assembly/src/main/descriptors/unix-bin.xml b/karaf/assembly/src/main/descriptors/unix-bin.xml
index e4093db..3ca944c 100644
--- a/karaf/assembly/src/main/descriptors/unix-bin.xml
+++ b/karaf/assembly/src/main/descriptors/unix-bin.xml
@@ -124,6 +124,7 @@
<include>org.apache.felix:org.apache.felix.configadmin</include>
<include>org.apache.felix:org.apache.felix.prefs</include>
<include>org.apache.felix:org.apache.felix.framework</include>
+ <include>org.apache.felix:org.apache.felix.fileinstall</include>
</includes>
</dependencySet>
<dependencySet>
@@ -181,7 +182,6 @@
<useProjectArtifact>false</useProjectArtifact>
<outputFileNameMapping>org/apache/felix/karaf/deployer/${artifact.artifactId}/${artifact.baseVersion}/${artifact.artifactId}-${artifact.baseVersion}${dashClassifier?}.${artifact.extension}</outputFileNameMapping>
<includes>
- <include>org.apache.felix.karaf.deployer:org.apache.felix.karaf.deployer.filemonitor</include>
<include>org.apache.felix.karaf.deployer:org.apache.felix.karaf.deployer.spring</include>
<include>org.apache.felix.karaf.deployer:org.apache.felix.karaf.deployer.blueprint</include>
<include>org.apache.felix.karaf.deployer:org.apache.felix.karaf.deployer.features</include>
diff --git a/karaf/assembly/src/main/descriptors/windows-bin.xml b/karaf/assembly/src/main/descriptors/windows-bin.xml
index 8039fba..0ab16dd 100644
--- a/karaf/assembly/src/main/descriptors/windows-bin.xml
+++ b/karaf/assembly/src/main/descriptors/windows-bin.xml
@@ -116,6 +116,7 @@
<include>org.apache.felix:org.apache.felix.configadmin</include>
<include>org.apache.felix:org.apache.felix.prefs</include>
<include>org.apache.felix:org.apache.felix.framework</include>
+ <include>org.apache.felix:org.apache.felix.fileinstall</include>
</includes>
</dependencySet>
<dependencySet>
@@ -173,7 +174,6 @@
<useProjectArtifact>false</useProjectArtifact>
<outputFileNameMapping>org/apache/felix/karaf/deployer/${artifact.artifactId}/${artifact.baseVersion}/${artifact.artifactId}-${artifact.baseVersion}${dashClassifier?}.${artifact.extension}</outputFileNameMapping>
<includes>
- <include>org.apache.felix.karaf.deployer:org.apache.felix.karaf.deployer.filemonitor</include>
<include>org.apache.felix.karaf.deployer:org.apache.felix.karaf.deployer.spring</include>
<include>org.apache.felix.karaf.deployer:org.apache.felix.karaf.deployer.blueprint</include>
<include>org.apache.felix.karaf.deployer:org.apache.felix.karaf.deployer.features</include>
diff --git a/karaf/assembly/src/main/distribution/text/etc/org.apache.felix.fileinstall-deploy.cfg b/karaf/assembly/src/main/distribution/text/etc/org.apache.felix.fileinstall-deploy.cfg
new file mode 100644
index 0000000..62330b9
--- /dev/null
+++ b/karaf/assembly/src/main/distribution/text/etc/org.apache.felix.fileinstall-deploy.cfg
@@ -0,0 +1,22 @@
+################################################################################
+#
+# 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.
+#
+################################################################################
+
+felix.fileinstall.dir = ${karaf.base}/deploy
+felix.fileinstall.tmpdir = ${karaf.base}/data/generated-bundles
+felix.fileinstall.poll = 1000
diff --git a/karaf/assembly/src/main/filtered-resources/etc/config.properties b/karaf/assembly/src/main/filtered-resources/etc/config.properties
index 59c1ade..57c893f 100644
--- a/karaf/assembly/src/main/filtered-resources/etc/config.properties
+++ b/karaf/assembly/src/main/filtered-resources/etc/config.properties
@@ -49,11 +49,9 @@
#
# FileMonitor properties
#
-org.apache.felix.karaf.filemonitor.configDir = ${karaf.base}/etc
-org.apache.felix.karaf.filemonitor.monitorDir = ${karaf.base}/deploy
-org.apache.felix.karaf.filemonitor.generatedJarDir = ${karaf.base}/data/generated-bundles
-org.apache.felix.karaf.filemonitor.scanInterval = 500
-
+felix.fileinstall.dir = ${karaf.base}/etc
+felix.fileinstall.filter = .*\\.cfg
+felix.fileinstall.poll = 1000
#
# Java platform package export properties.
diff --git a/karaf/assembly/src/main/filtered-resources/etc/startup.properties b/karaf/assembly/src/main/filtered-resources/etc/startup.properties
index 36f066b..ca50929 100644
--- a/karaf/assembly/src/main/filtered-resources/etc/startup.properties
+++ b/karaf/assembly/src/main/filtered-resources/etc/startup.properties
@@ -29,7 +29,7 @@
org/ops4j/pax/logging/pax-logging-service/${pax.logging.version}/pax-logging-service-${pax.logging.version}.jar=8
org/apache/felix/org.apache.felix.configadmin/${felix.configadmin.version}/org.apache.felix.configadmin-${felix.configadmin.version}.jar=10
org/apache/felix/org.apache.felix.prefs/${felix.prefs.version}/org.apache.felix.prefs-${felix.prefs.version}.jar=10
-org/apache/felix/karaf/deployer/org.apache.felix.karaf.deployer.filemonitor/${pom.version}/org.apache.felix.karaf.deployer.filemonitor-${pom.version}.jar=15
+org/apache/felix/org.apache.felix.fileinstall/${felix.fileinstall.version}/org.apache.felix.fileinstall-${felix.fileinstall.version}.jar=10
#
# The rest of the services..
diff --git a/karaf/deployer/blueprint/pom.xml b/karaf/deployer/blueprint/pom.xml
index e6e88e4..70b9116 100644
--- a/karaf/deployer/blueprint/pom.xml
+++ b/karaf/deployer/blueprint/pom.xml
@@ -46,8 +46,12 @@
<artifactId>spring-osgi-core</artifactId>
</dependency>
<dependency>
- <groupId>org.apache.felix.karaf.deployer</groupId>
- <artifactId>org.apache.felix.karaf.deployer.filemonitor</artifactId>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.fileinstall</artifactId>
</dependency>
<dependency>
<groupId>org.apache.servicemix.bundles</groupId>
diff --git a/karaf/deployer/blueprint/src/main/java/org/apache/felix/karaf/deployer/blueprint/BlueprintDeploymentListener.java b/karaf/deployer/blueprint/src/main/java/org/apache/felix/karaf/deployer/blueprint/BlueprintDeploymentListener.java
index 602f072..520f565 100644
--- a/karaf/deployer/blueprint/src/main/java/org/apache/felix/karaf/deployer/blueprint/BlueprintDeploymentListener.java
+++ b/karaf/deployer/blueprint/src/main/java/org/apache/felix/karaf/deployer/blueprint/BlueprintDeploymentListener.java
@@ -27,13 +27,13 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.felix.karaf.deployer.filemonitor.DeploymentListener;
+import org.apache.felix.fileinstall.listener.ArtifactTransformer;
/**
* A deployment listener that listens for spring xml applications
* and creates bundles for these.
*/
-public class BlueprintDeploymentListener implements DeploymentListener {
+public class BlueprintDeploymentListener implements ArtifactTransformer {
private static final Log LOGGER = LogFactory.getLog(BlueprintDeploymentListener.class);
@@ -56,7 +56,7 @@
return false;
}
- public File handle(File artifact, File tmpDir) {
+ public File transform(File artifact, File tmpDir) {
try {
File destFile = new File(tmpDir, artifact.getName() + ".jar");
FileOutputStream os = new FileOutputStream(destFile);
diff --git a/karaf/deployer/blueprint/src/main/resources/OSGI-INF/blueprint/blueprint-deployer.xml b/karaf/deployer/blueprint/src/main/resources/OSGI-INF/blueprint/blueprint-deployer.xml
index 9ebce77..f36bf0a 100644
--- a/karaf/deployer/blueprint/src/main/resources/OSGI-INF/blueprint/blueprint-deployer.xml
+++ b/karaf/deployer/blueprint/src/main/resources/OSGI-INF/blueprint/blueprint-deployer.xml
@@ -20,7 +20,7 @@
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:cm="http://www.osgi.org/xmlns/blueprint-cm/v1.0.0">
- <service interface="org.apache.felix.karaf.deployer.filemonitor.DeploymentListener">
+ <service auto-export="interfaces">
<bean class="org.apache.felix.karaf.deployer.blueprint.BlueprintDeploymentListener"/>
</service>
diff --git a/karaf/deployer/features/pom.xml b/karaf/deployer/features/pom.xml
index d56f795..19cee2b 100644
--- a/karaf/deployer/features/pom.xml
+++ b/karaf/deployer/features/pom.xml
@@ -50,8 +50,12 @@
<artifactId>org.apache.felix.karaf.features.core</artifactId>
</dependency>
<dependency>
- <groupId>org.apache.felix.karaf.deployer</groupId>
- <artifactId>org.apache.felix.karaf.deployer.filemonitor</artifactId>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.fileinstall</artifactId>
</dependency>
<dependency>
<groupId>org.apache.servicemix.bundles</groupId>
diff --git a/karaf/deployer/features/src/main/java/org/apache/felix/karaf/deployer/features/FeatureDeploymentListener.java b/karaf/deployer/features/src/main/java/org/apache/felix/karaf/deployer/features/FeatureDeploymentListener.java
index b7d4b47..0ea82bb 100644
--- a/karaf/deployer/features/src/main/java/org/apache/felix/karaf/deployer/features/FeatureDeploymentListener.java
+++ b/karaf/deployer/features/src/main/java/org/apache/felix/karaf/deployer/features/FeatureDeploymentListener.java
@@ -43,7 +43,7 @@
import org.apache.felix.karaf.features.Feature;
import org.apache.felix.karaf.features.FeaturesService;
import org.apache.felix.karaf.features.Repository;
-import org.apache.felix.karaf.deployer.filemonitor.DeploymentListener;
+import org.apache.felix.fileinstall.listener.ArtifactTransformer;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
@@ -53,7 +53,7 @@
/**
* A deployment listener able to hot deploy a feature descriptor
*/
-public class FeatureDeploymentListener implements DeploymentListener, SynchronousBundleListener {
+public class FeatureDeploymentListener implements ArtifactTransformer, SynchronousBundleListener {
public static final String FEATURE_PATH = "org.apache.felix.karaf.gshell.features";
@@ -106,7 +106,7 @@
return false;
}
- public File handle(File artifact, File tmpDir) {
+ public File transform(File artifact, File tmpDir) {
// We can't really install the feature right now and just return nothing.
// We would not be aware of the fact that the bundle has been uninstalled
// and therefore require the feature to be uninstalled.
diff --git a/karaf/deployer/features/src/main/resources/OSGI-INF/blueprint/features-deployer.xml b/karaf/deployer/features/src/main/resources/OSGI-INF/blueprint/features-deployer.xml
index 474b993..c27d26e 100644
--- a/karaf/deployer/features/src/main/resources/OSGI-INF/blueprint/features-deployer.xml
+++ b/karaf/deployer/features/src/main/resources/OSGI-INF/blueprint/features-deployer.xml
@@ -21,8 +21,7 @@
xmlns:cm="http://www.osgi.org/xmlns/blueprint-cm/v1.0.0"
default-activation="lazy">
- <service interface="org.apache.felix.karaf.deployer.filemonitor.DeploymentListener"
- ref="featureDeploymentListener"/>
+ <service ref="featureDeploymentListener" auto-export="interfaces"/>
<bean id="featureDeploymentListener" class="org.apache.felix.karaf.deployer.features.FeatureDeploymentListener"
init-method="init" destroy-method="destroy" activation="lazy">
diff --git a/karaf/deployer/filemonitor/pom.xml b/karaf/deployer/filemonitor/pom.xml
deleted file mode 100644
index 7c59ee9..0000000
--- a/karaf/deployer/filemonitor/pom.xml
+++ /dev/null
@@ -1,81 +0,0 @@
-<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">
-
- <!--
-
- 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.
- -->
-
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.apache.felix.karaf.deployer</groupId>
- <artifactId>deployer</artifactId>
- <version>0.9.0-SNAPSHOT</version>
- </parent>
-
- <groupId>org.apache.felix.karaf.deployer</groupId>
- <artifactId>org.apache.felix.karaf.deployer.filemonitor</artifactId>
- <packaging>bundle</packaging>
- <version>0.9.0-SNAPSHOT</version>
- <name>Apache Felix Karaf :: File Monitor</name>
-
- <description>This bundle monitors the deploy directory for new OSGi bundles in jar form, expanded form or for
- configuration file changes and undeploys/redeploys them
- </description>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.osgi.core</artifactId>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.osgi.compendium</artifactId>
- </dependency>
-
- <!-- testing -->
- <dependency>
- <groupId>org.apache.servicemix.bundles</groupId>
- <artifactId>org.apache.servicemix.bundles.junit</artifactId>
- <scope>test</scope>
- </dependency>
-
- </dependencies>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <configuration>
- <instructions>
- <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
- <Export-Package>${pom.artifactId}*;version=${project.version}</Export-Package>
- <Bundle-Activator>org.apache.felix.karaf.deployer.filemonitor.FileMonitorActivator</Bundle-Activator>
- <_versionpolicy>${bnd.version.policy}</_versionpolicy>
- </instructions>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
-</project>
diff --git a/karaf/deployer/filemonitor/src/main/java/org/apache/felix/karaf/deployer/filemonitor/DeploymentListener.java b/karaf/deployer/filemonitor/src/main/java/org/apache/felix/karaf/deployer/filemonitor/DeploymentListener.java
deleted file mode 100644
index f0098af..0000000
--- a/karaf/deployer/filemonitor/src/main/java/org/apache/felix/karaf/deployer/filemonitor/DeploymentListener.java
+++ /dev/null
@@ -1,36 +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.karaf.deployer.filemonitor;
-
-import java.io.File;
-
-
-public interface DeploymentListener {
-
- /**
- * Returns true if the listener can process the given file
- */
- boolean canHandle(File artifact);
-
- /**
- * Process the given file (canHandle returned true previously)
- * Can return <null> or a pointer to a transformed file.
- */
- File handle(File artifact, File tmpDir);
-
-}
diff --git a/karaf/deployer/filemonitor/src/main/java/org/apache/felix/karaf/deployer/filemonitor/FileMonitor.java b/karaf/deployer/filemonitor/src/main/java/org/apache/felix/karaf/deployer/filemonitor/FileMonitor.java
deleted file mode 100644
index e3a18c8..0000000
--- a/karaf/deployer/filemonitor/src/main/java/org/apache/felix/karaf/deployer/filemonitor/FileMonitor.java
+++ /dev/null
@@ -1,776 +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.karaf.deployer.filemonitor;
-
-import java.io.Closeable;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Dictionary;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-import java.util.concurrent.Executor;
-import java.util.concurrent.Executors;
-import java.util.jar.Attributes;
-import java.util.jar.JarFile;
-import java.util.jar.Manifest;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleEvent;
-import org.osgi.framework.BundleException;
-import org.osgi.framework.BundleListener;
-import org.osgi.framework.Constants;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceEvent;
-import org.osgi.framework.ServiceListener;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.cm.Configuration;
-import org.osgi.service.cm.ConfigurationAdmin;
-import org.osgi.service.packageadmin.PackageAdmin;
-import org.osgi.service.prefs.Preferences;
-import org.osgi.service.prefs.PreferencesService;
-import org.osgi.util.tracker.ServiceTracker;
-
-/**
- * Watches a deploy directory for files that are added, updated or removed then
- * processing them. Currently we support OSGi bundles, OSGi configuration files
- * and expanded directories of OSGi bundles.
- *
- * @version $Revision: 1.1 $
- */
-public class FileMonitor {
-
- public final static String CONFIG_DIR = "org.apache.felix.karaf.filemonitor.configDir";
- public final static String DEPLOY_DIR = "org.apache.felix.karaf.filemonitor.monitorDir";
- public final static String GENERATED_JAR_DIR = "org.apache.felix.karaf.filemonitor.generatedJarDir";
- public final static String SCAN_INTERVAL = "org.apache.felix.karaf.filemonitor.scanInterval";
- public final static String PREFERENCE_KEY = "FileMonitor";
-
- protected static final String FILENAME = "org.apache.felix.karaf.filemonitor.filename";
-
- private static final Log LOGGER = LogFactory.getLog(FileMonitor.class);
-
- private FileMonitorActivator activator;
- private File configDir;
- private File deployDir;
- private File generateDir;
- private Scanner scanner = new Scanner();
- private long scanInterval = 500L;
- private boolean loggedConfigAdminWarning;
- private List<Bundle> bundlesToStart = new ArrayList<Bundle>();
- private List<Bundle> bundlesToUpdate = new ArrayList<Bundle>();
- private Map<String, String> artifactToBundle = new HashMap<String, String>();
- private final Set<String> pendingTransformationArtifacts = new HashSet<String>();
- private final Set<Bundle> pendingStartBundles = new HashSet<Bundle>();
- private ServiceListener deployerListener;
- private BundleListener bundleListener;
- private Executor executor;
- private String pid;
-
- public FileMonitor() {
- String base = System.getProperty("karaf.base", ".");
- configDir = new File(base, "etc");
- deployDir = new File(base, "deploy");
- generateDir = new File(base, "data/generated-bundles");
- }
-
- @SuppressWarnings("unchecked")
- public FileMonitor(FileMonitorActivator activator, Dictionary properties, String pid) {
- this();
-
- this.activator = activator;
- this.pid = pid;
-
- File value = getFileValue(properties, CONFIG_DIR);
- if (value != null) {
- configDir = value;
- }
- value = getFileValue(properties, DEPLOY_DIR);
- if (value != null) {
- deployDir = value;
- }
- value = getFileValue(properties, GENERATED_JAR_DIR);
- if (value != null) {
- generateDir = value;
- }
- Long i = getLongValue(properties, SCAN_INTERVAL);
- if (i != null) {
- scanInterval = i;
- }
- }
-
- public void start() {
- executor = Executors.newSingleThreadExecutor();
- if (configDir != null) {
- configDir.mkdirs();
- }
- deployDir.mkdirs();
- generateDir.mkdirs();
-
- List<File> dirs = new ArrayList<File>();
- if (configDir != null) {
- dirs.add(configDir);
- }
- dirs.add(deployDir);
- scanner.setScanDirs(dirs);
- scanner.setScanInterval(scanInterval);
- // load the scan results for this monitor
- loadScannerState();
- scanner.addListener(new Scanner.BulkListener() {
- public void filesChanged(List<String> filenames) throws Exception {
- onFilesChanged(filenames);
- }
- });
-
- LOGGER.info("Starting to monitor the deploy directory: " + deployDir + " every " + scanInterval
- + " millis");
- if (configDir != null) {
- LOGGER.info("Config directory is at: " + configDir);
- }
- LOGGER.info("Will generate bundles from expanded source directories to: " + generateDir);
-
- executor.execute(new Runnable() {
- public void run() {
- scanner.start();
- }
- });
- }
-
- public void stop() {
- // first stop the scanner
- scanner.stop();
- // load the scan results for this monitor
- saveScannerState();
- }
-
- // Properties
- // -------------------------------------------------------------------------
-
- public BundleContext getContext() {
- return activator.getContext();
- }
-
- public FileMonitorActivator getActivator() {
- return activator;
- }
-
- public void setActivator(FileMonitorActivator activator) {
- this.activator = activator;
- }
-
- public File getConfigDir() {
- return configDir;
- }
-
- public void setConfigDir(File configDir) {
- this.configDir = configDir;
- }
-
- public File getDeployDir() {
- return deployDir;
- }
-
- public void setDeployDir(File deployDir) {
- this.deployDir = deployDir;
- }
-
- public File getGenerateDir() {
- return generateDir;
- }
-
- public void setGenerateDir(File generateDir) {
- this.generateDir = generateDir;
- }
-
- public long getScanInterval() {
- return scanInterval;
- }
-
- public void setScanInterval(long scanInterval) {
- this.scanInterval = scanInterval;
- }
-
- // Implementation methods
- // -------------------------------------------------------------------------
-
- protected synchronized void onFilesChanged(Collection<String> filenames) {
- bundlesToStart.clear();
- bundlesToUpdate.clear();
- Set<File> bundleJarsCreated = new HashSet<File>();
-
- for (String filename : filenames) {
- File file = new File(filename);
- try {
- LOGGER.debug("File changed: " + filename);
-
- // Handle config files
- if (isValidConfigFile(file)) {
- if (file.exists()) {
- updateConfiguration(file);
- } else {
- deleteConfiguration(file);
- }
- continue;
- }
-
- // Handle exploded artifacts removal
- if (!file.exists() && file.getName().equals("MANIFEST.MF")) {
- File parentFile = file.getParentFile();
- if (parentFile.getName().equals("META-INF")) {
- File bundleDir = parentFile.getParentFile();
- if (isValidBundleSourceDirectory(bundleDir)) {
- undeployBundle(bundleDir);
- continue;
- }
- }
- }
-
- // Handle exploded artifacts add
- File jardir = getExpandedBundleRootDirectory(file);
- if (jardir != null) {
- if (bundleJarsCreated.contains(jardir)) {
- continue;
- }
- bundleJarsCreated.add(jardir);
- file = createBundleJar(jardir);
- }
-
- // Transformation step
- if (file.exists()) {
- File f = transformArtifact(file);
- if (f == null) {
- LOGGER.warn("Unsupported deployment: " + filename);
- rescheduleTransformation(file);
- continue;
- }
- file = f;
- } else {
- String transformedFile = artifactToBundle.get(filename);
- if (transformedFile != null) {
- file = new File(transformedFile);
- if (file.exists()) {
- file.delete();
- }
- }
- }
-
- // Handle final bundles
- if (isValidArtifactFile(file)) {
- if (file.exists()) {
- deployBundle(file);
- } else {
- undeployBundle(file);
- }
- }
- } catch (Exception e) {
- LOGGER.warn("Failed to process: " + file + ". Reason: " + e, e);
- }
- }
- refreshPackagesAndStartOrUpdateBundles();
- }
-
- private void rescheduleTransformation(File file) {
- synchronized (pendingTransformationArtifacts) {
- pendingTransformationArtifacts.add(file.getAbsolutePath());
- }
- if (deployerListener == null) {
- try {
- String filter = "(" + Constants.OBJECTCLASS + "=" + DeploymentListener.class.getName() + ")";
- deployerListener = new ServiceListener() {
- public void serviceChanged(ServiceEvent event) {
- executor.execute(new Runnable() {
- public void run() {
- Set<String> files;
- synchronized (pendingTransformationArtifacts) {
- files = new HashSet<String>(pendingTransformationArtifacts);
- pendingTransformationArtifacts.clear();
- }
- onFilesChanged(files);
- }
- });
- }
- };
- getContext().addServiceListener(deployerListener, filter);
- } catch (InvalidSyntaxException e) {
- // Ignore
- }
- }
- }
-
- private File transformArtifact(File file) throws Exception {
- // Check registered deployers
- ServiceReference[] srvRefs = getContext().getAllServiceReferences(DeploymentListener.class.getName(),
- null);
- if (srvRefs != null) {
- for (ServiceReference sr : srvRefs) {
- try {
- DeploymentListener deploymentListener = (DeploymentListener)getContext().getService(sr);
- if (deploymentListener.canHandle(file)) {
- File transformedFile = deploymentListener.handle(file, getGenerateDir());
- artifactToBundle.put(file.getAbsolutePath(), transformedFile.getAbsolutePath());
- return transformedFile;
- }
- } finally {
- getContext().ungetService(sr);
- }
- }
- }
- JarFile jar = null;
- try {
- // Handle OSGi bundles with the default deployer
- if (file.getName().endsWith("txt") || file.getName().endsWith("xml")
- || file.getName().endsWith("properties")) {
- // that's file type which is not supported as bundle and avoid
- // exception in the log
- return null;
- }
- jar = new JarFile(file);
- Manifest m = jar.getManifest();
- if (m.getMainAttributes().getValue(new Attributes.Name("Bundle-SymbolicName")) != null
- && m.getMainAttributes().getValue(new Attributes.Name("Bundle-Version")) != null) {
- return file;
- }
- } catch (Exception e) {
- LOGGER.debug("Error transforming artifact " + file.getName(), e);
- } finally {
- if (jar != null) {
- jar.close();
- }
- }
- return null;
- }
-
- protected void deployBundle(File file) throws IOException, BundleException {
- LOGGER.info("Deploying: " + file.getCanonicalPath());
-
- InputStream in = new FileInputStream(file);
-
- try {
- Bundle bundle = getBundleForJarFile(file);
- if (bundle != null) {
- bundlesToUpdate.add(bundle);
- } else {
- bundle = getContext().installBundle(file.getCanonicalFile().toURI().toString(), in);
- if (!isBundleFragment(bundle)) {
- bundlesToStart.add(bundle);
- }
- }
- } finally {
- closeQuietly(in);
- }
- }
-
- protected void undeployBundle(File file) throws BundleException, IOException {
- LOGGER.info("Undeploying: " + file.getCanonicalPath());
- Bundle bundle = getBundleForJarFile(file);
-
- if (bundle == null) {
- LOGGER.warn("Could not find Bundle for file: " + file.getCanonicalPath());
- } else {
- if (!isBundleFragment(bundle)) {
- bundle.stop();
- }
- bundle.uninstall();
- }
- }
-
- protected Bundle getBundleForJarFile(File file) throws IOException {
- String absoluteFilePath = file.getAbsoluteFile().toURI().toString();
- Bundle bundles[] = getContext().getBundles();
- for (Bundle bundle : bundles) {
- String location = bundle.getLocation();
- if (filePathsMatch(absoluteFilePath, location)) {
- return bundle;
- }
- }
- return null;
- }
-
- protected static boolean filePathsMatch(String p1, String p2) {
- p1 = normalizeFilePath(p1);
- p2 = normalizeFilePath(p2);
- return (p1 != null && p1.equalsIgnoreCase(p2));
- }
-
- protected static String normalizeFilePath(String path) {
- if (path != null) {
- path = path.replaceFirst("file:/*", "");
- path = path.replaceAll("[\\\\/]+", "/");
- }
- return path;
- }
-
- protected void updateConfiguration(File file) throws IOException, InvalidSyntaxException {
- ConfigurationAdmin configurationAdmin = activator.getConfigurationAdmin();
- if (configurationAdmin == null) {
- if (!loggedConfigAdminWarning) {
- LOGGER.warn("No ConfigurationAdmin so cannot deploy configurations");
- loggedConfigAdminWarning = true;
- }
- } else {
- Properties properties = new Properties();
- InputStream in = new FileInputStream(file);
- try {
- properties.load(in);
- interpolation(properties);
- closeQuietly(in);
- String[] pid = parsePid(file);
- Hashtable<Object, Object> hashtable = new Hashtable<Object, Object>();
- hashtable.putAll(properties);
- hashtable.put(FILENAME, file.getName());
- Configuration config = getConfiguration(pid[0], pid[1]);
- if (config.getBundleLocation() != null) {
- config.setBundleLocation(null);
- }
- config.update(hashtable);
- } finally {
- closeQuietly(in);
- }
- }
- }
-
- protected void interpolation(Properties properties) {
- for (Enumeration e = properties.propertyNames(); e.hasMoreElements();) {
- String key = (String)e.nextElement();
- String val = properties.getProperty(key);
- Matcher matcher = Pattern.compile("\\$\\{([^}]+)\\}").matcher(val);
- while (matcher.find()) {
- String rep = System.getProperty(matcher.group(1));
- if (rep != null) {
- val = val.replace(matcher.group(0), rep);
- matcher.reset(val);
- }
- }
- properties.put(key, val);
- }
- }
-
- protected void deleteConfiguration(File file) throws IOException, InvalidSyntaxException {
- String[] pid = parsePid(file);
- Configuration config = getConfiguration(pid[0], pid[1]);
- config.delete();
- }
-
- protected Configuration getConfiguration(String pid, String factoryPid) throws IOException, InvalidSyntaxException {
- Configuration oldConfiguration = findExistingConfiguration(pid, factoryPid);
- if (oldConfiguration != null) {
- return oldConfiguration;
- } else {
- ConfigurationAdmin configurationAdmin = activator.getConfigurationAdmin();
- if (factoryPid != null) {
- return configurationAdmin.createFactoryConfiguration(pid, null);
- } else {
- return configurationAdmin.getConfiguration(pid, null);
- }
- }
- }
-
- protected Configuration findExistingConfiguration(String pid, String factoryPid) throws IOException, InvalidSyntaxException {
- String suffix = factoryPid == null ? ".cfg" : "-" + factoryPid + ".cfg";
- ConfigurationAdmin cm = activator.getConfigurationAdmin();
- String filter = "(" + FILENAME + "=" + pid + suffix + ")";
- Configuration[] configurations = cm.listConfigurations(filter);
- if (configurations != null && configurations.length > 0)
- {
- return configurations[0];
- }
- else
- {
- return null;
- }
- }
-
- protected String[] parsePid(File file) {
- String path = file.getName();
- String pid = path.substring(0, path.length() - 4);
- int n = pid.indexOf('-');
- if (n > 0) {
- String factoryPid = pid.substring(n + 1);
- pid = pid.substring(0, n);
- return new String[] {pid, factoryPid};
- } else {
- return new String[] {pid, null};
- }
- }
-
- protected PackageAdmin getPackageAdmin() {
- ServiceTracker packageAdminTracker = activator.getPackageAdminTracker();
- if (packageAdminTracker != null) {
- try {
- return (PackageAdmin)packageAdminTracker.waitForService(5000L);
- } catch (InterruptedException e) {
- // ignore
- }
- }
- return null;
- }
-
- protected boolean isBundleFragment(Bundle bundle) {
- PackageAdmin packageAdmin = getPackageAdmin();
- if (packageAdmin != null) {
- return packageAdmin.getBundleType(bundle) == PackageAdmin.BUNDLE_TYPE_FRAGMENT;
- }
- return false;
- }
-
- protected void refreshPackagesAndStartOrUpdateBundles() {
- for (Bundle bundle : bundlesToUpdate) {
- try {
- bundle.update();
- LOGGER.info("Updated: " + bundle);
- } catch (BundleException e) {
- LOGGER.warn("Failed to update bundle: " + bundle + ". Reason: " + e, e);
- }
- }
-
- for (Bundle bundle : bundlesToStart) {
- try {
- bundle.start();
- LOGGER.info("Started: " + bundle);
- } catch (BundleException e) {
- LOGGER.warn("Failed to start bundle: " + bundle + ". Reason: " + e, e);
- rescheduleStart(bundle);
- }
- }
-
- PackageAdmin packageAdmin = getPackageAdmin();
- if (packageAdmin != null) {
- packageAdmin.refreshPackages(null);
- }
- }
-
- private void rescheduleStart(Bundle bundle) {
- synchronized (pendingStartBundles) {
- pendingStartBundles.add(bundle);
- if (bundleListener == null) {
- bundleListener = new BundleListener() {
- public void bundleChanged(BundleEvent event) {
- if (event.getType() == BundleEvent.RESOLVED) {
- executor.execute(new Runnable() {
- public void run() {
- retryPendingStartBundles();
- }
- });
- } else if (event.getType() == BundleEvent.UNINSTALLED) {
- // bundle was uninstalled meanwhile, so remove
- // it from the list of pending bundles
- pendingStartBundles.remove(event.getBundle());
- }
- }
- };
- getContext().addBundleListener(bundleListener);
- }
- }
- }
-
- protected void retryPendingStartBundles() {
- synchronized (pendingStartBundles) {
- Set<Bundle> bundles = new HashSet<Bundle>();
- bundles.addAll(pendingStartBundles);
- pendingStartBundles.clear();
- boolean success = false;
- for (Bundle bundle : bundles) {
- try {
- bundle.start();
- LOGGER.info("Pending bundle started: " + bundle);
- success = true;
- } catch (BundleException e) {
- LOGGER.info("Pending bundle not started: " + bundle);
- pendingStartBundles.add(bundle);
- }
- }
- if (success) {
- PackageAdmin packageAdmin = getPackageAdmin();
- if (packageAdmin != null) {
- packageAdmin.refreshPackages(null);
- }
- }
- }
- }
-
- protected File createBundleJar(File dir) throws BundleException, IOException {
- File destFile = new File(generateDir, dir.getName() + ".jar");
- if (destFile.exists()) {
- undeployBundle(destFile);
- destFile.delete();
- }
- JarUtil.jarDir(dir.getPath(), destFile.getPath());
- return destFile;
- }
-
- /**
- * Returns the root directory of the expanded OSGi bundle if the file is
- * part of an expanded OSGi bundle or null if it is not
- */
- protected File getExpandedBundleRootDirectory(File file) throws IOException {
- File parent = file.getParentFile();
- if (file.isDirectory()) {
- String rootPath = deployDir.getCanonicalPath();
- if (file.getCanonicalPath().equals(rootPath)) {
- return null;
- }
- if (containsManifest(file)) {
- return file;
- }
- }
- if (isValidBundleSourceDirectory(parent)) {
- return getExpandedBundleRootDirectory(parent);
- }
- return null;
- }
-
- /**
- * Returns true if the given directory is a valid child directory within the
- * {@link #deployDir}
- */
- protected boolean isValidBundleSourceDirectory(File dir) throws IOException {
- if (dir != null) {
- String parentPath = dir.getCanonicalPath();
- String rootPath = deployDir.getCanonicalPath();
- return !parentPath.equals(rootPath) && parentPath.startsWith(rootPath);
- } else {
- return false;
- }
- }
-
- /**
- * Returns true if the given directory is a valid child file within the
- * {@link #deployDir} or a child of {@link #generateDir}
- */
- protected boolean isValidArtifactFile(File file) throws IOException {
- if (file != null) {
- String filePath = file.getParentFile().getCanonicalPath();
- String deployPath = deployDir.getCanonicalPath();
- String generatePath = generateDir.getCanonicalPath();
- return filePath.equals(deployPath) || filePath.startsWith(generatePath);
- } else {
- return false;
- }
- }
-
- /**
- * Returns true if the given directory is a valid child file within the
- * {@link #configDir}
- */
- protected boolean isValidConfigFile(File file) throws IOException {
- if (file != null && file.getName().endsWith(".cfg")) {
- String filePath = file.getParentFile().getCanonicalPath();
- String configPath = configDir.getCanonicalPath();
- return filePath.equals(configPath);
- } else {
- return false;
- }
- }
-
- /**
- * Returns true if the given directory contains a valid manifest file
- */
- protected boolean containsManifest(File dir) {
- File metaInfDir = new File(dir, "META-INF");
- if (metaInfDir.exists() && metaInfDir.isDirectory()) {
- File manifest = new File(metaInfDir, "MANIFEST.MF");
- return manifest.exists() && !manifest.isDirectory();
- }
- return false;
- }
-
- @SuppressWarnings("unchecked")
- protected File getFileValue(Dictionary properties, String key) {
- Object value = properties.get(key);
- if (value instanceof File) {
- return (File)value;
- } else if (value != null) {
- return new File(value.toString());
- }
- return null;
- }
-
- @SuppressWarnings("unchecked")
- protected Long getLongValue(Dictionary properties, String key) {
- Object value = properties.get(key);
- if (value instanceof Long) {
- return (Long)value;
- } else if (value != null) {
- return Long.parseLong(value.toString());
- }
- return null;
- }
-
- protected void closeQuietly(Closeable in) {
- try {
- in.close();
- } catch (IOException e) {
- LOGGER.warn("Failed to close stream. " + e, e);
- }
- }
-
- protected PreferencesService getPreferenceService() {
- if (activator.getPreferenceServiceTracker() != null) {
- try {
- return (PreferencesService)activator.getPreferenceServiceTracker().waitForService(5000L);
- } catch (InterruptedException e) {
- // ignore
- }
- }
- return null;
- }
-
- protected void saveScannerState() {
- try {
- Map<String, Long> results = scanner.getLastScanResults();
- Preferences prefs = getPreferenceService().getUserPreferences(PREFERENCE_KEY).node(pid);
- Iterator<String> it = results.keySet().iterator();
- while (it.hasNext()) {
- String key = it.next();
- Long value = results.get(key);
- prefs.putLong(key, value);
- }
- prefs.flush();
- } catch (Exception e) {
- LOGGER.error("Error persisting FileMonitor state", e);
- }
- }
-
- protected void loadScannerState() {
- try {
- Preferences prefs = getPreferenceService().getUserPreferences(PREFERENCE_KEY).node(pid);
- Map<String, Long> lastResult = new HashMap<String, Long>();
- for (String key : prefs.keys()) {
- lastResult.put(key, prefs.getLong(key, -1));
- }
- scanner.setLastScanResults(lastResult);
- } catch (Exception e) {
- LOGGER.error("Error loading FileMonitor state", e);
- }
- }
-}
diff --git a/karaf/deployer/filemonitor/src/main/java/org/apache/felix/karaf/deployer/filemonitor/FileMonitorActivator.java b/karaf/deployer/filemonitor/src/main/java/org/apache/felix/karaf/deployer/filemonitor/FileMonitorActivator.java
deleted file mode 100644
index 8ce5eee..0000000
--- a/karaf/deployer/filemonitor/src/main/java/org/apache/felix/karaf/deployer/filemonitor/FileMonitorActivator.java
+++ /dev/null
@@ -1,146 +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.karaf.deployer.filemonitor;
-
-import java.util.Collection;
-import java.util.Dictionary;
-import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.Map;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.service.cm.ConfigurationAdmin;
-import org.osgi.service.cm.ConfigurationException;
-import org.osgi.service.cm.ManagedServiceFactory;
-import org.osgi.service.packageadmin.PackageAdmin;
-import org.osgi.service.prefs.PreferencesService;
-import org.osgi.util.tracker.ServiceTracker;
-
-/**
- * Inspired by <a href="http://www.aqute.biz/Code/FileInstall">FileInstall</a>
- * by Peter Kriens.
- *
- * @version $Revision: 1.1 $
- */
-public class FileMonitorActivator implements BundleActivator, ManagedServiceFactory {
- private static final Log LOGGER = LogFactory.getLog(FileMonitorActivator.class);
-
- private BundleContext context;
- private ServiceTracker packageAdminTracker;
- private ServiceTracker configurationAdminTracker;
- private ServiceTracker preferenceServiceTracker;
- private Map<String, FileMonitor> fileMonitors = new HashMap<String, FileMonitor>();
-
- // BundleActivator interface
- // -------------------------------------------------------------------------
- public void start(BundleContext context) throws Exception {
- this.context = context;
-
- Hashtable properties = new Hashtable();
- properties.put(Constants.SERVICE_PID, getName());
- context.registerService(ManagedServiceFactory.class.getName(), this, properties);
-
- packageAdminTracker = new ServiceTracker(context, PackageAdmin.class.getName(), null);
- packageAdminTracker.open();
-
- configurationAdminTracker = new ServiceTracker(context, ConfigurationAdmin.class.getName(), null);
- configurationAdminTracker.open();
-
- preferenceServiceTracker = new ServiceTracker(context, PreferencesService.class.getName(), null);
- preferenceServiceTracker.open();
-
- Hashtable initialProperties = new Hashtable();
- setPropertiesFromContext(initialProperties, FileMonitor.CONFIG_DIR, FileMonitor.DEPLOY_DIR,
- FileMonitor.GENERATED_JAR_DIR, FileMonitor.SCAN_INTERVAL);
- updated("initialPid", initialProperties);
- }
-
- public void stop(BundleContext context) throws Exception {
- Collection<FileMonitor> fileMonitors = this.fileMonitors.values();
- for (FileMonitor monitor : fileMonitors) {
- try {
- // stop the monitor
- monitor.stop();
- } catch (Exception e) {
- // Ignore
- }
- }
- this.fileMonitors.clear();
-
- preferenceServiceTracker.close();
- configurationAdminTracker.close();
- packageAdminTracker.close();
- }
-
- // ManagedServiceFactory interface
- // -------------------------------------------------------------------------
- public String getName() {
- return "org.apache.felix.karaf.deployer.filemonitor.FileMonitor";
- }
-
- public void updated(String pid, Dictionary properties) throws ConfigurationException {
- deleted(pid);
- FileMonitor monitor = new FileMonitor(this, properties, pid);
- fileMonitors.put(pid, monitor);
- monitor.start();
- }
-
- public void deleted(String pid) {
- FileMonitor monitor = fileMonitors.remove(pid);
- if (monitor != null) {
- monitor.stop();
- }
- }
-
- // Properties
- // -------------------------------------------------------------------------
- public BundleContext getContext() {
- return context;
- }
-
- public ServiceTracker getConfigurationAdminTracker() {
- return configurationAdminTracker;
- }
-
- public ServiceTracker getPackageAdminTracker() {
- return packageAdminTracker;
- }
-
- public ConfigurationAdmin getConfigurationAdmin() {
- return (ConfigurationAdmin)getConfigurationAdminTracker().getService();
- }
-
- public ServiceTracker getPreferenceServiceTracker() {
- return preferenceServiceTracker;
- }
-
- // Implementation methods
- // -------------------------------------------------------------------------
- protected void setPropertiesFromContext(Hashtable properties, String... keys) {
- for (String key : keys) {
- Object value = context.getProperty(key);
- if (value != null) {
- properties.put(key, value);
- }
- }
- }
-}
diff --git a/karaf/deployer/filemonitor/src/main/java/org/apache/felix/karaf/deployer/filemonitor/JarUtil.java b/karaf/deployer/filemonitor/src/main/java/org/apache/felix/karaf/deployer/filemonitor/JarUtil.java
deleted file mode 100644
index ecf5bb9..0000000
--- a/karaf/deployer/filemonitor/src/main/java/org/apache/felix/karaf/deployer/filemonitor/JarUtil.java
+++ /dev/null
@@ -1,122 +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.karaf.deployer.filemonitor;
-
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.Collections;
-import java.util.Set;
-import java.util.jar.JarFile;
-import java.util.jar.JarOutputStream;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipOutputStream;
-
-public class JarUtil {
-
- /**
- * Zip up a directory
- *
- * @param directory
- * @param zipName
- * @throws IOException
- */
- public static void zipDir(String directory, String zipName) throws IOException {
- // create a ZipOutputStream to zip the data to
- ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipName)));
- String path = "";
- zipDir(directory, zos, path, Collections.<String>emptySet());
- // close the stream
- zos.close();
- }
-
- /**
- * Jar up a directory
- *
- * @param directory
- * @param zipName
- * @throws IOException
- */
- public static void jarDir(String directory, String zipName) throws IOException {
- // create a ZipOutputStream to zip the data to
- JarOutputStream zos = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(zipName)));
- String path = "";
- File manFile = new File(directory, JarFile.MANIFEST_NAME);
- if (manFile.exists()) {
- byte[] readBuffer = new byte[8192];
- FileInputStream fis = new FileInputStream(manFile);
- try {
- ZipEntry anEntry = new ZipEntry(JarFile.MANIFEST_NAME);
- zos.putNextEntry(anEntry);
- int bytesIn = fis.read(readBuffer);
- while (bytesIn != -1) {
- zos.write(readBuffer, 0, bytesIn);
- bytesIn = fis.read(readBuffer);
- }
- } finally {
- fis.close();
- }
- zos.closeEntry();
- }
- zipDir(directory, zos, path, Collections.singleton(JarFile.MANIFEST_NAME));
- // close the stream
- zos.close();
- }
-
- /**
- * Zip up a directory path
- * @param directory
- * @param zos
- * @param path
- * @throws IOException
- */
- public static void zipDir(String directory, ZipOutputStream zos, String path, Set<String> exclusions) throws IOException {
- File zipDir = new File(directory);
- // get a listing of the directory content
- String[] dirList = zipDir.list();
- byte[] readBuffer = new byte[8192];
- int bytesIn = 0;
- // loop through dirList, and zip the files
- for (int i = 0; i < dirList.length; i++) {
- File f = new File(zipDir, dirList[i]);
- if (f.isDirectory()) {
- String filePath = f.getPath();
- zipDir(filePath, zos, path + f.getName() + "/", exclusions);
- continue;
- }
- String entry = path + f.getName();
- if (!exclusions.contains(entry)) {
- FileInputStream fis = new FileInputStream(f);
- try {
- ZipEntry anEntry = new ZipEntry(entry);
- zos.putNextEntry(anEntry);
- bytesIn = fis.read(readBuffer);
- while (bytesIn != -1) {
- zos.write(readBuffer, 0, bytesIn);
- bytesIn = fis.read(readBuffer);
- }
- } finally {
- fis.close();
- }
- }
- }
- }
-
-}
diff --git a/karaf/deployer/filemonitor/src/main/java/org/apache/felix/karaf/deployer/filemonitor/Scanner.java b/karaf/deployer/filemonitor/src/main/java/org/apache/felix/karaf/deployer/filemonitor/Scanner.java
deleted file mode 100644
index 0c109a0..0000000
--- a/karaf/deployer/filemonitor/src/main/java/org/apache/felix/karaf/deployer/filemonitor/Scanner.java
+++ /dev/null
@@ -1,455 +0,0 @@
-//========================================================================
-//$Id: Scanner.java 2180 2007-10-31 04:01:26Z janb $
-//Copyright 2006 Mort Bay Consulting Pty. Ltd.
-//------------------------------------------------------------------------
-//Licensed 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.karaf.deployer.filemonitor;
-
-import java.io.File;
-import java.io.FilenameFilter;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.Timer;
-import java.util.TimerTask;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * Scanner
- * <p/>
- * Utility for scanning a directory for added, removed and changed files and
- * reporting these events via registered Listeners.
- * <p/>
- * From the <a href="http://jetty.codehaus.org/">Jetty Util project</a>
- *
- * @version $Revision: 1.1 $
- */
-public class Scanner {
-
- private static Log logger = LogFactory.getLog(Scanner.class);
- private long _scanInterval;
- private List<Listener> _listeners = Collections.synchronizedList(new ArrayList<Listener>());
- private Map<String, Long> _prevScan = new HashMap<String, Long>();
- private FilenameFilter _filter;
- private List<File> _scanDirs;
- private volatile boolean _running = false;
- private boolean _reportExisting = true;
- private Timer _timer;
- private TimerTask _task;
-
- /**
- * Listener
- * <p/>
- * Marker for notifications re file changes.
- */
- public interface Listener {
- }
-
- public interface DiscreteListener extends Listener {
- public void fileChanged(String filename) throws Exception;
-
- public void fileAdded(String filename) throws Exception;
-
- public void fileRemoved(String filename) throws Exception;
- }
-
- public interface BulkListener extends Listener {
- public void filesChanged(List<String> filenames) throws Exception;
- }
-
- /**
- *
- */
- public Scanner() {
- }
-
- /**
- * Get the scan interval
- *
- * @return interval between scans in millis
- */
- public long getScanInterval() {
- return _scanInterval;
- }
-
- /**
- * Set the scan interval
- *
- * @param scanInterval pause between scans in millis
- */
- public synchronized void setScanInterval(long scanInterval) {
- this._scanInterval = scanInterval;
-
- if (_running) {
- stop();
-
- _timer = newTimer();
- _task = newTimerTask();
-
- schedule(_timer, _task);
- _running = true;
- }
- }
-
- /**
- * Set the location of the directory to scan.
- *
- * @param dir
- * @deprecated use setScanDirs(List dirs) instead
- */
- public void setScanDir(File dir) {
- _scanDirs = new ArrayList<File>();
- _scanDirs.add(dir);
- }
-
- /**
- * Get the location of the directory to scan
- *
- * @return
- * @deprecated use getScanDirs() instead
- */
- public File getScanDir() {
- return (_scanDirs == null ? null : (File)_scanDirs.get(0));
- }
-
- public void setScanDirs(List<File> dirs) {
- _scanDirs = dirs;
- }
-
- public List<File> getScanDirs() {
- return _scanDirs;
- }
-
- /**
- * Apply a filter to files found in the scan directory. Only files matching
- * the filter will be reported as added/changed/removed.
- *
- * @param filter
- */
- public void setFilenameFilter(FilenameFilter filter) {
- this._filter = filter;
- }
-
- /**
- * Get any filter applied to files in the scan dir.
- *
- * @return
- */
- public FilenameFilter getFilenameFilter() {
- return _filter;
- }
-
- /**
- * Whether or not an initial scan will report all files as being added.
- *
- * @param reportExisting if true, all files found on initial scan will be
- * reported as being added, otherwise not
- */
- public void setReportExistingFilesOnStartup(boolean reportExisting) {
- this._reportExisting = reportExisting;
- }
-
- /**
- * Add an added/removed/changed listener
- *
- * @param listener
- */
- public synchronized void addListener(Listener listener) {
- if (listener == null) {
- return;
- }
-
- _listeners.add(listener);
- }
-
- /**
- * Remove a registered listener
- *
- * @param listener the Listener to be removed
- */
- public synchronized void removeListener(Listener listener) {
- if (listener == null) {
- return;
- }
- _listeners.remove(listener);
- }
-
- /**
- * Start the scanning action.
- */
- public synchronized void start() {
- if (_running) {
- return;
- }
-
- _running = true;
-
- if (_reportExisting) {
- // if files exist at startup, report them
- scan();
- } else {
- // just register the list of existing files and only report changes
- _prevScan = scanFiles();
- }
-
- _timer = newTimer();
- _task = newTimerTask();
-
- schedule(_timer, _task);
- }
-
- public TimerTask newTimerTask() {
- return new TimerTask() {
- public void run() {
- scan();
- }
- };
- }
-
- public Timer newTimer() {
- return new Timer(true);
- }
-
- public void schedule(Timer timer, TimerTask task) {
- if (timer == null) {
- throw new IllegalArgumentException("Timer is null");
- }
- if (task == null) {
- throw new IllegalArgumentException("TimerTask is null");
- }
-
- if (getScanInterval() > 0) {
- timer.scheduleAtFixedRate(task, getScanInterval(), getScanInterval());
- }
- }
-
- /**
- * Stop the scanning.
- */
- public synchronized void stop() {
- if (_running) {
- _running = false;
- _timer.cancel();
- _task.cancel();
- _task = null;
- _timer = null;
- }
- }
-
- /**
- * Perform a pass of the scanner and report changes
- */
- public void scan() {
- Map<String, Long> currentScan = scanFiles();
- reportDifferences(currentScan, _prevScan);
- _prevScan = currentScan;
- }
-
- /**
- * Recursively scan all files in the designated directories.
- *
- * @return Map of name of file to last modified time
- */
- public Map<String, Long> scanFiles() {
- if (_scanDirs == null) {
- return Collections.emptyMap();
- }
-
- HashMap<String, Long> scanInfo = new HashMap<String, Long>();
- Iterator<File> itor = _scanDirs.iterator();
- while (itor.hasNext()) {
- File dir = (File)itor.next();
-
- if ((dir != null) && (dir.exists())) {
- scanFile(dir, scanInfo);
- }
- }
-
- return scanInfo;
- }
-
- /**
- * Report the adds/changes/removes to the registered listeners
- *
- * @param currentScan the info from the most recent pass
- * @param oldScan info from the previous pass
- */
- public void reportDifferences(Map<String, Long> currentScan, Map<String, Long> oldScan) {
- List<String> bulkChanges = new ArrayList<String>();
-
- Set<String> oldScanKeys = new HashSet<String>(oldScan.keySet());
- Iterator<Map.Entry<String, Long>> itor = currentScan.entrySet().iterator();
- while (itor.hasNext()) {
- Map.Entry<String, Long> entry = itor.next();
- if (!oldScanKeys.contains(entry.getKey())) {
- logger.debug("File added: " + entry.getKey());
- reportAddition(entry.getKey());
- bulkChanges.add(entry.getKey());
- } else if (!oldScan.get(entry.getKey()).equals(entry.getValue())) {
- logger.debug("File changed: " + entry.getKey());
- reportChange(entry.getKey());
- oldScanKeys.remove(entry.getKey());
- bulkChanges.add(entry.getKey());
- } else {
- oldScanKeys.remove(entry.getKey());
- }
- }
-
- if (!oldScanKeys.isEmpty()) {
-
- Iterator<String> keyItor = oldScanKeys.iterator();
- while (keyItor.hasNext()) {
- String filename = keyItor.next();
- logger.debug("File removed: " + filename);
- reportRemoval(filename);
- bulkChanges.add(filename);
- }
- }
-
- if (!bulkChanges.isEmpty()) {
- reportBulkChanges(bulkChanges);
- }
- }
-
- /**
- * Get last modified time on a single file or recurse if the file is a
- * directory.
- *
- * @param f file or directory
- * @param scanInfoMap map of filenames to last modified times
- */
- private void scanFile(File f, Map<String, Long> scanInfoMap) {
- try {
- if (!f.exists()) {
- return;
- }
-
- if (f.isFile()) {
- if ((_filter == null)
- || ((_filter != null) && _filter.accept(f.getParentFile(), f.getName()))) {
- String name = f.getCanonicalPath();
- long lastModified = f.lastModified();
- scanInfoMap.put(name, new Long(lastModified));
- }
- } else if (f.isDirectory()) {
- File[] files = f.listFiles();
- for (int i = 0; i < files.length; i++) {
- scanFile(files[i], scanInfoMap);
- }
- }
- } catch (IOException e) {
- logger.warn("Error scanning watched files", e);
- }
- }
-
- /**
- * Report a file addition to the registered FileAddedListeners
- *
- * @param filename
- */
- private void reportAddition(String filename) {
- Iterator<Listener> itor = _listeners.iterator();
- while (itor.hasNext()) {
- try {
- Listener l = itor.next();
- if (l instanceof DiscreteListener) {
- ((DiscreteListener)l).fileAdded(filename);
- }
- } catch (Exception e) {
- logger.warn(e);
- } catch (Error e) {
- logger.warn(e);
- }
- }
- }
-
- /**
- * Report a file removal to the FileRemovedListeners
- *
- * @param filename
- */
- private void reportRemoval(String filename) {
- Iterator<Listener> itor = _listeners.iterator();
- while (itor.hasNext()) {
- try {
- Listener l = itor.next();
- if (l instanceof DiscreteListener) {
- ((DiscreteListener)l).fileRemoved(filename);
- }
- } catch (Exception e) {
- logger.warn(e);
- } catch (Error e) {
- logger.warn(e);
- }
- }
- }
-
- /**
- * Report a file change to the FileChangedListeners
- *
- * @param filename
- */
- private void reportChange(String filename) {
- Iterator<Listener> itor = _listeners.iterator();
- while (itor.hasNext()) {
- try {
- Listener l = itor.next();
- if (l instanceof DiscreteListener) {
- ((DiscreteListener)l).fileChanged(filename);
- }
- } catch (Exception e) {
- logger.warn(e);
- } catch (Error e) {
- logger.warn(e);
- }
- }
- }
-
- private void reportBulkChanges(List<String> filenames) {
- Iterator<Listener> itor = _listeners.iterator();
- while (itor.hasNext()) {
- try {
- Listener l = itor.next();
- if (l instanceof BulkListener) {
- ((BulkListener)l).filesChanged(filenames);
- }
- } catch (Exception e) {
- logger.warn(e);
- } catch (Error e) {
- logger.warn(e);
- }
- }
- }
-
- protected Map<String, Long> getLastScanResults() {
- Map<String, Long> result = new HashMap<String, Long>();
- synchronized (_prevScan) {
- result.putAll(_prevScan);
- }
- return result;
- }
-
- protected void setLastScanResults(Map<String, Long> results) {
- synchronized (_prevScan) {
- _prevScan.clear();
- _prevScan.putAll(results);
- }
- }
-}
diff --git a/karaf/deployer/filemonitor/src/test/data/camel-example-spring/META-INF/LICENSE.txt b/karaf/deployer/filemonitor/src/test/data/camel-example-spring/META-INF/LICENSE.txt
deleted file mode 100644
index 6b0b127..0000000
--- a/karaf/deployer/filemonitor/src/test/data/camel-example-spring/META-INF/LICENSE.txt
+++ /dev/null
@@ -1,203 +0,0 @@
-
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
-
- APPENDIX: How to apply the Apache License to your work.
-
- To apply the Apache License to your work, attach the following
- boilerplate notice, with the fields enclosed by brackets "[]"
- replaced with your own identifying information. (Don't include
- the brackets!) The text should be enclosed in the appropriate
- comment syntax for the file format. We also recommend that a
- file or class name and description of purpose be included on the
- same "printed page" as the copyright notice for easier
- identification within third-party archives.
-
- Copyright [yyyy] [name of copyright owner]
-
- Licensed 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.
-
diff --git a/karaf/deployer/filemonitor/src/test/data/camel-example-spring/META-INF/MANIFEST.MF b/karaf/deployer/filemonitor/src/test/data/camel-example-spring/META-INF/MANIFEST.MF
deleted file mode 100644
index 15e6aae..0000000
--- a/karaf/deployer/filemonitor/src/test/data/camel-example-spring/META-INF/MANIFEST.MF
+++ /dev/null
@@ -1,24 +0,0 @@
-Manifest-Version: 1.0
-Created-By: 1.5.0_07 (Apple Computer, Inc.)
-Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
-Import-Package: org.apache.camel.builder,org.apache.camel.example.spri
- ng;version=1.3.0.SNAPSHOT,org.apache.camel.model,org.apache.camel.spr
- ing
-Include-Resource: src/main/resources
-Bnd-LastModified: 1195835480265
-Export-Package: org.apache.camel.example.spring;uses:="org.apache.came
- l.model,org.apache.camel.builder,org.apache.camel.spring";version=1.3
- .0.SNAPSHOT
-Bundle-Version: 1.3.0.SNAPSHOT
-Bundle-Name: camel-example-spring
-Bundle-Description: An example showing how to work with Camel and Spri
- ng
-Private-Package: META-INF.spring
-Bundle-DocURL: http://www.apache.org/
-Bundle-Vendor: Apache Software Foundation
-Bundle-ManifestVersion: 2
-Implementation-Title: Apache Camel
-Bundle-SymbolicName: org.apache.camel.camel-example-spring
-Tool: Bnd-0.0.160
-Implementation-Version: 1.3-SNAPSHOT
-
diff --git a/karaf/deployer/filemonitor/src/test/data/camel-example-spring/META-INF/NOTICE.txt b/karaf/deployer/filemonitor/src/test/data/camel-example-spring/META-INF/NOTICE.txt
deleted file mode 100644
index 2e215bf..0000000
--- a/karaf/deployer/filemonitor/src/test/data/camel-example-spring/META-INF/NOTICE.txt
+++ /dev/null
@@ -1,11 +0,0 @@
- =========================================================================
- == NOTICE file corresponding to the section 4 d of ==
- == the Apache License, Version 2.0, ==
- == in this case for the Apache Camel distribution. ==
- =========================================================================
-
- This product includes software developed by
- The Apache Software Foundation (http://www.apache.org/).
-
- Please read the different LICENSE files present in the licenses directory of
- this distribution.
diff --git a/karaf/deployer/filemonitor/src/test/data/camel-example-spring/META-INF/spring/camel-context.xml b/karaf/deployer/filemonitor/src/test/data/camel-example-spring/META-INF/spring/camel-context.xml
deleted file mode 100644
index eb2c42a..0000000
--- a/karaf/deployer/filemonitor/src/test/data/camel-example-spring/META-INF/spring/camel-context.xml
+++ /dev/null
@@ -1,70 +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.
--->
-
-<!--
-
- The default Application Context used by the org.apache.camel.spring.Main if there
- is no /META-INF/sprint.xml
-
- -->
-
-<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
- http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd">
-
- <camelContext id="camel" useJmx="true" mbeanServer="mbeanServer"
- xmlns="http://activemq.apache.org/camel/schema/spring">
- <package>org.apache.camel.example.spring</package>
- </camelContext>
-
- <!-- lets configure the default ActiveMQ broker URL -->
- <bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
- <property name="connectionFactory">
- <bean class="org.apache.activemq.ActiveMQConnectionFactory">
- <property name="brokerURL" value="vm://localhost?broker.persistent=false&broker.useJmx=false"/>
- </bean>
- </property>
- </bean>
-
- <!-- Use JMX -->
- <bean id="agent" class="org.apache.camel.spring.SpringInstrumentationAgent">
- <property name="MBeanServer" ref="mbeanServer"/>
- </bean>
-
- <!--
- this bean needs to be eagerly pre-instantiated in order for the exporting to occur;
- this means that it must not be marked as lazily initialized
- -->
- <bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean">
- <property name="defaultDomain" value="org.apache.camel.test"/>
- </bean>
- <bean id="registry" class="org.springframework.remoting.rmi.RmiRegistryFactoryBean">
- <property name="port" value="1099"/>
- </bean>
- <bean id="serverConnector"
- class="org.springframework.jmx.support.ConnectorServerFactoryBean" depends-on="registry">
- <property name="objectName" value="connector:name=rmi"/>
- <property name="serviceUrl"
- value="service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi"/>
- <property name="threaded" value="true"/>
- <property name="daemon" value="true"/>
- </bean>
-
-</beans>
diff --git a/karaf/deployer/filemonitor/src/test/data/camel-example-spring/org/apache/camel/example/spring/MyRouteBuilder$SomeBean.class b/karaf/deployer/filemonitor/src/test/data/camel-example-spring/org/apache/camel/example/spring/MyRouteBuilder$SomeBean.class
deleted file mode 100644
index 158c9da..0000000
--- a/karaf/deployer/filemonitor/src/test/data/camel-example-spring/org/apache/camel/example/spring/MyRouteBuilder$SomeBean.class
+++ /dev/null
Binary files differ
diff --git a/karaf/deployer/filemonitor/src/test/data/camel-example-spring/org/apache/camel/example/spring/MyRouteBuilder.class b/karaf/deployer/filemonitor/src/test/data/camel-example-spring/org/apache/camel/example/spring/MyRouteBuilder.class
deleted file mode 100644
index 79a433e..0000000
--- a/karaf/deployer/filemonitor/src/test/data/camel-example-spring/org/apache/camel/example/spring/MyRouteBuilder.class
+++ /dev/null
Binary files differ
diff --git a/karaf/deployer/filemonitor/src/test/data/foo/META-INF/MANIFEST.MF b/karaf/deployer/filemonitor/src/test/data/foo/META-INF/MANIFEST.MF
deleted file mode 100644
index 001dd22..0000000
--- a/karaf/deployer/filemonitor/src/test/data/foo/META-INF/MANIFEST.MF
+++ /dev/null
@@ -1,17 +0,0 @@
-Manifest-Version: 1.0
-License-00:
-License-01: Licensed to the Apache Software Foundation (ASF) under one or more
-License-02: contributor license agreements. See the NOTICE file distributed with
-License-03: this work for additional information regarding copyright ownership.
-License-04: The ASF licenses this file to You under the Apache License, Version 2.0
-License-05: (the "License"); you may not use this file except in compliance with
-License-06: the License. You may obtain a copy of the License at
-License-07:
-License-08: http://www.apache.org/licenses/LICENSE-2.0
-License-09:
-License-10: Unless required by applicable law or agreed to in writing, software
-License-11: distributed under the License is distributed on an "AS IS" BASIS,
-License-12: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-License-13: See the License for the specific language governing permissions and
-License-14: limitations under the License.
-License-15:
diff --git a/karaf/deployer/filemonitor/src/test/data/foo/foo.txt b/karaf/deployer/filemonitor/src/test/data/foo/foo.txt
deleted file mode 100644
index c094a79..0000000
--- a/karaf/deployer/filemonitor/src/test/data/foo/foo.txt
+++ /dev/null
@@ -1,18 +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.
- */
-Hey!
\ No newline at end of file
diff --git a/karaf/deployer/filemonitor/src/test/java/org/apache/felix/karaf/deployer/filemonitor/BundlePackerTest.java b/karaf/deployer/filemonitor/src/test/java/org/apache/felix/karaf/deployer/filemonitor/BundlePackerTest.java
deleted file mode 100644
index be60315..0000000
--- a/karaf/deployer/filemonitor/src/test/java/org/apache/felix/karaf/deployer/filemonitor/BundlePackerTest.java
+++ /dev/null
@@ -1,42 +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.karaf.deployer.filemonitor;
-
-import junit.framework.TestCase;
-
-/**
- * @version $Revision: 1.1 $
- */
-public class BundlePackerTest extends TestCase {
- public void testFiles() throws Exception {
-/*
- File bundleDir = new File("target/deploy");
- File unpackDir = new File("target/data");
- FileUtils.deleteDirectory(unpackDir);
-
- bundleDir.mkdirs();
- unpackDir.mkdirs();
-
- FileUtils.copyDirectory(new File("src/test/data"), unpackDir);
-
- FileMonitor packer = new FileMonitor(bundleDir, unpackDir);
- packer.scan();
-*/
- }
-
-}
diff --git a/karaf/deployer/filemonitor/src/test/java/org/apache/felix/karaf/deployer/filemonitor/FileMonitorTest.java b/karaf/deployer/filemonitor/src/test/java/org/apache/felix/karaf/deployer/filemonitor/FileMonitorTest.java
deleted file mode 100644
index 0db1953..0000000
--- a/karaf/deployer/filemonitor/src/test/java/org/apache/felix/karaf/deployer/filemonitor/FileMonitorTest.java
+++ /dev/null
@@ -1,100 +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.karaf.deployer.filemonitor;
-
-import junit.framework.TestCase;
-import org.apache.felix.karaf.deployer.filemonitor.FileMonitor;
-
-/**
- * FileMonitor Tester.
- *
- * @author <Authors name>
- * @version 1.0
- * @since <pre>07/02/2008</pre>
- */
-public class FileMonitorTest extends TestCase {
-
- public FileMonitorTest(String name) {
- super(name);
- }
-
- public void setUp() throws Exception {
- super.setUp();
- }
-
- public void tearDown() throws Exception {
- super.tearDown();
- }
-
- public void testFilePathsMatch() throws Exception {
- assertTrue(FileMonitor.filePathsMatch(
- "C:/Apps/apache-felix-karaf-1.0.0-rc1/src/README.txt",
- "C:/Apps/apache-felix-karaf-1.0.0-rc1/src/README.txt"));
-
- assertTrue(FileMonitor.filePathsMatch(
- "C:\\Apps\\apache-felix-karaf-1.0.0-rc1\\src\\README.txt",
- "C:\\Apps\\apache-felix-karaf-1.0.0-rc1\\src\\README.txt"));
-
- assertTrue(FileMonitor.filePathsMatch(
- "C:/Apps/apache-felix-karaf-1.0.0-rc1/src/README.txt",
- "C:\\Apps\\apache-felix-karaf-1.0.0-rc1\\src\\README.txt"));
-
- assertTrue(FileMonitor.filePathsMatch(
- "file:/C:/Apps/apache-felix-karaf-1.0.0-rc1/src/README.txt",
- "C:\\Apps\\apache-felix-karaf-1.0.0-rc1\\src\\README.txt"));
-
- assertTrue(FileMonitor.filePathsMatch(
- "file://C:/Apps/apache-felix-karaf-1.0.0-rc1/src/README.txt",
- "C:\\Apps\\apache-felix-karaf-1.0.0-rc1\\src\\README.txt"));
- }
-
- public void testNormalizeFilePath() throws Exception {
- assertEquals(
- "C:/Apps/apache-felix-karaf-1.0.0-rc1/src/README.txt",
- FileMonitor.normalizeFilePath("C:/Apps/apache-felix-karaf-1.0.0-rc1/src/README.txt"));
-
- assertEquals(
- "C:/Apps/apache-felix-karaf-1.0.0-rc1/src/README.txt",
- FileMonitor.normalizeFilePath("C:/Apps//apache-felix-karaf-1.0.0-rc1////src/////README.txt"));
-
- assertEquals(
- "C:/Apps/apache-felix-karaf-1.0.0-rc1/src/README.txt",
- FileMonitor.normalizeFilePath("C:\\Apps\\apache-felix-karaf-1.0.0-rc1\\src\\README.txt"));
-
- assertEquals(
- "C:/Apps/apache-felix-karaf-1.0.0-rc1/src/README.txt",
- FileMonitor.normalizeFilePath("C:\\\\Apps\\\\apache-felix-karaf-1.0.0-rc1\\\\src\\\\README.txt"));
-
- assertEquals(
- "C:/Apps/apache-felix-karaf-1.0.0-rc1/src/README.txt",
- FileMonitor.normalizeFilePath("C:\\Apps\\//apache-felix-karaf-1.0.0-rc1\\/\\src///\\\\README.txt"));
-
- assertEquals(
- "C:/Apps/apache-felix-karaf-1.0.0-rc1/src/README.txt",
- FileMonitor.normalizeFilePath("file:C:/Apps/apache-felix-karaf-1.0.0-rc1/src/README.txt"));
-
- assertEquals(
- "C:/Apps/apache-felix-karaf-1.0.0-rc1/src/README.txt",
- FileMonitor.normalizeFilePath("file:/C:/Apps/apache-felix-karaf-1.0.0-rc1/src/README.txt"));
-
- assertEquals(
- "C:/Apps/apache-felix-karaf-1.0.0-rc1/src/README.txt",
- FileMonitor.normalizeFilePath("file://C:/Apps/apache-felix-karaf-1.0.0-rc1/src/README.txt"));
- }
-
-}
diff --git a/karaf/deployer/pom.xml b/karaf/deployer/pom.xml
index 067a04a..d4606eb 100644
--- a/karaf/deployer/pom.xml
+++ b/karaf/deployer/pom.xml
@@ -34,7 +34,6 @@
<name>Apache Felix Karaf :: Deployer</name>
<modules>
- <module>filemonitor</module>
<module>spring</module>
<module>blueprint</module>
<module>features</module>
diff --git a/karaf/deployer/spring/pom.xml b/karaf/deployer/spring/pom.xml
index 55d0e95..e3ee5a6 100644
--- a/karaf/deployer/spring/pom.xml
+++ b/karaf/deployer/spring/pom.xml
@@ -46,8 +46,12 @@
<artifactId>spring-osgi-core</artifactId>
</dependency>
<dependency>
- <groupId>org.apache.felix.karaf.deployer</groupId>
- <artifactId>org.apache.felix.karaf.deployer.filemonitor</artifactId>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.fileinstall</artifactId>
</dependency>
<dependency>
<groupId>org.apache.servicemix.bundles</groupId>
diff --git a/karaf/deployer/spring/src/main/java/org/apache/felix/karaf/deployer/spring/SpringDeploymentListener.java b/karaf/deployer/spring/src/main/java/org/apache/felix/karaf/deployer/spring/SpringDeploymentListener.java
index 7551f99..648cf1b 100644
--- a/karaf/deployer/spring/src/main/java/org/apache/felix/karaf/deployer/spring/SpringDeploymentListener.java
+++ b/karaf/deployer/spring/src/main/java/org/apache/felix/karaf/deployer/spring/SpringDeploymentListener.java
@@ -27,13 +27,13 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.felix.karaf.deployer.filemonitor.DeploymentListener;
+import org.apache.felix.fileinstall.listener.ArtifactTransformer;
/**
* A deployment listener that listens for spring xml applications
* and creates bundles for these.
*/
-public class SpringDeploymentListener implements DeploymentListener {
+public class SpringDeploymentListener implements ArtifactTransformer {
private static final Log LOGGER = LogFactory.getLog(SpringDeploymentListener.class);
@@ -55,7 +55,7 @@
return false;
}
- public File handle(File artifact, File tmpDir) {
+ public File transform(File artifact, File tmpDir) {
try {
File destFile = new File(tmpDir, artifact.getName() + ".jar");
FileOutputStream os = new FileOutputStream(destFile);
diff --git a/karaf/deployer/spring/src/main/resources/OSGI-INF/blueprint/spring-deployer.xml b/karaf/deployer/spring/src/main/resources/OSGI-INF/blueprint/spring-deployer.xml
index cb0c57b..6ec6a02 100644
--- a/karaf/deployer/spring/src/main/resources/OSGI-INF/blueprint/spring-deployer.xml
+++ b/karaf/deployer/spring/src/main/resources/OSGI-INF/blueprint/spring-deployer.xml
@@ -20,7 +20,7 @@
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:cm="http://www.osgi.org/xmlns/blueprint-cm/v1.0.0">
- <service interface="org.apache.felix.karaf.deployer.filemonitor.DeploymentListener">
+ <service auto-export="interfaces">
<bean class="org.apache.felix.karaf.deployer.spring.SpringDeploymentListener"/>
</service>
diff --git a/karaf/pom.xml b/karaf/pom.xml
index ff1f7f8..fbbd921 100644
--- a/karaf/pom.xml
+++ b/karaf/pom.xml
@@ -74,6 +74,7 @@
<felix.bundlerepository.version>1.4.0</felix.bundlerepository.version>
<felix.compendium.version>1.2.0</felix.compendium.version>
<felix.configadmin.version>1.0.4</felix.configadmin.version>
+ <felix.fileinstall.version>1.3.0-SNAPSHOT</felix.fileinstall.version>
<felix.framework.version>1.9.0-SNAPSHOT</felix.framework.version>
<felix.gogo.version>0.9.0-SNAPSHOT</felix.gogo.version>
<felix.osgi.version>1.3.0-SNAPSHOT</felix.osgi.version>
@@ -224,11 +225,13 @@
<artifactId>org.apache.felix.karaf.client</artifactId>
<version>${pom.version}</version>
</dependency>
+ <!--
<dependency>
<groupId>org.apache.felix.karaf.deployer</groupId>
<artifactId>org.apache.felix.karaf.deployer.filemonitor</artifactId>
<version>${pom.version}</version>
</dependency>
+ -->
<dependency>
<groupId>org.apache.felix.karaf.deployer</groupId>
<artifactId>org.apache.felix.karaf.deployer.spring</artifactId>
@@ -434,8 +437,8 @@
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.metatype</artifactId>
- <version>${felix.metatype.version}</version>
+ <artifactId>org.apache.felix.fileinstall</artifactId>
+ <version>${felix.fileinstall.version}</version>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>