Permalink
Browse files

* add generator for stub-gem with only gemspec but no data.tar.gz

* trigger stub-gem creation on lazy indexing
  • Loading branch information...
1 parent b79b113 commit d8865761925c2eeaed658378d9beb3b4f1487cde @mkristian committed Jul 15, 2010
@@ -63,6 +63,12 @@ public void createAndWriteGemspec( MavenArtifact mart, File target )
FileUtils.fileWrite( target.getAbsolutePath(), "UTF-8", gemspecString );
}
+ public void createGemStubFromArtifact(MavenArtifact mart, File target)
+ throws IOException
+ {
+ getMavenArtifactConverter().createGemStubFromArtifact( mart, target );
+ }
+
public void createGemFromArtifact( MavenArtifact mart, File target )
throws IOException
{
@@ -9,22 +9,22 @@
* This component is the central "ruby interaction" point, and is meant to focus all "ruby related" calls to make it
* easy to swap out and use proper stuff instead. What we have now is POC nexus-ruby-tools, and gemGenerateIndexes is
* not implemented. The "proper" stuff should use JRuby and invoke the proper Gem:: classes doing the actual work.
- *
+ *
* @author cstamas
*/
public interface RubyGateway
{
/**
* Queries is the MavenArtifact convertable to Gem.
- *
+ *
* @param pom Pom of the artifact.
* @return true if yes, false otherwise.
*/
boolean canConvert( MavenArtifact mart );
/**
* Just builds proper GEM filename out from information in POM object.
- *
+ *
* @param pom Pom of the artifact.
* @return
*/
@@ -33,7 +33,7 @@
/**
* Does Maven2 artifact conversion into Gem and writes the Gem to the target file. The file written to target should
* be a complete Ruby Gem.
- *
+ *
* @param mart
* @param target
* @throws IOException
@@ -42,9 +42,20 @@ void createGemFromArtifact( MavenArtifact mart, File target )
throws IOException;
/**
+ * Does Maven2 artifact conversion into Gem Stub with only a gemspec file and writes the Gem to the target file.
+ * The file written to target should be a Ruby Gem without data.tar.gz.
+ *
+ * @param mart
+ * @param target
+ * @throws IOException
+ */
+ void createGemStubFromArtifact(MavenArtifact mart, File target)
+ throws IOException;
+
+ /**
* Creates a Gem::Specification from the Maven2 artifact Pom and writes it into the designated target File as Yaml
* serialized file (for latter indexer use, this is the gemspec of "lazy" Gems).
- *
+ *
* @param pom
* @param target
* @throws IOException
@@ -54,7 +65,7 @@ void createAndWriteGemspec( MavenArtifact mart, File target )
/**
* Invokes "gem generate_index --directory=${basedir}". Should do the same as the CLI command written above.
- *
+ *
* @param basedir
* @param if true, update happens, oherwise full reindex
*/
@@ -63,7 +74,7 @@ void createAndWriteGemspec( MavenArtifact mart, File target )
/**
* Invokes Nexus modified "gem generate_index --directory=${basedir}". Should do the same as the CLI command written
* above, but will avoid to crank up GEM files, and will use .gemspec files instead, generated by Nexus.
- *
+ *
* @param basedir
* @param if true, update happens, oherwise full reindex
*/
@@ -22,13 +22,11 @@
import org.sonatype.nexus.proxy.ItemNotFoundException;
import org.sonatype.nexus.proxy.ResourceStoreRequest;
import org.sonatype.nexus.proxy.StorageException;
-import org.sonatype.nexus.proxy.item.ContentGenerator;
import org.sonatype.nexus.proxy.item.DefaultStorageFileItem;
import org.sonatype.nexus.proxy.item.RepositoryItemUid;
import org.sonatype.nexus.proxy.item.StorageFileItem;
import org.sonatype.nexus.proxy.item.StorageItem;
import org.sonatype.nexus.proxy.item.StorageLinkItem;
-import org.sonatype.nexus.proxy.item.StringContentLocator;
import org.sonatype.nexus.proxy.maven.MavenRepository;
import org.sonatype.nexus.proxy.maven.maven2.Maven2ContentClass;
import org.sonatype.nexus.proxy.registry.ContentClass;
@@ -39,7 +37,6 @@
import org.sonatype.nexus.proxy.repository.RepositoryKind;
import org.sonatype.nexus.proxy.repository.ShadowRepository;
import org.sonatype.nexus.proxy.storage.UnsupportedStorageOperationException;
-import org.sonatype.nexus.proxy.storage.local.fs.DefaultFSLocalRepositoryStorage;
import org.sonatype.nexus.proxy.storage.local.fs.FileContentLocator;
import org.sonatype.nexus.ruby.MavenArtifact;
@@ -187,43 +184,22 @@ protected StorageLinkItem createLink( StorageItem item )
getLogger().debug(
"Creating " + ( isLazyGemMaterialization() ? "lazily " : "" ) + " Gem " + gemName + " in repository "
+ getId() );
-
+ File target = File.createTempFile( "nexus-gem", ".gem.tmp" );
if ( isLazyGemMaterialization() )
{
- // 1st, we create the stub file, which is just the gemspec file in Yaml
- DefaultStorageFileItem gemStub =
- new DefaultStorageFileItem( this, new ResourceStoreRequest( "/gems/" + gemName, true ), true,
- false, new StringContentLocator( "STUB" ) );
-
- gemStub.getAttributes().put( ContentGenerator.CONTENT_GENERATOR_ID,
- Maven2RubyGemShadowContentGenerator.ID );
-
- gemStub.getAttributes().put( ORIGINAL_ITEM_PATH, item.getPath() );
-
- storeItem( true, gemStub );
-
- // 2nd, we create the raw gemspec file for indexer
- // THIS IS DIRTY!
- File gemspecFile =
- ( (DefaultFSLocalRepositoryStorage) getLocalStorage() ).getFileFromBase( this,
- new ResourceStoreRequest( "/gems/" + gemName + ".gemspec" ) );
-
- rubyGateway.createAndWriteGemspec( mart, gemspecFile );
+ rubyGateway.createGemStubFromArtifact( mart, target );
}
else
{
- File target = File.createTempFile( "nexus-gem", ".gem.tmp" );
-
rubyGateway.createGemFromArtifact( mart, target );
+ }
+ DefaultStorageFileItem gemItem =
+ new DefaultStorageFileItem( this, new ResourceStoreRequest( "/gems/" + gemName, true ), true, false,
+ new FileContentLocator( target, "binary/octet-stream" ) );
- DefaultStorageFileItem gemItem =
- new DefaultStorageFileItem( this, new ResourceStoreRequest( "/gems/" + gemName, true ), true,
- false, new FileContentLocator( target, "binary/octet-stream" ) );
-
- gemItem.getAttributes().put( ORIGINAL_ITEM_PATH, item.getPath() );
+ gemItem.getAttributes().put( ORIGINAL_ITEM_PATH, item.getPath() );
- storeItem( true, gemItem );
- }
+ storeItem( true, gemItem );
}
catch ( IOException e )
{
@@ -248,8 +224,6 @@ protected void deleteLink( StorageItem item )
deleteItem( true, new ResourceStoreRequest( "/gems/" + gemName ) );
- deleteItem( true, new ResourceStoreRequest( "/gems/" + gemName + ".gemspec" ) );
-
rubyIndexer.reindexRepository( this, true );
}
@@ -28,7 +28,7 @@
/**
* This is full of "workarounds" here, since for true artifact2gem conversion I would need interpolated POM!
- *
+ *
* @author cstamas
* @author mkristian
*/
@@ -114,9 +114,8 @@ private boolean canConvert( MavenArtifact artifact, String packaging, String ext
}
return StringUtils.equals( packaging, artifact.getPom().getPackaging() )
- && ( ( extension == null && artifact.getArtifactFile() == null ) || ( extension != null
- && artifact.getArtifactFile() != null && artifact
- .getArtifactFile().getName().endsWith( fixedExtension ) ) );
+ && ( ( extension == null && artifact.getArtifactFile() == null ) || ( extension != null
+ && artifact.getArtifactFile() != null && artifact.getArtifactFile().getName().endsWith( fixedExtension ) ) );
}
public String getGemFileName( MavenArtifact artifact )
@@ -174,6 +173,22 @@ public GemSpecification createSpecification( MavenArtifact artifact )
return result;
}
+ public GemArtifact createGemStubFromArtifact( MavenArtifact artifact, File target )
+ throws IOException
+ {
+ GemSpecification gemspec = createSpecification( artifact );
+
+ if ( target == null )
+ {
+ throw new IOException( "Must specify target file, where to generate Gem!" );
+ }
+
+ // write file
+ gemPackager.createGemStub( gemspec, target );
+
+ return new GemArtifact( gemspec, target );
+ }
+
public GemArtifact createGemFromArtifact( MavenArtifact artifact, File target )
throws IOException
{
@@ -7,22 +7,22 @@
/**
* This is the single entry point into the Maven artifact to Ruby Gem converter.
- *
+ *
* @author cstamas
*/
public interface MavenArtifactConverter
{
/**
* Returns is the artifact convertable safely into Gem.
- *
+ *
* @param pom
* @return true if yes.
*/
boolean canConvert( MavenArtifact artifact );
/**
* Returns the "regular" gem filename, as it is expected this artifact to be called as Gem.
- *
+ *
* @param pom
* @return
*/
@@ -31,15 +31,26 @@
/**
* Creates a Gem::Specification (the equivalent JavaBeans actually) filled up properly based on informaton from POM.
* The "better" POM is, the getter is gemspec. For best results, fed in interpolated POMs!
- *
+ *
* @param artifact
* @return
*/
GemSpecification createSpecification( MavenArtifact artifact );
/**
* Creates a valid Ruby Gem, and returns File pointing to the result.
- *
+ *
+ * @param artifact the artifact to gemize (without data only gemspec)
+ * @param target where to save Gem file. If null, it will be created next to artifact
+ * @return
+ * @throws IOException
+ */
+ GemArtifact createGemStubFromArtifact( MavenArtifact artifact, File target )
+ throws IOException;
+
+ /**
+ * Creates a valid Ruby Gem, and returns File pointing to the result.
+ *
* @param artifact the artifact to gemize
* @param target where to save Gem file. If null, it will be created next to artifact
* @return
@@ -19,6 +19,12 @@
@Requirement
private GemSpecificationIO gemSpecificationIO;
+ public void createGemStub( GemSpecification gemspec, File gemFile )
+ throws IOException
+ {
+ createGem( gemspec, null, gemFile );
+ }
+
public void createGem( GemSpecification gemspec, Collection<GemFileEntry> filesToAdd, File gemFile )
throws IOException
{
@@ -28,18 +34,21 @@ public void createGem( GemSpecification gemspec, Collection<GemFileEntry> filesT
gemWorkdir.mkdirs();
- for ( GemFileEntry entry : filesToAdd )
+ if ( filesToAdd != null )
{
- if ( !entry.getSource().isFile() )
+ for ( GemFileEntry entry : filesToAdd )
{
- throw new IOException( "The GEM entry must be a file!" );
- }
+ if ( !entry.getSource().isFile() )
+ {
+ throw new IOException( "The GEM entry must be a file!" );
+ }
- gemspec.getFiles().add( entry.getPathInGem() );
+ gemspec.getFiles().add( entry.getPathInGem() );
- if ( entry.isOnLoadPath() )
- {
- // we should ensure it's folder (usually "lib/" is here)
+ if ( entry.isOnLoadPath() )
+ {
+ // we should ensure it's folder (usually "lib/" is here)
+ }
}
}
@@ -62,24 +71,31 @@ public void createGem( GemSpecification gemspec, Collection<GemFileEntry> filesT
gzip.addFile( metadata, "metadata.gz" );
gzip.createArchive();
- // tar.gz the content into data.tar.gz
- File dataTarGz = new File( gemWorkdir, "data.tar.gz" );
TarArchiver tar = new TarArchiver();
TarCompressionMethod compression = new TarCompressionMethod();
- compression.setValue( "gzip" );
- tar.setCompression( compression );
- tar.setDestFile( dataTarGz );
- for ( GemFileEntry entry : filesToAdd )
+ File dataTarGz = null;
+ if ( filesToAdd != null )
{
- tar.addFile( entry.getSource(), entry.getPathInGem() );
+ // tar.gz the content into data.tar.gz
+ dataTarGz = new File( gemWorkdir, "data.tar.gz" );
+ compression.setValue( "gzip" );
+ tar.setCompression( compression );
+ tar.setDestFile( dataTarGz );
+ for ( GemFileEntry entry : filesToAdd )
+ {
+ tar.addFile( entry.getSource(), entry.getPathInGem() );
+ }
+ tar.createArchive();
}
- tar.createArchive();
// and finally create gem by tar.gz-ing data.tar.gz and metadata.gz
tar.setDestFile( gemFile );
compression.setValue( "none" );
tar.setCompression( compression );
- tar.addFile( dataTarGz, dataTarGz.getName() );
+ if ( dataTarGz != null )
+ {
+ tar.addFile( dataTarGz, dataTarGz.getName() );
+ }
tar.addFile( metadataGz, metadataGz.getName() );
tar.createArchive();
}
@@ -6,20 +6,32 @@
/**
* A low level component that manufactures the actual Gem file.
- *
+ *
* @author cstamas
+ * @author mkristian
*/
public interface GemPackager
{
/**
- * This method will create the GEM. It will do NO validation at all, just blindly create the Gem using supplied
+ * This method will create the GEM stub with only gemspec and not data. It will do NO validation at all, just blindly create the Gem using supplied
* stuff.
- *
+ *
* @param gemspec The Gem::Specification to embed into Gem.
- * @param filesToAdd The Gem file entries to add to gem.
* @param gemFile The File where the manufactured Gem should be saved.
* @throws IOException
*/
+ void createGemStub( GemSpecification gemspec, File gemFile )
+ throws IOException;
+
+ /**
+ * This method will create the GEM. It will do NO validation at all, just blindly create the Gem using supplied
+ * stuff.
+ *
+ * @param gemspec The Gem::Specification to embed into Gem.
+ * @param filesToAdd The Gem file entries to add to gem.
+ * @param gemFile The File where the manufactured Gem should be saved.
+ * @throws IOException
+ */
void createGem( GemSpecification gemspec, Collection<GemFileEntry> filesToAdd, File gemFile )
throws IOException;
}

0 comments on commit d886576

Please sign in to comment.