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

Commit

Permalink
Merge pull request #536 from sonatype/nexus-5216
Browse files Browse the repository at this point in the history
NEXUS-5216: Fix.
  • Loading branch information
cstamas committed Sep 14, 2012
2 parents bd8d01f + 728fbb5 commit 6900dd3
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 29 deletions.
8 changes: 7 additions & 1 deletion nexus/nexus-core-plugins/nexus-archetype-plugin/pom.xml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -30,10 +30,16 @@
<description>Adds a content generator for archetype.xml files.</description> <description>Adds a content generator for archetype.xml files.</description>


<dependencies> <dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>provided</scope>
</dependency>

<dependency> <dependency>
<groupId>org.sonatype.spice</groupId> <groupId>org.sonatype.spice</groupId>
<artifactId>nexus-archetype-common</artifactId> <artifactId>nexus-archetype-common</artifactId>
<version>1.1</version> <version>1.2-SNAPSHOT</version>
</dependency> </dependency>


<dependency> <dependency>
Expand Down
Original file line number Original file line 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.ContentLocator;
import org.sonatype.nexus.proxy.item.StorageFileItem; import org.sonatype.nexus.proxy.item.StorageFileItem;
import org.sonatype.nexus.proxy.repository.Repository; import org.sonatype.nexus.proxy.repository.Repository;
import org.sonatype.nexus.rest.RepositoryURLBuilder;


/** /**
* Archetype catalog content generator. * Archetype catalog content generator.
Expand All @@ -49,6 +50,9 @@ public class ArchetypeContentGenerator
@Inject @Inject
private IndexArtifactFilter indexArtifactFilter; private IndexArtifactFilter indexArtifactFilter;


@Inject
private RepositoryURLBuilder repositoryURLBuilder;

@Override @Override
public String getGeneratorId() 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) // make length unknown (since it will be known only in the moment of actual content pull)
item.setLength( -1 ); item.setLength( -1 );


return new ArchetypeContentLocator( repository.getId(), return new ArchetypeContentLocator( repository,
repositoryURLBuilder.getExposedRepositoryContentUrl( repository ),
( (DefaultIndexerManager) indexerManager ).getRepositoryIndexContext( repository ), macPlugin, ( (DefaultIndexerManager) indexerManager ).getRepositoryIndexContext( repository ), macPlugin,
new ArtifactInfoFilter() new ArtifactInfoFilter()
{ {
Expand Down
Original file line number Original file line 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.archetype.catalog.io.xpp3.ArchetypeCatalogXpp3Writer;
import org.apache.maven.index.ArtifactInfoFilter; import org.apache.maven.index.ArtifactInfoFilter;
import org.apache.maven.index.context.IndexingContext; 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.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 * 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, * 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. * when the content itself is asked for.
* *
* @author cstamas * @author cstamas
*/ */
public class ArchetypeContentLocator public class ArchetypeContentLocator
implements ContentLocator implements ContentLocator
{ {
private final Logger logger;

private final Repository repository;


private final String repositoryId; private final String repositoryContentUrl;


private final IndexingContext indexingContext; private final IndexingContext indexingContext;


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


private volatile String payload; private volatile String payload;


public ArchetypeContentLocator( String repositoryId, IndexingContext indexingContext, MacPlugin macPlugin, public ArchetypeContentLocator( final Repository repository, final String repositoryContentUrl,
ArtifactInfoFilter artifactInfoFilter ) 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.indexingContext = indexingContext;
this.macPlugin = macPlugin; this.macPlugin = macPlugin;
this.artifactInfoFilter = artifactInfoFilter; this.artifactInfoFilter = artifactInfoFilter;
Expand All @@ -58,25 +68,23 @@ protected synchronized String generateCatalogPayload()
{ {
if ( payload == null ) if ( payload == null )
{ {
// TODO: what if URL is needed? final MacRequest req = new MacRequest( repository.getId(), repositoryContentUrl, artifactInfoFilter );
// 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


// TODO: we have now the URL too, but I want to wait for ArchetypeCatalog improvements and possible changes // NEXUS-5216: Warn if indexing context is null (indexable=false) for given repository but continue
MacRequest req = new MacRequest( repositoryId, null, artifactInfoFilter ); // 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 // get the catalog
ArchetypeCatalog catalog = macPlugin.listArcherypesAsCatalog( req, indexingContext ); final ArchetypeCatalog catalog = macPlugin.listArcherypesAsCatalog( req, indexingContext );

// serialize it to XML // serialize it to XML
StringWriter sw = new StringWriter(); final StringWriter sw = new StringWriter();

final ArchetypeCatalogXpp3Writer writer = new ArchetypeCatalogXpp3Writer();
ArchetypeCatalogXpp3Writer writer = new ArchetypeCatalogXpp3Writer();

writer.write( sw, catalog ); writer.write( sw, catalog );

payload = sw.toString(); payload = sw.toString();
} }


Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; 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.RepositoryNotAvailableException;
import org.sonatype.nexus.proxy.ResourceStoreRequest; import org.sonatype.nexus.proxy.ResourceStoreRequest;
import org.sonatype.nexus.proxy.events.EventInspector; import org.sonatype.nexus.proxy.events.EventInspector;
Expand All @@ -39,13 +39,11 @@
* @author cstamas * @author cstamas
*/ */
public class MacPluginEventInspector public class MacPluginEventInspector
extends AbstractLoggingComponent
implements EventInspector implements EventInspector
{ {
private static final String ARCHETYPE_PATH = "/archetype-catalog.xml"; private static final String ARCHETYPE_PATH = "/archetype-catalog.xml";


@Inject
private Logger logger;

@Inject @Inject
@Named( "maven2" ) @Named( "maven2" )
private ContentClass maven2ContentClass; private ContentClass maven2ContentClass;
Expand Down Expand Up @@ -117,18 +115,18 @@ else if ( evt instanceof RepositoryEventLocalStatusChanged )
} }
catch ( RepositoryNotAvailableException e ) 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." ); + e.getRepository().getId() + "\" is out of service." );
} }
catch ( Exception e ) 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 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

0 comments on commit 6900dd3

Please sign in to comment.