This is an automated email from the ASF dual-hosted git repository. jdaugherty pushed a commit to branch wrapper-rewrite in repository https://gitbox.apache.org/repos/asf/grails-core.git
commit 20bba8ef2d7d4383b49288a182b361b0a17e7f53 Author: James Daugherty <jdaughe...@jdresources.net> AuthorDate: Tue May 13 16:10:11 2025 -0400 Support the same repo override that wrapper uses --- .../main/groovy/grails/util/BuildSettings.groovy | 28 ++- .../main/groovy/org/grails/cli/GrailsCli.groovy | 245 +++++++++------------ .../grails/cli/profile/ProfileRepoConfig.groovy | 60 +++++ .../GrailsRepositoryConfiguration.groovy | 41 ++-- 4 files changed, 195 insertions(+), 179 deletions(-) diff --git a/grails-gradle/model/src/main/groovy/grails/util/BuildSettings.groovy b/grails-gradle/model/src/main/groovy/grails/util/BuildSettings.groovy index 8c703e1810..e9811e4dba 100644 --- a/grails-gradle/model/src/main/groovy/grails/util/BuildSettings.groovy +++ b/grails-gradle/model/src/main/groovy/grails/util/BuildSettings.groovy @@ -1,20 +1,18 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * - * https://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package grails.util @@ -218,7 +216,7 @@ class BuildSettings { */ public static final String BUILD_RESOURCES_PATH = "build/resources/main" - public static final File SETTINGS_FILE = new File("${System.getProperty('user.home')}/.grails/settings.groovy") + public static final File SHARED_SETTINGS_FILE = new File("${System.getProperty('user.home')}/.grails/settings.groovy") /** * @return The version of Grails being used diff --git a/grails-shell-cli/src/main/groovy/org/grails/cli/GrailsCli.groovy b/grails-shell-cli/src/main/groovy/org/grails/cli/GrailsCli.groovy index 9ce449100e..7c7eaef17d 100644 --- a/grails-shell-cli/src/main/groovy/org/grails/cli/GrailsCli.groovy +++ b/grails-shell-cli/src/main/groovy/org/grails/cli/GrailsCli.groovy @@ -1,20 +1,18 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * - * https://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.grails.cli @@ -72,7 +70,10 @@ class GrailsCli { private static final int KEYPRESS_ESC = 27 private static final String USAGE_MESSAGE = "create-app [NAME] --profile=web" private static final String PLUGIN_USAGE_MESSAGE = "create-plugin [NAME] --profile=web-plugin" - private final SystemStreamsRedirector originalStreams = SystemStreamsRedirector.original() // store original System.in, System.out and System.err + + // store original System.in, System.out and System.err + private final SystemStreamsRedirector originalStreams = SystemStreamsRedirector.original() + private static ExecutionContext currentExecutionContext = null private static boolean interactiveModeActive @@ -80,12 +81,12 @@ class GrailsCli { private static final NavigableMap SETTINGS_MAP = new NavigableMap() static { - if(BuildSettings.SETTINGS_FILE.exists()) { + if (BuildSettings.SHARED_SETTINGS_FILE.exists()) { try { - SETTINGS_MAP.merge new ConfigSlurper().parse(BuildSettings.SETTINGS_FILE.toURI().toURL()) + SETTINGS_MAP.merge new ConfigSlurper().parse(BuildSettings.SHARED_SETTINGS_FILE.toURI().toURL()) } catch (Throwable e) { e.printStackTrace() - System.err.println("ERROR: Problem loading $BuildSettings.SETTINGS_FILE: ${e.message}") + System.err.println("ERROR: Problem loading $BuildSettings.SHARED_SETTINGS_FILE: ${e.message}") } try { @@ -105,10 +106,7 @@ class GrailsCli { } - - - - SortedAggregateCompleter aggregateCompleter=new SortedAggregateCompleter() + SortedAggregateCompleter aggregateCompleter = new SortedAggregateCompleter() CommandLineParser cliParser = new CommandLineParser() boolean keepRunning = true Boolean ansiEnabled = null @@ -121,22 +119,19 @@ class GrailsCli { List<GrailsRepositoryConfiguration> profileRepositories = [MavenProfileRepository.DEFAULT_REPO] /** - * Obtains a value from USER_HOME/.grails/settings.yml + * Obtains a value from .grails/settings.yml * * @param key the property name to resolve * @param targetType the expected type of the property value * @param defaultValue The default value */ - public static <T> T getSetting(String key, Class<T> targetType = Object.class, T defaultValue = null) { + static <T> T getSetting(String key, Class<T> targetType = Object.class, T defaultValue = null) { def value = SETTINGS_MAP.get(key, defaultValue) - if(value == null) { + if (value == null) { return null - } - - else if(targetType.isInstance(value)) { - return (T)value - } - else { + } else if (targetType.isInstance(value)) { + return (T) value + } else { try { return value.asType(targetType) } catch (Throwable e) { @@ -149,19 +144,18 @@ class GrailsCli { * * @param args The arguments */ - public static void main(String[] args) { - - Authenticator.setDefault( getSetting( BuildSettings.AUTHENTICATOR, Authenticator, new SystemPropertiesAuthenticator() ) ) + static void main(String[] args) { + Authenticator.setDefault(getSetting(BuildSettings.AUTHENTICATOR, Authenticator, new SystemPropertiesAuthenticator())) def proxySelector = getSetting(BuildSettings.PROXY_SELECTOR, ProxySelector) - if(proxySelector != null) { - ProxySelector.setDefault( proxySelector ) + if (proxySelector != null) { + ProxySelector.setDefault(proxySelector) } - GrailsCli cli=new GrailsCli() + GrailsCli cli = new GrailsCli() try { exit(cli.execute(args)) } - catch(BuildCancelledException e) { + catch (BuildCancelledException e) { GrailsConsole.instance.addStatus("Build stopped.") exit(0) } @@ -198,18 +192,18 @@ class GrailsCli { * @param args The arguments * @return The exit status code */ - public int execute(String... args) { - CommandLine mainCommandLine=cliParser.parse(args) + int execute(String... args) { + CommandLine mainCommandLine = cliParser.parse(args) - if(mainCommandLine.hasOption(CommandLine.VERBOSE_ARGUMENT)) { + if (mainCommandLine.hasOption(CommandLine.VERBOSE_ARGUMENT)) { System.setProperty("grails.verbose", "true") System.setProperty("grails.full.stacktrace", "true") } - if(mainCommandLine.hasOption(CommandLine.STACKTRACE_ARGUMENT)) { + if (mainCommandLine.hasOption(CommandLine.STACKTRACE_ARGUMENT)) { System.setProperty("grails.show.stacktrace", "true") } - if(mainCommandLine.hasOption(CommandLine.VERSION_ARGUMENT) || mainCommandLine.hasOption('v')) { + if (mainCommandLine.hasOption(CommandLine.VERSION_ARGUMENT) || mainCommandLine.hasOption('v')) { def console = GrailsConsole.instance console.addStatus("Grails Version: ${GrailsCli.getPackage().implementationVersion}") console.addStatus("JVM Version: ${System.getProperty('java.version')}") @@ -217,27 +211,26 @@ class GrailsCli { } - - if(mainCommandLine.hasOption(CommandLine.HELP_ARGUMENT) || mainCommandLine.hasOption('h')) { + if (mainCommandLine.hasOption(CommandLine.HELP_ARGUMENT) || mainCommandLine.hasOption('h')) { profileRepository = createMavenProfileRepository() def cmd = CommandRegistry.getCommand("help", profileRepository) cmd.handle(createExecutionContext(mainCommandLine)) exit(0) } - if(mainCommandLine.environmentSet) { + if (mainCommandLine.environmentSet) { System.setProperty(Environment.KEY, mainCommandLine.environment) Environment.reset() } - File grailsAppDir=new File("grails-app") - File applicationGroovy =new File("Application.groovy") - File profileYml =new File("profile.yml") - if(!grailsAppDir.isDirectory() && !applicationGroovy.exists() && !profileYml.exists()) { + File grailsAppDir = new File("grails-app") + File applicationGroovy = new File("Application.groovy") + File profileYml = new File("profile.yml") + if (!grailsAppDir.isDirectory() && !applicationGroovy.exists() && !profileYml.exists()) { profileRepository = createMavenProfileRepository() - if(!mainCommandLine || !mainCommandLine.commandName) { + if (!mainCommandLine || !mainCommandLine.commandName) { integrateGradle = false - def console = GrailsConsole.getInstance() + def console = GrailsConsole.getInstance() // force resolve of all profiles profileRepository.getAllProfiles() def commandNames = CommandRegistry.findCommands(profileRepository).collect() { Command cmd -> cmd.name } @@ -248,29 +241,27 @@ class GrailsCli { def cl = context.commandLine def name = cl.commandName def cmd = CommandRegistry.getCommand(name, profileRepository) - if(cmd != null) { + if (cmd != null) { return executeCommandWithArgumentValidation(cmd, cl) - } - else { + } else { console.error("Command not found [$name]") return false } - } ] as Profile + }] as Profile startInteractiveMode(console) return 0 } def cmd = CommandRegistry.getCommand(mainCommandLine.commandName, profileRepository) - if(cmd) { + if (cmd) { return executeCommandWithArgumentValidation(cmd, mainCommandLine) ? 0 : 1 - } - else { + } else { return getBaseUsage() } } else { initializeApplication(mainCommandLine) - if(mainCommandLine.commandName) { + if (mainCommandLine.commandName) { return handleCommand(mainCommandLine) ? 0 : 1 } else { handleInteractiveMode() @@ -310,27 +301,11 @@ class GrailsCli { } protected MavenProfileRepository createMavenProfileRepository() { - def profileRepos = getSetting(BuildSettings.PROFILE_REPOSITORIES, Map.class, Collections.emptyMap()) - if(!profileRepos.isEmpty()) { + List<ProfileRepoConfig> profileRepoOverrides = ProfileRepoConfig.getConfiguredRepositories() + if (profileRepoOverrides) { profileRepositories.clear() - for (repoName in profileRepos.keySet()) { - def data = profileRepos.get(repoName) - if(data instanceof Map) { - def uri = data.get("url") - def snapshots = data.get('snapshotsEnabled') - if(uri != null) { - boolean enableSnapshots = snapshots != null ? Boolean.valueOf(snapshots.toString()) : false - GrailsRepositoryConfiguration repositoryConfiguration - final String username = data.get('username') - final String password = data.get('password') - if (username != null && password != null) { - repositoryConfiguration = new GrailsRepositoryConfiguration(repoName.toString(), new URI(uri.toString()), enableSnapshots, username, password) - } else { - repositoryConfiguration = new GrailsRepositoryConfiguration(repoName.toString(), new URI(uri.toString()), enableSnapshots) - } - profileRepositories.add(repositoryConfiguration) - } - } + for (ProfileRepoConfig override : profileRepoOverrides) { + profileRepositories.add(new GrailsRepositoryConfiguration(override.name, new URI(override.url), override.snapshots, override.username, override.password)) } } return new MavenProfileRepository(profileRepositories) @@ -347,15 +322,15 @@ class GrailsCli { ExecutionContext createExecutionContext(CommandLine commandLine) { new ExecutionContextImpl(commandLine, projectContext) } - - Boolean handleCommand( CommandLine commandLine ) { + + Boolean handleCommand(CommandLine commandLine) { handleCommand(createExecutionContext(commandLine)) } - - Boolean handleCommand( ExecutionContext context ) { + + Boolean handleCommand(ExecutionContext context) { def console = GrailsConsole.getInstance() - synchronized(GrailsCli) { + synchronized (GrailsCli) { try { currentExecutionContext = context if (handleBuiltInCommands(context)) { @@ -363,22 +338,21 @@ class GrailsCli { } def mainCommandLine = context.getCommandLine() - if(mainCommandLine.hasOption(CommandLine.STACKTRACE_ARGUMENT)) { + if (mainCommandLine.hasOption(CommandLine.STACKTRACE_ARGUMENT)) { console.setStacktrace(true); } else { console.setStacktrace(false); } - if(mainCommandLine.hasOption(CommandLine.VERBOSE_ARGUMENT)) { + if (mainCommandLine.hasOption(CommandLine.VERBOSE_ARGUMENT)) { System.setProperty("grails.verbose", "true") System.setProperty("grails.full.stacktrace", "true") - } - else { + } else { System.setProperty("grails.verbose", "false") System.setProperty("grails.full.stacktrace", "false") } if (profile.handleCommand(context)) { - if(tiggerAppLoad) { + if (tiggerAppLoad) { console.updateStatus("Initializing application. Please wait...") try { initializeApplication(context.commandLine) @@ -391,7 +365,7 @@ class GrailsCli { } return false } - catch(Throwable e) { + catch (Throwable e) { console.error("Command [${context.commandLine.commandName}] error: ${e.message}", e) return false } finally { @@ -436,29 +410,29 @@ class GrailsCli { } private void interactiveModeLoop(GrailsConsole console, ExecutorService commandExecutor) { - NonBlockingInputStream nonBlockingInput = (NonBlockingInputStream)console.reader.getInput() + NonBlockingInputStream nonBlockingInput = (NonBlockingInputStream) console.reader.getInput() interactiveModeActive = true boolean firstRun = true - while(keepRunning) { + while (keepRunning) { try { - if(firstRun) { + if (firstRun) { console.addStatus("Enter a command name to run. Use TAB for completion:") firstRun = false } String commandLine = console.showPrompt() - if(commandLine==null) { + if (commandLine == null) { // CTRL-D was pressed, exit interactive mode exitInteractiveMode() } else if (commandLine.trim()) { - if(nonBlockingInput.isNonBlockingEnabled()) { + if (nonBlockingInput.isNonBlockingEnabled()) { handleCommandWithCancellationSupport(console, commandLine, commandExecutor, nonBlockingInput) } else { - handleCommand( cliParser.parseString(commandLine)) + handleCommand(cliParser.parseString(commandLine)) } } } catch (BuildCancelledException cancelledException) { console.updateStatus("Build stopped.") - }catch (UserInterruptException e) { + } catch (UserInterruptException e) { exitInteractiveMode() } catch (Throwable e) { console.error "Caught exception ${e.message}", e @@ -467,20 +441,20 @@ class GrailsCli { } private Boolean handleCommandWithCancellationSupport(GrailsConsole console, String commandLine, ExecutorService commandExecutor, NonBlockingInputStream nonBlockingInput) { - ExecutionContext executionContext = createExecutionContext( cliParser.parseString(commandLine)) + ExecutionContext executionContext = createExecutionContext(cliParser.parseString(commandLine)) Future<?> commandFuture = commandExecutor.submit({ handleCommand(executionContext) } as Callable<Boolean>) def terminal = console.reader.terminal if (terminal instanceof UnixTerminal) { ((UnixTerminal) terminal).disableInterruptCharacter() } try { - while(!commandFuture.done) { - if(nonBlockingInput.nonBlockingEnabled) { + while (!commandFuture.done) { + if (nonBlockingInput.nonBlockingEnabled) { int peeked = nonBlockingInput.peek(100L) - if(peeked > 0) { + if (peeked > 0) { // read peeked character from buffer nonBlockingInput.read(1L) - if(peeked == KEYPRESS_CTRL_C || peeked == KEYPRESS_ESC) { + if (peeked == KEYPRESS_CTRL_C || peeked == KEYPRESS_ESC) { executionContext.console.log(' ') executionContext.console.updateStatus("Stopping build. Please wait...") executionContext.cancel() @@ -493,7 +467,7 @@ class GrailsCli { ((UnixTerminal) terminal).enableInterruptCharacter() } } - if(!commandFuture.isCancelled()) { + if (!commandFuture.isCancelled()) { try { return commandFuture.get() } catch (ExecutionException e) { @@ -512,14 +486,14 @@ class GrailsCli { String profileName = applicationConfig.get(BuildSettings.PROFILE) ?: getSetting(BuildSettings.PROFILE, String, DEFAULT_PROFILE_NAME) this.profile = profileRepository.getProfile(profileName) - if(profile == null) { + if (profile == null) { throw new IllegalStateException("No profile found for name [$profileName].") } } protected void populateContextLoader() { try { - if(new File(BuildSettings.BASE_DIR, "build.gradle").exists()) { + if (new File(BuildSettings.BASE_DIR, "build.gradle").exists()) { def dependencyMap = new MapReadingCachedGradleOperation<List<URL>>(projectContext, ".dependencies") { @Override @@ -529,10 +503,9 @@ class GrailsCli { @Override List<URL> createMapValue(Object value) { - if(value instanceof List) { - return ((List)value).collect() { new URL(it.toString()) } as List<URL> - } - else { + if (value instanceof List) { + return ((List) value).collect() { new URL(it.toString()) } as List<URL> + } else { return [] } } @@ -544,29 +517,29 @@ class GrailsCli { BuildActionExecuter buildActionExecuter = connection.action(new ClasspathBuildAction()) buildActionExecuter.standardOutput = System.out - buildActionExecuter.standardError = System.err + buildActionExecuter.standardError = System.err buildActionExecuter.withArguments("-Dgrails.profile=${config.navigate("grails", "profile")}") def grailsClasspath = buildActionExecuter.run() - if(grailsClasspath.error) { + if (grailsClasspath.error) { GrailsConsole.instance.error("${grailsClasspath.error} Type 'gradle dependencies' for more information") exit 1 } return [ - dependencies: grailsClasspath.dependencies, - profiles: grailsClasspath.profileDependencies + dependencies: grailsClasspath.dependencies, + profiles : grailsClasspath.profileDependencies ] } }.call() - def urls = (List<URL>)dependencyMap.get("dependencies") + def urls = (List<URL>) dependencyMap.get("dependencies") try { // add tools.jar urls.add(new File("${System.getenv('JAVA_HOME')}/lib/tools.jar").toURI().toURL()) } catch (Throwable e) { // ignore } - def profiles = (List<URL>)dependencyMap.get("profiles") + def profiles = (List<URL>) dependencyMap.get("profiles") URLClassLoader classLoader = new URLClassLoader(urls as URL[], Thread.currentThread().contextClassLoader) this.profileRepository = new StaticJarProfileRepository(classLoader, profiles as URL[]) Thread.currentThread().contextClassLoader = classLoader @@ -583,10 +556,10 @@ class GrailsCli { CodeGenConfig config = new CodeGenConfig() File applicationYml = new File("grails-app/conf/application.yml") File applicationGroovy = new File("grails-app/conf/application.groovy") - if(applicationYml.exists()) { + if (applicationYml.exists()) { config.loadYml(applicationYml) } - if(applicationGroovy.exists()) { + if (applicationGroovy.exists()) { config.loadGroovy(applicationGroovy) } config @@ -596,11 +569,10 @@ class GrailsCli { CommandLine commandLine = context.commandLine def commandName = commandLine.commandName - if(commandName && commandName.size()>1 && commandName.startsWith('!')) { + if (commandName && commandName.size() > 1 && commandName.startsWith('!')) { return executeProcess(context, commandLine.rawArguments) - } - else { - switch(commandName) { + } else { + switch (commandName) { case '!': return bang(context) case 'exit': @@ -652,8 +624,7 @@ class GrailsCli { String historicalCommand = history.current() if (historicalCommand.startsWith("!")) { console.error "Can not repeat command: $historicalCommand" - } - else { + } else { return handleCommand(cliParser.parseString(historicalCommand)) } return false @@ -671,7 +642,8 @@ class GrailsCli { static class ExecutionContextImpl implements ExecutionContext { CommandLine commandLine - @Delegate(excludes = ['getConsole', 'getBaseDir']) ProjectContext projectContext + @Delegate(excludes = ['getConsole', 'getBaseDir']) + ProjectContext projectContext GrailsConsole console = GrailsConsole.getInstance() ExecutionContextImpl(CodeGenConfig config) { @@ -681,21 +653,22 @@ class GrailsCli { ExecutionContextImpl(CommandLine commandLine, ProjectContext projectContext) { this.commandLine = commandLine this.projectContext = projectContext - if(projectContext?.console) { + if (projectContext?.console) { console = projectContext.console } } - private List<CommandCancellationListener> cancelListeners=[] - - @Override //Fully qualified name to work around Groovy bug + private List<CommandCancellationListener> cancelListeners = [] + + @Override + //Fully qualified name to work around Groovy bug void addCancelledListener(org.grails.cli.profile.CommandCancellationListener listener) { cancelListeners << listener - } - + } + @Override void cancel() { - for(CommandCancellationListener listener : cancelListeners) { + for (CommandCancellationListener listener : cancelListeners) { try { listener.commandCancelled() } catch (Exception e) { @@ -709,7 +682,7 @@ class GrailsCli { this.projectContext?.baseDir ?: new File(".") } } - + @Canonical private static class ProjectContextImpl implements ProjectContext { GrailsConsole console = GrailsConsole.getInstance() @@ -717,7 +690,7 @@ class GrailsCli { CodeGenConfig grailsConfig @Override - public String navigateConfig(String... path) { + String navigateConfig(String... path) { grailsConfig.navigate(path) } @@ -727,8 +700,8 @@ class GrailsCli { } @Override - public <T> T navigateConfigForType(Class<T> requiredType, String... path) { + <T> T navigateConfigForType(Class<T> requiredType, String... path) { grailsConfig.navigate(requiredType, path) - } + } } } diff --git a/grails-shell-cli/src/main/groovy/org/grails/cli/profile/ProfileRepoConfig.groovy b/grails-shell-cli/src/main/groovy/org/grails/cli/profile/ProfileRepoConfig.groovy new file mode 100644 index 0000000000..36a5708456 --- /dev/null +++ b/grails-shell-cli/src/main/groovy/org/grails/cli/profile/ProfileRepoConfig.groovy @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.grails.cli.profile + +import grails.util.BuildSettings +import grails.util.Environment +import org.grails.cli.GrailsCli + +class ProfileRepoConfig { + String name + String url + boolean snapshots + + String username + String password + + static List<ProfileRepoConfig> getConfiguredRepositories() { + List<ProfileRepoConfig> repos = [] + + // If there is manual configuration, honor it + Map profileRepos = GrailsCli.getSetting(BuildSettings.PROFILE_REPOSITORIES, Map.class, Collections.emptyMap()) + if (profileRepos) { + for (repoName in profileRepos.keySet()) { + def data = profileRepos.get(repoName) + if (data instanceof Map) { + def uri = data.get("url") + def snapshots = data.get('snapshotsEnabled') + if (uri != null) { + boolean enableSnapshots = snapshots != null ? Boolean.valueOf(snapshots.toString()) : false + final String username = data.get('username') as String + final String password = data.get('password') as String + repos << new ProfileRepoConfig(name: repoName as String, url: uri as String, snapshots: enableSnapshots, username: username as String, password: password as String) + } + } + } + } + + // If the repo url from the wrapper is set, then the wrapper has been configured for a local install, so honor it as a valid source + String repoUrl = System.getProperty("grails.repo.url") ?: System.getenv('GRAILS_REPO_URL') + if (repoUrl) { + repos << new ProfileRepoConfig(name: "grails-override-repo", url: repoUrl, snapshots: Environment.grailsVersion.endsWith("SNAPSHOT")) + } + + repos + } +} diff --git a/grails-shell-cli/src/main/groovy/org/grails/cli/profile/repository/GrailsRepositoryConfiguration.groovy b/grails-shell-cli/src/main/groovy/org/grails/cli/profile/repository/GrailsRepositoryConfiguration.groovy index 133a7b045f..53c28725f9 100644 --- a/grails-shell-cli/src/main/groovy/org/grails/cli/profile/repository/GrailsRepositoryConfiguration.groovy +++ b/grails-shell-cli/src/main/groovy/org/grails/cli/profile/repository/GrailsRepositoryConfiguration.groovy @@ -1,20 +1,18 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * - * https://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.grails.cli.profile.repository @@ -39,19 +37,6 @@ class GrailsRepositoryConfiguration { final String username final String password - /** - * Creates a new {@code GrailsRepositoryConfiguration} instance. - * @param name The name of the repository - * @param uri The uri of the repository - * @param snapshotsEnabled {@code true} if the repository should enable access to snapshots, {@code false} otherwise - */ - public GrailsRepositoryConfiguration(String name, URI uri, boolean snapshotsEnabled) { - this.name = name - this.uri = uri - this.snapshotsEnabled = snapshotsEnabled - } - - /** * Creates a new {@code GrailsRepositoryConfiguration} instance. * @param name The name of the repository @@ -60,7 +45,7 @@ class GrailsRepositoryConfiguration { * @param username The username needed to authenticate with the repository * @param password The password needed to authenticate with the repository */ - public GrailsRepositoryConfiguration(String name, URI uri, boolean snapshotsEnabled, String username, String password) { + GrailsRepositoryConfiguration(String name, URI uri, boolean snapshotsEnabled, String username = null, String password = null) { this.name = name this.uri = uri this.snapshotsEnabled = snapshotsEnabled