Skip to content
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
13 changes: 13 additions & 0 deletions jbang-catalog.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"catalogs": {},
"aliases": {
"jmolecules": {
"script-ref": "org.jmolecules.integrations:jmolecules-cli:0.29.0-SNAPSHOT",
"dependencies": [
"org.slf4j:slf4j-simple:2.0.13"
],
"java": "17+"
}
},
"templates": {}
}
1 change: 1 addition & 0 deletions jmolecules-cli/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.jmolecules-cache/
4 changes: 4 additions & 0 deletions jmolecules-cli/etc/build-native.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
../mvnw native:compile
source ./target/jmolecules_completion
alias jmn=$(pwd)/target/jmolecules-codegen
4 changes: 4 additions & 0 deletions jmolecules-cli/etc/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
../mvnw package \
&& source ./target/jmolecules_completion \
&& cp $(pwd)/target/jmolecules-cli-*-SNAPSHOT.jar ~/.tools/jmolecules-cli.jar
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
*
* @author Oliver Drotbohm
*/
@SpringBootApplication
public class SampleApplication {

}
119 changes: 119 additions & 0 deletions jmolecules-cli/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jmolecules.integrations</groupId>
<artifactId>jmolecules-integrations</artifactId>
<version>0.29.0-SNAPSHOT</version>
</parent>
<artifactId>jmolecules-cli</artifactId>
<name>jMolecules - Command Line Interface</name>

<properties>
<java.version>17</java.version>
</properties>

<dependencies>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jmolecules-codegen</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>info.picocli</groupId>
<artifactId>picocli</artifactId>
<version>4.7.6</version>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>info.picocli</groupId>
<artifactId>picocli-codegen</artifactId>
<version>4.7.6</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-invoker</artifactId>
<version>3.3.0</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>

<dependency>
<groupId>org.jmolecules.integrations</groupId>
<artifactId>jmolecules-starter-ddd</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.xmlbeam</groupId>
<artifactId>xmlprojector</artifactId>
<version>1.4.24</version>
</dependency>

<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<build>
<plugins>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
</plugin>

<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<version>0.10.4</version>
<configuration>
<mainClass>org.jmolecules.cli.CliApplication</mainClass>
<buildArgs>
<buildArg>--no-fallback</buildArg>
<buildArg>--enable-url-protocols=file,jar</buildArg>
</buildArgs>
</configuration>
</plugin>

<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot3.version}</version>
<executions>
<execution>
<id>repackage</id>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>

</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Copyright 2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jmolecules.cli;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
import picocli.CommandLine.Parameters;

import java.util.Iterator;
import java.util.List;
import java.util.concurrent.Callable;

import org.jmolecules.codegen.ProjectContext;
import org.jmolecules.codegen.generator.JMoleculesCodeGenerator;

/**
* @author Oliver Drotbohm
*/
@Command(name = "add-aggregate", mixinStandardHelpOptions = true)
@Slf4j
@RequiredArgsConstructor
public class AddAggregateCommand implements Callable<Void> {

private final JMoleculesCodeGenerator generator;
private final ProjectContext context;

@Parameters //
public String name;

@Option(names = { "-p", "--package" },
description = "The package to add the aggregate to.") //
public String pkg;

@Option(names = { "-m", "--module" },
description = "The Spring Modulith module to add the aggregate to. Essentially causes --package to be configured to the module's base package. Requires spring-modulith.enabled to be configured to true.",
completionCandidates = ModuleReferencePlaceholder.class) //
public String module;

static class ModuleReferencePlaceholder implements Iterable<String> {

/*
* (non-Javadoc)
* @see java.lang.Iterable#iterator()
*/
@Override
public Iterator<String> iterator() {
return List.of(getClass().getName()).iterator();
}
}

/*
* (non-Javadoc)
* @see java.util.concurrent.Callable#call()
*/
@Override
public Void call() throws Exception {

if (!context.getConfiguration().isSpringModulithEnabled() && pkg == null) {

log.info("> No Spring Modulith configured, Explicit package (--package, -p) required!");

System.exit(1);
}

var packageName = pkg != null ? pkg : context.getPackageForModule(module);

generator.generateAggregate(name, packageName);

return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jmolecules.cli;

import lombok.RequiredArgsConstructor;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;

import java.util.concurrent.Callable;

import org.jmolecules.codegen.generator.JMoleculesCodeGenerator;

/**
* @author Oliver Drotbohm
*/
@Command(name = "add-module")
@RequiredArgsConstructor
public class AddModuleCommand implements Callable<Void> {

private final JMoleculesCodeGenerator generator;

@Option(names = { "-n", "--name" }) //
String name;

/*
* (non-Javadoc)
* @see java.util.concurrent.Callable#call()
*/
@Override
public Void call() throws Exception {

generator.createModule(name);

return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright 2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jmolecules.cli;

import picocli.CommandLine;
import picocli.CommandLine.Command;

import org.jmolecules.cli.core.BuildSystem;
import org.jmolecules.cli.core.DefaultProjectContext;
import org.jmolecules.cli.core.MetadataCache;
import org.jmolecules.codegen.ProjectFiles;
import org.jmolecules.codegen.generator.JMoleculesCodeGenerator;

/**
* @author Oliver Drotbohm
*/
@Command(name = "jm", mixinStandardHelpOptions = true)
public class CliApplication {

static {
System.setProperty("picocli.trace", "OFF");
}

public static void main(String[] args) throws Exception {

var commandLine = createCommandLine(".");

System.exit(commandLine.execute(args));
}

public static CommandLine createCommandLine(String root) throws Exception {

var files = new ProjectFiles(root);
var cache = new MetadataCache(files);
var buildSystem = BuildSystem.of(files, cache);
var context = new DefaultProjectContext(files, cache, buildSystem);

var code = new JMoleculesCodeGenerator(context);

var commandLine = new CommandLine(new CliApplication());
commandLine.addSubcommand(new AddAggregateCommand(code, context));
commandLine.addSubcommand(new AddModuleCommand(code));
commandLine.addSubcommand(new ConfigCommand(context));
commandLine.addSubcommand(new InitCommand(buildSystem, context, cache));

return commandLine;
}
}
Loading