]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
DRYD-1145: Get version info from implementation version (#311)
authorMichael Ritter <mikejritter@users.noreply.github.com>
Fri, 24 Feb 2023 00:27:04 +0000 (17:27 -0700)
committerGitHub <noreply@github.com>
Fri, 24 Feb 2023 00:27:04 +0000 (19:27 -0500)
* Reformatting

* DRYD-1145: Add build info to manifest for jar and war files

* DRYD-1145: Use implementation version for systeminfo endpoint

* Update version display name

* Add git commit id

pom.xml
services/common/src/main/java/org/collectionspace/services/common/ServiceMain.java
services/systeminfo/service/src/main/java/org/collectionspace/services/systeminfo/SystemInfoResource.java

diff --git a/pom.xml b/pom.xml
index 1d7691be519747af8a7ce8891405852ae86f2f2f..e3b6626f31d108b7ffbe831447c67ce1ee43083d 100644 (file)
--- a/pom.xml
+++ b/pom.xml
                                                <archive>
                                                        <manifest>
                                                                <addClasspath>true</addClasspath>
+                                                               <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
+                                                               <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
                                                        </manifest>
                                                </archive>
                                        </configuration>
                                        <groupId>org.apache.maven.plugins</groupId>
                                        <artifactId>maven-jar-plugin</artifactId>
                                        <version>2.2</version>
+                                       <configuration>
+                                               <archive>
+                                                       <manifest>
+                                                               <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
+                                                               <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
+                                                       </manifest>
+                                               </archive>
+                                       </configuration>
+                               </plugin>
+
+                               <plugin>
+                                       <groupId>pl.project13.maven</groupId>
+                                       <artifactId>git-commit-id-plugin</artifactId>
+                                       <version>4.9.10</version>
+                                       <executions>
+                                               <execution>
+                                                       <goals>
+                                                               <goal>revision</goal>
+                                                       </goals>
+                                                       <phase>initialize</phase>
+                                               </execution>
+                                       </executions>
+                                       <configuration>
+                                               <generateGitPropertiesFile>true</generateGitPropertiesFile>
+                                               <generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
+                                               <includeOnlyProperties>
+                                                       <includeOnlyProperty>^git.commit.id.abbrev$</includeOnlyProperty>
+                                               </includeOnlyProperties>
+                                               <commitIdGenerationMode>full</commitIdGenerationMode>
+                                       </configuration>
                                </plugin>
 
                                <plugin>
                     </files>
                 </configuration>
             </plugin>
+
+                       <plugin>
+                               <groupId>pl.project13.maven</groupId>
+                               <artifactId>git-commit-id-plugin</artifactId>
+                       </plugin>
                </plugins>
        </build>
 
index d7f54fe4238e485cf0f23e267cd42621818b3c33..d11f79681962b26f2656ff2e91557047029152e2 100644 (file)
@@ -74,11 +74,6 @@ import org.slf4j.LoggerFactory;
 public class ServiceMain {
        final static Logger logger = LoggerFactory.getLogger(ServiceMain.class);
 
-       public static final String VER_DISPLAY_NAME = "CollectionSpace Services v7.1";
-       public static final String VER_MAJOR = "7";
-       public static final String VER_MINOR = "1";
-       public static final String VER_PATCH = "0";
-       public static final String VER_BUILD = "1";
 
        private static final int PRIMARY_REPOSITORY_DOMAIN = 0;
 
@@ -1045,7 +1040,7 @@ public class ServiceMain {
        }
 
        private void initRepositoryDatabaseVersion(String dataSourceName, String repositoryName, String cspaceInstanceId) throws Exception {
-               String version = ServiceMain.VER_MAJOR + "." + ServiceMain.VER_MINOR + "." + ServiceMain.VER_PATCH;
+               String version = getClass().getPackage().getImplementationVersion();
                Connection conn = null;
 
                try {
index 24e45547a44492050459b86f944c822397e065e1..d7dfc6c1ea0b3872532cd3cc0e858d8136b0ef3d 100644 (file)
@@ -1,26 +1,25 @@
 package org.collectionspace.services.systeminfo;
 
+import java.io.IOException;
 import java.nio.charset.Charset;
 import java.util.Locale;
+import java.util.Properties;
 import java.util.TimeZone;
-
 import javax.ws.rs.Consumes;
 import javax.ws.rs.GET;
+import javax.ws.rs.HttpMethod;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
-import javax.ws.rs.HttpMethod;
 
 import org.collectionspace.services.authorization.AuthZ;
-import org.collectionspace.services.authorization.CSpaceAction;
 import org.collectionspace.services.authorization.CSpaceResource;
 import org.collectionspace.services.authorization.URIResourceImpl;
 import org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl;
 import org.collectionspace.services.common.CSWebApplicationException;
 import org.collectionspace.services.common.ServiceMain;
-import org.collectionspace.services.common.UriInfoWrapper;
 import org.collectionspace.services.common.context.RemoteServiceContextFactory;
 import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.context.ServiceContextFactory;
@@ -31,74 +30,95 @@ import org.collectionspace.services.common.security.UnauthorizedException;
 @Consumes({"application/xml"})
 public class SystemInfoResource extends AbstractCollectionSpaceResourceImpl<SystemInfoCommon, SystemInfoCommon> {
 
-       @Override
-       public Class<?> getCommonPartClass() {
-               // TODO Auto-generated method stub
-               return null;
-       }
+    private static final String VER_DISPLAY_NAME = "CollectionSpace Services v%s.%s";
+    private static final int MAJOR_IDX = 0;
+    private static final int MINOR_IDX = 1;
+    private static final int PATCH_IDX = 2;
+
+    @Override
+    public Class<?> getCommonPartClass() {
+        // TODO Auto-generated method stub
+        return null;
+    }
 
-       @Override
-       public String getServiceName() {
-               return SystemInfoClient.SERVICE_NAME;
-       }
+    @Override
+    public String getServiceName() {
+        return SystemInfoClient.SERVICE_NAME;
+    }
 
-       @Override
-       protected String getVersionString() {
-               // TODO Auto-generated method stub
-               return null;
-       }
+    @Override
+    protected String getVersionString() {
+        // TODO Auto-generated method stub
+        return null;
+    }
 
-       //
-       // API Endpoints
-       //
+    //
+    // API Endpoints
+    //
 
     @GET
     public SystemInfoCommon get(@Context UriInfo ui) {
-       SystemInfoCommon result = null;
-
-       try {
-               result = new SystemInfoCommon();
-               result.setInstanceId(ServiceMain.getInstance().getCspaceInstanceId());
-               result.setDisplayName(ServiceMain.VER_DISPLAY_NAME);
-               Version ver = new Version();
-               ver.setMajor(ServiceMain.VER_MAJOR);
-               ver.setMinor(ServiceMain.VER_MINOR);
-               ver.setPatch(ServiceMain.VER_PATCH);
-               ver.setBuild(ServiceMain.VER_BUILD);
-               result.setVersion(ver);
-
-               result.setHostTimezone(TimeZone.getDefault().getID());
-               result.setHostLocale(Locale.getDefault().toLanguageTag());
-               result.setHostCharset(Charset.defaultCharset().name());
-               //
-               // To get the full set of the system information, we required the user be authenticated *and* have "DELETE" privs on the "systeminfo" resource
-               //
-               try {
-                       ServiceContext<SystemInfoCommon, SystemInfoCommon> ctx = createServiceContext(getServiceName(), ui);
-                       CSpaceResource res = new URIResourceImpl(ctx.getTenantId(), SystemInfoClient.SERVICE_NAME, HttpMethod.DELETE);
-                       if (AuthZ.get().isAccessAllowed(res)) {
-                                                       // TODO: Stop hardcoding this!
-                                                       // result.setNuxeoVersionString("7.10-HF17");
-                                                       result.setHost(String.format("Architecture:%s Name:%s Version:%s",
-                                                                       System.getProperty("os.arch"), System.getProperty("os.name"), System.getProperty("os.version")));
-                                                       result.setJavaVersionString(System.getProperty("java.version"));
-                                                       // TODO: Stop hardcoding this!
-                                                       // result.setPostgresVersionString("9.5.7");
-                                       }
-                               } catch (UnauthorizedException e) {
-                               logger.trace(e.getMessage(), e);
-               }
-
-       } catch(Exception e) {
-               Response response = Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).type("text/plain").build();
+        SystemInfoCommon result;
+
+        try {
+            String packageVersion = SystemInfoResource.class.getPackage().getImplementationVersion();
+            String[] versionParts = packageVersion.split("\\.");
+
+            result = new SystemInfoCommon();
+            result.setInstanceId(ServiceMain.getInstance().getCspaceInstanceId());
+            result.setDisplayName(String.format(VER_DISPLAY_NAME, versionParts[MAJOR_IDX], versionParts[MINOR_IDX]));
+
+            Version ver = new Version();
+            ver.setMajor(versionParts[MAJOR_IDX]);
+            ver.setMinor(versionParts[MINOR_IDX]);
+            ver.setPatch(versionParts[PATCH_IDX]);
+            ver.setBuild(readGitCommitId());
+            result.setVersion(ver);
+
+            result.setHostTimezone(TimeZone.getDefault().getID());
+            result.setHostLocale(Locale.getDefault().toLanguageTag());
+            result.setHostCharset(Charset.defaultCharset().name());
+
+            // To get the full set of the system information, we required the user be authenticated *and* have "DELETE"
+            // privs on the "systeminfo" resource
+            try {
+                ServiceContext<SystemInfoCommon, SystemInfoCommon> ctx = createServiceContext(getServiceName(), ui);
+                CSpaceResource res = new URIResourceImpl(ctx.getTenantId(), SystemInfoClient.SERVICE_NAME,
+                                                         HttpMethod.DELETE);
+                if (AuthZ.get().isAccessAllowed(res)) {
+                    // TODO: Stop hardcoding this!
+                    // result.setNuxeoVersionString("7.10-HF17");
+                    result.setHost(String.format("Architecture:%s Name:%s Version:%s",
+                                                 System.getProperty("os.arch"),
+                                                 System.getProperty("os.name"),
+                                                 System.getProperty("os.version")));
+                    result.setJavaVersionString(System.getProperty("java.version"));
+                    // TODO: Stop hardcoding this!
+                    // result.setPostgresVersionString("9.5.7");
+                }
+            } catch (UnauthorizedException e) {
+                logger.trace(e.getMessage(), e);
+            }
+
+        } catch (Exception e) {
+            logger.error("Error generating system info", e);
+            Response response = Response.status(Response.Status.BAD_REQUEST)
+                                        .entity(e.getMessage())
+                                        .type("text/plain").build();
             throw new CSWebApplicationException(response);
-       }
+        }
+
+        return result;
+    }
 
-       return result;
+    private String readGitCommitId() throws IOException {
+        Properties properties = new Properties();
+        properties.load(getClass().getClassLoader().getResourceAsStream("git.properties"));
+        return properties.getProperty("git.commit.id.abbrev");
     }
 
-       @Override
-       public ServiceContextFactory<SystemInfoCommon, SystemInfoCommon> getServiceContextFactory() {
+    @Override
+    public ServiceContextFactory<SystemInfoCommon, SystemInfoCommon> getServiceContextFactory() {
         return (ServiceContextFactory<SystemInfoCommon, SystemInfoCommon>) RemoteServiceContextFactory.get();
-       }
+    }
 }