Permalink
Browse files

Use timestamped js/css files

A build timestamp in the actual resource path will provide better
browser cache busting.
  • Loading branch information...
1 parent ca7dcaa commit 6bf9773958de4c3d3959afc07e582ef8cdb770c0 @nabcos nabcos committed with cstamas Nov 19, 2012
@@ -266,7 +266,7 @@
<aggregations>
<aggregation>
<insertNewLine>true</insertNewLine>
- <output>${compressed-dir}/js/sonatype-all.js</output>
+ <output>${project.build.outputDirectory}/js/sonatype-all.js</output>
<inputDir>${project.build.directory}/generated-sources/yuicompressor/js</inputDir>
<excludes>
<exclude>lib/require*.js</exclude>
@@ -276,7 +276,7 @@
</includes>
</aggregation>
<aggregation>
- <output>${compressed-dir}/style/sonatype-all.css</output>
+ <output>${project.build.outputDirectory}/style/sonatype-all.css</output>
<inputDir>${project.build.directory}/generated-sources/yuicompressor/style</inputDir>
<includes>
<include>**/*.css</include>
@@ -342,15 +342,6 @@
js/lib/*,
style/sonatype-all.css
</warSourceIncludes>
- <webResources>
- <webResource>
- <directory>${compressed-dir}</directory>
- <includes>
- <include>**/sonatype-all.js</include>
- <include>**/sonatype-all.css</include>
- </includes>
- </webResource>
- </webResources>
</configuration>
</plugin>
@@ -29,6 +29,9 @@
<properties>
<nexus.plugin.name>Nexus Restlet 1.x Plugin</nexus.plugin.name>
<nexus.plugin.description>Provides Restlet 1.x REST API.</nexus.plugin.description>
+
+ <maven.build.timestamp.format>yyyyMMddHHmm</maven.build.timestamp.format>
+ <build.timestamp>${maven.build.timestamp}</build.timestamp>
</properties>
<dependencies>
@@ -164,6 +167,15 @@
</dependencies>
<build>
+ <resources>
+ <resource>
+ <directory>src/main/resources</directory>
+ </resource>
+ <resource>
+ <directory>src/main/filtered-resources</directory>
+ <filtering>true</filtering>
+ </resource>
+ </resources>
<plugins>
<plugin>
<groupId>org.sonatype.plugins</groupId>
@@ -0,0 +1,7 @@
+#
+# Copyright (c) 2011-2012 Sonatype, Inc. All rights reserved.
+# Includes the third-party code listed at http://links.sonatype.com/products/rhc/oss/attributions.
+# "Sonatype" is a trademark of Sonatype, Inc.
+#
+
+version = ${build.timestamp}
@@ -0,0 +1,61 @@
+/**
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+package org.sonatype.nexus.plugins.restlet1x;
+
+import java.io.InputStream;
+import java.util.Properties;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import org.apache.commons.io.IOUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Named
+@Singleton
+public class BuildNumberService
+{
+
+ private static final Logger logger = LoggerFactory.getLogger( BuildNumberService.class );
+
+ private final String buildNumber;
+
+ @Inject
+ BuildNumberService()
+ {
+ Properties props = new Properties();
+
+ InputStream is = getClass().getResourceAsStream( "version.properties" );
+ try
+ {
+ props.load( is );
+ }
+ catch ( Exception e )
+ {
+ logger.warn( "Could not determine build qualifier", e );
+ }
+ finally
+ {
+ IOUtils.closeQuietly( is );
+ }
+
+ buildNumber = props.getProperty( "version", "unknown-version" );
+ }
+
+ public String getBuildNumber()
+ {
+ return buildNumber;
+ }
+
+}
@@ -0,0 +1,56 @@
+/**
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+package org.sonatype.nexus.plugins.restlet1x;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.sonatype.nexus.plugins.rest.AbstractNexusResourceBundle;
+import org.sonatype.nexus.plugins.rest.DefaultStaticResource;
+import org.sonatype.nexus.plugins.rest.StaticResource;
+
+@Named
+public class NexusWebappResourceBundle
+ extends AbstractNexusResourceBundle
+{
+
+ private final BuildNumberService buildNumberService;
+
+ private static final Logger logger = LoggerFactory.getLogger( NexusWebappResourceBundle.class );
+
+ @Inject
+ public NexusWebappResourceBundle( final BuildNumberService buildNumberService )
+ {
+ this.buildNumberService = buildNumberService;
+ }
+
+ @Override
+ public List<StaticResource> getContributedResouces()
+ {
+ String prefix = buildNumberService.getBuildNumber();
+
+ List<StaticResource> result = new ArrayList<StaticResource>();
+
+ result.add( new DefaultStaticResource( this.getClass().getResource( "/js/sonatype-all.js" ),
+ "/js/" + prefix + "/sonatype-all.js", "text/javascript" ));
+ result.add( new DefaultStaticResource( this.getClass().getResource( "/style/sonatype-all.css" ),
+ "/style/" + prefix + "/sonatype-all.css", "text/css" ));
+
+ return result;
+ }
+
+}
@@ -18,6 +18,10 @@
import java.util.List;
import java.util.Map;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+
import org.apache.velocity.VelocityContext;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Configuration;
@@ -39,33 +43,45 @@
import org.restlet.resource.Variant;
import org.sonatype.nexus.Nexus;
import org.sonatype.nexus.plugins.rest.NexusIndexHtmlCustomizer;
+import org.sonatype.nexus.plugins.restlet1x.BuildNumberService;
import org.sonatype.plexus.rest.representation.VelocityRepresentation;
import org.sonatype.plexus.rest.resource.AbstractPlexusResource;
import org.sonatype.plexus.rest.resource.ManagedPlexusResource;
import org.sonatype.plexus.rest.resource.PathProtectionDescriptor;
import org.sonatype.sisu.velocity.Velocity;
-@Component( role = ManagedPlexusResource.class, hint = "indexTemplate" )
+@Named("indexTemplate")
+@Singleton
public class IndexTemplatePlexusResource
extends AbstractPlexusResource
- implements ManagedPlexusResource, Initializable
+ implements ManagedPlexusResource
{
- @Requirement
private Nexus nexus;
- @Requirement( role = NexusIndexHtmlCustomizer.class )
private Map<String, NexusIndexHtmlCustomizer> bundles;
- @Requirement
private Velocity velocity;
- @Configuration( value = "${index.template.file}" )
+ private BuildNumberService buildNumberService;
+
String templateFilename;
- public IndexTemplatePlexusResource()
+ @Inject
+ public IndexTemplatePlexusResource( final Map<String, NexusIndexHtmlCustomizer> bundles, final Nexus nexus,
+ final @Named("${index.template.file:-templates/index.vm}") String templateFilename,
+ final Velocity velocity, final BuildNumberService buildNumberService )
{
- super();
+ this();
+ this.bundles = bundles;
+ this.nexus = nexus;
+ this.templateFilename = templateFilename;
+ this.velocity = velocity;
+ this.buildNumberService = buildNumberService;
+ }
+
+ public IndexTemplatePlexusResource()
+ {
setReadable( true );
setModifiable( false );
@@ -200,6 +216,8 @@ protected VelocityRepresentation render( Context context, Request request, Respo
}
templatingContext.put( "debug", debug );
+ templatingContext.put( "buildQualifier", buildNumberService.getBuildNumber() );
+
return new VelocityRepresentation( context, templateFilename, getClass().getClassLoader(), templatingContext, MediaType.TEXT_HTML );
}
@@ -232,14 +250,4 @@ protected void evaluateIfNeeded( Map<String, Object> context, String template,
}
}
}
-
- public void initialize()
- throws InitializationException
- {
- // Hasn't been interpolated
- if ( "${index.template.file}".equals( templateFilename ) )
- {
- templateFilename = "templates/index.vm";
- }
- }
}
@@ -31,7 +31,7 @@
<link rel="stylesheet" href="ext-3.4.0/resources/css/ext-all.css" type="text/css" media="screen" charset="utf-8">
<link rel="stylesheet" href="ext-3.4.0/resources/css/xtheme-gray.css" type="text/css" media="screen" charset="utf-8">
- <link rel="stylesheet" href="style/sonatype-all.css?$nexusVersion" type="text/css" media="screen" title="no title" charset="utf-8">
+ <link rel="stylesheet" href="style/$buildQualifier/sonatype-all.css" type="text/css" media="screen" title="no title" charset="utf-8">
## <script src="js/sonatype-all.js?$nexusVersion" type="text/javascript" charset="utf-8"></script>
<script src="ext-3.4.0/adapter/ext/ext-base$!{debug}.js" type="text/javascript" charset="utf-8"></script>
@@ -48,7 +48,7 @@
#if ($!debug != "-debug")
## load aggregated module definitions
- <script src="js/sonatype-all.js?$nexusVersion" type="text/javascript" charset="utf-8"></script>
+ <script src="js/$buildQualifier/sonatype-all.js" type="text/javascript" charset="utf-8"></script>
#end
<script type="text/javascript" charset="utf-8">

0 comments on commit 6bf9773

Please sign in to comment.