Search in sources :

Example 1 with Translator

use of com.oxygenxml.git.translator.Translator in project oxygen-git-client-addon by oxygenxml.

the class RendererUtil method getChangeRenderingInfo.

/**
 * Get the rendering info (such as icon or tooltip text) for the given Git change type.
 *
 * @param changeType The Git change type.
 *
 * @return the rendering info.
 */
public static RenderingInfo getChangeRenderingInfo(GitChangeType changeType) {
    Translator translator = Translator.getInstance();
    RenderingInfo renderingInfo = null;
    if (GitChangeType.ADD == changeType || GitChangeType.UNTRACKED == changeType) {
        renderingInfo = new RenderingInfo(Icons.getIcon(Icons.GIT_ADD_ICON), translator.getTranslation(Tags.ADD_ICON_TOOLTIP));
    } else if (GitChangeType.MODIFIED == changeType || GitChangeType.CHANGED == changeType) {
        renderingInfo = new RenderingInfo(Icons.getIcon(Icons.GIT_MODIFIED_ICON), translator.getTranslation(Tags.MODIFIED_ICON_TOOLTIP));
    } else if (GitChangeType.MISSING == changeType || GitChangeType.REMOVED == changeType) {
        renderingInfo = new RenderingInfo(Icons.getIcon(Icons.GIT_DELETE_ICON), translator.getTranslation(Tags.DELETE_ICON_TOOLTIP));
    } else if (GitChangeType.RENAME == changeType) {
        renderingInfo = new RenderingInfo(Icons.getIcon(Icons.GIT_RENAME_ICON), translator.getTranslation(Tags.RENAMED_ICON_TOOLTIP));
    } else if (GitChangeType.CONFLICT == changeType) {
        renderingInfo = new RenderingInfo(Icons.getIcon(Icons.GIT_CONFLICT_ICON), translator.getTranslation(Tags.CONFLICT_ICON_TOOLTIP));
    } else if (GitChangeType.SUBMODULE == changeType) {
        renderingInfo = new RenderingInfo(Icons.getIcon(Icons.GIT_SUBMODULE_FILE_ICON), translator.getTranslation(Tags.SUBMODULE));
    }
    return renderingInfo;
}
Also used : Translator(com.oxygenxml.git.translator.Translator)

Example 2 with Translator

use of com.oxygenxml.git.translator.Translator in project oxygen-git-client-addon by oxygenxml.

the class RevertCommitAction method actionPerformed.

/**
 * Action performed.
 */
@Override
public void actionPerformed(ActionEvent e) {
    Translator translator = Translator.getInstance();
    int result = FileStatusDialog.showQuestionMessage(translator.getTranslation(Tags.REVERT_COMMIT), translator.getTranslation(Tags.REVERT_COMMIT_CONFIRMATION), translator.getTranslation(Tags.YES), translator.getTranslation(Tags.NO));
    if (result == OKCancelDialog.RESULT_OK) {
        GitOperationScheduler.getInstance().schedule(() -> {
            try {
                GitAccess.getInstance().revertCommit(commitCharacteristics.getCommitId());
            } catch (IOException | NoRepositorySelected | GitAPIException ex) {
                LOGGER.debug(ex.getMessage(), ex);
                PluginWorkspaceProvider.getPluginWorkspace().showErrorMessage(ex.getMessage(), ex);
            }
        });
    }
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) NoRepositorySelected(com.oxygenxml.git.service.NoRepositorySelected) Translator(com.oxygenxml.git.translator.Translator) IOException(java.io.IOException)

Example 3 with Translator

use of com.oxygenxml.git.translator.Translator in project oxygen-git-client-addon by oxygenxml.

the class DiffPresenterTest method testExistingFileDiff.

/**
 * Scenario 2:
 * - an existing file modified. Added into the index.
 * - the new file modified again.
 * To test:
 * - Diff in not-staged: compares the modified version with the index version
 * - Diff in staged: compares the index version with the remote one.
 *
 * @throws Exception If it fails.
 */
@Test
public void testExistingFileDiff() throws Exception {
    /**
     * The local repository.
     */
    String localTestRepository = "target/test-resources/local";
    /**
     * The remote repository.
     */
    String remoteTestRepository = "target/test-resources/remote";
    GitAccess gitAccess = GitAccess.getInstance();
    Repository remoteRepo = createRepository(remoteTestRepository);
    // Create the local repository.
    Repository localRepo = createRepository(localTestRepository);
    // Bind the local repository to the remote one.
    bindLocalToRemote(localRepo, remoteRepo);
    // Create a new file.
    File file = new File(localTestRepository + "/test.txt");
    file.createNewFile();
    // Modify the newly created file.
    setFileContent(file, "initial content");
    // Add it to the index.
    gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
    gitAccess.commit("First version.");
    // Change the file.
    setFileContent(file, "index content");
    // Add it to the index.
    gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
    // Change it again.
    setFileContent(file, "local content");
    FileStatus fileStatus = new FileStatus(GitChangeType.MODIFIED, "test.txt");
    GitControllerBase gitCtrl = Mockito.mock(GitControllerBase.class);
    // Mock the translator.
    Translator translator = Mockito.mock(Translator.class);
    Mockito.when(translator.getTranslation(Mockito.anyString())).then(new Answer<String>() {

        @Override
        public String answer(InvocationOnMock invocation) throws Throwable {
            return (String) invocation.getArguments()[0];
        }
    });
    // Diff the first WC local file.
    DiffPresenter.showDiff(fileStatus, gitCtrl);
    assertNotNull(leftDiff);
    assertNotNull(rightDiff);
    String localVersionURL = file.toURI().toURL().toString();
    assertEquals("The local file should be on the left side, but was: " + localVersionURL, localVersionURL, leftDiff.toString());
    String indexVersionURL = "git://" + VersionIdentifier.INDEX_OR_LAST_COMMIT + "/test.txt";
    assertEquals("The index version should be on the right, but was: " + rightDiff.toString(), indexVersionURL, rightDiff.toString());
    leftDiff = null;
    rightDiff = null;
    // Diff the index file.
    fileStatus = new FileStatus(GitChangeType.CHANGED, "test.txt");
    DiffPresenter.showDiff(fileStatus, gitCtrl);
    assertNotNull(leftDiff);
    assertNotNull(rightDiff);
    assertEquals("The index version should be on the left, but was: " + leftDiff.toString(), indexVersionURL, leftDiff.toString());
    String headVersionURL = "git://" + VersionIdentifier.LAST_COMMIT + "/test.txt";
    assertEquals("The head version should be on the right, but was: " + rightDiff.toString(), headVersionURL, rightDiff.toString());
    // Assert content.
    assertEquals("index content", TestUtil.read(new URL(indexVersionURL)));
}
Also used : GitControllerBase(com.oxygenxml.git.service.GitControllerBase) Repository(org.eclipse.jgit.lib.Repository) GitAccess(com.oxygenxml.git.service.GitAccess) FileStatus(com.oxygenxml.git.service.entities.FileStatus) Translator(com.oxygenxml.git.translator.Translator) InvocationOnMock(org.mockito.invocation.InvocationOnMock) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Example 4 with Translator

use of com.oxygenxml.git.translator.Translator in project oxygen-git-client-addon by oxygenxml.

the class DiffPresenterTest method testNewFileDiff.

/**
 * Scenario 1:
 * - a new file. Added into the index.
 * - modify the new.
 *
 * To test:
 * - Diff in not-staged: compares the modified version with the index version
 * - Diff in staged: compares the index version with nothing (no remote)
 *
 * @throws Exception If it fails.
 */
@Test
public void testNewFileDiff() throws Exception {
    String localTestRepository = "target/test-resources/local";
    String remoteTestRepository = "target/test-resources/remote";
    Repository remoteRepo = createRepository(remoteTestRepository);
    Repository localRepo = createRepository(localTestRepository);
    // Bind the local repository to the remote one.
    bindLocalToRemote(localRepo, remoteRepo);
    // Create a new file.
    File file = new File(localTestRepository + "/test.txt");
    file.createNewFile();
    // Add it to the index / Stage it.
    GitAccess.getInstance().add(new FileStatus(GitChangeType.ADD, "test.txt"));
    // Modify the newly created file.
    setFileContent(file, "content");
    FileStatus fileStatus = new FileStatus(GitChangeType.MODIFIED, "test.txt");
    GitControllerBase gitCtrl = Mockito.mock(GitControllerBase.class);
    // Mock the translator.
    Translator translator = Mockito.mock(Translator.class);
    Mockito.when(translator.getTranslation(Mockito.anyString())).then(new Answer<String>() {

        @Override
        public String answer(InvocationOnMock invocation) throws Throwable {
            return (String) invocation.getArguments()[0];
        }
    });
    // Diff the first WC local file.
    DiffPresenter.showDiff(fileStatus, gitCtrl);
    assertNotNull(leftDiff);
    assertNotNull(rightDiff);
    String localVersionURL = file.toURI().toURL().toString();
    assertEquals("The local file should be on the left side: " + localVersionURL, localVersionURL, leftDiff.toString());
    String indexVersionURL = "git://" + VersionIdentifier.INDEX_OR_LAST_COMMIT + "/test.txt";
    assertEquals("The index version should be on the right, but was: " + rightDiff.toString(), indexVersionURL, rightDiff.toString());
    leftDiff = null;
    rightDiff = null;
    // Diff the index file.
    fileStatus = new FileStatus(GitChangeType.ADD, "test.txt");
    DiffPresenter.showDiff(fileStatus, gitCtrl);
    // On the left we present the Index version.
    assertEquals("git://IndexOrLastCommit/test.txt", leftDiff.toString());
    // On the right we present the HEAD version.
    assertNull(rightDiff);
    assertNull(toOpen);
    // Assert content.
    assertEquals("", TestUtil.read(new URL(indexVersionURL)));
}
Also used : GitControllerBase(com.oxygenxml.git.service.GitControllerBase) Repository(org.eclipse.jgit.lib.Repository) FileStatus(com.oxygenxml.git.service.entities.FileStatus) Translator(com.oxygenxml.git.translator.Translator) InvocationOnMock(org.mockito.invocation.InvocationOnMock) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Aggregations

Translator (com.oxygenxml.git.translator.Translator)4 GitControllerBase (com.oxygenxml.git.service.GitControllerBase)2 FileStatus (com.oxygenxml.git.service.entities.FileStatus)2 File (java.io.File)2 URL (java.net.URL)2 Repository (org.eclipse.jgit.lib.Repository)2 Test (org.junit.Test)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 GitAccess (com.oxygenxml.git.service.GitAccess)1 NoRepositorySelected (com.oxygenxml.git.service.NoRepositorySelected)1 IOException (java.io.IOException)1 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)1