Skip to content

Commit 0b48d7d

Browse files
authored
Access project version dynamically in Java files (#1502)
1 parent dd4a1f1 commit 0b48d7d

File tree

4 files changed

+63
-2
lines changed

4 files changed

+63
-2
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright © 2021 DataSQRL ([email protected])
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of 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,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.datasqrl.cli;
17+
18+
import com.datasqrl.util.ProjectConstants;
19+
import picocli.CommandLine.IVersionProvider;
20+
21+
public class CliVersionProvider implements IVersionProvider {
22+
23+
@Override
24+
public String[] getVersion() {
25+
return new String[] {ProjectConstants.SQRL_VERSION};
26+
}
27+
}

sqrl-cli/src/main/java/com/datasqrl/cli/DatasqrlCli.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
@CommandLine.Command(
2727
name = "datasqrl",
2828
mixinStandardHelpOptions = true,
29-
version = "v0.7.0",
29+
versionProvider = CliVersionProvider.class,
3030
subcommands = {CompileCmd.class, TestCmd.class, RunCmd.class, ExecuteCmd.class})
3131
@Getter
3232
public class DatasqrlCli implements Runnable {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright © 2021 DataSQRL ([email protected])
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of 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,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.datasqrl.util;
17+
18+
import lombok.AccessLevel;
19+
import lombok.NoArgsConstructor;
20+
21+
@NoArgsConstructor(access = AccessLevel.PRIVATE)
22+
public final class ProjectConstants {
23+
24+
public static final String SQRL_VERSION;
25+
26+
static {
27+
var version = ProjectConstants.class.getPackage().getImplementationVersion();
28+
29+
SQRL_VERSION = version != null ? version : "unknown";
30+
}
31+
}

sqrl-server/sqrl-server-vertx-base/src/main/java/com/datasqrl/graphql/McpBridgeVerticle.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.datasqrl.graphql.server.RootGraphqlModel;
2020
import com.datasqrl.graphql.server.operation.ApiOperation;
2121
import com.datasqrl.graphql.server.operation.McpMethodType;
22+
import com.datasqrl.util.ProjectConstants;
2223
import com.fasterxml.jackson.core.JsonProcessingException;
2324
import com.fasterxml.jackson.core.type.TypeReference;
2425
import com.fasterxml.jackson.databind.JsonNode;
@@ -287,7 +288,9 @@ private JsonObject handleInitialize(JsonNode params) {
287288
.put("resources", new JsonObject().put("subscribe", false).put("listChanged", false));
288289

289290
JsonObject serverInfo =
290-
new JsonObject().put("name", "datasqrl-mcp-server").put("version", "0.7.0");
291+
new JsonObject()
292+
.put("name", "datasqrl-mcp-server")
293+
.put("version", ProjectConstants.SQRL_VERSION);
291294

292295
return new JsonObject()
293296
.put("protocolVersion", PROTOCOL_VERSION)

0 commit comments

Comments
 (0)