-
Notifications
You must be signed in to change notification settings - Fork 2.9k
[MNG-5913] Allow defining aliases for existing server configurations in settings.xml #2333
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
base: master
Are you sure you want to change the base?
Changes from 6 commits
aee6788
b248d2d
e96fbd1
81933fe
d634949
feb0392
6abdb32
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -529,6 +529,17 @@ | |
| Extra configuration for the transport layer. | ||
| </description> | ||
| </field> | ||
| <field> | ||
| <name>aliases</name> | ||
| <version>1.3.0+</version> | ||
| <description> | ||
| List of additional server aliases. For each alias, an additional server will be generated by copying the entire configuration, but using a different ID. | ||
| This is useful when the same credentials should be used for multiple servers. </description> | ||
|
||
| <association> | ||
| <type>String</type> | ||
| <multiplicity>*</multiplicity> | ||
| </association> | ||
| </field> | ||
| </fields> | ||
| </class> | ||
| <class> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,9 +29,11 @@ | |
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.stream.Stream; | ||
|
|
||
| import org.apache.maven.building.FileSource; | ||
| import org.apache.maven.building.Source; | ||
| import org.apache.maven.settings.Server; | ||
| import org.apache.maven.settings.Settings; | ||
| import org.apache.maven.settings.TrackableBase; | ||
| import org.apache.maven.settings.io.SettingsParseException; | ||
|
|
@@ -181,6 +183,7 @@ private Settings readSettings( | |
| return new Settings(); | ||
| } | ||
|
|
||
| settings.setServers(serversByIds(settings.getServers())); | ||
| settingsValidator.validate(settings, problems); | ||
|
|
||
| return settings; | ||
|
|
@@ -251,4 +254,18 @@ public Object execute(String expression, Object value) { | |
|
|
||
| return result; | ||
| } | ||
|
|
||
| private List<Server> serversByIds(List<Server> servers) { | ||
| return servers.stream() | ||
| .flatMap(server -> Stream.concat( | ||
slawekjaranowski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Stream.of(server), server.getAliases().stream().map(id -> serverAlias(server, id)))) | ||
| .toList(); | ||
| } | ||
|
|
||
| private Server serverAlias(Server server, String id) { | ||
slawekjaranowski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return new Server(org.apache.maven.api.settings.Server.newBuilder(server.getDelegate(), true) | ||
| .id(id) | ||
| .aliases(List.of()) | ||
| .build()); | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks very ugly. It is the clien't responsibility to traverse the Settings object, no?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is the core of change. Based on additional tag - aliases we create a next server instance in memory on server list.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do remember that Modello allows to add Java code to
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so you propose to override a getServers method directly in modelo?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, correct.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, I will check if it will be easier?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @michael-o
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Share the spot where this is done. Modello made it possible :-(
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There is two templates for generating output from modello files: I see some of code in
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see a way to provide such code in settings.mdo |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
|
|
||
| <!-- | ||
| 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 | ||
|
|
||
| http://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. | ||
| --> | ||
|
|
||
| <settings> | ||
| <localRepository>${user.home}/.m2/repository</localRepository> | ||
| <servers> | ||
| <server> | ||
| <id>server-1</id> | ||
| <username>username1</username> | ||
| <password>password1</password> | ||
| </server> | ||
| <server> | ||
| <id>server-2</id> | ||
| <username>username2</username> | ||
| <password>password2</password> | ||
| </server> | ||
| </servers> | ||
|
|
||
| </settings> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
|
|
||
| <!-- | ||
| 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 | ||
|
|
||
| http://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. | ||
| --> | ||
|
|
||
| <settings> | ||
| <localRepository>${user.home}/.m2/repository</localRepository> | ||
| <servers> | ||
| <server> | ||
| <id>server-1</id> | ||
| <aliases> | ||
| <alias>server-11</alias> | ||
| <alias>server-12</alias> | ||
| </aliases> | ||
| <username>username1</username> | ||
| <password>password1</password> | ||
| </server> | ||
| <server> | ||
| <id>server-2</id> | ||
| <aliases> | ||
| <alias>server-21</alias> | ||
| </aliases> | ||
| <username>username2</username> | ||
| <password>password2</password> | ||
| </server> | ||
| <server> | ||
| <id>server-3</id> | ||
| <username>username3</username> | ||
| <password>password3</password> | ||
| </server> | ||
| </servers> | ||
|
|
||
| </settings> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
|
|
||
| <!-- | ||
| 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 | ||
|
|
||
| http://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. | ||
| --> | ||
|
|
||
| <settings> | ||
| <localRepository>${user.home}/.m2/repository</localRepository> | ||
| <servers> | ||
| <server> | ||
| <id>server-1</id> | ||
| <aliases> | ||
| <alias>server-2</alias> | ||
| </aliases> | ||
| <username>username1</username> | ||
| <password>password1</password> | ||
| </server> | ||
| <server> | ||
| <id>server-2</id> | ||
| <username>username2</username> | ||
| <password>password2</password> | ||
| </server> | ||
| </servers> | ||
|
|
||
| </settings> |
Uh oh!
There was an error while loading. Please reload this page.