-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module type="PLUGIN_MODULE" version="4"> | ||
<component name="DevKit.ModuleBuildProperties" url="file://$MODULE_DIR$/resources/META-INF/plugin.xml" /> | ||
<component name="NewModuleRootManager" inherit-compiler-output="true"> | ||
<exclude-output /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> | ||
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" /> | ||
</content> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
<orderEntry type="library" name="io.codearte.props2yaml:props2yaml:0.4" level="project" /> | ||
</component> | ||
</module> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<idea-plugin version="2"> | ||
<id>io.codearte.props2yaml</id> | ||
<name>Properties to YAML Converter</name> | ||
<version>1.0</version> | ||
<vendor email="[email protected]" url="http://www.codearte.io">Codearte</vendor> | ||
|
||
<description><![CDATA[ | ||
Properties to YAML Converter | ||
]]></description> | ||
|
||
<change-notes><![CDATA[ | ||
Add change notes here.<br> | ||
<em>most HTML tags may be used</em> | ||
]]> | ||
</change-notes> | ||
|
||
<!-- please see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/build_number_ranges.html for description --> | ||
<idea-version since-build="141.0"/> | ||
|
||
<extensions defaultExtensionNs="com.intellij"> | ||
<!-- Add your extensions here --> | ||
</extensions> | ||
|
||
<actions> | ||
<!-- Add your actions here --> | ||
<action id="io.codearte.props2yaml.ConvertAction" class="io.codearte.props2yaml.ConvertAction" | ||
text="Convert Properties to YAML" description="Convert properties file to YAML"> | ||
<add-to-group group-id="CodeMenu" anchor="last"/> | ||
</action> | ||
</actions> | ||
|
||
</idea-plugin> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package io.codearte.props2yaml; | ||
|
||
import java.io.IOException; | ||
|
||
import com.intellij.notification.Notification; | ||
import com.intellij.notification.NotificationType; | ||
import com.intellij.notification.Notifications; | ||
import com.intellij.openapi.actionSystem.AnAction; | ||
import com.intellij.openapi.actionSystem.AnActionEvent; | ||
import com.intellij.openapi.actionSystem.LangDataKeys; | ||
import com.intellij.openapi.application.ApplicationManager; | ||
import com.intellij.openapi.fileTypes.StdFileTypes; | ||
import com.intellij.openapi.vfs.VirtualFile; | ||
import com.intellij.psi.PsiFile; | ||
|
||
/** | ||
* @author Jakub Kubrynski | ||
*/ | ||
public class ConvertAction extends AnAction { | ||
|
||
public static final String GROUP_DISPLAY_ID = "io.codearte.props2yaml"; | ||
|
||
@Override | ||
public void actionPerformed(AnActionEvent anActionEvent) { | ||
PsiFile selectedFile = anActionEvent.getData(LangDataKeys.PSI_FILE); | ||
if (selectedFile == null) { | ||
Notifications.Bus.notify(new Notification(GROUP_DISPLAY_ID, "No file selected", "Please select properties file first", NotificationType.ERROR)); | ||
return; | ||
} | ||
if (!StdFileTypes.PROPERTIES.equals(selectedFile.getFileType())) { | ||
Notifications.Bus.notify(new Notification(GROUP_DISPLAY_ID, "Incorrect file selected", "Please select properties file first", NotificationType.ERROR)); | ||
return; | ||
} | ||
|
||
VirtualFile propertiesFile = selectedFile.getVirtualFile(); | ||
ApplicationManager.getApplication().runWriteAction(() -> { | ||
try { | ||
String yamlContent = new Props2YAML(new String(propertiesFile.contentsToByteArray())).convert(); | ||
propertiesFile.rename(this, propertiesFile.getNameWithoutExtension() + ".yml"); | ||
propertiesFile.setBinaryContent(yamlContent.getBytes()); | ||
} catch (IOException e) { | ||
Notifications.Bus.notify(new Notification(GROUP_DISPLAY_ID, "Cannot rename file", e.getMessage(), NotificationType.ERROR)); | ||
} | ||
}); | ||
|
||
Notifications.Bus.notify(new Notification(GROUP_DISPLAY_ID, "File converted", "File converted successfully", NotificationType.INFORMATION)); | ||
} | ||
} |