Skip to content

Commit

Permalink
Merge pull request #45 from GoodforGod/dev
Browse files Browse the repository at this point in the history
[2.0.0]
  • Loading branch information
GoodforGod authored Oct 27, 2022
2 parents 610ea92 + fb0e8af commit ec54df2
Show file tree
Hide file tree
Showing 60 changed files with 621 additions and 606 deletions.
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ Stack-trace from IDEA Event Log.
A clear and concise description of what the bug is.


**Java Class examples \ Screenshots**
Java Class example (fields, annotations, method, type or what is applicable in a situation).
**Class examples \ Screenshots**
Class example (fields, annotations, method, type or what is applicable in a situation).


**Expected Behavior**
Expand Down
32 changes: 24 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_DummyMapper&metric=reliability_rating)](https://sonarcloud.io/dashboard?id=GoodforGod_DummyMapper)

[Intellij IDEA plugin](https://plugins.jetbrains.com/plugin/14911-dummymapper-json-avro-graphql-/)
for mapping Java Classes to formats like [JSON](#json)/[AVRO](#avro-schema)/[GraphQL](#graphql)/etc.
for mapping Java or Kotlin Classes to format like [JSON](#json)/[AVRO](#avro-schema)/[GraphQL](#graphql)/etc.

![](https://media.giphy.com/media/VelLohLlWETYZBNWlt/giphy.gif)

Expand All @@ -31,7 +31,7 @@ for mapping Java Classes to formats like [JSON](#json)/[AVRO](#avro-schema)/[Gra

## Format Support

Plugin allow mapping Java Classes to different formats,
Plugin allow mapping Java or Kotlin Classes to different formats,
this section describes information about supported formats and their options.

All format examples will be showed according to this class as example.
Expand All @@ -52,11 +52,26 @@ public class User {
}
```

Supports also Kotlin classes:
```kotlin
data class ExampleData(val surname: String, val number: Int, val simple: ExampleSimple)

class ExampleSimple {

var en: ExampleEnum? = null
var name: String? = null
var data: ExampleData? = null
var surnames: List<String>? = null
var numbers: Map<String, Int>? = null
var names: Set<String>? = null
}
```

### Json

Plugin uses [DummyMaker library](https://github.com/GoodforGod/dummymaker) for producing Java Classes and then converting them in JSON format.
Plugin uses [DummyMaker library](https://github.com/GoodforGod/dummymaker) for generating classes and then converting to JSON format.

Allow mapping Java class as JSON example with fields filled with
Allow mapping class as JSON example with fields filled with
random values as if class example was serialized to JSON format.
- <kbd>Mapping options..</kbd> > <kbd>Map as JSON</kbd>

Expand Down Expand Up @@ -130,8 +145,9 @@ and their parameters are supported):

### Json Schema

Allow mapping Java class as JSON Schema, 3 different drafts are available:
- [Draft 2019](https://json-schema.org/draft/2019-09/schema)
Allow mapping class as JSON Schema, 3 different drafts are available:
- [Draft 2020-12](https://json-schema.org/draft/2020-12/release-notes.html)
- [Draft 2019-09](https://json-schema.org/draft/2019-09/release-notes.html)
- [Draft 7](https://json-schema.org/draft-07/json-schema-release-notes.html)
- [Draft 6](https://json-schema.org/draft-06/json-schema-release-notes.html)

Expand Down Expand Up @@ -174,7 +190,7 @@ Mapping is under:

### Avro Schema

Allow mapping Java class as AVRO Schema for [version 1.9.2](https://avro.apache.org/docs/1.9.2/)
Allow mapping class as AVRO Schema for [version 1.9.2](https://avro.apache.org/docs/1.9.2/)

There is option for two different AVRO Schema builders like:
- [Jackson](https://github.com/FasterXML/jackson-dataformats-binary/tree/master/avro)
Expand Down Expand Up @@ -248,7 +264,7 @@ Annotations from [Apache Avro](https://github.com/apache/avro/tree/master/lang/j

### GraphQL

Allow mapping Java class as GraphQL query with [version v14](https://www.graphql-java.com/documentation/v14)
Allow mapping class as GraphQL query with [version v14](https://www.graphql-java.com/documentation/v14)

Mapping is under:
- <kbd>Mapping options..</kbd> > <kbd>Map as GraphQL</kbd>
Expand Down
11 changes: 6 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
id "java-library"
id "maven-publish"

id "org.jetbrains.intellij" version "1.8.1"
id "org.jetbrains.intellij" version "1.9.0"
id "org.sonarqube" version "3.3"
id "com.diffplug.spotless" version "6.1.0"
}
Expand All @@ -20,7 +20,7 @@ sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

intellij {
plugins = ["java"]
plugins = ["java", "Kotlin"]
version = "2022.2"
downloadSources = false
}
Expand Down Expand Up @@ -66,11 +66,12 @@ configurations {
}

dependencies {
implementation "com.github.goodforgod:dummymaker:3.2.0"
implementation "org.javassist:javassist:3.29.0-GA"
implementation "com.github.goodforgod:dummymaker:3.3.1"
implementation "org.javassist:javassist:3.29.2-GA"
implementation "io.goodforgod:jackson-datetime-configuration:1.0.0"

implementation "com.fasterxml.jackson.dataformat:jackson-dataformat-avro:$jacksonVersion"
implementation "com.github.victools:jsonschema-generator:4.25.0"
implementation "com.github.victools:jsonschema-generator:4.27.0"
implementation "org.apache.avro:avro-compiler:1.9.2"
implementation "io.leangen.graphql:spqr:0.11.2"
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
groupId=com.github.goodforgod
artifactId=dummymapper
artifactVersion=1.4.0
artifactVersion=2.0.0


##### GRADLE #####
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.goodforgod.dummymapper;

import io.goodforgod.dummymapper.mapper.IMapper;
import io.goodforgod.dummymapper.mapper.impl.AvroApacheMapper;
import io.goodforgod.dummymapper.marker.MarkerMapper;
import io.goodforgod.dummymapper.marker.mapper.AvroApacheMapper;
import org.jetbrains.annotations.NotNull;

/**
Expand All @@ -12,11 +12,11 @@
*/
public class AvroSchemaApacheAction extends MapperAction {

private final IMapper mapper = new AvroApacheMapper();
private final MarkerMapper mapper = new AvroApacheMapper();

@NotNull
@Override
public IMapper getMapper() {
public MarkerMapper getMapper() {
return mapper;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.goodforgod.dummymapper;

import io.goodforgod.dummymapper.mapper.IMapper;
import io.goodforgod.dummymapper.mapper.impl.AvroJacksonMapper;
import io.goodforgod.dummymapper.marker.MarkerMapper;
import io.goodforgod.dummymapper.marker.mapper.AvroJacksonMapper;
import io.goodforgod.dummymapper.ui.config.AvroJacksonConfig;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -19,7 +19,7 @@ public class AvroSchemaJacksonAction extends MapperAction<AvroJacksonConfig> {

@NotNull
@Override
public IMapper<AvroJacksonConfig> getMapper() {
public MarkerMapper<AvroJacksonConfig> getMapper() {
return mapper;
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/goodforgod/dummymapper/GraphQLAction.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.goodforgod.dummymapper;

import io.goodforgod.dummymapper.mapper.IMapper;
import io.goodforgod.dummymapper.mapper.impl.GraphQLMapper;
import io.goodforgod.dummymapper.marker.MarkerMapper;
import io.goodforgod.dummymapper.marker.mapper.GraphQLMapper;
import io.goodforgod.dummymapper.ui.config.GraphQLConfig;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -19,7 +19,7 @@ public class GraphQLAction extends MapperAction<GraphQLConfig> {

@NotNull
@Override
public IMapper<GraphQLConfig> getMapper() {
public MarkerMapper<GraphQLConfig> getMapper() {
return mapper;
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/goodforgod/dummymapper/JsonAction.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.goodforgod.dummymapper;

import io.goodforgod.dummymapper.mapper.IMapper;
import io.goodforgod.dummymapper.mapper.impl.JsonMapper;
import io.goodforgod.dummymapper.marker.MarkerMapper;
import io.goodforgod.dummymapper.marker.mapper.JsonMapper;
import org.jetbrains.annotations.NotNull;

/**
Expand All @@ -16,7 +16,7 @@ public class JsonAction extends MapperAction {

@NotNull
@Override
public IMapper getMapper() {
public MarkerMapper getMapper() {
return mapper;
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/goodforgod/dummymapper/JsonArrayAction.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.goodforgod.dummymapper;

import io.goodforgod.dummymapper.mapper.IMapper;
import io.goodforgod.dummymapper.mapper.impl.JsonArrayMapper;
import io.goodforgod.dummymapper.marker.MarkerMapper;
import io.goodforgod.dummymapper.marker.mapper.JsonArrayMapper;
import io.goodforgod.dummymapper.ui.config.JsonArrayConfig;
import org.jetbrains.annotations.NotNull;

Expand All @@ -18,7 +18,7 @@ public class JsonArrayAction extends MapperAction<JsonArrayConfig> {

@NotNull
@Override
public IMapper<JsonArrayConfig> getMapper() {
public MarkerMapper<JsonArrayConfig> getMapper() {
return mapper;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.goodforgod.dummymapper;

import io.goodforgod.dummymapper.mapper.impl.JsonSchemaMapper;
import io.goodforgod.dummymapper.marker.mapper.JsonSchemaMapper;
import io.goodforgod.dummymapper.ui.config.JsonSchemaConfig;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down
22 changes: 12 additions & 10 deletions src/main/java/io/goodforgod/dummymapper/MapperAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
import com.intellij.openapi.ui.popup.util.PopupUtil;
import com.intellij.psi.PsiClass;
import io.dummymaker.util.StringUtils;
import io.goodforgod.dummymapper.error.JavaFileException;
import io.goodforgod.dummymapper.error.JavaKindException;
import io.goodforgod.dummymapper.error.MapperException;
import io.goodforgod.dummymapper.mapper.IMapper;
import io.goodforgod.dummymapper.error.PsiKindException;
import io.goodforgod.dummymapper.error.UnsupportedPsiFileException;
import io.goodforgod.dummymapper.marker.MarkerMapper;
import io.goodforgod.dummymapper.marker.RawMarker;
import io.goodforgod.dummymapper.scanner.impl.PsiJavaFileScanner;
import io.goodforgod.dummymapper.service.PsiClassScanner;
import io.goodforgod.dummymapper.ui.ConfigDialog;
import io.goodforgod.dummymapper.ui.config.IConfig;
import io.goodforgod.dummymapper.util.IdeaUtils;
Expand Down Expand Up @@ -47,7 +47,7 @@ public MapperAction(@NotNull Icon icon) {
}

@NotNull
public abstract IMapper<T> getMapper();
public abstract MarkerMapper<T> getMapper();

/**
* @return format as string in which mapper is converting (like JSON)
Expand Down Expand Up @@ -89,21 +89,22 @@ public void actionPerformed(@NotNull AnActionEvent event) {
.orElseGet(() -> IdeaUtils.getFileFromAction(event)
.filter(file -> file.getClasses().length != 0)
.map(file -> file.getClasses()[0])
.orElseThrow(JavaFileException::new));
.orElseThrow(UnsupportedPsiFileException::new));

final T config = getConfig();
if (config != null) {
final Project project = event.getProject();
final Collection<JComponent> components = config.getComponents();
final ConfigDialog dialog = new ConfigDialog(project, configDialogTitle(), components);
dialog.show();
if (dialog.getExitCode() == 1)
if (dialog.getExitCode() == 1) {
return;
}

dialog.disposeIfNeeded();
}

final RawMarker marker = new PsiJavaFileScanner().scan(psiClass);
final RawMarker marker = new PsiClassScanner().scan(psiClass);
final String json = getMapper().map(marker, config);
if (StringUtils.isEmpty(json)) {
PopupUtil.showBalloonForActiveFrame(emptyResultMessage(), MessageType.WARNING);
Expand All @@ -112,9 +113,10 @@ public void actionPerformed(@NotNull AnActionEvent event) {

IdeaUtils.copyToClipboard(json);
PopupUtil.showBalloonForActiveFrame(successMessage(), MessageType.INFO);
} catch (MapperException | JavaFileException | JavaKindException e) {
if (StringUtils.isEmpty(e.getMessage()))
} catch (MapperException | UnsupportedPsiFileException | PsiKindException e) {
if (StringUtils.isEmpty(e.getMessage())) {
throw new IllegalArgumentException("Unknown error occurred", e);
}

PopupUtil.showBalloonForActiveFrame(e.getMessage(), MessageType.WARNING);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
*/
public class ClassBuildException extends RuntimeException {

public ClassBuildException(String message) {
super(message);
}

public ClassBuildException(Throwable cause) {
super(cause.getMessage());
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,4 @@ public class MapperException extends RuntimeException {
public MapperException(String message) {
super(message);
}

public MapperException(Throwable cause) {
super(cause.getMessage(), cause);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.goodforgod.dummymapper.error;

import com.intellij.lang.jvm.JvmClassKind;

/**
* @author Anton Kurako (GoodforGod)
* @since 6.5.2020
*/
public class PsiKindException extends RuntimeException {

public PsiKindException(JvmClassKind kind) {
super("Class is '" + kind + "' and can not be mapped!");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
*/
public class ScanException extends RuntimeException {

public ScanException(String message) {
super(message);
}

public ScanException(Throwable cause) {
super(cause.getMessage(), cause);
}
Expand Down
Loading

0 comments on commit ec54df2

Please sign in to comment.