]> source.dussan.org Git - archiva.git/commitdiff
more easy version display using bean properties
authorOlivier Lamy <olamy@apache.org>
Fri, 30 Sep 2011 16:17:56 +0000 (16:17 +0000)
committerOlivier Lamy <olamy@apache.org>
Fri, 30 Sep 2011 16:17:56 +0000 (16:17 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1177720 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webapp/src/main/filtered-resources/application.properties
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/AbstractActionSupport.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/startup/ArchivaStartup.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/startup/ArchivaVersion.java [deleted file]
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/startup/Banner.java
archiva-modules/archiva-web/archiva-webapp/src/main/resources/META-INF/spring-context.xml
archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/applicationContext.xml
archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/decorators/default.jsp

index 4ba7a293b1fda6ee95ea7e4c089d39e5105b009b..496b040c75004168c867e4cf486e28ffe21d8b4e 100644 (file)
@@ -44,6 +44,7 @@ import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 
 /**
  * LogEnabled and SessionAware ActionSupport
@@ -69,6 +70,10 @@ public abstract class AbstractActionSupport
 
     private String principal;
 
+    @Inject
+    @Named(value = "archivaRuntimeProperties")
+    private Properties archivaRuntimeProperties;
+
     @PostConstruct
     public void initialize()
     {
@@ -185,6 +190,11 @@ public abstract class AbstractActionSupport
         return auditInformation;
     }
 
+    public String getArchivaVersion()
+    {
+        return (String) archivaRuntimeProperties.get( "archiva.version" );
+    }
+
     /**
      * dummy information for audit events
      * @since 1.4
index da4bcce2558c239b71f401a9afe67288462c30c5..46aca0bb75c572b67d6c1bdc03296239946ab300 100644 (file)
@@ -19,10 +19,10 @@ package org.apache.archiva.web.startup;
  * under the License.
  */
 
+import org.apache.archiva.common.ArchivaException;
 import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
 import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException;
 import org.apache.archiva.scheduler.repository.RepositoryArchivaTaskScheduler;
-import org.apache.archiva.common.ArchivaException;
 import org.apache.maven.index.NexusIndexer;
 import org.apache.maven.index.context.IndexingContext;
 import org.codehaus.plexus.taskqueue.Task;
@@ -35,6 +35,7 @@ import org.springframework.web.context.support.WebApplicationContextUtils;
 import javax.servlet.ServletContextEvent;
 import javax.servlet.ServletContextListener;
 import java.lang.reflect.Field;
+import java.util.Properties;
 import java.util.concurrent.ExecutorService;
 
 /**
@@ -67,6 +68,8 @@ public class ArchivaStartup
         repositoryTaskScheduler =
             wac.getBean( "archivaTaskScheduler#repository", RepositoryArchivaTaskScheduler.class );
 
+        Properties archivaRuntimeProperties = wac.getBean( "archivaRuntimeProperties", Properties.class );
+
         tqeRepoScanning = wac.getBean( "taskQueueExecutor#repository-scanning", ThreadedTaskQueueExecutor.class );
 
         tqeIndexing = wac.getBean( "taskQueueExecutor#indexing", ThreadedTaskQueueExecutor.class );
@@ -85,7 +88,7 @@ public class ArchivaStartup
         {
             securitySync.startup();
             repositoryTaskScheduler.startup();
-            Banner.display();
+            Banner.display( (String) archivaRuntimeProperties.get( "archiva.version" ) );
         }
         catch ( ArchivaException e )
         {
@@ -147,12 +150,13 @@ public class ArchivaStartup
         }
 
         // closing correctly indexer to close correctly lock and file
-        for( IndexingContext indexingContext : nexusIndexer.getIndexingContexts().values() )
+        for ( IndexingContext indexingContext : nexusIndexer.getIndexingContexts().values() )
         {
             try
             {
                 indexingContext.close( false );
-            } catch ( Exception e )
+            }
+            catch ( Exception e )
             {
                 contextEvent.getServletContext().log( "skip error closing indexingContext " + e.getMessage() );
             }
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/startup/ArchivaVersion.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/startup/ArchivaVersion.java
deleted file mode 100644 (file)
index bd91e28..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-package org.apache.archiva.web.startup;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Properties;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang.StringUtils;
-import org.apache.archiva.configuration.ArchivaConfiguration;
-
-/**
- * ArchivaVersion 
- *
- * @version $Id$
- */
-public class ArchivaVersion
-{
-    private static String version = null;
-
-    private ArchivaVersion()
-    {
-    }
-
-    public static String determineVersion(  )
-    {
-        if ( version != null )
-        {
-            return version;
-        }
-        
-        InputStream is = ArchivaConfiguration.class.getResourceAsStream( "/META-INF/maven/org.apache.archiva/archiva-configuration/pom.properties" );
-        
-        if ( is != null )
-        {
-            try
-            {
-                Properties props = new Properties();
-                props.load( is );
-                String version = props.getProperty( "version" );
-                if ( StringUtils.isNotBlank( version ) )
-                {
-                    ArchivaVersion.version = version;
-                    return version;
-                }
-            }
-            catch ( IOException e )
-            {
-                /* do nothing */
-            }
-            finally
-            {
-                IOUtils.closeQuietly( is );
-            }
-        }
-
-        ArchivaVersion.version = "";
-        return version;
-    }
-
-    public static String getVersion()
-    {
-        return version;
-    }
-}
index 23ff026af4b4244f0f7db06d9bdb47760021d1ee..e9272c808dae81e08e35ed08076f407fc128cfbd 100644 (file)
@@ -221,9 +221,9 @@ public class Banner
         return injectVersion( decode( encodedBanner ), version );
     }
 
-    public static void display()
+    public static void display( String version )
     {
-        String banner = getBanner( ArchivaVersion.determineVersion() );
+        String banner = getBanner( version );
        LoggerFactory.getLogger( Banner.class ).info( StringUtils.repeat( "_", 25 ) + eol + banner );
     }
 }
index d4e9628f1bcc9beb57fda1895c9b3fcd1249a358..acce3d04eeed87c7a0d99f656ec68dfe08211f7c 100755 (executable)
 <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:context="http://www.springframework.org/schema/context"
+       xmlns:util="http://www.springframework.org/schema/util"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
            http://www.springframework.org/schema/context 
-           http://www.springframework.org/schema/context/spring-context-3.0.xsd"
+           http://www.springframework.org/schema/context/spring-context-3.0.xsd
+           http://www.springframework.org/schema/util
+           http://www.springframework.org/schema/util/spring-util-3.0.xsd"
        default-lazy-init="true">
 
   <context:annotation-config/>
   <context:component-scan base-package="org.apache.archiva.web"/>
 
+  <util:properties id="archivaRuntimeProperties" location="classpath:application.properties" />
 
 </beans>
\ No newline at end of file
index d5e6f2fd46fe427e279e75b7b0a6cb6c6d54fbee..8900c7ec69a2b930f9ebe60ca6f440ebc158cf7a 100644 (file)
@@ -25,8 +25,7 @@
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context-3.0.xsd">
 
-  <context:property-placeholder location="classpath:application.properties" />
-
+  <context:property-placeholder location="classpath:application.properties"/>
 
   <bean id="loggerManager" class="org.codehaus.plexus.logging.slf4j.Slf4jLoggerManager"
         init-method="initialize"/>
index 497e040003634860f8a35dac94eaf57c4d68f3b6..7a6d490f128ebf7eaffed8fb09c9ffe468547496 100644 (file)
@@ -26,7 +26,6 @@
 <%@ taglib prefix="my" tagdir="/WEB-INF/tags" %>
 <%@ taglib prefix="redback" uri="http://plexus.codehaus.org/redback/taglib-1.0" %>
 <%@ page import="java.util.Calendar" %>
-<%@ page import="org.apache.archiva.web.startup.ArchivaVersion" %>
 
 <html>
 <head>
 
 <div id="footer">
   <div class="xleft">
-    <a target="_blank" href="http://archiva.apache.org/">Apache Ar<c:if test="${is19Sep}">rr</c:if>chiva <%= ArchivaVersion.getVersion()%></a>
+    <a target="_blank" href="http://archiva.apache.org/">Apache Ar<c:if test="${is19Sep}">rr</c:if>chiva&nbsp;-&nbsp;<s:property value="archivaVersion"/></a>
   </div>
   <div class="xright">
     Copyright &#169; <%= copyrightRange%> <a target="_blank" href="http://www.apache.org/">The Apache Software Foundation</a>