This is an automated email from the ASF dual-hosted git repository. sseifert pushed a commit to branch feature/SLING-12284-parent-60 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock-oak.git
commit 980b5a0c2bc75a09074569e7f247bd3b977598bb Author: Stefan Seifert <stefanseif...@users.noreply.github.com> AuthorDate: Tue Apr 9 17:52:01 2024 +0200 SLING-12284 apply spotless code formatting --- pom.xml | 25 +- .../testing/mock/sling/oak/ExtraSlingContent.java | 11 +- .../sling/oak/OakMockResourceResolverAdapter.java | 1 - .../mock/sling/oak/OakMockSlingRepository.java | 62 ++- .../mock/sling/oak/impl/ComparableVersion.java | 542 ++++++++------------- .../sling/oak/loader/ContentLoaderBinaryTest.java | 1 - .../oak/loader/ContentLoaderFileVaultXmlTest.java | 1 - .../ContentLoaderFolderFileVaultXmlTest.java | 1 - .../oak/loader/ContentLoaderFolderJsonTest.java | 1 - .../sling/oak/loader/ContentLoaderJsonDamTest.java | 1 - .../sling/oak/loader/ContentLoaderJsonTest.java | 32 +- .../mock/sling/oak/resource/JcrNamespaceTest.java | 1 - .../oak/resource/JcrResourceResolverTest.java | 1 - .../oak/resource/MultipleResourceResolverTest.java | 1 - .../resource/SlingCrudResourceResolverTest.java | 1 - .../mock/sling/oak/resource/UniqueRootTest.java | 1 - 16 files changed, 285 insertions(+), 398 deletions(-) diff --git a/pom.xml b/pom.xml index b1998bf..66b50cb 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 @@ -28,12 +28,20 @@ </parent> <artifactId>org.apache.sling.testing.sling-mock-oak</artifactId> - <version>3.2.0-1.44.0-SNAPSHOT</version> <!-- second component is the oak version, please keep in sync with oak.version property --> + <version>3.2.0-1.44.0-SNAPSHOT</version> + <!-- second component is the oak version, please keep in sync with oak.version property --> <packaging>jar</packaging> <name>Apache Sling Testing Sling Mock Oak</name> <description>Implements a resource resolver type for Jackrabbit Oak that can be used in unit tests based on Sling Mocks.</description> + <scm> + <connection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock-oak.git</connection> + <developerConnection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock-oak.git</developerConnection> + <tag>HEAD</tag> + <url>https://github.com/apache/sling-org-apache-sling-testing-sling-mock-oak.git</url> + </scm> + <properties> <oak.version>1.44.0</oak.version> <jackrabbit.version>2.20.9</jackrabbit.version> @@ -42,13 +50,6 @@ <project.build.outputTimestamp>2023-05-16T08:40:51Z</project.build.outputTimestamp> </properties> - <scm> - <connection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock-oak.git</connection> - <developerConnection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock-oak.git</developerConnection> - <url>https://github.com/apache/sling-org-apache-sling-testing-sling-mock-oak.git</url> - <tag>HEAD</tag> - </scm> - <dependencies> <dependency> @@ -162,7 +163,7 @@ <dependency> <groupId>org.apache.geronimo.specs</groupId> <artifactId>geronimo-annotation_1.3_spec</artifactId> - <version>1.0</version> + <version>1.0</version> <scope>test</scope> </dependency> @@ -211,14 +212,14 @@ <pattern>com.google.common</pattern> <shadedPattern>sling-mock-oak.com.google.common</shadedPattern> </relocation> - </relocations> + </relocations> </configuration> <executions> <execution> - <phase>package</phase> <goals> <goal>shade</goal> </goals> + <phase>package</phase> </execution> </executions> </plugin> diff --git a/src/main/java/org/apache/sling/testing/mock/sling/oak/ExtraSlingContent.java b/src/main/java/org/apache/sling/testing/mock/sling/oak/ExtraSlingContent.java index 94c38f4..891de5c 100644 --- a/src/main/java/org/apache/sling/testing/mock/sling/oak/ExtraSlingContent.java +++ b/src/main/java/org/apache/sling/testing/mock/sling/oak/ExtraSlingContent.java @@ -18,6 +18,11 @@ */ package org.apache.sling.testing.mock.sling.oak; +import org.apache.jackrabbit.oak.plugins.name.Namespaces; +import org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer; +import org.apache.jackrabbit.oak.spi.state.NodeBuilder; +import org.jetbrains.annotations.NotNull; + import static java.util.Collections.singleton; import static org.apache.jackrabbit.JcrConstants.JCR_SYSTEM; import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_DEFINITIONS_NAME; @@ -25,11 +30,6 @@ import static org.apache.jackrabbit.oak.plugins.index.IndexUtils.createIndexDefi import static org.apache.jackrabbit.oak.spi.namespace.NamespaceConstants.REP_NAMESPACES; import static org.apache.sling.jcr.resource.api.JcrResourceConstants.SLING_NAMESPACE_URI; -import org.apache.jackrabbit.oak.plugins.name.Namespaces; -import org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer; -import org.apache.jackrabbit.oak.spi.state.NodeBuilder; -import org.jetbrains.annotations.NotNull; - /** * Adds some default indexes useful for by sling resource-jcr mapping. * This is only a small subset of what is defined by default in the org.apache.sling.jcr.oak.server bundle. @@ -74,5 +74,4 @@ final class ExtraSlingContent implements RepositoryInitializer { createIndexDefinition(index, indexName, true, false, singleton(propertyName), null); } } - } diff --git a/src/main/java/org/apache/sling/testing/mock/sling/oak/OakMockResourceResolverAdapter.java b/src/main/java/org/apache/sling/testing/mock/sling/oak/OakMockResourceResolverAdapter.java index cefb70b..73fb9ca 100644 --- a/src/main/java/org/apache/sling/testing/mock/sling/oak/OakMockResourceResolverAdapter.java +++ b/src/main/java/org/apache/sling/testing/mock/sling/oak/OakMockResourceResolverAdapter.java @@ -36,5 +36,4 @@ public class OakMockResourceResolverAdapter implements ResourceResolverTypeAdapt public SlingRepository newSlingRepository() { return new OakMockSlingRepository(); } - } diff --git a/src/main/java/org/apache/sling/testing/mock/sling/oak/OakMockSlingRepository.java b/src/main/java/org/apache/sling/testing/mock/sling/oak/OakMockSlingRepository.java index c30dfe4..2693cb5 100644 --- a/src/main/java/org/apache/sling/testing/mock/sling/oak/OakMockSlingRepository.java +++ b/src/main/java/org/apache/sling/testing/mock/sling/oak/OakMockSlingRepository.java @@ -18,6 +18,15 @@ */ package org.apache.sling.testing.mock.sling.oak; +import javax.jcr.Credentials; +import javax.jcr.LoginException; +import javax.jcr.NoSuchWorkspaceException; +import javax.jcr.Repository; +import javax.jcr.RepositoryException; +import javax.jcr.Session; +import javax.jcr.SimpleCredentials; +import javax.jcr.Value; + import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; @@ -29,15 +38,6 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; -import javax.jcr.Credentials; -import javax.jcr.LoginException; -import javax.jcr.NoSuchWorkspaceException; -import javax.jcr.Repository; -import javax.jcr.RepositoryException; -import javax.jcr.Session; -import javax.jcr.SimpleCredentials; -import javax.jcr.Value; - import org.apache.jackrabbit.api.JackrabbitRepository; import org.apache.jackrabbit.oak.Oak; import org.apache.jackrabbit.oak.jcr.Jcr; @@ -72,27 +72,26 @@ public final class OakMockSlingRepository implements SlingRepository { bundleContext.registerService(Executor.class, executor, null); } - Oak oak = new Oak() - .with(executor) - .with(scheduledExecutor); + Oak oak = new Oak().with(executor).with(scheduledExecutor); - Jcr jcr = new Jcr(oak) - .with(new ExtraSlingContent()) - .with(executor) - .with(scheduledExecutor); + Jcr jcr = new Jcr(oak).with(new ExtraSlingContent()).with(executor).with(scheduledExecutor); this.repository = jcr.createRepository(); - // check if the right Oak version is loaded (older versions may be loaded in case of non-deliberate class loader collisions) + // check if the right Oak version is loaded (older versions may be loaded in case of non-deliberate class loader + // collisions) String expectedVersion = getExpectedVersion(); String actualVersion = repository.getDescriptor(REP_VERSION_DESC); if (new ComparableVersion(expectedVersion).compareTo(new ComparableVersion(actualVersion)) > 0) { - throw new IllegalStateException("Unexpected (too old) Oak version " + actualVersion + ", expected " + expectedVersion + ". Make sure to load the `org.apache.sling.testing.sling-mock-oak` dependency before any other dependency which may transitively depend on Apache Jackrabbit Oak as well!"); + throw new IllegalStateException( + "Unexpected (too old) Oak version " + actualVersion + ", expected " + expectedVersion + + ". Make sure to load the `org.apache.sling.testing.sling-mock-oak` dependency before any other dependency which may transitively depend on Apache Jackrabbit Oak as well!"); } } private static String getExpectedVersion() throws IOException { try (InputStream inputStream = OakMockSlingRepository.class.getResourceAsStream("oak.version"); - BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) { + BufferedReader reader = + new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) { return reader.readLine(); } } @@ -100,24 +99,27 @@ public final class OakMockSlingRepository implements SlingRepository { @Deactivate protected void deactivate(ComponentContext componentContext) { // shutdown executors - // force immediate shutdown for all executors without waiting for tasks for completion - we're only in unit tests! + // force immediate shutdown for all executors without waiting for tasks for completion - we're only in unit + // tests! executor.shutdownNow(); scheduledExecutor.shutdownNow(); shutdownExecutorService(repository, "scheduledExecutor"); // shutdown OAK JCR repository - ((JackrabbitRepository)repository).shutdown(); + ((JackrabbitRepository) repository).shutdown(); } private void shutdownExecutorService(Object instance, String fieldName) { try { Field executorField = instance.getClass().getDeclaredField(fieldName); executorField.setAccessible(true); - ExecutorService executor = (ExecutorService)executorField.get(instance); + ExecutorService executor = (ExecutorService) executorField.get(instance); executor.shutdownNow(); - } - catch (Throwable ex) { - log.error("Potential Memory leak: Unable to shutdown executor service from field '" + fieldName + "' in " + instance, ex); + } catch (Throwable ex) { + log.error( + "Potential Memory leak: Unable to shutdown executor service from field '" + fieldName + "' in " + + instance, + ex); } } @@ -146,18 +148,15 @@ public final class OakMockSlingRepository implements SlingRepository { return repository.login(credentials, (workspaceName == null ? getDefaultWorkspace() : workspaceName)); } - public Session login(Credentials credentials) - throws LoginException, RepositoryException { + public Session login(Credentials credentials) throws LoginException, RepositoryException { return repository.login(credentials); } - public Session login(String workspaceName) - throws LoginException, NoSuchWorkspaceException, RepositoryException { + public Session login(String workspaceName) throws LoginException, NoSuchWorkspaceException, RepositoryException { return repository.login((workspaceName == null ? getDefaultWorkspace() : workspaceName)); } - public Session loginAdministrative(String workspaceName) - throws RepositoryException { + public Session loginAdministrative(String workspaceName) throws RepositoryException { final Credentials credentials = new SimpleCredentials(ADMIN_NAME, ADMIN_PASSWORD.toCharArray()); return this.login(credentials, (workspaceName == null ? getDefaultWorkspace() : workspaceName)); } @@ -189,5 +188,4 @@ public final class OakMockSlingRepository implements SlingRepository { throws LoginException, RepositoryException { return repository.login(credentials, (workspaceName == null ? getDefaultWorkspace() : workspaceName)); } - } diff --git a/src/main/java/org/apache/sling/testing/mock/sling/oak/impl/ComparableVersion.java b/src/main/java/org/apache/sling/testing/mock/sling/oak/impl/ComparableVersion.java index 1340acc..760f13f 100644 --- a/src/main/java/org/apache/sling/testing/mock/sling/oak/impl/ComparableVersion.java +++ b/src/main/java/org/apache/sling/testing/mock/sling/oak/impl/ComparableVersion.java @@ -1,3 +1,21 @@ +/* + * 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.testing.mock.sling.oak.impl; /* * Licensed to the Apache Software Foundation (ASF) under one @@ -18,7 +36,8 @@ package org.apache.sling.testing.mock.sling.oak.impl; * under the License. */ -//copied from https://github.com/apache/maven/blob/98a6c4f14c85f584e37773b86b448d36c30e0d93/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/ComparableVersion.java#L1 +// copied from +// https://github.com/apache/maven/blob/98a6c4f14c85f584e37773b86b448d36c30e0d93/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/ComparableVersion.java#L1 import java.math.BigInteger; import java.util.ArrayDeque; @@ -61,9 +80,7 @@ import java.util.Properties; * @author <a href="mailto:ken...@apache.org">Kenney Westerhof</a> * @author <a href="mailto:hbout...@apache.org">Hervé Boutemy</a> */ -public class ComparableVersion - implements Comparable<ComparableVersion> -{ +public class ComparableVersion implements Comparable<ComparableVersion> { private static final int MAX_INTITEM_LENGTH = 9; private static final int MAX_LONGITEM_LENGTH = 18; @@ -74,15 +91,14 @@ public class ComparableVersion private ListItem items; - private interface Item - { + private interface Item { int INT_ITEM = 3; int LONG_ITEM = 4; int BIGINTEGER_ITEM = 0; int STRING_ITEM = 1; int LIST_ITEM = 2; - int compareTo( Item item ); + int compareTo(Item item); int getType(); @@ -92,48 +108,39 @@ public class ComparableVersion /** * Represents a numeric item in the version item list that can be represented with an int. */ - private static class IntItem - implements Item - { + private static class IntItem implements Item { private final int value; public static final IntItem ZERO = new IntItem(); - private IntItem() - { + private IntItem() { this.value = 0; } - IntItem( String str ) - { - this.value = Integer.parseInt( str ); + IntItem(String str) { + this.value = Integer.parseInt(str); } @Override - public int getType() - { + public int getType() { return INT_ITEM; } @Override - public boolean isNull() - { + public boolean isNull() { return value == 0; } @Override - public int compareTo( Item item ) - { - if ( item == null ) - { - return ( value == 0 ) ? 0 : 1; // 1.0 == 1, 1.1 > 1 + public int compareTo(Item item) { + if (item == null) { + return (value == 0) ? 0 : 1; // 1.0 == 1, 1.1 > 1 } - switch ( item.getType() ) - { + switch (item.getType()) { case INT_ITEM: - int itemValue = ( (IntItem) item ).value; - return Integer.compare( value, itemValue ); + int itemValue = ((IntItem) item).value; + return Integer.compare(value, itemValue); case LONG_ITEM: case BIGINTEGER_ITEM: return -1; @@ -145,81 +152,67 @@ public class ComparableVersion return 1; // 1.1 > 1-1 default: - throw new IllegalStateException( "invalid item: " + item.getClass() ); + throw new IllegalStateException("invalid item: " + item.getClass()); } } @Override - public boolean equals( Object o ) - { - if ( this == o ) - { + public boolean equals(Object o) { + if (this == o) { return true; } - if ( o == null || getClass() != o.getClass() ) - { + if (o == null || getClass() != o.getClass()) { return false; } IntItem intItem = (IntItem) o; return value == intItem.value; - } @Override - public int hashCode() - { + public int hashCode() { return value; } @Override - public String toString() - { - return Integer.toString( value ); + public String toString() { + return Integer.toString(value); } } /** * Represents a numeric item in the version item list that can be represented with a long. */ - private static class LongItem - implements Item - { + private static class LongItem implements Item { private final long value; - LongItem( String str ) - { - this.value = Long.parseLong( str ); + LongItem(String str) { + this.value = Long.parseLong(str); } @Override - public int getType() - { + public int getType() { return LONG_ITEM; } @Override - public boolean isNull() - { + public boolean isNull() { return value == 0; } @Override - public int compareTo( Item item ) - { - if ( item == null ) - { - return ( value == 0 ) ? 0 : 1; // 1.0 == 1, 1.1 > 1 + public int compareTo(Item item) { + if (item == null) { + return (value == 0) ? 0 : 1; // 1.0 == 1, 1.1 > 1 } - switch ( item.getType() ) - { + switch (item.getType()) { case INT_ITEM: return 1; case LONG_ITEM: - long itemValue = ( (LongItem) item ).value; - return Long.compare( value, itemValue ); + long itemValue = ((LongItem) item).value; + return Long.compare(value, itemValue); case BIGINTEGER_ITEM: return -1; @@ -230,82 +223,68 @@ public class ComparableVersion return 1; // 1.1 > 1-1 default: - throw new IllegalStateException( "invalid item: " + item.getClass() ); + throw new IllegalStateException("invalid item: " + item.getClass()); } } @Override - public boolean equals( Object o ) - { - if ( this == o ) - { + public boolean equals(Object o) { + if (this == o) { return true; } - if ( o == null || getClass() != o.getClass() ) - { + if (o == null || getClass() != o.getClass()) { return false; } LongItem longItem = (LongItem) o; return value == longItem.value; - } @Override - public int hashCode() - { - return (int) ( value ^ ( value >>> 32 ) ); + public int hashCode() { + return (int) (value ^ (value >>> 32)); } @Override - public String toString() - { - return Long.toString( value ); + public String toString() { + return Long.toString(value); } } /** * Represents a numeric item in the version item list. */ - private static class BigIntegerItem - implements Item - { + private static class BigIntegerItem implements Item { private final BigInteger value; - BigIntegerItem( String str ) - { - this.value = new BigInteger( str ); + BigIntegerItem(String str) { + this.value = new BigInteger(str); } @Override - public int getType() - { + public int getType() { return BIGINTEGER_ITEM; } @Override - public boolean isNull() - { - return BigInteger.ZERO.equals( value ); + public boolean isNull() { + return BigInteger.ZERO.equals(value); } @Override - public int compareTo( Item item ) - { - if ( item == null ) - { - return BigInteger.ZERO.equals( value ) ? 0 : 1; // 1.0 == 1, 1.1 > 1 + public int compareTo(Item item) { + if (item == null) { + return BigInteger.ZERO.equals(value) ? 0 : 1; // 1.0 == 1, 1.1 > 1 } - switch ( item.getType() ) - { + switch (item.getType()) { case INT_ITEM: case LONG_ITEM: return 1; case BIGINTEGER_ITEM: - return value.compareTo( ( (BigIntegerItem) item ).value ); + return value.compareTo(((BigIntegerItem) item).value); case STRING_ITEM: return 1; // 1.1 > 1-sp @@ -314,36 +293,30 @@ public class ComparableVersion return 1; // 1.1 > 1-1 default: - throw new IllegalStateException( "invalid item: " + item.getClass() ); + throw new IllegalStateException("invalid item: " + item.getClass()); } } @Override - public boolean equals( Object o ) - { - if ( this == o ) - { + public boolean equals(Object o) { + if (this == o) { return true; } - if ( o == null || getClass() != o.getClass() ) - { + if (o == null || getClass() != o.getClass()) { return false; } BigIntegerItem that = (BigIntegerItem) o; - return value.equals( that.value ); - + return value.equals(that.value); } @Override - public int hashCode() - { + public int hashCode() { return value.hashCode(); } - public String toString() - { + public String toString() { return value.toString(); } } @@ -351,36 +324,31 @@ public class ComparableVersion /** * Represents a string in the version item list, usually a qualifier. */ - private static class StringItem - implements Item - { + private static class StringItem implements Item { private static final List<String> QUALIFIERS = - Arrays.asList( "alpha", "beta", "milestone", "rc", "snapshot", "", "sp" ); + Arrays.asList("alpha", "beta", "milestone", "rc", "snapshot", "", "sp"); private static final Properties ALIASES = new Properties(); - static - { - ALIASES.put( "ga", "" ); - ALIASES.put( "final", "" ); - ALIASES.put( "release", "" ); - ALIASES.put( "cr", "rc" ); + + static { + ALIASES.put("ga", ""); + ALIASES.put("final", ""); + ALIASES.put("release", ""); + ALIASES.put("cr", "rc"); } /** * A comparable value for the empty-string qualifier. This one is used to determine if a given qualifier makes * the version older than one without a qualifier, or more recent. */ - private static final String RELEASE_VERSION_INDEX = String.valueOf( QUALIFIERS.indexOf( "" ) ); + private static final String RELEASE_VERSION_INDEX = String.valueOf(QUALIFIERS.indexOf("")); private final String value; - StringItem( String value, boolean followedByDigit ) - { - if ( followedByDigit && value.length() == 1 ) - { + StringItem(String value, boolean followedByDigit) { + if (followedByDigit && value.length() == 1) { // a1 = alpha-1, b1 = beta-1, m1 = milestone-1 - switch ( value.charAt( 0 ) ) - { + switch (value.charAt(0)) { case 'a': value = "alpha"; break; @@ -393,19 +361,17 @@ public class ComparableVersion default: } } - this.value = ALIASES.getProperty( value , value ); + this.value = ALIASES.getProperty(value, value); } @Override - public int getType() - { + public int getType() { return STRING_ITEM; } @Override - public boolean isNull() - { - return ( comparableQualifier( value ).compareTo( RELEASE_VERSION_INDEX ) == 0 ); + public boolean isNull() { + return (comparableQualifier(value).compareTo(RELEASE_VERSION_INDEX) == 0); } /** @@ -421,65 +387,55 @@ public class ComparableVersion * @param qualifier * @return an equivalent value that can be used with lexical comparison */ - public static String comparableQualifier( String qualifier ) - { - int i = QUALIFIERS.indexOf( qualifier ); + public static String comparableQualifier(String qualifier) { + int i = QUALIFIERS.indexOf(qualifier); - return i == -1 ? ( QUALIFIERS.size() + "-" + qualifier ) : String.valueOf( i ); + return i == -1 ? (QUALIFIERS.size() + "-" + qualifier) : String.valueOf(i); } @Override - public int compareTo( Item item ) - { - if ( item == null ) - { + public int compareTo(Item item) { + if (item == null) { // 1-rc < 1, 1-ga > 1 - return comparableQualifier( value ).compareTo( RELEASE_VERSION_INDEX ); + return comparableQualifier(value).compareTo(RELEASE_VERSION_INDEX); } - switch ( item.getType() ) - { + switch (item.getType()) { case INT_ITEM: case LONG_ITEM: case BIGINTEGER_ITEM: return -1; // 1.any < 1.1 ? case STRING_ITEM: - return comparableQualifier( value ).compareTo( comparableQualifier( ( (StringItem) item ).value ) ); + return comparableQualifier(value).compareTo(comparableQualifier(((StringItem) item).value)); case LIST_ITEM: return -1; // 1.any < 1-1 default: - throw new IllegalStateException( "invalid item: " + item.getClass() ); + throw new IllegalStateException("invalid item: " + item.getClass()); } } @Override - public boolean equals( Object o ) - { - if ( this == o ) - { + public boolean equals(Object o) { + if (this == o) { return true; } - if ( o == null || getClass() != o.getClass() ) - { + if (o == null || getClass() != o.getClass()) { return false; } StringItem that = (StringItem) o; - return value.equals( that.value ); - + return value.equals(that.value); } @Override - public int hashCode() - { + public int hashCode() { return value.hashCode(); } - public String toString() - { + public String toString() { return value; } } @@ -488,62 +444,46 @@ public class ComparableVersion * Represents a version list item. This class is used both for the global item list and for sub-lists (which start * with '-(number)' in the version specification). */ - private static class ListItem - extends ArrayList<Item> - implements Item - { + private static class ListItem extends ArrayList<Item> implements Item { @Override - public int getType() - { + public int getType() { return LIST_ITEM; } @Override - public boolean isNull() - { - return ( size() == 0 ); + public boolean isNull() { + return (size() == 0); } - void normalize() - { - for ( int i = size() - 1; i >= 0; i-- ) - { - Item lastItem = get( i ); + void normalize() { + for (int i = size() - 1; i >= 0; i--) { + Item lastItem = get(i); - if ( lastItem.isNull() ) - { + if (lastItem.isNull()) { // remove null trailing items: 0, "", empty list - remove( i ); - } - else if ( !( lastItem instanceof ListItem ) ) - { + remove(i); + } else if (!(lastItem instanceof ListItem)) { break; } } } @Override - public int compareTo( Item item ) - { - if ( item == null ) - { - if ( size() == 0 ) - { + public int compareTo(Item item) { + if (item == null) { + if (size() == 0) { return 0; // 1-0 = 1- (normalize) = 1 } // Compare the entire list of items with null - not just the first one, MNG-6964 - for ( Item i : this ) - { - int result = i.compareTo( null ); - if ( result != 0 ) - { + for (Item i : this) { + int result = i.compareTo(null); + if (result != 0) { return result; } } return 0; } - switch ( item.getType() ) - { + switch (item.getType()) { case INT_ITEM: case LONG_ITEM: case BIGINTEGER_ITEM: @@ -554,18 +494,16 @@ public class ComparableVersion case LIST_ITEM: Iterator<Item> left = iterator(); - Iterator<Item> right = ( (ListItem) item ).iterator(); + Iterator<Item> right = ((ListItem) item).iterator(); - while ( left.hasNext() || right.hasNext() ) - { + while (left.hasNext() || right.hasNext()) { Item l = left.hasNext() ? left.next() : null; Item r = right.hasNext() ? right.next() : null; // if this is shorter, then invert the compare and mul with -1 - int result = l == null ? ( r == null ? 0 : -1 * r.compareTo( l ) ) : l.compareTo( r ); + int result = l == null ? (r == null ? 0 : -1 * r.compareTo(l)) : l.compareTo(r); - if ( result != 0 ) - { + if (result != 0) { return result; } } @@ -573,21 +511,18 @@ public class ComparableVersion return 0; default: - throw new IllegalStateException( "invalid item: " + item.getClass() ); + throw new IllegalStateException("invalid item: " + item.getClass()); } } @Override - public String toString() - { + public String toString() { StringBuilder buffer = new StringBuilder(); - for ( Item item : this ) - { - if ( buffer.length() > 0 ) - { - buffer.append( ( item instanceof ListItem ) ? '-' : '.' ); + for (Item item : this) { + if (buffer.length() > 0) { + buffer.append((item instanceof ListItem) ? '-' : '.'); } - buffer.append( item ); + buffer.append(item); } return buffer.toString(); } @@ -595,191 +530,150 @@ public class ComparableVersion /** * Return the contents in the same format that is used when you call toString() on a List. */ - private String toListString() - { + private String toListString() { StringBuilder buffer = new StringBuilder(); - buffer.append( "[" ); - for ( Item item : this ) - { - if ( buffer.length() > 1 ) - { - buffer.append( ", " ); - } - if ( item instanceof ListItem ) - { - buffer.append( ( (ListItem ) item ).toListString() ); + buffer.append("["); + for (Item item : this) { + if (buffer.length() > 1) { + buffer.append(", "); } - else - { - buffer.append( item ); + if (item instanceof ListItem) { + buffer.append(((ListItem) item).toListString()); + } else { + buffer.append(item); } } - buffer.append( "]" ); + buffer.append("]"); return buffer.toString(); } } - public ComparableVersion( String version ) - { - parseVersion( version ); + public ComparableVersion(String version) { + parseVersion(version); } - @SuppressWarnings( "checkstyle:innerassignment" ) - public final void parseVersion( String version ) - { + @SuppressWarnings("checkstyle:innerassignment") + public final void parseVersion(String version) { this.value = version; items = new ListItem(); - version = version.toLowerCase( Locale.ENGLISH ); + version = version.toLowerCase(Locale.ENGLISH); ListItem list = items; Deque<Item> stack = new ArrayDeque<>(); - stack.push( list ); + stack.push(list); boolean isDigit = false; int startIndex = 0; - for ( int i = 0; i < version.length(); i++ ) - { - char c = version.charAt( i ); + for (int i = 0; i < version.length(); i++) { + char c = version.charAt(i); - if ( c == '.' ) - { - if ( i == startIndex ) - { - list.add( IntItem.ZERO ); - } - else - { - list.add( parseItem( isDigit, version.substring( startIndex, i ) ) ); + if (c == '.') { + if (i == startIndex) { + list.add(IntItem.ZERO); + } else { + list.add(parseItem(isDigit, version.substring(startIndex, i))); } startIndex = i + 1; - } - else if ( c == '-' ) - { - if ( i == startIndex ) - { - list.add( IntItem.ZERO ); - } - else - { - list.add( parseItem( isDigit, version.substring( startIndex, i ) ) ); + } else if (c == '-') { + if (i == startIndex) { + list.add(IntItem.ZERO); + } else { + list.add(parseItem(isDigit, version.substring(startIndex, i))); } startIndex = i + 1; - list.add( list = new ListItem() ); - stack.push( list ); - } - else if ( Character.isDigit( c ) ) - { - if ( !isDigit && i > startIndex ) - { - list.add( new StringItem( version.substring( startIndex, i ), true ) ); + list.add(list = new ListItem()); + stack.push(list); + } else if (Character.isDigit(c)) { + if (!isDigit && i > startIndex) { + list.add(new StringItem(version.substring(startIndex, i), true)); startIndex = i; - list.add( list = new ListItem() ); - stack.push( list ); + list.add(list = new ListItem()); + stack.push(list); } isDigit = true; - } - else - { - if ( isDigit && i > startIndex ) - { - list.add( parseItem( true, version.substring( startIndex, i ) ) ); + } else { + if (isDigit && i > startIndex) { + list.add(parseItem(true, version.substring(startIndex, i))); startIndex = i; - list.add( list = new ListItem() ); - stack.push( list ); + list.add(list = new ListItem()); + stack.push(list); } isDigit = false; } } - if ( version.length() > startIndex ) - { - list.add( parseItem( isDigit, version.substring( startIndex ) ) ); + if (version.length() > startIndex) { + list.add(parseItem(isDigit, version.substring(startIndex))); } - while ( !stack.isEmpty() ) - { + while (!stack.isEmpty()) { list = (ListItem) stack.pop(); list.normalize(); } } - private static Item parseItem( boolean isDigit, String buf ) - { - if ( isDigit ) - { - buf = stripLeadingZeroes( buf ); - if ( buf.length() <= MAX_INTITEM_LENGTH ) - { + private static Item parseItem(boolean isDigit, String buf) { + if (isDigit) { + buf = stripLeadingZeroes(buf); + if (buf.length() <= MAX_INTITEM_LENGTH) { // lower than 2^31 - return new IntItem( buf ); - } - else if ( buf.length() <= MAX_LONGITEM_LENGTH ) - { + return new IntItem(buf); + } else if (buf.length() <= MAX_LONGITEM_LENGTH) { // lower than 2^63 - return new LongItem( buf ); + return new LongItem(buf); } - return new BigIntegerItem( buf ); + return new BigIntegerItem(buf); } - return new StringItem( buf, false ); + return new StringItem(buf, false); } - private static String stripLeadingZeroes( String buf ) - { - if ( buf == null || buf.isEmpty() ) - { + private static String stripLeadingZeroes(String buf) { + if (buf == null || buf.isEmpty()) { return "0"; } - for ( int i = 0; i < buf.length(); ++i ) - { - char c = buf.charAt( i ); - if ( c != '0' ) - { - return buf.substring( i ); + for (int i = 0; i < buf.length(); ++i) { + char c = buf.charAt(i); + if (c != '0') { + return buf.substring(i); } } return buf; } @Override - public int compareTo( ComparableVersion o ) - { - return items.compareTo( o.items ); + public int compareTo(ComparableVersion o) { + return items.compareTo(o.items); } @Override - public String toString() - { + public String toString() { return value; } - public String getCanonical() - { - if ( canonical == null ) - { + public String getCanonical() { + if (canonical == null) { canonical = items.toString(); } return canonical; } @Override - public boolean equals( Object o ) - { - return ( o instanceof ComparableVersion ) && items.equals( ( (ComparableVersion) o ).items ); + public boolean equals(Object o) { + return (o instanceof ComparableVersion) && items.equals(((ComparableVersion) o).items); } @Override - public int hashCode() - { + public int hashCode() { return items.hashCode(); } @@ -801,30 +695,26 @@ public class ComparableVersion * two adjacent will be compared */ // CHECKSTYLE_ON: LineLength - public static void main( String... args ) - { - System.out.println( "Display parameters as parsed by Maven (in canonical form and as a list of tokens) and" - + " comparison result:" ); - if ( args.length == 0 ) - { + public static void main(String... args) { + System.out.println("Display parameters as parsed by Maven (in canonical form and as a list of tokens) and" + + " comparison result:"); + if (args.length == 0) { return; } ComparableVersion prev = null; int i = 1; - for ( String version : args ) - { - ComparableVersion c = new ComparableVersion( version ); - - if ( prev != null ) - { - int compare = prev.compareTo( c ); - System.out.println( " " + prev.toString() + ' ' - + ( ( compare == 0 ) ? "==" : ( ( compare < 0 ) ? "<" : ">" ) ) + ' ' + version ); + for (String version : args) { + ComparableVersion c = new ComparableVersion(version); + + if (prev != null) { + int compare = prev.compareTo(c); + System.out.println(" " + prev.toString() + ' ' + ((compare == 0) ? "==" : ((compare < 0) ? "<" : ">")) + + ' ' + version); } - System.out.println( ( i++ ) + ". " + version + " -> " + c.getCanonical() - + "; tokens: " + c.items.toListString() ); + System.out.println( + (i++) + ". " + version + " -> " + c.getCanonical() + "; tokens: " + c.items.toListString()); prev = c; } diff --git a/src/test/java/org/apache/sling/testing/mock/sling/oak/loader/ContentLoaderBinaryTest.java b/src/test/java/org/apache/sling/testing/mock/sling/oak/loader/ContentLoaderBinaryTest.java index d9fc530..bce0f6b 100644 --- a/src/test/java/org/apache/sling/testing/mock/sling/oak/loader/ContentLoaderBinaryTest.java +++ b/src/test/java/org/apache/sling/testing/mock/sling/oak/loader/ContentLoaderBinaryTest.java @@ -27,5 +27,4 @@ public class ContentLoaderBinaryTest extends AbstractContentLoaderBinaryTest { protected ResourceResolverType getResourceResolverType() { return ResourceResolverType.JCR_OAK; } - } diff --git a/src/test/java/org/apache/sling/testing/mock/sling/oak/loader/ContentLoaderFileVaultXmlTest.java b/src/test/java/org/apache/sling/testing/mock/sling/oak/loader/ContentLoaderFileVaultXmlTest.java index f300a78..4c113a4 100644 --- a/src/test/java/org/apache/sling/testing/mock/sling/oak/loader/ContentLoaderFileVaultXmlTest.java +++ b/src/test/java/org/apache/sling/testing/mock/sling/oak/loader/ContentLoaderFileVaultXmlTest.java @@ -27,5 +27,4 @@ public class ContentLoaderFileVaultXmlTest extends AbstractContentLoaderFileVaul protected ResourceResolverType getResourceResolverType() { return ResourceResolverType.JCR_OAK; } - } diff --git a/src/test/java/org/apache/sling/testing/mock/sling/oak/loader/ContentLoaderFolderFileVaultXmlTest.java b/src/test/java/org/apache/sling/testing/mock/sling/oak/loader/ContentLoaderFolderFileVaultXmlTest.java index 761f37d..c65f0f3 100644 --- a/src/test/java/org/apache/sling/testing/mock/sling/oak/loader/ContentLoaderFolderFileVaultXmlTest.java +++ b/src/test/java/org/apache/sling/testing/mock/sling/oak/loader/ContentLoaderFolderFileVaultXmlTest.java @@ -27,5 +27,4 @@ public class ContentLoaderFolderFileVaultXmlTest extends AbstractContentLoaderFo protected ResourceResolverType getResourceResolverType() { return ResourceResolverType.JCR_OAK; } - } diff --git a/src/test/java/org/apache/sling/testing/mock/sling/oak/loader/ContentLoaderFolderJsonTest.java b/src/test/java/org/apache/sling/testing/mock/sling/oak/loader/ContentLoaderFolderJsonTest.java index 2dbd8d4..78bab64 100644 --- a/src/test/java/org/apache/sling/testing/mock/sling/oak/loader/ContentLoaderFolderJsonTest.java +++ b/src/test/java/org/apache/sling/testing/mock/sling/oak/loader/ContentLoaderFolderJsonTest.java @@ -27,5 +27,4 @@ public class ContentLoaderFolderJsonTest extends AbstractContentLoaderFolderJson protected ResourceResolverType getResourceResolverType() { return ResourceResolverType.JCR_OAK; } - } diff --git a/src/test/java/org/apache/sling/testing/mock/sling/oak/loader/ContentLoaderJsonDamTest.java b/src/test/java/org/apache/sling/testing/mock/sling/oak/loader/ContentLoaderJsonDamTest.java index 28e27ba..99e0c01 100644 --- a/src/test/java/org/apache/sling/testing/mock/sling/oak/loader/ContentLoaderJsonDamTest.java +++ b/src/test/java/org/apache/sling/testing/mock/sling/oak/loader/ContentLoaderJsonDamTest.java @@ -27,5 +27,4 @@ public class ContentLoaderJsonDamTest extends AbstractContentLoaderJsonDamTest { protected ResourceResolverType getResourceResolverType() { return ResourceResolverType.JCR_OAK; } - } diff --git a/src/test/java/org/apache/sling/testing/mock/sling/oak/loader/ContentLoaderJsonTest.java b/src/test/java/org/apache/sling/testing/mock/sling/oak/loader/ContentLoaderJsonTest.java index ecc315e..cfe731e 100644 --- a/src/test/java/org/apache/sling/testing/mock/sling/oak/loader/ContentLoaderJsonTest.java +++ b/src/test/java/org/apache/sling/testing/mock/sling/oak/loader/ContentLoaderJsonTest.java @@ -18,11 +18,6 @@ */ package org.apache.sling.testing.mock.sling.oak.loader; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - import javax.jcr.Node; import javax.jcr.RepositoryException; @@ -34,6 +29,11 @@ import org.apache.sling.testing.mock.sling.ResourceResolverType; import org.apache.sling.testing.mock.sling.loader.AbstractContentLoaderJsonTest; import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + @SuppressWarnings("null") public class ContentLoaderJsonTest extends AbstractContentLoaderJsonTest { @@ -44,7 +44,8 @@ public class ContentLoaderJsonTest extends AbstractContentLoaderJsonTest { @Test public void testJcrUuid() { - Resource resource = context.resourceResolver().getResource(path + "/sample/en/jcr:content/par/image/file/jcr:content"); + Resource resource = + context.resourceResolver().getResource(path + "/sample/en/jcr:content/par/image/file/jcr:content"); ValueMap props = ResourceUtil.getValueMap(resource); // jcr:uuid is not imported from json with OAK repository - just check for not null @@ -53,14 +54,18 @@ public class ContentLoaderJsonTest extends AbstractContentLoaderJsonTest { @Test public void testMixinNodeType() throws Exception { - Resource resource = context.resourceResolver().getResource(path + "/sample/en/jcr:content/par/image/ntLinkedFileTargetWithMixin/" + JcrConstants.JCR_CONTENT); + Resource resource = context.resourceResolver() + .getResource(path + "/sample/en/jcr:content/par/image/ntLinkedFileTargetWithMixin/" + + JcrConstants.JCR_CONTENT); assertMixinNodeType(resource, "app:TestMixin"); } @Test public void testReferenceable() throws Exception { - Resource resource = context.resourceResolver().getResource(path + "/sample/en/jcr:content/par/image/ntLinkedFileTargetWithMixin/" + JcrConstants.JCR_CONTENT); + Resource resource = context.resourceResolver() + .getResource(path + "/sample/en/jcr:content/par/image/ntLinkedFileTargetWithMixin/" + + JcrConstants.JCR_CONTENT); ValueMap props = ResourceUtil.getValueMap(resource); assertMixinNodeType(resource, JcrConstants.MIX_REFERENCEABLE); @@ -69,13 +74,18 @@ public class ContentLoaderJsonTest extends AbstractContentLoaderJsonTest { @Test public void testLinkedFile() throws Exception { - Resource resource = context.resourceResolver().getResource(path + "/sample/en/jcr:content/par/image/ntLinkedFile"); - Resource targetResource = context.resourceResolver().getResource(path + "/sample/en/jcr:content/par/image/ntLinkedFileTargetWithMixin/" + JcrConstants.JCR_CONTENT); + Resource resource = + context.resourceResolver().getResource(path + "/sample/en/jcr:content/par/image/ntLinkedFile"); + Resource targetResource = context.resourceResolver() + .getResource(path + "/sample/en/jcr:content/par/image/ntLinkedFileTargetWithMixin/" + + JcrConstants.JCR_CONTENT); Node node = resource.adaptTo(Node.class); Node target = node.getProperty(JcrConstants.JCR_CONTENT).getNode(); assertEquals(targetResource.getPath(), target.getPath()); - assertEquals(targetResource.getValueMap().get(JcrConstants.JCR_UUID), target.getProperty(JcrConstants.JCR_UUID).getString()); + assertEquals( + targetResource.getValueMap().get(JcrConstants.JCR_UUID), + target.getProperty(JcrConstants.JCR_UUID).getString()); } private void assertMixinNodeType(final Resource resource, final String mixinNodeType) throws RepositoryException { diff --git a/src/test/java/org/apache/sling/testing/mock/sling/oak/resource/JcrNamespaceTest.java b/src/test/java/org/apache/sling/testing/mock/sling/oak/resource/JcrNamespaceTest.java index 0325b18..b43d31b 100644 --- a/src/test/java/org/apache/sling/testing/mock/sling/oak/resource/JcrNamespaceTest.java +++ b/src/test/java/org/apache/sling/testing/mock/sling/oak/resource/JcrNamespaceTest.java @@ -27,5 +27,4 @@ public class JcrNamespaceTest extends AbstractJcrNamespaceTest { protected ResourceResolverType getResourceResolverType() { return ResourceResolverType.JCR_OAK; } - } diff --git a/src/test/java/org/apache/sling/testing/mock/sling/oak/resource/JcrResourceResolverTest.java b/src/test/java/org/apache/sling/testing/mock/sling/oak/resource/JcrResourceResolverTest.java index 7d055d6..43f101c 100644 --- a/src/test/java/org/apache/sling/testing/mock/sling/oak/resource/JcrResourceResolverTest.java +++ b/src/test/java/org/apache/sling/testing/mock/sling/oak/resource/JcrResourceResolverTest.java @@ -27,5 +27,4 @@ public class JcrResourceResolverTest extends AbstractJcrResourceResolverTest { protected ResourceResolverType getResourceResolverType() { return ResourceResolverType.JCR_OAK; } - } diff --git a/src/test/java/org/apache/sling/testing/mock/sling/oak/resource/MultipleResourceResolverTest.java b/src/test/java/org/apache/sling/testing/mock/sling/oak/resource/MultipleResourceResolverTest.java index e90020f..4a4efbe 100644 --- a/src/test/java/org/apache/sling/testing/mock/sling/oak/resource/MultipleResourceResolverTest.java +++ b/src/test/java/org/apache/sling/testing/mock/sling/oak/resource/MultipleResourceResolverTest.java @@ -27,5 +27,4 @@ public class MultipleResourceResolverTest extends AbstractMultipleResourceResolv protected ResourceResolverType getResourceResolverType() { return ResourceResolverType.JCR_OAK; } - } diff --git a/src/test/java/org/apache/sling/testing/mock/sling/oak/resource/SlingCrudResourceResolverTest.java b/src/test/java/org/apache/sling/testing/mock/sling/oak/resource/SlingCrudResourceResolverTest.java index 10a01dc..69c0002 100644 --- a/src/test/java/org/apache/sling/testing/mock/sling/oak/resource/SlingCrudResourceResolverTest.java +++ b/src/test/java/org/apache/sling/testing/mock/sling/oak/resource/SlingCrudResourceResolverTest.java @@ -27,5 +27,4 @@ public class SlingCrudResourceResolverTest extends AbstractSlingCrudResourceReso protected ResourceResolverType getResourceResolverType() { return ResourceResolverType.JCR_OAK; } - } diff --git a/src/test/java/org/apache/sling/testing/mock/sling/oak/resource/UniqueRootTest.java b/src/test/java/org/apache/sling/testing/mock/sling/oak/resource/UniqueRootTest.java index cf70e5a..07d65cc 100644 --- a/src/test/java/org/apache/sling/testing/mock/sling/oak/resource/UniqueRootTest.java +++ b/src/test/java/org/apache/sling/testing/mock/sling/oak/resource/UniqueRootTest.java @@ -27,5 +27,4 @@ public class UniqueRootTest extends AbstractUniqueRootTest { protected ResourceResolverType getResourceResolverType() { return ResourceResolverType.JCR_OAK; } - }