use of gen.core.project.Omegat in project omegat by omegat-org.
the class ProjectFileStorageTest method testFarRelativePaths.
@Test
public void testFarRelativePaths() throws Exception {
File projFile = new File(PROJECT_DIR, "defaultdirs.project");
Omegat omt = ProjectFileStorage.parseProjectFile(projFile);
String prefix = repeat(OConsts.MAX_PARENT_DIRECTORIES_ABS2REL, "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();
String relPrefix = repeat(OConsts.MAX_PARENT_DIRECTORIES_ABS2REL + 1, "../");
omt.getProject().setSourceDir(relPrefix + srcDir.getName());
omt.getProject().setTargetDir(relPrefix + trgDir.getName());
omt.getProject().setDictionaryDir(relPrefix + dictDir.getName());
omt.getProject().setGlossaryDir(relPrefix + glosDir.getName());
omt.getProject().setTmDir(relPrefix + tmDir.getName());
// 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();
// Indirections should be resolved.
assertFalse(props.getSourceRoot().contains("../"));
assertFalse(props.getTargetRoot().contains("../"));
assertFalse(props.getDictRoot().contains("../"));
assertFalse(props.getGlossaryRoot().contains("../"));
assertFalse(props.getTMRoot().contains("../"));
// Write the project file out and read it again to make sure the
// paths are correctly round-tripped. Since these are "far" paths
// they should become absolute and not remain relative.
ProjectFileStorage.writeProjectFile(props);
File outProjFile = new File(projRoot, OConsts.FILE_PROJECT);
assertTrue(outProjFile.isFile());
Omegat outOmt = ProjectFileStorage.parseProjectFile(outProjFile);
assertEquals(ProjectFileStorage.normalizeSlashes(srcDir.getPath()), outOmt.getProject().getSourceDir());
assertEquals(ProjectFileStorage.normalizeSlashes(trgDir.getPath()), outOmt.getProject().getTargetDir());
assertEquals(ProjectFileStorage.normalizeSlashes(dictDir.getPath()), outOmt.getProject().getDictionaryDir());
assertEquals(ProjectFileStorage.normalizeSlashes(glosDir.getPath()), outOmt.getProject().getGlossaryDir());
assertEquals(ProjectFileStorage.normalizeSlashes(tmDir.getPath()), outOmt.getProject().getTmDir());
}
use of gen.core.project.Omegat in project omegat by omegat-org.
the class ProjectFileStorageTest method testNearRelativePaths.
@Test
public void testNearRelativePaths() 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++) {
File projRoot = Paths.get(tempDir.getAbsolutePath(), repeat(i, "a/"), "root").toFile();
projRoot.mkdirs();
// Set project folders to relative 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();
String prefix = repeat(i + 1, "../");
omt.getProject().setSourceDir(prefix + srcDir.getName());
omt.getProject().setTargetDir(prefix + trgDir.getName());
omt.getProject().setDictionaryDir(prefix + dictDir.getName());
omt.getProject().setGlossaryDir(prefix + glosDir.getName());
omt.getProject().setTmDir(prefix + tmDir.getName());
// 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();
// Indirections should be resolved.
assertFalse(props.getSourceRoot().contains("../"));
assertFalse(props.getTargetRoot().contains("../"));
assertFalse(props.getDictRoot().contains("../"));
assertFalse(props.getGlossaryRoot().contains("../"));
assertFalse(props.getTMRoot().contains("../"));
// 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 remain relative and not absolute.
ProjectFileStorage.writeProjectFile(props);
File outProjFile = new File(projRoot, OConsts.FILE_PROJECT);
assertTrue(outProjFile.isFile());
Omegat outOmt = ProjectFileStorage.parseProjectFile(outProjFile);
assertEquals(prefix + srcDir.getName(), outOmt.getProject().getSourceDir());
assertEquals(prefix + trgDir.getName(), outOmt.getProject().getTargetDir());
assertEquals(prefix + dictDir.getName(), outOmt.getProject().getDictionaryDir());
assertEquals(prefix + glosDir.getName(), outOmt.getProject().getGlossaryDir());
assertEquals(prefix + tmDir.getName(), outOmt.getProject().getTmDir());
}
}
use of gen.core.project.Omegat 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());
}
}
use of gen.core.project.Omegat in project omegat by omegat-org.
the class ProjectFileStorage method writeProjectFile.
/**
* Saves project file to disk.
*/
public static void writeProjectFile(ProjectProperties props) throws Exception {
File outFile = new File(props.getProjectRoot(), OConsts.FILE_PROJECT);
String root = outFile.getAbsoluteFile().getParent();
Omegat om = new Omegat();
om.setProject(new Project());
om.getProject().setVersion(OConsts.PROJ_CUR_VERSION);
om.getProject().setSourceDir(getPathForStoring(root, props.getSourceRoot(), OConsts.DEFAULT_SOURCE));
om.getProject().setSourceDirExcludes(new Masks());
om.getProject().getSourceDirExcludes().getMask().addAll(props.getSourceRootExcludes());
om.getProject().setTargetDir(getPathForStoring(root, props.getTargetRoot(), OConsts.DEFAULT_TARGET));
om.getProject().setTmDir(getPathForStoring(root, props.getTMRoot(), OConsts.DEFAULT_TM));
String glossaryDir = getPathForStoring(root, props.getGlossaryRoot(), OConsts.DEFAULT_GLOSSARY);
om.getProject().setGlossaryDir(glossaryDir);
// Compute glossary file location: must be relative to glossary root
String glossaryFile = getPathForStoring(props.getGlossaryRoot(), props.getWriteableGlossary(), null);
if (glossaryDir.equalsIgnoreCase(DEFAULT_FOLDER_MARKER) && props.isDefaultWriteableGlossaryFile()) {
// Everything equals to default
glossaryFile = DEFAULT_FOLDER_MARKER;
}
om.getProject().setGlossaryFile(glossaryFile);
om.getProject().setDictionaryDir(getPathForStoring(root, props.getDictRoot(), OConsts.DEFAULT_DICT));
om.getProject().setSourceLang(props.getSourceLanguage().toString());
om.getProject().setTargetLang(props.getTargetLanguage().toString());
om.getProject().setSourceTok(props.getSourceTokenizer().getCanonicalName());
om.getProject().setTargetTok(props.getTargetTokenizer().getCanonicalName());
om.getProject().setSentenceSeg(props.isSentenceSegmentingEnabled());
om.getProject().setSupportDefaultTranslations(props.isSupportDefaultTranslations());
om.getProject().setRemoveTags(props.isRemoveTags());
om.getProject().setExternalCommand(props.getExternalCommand());
if (props.getRepositories() != null && !props.getRepositories().isEmpty()) {
om.getProject().setRepositories(new Repositories());
om.getProject().getRepositories().getRepository().addAll(props.getRepositories());
}
Marshaller m = CONTEXT.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
m.marshal(om, outFile);
}
use of gen.core.project.Omegat in project omegat by omegat-org.
the class ProjectFileStorageTest method testFarAbsolutePaths.
@Test
public void testFarAbsolutePaths() throws Exception {
File projFile = new File(PROJECT_DIR, "defaultdirs.project");
Omegat omt = ProjectFileStorage.parseProjectFile(projFile);
String prefix = repeat(OConsts.MAX_PARENT_DIRECTORIES_ABS2REL, "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 "far" paths
// they should remain absolute.
ProjectFileStorage.writeProjectFile(props);
File outProjFile = new File(projRoot, OConsts.FILE_PROJECT);
assertTrue(outProjFile.isFile());
Omegat outOmt = ProjectFileStorage.parseProjectFile(outProjFile);
assertEquals(ProjectFileStorage.normalizeSlashes(srcDir.getPath()), outOmt.getProject().getSourceDir());
assertEquals(ProjectFileStorage.normalizeSlashes(trgDir.getPath()), outOmt.getProject().getTargetDir());
assertEquals(ProjectFileStorage.normalizeSlashes(dictDir.getPath()), outOmt.getProject().getDictionaryDir());
assertEquals(ProjectFileStorage.normalizeSlashes(glosDir.getPath()), outOmt.getProject().getGlossaryDir());
assertEquals(ProjectFileStorage.normalizeSlashes(tmDir.getPath()), outOmt.getProject().getTmDir());
}
Aggregations