Skip to content

Commit

Permalink
[Enhancement #243] Log JOPA version info on PU start.
Browse files Browse the repository at this point in the history
  • Loading branch information
ledsoft committed Jun 12, 2024
1 parent 139acde commit ae7e564
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
13 changes: 13 additions & 0 deletions jopa-impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<packaging>jar</packaging>

<properties>
<maven.build.timestamp.format>yyyy-MM-dd</maven.build.timestamp.format>

<org.antlr4.version>4.12.0</org.antlr4.version>
<net.bytebuddy.version>1.14.8</net.bytebuddy.version>
</properties>
Expand Down Expand Up @@ -49,6 +51,12 @@


<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.antlr</groupId>
Expand All @@ -63,6 +71,11 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,46 @@
*/
package cz.cvut.kbss.jopa.model;

import java.util.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
import java.util.Set;

public class JOPAPersistenceProvider implements PersistenceProvider, ProviderUtil {

private static final Logger LOG = LoggerFactory.getLogger(JOPAPersistenceProvider.class);

private static final Set<EntityManagerFactoryImpl> EMFS = Collections.synchronizedSet(new HashSet<>());

public JOPAPersistenceProvider() {
logVersionInfo();
}

@Override
public EntityManagerFactoryImpl createEntityManagerFactory(String emName, Map<String, String> properties) {
final EntityManagerFactoryImpl emf = new EntityManagerFactoryImpl(properties, this::emfClosed);
EMFS.add(emf);
return emf;
}

private static void logVersionInfo() {
try {
final Properties props = new Properties();
props.load(JOPAPersistenceProvider.class.getClassLoader().getResourceAsStream("jopa.properties"));
assert props.containsKey("cz.cvut.jopa.version");
assert props.containsKey("cz.cvut.jopa.build.timestamp");
LOG.info("This is JOPA {}, built on {}...", props.get("cz.cvut.jopa.version"), props.get("cz.cvut.jopa.build.timestamp"));
} catch (IOException e) {
LOG.warn("Unable to load properties file to log version info.", e);
}
}

void emfClosed(EntityManagerFactoryImpl emf) {
EMFS.remove(emf);
}
Expand Down
2 changes: 2 additions & 0 deletions jopa-impl/src/main/resources/jopa.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cz.cvut.jopa.version=${project.version}
cz.cvut.jopa.build.timestamp=${maven.build.timestamp}

0 comments on commit ae7e564

Please sign in to comment.