From c7bd42337530ca5ec58d3ca0668164783811015a Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 30 Sep 2011 16:17:56 +0000 Subject: [PATCH] more easy version display using bean properties git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1177720 13f79535-47bb-0310-9956-ffa450edef68 --- .../filtered-resources/application.properties | 1 + .../web/action/AbstractActionSupport.java | 10 +++ .../archiva/web/startup/ArchivaStartup.java | 12 ++- .../archiva/web/startup/ArchivaVersion.java | 83 ------------------- .../apache/archiva/web/startup/Banner.java | 4 +- .../resources/META-INF/spring-context.xml | 6 +- .../webapp/WEB-INF/applicationContext.xml | 3 +- .../webapp/WEB-INF/jsp/decorators/default.jsp | 3 +- 8 files changed, 28 insertions(+), 94 deletions(-) delete mode 100644 archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/startup/ArchivaVersion.java diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/filtered-resources/application.properties b/archiva-modules/archiva-web/archiva-webapp/src/main/filtered-resources/application.properties index b83169335..0f38c6dcc 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/filtered-resources/application.properties +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/filtered-resources/application.properties @@ -17,3 +17,4 @@ # under the License. # user.agent=Apache Archiva/${project.version} +archiva.version=${project.version} diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/AbstractActionSupport.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/AbstractActionSupport.java index 4ba7a293b..496b040c7 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/AbstractActionSupport.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/AbstractActionSupport.java @@ -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 diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/startup/ArchivaStartup.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/startup/ArchivaStartup.java index da4bcce25..46aca0bb7 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/startup/ArchivaStartup.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/startup/ArchivaStartup.java @@ -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 index bd91e288e..000000000 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/startup/ArchivaVersion.java +++ /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; - } -} diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/startup/Banner.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/startup/Banner.java index 23ff026af..e9272c808 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/startup/Banner.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/startup/Banner.java @@ -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 ); } } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/resources/META-INF/spring-context.xml b/archiva-modules/archiva-web/archiva-webapp/src/main/resources/META-INF/spring-context.xml index d4e9628f1..acce3d04e 100755 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/resources/META-INF/spring-context.xml +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/resources/META-INF/spring-context.xml @@ -21,14 +21,18 @@ + \ No newline at end of file diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/applicationContext.xml b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/applicationContext.xml index d5e6f2fd4..8900c7ec6 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/applicationContext.xml +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/applicationContext.xml @@ -25,8 +25,7 @@ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> - - + diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/decorators/default.jsp b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/decorators/default.jsp index 497e04000..7a6d490f1 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/decorators/default.jsp +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/decorators/default.jsp @@ -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" %> @@ -196,7 +195,7 @@