Index: oak-run/src/main/java/org/apache/jackrabbit/oak/run/build/NestedResourceBuilder.java =================================================================== --- oak-run/src/main/java/org/apache/jackrabbit/oak/run/build/NestedResourceBuilder.java (revision 0) +++ oak-run/src/main/java/org/apache/jackrabbit/oak/run/build/NestedResourceBuilder.java (working copy) @@ -0,0 +1,52 @@ +/* + * 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.jackrabbit.oak.run.build; + +import java.net.URI; + +/** + * Inspects the scheme of the URI and delegates to a child {@link + * ResourceBuilder} for the actual creation of the resource. + * + * @param The type of resource to create. + */ +public abstract class NestedResourceBuilder implements ResourceBuilder { + + @Override + public final T build(URI resource) { + ResourceBuilder builder = getResourceBuilder(resource.getScheme()); + + if (builder == null) { + return null; + } + + return builder.build(URI.create(resource.getRawSchemeSpecificPart())); + } + + /** + * Get the {@link ResourceBuilder} for the given scheme. + * + * @param scheme The scheme of the URI currently processed. It can be {@code + * null} if the URI has no scheme. + * @return A {@link ResourceBuilder} to delegate the creation of the + * resource, or {@code null} if no {@link ResourceBuilder} can be found for + * the given scheme. + */ + protected abstract ResourceBuilder getResourceBuilder(String scheme); + +} Property changes on: oak-run/src/main/java/org/apache/jackrabbit/oak/run/build/NestedResourceBuilder.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: oak-run/src/main/java/org/apache/jackrabbit/oak/run/build/ResourceBuilder.java =================================================================== --- oak-run/src/main/java/org/apache/jackrabbit/oak/run/build/ResourceBuilder.java (revision 0) +++ oak-run/src/main/java/org/apache/jackrabbit/oak/run/build/ResourceBuilder.java (working copy) @@ -0,0 +1,31 @@ +/* + * 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.jackrabbit.oak.run.build; + +import java.net.URI; + +/** + * Create a resource given an URI specifying its characteristics. + * + * @param The type of resource to create. + */ +public interface ResourceBuilder { + + T build(URI resource); + +} Property changes on: oak-run/src/main/java/org/apache/jackrabbit/oak/run/build/ResourceBuilder.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: oak-run/src/main/java/org/apache/jackrabbit/oak/run/build/store/NodeStoreResourceBuilder.java =================================================================== --- oak-run/src/main/java/org/apache/jackrabbit/oak/run/build/store/NodeStoreResourceBuilder.java (revision 0) +++ oak-run/src/main/java/org/apache/jackrabbit/oak/run/build/store/NodeStoreResourceBuilder.java (working copy) @@ -0,0 +1,88 @@ +/* + * 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.jackrabbit.oak.run.build.store; + +import java.net.URI; + +import org.apache.jackrabbit.oak.run.build.NestedResourceBuilder; +import org.apache.jackrabbit.oak.run.build.ResourceBuilder; +import org.apache.jackrabbit.oak.spi.state.NodeStore; + +/** + * Utility methods to create a {@link NodeStore} from its URI specification. + */ +public class NodeStoreResourceBuilder { + + private NodeStoreResourceBuilder() { + // Prevent instantiation. + } + + /** + * Creates a new {@link NodeStore} described by the given URI. + * + * @param uri An URI describing the {@link NodeStore} to build. + * @return An instance of {@link NodeStore} or {@code null} for an invalid + * URI. + */ + public static NodeStore buildNodeStore(URI uri) { + return newNodeStoreResourceBuilder().build(uri); + } + + private static ResourceBuilder newNodeStoreResourceBuilder() { + return new NestedResourceBuilder() { + + @Override + protected ResourceBuilder getResourceBuilder(String scheme) { + if (scheme == null) { + return null; + } + + switch (scheme) { + case "segment": + return newSegmentResourceBuilder(); + default: + return null; + } + } + + }; + } + + private static ResourceBuilder newSegmentResourceBuilder() { + return new NestedResourceBuilder() { + + @Override + protected ResourceBuilder getResourceBuilder(String scheme) { + if (scheme == null) { + return new SegmentResourceBuilder(); + } + + switch (scheme) { + case "tar": + return new SegmentTarResourceBuilder(); + case "mem": + return new SegmentMemResourceBuilder(); + default: + return null; + } + } + + }; + } + +} Property changes on: oak-run/src/main/java/org/apache/jackrabbit/oak/run/build/store/NodeStoreResourceBuilder.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: oak-run/src/main/java/org/apache/jackrabbit/oak/run/build/store/SegmentMemResourceBuilder.java =================================================================== --- oak-run/src/main/java/org/apache/jackrabbit/oak/run/build/store/SegmentMemResourceBuilder.java (revision 0) +++ oak-run/src/main/java/org/apache/jackrabbit/oak/run/build/store/SegmentMemResourceBuilder.java (working copy) @@ -0,0 +1,43 @@ +/* + * 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.jackrabbit.oak.run.build.store; + +import java.io.IOException; +import java.net.URI; + +import org.apache.jackrabbit.oak.run.build.ResourceBuilder; +import org.apache.jackrabbit.oak.segment.SegmentNodeStore; +import org.apache.jackrabbit.oak.segment.memory.MemoryStore; +import org.apache.jackrabbit.oak.spi.state.NodeStore; + +class SegmentMemResourceBuilder implements ResourceBuilder { + + @Override + public NodeStore build(URI resource) { + MemoryStore store; + + try { + store = new MemoryStore(); + } catch (IOException e) { + throw new IllegalStateException(e); + } + + return SegmentNodeStore.builder(store).build(); + } + +} Property changes on: oak-run/src/main/java/org/apache/jackrabbit/oak/run/build/store/SegmentMemResourceBuilder.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: oak-run/src/main/java/org/apache/jackrabbit/oak/run/build/store/SegmentResourceBuilder.java =================================================================== --- oak-run/src/main/java/org/apache/jackrabbit/oak/run/build/store/SegmentResourceBuilder.java (revision 0) +++ oak-run/src/main/java/org/apache/jackrabbit/oak/run/build/store/SegmentResourceBuilder.java (working copy) @@ -0,0 +1,44 @@ +/* + * 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.jackrabbit.oak.run.build.store; + +import java.io.File; +import java.io.IOException; +import java.net.URI; + +import org.apache.jackrabbit.oak.plugins.segment.SegmentNodeStore; +import org.apache.jackrabbit.oak.plugins.segment.file.FileStore; +import org.apache.jackrabbit.oak.run.build.ResourceBuilder; +import org.apache.jackrabbit.oak.spi.state.NodeStore; + +class SegmentResourceBuilder implements ResourceBuilder { + + @Override + public NodeStore build(URI resource) { + FileStore store; + + try { + store = FileStore.builder(new File(resource.getPath())).build(); + } catch (IOException e) { + throw new IllegalStateException(e); + } + + return SegmentNodeStore.builder(store).build(); + } + +} Property changes on: oak-run/src/main/java/org/apache/jackrabbit/oak/run/build/store/SegmentResourceBuilder.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: oak-run/src/main/java/org/apache/jackrabbit/oak/run/build/store/SegmentTarResourceBuilder.java =================================================================== --- oak-run/src/main/java/org/apache/jackrabbit/oak/run/build/store/SegmentTarResourceBuilder.java (revision 0) +++ oak-run/src/main/java/org/apache/jackrabbit/oak/run/build/store/SegmentTarResourceBuilder.java (working copy) @@ -0,0 +1,44 @@ +/* + * 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.jackrabbit.oak.run.build.store; + +import java.io.File; +import java.io.IOException; +import java.net.URI; + +import org.apache.jackrabbit.oak.run.build.ResourceBuilder; +import org.apache.jackrabbit.oak.segment.SegmentNodeStore; +import org.apache.jackrabbit.oak.segment.file.FileStore; +import org.apache.jackrabbit.oak.spi.state.NodeStore; + +class SegmentTarResourceBuilder implements ResourceBuilder { + + @Override + public NodeStore build(URI resource) { + FileStore store; + + try { + store = FileStore.builder(new File(resource.getPath())).build(); + } catch (IOException e) { + throw new IllegalStateException(e); + } + + return SegmentNodeStore.builder(store).build(); + } + +} Property changes on: oak-run/src/main/java/org/apache/jackrabbit/oak/run/build/store/SegmentTarResourceBuilder.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: oak-run/src/test/java/org/apache/jackrabbit/oak/run/build/NestedResourceBuilderTest.java =================================================================== --- oak-run/src/test/java/org/apache/jackrabbit/oak/run/build/NestedResourceBuilderTest.java (revision 0) +++ oak-run/src/test/java/org/apache/jackrabbit/oak/run/build/NestedResourceBuilderTest.java (working copy) @@ -0,0 +1,104 @@ +/* + * 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.jackrabbit.oak.run.build; + +import static org.junit.Assert.assertEquals; + +import java.net.URI; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +@RunWith(Parameterized.class) +public class NestedResourceBuilderTest { + + private static ResourceBuilder SCHEME = new NestedResourceBuilder() { + + @Override + protected ResourceBuilder getResourceBuilder(final String scheme) { + return new ResourceBuilder() { + + @Override + public String build(URI resource) { + return scheme; + } + + }; + } + + }; + + private static ResourceBuilder NESTED = new NestedResourceBuilder() { + + @Override + protected ResourceBuilder getResourceBuilder(String scheme) { + return new ResourceBuilder() { + + @Override + public URI build(URI resource) { + return resource; + } + + }; + } + + }; + + private static void assertScheme(String uri, String scheme) { + assertEquals(SCHEME.build(URI.create(uri)), scheme); + } + + private static void assertNested(String uri, String nested) { + assertEquals(NESTED.build(URI.create(uri)), URI.create(nested)); + } + + @Parameters(name = "{0}") + public static Object[][] parameters() { + return new Object[][] { + {"/path", null, "/path"}, + {"segment:///path", "segment", "/path"}, + {"segment:///path?mm=false", "segment", "/path?mm=false"}, + {"segment:tar:///path", "segment", "tar:///path"} + }; + } + + private final String uri; + + private final String scheme; + + private final String nested; + + public NestedResourceBuilderTest(String uri, String scheme, String nested) { + this.uri = uri; + this.scheme = scheme; + this.nested = nested; + } + + @Test + public void testScheme() { + assertScheme(uri, scheme); + } + + @Test + public void testNested() { + assertNested(uri, nested); + } + +} Property changes on: oak-run/src/test/java/org/apache/jackrabbit/oak/run/build/NestedResourceBuilderTest.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property