Skip to content

Commit

Permalink
Set major.minor in json schema path name
Browse files Browse the repository at this point in the history
  • Loading branch information
Bramaten committed Jan 14, 2025
1 parent 32af40f commit c4444b2
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package com.buschmais.jqassistant.commandline.test;
package com.buschmais.jqassistant.commandline.task;

import com.buschmais.jqassistant.commandline.configuration.CliConfiguration;
import com.buschmais.jqassistant.core.runtime.api.configuration.JsonSchemaGenerator;

import com.fasterxml.jackson.databind.JsonNode;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

class CliJsonSchemaGeneratorTest {

@Test
void generateSchemaAndValidate() throws Exception {
JsonSchemaGenerator generator = new JsonSchemaGenerator();
String path = "target/generated-resources/schema/jqassistant-configuration-cli.schema.json";
JsonNode node = generator.generateSchema(CliConfiguration.class, path);
assertThat(generator.validateYaml("src/test/resources/validCliYaml.yaml", node)).isEmpty();
Assertions.assertThat(generator.validateYaml("src/test/resources/validCliYaml.yaml", node)).isEmpty();
}

}
34 changes: 34 additions & 0 deletions core/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,40 @@

<artifactId>runtime</artifactId>
<name>jQAssistant Core Runtime</name>

<build>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<includes>
<include>META-INF/jqassistant.properties</include>
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<excludes>
<exclude>META-INF/jqassistant.properties</exclude>
</excludes>
<filtering>false</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>parse-version</id>
<goals>
<goal>parse-version</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>com.buschmais.jqassistant.core</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,29 @@
import java.io.InputStream;
import java.util.Properties;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Getter
public class VersionProvider {

private static final String PROPERTIES_FILE = "/META-INF/jqassistant.properties";
private static final String VERSION_KEY = "jqassistant.version";
private static final String MINOR_VERSION = "jqassistant.version.minor";
private static final String MAJOR_VERSION = "jqassistant.version.major";
private static final String VERSION = "jqassistant.version";

public static String getVersion() {
private static final VersionProvider INSTANCE = new VersionProvider();

private final String minorVersion;
private final String majorVersion;
private final String version;

public static VersionProvider getVersionProvider() {
return INSTANCE;
}

private VersionProvider() {
Properties props = new Properties();
InputStream inputStream = VersionProvider.class.getResourceAsStream(PROPERTIES_FILE);
if (inputStream == null) {
Expand All @@ -23,7 +37,9 @@ public static String getVersion() {
} catch (IOException e) {
log.warn("Failed to load inout stream from " + PROPERTIES_FILE);
}
return props.getProperty(VERSION_KEY);
this.minorVersion = props.getProperty(MINOR_VERSION);
this.majorVersion = props.getProperty(MAJOR_VERSION);
this.version = props.getProperty(VERSION);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import java.util.Optional;
import java.util.Set;

import com.buschmais.jqassistant.core.runtime.api.bootstrap.VersionProvider;

import com.fasterxml.classmate.ResolvedType;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand All @@ -25,6 +23,7 @@
import io.smallrye.config.WithDefault;
import org.yaml.snakeyaml.Yaml;

import static com.buschmais.jqassistant.core.runtime.api.bootstrap.VersionProvider.getVersionProvider;
import static io.smallrye.config._private.ConfigLogging.log;

public class JsonSchemaGenerator {
Expand Down Expand Up @@ -105,7 +104,7 @@ private static void saveSchemaToFile(ObjectNode schema, String path) throws IOEx
} else {
log.warn("Path name does not meet naming strategy of json schemas and therefore could not be versioned.");
}
String versionedFilePath = pathName + "-" + VersionProvider.getVersion() + ".schema.json";
String versionedFilePath = pathName + "-v" + getVersionProvider().getMajorVersion() + "." + getVersionProvider().getMinorVersion() + ".schema.json";

File file = new File(versionedFilePath);
File parentDir = file.getParentFile();
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
jqassistant.version=${project.version}
jqassistant.version.major = ${parsedVersion.majorVersion}
jqassistant.version.minor = ${parsedVersion.minorVersion}

Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,27 @@
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;

import static com.buschmais.jqassistant.core.runtime.api.bootstrap.VersionProvider.getVersionProvider;
import static org.assertj.core.api.Assertions.assertThat;

@Slf4j
public class VersionProviderTest {

@Test
void testGetVersion() {
String version = VersionProvider.getVersion();
if (version == null) {
log.warn("Version should not be null");
}
String version = getVersionProvider().getVersion();
assertThat(version).isNotNull();
assertThat(version.startsWith("$")).isFalse();
}

@Test
void testGetMinorMajorVersion() {
String versionMinor = getVersionProvider().getMinorVersion();
assertThat(versionMinor).isNotNull();
assertThat(versionMinor.startsWith("$")).isFalse();

String versionMajor = getVersionProvider().getMajorVersion();
assertThat(versionMajor).isNotNull();
assertThat(versionMajor .startsWith("$")).isFalse();
}
}
7 changes: 0 additions & 7 deletions plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@
</excludes>
<filtering>false</filtering>
</resource>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<includes>
<include>META-INF/jqassistant.properties</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>

<pluginManagement>
Expand Down

0 comments on commit c4444b2

Please sign in to comment.