Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;
import java.util.StringJoiner;
import org.apache.maven.model.Resource;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
Expand Down Expand Up @@ -66,25 +68,19 @@ public class AotGenMojo extends AbstractMojo {
private MavenProject project;

@Override
@SuppressWarnings({"StringSplitter", "deprecation"})
public void execute() throws MojoExecutionException {
var module = Parser.parse(wasmFile);
var result = AotCompiler.compileModule(module, name);
var split = name.split("\\.");

var finalFolder = targetClassFolder.toPath();
var finalSourceFolder = targetSourceFolder.toPath();
for (int i = 0; i < (split.length - 1); i++) {
finalFolder = finalFolder.resolve(split[i]);
finalSourceFolder = finalSourceFolder.resolve(split[i]);
}
finalFolder.toFile().mkdirs();
var packageName = split[0];
for (int i = 1; i < (split.length - 1); i++) {
packageName += "." + split[i];
}

createFolders(finalFolder, finalSourceFolder, split);

String packageName = getPackageName(split);

// Generate static Machine implementation
finalSourceFolder.toFile().mkdirs();
final SourceRoot dest = new SourceRoot(finalSourceFolder);

var machineName = split[split.length - 1] + "MachineFactory";
Expand Down Expand Up @@ -131,4 +127,22 @@ public void execute() throws MojoExecutionException {
project.addResource(resource);
project.addCompileSourceRoot(targetSourceFolder.getPath());
}

static void createFolders(
Path classFilesBaseFolder, Path generatedSourceBaseFolder, String[] split) {
for (int i = 0; i < (split.length - 1); i++) {
classFilesBaseFolder = classFilesBaseFolder.resolve(split[i]);
generatedSourceBaseFolder = generatedSourceBaseFolder.resolve(split[i]);
}
classFilesBaseFolder.toFile().mkdirs();
generatedSourceBaseFolder.toFile().mkdirs();
}

static String getPackageName(String[] split) {
StringJoiner packageName = new StringJoiner(".");
for (int i = 0; i < split.length - 1; i++) {
packageName.add(split[i]);
}
return packageName.toString();
}
}
Loading