This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to annotated tag org.apache.sling.jcr.repoinit-1.0.0 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-repoinit.git
commit 1a15e8633e21efbac543d6537a352ba8083c6eac Author: Bertrand Delacretaz <[email protected]> AuthorDate: Mon Jul 4 11:38:33 2016 +0000 SLING-5819 - jcr.repoinit bundle should only export what's strictly needed git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/repoinit/jcr@1751251 13f79535-47bb-0310-9956-ffa450edef68 --- ...kage-info.java => JcrRepoInitOpsProcessor.java} | 19 +++++++---- .../JcrRepoInitOperationVisitor.java} | 8 ++--- .../jcr/impl/JcrRepoInitOpsProcessorImpl.java | 38 ++++++++++++++++++++++ .../jcr/{ => impl}/RepositoryInitializer.java | 20 ++++++------ .../apache/sling/repoinit/jcr/package-info.java | 2 +- .../apache/sling/repoinit/jcr/CreatePathsTest.java | 1 + .../sling/repoinit/jcr/CreateServiceUsersTest.java | 1 + .../apache/sling/repoinit/jcr/GeneralAclTest.java | 1 + .../sling/repoinit/jcr/NonExistentPathTest.java | 1 + .../sling/repoinit/jcr/{ => impl}/TestUtil.java | 29 +++++++++-------- 10 files changed, 84 insertions(+), 36 deletions(-) diff --git a/src/main/java/org/apache/sling/repoinit/jcr/package-info.java b/src/main/java/org/apache/sling/repoinit/jcr/JcrRepoInitOpsProcessor.java similarity index 69% copy from src/main/java/org/apache/sling/repoinit/jcr/package-info.java copy to src/main/java/org/apache/sling/repoinit/jcr/JcrRepoInitOpsProcessor.java index a2fd18a..572a41e 100644 --- a/src/main/java/org/apache/sling/repoinit/jcr/package-info.java +++ b/src/main/java/org/apache/sling/repoinit/jcr/JcrRepoInitOpsProcessor.java @@ -1,4 +1,4 @@ -/******************************************************************************* +/* * 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. @@ -6,16 +6,23 @@ * (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. - ******************************************************************************/ - -@Version("1.0.0") + */ package org.apache.sling.repoinit.jcr; -import aQute.bnd.annotation.Version; +import java.util.List; + +import javax.jcr.Session; + +import org.apache.sling.repoinit.parser.operations.Operation; + +/** Apply Operations produced by the repoinit parser to a JCR Repository */ +public interface JcrRepoInitOpsProcessor { + void apply(Session session, List<Operation> ops); +} diff --git a/src/main/java/org/apache/sling/repoinit/jcr/JcrRepoInitOpVisitor.java b/src/main/java/org/apache/sling/repoinit/jcr/impl/JcrRepoInitOperationVisitor.java similarity index 95% rename from src/main/java/org/apache/sling/repoinit/jcr/JcrRepoInitOpVisitor.java rename to src/main/java/org/apache/sling/repoinit/jcr/impl/JcrRepoInitOperationVisitor.java index 8abb41b..bfe7e97 100644 --- a/src/main/java/org/apache/sling/repoinit/jcr/JcrRepoInitOpVisitor.java +++ b/src/main/java/org/apache/sling/repoinit/jcr/impl/JcrRepoInitOperationVisitor.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.sling.repoinit.jcr; +package org.apache.sling.repoinit.jcr.impl; import static org.apache.sling.repoinit.parser.operations.AclLine.PROP_PATHS; import static org.apache.sling.repoinit.parser.operations.AclLine.PROP_PRINCIPALS; @@ -25,8 +25,6 @@ import java.util.List; import javax.jcr.Node; import javax.jcr.Session; -import org.apache.sling.repoinit.jcr.impl.AclUtil; -import org.apache.sling.repoinit.jcr.impl.ServiceUserUtil; import org.apache.sling.repoinit.parser.operations.AclLine; import org.apache.sling.repoinit.parser.operations.CreatePath; import org.apache.sling.repoinit.parser.operations.CreateServiceUser; @@ -39,7 +37,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** JCR visitor for the Operations produced by the repoinit parser */ -public class JcrRepoInitOpVisitor implements OperationVisitor { +class JcrRepoInitOperationVisitor implements OperationVisitor { private final Logger log = LoggerFactory.getLogger(getClass()); @@ -49,7 +47,7 @@ public class JcrRepoInitOpVisitor implements OperationVisitor { * @param s must have sufficient rights to create users * and set ACLs. */ - public JcrRepoInitOpVisitor(Session s) { + public JcrRepoInitOperationVisitor(Session s) { session = s; } diff --git a/src/main/java/org/apache/sling/repoinit/jcr/impl/JcrRepoInitOpsProcessorImpl.java b/src/main/java/org/apache/sling/repoinit/jcr/impl/JcrRepoInitOpsProcessorImpl.java new file mode 100644 index 0000000..c4e3ed0 --- /dev/null +++ b/src/main/java/org/apache/sling/repoinit/jcr/impl/JcrRepoInitOpsProcessorImpl.java @@ -0,0 +1,38 @@ +/* + * 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.sling.repoinit.jcr.impl; + +import java.util.List; + +import javax.jcr.Session; + +import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.Service; +import org.apache.sling.repoinit.jcr.JcrRepoInitOpsProcessor; +import org.apache.sling.repoinit.parser.operations.Operation; + +/** Apply Operations produced by the repoinit parser to a JCR Repository */ +@Component +@Service(JcrRepoInitOpsProcessor.class) +public class JcrRepoInitOpsProcessorImpl implements JcrRepoInitOpsProcessor { + public void apply(Session session, List<Operation> ops) { + final JcrRepoInitOperationVisitor v = new JcrRepoInitOperationVisitor(session); + for(Operation op : ops) { + op.accept(v); + } + } +} diff --git a/src/main/java/org/apache/sling/repoinit/jcr/RepositoryInitializer.java b/src/main/java/org/apache/sling/repoinit/jcr/impl/RepositoryInitializer.java similarity index 94% rename from src/main/java/org/apache/sling/repoinit/jcr/RepositoryInitializer.java rename to src/main/java/org/apache/sling/repoinit/jcr/impl/RepositoryInitializer.java index 648d073..adbca24 100644 --- a/src/main/java/org/apache/sling/repoinit/jcr/RepositoryInitializer.java +++ b/src/main/java/org/apache/sling/repoinit/jcr/impl/RepositoryInitializer.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.sling.repoinit.jcr; +package org.apache.sling.repoinit.jcr.impl; import java.io.IOException; import java.io.InputStream; @@ -22,6 +22,7 @@ import java.io.StringReader; import java.io.StringWriter; import java.net.URL; import java.net.URLConnection; +import java.util.List; import java.util.Map; import javax.jcr.Session; @@ -40,6 +41,7 @@ import org.apache.sling.provisioning.model.Feature; import org.apache.sling.provisioning.model.Model; import org.apache.sling.provisioning.model.Section; import org.apache.sling.provisioning.model.io.ModelReader; +import org.apache.sling.repoinit.jcr.JcrRepoInitOpsProcessor; import org.apache.sling.repoinit.parser.RepoInitParser; import org.apache.sling.repoinit.parser.operations.Operation; import org.osgi.framework.Constants; @@ -87,6 +89,9 @@ public class RepositoryInitializer implements SlingRepositoryInitializer { @Reference private RepoInitParser parser; + @Reference + private JcrRepoInitOpsProcessor processor; + @Activate public void activate(Map<String, Object> config) { textURL = PropertiesUtil.toString(config.get(PROP_TEXT_URL), DEFAULT_TEXT_URL); @@ -96,19 +101,14 @@ public class RepositoryInitializer implements SlingRepositoryInitializer { @Override public void processRepository(SlingRepository repo) throws Exception { final String repoinit = getRepoInitText(); - int count=0; // loginAdministrative is ok here, definitely an admin operation final Session s = repo.loginAdministrative(null); - final JcrRepoInitOpVisitor v = new JcrRepoInitOpVisitor(s); try { - for(Operation op : parser.parse(new StringReader(repoinit))) { - count++; - log.info("Executing {}", op); - op.accept(v); - } + final List<Operation> ops = parser.parse(new StringReader(repoinit)); + log.info("Executing {} repoinit operations", ops.size()); + processor.apply(s, ops); s.save(); - log.info("{} repoinit operations executed", count); } finally { s.logout(); } @@ -164,4 +164,4 @@ public class RepositoryInitializer implements SlingRepositoryInitializer { } return result; } -} \ No newline at end of file +} diff --git a/src/main/java/org/apache/sling/repoinit/jcr/package-info.java b/src/main/java/org/apache/sling/repoinit/jcr/package-info.java index a2fd18a..a672011 100644 --- a/src/main/java/org/apache/sling/repoinit/jcr/package-info.java +++ b/src/main/java/org/apache/sling/repoinit/jcr/package-info.java @@ -15,7 +15,7 @@ * limitations under the License. ******************************************************************************/ -@Version("1.0.0") +@Version("1.1.0") package org.apache.sling.repoinit.jcr; import aQute.bnd.annotation.Version; diff --git a/src/test/java/org/apache/sling/repoinit/jcr/CreatePathsTest.java b/src/test/java/org/apache/sling/repoinit/jcr/CreatePathsTest.java index faf5cf2..23a560e 100644 --- a/src/test/java/org/apache/sling/repoinit/jcr/CreatePathsTest.java +++ b/src/test/java/org/apache/sling/repoinit/jcr/CreatePathsTest.java @@ -21,6 +21,7 @@ import java.io.IOException; import javax.jcr.RepositoryException; import org.apache.sling.commons.testing.jcr.RepositoryUtil; +import org.apache.sling.repoinit.jcr.impl.TestUtil; import org.apache.sling.testing.mock.sling.ResourceResolverType; import org.apache.sling.testing.mock.sling.junit.SlingContext; import org.junit.Before; diff --git a/src/test/java/org/apache/sling/repoinit/jcr/CreateServiceUsersTest.java b/src/test/java/org/apache/sling/repoinit/jcr/CreateServiceUsersTest.java index db31485..4cbdcd4 100644 --- a/src/test/java/org/apache/sling/repoinit/jcr/CreateServiceUsersTest.java +++ b/src/test/java/org/apache/sling/repoinit/jcr/CreateServiceUsersTest.java @@ -20,6 +20,7 @@ import java.util.Random; import javax.jcr.RepositoryException; +import org.apache.sling.repoinit.jcr.impl.TestUtil; import org.apache.sling.testing.mock.sling.ResourceResolverType; import org.apache.sling.testing.mock.sling.junit.SlingContext; import org.junit.Before; diff --git a/src/test/java/org/apache/sling/repoinit/jcr/GeneralAclTest.java b/src/test/java/org/apache/sling/repoinit/jcr/GeneralAclTest.java index 0055d83..01424c7 100644 --- a/src/test/java/org/apache/sling/repoinit/jcr/GeneralAclTest.java +++ b/src/test/java/org/apache/sling/repoinit/jcr/GeneralAclTest.java @@ -26,6 +26,7 @@ import javax.jcr.PathNotFoundException; import javax.jcr.RepositoryException; import javax.jcr.Session; +import org.apache.sling.repoinit.jcr.impl.TestUtil; import org.apache.sling.repoinit.parser.RepoInitParsingException; import org.apache.sling.testing.mock.sling.ResourceResolverType; import org.apache.sling.testing.mock.sling.junit.SlingContext; diff --git a/src/test/java/org/apache/sling/repoinit/jcr/NonExistentPathTest.java b/src/test/java/org/apache/sling/repoinit/jcr/NonExistentPathTest.java index bb727b0..4c11e8f 100644 --- a/src/test/java/org/apache/sling/repoinit/jcr/NonExistentPathTest.java +++ b/src/test/java/org/apache/sling/repoinit/jcr/NonExistentPathTest.java @@ -23,6 +23,7 @@ import javax.jcr.PathNotFoundException; import javax.jcr.RepositoryException; import javax.jcr.Session; +import org.apache.sling.repoinit.jcr.impl.TestUtil; import org.apache.sling.repoinit.parser.RepoInitParsingException; import org.apache.sling.testing.mock.sling.ResourceResolverType; import org.apache.sling.testing.mock.sling.junit.SlingContext; diff --git a/src/test/java/org/apache/sling/repoinit/jcr/TestUtil.java b/src/test/java/org/apache/sling/repoinit/jcr/impl/TestUtil.java similarity index 78% rename from src/test/java/org/apache/sling/repoinit/jcr/TestUtil.java rename to src/test/java/org/apache/sling/repoinit/jcr/impl/TestUtil.java index 7d72df8..42e173c 100644 --- a/src/test/java/org/apache/sling/repoinit/jcr/TestUtil.java +++ b/src/test/java/org/apache/sling/repoinit/jcr/impl/TestUtil.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.sling.repoinit.jcr; +package org.apache.sling.repoinit.jcr.impl; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; @@ -33,6 +33,7 @@ import javax.jcr.SimpleCredentials; import org.apache.commons.io.IOUtils; import org.apache.jackrabbit.api.security.user.Authorizable; import org.apache.jackrabbit.api.security.user.User; +import org.apache.sling.repoinit.jcr.impl.JcrRepoInitOperationVisitor; import org.apache.sling.repoinit.jcr.impl.ServiceUserUtil; import org.apache.sling.repoinit.parser.RepoInitParsingException; import org.apache.sling.repoinit.parser.impl.RepoInitParserService; @@ -40,20 +41,20 @@ import org.apache.sling.repoinit.parser.operations.Operation; import org.apache.sling.testing.mock.sling.junit.SlingContext; /** Test utilities */ -class TestUtil { +public class TestUtil { public static final String JCR_PRIMARY_TYPE = "jcr:primaryType"; - final Session adminSession; - final String id; - final String username; + public final Session adminSession; + public final String id; + public final String username; - TestUtil(SlingContext ctx) { + public TestUtil(SlingContext ctx) { adminSession = ctx.resourceResolver().adaptTo(Session.class); id = UUID.randomUUID().toString(); username = "user_" + id; } - List<Operation> parse(String input) throws RepoInitParsingException { + public List<Operation> parse(String input) throws RepoInitParsingException { final Reader r = new StringReader(input); try { return new RepoInitParserService().parse(r); @@ -62,7 +63,7 @@ class TestUtil { } } - void assertServiceUser(String info, String id, boolean expectToExist) throws RepositoryException { + public void assertServiceUser(String info, String id, boolean expectToExist) throws RepositoryException { final Authorizable a = ServiceUserUtil.getUserManager(adminSession).getAuthorizable(id); if(!expectToExist) { assertNull(info + ", expecting Principal to be absent:" + id, a); @@ -73,11 +74,11 @@ class TestUtil { } } - void assertNodeExists(String path) throws RepositoryException { + public void assertNodeExists(String path) throws RepositoryException { assertNodeExists(path, null); } - void assertNodeExists(String path, String primaryType) throws RepositoryException { + public void assertNodeExists(String path, String primaryType) throws RepositoryException { if(!adminSession.nodeExists(path)) { fail("Node does not exist:" + path); } @@ -93,20 +94,20 @@ class TestUtil { } } - void parseAndExecute(String input) throws RepositoryException, RepoInitParsingException { - final JcrRepoInitOpVisitor v = new JcrRepoInitOpVisitor(adminSession); + public void parseAndExecute(String input) throws RepositoryException, RepoInitParsingException { + final JcrRepoInitOperationVisitor v = new JcrRepoInitOperationVisitor(adminSession); for(Operation o : parse(input)) { o.accept(v); } adminSession.save(); } - void cleanupUser() throws RepositoryException, RepoInitParsingException { + public void cleanupUser() throws RepositoryException, RepoInitParsingException { parseAndExecute("delete service user " + username); assertServiceUser("in cleanupUser()", username, false); } - Session loginService(String serviceUsername) throws RepositoryException { + public Session loginService(String serviceUsername) throws RepositoryException { final SimpleCredentials cred = new SimpleCredentials(serviceUsername, new char[0]); return adminSession.impersonate(cred); } -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
