GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — IntelliJ formatter by IlyasYOY · Pull Request #2020 · diffplug/spotless

IntelliJ formatter #2020

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.

Sign up for GitHub

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

Merged
simschla merged 17 commits into diffplug:main from IlyasYOY:main
Jul 2, 2025

Uh oh!

There was an error while loading. Please reload this page.

Merged

IntelliJ formatter #2020

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
6419de1
Basic IDEA usage locally.
IlyasYOY Jan 11, 2024
b84d243
Parameterize IDEA usage.
IlyasYOY Jan 23, 2024
1d8d9b2
Verify IDEA binary.
IlyasYOY Jan 23, 2024
9d09760
Merge branch 'main' of github.com:diffplug/spotless
IlyasYOY Jan 23, 2024
affd905
Gradle IDEA integration.
IlyasYOY Jan 23, 2024
effe2fc
Maven IDEA integration.
IlyasYOY Jan 23, 2024
8e30175
Make IDEA tests special
IlyasYOY Jan 23, 2024
1554dd6
docs: CHANGES.md
IlyasYOY Jan 23, 2024
763eaac
Config file for IDEA step
IlyasYOY Jan 23, 2024
fdb73b7
CI Fixes
IlyasYOY Jan 24, 2024
e58c9f8
Merge branch 'main' of github.com:diffplug/spotless
IlyasYOY Jan 24, 2024
c6c6cce
docs: fixed structure of CHANGES.md
IlyasYOY Jan 24, 2024
bf5918c
Merge branch 'main' of github.com:diffplug/spotless
IlyasYOY Jan 27, 2024
9123527
Create State object
IlyasYOY Jan 27, 2024
7d6eed4
Merge branch 'main' of github.com:diffplug/spotless
IlyasYOY Jan 28, 2024
e03e715
Merge branch 'main' into main-IlyasYOY
nedtwigg Feb 13, 2024
a0bde46
spotlessApply
nedtwigg Feb 13, 2024
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

1 change: 1 addition & 0 deletions 1 CHANGES.md
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
## [Unreleased]
### Added
* `FileSignature.Promised` and `JarState.Promised` to facilitate round-trip serialization for the Gradle configuration cache. ([#1945](https://github.com/diffplug/spotless/pull/1945))
* Support for `idea` ([#2020](https://github.com/diffplug/spotless/pull/2020))
Comment thread
nedtwigg marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

* Respect `.editorconfig` settings for formatting shell via `shfmt` ([#2031](https://github.com/diffplug/spotless/pull/2031))

### Removed
Expand Down
1 change: 1 addition & 0 deletions 1 gradle/special-tests.gradle
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ def special = [
'buf',
'clang',
'gofmt',
'idea',
'npm',
'shfmt'
]
Expand Down
137 changes: 137 additions & 0 deletions 137 lib/src/main/java/com/diffplug/spotless/java/IdeaStep.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/*
* Copyright 2024 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.diffplug.spotless.java;

import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.List;
import java.util.Objects;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import javax.annotation.Nullable;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.diffplug.spotless.ForeignExe;
import com.diffplug.spotless.FormatterFunc;
import com.diffplug.spotless.FormatterStep;
import com.diffplug.spotless.ProcessRunner;

public final class IdeaStep {

private static final Logger LOGGER = LoggerFactory.getLogger(IdeaStep.class);

private IdeaStep() {}

public static FormatterStep create() {
return create(true);
}

public static FormatterStep create(boolean withDefaults) {
return create(withDefaults, null);
}

public static FormatterStep create(boolean withDefaults,
@Nullable String binaryPath) {
return create(withDefaults, binaryPath, null);
}

public static FormatterStep create(boolean withDefaults,
@Nullable String binaryPath, @Nullable String configPath) {
return FormatterStep.createLazy("IDEA",
() -> createState(withDefaults, binaryPath, configPath),
state -> state);
}

private static State createState(boolean withDefaults,
@Nullable String binaryPath, @Nullable String configPath) {
return new State(withDefaults, binaryPath, configPath);
}

private static class State
implements FormatterFunc.NeedsFile, Serializable {

private static final long serialVersionUID = -1825662355363926318L;
private static final String DEFAULT_IDEA = "idea";

private String binaryPath;
@Nullable
private String configPath;
private boolean withDefaults;

private State(boolean withDefaults, @Nullable String binaryPath,
@Nullable String configPath) {
this.withDefaults = withDefaults;
this.configPath = configPath;
this.binaryPath = Objects.requireNonNullElse(binaryPath, DEFAULT_IDEA);
resolveFullBinaryPathAndCheckVersion();
}

private void resolveFullBinaryPathAndCheckVersion() {
var exe = ForeignExe
.nameAndVersion(this.binaryPath, "IntelliJ IDEA")
.versionRegex(Pattern.compile("(IntelliJ IDEA) .*"))
.fixCantFind(
"IDEA executable cannot be found on your machine, "
+ "please install it and put idea binary to PATH; or report the problem")
.fixWrongVersion("Provided binary is not IDEA, "
+ "please check it and fix the problem; or report the problem");
try {
this.binaryPath = exe.confirmVersionAndGetAbsolutePath();
} catch (IOException e) {
throw new IllegalArgumentException("binary cannot be found", e);
} catch (InterruptedException e) {
throw new IllegalArgumentException(
"binary cannot be found, process was interrupted", e);
}
}

@Override
public String applyWithFile(String unix, File file) throws Exception {
List<String> params = getParams(file);

try (ProcessRunner runner = new ProcessRunner()) {
var result = runner.exec(params);

LOGGER.debug("command finished with stdout: {}",
result.assertExitZero(StandardCharsets.UTF_8));

return Files.readString(file.toPath());
}
}

private List<String> getParams(File file) {
var builder = Stream.<String> builder();
builder.add(binaryPath);
builder.add("format");
if (withDefaults) {
builder.add("-allowDefaults");
}
if (configPath != null) {
builder.add("-s");
builder.add(configPath);
}
builder.add(file.toString());
return builder.build().collect(Collectors.toList());
}
}
}
2 changes: 2 additions & 0 deletions 2 plugin-gradle/CHANGES.md
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`).

## [Unreleased]
### Added
* Support for `idea` ([#2020](https://github.com/diffplug/spotless/pull/2020))
### Fixed
* Ignore system git config when running tests ([#1990](https://github.com/diffplug/spotless/issues/1990))

Expand Down
42 changes: 41 additions & 1 deletion 42 plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.diffplug.spotless.java.CleanthatJavaStep;
import com.diffplug.spotless.java.FormatAnnotationsStep;
import com.diffplug.spotless.java.GoogleJavaFormatStep;
import com.diffplug.spotless.java.IdeaStep;
import com.diffplug.spotless.java.ImportOrderStep;
import com.diffplug.spotless.java.PalantirJavaFormatStep;
import com.diffplug.spotless.java.RemoveUnusedImportsStep;
Expand Down Expand Up @@ -313,6 +314,45 @@ public EclipseConfig withP2Mirrors(Map<String, String> mirrors) {

}

public IdeaConfig idea() {
return new IdeaConfig();
}

public class IdeaConfig {
private String binaryPath;
private String configPath;
private boolean withDefaults = false;

IdeaConfig() {
addStep(createStep());
}

private FormatterStep createStep() {
return IdeaStep.create(withDefaults, binaryPath, configPath);
}

public IdeaConfig binaryPath(String binaryPath) {
Objects.requireNonNull(binaryPath);
this.binaryPath = binaryPath;
replaceStep(createStep());
return this;
}

public IdeaConfig configPath(String configPath) {
Objects.requireNonNull(configPath);
this.configPath = configPath;
replaceStep(createStep());
return this;
}

public IdeaConfig withDefaults(Boolean withDefaults) {
Objects.requireNonNull(withDefaults);
this.withDefaults = withDefaults;
replaceStep(createStep());
return this;
}
}

/** Removes newlines between type annotations and types. */
public FormatAnnotationsConfig formatAnnotations() {
return new FormatAnnotationsConfig();
Expand Down Expand Up @@ -400,7 +440,7 @@ public CleanthatJavaConfig clearMutators() {
}

// An id of a mutator (see IMutator.getIds()) or
// tThe fully qualified name of a class implementing eu.solven.cleanthat.engine.java.refactorer.meta.IMutator
// The fully qualified name of a class implementing eu.solven.cleanthat.engine.java.refactorer.meta.IMutator
public CleanthatJavaConfig addMutator(String mutator) {
this.mutators.add(mutator);
replaceStep(createStep());
Expand Down
43 changes: 43 additions & 0 deletions 43 plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JavaIdeaTest.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2020-2024 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.diffplug.gradle.spotless;

import java.io.IOException;

import org.junit.jupiter.api.Test;

import com.diffplug.spotless.tag.IdeaTest;

@IdeaTest
class JavaIdeaTest extends GradleIntegrationHarness {
@Test
void idea() throws IOException {
setFile("build.gradle").toLines(
"plugins {",
" id 'com.diffplug.spotless'",
"}",
"spotless {",
" java {",
" target file('test.java')",
" idea().binaryPath('idea').withDefaults(true)",
" }",
"}");

setFile("test.java").toResource("java/idea/full.dirty.java");
gradleRunner().withArguments("spotlessApply").build();
assertFile("test.java").notSameAsResource("java/idea/full.dirty.java");
}
}
6 changes: 3 additions & 3 deletions 6 plugin-maven/CHANGES.md
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`).

## [Unreleased]
### Fixed
* Ignore system git config when running tests ([#1990](https://github.com/diffplug/spotless/issues/1990))

### Added
* Support for `idea` ([#2020](https://github.com/diffplug/spotless/pull/2020))
* Respect `.editorconfig` settings for formatting shell via `shfmt` ([#2031](https://github.com/diffplug/spotless/pull/2031))
### Fixed
* Ignore system git config when running tests ([#1990](https://github.com/diffplug/spotless/issues/1990))

## [2.43.0] - 2024-01-23
### Added
Expand Down
40 changes: 40 additions & 0 deletions 40 plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Idea.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2016-2024 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.diffplug.spotless.maven.java;

import org.apache.maven.plugins.annotations.Parameter;

import com.diffplug.spotless.FormatterStep;
import com.diffplug.spotless.java.IdeaStep;
import com.diffplug.spotless.maven.FormatterStepConfig;
import com.diffplug.spotless.maven.FormatterStepFactory;

public class Idea implements FormatterStepFactory {

@Parameter
private String binaryPath;

@Parameter
private String configPath;

@Parameter
private Boolean withDefaults = false;

@Override
public FormatterStep newFormatterStep(FormatterStepConfig config) {
return IdeaStep.create(withDefaults, binaryPath, configPath);
}
}
6 changes: 5 additions & 1 deletion 6 plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2023 DiffPlug
* Copyright 2016-2024 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -68,6 +68,10 @@ public void addImportOrder(ImportOrder importOrder) {
addStepFactory(importOrder);
}

public void addIdea(Idea idea) {
addStepFactory(idea);
}

public void addPalantirJavaFormat(PalantirJavaFormat palantirJavaFormat) {
addStepFactory(palantirJavaFormat);
}
Expand Down
37 changes: 37 additions & 0 deletions 37 plugin-maven/src/test/java/com/diffplug/spotless/maven/java/IdeaTest.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2016-2024 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.diffplug.spotless.maven.java;

import org.junit.jupiter.api.Test;

import com.diffplug.spotless.maven.MavenIntegrationHarness;

@com.diffplug.spotless.tag.IdeaTest
class IdeaTest extends MavenIntegrationHarness {
@Test
void idea() throws Exception {
setFile("test.java").toResource("java/cleanthat/MultipleMutators.dirty.test");
writePomWithJavaSteps(
"<idea>",
" <binaryPath>idea</binaryPath>",
" <withDefaults>true</withDefaults>",
"</idea>");

mavenRunner().withArguments("spotless:apply").runNoError();

assertFile("test.java").notSameAsResource("java/cleanthat/MultipleMutators.dirty.test");
}
}
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.