Skip to content

Commit feb5456

Browse files
CopilotjGauravGupta
andcommitted
feat: add PayaraMicroMavenProjectTools and PayaraServerMavenProjectTools
Co-authored-by: jGauravGupta <15934072+jGauravGupta@users.noreply.github.com>
1 parent 5966c66 commit feb5456

16 files changed

Lines changed: 489 additions & 1 deletion

File tree

src/main/java/io/github/jeddict/ai/agent/project/MavenProjectTools.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ String resolveTestCommand() {
250250
* Returns the Maven executable to use: the Maven wrapper ({@code ./mvnw}
251251
* or {@code mvnw.cmd}) when present, otherwise the system {@code mvn}.
252252
*/
253-
private String resolveWrapper() {
253+
protected String resolveWrapper() {
254254
final boolean isWindows = System.getProperty("os.name").toLowerCase().contains("win");
255255
final File basedirFile = new File(basedir);
256256
if (isWindows) {
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/**
2+
* Copyright 2025 the original author or authors from the Jeddict project (https://jeddict.github.io/).
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
package io.github.jeddict.ai.agent.project;
17+
18+
import dev.langchain4j.agent.tool.Tool;
19+
import io.github.jeddict.ai.agent.ToolPolicy;
20+
import static io.github.jeddict.ai.agent.ToolPolicy.Policy.READWRITE;
21+
import java.io.IOException;
22+
import org.netbeans.api.project.Project;
23+
24+
/**
25+
* Project-tool specialisation for Maven projects that use the
26+
* <a href="https://github.com/payara/ecosystem-maven">Payara Micro Maven Plugin</a>
27+
* ({@code fish.payara.maven.plugins:payara-micro-maven-plugin}).
28+
*
29+
* <p>Overrides the generic Maven build/run commands with Payara Micro-specific
30+
* goals, and exposes additional tools for the full lifecycle:</p>
31+
* <ul>
32+
* <li><b>bundle</b> – create an Uber JAR ({@code payara-micro:bundle})</li>
33+
* <li><b>start</b> – start Payara Micro ({@code payara-micro:start})</li>
34+
* <li><b>stop</b> – stop the running instance ({@code payara-micro:stop})</li>
35+
* <li><b>reload</b> – redeploy without restarting ({@code payara-micro:reload})</li>
36+
* <li><b>dev</b> – development mode with live reload ({@code payara-micro:dev})</li>
37+
* </ul>
38+
*/
39+
public class PayaraMicroMavenProjectTools extends MavenProjectTools {
40+
41+
public PayaraMicroMavenProjectTools(final Project project) throws IOException {
42+
super(project);
43+
}
44+
45+
// -----------------------------------------------------------------------
46+
// Overrides – build / run / test
47+
// -----------------------------------------------------------------------
48+
49+
@Override
50+
@Tool(
51+
name = "buildProject",
52+
value = "Build the Payara Micro project by creating an Uber JAR "
53+
+ "using 'mvn payara-micro:bundle' (or the Maven wrapper) and return the full log"
54+
)
55+
@ToolPolicy(READWRITE)
56+
public String buildProject() {
57+
return runCommand(resolveBuildCommand(), "Bundling");
58+
}
59+
60+
/**
61+
* Returns the command to bundle the Payara Micro Uber JAR
62+
* ({@code mvn[w] payara-micro:bundle}).
63+
*/
64+
@Override
65+
String resolveBuildCommand() {
66+
return resolveWrapper() + " payara-micro:bundle";
67+
}
68+
69+
@Override
70+
@Tool(
71+
name = "runJavaClass",
72+
value = "Start the Payara Micro server using 'mvn payara-micro:start' "
73+
+ "(or the Maven wrapper) and return the full output"
74+
)
75+
@ToolPolicy(READWRITE)
76+
public String runJavaClass(final String mainClass) {
77+
return runCommand(resolveRunCommand(mainClass), "Starting Payara Micro");
78+
}
79+
80+
/**
81+
* Returns the Payara Micro start command ({@code mvn[w] payara-micro:start}).
82+
* The {@code mainClass} parameter is not used because Payara Micro manages
83+
* deployment through its own plugin configuration.
84+
*/
85+
@Override
86+
String resolveRunCommand(final String mainClass) {
87+
return resolveWrapper() + " payara-micro:start";
88+
}
89+
90+
// -----------------------------------------------------------------------
91+
// Payara Micro-specific tools
92+
// -----------------------------------------------------------------------
93+
94+
@Tool(
95+
name = "stopServer",
96+
value = "Stop the running Payara Micro instance using 'mvn payara-micro:stop' "
97+
+ "(or the Maven wrapper)"
98+
)
99+
@ToolPolicy(READWRITE)
100+
public String stopServer() {
101+
return runCommand(resolveWrapper() + " payara-micro:stop", "Stopping Payara Micro");
102+
}
103+
104+
@Tool(
105+
name = "reloadApplication",
106+
value = "Redeploy the application without restarting Payara Micro "
107+
+ "using 'mvn payara-micro:reload' (or the Maven wrapper)"
108+
)
109+
@ToolPolicy(READWRITE)
110+
public String reloadApplication() {
111+
return runCommand(resolveWrapper() + " payara-micro:reload", "Reloading Payara Micro");
112+
}
113+
114+
@Tool(
115+
name = "devMode",
116+
value = "Start Payara Micro in development mode with auto deploy and live reload "
117+
+ "using 'mvn payara-micro:dev' (or the Maven wrapper)"
118+
)
119+
@ToolPolicy(READWRITE)
120+
public String devMode() {
121+
return runCommand(resolveWrapper() + " payara-micro:dev", "Dev mode Payara Micro");
122+
}
123+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/**
2+
* Copyright 2025 the original author or authors from the Jeddict project (https://jeddict.github.io/).
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
package io.github.jeddict.ai.agent.project;
17+
18+
import dev.langchain4j.agent.tool.Tool;
19+
import io.github.jeddict.ai.agent.ToolPolicy;
20+
import static io.github.jeddict.ai.agent.ToolPolicy.Policy.READWRITE;
21+
import java.io.IOException;
22+
import org.netbeans.api.project.Project;
23+
24+
/**
25+
* Project-tool specialisation for Maven projects that use the
26+
* <a href="https://github.com/payara/ecosystem-maven">Payara Server Maven Plugin</a>
27+
* ({@code fish.payara.maven.plugins:payara-server-maven-plugin}).
28+
*
29+
* <p>Overrides the generic Maven run command with Payara Server-specific
30+
* goals, and exposes additional tools for the full lifecycle:</p>
31+
* <ul>
32+
* <li><b>start</b> – start Payara Server and deploy the application
33+
* ({@code payara-server:start})</li>
34+
* <li><b>dev</b> – development mode with auto deploy and live reload
35+
* ({@code payara-server:dev})</li>
36+
* </ul>
37+
*
38+
* <p>The standard {@code buildProject()} ({@code mvn clean install}) and
39+
* {@code testProject()} ({@code mvn test}) goals are inherited from
40+
* {@link MavenProjectTools} unchanged.</p>
41+
*/
42+
public class PayaraServerMavenProjectTools extends MavenProjectTools {
43+
44+
public PayaraServerMavenProjectTools(final Project project) throws IOException {
45+
super(project);
46+
}
47+
48+
// -----------------------------------------------------------------------
49+
// Overrides – run
50+
// -----------------------------------------------------------------------
51+
52+
@Override
53+
@Tool(
54+
name = "runJavaClass",
55+
value = "Start Payara Server and deploy the application using 'mvn payara-server:start' "
56+
+ "(or the Maven wrapper) and return the full output"
57+
)
58+
@ToolPolicy(READWRITE)
59+
public String runJavaClass(final String mainClass) {
60+
return runCommand(resolveRunCommand(mainClass), "Starting Payara Server");
61+
}
62+
63+
/**
64+
* Returns the Payara Server start command ({@code mvn[w] payara-server:start}).
65+
* The {@code mainClass} parameter is not used because Payara Server manages
66+
* deployment through its own plugin configuration.
67+
*/
68+
@Override
69+
String resolveRunCommand(final String mainClass) {
70+
return resolveWrapper() + " payara-server:start";
71+
}
72+
73+
// -----------------------------------------------------------------------
74+
// Payara Server-specific tools
75+
// -----------------------------------------------------------------------
76+
77+
@Tool(
78+
name = "devMode",
79+
value = "Start Payara Server in development mode with auto deploy and live reload "
80+
+ "using 'mvn payara-server:dev' (or the Maven wrapper)"
81+
)
82+
@ToolPolicy(READWRITE)
83+
public String devMode() {
84+
return runCommand(resolveWrapper() + " payara-server:dev", "Dev mode Payara Server");
85+
}
86+
}

src/main/java/io/github/jeddict/ai/agent/project/ProjectTools.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,17 @@ public ProjectTools(final Project project) throws IOException {
8282
public static ProjectTools forProject(final Project project) throws IOException {
8383
final FileObject dir = project.getProjectDirectory();
8484
if (dir.getFileObject("pom.xml") != null) {
85+
try {
86+
final String pomContent = dir.getFileObject("pom.xml").asText();
87+
if (pomContent.contains("payara-micro-maven-plugin")) {
88+
return new PayaraMicroMavenProjectTools(project);
89+
}
90+
if (pomContent.contains("payara-server-maven-plugin")) {
91+
return new PayaraServerMavenProjectTools(project);
92+
}
93+
} catch (final IOException ignored) {
94+
// fall through to the generic MavenProjectTools
95+
}
8596
return new MavenProjectTools(project);
8697
}
8798
if (dir.getFileObject("build.gradle") != null
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/**
2+
* Copyright 2025 the original author or authors from the Jeddict project
3+
* (https://jeddict.github.io/).
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
6+
* use this file except in compliance with the License. You may obtain a copy of
7+
* the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
* License for the specific language governing permissions and limitations under
15+
* the License.
16+
*/
17+
package io.github.jeddict.ai.agent.project;
18+
19+
import com.github.caciocavallosilano.cacio.ctc.junit.CacioTest;
20+
import io.github.jeddict.ai.test.TestBase;
21+
import java.nio.file.Files;
22+
import java.nio.file.Path;
23+
import java.nio.file.Paths;
24+
import static org.assertj.core.api.BDDAssertions.then;
25+
import org.junit.jupiter.api.Test;
26+
27+
@CacioTest
28+
public class PayaraMicroMavenProjectToolsTest extends TestBase {
29+
30+
@Test
31+
public void forProject_returns_PayaraMicroMavenProjectTools_for_payara_micro_project()
32+
throws Exception {
33+
final Path homePath = Paths.get(".").toAbsolutePath().normalize();
34+
final String dir = homePath.resolve("src/test/projects/payara-micro").toString();
35+
final ProjectTools tool = ProjectTools.forProject(project(dir));
36+
then(tool).isInstanceOf(PayaraMicroMavenProjectTools.class);
37+
}
38+
39+
@Test
40+
public void payaraMicroProjectTools_is_instance_of_MavenProjectTools()
41+
throws Exception {
42+
final Path homePath = Paths.get(".").toAbsolutePath().normalize();
43+
final String dir = homePath.resolve("src/test/projects/payara-micro").toString();
44+
final ProjectTools tool = ProjectTools.forProject(project(dir));
45+
then(tool).isInstanceOf(MavenProjectTools.class);
46+
}
47+
48+
@Test
49+
public void resolveBuildCommand_uses_payara_micro_bundle()
50+
throws Exception {
51+
final Path homePath = Paths.get(".").toAbsolutePath().normalize();
52+
final String dir = homePath.resolve("src/test/projects/payara-micro").toString();
53+
final PayaraMicroMavenProjectTools tool = new PayaraMicroMavenProjectTools(project(dir));
54+
then(tool.resolveBuildCommand()).isEqualTo("mvn payara-micro:bundle");
55+
}
56+
57+
@Test
58+
public void resolveRunCommand_uses_payara_micro_start()
59+
throws Exception {
60+
final Path homePath = Paths.get(".").toAbsolutePath().normalize();
61+
final String dir = homePath.resolve("src/test/projects/payara-micro").toString();
62+
final PayaraMicroMavenProjectTools tool = new PayaraMicroMavenProjectTools(project(dir));
63+
then(tool.resolveRunCommand("com.example.Main")).isEqualTo("mvn payara-micro:start");
64+
}
65+
66+
@Test
67+
public void resolveTestCommand_uses_mvn_test()
68+
throws Exception {
69+
final Path homePath = Paths.get(".").toAbsolutePath().normalize();
70+
final String dir = homePath.resolve("src/test/projects/payara-micro").toString();
71+
final PayaraMicroMavenProjectTools tool = new PayaraMicroMavenProjectTools(project(dir));
72+
then(tool.resolveTestCommand()).isEqualTo("mvn test");
73+
}
74+
75+
@Test
76+
public void resolveBuildCommand_uses_mvnw_when_wrapper_present()
77+
throws Exception {
78+
Files.createFile(projectPath.resolve("mvnw"));
79+
final PayaraMicroMavenProjectTools tool = new PayaraMicroMavenProjectTools(project(projectDir));
80+
then(tool.resolveBuildCommand()).isEqualTo("./mvnw payara-micro:bundle");
81+
}
82+
83+
@Test
84+
public void resolveRunCommand_uses_mvnw_when_wrapper_present()
85+
throws Exception {
86+
Files.createFile(projectPath.resolve("mvnw"));
87+
final PayaraMicroMavenProjectTools tool = new PayaraMicroMavenProjectTools(project(projectDir));
88+
then(tool.resolveRunCommand("com.example.App")).isEqualTo("./mvnw payara-micro:start");
89+
}
90+
91+
@Test
92+
public void resolveTestCommand_uses_mvnw_when_wrapper_present()
93+
throws Exception {
94+
Files.createFile(projectPath.resolve("mvnw"));
95+
final PayaraMicroMavenProjectTools tool = new PayaraMicroMavenProjectTools(project(projectDir));
96+
then(tool.resolveTestCommand()).isEqualTo("./mvnw test");
97+
}
98+
}

0 commit comments

Comments
 (0)