Skip to content

Commit 684627a

Browse files
authored
adding spotless in common module (opensearch-project#2658)
* adding spotless in common module Signed-off-by: Dhrubo Saha <dhrubo@amazon.com> * applied spotless Signed-off-by: Dhrubo Saha <dhrubo@amazon.com> --------- Signed-off-by: Dhrubo Saha <dhrubo@amazon.com>
1 parent 1071a48 commit 684627a

File tree

418 files changed

+9079
-7926
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

418 files changed

+9079
-7926
lines changed

common/build.gradle

+11-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ plugins {
99
id 'io.github.goooler.shadow' version "8.1.7"
1010
id 'jacoco'
1111
id "io.freefair.lombok"
12+
id 'com.diffplug.spotless' version '6.25.0'
1213
id 'maven-publish'
1314
id 'signing'
1415
}
@@ -67,6 +68,15 @@ jacocoTestCoverageVerification {
6768
}
6869
check.dependsOn jacocoTestCoverageVerification
6970

71+
spotless {
72+
java {
73+
removeUnusedImports()
74+
importOrder 'java', 'javax', 'org', 'com'
75+
76+
eclipse().configFile rootProject.file('.eclipseformat.xml')
77+
}
78+
}
79+
7080
shadowJar {
7181
destinationDirectory = file("${project.buildDir}/distributions")
7282
archiveClassifier.set(null)
@@ -137,4 +147,4 @@ publishing {
137147
}
138148
}
139149
}
140-
publishShadowPublicationToMavenLocal.mustRunAfter shadowJar
150+
publishShadowPublicationToMavenLocal.mustRunAfter shadowJar

common/src/main/java/org/opensearch/ml/common/AccessMode.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88
package org.opensearch.ml.common;
99

10-
import lombok.Getter;
11-
1210
import java.util.HashMap;
1311
import java.util.Map;
1412

13+
import lombok.Getter;
14+
1515
public enum AccessMode {
1616
PUBLIC("public"),
1717
PRIVATE("private"),

common/src/main/java/org/opensearch/ml/common/CommonValue.java

+532-497
Large diffs are not rendered by default.

common/src/main/java/org/opensearch/ml/common/Configuration.java

+10-13
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,21 @@
55

66
package org.opensearch.ml.common;
77

8-
import lombok.Builder;
9-
import lombok.EqualsAndHashCode;
10-
import lombok.Getter;
11-
import lombok.Setter;
8+
import static org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken;
9+
10+
import java.io.IOException;
11+
1212
import org.opensearch.core.common.io.stream.StreamInput;
1313
import org.opensearch.core.common.io.stream.StreamOutput;
1414
import org.opensearch.core.common.io.stream.Writeable;
1515
import org.opensearch.core.xcontent.ToXContentObject;
1616
import org.opensearch.core.xcontent.XContentBuilder;
1717
import org.opensearch.core.xcontent.XContentParser;
1818

19-
import java.io.IOException;
20-
21-
import static org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken;
19+
import lombok.Builder;
20+
import lombok.EqualsAndHashCode;
21+
import lombok.Getter;
22+
import lombok.Setter;
2223

2324
@Getter
2425
@EqualsAndHashCode
@@ -30,9 +31,7 @@ public class Configuration implements ToXContentObject, Writeable {
3031
private String agentId;
3132

3233
@Builder(toBuilder = true)
33-
public Configuration(
34-
String agentId
35-
) {
34+
public Configuration(String agentId) {
3635
this.agentId = agentId;
3736
}
3837

@@ -76,8 +75,6 @@ public static Configuration parse(XContentParser parser) throws IOException {
7675
break;
7776
}
7877
}
79-
return Configuration.builder()
80-
.agentId(agentId)
81-
.build();
78+
return Configuration.builder().agentId(agentId).build();
8279
}
8380
}

common/src/main/java/org/opensearch/ml/common/FunctionName.java

+3-7
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,9 @@ public static FunctionName from(String value) {
4141
}
4242
}
4343

44-
private static final HashSet<FunctionName> DL_MODELS = new HashSet<>(Set.of(
45-
TEXT_EMBEDDING,
46-
TEXT_SIMILARITY,
47-
SPARSE_ENCODING,
48-
SPARSE_TOKENIZE,
49-
QUESTION_ANSWERING
50-
));
44+
private static final HashSet<FunctionName> DL_MODELS = new HashSet<>(
45+
Set.of(TEXT_EMBEDDING, TEXT_SIMILARITY, SPARSE_ENCODING, SPARSE_TOKENIZE, QUESTION_ANSWERING)
46+
);
5147

5248
/**
5349
* Check if model is deep learning model.

common/src/main/java/org/opensearch/ml/common/MLCommonsClassLoader.java

+19-21
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@
55

66
package org.opensearch.ml.common;
77

8-
import lombok.extern.log4j.Log4j2;
8+
import java.io.IOException;
9+
import java.lang.reflect.Constructor;
10+
import java.security.AccessController;
11+
import java.security.PrivilegedActionException;
12+
import java.security.PrivilegedExceptionAction;
13+
import java.util.HashMap;
14+
import java.util.Map;
15+
import java.util.Set;
16+
917
import org.opensearch.core.common.io.stream.StreamInput;
1018
import org.opensearch.ml.common.annotation.Connector;
1119
import org.opensearch.ml.common.annotation.ExecuteInput;
@@ -20,14 +28,7 @@
2028
import org.opensearch.ml.common.output.MLOutputType;
2129
import org.reflections.Reflections;
2230

23-
import java.io.IOException;
24-
import java.lang.reflect.Constructor;
25-
import java.security.AccessController;
26-
import java.security.PrivilegedActionException;
27-
import java.security.PrivilegedExceptionAction;
28-
import java.util.HashMap;
29-
import java.util.Map;
30-
import java.util.Set;
31+
import lombok.extern.log4j.Log4j2;
3132

3233
@Log4j2
3334
@SuppressWarnings("removal")
@@ -93,7 +94,7 @@ private static void loadMLAlgoParameterClassMapping() {
9394
if (mlAlgoParameter != null) {
9495
FunctionName[] algorithms = mlAlgoParameter.algorithms();
9596
if (algorithms != null && algorithms.length > 0) {
96-
for(FunctionName name : algorithms){
97+
for (FunctionName name : algorithms) {
9798
parameterClassMap.put(name, clazz);
9899
}
99100
}
@@ -157,7 +158,7 @@ private static void loadExecuteInputClassMapping() {
157158
if (executeInput != null) {
158159
FunctionName[] algorithms = executeInput.algorithms();
159160
if (algorithms != null && algorithms.length > 0) {
160-
for(FunctionName name : algorithms){
161+
for (FunctionName name : algorithms) {
161162
executeInputClassMap.put(name, clazz);
162163
}
163164
}
@@ -176,7 +177,7 @@ private static void loadExecuteOutputClassMapping() {
176177
if (executeOutput != null) {
177178
FunctionName[] algorithms = executeOutput.algorithms();
178179
if (algorithms != null && algorithms.length > 0) {
179-
for(FunctionName name : algorithms){
180+
for (FunctionName name : algorithms) {
180181
executeOutputClassMap.put(name, clazz);
181182
}
182183
}
@@ -192,7 +193,7 @@ private static void loadMLInputClassMapping() {
192193
if (mlInput != null) {
193194
FunctionName[] algorithms = mlInput.functionNames();
194195
if (algorithms != null && algorithms.length > 0) {
195-
for(FunctionName name : algorithms){
196+
for (FunctionName name : algorithms) {
196197
mlInputClassMap.put(name, clazz);
197198
}
198199
}
@@ -242,7 +243,7 @@ private static <T, S, I extends Object> S init(Map<T, Class<?>> map, T type, I i
242243
} catch (Exception e) {
243244
Throwable cause = e.getCause();
244245
if (cause instanceof MLException || cause instanceof IllegalArgumentException) {
245-
throw (RuntimeException)cause;
246+
throw (RuntimeException) cause;
246247
} else {
247248
log.error("Failed to init instance for type " + type, e);
248249
return null;
@@ -254,19 +255,16 @@ public static boolean canInitMLInput(FunctionName functionName) {
254255
return mlInputClassMap.containsKey(functionName);
255256
}
256257

257-
public static <S> S initConnector(String name, Object[] initArgs,
258-
Class<?>... constructorParameterTypes) {
258+
public static <S> S initConnector(String name, Object[] initArgs, Class<?>... constructorParameterTypes) {
259259
return init(connectorClassMap, name, initArgs, constructorParameterTypes);
260260
}
261261

262262
@SuppressWarnings("unchecked")
263-
public static <T extends Enum<T>, S> S initMLInput(T type, Object[] initArgs,
264-
Class<?>... constructorParameterTypes) {
263+
public static <T extends Enum<T>, S> S initMLInput(T type, Object[] initArgs, Class<?>... constructorParameterTypes) {
265264
return init(mlInputClassMap, type, initArgs, constructorParameterTypes);
266265
}
267266

268-
private static <T, S> S init(Map<T, Class<?>> map, T type,
269-
Object[] initArgs, Class<?>... constructorParameterTypes) {
267+
private static <T, S> S init(Map<T, Class<?>> map, T type, Object[] initArgs, Class<?>... constructorParameterTypes) {
270268
Class<?> clazz = map.get(type);
271269
if (clazz == null) {
272270
throw new IllegalArgumentException("Can't find class for type " + type);
@@ -277,7 +275,7 @@ private static <T, S> S init(Map<T, Class<?>> map, T type,
277275
} catch (Exception e) {
278276
Throwable cause = e.getCause();
279277
if (cause instanceof MLException) {
280-
throw (MLException)cause;
278+
throw (MLException) cause;
281279
} else if (cause instanceof IllegalArgumentException) {
282280
throw (IllegalArgumentException) cause;
283281
} else {

common/src/main/java/org/opensearch/ml/common/MLConfig.java

+17-21
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,22 @@
55

66
package org.opensearch.ml.common;
77

8-
import lombok.Builder;
9-
import lombok.EqualsAndHashCode;
10-
import lombok.Getter;
11-
import lombok.Setter;
8+
import static org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken;
9+
10+
import java.io.IOException;
11+
import java.time.Instant;
12+
1213
import org.opensearch.core.common.io.stream.StreamInput;
1314
import org.opensearch.core.common.io.stream.StreamOutput;
1415
import org.opensearch.core.common.io.stream.Writeable;
1516
import org.opensearch.core.xcontent.ToXContentObject;
1617
import org.opensearch.core.xcontent.XContentBuilder;
1718
import org.opensearch.core.xcontent.XContentParser;
1819

19-
import java.io.IOException;
20-
import java.time.Instant;
21-
22-
import static org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken;
20+
import lombok.Builder;
21+
import lombok.EqualsAndHashCode;
22+
import lombok.Getter;
23+
import lombok.Setter;
2324

2425
@Getter
2526
@EqualsAndHashCode
@@ -38,7 +39,6 @@ public class MLConfig implements ToXContentObject, Writeable {
3839

3940
public static final String LAST_UPDATED_TIME_FIELD = "last_updated_time";
4041

41-
4242
@Setter
4343
private String type;
4444

@@ -47,12 +47,7 @@ public class MLConfig implements ToXContentObject, Writeable {
4747
private Instant lastUpdateTime;
4848

4949
@Builder(toBuilder = true)
50-
public MLConfig(
51-
String type,
52-
Configuration configuration,
53-
Instant createTime,
54-
Instant lastUpdateTime
55-
) {
50+
public MLConfig(String type, Configuration configuration, Instant createTime, Instant lastUpdateTime) {
5651
this.type = type;
5752
this.configuration = configuration;
5853
this.createTime = createTime;
@@ -145,11 +140,12 @@ public static MLConfig parse(XContentParser parser) throws IOException {
145140
break;
146141
}
147142
}
148-
return MLConfig.builder()
149-
.type(configType == null ? type : configType)
150-
.configuration(mlConfiguration == null ? configuration : mlConfiguration)
151-
.createTime(createTime)
152-
.lastUpdateTime(lastUpdatedTime == null ? lastUpdateTime : lastUpdatedTime)
153-
.build();
143+
return MLConfig
144+
.builder()
145+
.type(configType == null ? type : configType)
146+
.configuration(mlConfiguration == null ? configuration : mlConfiguration)
147+
.createTime(createTime)
148+
.lastUpdateTime(lastUpdatedTime == null ? lastUpdateTime : lastUpdatedTime)
149+
.build();
154150
}
155151
}

0 commit comments

Comments
 (0)