Permalink
Browse files

Merge branch 'master' into NXCM-5181-allowForceUpdateOfSystemStatus

  • Loading branch information...
2 parents 52221aa + 46b1f8d commit f11fba989a5ff8d4017bb98b4846111a9d877178 @kellyrob99 kellyrob99 committed Apr 9, 2013
Showing with 1,609 additions and 804 deletions.
  1. +85 −0 nexus-client-core/src/main/java/org/sonatype/nexus/client/internal/util/Version.java
  2. +9 −2 nexus-client-core/src/main/java/org/sonatype/nexus/client/rest/jersey/JerseyNexusClientFactory.java
  3. +2 −0 ...test/filtered-resources/META-INF/maven/org.sonatype.nexus.client/nexus-client-core/pom.properties
  4. +64 −0 ...-core/src/test/java/org/sonatype/nexus/client/rest/jersey/JerseyNexusTestClientUserAgentTest.java
  5. +57 −0 nexus-core/src/main/java/org/sonatype/nexus/guice/AbstractInterceptorModule.java
  6. +2 −3 nexus-core/src/main/java/org/sonatype/nexus/guice/NexusModules.java
  7. +11 −6 nexus-core/src/main/java/org/sonatype/nexus/plugins/DefaultNexusPluginManager.java
  8. +8 −0 nexus-core/src/main/java/org/sonatype/nexus/proxy/maven/AbstractChecksumContentValidator.java
  9. +1 −1 nexus-core/src/main/java/org/sonatype/nexus/proxy/maven/ChecksumContentValidator.java
  10. +18 −0 nexus-core/src/main/java/org/sonatype/nexus/proxy/maven/ChecksumPolicy.java
  11. +4 −3 nexus-core/src/main/java/org/sonatype/nexus/proxy/maven/metadata/operations/AddPluginOperation.java
  12. +7 −6 nexus-core/src/main/java/org/sonatype/nexus/proxy/maven/metadata/operations/MetadataUtil.java
  13. +12 −0 nexus-core/src/main/java/org/sonatype/nexus/proxy/maven/routing/internal/FilePrefixSource.java
  14. +37 −3 ...-core/src/main/java/org/sonatype/nexus/proxy/maven/routing/internal/RemotePrefixFileStrategy.java
  15. +12 −8 ...core/src/main/java/org/sonatype/nexus/proxy/storage/local/fs/DefaultFSLocalRepositoryStorage.java
  16. +2 −3 nexus-core/src/main/java/org/sonatype/nexus/proxy/storage/local/fs/DefaultFSPeer.java
  17. +5 −1 nexus-core/src/main/java/org/sonatype/nexus/scheduling/AbstractNexusRepositoriesTask.java
  18. +6 −2 nexus-core/src/main/java/org/sonatype/nexus/timing/TimingModule.java
  19. +4 −1 nexus-core/src/test/java/org/sonatype/nexus/plugins/DefaultNexusPluginManagerTest.java
  20. +104 −0 ...core/src/test/java/org/sonatype/nexus/proxy/maven/metadata/operations/AddPluginOperationTest.java
  21. +44 −0 ...e/src/test/java/org/sonatype/nexus/proxy/maven/routing/internal/RemotePrefixFileStrategyTest.java
  22. +216 −0 .../java/org/sonatype/nexus/proxy/storage/local/fs/NEXUS5612DefaultFSLocalRepositoryStorageTest.java
  23. +290 −0 nexus-webapp/src/main/webapp/js/Sonatype/repoServer/AbstractMirrorPanel.js
  24. +144 −0 nexus-webapp/src/main/webapp/js/Sonatype/repoServer/HostedMirrorEditor.js
  25. +172 −0 nexus-webapp/src/main/webapp/js/Sonatype/repoServer/Maven2InformationPanel.js
  26. +178 −0 nexus-webapp/src/main/webapp/js/Sonatype/repoServer/ProxyMirrorEditor.js
  27. +12 −11 nexus-webapp/src/main/webapp/js/repoServer.js
  28. +0 −176 nexus-webapp/src/main/webapp/js/repoServer/Maven2InformationPanel.js
  29. +0 −558 nexus-webapp/src/main/webapp/js/repoServer/MirrorConfigPanel.js
  30. +1 −1 plugins/indexer/nexus-indexer-lucene-plugin/pom.xml
  31. +12 −0 ...xer/nexus-indexer-lucene-plugin/src/main/java/org/sonatype/nexus/index/DefaultIndexerManager.java
  32. +8 −1 plugins/nexus-rrb-plugin/src/main/java/org/sonatype/nexus/plugins/rrb/MavenRepositoryReader.java
  33. +20 −9 plugins/nexus-timeline-plugin/src/main/java/org/sonatype/timeline/internal/DefaultTimeline.java
  34. +61 −8 ...ns/nexus-timeline-plugin/src/main/java/org/sonatype/timeline/internal/DefaultTimelineIndexer.java
  35. +1 −1 plugins/restlet1x/nexus-restlet1x-plugin/src/main/resources/templates/index.vm
@@ -0,0 +1,85 @@
+/*
+ * 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.client.internal.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.io.Closeables;
+
+/**
+ * Helper static methods for reading Maven properties file to get the version from it.
+ *
+ * @author cstamas
+ * @since 2.5.0
+ */
+public class Version
+{
+ private static final Logger LOG = LoggerFactory.getLogger( Version.class );
+
+ private Version()
+ {
+ // no instances
+ }
+
+ /**
+ * Reads the version from a properties file, the one embedded by Maven into Jar during build.
+ *
+ * @param cl the class loader to be used to load the properties file.
+ * @param path the binary path of the properties file to read from (might have more in case of shaded JAR).
+ * @param defaultVersion the version string to return in case of unsuccessful read of the properties file.
+ * @return the version from the Maven properties file on given path, embedded into JAR.
+ * @since 2.4.1
+ */
+ public static String readVersion( final ClassLoader cl, final String path, final String defaultVersion )
+ {
+ String version = defaultVersion;
+ InputStream is = null;
+ try
+ {
+ final Properties props = new Properties();
+ is = cl.getResourceAsStream( path );
+ if ( is != null )
+ {
+ props.load( is );
+ version = props.getProperty( "version" );
+ }
+ }
+ catch ( IOException e )
+ {
+ LOG.error( "Could not load/read version from " + path, e );
+ }
+ finally
+ {
+ Closeables.closeQuietly( is );
+ }
+ return version;
+ }
+
+ /**
+ * Shorthand method. Reads the version from a properties file using classloader that loaded up this class.
+ *
+ * @param path the binary path of the properties file to read from (might have more in case of shaded JAR).
+ * @param defaultVersion the version string to return in case of unsuccessful read of the properties file.
+ * @return the version from the Maven properties file on given path, embedded into JAR.
+ * @since 2.4.1
+ */
+ public static String readVersion( final String path, final String defaultVersion )
+ {
+ return readVersion( Version.class.getClassLoader(), path, defaultVersion );
+ }
+}
@@ -14,6 +14,7 @@
import java.net.URI;
import java.util.Set;
+
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
@@ -24,7 +25,6 @@
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.conn.params.ConnRoutePNames;
-import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import org.apache.http.params.CoreProtocolPNames;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -34,9 +34,11 @@
import org.sonatype.nexus.client.internal.rest.NexusXStreamFactory;
import org.sonatype.nexus.client.internal.rest.XStreamXmlProvider;
import org.sonatype.nexus.client.internal.util.Template;
+import org.sonatype.nexus.client.internal.util.Version;
import org.sonatype.nexus.client.rest.ConnectionInfo;
import org.sonatype.nexus.client.rest.ProxyInfo;
import org.sonatype.nexus.client.rest.UsernamePasswordAuthenticationInfo;
+
import com.sun.jersey.api.client.ClientHandlerException;
import com.sun.jersey.api.client.filter.LoggingFilter;
import com.sun.jersey.api.json.JSONConfiguration;
@@ -110,7 +112,7 @@ protected ApacheHttpClient4 doCreateHttpClientFor( final ConnectionInfo connecti
// set UA
client.getClientHandler().getHttpClient().getParams().setParameter( CoreProtocolPNames.USER_AGENT,
- "Nexus-Client/1.0" );
+ "Nexus-Client/" + discoverClientVersion() );
// NXCM-4547 JERSEY-1293 Enforce proxy setting on httpclient
enforceProxyUri( config, client );
@@ -123,6 +125,11 @@ protected ApacheHttpClient4 doCreateHttpClientFor( final ConnectionInfo connecti
return client;
}
+ protected String discoverClientVersion()
+ {
+ return Version.readVersion( "META-INF/maven/org.sonatype.nexus.client/nexus-client-core/pom.properties", "unknown" );
+ }
+
// ==
/**
@@ -0,0 +1,2 @@
+# test
+version=${project.version}
@@ -0,0 +1,64 @@
+/*
+ * 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.client.rest.jersey;
+
+import java.net.MalformedURLException;
+
+import junit.framework.Assert;
+
+import org.apache.http.params.CoreProtocolPNames;
+import org.junit.Test;
+import org.sonatype.nexus.client.core.NexusClient;
+import org.sonatype.nexus.client.internal.util.Version;
+import org.sonatype.nexus.client.rest.BaseUrl;
+import org.sonatype.nexus.client.rest.NexusClientFactory;
+
+import com.sun.jersey.client.apache4.ApacheHttpClient4;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.notNullValue;
+
+/**
+ * UT for NexusClient UA, as it should carry the version from now on.
+ *
+ * @author cstamas
+ * @since 2.5
+ */
+public class JerseyNexusTestClientUserAgentTest
+ extends JerseyNexusClientTestSupport
+{
+ @Test
+ public void checkUAVersionIsProperlyReadAndSet()
+ throws MalformedURLException
+ {
+ final String version =
+ Version.readVersion( "META-INF/maven/org.sonatype.nexus.client/nexus-client-core/pom.properties", "foo" );
+ assertThat( "Version read must not return null!", version, notNullValue() );
+ assertThat( "Version read must not return the default (it should succeed in reading the stuff up)!", version,
+ not( equalTo( "foo" ) ) );
+
+ final NexusClientFactory factory = new JerseyNexusClientFactory();
+ final NexusClient client = factory.createFor( BaseUrl.baseUrlFrom( "https://repository.sonatype.org/" ) );
+ Assert.assertNotNull( client.getNexusStatus() );
+ final String userAgent =
+ (String) ( (ApacheHttpClient4) ( (JerseyNexusClient) client ).getClient() ).getClientHandler().getHttpClient().getParams().getParameter(
+ CoreProtocolPNames.USER_AGENT );
+ assertThat( "UA must not be null!", userAgent, notNullValue() );
+ assertThat( "UA must not be empty!", userAgent, containsString( "Nexus-Client" ) );
+ assertThat( "UA should be correct!", userAgent, equalTo( "Nexus-Client/" + version ) );
+ }
+}
@@ -0,0 +1,57 @@
+/*
+ * 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.guice;
+
+import java.lang.reflect.Method;
+
+import org.aopalliance.intercept.MethodInterceptor;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Key;
+import com.google.inject.matcher.Matcher;
+import com.google.inject.name.Names;
+
+/**
+ * Workaround to automatically share method interceptors until
+ * <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=403108">proper Sisu feature</a> is implemented.
+ *
+ * <p>
+ * This module is only bound once in its originating realm, when the bindInterceptor method is first called. The Nexus
+ * Plugin Manager can then see this module via the injected dynamic list of AbstractInterceptorModules and will install
+ * it in any plugins registered after this point.
+ *
+ * <p>
+ * Note: you can't contribute interceptors to earlier plugins or from a plugin to core, but the other direction works fine.
+ *
+ * @since 2.4
+ */
+public abstract class AbstractInterceptorModule
+ extends AbstractModule
+{
+ private boolean bound;
+
+ @Override
+ protected void bindInterceptor( final Matcher<? super Class<?>> classMatcher,
+ final Matcher<? super Method> methodMatcher,
+ final MethodInterceptor... interceptors )
+ {
+ if ( !bound )
+ {
+ // Explicitly bind module instance under a specific sub-type (not Module as Guice forbids that)
+ bind( Key.get( AbstractInterceptorModule.class, Names.named( getClass().getName() ) ) ).toInstance( this );
+ bound = true;
+ }
+ super.bindInterceptor( classMatcher, methodMatcher, interceptors );
+ }
+}
@@ -13,9 +13,9 @@
package org.sonatype.nexus.guice;
-import com.google.inject.AbstractModule;
import org.apache.shiro.guice.aop.ShiroAopModule;
-import org.sonatype.nexus.timing.TimingModule;
+
+import com.google.inject.AbstractModule;
/**
* Nexus guice modules.
@@ -33,7 +33,6 @@
@Override
protected void configure() {
install(new ShiroAopModule());
- install(new TimingModule());
}
}
@@ -40,6 +40,7 @@
import org.sonatype.guice.plexus.binders.PlexusXmlBeanModule;
import org.sonatype.guice.plexus.config.PlexusBeanModule;
import org.sonatype.inject.Parameters;
+import org.sonatype.nexus.guice.AbstractInterceptorModule;
import org.sonatype.nexus.guice.NexusModules.PluginModule;
import org.sonatype.nexus.mime.MimeSupport;
import org.sonatype.nexus.plugins.events.PluginActivatedEvent;
@@ -91,6 +92,8 @@
private final Map<String, String> variables;
+ private final List<AbstractInterceptorModule> interceptorModules;
+
private final Map<GAVCoordinate, PluginDescriptor> activePlugins = new HashMap<GAVCoordinate, PluginDescriptor>();
private final Map<GAVCoordinate, PluginResponse> pluginResponses = new HashMap<GAVCoordinate, PluginResponse>();
@@ -103,14 +106,16 @@ public DefaultNexusPluginManager( final RepositoryTypeRegistry repositoryTypeReg
final PluginRepositoryManager repositoryManager,
final DefaultPlexusContainer container,
final MimeSupport mimeSupport,
- final @Parameters Map<String, String> variables )
+ final @Parameters Map<String, String> variables,
+ final List<AbstractInterceptorModule> interceptorModules )
{
this.repositoryTypeRegistry = checkNotNull( repositoryTypeRegistry );
this.eventBus = checkNotNull( eventBus );
this.repositoryManager = checkNotNull( repositoryManager );
this.container = checkNotNull( container );
this.mimeSupport = checkNotNull( mimeSupport );
this.variables = checkNotNull( variables );
+ this.interceptorModules = checkNotNull( interceptorModules );
}
// ----------------------------------------------------------------------
@@ -462,12 +467,12 @@ protected void configure()
final ClassSpace annSpace = new URLClassSpace( pluginRealm, scanList.toArray( new URL[scanList.size()] ) );
beanModules.add( new NexusAnnotatedBeanModule( annSpace, variables, exportedClassNames, repositoryTypes ) );
- final Module[] modules = {
- resourceModule,
- new PluginModule()
- };
+ final List<Module> modules = new ArrayList<Module>();
+ modules.add( resourceModule );
+ modules.add( new PluginModule() );
+ modules.addAll( interceptorModules );
- container.addPlexusInjector( beanModules, modules );
+ container.addPlexusInjector( beanModules, modules.toArray( new Module[modules.size()] ) );
for ( final RepositoryTypeDescriptor r : repositoryTypes )
{
@@ -40,6 +40,14 @@ public boolean isRemoteItemContentValid(final ProxyRepository proxy, final Reso
return true;
}
+ final ChecksumPolicy requestChecksumPolicy =
+ (ChecksumPolicy) req.getRequestContext().get( ChecksumPolicy.REQUEST_CHECKSUM_POLICY_KEY );
+ if ( requestChecksumPolicy != null )
+ {
+ // found, it overrides the repository-set checksum policy then
+ checksumPolicy = requestChecksumPolicy;
+ }
+
RemoteHashResponse remoteHash = retrieveRemoteHash( item, proxy, baseUrl );
// let compiler make sure I did not forget to populate validation results
@@ -75,7 +75,7 @@
protected void cleanup( ProxyRepository proxy, RemoteHashResponse remoteHash, boolean contentValid )
throws LocalStorageException
{
- if ( !contentValid && remoteHash.getHashItem() != null )
+ if ( !contentValid && remoteHash != null && remoteHash.getHashItem() != null )
{
// TODO should we remove bad checksum if policy==WARN?
try
@@ -12,6 +12,9 @@
*/
package org.sonatype.nexus.proxy.maven;
+import org.sonatype.nexus.proxy.RequestContext;
+import org.sonatype.nexus.proxy.ResourceStoreRequest;
+
/**
* Checksum policies known in Maven1/2 repositories where checksums are available according to maven layout.
*
@@ -39,6 +42,21 @@
*/
STRICT;
+ /**
+ * Key to be used in {@link ResourceStoreRequest} context to mark per-request "override" of the
+ * {@link MavenProxyRepository} checksum policy. The policy put with this key into request context will be applied
+ * to given request execution (and all sub-requests, as {@link RequestContext} hierarchy is used). The use of this
+ * key has effect only on Maven1/2 proxy repositories, as {@link ChecksumPolicy} itself is a Maven specific
+ * property, and is globally (on repository level) controlled by getters and setters on {@link MavenProxyRepository}
+ * interface. This "request override" - usually to relax the policy - should be used sparingly, for cases when it's
+ * known that global repository level checksum policy might pose a blocker to the tried content retrieval, but even
+ * a corrupted content would not pose any downstream problems (as Nexus would shield downstream consumers by some
+ * other means, like processing and checking content in-situ).
+ *
+ * @since 2.5
+ */
+ public static String REQUEST_CHECKSUM_POLICY_KEY = "request.maven.checksumPolicy";
+
public boolean shouldCheckChecksum()
{
return !IGNORE.equals( this );
Oops, something went wrong.

0 comments on commit f11fba9

Please sign in to comment.