Search in sources :

Example 11 with ProjectProperties

use of org.omegat.core.data.ProjectProperties in project omegat by omegat-org.

the class ProjectFileStorageTest method testMissingDirs.

@Test
public void testMissingDirs() throws Exception {
    // Older project files can be missing path definitions, in which case
    // we should fall back to the default values.
    File projFile = new File(PROJECT_DIR, "missingdirs.project");
    ProjectProperties props = ProjectFileStorage.loadPropertiesFile(tempDir, projFile);
    assertTrue(props.getSourceRoot().endsWith(OConsts.DEFAULT_SOURCE + '/'));
    assertTrue(props.getTargetRoot().endsWith(OConsts.DEFAULT_TARGET + '/'));
    assertTrue(props.getDictRoot().endsWith(OConsts.DEFAULT_DICT + '/'));
    assertTrue(props.getGlossaryRoot().endsWith(OConsts.DEFAULT_GLOSSARY + '/'));
    assertTrue(props.getTMRoot().endsWith(OConsts.DEFAULT_TM + '/'));
}
Also used : ProjectProperties(org.omegat.core.data.ProjectProperties) File(java.io.File) Test(org.junit.Test)

Example 12 with ProjectProperties

use of org.omegat.core.data.ProjectProperties in project omegat by omegat-org.

the class ProjectFileStorageTest method testNearAbsolutePaths.

@Test
public void testNearAbsolutePaths() throws Exception {
    File projFile = new File(PROJECT_DIR, "defaultdirs.project");
    Omegat omt = ProjectFileStorage.parseProjectFile(projFile);
    for (int i = 0; i < OConsts.MAX_PARENT_DIRECTORIES_ABS2REL; i++) {
        String prefix = repeat(i, "a/");
        File projRoot = Paths.get(tempDir.getAbsolutePath(), prefix, "root").toFile();
        projRoot.mkdirs();
        // Set project folders to absolute paths
        File srcDir = new File(tempDir, "source").getAbsoluteFile();
        File trgDir = new File(tempDir, "target").getAbsoluteFile();
        File dictDir = new File(tempDir, "dictionary").getAbsoluteFile();
        File glosDir = new File(tempDir, "glossary").getAbsoluteFile();
        File tmDir = new File(tempDir, "tm").getAbsoluteFile();
        omt.getProject().setSourceDir(srcDir.getPath());
        omt.getProject().setTargetDir(trgDir.getPath());
        omt.getProject().setDictionaryDir(dictDir.getPath());
        omt.getProject().setGlossaryDir(glosDir.getPath());
        omt.getProject().setTmDir(tmDir.getPath());
        // Make all the actual folders
        Arrays.asList(srcDir, trgDir, dictDir, glosDir, tmDir).forEach(File::mkdirs);
        // Load the ProjectProperties and verify that the project folders
        // are resolved correctly
        ProjectProperties props = ProjectFileStorage.loadPropertiesFile(projRoot, omt);
        props.verifyProject();
        // Write the project file out and read it again to make sure the
        // paths are correctly round-tripped. Since these are "near" paths
        // they should become relative and not be absolute.
        ProjectFileStorage.writeProjectFile(props);
        File outProjFile = new File(projRoot, OConsts.FILE_PROJECT);
        assertTrue(outProjFile.isFile());
        Omegat outOmt = ProjectFileStorage.parseProjectFile(outProjFile);
        String relPrefix = repeat(i + 1, "../");
        assertEquals(relPrefix + srcDir.getName(), outOmt.getProject().getSourceDir());
        assertEquals(relPrefix + trgDir.getName(), outOmt.getProject().getTargetDir());
        assertEquals(relPrefix + dictDir.getName(), outOmt.getProject().getDictionaryDir());
        assertEquals(relPrefix + glosDir.getName(), outOmt.getProject().getGlossaryDir());
        assertEquals(relPrefix + tmDir.getName(), outOmt.getProject().getTmDir());
    }
}
Also used : ProjectProperties(org.omegat.core.data.ProjectProperties) File(java.io.File) Omegat(gen.core.project.Omegat) Test(org.junit.Test)

Example 13 with ProjectProperties

use of org.omegat.core.data.ProjectProperties in project omegat by omegat-org.

the class TeamTool method initTeamProject.

/**
 * Utility function to create a minimal project to serve as a base for a
 * team project. Will add/stage everything if invoked on a path already
 * containing a git working tree or svn checkout.
 *
 * @param dir
 *            Directory in which to create team project
 * @param srcLang
 *            Source language
 * @param trgLang
 *            Target language
 * @param showGui
 *            If true, show the Project Properties dialog
 * @throws Exception
 *             If specified dir is not a directory, is not writeable, etc.
 */
public static void initTeamProject(File dir, String srcLang, String trgLang) throws Exception {
    if (!dir.isDirectory()) {
        throw new IllegalArgumentException("Specified dir is not a directory: " + dir.getPath());
    }
    if (!dir.canWrite()) {
        throw new IOException("Specified dir is not writeable: " + dir.getPath());
    }
    // Create project properties
    ProjectProperties props = new ProjectProperties(dir);
    props.setSourceLanguage(srcLang);
    props.setTargetLanguage(trgLang);
    // Set default tokenizers
    props.setSourceTokenizer(PluginUtils.getTokenizerClassForLanguage(new Language(srcLang)));
    props.setTargetTokenizer(PluginUtils.getTokenizerClassForLanguage(new Language(trgLang)));
    // Create project internal directories
    props.autocreateDirectories();
    // Create version-controlled glossary file
    props.getWritableGlossaryFile().getAsFile().createNewFile();
    ProjectFileStorage.writeProjectFile(props);
    // Create empty project TM
    new ProjectTMX(props.getSourceLanguage(), props.getTargetLanguage(), props.isSentenceSegmentingEnabled(), null, null).save(props, new File(props.getProjectInternal(), OConsts.STATUS_EXTENSION).getPath(), false);
    // and set EOL handling correctly for cross-platform work
    if (new File(dir, ".svn").isDirectory()) {
        SVNClientManager mgr = SVNClientManager.newInstance();
        mgr.getWCClient().doSetProperty(dir, "svn:auto-props", SVNPropertyValue.create("*.txt = svn:eol-style=native\n*.tmx = svn:eol-style=native\n"), false, SVNDepth.EMPTY, null, null);
        mgr.getWCClient().doAdd(dir.listFiles(f -> !f.getName().startsWith(".")), false, false, true, SVNDepth.fromRecurse(true), false, false, false, true);
    } else if (new File(dir, ".git").isDirectory()) {
        try (BufferedWriter writer = Files.newBufferedWriter(new File(dir, ".gitattributes").toPath())) {
            writer.write("* text=auto\n");
            writer.write("*.tmx text\n");
            writer.write("*.txt text\n");
        }
        Git.open(dir).add().addFilepattern(".").call();
    }
    System.out.println(StringUtil.format(OStrings.getString("TEAM_TOOL_INIT_COMPLETE"), srcLang, trgLang));
}
Also used : ProjectTMX(org.omegat.core.data.ProjectTMX) OConsts(org.omegat.util.OConsts) Arrays(java.util.Arrays) ProjectProperties(org.omegat.core.data.ProjectProperties) Files(java.nio.file.Files) BufferedWriter(java.io.BufferedWriter) CLIParameters(org.omegat.CLIParameters) Log(org.omegat.util.Log) SVNDepth(org.tmatesoft.svn.core.SVNDepth) IOException(java.io.IOException) Language(org.omegat.util.Language) PluginUtils(org.omegat.filters2.master.PluginUtils) SVNClientManager(org.tmatesoft.svn.core.wc.SVNClientManager) File(java.io.File) Level(java.util.logging.Level) StringUtil(org.omegat.util.StringUtil) ProjectTMX(org.omegat.core.data.ProjectTMX) OStrings(org.omegat.util.OStrings) SVNPropertyValue(org.tmatesoft.svn.core.SVNPropertyValue) ProjectFileStorage(org.omegat.util.ProjectFileStorage) Git(org.eclipse.jgit.api.Git) Collections(java.util.Collections) Preferences(org.omegat.util.Preferences) Language(org.omegat.util.Language) IOException(java.io.IOException) ProjectProperties(org.omegat.core.data.ProjectProperties) File(java.io.File) SVNClientManager(org.tmatesoft.svn.core.wc.SVNClientManager) BufferedWriter(java.io.BufferedWriter)

Example 14 with ProjectProperties

use of org.omegat.core.data.ProjectProperties in project omegat by omegat-org.

the class ExternalFinder method getProjectFile.

/**
 * Get the project-specific config file. In the original plugin this was
 * stored in the project root ({@link ProjectProperties#getProjectRoot()});
 * now it's in the <code>omegat</code> directory for consistency with other
 * project-specific config files.
 */
private static File getProjectFile(IProject project) {
    ProjectProperties projectProperties = project.getProjectProperties();
    File projectRoot = projectProperties.getProjectInternalDir();
    return new File(projectRoot, FINDER_FILE);
}
Also used : ProjectProperties(org.omegat.core.data.ProjectProperties) File(java.io.File)

Example 15 with ProjectProperties

use of org.omegat.core.data.ProjectProperties in project omegat by omegat-org.

the class ProjectFileStorage method loadPropertiesFile.

static ProjectProperties loadPropertiesFile(File projectDir, Omegat om) throws Exception {
    if (!projectDir.isDirectory()) {
        throw new IllegalArgumentException("Project directory was not a directory");
    }
    ProjectProperties result = new ProjectProperties(projectDir);
    if (!OConsts.PROJ_CUR_VERSION.equals(om.getProject().getVersion())) {
        throw new TranslationException(StringUtil.format(OStrings.getString("PFR_ERROR_UNSUPPORTED_PROJECT_VERSION"), om.getProject().getVersion()));
    }
    result.setTargetRoot(normalizeLoadedPath(om.getProject().getTargetDir(), OConsts.DEFAULT_TARGET));
    result.setSourceRoot(normalizeLoadedPath(om.getProject().getSourceDir(), OConsts.DEFAULT_SOURCE));
    result.getSourceRootExcludes().clear();
    if (om.getProject().getSourceDirExcludes() != null) {
        result.getSourceRootExcludes().addAll(om.getProject().getSourceDirExcludes().getMask());
    } else {
        // sourceRootExclude was not defined
        result.getSourceRootExcludes().addAll(ProjectProperties.getDefaultExcludes());
    }
    result.setTMRoot(normalizeLoadedPath(om.getProject().getTmDir(), OConsts.DEFAULT_TM));
    result.setGlossaryRoot(normalizeLoadedPath(om.getProject().getGlossaryDir(), OConsts.DEFAULT_GLOSSARY));
    // Compute glossary file location
    String glossaryFile = om.getProject().getGlossaryFile();
    if (StringUtil.isEmpty(glossaryFile)) {
        glossaryFile = DEFAULT_FOLDER_MARKER;
    }
    if (glossaryFile.equalsIgnoreCase(DEFAULT_FOLDER_MARKER)) {
        glossaryFile = result.computeDefaultWriteableGlossaryFile();
    } else {
        glossaryFile = result.getGlossaryDir().getAsString() + glossaryFile;
    }
    result.setWriteableGlossary(glossaryFile);
    result.setDictRoot(normalizeLoadedPath(om.getProject().getDictionaryDir(), OConsts.DEFAULT_DICT));
    result.setSourceLanguage(om.getProject().getSourceLang());
    result.setTargetLanguage(om.getProject().getTargetLang());
    result.setSourceTokenizer(loadTokenizer(om.getProject().getSourceTok(), result.getSourceLanguage()));
    result.setTargetTokenizer(loadTokenizer(om.getProject().getTargetTok(), result.getTargetLanguage()));
    if (om.getProject().isSentenceSeg() != null) {
        result.setSentenceSegmentingEnabled(om.getProject().isSentenceSeg());
    }
    if (om.getProject().isSupportDefaultTranslations() != null) {
        result.setSupportDefaultTranslations(om.getProject().isSupportDefaultTranslations());
    }
    if (om.getProject().isRemoveTags() != null) {
        result.setRemoveTags(om.getProject().isRemoveTags());
    }
    if (om.getProject().getExternalCommand() != null) {
        result.setExternalCommand(om.getProject().getExternalCommand());
    }
    if (om.getProject().getRepositories() != null) {
        result.setRepositories(om.getProject().getRepositories().getRepository());
    }
    return result;
}
Also used : TranslationException(org.omegat.filters2.TranslationException) ProjectProperties(org.omegat.core.data.ProjectProperties)

Aggregations

ProjectProperties (org.omegat.core.data.ProjectProperties)29 File (java.io.File)20 Test (org.junit.Test)11 IOException (java.io.IOException)10 ExecutionException (java.util.concurrent.ExecutionException)6 KnownException (org.omegat.core.KnownException)6 Omegat (gen.core.project.Omegat)4 Cursor (java.awt.Cursor)4 List (java.util.List)4 Language (org.omegat.util.Language)4 ArrayList (java.util.ArrayList)3 NotLoadedProject (org.omegat.core.data.NotLoadedProject)3 ProjectPropertiesDialog (org.omegat.gui.dialogs.ProjectPropertiesDialog)3 RepositoryDefinition (gen.core.project.RepositoryDefinition)2 RepositoryMapping (gen.core.project.RepositoryMapping)2 InputStream (java.io.InputStream)2 Properties (java.util.Properties)2 ZipEntry (java.util.zip.ZipEntry)2 ZipFile (java.util.zip.ZipFile)2 Before (org.junit.Before)2