Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
849775c
SQLite User Table
Mar 2, 2023
147122f
Working perfectly when a user value is not null.
Mar 5, 2023
5cd5121
Refactoring code 1
Mar 6, 2023
1e2818a
Can create database and user table on new system.
Mar 6, 2023
8c78a43
Automated process of transforming user file to user table if does not…
Mar 7, 2023
e336f69
Setting db path variable
Mar 7, 2023
65d61cd
Fix db path
Mar 7, 2023
14c61f3
Feedback by Basit implemented except for UserFile class
syedgulahmed Mar 7, 2023
56d0525
Resolving conflict in CodeSyncLogger file
syedgulahmed Mar 13, 2023
beddd92
Undo changes for resolving conflict
syedgulahmed Mar 9, 2023
9c73fa1
Removed line missed earlier!
syedgulahmed Mar 13, 2023
abcbbb2
Resolving sonarCloud issues
syedgulahmed Mar 15, 2023
11a0985
Adding test cases!
syedgulahmed Mar 20, 2023
8d49683
Refactoring and creating Queries class and Helper class for test cons…
syedgulahmed Mar 21, 2023
08a47fc
Created all the required test cases for new classes I had created.
syedgulahmed Mar 27, 2023
7c5da99
Further refactoring and implmeneted Basit's feedback.
syedgulahmed Mar 30, 2023
8574107
Build git action.
syedgulahmed Apr 3, 2023
50c66b7
Jacoco Coverage
syedgulahmed Apr 3, 2023
8f06555
Jacoco Coverage 2
syedgulahmed Apr 3, 2023
27aebdf
Trying JaCoCo
syedgulahmed Apr 4, 2023
a48599a
JaCoCo 2
syedgulahmed Apr 4, 2023
45eb1ce
Reverting changes.
syedgulahmed Apr 4, 2023
1475e53
Getting working directory.
syedgulahmed Apr 4, 2023
c61327c
Renaming taks.
syedgulahmed Apr 4, 2023
7f09727
Adding path and action
syedgulahmed Apr 4, 2023
9b35754
Rename action.
syedgulahmed Apr 4, 2023
e7657f1
Using Coberture.
syedgulahmed Apr 4, 2023
1ecbada
Trying gradle test.
syedgulahmed Apr 4, 2023
66ccaa8
Trying gradle test 2
syedgulahmed Apr 4, 2023
fd5b213
Using run instead of use
syedgulahmed Apr 4, 2023
8375042
Using JaCoCo with gradle.
syedgulahmed Apr 4, 2023
461e495
Reading coverage in console.
syedgulahmed Apr 4, 2023
500b228
Publishing Coverage.
syedgulahmed Apr 4, 2023
d979cdb
Working with Grep
syedgulahmed Apr 4, 2023
ce53732
Printing coverage % using grep
syedgulahmed Apr 4, 2023
1d05570
Formated text.
syedgulahmed Apr 4, 2023
d19ff23
Trying to get report in CSV
syedgulahmed Apr 4, 2023
f6ea5c6
Report in comment.
syedgulahmed Apr 4, 2023
4a965a8
Version splash
syedgulahmed Apr 4, 2023
3105715
Without version
syedgulahmed Apr 4, 2023
391933c
Old version
syedgulahmed Apr 4, 2023
b45cf30
Setting path
syedgulahmed Apr 4, 2023
1fb6805
Changing message to msg
syedgulahmed Apr 5, 2023
a9b0d14
Hello, World!
syedgulahmed Apr 5, 2023
e448446
Echo CSV file
syedgulahmed Apr 5, 2023
3eeca9b
Printing CSV file
syedgulahmed Apr 5, 2023
452e017
Printing values in comment
syedgulahmed Apr 5, 2023
b79f5bc
Fix indentation
syedgulahmed Apr 5, 2023
dec627f
Fix Version Issue
syedgulahmed Apr 5, 2023
3dc8eaa
Valid msg argument
syedgulahmed Apr 5, 2023
5c5407d
Using different action
syedgulahmed Apr 5, 2023
b9b1076
Removed env
syedgulahmed Apr 5, 2023
5e96acc
Rigid
syedgulahmed Apr 5, 2023
9042e81
Syntax fixed
syedgulahmed Apr 5, 2023
f019389
Simple Hellow World
syedgulahmed Apr 5, 2023
c109f03
Modified curl
syedgulahmed Apr 5, 2023
23e9a90
Fixed cred issue
syedgulahmed Apr 5, 2023
5c744a9
Github Token
syedgulahmed Apr 5, 2023
b16e6eb
Testing GitToken
syedgulahmed Apr 5, 2023
6149f9e
Peter action
syedgulahmed Apr 5, 2023
7c46a61
Posting comment.
syedgulahmed Apr 5, 2023
721467b
Retrying
syedgulahmed Apr 5, 2023
cf121f2
Add comment.
syedgulahmed Apr 5, 2023
aec7f3b
Add comment...
syedgulahmed Apr 5, 2023
0c703d6
Restoring
syedgulahmed Apr 5, 2023
b53214a
Setting code coverage in sonarcloud 1
syedgulahmed Apr 18, 2023
a9387fd
SonarCloud Token Issue Fixed
syedgulahmed Apr 18, 2023
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
38 changes: 38 additions & 0 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: First Git Actions

on: [push]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'

- name: Build and run tests with JaCoCo
run: ./gradlew clean build jacocoTestReport --stacktrace

- name: SonarCloud Scan
uses: sonarsource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}


# - name: Upload test reports
# uses: actions/upload-artifact@v2
# with:
# name: test-reports
# path: build/test-results/test
#
# - name: Upload code coverage report
# uses: actions/upload-artifact@v2
# with:
# name: coverage-report
# path: build/reports/coverage/report.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<ExternalSystemSettings>
<option name="env">
<map>
<entry key="ORG_GRADLE_PROJECT_intellijPublishToken" value="perm:{add-key-here}" />
<entry key="ORG_GRADLE_PROJECT_intellijPublishToken" value="" />
</map>
</option>
<option name="executionName" />
Expand Down
11 changes: 11 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
id 'java'
id 'org.jetbrains.intellij' version '0.6.5'
id("org.jetbrains.kotlin.jvm") version "1.8.0"
id 'jacoco'
}

group 'com.codesync'
Expand Down Expand Up @@ -33,6 +34,13 @@ patchPluginXml {
untilBuild = '231.*'
}

jacocoTestReport {
reports {
csv.enabled true
csv.destination file("$buildDir/reports/coverage/report.csv")
}
}

dependencies {
implementation files('libs/diff_match_patch.jar')
implementation files('libs/gitignore-file-filter-1.0.0.jar')
Expand All @@ -58,6 +66,9 @@ dependencies {
exclude group: 'org.slf4j'
}

// https://mvnrepository.com/artifact/org.xerial/sqlite-jdbc
implementation group: 'org.xerial', name: 'sqlite-jdbc', version: '3.40.0.0'

implementation 'org.eclipse.jetty:jetty-server:9.4.3.v20170317'
implementation 'org.eclipse.jetty:jetty-servlet:9.4.3.v20170317'

Expand Down
Empty file added src/main/.syncignore
Empty file.
29 changes: 11 additions & 18 deletions src/main/java/org/intellij/sdk/codesync/CodeSyncLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import software.amazon.awssdk.services.cloudwatchlogs.model.*;

import org.intellij.sdk.codesync.exceptions.InvalidYmlFileError;
import org.intellij.sdk.codesync.files.UserFile;
import org.intellij.sdk.codesync.models.UserAccount;
import static org.intellij.sdk.codesync.Constants.*;

import java.io.FileNotFoundException;
Expand Down Expand Up @@ -114,26 +114,19 @@ private static void logEvent(String message, String type) {
logEvent(message, null, type);
}

private static void logEvent(String message, String userEmail, String type) {
UserFile.User user = null;
UserFile userFile = null;
public static void logEvent(String message, String userEmail, String type) {
UserAccount userAccount = new UserAccount();
logConsoleMessage(message, type);

try {
userFile = new UserFile(USER_FILE_PATH);
} catch (FileNotFoundException | InvalidYmlFileError e) {
e.printStackTrace();
}

if (userEmail != null && userFile != null) {
user = userFile.getUser(userEmail);
} else if (userFile != null) {
user = userFile.getActiveUser();
if (userEmail != null && userAccount != null) {
userAccount = userAccount.getUser(userEmail);
} else if (userAccount != null) {
userAccount = userAccount.getActiveUser();
}

String streamName, accessKey, secretKey;

if (user == null || user.getAccessKey() == null || user.getSecretKey() == null || user.getUserEmail() == null) {
if (userAccount == null || userAccount.getAccessKey() == null || userAccount.getSecretKey() == null || userAccount.getUserEmail() == null) {
//Log with the plugin user.
streamName = PLUGIN_USER_LOG_STREAM;
if (PLUGIN_USER_ACCESS_KEY == null || PLUGIN_USER_SECRET_KEY == null) {
Expand All @@ -145,9 +138,9 @@ private static void logEvent(String message, String userEmail, String type) {
secretKey = PLUGIN_USER_SECRET_KEY;
}
} else {
streamName = user.getUserEmail();
accessKey = user.getAccessKey();
secretKey = user.getSecretKey();
streamName = userAccount.getUserEmail();
accessKey = userAccount.getAccessKey();
secretKey = userAccount.getSecretKey();
}

try {
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/intellij/sdk/codesync/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ private Constants() {
public static final String DELETED_REPO = Paths.get(CODESYNC_ROOT, ".deleted").toString();
public static final String SHADOW_REPO = Paths.get(CODESYNC_ROOT, ".shadow").toString();
public static final String CONFIG_PATH = Paths.get(CODESYNC_ROOT, "config.yml").toString();

//TODO: User file will be removed
public static final String USER_FILE_PATH = Paths.get(CODESYNC_ROOT, "user.yml").toString();
public static final String ALERTS_FILE_PATH = Paths.get(CODESYNC_ROOT, "alerts.yml").toString();
public static final String SEQUENCE_TOKEN_FILE_PATH = Paths.get(CODESYNC_ROOT, "sequence_token.yml").toString();
Expand All @@ -45,6 +47,10 @@ private Constants() {
public static final Integer DELAY_BETWEEN_ACTIVITY_ALERT_TASKS = 10 * 60 * 1000; // 10 minutes wait.
public static final Integer DELAY_BETWEEN_BUFFER_TASKS_IN_SECONDS = 5;

//Database queries and strings
public static final String DATABASE_PATH = Paths.get(CODESYNC_ROOT, "codesyncdb.db").toString();
public static final String CONNECTION_STRING = "jdbc:sqlite:" + DATABASE_PATH;

public static final String DEFAULT_TIMEZONE = ZoneId.systemDefault().getId();
public static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS z";
public static final String DATE_FORMAT = "yyyy-MM-dd";
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/intellij/sdk/codesync/HandleBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.intellij.sdk.codesync.clients.CodeSyncWebSocketClient;
import org.intellij.sdk.codesync.exceptions.*;
import org.intellij.sdk.codesync.files.*;
import org.intellij.sdk.codesync.locks.CodeSyncLock;
import org.intellij.sdk.codesync.models.UserAccount;
import org.intellij.sdk.codesync.repoManagers.DeletedRepoManager;
import org.intellij.sdk.codesync.repoManagers.OriginalsRepoManager;
import org.intellij.sdk.codesync.repoManagers.ShadowRepoManager;
Expand Down Expand Up @@ -208,7 +208,7 @@ public static void handleBuffer(Project project) {
}

ConfigRepo configRepo = configFile.getRepo(diffFile.repoPath);
String accessToken = UserFile.getAccessToken(configRepo.email);
String accessToken = UserAccount.getAccessToken(configRepo.email);

if (accessToken == null) {
CodeSyncLogger.critical(String.format(
Expand Down Expand Up @@ -355,7 +355,7 @@ public static void handleBuffer(Project project) {
// Send Diffs in a single request.

ConfigRepo configRepo = configFile.getRepo(currentRepo);
String accessToken = UserFile.getAccessToken(configRepo.email);
String accessToken = UserAccount.getAccessToken(configRepo.email);
if (accessToken == null) {
CodeSyncLogger.warning(String.format(
"Access token for user '%s' not present so skipping diffs for repo '%s'.",
Expand Down
22 changes: 6 additions & 16 deletions src/main/java/org/intellij/sdk/codesync/PopulateBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
import org.intellij.sdk.codesync.codeSyncSetup.CodeSyncSetup;
import org.intellij.sdk.codesync.exceptions.FileInfoError;
import org.intellij.sdk.codesync.exceptions.InvalidConfigFileError;
import org.intellij.sdk.codesync.exceptions.InvalidYmlFileError;
import org.intellij.sdk.codesync.factories.DiffFactory;
import org.intellij.sdk.codesync.files.ConfigFile;
import org.intellij.sdk.codesync.files.ConfigRepo;
import org.intellij.sdk.codesync.files.ConfigRepoBranch;
import org.intellij.sdk.codesync.files.UserFile;
import org.intellij.sdk.codesync.models.UserAccount;
import org.intellij.sdk.codesync.repoManagers.DeletedRepoManager;
import org.intellij.sdk.codesync.repoManagers.OriginalsRepoManager;
import org.intellij.sdk.codesync.repoManagers.ShadowRepoManager;
Expand All @@ -20,7 +19,6 @@
import static org.intellij.sdk.codesync.Constants.*;

import java.io.File;
import java.io.FileNotFoundException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
Expand Down Expand Up @@ -167,16 +165,8 @@ public static Map<String, String> detectBranchChange() {
return reposToUpdate;
}
Map<String, ConfigRepo> configRepoMap = configFile.getRepos();
UserFile userFile;

try {
userFile = new UserFile(USER_FILE_PATH);
} catch (FileNotFoundException | InvalidYmlFileError error) {
CodeSyncLogger.critical(String.format(
"[POPULATE_BUFFER] User file error, %s.\n", error.getMessage()
));
return reposToUpdate;
}
UserAccount userAccount;
userAccount = new UserAccount();

for (Map.Entry<String, ConfigRepo> configRepoEntry: configRepoMap.entrySet()) {
String repoPath = configRepoEntry.getKey();
Expand All @@ -193,13 +183,13 @@ public static Map<String, String> detectBranchChange() {
continue;
}

UserFile.User user = userFile.getUser(configRepo.email);
if (user == null) {
userAccount = userAccount.getUser(configRepo.email);
if (userAccount == null) {
// Could not find the user with this email in user.yml file.
continue;
}

if (user.getAccessToken() == null) {
if (userAccount.getAccessToken() == null) {
CodeSyncLogger.error(String.format("Access token not found for repo: %s, %s`.", repoPath, configRepo.email));
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.commons.codec.digest.DigestUtils;
import org.intellij.sdk.codesync.alerts.ActivityAlerts;
import org.intellij.sdk.codesync.codeSyncSetup.CodeSyncSetup;
import org.intellij.sdk.codesync.database.Database;
import org.intellij.sdk.codesync.exceptions.common.FileNotInModuleError;
import org.intellij.sdk.codesync.locks.CodeSyncLock;
import org.intellij.sdk.codesync.state.StateUtils;
Expand Down Expand Up @@ -191,6 +192,7 @@ public void projectClosed(@NotNull Project project) {
}

public void disposeProjectListeners(Project project) {
Database.disconnect();
// Release all the locks acquired by this project.
CodeSyncLock.releaseAllLocks(LockFileType.PROJECT_LOCK, project.getName());
CodeSyncLock.releaseAllLocks(LockFileType.HANDLE_BUFFER_LOCK, project.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.intellij.sdk.codesync.Constants;
import org.intellij.sdk.codesync.clients.CodeSyncClient;
import org.intellij.sdk.codesync.files.AlertsFile;
import org.intellij.sdk.codesync.files.UserFile;
import org.intellij.sdk.codesync.models.UserAccount;
import org.intellij.sdk.codesync.locks.CodeSyncLock;
import org.intellij.sdk.codesync.ui.dialogs.ActivityAlertDialog;
import org.intellij.sdk.codesync.utils.CommonUtils;
Expand Down Expand Up @@ -86,8 +86,8 @@ public static void showActivityAlert(Project project) {
}
CodeSyncLogger.debug("[CODESYNC_DAEMON] [ACTIVITY_ALERT] Activity alert lock acquired.");

String accessToken = UserFile.getAccessToken();
String email = UserFile.getEmail();
String accessToken = UserAccount.getAccessTokenByEmail();
String email = UserAccount.getEmail();

if (accessToken == null) {
ActivityAlerts.remindLater(5);
Expand Down
47 changes: 5 additions & 42 deletions src/main/java/org/intellij/sdk/codesync/auth/AuthAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,11 @@
import org.intellij.sdk.codesync.NotificationManager;
import org.intellij.sdk.codesync.commands.ClearReposToIgnoreCache;
import org.intellij.sdk.codesync.commands.ReloadStateCommand;
import org.intellij.sdk.codesync.exceptions.InvalidYmlFileError;
import org.intellij.sdk.codesync.files.UserFile;
import org.intellij.sdk.codesync.models.UserAccount;
import org.intellij.sdk.codesync.state.PluginState;
import org.intellij.sdk.codesync.state.StateUtils;
import org.jetbrains.annotations.NotNull;

import java.io.FileNotFoundException;

import static org.intellij.sdk.codesync.Constants.*;


public class AuthAction extends AnAction {
@Override
public void update(@NotNull AnActionEvent e) {
Expand Down Expand Up @@ -59,44 +53,13 @@ public void actionPerformed(@NotNull AnActionEvent e) {
server = CodeSyncAuthServer.getInstance();
String targetURL = server.getAuthorizationUrl();
if (pluginState.isAuthenticated) {
UserFile userFile;
try {
userFile = new UserFile(USER_FILE_PATH);
} catch (FileNotFoundException error) {
NotificationManager.notifyError(
"An error occurred trying to logout the user, please tyr again later.", project
);
CodeSyncLogger.error(
String.format("[INTELLIJ_AUTH_ERROR]: auth file not found. Error: %s", error.getMessage())
);
return;
} catch (InvalidYmlFileError error) {
error.printStackTrace();
NotificationManager.notifyError(
"An error occurred trying to logout the user, please tyr again later.", project
);
CodeSyncLogger.critical(
String.format("[INTELLIJ_AUTH_ERROR]: Invalid auth file. Error: %s", error.getMessage()),
pluginState.userEmail
);
// Could not read user file.
return;
}
userFile.makeAllUsersInActive();
UserAccount userAccount = new UserAccount();

// Clear any cache that depends on user authentication status.
new ClearReposToIgnoreCache().execute();
try {
userFile.writeYml();
} catch (FileNotFoundException | InvalidYmlFileError error) {
NotificationManager.notifyError(
"An error occurred trying to logout the user, please tyr again later.", project
);
CodeSyncLogger.error(
String.format("[INTELLIJ_AUTH_ERROR]: Could write to auth file. Error: %s", error.getMessage())
);
return;
}

userAccount.makeAllUsersInActive();

// Reload the state now.
StateUtils.reloadState(project);

Expand Down
Loading