This repository has been archived by the owner on Aug 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TYCHO-483 add maven dependencies for checked-in jars
Dependencies to nested jars within the same reactor are now added as system scope dependencies to maven dependency model if they exist in the filesystem. This covers the scenario of jars checked in to SCM. Move corresponding testcase from maven-osgi-compiler-plugin where it was misplaced to a dedicated testcase in tycho-osgi-components.
- Loading branch information
Showing
16 changed files
with
275 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
...-components/src/test/java/org/codehaus/tycho/maven/test/MavenDependencyCollectorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
package org.codehaus.tycho.maven.test; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import org.apache.maven.artifact.Artifact; | ||
import org.apache.maven.model.Dependency; | ||
import org.apache.maven.project.MavenProject; | ||
import org.codehaus.tycho.testing.AbstractTychoMojoTestCase; | ||
import org.junit.Assert; | ||
|
||
public class MavenDependencyCollectorTest | ||
extends AbstractTychoMojoTestCase | ||
{ | ||
|
||
public void testNestedJars() | ||
throws Exception | ||
{ | ||
File targetPlatform = getBasedir( "targetplatforms/nestedJar" ); | ||
List<MavenProject> projects = getSortedProjects( getBasedir( "projects/mavendeps" ), targetPlatform ); | ||
{ | ||
// 1. project with dependency to external bundle with nested jar | ||
MavenProject project = projects.get( 1 ); | ||
final String plainJarPath = "target/targetplatforms/nestedJar/plugins/nested_1.0.0.jar"; | ||
final String nestedJarPath = "target/local-repo/.cache/tycho/nested_1.0.0.jar/lib/lib.jar"; | ||
List<Dependency> mavenDependencies = project.getModel().getDependencies(); | ||
Assert.assertEquals( 2, mavenDependencies.size() ); | ||
final String expectedGroupId = "p2.eclipse-plugin"; | ||
final String expectedArtifactId = "nested"; | ||
final String expectedVersion = "1.0.0"; | ||
final String expectedType = "jar"; | ||
final String expectedScope = Artifact.SCOPE_SYSTEM; | ||
// assert that dependencies to both plain jar and nested jar are injected back into maven model | ||
assertDependenciesContains( mavenDependencies, expectedGroupId, expectedArtifactId, expectedVersion, null, | ||
expectedType, expectedScope, new File( getBasedir(), plainJarPath ) ); | ||
assertDependenciesContains( mavenDependencies, expectedGroupId, expectedArtifactId, expectedVersion, | ||
"lib/lib.jar", expectedType, expectedScope, new File( getBasedir(), | ||
nestedJarPath ) ); | ||
} | ||
{ | ||
// 2. project with dependency to bundle with nested jar within the same reactor | ||
MavenProject project = projects.get( 3 ); | ||
List<Dependency> mavenDependencies = project.getModel().getDependencies(); | ||
// assert that dependencies to both reactor module and checked-in nested jar are injected back into maven | ||
// model. | ||
// Also, dependency to missing nested jar must *not* be injected (would throw | ||
// MavenDependencyResolutionException otherwise) | ||
Assert.assertEquals( 2, mavenDependencies.size() ); | ||
final String expectedGroupId = "mavenDependencies"; | ||
final String expectedArtifactId = "p002"; | ||
final String expectedVersion = "1.0.0"; | ||
assertDependenciesContains( mavenDependencies, expectedGroupId, expectedArtifactId, expectedVersion, null, | ||
"eclipse-plugin", Artifact.SCOPE_PROVIDED, null ); | ||
assertDependenciesContains( mavenDependencies, expectedGroupId, expectedArtifactId, expectedVersion, | ||
"lib/lib.jar", "jar", Artifact.SCOPE_SYSTEM, | ||
new File( getBasedir( "projects/mavendeps" ), "p002/lib/lib.jar" ) ); | ||
} | ||
} | ||
|
||
private void assertDependenciesContains( List<Dependency> mavenDependencies, String groupId, String artifactId, | ||
String version, String classifier, String type, String scope, | ||
File systemLocation ) | ||
throws IOException | ||
{ | ||
for ( Dependency dependency : mavenDependencies ) | ||
{ | ||
boolean systemLocationEquals = true; | ||
if ( systemLocation != null ) | ||
{ | ||
systemLocationEquals = | ||
dependency.getSystemPath() != null | ||
&& systemLocation.getCanonicalFile().getAbsolutePath().equals( new File( | ||
dependency.getSystemPath() ).getCanonicalFile().getAbsolutePath() ); | ||
} | ||
if ( systemLocationEquals // | ||
&& groupId.equals( dependency.getGroupId() ) // | ||
&& artifactId.equals( dependency.getArtifactId() )// | ||
&& version.equals( dependency.getVersion() ) // | ||
&& type.equals( dependency.getType() )// | ||
&& scope.equals( dependency.getScope() ) // | ||
) | ||
{ | ||
if ( classifier == null ) | ||
{ | ||
if ( dependency.getClassifier() == null ) | ||
{ | ||
return; | ||
} | ||
} | ||
else | ||
{ | ||
if ( classifier.equals( dependency.getClassifier() ) ) | ||
{ | ||
return; | ||
} | ||
} | ||
} | ||
} | ||
fail( "Expected dependency [" + groupId + ":" + artifactId + ":" + version + ":" + classifier + ":" + type | ||
+ ":" + scope + ":" + systemLocation + "] not found in actual dependencies: " | ||
+ toDebugString( mavenDependencies ) ); | ||
} | ||
|
||
private static String toDebugString( List<Dependency> mavenDependencies ) | ||
{ | ||
StringBuilder sb = new StringBuilder(); | ||
for ( Dependency dependency : mavenDependencies ) | ||
{ | ||
sb.append( toDebugString( dependency ) ); | ||
} | ||
return sb.toString(); | ||
} | ||
|
||
private static String toDebugString( Dependency dependency ) | ||
{ | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append( '[' ); | ||
sb.append( dependency.getGroupId() ); | ||
sb.append( ':' ); | ||
sb.append( dependency.getArtifactId() ); | ||
sb.append( ':' ); | ||
sb.append( dependency.getVersion() ); | ||
sb.append( ':' ); | ||
sb.append( dependency.getClassifier() ); | ||
sb.append( ':' ); | ||
sb.append( dependency.getType() ); | ||
sb.append( ", scope: " ); | ||
sb.append( dependency.getScope() ); | ||
sb.append( ", systemPath: " ); | ||
sb.append( dependency.getSystemPath() ); | ||
sb.append( ']' ); | ||
return sb.toString(); | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
tycho-osgi-components/src/test/resources/projects/mavendeps/p001/META-INF/MANIFEST.MF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
hManifest-Version: 1.0 | ||
Bundle-ManifestVersion: 2 | ||
Bundle-Name: P001 Plug-in | ||
Bundle-SymbolicName: p001 | ||
Bundle-Version: 1.0.0 | ||
Bundle-ClassPath: . | ||
Require-Bundle: nested |
4 changes: 4 additions & 0 deletions
4
tycho-osgi-components/src/test/resources/projects/mavendeps/p001/build.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
source.. = src/ | ||
output.. = bin/ | ||
bin.includes = META-INF/,\ | ||
. |
13 changes: 13 additions & 0 deletions
13
tycho-osgi-components/src/test/resources/projects/mavendeps/p001/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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/maven-v4_0_0.xsd"> | ||
<parent> | ||
<artifactId>projects</artifactId> | ||
<groupId>mavenDependencies</groupId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>p001</artifactId> | ||
<packaging>eclipse-plugin</packaging> | ||
<version>1.0.0</version> | ||
</project> |
6 changes: 6 additions & 0 deletions
6
tycho-osgi-components/src/test/resources/projects/mavendeps/p002/META-INF/MANIFEST.MF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
hManifest-Version: 1.0 | ||
Bundle-ManifestVersion: 2 | ||
Bundle-Name: P002 Plug-in | ||
Bundle-SymbolicName: p002 | ||
Bundle-Version: 1.0.0 | ||
Bundle-ClassPath: .,lib/lib.jar,lib/notexisting.jar |
5 changes: 5 additions & 0 deletions
5
tycho-osgi-components/src/test/resources/projects/mavendeps/p002/build.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
source.. = src/ | ||
output.. = bin/ | ||
bin.includes = META-INF/,\ | ||
lib/,\ | ||
. |
Empty file.
13 changes: 13 additions & 0 deletions
13
tycho-osgi-components/src/test/resources/projects/mavendeps/p002/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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/maven-v4_0_0.xsd"> | ||
<parent> | ||
<artifactId>projects</artifactId> | ||
<groupId>mavenDependencies</groupId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>p002</artifactId> | ||
<packaging>eclipse-plugin</packaging> | ||
<version>1.0.0</version> | ||
</project> |
7 changes: 7 additions & 0 deletions
7
tycho-osgi-components/src/test/resources/projects/mavendeps/p003/META-INF/MANIFEST.MF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
hManifest-Version: 1.0 | ||
Bundle-ManifestVersion: 2 | ||
Bundle-Name: P003 Plug-in | ||
Bundle-SymbolicName: p003 | ||
Bundle-Version: 1.0.0 | ||
Bundle-ClassPath: . | ||
Require-Bundle: p002 |
4 changes: 4 additions & 0 deletions
4
tycho-osgi-components/src/test/resources/projects/mavendeps/p003/build.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
source.. = src/ | ||
output.. = bin/ | ||
bin.includes = META-INF/,\ | ||
. |
13 changes: 13 additions & 0 deletions
13
tycho-osgi-components/src/test/resources/projects/mavendeps/p003/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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/maven-v4_0_0.xsd"> | ||
<parent> | ||
<artifactId>projects</artifactId> | ||
<groupId>mavenDependencies</groupId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>p003</artifactId> | ||
<packaging>eclipse-plugin</packaging> | ||
<version>1.0.0</version> | ||
</project> |
13 changes: 13 additions & 0 deletions
13
tycho-osgi-components/src/test/resources/projects/mavendeps/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?><project> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>mavenDependencies</groupId> | ||
<artifactId>projects</artifactId> | ||
<packaging>pom</packaging> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<modules> | ||
<module>p001</module> | ||
<module>p002</module> | ||
<module>p003</module> | ||
</modules> | ||
|
||
</project> |
Binary file added
BIN
+359 Bytes
tycho-osgi-components/src/test/resources/targetplatforms/nestedJar/plugins/nested_1.0.0.jar
Binary file not shown.
Oops, something went wrong.