mirror of
https://github.com/actions/setup-java.git
synced 2026-08-28 20:02:57 +00:00
Add Maven dependency-resolution repositories (#1240)
* Add Maven dependency repositories Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 8897ad63-2d05-4a6d-8ccd-c1155348b59e * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Copilot-Session: 8897ad63-2d05-4a6d-8ccd-c1155348b59e
This commit is contained in:
+171
-18
@@ -15,8 +15,22 @@ export interface MavenServerCredentials {
|
||||
passwordEnvVar: string;
|
||||
}
|
||||
|
||||
export interface MavenRepository {
|
||||
id: string;
|
||||
url: string;
|
||||
snapshotsEnabled: boolean;
|
||||
releasesEnabled?: boolean;
|
||||
}
|
||||
|
||||
export interface MavenRepositorySettings {
|
||||
repositories: MavenRepository[];
|
||||
includeCentral: boolean;
|
||||
prioritizeCentral: boolean;
|
||||
}
|
||||
|
||||
export async function configureAuthentication() {
|
||||
const servers = getMavenServerSettings();
|
||||
const repositorySettings = getMavenRepositorySettings();
|
||||
const settingsDirectory =
|
||||
core.getInput(constants.INPUT_SETTINGS_PATH) ||
|
||||
path.join(os.homedir(), constants.M2_DIR);
|
||||
@@ -41,7 +55,8 @@ export async function configureAuthentication() {
|
||||
servers,
|
||||
settingsDirectory,
|
||||
overwriteSettings,
|
||||
gpgPassphraseEnvVar
|
||||
gpgPassphraseEnvVar,
|
||||
repositorySettings
|
||||
);
|
||||
|
||||
if (gpgPrivateKey) {
|
||||
@@ -141,11 +156,93 @@ export function parseMavenServerCredentials(
|
||||
return servers;
|
||||
}
|
||||
|
||||
// only exported for testing purposes
|
||||
export function getMavenRepositorySettings():
|
||||
MavenRepositorySettings | undefined {
|
||||
const entries = core.getMultilineInput(constants.INPUT_MVN_REPOSITORIES);
|
||||
if (!entries.some(entry => entry.trim())) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const includeCentral = getBooleanInput(
|
||||
constants.INPUT_MVN_REPOSITORIES_INCLUDE_CENTRAL,
|
||||
true
|
||||
);
|
||||
return {
|
||||
repositories: parseMavenRepositories(entries, includeCentral),
|
||||
includeCentral,
|
||||
prioritizeCentral: getBooleanInput(
|
||||
constants.INPUT_MVN_REPOSITORIES_PRIORITIZE_CENTRAL,
|
||||
true
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
// only exported for testing purposes
|
||||
export function parseMavenRepositories(
|
||||
entries: string[],
|
||||
includeCentral: boolean
|
||||
): MavenRepository[] {
|
||||
const repositories: MavenRepository[] = [];
|
||||
const repositoryIds = new Set<string>();
|
||||
|
||||
entries.forEach((entry, index) => {
|
||||
if (!entry.trim()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const firstSeparator = entry.indexOf(':');
|
||||
const lastSeparator = entry.lastIndexOf(':');
|
||||
if (firstSeparator <= 0 || lastSeparator <= firstSeparator) {
|
||||
throw new Error(
|
||||
`Invalid mvn-repositories entry at line ${index + 1}. Expected format: repository-id:repository-url:snapshots-enabled`
|
||||
);
|
||||
}
|
||||
|
||||
const id = entry.slice(0, firstSeparator).trim();
|
||||
const url = entry.slice(firstSeparator + 1, lastSeparator).trim();
|
||||
const snapshotsValue = entry
|
||||
.slice(lastSeparator + 1)
|
||||
.trim()
|
||||
.toLowerCase();
|
||||
if (!id || !url || !snapshotsValue) {
|
||||
throw new Error(
|
||||
`Invalid mvn-repositories entry at line ${index + 1}. repository-id, repository URL, and snapshots-enabled are required`
|
||||
);
|
||||
}
|
||||
if (snapshotsValue !== 'true' && snapshotsValue !== 'false') {
|
||||
throw new Error(
|
||||
`Invalid snapshots-enabled value '${snapshotsValue}' in mvn-repositories entry at line ${index + 1}. Expected true or false`
|
||||
);
|
||||
}
|
||||
if (repositoryIds.has(id)) {
|
||||
throw new Error(
|
||||
`Duplicate repository-id '${id}' in mvn-repositories input`
|
||||
);
|
||||
}
|
||||
if (includeCentral && id === constants.MAVEN_CENTRAL_REPOSITORY_ID) {
|
||||
throw new Error(
|
||||
`Repository-id '${constants.MAVEN_CENTRAL_REPOSITORY_ID}' is reserved when ${constants.INPUT_MVN_REPOSITORIES_INCLUDE_CENTRAL} is enabled`
|
||||
);
|
||||
}
|
||||
|
||||
repositoryIds.add(id);
|
||||
repositories.push({
|
||||
id,
|
||||
url,
|
||||
snapshotsEnabled: snapshotsValue === 'true'
|
||||
});
|
||||
});
|
||||
|
||||
return repositories;
|
||||
}
|
||||
|
||||
export async function createAuthenticationSettings(
|
||||
servers: MavenServerCredentials[],
|
||||
settingsDirectory: string,
|
||||
overwriteSettings: boolean,
|
||||
gpgPassphraseEnvVar: string | undefined = undefined
|
||||
gpgPassphraseEnvVar: string | undefined = undefined,
|
||||
repositorySettings: MavenRepositorySettings | undefined = undefined
|
||||
) {
|
||||
core.info(
|
||||
`Creating ${constants.MVN_SETTINGS_FILE} with server-id: ${servers.map(server => server.id).join(', ')}`
|
||||
@@ -155,7 +252,7 @@ export async function createAuthenticationSettings(
|
||||
await io.mkdirP(settingsDirectory);
|
||||
await write(
|
||||
settingsDirectory,
|
||||
generate(servers, gpgPassphraseEnvVar),
|
||||
generate(servers, gpgPassphraseEnvVar, repositorySettings),
|
||||
overwriteSettings
|
||||
);
|
||||
}
|
||||
@@ -163,7 +260,8 @@ export async function createAuthenticationSettings(
|
||||
// only exported for testing purposes
|
||||
export function generate(
|
||||
servers: MavenServerCredentials[],
|
||||
gpgPassphraseEnvVar?: string | undefined
|
||||
gpgPassphraseEnvVar?: string | undefined,
|
||||
repositorySettings?: MavenRepositorySettings | undefined
|
||||
) {
|
||||
// The maven-gpg-plugin reads the passphrase from the environment variable
|
||||
// named by the `gpg.passphraseEnvName` property (default MAVEN_GPG_PASSPHRASE).
|
||||
@@ -194,20 +292,75 @@ export function generate(
|
||||
}
|
||||
lines.push(' </servers>');
|
||||
|
||||
if (includeGpgPassphraseProfile) {
|
||||
lines.push(
|
||||
' <profiles>',
|
||||
' <profile>',
|
||||
` <id>${constants.GPG_PASSPHRASE_PROFILE_ID}</id>`,
|
||||
' <properties>',
|
||||
` <gpg.passphraseEnvName>${escapeXmlText(gpgPassphraseEnvVar)}</gpg.passphraseEnvName>`,
|
||||
' </properties>',
|
||||
' </profile>',
|
||||
' </profiles>',
|
||||
' <activeProfiles>',
|
||||
` <activeProfile>${constants.GPG_PASSPHRASE_PROFILE_ID}</activeProfile>`,
|
||||
' </activeProfiles>'
|
||||
);
|
||||
if (repositorySettings || includeGpgPassphraseProfile) {
|
||||
lines.push(' <profiles>');
|
||||
if (repositorySettings) {
|
||||
const centralRepository: MavenRepository = {
|
||||
id: constants.MAVEN_CENTRAL_REPOSITORY_ID,
|
||||
url: constants.MAVEN_CENTRAL_REPOSITORY_URL,
|
||||
snapshotsEnabled: false
|
||||
};
|
||||
const customCentralConfigured = repositorySettings.repositories.some(
|
||||
repository => repository.id === constants.MAVEN_CENTRAL_REPOSITORY_ID
|
||||
);
|
||||
const repositories = repositorySettings.includeCentral
|
||||
? repositorySettings.prioritizeCentral
|
||||
? [centralRepository, ...repositorySettings.repositories]
|
||||
: [...repositorySettings.repositories, centralRepository]
|
||||
: customCentralConfigured
|
||||
? repositorySettings.repositories
|
||||
: [
|
||||
...repositorySettings.repositories,
|
||||
{...centralRepository, releasesEnabled: false}
|
||||
];
|
||||
|
||||
lines.push(
|
||||
' <profile>',
|
||||
` <id>${constants.MAVEN_REPOSITORIES_PROFILE_ID}</id>`,
|
||||
' <repositories>'
|
||||
);
|
||||
for (const repository of repositories) {
|
||||
lines.push(
|
||||
' <repository>',
|
||||
` <id>${escapeXmlText(repository.id)}</id>`,
|
||||
` <url>${escapeXmlText(repository.url)}</url>`,
|
||||
...(repository.releasesEnabled === undefined
|
||||
? []
|
||||
: [
|
||||
' <releases>',
|
||||
` <enabled>${repository.releasesEnabled}</enabled>`,
|
||||
' </releases>'
|
||||
]),
|
||||
' <snapshots>',
|
||||
` <enabled>${repository.snapshotsEnabled}</enabled>`,
|
||||
' </snapshots>',
|
||||
' </repository>'
|
||||
);
|
||||
}
|
||||
lines.push(' </repositories>', ' </profile>');
|
||||
}
|
||||
if (includeGpgPassphraseProfile) {
|
||||
lines.push(
|
||||
' <profile>',
|
||||
` <id>${constants.GPG_PASSPHRASE_PROFILE_ID}</id>`,
|
||||
' <properties>',
|
||||
` <gpg.passphraseEnvName>${escapeXmlText(gpgPassphraseEnvVar)}</gpg.passphraseEnvName>`,
|
||||
' </properties>',
|
||||
' </profile>'
|
||||
);
|
||||
}
|
||||
lines.push(' </profiles>', ' <activeProfiles>');
|
||||
if (repositorySettings) {
|
||||
lines.push(
|
||||
` <activeProfile>${constants.MAVEN_REPOSITORIES_PROFILE_ID}</activeProfile>`
|
||||
);
|
||||
}
|
||||
if (includeGpgPassphraseProfile) {
|
||||
lines.push(
|
||||
` <activeProfile>${constants.GPG_PASSPHRASE_PROFILE_ID}</activeProfile>`
|
||||
);
|
||||
}
|
||||
lines.push(' </activeProfiles>');
|
||||
}
|
||||
|
||||
lines.push('</settings>');
|
||||
|
||||
Reference in New Issue
Block a user