Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' into NEXUS-5662-userid-mdc
Browse files Browse the repository at this point in the history
Conflicts:
	plugins/siesta/nexus-siesta-plugin/src/main/java/org/sonatype/nexus/plugins/siesta/SiestaModule.java
  • Loading branch information
jdillon committed Apr 15, 2013
2 parents 9ce6299 + 5ff39ca commit 4c41118
Show file tree
Hide file tree
Showing 49 changed files with 1,368 additions and 353 deletions.
Expand Up @@ -71,7 +71,7 @@ protected ReadWriteLock getLock()
// ==

/**
* Returns the SystemStatus, guaranteeing it's consistent state.
* Returns the SystemStatus, guaranteeing its consistent state.
*/
public SystemStatus getSystemStatus()
{
Expand All @@ -91,6 +91,14 @@ public SystemStatus getSystemStatus()
}
}

/**
* Force an update of SystemStatus.
*/
public void updateSystemStatus()
{
updateSystemStatusIfNeeded( true );
}

public boolean setState( SystemState state )
{
Lock lock = getLock().writeLock();
Expand Down
@@ -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 );
}
}
@@ -0,0 +1,37 @@
/*
* 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 org.sonatype.nexus.security.FilterChain;
import com.google.inject.AbstractModule;
import com.google.inject.name.Names;

/**
* Support module for configuring {@link FilterChain}s.
*
* @since 2.5
*/
public abstract class FilterChainModule
extends AbstractModule
{

protected void addFilterChain( final String pathPattern, final String filterExpression )
{
bind( FilterChain.class )
.annotatedWith( Names.named( pathPattern ) )
.toInstance( new FilterChain( pathPattern, filterExpression )
);
}

}
Expand Up @@ -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.
Expand All @@ -33,7 +33,6 @@ public static class CommonModule
@Override
protected void configure() {
install(new ShiroAopModule());
install(new TimingModule());
}
}

Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -91,6 +92,8 @@ public class DefaultNexusPluginManager

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>();
Expand All @@ -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 );
}

// ----------------------------------------------------------------------
Expand Down Expand Up @@ -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 )
{
Expand Down
Expand Up @@ -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
Expand Down
Expand Up @@ -75,7 +75,7 @@ public class ChecksumContentValidator
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
Expand Down
Expand Up @@ -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.
*
Expand Down Expand Up @@ -39,6 +42,21 @@ public enum ChecksumPolicy
*/
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 );
Expand Down
Expand Up @@ -12,8 +12,6 @@
*/
package org.sonatype.nexus.proxy.maven.metadata.operations;

import static org.sonatype.nexus.proxy.maven.metadata.operations.MetadataUtil.isPluginEquals;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -23,6 +21,8 @@
import org.apache.maven.artifact.repository.metadata.Metadata;
import org.apache.maven.artifact.repository.metadata.Plugin;

import static org.sonatype.nexus.proxy.maven.metadata.operations.MetadataUtil.isPluginPrefixAndArtifactIdEquals;

/**
* adds new plugin to metadata
*
Expand Down Expand Up @@ -88,8 +88,9 @@ public boolean perform( Metadata metadata )
{
if ( p.getArtifactId().equals( plugin.getArtifactId() ) )
{
if ( isPluginEquals( p, plugin ) )
if ( isPluginPrefixAndArtifactIdEquals( p, plugin ) )
{
p.setName( plugin.getName() );
// plugin already enlisted
return false;
}
Expand Down
Expand Up @@ -47,13 +47,14 @@ public static boolean isPluginEquals( Plugin p1, Plugin p2 )
p2.setName( "" );
}

if ( StringUtils.equals( p1.getArtifactId(), p2.getArtifactId() )
&& StringUtils.equals( p1.getPrefix(), p2.getPrefix() ) && StringUtils.equals( p1.getName(), p2.getName() ) )
{
return true;
}
return StringUtils.equals( p1.getArtifactId(), p2.getArtifactId() )
&& StringUtils.equals( p1.getPrefix(), p2.getPrefix() ) && StringUtils.equals( p1.getName(), p2.getName() );
}

return false;
public static boolean isPluginPrefixAndArtifactIdEquals( Plugin p1, Plugin p2 )
{
return StringUtils.equals( p1.getArtifactId(), p2.getArtifactId() )
&& StringUtils.equals( p1.getPrefix(), p2.getPrefix() );
}

}
Expand Up @@ -303,6 +303,12 @@ protected void putFileItem( final ContentLocator content )
new DefaultStorageFileItem( getMavenRepository(), request, true, true, content );
try
{
// NXCM-5188: Remark to not get tempted to change these to storeItemWithChecksums() method:
// Since NEXUS-5418 was fixed (in 2.4), Nexus serves up ALL request for existing items that
// has extra trailing ".sha1" or ".md5" from item attributes. This means, that when prefix file
// is published in Nexus, there is no need anymore to save checksums to disk, as they will
// be served up just fine. This is true for all items in Nexus storage, not just prefix
// file related ones!
getMavenRepository().storeItem( true, file );
}
catch ( UnsupportedStorageOperationException e )
Expand All @@ -325,6 +331,12 @@ protected void deleteFileItem()
request.getRequestContext().put( Manager.ROUTING_INITIATED_FILE_OPERATION_FLAG_KEY, Boolean.TRUE );
try
{
// NXCM-5188: Remark to not get tempted to change these to deleteItemWithChecksums() method:
// Since NEXUS-5418 was fixed (in 2.4), Nexus serves up ALL request for existing items that
// has extra trailing ".sha1" or ".md5" from item attributes. This means, that when prefix file
// is published in Nexus, there is no need anymore to save checksums to disk, as they will
// be served up just fine. This is true for all items in Nexus storage, not just prefix
// file related ones!
getMavenRepository().deleteItem( true, request );
}
catch ( ItemNotFoundException e )
Expand Down
Expand Up @@ -179,6 +179,8 @@ public ManagerImpl( final EventBus eventBus, final ApplicationStatusSource appli
this.eventBus.register( this );
}

private volatile boolean periodicUpdaterDidRunAtLeastOnce = false;

@Override
public void startup()
{
Expand Down Expand Up @@ -224,6 +226,7 @@ public void run()
return;
}
mayUpdateAllProxyPrefixFiles();
periodicUpdaterDidRunAtLeastOnce = true;
}
}, 0L /*no initial delay*/, TimeUnit.HOURS.toMillis( 1 ), TimeUnit.MILLISECONDS );

Expand Down Expand Up @@ -524,6 +527,11 @@ protected boolean doUpdatePrefixFileAsync( final boolean forced, final MavenRepo
@VisibleForTesting
public boolean isUpdatePrefixFileJobRunning()
{
if ( config.isFeatureActive() && !periodicUpdaterDidRunAtLeastOnce )
{
getLogger().debug( "Boot process not done yet, periodic updater did not yet finish!" );
return true;
}
final Statistics statistics = constrainedExecutor.getStatistics();
getLogger().debug( "Running update jobs for {}", statistics.getCurrentlyRunningJobKeys() );
return !statistics.getCurrentlyRunningJobKeys().isEmpty();
Expand Down Expand Up @@ -570,7 +578,7 @@ else if ( mavenRepository.getRepositoryKind().isFacetAvailable( MavenHostedRepos
catch ( IllegalStateException e )
{
// just ack it, log it and return peacefully
getLogger().info( e.getMessage() );
getLogger().info( "Maven repository {} not in state for prefix file update: {}", mavenRepository, e.getMessage() );
return;
}
}
Expand Down
Expand Up @@ -103,7 +103,7 @@ public DiscoveryResult<MavenProxyRepository> discoverRemoteContent( final MavenP
}
catch ( Exception e )
{
getLogger().warn( "Remote strategy {} error: {}", strategy.getId(), e.getMessage() );
getLogger().warn( "Remote strategy {} error", strategy.getId(), e );
discoveryResult.recordError( strategy.getId(), e );
break;
}
Expand Down

0 comments on commit 4c41118

Please sign in to comment.