Skip to content

Commit

Permalink
Cleaning up
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Farr <[email protected]>
  • Loading branch information
Xtansia committed Jun 10, 2024
1 parent ab4bec2 commit 996a379
Show file tree
Hide file tree
Showing 17 changed files with 712 additions and 306 deletions.

This file was deleted.

13 changes: 10 additions & 3 deletions java-codegen/src/main/java/org/opensearch/client/codegen/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.opensearch.client.codegen.exceptions.RenderException;
import org.opensearch.client.codegen.model.Namespace;
import org.opensearch.client.codegen.model.OperationGroup;
import org.opensearch.client.codegen.model.ShapeRenderingContext;
import org.opensearch.client.codegen.model.SpecTransformer;
import org.opensearch.client.codegen.openapi.OpenApiSpecification;

Expand Down Expand Up @@ -84,10 +85,16 @@ public static void main(String[] args) {

cleanDirectory(outputDir);

outputDir = new File(outputDir, root.getPackageName().replace('.', '/'));
final var rootPackageOutputDir = new File(outputDir, root.getPackageName().replace('.', '/'));

try (var formatter = new JavaFormatter(outputDir.toPath(), eclipseConfig)) {
root.render(outputDir, formatter);
try (
var ctx = ShapeRenderingContext.builder()
.withOutputDir(rootPackageOutputDir)
.withJavaCodeFormatter(b -> b.withRootDir(rootPackageOutputDir.toPath()).withEclipseFormatterConfig(eclipseConfig))
.withTemplateLoader(b -> b.withTemplatesResourceSubPath("/org/opensearch/client/codegen/templates"))
.build()
) {
root.render(ctx);
}
} catch (ParseException e) {
LOGGER.error("Argument Parsing Failed. Reason: {}", e.getMessage());
Expand Down
165 changes: 0 additions & 165 deletions java-codegen/src/main/java/org/opensearch/client/codegen/Renderer.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@

package org.opensearch.client.codegen.model;

import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.opensearch.client.codegen.JavaFormatter;
import org.opensearch.client.codegen.exceptions.RenderException;
import org.opensearch.client.codegen.utils.Lists;
import org.opensearch.client.codegen.utils.Strings;
Expand Down Expand Up @@ -69,15 +67,13 @@ public Namespace child(@Nullable String name) {
}

@Override
public void render(File outputDir, JavaFormatter formatter) throws RenderException {
outputDir.mkdirs();

public void render(ShapeRenderingContext ctx) throws RenderException {
for (Namespace child : children.values()) {
child.render(new File(outputDir, child.getPackageNamePart()), formatter);
child.render(ctx.forSubDir(child.getPackageNamePart()));
}

for (Shape shape : shapes) {
shape.render(outputDir, formatter);
shape.render(ctx);
}

if (operations.isEmpty()) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@

package org.opensearch.client.codegen.model;

import java.io.File;
import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.opensearch.client.codegen.JavaFormatter;
import org.opensearch.client.codegen.Renderer;
import org.opensearch.client.codegen.exceptions.RenderException;

public abstract class Shape {
Expand Down Expand Up @@ -51,10 +48,13 @@ public String getTypedefName() {
return this.typedefName;
}

public void render(File outputDir, JavaFormatter formatter) throws RenderException {
var outFile = new File(outputDir, this.className + ".java");
public void render(ShapeRenderingContext ctx) throws RenderException {
var outFile = ctx.getOutputFile(className + ".java");
LOGGER.info("Rendering: {}", outFile);
var renderer = new Renderer(referencedTypes::add, formatter);
var renderer = ctx.getTemplateRenderer(b -> b.withFormatter(Type.class, t -> {
referencedTypes.add(t);
return t.toString();
}));
renderer.renderJava(this, outFile);
}

Expand Down
Loading

0 comments on commit 996a379

Please sign in to comment.