Skip to content

Commit

Permalink
Merge pull request #411 from adessoAG/teams-frontend-roles
Browse files Browse the repository at this point in the history
Proper handling of roles in the UI and many performance improvements.
  • Loading branch information
maximAtanasov authored Oct 9, 2020
2 parents 4dad941 + cd884e3 commit d666578
Show file tree
Hide file tree
Showing 451 changed files with 3,910 additions and 3,211 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM openjdk:11.0.8-jre-buster
ARG JAR_FILE=coderadar-app/build/**/*.jar
COPY ${JAR_FILE} coderadar-app-0.5.0.local.jar
ENTRYPOINT ["java","-jar","/coderadar-app-0.5.0.local.jar"]
COPY ${JAR_FILE} coderadar-app-1.0.0.local.jar
ENTRYPOINT ["java","-jar","/coderadar-app-1.0.0.local.jar"]
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ apply plugin: "java"
apply plugin: "org.sonarqube"

ext {
majorVersion = '0'
minorVersion = '5'
majorVersion = '1'
minorVersion = '0'
patchVersion = '0'
baseVersion = "${majorVersion}.${minorVersion}.${patchVersion}"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.stereotype.Controller;
Expand All @@ -18,15 +19,23 @@
@EntityScan(basePackages = "io.reflectoring.coderadar")
@SpringBootApplication(scanBasePackages = "io.reflectoring.coderadar")
@Controller
public class CoderadarApplication {
public class CoderadarApplication implements ErrorController {

public static void main(String[] args) {
Locale.setDefault(Locale.US);
SpringApplication.run(CoderadarApplication.class, args);
}

@GetMapping(value = "/**/{path:[^.]*}")
public String redirect() {
private static final String ERROR = "/error";

/** @return forwards to index.html (angular app) */
@GetMapping(value = ERROR)
public String error() {
return "forward:/index.html";
}

@Override
public String getErrorPath() {
return ERROR;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ coderadar.authentication.accessToken.durationInMinutes=15
coderadar.authentication.refreshToken.durationInMinutes=86400
coderadar.authentication.enabled=true
coderadar.cors.enabled=true
coderadar.gitPasswordsEncryptionKey=test-key

logging.level.io.reflectoring.coderadar=DEBUG
logging.level.org.reflections=ERROR
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.reflectoring.coderadar;

import io.reflectoring.coderadar.useradministration.service.security.PasswordUtil;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -30,6 +31,8 @@ public class CoderadarConfigurationProperties {

@NotNull private Integer scanIntervalInSeconds = 30;

@NotNull private String gitPasswordsEncryptionKey;

@NotNull private Locale dateLocale = Locale.ENGLISH;

private Authentication authentication = new Authentication();
Expand Down Expand Up @@ -69,6 +72,11 @@ public void validateWorkdirIsWritable() {
}
}

@PostConstruct
public void setGitPasswordEncryptionKey() {
PasswordUtil.setKey(gitPasswordsEncryptionKey);
}

@Data
public static class Authentication {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.reflectoring.coderadar;

public class CoderadarConstants {

private CoderadarConstants() {}

public static final int COMMIT_HASH_LENGTH = 16;

public static final String ZERO_HASH = "0000000000000000";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.reflectoring.coderadar;

import io.reflectoring.coderadar.analyzer.service.AnalyzingService;
import io.reflectoring.coderadar.projectadministration.service.ProcessProjectService;
import io.reflectoring.coderadar.projectadministration.service.project.ScanProjectScheduler;
import io.reflectoring.coderadar.useradministration.service.security.TokenService;
import lombok.RequiredArgsConstructor;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class ShutdownService implements ShutdownUseCase {

private final ProcessProjectService processProjectService;
private final ScanProjectScheduler scanProjectScheduler;
private final AnalyzingService analyzingService;
private final ConfigurableApplicationContext applicationContext;
private final TokenService tokenService;

@Override
public void shutdown() throws InterruptedException {
tokenService.setShuttingDown(true);
analyzingService.onShutdown();
scanProjectScheduler.onShutdown();
processProjectService.onShutdown();
applicationContext.close();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package io.reflectoring.coderadar;

public interface ShutdownUseCase {
void shutdown() throws InterruptedException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.reflectoring.coderadar;

public class ValidationUtils {

private ValidationUtils() {}

public static String validateAndTrimCommitHash(String commitHash) {
if (commitHash.length() < CoderadarConstants.COMMIT_HASH_LENGTH) {
throw new IllegalArgumentException(
String.format(
"The length of the commit hash must be at least %d",
CoderadarConstants.COMMIT_HASH_LENGTH));
}
return commitHash.substring(0, CoderadarConstants.COMMIT_HASH_LENGTH);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ public class AnalyzerConfiguration {
private String analyzerName;
private boolean enabled;

private AnalyzerConfigurationFile analyzerConfigurationFile;

public AnalyzerConfiguration(long id, String analyzerName, boolean enabled) {
this.id = id;
this.analyzerName = analyzerName;
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.reflectoring.coderadar.analyzer.domain;

import io.reflectoring.coderadar.plugin.api.Finding;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Data;
Expand All @@ -9,7 +10,7 @@
@AllArgsConstructor
public class MetricValue {
private final String name;
private final long value;
private final int value;
private final long commitId;
private final long fileId;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,41 +1,29 @@
package io.reflectoring.coderadar.analyzer.service;

import com.google.common.collect.Maps;
import io.reflectoring.coderadar.CoderadarConfigurationProperties;
import io.reflectoring.coderadar.analyzer.domain.Finding;
import io.reflectoring.coderadar.analyzer.domain.MetricValue;
import io.reflectoring.coderadar.analyzer.port.driver.AnalyzeCommitUseCase;
import io.reflectoring.coderadar.plugin.api.FileMetrics;
import io.reflectoring.coderadar.plugin.api.Metric;
import io.reflectoring.coderadar.plugin.api.SourceCodeFileAnalyzerPlugin;
import io.reflectoring.coderadar.projectadministration.domain.Commit;
import io.reflectoring.coderadar.projectadministration.domain.File;
import io.reflectoring.coderadar.projectadministration.domain.FileToCommitRelationship;
import io.reflectoring.coderadar.projectadministration.domain.Project;
import io.reflectoring.coderadar.vcs.UnableToGetCommitContentException;
import io.reflectoring.coderadar.vcs.port.driven.GetRawCommitContentPort;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.*;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/** Performs analysis on a commit. */
@Service
public class AnalyzeCommitService implements AnalyzeCommitUseCase {
@RequiredArgsConstructor
public class AnalyzeCommitService {

private final AnalyzeFileService analyzeFileService;
private final GetRawCommitContentPort getRawCommitContentPort;
private final CoderadarConfigurationProperties coderadarConfigurationProperties;

public AnalyzeCommitService(
AnalyzeFileService analyzeFileService,
GetRawCommitContentPort getRawCommitContentPort,
CoderadarConfigurationProperties coderadarConfigurationProperties) {
this.analyzeFileService = analyzeFileService;
this.getRawCommitContentPort = getRawCommitContentPort;
this.coderadarConfigurationProperties = coderadarConfigurationProperties;
}

/**
* Analyzes a single commit.
*
Expand All @@ -44,19 +32,13 @@ public AnalyzeCommitService(
* @param analyzers The analyzers to use.
* @return A list of metric values for the given commit.
*/
@Override
public List<MetricValue> analyzeCommit(
Commit commit, Project project, List<SourceCodeFileAnalyzerPlugin> analyzers) {
List<MetricValue> metricValues = new ArrayList<>();
List<File> files = new ArrayList<>(commit.getTouchedFiles().size());
for (FileToCommitRelationship ftr : commit.getTouchedFiles()) {
files.add(ftr.getFile());
}

analyzeBulk(commit.getHash(), files, analyzers, project)
analyzeBulk(commit.getHash(), commit.getChangedFiles(), analyzers, project)
.forEach(
(file, fileMetrics) ->
metricValues.addAll(getMetrics(fileMetrics, commit.getId(), file.getId())));
(fileId, fileMetrics) ->
metricValues.addAll(getMetrics(fileMetrics, commit.getId(), fileId)));
return metricValues;
}

Expand All @@ -69,12 +51,12 @@ public List<MetricValue> analyzeCommit(
* @param project The project the commit is in.
* @return A map of File and corresponding FileMetrics
*/
private HashMap<File, FileMetrics> analyzeBulk(
private Map<Long, FileMetrics> analyzeBulk(
String commitHash,
List<File> files,
List<SourceCodeFileAnalyzerPlugin> analyzers,
Project project) {
HashMap<File, FileMetrics> fileMetricsMap = new LinkedHashMap<>();
Map<Long, FileMetrics> fileMetricsMap = Maps.newLinkedHashMapWithExpectedSize(files.size());
try {
HashMap<File, byte[]> fileContents =
getRawCommitContentPort.getCommitContentBulkWithFiles(
Expand All @@ -84,9 +66,10 @@ private HashMap<File, FileMetrics> analyzeBulk(
files,
commitHash);
fileContents.forEach(
(key, value) ->
(file, content) ->
fileMetricsMap.put(
key, analyzeFileService.analyzeFile(analyzers, key.getPath(), value)));
file.getId(),
analyzeFileService.analyzeFile(analyzers, file.getPath(), content)));
} catch (UnableToGetCommitContentException e) {
e.printStackTrace();
}
Expand All @@ -102,21 +85,15 @@ private HashMap<File, FileMetrics> analyzeBulk(
* @return A list of MetricValues.
*/
private List<MetricValue> getMetrics(FileMetrics fileMetrics, Long commitId, Long fileId) {
List<MetricValue> metricValues = new ArrayList<>();
List<MetricValue> metricValues = new ArrayList<>(fileMetrics.getMetrics().size());
for (Metric metric : fileMetrics.getMetrics()) {
List<Finding> findings = new ArrayList<>();
for (io.reflectoring.coderadar.plugin.api.Finding finding : fileMetrics.getFindings(metric)) {
findings.add(
new Finding(
finding.getLineStart(),
finding.getLineEnd(),
finding.getCharStart(),
finding.getCharEnd(),
finding.getMessage()));
}
metricValues.add(
new MetricValue(
metric.getId(), fileMetrics.getMetricCount(metric), commitId, fileId, findings));
metric.getId(),
fileMetrics.getMetricCount(metric),
commitId,
fileId,
fileMetrics.getFindings(metric)));
}
return metricValues;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@Service
public class AnalyzeFileService {

private Logger logger = LoggerFactory.getLogger(AnalyzeFileService.class);
private static final Logger logger = LoggerFactory.getLogger(AnalyzeFileService.class);

/**
* Analyzes a single file. Lets all AnalyzerPlugins run over the given file to calculate their
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

@Service
public class AnalyzerPluginService {
private final Logger logger = LoggerFactory.getLogger(AnalyzerPluginService.class);
private static final Logger logger = LoggerFactory.getLogger(AnalyzerPluginService.class);

private final Map<String, Class<? extends SourceCodeFileAnalyzerPlugin>>
sourceCodeFileAnalyzerPlugins = new HashMap<>();
Expand Down
Loading

0 comments on commit d666578

Please sign in to comment.