aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api-impl
diff options
context:
space:
mode:
authorOrlovAlexander <35396155+OrlovAlexander85@users.noreply.github.com>2024-04-09 15:22:11 +0200
committersonartech <sonartech@sonarsource.com>2024-04-10 20:02:53 +0000
commit791659dd5e60709f28f9afa7983cee5375acb136 (patch)
tree23a8152c5ab1e21edb5c4cacfac1d5e99ec2e24f /sonar-plugin-api-impl
parentf5dd75ab4b842eb2a5280411cfaceb0c09eea57d (diff)
downloadsonarqube-791659dd5e60709f28f9afa7983cee5375acb136.tar.gz
sonarqube-791659dd5e60709f28f9afa7983cee5375acb136.zip
SONAR-22018 introduce version EOL to properties, and update GlobalAction
Diffstat (limited to 'sonar-plugin-api-impl')
-rw-r--r--sonar-plugin-api-impl/build.gradle3
-rw-r--r--sonar-plugin-api-impl/src/main/java/org/sonar/api/internal/MetadataLoader.java26
-rw-r--r--sonar-plugin-api-impl/src/main/resources/sq-version-eol.txt1
-rw-r--r--sonar-plugin-api-impl/src/test/java/org/sonar/api/internal/MetadataLoaderTest.java13
4 files changed, 34 insertions, 9 deletions
diff --git a/sonar-plugin-api-impl/build.gradle b/sonar-plugin-api-impl/build.gradle
index 51480338d9d..a55d546a8f6 100644
--- a/sonar-plugin-api-impl/build.gradle
+++ b/sonar-plugin-api-impl/build.gradle
@@ -28,7 +28,8 @@ dependencies {
import org.apache.tools.ant.filters.ReplaceTokens
processResources {
filter ReplaceTokens, tokens: [
- 'project.version': project.version
+ 'project.version': project.version,
+ 'versionEOL': project.properties["versionEOL"]
]
}
diff --git a/sonar-plugin-api-impl/src/main/java/org/sonar/api/internal/MetadataLoader.java b/sonar-plugin-api-impl/src/main/java/org/sonar/api/internal/MetadataLoader.java
index e0c75d17013..16ff62524fa 100644
--- a/sonar-plugin-api-impl/src/main/java/org/sonar/api/internal/MetadataLoader.java
+++ b/sonar-plugin-api-impl/src/main/java/org/sonar/api/internal/MetadataLoader.java
@@ -28,6 +28,7 @@ import org.sonar.api.SonarEdition;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.Version;
+import static java.lang.String.format;
import static org.apache.commons.lang.StringUtils.trimToEmpty;
/**
@@ -40,6 +41,8 @@ public class MetadataLoader {
private static final String SQ_VERSION_FILE_PATH = "/sq-version.txt";
private static final String SONAR_API_VERSION_FILE_PATH = "/sonar-api-version.txt";
private static final String EDITION_FILE_PATH = "/sonar-edition.txt";
+ private static final String SQ_VERSION_EOL_FILE_PATH = "/sq-version-eol.txt";
+ public static final String CAN_NOT_LOAD_FROM_CLASSPATH = "Can not load %s from classpath";
private MetadataLoader() {
// only static methods
@@ -48,18 +51,25 @@ public class MetadataLoader {
public static Version loadApiVersion(System2 system) {
return getVersion(system, SONAR_API_VERSION_FILE_PATH);
}
+
public static Version loadSQVersion(System2 system) {
return getVersion(system, SQ_VERSION_FILE_PATH);
}
+ public static String loadSqVersionEol(System2 system) {
+ return getParamFromFile(system, SQ_VERSION_EOL_FILE_PATH);
+ }
+
private static Version getVersion(System2 system, String versionFilePath) {
- URL url = system.getResource(versionFilePath);
+ return Version.parse(getParamFromFile(system, versionFilePath));
+ }
- try (Scanner scanner = new Scanner(url.openStream(), StandardCharsets.UTF_8.name())) {
- String versionInFile = scanner.nextLine();
- return Version.parse(versionInFile);
+ private static String getParamFromFile(System2 system, String filePath) {
+ URL url = system.getResource(filePath);
+ try (Scanner scanner = new Scanner(url.openStream(), StandardCharsets.UTF_8)) {
+ return scanner.nextLine();
} catch (IOException e) {
- throw new IllegalStateException("Can not load " + versionFilePath + " from classpath ", e);
+ throw new IllegalStateException(format(CAN_NOT_LOAD_FROM_CLASSPATH, filePath), e);
}
}
@@ -68,11 +78,11 @@ public class MetadataLoader {
if (url == null) {
return SonarEdition.COMMUNITY;
}
- try (Scanner scanner = new Scanner(url.openStream(), StandardCharsets.UTF_8.name())) {
+ try (Scanner scanner = new Scanner(url.openStream(), StandardCharsets.UTF_8)) {
String editionInFile = scanner.nextLine();
return parseEdition(editionInFile);
} catch (IOException e) {
- throw new IllegalStateException("Can not load " + EDITION_FILE_PATH + " from classpath", e);
+ throw new IllegalStateException(format(CAN_NOT_LOAD_FROM_CLASSPATH, EDITION_FILE_PATH), e);
}
}
@@ -81,7 +91,7 @@ public class MetadataLoader {
try {
return SonarEdition.valueOf(str);
} catch (IllegalArgumentException e) {
- throw new IllegalStateException(String.format("Invalid edition found in '%s': '%s'", EDITION_FILE_PATH, str));
+ throw new IllegalStateException(format("Invalid edition found in '%s': '%s'", EDITION_FILE_PATH, str));
}
}
}
diff --git a/sonar-plugin-api-impl/src/main/resources/sq-version-eol.txt b/sonar-plugin-api-impl/src/main/resources/sq-version-eol.txt
new file mode 100644
index 00000000000..154f9322c6d
--- /dev/null
+++ b/sonar-plugin-api-impl/src/main/resources/sq-version-eol.txt
@@ -0,0 +1 @@
+@versionEOL@
diff --git a/sonar-plugin-api-impl/src/test/java/org/sonar/api/internal/MetadataLoaderTest.java b/sonar-plugin-api-impl/src/test/java/org/sonar/api/internal/MetadataLoaderTest.java
index 3ee4ec5df9a..31628e5ebda 100644
--- a/sonar-plugin-api-impl/src/test/java/org/sonar/api/internal/MetadataLoaderTest.java
+++ b/sonar-plugin-api-impl/src/test/java/org/sonar/api/internal/MetadataLoaderTest.java
@@ -78,4 +78,17 @@ public class MetadataLoaderTest {
.hasMessageContaining("Can not load /sonar-api-version.txt from classpath");
}
+ @Test
+ public void loadSqVersionEol_shouldLoadCorrectEol() {
+ String eol = MetadataLoader.loadSqVersionEol(System2.INSTANCE);
+ assertThat(eol).isNotNull();
+ }
+
+ @Test
+ public void loadSqVersionEol_whenFileNotFound_shouldThrowException() throws MalformedURLException {
+ when(system.getResource(anyString())).thenReturn(new File("target/unknown").toURI().toURL());
+ assertThatThrownBy(() -> MetadataLoader.loadSqVersionEol(system))
+ .isInstanceOf(IllegalStateException.class)
+ .hasMessageContaining("Can not load /sq-version-eol.txt from classpath");
+ }
}