Skip to content

fix: spotless plugin activation issue #2704

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
wants to merge 2 commits into from
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
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
cache: 'maven'
- name: Check code format
run: |
./mvnw ${MAVEN_ARGS} spotless:check --file pom.xml
./mvnw ${MAVEN_ARGS} spotless:check --file pom.xml -Dhighest-basedir=$PWD
- name: Run unit tests
run: ./mvnw ${MAVEN_ARGS} clean install -Pno-apt --file pom.xml

Expand Down
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 @@ -67,8 +66,7 @@ private void addJavaFiles(File projectDir, String groupId, String artifactId) {
addTemplatedFile(projectDir, "Runner.java", groupId, artifactId, targetDir, null);
addTemplatedFile(projectDir, "ConfigMapDependentResource.java", groupId, artifactId,
targetDir, null);
addTemplatedFile(projectDir, "ReconcilerIntegrationTest.java", groupId,
artifactId,
addTemplatedFile(projectDir, "ReconcilerIntegrationTest.java", groupId, artifactId,
targetTestDir, artifactClassId(artifactId) + "ReconcilerIntegrationTest.java");
} catch (IOException e) {
throw new RuntimeException(e);
Expand All @@ -89,10 +87,9 @@ private void addTemplatedFile(File projectDir, String fileName, String groupId,
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,
Expand Down Expand Up @@ -132,8 +129,7 @@ private void addStaticFile(File targetDir, String fileName, String targetFilenam

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(""));
}

Expand Down
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 @@ -30,9 +30,8 @@ void copiesFilesToTarget() {

private void assertProjectCompiles() {
try {
var process = Runtime.getRuntime()
.exec(
"mvn clean install -f target/test-project/pom.xml -DskipTests -Dspotless.apply.skip");
var process = Runtime.getRuntime().exec(
"mvn clean install -f target/test-project/pom.xml -DskipTests -Dspotless.apply.skip");

BufferedReader stdOut = new BufferedReader(new InputStreamReader(process.getInputStream()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,8 @@ 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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,16 @@ 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 @@ -19,18 +19,13 @@ class CaffeineBoundedCacheNamespacedIT
@RegisterExtension
LocallyRunOperatorExtension extension =
LocallyRunOperatorExtension.builder().withReconciler(new BoundedCacheTestReconciler(), o -> {
o.withItemStore(boundedItemStore(
new KubernetesClientBuilder().build(), BoundedCacheTestCustomResource.class,
Duration.ofMinutes(1),
1));
})
.build();
o.withItemStore(boundedItemStore(new KubernetesClientBuilder().build(),
BoundedCacheTestCustomResource.class, Duration.ofMinutes(1), 1));
}).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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,9 @@ 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),
maybeConfigMap.ifPresentOrElse(cm -> updateConfigMapIfNeeded(cm, resource, context),
() -> createConfigMap(resource, context));
ensureStatus(resource);
log.info("Reconciled: {}", resource.getMetadata().getName());
Expand All @@ -59,32 +56,24 @@ protected void updateConfigMapIfNeeded(ConfigMap cm, P resource, Context<P> cont

protected void createConfigMap(P resource, Context<P> context) {
var cm = new ConfigMapBuilder()
.withMetadata(new ObjectMetaBuilder()
.withName(resource.getMetadata().getName())
.withNamespace(resource.getSpec().getTargetNamespace())
.build())
.withData(Map.of(DATA_KEY, resource.getSpec().getData()))
.build();
.withMetadata(new ObjectMetaBuilder().withName(resource.getMetadata().getName())
.withNamespace(resource.getSpec().getTargetNamespace()).build())
.withData(Map.of(DATA_KEY, resource.getSpec().getData())).build();
cm.addOwnerReference(resource);
context.getClient().configMaps().resource(cm).create();
}

@Override
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 es = new InformerEventSource<>(
InformerEventSourceConfiguration.from(ConfigMap.class, primaryClass())
.withItemStore(boundedItemStore)
.withSecondaryToPrimaryMapper(
Mappers.fromOwnerReferences(context.getPrimaryResourceClass(),
this instanceof BoundedCacheClusterScopeTestReconciler))
.build(),
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 es = new InformerEventSource<>(InformerEventSourceConfiguration
.from(ConfigMap.class, primaryClass()).withItemStore(boundedItemStore)
.withSecondaryToPrimaryMapper(Mappers.fromOwnerReferences(context.getPrimaryResourceClass(),
this instanceof BoundedCacheClusterScopeTestReconciler))
.build(), context);

return List.of(es);
}
Expand All @@ -96,14 +85,11 @@ private void ensureStatus(P resource) {
}

public static <R extends HasMetadata> BoundedItemStore<R> boundedItemStore(
KubernetesClient client, Class<R> rClass,
Duration accessExpireDuration,
KubernetesClient client, Class<R> rClass, Duration accessExpireDuration,
// max size is only for testing purposes
long cacheMaxSize) {
Cache<String, R> cache = Caffeine.newBuilder()
.expireAfterAccess(accessExpireDuration)
.maximumSize(cacheMaxSize)
.build();
Cache<String, R> cache = Caffeine.newBuilder().expireAfterAccess(accessExpireDuration)
.maximumSize(cacheMaxSize).build();
return CaffeineBoundedItemStores.boundedItemStore(client, rClass, cache);
}

Expand Down
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
2 changes: 1 addition & 1 deletion contributing/eclipse-google-style.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<setting id="org.eclipse.jdt.core.formatter.comment.format_line_comments" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.join_wrapped_lines" value="false"/>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@csviri @metacosm this is the only change I had to do in order for spotless to not mess things up. But it unrolled a lot of lines.

Copy link
Collaborator

@csviri csviri Feb 26, 2025

Choose a reason for hiding this comment

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

I would rather stay on an older version while is this fixed in spotless, or is it not expected to be fixed?
can we create an issue for spotless regarding this?

<setting id="org.eclipse.jdt.core.formatter.join_wrapped_lines" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.wrap_non_simple_local_variable_annotation" value="true"/>
Expand Down
7 changes: 0 additions & 7 deletions contributing/eclipse.importorder

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,8 @@ public <T> T timeControllerExecution(ControllerExecution<T> execution) {
final var tags = new ArrayList<Tag>(16);
tags.add(Tag.of(CONTROLLER, name));
addMetadataTags(resourceID, metadata, tags, true);
final var timer =
Timer.builder(execName)
.tags(tags)
.publishPercentiles(0.3, 0.5, 0.95)
.publishPercentileHistogram()
.register(registry);
final var timer = Timer.builder(execName).tags(tags).publishPercentiles(0.3, 0.5, 0.95)
.publishPercentileHistogram().register(registry);
try {
final var result = timer.record(() -> {
try {
Expand All @@ -152,14 +148,11 @@ public <T> T timeControllerExecution(ControllerExecution<T> execution) {
}
});
final var successType = execution.successTypeName(result);
registry
.counter(execName + SUCCESS_SUFFIX, CONTROLLER, name, TYPE, successType)
.increment();
registry.counter(execName + SUCCESS_SUFFIX, CONTROLLER, name, TYPE, successType).increment();
return result;
} catch (Exception e) {
final var exception = e.getClass().getSimpleName();
registry
.counter(execName + FAILURE_SUFFIX, CONTROLLER, name, EXCEPTION, exception)
registry.counter(execName + FAILURE_SUFFIX, CONTROLLER, name, EXCEPTION, exception)
.increment();
throw e;
}
Expand All @@ -168,13 +161,11 @@ public <T> T timeControllerExecution(ControllerExecution<T> execution) {
@Override
public void receivedEvent(Event event, Map<String, Object> metadata) {
if (event instanceof ResourceEvent) {
incrementCounter(event.getRelatedCustomResourceID(), EVENTS_RECEIVED,
metadata,
incrementCounter(event.getRelatedCustomResourceID(), EVENTS_RECEIVED, metadata,
Tag.of(EVENT, event.getClass().getSimpleName()),
Tag.of(ACTION, ((ResourceEvent) event).getAction().toString()));
} else {
incrementCounter(event.getRelatedCustomResourceID(), EVENTS_RECEIVED,
metadata,
incrementCounter(event.getRelatedCustomResourceID(), EVENTS_RECEIVED, metadata,
Tag.of(EVENT, event.getClass().getSimpleName()));
}
}
Expand All @@ -190,8 +181,7 @@ public void cleanupDoneFor(ResourceID resourceID, Map<String, Object> metadata)
public void reconcileCustomResource(HasMetadata resource, RetryInfo retryInfoNullable,
Map<String, Object> metadata) {
Optional<RetryInfo> retryInfo = Optional.ofNullable(retryInfoNullable);
incrementCounter(ResourceID.fromResource(resource), RECONCILIATIONS_STARTED,
metadata,
incrementCounter(ResourceID.fromResource(resource), RECONCILIATIONS_STARTED, metadata,
Tag.of(RECONCILIATIONS_RETRIES_NUMBER,
String.valueOf(retryInfo.map(RetryInfo::getAttemptCount).orElse(0))),
Tag.of(RECONCILIATIONS_RETRIES_LAST,
Expand Down Expand Up @@ -244,8 +234,8 @@ public void failedReconciliation(HasMetadata resource, Exception exception,
}


private void addMetadataTags(ResourceID resourceID, Map<String, Object> metadata,
List<Tag> tags, boolean prefixed) {
private void addMetadataTags(ResourceID resourceID, Map<String, Object> metadata, List<Tag> tags,
boolean prefixed) {
if (collectPerResourceMetrics) {
addTag(NAME, resourceID.getName(), tags, prefixed);
addTagOmittingOnEmptyValue(NAMESPACE, resourceID.getNamespace().orElse(null), tags, prefixed);
Expand Down Expand Up @@ -432,8 +422,8 @@ private DelayedCleaner(MeterRegistry registry, int cleanUpDelayInSeconds,
@Override
public void removeMetersFor(ResourceID resourceID) {
// schedule deletion of meters associated with ResourceID
metersCleaner.schedule(() -> super.removeMetersFor(resourceID),
cleanUpDelayInSeconds, TimeUnit.SECONDS);
metersCleaner.schedule(() -> super.removeMetersFor(resourceID), cleanUpDelayInSeconds,
TimeUnit.SECONDS);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,22 @@ public abstract class AbstractMicrometerMetricsTestFixture {


@RegisterExtension
LocallyRunOperatorExtension operator =
LocallyRunOperatorExtension.builder()
.withConfigurationService(overrider -> overrider.withMetrics(metrics))
.withReconciler(new MetricsCleaningTestReconciler())
.build();
LocallyRunOperatorExtension operator = LocallyRunOperatorExtension.builder()
.withConfigurationService(overrider -> overrider.withMetrics(metrics))
.withReconciler(new MetricsCleaningTestReconciler()).build();


protected abstract MicrometerMetrics getMetrics();

@Test
void properlyHandlesResourceDeletion() throws Exception {
var testResource = new ConfigMapBuilder()
.withNewMetadata()
.withName(testResourceName)
.endMetadata()
.build();
var testResource =
new ConfigMapBuilder().withNewMetadata().withName(testResourceName).endMetadata().build();
final var created = operator.create(testResource);

// make sure the resource is created
await().until(() -> !operator.get(ConfigMap.class, testResourceName)
.getMetadata().getFinalizers().isEmpty());
await().until(() -> !operator.get(ConfigMap.class, testResourceName).getMetadata()
.getFinalizers().isEmpty());

final var resourceID = ResourceID.fromResource(created);
final var meters = preDeleteChecks(resourceID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ public Map<String, Exception> getAggregatedExceptions() {

@Override
public String getMessage() {
return super.getMessage() + " " + causes.entrySet().stream()
.map(entry -> entry.getKey() + " -> " + exceptionDescription(entry))
.collect(Collectors.joining("\n - ", "Details:\n - ", ""));
return super.getMessage() + " "
+ causes.entrySet().stream()
.map(entry -> entry.getKey() + " -> " + exceptionDescription(entry))
.collect(Collectors.joining("\n - ", "Details:\n - ", ""));
}

private static String exceptionDescription(Entry<String, Exception> entry) {
Expand Down
Loading
Loading