Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Cleanup: removed extra prefix and noscrape paths

There is currently no use case for these extra file paths,
they complicate the code and make proper synchronization
harder to implement.

Signed-off-by: Igor Fedorenko <igor@ifedorenko.com>
  • Loading branch information...
commit 954df0f0fcab4bd5717ba187d46fed368c2402d0 1 parent 7379216
@ifedorenko ifedorenko authored
View
9 nexus-core/src/main/java/org/sonatype/nexus/proxy/maven/routing/Config.java
@@ -12,7 +12,6 @@
*/
package org.sonatype.nexus.proxy.maven.routing;
-import java.util.List;
/**
* WL Configuration.
@@ -47,18 +46,18 @@
String getLocalPrefixFilePath();
/**
- * Returns the paths that should be checked for published no scrape flags on remote.
+ * Returns the path that should be checked for published no scrape flag on remote.
*
* @return the array of paths to have checked on remote.
*/
- List<String> getRemoteNoScrapeFlagPaths();
+ String getRemoteNoScrapeFlagPath();
/**
- * Returns the paths that should be checked for published prefix files on remote.
+ * Returns the path that should be checked for published prefix file on remote.
*
* @return the array of paths to have checked on remote.
*/
- List<String> getRemotePrefixFilePaths();
+ String getRemotePrefixFilePath();
/**
* Returns the depth (directory depth) that remote scrape should dive in.
View
35 nexus-core/src/main/java/org/sonatype/nexus/proxy/maven/routing/internal/ConfigImpl.java
@@ -12,9 +12,6 @@
*/
package org.sonatype.nexus.proxy.maven.routing.internal;
-import java.util.ArrayList;
-import java.util.List;
-
import javax.inject.Named;
import javax.inject.Singleton;
@@ -56,12 +53,6 @@
private static final String LOCAL_PREFIX_FILE_PATH = "/.meta/prefixes.txt";
- private static final String[] EXTRA_REMOTE_NO_SCRAPE_FLAG_PATHS =
- SystemPropertiesHelper.getStringlist( Config.class.getName() + ".extraRemoteNoscrapeFlagPaths" );
-
- private static final String[] EXTRA_REMOTE_PREFIX_FILE_PATHS =
- SystemPropertiesHelper.getStringlist( Config.class.getName() + ".extraRemotePrefixFilePaths" );
-
private static final int REMOTE_SCRAPE_DEPTH = SystemPropertiesHelper.getInteger( Config.class.getName()
+ ".remoteScrapeDepth", 2 );
@@ -116,33 +107,15 @@ public String getLocalPrefixFilePath()
}
@Override
- public List<String> getRemoteNoScrapeFlagPaths()
+ public String getRemoteNoScrapeFlagPath()
{
- final ArrayList<String> result = new ArrayList<String>();
- result.add( LOCAL_NO_SCRAPE_FLAG_PATH );
- for ( String extra : EXTRA_REMOTE_NO_SCRAPE_FLAG_PATHS )
- {
- if ( extra != null && extra.trim().length() > 0 )
- {
- result.add( extra );
- }
- }
- return result;
+ return LOCAL_NO_SCRAPE_FLAG_PATH;
}
@Override
- public List<String> getRemotePrefixFilePaths()
+ public String getRemotePrefixFilePath()
{
- final ArrayList<String> result = new ArrayList<String>();
- result.add( LOCAL_PREFIX_FILE_PATH );
- for ( String extra : EXTRA_REMOTE_PREFIX_FILE_PATHS )
- {
- if ( extra != null && extra.trim().length() > 0 )
- {
- result.add( extra );
- }
- }
- return result;
+ return LOCAL_PREFIX_FILE_PATH;
}
@Override
View
5 nexus-core/src/main/java/org/sonatype/nexus/proxy/maven/routing/internal/ManagerImpl.java
@@ -1139,10 +1139,7 @@ protected void unpublish( final MavenRepository mavenRepository, final boolean p
// TODO: We do this due to RemotePrefixFileStrategy, but this is now scattered (that one may write these file,
// and here we are cleaning them)
- for ( String path : config.getRemotePrefixFilePaths() )
- {
- new FilePrefixSource( mavenRepository, path, config ).delete();
- }
+ new FilePrefixSource( mavenRepository, config.getRemotePrefixFilePath(), config ).delete();
// set noscrape flag
addNoscrapeFlag( mavenRepository );
View
64 ...c/main/java/org/sonatype/nexus/proxy/maven/routing/internal/RemotePrefixFileStrategy.java
@@ -15,7 +15,6 @@
import static com.google.common.base.Preconditions.checkNotNull;
import java.io.IOException;
-import java.util.List;
import javax.inject.Inject;
import javax.inject.Named;
@@ -29,9 +28,9 @@
import org.sonatype.nexus.proxy.item.StorageFileItem;
import org.sonatype.nexus.proxy.item.StorageItem;
import org.sonatype.nexus.proxy.maven.MavenProxyRepository;
-import org.sonatype.nexus.proxy.maven.routing.PrefixSource;
import org.sonatype.nexus.proxy.maven.routing.Config;
import org.sonatype.nexus.proxy.maven.routing.Manager;
+import org.sonatype.nexus.proxy.maven.routing.PrefixSource;
import org.sonatype.nexus.proxy.maven.routing.discovery.RemoteStrategy;
import org.sonatype.nexus.proxy.maven.routing.discovery.StrategyFailedException;
import org.sonatype.nexus.proxy.maven.routing.discovery.StrategyResult;
@@ -68,49 +67,46 @@ public StrategyResult discover( final MavenProxyRepository mavenProxyRepository
throws StrategyFailedException, IOException
{
StorageFileItem item;
- final List<String> remoteFilePath = config.getRemotePrefixFilePaths();
- for ( String path : remoteFilePath )
+ String path = config.getRemotePrefixFilePath();
+ getLogger().debug( "Looking for remote prefix on {} at path {}", mavenProxyRepository, path );
+ // we keep exclusive lock on UID during discovery to prevent other WL threads grabbing this file
+ // prematurely. We release the lock only when file is present locally, and is validated.
+ // in that moment it's not published yet, but the content is correct and it will be
+ // the same that will get published.
+ final RepositoryItemUid uid = mavenProxyRepository.createUid( path );
+ uid.getLock().lock( Action.update );
+ try
{
- getLogger().debug( "Looking for remote prefix on {} at path {}", mavenProxyRepository, path );
- // we keep exclusive lock on UID during discovery to prevent other WL threads grabbing this file
- // prematurely. We release the lock only when file is present locally, and is validated.
- // in that moment it's not published yet, but the content is correct and it will be
- // the same that will get published.
- final RepositoryItemUid uid = mavenProxyRepository.createUid( path );
- uid.getLock().lock( Action.update );
- try
+ item = retrieveFromRemoteIfExists( mavenProxyRepository, path );
+ if ( item != null )
{
- item = retrieveFromRemoteIfExists( mavenProxyRepository, path );
- if ( item != null )
+ getLogger().debug( "Remote prefix on {} at path {} found!", mavenProxyRepository, path );
+ long prefixFileAgeInDays = ( System.currentTimeMillis() - item.getModified() ) / 86400000L;
+ final PrefixSource prefixSource = createPrefixSource( mavenProxyRepository, path );
+ if ( prefixSource != null )
{
- getLogger().debug( "Remote prefix on {} at path {} found!", mavenProxyRepository, path );
- long prefixFileAgeInDays = ( System.currentTimeMillis() - item.getModified() ) / 86400000L;
- final PrefixSource prefixSource = createPrefixSource( mavenProxyRepository, path );
- if ( prefixSource != null )
+ if ( prefixFileAgeInDays < 1 )
{
- if ( prefixFileAgeInDays < 1 )
- {
- return new StrategyResult(
- "Remote publishes prefix file (is less than a day old), using it.", prefixSource );
- }
- else
- {
- return new StrategyResult( "Remote publishes prefix file (is " + prefixFileAgeInDays
- + " days old), using it.", prefixSource );
- }
+ return new StrategyResult(
+ "Remote publishes prefix file (is less than a day old), using it.", prefixSource );
}
else
{
- getLogger().info( "Prefix file retrieved from {} is corrupt, skipping it.", item.getRemoteUrl() );
+ return new StrategyResult( "Remote publishes prefix file (is " + prefixFileAgeInDays
+ + " days old), using it.", prefixSource );
}
}
+ else
+ {
+ getLogger().info( "Prefix file retrieved from {} is corrupt, skipping it.", item.getRemoteUrl() );
+ }
}
- finally
- {
- uid.getLock().unlock();
- }
}
- throw new StrategyFailedException( "Remote does not publish prefix files on paths " + remoteFilePath );
+ finally
+ {
+ uid.getLock().unlock();
+ }
+ throw new StrategyFailedException( "Remote does not publish prefix files on paths " + path );
}
// ==
View
37 ...e/src/main/java/org/sonatype/nexus/proxy/maven/routing/internal/RemoteScrapeStrategy.java
@@ -145,30 +145,27 @@ public StrategyResult discover( final MavenProxyRepository mavenProxyRepository
protected boolean isMarkedForNoScrape( final ScrapeContext context )
throws IOException
{
- final List<String> noscrapeFlags = config.getRemoteNoScrapeFlagPaths();
- for ( String noscrapeFlag : noscrapeFlags )
+ String noscrapeFlag = config.getRemoteNoScrapeFlagPath();
+ while ( noscrapeFlag.startsWith( "/" ) )
{
- while ( noscrapeFlag.startsWith( "/" ) )
+ noscrapeFlag = noscrapeFlag.substring( 1 );
+ }
+ final String flagRemoteUrl = context.getRemoteRepositoryRootUrl() + noscrapeFlag;
+ HttpResponse response = null;
+ try
+ {
+ final HttpHead head = new HttpHead( flagRemoteUrl );
+ response = context.executeHttpRequest( head );
+ if ( response.getStatusLine().getStatusCode() > 199 && response.getStatusLine().getStatusCode() < 300 )
{
- noscrapeFlag = noscrapeFlag.substring( 1 );
+ return true;
}
- final String flagRemoteUrl = context.getRemoteRepositoryRootUrl() + noscrapeFlag;
- HttpResponse response = null;
- try
- {
- final HttpHead head = new HttpHead( flagRemoteUrl );
- response = context.executeHttpRequest( head );
- if ( response.getStatusLine().getStatusCode() > 199 && response.getStatusLine().getStatusCode() < 300 )
- {
- return true;
- }
- }
- finally
+ }
+ finally
+ {
+ if ( response != null )
{
- if ( response != null )
- {
- EntityUtils.consumeQuietly( response.getEntity() );
- }
+ EntityUtils.consumeQuietly( response.getEntity() );
}
}
return false;

0 comments on commit 954df0f

Please sign in to comment.
Something went wrong with that request. Please try again.