Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use unique name for version property #257

Merged
merged 1 commit into from
Feb 4, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
@Mojo(name = "gitVersion", defaultPhase = LifecyclePhase.PREPARE_PACKAGE)
public class GitTagMojo extends AbstractMojo {

@Parameter(required = true, defaultValue = "${project.build.outputDirectory}/version.properties")
@Parameter(required = true, defaultValue = "${project.build.outputDirectory}/exporter-version.properties")
private File outputFile;

private final GitTagExecutor executor;
Expand Down Expand Up @@ -48,7 +48,7 @@ public void execute() throws MojoExecutionException {
}

private List<String> createProperties(String versionString) {
return Collections.singletonList("version=" + versionString);
return Collections.singletonList("monitoring-exporter-version=" + versionString);
}

// parses the result of 'git describe --tag' to describe the current code version/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void mojoAnnotatedWithDefaultPhase() {
void hasRequiredOutputDirectoryParameter() throws NoSuchFieldException {
assertThat(mojoTestSupport.getParameterField("outputFile").getType(), equalTo(File.class));
assertThat(mojoTestSupport.getParameterAnnotation("outputFile").get("required"), is(true));
assertThat(mojoTestSupport.getParameterAnnotation("outputFile").get("defaultValue"), equalTo("${project.build.outputDirectory}/version.properties"));
assertThat(mojoTestSupport.getParameterAnnotation("outputFile").get("defaultValue"), equalTo("${project.build.outputDirectory}/exporter-version.properties"));
}

@Test
Expand Down Expand Up @@ -92,7 +92,7 @@ void whenGitResponseIsVersionPlusHistory_createVersionProperty() throws Exceptio
mojo.execute();

assertThat(inMemoryFileSystem.getContents(outputFile.getAbsolutePath()),
containsString("version=cb4385f3aa (946 commits since v3.3.5-3)"));
containsString("monitoring-exporter-version=cb4385f3aa (946 commits since v3.3.5-3)"));
}

@Test
Expand All @@ -101,7 +101,8 @@ void whenGitResponseIsVersionOnly_createVersionProperty() throws Exception {

mojo.execute();

assertThat(inMemoryFileSystem.getContents(outputFile.getAbsolutePath()), containsString("version=v3.4-1"));
assertThat(inMemoryFileSystem.getContents(outputFile.getAbsolutePath()),
containsString("monitoring-exporter-version=v3.4-1"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
// Copyright (c) 2017, 2022, Oracle and/or its affiliates.
// Copyright (c) 2017, 2023, Oracle and/or its affiliates.
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.

package com.oracle.wls.exporter;

import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.oracle.wls.exporter.domain.ExporterConfig;
import com.oracle.wls.exporter.domain.MBeanSelector;
import com.oracle.wls.exporter.domain.QuerySyncConfiguration;
import org.yaml.snakeyaml.Yaml;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -19,13 +12,23 @@
import java.util.Optional;
import java.util.Properties;

import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.oracle.wls.exporter.domain.ExporterConfig;
import com.oracle.wls.exporter.domain.MBeanSelector;
import com.oracle.wls.exporter.domain.QuerySyncConfiguration;
import org.yaml.snakeyaml.Yaml;

/**
* The repository for the current exporter configuration.
*
* @author Russell Gold
*/
public class LiveConfiguration {

public static final String VERSION_PROPERTY_FILE = "exporter-version.properties";
public static final String VERSION_PROPERTY = "monitoring-exporter-version";

private LiveConfiguration() {
// no-op
}
Expand Down Expand Up @@ -59,10 +62,10 @@ private static ExporterConfig getConfig() {
}

public static String getVersionString() {
try (InputStream in = LiveConfiguration.class.getClassLoader().getResourceAsStream("version.properties")) {
try (InputStream in = LiveConfiguration.class.getClassLoader().getResourceAsStream(VERSION_PROPERTY_FILE)) {
Properties properties = new Properties();
properties.load(in);
return properties.getProperty("version");
return properties.getProperty(VERSION_PROPERTY);

} catch (IOException e) {
return "** unknown version";
Expand Down