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

NEXUS-5216: Fix. #536

Merged
merged 2 commits into from
Sep 14, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion nexus/nexus-core-plugins/nexus-archetype-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,16 @@
<description>Adds a content generator for archetype.xml files.</description>

<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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -49,6 +50,9 @@ public class ArchetypeContentGenerator
@Inject
private IndexArtifactFilter indexArtifactFilter;

@Inject
private RepositoryURLBuilder repositoryURLBuilder;

@Override
public String getGeneratorId()
{
Expand All @@ -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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -44,10 +51,13 @@ public class ArchetypeContentLocator

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -39,13 +39,11 @@
* @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;
Expand Down Expand Up @@ -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() );
}
}
}
Expand Down