Browse files

Merge pull request #13 from pierre/add-classifier-support

Add classifier support
  • Loading branch information...
2 parents 5e844a6 + c60c648 commit 52360659d9cd6b391430d9a813a3c5ac3e4c6a27 @mkristian committed Jan 20, 2013
Showing with 139 additions and 19 deletions.
  1. +3 −0 .gitignore
  2. +3 −3 Rakefile
  3. +1 −1 lib/jbundler/cli.rb
  4. +12 −1 lib/jbundler/pom.rb
  5. +38 −0 pom.xml
  6. +6 −0 spec/pom_spec.rb
  7. +24 −14 src/main/java/jbundler/Aether.java
  8. +52 −0 src/test/java/jbundler/TestAether.java
View
3 .gitignore
@@ -4,3 +4,6 @@
target
# no Gemfile.lock
Gemfile.lock
+.idea
+*.iml
+*.log
View
6 Rakefile
@@ -13,7 +13,7 @@ require 'fileutils'
task :default => [ :minispec]
task :build do
- rmvn = Maven::RubyMaven.new
+ rmvn = Maven::Ruby::Maven.new
rmvn.options['-Dmaven.test.skip'] = true
if rmvn.exec('package')
puts 'you find the gem inside "target"'
@@ -23,15 +23,15 @@ task :build do
end
task :compile do
- rmvn = Maven::RubyMaven.new
+ rmvn = Maven::Ruby::Maven.new
rmvn.options['-Dmaven.test.skip'] = true
unless rmvn.exec('prepare-package')
raise 'failed'
end
end
task :features => [:compile] do
- rmvn = Maven::RubyMaven.new
+ rmvn = Maven::Ruby::Maven.new
rversion = RUBY_VERSION =~ /^1.8./ ? '--1.8': '--1.9'
rmvn.options['-Djruby.versions'] = '1.6.7.2'#JRUBY_VERSION
rmvn.options['-Djruby.switches'] = rversion
View
2 lib/jbundler/cli.rb
@@ -3,7 +3,7 @@ module JBundler
class Cli < Thor
no_tasks do
def mvn
- @mvn ||= Maven::RubyMaven.new
+ @mvn ||= Maven::Ruby::Maven.new
end
def do_show
View
13 lib/jbundler/pom.rb
@@ -73,14 +73,25 @@ def initialize(name, version, deps, packaging = nil)
deps.each do |line|
if coord = to_coordinate(line)
- group_id, artifact_id, extension, version = coord.split(/:/)
+ coords = coord.split(/:/)
+ group_id = coords[0]
+ artifact_id = coords[1]
+ extension = coords[2]
+ classifier = nil
+ if coords.size == 4
+ version = coords[3]
+ else
+ classifier = coords[3]
+ version = coords[4]
+ end
xmlStreamWriter.writeStartElement("dependency".to_java)
writeElement(xmlStreamWriter,"groupId", group_id)
writeElement(xmlStreamWriter,"artifactId", artifact_id)
writeElement(xmlStreamWriter,"version", version)
writeElement(xmlStreamWriter,"type", extension) if extension != 'jar'
+ writeElement(xmlStreamWriter,"classifier", classifier) if classifier
xmlStreamWriter.writeEndElement #dependency
end
end
View
38 pom.xml
@@ -115,6 +115,18 @@
<artifactId>bundler</artifactId>
<type>gem</type>
</dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>1.9.5</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.testng</groupId>
+ <artifactId>testng</artifactId>
+ <version>6.8</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<dependencyManagement>
<dependencies>
@@ -209,6 +221,32 @@
<build>
<plugins>
<plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.0</version>
+ <executions>
+ <execution>
+ <phase>test-compile</phase>
+ <goals>
+ <goal>testCompile</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.13</version>
+ <executions>
+ <execution>
+ <phase>test</phase>
+ <goals>
+ <goal>test</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
<groupId>de.saumya.mojo</groupId>
<artifactId>gem-maven-plugin</artifactId>
<version>${jruby.plugins.version}</version>
View
6 spec/pom_spec.rb
@@ -22,4 +22,10 @@
pom.coordinate.must_equal "ruby.bundler:second:jar:1"
end
+ it 'should respect classifiers' do
+ pom = JBundler::Pom.new("third", "1", ["jar \"org.jruby:jruby-core\", '~>1.7.0'", "pom \"f:g:jdk15\", \">1.2\", \"<=2.0\""])
+ File.read(pom.file).must_equal "<?xml version=\"1.0\" ?><project><modelVersion>4.0.0</modelVersion><groupId>ruby.bundler</groupId><artifactId>third</artifactId><version>1</version><dependencies><dependency><groupId>org.jruby</groupId><artifactId>jruby-core</artifactId><version>[1.7.0,1.7.99999]</version></dependency><dependency><groupId>f</groupId><artifactId>g</artifactId><version>(1.2,2.0]</version><type>pom</type><classifier>jdk15</classifier></dependency></dependencies></project>"
+ pom.coordinate.must_equal "ruby.bundler:third:jar:1"
+ end
+
end
View
38 src/main/java/jbundler/Aether.java
@@ -137,28 +137,38 @@ public String getClasspath() {
}
public List<String> getResolvedCoordinates() {
- List<String> result = new ArrayList<String>();
-
PreorderNodeListGenerator nlg = new PreorderNodeListGenerator();
node.accept( nlg );
-
- for ( DependencyNode node: nlg.getNodes() )
- {
- if ( node.getDependency() != null )
- {
- Artifact artifact = node.getDependency().getArtifact();
- if ( artifact.getFile() != null)
- {
- StringBuilder coord = new StringBuilder(artifact.getGroupId()).append(":").append(artifact.getArtifactId())
- .append(":").append(artifact.getExtension()).append(":").append(artifact.getVersion());
+
+ return generateCoordinatesForNodes(nlg.getNodes());
+ }
+
+ //@VisibleForTesting
+ static List<String> generateCoordinatesForNodes(final List<DependencyNode> nodes) {
+ final List<String> result = new ArrayList<String>();
+ for (final DependencyNode node : nodes) {
+ if (node.getDependency() != null) {
+ final Artifact artifact = node.getDependency().getArtifact();
+ if (artifact.getFile() != null) {
+ final StringBuilder coord = new StringBuilder(artifact.getGroupId()).append(":")
+ .append(artifact.getArtifactId())
+ .append(":")
+ .append(artifact.getExtension())
+ .append(":");
+ // The classifier should never be null
+ if (!artifact.getClassifier().isEmpty()) {
+ coord.append(artifact.getClassifier()).append(":");
+ }
+
+ coord.append(artifact.getVersion());
result.add(coord.toString());
}
}
}
return result;
}
-
+
public void install(String coordinate, String file) throws InstallationException{
LocalRepositoryManager lrm = session.getLocalRepositoryManager();
@@ -172,4 +182,4 @@ public void install(String coordinate, String file) throws InstallationException
installer.install(session, request);
}
}
-}
+}
View
52 src/test/java/jbundler/TestAether.java
@@ -0,0 +1,52 @@
+package jbundler;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.mockito.Mockito;
+import org.sonatype.aether.artifact.Artifact;
+import org.sonatype.aether.graph.Dependency;
+import org.sonatype.aether.graph.DependencyNode;
+import org.sonatype.aether.util.artifact.DefaultArtifact;
+import org.sonatype.aether.util.graph.DefaultDependencyNode;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+public class TestAether {
+
+ @Test
+ public void testGetResolvedCoordinates() throws Exception {
+ final String[] coords = new String[]{
+ "a:b:jar:[0,)",
+ "b:c:pom:(2.3.4,)",
+ "c:d:jar:2.3.4",
+ "d:e:jar:[1.8.2,1.8.99999]",
+ "e:f:pom:[1.8,1.9.9)",
+ "f:g:pom:(1.2,2.0]",
+ "a:b:jar:jdk15:[0,)",
+ "b:c:pom:jdk15:(2.3.4,)",
+ "c:d:jar:jdk15:2.3.4",
+ "d:e:jar:jdk15:[1.8.2,1.8.99999]",
+ "e:f:pom:jdk15:[1.8,1.9.9)",
+ "f:g:pom:jdk15:(1.2,2.0]"};
+
+ final List<DependencyNode> nodes = new ArrayList<DependencyNode>();
+ for (final String coord : coords) {
+ nodes.add(generateNode(coord));
+ }
+
+ final List<String> generatedCoords = Aether.generateCoordinatesForNodes(nodes);
+ Assert.assertEquals(generatedCoords, Arrays.asList(coords));
+ }
+
+ private DefaultDependencyNode generateNode(final String coordinates) {
+ final DefaultArtifact artifact = new DefaultArtifact(coordinates);
+ // Add a dummy file to pretend the artifact was resolved
+ final Artifact artifactWithFile = artifact.setFile(Mockito.mock(File.class));
+
+ final Dependency dependency = new Dependency(artifactWithFile, null);
+ return new DefaultDependencyNode(dependency);
+ }
+}

0 comments on commit 5236065

Please sign in to comment.