Skip to content

Commit

Permalink
FORGE-2219: Fix NonSnapshotDependencyFilter activation criteria
Browse files Browse the repository at this point in the history
Signed-off-by: George Gastaldi <gegastaldi@gmail.com>
  • Loading branch information
neoludo authored and gastaldi committed Feb 16, 2015
1 parent 7b140cf commit 4386af8
Show file tree
Hide file tree
Showing 23 changed files with 432 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.jboss.forge.addon.maven.projects.MavenFacetImpl;
import org.jboss.forge.addon.projects.Project;
import org.jboss.forge.addon.projects.facets.DependencyFacet;
import org.jboss.forge.furnace.util.Strings;

/**
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
Expand Down Expand Up @@ -387,7 +388,7 @@ public List<Coordinate> resolveAvailableVersions(final Dependency dep)
{
DependencyQueryBuilder query = DependencyQueryBuilder.create(dep.getCoordinate()).setRepositories(
getRepositories());
if (dep.getCoordinate().getVersion() != null && !dep.getCoordinate().getVersion().contains("SNAPSHOT"))
if (!Strings.isNullOrEmpty(dep.getCoordinate().getVersion()) && !dep.getCoordinate().getVersion().contains("SNAPSHOT"))
{
query.setFilter(new NonSnapshotDependencyFilter());
}
Expand Down
65 changes: 64 additions & 1 deletion maven/tests/pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<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">
<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>
<parent>
<groupId>org.jboss.forge.addon</groupId>
Expand Down Expand Up @@ -47,4 +48,66 @@
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>default-testResources</id>
<phase>process-test-resources</phase>
<goals>
<goal>testResources</goal>
</goals>
<configuration>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>jar</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</execution>
<execution>
<id>copy-repository</id>
<phase>process-test-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/repository</outputDirectory>
<resources>
<resource>
<directory>${basedir}/src/test/resources/repository</directory>
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>copy-settings</id>
<phase>process-test-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/settings/profiles</outputDirectory>
<resources>
<resource>
<directory>${basedir}/src/test/resources/profiles</directory>
<filtering>true</filtering>
</resource>
</resources>
<escapeString>\</escapeString>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@

import static org.jboss.forge.addon.dependencies.util.Dependencies.areEquivalent;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
import java.util.List;

import javax.inject.Inject;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.forge.addon.dependencies.Coordinate;
import org.jboss.forge.addon.dependencies.Dependency;
import org.jboss.forge.addon.dependencies.builder.DependencyBuilder;
import org.jboss.forge.addon.projects.Project;
Expand All @@ -23,10 +27,13 @@
import org.jboss.forge.arquillian.AddonDependency;
import org.jboss.forge.arquillian.Dependencies;
import org.jboss.forge.arquillian.archive.ForgeArchive;
import org.jboss.forge.furnace.manager.maven.MavenContainer;
import org.jboss.forge.furnace.repositories.AddonDependencyEntry;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;

Expand Down Expand Up @@ -64,12 +71,53 @@ public static ForgeArchive getDeployment()
@Inject
private ProjectFactory projectFactory;

private static String previousUserSettings;
private static String previousLocalRepository;

@Before
public void setUp()
{
project = projectFactory.createTempProject();
}

@BeforeClass
public static void setRemoteRepository() throws IOException
{
previousUserSettings = System.setProperty(MavenContainer.ALT_USER_SETTINGS_XML_LOCATION,
getAbsolutePath("profiles/settings.xml"));
previousLocalRepository = System.setProperty(MavenContainer.ALT_LOCAL_REPOSITORY_LOCATION,
"target/the-other-repository");
}

private static String getAbsolutePath(String path) throws FileNotFoundException
{
URL resource = Thread.currentThread().getContextClassLoader().getResource(path);
if (resource == null)
throw new FileNotFoundException(path);
return resource.getFile();
}

@AfterClass
public static void clearRemoteRepository()
{
if (previousUserSettings == null)
{
System.clearProperty(MavenContainer.ALT_USER_SETTINGS_XML_LOCATION);
}
else
{
System.setProperty(MavenContainer.ALT_USER_SETTINGS_XML_LOCATION, previousUserSettings);
}
if (previousLocalRepository == null)
{
System.clearProperty(MavenContainer.ALT_LOCAL_REPOSITORY_LOCATION);
}
else
{
System.setProperty(MavenContainer.ALT_LOCAL_REPOSITORY_LOCATION, previousUserSettings);
}
}

@Test
public void testAddDirectDependencyOrder() throws Exception
{
Expand Down Expand Up @@ -121,6 +169,15 @@ public void testAddDirectManagedDependencyOrder() throws Exception
assertDependencies(dependencyTwo, dependencies.get(1));
}

@Test
public void testResolveAvailableVersions() throws Exception
{
final DependencyFacet facet = project.getFacet(DependencyFacet.class);
DependencyBuilder dependency = DependencyBuilder.create("test:no_dep:::pom");
List<Coordinate> versions = facet.resolveAvailableVersions(dependency);
Assert.assertEquals(6, versions.size());
}

@Test
public void testDifferentDependencyType() throws Exception
{
Expand Down
45 changes: 45 additions & 0 deletions maven/tests/src/test/resources/profiles/settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

<profiles>
<profile>
<id>supertest</id>

<repositories>
<repository>
<id>test-repository</id>
<name>Test repository</name>
<url>file://${basedir}/target/repository</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>test-repository</id>
<name>Test repository</name>
<url>file://${basedir}/target/repository</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>

<activeProfiles>
<activeProfile>supertest</activeProfile>
</activeProfiles>

</settings>
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<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>no_dep</artifactId>
<version>1.0.0.Final</version>
<name>Forge - Example Addon</name>

<dependencies>
<dependency>
<groupId>org.jboss.forge.furnace</groupId>
<artifactId>furnace-api</artifactId>
<version>2.4.1.Final</version>
<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>
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<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>no_dep</artifactId>
<version>1.0.1.Final</version>
<name>Forge - Example Addon</name>

<dependencies>
<dependency>
<groupId>org.jboss.forge.furnace</groupId>
<artifactId>furnace-api</artifactId>
<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>
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<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>no_dep</artifactId>
<version>1.1.0.Final</version>
<name>Forge - Example Addon</name>

<dependencies>
<dependency>
<groupId>org.jboss.forge.furnace</groupId>
<artifactId>furnace-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.forge.addon</groupId>
<artifactId>example2</artifactId>
<version>2.0.0-SNAPSHOT</version>
<classifier>forge-addon</classifier>
<optional>true</optional>
</dependency>
<!-- Just added for testing dependency resolution -->
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</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>
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 4386af8

Please sign in to comment.