Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/maven/junit-junit-4.13.2
Browse files Browse the repository at this point in the history
  • Loading branch information
ThuF authored Jan 10, 2022
2 parents 60eb97f + 8ac991d commit dc4409c
Show file tree
Hide file tree
Showing 43 changed files with 492 additions and 159 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -641,10 +641,6 @@ public static final Connection getConnection(String databaseType, String datasou
}
Connection connection = dataSource.getConnection();

if(((WrappedDataSource) dataSource).getDatabaseName().equals(DATABASE_NAME_HDB)) {
connection.setClientInfo("APPLICATIONUSER", UserFacade.getName());
}

return connection;
}

Expand Down
8 changes: 7 additions & 1 deletion api/api-facade/api-git/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,15 @@
</dependency>
<dependency>
<groupId>org.eclipse.dirigible</groupId>
<artifactId>dirigible-core</artifactId>
<artifactId>dirigible-core-git</artifactId>
<version>7.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.eclipse.dirigible</groupId>
<artifactId>dirigible-commons-test</artifactId>
<version>7.0.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.dirigible</groupId>
<artifactId>dirigible-api-facade-platform</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import org.eclipse.dirigible.core.workspace.json.WorkspaceGitHelper;
import org.eclipse.dirigible.core.workspace.service.WorkspacesCoreService;
import org.eclipse.dirigible.repository.api.IRepository;
import org.eclipse.jgit.api.Status;
import org.eclipse.jgit.api.errors.*;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -39,26 +39,26 @@ public static void initRepository(String username, String email, String workspac
IWorkspace workspaceObject = workspacesCoreService.getWorkspace(workspaceName);
IProject projectObject = workspaceObject.getProject(projectName);
String user = UserFacade.getName();
File tempGitDirectory = GitFileUtils.getGitDirectory(user, workspaceName, repositoryName);
boolean isExistingGitRepository = tempGitDirectory != null;
File gitDirectory = GitFileUtils.getGitDirectoryByRepositoryName(workspaceName, repositoryName);
boolean isExistingGitRepository = gitDirectory != null;

if (!isExistingGitRepository) {
tempGitDirectory = GitFileUtils.createGitDirectory(user, workspaceName, repositoryName);
gitDirectory = GitFileUtils.createGitDirectory(user, workspaceName, repositoryName);
} else {
throw new RefAlreadyExistsException("Git repository already exists");
}
GitFileUtils.copyProjectToDirectory(projectObject, tempGitDirectory);
GitFileUtils.copyProjectToDirectory(projectObject, gitDirectory);

projectObject.delete();

File projectGitDirectory = new File(tempGitDirectory, projectObject.getName());
File projectGitDirectory = new File(gitDirectory, projectObject.getName());
GitFileUtils gitFileUtils = new GitFileUtils();

GitConnectorFactory.initRepository(tempGitDirectory.getCanonicalPath(), false);
GitConnectorFactory.initRepository(gitDirectory.getCanonicalPath(), false);
gitFileUtils.importProjectFromGitRepositoryToWorkspace(projectGitDirectory, projectObject.getPath());

//the code below is needed because otherwise getHistory method will throw an error in the git perspective
IGitConnector gitConnector = GitConnectorFactory.getConnector(tempGitDirectory.getCanonicalPath());
IGitConnector gitConnector = GitConnectorFactory.getConnector(gitDirectory.getCanonicalPath());
gitConnector.add(IGitConnector.GIT_ADD_ALL_FILE_PATTERN);
gitConnector.commit(commitMessage, username, email, true);
}
Expand All @@ -76,7 +76,8 @@ public static void commit(String username, String email, final String workspaceN
gitConnector.commit(commitMessage, username, email, add);
}

public static List<ProjectDescriptor> getGitRepositories(String user, String workspaceName) {
public static List<ProjectDescriptor> getGitRepositories(String workspaceName) {
String user = UserFacade.getName();
IWorkspace workspaceObject = workspacesCoreService.getWorkspace(workspaceName);
if (!workspaceObject.exists()) {
return null;
Expand Down Expand Up @@ -104,26 +105,24 @@ public static List<ProjectDescriptor> getGitRepositories(String user, String wor
return gitRepositories;
}

public static List<GitCommitInfo> getHistory(String user, String repositoryName, String workspaceName, String path) throws GitConnectorException {
public static List<GitCommitInfo> getHistory(String repositoryName, String workspaceName, String path) throws GitConnectorException {
try {
File gitDirectory = GitFileUtils.getGitDirectory(user, workspaceName, repositoryName);
IGitConnector gitConnector = GitConnectorFactory.getConnector(gitDirectory.getCanonicalPath());
List<GitCommitInfo> history = gitConnector.getHistory(path);
List<GitCommitInfo> history = getConnector(workspaceName, repositoryName).getHistory(path);
return history;
} catch (Exception e) {
throw new GitConnectorException(e);
}
}

public static void deleteRepository(String workspace, String repositoryName) throws GitConnectorException {
public static void deleteRepository(String workspaceName, String repositoryName) throws GitConnectorException {
try {

File gitRepository = GitFileUtils.getGitDirectoryByRepositoryName(workspace, repositoryName);
File gitRepository = GitFileUtils.getGitDirectoryByRepositoryName(workspaceName, repositoryName);
if (gitRepository == null) {
throw new RefNotFoundException("Repository not found");
}

IWorkspace workspaceApi = workspacesCoreService.getWorkspace(workspace);
IWorkspace workspaceApi = workspacesCoreService.getWorkspace(workspaceName);
IProject[] workspaceProjects = workspaceApi.getProjects().toArray(new IProject[0]);
for (IProject next : workspaceProjects) {
if (next.exists()) {
Expand All @@ -137,4 +136,72 @@ public static void deleteRepository(String workspace, String repositoryName) thr
}
}

public static IGitConnector cloneRepository(String workspaceName, String repositoryUri, String username, String password, String branch) throws IOException, GitAPIException {
String user = UserFacade.getName();
File gitDirectory = GitFileUtils.createGitDirectory(user, workspaceName, repositoryUri);
return GitConnectorFactory.cloneRepository(gitDirectory.getCanonicalPath(), repositoryUri, username, password, branch);
}

public static void pull(String workspaceName, String repositoryName, String username, String password) throws GitAPIException, IOException, GitConnectorException {
getConnector(workspaceName, repositoryName).pull(username, password);
}

public static void push(String workspaceName, String repositoryName, String username, String password) throws GitAPIException, IOException, GitConnectorException {
getConnector(workspaceName, repositoryName).push(username, password);
}

public static void checkout(String workspaceName, String repositoryName, String branchName) throws GitAPIException, IOException, GitConnectorException {
getConnector(workspaceName, repositoryName).checkout(branchName);
}

public static void createBranch(String workspaceName, String repositoryName, String branchName, String startingPoint) throws GitAPIException, IOException, GitConnectorException {
getConnector(workspaceName, repositoryName).createBranch(branchName, startingPoint);
}

public static void hardReset(String workspaceName, String repositoryName) throws GitAPIException, IOException, GitConnectorException {
getConnector(workspaceName, repositoryName).hardReset();
}

public static void rebase(String workspaceName, String repositoryName, String branchName) throws GitAPIException, IOException, GitConnectorException {
getConnector(workspaceName, repositoryName).rebase(branchName);
}

public static Status status(String workspaceName, String repositoryName) throws GitAPIException, IOException, GitConnectorException {
return getConnector(workspaceName, repositoryName).status();
}

public static String getBranch(String workspaceName, String repositoryName) throws GitAPIException, IOException, GitConnectorException {
return getConnector(workspaceName, repositoryName).getBranch();
}

public static List<GitBranch> getLocalBranches(String workspaceName, String repositoryName) throws GitAPIException, IOException, GitConnectorException {
return getConnector(workspaceName, repositoryName).getLocalBranches();
}

public static List<GitBranch> getRemoteBranches(String workspaceName, String repositoryName) throws GitAPIException, IOException, GitConnectorException {
return getConnector(workspaceName, repositoryName).getRemoteBranches();
}

public static List<GitChangedFile> getUnstagedChanges(String workspaceName, String repositoryName) throws GitAPIException, IOException, GitConnectorException {
return getConnector(workspaceName, repositoryName).getUnstagedChanges();
}

public static List<GitChangedFile> getStagedChanges(String workspaceName, String repositoryName) throws GitAPIException, IOException, GitConnectorException {
return getConnector(workspaceName, repositoryName).getStagedChanges();
}

public static String getFileContent(String workspaceName, String repositoryName, String filePath, String revStr) throws GitAPIException, IOException, GitConnectorException {
return getConnector(workspaceName, repositoryName).getFileContent(filePath, revStr);
}

private static IGitConnector getConnector(String workspaceName, String repositoryName) throws GitConnectorException {
try {
String user = UserFacade.getName();
File gitDirectory = GitFileUtils.getGitDirectory(user, workspaceName, repositoryName);
IGitConnector gitConnector = GitConnectorFactory.getConnector(gitDirectory.getCanonicalPath());
return gitConnector;
} catch (IOException e) {
throw new GitConnectorException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ public void testInitRepositoryAndCommit() throws GitAPIException, GitConnectorEx
IProject project = workspace.createProject(projectName);
project.createFile("www/oldFile", "str".getBytes(StandardCharsets.UTF_8));
GitFacade.initRepository(user, email, workspaceName, projectName, repository, "Initial commit");
List<ProjectDescriptor> repos = GitFacade.getGitRepositories(user, workspaceName);
List<ProjectDescriptor> repos = GitFacade.getGitRepositories(workspaceName);
assertTrue(repos.size() == 1);

project.createFile("www/newFile", "str".getBytes(StandardCharsets.UTF_8));
String message = "Second commit";
GitFacade.commit(username, email, workspaceName, repository, message, true);
List<GitCommitInfo> history = GitFacade.getHistory(user, repository, workspaceName, projectName);
List<GitCommitInfo> history = GitFacade.getHistory(repository, workspaceName, projectName);
assertTrue(history.size() == 2);
assertTrue(history.get(0).getMessage().equals(message));
GitFacade.deleteRepository(workspaceName, repository);
Expand Down
10 changes: 10 additions & 0 deletions api/api-facade/api-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@
<artifactId>dirigible-api-facade-spark</artifactId>
<version>7.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.eclipse.dirigible</groupId>
<artifactId>dirigible-api-facade-git</artifactId>
<version>7.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.eclipse.dirigible</groupId>
<artifactId>dirigible-ext-spark</artifactId>
Expand Down Expand Up @@ -197,6 +202,11 @@
<artifactId>dirigible-api-javascript-platform</artifactId>
<version>7.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.eclipse.dirigible</groupId>
<artifactId>dirigible-api-javascript-git</artifactId>
<version>7.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.eclipse.dirigible</groupId>
<artifactId>dirigible-ext-redis</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ private void registerModulesUtilsV4() {
TEST_MODULES.add("utils/v4/url/escapePath.js");
TEST_MODULES.add("utils/v4/url/escapeForm.js");
TEST_MODULES.add("utils/v4/qrcode/qrCode.js");
TEST_MODULES.add("git/v4/client/local.js");
}

protected void registerModulesV3() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright (c) 2021 SAP SE or an SAP affiliate company and Eclipse Dirigible contributors
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* SPDX-FileCopyrightText: 2021 SAP SE or an SAP affiliate company and Eclipse Dirigible contributors
* SPDX-License-Identifier: EPL-2.0
*/
const git = require('git/v4/client');
const assertTrue = require('utils/v4/assert').assertTrue;
const workspaceManager = require("platform/v4/workspace");

const user = 'dirigible';
const email = '[email protected]';
const workspaceName = 'test-workspace';
const projectName = 'test-project';
const repositoryName = projectName;

const workspace = workspaceManager.createWorkspace(workspaceName);
project = workspace.createProject(projectName);
let firstFile = project.createFile("firstFile.js");
firstFile.setText('first file content');

git.initRepository(user, email, workspaceName, projectName, repositoryName, 'initial commit');

let repos = git.getGitRepositories(workspaceName);
console.log("Repository name " + repos[0].getName())
assertTrue(repos[0].getName() === repositoryName);

let secondFile = project.createFile("secondFile.js");
secondFile.setText('second file content');
console.log("Getting staged changes...");
let staged = git.getStagedChanges(workspaceName, repositoryName);
console.log("Staged changes count: " + staged.size())
assertTrue(staged.size() === 0);

console.log("Getting unstaged changes...");
let unstaged = git.getUnstagedChanges(workspaceName, repositoryName);
console.log("Unstaged changes count: " + unstaged.size())
assertTrue(unstaged.size() === 1);

git.commit(user, email, workspaceName, repositoryName, "second file added", true);
const his = git.getHistory(repositoryName, workspaceName, projectName);

console.log("History size: " + his.size())
assertTrue(his.size() === 2);

let branches = git.getLocalBranches(workspaceName, repositoryName);
console.log("Local branches size: " + branches.size());
assertTrue(branches.size() === 1);

git.createBranch(workspaceName, repositoryName, 'new-branch', 'master');
branches = git.getLocalBranches(workspaceName, repositoryName);
console.log("New local branches size: " + branches.size());
assertTrue(branches.size() === 2);

const status = git.status(workspaceName, repositoryName);
console.log("Status is clean: " + status.isClean());
assertTrue(status.isClean() === true);

console.log("Deleting test repo...");
git.deleteRepository(workspaceName, repositoryName);
console.log("Repositories size at the end: " + git.getGitRepositories(workspaceName).size());
assertTrue(git.getGitRepositories(workspaceName).size() === 0);
25 changes: 25 additions & 0 deletions api/api-javascript/api-git/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.eclipse.dirigible</groupId>
<artifactId>dirigible-api-javascript-parent</artifactId>
<version>7.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<name>API - JavaScript - HTTP</name>
<artifactId>dirigible-api-javascript-git</artifactId>
<description>Git Module</description>
<packaging>jar</packaging>

<properties>
<profile.content.phase>generate-sources</profile.content.phase>
<content.repository.name>api-git</content.repository.name>
<content.project.name>git</content.project.name>

<license.header.location>../../../licensing-header.txt</license.header.location>
</properties>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* SPDX-FileCopyrightText: 2021 SAP SE or an SAP affiliate company and Eclipse Dirigible contributors
* SPDX-License-Identifier: EPL-2.0
*/
var git = require('utils/v4/git');
var git = require('git/v4/client');
for(var propertyName in git) {
exports[propertyName] = git[propertyName];
}
Loading

0 comments on commit dc4409c

Please sign in to comment.