Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Commit

Permalink
Add automatic code formatting
Browse files Browse the repository at this point in the history
Spotless will make automatic code formatting across all files.
This allows having a unified look across all files.

The process of formatting is automated using Elegant Git.
  • Loading branch information
extsoft committed Oct 31, 2019
1 parent 2232ccb commit 3d6743d
Show file tree
Hide file tree
Showing 95 changed files with 597 additions and 619 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/quality-pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
with:
java-version: 1.8
- name: Build with Gradle
run: ./gradlew clean ready
run: ./workflows testing
- name: Upload coverage to Codecov
uses: codecov/[email protected]
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ build/
_build/
.python-version
*.iml
out/
1 change: 1 addition & 0 deletions .workflows/amend-work-after
1 change: 1 addition & 0 deletions .workflows/amend-work-ahead
2 changes: 2 additions & 0 deletions .workflows/save-work-after
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
./workflows testing
2 changes: 2 additions & 0 deletions .workflows/save-work-ahead
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
./workflows formatting
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,15 @@ Before sending any pull request, please discuss requirements/changes to be imple
by creating a new one.

## Development notes
If you will install <https://elegant-git.bees-hive.org> and use Git via CLI, all required workflows
will be executed automatically. Otherwise, you can do it manually by running `./workflows` script.

### Code formatting
We use <https://github.com/diffplug/spotless> to format the code. Please run
`./gradlew spotlessApply` to call the formatting manually.

### Code assessment
Run `./gradlew` (or `gradlew.bat`). It will execute unit & integration tests and let you know if everything is working fine.
Run `./gradlew` (or `gradlew.bat`). It will execute unit, integration tests, and formatting verifications.

### Docs review
Automatic analysis of documentation changes in not configured. That's why manual validation is required.
Expand Down
38 changes: 38 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,49 @@
plugins {
id "com.jfrog.bintray" version "1.8.4" apply false
id "com.diffplug.gradle.spotless" version "3.25.0"
}

ext {
GITHUB_URL = "https://github.com/tatools/sunshine"
BINTRAY_ORG = "tatools"
}
repositories {
mavenLocal()
jcenter()
mavenCentral()
}

spotless {
apply plugin: 'java'
format 'misc', {
target '**/*.gradle', '**/*.md', '**/.gitignore'
trimTrailingWhitespace()
indentWithSpaces()
endWithNewline()
}
java {
removeUnusedImports()
indentWithSpaces()
trimTrailingWhitespace()
endWithNewline()

custom 'Lambda fix', { it.replace('} )', '})').replace('} ,', '},') }

// use standard modifier order (JLS 4.8.7 Modifiers)
// public protected private abstract static final transient volatile synchronized native strictfp
replaceRegex 'Modifier order 1', '^(\\s*)((?:static)|(?:final)|(?:abstract))\\s+((public)|(protected)|(private))\\s', '$1$3 $2 '
replaceRegex 'Modifier order 2', '^(\\s*)final\\s+static\\s+((public)|(protected)|(private))\\s', '$1$2 static final '
replaceRegex 'Modifier order 3', '^(\\s*)static\\s+final\\s+((public)|(protected)|(private))\\s', '$1$2 static final '
replaceRegex 'Modifier order 4', '^(\\s*((public)|(protected)|(private))?\\s*)\\sfinal\\s+static', '$1 static final'

// remove empty lines before end of block (closing "}")
replaceRegex 'Remove empty lines before end of block', '\\n[\\n]+(\\s*})(?=\\n)', '\n$1'

}
freshmark {
target '**/*.md'
}
}

subprojects {
apply plugin: 'java'
Expand Down
8 changes: 4 additions & 4 deletions docs/md/entry-points.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Entry points
An entry point is a Java class which is configured for a JAR and will be used when
An entry point is a Java class which is configured for a JAR and will be used when
```bash
java -jar my.jar
```
Expand All @@ -14,7 +14,7 @@ Sunshine's wrapper:

Also, there is a `SunshineSuite` interface with several core implementations which allow seeking
and filtering of the classes to be treated as tests. Sunshine uses a string representation of a class
as an input to a filter which uses
as an input to a filter which uses
[Java pattern matching](https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)
to filter classes. For instance, there is a `LoginTest` class in `com.example.mypackage` package.
It will be converted to `com.example.mypackage.LoginTest` and then put to a filter.
Expand Down Expand Up @@ -45,7 +45,7 @@ The class exposes the following behavior:
2. `java -Dtests-regex="^(com.company.smoke)(.+)" -jar my.jar` does the same as the previous one except
a class name has to match with `^(com.company.smoke)(.+)` regex.
3. `java -jar my.jar testng.xml` runs tests defined in `testng.xml` file (it can be either
[TestNG XML](http://testng.org/doc/documentation-main.html#testng-xml) or
[TestNG XML](http://testng.org/doc/documentation-main.html#testng-xml) or
[TestNG YAML](http://testng.org/doc/documentation-main.html#yaml)).


Expand Down Expand Up @@ -91,7 +91,7 @@ new Sun(
```

### Specify classes directly
There are some classes which have to be treat as a test suite.
There are some classes which have to be treat as a test suite.

TestNG sample
```java
Expand Down
6 changes: 3 additions & 3 deletions docs/md/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ Suppose, there is a Maven project with automated tests
├── README.md
├── pom.xml
└── src
   ├── main
   └── test
   ├── main
   └── test
```
Usually, the code is located under `src/main` directory and automated tests under `src/test`.
According to [Sunshine's concept](concept.md), the code and automated tests have to live together in `src/main`.
Expand All @@ -34,5 +34,5 @@ of the configuration, [a JAR's entry point](https://docs.oracle.com/javase/tutor
has to be defined.

There are predefined classes to be used as the entry points for each test runner. However,
Sunshine was designed to encourage you to create your own configurations based on the project's requirements.
Sunshine was designed to encourage you to create your own configurations based on the project's requirements.
Please visit [entry points page](entry-points.md) to find out more.
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package org.tatools.testng;


/**
* @author Dmytro Serdiuk ([email protected])
* @version $Id$
* @since 0.1
*/
public class DisabledTest {
}
public class DisabledTest {}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package org.tatools.testng;


/**
* @author Dmytro Serdiuk ([email protected])
* @version $Id$
* @since 0.1
*/
public class FailedTest {
}
public class FailedTest {}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package org.tatools.testng;


/**
* @author Dmytro Serdiuk ([email protected])
* @version $Id$
* @since 0.1
*/
public class PassedTest {
}
public class PassedTest {}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package org.tatools.testng;


/**
* @author Dmytro Serdiuk ([email protected])
* @version $Id$
* @since 0.1
*/
public class SkippedTest {
}
public class SkippedTest {}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@
* @version $Id$
* @since 0.1
*/
public class Test1 {
}
public class Test1 {}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ public CompositeStatus(List<Status> statuses) {

/**
* Returns the exit code of an execution provided by xunit tests runner.
* <p>
* The code will be a maximum value from all available codes expect zero ones. If there is no
* maximal value, 0 is given (means all are passed), otherwise, a non-zero number (if there is at least one failure).
*
* <p>The code will be a maximum value from all available codes expect zero ones. If there is no
* maximal value, 0 is given (means all are passed), otherwise, a non-zero number (if there is
* at least one failure).
*
* @return a calculated exit code
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,10 @@ public Fake(Path path, boolean exist) {
}

@Override
public void create() {

}
public void create() {}

@Override
public void remove() {

}
public void remove() {}

@Override
public Path path() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package org.tatools.sunshine.core;

import lombok.EqualsAndHashCode;

import java.io.IOException;
import java.nio.file.FileVisitOption;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Comparator;
import lombok.EqualsAndHashCode;

/**
* @author Dmytro Serdiuk ([email protected])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package org.tatools.sunshine.core;

import lombok.EqualsAndHashCode;

import java.io.IOException;
import java.nio.file.Path;
import lombok.EqualsAndHashCode;

/**
* The class allows communicating with a {@link Directory} object safely. This means it does not touch real file system
* until it's really needed.
* The class allows communicating with a {@link Directory} object safely. This means it does not
* touch real file system until it's really needed.
*
* @author Dmytro Serdiuk ([email protected])
* @version $Id$
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.tatools.sunshine.core;


import java.io.IOException;
import java.nio.file.Path;

Expand All @@ -19,16 +18,18 @@ public DirectoryWithAutomaticDeletion(Directory directory) {

@Override
public final void create() throws IOException {
Runtime.getRuntime().addShutdownHook(new Thread("ds") {
@Override
public void run() {
try {
directory.remove();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
});
Runtime.getRuntime()
.addShutdownHook(
new Thread("ds") {
@Override
public void run() {
try {
directory.remove();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
});
directory.create();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package org.tatools.sunshine.core;

import lombok.EqualsAndHashCode;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import lombok.EqualsAndHashCode;

/**
* @author Dmytro Serdiuk ([email protected])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
*/
public interface FileSystem {
/**
* Returns a list of files within given file system. An implementation may support recursive search or not.
* Returns a list of files within given file system. An implementation may support recursive
* search or not.
*
* @return a list of files
* @throws FileSystemException if some error occurs
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.tatools.sunshine.core;

/**
* The {@link FileSystemException} class is a default exception to handle errors which may occur in the implementations of
* a {@link FileSystem} interface.
* The {@link FileSystemException} class is a default exception to handle errors which may occur in
* the implementations of a {@link FileSystem} interface.
*
* @author Dmytro Serdiuk ([email protected])
* @version $Id$
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package org.tatools.sunshine.core;

import lombok.EqualsAndHashCode;

import java.util.List;
import java.util.stream.Collectors;
import lombok.EqualsAndHashCode;

/**
* The {@link FileSystemFiltered} class allows to filter files by given condition.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package org.tatools.sunshine.core;

import lombok.EqualsAndHashCode;

import java.util.List;
import lombok.EqualsAndHashCode;

/**
* The {@link FileSystemOfClasses} class allows to select only Java classes.
Expand All @@ -17,12 +16,13 @@ final class FileSystemOfClasses implements FileSystem {
private final FileSystem fileSystem;

FileSystemOfClasses(FileSystem fileSystem) {
this.fileSystem = new FileSystemFiltered(
new FileSystemOfFileSystems(
fileSystem,
new FileSystemOfJarFiles(new FileSystemFiltered(fileSystem, new JarCondition()))
), new ClassCondition()
);
this.fileSystem =
new FileSystemFiltered(
new FileSystemOfFileSystems(
fileSystem,
new FileSystemOfJarFiles(
new FileSystemFiltered(fileSystem, new JarCondition()))),
new ClassCondition());
}

@Override
Expand All @@ -37,7 +37,6 @@ public boolean applicable(String identity) {
}
}


private final class JarCondition implements Condition {
@Override
public boolean applicable(String identity) {
Expand Down
Loading

0 comments on commit 3d6743d

Please sign in to comment.