Skip to content

Commit

Permalink
FORGE-1324: Added tests and fix for indirect furnace dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Nov 22, 2013
1 parent 0d46b9d commit 38f8018
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,27 +156,29 @@ public String resolveAPIVersion(AddonId addonId)
Settings settings = container.getSettings();
DefaultRepositorySystemSession session = container.setupRepoSession(system, settings);
List<RemoteRepository> repositories = MavenRepositories.getRemoteRepositories(container, settings);
// Furnace API is in provided scope.
session.setDependencySelector(new ScopeDependencySelector(Arrays.asList("provided", "compile"), null));
String mavenCoords = toMavenCoords(addonId);
Artifact queryArtifact = new DefaultArtifact(mavenCoords);
CollectRequest collectRequest = new CollectRequest(new Dependency(queryArtifact, null), repositories);

session.setDependencySelector(new ScopeDependencySelector(Arrays.asList("provided", "compile"), Arrays
.asList("test")));

CollectRequest request = new CollectRequest(new Dependency(queryArtifact, null), repositories);
CollectResult result;
try
{
result = system.collectDependencies(session, collectRequest);
result = system.collectDependencies(session, request);
}
catch (DependencyCollectionException e)
{
throw new RuntimeException(e);
}
String apiVersion = findVersion(result.getRoot(), FURNACE_API_GROUP_ID, FURNACE_API_ARTIFACT_ID);
String apiVersion = findVersion(result.getRoot().getChildren(), FURNACE_API_GROUP_ID, FURNACE_API_ARTIFACT_ID);
return apiVersion;
}

private String findVersion(DependencyNode node, String groupId, String artifactId)
private String findVersion(List<DependencyNode> dependencies, String groupId, String artifactId)
{
for (DependencyNode child : node.getChildren())
for (DependencyNode child : dependencies)
{
Artifact childArtifact = child.getArtifact();

Expand All @@ -185,6 +187,14 @@ private String findVersion(DependencyNode node, String groupId, String artifactI
{
return childArtifact.getBaseVersion();
}
else
{
String version = findVersion(child.getChildren(), groupId, artifactId);
if (version != null)
{
return version;
}
}
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,12 @@ public void testResolveAPIVersion() throws Exception
Assert.assertEquals("2.0.0.Beta3", apiVersion);
}

@Test
public void testResolveIndirectAPIVersion() throws Exception
{
AddonId sut = AddonId.from("test:furnace_api_indirect_dep", "1.0.0.Final");
String apiVersion = resolver.resolveAPIVersion(sut);
Assert.assertEquals("2.0.0.Beta3", apiVersion);
}

}
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>furnace_api_indirect_dep</artifactId>
<version>1.0.0.Final</version>
<name>Forge - Example Addon</name>
<dependencies>
<dependency>
<groupId>test</groupId>
<artifactId>no_dep</artifactId>
<version>1.0.0.Final</version>
<classifier>forge-addon</classifier>
</dependency>
<dependency>
<groupId>test</groupId>
<artifactId>furnace_api_dep</artifactId>
<version>1.0.0.Final</version>
<classifier>forge-addon</classifier>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>create-forge-addon</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<inherited>false</inherited>
<configuration>
<classifier>forge-addon</classifier>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>test</groupId>
<artifactId>furnace_api_indirect_dep</artifactId>
<versioning>
<latest>1.0.0.Final</latest>
<release>1.0.0.Final</release>
<versions>
<version>1.0.0.Final</version>
</versions>
<lastUpdated>20130310152137</lastUpdated>
</versioning>
</metadata>

0 comments on commit 38f8018

Please sign in to comment.