Skip to content

fix: spotless plugin (palantir with google style) #2707

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

Closed
Closed
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ public class Bootstrapper {
private static final Map<String, String> TOP_LEVEL_STATIC_FILES =
Map.of("_.gitignore", ".gitignore", "README.md", "README.md");
private static final List<String> JAVA_FILES =
List.of("CustomResource.java", "Reconciler.java",
"Spec.java", "Status.java");
List.of("CustomResource.java", "Reconciler.java", "Spec.java", "Status.java");

public void create(File targetDir, String groupId, String artifactId) {
try {
Expand Down Expand Up @@ -61,41 +60,57 @@ private void addJavaFiles(File projectDir, String groupId, String artifactId) {
var targetTestDir = new File(projectDir, "src/test/java/" + packages);
FileUtils.forceMkdir(targetDir);
var classFileNamePrefix = artifactClassId(artifactId);
JAVA_FILES.forEach(f -> addTemplatedFile(projectDir, f, groupId, artifactId, targetDir,
classFileNamePrefix + f));
JAVA_FILES.forEach(f ->
addTemplatedFile(projectDir, f, groupId, artifactId, targetDir, classFileNamePrefix + f));

addTemplatedFile(projectDir, "Runner.java", groupId, artifactId, targetDir, null);
addTemplatedFile(projectDir, "ConfigMapDependentResource.java", groupId, artifactId,
targetDir, null);
addTemplatedFile(projectDir, "ReconcilerIntegrationTest.java", groupId,
addTemplatedFile(
projectDir, "ConfigMapDependentResource.java", groupId, artifactId, targetDir, null);
addTemplatedFile(
projectDir,
"ReconcilerIntegrationTest.java",
groupId,
artifactId,
targetTestDir, artifactClassId(artifactId) + "ReconcilerIntegrationTest.java");
targetTestDir,
artifactClassId(artifactId) + "ReconcilerIntegrationTest.java");
} catch (IOException e) {
throw new RuntimeException(e);
}

}

private void addTemplatedFiles(File projectDir, String groupId, String artifactId) {
addTemplatedFile(projectDir, "pom.xml", groupId, artifactId);
addTemplatedFile(projectDir, "k8s/test-resource.yaml", groupId, artifactId);
}

private void addTemplatedFile(File projectDir, String fileName, String groupId,
String artifactId) {
private void addTemplatedFile(
File projectDir, String fileName, String groupId, String artifactId) {
addTemplatedFile(projectDir, fileName, groupId, artifactId, null, null);
}

private void addTemplatedFile(File projectDir, String fileName, String groupId, String artifactId,
File targetDir, String targetFileName) {
private void addTemplatedFile(
File projectDir,
String fileName,
String groupId,
String artifactId,
File targetDir,
String targetFileName) {
try {
var values = Map.of("groupId", groupId, "artifactId", artifactId,
"artifactClassId", artifactClassId(artifactId),
"josdkVersion", Versions.JOSDK,
"fabric8Version", Versions.KUBERNETES_CLIENT);
var values = Map.of(
"groupId",
groupId,
"artifactId",
artifactId,
"artifactClassId",
artifactClassId(artifactId),
"josdkVersion",
Versions.JOSDK,
"fabric8Version",
Versions.KUBERNETES_CLIENT);

var mustache = mustacheFactory.compile("templates/" + fileName);
var targetFile = new File(targetDir == null ? projectDir : targetDir,
var targetFile = new File(
targetDir == null ? projectDir : targetDir,
targetFileName == null ? fileName : targetFileName);
FileUtils.forceMkdir(targetFile.getParentFile());
var writer = new FileWriter(targetFile);
Expand All @@ -114,8 +129,8 @@ private void addStaticFile(File targetDir, String fileName, String targetFileNam
addStaticFile(targetDir, fileName, targetFileName, null);
}

private void addStaticFile(File targetDir, String fileName, String targetFilename,
String subDir) {
private void addStaticFile(
File targetDir, String fileName, String targetFilename, String subDir) {
String sourcePath = subDir == null ? "/static/" : "/static/" + subDir;
String path = sourcePath + fileName;
try (var is = Bootstrapper.class.getResourceAsStream(path)) {
Expand All @@ -127,14 +142,12 @@ private void addStaticFile(File targetDir, String fileName, String targetFilenam
} catch (IOException e) {
throw new RuntimeException("File path: " + path, e);
}

}

public static String artifactClassId(String artifactId) {
var parts = artifactId.split("-");
return Arrays.stream(parts).map(p -> p.substring(0, 1)
.toUpperCase() + p.substring(1))
return Arrays.stream(parts)
.map(p -> p.substring(0, 1).toUpperCase() + p.substring(1))
.collect(Collectors.joining(""));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@
import org.apache.maven.plugins.annotations.Parameter;

@Mojo(name = "create", requiresProject = false)
public class BootstrapperMojo
extends AbstractMojo {
public class BootstrapperMojo extends AbstractMojo {

@Parameter(defaultValue = "${projectGroupId}")
protected String projectGroupId;

@Parameter(defaultValue = "${projectArtifactId}")
protected String projectArtifactId;

public void execute()
throws MojoExecutionException {
public void execute() throws MojoExecutionException {
String userDir = System.getProperty("user.dir");
new Bootstrapper().create(new File(userDir), projectGroupId, projectArtifactId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,14 @@ private CaffeineBoundedItemStores() {}
*/
@SuppressWarnings("unused")
public static <R extends HasMetadata> BoundedItemStore<R> boundedItemStore(
KubernetesClient client, Class<R> rClass,
Duration accessExpireDuration) {
Cache<String, R> cache = Caffeine.newBuilder()
.expireAfterAccess(accessExpireDuration)
.build();
KubernetesClient client, Class<R> rClass, Duration accessExpireDuration) {
Cache<String, R> cache =
Caffeine.newBuilder().expireAfterAccess(accessExpireDuration).build();
return boundedItemStore(client, rClass, cache);
}

public static <R extends HasMetadata> BoundedItemStore<R> boundedItemStore(
KubernetesClient client, Class<R> rClass, Cache<String, R> cache) {
return new BoundedItemStore<>(new CaffeineBoundedCache<>(cache), rClass, client);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;

public abstract class BoundedCacheTestBase<P extends CustomResource<BoundedCacheTestSpec, BoundedCacheTestStatus>> {
public abstract class BoundedCacheTestBase<
P extends CustomResource<BoundedCacheTestSpec, BoundedCacheTestStatus>> {

private static final Logger log = LoggerFactory.getLogger(BoundedCacheTestBase.class);

Expand All @@ -42,7 +43,8 @@ void reconciliationWorksWithLimitedCache() {
}

private void assertConfigMapsDeleted() {
await().atMost(Duration.ofSeconds(30))
await()
.atMost(Duration.ofSeconds(30))
.untilAsserted(() -> IntStream.range(0, NUMBER_OF_RESOURCE_TO_TEST).forEach(i -> {
var cm = extension().get(ConfigMap.class, RESOURCE_NAME_PREFIX + i);
assertThat(cm).isNull();
Expand Down Expand Up @@ -89,7 +91,4 @@ private void createTestResources() {
abstract Class<P> customResourceClass();

abstract LocallyRunOperatorExtension extension();



}
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,21 @@ public class CaffeineBoundedCacheClusterScopeIT
extends BoundedCacheTestBase<BoundedCacheClusterScopeTestCustomResource> {

@RegisterExtension
LocallyRunOperatorExtension extension =
LocallyRunOperatorExtension.builder()
.withReconciler(new BoundedCacheClusterScopeTestReconciler(), o -> {
o.withItemStore(boundedItemStore(
new KubernetesClientBuilder().build(),
BoundedCacheClusterScopeTestCustomResource.class,
Duration.ofMinutes(1),
1));
})
.build();
LocallyRunOperatorExtension extension = LocallyRunOperatorExtension.builder()
.withReconciler(new BoundedCacheClusterScopeTestReconciler(), o -> {
o.withItemStore(boundedItemStore(
new KubernetesClientBuilder().build(),
BoundedCacheClusterScopeTestCustomResource.class,
Duration.ofMinutes(1),
1));
})
.build();

@Override
BoundedCacheClusterScopeTestCustomResource createTestResource(int index) {
var res = new BoundedCacheClusterScopeTestCustomResource();
res.setMetadata(new ObjectMetaBuilder()
.withName(RESOURCE_NAME_PREFIX + index)
.build());
res.setMetadata(
new ObjectMetaBuilder().withName(RESOURCE_NAME_PREFIX + index).build());
res.setSpec(new BoundedCacheTestSpec());
res.getSpec().setData(INITIAL_DATA_PREFIX + index);
res.getSpec().setTargetNamespace(extension.getNamespace());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ class CaffeineBoundedCacheNamespacedIT
extends BoundedCacheTestBase<BoundedCacheTestCustomResource> {

@RegisterExtension
LocallyRunOperatorExtension extension =
LocallyRunOperatorExtension.builder().withReconciler(new BoundedCacheTestReconciler(), o -> {
LocallyRunOperatorExtension extension = LocallyRunOperatorExtension.builder()
.withReconciler(new BoundedCacheTestReconciler(), o -> {
o.withItemStore(boundedItemStore(
new KubernetesClientBuilder().build(), BoundedCacheTestCustomResource.class,
new KubernetesClientBuilder().build(),
BoundedCacheTestCustomResource.class,
Duration.ofMinutes(1),
1));
})
.build();
.build();

BoundedCacheTestCustomResource createTestResource(int index) {
var res = new BoundedCacheTestCustomResource();
res.setMetadata(new ObjectMetaBuilder()
.withName(RESOURCE_NAME_PREFIX + index)
.build());
res.setMetadata(
new ObjectMetaBuilder().withName(RESOURCE_NAME_PREFIX + index).build());
res.setSpec(new BoundedCacheTestSpec());
res.getSpec().setData(INITIAL_DATA_PREFIX + index);
res.getSpec().setTargetNamespace(extension.getNamespace());
Expand All @@ -46,5 +46,4 @@ Class<BoundedCacheTestCustomResource> customResourceClass() {
LocallyRunOperatorExtension extension() {
return extension;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;

public abstract class AbstractTestReconciler<P extends CustomResource<BoundedCacheTestSpec, BoundedCacheTestStatus>>
public abstract class AbstractTestReconciler<
P extends CustomResource<BoundedCacheTestSpec, BoundedCacheTestStatus>>
implements Reconciler<P> {

private static final Logger log =
Expand All @@ -37,9 +38,7 @@ public abstract class AbstractTestReconciler<P extends CustomResource<BoundedCac
public static final String DATA_KEY = "dataKey";

@Override
public UpdateControl<P> reconcile(
P resource,
Context<P> context) {
public UpdateControl<P> reconcile(P resource, Context<P> context) {
var maybeConfigMap = context.getSecondaryResource(ConfigMap.class);
maybeConfigMap.ifPresentOrElse(
cm -> updateConfigMapIfNeeded(cm, resource, context),
Expand Down Expand Up @@ -70,19 +69,20 @@ protected void createConfigMap(P resource, Context<P> context) {
}

@Override
public List<EventSource<?, P>> prepareEventSources(
EventSourceContext<P> context) {
public List<EventSource<?, P>> prepareEventSources(EventSourceContext<P> context) {

var boundedItemStore =
boundedItemStore(new KubernetesClientBuilder().build(),
ConfigMap.class, Duration.ofMinutes(1), 1); // setting max size for testing purposes
var boundedItemStore = boundedItemStore(
new KubernetesClientBuilder().build(),
ConfigMap.class,
Duration.ofMinutes(1),
1); // setting max size for testing purposes

var es = new InformerEventSource<>(
InformerEventSourceConfiguration.from(ConfigMap.class, primaryClass())
.withItemStore(boundedItemStore)
.withSecondaryToPrimaryMapper(
Mappers.fromOwnerReferences(context.getPrimaryResourceClass(),
this instanceof BoundedCacheClusterScopeTestReconciler))
.withSecondaryToPrimaryMapper(Mappers.fromOwnerReferences(
context.getPrimaryResourceClass(),
this instanceof BoundedCacheClusterScopeTestReconciler))
.build(),
context);

Expand All @@ -96,7 +96,8 @@ private void ensureStatus(P resource) {
}

public static <R extends HasMetadata> BoundedItemStore<R> boundedItemStore(
KubernetesClient client, Class<R> rClass,
KubernetesClient client,
Class<R> rClass,
Duration accessExpireDuration,
// max size is only for testing purposes
long cacheMaxSize) {
Expand All @@ -108,5 +109,4 @@ public static <R extends HasMetadata> BoundedItemStore<R> boundedItemStore(
}

protected abstract Class<P> primaryClass();

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@
@Version("v1")
@ShortNames("bccs")
public class BoundedCacheClusterScopeTestCustomResource
extends CustomResource<BoundedCacheTestSpec, BoundedCacheTestStatus> {
}
extends CustomResource<BoundedCacheTestSpec, BoundedCacheTestStatus> {}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import io.javaoperatorsdk.operator.processing.event.source.cache.sample.AbstractTestReconciler;

@ControllerConfiguration
public class BoundedCacheClusterScopeTestReconciler extends
AbstractTestReconciler<BoundedCacheClusterScopeTestCustomResource> {
public class BoundedCacheClusterScopeTestReconciler
extends AbstractTestReconciler<BoundedCacheClusterScopeTestCustomResource> {

@Override
protected Class<BoundedCacheClusterScopeTestCustomResource> primaryClass() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@
@Version("v1")
@ShortNames("bct")
public class BoundedCacheTestCustomResource
extends CustomResource<BoundedCacheTestSpec, BoundedCacheTestStatus> implements Namespaced {
}
extends CustomResource<BoundedCacheTestSpec, BoundedCacheTestStatus> implements Namespaced {}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
package io.javaoperatorsdk.operator.processing.event.source.cache.sample.namespacescope;

public class BoundedCacheTestStatus {
}
public class BoundedCacheTestStatus {}
Loading
Loading