Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #536 from sonatype/nexus-5216

NEXUS-5216: Fix.
  • Loading branch information...
commit 6900dd3154b8c2976039003bbf08953993c57cc4 2 parents bd8d01f + 728fbb5
@cstamas cstamas authored
View
8 nexus/nexus-core-plugins/nexus-archetype-plugin/pom.xml
@@ -31,9 +31,15 @@
<dependencies>
<dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
<groupId>org.sonatype.spice</groupId>
<artifactId>nexus-archetype-common</artifactId>
- <version>1.1</version>
+ <version>1.2-SNAPSHOT</version>
</dependency>
<dependency>
View
7 ...hetype-plugin/src/main/java/org/sonatype/nexus/plugins/mac/ArchetypeContentGenerator.java
@@ -28,6 +28,7 @@
import org.sonatype.nexus.proxy.item.ContentLocator;
import org.sonatype.nexus.proxy.item.StorageFileItem;
import org.sonatype.nexus.proxy.repository.Repository;
+import org.sonatype.nexus.rest.RepositoryURLBuilder;
/**
* Archetype catalog content generator.
@@ -49,6 +50,9 @@
@Inject
private IndexArtifactFilter indexArtifactFilter;
+ @Inject
+ private RepositoryURLBuilder repositoryURLBuilder;
+
@Override
public String getGeneratorId()
{
@@ -62,7 +66,8 @@ public ContentLocator generateContent( Repository repository, String path, Stora
// make length unknown (since it will be known only in the moment of actual content pull)
item.setLength( -1 );
- return new ArchetypeContentLocator( repository.getId(),
+ return new ArchetypeContentLocator( repository,
+ repositoryURLBuilder.getExposedRepositoryContentUrl( repository ),
( (DefaultIndexerManager) indexerManager ).getRepositoryIndexContext( repository ), macPlugin,
new ArtifactInfoFilter()
{
View
46 ...rchetype-plugin/src/main/java/org/sonatype/nexus/plugins/mac/ArchetypeContentLocator.java
@@ -21,20 +21,27 @@
import org.apache.maven.archetype.catalog.io.xpp3.ArchetypeCatalogXpp3Writer;
import org.apache.maven.index.ArtifactInfoFilter;
import org.apache.maven.index.context.IndexingContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.sonatype.nexus.proxy.item.ContentLocator;
+import org.sonatype.nexus.proxy.repository.Repository;
+import org.sonatype.nexus.proxy.utils.RepositoryStringUtils;
/**
* A content locator to generate archetype catalog. This way, the actual work (search, archetype catalog model fillup
* from results, converting it to string and flushing it as byte array backed stream) is postponed to very last moment,
* when the content itself is asked for.
- *
+ *
* @author cstamas
*/
public class ArchetypeContentLocator
implements ContentLocator
{
+ private final Logger logger;
+
+ private final Repository repository;
- private final String repositoryId;
+ private final String repositoryContentUrl;
private final IndexingContext indexingContext;
@@ -44,10 +51,13 @@
private volatile String payload;
- public ArchetypeContentLocator( String repositoryId, IndexingContext indexingContext, MacPlugin macPlugin,
- ArtifactInfoFilter artifactInfoFilter )
+ public ArchetypeContentLocator( final Repository repository, final String repositoryContentUrl,
+ final IndexingContext indexingContext, final MacPlugin macPlugin,
+ final ArtifactInfoFilter artifactInfoFilter )
{
- this.repositoryId = repositoryId;
+ this.logger = LoggerFactory.getLogger( getClass() );
+ this.repository = repository;
+ this.repositoryContentUrl = repositoryContentUrl;
this.indexingContext = indexingContext;
this.macPlugin = macPlugin;
this.artifactInfoFilter = artifactInfoFilter;
@@ -58,25 +68,23 @@ protected synchronized String generateCatalogPayload()
{
if ( payload == null )
{
- // TODO: what if URL is needed?
- // this content generator will be sucked from the repo root,
- // so it is fine for it to have no repositoryUrl
- // perm filter added, now this generator will generate catalog with archetypes that user
- // fetching it may see
+ final MacRequest req = new MacRequest( repository.getId(), repositoryContentUrl, artifactInfoFilter );
- // TODO: we have now the URL too, but I want to wait for ArchetypeCatalog improvements and possible changes
- MacRequest req = new MacRequest( repositoryId, null, artifactInfoFilter );
+ // NEXUS-5216: Warn if indexing context is null (indexable=false) for given repository but continue
+ // to return the correct empty catalog
+ if ( indexingContext == null )
+ {
+ logger.info(
+ "Archetype Catalog for repository {} is not buildable as it lacks IndexingContext (indexable=false?).",
+ RepositoryStringUtils.getHumanizedNameString( repository ) );
+ }
// get the catalog
- ArchetypeCatalog catalog = macPlugin.listArcherypesAsCatalog( req, indexingContext );
-
+ final ArchetypeCatalog catalog = macPlugin.listArcherypesAsCatalog( req, indexingContext );
// serialize it to XML
- StringWriter sw = new StringWriter();
-
- ArchetypeCatalogXpp3Writer writer = new ArchetypeCatalogXpp3Writer();
-
+ final StringWriter sw = new StringWriter();
+ final ArchetypeCatalogXpp3Writer writer = new ArchetypeCatalogXpp3Writer();
writer.write( sw, catalog );
-
payload = sw.toString();
}
View
14 ...rchetype-plugin/src/main/java/org/sonatype/nexus/plugins/mac/MacPluginEventInspector.java
@@ -15,7 +15,7 @@
import javax.inject.Inject;
import javax.inject.Named;
-import org.slf4j.Logger;
+import org.sonatype.nexus.logging.AbstractLoggingComponent;
import org.sonatype.nexus.proxy.RepositoryNotAvailableException;
import org.sonatype.nexus.proxy.ResourceStoreRequest;
import org.sonatype.nexus.proxy.events.EventInspector;
@@ -39,14 +39,12 @@
* @author cstamas
*/
public class MacPluginEventInspector
+ extends AbstractLoggingComponent
implements EventInspector
{
private static final String ARCHETYPE_PATH = "/archetype-catalog.xml";
@Inject
- private Logger logger;
-
- @Inject
@Named( "maven2" )
private ContentClass maven2ContentClass;
@@ -117,18 +115,18 @@ else if ( evt instanceof RepositoryEventLocalStatusChanged )
}
catch ( RepositoryNotAvailableException e )
{
- logger.info( "Unable to install the generated archetype catalog, repository \""
+ getLogger().info( "Unable to install the generated archetype catalog, repository \""
+ e.getRepository().getId() + "\" is out of service." );
}
catch ( Exception e )
{
- if ( logger.isDebugEnabled() )
+ if ( getLogger().isDebugEnabled() )
{
- logger.info( "Unable to install the generated archetype catalog!", e );
+ getLogger().info( "Unable to install the generated archetype catalog!", e );
}
else
{
- logger.info( "Unable to install the generated archetype catalog:" + e.getMessage() );
+ getLogger().info( "Unable to install the generated archetype catalog:" + e.getMessage() );
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.