Convert yang-data-jaxen to OSGi DS 05/94205/1
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 11 Dec 2020 00:27:45 +0000 (01:27 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 11 Dec 2020 10:09:30 +0000 (11:09 +0100)
We do not need a dependency on osgi.core here, just use component
annotations.

Change-Id: If19fd9722e7c09088a5dc8839ef774813a4a217d
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 2ffac169b97ad0b8294635d8f27874d24fae28aa)

attic/yang-data-jaxen/pom.xml
attic/yang-data-jaxen/src/main/java/org/opendaylight/yangtools/yang/data/jaxen/JaxenSchemaContextFactory.java
attic/yang-data-jaxen/src/main/java/org/opendaylight/yangtools/yang/data/jaxen/osgi/Activator.java [deleted file]
attic/yang-data-jaxen/src/main/java/org/opendaylight/yangtools/yang/data/jaxen/osgi/package-info.java [deleted file]
docs/pom.xml

index b318b2973b7644313ff87f84f9d56b21616f1d59..a646e6294f603d2609f98cc73065c0bd959bf80c 100644 (file)
             <groupId>org.kohsuke.metainf-services</groupId>
             <artifactId>metainf-services</artifactId>
         </dependency>
+        <dependency>
+            <groupId>com.guicedee.services</groupId>
+            <artifactId>javax.inject</artifactId>
+            <optional>true</optional>
+        </dependency>
         <dependency>
             <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.core</artifactId>
+            <artifactId>org.osgi.service.component.annotations</artifactId>
         </dependency>
 
         <dependency>
@@ -84,7 +89,6 @@
                 <configuration>
                     <instructions>
                         <Automatic-Module-Name>org.opendaylight.yangtools.yang.data.jaxen</Automatic-Module-Name>
-                        <Bundle-Activator>org.opendaylight.yangtools.yang.data.jaxen.osgi.Activator</Bundle-Activator>
                     </instructions>
                 </configuration>
             </plugin>
index 22117dfe56ada0a3018e6c604b34d2627c320114..e66810fbdfbd2a42d9f8331dacc21d60b4b311fc 100644 (file)
@@ -7,17 +7,45 @@
  */
 package org.opendaylight.yangtools.yang.data.jaxen;
 
+import javax.inject.Inject;
+import javax.inject.Singleton;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.kohsuke.MetaInfServices;
 import org.opendaylight.yangtools.yang.data.jaxen.api.XPathSchemaContext;
 import org.opendaylight.yangtools.yang.data.jaxen.api.XPathSchemaContextFactory;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 @MetaInfServices
+@Singleton
+@Component
 @NonNullByDefault
 public final class JaxenSchemaContextFactory implements XPathSchemaContextFactory {
+    private static final Logger LOG = LoggerFactory.getLogger(JaxenSchemaContextFactory.class);
+
+    @Inject
+    public JaxenSchemaContextFactory() {
+        // For DI
+    }
+
     @Override
     public XPathSchemaContext createContext(final EffectiveModelContext context) {
         return new JaxenSchemaContext(context);
     }
+
+    @Activate
+    @SuppressWarnings("static-method")
+    void activate() {
+        LOG.info("Jaxen XPathSchemaContextFactory enabled");
+    }
+
+    @Deactivate
+    @SuppressWarnings("static-method")
+    void deactivate() {
+        LOG.info("Jaxen XPathSchemaContextFactory disabled");
+    }
 }
diff --git a/attic/yang-data-jaxen/src/main/java/org/opendaylight/yangtools/yang/data/jaxen/osgi/Activator.java b/attic/yang-data-jaxen/src/main/java/org/opendaylight/yangtools/yang/data/jaxen/osgi/Activator.java
deleted file mode 100644 (file)
index e8b7ec4..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (c) 2018 Pantheon Technologies, s.r.o. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.data.jaxen.osgi;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.data.jaxen.JaxenSchemaContextFactory;
-import org.opendaylight.yangtools.yang.data.jaxen.api.XPathSchemaContextFactory;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceRegistration;
-
-/**
- * YANG Jaxen XPath implementation activator. Publishes a {@link XPathSchemaContextFactory} implementation on bundle
- * start.
- *
- * @author Robert Varga
- */
-public final class Activator implements BundleActivator {
-    private ServiceRegistration<@NonNull XPathSchemaContextFactory> registration;
-
-    @Override
-    public void start(final BundleContext context) throws Exception {
-        registration = context.registerService(XPathSchemaContextFactory.class, new JaxenSchemaContextFactory(), null);
-    }
-
-    @Override
-    public void stop(final BundleContext context) throws Exception {
-        if (registration != null) {
-            registration.unregister();
-            registration = null;
-        }
-    }
-}
diff --git a/attic/yang-data-jaxen/src/main/java/org/opendaylight/yangtools/yang/data/jaxen/osgi/package-info.java b/attic/yang-data-jaxen/src/main/java/org/opendaylight/yangtools/yang/data/jaxen/osgi/package-info.java
deleted file mode 100644 (file)
index 1b3732a..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-/*
- * Copyright (c) 2018 Pantheon Technologies, s.r.o. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-/**
- * OSGi-specific Jaxen XPath implementation code. Contains activators and similar.
- */
-package org.opendaylight.yangtools.yang.data.jaxen.osgi;
\ No newline at end of file
index fa8cf5056f4df38c72766248d7fc3a6bdceb5498..4b70ba50af4bdab1939ad158bbf8e8729d044052 100644 (file)
             <artifactId>org.osgi.service.component.annotations</artifactId>
             <scope>provided</scope>
         </dependency>
-        <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.core</artifactId>
-            <scope>provided</scope>
-        </dependency>
         <dependency>
             <groupId>org.immutables</groupId>
             <artifactId>value</artifactId>