Skip to content

Commit

Permalink
Fix scala linter warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
kaklakariada committed May 16, 2024
1 parent b38b86b commit 1530540
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 32 deletions.
6 changes: 6 additions & 0 deletions doc/developers_guide/developers_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

This guide contains information for developers.

## Running Scala Linter

```
mvn compile test-compile scalastyle:check scalafix:scalafix spotless:check
```

## Working With the Managed Extension

This describes how to develop the extension for the [Extension Manager](https://github.com/exasol/extension-manager/).
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@
<verbose>false</verbose>
<failOnViolation>true</failOnViolation>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
<failOnWarning>false</failOnWarning>
<failOnWarning>true</failOnWarning>
<sourceDirectory>${project.basedir}/src/main/scala</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/scala</testSourceDirectory>
<configLocation>${project.basedir}/scalastyle-config.xml</configLocation>
Expand Down
2 changes: 1 addition & 1 deletion scalastyle-config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@
</check>

<!-- Checks for use of magic numbers, avoids assignments like: var baz = 4 -->
<check level="warn" class="org.scalastyle.scalariform.MagicNumberChecker" enabled="true">
<check level="warn" class="org.scalastyle.scalariform.MagicNumberChecker" enabled="false">
<parameters>
<parameter name="ignore"><![CDATA[-1,0,1,2,3,4,5,6,7]]></parameter>
</parameters>
Expand Down
49 changes: 23 additions & 26 deletions src/main/scala/com/exasol/cloudetl/bucket/GCSBucket.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +57,24 @@ final case class GCSBucket(path: String, params: StorageProperties) extends Buck
}
}

private def validateConnectionProperties(): Unit = {
if (!properties.hasNamedConnection()) {
return
}
val connectionName = properties.getString(CONNECTION_NAME)
val content = getKeyfileContentFromConnection(connectionName)
if (!content.trim().startsWith("{")) {
throw new IllegalArgumentException(
ExaError
.messageBuilder("E-CSE-33")
.message(
"The connection {{connectionName}} does not contain valid JSON in property {{GCS_KEYFILE_CONTENT}}.",
connectionName,
GCS_KEYFILE_CONTENT
)
.mitigation("Please check the connection properties.")
.toString()
)
private def validateConnectionProperties(): Unit =
if (properties.hasNamedConnection()) {
val connectionName = properties.getString(CONNECTION_NAME)
val content = getKeyfileContentFromConnection(connectionName)
if (!content.trim().startsWith("{")) {
throw new IllegalArgumentException(
ExaError
.messageBuilder("E-CSE-33")
.message(
"The connection {{connectionName}} does not contain valid JSON in property {{GCS_KEYFILE_CONTENT}}.",
connectionName,
GCS_KEYFILE_CONTENT
)
.mitigation("Please check the connection properties.")
.toString()
)
}
}
}

/**
* Returns the list of required property keys for Google Cloud Storage.
Expand Down Expand Up @@ -108,15 +106,14 @@ final case class GCSBucket(path: String, params: StorageProperties) extends Buck
conf
}

private def getKeyFilePath(): String = {
private def getKeyFilePath(): String =
if (properties.containsKey(GCS_KEYFILE_PATH)) {
return properties.getString(GCS_KEYFILE_PATH)
properties.getString(GCS_KEYFILE_PATH)
} else {
val connectionName = properties.getString(CONNECTION_NAME)
val jsonContent = getKeyfileContentFromConnection(connectionName)
writeToTempFile(jsonContent)
}
val connectionName = properties.getString(CONNECTION_NAME)
val jsonContent = getKeyfileContentFromConnection(connectionName)
val keyFilePath = writeToTempFile(jsonContent)
return keyFilePath
}

private def getKeyfileContentFromConnection(connectionName: String): String = {
def map = properties.getConnectionProperties(null)
Expand Down
12 changes: 8 additions & 4 deletions src/test/scala/com/exasol/cloudetl/bucket/GCSBucketTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,23 @@ class GCSBucketTest extends AbstractBucketTest {
val invalidConnectionContent = Table(
(
"",
"E-IEUCS-4: Properties input string does not contain key-value assignment '='. Please make sure that key-value pairs encoded correctly."
"E-IEUCS-4: Properties input string does not contain key-value assignment '='. "
+ "Please make sure that key-value pairs encoded correctly."
),
(
"wrong-format",
"E-IEUCS-4: Properties input string does not contain key-value assignment '='. Please make sure that key-value pairs encoded correctly."
"E-IEUCS-4: Properties input string does not contain key-value assignment '='. "
+ "Please make sure that key-value pairs encoded correctly."
),
(
"wrong_key=value",
"E-CSE-32: The connection 'connection_info' does not contain 'GCS_KEYFILE_CONTENT' property. Please check the connection properties."
"E-CSE-32: The connection 'connection_info' does not contain 'GCS_KEYFILE_CONTENT' property. "
+ "Please check the connection properties."
),
(
"GCS_KEYFILE_CONTENT=invalid_json",
"E-CSE-33: The connection 'connection_info' does not contain valid JSON in property 'GCS_KEYFILE_CONTENT'. Please check the connection properties."
"E-CSE-33: The connection 'connection_info' does not contain valid JSON in property 'GCS_KEYFILE_CONTENT'. "
+ "Please check the connection properties."
)
)
forAll(invalidConnectionContent) { (connectionContent: String, expectedErrorMessage: String) =>
Expand Down

0 comments on commit 1530540

Please sign in to comment.