Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new path for provisioning profiles starting Xcode 16 #1292

Merged
merged 2 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/main/java/com/gluonhq/substrate/util/ios/CodeSigning.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private MobileProvision getProvisioningProfile() throws IOException {
if (providedMobileProvision == null
|| providedMobileProvision.equals(mobileProvision.getName())) {
this.identity = identity;
Logger.logDebug("Got provisioning profile: " + mobileProvision.getName());
Logger.logDebug("Got provisioning profile: " + mobileProvision.getName() + " from " + mobileProvision.getProvisioningPath());
return mobileProvision;
}
}
Expand Down Expand Up @@ -206,7 +206,7 @@ private MobileProvision tryModifiedBundleId(Identity identity, String bundleId,
private List<MobileProvision> retrieveValidMobileProvisions() {
final LocalDate now = LocalDate.now();
if (mobileProvisions == null) {
mobileProvisions = retrieveAllMobileProvisions();
mobileProvisions = getProvisioningProfiles();
}
return mobileProvisions.stream()
.filter(provision -> {
Expand All @@ -216,8 +216,17 @@ private List<MobileProvision> retrieveValidMobileProvisions() {
.collect(Collectors.toList());
}

public static List<MobileProvision> retrieveAllMobileProvisions() {
Path provisionPath = Paths.get(System.getProperty("user.home"), "Library", "MobileDevice", "Provisioning Profiles");
public static List<MobileProvision> getProvisioningProfiles() {
// Starting Xcode 16+:
Path provisionPath = Paths.get(System.getProperty("user.home"), "Library", "Developer", "Xcode", "UserData", "Provisioning Profiles");
List<MobileProvision> provisions = new ArrayList<>(retrieveAllMobileProvisionsFromPath(provisionPath));
// Before Xcode 16:
provisionPath = Paths.get(System.getProperty("user.home"), "Library", "MobileDevice", "Provisioning Profiles");
provisions.addAll(retrieveAllMobileProvisionsFromPath(provisionPath));
return provisions;
}

private static List<MobileProvision> retrieveAllMobileProvisionsFromPath(Path provisionPath) {
if (!Files.exists(provisionPath) || !Files.isDirectory(provisionPath)) {
Logger.logSevere("Invalid provisioning profiles folder at " + provisionPath.toString());
return Collections.emptyList();
Expand Down
24 changes: 17 additions & 7 deletions src/main/java/com/gluonhq/substrate/util/macos/CodeSigning.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2021, Gluon
* Copyright (c) 2019, 2024, Gluon
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -377,7 +377,8 @@ private ProvisionProfile getProvisioningProfile() {
.findFirst()
.orElse(null);
}
Logger.logDebug("Provisioning profile: " + (provisionProfile != null ? provisionProfile.getName() : null));
Logger.logDebug("Got provisioning profile: " + (provisionProfile != null ?
provisionProfile.getName() + " from " + provisionProfile.getProvisioningPath() : null));
return provisionProfile;
}

Expand All @@ -393,18 +394,27 @@ private ProvisionProfile findProvisionProfile(Identity identity, String bundleId
private List<ProvisionProfile> retrieveValidProvisionProfiles() {
final LocalDate now = LocalDate.now();
if (provisionProfiles == null) {
provisionProfiles = retrieveAllProvisionProfiles().stream()
provisionProfiles = getProvisioningProfiles();
}
return provisionProfiles.stream()
.filter(provision -> {
LocalDate expirationDate = provision.getExpirationDate();
return expirationDate != null && !expirationDate.isBefore(now);
})
.collect(Collectors.toList());
}
return provisionProfiles;
}

private static List<ProvisionProfile> retrieveAllProvisionProfiles() {
Path provisionPath = Paths.get(System.getProperty("user.home"), "Library", "MobileDevice", "Provisioning Profiles");
private static List<ProvisionProfile> getProvisioningProfiles() {
// Starting Xcode 16+:
Path provisionPath = Paths.get(System.getProperty("user.home"), "Library", "Developer", "Xcode", "UserData", "Provisioning Profiles");
List<ProvisionProfile> provisions = new ArrayList<>(retrieveAllProvisionProfilesFromPath(provisionPath));
// Before Xcode 16:
provisionPath = Paths.get(System.getProperty("user.home"), "Library", "MobileDevice", "Provisioning Profiles");
provisions.addAll(retrieveAllProvisionProfilesFromPath(provisionPath));
return provisions;
}

private static List<ProvisionProfile> retrieveAllProvisionProfilesFromPath(Path provisionPath) {
if (!Files.exists(provisionPath) || !Files.isDirectory(provisionPath)) {
Logger.logSevere("Invalid provisioning profiles folder at " + provisionPath.toString());
return Collections.emptyList();
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/gluonhq/substrate/IOSTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2021, Gluon
* Copyright (c) 2019, 2024, Gluon
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -97,7 +97,7 @@ void testSigning() {
@Test
void testProvisioning() {
assumeTrue(!isCI());
List<MobileProvision> provisions = CodeSigning.retrieveAllMobileProvisions();
List<MobileProvision> provisions = CodeSigning.getProvisioningProfiles();
assertNotNull(provisions);
assertFalse(provisions.isEmpty());
}
Expand Down
Loading