Skip to content

Breaking/migrate maven to plugin parameters #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ buildNumber.properties
.classpath

node_modules
/java-to-zod-gradle-plugin/.gradle/
/java-to-zod-gradle-plugin/build/
/.idea/
22 changes: 21 additions & 1 deletion java-to-zod-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>sh.ivan</groupId>
<artifactId>java-to-zod</artifactId>
<version>0.7.0-SNAPSHOT</version>
<version>0.8.0-SNAPSHOT</version>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to change the version number. This is all handled automatically when I do the release

</parent>
<artifactId>java-to-zod-core</artifactId>
<packaging>jar</packaging>
Expand Down Expand Up @@ -49,5 +49,25 @@
<version>3.9.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.10.2</version>
<scope>compile</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jetbrains.intellij.deps/gradle-api -->
<dependency>
<groupId>org.jetbrains.intellij.deps</groupId>
<artifactId>gradle-api</artifactId>
<version>8.5</version>
<scope>compile</scope>
</dependency>

</dependencies>
<repositories>
<repository>
<id>jetbrains-intellij-dependencies</id>
<url>https://packages.jetbrains.team/maven/p/ij/intellij-dependencies/</url>
</repository>
</repositories>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package sh.ivan.zod;

import cz.habarta.typescript.generator.*;
import cz.habarta.typescript.generator.parser.Model;
import java.io.File;
import java.io.IOException;
import java.net.URLClassLoader;
import java.util.Map;
import java.util.function.Supplier;
import sh.ivan.zod.plugins.PluginParameters;
import sh.ivan.zod.schema.ObjectSchema;

public class JavaToZodConvertorWrapper {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested name: JavaToZodPluginConverter. Thoughts?

private final URLClassLoader classLoader;
private final PluginParameters pluginParameters;
private final Supplier<File> getOutputFile;

public JavaToZodConvertorWrapper(
URLClassLoader classLoader, PluginParameters pluginParameters, Supplier<File> getOutputFile) {
this.classLoader = classLoader;
this.pluginParameters = pluginParameters;
this.getOutputFile = getOutputFile;
}

public void run() throws IOException {
Settings settings = from(classLoader, pluginParameters);

Input.Parameters parameters = new Input.Parameters();
parameters.classNames = pluginParameters.getClasses();
parameters.classNamePatterns = pluginParameters.getClassPatterns();
parameters.classesWithAnnotations = pluginParameters.getClassesWithAnnotations();
parameters.classesImplementingInterfaces = pluginParameters.getClassesImplementingInterfaces();
parameters.classesExtendingClasses = pluginParameters.getClassesExtendingClasses();
parameters.jaxrsApplicationClassName = pluginParameters.getClassesFromJaxrsApplication();
parameters.automaticJaxrsApplication = pluginParameters.isClassesFromAutomaticJaxrsApplication();
parameters.isClassNameExcluded = settings.getExcludeFilter();
parameters.classLoader = classLoader;
parameters.scanningAcceptedPackages = pluginParameters.getScanningAcceptedPackages();
parameters.debug = pluginParameters.getLoggingLevel() == Logger.Level.Debug;

Input input = Input.from(parameters);
TypeScriptGenerator typeScriptGenerator = new TypeScriptGenerator(settings);
Model model = typeScriptGenerator.getModelParser().parseModel(input.getSourceTypes());
Configuration configuration = Configuration.builder()
.schemaNamePrefix(pluginParameters.getSchemaNamePrefix())
.schemaNameSuffix(pluginParameters.getSchemaNameSuffix())
.build();
JavaToZodConverter javaToZodConverter =
new JavaToZodConverter(typeScriptGenerator.getModelParser(), configuration);
Map<String, ObjectSchema> beanSchemas = javaToZodConverter.getBeanSchemas(model);
SchemaFileWriter schemaFileWriter = new SchemaFileWriter(beanSchemas, getOutputFile.get());
schemaFileWriter.write();
}

private Settings from(URLClassLoader classLoader, PluginParameters pluginParameters) {
Settings settings = new Settings();
settings.setExcludeFilter(pluginParameters.getExcludeClasses(), pluginParameters.getExcludeClassPatterns());
settings.jsonLibrary = pluginParameters.getJsonLibrary();
settings.setJackson2Configuration(classLoader, pluginParameters.getJackson2Configuration());
settings.gsonConfiguration = pluginParameters.getGsonConfiguration();
settings.jsonbConfiguration = pluginParameters.getJsonbConfiguration();
settings.scanSpringApplication = pluginParameters.isScanSpringApplication();
settings.loadIncludePropertyAnnotations(classLoader, pluginParameters.getIncludePropertyAnnotations());
settings.loadExcludePropertyAnnotations(classLoader, pluginParameters.getIncludePropertyAnnotations());
settings.classLoader = classLoader;
settings.outputKind = TypeScriptOutputKind.global; // Unused, but required by settings validation
settings.outputFileType = TypeScriptFileType.implementationFile;
settings.loadOptionalAnnotations(classLoader, pluginParameters.getOptionalAnnotations());
return settings;
}
}
Loading
Loading