Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Introduce checkstyle to enforce conventions #326

Merged
merged 9 commits into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions checkstyle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" ?>

<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.2//EN"
"https://checkstyle.org/dtds/configuration_1_2.dtd">

<module name="Checker">
<module name="TreeWalker">

<!-- No if/else/do/for/while without braces -->
<module name="NeedBraces"/>

<!-- No empty blocks -->
<module name="EmptyBlock"/>

<!-- Disallow unnecessary instantiation of Boolean, String -->
<module name="IllegalInstantiation">
<!-- property name="classes" value="java.lang.Boolean, java.lang.String"/ -->
<property name="classes" value="java.lang.Boolean"/>
</module>

<!-- Import should be explicit, really needed and only from pure java packages -->
<module name="AvoidStarImport" />
<module name="UnusedImports" />
<module name="IllegalImport" />

<!-- TODO: Find how to exclude spring application classes and uncomment -->
<!-- Check https://checkstyle.org/config_filters.html#SuppressionXpathSingleFilter -->
<!-- Utility class should not be instantiated, they must have a private constructor -->
<!-- module name="HideUtilityClassConstructor" /-->

<!-- No System.out.println() statements -->
<module name="Regexp">
<!-- no sysouts -->
<property name="format" value="System\.out\.println"/>
<property name="illegalPattern" value="true"/>
</module>

<!-- No trailing whitespace -->
<module name="Regexp">
<property name="format" value="[ \t]+$"/>
<property name="illegalPattern" value="true"/>
<property name="message" value="Trailing whitespace"/>
</module>
</module>
</module>
4 changes: 4 additions & 0 deletions notification-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ public String getUsername() {
if (ldapDetails != null) {
return ldapDetails.getUsername();
}
else
else {
log.error("Unable to get the LdapDetails to get the username");
}
return null;
}

Expand Down
4 changes: 4 additions & 0 deletions parodos-model-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*
* @author Luke Shannon (Github: lshannon)
* @author Gloria Ciavarrini (Github: gciavarrini)
*
*
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,16 @@ public Map<String, Object> getAsJsonSchema() {
Map<String, Object> properties = type.getAsJsonSchema();
properties.put(REQUIRED, !optional);
properties.put(DESCRIPTION, description);
if (valueProviderName != null && !valueProviderName.isEmpty())
if (valueProviderName != null && !valueProviderName.isEmpty()) {
properties.put(VALUE_PROVIDER_NAME, valueProviderName);
}
if (type.isSelect() && selectOptions != null && !selectOptions.isEmpty()) {
properties.put(ENUM, selectOptions);
}

if (jsonSchemaOptions != null)
if (jsonSchemaOptions != null) {
properties.putAll(jsonSchemaOptions);
}

return properties;
}
Expand Down
9 changes: 9 additions & 0 deletions pattern-detection-library/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,13 @@
<version>${guava.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
package com.redhat.parodos.patterndetection.exceptions;

/**
* A catch all thrown when when issues occur during the execution of scans in the WorkFlow
*
* A catch-all thrown when issues occur during the execution of scans in the WorkFlow
*
* @author Luke Shannon (Github: lshannon)
*
*/
Expand Down
31 changes: 31 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,37 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.1</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>9.3</version>
</dependency>
<dependency>
<groupId>io.spring.javaformat</groupId>
<artifactId>spring-javaformat-checkstyle</artifactId>
<version>0.0.38</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>checkstyle-validation</id>
<phase>validate</phase>
<inherited>true</inherited>
<configuration>
<configLocation>checkstyle.xml</configLocation>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
</configuration>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
Expand Down
9 changes: 9 additions & 0 deletions prebuilt-tasks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,13 @@
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@

import static com.redhat.parodos.workflows.workflow.WorkContextAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
public class SubmitAnalysisTaskTest {
Expand Down
8 changes: 8 additions & 0 deletions sdk-utils/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,12 @@
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
4 changes: 4 additions & 0 deletions workflow-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ public List<WorkParameterValueResponse> getValues(List<WorkParameterValueRequest

if (!workParameterValueRequests.isEmpty()
&& workParameterValueRequests.get(0).getKey().equalsIgnoreCase("WORKFLOW_SELECT_SAMPLE")
&& workParameterValueRequests.get(0).getValue().equalsIgnoreCase("option2"))
&& workParameterValueRequests.get(0).getValue().equalsIgnoreCase("option2")) {
return List.of(
WorkParameterValueResponse.builder().key("WORKFLOW_MULTI_SELECT_SAMPLE")
.options(List.of("option5", "option4", "option3")).value("option5")
.workName("complexWorkFlow").build(),
WorkParameterValueResponse.builder().key("dynamic-options")
.options(List.of("option15", "option14", "option13")).value("option13")
.workName("adGroupsWorkFlowTask").build());
}
return Collections.emptyList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
import java.util.function.Consumer;

import com.redhat.parodos.email.Message;
import com.redhat.parodos.tasks.migrationtoolkit.*;
import com.redhat.parodos.tasks.migrationtoolkit.CreateApplicationTask;
import com.redhat.parodos.tasks.migrationtoolkit.GetAnalysisTask;
import com.redhat.parodos.tasks.migrationtoolkit.GetApplicationTask;
import com.redhat.parodos.tasks.migrationtoolkit.SubmitAnalysisTask;
import com.redhat.parodos.workflow.annotation.Checker;
import com.redhat.parodos.workflow.annotation.Infrastructure;
import com.redhat.parodos.workflows.workflow.WorkFlow;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
import org.springframework.context.annotation.Profile;

/**
*
*
* Sample configuration for Tibco Task
*
*/
@Configuration
@Profile("tibco")
public class TibcoWorkFlowConfiguration {

@Bean
TibcoWorkFlowTask tibcoTask() {
// TIBCO's default installation:
Expand Down
4 changes: 4 additions & 0 deletions workflow-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,10 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ public static String getUsername() {
if (ldapDetails != null) {
return ldapDetails.getUsername();
}
else
else {
log.error("Unable to get the LdapDetails to get the username");
}
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ public WorkContext initWorkFlowContext(WorkFlowRequestDTO workFlowRequestDTO,
workFlowRequestDTO.getWorkFlowName(), WorkContextDelegate.Resource.ARGUMENTS,
WorkFlowDTOUtil.convertArgumentListToMap(workFlowRequestDTO.getArguments()));
}
if (mainWorkFlowDefinitionDto.getWorks() != null && !mainWorkFlowDefinitionDto.getWorks().isEmpty())
if (mainWorkFlowDefinitionDto.getWorks() != null && !mainWorkFlowDefinitionDto.getWorks().isEmpty()) {
mainWorkFlowDefinitionDto.getWorks().forEach(work -> initWorkContext(workContext,
workFlowRequestDTO.findFirstWorkByName(work.getName()), work, mainWorkFlowDefinitionDto.getName()));
}
return workContext;
}

Expand All @@ -74,12 +75,13 @@ private void initWorkContext(WorkContext workContext, WorkFlowRequestDTO.WorkReq
workRequestDTO.getWorkName(), WorkContextDelegate.Resource.ARGUMENTS,
WorkFlowDTOUtil.convertArgumentListToMap(workRequestDTO.getArguments())));

if (workDefinitionResponseDTO.getWorks() != null)
if (workDefinitionResponseDTO.getWorks() != null) {
workDefinitionResponseDTO.getWorks()
.forEach(work -> initWorkContext(
workContext, Optional.ofNullable(workRequestDTO)
.map(dto -> dto.findFirstWorkByName(work.getName())).orElse(null),
work, workDefinitionResponseDTO.getName()));
}
}

public WorkFlow getWorkFlowByName(String workFlowName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ private WorkParameterValueResponseDTO mappingParameterResponse(String workflowDe
WorkParameterValueResponse workParameterValueResponse) {
String workName = Optional.ofNullable(workParameterValueResponse.getWorkName()).orElse(workflowDefinitionName);
Map<String, Object> parameters = workFlowDefinitionService.getWorkParametersByWorkName(workName);
if (parameters == null || !parameters.containsKey(workParameterValueResponse.getKey()))
if (parameters == null || !parameters.containsKey(workParameterValueResponse.getKey())) {
return null;
}

String propertyPath = workName;
WorkFlowDefinition workFlowDefinition = workFlowDefinitionService.getParentWorkFlowByWorkName(workName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ public WorkFlowDefinitionServiceImpl(WorkFlowDefinitionRepository workFlowDefini
private HashMap<String, Map<String, Object>> convertWorkParameters(List<WorkParameter> workParameters) {
HashMap<String, Map<String, Object>> result = new HashMap<>();
for (WorkParameter workParameter : workParameters) {
if (workParameter == null)
if (workParameter == null) {
continue;
}

result.put(workParameter.getKey(), workParameter.getAsJsonSchema());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public WorkReport handlePostWorkFlowExecution() {
workFlowCheckerDefinition.getCheckWorkFlow().getId(), mainWorkFlowExecution))
.toList();

for (WorkFlowExecution checkerExecution : checkerExecutions)
for (WorkFlowExecution checkerExecution : checkerExecutions) {
if (checkerExecution != null && checkerExecution.getStatus() == WorkStatus.REJECTED) {
log.info("fail workflow: {} because it has declined checker(s)", workFlowDefinition.getName());
workFlowExecution.setStatus(WorkStatus.FAILED);
Expand All @@ -88,6 +88,7 @@ else if (checkerExecution == null || checkerExecution.getStatus() == WorkStatus.
workFlowExecution.setStatus(WorkStatus.IN_PROGRESS);
report = new DefaultWorkReport(WorkStatus.IN_PROGRESS, workContext);
}
}

workFlowService.updateWorkFlow(workFlowExecution);
return report;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,12 @@ private void startOrStopWorkFlowCheckerOnSchedule(WorkFlow workFlow,
* restart main workflow execution with same execution Id when there is no other
* active checkers
*/
if (workFlowService.findRunningChecker(mainWorkFlowExecution).isEmpty())
if (workFlowService.findRunningChecker(mainWorkFlowExecution).isEmpty()) {
workFlowContinuationServiceImpl.continueWorkFlow(projectId, userId, mainWorkFlowName, workContext,
mainWorkFlowExecution.getId(),
Optional.ofNullable(mainWorkFlowExecution.getWorkFlowDefinition().getRollbackWorkFlowDefinition())
.map(WorkFlowDefinition::getName).orElse(null));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,9 @@ else if (WorkStatus.FAILED != workFlowTaskExecution.getStatus()) {
}
try {
report = (WorkReport) proceedingJoinPoint.proceed();
if (report == null || report.getStatus() == null)
if (report == null || report.getStatus() == null) {
throw new NullPointerException("task execution not returns status: " + workFlowTaskName);
}
}
catch (Throwable e) {
log.error("Workflow task execution {} has failed! error message: {}", workFlowTaskName, e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ public boolean stop(UUID projectId, UUID userId, WorkFlow workFlow) {
boolean stopped = hm.get(new ScheduledTaskKey(projectId, userId)).get(workFlow.getName()).cancel(false);
if (stopped) {
hm.get(new ScheduledTaskKey(projectId, userId)).remove(workFlow.getName());
if (hm.get(new ScheduledTaskKey(projectId, userId)).isEmpty())
if (hm.get(new ScheduledTaskKey(projectId, userId)).isEmpty()) {
hm.remove(new ScheduledTaskKey(projectId, userId));
}
}
return stopped;
}
Expand Down
Loading