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.1.0 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-repoinit.git
commit 7e3df05bc8b0532294ffaedd6677a8d4182d1e56 Author: Carsten Ziegeler <cziege...@apache.org> AuthorDate: Tue Nov 8 16:36:26 2016 +0000 Update to parent pom 29 git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/jcr/repoinit@1768725 13f79535-47bb-0310-9956-ffa450edef68 --- pom.xml | 236 ++++++++++----------- .../jcr/repoinit/JcrRepoInitOpsProcessor.java | 7 +- .../repoinit/impl/JcrRepoInitOpsProcessorImpl.java | 10 +- .../jcr/repoinit/impl/RepositoryInitializer.java | 78 +++---- .../apache/sling/jcr/repoinit/package-info.java | 3 +- .../jcr/repoinit/RepositoryInitializerTest.java | 63 +++--- 6 files changed, 189 insertions(+), 208 deletions(-) diff --git a/pom.xml b/pom.xml index 1d9235d..bddd34f 100644 --- a/pom.xml +++ b/pom.xml @@ -46,125 +46,121 @@ <url>https://svn.apache.org/repos/asf/sling/trunk/bundles/jcr/repoinit</url> </scm> - <build> - <plugins> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-scr-plugin</artifactId> - </plugin> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <extensions>true</extensions> - </plugin> - </plugins> - </build> + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <extensions>true</extensions> + <executions> + <!-- Configure extra execution of 'manifest' in process-classes phase to make sure SCR metadata is generated before unit test runs --> + <execution> + <id>scr-metadata</id> + <goals> + <goal>manifest</goal> + </goals> + <configuration> + <supportIncrementalBuild>true</supportIncrementalBuild> + </configuration> + </execution> + </executions> + <configuration> + <!-- Export SCR metadata to classpath to have them available in unit tests --> + <exportScr>true</exportScr> + </configuration> + </plugin> + </plugins> + </build> - <dependencies> - <dependency> - <groupId>org.osgi</groupId> - <artifactId>osgi.core</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.osgi</groupId> - <artifactId>osgi.cmpn</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-api</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-simple</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>javax.jcr</groupId> - <artifactId>jcr</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.apache.jackrabbit</groupId> - <artifactId>jackrabbit-api</artifactId> - <version>${jackrabbit.version}</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.apache.jackrabbit</groupId> - <artifactId>jackrabbit-jcr-commons</artifactId> - <version>${jackrabbit.version}</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>javax.servlet</groupId> - <artifactId>javax.servlet-api</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.apache.sling</groupId> - <artifactId>org.apache.sling.repoinit.parser</artifactId> - <version>1.0.5-SNAPSHOT</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.apache.sling</groupId> - <artifactId>org.apache.sling.jcr.api</artifactId> - <version>2.4.0</version> - </dependency> - <dependency> - <groupId>org.apache.sling</groupId> - <artifactId>org.apache.sling.provisioning.model</artifactId> - <version>1.4.2</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.apache.sling</groupId> - <artifactId>org.apache.sling.commons.osgi</artifactId> - <version>2.2.0</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>commons-io</groupId> - <artifactId>commons-io</artifactId> - <version>2.4</version> - </dependency> - <dependency> - <groupId>org.apache.sling</groupId> - <artifactId>org.apache.sling.testing.osgi-mock</artifactId> - <version>1.6.0</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.sling</groupId> - <artifactId>org.apache.sling.testing.jcr-mock</artifactId> - <version>1.1.10</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.sling</groupId> - <artifactId>org.apache.sling.testing.sling-mock</artifactId> - <version>1.6.0</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.sling</groupId> - <artifactId>org.apache.sling.testing.sling-mock-oak</artifactId> - <version>1.0.0</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.sling</groupId> - <artifactId>org.apache.sling.commons.testing</artifactId> - <version>2.0.18</version> - <scope>test</scope> - </dependency> - </dependencies> + <dependencies> + <dependency> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.testing.osgi-mock</artifactId> + <version>2.1.0</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.testing.jcr-mock</artifactId> + <version>1.1.16</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.testing.sling-mock</artifactId> + <version>2.1.2</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.testing.sling-mock-oak</artifactId> + <version>2.0.2</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>osgi.core</artifactId> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-simple</artifactId> + </dependency> + <dependency> + <groupId>javax.jcr</groupId> + <artifactId>jcr</artifactId> + </dependency> + <dependency> + <groupId>org.apache.jackrabbit</groupId> + <artifactId>jackrabbit-api</artifactId> + <version>${jackrabbit.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.jackrabbit</groupId> + <artifactId>jackrabbit-jcr-commons</artifactId> + <version>${jackrabbit.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>javax.servlet-api</artifactId> + </dependency> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>2.4</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.repoinit.parser</artifactId> + <version>1.0.5-SNAPSHOT</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.jcr.api</artifactId> + <version>2.4.0</version> + </dependency> + <dependency> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.provisioning.model</artifactId> + <version>1.4.2</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </dependency> + <dependency> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.commons.testing</artifactId> + <version>2.1.0</version> + <scope>test</scope> + </dependency> + </dependencies> </project> diff --git a/src/main/java/org/apache/sling/jcr/repoinit/JcrRepoInitOpsProcessor.java b/src/main/java/org/apache/sling/jcr/repoinit/JcrRepoInitOpsProcessor.java index 31de8ca..79ee7b2 100644 --- a/src/main/java/org/apache/sling/jcr/repoinit/JcrRepoInitOpsProcessor.java +++ b/src/main/java/org/apache/sling/jcr/repoinit/JcrRepoInitOpsProcessor.java @@ -21,8 +21,13 @@ import java.util.List; import javax.jcr.Session; import org.apache.sling.repoinit.parser.operations.Operation; +import org.osgi.annotation.versioning.ProviderType; -/** Apply Operations produced by the repoinit parser to a JCR Repository */ +/** + * Apply Operations produced by the repoinit parser to a JCR Repository + */ +@ProviderType public interface JcrRepoInitOpsProcessor { + void apply(Session session, List<Operation> ops); } diff --git a/src/main/java/org/apache/sling/jcr/repoinit/impl/JcrRepoInitOpsProcessorImpl.java b/src/main/java/org/apache/sling/jcr/repoinit/impl/JcrRepoInitOpsProcessorImpl.java index ca3aee0..4b37435 100644 --- a/src/main/java/org/apache/sling/jcr/repoinit/impl/JcrRepoInitOpsProcessorImpl.java +++ b/src/main/java/org/apache/sling/jcr/repoinit/impl/JcrRepoInitOpsProcessorImpl.java @@ -20,15 +20,15 @@ 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.jcr.repoinit.JcrRepoInitOpsProcessor; import org.apache.sling.repoinit.parser.operations.Operation; import org.apache.sling.repoinit.parser.operations.OperationVisitor; +import org.osgi.service.component.annotations.Component; -/** Apply Operations produced by the repoinit parser to a JCR Repository */ -@Component -@Service(JcrRepoInitOpsProcessor.class) +/** + * Apply Operations produced by the repoinit parser to a JCR Repository + */ +@Component(service = JcrRepoInitOpsProcessor.class) public class JcrRepoInitOpsProcessorImpl implements JcrRepoInitOpsProcessor { /** Apply the supplied operations: first the namespaces and nodetypes diff --git a/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializer.java b/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializer.java index c73f784..40fd13f 100644 --- a/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializer.java +++ b/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializer.java @@ -19,52 +19,49 @@ package org.apache.sling.jcr.repoinit.impl; import java.io.StringReader; import java.util.Arrays; import java.util.List; -import java.util.Map; import javax.jcr.Session; -import org.apache.felix.scr.annotations.Activate; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Properties; -import org.apache.felix.scr.annotations.Property; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.Service; -import org.apache.sling.commons.osgi.PropertiesUtil; import org.apache.sling.jcr.api.SlingRepository; import org.apache.sling.jcr.api.SlingRepositoryInitializer; import org.apache.sling.jcr.repoinit.JcrRepoInitOpsProcessor; import org.apache.sling.repoinit.parser.RepoInitParser; import org.apache.sling.repoinit.parser.operations.Operation; import org.osgi.framework.Constants; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; +import org.osgi.service.metatype.annotations.AttributeDefinition; +import org.osgi.service.metatype.annotations.Designate; +import org.osgi.service.metatype.annotations.ObjectClassDefinition; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** SlingRepositoryInitializer that executes repoinit statements read * from a configurable URL. */ -@Component( - label="Apache Sling Repository Initializer", - description="Initializes the JCR content repository using repoinit statements", - metatype=true) -@Service(SlingRepositoryInitializer.class) -@Properties({ - // SlingRepositoryInitializers are executed in ascending - // order of their service ranking - @Property(name=Constants.SERVICE_RANKING, intValue=100) -}) +@Designate(ocd = RepositoryInitializer.Config.class) +@Component(service = SlingRepositoryInitializer.class, + property = { + Constants.SERVICE_VENDOR + "=The Apache Software Foundation", + // SlingRepositoryInitializers are executed in ascending + // order of their service ranking + Constants.SERVICE_RANKING + ":Integer=100" + }) public class RepositoryInitializer implements SlingRepositoryInitializer { - private final Logger log = LoggerFactory.getLogger(getClass()); - @Property( - label="Repoinit references", + @ObjectClassDefinition(name = "Apache Sling Repository Initializer", + description="Initializes the JCR content repository using repoinit statements") + public @interface Config { + + @AttributeDefinition(name="Repoinit references", description= "References to the source text that provides repoinit statements." - + " format is either model@repoinit:<provisioning model URL> or raw:<raw URL>" - , - cardinality=Integer.MAX_VALUE, - value={}) - public static final String PROP_REFERENCES = "references"; - private String [] references; + + " format is either model@repoinit:<provisioning model URL> or raw:<raw URL>") + String[] references() default {}; + } + private final Logger log = LoggerFactory.getLogger(getClass()); + @Reference private RepoInitParser parser; @@ -72,32 +69,17 @@ public class RepositoryInitializer implements SlingRepositoryInitializer { @Reference private JcrRepoInitOpsProcessor processor; + private Config config; + @Activate - public void activate(Map<String, Object> config) { - warnForOldConfigParameters(config); - references = PropertiesUtil.toStringArray(config.get(PROP_REFERENCES), new String[]{}); + public void activate(Config config) { + this.config = config; log.debug("Activated: {}", this.toString()); } - /** Some config parameters are not used anymore as of V1.0.2, this logs - * warnings if they are still used. - */ - private void warnForOldConfigParameters(Map<String, Object> config) { - final String [] names = { - "text.url", - "text.format", - "model.section.name" - }; - for(String name : names) { - if(config.containsKey(name)) { - log.warn("Configuration parameter '{}' is not used anymore, will be ignored", name); - } - } - } - @Override public String toString() { - return getClass().getSimpleName() + ", references=" + Arrays.asList(references); + return getClass().getSimpleName() + ", references=" + Arrays.asList(config.references()); } @Override @@ -106,7 +88,7 @@ public class RepositoryInitializer implements SlingRepositoryInitializer { final Session s = repo.loginAdministrative(null); try { final RepoinitTextProvider p = new RepoinitTextProvider(); - for(String reference : references) { + for(String reference : config.references()) { final String repoinitText = p.getRepoinitText(reference); final List<Operation> ops = parser.parse(new StringReader(repoinitText)); log.info("Executing {} repoinit operations", ops.size()); diff --git a/src/main/java/org/apache/sling/jcr/repoinit/package-info.java b/src/main/java/org/apache/sling/jcr/repoinit/package-info.java index e52e88f..70246fb 100644 --- a/src/main/java/org/apache/sling/jcr/repoinit/package-info.java +++ b/src/main/java/org/apache/sling/jcr/repoinit/package-info.java @@ -15,7 +15,6 @@ * limitations under the License. ******************************************************************************/ -@Version("1.1.0") +@org.osgi.annotation.versioning.Version("1.1.2") package org.apache.sling.jcr.repoinit; -import aQute.bnd.annotation.Version; diff --git a/src/test/java/org/apache/sling/jcr/repoinit/RepositoryInitializerTest.java b/src/test/java/org/apache/sling/jcr/repoinit/RepositoryInitializerTest.java index 7167385..bbbf605 100644 --- a/src/test/java/org/apache/sling/jcr/repoinit/RepositoryInitializerTest.java +++ b/src/test/java/org/apache/sling/jcr/repoinit/RepositoryInitializerTest.java @@ -47,14 +47,14 @@ import org.junit.runners.Parameterized.Parameters; /** Test the two ways in which our RepositoryInitializer * can read repoinit statements: either from a provisioning - * model file or directly as raw repoinit statements. + * model file or directly as raw repoinit statements. */ @RunWith(Parameterized.class) public class RepositoryInitializerTest { - + @Rule public final SlingContext context = new SlingContext(ResourceResolverType.JCR_OAK); - + private RepositoryInitializer initializer; private Map<String, Object> config; private TestUtil U; @@ -65,37 +65,37 @@ public class RepositoryInitializerTest { private final boolean testLogin; private final String serviceUser; private final Class<?> expectedActivateException; - + @Parameters(name="{0}") public static Collection<Object[]> data() { final List<Object []> result = new ArrayList<Object[]>(); - + // Realistic cases - result.add(new Object[] { "Using provisioning model", "SECTION_" + UUID.randomUUID(), TextFormat.model.toString(), true, true, null }); + result.add(new Object[] { "Using provisioning model", "SECTION_" + UUID.randomUUID(), TextFormat.model.toString(), true, true, null }); result.add(new Object[] { "Default value of model section config", null, TextFormat.model.toString(), true, true, null }); - result.add(new Object[] { "Raw repoinit/empty section", "", TextFormat.raw.toString(), false, true, null }); - result.add(new Object[] { "Raw repoinit/ignored section name", "IGNORED_SectionName", TextFormat.raw.toString(), false, true, null }); - - // Edge and failure cases + result.add(new Object[] { "Raw repoinit/empty section", "", TextFormat.raw.toString(), false, true, null }); + result.add(new Object[] { "Raw repoinit/ignored section name", "IGNORED_SectionName", TextFormat.raw.toString(), false, true, null }); + + // Edge and failure cases result.add(new Object[] { "All empty, just setup + parsing", "", TextFormat.raw.toString(), false, false, null }); result.add(new Object[] { "Raw repoinit/null format", null, null, true, false, RepoInitParsingException.class }); result.add(new Object[] { "With model/null format", null, null, false, false, RuntimeException.class }); - result.add(new Object[] { "Invalid format", null, "invalidFormat", false, false, RuntimeException.class }); - result.add(new Object[] { "Empty model section", "", TextFormat.model.toString(), false, false, IllegalArgumentException.class }); + result.add(new Object[] { "Invalid format", null, "invalidFormat", false, false, RuntimeException.class }); + result.add(new Object[] { "Empty model section", "", TextFormat.model.toString(), false, false, IllegalArgumentException.class }); result.add(new Object[] { "Null model section", null, TextFormat.model.toString(), false, false, IOException.class }); - + return result; } - - public RepositoryInitializerTest(String description, String modelSection, String textFormat, + + public RepositoryInitializerTest(String description, String modelSection, String textFormat, boolean useProvisioningModel, boolean testLogin, Class<?> expectedException) throws IOException { serviceUser = getClass().getSimpleName() + "-" + UUID.randomUUID(); - - String txt = "create service user " + serviceUser; + + String txt = "create service user " + serviceUser; if(useProvisioningModel && modelSection == null) { - txt = "[feature name=foo]\n[:repoinit]\n" + txt; + txt = "[feature name=foo]\n[:repoinit]\n" + txt; } else if(useProvisioningModel) { - txt = "[feature name=bar]\n[:" + modelSection + "]\n" + txt; + txt = "[feature name=bar]\n[:" + modelSection + "]\n" + txt; } this.repoInitText = txt + "\n"; this.url = getTestUrl(repoInitText); @@ -104,15 +104,12 @@ public class RepositoryInitializerTest { this.textFormat = textFormat; this.expectedActivateException = expectedException; } - + @Before public void setup() throws Exception { U = new TestUtil(context); - initializer = new RepositoryInitializer(); - config = new HashMap<String, Object>(); - - String ref = null; + final String ref; if(TextFormat.model.toString().equals(textFormat)) { if(modelSection != null) { ref = "model@" + modelSection + ":" + url; @@ -122,15 +119,17 @@ public class RepositoryInitializerTest { } else { ref = "raw:" + url; } - - config.put(RepositoryInitializer.PROP_REFERENCES, new String[] { ref }); - + + initializer = new RepositoryInitializer(); + config = new HashMap<String, Object>(); + config.put("references", new String[] { ref }); + context.registerInjectActivateService(new RepoInitParserService()); context.registerInjectActivateService(new JcrRepoInitOpsProcessorImpl()); - + try { context.registerInjectActivateService(initializer, config); - + // Mock environment doesn't cause this to be called initializer.processRepository(context.getService(SlingRepository.class)); } catch(Exception e) { @@ -140,9 +139,9 @@ public class RepositoryInitializerTest { fail("Got unexpected " + e.getClass().getName() + " in activation"); } } - + } - + @Test public void testLogin() throws Exception { if(testLogin) { @@ -153,7 +152,7 @@ public class RepositoryInitializerTest { } } } - + /** Return the URL of a temporary file that contains repoInitText */ private String getTestUrl(String repoInitText) throws IOException { final File tmpFile = File.createTempFile(getClass().getSimpleName(), "txt"); -- To stop receiving notification emails like this one, please contact "commits@sling.apache.org" <commits@sling.apache.org>.