diff options
author | Andrej Shadura <andrewsh@debian.org> | 2019-01-04 21:32:28 +0100 |
---|---|---|
committer | Andrej Shadura <andrewsh@debian.org> | 2019-01-04 21:32:28 +0100 |
commit | 487c1776ab9340be91a58e9b5a040316f97ea465 (patch) | |
tree | 2222155fd0fbdd592652700f4a2bd83ce979accd | |
parent | e60eabdd3cb3f9fafc3196ea3b4922247b610730 (diff) |
Strip missing dependenciesarchive/debian/3.6.0.10+dfsg-1
Make it possible to build OmegaT without Git/Subversion support and
also without SuperTMXMerge and LanguageTool.
Gbp-Pq: Name 08-disable-extra-dependencies.patch
-rw-r--r-- | manifest-template.mf | 6 | ||||
-rw-r--r-- | src/org/omegat/core/Core.java | 4 | ||||
-rw-r--r-- | src/org/omegat/core/data/RealProject.java | 4 | ||||
-rw-r--r-- | src/org/omegat/core/team/GITRemoteRepository.java | 601 | ||||
-rw-r--r-- | src/org/omegat/core/team/RepositoryUtils.java | 2 | ||||
-rw-r--r-- | src/org/omegat/core/team/SVNRemoteRepository.java | 363 | ||||
-rw-r--r-- | src/org/omegat/gui/dialogs/NewTeamProject.java | 7 | ||||
-rw-r--r-- | src/org/omegat/gui/main/ProjectUICommands.java | 6 | ||||
-rw-r--r-- | src/org/omegat/languagetools/LanguageToolWrapper.java | 186 | ||||
-rw-r--r-- | src/org/omegat/tokenizer/LuceneKoreanTokenizer.java | 68 | ||||
-rw-r--r-- | src/org/omegat/tokenizer/TinySegmenterJapaneseTokenizer.java | 101 |
11 files changed, 15 insertions, 1333 deletions
diff --git a/manifest-template.mf b/manifest-template.mf index efcc04d..c83a5e4 100644 --- a/manifest-template.mf +++ b/manifest-template.mf @@ -191,9 +191,6 @@ OmegaT-Plugin: tokenizer Name: org.omegat.tokenizer.LuceneJapaneseTokenizer OmegaT-Plugin: tokenizer -Name: org.omegat.tokenizer.LuceneKoreanTokenizer -OmegaT-Plugin: tokenizer - Name: org.omegat.tokenizer.LuceneLatvianTokenizer OmegaT-Plugin: tokenizer @@ -278,9 +275,6 @@ OmegaT-Plugin: tokenizer Name: org.omegat.tokenizer.SnowballTurkishTokenizer OmegaT-Plugin: tokenizer -Name: org.omegat.tokenizer.TinySegmenterJapaneseTokenizer -OmegaT-Plugin: tokenizer - Name: org.omegat.gui.glossary.TransTipsMarker OmegaT-Plugin: Marker diff --git a/src/org/omegat/core/Core.java b/src/org/omegat/core/Core.java index 124d2f7..82623c7 100644 --- a/src/org/omegat/core/Core.java +++ b/src/org/omegat/core/Core.java @@ -72,7 +72,7 @@ import org.omegat.gui.notes.INotes; import org.omegat.gui.notes.NotesTextArea; import org.omegat.gui.tagvalidation.ITagValidation; import org.omegat.gui.tagvalidation.TagValidationTool; -import org.omegat.languagetools.LanguageToolWrapper; +//import org.omegat.languagetools.LanguageToolWrapper; import org.omegat.tokenizer.ITokenizer; import org.omegat.util.Preferences; import org.omegat.util.RecentProjects; @@ -233,7 +233,7 @@ public class Core { Core.registerMarker(new ReplaceMarker()); Core.registerMarker(new ComesFromAutoTMMarker()); Core.registerMarker(new FontFallbackMarker()); - Core.registerMarker(new LanguageToolWrapper()); + //Core.registerMarker(new LanguageToolWrapper()); // 3. Initialize other components. They add themselves to the main window. editor = new EditorController(me); diff --git a/src/org/omegat/core/data/RealProject.java b/src/org/omegat/core/data/RealProject.java index 3e807af..9f66ec9 100644 --- a/src/org/omegat/core/data/RealProject.java +++ b/src/org/omegat/core/data/RealProject.java @@ -62,8 +62,10 @@ import javax.swing.SwingUtilities; import org.apache.commons.io.IOUtils; import org.apache.lucene.util.Version; +/* import org.madlonkay.supertmxmerge.StmProperties; import org.madlonkay.supertmxmerge.SuperTmxMerge; +*/ import org.omegat.CLIParameters; import org.omegat.core.Core; import org.omegat.core.CoreEvents; @@ -1027,6 +1029,7 @@ public class RealProject implements IProject { * File 2: headTMX (theirs) */ protected void mergeTMX(ProjectTMX baseTMX, ProjectTMX headTMX, StringBuilder commitDetails) { + /* StmProperties props = new StmProperties().setBaseTmxName(OStrings.getString("TMX_MERGE_BASE")) .setTmx1Name(OStrings.getString("TMX_MERGE_MINE")) .setTmx2Name(OStrings.getString("TMX_MERGE_THEIRS")) @@ -1040,6 +1043,7 @@ public class RealProject implements IProject { Log.logDebug(LOGGER, "Merge report: {0}", props.getReport()); commitDetails.append('\n'); commitDetails.append(props.getReport().toString()); + */ } /** diff --git a/src/org/omegat/core/team/GITRemoteRepository.java b/src/org/omegat/core/team/GITRemoteRepository.java deleted file mode 100644 index ea8ecd7..0000000 --- a/src/org/omegat/core/team/GITRemoteRepository.java +++ /dev/null @@ -1,601 +0,0 @@ -/************************************************************************** - OmegaT - Computer Assisted Translation (CAT) tool - with fuzzy matching, translation memory, keyword search, - glossaries, and translation leveraging into updated projects. - - Copyright (C) 2012 Alex Buloichik - 2014 Aaron Madlon-Kay - Home page: http://www.omegat.org/ - Support center: http://groups.yahoo.com/group/OmegaT/ - - This file is part of OmegaT. - - OmegaT is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OmegaT is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - **************************************************************************/ -package org.omegat.core.team; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.Collection; -import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import javax.swing.JOptionPane; - -import org.eclipse.jgit.api.CheckoutCommand; -import org.eclipse.jgit.api.CloneCommand; -import org.eclipse.jgit.api.Git; -import org.eclipse.jgit.api.LogCommand; -import org.eclipse.jgit.api.LsRemoteCommand; -import org.eclipse.jgit.api.ResetCommand; -import org.eclipse.jgit.api.Status; -import org.eclipse.jgit.api.errors.GitAPIException; -import org.eclipse.jgit.api.errors.InvalidRemoteException; -import org.eclipse.jgit.api.errors.JGitInternalException; -import org.eclipse.jgit.api.errors.TransportException; -import org.eclipse.jgit.errors.UnsupportedCredentialItem; -import org.eclipse.jgit.lib.ProgressMonitor; -import org.eclipse.jgit.lib.Ref; -import org.eclipse.jgit.lib.Repository; -import org.eclipse.jgit.lib.StoredConfig; -import org.eclipse.jgit.revwalk.RevCommit; -import org.eclipse.jgit.revwalk.RevWalk; -import org.eclipse.jgit.transport.CredentialItem; -import org.eclipse.jgit.transport.CredentialsProvider; -import org.eclipse.jgit.transport.PushResult; -import org.eclipse.jgit.transport.RemoteRefUpdate; -import org.eclipse.jgit.transport.URIish; -import org.omegat.core.Core; -import org.omegat.gui.dialogs.TeamUserPassDialog; -import org.omegat.util.FileUtil; -import org.omegat.util.Log; -import org.omegat.util.OStrings; -import org.omegat.util.StringUtil; - -/** - * GIT repository connection implementation. - * - * Project should use "autocrlf=true" options. Otherwise, repository can be changed every 5 minutes. This - * property will be setted by OmegaT on checkoutFullProject(). - * - * GIT project can't be locked, because git requires to update full snapshot. - * - * @author Alex Buloichik (alex73mail@gmail.com) - * @author Martin Fleurke - * @author Aaron Madlon-Kay - */ -public class GITRemoteRepository implements IRemoteRepository { - private static final Logger LOGGER = Logger.getLogger(GITRemoteRepository.class.getName()); - - protected static String LOCAL_BRANCH = "master"; - protected static String REMOTE_BRANCH = "origin/master"; - protected static String REMOTE = "origin"; - boolean readOnly; - - File localDirectory; - protected Repository repository; - - private MyCredentialsProvider myCredentialsProvider; - - public static boolean isGITDirectory(File localDirectory) { - return getLocalRepositoryRoot(localDirectory) != null; - } - - public boolean isFilesLockingAllowed() { - return true; - } - - public GITRemoteRepository(File localDirectory) throws Exception { - - try { - //workaround for: file c:\project\omegat\project_save.tmx is not contained in C:\project\. - //The git repo uses the canonical path for some actions, and if c: != C: then an error is raised. - //if we make it canonical already here, then we don't have that problem. - localDirectory = localDirectory.getCanonicalFile(); - } catch (Exception e) {} - - this.localDirectory = localDirectory; - CredentialsProvider prevProvider = CredentialsProvider.getDefault(); - myCredentialsProvider = new MyCredentialsProvider(this); - if (prevProvider instanceof MyCredentialsProvider) { - myCredentialsProvider.setCredentials(((MyCredentialsProvider)prevProvider).credentials); - } - CredentialsProvider.setDefault(myCredentialsProvider); - File localRepositoryDirectory = getLocalRepositoryRoot(localDirectory); - if (localRepositoryDirectory != null) { - repository = Git.open(localRepositoryDirectory).getRepository(); - } - } - - public void checkoutFullProject(String repositoryURL) throws Exception { - Log.logInfoRB("GIT_START", "clone"); - CloneCommand c = Git.cloneRepository(); - c.setURI(repositoryURL); - c.setDirectory(localDirectory); - try { - c.call(); - } catch (InvalidRemoteException e) { - FileUtil.deleteTree(localDirectory); - Throwable cause = e.getCause(); - if (cause != null && cause instanceof org.eclipse.jgit.errors.NoRemoteRepositoryException) { - BadRepositoryException bre = new BadRepositoryException(((org.eclipse.jgit.errors.NoRemoteRepositoryException)cause).getLocalizedMessage()); - bre.initCause(e); - throw bre; - } - throw e; - } - repository = Git.open(localDirectory).getRepository(); - new Git(repository).submoduleInit().call(); - new Git(repository).submoduleUpdate().call(); - - //Deal with line endings. A normalized repo has LF line endings. - //OmegaT uses line endings of OS for storing tmx files. - //To do auto converting, we need to change a setting: - StoredConfig config = repository.getConfig(); - if ("\r\n".equals(FileUtil.LINE_SEPARATOR)) { - //on windows machines, convert text files to CRLF - config.setBoolean("core", null, "autocrlf", true); - } else { - //on Linux/Mac machines (using LF), don't convert text files - //but use input format, unchanged. - //NB: I don't know correct setting for OS'es like MacOS <= 9, - // which uses CR. Git manual only speaks about converting from/to - //CRLF, so for CR, you probably don't want conversion either. - config.setString("core", null, "autocrlf", "input"); - } - config.save(); - myCredentialsProvider.saveCredentials(); - Log.logInfoRB("GIT_FINISH", "clone"); - } - - public boolean isChanged(File file) throws Exception { - Log.logInfoRB("GIT_START", "status"); - String relativeFile = FileUtil.computeRelativePath(repository.getWorkTree(), file); - Status status = new Git(repository).status().call(); - Log.logInfoRB("GIT_FINISH", "status"); - boolean result = status.getModified().contains(relativeFile); - Log.logDebug(LOGGER, "GIT modified status of {0} is {1}", relativeFile, result); - return result; - } - - public boolean isUnderVersionControl(File file) throws Exception { - boolean result = file.exists(); - String relativeFile = FileUtil.computeRelativePath(repository.getWorkTree(), file); - Status status = new Git(repository).status().call(); - - if (status.getAdded().contains(relativeFile) || status.getModified().contains(relativeFile) - || status.getChanged().contains(relativeFile) - || status.getConflicting().contains(relativeFile) - || status.getMissing().contains(relativeFile) || status.getRemoved().contains(relativeFile)) { - result = true; - } - if (status.getUntracked().contains(relativeFile)) { - result = false; - } - Log.logDebug(LOGGER, "GIT file {0} is under version control: {1}", relativeFile, result); - return result; - } - - public void setCredentials(Credentials credentials) { - if (credentials == null) { - return; - } - myCredentialsProvider.setCredentials(credentials); - setReadOnly(credentials.readOnly); - } - - public void setReadOnly(boolean value) { - readOnly = value; - } - - public String getBaseRevisionId(File file) throws Exception { - RevWalk walk = new RevWalk(repository); - - Ref localBranch = repository.getRef("HEAD"); - Ref remoteBranch = repository.getRef(REMOTE_BRANCH); - RevCommit headCommit = walk.lookupCommit(localBranch.getObjectId()); - RevCommit upstreamCommit = walk.lookupCommit(remoteBranch.getObjectId()); - Log.logDebug(LOGGER, "GIT HEAD rev: {0}", headCommit.getName()); - Log.logDebug(LOGGER, "GIT origin/master rev: {0}", upstreamCommit.getName()); - - LogCommand cmd = new Git(repository).log().addRange(upstreamCommit, headCommit); - Iterable<RevCommit> commitsToUse = cmd.call(); - RevCommit last = null; - for (RevCommit commit : commitsToUse) { - last = commit; - } - RevCommit commonBase = last != null ? last.getParent(0) : upstreamCommit; - Log.logDebug(LOGGER, "GIT commonBase rev: {0}", commonBase.getName()); - return commonBase.getName(); - } - - public void restoreBase(File[] files) throws Exception { - String baseRevisionId = getBaseRevisionId(files[0]); - Log.logDebug(LOGGER, "GIT restore base {0} for {1}", baseRevisionId, (Object) files); - //undo local changes of specific file. - CheckoutCommand checkoutCommand = new Git(repository).checkout(); - for (File f: files) { - String relativeFileName = FileUtil.computeRelativePath(repository.getWorkTree(), f); - checkoutCommand.addPath(relativeFileName); - } - checkoutCommand.call(); - //reset repo to previous version. Can cause conflicts for other files! - new Git(repository).checkout().setName(baseRevisionId).call(); - } - - public void reset() throws Exception { - Log.logInfoRB("GIT_START", "reset"); - try { - new Git(repository).reset().setMode(ResetCommand.ResetType.HARD).call(); - Log.logInfoRB("GIT_FINISH", "reset"); - } catch (Exception ex) { - Log.logErrorRB("GIT_ERROR", "reset", ex.getMessage()); - checkAndThrowException(ex); - } - } - - public void updateFullProject() throws NetworkException, Exception { - Log.logInfoRB("GIT_START", "pull"); - try { - new Git(repository).fetch().call(); - new Git(repository).checkout().setName(REMOTE_BRANCH).call(); - new Git(repository).branchDelete().setBranchNames(LOCAL_BRANCH).setForce(true).call(); - new Git(repository).checkout().setStartPoint(REMOTE_BRANCH).setCreateBranch(true) - .setName(LOCAL_BRANCH).setForce(true).call(); - new Git(repository).submoduleUpdate().call(); - Log.logInfoRB("GIT_FINISH", "pull"); - } catch (Exception ex) { - Log.logErrorRB("GIT_ERROR", "pull", ex.getMessage()); - checkAndThrowException(ex); - } - } - - public void download(File[] files) throws NetworkException, Exception { - Log.logInfoRB("GIT_START", "download"); - try { - new Git(repository).fetch().call(); - new Git(repository).checkout().setName(REMOTE_BRANCH).call(); - new Git(repository).branchDelete().setBranchNames(LOCAL_BRANCH).setForce(true).call(); - new Git(repository).checkout().setStartPoint(REMOTE_BRANCH).setCreateBranch(true) - .setName(LOCAL_BRANCH).setForce(true).call(); - Log.logInfoRB("GIT_FINISH", "download"); - } catch (Exception ex) { - Log.logErrorRB("GIT_ERROR", "download", ex.getMessage()); - checkAndThrowException(ex); - } - } - - public void upload(File file, String commitMessage) throws NetworkException, Exception { - if (readOnly) { - // read-only - upload disabled - Log.logInfoRB("GIT_READONLY"); - return; - } - - boolean ok = true; - Log.logInfoRB("GIT_START", "upload"); - try { -// if (!isChanged(file)) { -// Log.logInfoRB("GIT_FINISH", "upload(not changed)"); -// return; -// } - String filePattern = FileUtil.computeRelativePath(repository.getWorkTree(), file); - new Git(repository).add().addFilepattern(filePattern).call(); - new Git(repository).commit().setMessage(commitMessage).call(); - Iterable<PushResult> results = new Git(repository).push().setRemote(REMOTE).add(LOCAL_BRANCH) - .call(); - int count = 0; - for (PushResult r : results) { - for (RemoteRefUpdate update : r.getRemoteUpdates()) { - count++; - if (update.getStatus() != RemoteRefUpdate.Status.OK) { - ok = false; - } - } - } - if (count < 1) { - ok = false; - } - Log.logInfoRB("GIT_FINISH", "upload"); - } catch (Exception ex) { - Log.logErrorRB("GIT_ERROR", "upload", ex.getMessage()); - checkAndThrowException(ex); - } - if (!ok) { - Log.logWarningRB("GIT_CONFLICT"); - } - } - - private void checkAndThrowException(Exception ex) throws NetworkException, Exception { - if (ex instanceof TransportException) { - throw new NetworkException(ex); - } else { - throw ex; - } - } - - private static File getLocalRepositoryRoot(File path) { - if (path == null) { - return null; - } - File possibleControlDir = new File(path, ".git"); - if (possibleControlDir.exists() && possibleControlDir.isDirectory()) { - return path; - } else { - // We need to call getAbsoluteFile() because "path" can be relative. In this case, we will have - // "null" instead real parent directory. - return getLocalRepositoryRoot(path.getAbsoluteFile().getParentFile()); - } - } - - static ProgressMonitor gitProgress = new ProgressMonitor() { - public void update(int completed) { - System.out.println("update: " + completed); - } - - public void start(int totalTasks) { - System.out.println("start: " + totalTasks); - } - - public boolean isCancelled() { - return false; - } - - public void endTask() { - System.out.println("endTask"); - } - - public void beginTask(String title, int totalWork) { - System.out.println("beginTask: " + title + " total: " + totalWork); - } - }; - - /** - * CredentialsProvider that will ask user for credentials when required, - * and can store the credentials to plain text file. - */ - private static class MyCredentialsProvider extends CredentialsProvider { - - GITRemoteRepository gitRemoteRepository; - File credentialsFile; - - private Credentials credentials; - - public MyCredentialsProvider(GITRemoteRepository repo) { - super(); - this.gitRemoteRepository = repo; - if (repo != null) { - credentialsFile = new File(gitRemoteRepository.localDirectory, "credentials.properties"); - } - } - - public void setCredentials(Credentials credentials) { - if (credentials == null) { - return; - } - this.credentials = credentials.clone(); - } - - private void loadCredentials() { - if (credentialsFile == null || !credentialsFile.exists()) { - credentials = new Credentials(); - return; - } - try { - credentials = Credentials.fromFile(credentialsFile); - } catch (FileNotFoundException ex) { - credentials = new Credentials(); - } catch (IOException ex) { - ex.printStackTrace(); - } - } - - private void saveCredentials() { - if (credentials == null || credentialsFile == null || !credentials.saveAsPlainText) { - return; - } - try { - credentials.saveToPlainTextFile(credentialsFile); - } catch (FileNotFoundException e) { - Core.getMainWindow().displayErrorRB(e, "TEAM_ERROR_SAVE_CREDENTIALS", null, "TF_ERROR"); - } catch (IOException e) { - Core.getMainWindow().displayErrorRB(e, "TEAM_ERROR_SAVE_CREDENTIALS", null, "TF_ERROR"); - } - } - - @Override - public boolean get(URIish uri, CredentialItem... items) - throws UnsupportedCredentialItem { - if (credentials == null) { - loadCredentials(); - } - boolean ok = false; - //theoretically, username can be unknown, but in practice it is always set, so not requested. - for (CredentialItem i : items) { - if (i instanceof CredentialItem.Username) { - if (credentials.username==null) { - ok = askCredentials(uri.getUser()); - if (!ok) { - throw new UnsupportedCredentialItem(uri, OStrings.getString("TEAM_CREDENTIALS_DENIED")); - } - } - ((CredentialItem.Username) i).setValue(credentials.username); - continue; - } else if (i instanceof CredentialItem.Password) { - if (credentials.password==null) { - ok = askCredentials(uri.getUser()); - if (!ok) { - throw new UnsupportedCredentialItem(uri, OStrings.getString("TEAM_CREDENTIALS_DENIED")); - } - } - ((CredentialItem.Password) i).setValue(credentials.password); - if (credentials.password != null) { - uri.setPass(new String(credentials.password)); - } - continue; - } else if (i instanceof CredentialItem.StringType) { - if (i.getPromptText().equals("Password: ")) { - if (credentials.password==null) { - if (!ok) { - ok = askCredentials(uri.getUser()); - if (!ok) { - throw new UnsupportedCredentialItem(uri, OStrings.getString("TEAM_CREDENTIALS_DENIED")); - } - } - } - ((CredentialItem.StringType) i).setValue(new String(credentials.password)); - continue; - } - } else if (i instanceof CredentialItem.YesNoType) { - //e.g.: The authenticity of host 'mygitserver' can't be established. - //RSA key fingerprint is e2:d3:84:d5:86:e7:68:69:a0:aa:a6:ad:a3:a0:ab:a2. - //Are you sure you want to continue connecting? - String promptText = i.getPromptText(); - String promptedFingerprint = extractFingerprint(promptText); - if (promptedFingerprint.equals(credentials.fingerprint)) { - ((CredentialItem.YesNoType) i).setValue(true); - continue; - } - int choice = Core.getMainWindow().showConfirmDialog(promptText, null, JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); - if (choice==JOptionPane.YES_OPTION) { - ((CredentialItem.YesNoType) i).setValue(true); - if (promptedFingerprint != null) { - credentials.fingerprint = promptedFingerprint; - } - saveCredentials(); - } else { - ((CredentialItem.YesNoType) i).setValue(false); - } - continue; - } else if (i instanceof CredentialItem.InformationalMessage) { - Core.getMainWindow().showMessageDialog(i.getPromptText()); - continue; - } - throw new UnsupportedCredentialItem(uri, i.getClass().getName() - + ":" + i.getPromptText()); - } - return true; - } - - @Override - public boolean isInteractive() { - return true; - } - - @Override - public boolean supports(CredentialItem... items) { - for (CredentialItem i : items) { - if (i instanceof CredentialItem.Username) - continue; - - else if (i instanceof CredentialItem.Password) - continue; - - else - return false; - } - return true; - } - - /** - * shows dialog to ask for credentials, and stores credentials. - * @return true when entered, false on cancel. - */ - private boolean askCredentials(String usernameInUri) { - TeamUserPassDialog userPassDialog = new TeamUserPassDialog(Core.getMainWindow().getApplicationFrame()); - userPassDialog.descriptionTextArea.setText(OStrings.getString(credentials.username==null ? "TEAM_USERPASS_FIRST" : "TEAM_USERPASS_WRONG")); - //if username is already available in uri, then we will not be asked for an username, so we cannot change it. - if (!StringUtil.isEmpty(usernameInUri)) { - userPassDialog.setFixedUsername(usernameInUri); - } - userPassDialog.setVisible(true); - if (userPassDialog.getReturnStatus() == TeamUserPassDialog.RET_OK) { - credentials.username = userPassDialog.userText.getText(); - credentials.password = userPassDialog.getPasswordCopy(); - credentials.readOnly = userPassDialog.cbReadOnly.isSelected(); - if (gitRemoteRepository != null) { - gitRemoteRepository.setReadOnly(credentials.readOnly); - } - credentials.saveAsPlainText = userPassDialog.cbForceSavePlainPassword.isSelected(); - saveCredentials(); - return true; - } else { - return false; - } - } - - public void reset(URIish uri) { - //reset is called after 5 authorization failures. After 3 resets, the transport gives up. - credentials.clear(); - } - - } - - private static String extractFingerprint(String text) { - Pattern p = Pattern.compile("The authenticity of host '.*' can't be established\\.\\nRSA key fingerprint is (([0-9a-f]{2}:){15}[0-9a-f]{2})\\.\\nAre you sure you want to continue connecting\\?"); - Matcher fingerprintMatcher = p.matcher(text); - if (fingerprintMatcher.find()) { - int start = fingerprintMatcher.start(1); - int end = fingerprintMatcher.end(1); - return text.substring(start, end); - } - return null; - } - - - /** - * Determines whether or not the supplied URL represents a valid Git repository. - * - * <p>Does the equivalent of <code>git ls-remote <i>url</i></code>. - * - * @param url URL of supposed remote repository - * @return true if repository appears to be valid, false otherwise - */ - public static boolean isGitRepository(String url, Credentials credentials) - throws AuthenticationException { - // Heuristics to save some waiting time - if (url.startsWith("svn://") || url.startsWith("svn+")) { - return false; - } - try { - if (credentials != null) { - MyCredentialsProvider provider = new MyCredentialsProvider(null); - provider.setCredentials(credentials); - CredentialsProvider.setDefault(provider); - } - Collection<Ref> result = new LsRemoteCommand(null).setRemote(url).call(); - return !result.isEmpty(); - } catch (TransportException ex) { - String message = ex.getMessage(); - if (message.endsWith("not authorized") || message.endsWith("Auth fail") - || message.contains("Too many authentication failures") - || message.contains("Authentication is required")) { - throw new AuthenticationException(ex); - } - return false; - } catch (GitAPIException ex) { - throw new AuthenticationException(ex); - } catch (JGitInternalException ex) { - // Happens if the URL is a Subversion URL like svn://... - return false; - } - } - - public static String guessRepoName(String url) { - url = StringUtil.stripFromEnd(url, "/", ".git"); - return url.substring(url.lastIndexOf('/') + 1); - } -} diff --git a/src/org/omegat/core/team/RepositoryUtils.java b/src/org/omegat/core/team/RepositoryUtils.java index 2bb8f61..1abb2fd 100644 --- a/src/org/omegat/core/team/RepositoryUtils.java +++ b/src/org/omegat/core/team/RepositoryUtils.java @@ -162,6 +162,7 @@ public class RepositoryUtils { private Class<? extends IRemoteRepository> detect(Credentials credentials) throws Exception { Exception thrown = null; + /* try { if (GITRemoteRepository.isGitRepository(url, credentials)) { return GITRemoteRepository.class; @@ -172,6 +173,7 @@ public class RepositoryUtils { if (SVNRemoteRepository.isSVNRepository(url, credentials)) { return SVNRemoteRepository.class; } + */ if (thrown != null) { throw thrown; } diff --git a/src/org/omegat/core/team/SVNRemoteRepository.java b/src/org/omegat/core/team/SVNRemoteRepository.java deleted file mode 100644 index 442ad83..0000000 --- a/src/org/omegat/core/team/SVNRemoteRepository.java +++ /dev/null @@ -1,363 +0,0 @@ -/************************************************************************** - OmegaT - Computer Assisted Translation (CAT) tool - with fuzzy matching, translation memory, keyword search, - glossaries, and translation leveraging into updated projects. - - Copyright (C) 2012 Alex Buloichik - 2014 Aaron Madlon-Kay - Home page: http://www.omegat.org/ - Support center: http://groups.yahoo.com/group/OmegaT/ - - This file is part of OmegaT. - - OmegaT is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OmegaT is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - **************************************************************************/ -package org.omegat.core.team; - -import java.io.File; -import java.net.SocketException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; -import java.util.logging.Logger; - -import org.omegat.core.Core; -import org.omegat.util.Log; -import org.omegat.util.StringUtil; -import org.tmatesoft.svn.core.SVNAuthenticationException; -import org.tmatesoft.svn.core.SVNCommitInfo; -import org.tmatesoft.svn.core.SVNDepth; -import org.tmatesoft.svn.core.SVNErrorCode; -import org.tmatesoft.svn.core.SVNException; -import org.tmatesoft.svn.core.SVNURL; -import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager; -import org.tmatesoft.svn.core.auth.SVNAuthentication; -import org.tmatesoft.svn.core.internal.wc.DefaultSVNAuthenticationManager; -import org.tmatesoft.svn.core.internal.wc.ISVNAuthStoreHandler; -import org.tmatesoft.svn.core.internal.wc.ISVNAuthenticationStorageOptions; -import org.tmatesoft.svn.core.internal.wc.ISVNGnomeKeyringPasswordProvider; -import org.tmatesoft.svn.core.wc.ISVNOptions; -import org.tmatesoft.svn.core.wc.SVNClientManager; -import org.tmatesoft.svn.core.wc.SVNInfo; -import org.tmatesoft.svn.core.wc.SVNRevision; -import org.tmatesoft.svn.core.wc.SVNStatus; -import org.tmatesoft.svn.core.wc.SVNStatusType; -import org.tmatesoft.svn.core.wc.SVNWCUtil; - -/** - * SVN repository connection implementation. - * - * @author Alex Buloichik (alex73mail@gmail.com) - * @author Aaron Madlon-Kay - */ -public class SVNRemoteRepository implements IRemoteRepository { - private static final Logger LOGGER = Logger.getLogger(SVNRemoteRepository.class.getName()); - - /** Tests can disable show error. */ - public static boolean SHOW_UNKNOWN_ERRORS = true; - - File baseDirectory; - SVNClientManager ourClientManager; - boolean readOnly; - - public static boolean isSVNDirectory(File localDirectory) { - File svnDir = new File(localDirectory, ".svn"); - return svnDir.exists() && svnDir.isDirectory(); - } - - public boolean isFilesLockingAllowed() { - return true; - } - - /** - * Open working copy. - */ - public SVNRemoteRepository(File localDirectory) throws Exception { - this.baseDirectory = localDirectory; - ISVNOptions options = SVNWCUtil.createDefaultOptions(true); - ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(); - ourClientManager = SVNClientManager.newInstance(options, authManager); - } - - public boolean isChanged(File file) throws Exception { - SVNStatus status = null; - try { - status = ourClientManager.getStatusClient().doStatus(file, false); - } catch (SVNException e) { - if (e.getErrorMessage().getErrorCode().getCode()==155007) { - //file is outside repository, so not under version control. - return false; - } else throw e; - } - //if file does not exist and not under version control, then return false. - if (status == null) return false; - SVNStatusType statusType = status.getContentsStatus(); - //hmm, if file not under version control, status is STATUS_NONE, and not STATUS_UNVERSIONED? - return statusType != SVNStatusType.STATUS_NORMAL && statusType != SVNStatusType.STATUS_UNVERSIONED && statusType != SVNStatusType.STATUS_NONE; - } - - public boolean isUnderVersionControl(File file) throws Exception { - SVNStatus status = null; - try { - status = ourClientManager.getStatusClient().doStatus(file, false); - } catch (SVNException e) { - if (e.getErrorMessage().getErrorCode().getCode()==155007) { - //file is outside repository, so not under version control. - return false; - } else throw e; - } - //if file does not exist and not under version control, then return false. - if (status == null) return false; - SVNStatusType statusType = status.getContentsStatus(); - //hmm, if file not under version control, status is STATUS_NONE, and not STATUS_UNVERSIONED? - return statusType != SVNStatusType.STATUS_UNVERSIONED && statusType != SVNStatusType.STATUS_NONE; - } - - public void setCredentials(Credentials credentials) { - if (credentials == null) { - return; - } - ourClientManager.dispose(); - - DefaultSVNAuthenticationManager authManager = new DefaultSVNAuthenticationManager(null, true, - credentials.username, new String(credentials.password)); - if (credentials.saveAsPlainText) { - authManager.setAuthenticationStorageOptions(FORCE_SAVE_PLAIN_PASSWORD); - } - ISVNOptions options = SVNWCUtil.createDefaultOptions(true); - ourClientManager = SVNClientManager.newInstance(options, authManager); - setReadOnly(credentials.readOnly); - } - - public void setReadOnly(boolean value) { - readOnly = value; - } - - public void updateFullProject() throws SocketException, Exception { - Log.logInfoRB("SVN_START", "update"); - try { - long rev = ourClientManager.getUpdateClient().doUpdate(baseDirectory, SVNRevision.HEAD, SVNDepth.INFINITY, - false, false); - Log.logDebug(LOGGER, "SVN updated to revision {0}", rev); - Log.logInfoRB("SVN_FINISH", "update"); - } catch (SVNAuthenticationException ex) { - // authentication failed - need to ask username/password - Log.logWarningRB("SVN_ERROR", "update", ex.getMessage()); - throw new AuthenticationException(ex); - } catch (SVNException ex) { - Log.logErrorRB("SVN_ERROR", "update", ex.getMessage()); - checkNetworkException(ex); - throw ex; - } catch (Exception ex) { - Log.logErrorRB("SVN_ERROR", "update", ex.getMessage()); - throw ex; - } - } - - public void checkoutFullProject(String repositoryURL) throws Exception { - Log.logInfoRB("SVN_START", "checkout"); - - SVNURL url = SVNURL.parseURIDecoded(repositoryURL); - try { - long rev = ourClientManager.getUpdateClient().doCheckout(url, baseDirectory, SVNRevision.HEAD, - SVNRevision.HEAD, SVNDepth.INFINITY, false); - Log.logDebug(LOGGER, "SVN checked out to revision {0}", rev); - Log.logInfoRB("SVN_FINISH", "checkout"); - } catch (SVNAuthenticationException ex) { - // authentication failed - need to ask username/password - Log.logWarningRB("TEAM_WRONG_AUTHENTICATION"); - throw new AuthenticationException(ex); - } catch (Exception ex) { - Log.logErrorRB("SVN_ERROR", "checkout", ex.getMessage()); - throw ex; - } - } - - public String getBaseRevisionId(File file) throws Exception { - SVNInfo info = ourClientManager.getWCClient().doInfo(file, SVNRevision.BASE); - Log.logDebug(LOGGER, "SVN committed revision for file {0} is {1}", file, info.getCommittedRevision().getNumber()); - - return Long.toString(info.getCommittedRevision().getNumber()); - } - - public void restoreBase(File[] files) throws Exception { - ourClientManager.getWCClient().doRevert(files, SVNDepth.EMPTY, null); - Log.logDebug(LOGGER, "SVN restore base for {0}", toList(files)); - } - - public void download(File[] files) throws SocketException, Exception { - Log.logInfoRB("SVN_START", "download"); - try { - long[] revs = ourClientManager.getUpdateClient().doUpdate(files, SVNRevision.HEAD, SVNDepth.INFINITY, - false, false); - Log.logDebug(LOGGER, "SVN updated files {0} to revisions {1}", toList(files), toList(revs)); - Log.logInfoRB("SVN_FINISH", "download"); - } catch (SVNException ex) { - Log.logErrorRB("SVN_ERROR", "download", ex.getMessage()); - checkNetworkException(ex); - throw ex; - } catch (Exception ex) { - Log.logErrorRB("SVN_ERROR", "download", ex.getMessage()); - throw ex; - } - } - - public void reset() throws Exception { - Log.logInfoRB("SVN_START", "reset"); - try { - // not tested. Can anyone confirm this code? - Log.logDebug(LOGGER, "SVN revert all files in {0}", baseDirectory); - ourClientManager.getWCClient().doRevert(new File[] { baseDirectory }, SVNDepth.INFINITY, - (Collection<String>) null); - Log.logInfoRB("SVN_FINISH", "reset"); - } catch (Exception ex) { - Log.logErrorRB("SVN_ERROR", "reset", ex.getMessage()); - throw ex; - } - } - - public void upload(File file, String commitMessage) throws SocketException, Exception { - if (readOnly) { - // read-only - upload disabled - Log.logInfoRB("SVN_READONLY"); - return; - } - - Log.logInfoRB("SVN_START", "upload"); - try { - SVNCommitInfo info = ourClientManager.getCommitClient().doCommit(new File[] { file }, false, commitMessage, - null, null, false, false, SVNDepth.INFINITY); - Log.logDebug(LOGGER, "SVN committed file {0} into new revision {1}", file, info.getNewRevision()); - Log.logInfoRB("SVN_FINISH", "upload"); - } catch (SVNAuthenticationException ex) { - // authentication failed - need to ask username/password - Log.logWarningRB("SVN_ERROR", "update", ex.getMessage()); - throw new AuthenticationException(ex); - } catch (SVNException ex) { - if (Arrays.asList(SVNErrorCode.FS_TXN_OUT_OF_DATE, SVNErrorCode.WC_NOT_UP_TO_DATE, SVNErrorCode.FS_CONFLICT) - .contains(ex.getErrorMessage().getErrorCode())) { - // Somebody else committed changes - it's normal. Will upload on next save. - Log.logWarningRB("SVN_CONFLICT"); - return; - } else { - Log.logErrorRB("SVN_ERROR", "upload", ex.getMessage()); - checkNetworkException(ex); - } - if (SHOW_UNKNOWN_ERRORS) { - Core.getMainWindow().showErrorDialogRB("SVN_UPLOAD_ERROR_TITLE", "SVN_UPLOAD_ERROR", - ex.getMessage()); - } - throw ex; - } catch (Exception ex) { - Log.logErrorRB("SVN_ERROR", "upload", ex.getMessage()); - throw ex; - } - } - - List<File> toList(File[] files) { - return Arrays.asList(files); - } - - List<Long> toList(long[] arr) { - List<Long> result = new ArrayList<Long>(arr.length); - for (long v : arr) { - result.add(v); - } - return result; - } - - void checkNetworkException(Exception ex) throws NetworkException { - if (ex.getCause() instanceof SocketException) { - throw new NetworkException(ex.getCause()); - } - if (ex instanceof SVNException) { - SVNException se = (SVNException) ex; - if (se.getErrorMessage().getErrorCode().getCategory() == SVNErrorCode.RA_DAV_CATEGORY) { - throw new NetworkException(se); - } - } - } - - static ISVNAuthenticationStorageOptions FORCE_SAVE_PLAIN_PASSWORD = new ISVNAuthenticationStorageOptions() { - public boolean isNonInteractive() throws SVNException { - return false; - } - - public ISVNAuthStoreHandler getAuthStoreHandler() throws SVNException { - return FORCE_SAVE_PLAIN_PASSWORD_HANDLER; - } - - public boolean isSSLPassphrasePromptSupported() { - return false; - } - - public ISVNGnomeKeyringPasswordProvider getGnomeKeyringPasswordProvider() { - return null; - } - }; - - static ISVNAuthStoreHandler FORCE_SAVE_PLAIN_PASSWORD_HANDLER = new ISVNAuthStoreHandler() { - public boolean canStorePlainTextPassphrases(String realm, SVNAuthentication auth) throws SVNException { - return false; - } - - public boolean canStorePlainTextPasswords(String realm, SVNAuthentication auth) throws SVNException { - return true; - } - }; - - /** - * Determines whether or not the supplied URL represents a valid Subversion repository. - * - * <p>Does the equivalent of <code>svn info <i>url</i></code>. - * - * @param url URL of supposed remote repository - * @return true if repository appears to be valid, false otherwise - */ - public static boolean isSVNRepository(String url, Credentials credentials) - throws AuthenticationException { - // Heuristics to save some waiting time - if (url.startsWith("git://")) { - return false; - } - try { - SVNURL svnurl = SVNURL.parseURIDecoded(url); - SVNClientManager manager = SVNClientManager.newInstance(); - ISVNAuthenticationManager authManager; - if (credentials != null) { - DefaultSVNAuthenticationManager defaultManager = new DefaultSVNAuthenticationManager(null, - true, credentials.username, new String(credentials.password)); - if (credentials.saveAsPlainText) { - defaultManager.setAuthenticationStorageOptions(FORCE_SAVE_PLAIN_PASSWORD); - } - authManager = defaultManager; - } else { - authManager = SVNWCUtil.createDefaultAuthenticationManager(); - } - manager.setAuthenticationManager(authManager); - manager.getWCClient().doInfo(svnurl, SVNRevision.HEAD, SVNRevision.HEAD); - } catch (SVNAuthenticationException ex) { - throw new AuthenticationException(ex); - } catch (SVNException ex) { - return false; - } - return true; - } - - public static String guessRepoName(String url) { - url = StringUtil.stripFromEnd(url, "/", "/trunk", "/branches", "/tags", "/svn"); - return url.substring(url.lastIndexOf('/') + 1); - } -} diff --git a/src/org/omegat/gui/dialogs/NewTeamProject.java b/src/org/omegat/gui/dialogs/NewTeamProject.java index 16327c6..e097c84 100644 --- a/src/org/omegat/gui/dialogs/NewTeamProject.java +++ b/src/org/omegat/gui/dialogs/NewTeamProject.java @@ -34,11 +34,9 @@ import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import org.omegat.core.Core; -import org.omegat.core.team.GITRemoteRepository; import org.omegat.core.team.IRemoteRepository; import org.omegat.core.team.IRemoteRepository.Credentials; import org.omegat.core.team.RepositoryUtils.RepoTypeDetector; -import org.omegat.core.team.SVNRemoteRepository; import org.omegat.util.Log; import org.omegat.util.OStrings; import org.omegat.util.Preferences; @@ -125,6 +123,8 @@ public class NewTeamProject extends javax.swing.JDialog { if (StringUtil.isEmpty(url)) { return; } + return; + /* if (url.startsWith("git!")) { txtRepositoryURL.setText(url.substring("git!".length())); detectedRepoLabel.setText(OStrings.getString("TEAM_DETECTED_REPO_GIT")); @@ -137,6 +137,7 @@ public class NewTeamProject extends javax.swing.JDialog { repoTypeWorker = new RepoTypeWorker(url); repoTypeWorker.execute(); } + */ } private synchronized void startDetectingRepo() { @@ -183,6 +184,7 @@ public class NewTeamProject extends javax.swing.JDialog { repoType = detector.repoType; credentials = detector.credentials; if (repoType != null) { + /* if (repoType.equals(GITRemoteRepository.class)) { resultText = OStrings.getString("TEAM_DETECTED_REPO_GIT"); repoName = GITRemoteRepository.guessRepoName(url); @@ -190,6 +192,7 @@ public class NewTeamProject extends javax.swing.JDialog { resultText = OStrings.getString("TEAM_DETECTED_REPO_SVN"); repoName = SVNRemoteRepository.guessRepoName(url); } + */ } } catch (CancellationException ex) { resultText = " "; diff --git a/src/org/omegat/gui/main/ProjectUICommands.java b/src/org/omegat/gui/main/ProjectUICommands.java index b815c19..bc27d5a 100644 --- a/src/org/omegat/gui/main/ProjectUICommands.java +++ b/src/org/omegat/gui/main/ProjectUICommands.java @@ -45,10 +45,8 @@ import org.omegat.core.KnownException; import org.omegat.core.data.ProjectFactory; import org.omegat.core.data.ProjectProperties; import org.omegat.core.events.IProjectEventListener; -import org.omegat.core.team.GITRemoteRepository; import org.omegat.core.team.IRemoteRepository; import org.omegat.core.team.RepositoryUtils; -import org.omegat.core.team.SVNRemoteRepository; import org.omegat.gui.dialogs.NewProjectFileChooser; import org.omegat.gui.dialogs.NewTeamProject; import org.omegat.gui.dialogs.ProjectPropertiesDialog; @@ -296,12 +294,12 @@ public class ProjectUICommands { if (Core.getParams().containsKey(CLIParameters.NO_TEAM)) { // disable team functionality repository = null; - } else if (SVNRemoteRepository.isSVNDirectory(projectRootFolder)) { + } /* else if (SVNRemoteRepository.isSVNDirectory(projectRootFolder)) { // SVN selected repository = new SVNRemoteRepository(projectRootFolder); } else if (GITRemoteRepository.isGITDirectory(projectRootFolder)) { repository = new GITRemoteRepository(projectRootFolder); - } else { + } */ else { repository = null; } } catch (Exception e) { diff --git a/src/org/omegat/languagetools/LanguageToolWrapper.java b/src/org/omegat/languagetools/LanguageToolWrapper.java deleted file mode 100644 index a57224c..0000000 --- a/src/org/omegat/languagetools/LanguageToolWrapper.java +++ /dev/null @@ -1,186 +0,0 @@ -/************************************************************************** - OmegaT - Computer Assisted Translation (CAT) tool - with fuzzy matching, translation memory, keyword search, - glossaries, and translation leveraging into updated projects. - - Copyright (C) 2010-2013 Alex Buloichik - 2015 Aaron Madlon-Kay - Home page: http://www.omegat.org/ - Support center: http://groups.yahoo.com/group/OmegaT/ - - This file is part of OmegaT. - - OmegaT is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OmegaT is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - **************************************************************************/ - -package org.omegat.languagetools; - -import java.util.ArrayList; -import java.util.List; - -import javax.swing.text.Highlighter.HighlightPainter; - -import org.languagetool.JLanguageTool; -import org.languagetool.Language; -import org.languagetool.rules.RuleMatch; -import org.languagetool.rules.bitext.BitextRule; -import org.languagetool.rules.bitext.DifferentLengthRule; -import org.languagetool.rules.bitext.SameTranslationRule; -import org.languagetool.tools.Tools; -import org.omegat.core.Core; -import org.omegat.core.CoreEvents; -import org.omegat.core.data.SourceTextEntry; -import org.omegat.core.events.IProjectEventListener; -import org.omegat.gui.editor.UnderlineFactory; -import org.omegat.gui.editor.mark.IMarker; -import org.omegat.gui.editor.mark.Mark; -import org.omegat.util.Log; -import org.omegat.util.gui.Styles; - -/** - * Marker implementation for LanguageTool support. - * - * Bilingual check described <a href= - * "http://languagetool.wikidot.com/checking-translations-bilingual-texts">here - * </a> - * - * @author Alex Buloichik (alex73mail@gmail.com) - * @author Aaron Madlon-Kay - */ -public class LanguageToolWrapper implements IMarker, IProjectEventListener { - protected static final HighlightPainter PAINTER = new UnderlineFactory.WaveUnderline(Styles.EditorColor.COLOR_LANGUAGE_TOOLS.getColor()); - - private JLanguageTool sourceLt, targetLt; - private List<BitextRule> bRules; - - public LanguageToolWrapper() throws Exception { - CoreEvents.registerProjectChangeListener(this); - } - - public boolean isEnabled() { - return Core.getEditor().getSettings().isMarkLanguageChecker(); - } - - public synchronized void onProjectChanged(PROJECT_CHANGE_TYPE eventType) { - switch (eventType) { - case CREATE: - case LOAD: - Language sourceLang = getLTLanguage(Core.getProject().getProjectProperties().getSourceLanguage()); - Language targetLang = getLTLanguage(Core.getProject().getProjectProperties().getTargetLanguage()); - sourceLt = getLanguageToolInstance(sourceLang); - targetLt = getLanguageToolInstance(targetLang); - if (sourceLt != null && targetLt != null) { - bRules = getBiTextRules(sourceLang, targetLang); - } - break; - case CLOSE: - sourceLt = null; - targetLt = null; - break; - default: - // Nothing - } - } - - protected JLanguageTool getLanguageToolInstance(Language ltLang) { - JLanguageTool result = null; - - if (ltLang != null) { - try { - result = new JLanguageTool(ltLang); - result.activateDefaultPatternRules(); - } catch (Exception ex) { - result = null; - Log.log(ex); - } - } - - return result; - } - - @Override - public synchronized List<Mark> getMarksForEntry(SourceTextEntry ste, String sourceText, String translationText, - boolean isActive) throws Exception { - if (translationText == null || !isEnabled()) { - return null; - } - - JLanguageTool ltSource = sourceLt; - JLanguageTool ltTarget = targetLt; - if (ltTarget == null) { - // LT doesn't know anything about target language - return null; - } - - List<Mark> r = new ArrayList<Mark>(); - List<RuleMatch> matches; - if (ltSource != null && bRules != null) { - // LT knows about source and target languages both and has bitext rules. - - // sourceText represents the displayed source text: it may be null (not displayed) or have extra - // bidi characters for display. Since we need it for linguistic comparison here, if it's null then - // we pull from the SourceTextEntry, which is guaranteed not to be null. - matches = Tools.checkBitext(sourceText == null ? ste.getSrcText() : sourceText, translationText, - ltSource, ltTarget, bRules); - } else { - // LT knows about target language only - matches = ltTarget.check(translationText); - } - - for (RuleMatch match : matches) { - Mark m = new Mark(Mark.ENTRY_PART.TRANSLATION, match.getFromPos(), match.getToPos()); - m.toolTipText = match.getMessage(); - m.painter = PAINTER; - r.add(m); - } - - return r; - } - - private Language getLTLanguage(org.omegat.util.Language lang) { - String omLang = lang.getLanguageCode(); - for (Language ltLang : Language.LANGUAGES) { - if (omLang.equalsIgnoreCase(ltLang.getShortName())) { - return ltLang; - } - } - return null; - } - - /** - * Retrieve bitext rules for specified languages, but remove some rules, which not required in OmegaT - */ - private List<BitextRule> getBiTextRules(Language sourceLang, Language targetLang) { - List<BitextRule> result; - try { - result = Tools.getBitextRules(sourceLang, targetLang); - } catch (Exception ex) { - // bitext rules can be not defined - return null; - } - for (int i = 0; i < result.size(); i++) { - if (result.get(i) instanceof DifferentLengthRule) { - result.remove(i); - i--; - continue; - } - if (result.get(i) instanceof SameTranslationRule) { - result.remove(i); - i--; - continue; - } - } - return result; - } -} diff --git a/src/org/omegat/tokenizer/LuceneKoreanTokenizer.java b/src/org/omegat/tokenizer/LuceneKoreanTokenizer.java deleted file mode 100644 index 5c639a7..0000000 --- a/src/org/omegat/tokenizer/LuceneKoreanTokenizer.java +++ /dev/null @@ -1,68 +0,0 @@ -/************************************************************************** - OmegaT - Computer Assisted Translation (CAT) tool - with fuzzy matching, translation memory, keyword search, - glossaries, and translation leveraging into updated projects. - - Copyright (C) 2014 Aaron Madlon-Kay - Home page: http://www.omegat.org/ - Support center: http://groups.yahoo.com/group/OmegaT/ - - This file is part of OmegaT. - - OmegaT is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OmegaT is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - **************************************************************************/ -package org.omegat.tokenizer; - -import java.io.StringReader; -import java.util.Collections; -import java.util.Set; - -import org.apache.lucene.analysis.TokenStream; -import org.apache.lucene.analysis.kr.KoreanAnalyzer; -import org.apache.lucene.analysis.kr.KoreanTokenizer; - -/** - * This uses the Korean tokenizer currently under development for inclusion in - * Lucene (but not yet incorporated). - * <p> - * The code quality appears to be poor at the moment (see LUCENE-4956 thread; - * spurious ArrayIndexOutOfBoundsException errors observable in normal usage - * within OmegaT) so {@link Tokenizer#isDefault()} is currently - * <code>false</code>. - * - * @see <a href="http://sourceforge.net/projects/lucenekorean/">SourceForge - * project</a> - * @see <a href="http://cafe.naver.com/korlucene">Korean site</a> - * @see <a href="https://issues.apache.org/jira/browse/LUCENE-4956">Lucene - * issue</a> - * - * @author Aaron Madlon-Kay - */ -@Tokenizer(languages = { "ko" }) -public class LuceneKoreanTokenizer extends BaseTokenizer { - - @SuppressWarnings("resource") - @Override - protected TokenStream getTokenStream(final String strOrig, - final boolean stemsAllowed, final boolean stopWordsAllowed) { - if (stemsAllowed) { - Set<?> stopWords = stopWordsAllowed ? KoreanAnalyzer.STOP_WORDS_SET - : Collections.emptySet(); - return new KoreanAnalyzer(getBehavior(), stopWords).tokenStream("", - new StringReader(strOrig)); - } else { - return new KoreanTokenizer(getBehavior(), new StringReader(strOrig)); - } - } -} diff --git a/src/org/omegat/tokenizer/TinySegmenterJapaneseTokenizer.java b/src/org/omegat/tokenizer/TinySegmenterJapaneseTokenizer.java deleted file mode 100644 index 8573bc9..0000000 --- a/src/org/omegat/tokenizer/TinySegmenterJapaneseTokenizer.java +++ /dev/null @@ -1,101 +0,0 @@ -/************************************************************************** - OmegaT - Computer Assisted Translation (CAT) tool - with fuzzy matching, translation memory, keyword search, - glossaries, and translation leveraging into updated projects. - - Copyright (C) 2013 Aaron Madlon-Kay - Home page: http://www.omegat.org/ - Support center: http://groups.yahoo.com/group/OmegaT/ - - This file is part of OmegaT. - - OmegaT is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OmegaT is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - **************************************************************************/ - -package org.omegat.tokenizer; - -import java.io.IOException; -import java.io.StringReader; -import java.util.Collections; -import java.util.Set; - -import net.moraleboost.io.BasicCodePointReader; -import net.moraleboost.io.CodePointReader; -import net.moraleboost.tinysegmenter.TinySegmenter; - -import org.apache.lucene.analysis.StopFilter; -import org.apache.lucene.analysis.TokenStream; -import org.apache.lucene.analysis.cjk.CJKAnalyzer; -import org.apache.lucene.analysis.tokenattributes.CharTermAttribute; -import org.apache.lucene.analysis.tokenattributes.OffsetAttribute; - -/** - * A tokenizer based on <a href="http://chasen.org/~taku/software/TinySegmenter/">TinySegmenter by Taku Kudo</a>. - * - * This implementation uses the <a href="http://code.google.com/p/cmecab-java/source/browse/trunk/src/net/moraleboost/tinysegmenter/"> - * Java port by Kohei Taketa</a>. - * - * For stopword filtering we borrow the facilities provided - * by {@link CJKAnalyzer} and {@link StopFilter}. - * - * @author Aaron Madlon-Kay - * - */ -@Tokenizer(languages = { "ja" }) -public class TinySegmenterJapaneseTokenizer extends BaseTokenizer { - - public TinySegmenterJapaneseTokenizer() { - super(); - shouldDelegateTokenizeExactly = false; - } - - @Override - protected TokenStream getTokenStream(String strOrig, boolean stemsAllowed, - boolean stopWordsAllowed) { - - TokenStream ts = new TokenStreamWrapper(new BasicCodePointReader(new StringReader(strOrig))); - - if (stemsAllowed) { - Set<?> stopWords = stopWordsAllowed ? CJKAnalyzer.getDefaultStopSet() - : Collections.emptySet(); - return new StopFilter(getBehavior(), ts, stopWords); - } - - return ts; - } - - /** - * Wrap a {@link TinySegmenter} to behave like a {@link TokenStream}. - */ - public static class TokenStreamWrapper extends TokenStream { - private TinySegmenter ts; - private CharTermAttribute termAttr; - private OffsetAttribute offAttr; - - public TokenStreamWrapper(CodePointReader reader) { - ts = new TinySegmenter(reader); - termAttr = addAttribute(CharTermAttribute.class); - offAttr = addAttribute(OffsetAttribute.class); - } - - public boolean incrementToken() throws IOException { - TinySegmenter.Token token = ts.next(); - if (token == null) return false; - termAttr.setEmpty(); - termAttr.append(token.str); - offAttr.setOffset((int) token.start, (int) token.end); - return true; - } - } -} |