From 7fc223c6025393aff76d42ac68f808cd08aa3551 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Briac=20Pilpr=C3=A9?= Date: Mon, 11 Mar 2019 13:16:39 +0100 Subject: [PATCH] ## [v1.0.1] ### Changed - Title of the Export OMT dialog - Empty directories have ".empty" files instead of ".ignore" files - If there are projects folder inside the project to package, they are skipped. - the Gradle task to install the plugin is `installPlugin`, but it requires you to change the `gradle.properties` file and modify the `omegatPluginDir`. ### Add - More logging when zipping the package. ### Fixed - Bug when zipping empty subdirectories, they would show up at the root of the package --- .gitignore | 1 + CHANGELOG.md | 21 ++++++++---- build.gradle | 9 +++-- gradle.properties | 5 ++- .../omegat/plugin/omt/ManageOMTPackage.java | 34 ++++++++++++++----- src/main/resources/omt-package.properties | 2 +- 6 files changed, 48 insertions(+), 24 deletions(-) diff --git a/.gitignore b/.gitignore index f4ef481..b37b2f5 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,4 @@ plugin-omt-package.iws .idea/misc.xml .idea/uiDesigner.xml .idea/vcs.xml +register_omt.reg diff --git a/CHANGELOG.md b/CHANGELOG.md index ca0e480..6602220 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,14 +1,21 @@ # Change Log -All notable changes to this project will be documented in this file. -## [Unreleased] - -### Add -- foo -- boo +## [v1.0.1] ### Changed +- Title of the Export OMT dialog +- Empty directories have ".empty" files instead of ".ignore" files +- If there are projects folder inside the project to package, they are skipped. + +- the Gradle task to install the plugin is `installPlugin`, but it requires you to change the `gradle.properties` file +and modify the `omegatPluginDir`. + +### Add +- More logging when zipping the package. + ### Fixed +- Bug when zipping empty subdirectories, they would show up at the root of the package + +## [v1.0.0] -[Unreleased]: https://github.com/miurahr/omegat-plugin-skelton/compare/v0.1...HEAD diff --git a/build.gradle b/build.gradle index 8b8f186..3c30086 100644 --- a/build.gradle +++ b/build.gradle @@ -5,6 +5,7 @@ plugins { id 'distribution' id 'maven' id 'idea' + id 'eclipse' } repositories { @@ -102,12 +103,10 @@ distributions { } } -task deployOmegaT(type: Copy) { - +task installPlugin(type: Copy) { from 'build/install/plugin-omt-package/plugin' - into omegatDir + into omegatPluginDir include('*.jar') - } -installDist.dependsOn deployOmegaT +installPlugin.dependsOn installDist diff --git a/gradle.properties b/gradle.properties index 3ac4057..7044575 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,4 @@ pluginMainClass=net.briac.omegat.plugin.omt.ManageOMTPackage pluginName=OMT Package Plugin -version=1.0.0 - -omegatDir=C:/Users/briac/AppData/Roaming/OmegaT/plugins/ \ No newline at end of file +version=1.0.1 +omegatPluginDir=C:/Users/briac/AppData/Roaming/OmegaT/plugins/ diff --git a/src/main/java/net/briac/omegat/plugin/omt/ManageOMTPackage.java b/src/main/java/net/briac/omegat/plugin/omt/ManageOMTPackage.java index a74a4c0..182c862 100644 --- a/src/main/java/net/briac/omegat/plugin/omt/ManageOMTPackage.java +++ b/src/main/java/net/briac/omegat/plugin/omt/ManageOMTPackage.java @@ -53,7 +53,7 @@ public class ManageOMTPackage { public static final String OMT_EXTENSION = ".omt"; - public static final String IGNORE_FILE = ".ignore"; + public static final String IGNORE_FILE = ".empty"; static final ResourceBundle res = ResourceBundle.getBundle("omt-package", Locale.getDefault()); private static JMenuItem importOMT; private static JMenuItem exportOMT; @@ -172,7 +172,7 @@ public static void projectExportOMT() { .endsWith(OMT_EXTENSION) ? ndm.getSelectedFile() : new File(ndm.getSelectedFile().getAbsolutePath() + OMT_EXTENSION); - Log.log("\n\n*******\n********\n"); + Log.log(String.format("Exporting OMT \"%s\"", omtFile.getAbsolutePath())); // Check and ask if the user wants to overwrite an existing package if (omtFile.exists()) { @@ -314,7 +314,7 @@ public static void createOmt(final File omtZip, final ProjectProperties props) t } BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(omtZip)); - + Log.log(String.format("Zipping to file [%s]", omtZip.getAbsolutePath())); try (ZipOutputStream out = new ZipOutputStream(bos)) { addZipDir(out, null, path, props); } @@ -334,24 +334,39 @@ private static final void addZipDir(final ZipOutputStream out, final Path root, final Path childPath = child.getFileName(); final String name = childPath.toFile().getName(); - if (name.endsWith(OConsts.BACKUP_EXTENSION) || name.endsWith(OMT_EXTENSION) + + // TODO - The list of excluded/included files should be read from a + // properties file in OmT config folder. + if (name.endsWith(".zip") || name.endsWith(OConsts.BACKUP_EXTENSION) || name.endsWith(OMT_EXTENSION) ) { // Skip .bak and .omt files continue; } - if (childPath.endsWith(OConsts.FILE_PROJECT)) { + + // Skip projects inside projects + if (Files.isDirectory(child) && new File(child.toFile(), OConsts.FILE_PROJECT).exists()) { + Log.log(String.format("The directory \"%s\" appears to be an OmegaT project, we'll skip it.", child.toFile().getAbsolutePath())); + continue; + } + + if (root == null && childPath.endsWith(OConsts.FILE_PROJECT)) { // Special case - when a project is opened, the project file is locked and // can't be copied directly. To avoid this, we make a temp copy. - File tmpProjectFile = File.createTempFile("omt", null, props.getProjectRootDir()); + // We name it with a .bak extension to make sure it's not included in the package. + File tmpProjectFile = File.createTempFile("omt", OConsts.BACKUP_EXTENSION, props.getProjectRootDir()); try { ProjectFileStorage.writeProjectFile(props, tmpProjectFile); } catch (Exception e) { throw new IOException(e); } + Log.log(String.format("addZipDir\tproject\t[%s]", OConsts.FILE_PROJECT)); out.putNextEntry(new ZipEntry(OConsts.FILE_PROJECT)); Files.copy(Paths.get(tmpProjectFile.getAbsolutePath()), out); out.closeEntry(); - tmpProjectFile.delete(); + boolean isTmpDeleted = tmpProjectFile.delete(); + if (!isTmpDeleted) { + Log.log(String.format("Could not delete temporary file \"%s\". You can safely delete it.", tmpProjectFile.getAbsolutePath())); + } continue; } @@ -360,11 +375,14 @@ private static final void addZipDir(final ZipOutputStream out, final Path root, // Before recursing, we add a ZipEntry for the directory to allow // empty dirs. if (child.toFile().listFiles().length == 0) { - out.putNextEntry(new ZipEntry(name + File.separatorChar + IGNORE_FILE)); + String emptyDirFile = entry.toString() + File.separatorChar + IGNORE_FILE; + Log.log(String.format("addZipDir\tempty\t[%s]", emptyDirFile)); + out.putNextEntry(new ZipEntry(emptyDirFile)); out.closeEntry(); } addZipDir(out, entry, child, props); } else { + Log.log(String.format("addZipDir\tfile\t[%s]", entry)); out.putNextEntry(new ZipEntry(entry.toString())); Files.copy(child, out); out.closeEntry(); diff --git a/src/main/resources/omt-package.properties b/src/main/resources/omt-package.properties index b576c91..c2188f9 100644 --- a/src/main/resources/omt-package.properties +++ b/src/main/resources/omt-package.properties @@ -22,7 +22,7 @@ omt.menu.import=Import OMT package... omt.menu.export=Export OMT package... omt.chooser.import=Select the OMT package to import -omt.chooser.export=Select the OMT package to export +omt.chooser.export=Select location and name of the OMT export omt.chooser.filter=OMT Package file omt.invalid.package=Invalid OMT package, file "omegat.project" is missing. omt.update.package=Updating current project with OMT package content