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

DAT-18810: app naming updated, it contains now versions of core/pro liquibase and extension version also. #595

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@
<artifactId>json</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
<version>3.9.9</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
package liquibase.ext.mongodb.database;

import com.mongodb.ConnectionString;
import com.mongodb.MongoClientSettings;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import com.mongodb.MongoClientSettings;
import com.mongodb.MongoClientSettings.Builder;
import liquibase.Scope;
import liquibase.exception.DatabaseException;
import liquibase.util.LiquibaseUtil;
import liquibase.util.StringUtil;
import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverPropertyInfo;
import java.util.Enumeration;
import java.util.Properties;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
import java.util.logging.Logger;

public class MongoClientDriver implements Driver {
Expand All @@ -28,7 +39,7 @@

MongoClientSettings settings = MongoClientSettings.builder()
.applyConnectionString(connectionString)
.applicationName("Liquibase")
.applicationName(getFullApplicationName())
.build();

try {
Expand All @@ -40,6 +51,27 @@
return client;
}

private String getFullApplicationName() {
try {
MavenXpp3Reader reader = new MavenXpp3Reader();
Model model = reader.read(new FileReader("pom.xml"));

Check warning

Code scanning / CodeQL

Potential input resource leak Warning

This FileReader is not always closed on method exit.

boolean isCommercial = model.getArtifactId().contains("commercial");
String buildVersion = LiquibaseUtil.getBuildVersion();
String extVersion = model.getVersion();
String appType = isCommercial ? "PRO" : "OSS";
String extType = isCommercial ? "ProExt" : "OssExt";
URL url = Scope.getCurrentScope().getClassLoader().getResource("META-INF/MANIFEST.MF");
Manifest manifest = new Manifest(url.openStream());
Attributes attr = manifest.getMainAttributes();

Check notice

Code scanning / CodeQL

Unread local variable Note

Variable 'Attributes attr' is never read.

return String.join("_", "Liquibase", appType, buildVersion, extType, extVersion);
} catch (XmlPullParserException | IOException e) {
Scope.getCurrentScope().getLog(this.getClass()).warning("Failed to extract application full name for current connection.");
}
return "";
}

@Override
public boolean acceptsURL(final String url) {
final String trimmedUrl = StringUtil.trimToEmpty(url);
Expand Down
Loading