Skip to content

Commit

Permalink
Update to version 1.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Elhussein-Hamed committed Jan 22, 2023
1 parent 4adac14 commit e1151b8
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 22 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
# PostmanToRetrofit2
This is an Android Studio plugin which can generate Retrofit2's Java/Kotlin code from Postman's collection.

## Features:
<ul>
<li>Supports RxJava and Coroutines with Retrofit2</li>
<li>Class generation and selection for each request in the collection from the directory of your choice</li>
<li>Automatic class generation from saved responses in a collection</li>
<li>Sub-collections within a collection handling</li>
<li>Postman Url parameters (i.e. :param) handling</li>
<li>Postman form-data, form-urlencoded and raw body types handling</li>
<li>GUI to help selecting the Postman collection from the file system and to choose the conversion settings</li>
<li>mnemonics support in the GUI</li>
<li>Saving the last user settings per project</li>
</ul>

## Install
### From Android Studio plugin marketplace
Open Android Studio:
Expand Down
9 changes: 4 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group = "com.hamed"
version = "1.5.3-beta"
version = "1.6.0"

repositories {
mavenCentral()
Expand All @@ -15,16 +15,15 @@ repositories {
// Configure Gradle IntelliJ Plugin
// Read more: https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html
intellij {
version.set("2022.2.4")
version.set("2022.2")
type.set("IC") // Target IDE Platform

plugins.set(listOf("com.robohorse.robopojogenerator:2.3.8"))
plugins.set(listOf("com.robohorse.robopojogenerator:2.4.0"))
}

dependencies {

implementation("com.squareup.okhttp3:okhttp:4.10.0")
implementation("com.fifesoft:rsyntaxtextarea:3.3.0")
implementation("com.fifesoft:rsyntaxtextarea:3.3.1")
}

tasks {
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/com/hamed/postmantoretrofit2v2/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.hamed.postmantoretrofit2v2.gsondeserialisers.RequestJsonDeserializer;
import com.hamed.postmantoretrofit2v2.gsondeserialisers.UrlJsonDeserializer;
import com.hamed.postmantoretrofit2v2.pluginstate.helperclasses.enums.Language;
import com.hamed.postmantoretrofit2v2.utils.DependencyPluginHelper;
import com.hamed.postmantoretrofit2v2.utils.RetrofitSyntaxHelper;
import com.hamed.postmantoretrofit2v2.utils.Utils;
import com.intellij.openapi.command.WriteCommandAction;
Expand Down Expand Up @@ -62,7 +63,8 @@ public void generateRetrofitCode(Project project, Editor editor, List<Item> item
String returnTypeFormat = Utils.highlightReturnTypeWithHashes(userSettings.getReturnType());

if (userSettings.automaticallyGenerateClassesFromResponses())
generatedClasses = generateClassFromResponse(project, items, userSettings);
if (DependencyPluginHelper.isPluginUsable(project, "RoboPojoGenerator", "com.robohorse.robopojogenerator"))
generatedClasses = generateClassFromResponse(project, items, userSettings);

ArrayList<String> retrofitAnnotatedMethods = constructRetrofitAnnotatedMethods(items, isDynamicHeader, returnTypeFormat, userSettings.getLanguage(), userSettings.useCoroutines(), generatedClasses);

Expand Down Expand Up @@ -217,7 +219,12 @@ private String getApiPath(String url) {
String domain = uri.getHost();
url = url.replace("http://", "");
url = url.replace("https://", "");
url = url.replace(domain, "");

try {
url = url.replace(domain, "");
} catch (NullPointerException e) {
throw new NullPointerException("Couldn't get the domain for URL: " + uri + "\n" + e.getMessage());
}

// Replace all path variables
url = url.replaceAll(":(\\w+)", "{$1}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ import org.koin.core.context.GlobalContext
import org.koin.core.context.startKoin

class GenerationApp : KoinComponent {

private var controller: GeneratePOJOActionController

init {
GlobalContext.getOrNull() ?: startKoin {
modules(generatorModule)
}
}

private val controller: GeneratePOJOActionController = GeneratePOJOActionController(GlobalContext.get().get())
controller = GeneratePOJOActionController(GlobalContext.get().get())
}

fun generate(model: GenerationModel, projectModel: ProjectModel) {
controller.generate(model, projectModel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.hamed.postmantoretrofit2v2.pluginstate.helperclasses.AutomaticClassGenerationOptions;
import com.hamed.postmantoretrofit2v2.pluginstate.helperclasses.enums.Framework;
import com.hamed.postmantoretrofit2v2.pluginstate.helperclasses.enums.Language;
import com.hamed.postmantoretrofit2v2.utils.DependencyPluginHelper;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.ui.Messages;
Expand All @@ -24,9 +23,6 @@ public static boolean generateClasses(Project project, String directory, String
// "{\n \"userId\": 1,\n \"id\": 1,\n \"title\": \"sunt aut facere repellat provident occaecati excepturi optio reprehenderit\",\n \"body\": \"quia et suscipit\\nsuscipit recusandae consequuntur expedita et cum\\nreprehenderit molestiae ut ut quas totam\\nnostrum rerum est autem sunt rem eveniet architecto\"\n}"
//responseBody = "{\n \"userId\": 1,\n \"id\": 1,\n \"title\": \"sunt aut facere repellat provident occaecati excepturi optio reprehenderit\",\n \"body\": \"quia et suscipit\\nsuscipit recusandae consequuntur expedita et cum\\nreprehenderit molestiae ut ut quas totam\\nnostrum rerum est autem sunt rem eveniet architecto\"\n}";

if (!DependencyPluginHelper.isPluginUsable(project, "RoboPojoGenerator", "com.robohorse.robopojogenerator"))
return false;

try {
// Prepare the generation model
GenerationModel generationModel = new GenerationModel(
Expand Down Expand Up @@ -74,12 +70,14 @@ public static boolean generateClasses(Project project, String directory, String
"Parsing Json Failure", Messages.getWarningIcon());
}

return true;

} catch (NoClassDefFoundError ex) {
// Restart the IDE
Messages.showMessageDialog(project, "Error calling RoboPojoGenerator plugin, please restart the IDE", "Plugin Requires Restart", Messages.getWarningIcon());
}

return true;
return false;
}

private static FrameworkVW getFrameworkVW(Framework framework)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Library/Framework:"/>
<labelFor value="cfced"/>
<text resource-bundle="labels" key="OptionsDialog.Label.Framework"/>
</properties>
</component>
<component id="cfced" class="javax.swing.JComboBox" binding="frameworkComboBox" custom-create="true">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.intellij.openapi.extensions.PluginId;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.robohorse.robopojogenerator.models.FrameworkVW;

public class DependencyPluginHelper {

Expand All @@ -25,7 +26,7 @@ public static boolean isPluginUsable(Project project, String pluginName, String
if (doEnable) {
PluginManager.getInstance().enablePlugin(PluginId.getId(pluginId));
System.out.printf("Enabled %s plugin\n", pluginName);
ProjectUtils.restartIde();
return ProjectUtils.restartIde();
}
else
return false;
Expand All @@ -36,6 +37,16 @@ else if (!PluginManagerCore.isPluginInstalled(PluginId.getId(pluginId)))
Messages.showMessageDialog(project, String.format("Error %s plugin is not installed, please install it from the market place", pluginName), "Dependency Plugin Missing", Messages.getWarningIcon());
return false;
}

// Extra check in case the plugin was installed but the IDE was not restarted
try {
new FrameworkVW.Gson();
}
catch (NoClassDefFoundError e) {
System.out.println("Caught an exception");
Messages.showMessageDialog(project, String.format("%s plugin seems to be installed but IDE restart is required. Please restart the IDE.", pluginName), "IDE Restart Required", Messages.getWarningIcon());
return false;
}

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

public class ProjectUtils {

public static void restartIde()
public static boolean restartIde()
{
boolean result = Messages.showYesNoDialog(
"Would you like to restart the IDE?",
Expand All @@ -30,6 +30,8 @@ public static void restartIde()

app.restart(true);
}

return false;
}

public static ArrayList<ClassInfo> getClassesInDirectory(Project project, VirtualFile directory, ArrayList<ClassInfo> originalList)
Expand Down
25 changes: 21 additions & 4 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,30 @@
Simple HTML elements (text formatting, paragraphs, and lists) can be added inside of <![CDATA[ ]]> tag.
Guidelines: https://plugins.jetbrains.com/docs/marketplace/plugin-overview-page.html#plugin-description -->
<description><![CDATA[
Convert postman collection to Retrofit2 Java/Kotlin code<br>
This is a fork of <a href="https://plugins.jetbrains.com/plugin/11612-postman-to-retrofit2">Postman to Retrofit2</a>.<br>
This is an open source project, please check out the <a href="https://github.com/Elhussein-Hamed/PostmanToRetrofit2-v2">GitHup page</a>.
Any suggestions and improvements are most welcome!
<br>Convert postman collection to Retrofit2 Java/Kotlin code</br>
<b><br>Features:</br></b>
<ul>
<li>Retrofit2 with RxJava and Coroutines</li>
<li>Class generation and selection for each request in the collection from the directory of your choice</li>
<li>Automatic class generation from saved responses in a collection</li>
<li>Sub-collections within a collection handling</li>
<li>Postman Url parameters (i.e. :param) handling</li>
<li>Postman form-data, form-urlencoded and raw body types handling</li>
<li>GUI to help selecting the Postman collection from the file system and to choose the conversion settings</li>
<li>mnemonics in the GUI</li>
<li>Saving the last user settings per project</li>
</ul>
]]></description>

<change-notes><![CDATA[
<h2>1.6.0</h2>
<h3>New Features</h3>
<ul>
<li>Automatic class generation from saved responses in a collection</li>
</ul>
<h2>1.5.2</h2>
<h3>Improvements</h3>
<ul>
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/labels.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ OptionsDialog.RadioButtonText.RetrofitAndCoroutines=Retrofit + Coro&utines
ClassPickerDialog.Label.ChangeReturnType=Change return &type:
ClassPickerDialog.ButtonText.KeepDefault=Keep &Default
OptionsDialog.Label.GenerationOptions=Generation Options
OptionsDialog.CheckBoxText.AutomaticGenerate=Automatically generate classes from responses (only the first response is picked if exists)
OptionsDialog.CheckBoxText.AutomaticGenerate=<html>&Automatically generate classes from responses (only the first response is picked if exists) - <br> requires RoboPojoGenerator plugin to be installed
OptionsDialog.Label.Framework=Library/&Framework:

0 comments on commit e1151b8

Please sign in to comment.