Skip to content
This repository has been archived by the owner on Jan 2, 2025. It is now read-only.

Commit

Permalink
Add support for proxies (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
zteater authored Oct 1, 2021
1 parent c347ddc commit 70088ab
Show file tree
Hide file tree
Showing 28 changed files with 298 additions and 3,013 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,13 @@ jobs:
output_file: custom.xml
- run: |
cat custom.xml
- uses: actions/setup-java@v1.4.3
- uses: actions/setup-java@v2.3.1
with:
java-version: 11
distribution: 'adopt'
- run: |
cd test/maven;
./mvnw -s /home/runner/work/maven-settings-xml-action/maven-settings-xml-action/custom.xml clean test
./mvnw -s ../../custom.xml clean test
test-env-filepath:
runs-on: ubuntu-latest
Expand All @@ -150,9 +151,10 @@ jobs:
output_file: $GITHUB_WORKSPACE/custom.xml
- run: |
cat $GITHUB_WORKSPACE/custom.xml
- uses: actions/setup-java@v1.4.3
- uses: actions/setup-java@v2.3.1
with:
java-version: 11
distribution: 'adopt'
- run: |
cd test/maven;
./mvnw -s $GITHUB_WORKSPACE/custom.xml clean test
40 changes: 39 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Github Action to create maven settings (`~/.m2/settings.xml`).

Supports `<servers>`, `<repositories>`, `<pluginRepositories>`, `<pluginGroups>`, `<mirrors>`, `<activeProfiles>`, and `<profiles>`.
Supports `<servers>`, `<repositories>`, `<pluginRepositories>`, `<pluginGroups>`, `<mirrors>`, `<activeProfiles>`, `<proxies>`, and `<profiles>`.

## Inputs

Expand Down Expand Up @@ -85,6 +85,18 @@ Set of `activeProfile` elements, which each have a value of a `profile` `id`. An

Reference: [Maven Settings > Active Profiles](https://maven.apache.org/settings.html#Active_Profiles)

### `proxies`

**Optional** json array of proxies to add to settings.xml.
* **id** - The unique identifier for this proxy. This is used to differentiate between proxy elements.
* **active** - true if this proxy is active. This is useful for declaring a set of proxies, but only one may be active at a time.
* **protocol, host, port** - The protocol://host:port of the proxy, separated into discrete elements.
* **username, password** - These elements appear as a pair denoting the login and password required to authenticate to this proxy server.
* **nonProxyHosts** - This is a list of hosts which should not be proxied. The delimiter of the list is the expected type of the proxy server; the example above is pipe delimited - comma delimited is also common.


Reference: [Maven Settings > Proxies](https://maven.apache.org/settings.html#proxies)

### `output_file`
**Optional** String path of to generate `settings.xml`. By default, `~/.m2/settings.xml` is used.

Expand Down Expand Up @@ -227,6 +239,19 @@ The generated `settings.xml` will be created at `/home/runner/work/{repo}/foo/cu
"some.plugin.group.id",
"some.other.plugin.group.id"
]
proxies: >
[
{
"id": "foo-proxy",
"active": "true",
"protocol": "http",
"host": "https://proxy.example.com",
"port": "443",
"username": "foo",
"password": "bar",
"nonProxyHosts": "noproxy1.example.com|noproxy2.example.com"
}
]
active_profiles: >
[
"some-profile"
Expand Down Expand Up @@ -318,6 +343,19 @@ The generated `settings.xml` will be created at `/home/runner/work/{repo}/foo/cu
<pluginGroup>some.plugin.group.id</pluginGroup>
<pluginGroup>some.other.plugin.group.id</pluginGroup>
</pluginGroups>

<proxies>
<proxy>
<id>foo-proxy</id>
<active>true</active>
<protocol>http</protocol>
<host>https://proxy.example.com</host>
<port>443</port>
<username>foo</username>
<password>bar</password>
<nonProxyHosts>noproxy1.example.com|noproxy2.example.com</nonProxyHosts>
</proxy>
</proxies>

</settings>
````
Expand Down
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ inputs:
required: false
active_profiles:
description: 'json array of profile ids to add to settings.xml'
proxies:
description: 'json array of proxies to add to settings.xml'
output_file:
description: 'path to generated file, default is .m2/settings.xml'
runs:
Expand Down
31 changes: 30 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3527,6 +3527,7 @@ function update(templateXml) {
this.updatePluginRepositories(templateXml);
this.updateProfiles(templateXml)
this.updatePluginGroups(templateXml)
this.updateProxies(templateXml)
}

function updateActiveProfiles(templateXml) {
Expand Down Expand Up @@ -3750,6 +3751,33 @@ function updatePluginGroups(templateXml) {

}

function updateProxies(templateXml) {
var proxiesInput = core.getInput('proxies');

if (!proxiesInput) {
return;
}

var proxiesXml = templateXml.getElementsByTagName('proxies')[0];

JSON.parse(proxiesInput).forEach((proxyInput) => {
var proxyXml = templateXml.createElement('proxy');
for (var key in proxyInput) {
var keyXml = templateXml.createElement(key);

// convert all json content as xml
var value = objectToXml(proxyInput[key]);
var xmlValue = new DOMParser().parseFromString(value, 'text/xml');

// append new xml to current node
keyXml.appendChild(xmlValue);
proxyXml.appendChild(keyXml);
}
proxiesXml.appendChild(proxyXml);
});

}

function objectToXml(obj) {
var xml = '';
for (var prop in obj) {
Expand Down Expand Up @@ -3782,7 +3810,8 @@ module.exports = {
updateRepositories,
updatePluginRepositories,
updateProfiles,
updatePluginGroups
updatePluginGroups,
updateProxies
}


Expand Down
4 changes: 3 additions & 1 deletion dist/template/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@

<pluginGroups/>

</settings>
<proxies/>

</settings>
Loading

0 comments on commit 70088ab

Please sign in to comment.