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

Enable pmd #288

Merged
merged 2 commits into from
Sep 24, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.eclipse.jnosql.communication.Configurations;
import org.eclipse.jnosql.communication.Settings;

import java.util.Arrays;
import java.util.List;

import static java.util.Arrays.asList;
Expand Down Expand Up @@ -62,7 +61,7 @@ static void load(Settings settings, ArangoDBBuilder arangoDB) {
settings.get(ArangoDBConfigurations.PROTOCOL).map(Object::toString).map(Protocol::valueOf)
.ifPresent(arangoDB::protocol);

settings.prefixSupplier(Arrays.asList(ArangoDBConfigurations.HOST, Configurations.HOST))
settings.prefixSupplier(asList(ArangoDBConfigurations.HOST, Configurations.HOST))
.stream()
.map(Object::toString)
.map(ArangoDBHost::new)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.arangodb.entity.BaseDocument;
import com.arangodb.entity.CollectionEntity;
import org.eclipse.jnosql.communication.Value;

import org.eclipse.jnosql.communication.ValueUtil;
import org.eclipse.jnosql.communication.semistructured.CommunicationEntity;
import org.eclipse.jnosql.communication.semistructured.Element;
Expand All @@ -33,8 +32,6 @@
import java.util.function.Function;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

import static java.util.Collections.singletonMap;
import static java.util.stream.Collectors.toList;
Expand Down Expand Up @@ -85,7 +82,7 @@ static CommunicationEntity toEntity(BaseDocument document) {
Map<String, Object> properties = document.getProperties();
List<Element> documents = properties.keySet().stream()
.map(k -> toDocument(k, properties))
.collect(Collectors.toList());
.collect(toList());

documents.add(Element.of(KEY, document.getKey()));
documents.add(Element.of(ID, document.getId()));
Expand All @@ -110,7 +107,7 @@ private static Element toDocument(String key, Map<String, Object> properties) {
if (value instanceof Map map) {
return Element.of(key, map.keySet()
.stream().map(k -> toDocument(k.toString(), map))
.collect(Collectors.toList()));
.collect(toList()));
}
if (isADocumentIterable(value)) {
List<List<Element>> documents = new ArrayList<>();
Expand Down Expand Up @@ -141,7 +138,7 @@ private static Object convert(Value value) {
return getMap(val);
}
if (isSudDocumentList(val)) {
return StreamSupport.stream(Iterable.class.cast(val).spliterator(), false)
return stream(Iterable.class.cast(val).spliterator(), false)
.map(ArangoDBUtil::getMap).collect(toList());
}
return val;
Expand All @@ -158,12 +155,12 @@ private static Object getMap(Object val) {
}

private static boolean isSudDocumentList(Object value) {
return value instanceof Iterable && StreamSupport.stream(Iterable.class.cast(value).spliterator(), false).
return value instanceof Iterable && stream(Iterable.class.cast(value).spliterator(), false).
allMatch(d -> d instanceof Iterable && isSudDocument(d));
}

private static boolean isSudDocument(Object value) {
return value instanceof Iterable && StreamSupport.stream(Iterable.class.cast(value).spliterator(), false).
return value instanceof Iterable && stream(Iterable.class.cast(value).spliterator(), false).
allMatch(Element.class::isInstance);
}

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

import java.time.Duration;
import java.util.Map;
import java.util.Objects;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -61,7 +60,7 @@ public String name() {

@Override
public CommunicationEntity insert(CommunicationEntity entity) {
Objects.requireNonNull(entity, "entity is required");
requireNonNull(entity, "entity is required");
String collectionName = entity.name();
checkCollection(collectionName);
BaseDocument baseDocument = ArangoDBUtil.getBaseDocument(entity);
Expand All @@ -73,7 +72,7 @@ public CommunicationEntity insert(CommunicationEntity entity) {

@Override
public CommunicationEntity update(CommunicationEntity entity) {
Objects.requireNonNull(entity, "entity is required");
requireNonNull(entity, "entity is required");
String collectionName = entity.name();
checkCollection(collectionName);
String id = entity.find(ID, String.class)
Expand All @@ -90,7 +89,7 @@ public CommunicationEntity update(CommunicationEntity entity) {

@Override
public Iterable<CommunicationEntity> update(Iterable<CommunicationEntity> entities) {
Objects.requireNonNull(entities, "entities is required");
requireNonNull(entities, "entities is required");
return StreamSupport.stream(entities.spliterator(), false)
.map(this::update)
.collect(Collectors.toList());
Expand Down Expand Up @@ -135,7 +134,7 @@ public Stream<CommunicationEntity> select(SelectQuery query) throws NullPointerE

@Override
public long count(String documentCollection) {
Objects.requireNonNull(documentCollection, "document collection is required");
requireNonNull(documentCollection, "document collection is required");
String aql = "RETURN LENGTH(" + documentCollection + ")";
ArangoCursor<Object> query = arangoDB.db(database).query(aql, Object.class, emptyMap(), null);
return StreamSupport.stream(query.spliterator(), false).findFirst().map(Number.class::cast)
Expand Down Expand Up @@ -188,16 +187,16 @@ public CommunicationEntity insert(CommunicationEntity entity, Duration ttl) {

@Override
public Iterable<CommunicationEntity> insert(Iterable<CommunicationEntity> entities) {
Objects.requireNonNull(entities, "entities is required");
requireNonNull(entities, "entities is required");
return StreamSupport.stream(entities.spliterator(), false)
.map(this::insert)
.collect(Collectors.toList());
}

@Override
public Iterable<CommunicationEntity> insert(Iterable<CommunicationEntity> entities, Duration ttl) {
Objects.requireNonNull(entities, "entities is required");
Objects.requireNonNull(ttl, "ttl is required");
requireNonNull(entities, "entities is required");
requireNonNull(ttl, "ttl is required");
return StreamSupport.stream(entities.spliterator(), false)
.map(e -> this.insert(e, ttl))
.collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ private static void definesCondition(CriteriaCondition condition,
if (isFirstCondition(aql, counter)) {
aql.append(AND);
}
definesCondition(dc, aql, params, entity, ++counter);
definesCondition(dc, aql, params, entity, counter +1);
}
return;
case OR:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void onAfterBeanDiscovery(@Observes final AfterBeanDiscovery afterBeanDiscovery)

LOGGER.info("Starting the onAfterBeanDiscovery with elements number: " + crudTypes.size());

crudTypes.forEach(type -> afterBeanDiscovery.addBean(new ArangoDBRepositoryBean(type)));
crudTypes.forEach(type -> afterBeanDiscovery.addBean(new ArangoDBRepositoryBean<>(type)));

LOGGER.info("Finished the onAfterBeanDiscovery");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@ enum DefaultJsonbSupplier implements JsonbSupplier {

INSTANCE;

{
JsonbConfig config = new JsonbConfig().withPropertyVisibilityStrategy(new PrivateVisibilityStrategy());
this.json = JsonbBuilder.newBuilder().withConfig(config).build();
}

private final Jsonb json;

DefaultJsonbSupplier() {
JsonbConfig config = new JsonbConfig()
.withPropertyVisibilityStrategy(new PrivateVisibilityStrategy());
this.json = JsonbBuilder.newBuilder()
.withConfig(config)
.build();
}

@Override
public Jsonb get() {
return json;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

/**
* Default representation of {@link EntityAttachment} for in-memory data.
Expand All @@ -33,7 +34,8 @@ public ByteArrayEntityAttachment(String name, String contentType, long lastModif
this.name = name;
this.contentType = contentType;
this.lastModified = lastModified;
this.data = data;
this.data = data != null ? Arrays.copyOf(data, data.length) : new byte[0];

}

@Override
Expand Down
40 changes: 40 additions & 0 deletions pmd/pmd-rules.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0"?>

<!--
This file is uploaded to https://nexus.cicd.portit.io/#browse/upload:portit-webapps (`/pmd-ruleset/` dir)
and then referenced by URL https://nexus.cicd.portit.io/repository/portit-webapps/pmd-ruleset/pmd-ruleset.xml
-->
<ruleset name="Custom Rules"
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
<description>Remove rules</description>
<rule ref="category/java/bestpractices.xml">
<exclude name="GuardLogStatement" />
<exclude name="AbstractClassWithoutAbstractMethod" />
<exclude name="JUnitTestsShouldIncludeAssert" />
<exclude name="UseVarargs" />
<exclude name="MethodReturnsInternalArray" />
</rule>
<rule ref="category/java/codestyle.xml">
<exclude name="LongVariable" />
<exclude name="MethodArgumentCouldBeFinal" />
<exclude name="ShortMethodName" />
<exclude name="ShortVariable" />
<exclude name="AtLeastOneConstructor" />
<exclude name="LocalVariableCouldBeFinal" />
<exclude name="UseExplicitTypes" />
<exclude name="OnlyOneReturn" />
<exclude name="CommentDefaultAccessModifier" />
<exclude name="UnnecessaryBoxing" />
<exclude name="UnnecessaryCast" />
<exclude name="TooManyStaticImports" />
<exclude name="CallSuperInConstructor" />
<exclude name="LinguisticNaming" />
<exclude name="EmptyMethodInAbstractClassShouldBeAbstract" />
<exclude name="LambdaCanBeMethodReference" />
</rule>
<rule ref="category/java/security.xml" />
<rule ref="category/java/performance.xml" />

</ruleset>