Skip to content

Commit

Permalink
First version
Browse files Browse the repository at this point in the history
  • Loading branch information
jkubrynski committed Oct 26, 2015
1 parent 5eaaf73 commit 118a425
Show file tree
Hide file tree
Showing 11 changed files with 171 additions and 0 deletions.
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/copyright/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/libraries/io_codearte_props2yaml_props2yaml_0_4.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions props2yaml-idea-plugin.iml
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>
32 changes: 32 additions & 0 deletions resources/META-INF/plugin.xml
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>
48 changes: 48 additions & 0 deletions src/io/codearte/props2yaml/ConvertAction.java
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));
}
}

0 comments on commit 118a425

Please sign in to comment.