This is an automated email from the ASF dual-hosted git repository. sseifert pushed a commit to branch feature/SLING-13013-parent-62 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-registration.git
commit 153d9e0ce5dac656b37d0838ed59e3b21aa24b2b Author: Stefan Seifert <[email protected]> AuthorDate: Wed Nov 26 13:38:47 2025 +0100 SLING-13013 apply spotless formatting --- pom.xml | 16 ++--- .../registration/AbstractRegistrationSupport.java | 59 ++++++++-------- .../registration/impl/JndiRegistrationSupport.java | 78 ++++++++++++---------- .../registration/impl/RmiRegistrationSupport.java | 77 +++++++++++---------- .../sling/jcr/registration/package-info.java | 3 +- 5 files changed, 125 insertions(+), 108 deletions(-) diff --git a/pom.xml b/pom.xml index b3da429..2b0cc7e 100644 --- a/pom.xml +++ b/pom.xml @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="ISO-8859-1"?> +<?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 @@ -30,21 +30,19 @@ <version>1.0.7-SNAPSHOT</version> <name>Apache Sling JCR Repository Registration</name> - <description> - Bundle providing support to publish JCR repository services via RMI and/or JNDI - </description> - - <properties> - <sling.java.version>11</sling.java.version> - </properties> + <description>Bundle providing support to publish JCR repository services via RMI and/or JNDI</description> <scm> <connection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-registration.git</connection> <developerConnection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-registration.git</developerConnection> - <url>https://github.com/apache/sling-org-apache-sling-jcr-registration.git</url> <tag>HEAD</tag> + <url>https://github.com/apache/sling-org-apache-sling-jcr-registration.git</url> </scm> + <properties> + <sling.java.version>11</sling.java.version> + </properties> + <dependencies> <dependency> <groupId>javax.jcr</groupId> diff --git a/src/main/java/org/apache/sling/jcr/registration/AbstractRegistrationSupport.java b/src/main/java/org/apache/sling/jcr/registration/AbstractRegistrationSupport.java index cd724e6..62485d5 100644 --- a/src/main/java/org/apache/sling/jcr/registration/AbstractRegistrationSupport.java +++ b/src/main/java/org/apache/sling/jcr/registration/AbstractRegistrationSupport.java @@ -1,27 +1,29 @@ /* - * 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 + * 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 + * 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. + * 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.sling.jcr.registration; +import javax.jcr.Repository; + import java.util.HashMap; import java.util.Iterator; import java.util.Map; -import javax.jcr.Repository; - import org.osgi.framework.Constants; import org.osgi.framework.ServiceReference; import org.osgi.service.component.ComponentConstants; @@ -207,18 +209,18 @@ public abstract class AbstractRegistrationSupport { if (this.doActivate()) { // register all repositories in the tmp map - for (Iterator<Map.Entry<String, ServiceReference>> ri = this.repositoryRegistrationBacklog.entrySet().iterator(); ri.hasNext();) { + for (Iterator<Map.Entry<String, ServiceReference>> ri = + this.repositoryRegistrationBacklog.entrySet().iterator(); + ri.hasNext(); ) { Map.Entry<String, ServiceReference> entry = ri.next(); - this.bindRepositoryInternal(entry.getKey(), - entry.getValue()); + this.bindRepositoryInternal(entry.getKey(), entry.getValue()); ri.remove(); } } else { // disable this component - String name = (String) componentContext.getProperties().get( - ComponentConstants.COMPONENT_NAME); + String name = (String) componentContext.getProperties().get(ComponentConstants.COMPONENT_NAME); this.getComponentContext().disableComponent(name); } } @@ -241,7 +243,9 @@ public abstract class AbstractRegistrationSupport { synchronized (this.registryLock) { // unregister all repositories in the tmp map - for (Iterator<Map.Entry<String, Object>> ri = this.registeredRepositories.entrySet().iterator(); ri.hasNext();) { + for (Iterator<Map.Entry<String, Object>> ri = + this.registeredRepositories.entrySet().iterator(); + ri.hasNext(); ) { Map.Entry<String, Object> entry = ri.next(); this.unbindRepository(entry.getKey(), entry.getValue()); @@ -276,7 +280,8 @@ public abstract class AbstractRegistrationSupport { } } } else { - logger.info("Service {} has no name property, not registering", reference.getProperty(Constants.SERVICE_ID)); + logger.info( + "Service {} has no name property, not registering", reference.getProperty(Constants.SERVICE_ID)); } } @@ -309,7 +314,8 @@ public abstract class AbstractRegistrationSupport { } } } else { - logger.info("Service {} has no name property, not registering", reference.getProperty(Constants.SERVICE_ID)); + logger.info( + "Service {} has no name property, not registering", reference.getProperty(Constants.SERVICE_ID)); } } @@ -320,12 +326,12 @@ public abstract class AbstractRegistrationSupport { /** Unbinds the Logger */ protected void unbindLogger(Logger logger) { - if ( this.logger == logger ) { + if (this.logger == logger) { this.logger = null; } } - //---------- internal ----------------------------------------------------- + // ---------- internal ----------------------------------------------------- /** * Internal bind method called by {@link #activate(ComponentContext)} and @@ -334,12 +340,11 @@ public abstract class AbstractRegistrationSupport { * {@link #bindRepository(String, Repository)} method. */ private void bindRepositoryInternal(String name, ServiceReference reference) { - Repository repository = (Repository) this.getComponentContext().getBundleContext().getService( - reference); + Repository repository = + (Repository) this.getComponentContext().getBundleContext().getService(reference); Object data = this.bindRepository(name, repository); if (data != null) { this.registeredRepositories.put(name, data); } } - } diff --git a/src/main/java/org/apache/sling/jcr/registration/impl/JndiRegistrationSupport.java b/src/main/java/org/apache/sling/jcr/registration/impl/JndiRegistrationSupport.java index f24c4bd..bc05292 100644 --- a/src/main/java/org/apache/sling/jcr/registration/impl/JndiRegistrationSupport.java +++ b/src/main/java/org/apache/sling/jcr/registration/impl/JndiRegistrationSupport.java @@ -1,21 +1,28 @@ /* - * 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 + * 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 + * 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. + * 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.sling.jcr.registration.impl; +import javax.jcr.Repository; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; + import java.security.AccessController; import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; @@ -23,11 +30,6 @@ import java.util.Dictionary; import java.util.Enumeration; import java.util.Properties; -import javax.jcr.Repository; -import javax.naming.Context; -import javax.naming.InitialContext; -import javax.naming.NamingException; - import org.apache.sling.jcr.registration.AbstractRegistrationSupport; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.ConfigurationPolicy; @@ -35,13 +37,12 @@ import org.osgi.service.component.annotations.Reference; import org.osgi.service.component.annotations.ReferenceCardinality; import org.osgi.service.component.annotations.ReferencePolicy; import org.osgi.service.component.propertytypes.ServiceDescription; +import org.osgi.service.log.Logger; +import org.osgi.service.log.LoggerFactory; import org.osgi.service.metatype.annotations.AttributeDefinition; import org.osgi.service.metatype.annotations.Designate; import org.osgi.service.metatype.annotations.ObjectClassDefinition; -import org.osgi.service.log.LoggerFactory; -import org.osgi.service.log.Logger; - /** * The <code>JndiRegistrationSupport</code> extends the * {@link AbstractRegistrationSupport} class to register repositories with a @@ -56,10 +57,12 @@ import org.osgi.service.log.Logger; configurationPolicy = ConfigurationPolicy.REQUIRE, name = "org.apache.sling.jcr.jackrabbit.server.JndiRegistrationSupport", reference = { - @Reference(name = "Repository", policy = ReferencePolicy.DYNAMIC, - cardinality = ReferenceCardinality.MULTIPLE, service = Repository.class) - } -) + @Reference( + name = "Repository", + policy = ReferencePolicy.DYNAMIC, + cardinality = ReferenceCardinality.MULTIPLE, + service = Repository.class) + }) @Designate(ocd = JndiRegistrationSupport.Configuration.class) @ServiceDescription("JNDI Repository Registration") public class JndiRegistrationSupport extends AbstractRegistrationSupport { @@ -68,22 +71,24 @@ public class JndiRegistrationSupport extends AbstractRegistrationSupport { // ---------- Configuration --------------------------------------------- - @ObjectClassDefinition(name = "Apache Sling JCR Repository JNDI Registrar", - description = "The JNDI Registrar listens for embedded repositories " + - "to be registered as services and registers them in the JNDI context under the " + - "name specified in the \"name\" service property.") + @ObjectClassDefinition( + name = "Apache Sling JCR Repository JNDI Registrar", + description = "The JNDI Registrar listens for embedded repositories " + + "to be registered as services and registers them in the JNDI context under the " + + "name specified in the \"name\" service property.") public @interface Configuration { @AttributeDefinition( name = "Initial Context Factory", - description = "The fully qualified class name of the factory class that will create an initial context.") - String java_naming_factory_initial() default "org.apache.jackrabbit.core.jndi.provider.DummyInitialContextFactory"; //NOSONAR + description = + "The fully qualified class name of the factory class that will create an initial context.") + String java_naming_factory_initial() default + "org.apache.jackrabbit.core.jndi.provider.DummyInitialContextFactory"; // NOSONAR @AttributeDefinition( name = "Provider URL", description = "An URL string for the service provider (e.g. ldap://somehost:389)") - String java_naming_provider_url() default "http://sling.apache.org"; //NOSONAR - + String java_naming_provider_url() default "http://sling.apache.org"; // NOSONAR } // ---------- SCR integration --------------------------------------------- @@ -93,7 +98,7 @@ public class JndiRegistrationSupport extends AbstractRegistrationSupport { @SuppressWarnings("unchecked") Dictionary<String, Object> props = this.getComponentContext().getProperties(); Properties env = new Properties(); - for (Enumeration<String> pe = props.keys(); pe.hasMoreElements();) { + for (Enumeration<String> pe = props.keys(); pe.hasMoreElements(); ) { String key = pe.nextElement(); if (key.startsWith("java.naming.")) { env.setProperty(key, (String) props.get(key)); @@ -107,7 +112,9 @@ public class JndiRegistrationSupport extends AbstractRegistrationSupport { return true; } catch (NamingException ne) { - logger.error("Problem setting up JNDI initial context, repositories will not be registered. Reason: {}", ne.getMessage()); + logger.error( + "Problem setting up JNDI initial context, repositories will not be registered. Reason: {}", + ne.getMessage()); } // fallback to false @@ -132,7 +139,8 @@ public class JndiRegistrationSupport extends AbstractRegistrationSupport { return AccessController.doPrivileged((PrivilegedExceptionAction<Context>) () -> { Thread currentThread = Thread.currentThread(); ClassLoader old = currentThread.getContextClassLoader(); - currentThread.setContextClassLoader(JndiRegistrationSupport.this.getClass().getClassLoader()); + currentThread.setContextClassLoader( + JndiRegistrationSupport.this.getClass().getClassLoader()); try { return new InitialContext(env); } finally { diff --git a/src/main/java/org/apache/sling/jcr/registration/impl/RmiRegistrationSupport.java b/src/main/java/org/apache/sling/jcr/registration/impl/RmiRegistrationSupport.java index cd9a963..a2fb995 100644 --- a/src/main/java/org/apache/sling/jcr/registration/impl/RmiRegistrationSupport.java +++ b/src/main/java/org/apache/sling/jcr/registration/impl/RmiRegistrationSupport.java @@ -1,21 +1,25 @@ /* - * 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 + * 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 + * 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. + * 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.sling.jcr.registration.impl; +import javax.jcr.Repository; + import java.io.IOException; import java.net.InetAddress; import java.rmi.NoSuchObjectException; @@ -25,8 +29,6 @@ import java.rmi.registry.LocateRegistry; import java.rmi.registry.Registry; import java.rmi.server.UnicastRemoteObject; -import javax.jcr.Repository; - import org.apache.jackrabbit.rmi.server.RemoteAdapterFactory; import org.apache.jackrabbit.rmi.server.ServerAdapterFactory; import org.apache.sling.jcr.registration.AbstractRegistrationSupport; @@ -50,15 +52,16 @@ import org.osgi.service.metatype.annotations.ObjectClassDefinition; * Note: Currently only registries in this Java VM are supported. In the future * support for external registries may be added. */ - @Component( configurationPolicy = ConfigurationPolicy.REQUIRE, name = "org.apache.sling.jcr.jackrabbit.server.RmiRegistrationSupport", reference = { - @Reference(name = "Repository", policy = ReferencePolicy.DYNAMIC, - cardinality = ReferenceCardinality.MULTIPLE, service = Repository.class) - } -) + @Reference( + name = "Repository", + policy = ReferencePolicy.DYNAMIC, + cardinality = ReferenceCardinality.MULTIPLE, + service = Repository.class) + }) @Designate(ocd = RmiRegistrationSupport.Configuration.class) @ServiceDescription("RMI based Repository Registration") public class RmiRegistrationSupport extends AbstractRegistrationSupport { @@ -74,20 +77,21 @@ public class RmiRegistrationSupport extends AbstractRegistrationSupport { // ---------- Configuration --------------------------------------------- - @ObjectClassDefinition(name = "Apache Sling JCR Repository RMI Registrar", - description = "The RMI Registrar listens for embedded repositories " + - " to be registered as services and registers them in an RMI registry under the " + - " name specified in the \"name\" service property.") + @ObjectClassDefinition( + name = "Apache Sling JCR Repository RMI Registrar", + description = "The RMI Registrar listens for embedded repositories " + + " to be registered as services and registers them in an RMI registry under the " + + " name specified in the \"name\" service property.") public @interface Configuration { @AttributeDefinition( name = "Port Number", - description = "Port number of the RMI registry to use. The RMI Registrar first tries to " + - "create a private RMI registry at this port. If this fails, an existing registry " + - "is tried to connect at this port on local host. If this number is negative, " + - "the RMI registrar is disabled. If this number is higher than 65535, an error " + - "message is logged and the RMI Registrar is also disabled. If this number is " + - "zero, the system default RMI Registry port 1099 is used.") + description = "Port number of the RMI registry to use. The RMI Registrar first tries to " + + "create a private RMI registry at this port. If this fails, an existing registry " + + "is tried to connect at this port on local host. If this number is negative, " + + "the RMI registrar is disabled. If this number is higher than 65535, an error " + + "message is logged and the RMI Registrar is also disabled. If this number is " + + "zero, the system default RMI Registry port 1099 is used.") int port() default 1099; } @@ -102,8 +106,7 @@ public class RmiRegistrationSupport extends AbstractRegistrationSupport { @Override protected boolean doActivate() { - Object portProp = this.getComponentContext().getProperties().get( - PROP_REGISTRY_PORT); + Object portProp = this.getComponentContext().getProperties().get(PROP_REGISTRY_PORT); if (portProp instanceof Number) { this.registryPort = ((Number) portProp).intValue(); } else { @@ -179,7 +182,10 @@ public class RmiRegistrationSupport extends AbstractRegistrationSupport { } catch (RemoteException re) { // creating failed, check whether there is already one - logger.info("Cannot create private registry, trying existing registry at {}, reason: {}", this.registryPort, re); + logger.info( + "Cannot create private registry, trying existing registry at {}, reason: {}", + this.registryPort, + re); try { this.registry = LocateRegistry.getRegistry(this.registryPort); @@ -232,8 +238,7 @@ public class RmiRegistrationSupport extends AbstractRegistrationSupport { } catch (IOException ignore) { host = "localhost"; } - return "//" + host + ":" + RmiRegistrationSupport.this.registryPort - + "/" + this.getRmiName(); + return "//" + host + ":" + RmiRegistrationSupport.this.registryPort + "/" + this.getRmiName(); } private void register(String rmiName, Repository repository) { @@ -263,7 +268,9 @@ public class RmiRegistrationSupport extends AbstractRegistrationSupport { } catch (NoSuchObjectException nsoe) { // the registry does not really exist - logger.warn("Cannot contact RMI registry at {}, repository not registered", RmiRegistrationSupport.this.registryPort); + logger.warn( + "Cannot contact RMI registry at {}, repository not registered", + RmiRegistrationSupport.this.registryPort); } catch (Exception e) { logger.error("Unable to bind repository via RMI.", e); } diff --git a/src/main/java/org/apache/sling/jcr/registration/package-info.java b/src/main/java/org/apache/sling/jcr/registration/package-info.java index ae6a463..8d55942 100644 --- a/src/main/java/org/apache/sling/jcr/registration/package-info.java +++ b/src/main/java/org/apache/sling/jcr/registration/package-info.java @@ -26,5 +26,4 @@ @Version("2.0.0") package org.apache.sling.jcr.registration; - -import org.osgi.annotation.versioning.Version; \ No newline at end of file +import org.osgi.annotation.versioning.Version;
