Skip to content

Commit

Permalink
chore: spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
StarWishsama committed Mar 24, 2024
1 parent 5d336ec commit 8db96a5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 23 deletions.
19 changes: 6 additions & 13 deletions .git-hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,11 @@

echo "[pre-commit check]"

STAGED_FILES=$(git --no-pager diff --name-only --staged --line-prefix=$(git rev-parse --show-toplevel)/ | paste -sd ',')

if [ ! -z "$STAGED_FILES" ]
echo -n "Checking code format with spotless: "
mvn spotless:apply > /tmp/spotless.out 2>&1
RETURN_VALUE=$?
if [ $RETURN_VALUE -gt 0 ]
then
echo -n "Checking code format with spotless: "
mvn spotless:check -DspotlessFiles=$STAGED_FILES > /tmp/spotless.out 2>&1
RETURN_VALUE=$?
if [ $RETURN_VALUE -gt 0 ]
then
echo "Please run 'mvn spotless:check' for more details or 'mvn spotless:apply' to automatically fix the violations."
fi
exit $RETURN_VALUE
echo "Please run 'mvn spotless:check' for more details or 'mvn spotless:apply' to automatically fix the violations."
fi

exit 0
exit $RETURN_VALUE
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.logging.Level;
Expand Down Expand Up @@ -130,14 +129,17 @@ private void addDirectory(@Nonnull ZipOutputStream output, @Nonnull File directo
* An {@link IOException} is thrown if a {@link File} could not be deleted
*/
private void purgeBackups(@Nonnull List<File> backups) throws IOException {
var matchedBackup = backups.stream().filter(f -> f.getName().matches("^\\d{4}-\\d{2}-\\d{2}-\\d{2}-\\d{2}$")).sorted((a, b) -> {
LocalDateTime time1 =
LocalDateTime.parse(a.getName().substring(0, a.getName().length() - 4), format);
LocalDateTime time2 =
LocalDateTime.parse(b.getName().substring(0, b.getName().length() - 4), format);

return time2.compareTo(time1);
}).toList();
var matchedBackup = backups.stream()
.filter(f -> f.getName().matches("^\\d{4}-\\d{2}-\\d{2}-\\d{2}-\\d{2}$"))
.sorted((a, b) -> {
LocalDateTime time1 = LocalDateTime.parse(
a.getName().substring(0, a.getName().length() - 4), format);
LocalDateTime time2 = LocalDateTime.parse(
b.getName().substring(0, b.getName().length() - 4), format);

return time2.compareTo(time1);
})
.toList();

for (int i = matchedBackup.size() - MAX_BACKUPS; i > 0; i--) {
Files.delete(matchedBackup.get(i).toPath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void onResult(SlimefunBlockData result) {
}
}

// Don't move my machine :|
// Don't move my machine :|
case ENDERMAN -> e.setCancelled(true);
}
}
Expand Down

0 comments on commit 8db96a5

Please sign in to comment.