Skip to content

Commit

Permalink
spotless formatting instead of checkstyle
Browse files Browse the repository at this point in the history
  • Loading branch information
aamotharald committed Nov 12, 2024
1 parent 9cb8366 commit 1353454
Show file tree
Hide file tree
Showing 338 changed files with 13,864 additions and 13,773 deletions.
34 changes: 3 additions & 31 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@
<version.hamcrest>3.0</version.hamcrest>
<version.spotless-maven-plugin>2.43.0</version.spotless-maven-plugin>
<version.googleJavaFormat>1.24.0</version.googleJavaFormat>
<version.maven-checkstyle-plugin>3.1.2</version.maven-checkstyle-plugin>
<version.maven-gpg-plugin>3.1.0</version.maven-gpg-plugin>
<version.nexus-staging-maven-plugin>1.6.13</version.nexus-staging-maven-plugin>
<version.maven-compiler-plugin>3.11.0</version.maven-compiler-plugin>
Expand Down Expand Up @@ -137,7 +136,6 @@
<version>${version.maven-javadoc-plugin}</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<failOnError>true</failOnError>
<failOnWarnings>true</failOnWarnings>
<additionalOptions>-Xdoclint:none</additionalOptions>
Expand Down Expand Up @@ -206,7 +204,7 @@
<executions>
<execution>
<goals>
<goal>check</goal>
<goal>apply</goal>
</goals>
<phase>compile</phase>
</execution>
Expand All @@ -219,32 +217,6 @@
</java>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${version.maven-checkstyle-plugin}</version>
<configuration>
<configLocation>google_checks.xml</configLocation>
<encoding>${project.build.sourceEncoding}</encoding>
<consoleOutput>true</consoleOutput>
<violationSeverity>warning</violationSeverity>
<failsOnError>true</failsOnError>
<linkXRef>false</linkXRef>
<suppressionsLocation>checkstyle-suppressions.xml</suppressionsLocation>
<suppressionsFileExpression>checkstyle.suppressions.file</suppressionsFileExpression>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
</configuration>
<executions>
<execution>
<id>validate</id>
<phase>package</phase>
<goals>
<goal>checkstyle</goal>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down Expand Up @@ -284,7 +256,7 @@
<profile>
<id>develop</id>
<properties>
<checkstyle.skip>true</checkstyle.skip>
<!--<checkstyle.skip>true</checkstyle.skip>-->
<maven.javadoc.skip>true</maven.javadoc.skip>
<skipAssembly>true</skipAssembly>
<spotless.apply.skip>true</spotless.apply.skip>
Expand All @@ -293,7 +265,7 @@
<profile>
<id>quick-assemble</id>
<properties>
<checkstyle.skip>true</checkstyle.skip>
<!--<checkstyle.skip>true</checkstyle.skip>-->
<maven.javadoc.skip>true</maven.javadoc.skip>
<skipAssembly>false</skipAssembly>
<skipTests>true</skipTests>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ public boolean equals(Object o) {
return true;
}

if (o instanceof AdviceContent) {
AdviceContent that = (AdviceContent) o;
if (o instanceof AdviceContent that) {
return Objects.equals(feature, that.feature)
&& Objects.equals(text, that.text)
&& Objects.equals(links, that.links);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,6 @@ protected AdviceContentYamlStorage(Map<String, List<RawAdviceContent>> featureTo
this.featureToContent = new HashMap<>(featureToContent);
}

/**
* Returns advice for a feature in a specified context.
*
* @param feature The feature.
* @param context The context.
* @return A list of advice.
* @throws MalformedURLException If the method couldn't parse URLs.
*/
public List<AdviceContent> adviceFor(Feature<?> feature, AdviceContext context)
throws MalformedURLException {

List<AdviceContent> adviceContents = new ArrayList<>();
for (RawAdviceContent rawAdvice : featureToContent.getOrDefault(feature.name(), emptyList())) {
adviceContents.add(rawAdvice.transformFor(feature, context));
}

return adviceContents;
}

/**
* Loads advice from a resource.
*
Expand All @@ -104,6 +85,25 @@ public static AdviceContentYamlStorage loadFrom(String path) throws IOException
throw new IOException(String.format("'%s' not found!", path));
}

/**
* Returns advice for a feature in a specified context.
*
* @param feature The feature.
* @param context The context.
* @return A list of advice.
* @throws MalformedURLException If the method couldn't parse URLs.
*/
public List<AdviceContent> adviceFor(Feature<?> feature, AdviceContext context)
throws MalformedURLException {

List<AdviceContent> adviceContents = new ArrayList<>();
for (RawAdviceContent rawAdvice : featureToContent.getOrDefault(feature.name(), emptyList())) {
adviceContents.add(rawAdvice.transformFor(feature, context));
}

return adviceContents;
}

/** A link to additional info for an advice. */
static class RawLink {

Expand Down Expand Up @@ -187,6 +187,24 @@ static class RawAdviceContent {
this.links = new ArrayList<>(links != null ? links : emptyList());
}

/**
* Replaces variables with their values in a string.
*
* @param string The string.
* @param values Maps variable names to their values.
* @return An updated string.
*/
private static String resolve(String string, Map<String, Optional<String>> values) {
for (Map.Entry<String, Optional<String>> entry : values.entrySet()) {
if (entry.getValue().isPresent()) {
string =
string.replaceAll(
String.format("\\$\\{%s\\}", entry.getKey()), entry.getValue().get());
}
}
return string;
}

@JsonGetter("advice")
private String advice() {
return advice;
Expand Down Expand Up @@ -258,24 +276,6 @@ AdviceContent transformFor(Feature<?> feature, AdviceContext context)
return new AdviceContent(feature, advice, links);
}

/**
* Replaces variables with their values in a string.
*
* @param string The string.
* @param values Maps variable names to their values.
* @return An updated string.
*/
private static String resolve(String string, Map<String, Optional<String>> values) {
for (Map.Entry<String, Optional<String>> entry : values.entrySet()) {
if (entry.getValue().isPresent()) {
string =
string.replaceAll(
String.format("\\$\\{%s\\}", entry.getKey()), entry.getValue().get());
}
}
return string;
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/sap/oss/phosphor/fosstars/advice/Link.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public boolean equals(Object o) {
return true;
}

if (o instanceof Link) {
Link link = (Link) o;
if (o instanceof Link link) {
return Objects.equals(name, link.name) && Objects.equals(url, link.url);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ public boolean equals(Object o) {
return true;
}

if (o instanceof SimpleAdvice) {
SimpleAdvice that = (SimpleAdvice) o;
if (o instanceof SimpleAdvice that) {
return Objects.equals(subject, that.subject)
&& Objects.equals(value, that.value)
&& Objects.equals(content, that.content);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,59 @@ protected AbstractOssAdvisor(
this.contextFactory = contextFactory;
}

/**
* Checks if a boolean value is known and false.
*
* @param value The value to be checked.
* @return True if the value is known and false, false otherwise.
*/
protected static boolean knownFalseValue(Value<?> value) {
return !value.isUnknown() && Boolean.FALSE.equals(value.get());
}

/**
* Looks for a sub-score value in a rating value assigned to a subject.
*
* @param subject The subject.
* @param subScoreClass A class of the sub-score.
* @return A sub-score value if present.
*/
protected static Optional<ScoreValue> findSubScoreValue(
Subject subject, Class<? extends Score> subScoreClass) {

if (!subject.ratingValue().isPresent()) {
return Optional.empty();
}

return findSubScoreValue(subject.ratingValue().get().scoreValue(), subScoreClass);
}

/**
* Looks for a sub-score value in a score value.
*
* @param scoreValue The score value.
* @param subScoreClass A class of the sub-score.
* @return A sub-score value if present.
*/
private static Optional<ScoreValue> findSubScoreValue(
ScoreValue scoreValue, Class<? extends Score> subScoreClass) {

if (scoreValue.score().getClass().equals(subScoreClass)) {
return Optional.of(scoreValue);
}

for (Value<?> usedValue : scoreValue.usedValues()) {
if (usedValue instanceof ScoreValue) {
Optional<ScoreValue> result = findSubScoreValue((ScoreValue) usedValue, subScoreClass);
if (result.isPresent()) {
return result;
}
}
}

return Optional.empty();
}

@Override
public final List<Advice> adviceFor(Subject subject) throws MalformedURLException {
if (!subject.ratingValue().isPresent()) {
Expand Down Expand Up @@ -123,59 +176,6 @@ protected <T> List<Advice> adviceForFeature(
.collect(Collectors.toList());
}

/**
* Checks if a boolean value is known and false.
*
* @param value The value to be checked.
* @return True if the value is known and false, false otherwise.
*/
protected static boolean knownFalseValue(Value<?> value) {
return !value.isUnknown() && Boolean.FALSE.equals(value.get());
}

/**
* Looks for a sub-score value in a rating value assigned to a subject.
*
* @param subject The subject.
* @param subScoreClass A class of the sub-score.
* @return A sub-score value if present.
*/
protected static Optional<ScoreValue> findSubScoreValue(
Subject subject, Class<? extends Score> subScoreClass) {

if (!subject.ratingValue().isPresent()) {
return Optional.empty();
}

return findSubScoreValue(subject.ratingValue().get().scoreValue(), subScoreClass);
}

/**
* Looks for a sub-score value in a score value.
*
* @param scoreValue The score value.
* @param subScoreClass A class of the sub-score.
* @return A sub-score value if present.
*/
private static Optional<ScoreValue> findSubScoreValue(
ScoreValue scoreValue, Class<? extends Score> subScoreClass) {

if (scoreValue.score().getClass().equals(subScoreClass)) {
return Optional.of(scoreValue);
}

for (Value<?> usedValue : scoreValue.usedValues()) {
if (usedValue instanceof ScoreValue) {
Optional<ScoreValue> result = findSubScoreValue((ScoreValue) usedValue, subScoreClass);
if (result.isPresent()) {
return result;
}
}
}

return Optional.empty();
}

/** A factory that provides advice contexts for open-source projects. */
public interface OssAdviceContextFactory {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,6 @@ public LgtmAdvisor(OssAdviceContextFactory contextFactory) {
super(OssAdviceContentYamlStorage.DEFAULT, contextFactory);
}

@Override
protected List<Advice> adviceFor(
Subject subject, List<Value<?>> usedValues, OssAdviceContext context)
throws MalformedURLException {

Optional<Value<LgtmGrade>> value =
findValue(usedValues, WORST_LGTM_GRADE)
.filter(LgtmAdvisor::isKnown)
.filter(LgtmAdvisor::notTheBest);

if (!value.isPresent()) {
return emptyList();
}

return adviceStorage.adviceFor(value.get().feature(), context).stream()
.map(content -> new SimpleAdvice(subject, value.get(), content))
.map(Advice.class::cast)
.collect(Collectors.toList());
}

/**
* Checks if a value is known.
*
Expand All @@ -67,4 +47,24 @@ private static boolean isKnown(Value<LgtmGrade> value) {
private static boolean notTheBest(Value<LgtmGrade> value) {
return value.get() != A_PLUS;
}

@Override
protected List<Advice> adviceFor(
Subject subject, List<Value<?>> usedValues, OssAdviceContext context)
throws MalformedURLException {

Optional<Value<LgtmGrade>> value =
findValue(usedValues, WORST_LGTM_GRADE)
.filter(LgtmAdvisor::isKnown)
.filter(LgtmAdvisor::notTheBest);

if (!value.isPresent()) {
return emptyList();
}

return adviceStorage.adviceFor(value.get().feature(), context).stream()
.map(content -> new SimpleAdvice(subject, value.get(), content))
.map(Advice.class::cast)
.collect(Collectors.toList());
}
}
Loading

0 comments on commit 1353454

Please sign in to comment.