Skip to content

Commit 1d18064

Browse files
committed
support for android packages with classifier in their namespaces.
Using dummy packages for testing. support for android packages with classifier in their spec integration tests for android packages specified with classifier. Bug: 176239199 Fixes: googlesamples#416 Change-Id: Ic9037755da8fc9afc2b995a9276245165c967a75
1 parent 15e6516 commit 1d18064

File tree

29 files changed

+154
-24
lines changed

29 files changed

+154
-24
lines changed

source/AndroidResolver/scripts/download_artifacts.gradle

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -439,31 +439,48 @@ public class PackageSpecifier implements Comparable {
439439
public String artifact = ""
440440
// Version expression of a maven package.
441441
public String versionExpression = ""
442+
// Classifier of the artifact.
443+
public String classifier = ""
442444
// Type of the artifact.
443445
public String artifactType = ""
444446

445447
/*
446448
* Extract the components of a package specifier string.
447449
*
448450
* @param packageSpecifier Package specification.
449-
* Package specification should match agroup:apackage:version@artifacttype
450-
* e.g a.b.c:d.e:1.2.3@aar
451+
* Package specification should match one of the following formats,
452+
* - agroup:apackage:version@artifacttype
453+
* e.g a.b.c:d.e:1.2.3@aar
454+
* - agroup:apackage:version:classifier@artifacttype
455+
* e.g a.b.c:d.e:1.2.3:f@aar
451456
*
452-
* @returns [group, artifact, version, artifactType] list with the components
457+
* @returns [group, artifact, version, artifactType, classifier] list with the components
453458
* of the package spec. If a component is not present the entry in the list
454459
* is null.
455460
*/
456461
public static PackageSpecifier fromString(String packageSpecifierString) {
457462
List<String> components = packageSpecifierString ?
458463
packageSpecifierString.split(/[:@]/) : []
464+
if (components.size() == 5) {
465+
// Special case to handle group:artifact:version:classifier@artifactType,
466+
// We want to maintain the components list as,
467+
// [group, artifact, version, artifactType, classifier]
468+
// because classifiers are a rare case and more often than not, the parser
469+
// will find artifactType in the second to last position.
470+
// Hence, if there are 5 components, swap the last two to make sure
471+
// artifactType is second to last.
472+
components.swap(3,4)
473+
}
459474
// Fill the list of components with null elements.
460-
components += ([""] * Math.min(4, (4 - components.size())))
475+
components += ([""] * Math.min(5, (5 - components.size())))
476+
461477
return new PackageSpecifier(
462478
group: components[0],
463479
artifact: components[1],
464480
versionExpression: components[2] ? (VersionRange.fromExpression(
465481
components[2])).expression : "",
466-
artifactType: components[3])
482+
artifactType: components[3],
483+
classifier: components[4])
467484
}
468485

469486
/*
@@ -508,6 +525,7 @@ public class PackageSpecifier implements Comparable {
508525
return resolvedArtifact.with {
509526
PackageSpecifier pkg = fromModuleVersionIdentifier(moduleVersion.id)
510527
pkg.artifactType = type
528+
pkg.classifier = classifier
511529
return pkg
512530
}
513531
}
@@ -613,7 +631,11 @@ public class PackageSpecifier implements Comparable {
613631
components.add(artifact)
614632
if (versionExpression) {
615633
if (artifactType) {
616-
components.add(versionExpression + "@" + artifactType)
634+
if (classifier) {
635+
components.add(versionExpression + ':' + classifier + "@" + artifactType)
636+
} else {
637+
components.add(versionExpression + "@" + artifactType)
638+
}
617639
} else {
618640
components.add(versionExpression)
619641
}
@@ -665,6 +687,9 @@ public class PackageSpecifier implements Comparable {
665687
if (versionExpression) {
666688
hypenSeparatedComponents += [versionExpression]
667689
}
690+
if (classifier) {
691+
hypenSeparatedComponents += [classifier]
692+
}
668693
String filename = hypenSeparatedComponents.join("-")
669694
if (artifactType) {
670695
filename += "." + (artifactType == "srcaar" ? "aar" : artifactType)
@@ -1345,6 +1370,7 @@ Tuple2<Boolean, Set<PackageSpecifier>> loosenVersionContraintsForConflicts(
13451370
new PackageSpecifier(
13461371
group: pkg.group,
13471372
artifact: pkg.artifact,
1373+
classifier: pkg.classifier,
13481374
versionExpression: (
13491375
isConflicting ?
13501376
pkg.versionRange.matchType == VersionExpressionMatchType.RANGE ?

source/AndroidResolver/scripts/download_artifacts_test.gradle

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,21 @@ createTestTask(
418418
["Copied artifacts:\n" +
419419
"com.android.support.support-annotations-23.0.1.magic"])
420420

421+
createTestTask(
422+
"testDownloadAvailableWithClassifier",
423+
"Downloads artifacts with one of them having a classifier in the name.",
424+
"org.test.psr:classifier:1.0.1:foo@aar;" +
425+
"com.android.support:support-annotations:26.1.0;",
426+
["org.test.psr.classifier-1.0.1-foo.aar":
427+
"org/test/psr/classifier/1.0.1/" +
428+
"org.test.psr.classifier-1.0.1-foo.aar",
429+
"com.android.support.support-annotations-26.1.0.jar":
430+
"com/android/support/support-annotations/26.1.0/" +
431+
"support-annotations-26.1.0.jar"],
432+
["Copied artifacts:\n" +
433+
"com.android.support.support-annotations-26.1.0.jar\n" +
434+
"org.test.psr.classifier-1.0.1-foo.aar"])
435+
421436
createTestTask(
422437
"testDownloadAvailableTwice",
423438
"Downloads a single artifact and it's dependencies from maven.",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xmlns="http://maven.apache.org/POM/4.0.0"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>org.test.psr</groupId>
6+
<artifactId>classifier</artifactId>
7+
<version>1.0.1</version>
8+
<packaging>aar</packaging>
9+
<dependencies>
10+
11+
</dependencies>
12+
</project>
13+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<metadata>
2+
<groupId>org.test.psr</groupId>
3+
<artifactId>classifier</artifactId>
4+
<versioning>
5+
<release>1.0.1</release>
6+
<versions>
7+
<version>1.0.1</version>
8+
9+
</versions>
10+
<lastUpdated/>
11+
</versioning>
12+
</metadata>
13+

source/AndroidResolver/src/AndroidXmlDependencies.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ protected override bool Read(string filename, Logger logger) {
5858
string group = null;
5959
string artifact = null;
6060
string versionSpec = null;
61+
string classifier = null;
6162
List<string> repositories = null;
6263
logger.Log(
6364
String.Format("Reading Android dependency XML file {0}", filename),
@@ -79,12 +80,15 @@ protected override bool Read(string filename, Logger logger) {
7980
group = null;
8081
artifact = null;
8182
versionSpec = null;
83+
classifier = null;
8284
repositories = new List<string>();
8385
// Parse a package specification in the form:
8486
// group:artifact:version_spec
87+
// (or)
88+
// group:artifact:version_spec:classifier
8589
var spec = reader.GetAttribute("spec") ?? "";
8690
var specComponents = spec.Split(new [] { ':' });
87-
if (specComponents.Length != 3) {
91+
if (specComponents.Length != 3 && specComponents.Length != 4) {
8892
logger.Log(
8993
String.Format(
9094
"Ignoring invalid package specification '{0}' " +
@@ -96,11 +100,15 @@ protected override bool Read(string filename, Logger logger) {
96100
group = specComponents[0];
97101
artifact = specComponents[1];
98102
versionSpec = specComponents[2];
103+
if (specComponents.Length == 4)
104+
classifier = specComponents[3];
105+
99106
return true;
100107
} else if (!(String.IsNullOrEmpty(group) ||
101108
String.IsNullOrEmpty(artifact) ||
102-
String.IsNullOrEmpty(versionSpec))) {
103-
svcSupport.DependOn(group, artifact, versionSpec,
109+
String.IsNullOrEmpty(versionSpec)
110+
)) {
111+
svcSupport.DependOn(group, artifact, versionSpec, classifier: classifier,
104112
packageIds: androidSdkPackageIds.ToArray(),
105113
repositories: repositories.ToArray(),
106114
createdBy: String.Format("{0}:{1}", filename,

source/AndroidResolver/test/AndroidResolverIntegrationTestsUnityProject/Assets/ExternalDependencyManager/Editor/TestDependencies.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
<repository>Assets/Firebase/m2repository</repository>
99
</repositories>
1010
</androidPackage>
11+
<!-- Java package specified with a classifier. -->
12+
<androidPackage spec="org.test.psr:classifier:1.0.1:foo@aar"/>
1113
<!-- Global repository. -->
1214
<repositories>
1315
<repository>file:///my/nonexistant/test/repo</repository>

source/AndroidResolver/test/AndroidResolverIntegrationTestsUnityProject/ExpectedArtifacts/NoExport/GradleTemplate/mainTemplate.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ allprojects {
2727
url "https://maven.google.com"
2828
}
2929
maven {
30-
url "file:///my/nonexistant/test/repo" // Assets/ExternalDependencyManager/Editor/TestDependencies.xml:15
30+
url "file:///my/nonexistant/test/repo" // Assets/ExternalDependencyManager/Editor/TestDependencies.xml:17
3131
}
3232
maven {
33-
url (unityProjectPath + "/project_relative_path/repo") // Assets/ExternalDependencyManager/Editor/TestDependencies.xml:15
33+
url (unityProjectPath + "/project_relative_path/repo") // Assets/ExternalDependencyManager/Editor/TestDependencies.xml:17
3434
}
3535
maven {
3636
url (unityProjectPath + "/Assets/GeneratedLocalRepo/Firebase/m2repository") // Assets/ExternalDependencyManager/Editor/TestDependencies.xml:10
@@ -49,6 +49,7 @@ dependencies {
4949
compile 'com.android.support:support-annotations:26.1.0' // Assets/ExternalDependencyManager/Editor/TestDependencies.xml:4
5050
compile 'com.google.firebase:firebase-app-unity:5.1.1' // Assets/ExternalDependencyManager/Editor/TestDependencies.xml:10
5151
compile 'com.google.firebase:firebase-common:16.0.0' // Google.AndroidResolverIntegrationTests.SetupDependencies
52+
compile 'org.test.psr:classifier:1.0.1:foo@aar' // Assets/ExternalDependencyManager/Editor/TestDependencies.xml:12
5253
// Android Resolver Dependencies End
5354
**DEPS**}
5455

source/AndroidResolver/test/AndroidResolverIntegrationTestsUnityProject/ExpectedArtifacts/NoExport/GradleTemplateJetifier/mainTemplate.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ allprojects {
3333
url "https://maven.google.com"
3434
}
3535
maven {
36-
url "file:///my/nonexistant/test/repo" // Assets/ExternalDependencyManager/Editor/TestDependencies.xml:15
36+
url "file:///my/nonexistant/test/repo" // Assets/ExternalDependencyManager/Editor/TestDependencies.xml:17
3737
}
3838
maven {
39-
url (unityProjectPath + "/project_relative_path/repo") // Assets/ExternalDependencyManager/Editor/TestDependencies.xml:15
39+
url (unityProjectPath + "/project_relative_path/repo") // Assets/ExternalDependencyManager/Editor/TestDependencies.xml:17
4040
}
4141
maven {
4242
url (unityProjectPath + "/Assets/GeneratedLocalRepo/Firebase/m2repository") // Assets/ExternalDependencyManager/Editor/TestDependencies.xml:10
@@ -55,6 +55,7 @@ dependencies {
5555
compile 'com.android.support:support-annotations:26.1.0' // Assets/ExternalDependencyManager/Editor/TestDependencies.xml:4
5656
compile 'com.google.firebase:firebase-app-unity:5.1.1' // Assets/ExternalDependencyManager/Editor/TestDependencies.xml:10
5757
compile 'com.google.firebase:firebase-common:16.0.0' // Google.AndroidResolverIntegrationTests.SetupDependencies
58+
compile 'org.test.psr:classifier:1.0.1:foo@aar' // Assets/ExternalDependencyManager/Editor/TestDependencies.xml:12
5859
// Android Resolver Dependencies End
5960
**DEPS**}
6061

source/AndroidResolver/test/AndroidResolverIntegrationTestsUnityProject/ExpectedArtifacts/NoExport/GradleTemplateLibrary/mainTemplate.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ allprojects {
2727
url "https://maven.google.com"
2828
}
2929
maven {
30-
url "file:///my/nonexistant/test/repo" // Assets/ExternalDependencyManager/Editor/TestDependencies.xml:15
30+
url "file:///my/nonexistant/test/repo" // Assets/ExternalDependencyManager/Editor/TestDependencies.xml:17
3131
}
3232
maven {
33-
url (unityProjectPath + "/project_relative_path/repo") // Assets/ExternalDependencyManager/Editor/TestDependencies.xml:15
33+
url (unityProjectPath + "/project_relative_path/repo") // Assets/ExternalDependencyManager/Editor/TestDependencies.xml:17
3434
}
3535
maven {
3636
url (unityProjectPath + "/Assets/GeneratedLocalRepo/Firebase/m2repository") // Assets/ExternalDependencyManager/Editor/TestDependencies.xml:10
@@ -49,6 +49,7 @@ dependencies {
4949
compile 'com.android.support:support-annotations:26.1.0' // Assets/ExternalDependencyManager/Editor/TestDependencies.xml:4
5050
compile 'com.google.firebase:firebase-app-unity:5.1.1' // Assets/ExternalDependencyManager/Editor/TestDependencies.xml:10
5151
compile 'com.google.firebase:firebase-common:16.0.0' // Google.AndroidResolverIntegrationTests.SetupDependencies
52+
compile 'org.test.psr:classifier:1.0.1:foo@aar' // Assets/ExternalDependencyManager/Editor/TestDependencies.xml:12
5253
// Android Resolver Dependencies End
5354
**DEPS**}
5455

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xmlns="http://maven.apache.org/POM/4.0.0"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>org.test.psr</groupId>
6+
<artifactId>classifier</artifactId>
7+
<version>1.0.1</version>
8+
<packaging>aar</packaging>
9+
<dependencies>
10+
11+
</dependencies>
12+
</project>
13+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<metadata>
2+
<groupId>org.test.psr</groupId>
3+
<artifactId>classifier</artifactId>
4+
<versioning>
5+
<release>1.0.1</release>
6+
<versions>
7+
<version>1.0.1</version>
8+
9+
</versions>
10+
<lastUpdated/>
11+
</versioning>
12+
</metadata>
13+

source/AndroidResolver/test/src/AndroidResolverIntegrationTests.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,10 @@ private static void ValidateDependencies(IntegrationTester.TestCaseResult testCa
467467
"Assets/ExternalDependencyManager/Editor/TestDependencies.xml:10"),
468468
new KeyValuePair<string, string>(
469469
"com.google.firebase:firebase-common:16.0.0",
470-
"Google.AndroidResolverIntegrationTests.SetupDependencies")
470+
"Google.AndroidResolverIntegrationTests.SetupDependencies"),
471+
new KeyValuePair<string, string>(
472+
"org.test.psr:classifier:1.0.1:foo@aar",
473+
"Assets/ExternalDependencyManager/Editor/TestDependencies.xml:12"),
471474
},
472475
PlayServicesResolver.GetPackageSpecs(),
473476
"Package Specs", testCaseResult);
@@ -476,10 +479,10 @@ private static void ValidateDependencies(IntegrationTester.TestCaseResult testCa
476479
new List<KeyValuePair<string, string>>() {
477480
new KeyValuePair<string, string>(
478481
"file:///my/nonexistant/test/repo",
479-
"Assets/ExternalDependencyManager/Editor/TestDependencies.xml:15"),
482+
"Assets/ExternalDependencyManager/Editor/TestDependencies.xml:17"),
480483
new KeyValuePair<string, string>(
481484
"file:///" + Path.GetFullPath("project_relative_path/repo").Replace("\\", "/"),
482-
"Assets/ExternalDependencyManager/Editor/TestDependencies.xml:15"),
485+
"Assets/ExternalDependencyManager/Editor/TestDependencies.xml:17"),
483486
new KeyValuePair<string, string>(
484487
"file:///" + Path.GetFullPath(
485488
"Assets/Firebase/m2repository").Replace("\\", "/"),

source/JarResolverLib/src/Google.JarResolver/Dependency.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,15 @@ public class Dependency {
4949
/// <param name="group">Group ID</param>
5050
/// <param name="artifact">Artifact ID</param>
5151
/// <param name="version">Version constraint.</param>
52+
/// <param name="classifier">Artifact classifier.</param>
5253
/// <param name="packageIds">Android SDK package identifiers required for this
5354
/// artifact.</param>
5455
/// <param name="repositories">List of additional repository directories to search for
5556
/// this artifact.</param>
5657
/// <param name="createdBy">Human readable string that describes where this dependency
5758
/// originated.</param>
58-
public Dependency(string group, string artifact, string version, string[] packageIds=null,
59+
public Dependency(string group, string artifact, string version,
60+
string classifier = null, string[] packageIds=null,
5961
string[] repositories=null, string createdBy=null) {
6062
// If the dependency was added programmatically, strip out stack frames from inside the
6163
// library since the developer is likely interested in where in their code the
@@ -88,6 +90,7 @@ public Dependency(string group, string artifact, string version, string[] packag
8890
Group = group;
8991
Artifact = artifact;
9092
Version = version;
93+
Classifier = classifier;
9194
PackageIds = packageIds;
9295
Repositories = repositories;
9396
CreatedBy = createdBy;
@@ -101,6 +104,7 @@ public Dependency(Dependency dependency) {
101104
Group = dependency.Group;
102105
Artifact = dependency.Artifact;
103106
Version = dependency.Version;
107+
Classifier = dependency.Classifier;
104108
if (dependency.PackageIds != null) {
105109
PackageIds = (string[])dependency.PackageIds.Clone();
106110
}
@@ -133,6 +137,14 @@ public Dependency(Dependency dependency) {
133137
/// <value>The version.</value>
134138
public string Version { get; set; }
135139

140+
/// <summary>
141+
/// Gets the classifier.
142+
/// </summary>
143+
/// <value>The classifier.</value>
144+
public string Classifier { get; set; }
145+
146+
/// <summary>
147+
136148
/// <summary>
137149
/// Array of Android SDK identifiers for packages that are required for this
138150
/// artifact.
@@ -158,7 +170,11 @@ public Dependency(Dependency dependency) {
158170
/// group, artifact and version constraint.
159171
/// </summary>
160172
/// <value>The key.</value>
161-
public string Key { get { return Group + ":" + Artifact + ":" + Version; } }
173+
public string Key { get {
174+
string key = Group + ":" + Artifact + ":" + Version;
175+
if (!String.IsNullOrEmpty(Classifier))
176+
key += ":" + Classifier;
177+
return key; } }
162178

163179
/// <summary>
164180
/// Returns a <see cref="System.String"/> that represents

0 commit comments

Comments
 (0)