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

Java Autoformatter #728

Merged
merged 57 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
0bceb05
Create java-autoformat.yml
jadeandtea Feb 7, 2024
782223a
Setup Java
jadeandtea Feb 8, 2024
ab30e26
Run spotless on repository
jadeandtea Feb 8, 2024
ee58d4e
Adding spotless dependency during build
jadeandtea Feb 8, 2024
283e6c4
Adding spotless dependency during build
jadeandtea Feb 8, 2024
51070b5
Give permissions to run spotless
jadeandtea Feb 8, 2024
51919f1
Syntax
jadeandtea Feb 8, 2024
59c3c8d
Adding Debug Tag
jadeandtea Feb 8, 2024
06d3d01
Check for modified files
jadeandtea Feb 8, 2024
4cc5893
Automated Java code formatting changes
Bram28 Feb 8, 2024
d62ea2e
Test command syntax
jadeandtea Feb 8, 2024
31405c7
Merge branch 'autoformatter' of https://github.com/Bram-Hub/LEGUP int…
jadeandtea Feb 8, 2024
4d556fe
Correctly Identify modified files
jadeandtea Feb 8, 2024
bbe699b
Test autoformatter
jadeandtea Feb 8, 2024
e7eca25
Test autoformatter
jadeandtea Feb 8, 2024
5850b26
Test autoformatter
jadeandtea Feb 8, 2024
e5e3221
Debugging
jadeandtea Feb 8, 2024
bb9c82e
Debugging
jadeandtea Feb 8, 2024
3330a5a
Change method for detecting changed files
jadeandtea Feb 8, 2024
b33ba20
Try building before calling spotless
jadeandtea Feb 8, 2024
6fb587f
Update java-autoformat.yml
charlestian23 Feb 13, 2024
932daeb
Update java-autoformat.yml
charlestian23 Feb 13, 2024
ecfc69e
Update java-autoformat.yml
charlestian23 Feb 13, 2024
05bed9f
Purposely bad formatting
charlestian23 Feb 13, 2024
92ed811
Update build.gradle
charlestian23 Feb 13, 2024
25b884e
Update java-autoformat.yml
charlestian23 Feb 13, 2024
26b53f1
Debugging
charlestian23 Feb 13, 2024
bbd679a
Adding more awful formatting
charlestian23 Feb 13, 2024
ba776d0
Update java-autoformat.yml
charlestian23 Feb 13, 2024
1a8af74
Changing repo URL
charlestian23 Feb 13, 2024
b43f50f
Going back to checkout v1
charlestian23 Feb 13, 2024
112937e
Trying URL change
charlestian23 Feb 13, 2024
ac6ee76
Trying out using env
charlestian23 Feb 13, 2024
872a268
Trying this now...?
charlestian23 Feb 13, 2024
c707f57
Introducing more horrible changes
charlestian23 Feb 13, 2024
9936767
Spotless formatting using google format v1.19.2
jadeandtea Feb 13, 2024
f6c5453
Manual formatting fix
jadeandtea Feb 13, 2024
3eddb77
Automated Java code formatting changes
Bram28 Feb 13, 2024
b9000bb
Different format type
jadeandtea Feb 13, 2024
55a1b32
Disable checkstyle temporarily
jadeandtea Feb 13, 2024
77fff2c
Automated Java code formatting changes
Bram28 Feb 13, 2024
a62e03f
Default google formatting style
jadeandtea Feb 13, 2024
96da739
Automated Java code formatting changes
Bram28 Feb 13, 2024
969d4f7
Comments and reordering styles
jadeandtea Feb 13, 2024
4e0ef24
Adding extra newlines
jadeandtea Feb 13, 2024
4c4b6fa
Automated Java code formatting changes
Bram28 Feb 13, 2024
76904a2
Changing tabs from 2 to 4 spaces
jadeandtea Feb 14, 2024
e8ae4db
Remove solo } requirement and reactivate checkstyle
jadeandtea Feb 14, 2024
a7db981
Automated Java code formatting changes
Bram28 Feb 14, 2024
0e65e20
Merge branch 'autoformatter' of https://github.com/Bram-Hub/LEGUP int…
jadeandtea Feb 14, 2024
bee026f
Update checkstyle.xml
charlestian23 Feb 14, 2024
58953d8
Changing back to tabWidth
charlestian23 Feb 14, 2024
0a10c76
Add newline to test formatter + build
jadeandtea Feb 14, 2024
30afaf1
Automated Java code formatting changes
Bram28 Feb 14, 2024
19697b9
Trying some ChatGPT stuff
charlestian23 Feb 14, 2024
0d16d6f
Merge branch 'autoformatter' of https://github.com/Bram-Hub/LEGUP int…
charlestian23 Feb 14, 2024
6933cb0
Getting rid of problematic experimentation
charlestian23 Feb 14, 2024
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
  •  
  •  
  •  
38 changes: 38 additions & 0 deletions .github/workflows/java-autoformat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Java Code Auto Format
on: pull_request

jobs:
format:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v1
with:
ref: ${{ github.head_ref }}

- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Build with Gradle
run: ./gradlew build -x test

- name: Run spotless
run: ./gradlew :spotlessApply

- name: Check for modified files
id: git-check
run: echo "modified=$(if git diff-index --quiet HEAD --; then echo "false"; else echo "true"; fi)" >> $GITHUB_OUTPUT

- name: Push changes
if: steps.git-check.outputs.modified == 'true'
run: |
git config --global user.name 'Bram van Heuveln'
git config --global user.email '[email protected]'
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
git add .
git diff --cached --exit-code || git commit -am "Automated Java code formatting changes" && git push
30 changes: 30 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,43 @@ plugins {
id 'java'
id 'edu.sc.seis.launch4j' version '2.5.3'
id 'kr.motd.sphinx' version '2.10.0'
id 'com.diffplug.spotless' version '6.25.0'
}


version '2.0.0'

apply plugin: 'java'
apply plugin: 'application'

spotless{
enforceCheck false

format 'misc', {
// define the files to apply `misc` to
target '*.gradle', '*.md', '.gitignore'

// define the steps to apply to those files
trimTrailingWhitespace()
indentWithSpaces() // or spaces. Takes an integer argument if you don't like 4
endWithNewline()
}

java{
// Use the default importOrder configuration
importOrder()

// Cleanthat will refactor your code, but it may break your style: apply it before your formatter
cleanthat()

googleJavaFormat('1.19.2').aosp()

formatAnnotations()
}
}

apply plugin: 'checkstyle'

mainClassName = 'edu.rpi.legup.Legup'

sourceCompatibility = 11
Expand Down
6 changes: 0 additions & 6 deletions config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@
<module name="Checker">
<module name="TreeWalker">
<property name="tabWidth" value="4"/>
<module name="LeftCurly"/>
<module name="RightCurly">
<property name="option" value="alone"/>
<property name="tokens"
value="LITERAL_IF, LITERAL_ELSE, LITERAL_TRY, LITERAL_CATCH, LITERAL_FINALLY, LITERAL_WHILE, LITERAL_DO, LITERAL_FOR, METHOD_DEF"/>
</module>
<module name="NeedBraces">
<property name="allowSingleLineStatement" value="true"/>
</module>
Expand Down
Empty file modified gradlew
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion src/main/java/edu/rpi/legup/Legup.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ public static void main(String[] args) {
GameBoardFacade.getInstance();
GameBoardFacade.setupConfig();
}
}
}
3 changes: 1 addition & 2 deletions src/main/java/edu/rpi/legup/ai/Solver.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
package edu.rpi.legup.ai;

public class Solver {
}
public class Solver {}
22 changes: 10 additions & 12 deletions src/main/java/edu/rpi/legup/app/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,18 @@

import java.io.*;
import java.util.*;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

public class Config {
private final static Logger Logger = LogManager.getLogger(Config.class.getName());
private static final Logger Logger = LogManager.getLogger(Config.class.getName());

private Map<String, String> puzzles;
private Map<String, Boolean> fileCreationDisabledStatuses;
Expand All @@ -43,8 +40,8 @@ public List<String> getPuzzleClassNames() {
}

/**
* Returns a list of the names of the puzzles which can have puzzles created and edited
* within the proof editor.
* Returns a list of the names of the puzzles which can have puzzles created and edited within
* the proof editor.
*
* @return the aforementioned list of Strings
*/
Expand All @@ -59,8 +56,8 @@ public List<String> getFileCreationEnabledPuzzles() {
}

/**
* Converts the class name of the puzzles to their display names. Some examples of the conversion:
* convertClassNameToDisplayName("TreeTent") will return "Tree Tent"
* Converts the class name of the puzzles to their display names. Some examples of the
* conversion: convertClassNameToDisplayName("TreeTent") will return "Tree Tent"
* convertClassNameToDisplayName("Nurikabe") will return "Nurikabe"
*
* @param className the name of the class
Expand Down Expand Up @@ -140,15 +137,16 @@ private void loadConfig(InputStream stream) throws InvalidConfigException {
Element puzzle = (Element) puzzleNodes.item(i);
String name = puzzle.getAttribute("name");
String className = puzzle.getAttribute("qualifiedClassName");
boolean status = Boolean.parseBoolean(puzzle.getAttribute("fileCreationDisabled").toLowerCase());
boolean status =
Boolean.parseBoolean(
puzzle.getAttribute("fileCreationDisabled").toLowerCase());
Logger.debug("Class Name: " + className);
this.puzzles.put(name, className);
this.fileCreationDisabledStatuses.put(name, Boolean.valueOf(status));
}

}
catch (ParserConfigurationException | SAXException | IOException e) {
} catch (ParserConfigurationException | SAXException | IOException e) {
throw new InvalidConfigException(e.getMessage());
}
}
}
}
Loading
Loading