Skip to content

Commit

Permalink
Merge pull request #1212 from omegat-org/topic/miurahr/test-integ/fix…
Browse files Browse the repository at this point in the history
…-error-no-gui-environment

chore: fix error on Integration Test
  • Loading branch information
miurahr authored Dec 16, 2024
2 parents 4028d6f + 4628ca7 commit 8bcd883
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 63 deletions.
15 changes: 7 additions & 8 deletions src/org/omegat/core/team2/impl/GITCredentialsProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

import org.eclipse.jgit.errors.UnsupportedCredentialItem;
Expand All @@ -49,7 +50,6 @@
import org.omegat.core.team2.gui.PassphraseDialog;
import org.omegat.core.team2.gui.UserPassDialog;
import org.omegat.core.team2.impl.TeamUtils.Credentials;
import org.omegat.gui.main.IMainWindow;
import org.omegat.util.Log;
import org.omegat.util.OStrings;
import org.omegat.util.gui.StaticUIUtils;
Expand Down Expand Up @@ -281,8 +281,7 @@ public boolean supports(CredentialItem... items) {
}

private void askYesNoGUI(CredentialItem item, String promptText, URIish uri, String promptedFingerprint) {
IMainWindow mw = Core.getMainWindow();
int choice = mw.showConfirmDialog(promptText, null, JOptionPane.YES_NO_OPTION,
int choice = Core.getMainWindow().showConfirmDialog(promptText, null, JOptionPane.YES_NO_OPTION,
JOptionPane.WARNING_MESSAGE);
if (choice == JOptionPane.YES_OPTION) {
((CredentialItem.YesNoType) item).setValue(true);
Expand Down Expand Up @@ -325,10 +324,10 @@ private void askYesNo(CredentialItem item, String promptText, URIish uri, String
*/
private Credentials askCredentialsGUI(URIish uri, Credentials credentials, boolean passwordOnly,
String msg) {
IMainWindow mw = Core.getMainWindow();
JFrame parent = Core.getMainWindow().getApplicationFrame();
if (passwordOnly) {
PassphraseDialog passphraseDialog = new PassphraseDialog(mw.getApplicationFrame());
passphraseDialog.setLocationRelativeTo(Core.getMainWindow().getApplicationFrame());
PassphraseDialog passphraseDialog = new PassphraseDialog(parent);
passphraseDialog.setLocationRelativeTo(parent);
if (uri.getScheme() == null) {
// asked passphrase
passphraseDialog.setTitleDesc(OStrings.getString(
Expand All @@ -347,8 +346,8 @@ private Credentials askCredentialsGUI(URIish uri, Credentials credentials, boole
return credentials;
}
} else {
UserPassDialog userPassDialog = new UserPassDialog(mw.getApplicationFrame());
userPassDialog.setLocationRelativeTo(Core.getMainWindow().getApplicationFrame());
UserPassDialog userPassDialog = new UserPassDialog(parent);
userPassDialog.setLocationRelativeTo(parent);
userPassDialog.setDescription(OStrings.getString(
credentials.username == null ? "TEAM_USERPASS_FIRST" : "TEAM_USERPASS_WRONG",
uri.getHumanishName()));
Expand Down
14 changes: 7 additions & 7 deletions src/org/omegat/core/team2/impl/SVNAuthenticationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@
import org.omegat.core.team2.ProjectTeamSettings;
import org.omegat.core.team2.gui.UserPassDialog;
import org.omegat.core.team2.impl.TeamUtils.Credentials;
import org.omegat.gui.main.ConsoleWindow;
import org.omegat.util.Log;
import org.omegat.util.OStrings;
import org.omegat.util.gui.StaticUIUtils;

import gen.core.project.RepositoryDefinition;

Expand Down Expand Up @@ -194,11 +194,11 @@ public SVNAuthentication getFirstAuthentication(String kind, String realm, SVNUR
return getAuthenticatorInstance(kind, url, credentials);
}

if (Core.getMainWindow() == null || Core.getMainWindow() instanceof ConsoleWindow) {
if (StaticUIUtils.isGUI()) {
return ask(kind, url, OStrings.getString("TEAM_USERPASS_FIRST", url.getPath()));
} else {
// run on headless.
return askCUI(kind, url, OStrings.getString("TEAM_USERPASS_FIRST", url.getPath()));
} else {
return ask(kind, url, OStrings.getString("TEAM_USERPASS_FIRST", url.getPath()));
}
}

Expand All @@ -207,11 +207,11 @@ public SVNAuthentication getNextAuthentication(String kind, String realm, SVNURL
if (predefinedUser != null && predefinedPass != null) {
throw new KnownException("TEAM_PREDEFINED_CREDENTIALS_ERROR");
}
if (Core.getMainWindow() == null) {
if (StaticUIUtils.isGUI()) {
return ask(kind, url, OStrings.getString("TEAM_USERPASS_WRONG", url.getPath()));
} else {
// run on headless.
return askCUI(kind, url, OStrings.getString("TEAM_USERPASS_WRONG", url.getPath()));
} else {
return ask(kind, url, OStrings.getString("TEAM_USERPASS_WRONG", url.getPath()));
}
}

Expand Down
6 changes: 3 additions & 3 deletions test-integration/docker/client/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@

FROM debian:bookworm-slim
ARG CAVER=1.0.3-1
ARG JAVA=11
ARG JDKVER=jdk_11.0.23.0.0+9
ARG JAVA=17
ARG JDKVER=jdk_17.0.9.0.0+9
ARG GRADLE=8.8
RUN apt-get -y update && apt-get upgrade -y && apt-get install -y openssh-client git inotify-tools curl subversion unzip rsync \
java-common libasound2 libfontconfig1 libfreetype6 libxi6 libxrender1 libxtst6 p11-kit openjdk-17-jdk
java-common libasound2 libfontconfig1 libfreetype6 libxi6 libxrender1 libxtst6 p11-kit
RUN adduser --disabled-password --gecos "" --home /home/omegat --shell /bin/bash omegat && mkdir -p /home/omegat/.ssh
RUN chown -R omegat.omegat /home/omegat
COPY --chown=omegat ssh_config /home/omegat/.ssh/config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ static class Run extends Thread {
+ dir.getAbsolutePath() + " " + repo + " " + delay + " " + SEG_COUNT);
ProcessBuilder pb = new ProcessBuilder(cmd);
pb.inheritIO();
pb.redirectErrorStream(true);
p = pb.start();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.awt.Cursor;
import java.awt.Font;
import java.awt.Frame;
import java.awt.HeadlessException;
import java.io.File;
import java.io.InputStream;
import java.nio.file.Files;
Expand All @@ -44,7 +43,6 @@
import java.util.Set;
import java.util.concurrent.ThreadLocalRandom;

import javax.swing.JFrame;
import javax.swing.JMenu;

import org.madlonkay.supertmxmerge.StmProperties;
Expand All @@ -70,6 +68,7 @@
import org.omegat.gui.glossary.GlossaryManager;
import org.omegat.gui.glossary.GlossaryReaderTSV;
import org.omegat.gui.glossary.IGlossaries;
import org.omegat.gui.main.ConsoleWindow;
import org.omegat.gui.main.IMainMenu;
import org.omegat.gui.main.IMainWindow;
import org.omegat.util.Log;
Expand All @@ -81,7 +80,6 @@
import org.omegat.util.gui.MenuExtender.MenuKey;

import com.vlsolutions.swing.docking.Dockable;
import com.vlsolutions.swing.docking.DockingDesktop;
import gen.core.project.RepositoryDefinition;

/**
Expand Down Expand Up @@ -595,37 +593,20 @@ public boolean isOrientationAllLtr() {
}
};

static IMainWindow mainWindow = new IMainWindow() {
static IMainWindow mainWindow = new ConsoleWindow() {
@Override
public void unlockUI() {
}

public void showStatusMessageRB(String messageKey, Object... params) {
}

public void showTimedStatusMessageRB(String messageKey, Object... params) {
}

@Override
public void showProgressMessage(String messageText) {
}

public void showMessageDialog(String message) {
}

@Override
public void showLengthMessage(String messageText) {
}

public void showErrorDialogRB(String title, String message, Object... args) {
System.err.println(message);
}

public int showConfirmDialog(Object message, String title, int optionType, int messageType)
throws HeadlessException {
return 0;
}

public void setCursor(Cursor cursor) {
}

@Override
public void lockUI() {
}

Expand Down Expand Up @@ -673,23 +654,10 @@ public IMainMenu getMainMenu() {
return menu;
}

@Override
public DockingDesktop getDesktop() {
return null;
}

@Override
public void resetDesktopLayout() {
}

public Cursor getCursor() {
return null;
}

public JFrame getApplicationFrame() {
return null;
}

public Font getApplicationFont() {
return null;
}
Expand All @@ -709,9 +677,6 @@ public void displayErrorRB(Throwable ex, String errorKey, Object... params) {

public void addDockable(Dockable pane) {
}

public void showLockInsertMessage(String messageText, String toolTip) {
}
};

/**
Expand Down
7 changes: 3 additions & 4 deletions test/fixtures/org/omegat/core/TestCoreInitializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
import org.omegat.core.threads.IAutoSave;
import org.omegat.gui.editor.IEditor;
import org.omegat.gui.glossary.IGlossaries;
import org.omegat.gui.main.ConsoleWindow;
import org.omegat.gui.main.IMainWindow;
import org.omegat.util.gui.StaticUIUtils;

/**
* Core initializer for unit tests.
Expand All @@ -52,10 +52,9 @@ public static void initAutoSave(IAutoSave autoSave) {
public static void initMainWindow(IMainWindow mainWindow) throws Exception {
Core.setMainWindow(mainWindow);

if (mainWindow instanceof ConsoleWindow) {
return;
if (StaticUIUtils.isGUI()) {
Core.initializeGUIimpl(mainWindow);
}
Core.initializeGUIimpl(mainWindow);
}

public static void initGlossary(IGlossaries glossaries) {
Expand Down

0 comments on commit 8bcd883

Please sign in to comment.