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>

0 commit comments

Comments
 (0)