Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OAK-11078: Remove usage of Guava checkArgument #1687

Draft
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions oak-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,10 @@
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
*/
package org.apache.jackrabbit.oak.core;

import static org.apache.jackrabbit.guava.common.base.Preconditions.checkArgument;
import static org.apache.jackrabbit.oak.commons.PathUtils.elements;

import java.io.InputStream;
import java.util.Map;

import org.apache.commons.lang3.Validate;
import org.apache.jackrabbit.oak.api.AuthInfo;
import org.apache.jackrabbit.oak.api.Blob;
import org.apache.jackrabbit.oak.api.ContentSession;
Expand Down Expand Up @@ -71,7 +71,7 @@ public ImmutableRoot(@NotNull Root root) {
}

public ImmutableRoot(@NotNull ImmutableTree rootTree) {
checkArgument(rootTree.isRoot());
Validate.isTrue(rootTree.isRoot());
this.rootTree = rootTree;
this.authInfo = AuthInfo.EMPTY;
this.wspName = null;
Expand All @@ -90,7 +90,7 @@ public static ImmutableRoot getInstance(@NotNull Root root) {
@NotNull
@Override
public ImmutableTree getTree(@NotNull String path) {
checkArgument(PathUtils.isAbsolute(path));
Validate.isTrue(PathUtils.isAbsolute(path));
ImmutableTree child = rootTree;
for (String name : elements(path)) {
child = child.getChild(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
package org.apache.jackrabbit.oak.core;

import static java.util.Objects.requireNonNull;
import static org.apache.jackrabbit.guava.common.base.Preconditions.checkArgument;

import static org.apache.jackrabbit.oak.commons.PathUtils.elements;
import static org.apache.jackrabbit.oak.commons.PathUtils.isAbsolute;

import org.apache.commons.lang3.Validate;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.Tree;
import org.apache.jackrabbit.oak.api.Type;
Expand Down Expand Up @@ -284,7 +285,7 @@ boolean moveTo(@NotNull MutableTree newParent, @NotNull String newName) {
*/
@NotNull
MutableTree getTree(@NotNull String path) {
checkArgument(isAbsolute(requireNonNull(path)));
Validate.isTrue(isAbsolute(requireNonNull(path)));
beforeRead();
MutableTree child = this;
for (String name : elements(path)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.apache.jackrabbit.oak.namepath.impl;

import static org.apache.jackrabbit.guava.common.base.Preconditions.checkArgument;
import static java.util.Collections.emptyList;
import static java.util.Collections.emptyMap;
import static java.util.Objects.requireNonNull;
Expand All @@ -37,6 +36,7 @@

import javax.jcr.RepositoryException;

import org.apache.commons.lang3.Validate;
import org.apache.jackrabbit.oak.api.Root;
import org.apache.jackrabbit.oak.api.Tree;
import org.apache.jackrabbit.oak.namepath.NameMapper;
Expand Down Expand Up @@ -117,8 +117,8 @@ public GlobalNameMapper(Map<String, String> mappings) {
public String getJcrName(@NotNull String oakName) {
// Sanity checks, can be turned to assertions if needed for performance
requireNonNull(oakName);
checkArgument(!isHiddenName(oakName), oakName);
checkArgument(!isExpandedName(oakName), oakName);
Validate.isTrue(!isHiddenName(oakName), oakName);
Validate.isTrue(!isExpandedName(oakName), oakName);

return oakName;
}
Expand Down Expand Up @@ -149,7 +149,7 @@ public Map<String, String> getSessionLocalMappings() {

@Nullable
protected String getOakNameFromExpanded(String expandedName) {
checkArgument(expandedName.startsWith("{"));
Validate.isTrue(expandedName.startsWith("{"));

int brace = expandedName.indexOf('}', 1);
if (brace > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
package org.apache.jackrabbit.oak.namepath.impl;

import static java.util.Objects.requireNonNull;
import static org.apache.jackrabbit.guava.common.base.Preconditions.checkArgument;

import java.util.Map;

import org.apache.commons.lang3.Validate;
import org.apache.jackrabbit.oak.api.Root;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -55,8 +55,8 @@ public synchronized Map<String, String> getSessionLocalMappings() {
@Override @NotNull
public synchronized String getJcrName(@NotNull String oakName) {
requireNonNull(oakName);
checkArgument(!oakName.startsWith(":"), oakName); // hidden name
checkArgument(!isExpandedName(oakName), oakName); // expanded name
Validate.isTrue(!oakName.startsWith(":"), oakName); // hidden name
Validate.isTrue(!isExpandedName(oakName), oakName); // expanded name

if (!local.isEmpty()) {
int colon = oakName.indexOf(':');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import org.apache.jackrabbit.guava.common.collect.Iterables;
import org.apache.jackrabbit.guava.common.collect.Iterators;
import org.apache.commons.lang3.Validate;
import org.apache.jackrabbit.JcrConstants;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.PropertyValue;
Expand All @@ -50,7 +51,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.apache.jackrabbit.guava.common.base.Preconditions.checkArgument;
import static org.apache.jackrabbit.guava.common.collect.Iterators.filter;
import static org.apache.jackrabbit.guava.common.collect.Iterators.singletonIterator;
import static org.apache.jackrabbit.guava.common.collect.Iterators.transform;
Expand Down Expand Up @@ -130,7 +130,7 @@ public Tree getTree(String identifier) {
? identifier
: identifier.substring(0, k);

checkArgument(UUIDUtils.isValidUUID(uuid), "Not a valid identifier '" + identifier + '\'');
Validate.isTrue(UUIDUtils.isValidUUID(uuid), "Not a valid identifier '%s'", identifier);

Tree tree = resolveUUIDToTree(createPropertyValue(uuid));
if (tree == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.apache.jackrabbit.oak.plugins.index;

import static org.apache.jackrabbit.guava.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;
import static org.apache.jackrabbit.guava.common.base.Throwables.getStackTraceAsString;
import static org.apache.jackrabbit.guava.common.collect.Sets.newHashSet;
Expand Down Expand Up @@ -51,6 +50,7 @@

import com.codahale.metrics.MetricRegistry;
import org.apache.jackrabbit.guava.common.collect.Lists;
import org.apache.commons.lang3.Validate;
import org.apache.jackrabbit.api.stats.TimeSeries;
import org.apache.jackrabbit.oak.api.CommitFailedException;
import org.apache.jackrabbit.oak.api.PropertyState;
Expand Down Expand Up @@ -244,8 +244,8 @@ public static String checkValidName(String asyncName){
if (IndexConstants.ASYNC_REINDEX_VALUE.equals(asyncName)){
return asyncName;
}
checkArgument(asyncName.endsWith("async"), "async name [%s] does not confirm to " +
"naming pattern of ending with 'async'", asyncName);
Validate.isTrue(asyncName.endsWith("async"), "async name [%s] does not confirm to naming pattern of ending with 'async'",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/confirm/conform

asyncName);
return asyncName;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.jackrabbit.oak.plugins.index;

import java.io.Closeable;
Expand All @@ -26,6 +25,7 @@
import java.util.List;
import java.util.concurrent.TimeUnit;

import org.apache.commons.lang3.Validate;
import org.apache.jackrabbit.guava.common.collect.Lists;
import org.apache.jackrabbit.guava.common.io.Closer;
import org.apache.jackrabbit.oak.api.jmx.IndexStatsMBean;
Expand Down Expand Up @@ -54,7 +54,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.apache.jackrabbit.guava.common.base.Preconditions.checkArgument;
import static org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardUtils.registerMBean;

@Component(
Expand Down Expand Up @@ -215,7 +214,7 @@ static List<AsyncConfig> getAsyncConfig(String[] configs) {
List<AsyncConfig> result = Lists.newArrayList();
for (String config : configs) {
int idOfEq = config.indexOf(CONFIG_SEP);
checkArgument(idOfEq > 0, "Invalid config provided [%s]", Arrays.toString(configs));
Validate.isTrue(idOfEq > 0, "Invalid config provided [%s]", Arrays.toString(configs));

String[] configElements = config.split(String.valueOf(CONFIG_SEP));
String name = configElements[0].trim();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.apache.jackrabbit.oak.plugins.index;

import static org.apache.jackrabbit.guava.common.base.Preconditions.checkArgument;
import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
import static org.apache.jackrabbit.JcrConstants.NT_UNSTRUCTURED;
import static org.apache.jackrabbit.oak.api.Type.NAME;
Expand All @@ -42,6 +41,7 @@

import javax.jcr.RepositoryException;

import org.apache.commons.lang3.Validate;
import org.apache.jackrabbit.guava.common.collect.ImmutableList;
import org.apache.jackrabbit.guava.common.collect.Iterables;
import org.apache.jackrabbit.guava.common.collect.Sets;
Expand Down Expand Up @@ -248,8 +248,7 @@ public static String getAsyncLaneName(NodeState idxState, String indexPath, Prop
Set<String> asyncNames = Sets.newHashSet(async.getValue(Type.STRINGS));
asyncNames.remove(IndexConstants.INDEXING_MODE_NRT);
asyncNames.remove(IndexConstants.INDEXING_MODE_SYNC);
checkArgument(!asyncNames.isEmpty(), "No valid async name found for " +
"index [%s], definition %s", indexPath, idxState);
Validate.isTrue(!asyncNames.isEmpty(), "No valid async name found for index [%s], definition %s", indexPath, idxState);
return Iterables.getOnlyElement(asyncNames);
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.util.List;

import org.apache.commons.lang3.Validate;
import org.apache.jackrabbit.oak.query.FilterIterators;
import org.apache.jackrabbit.oak.spi.query.Cursor;
import org.apache.jackrabbit.oak.spi.query.Filter;
Expand All @@ -26,7 +27,6 @@
import org.apache.jackrabbit.oak.spi.state.PrefetchNodeStore;

import static java.util.Objects.requireNonNull;
import static org.apache.jackrabbit.guava.common.base.Preconditions.checkArgument;

/**
* This utility class provides factory methods to create commonly used types of
Expand Down Expand Up @@ -105,7 +105,7 @@ public static Cursor newTraversingCursor(Filter filter,
*/
public static Cursor newAncestorCursor(Cursor c, int level, QueryLimits settings) {
requireNonNull(c);
checkArgument(level >= 1);
Validate.isTrue(level >= 1);
return new AncestorCursor(c, level, settings);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.jackrabbit.oak.plugins.index.datastore;

import java.io.File;
import java.io.IOException;

import org.apache.commons.lang3.Validate;
import org.apache.jackrabbit.oak.plugins.index.fulltext.PreExtractedTextProvider;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
Expand All @@ -33,7 +33,6 @@
import org.osgi.service.metatype.annotations.Designate;
import org.osgi.service.metatype.annotations.ObjectClassDefinition;

import static org.apache.jackrabbit.guava.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;

@Component(
Expand Down Expand Up @@ -65,7 +64,7 @@ private void activate(BundleContext context, Configuration config) throws IOExce
String dirPath = config.dir();
requireNonNull(dirPath, "Directory path not configured via 'dir'");
File dir = new File(dirPath);
checkArgument(dir.exists(), "Directory %s does not exist", dir.getAbsolutePath());
Validate.isTrue(dir.exists(), "Directory %s does not exist", dir.getAbsolutePath());
textWriter = new DataStoreTextWriter(dir, true);
reg = context.registerService(PreExtractedTextProvider.class.getName(), textWriter, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.jackrabbit.oak.plugins.index.datastore;

import java.io.BufferedWriter;
Expand All @@ -31,6 +30,7 @@
import org.apache.jackrabbit.guava.common.collect.Sets;
import org.apache.jackrabbit.guava.common.io.Files;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.Validate;
import org.apache.jackrabbit.oak.api.Blob;
import org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore;
import org.apache.jackrabbit.oak.plugins.blob.datastore.InMemoryDataRecord;
Expand All @@ -42,7 +42,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.apache.jackrabbit.guava.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;
import static org.apache.jackrabbit.guava.common.base.Preconditions.checkState;

Expand Down Expand Up @@ -71,7 +70,7 @@ public class DataStoreTextWriter implements TextWriter, Closeable, PreExtractedT

public DataStoreTextWriter(File directory, boolean readOnlyMode) throws IOException {
if (!directory.exists()) {
checkArgument(directory.mkdirs(), "Cannot create directory %s", directory.getAbsolutePath());
Validate.isTrue(directory.mkdirs(), "Cannot create directory %s", directory.getAbsolutePath());
}
this.directory = directory;
this.readOnlyMode = readOnlyMode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.jackrabbit.oak.plugins.index.importer;

import java.io.File;
Expand All @@ -27,6 +26,7 @@

import org.apache.jackrabbit.guava.common.collect.Maps;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.Validate;
import org.apache.jackrabbit.oak.api.CommitFailedException;
import org.apache.jackrabbit.oak.api.Tree;
import org.apache.jackrabbit.oak.commons.PathUtils;
Expand All @@ -43,7 +43,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.apache.jackrabbit.guava.common.base.Preconditions.checkArgument;
import static org.apache.jackrabbit.guava.common.base.Preconditions.checkState;
import static org.apache.jackrabbit.oak.plugins.index.importer.NodeStoreUtils.childBuilder;
import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
Expand All @@ -57,7 +56,7 @@ public class IndexDefinitionUpdater {
private final Map<String, NodeState> indexNodeStates;

public IndexDefinitionUpdater(File file) throws IOException {
checkArgument(file.exists() && file.canRead(), "File [%s] cannot be read", file);
Validate.isTrue(file.exists() && file.canRead(), "File [%s] cannot be read", file);
this.indexNodeStates = getIndexDefnStates(FileUtils.readFileToString(file, StandardCharsets.UTF_8));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.apache.jackrabbit.oak.plugins.index.importer;

import org.apache.commons.lang3.Validate;
import org.apache.jackrabbit.guava.common.base.Stopwatch;
import org.apache.jackrabbit.guava.common.collect.ArrayListMultimap;
import org.apache.jackrabbit.guava.common.collect.ListMultimap;
Expand Down Expand Up @@ -55,7 +56,6 @@
import java.util.Set;
import java.util.concurrent.TimeUnit;

import static org.apache.jackrabbit.guava.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;
import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.REINDEX_COUNT;
import static org.apache.jackrabbit.oak.plugins.index.IndexUtils.INDEXING_PHASE_LOGGER;
Expand Down Expand Up @@ -106,8 +106,7 @@ public IndexImporter(NodeStore nodeStore, File indexDir, IndexEditorProvider ind
AsyncIndexerLock indexerLock, StatisticsProvider statisticsProvider, IndexingReporter indexingReporter) throws IOException {
this.statisticsProvider = statisticsProvider;
this.indexingReporter = indexingReporter;
checkArgument(indexDir.exists() && indexDir.isDirectory(), "Path [%s] does not point " +
"to existing directory", indexDir.getAbsolutePath());
Validate.isTrue(indexDir.exists() && indexDir.isDirectory(), "Path [%s] does not point to existing directory", indexDir.getAbsolutePath());
this.nodeStore = nodeStore;
this.indexDir = indexDir;
this.indexEditorProvider = indexEditorProvider;
Expand Down Expand Up @@ -386,7 +385,7 @@ private ListMultimap<String, IndexInfo> mapIndexesToLanes(Map<String, File> inde


NodeState indexState = indexDefinitionUpdater.getIndexState(indexPath);
checkArgument(indexState.exists(), "No index node found at path [%s]", indexPath);
Validate.isTrue(indexState.exists(), "No index node found at path [%s]", indexPath);

boolean newIndex = !NodeStateUtils.getNode(rootState, indexPath).exists();

Expand Down
Loading
Loading