You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by er...@apache.org on 2020/05/08 09:57:09 UTC

[plc4x] branch feature/osgi updated (1a70894 -> f2db740)

This is an automated email from the ASF dual-hosted git repository.

erobinet pushed a change to branch feature/osgi
in repository https://gitbox.apache.org/repos/asf/plc4x.git.


    from 1a70894  Merge branch 'feature/osgi' of https://github.com/apache/plc4x into feature/osgi
     add fd3e9d5  - Added the RequirePcap annotation to the RawSocketChannelTest
     add f6256a7  - Added Apache headers to the remaining README files.
     add a2fbff8  - Added two variants of an initial plc4c api
     add 0cf4505  - Made the Hello-Webapp runable outside of IntelliJ (There were problems preventing the application from starting correclty when run from the commandline)
     add 3396cf6  - Included Otto's proposal for a plc4c api - Removed the other alternatives that are now sort of obsolete
     add cf534c7  PLC4X-192 Support for connection string parameter conversion.
     add b38b9c1  Merge pull request #140 from ConnectorIO/PLC4X-192
     add d232005  Update linux.adoc
     add d8cda50  Update opc-ua.adoc
     add f036168  Update opc-ua.adoc
     add ad27607  Update ads.adoc
     add a61aaed  Update ads.adoc
     add e35b725  Update bacnetip.adoc
     add 83497c5  - Added a missing dependency
     add a4e9643  - Made the constants actually 16 bit values (cosmetics)
     add 6f4e81e  - Disabled the hello-webapp example as the Apache Royale folks seem unable to release.
     add b448eae  - Updated the RELEASE_NOTES in preparation of the next release
     add a1fe24c  - Made the OKs appear alligned with the rest.
     add 195df3b  - Made the autoVersionSubmodules a default setting for the release plugin - Removed the autoVersionSubmodules property from the documentation
     add c8748c3  - Added some more facts to the RELEASE_NOTES
     add 80767dd  Merge branch 'develop' into feature/osgi
     add 169f53b  Update ethernet-ip.adoc
     new 253abab  Merge branch 'develop' of https://github.com/apache/plc4x into feature/osgi
     new 238a249  OSGi Module -Generic Activators for Drivers and Transports -Add Bundle-Activator in Driver's/Transport's POM -Adapted EIP Feature generation
     new f2db740  OSGi Module -Adapted S7 Feature generation

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 RELEASE_NOTES                                      |  24 +-
 plc4j/api/pom.xml                                  |  20 +-
 .../java/org/apache/plc4x/java/DriverManager.java  |  30 ---
 .../org/apache/plc4x/java/PlcDriverManager.java    |   6 +-
 .../org/apache/plc4x/java/osgi/ApiActivator.java   | 104 --------
 .../apache/plc4x/java/osgi/OsgiDriverManager.java  |  81 ------
 plc4j/drivers/eip/pom.xml                          |   1 +
 .../knxnetip/protocol/KnxNetIpProtocolLogic.java   |   2 +-
 plc4j/drivers/s7/pom.xml                           |   1 +
 plc4j/examples/dummy-driver/pom.xml                |   1 -
 plc4j/examples/hello-connectivity-mqtt/pom.xml     |   5 +
 plc4j/examples/hello-storage-elasticsearch/pom.xml |   1 -
 plc4j/examples/hello-webapp/pom.xml                |   1 -
 plc4j/examples/hello-webapp/webapp/README.adoc     |  41 +++
 plc4j/examples/hello-webapp/webapp/pom.xml         |  66 ++++-
 .../src/main/resources/application.properties      |   3 +-
 plc4j/examples/pom.xml                             |   3 +-
 plc4j/karaf-features/eip/pom.xml                   |   6 +
 plc4j/karaf-features/s7/pom.xml                    |   5 +
 plc4j/{transports/pcap-shared => osgi}/pom.xml     |  30 ++-
 .../apache/plc4x/java/osgi/DriverActivator.java    |  53 ++++
 .../apache/plc4x/java/osgi/TransportActivator.java |  54 ++++
 plc4j/pom.xml                                      |   5 +-
 plc4j/spi/pom.xml                                  |   8 +-
 .../org/apache/plc4x/java/osgi/SpiActivator.java   |  89 -------
 .../spi/configuration/ConfigurationFactory.java    |  19 +-
 ...n.java => ConfigurationParameterConverter.java} |  23 +-
 ...ationParameter.java => ParameterConverter.java} |  13 +-
 plc4j/tools/capture-replay/pom.xml                 |   1 -
 plc4j/transports/tcp/pom.xml                       |   1 +
 .../rawsockets/netty/RawSocketChannelTest.java     |   2 +
 pom.xml                                            |   4 +-
 .../main/resources/protocols/amsads/amsads.mspec   |  20 +-
 sandbox/plc-simulator/pom.xml                      |   1 -
 sandbox/plc4c/CMakeLists.txt                       |   2 +-
 sandbox/plc4c/api/CMakeLists.txt                   |   3 +-
 sandbox/plc4c/api/src/main/include/plc4c.h         | 280 +++++++++++++++++++++
 .../README.adoc => plc4c/design-guidelines.adoc}   |  27 +-
 sandbox/plc4c/examples/hello-world/CMakeLists.txt  |   9 +-
 .../examples/hello-world/src/main/c/HelloWorld.c   |  30 ---
 .../examples/hello-world/src/main/c/hello_world.c  |  71 ++++++
 .../hello-world/src/main/include/HelloWorld.h      |  25 --
 sandbox/plc4c/spi/CMakeLists.txt                   |   7 +-
 sandbox/plc4c/spi/src/main/c/plc4c.c               | 100 ++++++++
 .../plc4c/spi/src/main/c/plc4c_private_types.c     |  23 +-
 .../amsads/configuration/AdsConfiguration.java     |  26 ++
 src/main/script/prerequisiteCheck.groovy           |   8 +-
 src/site/asciidoc/developers/preparing/linux.adoc  |   2 +-
 .../asciidoc/developers/release/build-tools.adoc   |   9 +-
 src/site/asciidoc/developers/release/release.adoc  |  13 +-
 src/site/asciidoc/users/protocols/ads.adoc         |  34 +++
 src/site/asciidoc/users/protocols/bacnetip.adoc    |  44 ++++
 src/site/asciidoc/users/protocols/ethernet-ip.adoc |  78 ++++++
 src/site/asciidoc/users/protocols/opc-ua.adoc      |  55 ++++
 54 files changed, 1087 insertions(+), 483 deletions(-)
 delete mode 100644 plc4j/api/src/main/java/org/apache/plc4x/java/DriverManager.java
 delete mode 100644 plc4j/api/src/main/java/org/apache/plc4x/java/osgi/ApiActivator.java
 delete mode 100644 plc4j/api/src/main/java/org/apache/plc4x/java/osgi/OsgiDriverManager.java
 create mode 100644 plc4j/examples/hello-webapp/webapp/README.adoc
 copy plc4j/{transports/pcap-shared => osgi}/pom.xml (66%)
 create mode 100644 plc4j/osgi/src/main/java/org/apache/plc4x/java/osgi/DriverActivator.java
 create mode 100644 plc4j/osgi/src/main/java/org/apache/plc4x/java/osgi/TransportActivator.java
 delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/osgi/SpiActivator.java
 copy plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/{Configuration.java => ConfigurationParameterConverter.java} (53%)
 copy plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/{ConfigurationParameter.java => ParameterConverter.java} (71%)
 create mode 100644 sandbox/plc4c/api/src/main/include/plc4c.h
 copy sandbox/{test-java-amsads-driver/README.adoc => plc4c/design-guidelines.adoc} (56%)
 delete mode 100644 sandbox/plc4c/examples/hello-world/src/main/c/HelloWorld.c
 create mode 100644 sandbox/plc4c/examples/hello-world/src/main/c/hello_world.c
 delete mode 100644 sandbox/plc4c/examples/hello-world/src/main/include/HelloWorld.h
 create mode 100644 sandbox/plc4c/spi/src/main/c/plc4c.c
 copy plc4j/transports/test/src/main/java/org/apache/plc4x/java/transport/test/TestSocketAddress.java => sandbox/plc4c/spi/src/main/c/plc4c_private_types.c (79%)


[plc4x] 01/03: Merge branch 'develop' of https://github.com/apache/plc4x into feature/osgi

Posted by er...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

erobinet pushed a commit to branch feature/osgi
in repository https://gitbox.apache.org/repos/asf/plc4x.git

commit 253abab6e371ac7415227150b2db5e039e7a6b8e
Merge: 80767dd 169f53b
Author: etiennerobinet <61...@users.noreply.github.com>
AuthorDate: Wed May 6 08:27:04 2020 +0200

    Merge branch 'develop' of https://github.com/apache/plc4x into feature/osgi

 src/site/asciidoc/users/protocols/ethernet-ip.adoc | 78 ++++++++++++++++++++++
 1 file changed, 78 insertions(+)


[plc4x] 02/03: OSGi Module -Generic Activators for Drivers and Transports -Add Bundle-Activator in Driver's/Transport's POM -Adapted EIP Feature generation

Posted by er...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

erobinet pushed a commit to branch feature/osgi
in repository https://gitbox.apache.org/repos/asf/plc4x.git

commit 238a249e371bb807b36016c92812a162865a5a9d
Author: Etienne Robinet <et...@gmail.com>
AuthorDate: Fri May 8 11:56:07 2020 +0200

    OSGi Module
    -Generic Activators for Drivers and Transports
    -Add Bundle-Activator in Driver's/Transport's POM
    -Adapted EIP Feature generation
---
 plc4j/api/pom.xml                                  |  20 +---
 .../java/org/apache/plc4x/java/DriverManager.java  |  30 ------
 .../org/apache/plc4x/java/PlcDriverManager.java    |   6 +-
 .../org/apache/plc4x/java/osgi/ApiActivator.java   | 104 ---------------------
 .../apache/plc4x/java/osgi/OsgiDriverManager.java  |  81 ----------------
 plc4j/drivers/eip/pom.xml                          |   1 +
 plc4j/drivers/s7/pom.xml                           |   1 +
 plc4j/karaf-features/eip/pom.xml                   |   6 ++
 plc4j/{karaf-features/eip => osgi}/pom.xml         |  50 ++++------
 .../apache/plc4x/java/osgi/DriverActivator.java    |  53 +++++++++++
 .../apache/plc4x/java/osgi/TransportActivator.java |  54 +++++++++++
 plc4j/pom.xml                                      |   5 +-
 plc4j/spi/pom.xml                                  |   8 +-
 .../org/apache/plc4x/java/osgi/SpiActivator.java   |  89 ------------------
 plc4j/transports/tcp/pom.xml                       |   1 +
 15 files changed, 142 insertions(+), 367 deletions(-)

diff --git a/plc4j/api/pom.xml b/plc4j/api/pom.xml
index 4abdd4d..371d847 100644
--- a/plc4j/api/pom.xml
+++ b/plc4j/api/pom.xml
@@ -41,30 +41,12 @@
       <artifactId>jackson-annotations</artifactId>
     </dependency>
     <dependency>
-      <groupId>org.osgi</groupId>
-      <artifactId>osgi.core</artifactId>
-      <version>6.0.0</version>
-      <scope>provided</scope>
-    </dependency>
-    <dependency>
       <groupId>nl.jqno.equalsverifier</groupId>
       <artifactId>equalsverifier</artifactId>
       <scope>test</scope>
     </dependency>
   </dependencies>
 
-  <build>
-    <plugins>
-      <plugin>
-        <groupId>org.apache.felix</groupId>
-        <artifactId>maven-bundle-plugin</artifactId>
-        <configuration>
-          <instructions>
-            <Bundle-Activator>org.apache.plc4x.java.osgi.ApiActivator</Bundle-Activator>
-          </instructions>
-        </configuration>
-      </plugin>
-    </plugins>
-  </build>
+
 
 </project>
\ No newline at end of file
diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/DriverManager.java b/plc4j/api/src/main/java/org/apache/plc4x/java/DriverManager.java
deleted file mode 100644
index 0b574dd..0000000
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/DriverManager.java
+++ /dev/null
@@ -1,30 +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.plc4x.java;
-
-import org.apache.plc4x.java.api.PlcConnection;
-import org.apache.plc4x.java.api.authentication.PlcAuthentication;
-import org.apache.plc4x.java.api.exceptions.PlcConnectionException;
-
-public interface DriverManager {
-
-    PlcConnection getConnection(String url) throws PlcConnectionException;
-    PlcConnection getConnection(String url, PlcAuthentication authentication) throws PlcConnectionException;
-
-}
\ No newline at end of file
diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/PlcDriverManager.java b/plc4j/api/src/main/java/org/apache/plc4x/java/PlcDriverManager.java
index cfe94cc..7b3652c 100644
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/PlcDriverManager.java
+++ b/plc4j/api/src/main/java/org/apache/plc4x/java/PlcDriverManager.java
@@ -32,7 +32,7 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.ServiceLoader;
 
-public class PlcDriverManager implements DriverManager {
+public class PlcDriverManager {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(PlcDriverManager.class);
 
@@ -68,7 +68,6 @@ public class PlcDriverManager implements DriverManager {
      * @return PlcConnection object.
      * @throws PlcConnectionException an exception if the connection attempt failed.
      */
-    @Override
     public PlcConnection getConnection(String url) throws PlcConnectionException {
         PlcDriver driver = getDriver(url);
         PlcConnection connection = driver.getConnection(url);
@@ -84,7 +83,6 @@ public class PlcDriverManager implements DriverManager {
      * @return PlcConnection object.
      * @throws PlcConnectionException an exception if the connection attempt failed.
      */
-    @Override
     public PlcConnection getConnection(String url, PlcAuthentication authentication) throws PlcConnectionException {
         PlcDriver driver = getDriver(url);
         PlcConnection connection = driver.getConnection(url, authentication);
@@ -113,4 +111,4 @@ public class PlcDriverManager implements DriverManager {
         }
     }
 
-}
+}
\ No newline at end of file
diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/osgi/ApiActivator.java b/plc4j/api/src/main/java/org/apache/plc4x/java/osgi/ApiActivator.java
deleted file mode 100644
index 48d66b6..0000000
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/osgi/ApiActivator.java
+++ /dev/null
@@ -1,104 +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.plc4x.java.osgi;
-
-import org.apache.plc4x.java.DriverManager;
-import org.apache.plc4x.java.api.PlcDriver;
-import org.osgi.framework.*;
-import org.osgi.framework.wiring.BundleWiring;
-import org.osgi.util.tracker.BundleTracker;
-import org.osgi.util.tracker.BundleTrackerCustomizer;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.ArrayList;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.ServiceLoader;
-
-public class ApiActivator implements BundleActivator, BundleTrackerCustomizer<List<ServiceRegistration<PlcDriver>>>,
-    ServiceFactory<DriverManager> {
-
-    private Logger logger = LoggerFactory.getLogger(ApiActivator.class);
-    private ServiceRegistration<DriverManager> registration;
-    private BundleTracker<List<ServiceRegistration<PlcDriver>>> tracker;
-
-    @Override
-    public void start(BundleContext context) throws Exception {
-        tracker = new BundleTracker<>(context, Bundle.ACTIVE, this);
-        tracker.open();
-
-        registration = context.registerService(DriverManager.class, new OsgiDriverManager(context), new Hashtable<>());
-    }
-
-    @Override
-    public void stop(BundleContext context) throws Exception {
-        registration.unregister();
-
-        tracker.close();
-    }
-
-    @Override
-    public List<ServiceRegistration<PlcDriver>> addingBundle(Bundle bundle, BundleEvent event) {
-        if (bundle.getBundleId() == 0) {
-            return null;
-        }
-        try {
-            ClassLoader cl = bundle.adapt(BundleWiring.class).getClassLoader();
-            ServiceLoader<PlcDriver> drivers = ServiceLoader.load(PlcDriver.class, cl);
-            List<ServiceRegistration<PlcDriver>> registrations = new ArrayList<>();
-            for (PlcDriver driver : drivers) {
-                Hashtable<String, String> props = new Hashtable<String, String>();
-                props.put(OsgiDriverManager.PROTOCOL_CODE, driver.getProtocolCode());
-                props.put(OsgiDriverManager.PROTOCOL_NAME, driver.getProtocolName());
-                ServiceRegistration<PlcDriver> reg = bundle.getBundleContext().registerService(PlcDriver.class, driver, props);
-                registrations.add(reg);
-                logger.info("Added {}",driver.getProtocolName());
-            }
-
-            return registrations.isEmpty() ? null : registrations;
-        } catch (Exception ex) {
-            logger.error("Could not register PlcDrivers from bundle {}", bundle.getSymbolicName(), ex);
-            return null;
-        }
-    }
-
-    @Override
-    public void modifiedBundle(Bundle bundle, BundleEvent event, List<ServiceRegistration<PlcDriver>> object) {
-    }
-
-    @Override
-    public void removedBundle(Bundle bundle, BundleEvent event, List<ServiceRegistration<PlcDriver>> object) {
-        for (ServiceRegistration<PlcDriver> reg : object) {
-            reg.unregister();
-        }
-    }
-
-    @Override
-    public DriverManager getService(Bundle bundle, ServiceRegistration<DriverManager> registration) {
-        return new OsgiDriverManager(bundle.getBundleContext());
-    }
-
-    @Override
-    public void ungetService(Bundle bundle, ServiceRegistration<DriverManager> registration, DriverManager service) {
-        if (service instanceof OsgiDriverManager) {
-            ((OsgiDriverManager) service).close();
-        }
-    }
-}
\ No newline at end of file
diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/osgi/OsgiDriverManager.java b/plc4j/api/src/main/java/org/apache/plc4x/java/osgi/OsgiDriverManager.java
deleted file mode 100644
index 99e378a..0000000
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/osgi/OsgiDriverManager.java
+++ /dev/null
@@ -1,81 +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.plc4x.java.osgi;
-
-import org.apache.plc4x.java.DriverManager;
-import org.apache.plc4x.java.api.PlcConnection;
-import org.apache.plc4x.java.api.authentication.PlcAuthentication;
-import org.apache.plc4x.java.api.exceptions.PlcConnectionException;
-import org.apache.plc4x.java.api.PlcDriver;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
-
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.Collection;
-
-public class OsgiDriverManager implements DriverManager {
-
-    public static final String PROTOCOL_NAME = "org.apache.plc4x.driver.name";
-    public static final String PROTOCOL_CODE = "org.apache.plc4x.driver.code";
-
-    private final BundleContext context;
-
-    OsgiDriverManager(BundleContext context) {
-        this.context = context;
-    }
-
-    @Override
-    public PlcConnection getConnection(String url) throws PlcConnectionException {
-        PlcDriver driver = getDriver(url);
-        return driver.getConnection(url);
-    }
-
-    @Override
-    public PlcConnection getConnection(String url, PlcAuthentication authentication) throws PlcConnectionException {
-        PlcDriver driver = getDriver(url);
-        return driver.getConnection(url, authentication);
-    }
-
-    private PlcDriver getDriver(String url) throws PlcConnectionException {
-        try {
-            URI connectionUri = new URI(url);
-            String protocol = connectionUri.getScheme();
-
-            Collection<ServiceReference<PlcDriver>> references = context.getServiceReferences(PlcDriver.class, null);
-
-            for (ServiceReference<PlcDriver> driverReference : references) {
-                Object property = driverReference.getProperty(PROTOCOL_CODE);
-                if (protocol.equals(property)) {
-                    return context.getService(driverReference);
-                }
-            }
-            throw new PlcConnectionException("Unable to find driver for protocol '" + protocol + "'");
-        } catch (InvalidSyntaxException e) {
-            throw new PlcConnectionException("Could not locate driver for url: " + url, e);
-        } catch (URISyntaxException e) {
-            throw new PlcConnectionException("Malformed connection string: " + url, e);
-        }
-    }
-
-    void close() {
-
-    }
-}
\ No newline at end of file
diff --git a/plc4j/drivers/eip/pom.xml b/plc4j/drivers/eip/pom.xml
index cb18d40..91a52f1 100644
--- a/plc4j/drivers/eip/pom.xml
+++ b/plc4j/drivers/eip/pom.xml
@@ -67,6 +67,7 @@
         <configuration>
           <instructions>
             <Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
+            <Bundle-Activator>org.apache.plc4x.java.osgi.DriverActivator</Bundle-Activator>
             <Export-Service>org.apache.plc4x.java.api.PlcDriver,org.apache.plc4x.java.eip.readwrite.EIPDriver</Export-Service>
           </instructions>
         </configuration>
diff --git a/plc4j/drivers/s7/pom.xml b/plc4j/drivers/s7/pom.xml
index 7b503ff..d8378b2 100644
--- a/plc4j/drivers/s7/pom.xml
+++ b/plc4j/drivers/s7/pom.xml
@@ -97,6 +97,7 @@
         <configuration>
           <instructions>
             <Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
+            <Bundle-Activator>org.apache.plc4x.java.osgi.DriverActivator</Bundle-Activator>
             <Export-Service>org.apache.plc4x.java.api.PlcDriver,org.apache.plc4x.java.s7.readwrite.S7Driver</Export-Service>
           </instructions>
         </configuration>
diff --git a/plc4j/karaf-features/eip/pom.xml b/plc4j/karaf-features/eip/pom.xml
index 03821af..a0cba28 100644
--- a/plc4j/karaf-features/eip/pom.xml
+++ b/plc4j/karaf-features/eip/pom.xml
@@ -34,9 +34,15 @@
   <dependencies>
     <dependency>
       <groupId>org.apache.plc4x</groupId>
+      <artifactId>plc4j-osgi</artifactId>
+      <version>0.7.0-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.plc4x</groupId>
       <artifactId>plc4j-driver-eip</artifactId>
       <version>${project.version}</version>
     </dependency>
+
   </dependencies>
 
   <build>
diff --git a/plc4j/karaf-features/eip/pom.xml b/plc4j/osgi/pom.xml
similarity index 58%
copy from plc4j/karaf-features/eip/pom.xml
copy to plc4j/osgi/pom.xml
index 03821af..359c2ab 100644
--- a/plc4j/karaf-features/eip/pom.xml
+++ b/plc4j/osgi/pom.xml
@@ -22,45 +22,33 @@
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <parent>
     <groupId>org.apache.plc4x</groupId>
-    <artifactId>karaf-features</artifactId>
+    <artifactId>plc4j</artifactId>
     <version>0.7.0-SNAPSHOT</version>
   </parent>
-
   <modelVersion>4.0.0</modelVersion>
-  <packaging>pom</packaging>
 
-  <artifactId>driver-eip-feature</artifactId>
-  <name>PLC4J: Karaf-Features: EIP</name>
+  <artifactId>plc4j-osgi</artifactId>
+  <name>PLC4J: OSGi</name>
+  <description>OSGi Module for PLC4X</description>
   <dependencies>
     <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>osgi.core</artifactId>
+      <version>6.0.0</version>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.plc4x</groupId>
+      <artifactId>plc4j-api</artifactId>
+      <version>0.7.0-SNAPSHOT</version>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
       <groupId>org.apache.plc4x</groupId>
-      <artifactId>plc4j-driver-eip</artifactId>
-      <version>${project.version}</version>
+      <artifactId>plc4j-spi</artifactId>
+      <version>0.7.0-SNAPSHOT</version>
+      <scope>compile</scope>
     </dependency>
   </dependencies>
 
-  <build>
-    <plugins>
-      <plugin>
-        <groupId>org.apache.karaf.tooling</groupId>
-        <artifactId>karaf-maven-plugin</artifactId>
-        <extensions>true</extensions>
-        <configuration>
-          <enableGeneration>true</enableGeneration>
-          <aggregateFeatures>true</aggregateFeatures>
-        </configuration>
-        <executions>
-          <execution>
-            <id>generate-features-file</id>
-            <phase>generate-resources</phase>
-            <goals>
-              <goal>features-generate-descriptor</goal>
-            </goals>
-          </execution>
-        </executions>
-      </plugin>
-    </plugins>
-  </build>
-
-
 </project>
\ No newline at end of file
diff --git a/plc4j/osgi/src/main/java/org/apache/plc4x/java/osgi/DriverActivator.java b/plc4j/osgi/src/main/java/org/apache/plc4x/java/osgi/DriverActivator.java
new file mode 100644
index 0000000..215434f
--- /dev/null
+++ b/plc4j/osgi/src/main/java/org/apache/plc4x/java/osgi/DriverActivator.java
@@ -0,0 +1,53 @@
+/*
+ * 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.plc4x.java.osgi;
+
+import org.apache.plc4x.java.api.PlcDriver;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.framework.wiring.BundleWiring;
+
+import java.util.Hashtable;
+import java.util.ServiceLoader;
+
+public class DriverActivator implements BundleActivator {
+
+    private ServiceRegistration<PlcDriver> reg;
+    public static final String PROTOCOL_NAME = "org.apache.plc4x.driver.name";
+    public static final String PROTOCOL_CODE = "org.apache.plc4x.driver.code";
+
+
+    @Override
+    public void start(BundleContext context) throws Exception {
+        ServiceLoader<PlcDriver> drivers = ServiceLoader.load(PlcDriver.class, context.getBundle().adapt(BundleWiring.class).getClassLoader());
+        for (PlcDriver driver : drivers) {
+            Hashtable<String, String> props = new Hashtable<>();
+            props.put(PROTOCOL_CODE, driver.getProtocolCode());
+            props.put(PROTOCOL_NAME, driver.getProtocolName());
+            reg = context.registerService(PlcDriver.class, driver, props);
+        }
+    }
+
+    @Override
+    public void stop(BundleContext context) {
+        reg.unregister();
+    }
+}
+
diff --git a/plc4j/osgi/src/main/java/org/apache/plc4x/java/osgi/TransportActivator.java b/plc4j/osgi/src/main/java/org/apache/plc4x/java/osgi/TransportActivator.java
new file mode 100644
index 0000000..7f3fefa
--- /dev/null
+++ b/plc4j/osgi/src/main/java/org/apache/plc4x/java/osgi/TransportActivator.java
@@ -0,0 +1,54 @@
+/*
+ * 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.plc4x.java.osgi;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.framework.wiring.BundleWiring;
+import org.apache.plc4x.java.spi.transport.Transport;
+
+import java.util.Hashtable;
+import java.util.ServiceLoader;
+
+public class TransportActivator implements BundleActivator {
+
+    private ServiceRegistration<Transport> reg;
+    private final String TRANSPORT_CODE ="org.apache.plc4x.transport.code";
+    private final String TRANSPORT_NAME ="org.apache.plc4x.transport.name";
+
+
+    @Override
+    public void start(BundleContext context) throws Exception {
+        ServiceLoader<Transport> transports = ServiceLoader.load(Transport.class, context.getBundle().adapt(BundleWiring.class).getClassLoader());
+        for (Transport transport : transports) {
+            Hashtable<String, String> props = new Hashtable<String, String>();
+            props.put(TRANSPORT_CODE, transport.getTransportCode());
+            props.put(TRANSPORT_NAME, transport.getTransportName());
+            reg = context.registerService(Transport.class, transport, props);
+        }
+    }
+
+    @Override
+    public void stop(BundleContext context) {
+        reg.unregister();
+    }
+}
+
+
diff --git a/plc4j/pom.xml b/plc4j/pom.xml
index cd71a02..24046d9 100644
--- a/plc4j/pom.xml
+++ b/plc4j/pom.xml
@@ -36,13 +36,14 @@
   <modules>
     <module>api</module>
     <module>drivers</module>
-    <module>examples</module>
+    <!--module>examples</module-->
     <module>integrations</module>
-    <!--module>karaf-features</module-->
+    <module>karaf-features</module>
     <module>spi</module>
     <module>tools</module>
     <module>transports</module>
     <module>utils</module>
+    <module>osgi</module>
   </modules>
 
   <build>
diff --git a/plc4j/spi/pom.xml b/plc4j/spi/pom.xml
index 65fdf69..7e3d9d6 100644
--- a/plc4j/spi/pom.xml
+++ b/plc4j/spi/pom.xml
@@ -84,12 +84,7 @@
       <groupId>commons-codec</groupId>
       <artifactId>commons-codec</artifactId>
     </dependency>
-    <dependency>
-      <groupId>org.osgi</groupId>
-      <artifactId>osgi.core</artifactId>
-      <version>6.0.0</version>
-      <scope>compile</scope>
-    </dependency>
+
   </dependencies>
 
   <build>
@@ -100,7 +95,6 @@
         <extensions>true</extensions>
         <configuration>
           <instructions>
-            <Bundle-Activator>org.apache.plc4x.java.osgi.SpiActivator</Bundle-Activator>
             <Export-package>io.netty.bootstrap,*</Export-package>
           </instructions>
         </configuration>
diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/osgi/SpiActivator.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/osgi/SpiActivator.java
deleted file mode 100644
index 5265b16..0000000
--- a/plc4j/spi/src/main/java/org/apache/plc4x/java/osgi/SpiActivator.java
+++ /dev/null
@@ -1,89 +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.plc4x.java.osgi;
-
-import org.apache.plc4x.java.spi.transport.Transport;
-import org.osgi.framework.*;
-import org.osgi.framework.wiring.BundleWiring;
-import org.osgi.util.tracker.BundleTracker;
-import org.osgi.util.tracker.BundleTrackerCustomizer;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.ArrayList;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.ServiceLoader;
-
-public class SpiActivator implements BundleActivator, BundleTrackerCustomizer<List<ServiceRegistration<Transport>>>{
-
-    private Logger logger = LoggerFactory.getLogger(SpiActivator.class);
-    private BundleTracker<List<ServiceRegistration<Transport>>> tracker;
-
-    private final String TRANSPORT_CODE ="org.apache.plc4x.transport.code";
-    private final String TRANSPORT_NAME ="org.apache.plc4x.transport.name";
-
-    @Override
-    public void start(BundleContext context) throws Exception {
-        tracker = new BundleTracker<>(context, Bundle.ACTIVE, this);
-        tracker.open();
-    }
-
-    @Override
-    public void stop(BundleContext context) throws Exception {
-        tracker.close();
-    }
-
-    @Override
-    public List<ServiceRegistration<Transport>> addingBundle(Bundle bundle, BundleEvent event) {
-        if (bundle.getBundleId() == 0) {
-            return null;
-        }
-        try {
-            ClassLoader cl = bundle.adapt(BundleWiring.class).getClassLoader();
-            ServiceLoader<Transport> transports = ServiceLoader.load(Transport.class, cl);
-            List<ServiceRegistration<Transport>> registrations = new ArrayList<>();
-            for (Transport transport : transports) {
-                Hashtable<String, String> props = new Hashtable<String, String>();
-                props.put(TRANSPORT_CODE, transport.getTransportCode());
-                props.put(TRANSPORT_NAME, transport.getTransportName());
-                ServiceRegistration<Transport> reg = bundle.getBundleContext().registerService(Transport.class, transport, props);
-                registrations.add(reg);
-                logger.info("Added {}",transport.getTransportName());
-            }
-
-            return registrations.isEmpty() ? null : registrations;
-        } catch (Exception ex) {
-            logger.error("Could not register Transport(s) from bundle {}", bundle.getSymbolicName(), ex);
-            return null;
-        }
-    }
-
-    @Override
-    public void modifiedBundle(Bundle bundle, BundleEvent event, List<ServiceRegistration<Transport>> object) {
-    }
-
-    @Override
-    public void removedBundle(Bundle bundle, BundleEvent event, List<ServiceRegistration<Transport>> object) {
-        for (ServiceRegistration<Transport> reg : object) {
-            reg.unregister();
-        }
-    }
-
-}
\ No newline at end of file
diff --git a/plc4j/transports/tcp/pom.xml b/plc4j/transports/tcp/pom.xml
index 879612e..252fc59 100644
--- a/plc4j/transports/tcp/pom.xml
+++ b/plc4j/transports/tcp/pom.xml
@@ -67,6 +67,7 @@
         <configuration>
           <instructions>
             <Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
+            <Bundle-Activator>org.apache.plc4x.java.osgi.TransportActivator</Bundle-Activator>
             <Export-Service>org.apache.plc4x.java.spi.transport.Transport,org.apache.plc4x.java.transport.tcp.TcpTransport</Export-Service>
           </instructions>
         </configuration>


[plc4x] 03/03: OSGi Module -Adapted S7 Feature generation

Posted by er...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

erobinet pushed a commit to branch feature/osgi
in repository https://gitbox.apache.org/repos/asf/plc4x.git

commit f2db7406a4bfb81d84e8fd3cacf480879bb80f8f
Author: etiennerobinet <61...@users.noreply.github.com>
AuthorDate: Fri May 8 11:56:49 2020 +0200

    OSGi Module
    -Adapted S7 Feature generation
---
 plc4j/karaf-features/s7/pom.xml | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/plc4j/karaf-features/s7/pom.xml b/plc4j/karaf-features/s7/pom.xml
index 2c023c5..81dc7a1 100644
--- a/plc4j/karaf-features/s7/pom.xml
+++ b/plc4j/karaf-features/s7/pom.xml
@@ -35,6 +35,11 @@
   <dependencies>
     <dependency>
       <groupId>org.apache.plc4x</groupId>
+      <artifactId>plc4j-osgi</artifactId>
+      <version>0.7.0-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.plc4x</groupId>
       <artifactId>plc4j-driver-s7</artifactId>
       <version>${project.version}</version>
     </dependency>