├── template ├── default-active-profile.xml ├── default-repository.xml └── settings.xml ├── dist └── template │ ├── default-active-profile.xml │ ├── default-repository.xml │ └── settings.xml ├── .eslintignore ├── test ├── maven │ ├── .mvn │ │ └── wrapper │ │ │ ├── maven-wrapper.jar │ │ │ ├── maven-wrapper.properties │ │ │ └── MavenWrapperDownloader.java │ ├── target │ │ └── classes │ │ │ └── com │ │ │ └── example │ │ │ └── Service.class │ ├── src │ │ ├── main │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── Service.java │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── ServiceTest.java │ ├── pom.xml │ ├── mvnw.cmd │ └── mvnw └── js │ ├── resources │ ├── when-repositories-present.xml │ ├── when-repositories-empty.xml │ ├── when-repositories-missing.xml │ ├── when-repositories-update-policy.xml │ ├── when-proxies-missing.xml │ ├── when-servers-missing.xml │ ├── when-active-profiles-empty.xml │ ├── when-active-profiles-missing.xml │ ├── when-active-profiles-present.xml │ ├── when-plugin-repositories-empty.xml │ ├── when-plugin-repositories-missing.xml │ ├── when-plugin-groups-present.xml │ ├── when-servers-present.xml │ ├── when-servers-with-env-variables.xml │ ├── when-mirrors-present.xml │ ├── when-profiles-present.xml │ ├── when-proxies-present.xml │ ├── when-servers-with-extended-properties.xml │ ├── when-servers-with-extended-configuration.xml │ └── when-plugin-repositories-present.xml │ ├── update-plugin-groups.js │ ├── update-mirrors.js │ ├── update-profiles.js │ ├── update-proxies.js │ ├── update-active-profiles.js │ ├── update-plugin-repositories.js │ ├── update-repositories.js │ └── update-servers.js ├── .github ├── dependabot.yml └── workflows │ ├── codeql-analysis.yml │ └── build.yml ├── .eslintrc.json ├── CONTRIBUTING.md ├── action.yml ├── package.json ├── src ├── index.js └── settings.js ├── .gitignore ├── LICENSE └── README.md /template/default-active-profile.xml: -------------------------------------------------------------------------------- 1 | github -------------------------------------------------------------------------------- /dist/template/default-active-profile.xml: -------------------------------------------------------------------------------- 1 | github -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | test/ 3 | dist/ 4 | node_modules/ 5 | -------------------------------------------------------------------------------- /test/maven/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whelk-io/maven-settings-xml-action/HEAD/test/maven/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /test/maven/target/classes/com/example/Service.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whelk-io/maven-settings-xml-action/HEAD/test/maven/target/classes/com/example/Service.class -------------------------------------------------------------------------------- /test/maven/src/main/java/com/example/Service.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | public class Service { 4 | 5 | public String hello(String name) { 6 | return "Hello " + name; 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /test/maven/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.1/apache-maven-3.8.1-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: github-actions 4 | directory: "/" 5 | target-branch: develop 6 | schedule: 7 | interval: daily 8 | timezone: America/Chicago 9 | open-pull-requests-limit: 10 10 | assignees: 11 | - zteater -------------------------------------------------------------------------------- /template/default-repository.xml: -------------------------------------------------------------------------------- 1 | 2 | central 3 | Maven Central 4 | https://repo1.maven.org/maven2 5 | 6 | true 7 | 8 | 9 | false 10 | 11 | -------------------------------------------------------------------------------- /dist/template/default-repository.xml: -------------------------------------------------------------------------------- 1 | 2 | central 3 | Maven Central 4 | https://repo1.maven.org/maven2 5 | 6 | true 7 | 8 | 9 | false 10 | 11 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": ["mocha"], 3 | "env": { 4 | "commonjs": true, 5 | "es6": true, 6 | "node": true, 7 | "mocha": true 8 | }, 9 | "extends": "eslint:recommended", 10 | "globals": { 11 | "Atomics": "readonly", 12 | "SharedArrayBuffer": "readonly" 13 | }, 14 | "parserOptions": { 15 | "ecmaVersion": 2018 16 | }, 17 | "rules": { 18 | } 19 | } -------------------------------------------------------------------------------- /test/maven/src/test/java/com/example/ServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import static org.junit.jupiter.api.Assertions.assertEquals; 4 | 5 | import org.junit.jupiter.api.BeforeEach; 6 | import org.junit.jupiter.api.Test; 7 | 8 | class ServiceTest { 9 | 10 | Service service; 11 | 12 | @BeforeEach 13 | void setup() { 14 | service = new Service(); 15 | } 16 | 17 | @Test 18 | void nameInput() { 19 | assertEquals("Hello Alan Turing", service.hello("Alan Turing")); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /template/settings.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 9 | 10 | github 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /dist/template/settings.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 9 | 10 | github 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /test/js/resources/when-repositories-present.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | github 7 | 8 | 9 | 10 | 11 | github 12 | 13 | 14 | foo 15 | foo 16 | http://foo.bar 17 | 18 | true 19 | 20 | 21 | true 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to `whelk.io` 2 | 3 | ## Getting Started 4 | 5 | 1) Clone the repository to your local system. 6 | 7 | 1) Build and install in your local with npm: `npm i` 8 | 9 | ## Pull Requests 10 | 11 | 1) Fork the repository to your personal GitHub account. 12 | 13 | 1) Create a feature branch from `develop`. Example: `feature/adding-widget` 14 | 15 | 1) Add unit-tests for new code. 16 | 17 | 1) Update [README.md](readme.md), if necessary. 18 | 19 | 1) Raise a pull request from your feature branch to `develop`. 20 | 21 | ## Bug Reporting 22 | 23 | Report bugs using Github's [issues](https://github.com/whelk-io/maven-settings-xml-action/issues). 24 | 25 | **Write bug reports with detail, background, and sample code** 26 | 27 | - A quick summary and/or background 28 | - Steps to reproduce 29 | - Be specific 30 | - Give sample code if you can 31 | - What you expected would happen 32 | - What actually happens 33 | 34 | ## License 35 | 36 | By contributing, you agree that your contributions will be licensed under its Apache 2.0 License. 37 | -------------------------------------------------------------------------------- /test/js/resources/when-repositories-empty.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | github 7 | 8 | 9 | 10 | 11 | github 12 | 13 | 14 | central 15 | Maven Central 16 | https://repo1.maven.org/maven2 17 | 18 | true 19 | 20 | 21 | false 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /test/js/update-plugin-groups.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var process = require('process'); 3 | var settings = require('../../src/settings') 4 | 5 | describe('validate plugin groups', function () { 6 | 7 | describe('when input present', function () { 8 | it(' should be appended with when input.pluginGroups is present', function () { 9 | // given input 10 | process.env['INPUT_PLUGIN_GROUPS'] = '[ "some.plugin.group.id" ]'; 11 | 12 | // when 13 | var actualXml = settings.getSettingsTemplate(); 14 | settings.update(actualXml); 15 | var actual = settings.formatSettings(actualXml); 16 | 17 | // then 18 | var expectedXml = settings.getTemplate('../test/js/resources/', 'when-plugin-groups-present.xml'); 19 | expected = settings.formatSettings(expectedXml); 20 | assert.equal(actual, expected); 21 | 22 | process.env['INPUT_PLUGIN_GROUPS'] = ''; 23 | }); 24 | }); 25 | 26 | }); 27 | 28 | -------------------------------------------------------------------------------- /test/js/resources/when-repositories-missing.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | github 7 | 8 | 9 | 10 | 11 | github 12 | 13 | 14 | central 15 | Maven Central 16 | https://repo1.maven.org/maven2 17 | 18 | true 19 | 20 | 21 | false 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /test/js/resources/when-repositories-update-policy.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | github 7 | 8 | 9 | 10 | 11 | github 12 | 13 | 14 | foo 15 | foo 16 | http://foo.bar 17 | 18 | true 19 | always 20 | 21 | 22 | true 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /test/js/update-mirrors.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var process = require('process'); 3 | var settings = require('../../src/settings') 4 | 5 | describe('validate mirrors', function () { 6 | 7 | describe('when input present', function () { 8 | it(' should be appended with when input.mirror is present', function () { 9 | // given input 10 | process.env['INPUT_MIRRORS'] = '[{ "id": "nexus", "mirrorOf": "!my-org-snapshots,*", "url": "http://redacted/nexus/content/groups/public" }]'; 11 | 12 | // when 13 | var actualXml = settings.getSettingsTemplate(); 14 | settings.update(actualXml); 15 | var actual = settings.formatSettings(actualXml); 16 | 17 | // then 18 | var expectedXml = settings.getTemplate('../test/js/resources/', 'when-mirrors-present.xml'); 19 | expected = settings.formatSettings(expectedXml); 20 | assert.equal(actual, expected); 21 | 22 | process.env['INPUT_MIRRORS'] = ''; 23 | }); 24 | }); 25 | 26 | }); 27 | 28 | -------------------------------------------------------------------------------- /test/js/update-profiles.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var process = require('process'); 3 | var settings = require('../../src/settings') 4 | 5 | describe('validate profiles', function () { 6 | 7 | describe('when input present', function () { 8 | it(' should be appended with when input.profiles is present', function () { 9 | // given input 10 | process.env['INPUT_PROFILES'] = '[{ "id": "foo.profile", "name": "foo.profile", "properties": { "foo": "property-1", "bar": "property-2"} }]'; 11 | 12 | // when 13 | var actualXml = settings.getSettingsTemplate(); 14 | settings.update(actualXml); 15 | var actual = settings.formatSettings(actualXml); 16 | 17 | // then 18 | var expectedXml = settings.getTemplate('../test/js/resources/', 'when-profiles-present.xml'); 19 | expected = settings.formatSettings(expectedXml); 20 | assert.equal(actual, expected); 21 | 22 | process.env['INPUT_PROFILES'] = ''; 23 | }); 24 | }); 25 | 26 | }); 27 | 28 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: 'Generate settings.xml for Maven Builds' 2 | description: 'Create and customize ~/.m2/settings.xml' 3 | branding: 4 | icon: feather 5 | color: orange 6 | inputs: 7 | servers: 8 | description: 'json array of servers to add to settings.xml' 9 | required: false 10 | mirrors: 11 | description: 'json array of mirrors to add to settings.xml' 12 | required: false 13 | repositories: 14 | description: 'json array of repositories to add to settings.xml' 15 | required: false 16 | plugin_repositories: 17 | description: 'json array of plugin repositories to add to settings.xml' 18 | required: false 19 | profiles: 20 | description: 'json array of profiles to add to settings.xml' 21 | required: false 22 | plugin_groups: 23 | description: 'json array of plugin groups to add to settings.xml' 24 | required: false 25 | active_profiles: 26 | description: 'json array of profile ids to add to settings.xml' 27 | proxies: 28 | description: 'json array of proxies to add to settings.xml' 29 | output_file: 30 | description: 'path to generated file, default is .m2/settings.xml' 31 | runs: 32 | using: 'node20' 33 | main: 'dist/index.js' 34 | -------------------------------------------------------------------------------- /test/js/resources/when-proxies-missing.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | github 7 | 8 | 9 | 10 | 11 | github 12 | 13 | 14 | central 15 | Maven Central 16 | https://repo1.maven.org/maven2 17 | 18 | true 19 | 20 | 21 | false 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /test/js/resources/when-servers-missing.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | github 7 | 8 | 9 | 10 | 11 | github 12 | 13 | 14 | central 15 | Maven Central 16 | https://repo1.maven.org/maven2 17 | 18 | true 19 | 20 | 21 | false 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /test/js/resources/when-active-profiles-empty.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | github 7 | 8 | 9 | 10 | 11 | github 12 | 13 | 14 | central 15 | Maven Central 16 | https://repo1.maven.org/maven2 17 | 18 | true 19 | 20 | 21 | false 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /test/js/resources/when-active-profiles-missing.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | github 7 | 8 | 9 | 10 | 11 | github 12 | 13 | 14 | central 15 | Maven Central 16 | https://repo1.maven.org/maven2 17 | 18 | true 19 | 20 | 21 | false 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /test/js/resources/when-active-profiles-present.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | foo-bar 7 | 8 | 9 | 10 | 11 | github 12 | 13 | 14 | central 15 | Maven Central 16 | https://repo1.maven.org/maven2 17 | 18 | true 19 | 20 | 21 | false 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /test/js/resources/when-plugin-repositories-empty.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | github 7 | 8 | 9 | 10 | 11 | github 12 | 13 | 14 | central 15 | Maven Central 16 | https://repo1.maven.org/maven2 17 | 18 | true 19 | 20 | 21 | false 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /test/js/resources/when-plugin-repositories-missing.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | github 7 | 8 | 9 | 10 | 11 | github 12 | 13 | 14 | central 15 | Maven Central 16 | https://repo1.maven.org/maven2 17 | 18 | true 19 | 20 | 21 | false 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /test/js/resources/when-plugin-groups-present.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | github 7 | 8 | 9 | 10 | 11 | github 12 | 13 | 14 | central 15 | Maven Central 16 | https://repo1.maven.org/maven2 17 | 18 | true 19 | 20 | 21 | false 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | some.plugin.group.id 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /test/maven/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 4.0.0 6 | 7 | com.example 8 | demo 9 | 0.0.1-SNAPSHOT 10 | 11 | 12 | 1.8 13 | 1.8 14 | UTF-8 15 | 16 | 17 | 18 | 19 | org.junit.jupiter 20 | junit-jupiter-engine 21 | 5.7.2 22 | test 23 | 24 | 25 | 26 | 27 | 28 | 29 | org.apache.maven.plugins 30 | maven-surefire-plugin 31 | 2.22.2 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /test/js/resources/when-servers-present.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | github 7 | 8 | 9 | 10 | 11 | github 12 | 13 | 14 | central 15 | Maven Central 16 | https://repo1.maven.org/maven2 17 | 18 | true 19 | 20 | 21 | false 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | foo 32 | fu 33 | bar 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /test/js/resources/when-servers-with-env-variables.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | github 7 | 8 | 9 | 10 | 11 | github 12 | 13 | 14 | central 15 | Maven Central 16 | https://repo1.maven.org/maven2 17 | 18 | true 19 | 20 | 21 | false 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | foo 32 | ${env.USERNAME} 33 | ${env.PASSWORD} 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /test/js/resources/when-mirrors-present.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | github 7 | 8 | 9 | 10 | 11 | github 12 | 13 | 14 | central 15 | Maven Central 16 | https://repo1.maven.org/maven2 17 | 18 | true 19 | 20 | 21 | false 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | nexus 34 | !my-org-snapshots,* 35 | http://redacted/nexus/content/groups/public 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /test/js/resources/when-profiles-present.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | github 7 | 8 | 9 | 10 | 11 | github 12 | 13 | 14 | central 15 | Maven Central 16 | https://repo1.maven.org/maven2 17 | 18 | true 19 | 20 | 21 | false 22 | 23 | 24 | 25 | 26 | 27 | 28 | foo.profile 29 | foo.profile 30 | 31 | property-1 32 | property-2 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "maven-settings-xml-action", 3 | "version": "0.0.18", 4 | "description": "Update maven ~/.m2/settings.xml", 5 | "main": "src/index.js", 6 | "directories": { 7 | "test": "test/js" 8 | }, 9 | "dependencies": { 10 | "@actions/core": "^1.3.0", 11 | "@actions/github": "^5.0.0", 12 | "fs": "0.0.1-security", 13 | "os": "^0.1.1", 14 | "path": "^0.12.7", 15 | "xml-formatter": "^2.4.0", 16 | "@xmldom/xmldom": "^0.8.10" 17 | }, 18 | "devDependencies": { 19 | "@zeit/ncc": "^0.20.5", 20 | "eslint": "^7.3.0", 21 | "eslint-plugin-mocha": "^10.2.0", 22 | "mocha": "^10.2.0", 23 | "mocha-eslint": "^6.0.0" 24 | }, 25 | "scripts": { 26 | "lint": "eslint ./src/*.js", 27 | "test": "mocha test/js", 28 | "build_index": "ncc build src/index.js -o dist ", 29 | "copy_templates": "rm -rf dist/template && mkdir dist/template && cp -a template/. dist/template/", 30 | "build": "npm run build_index && npm run copy_templates" 31 | }, 32 | "engines": { 33 | "node": "16.x" 34 | }, 35 | "repository": { 36 | "type": "git", 37 | "url": "https://github.com/whelk-io/maven-settings-xml-action.git" 38 | }, 39 | "author": { 40 | "name": "Zack Teater", 41 | "url": "http://whelk.io" 42 | }, 43 | "license": "Apache-2.0", 44 | "bugs": { 45 | "url": "https://github.com/whelk-io/maven-settings-xml-action/issues" 46 | }, 47 | "homepage": "https://github.com/whelk-io/maven-settings-xml-action#readme", 48 | "contributors": [ 49 | { 50 | "name": "Jason Edstrom", 51 | "email": "jason@instacode.io" 52 | } 53 | ] 54 | } -------------------------------------------------------------------------------- /test/js/resources/when-proxies-present.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | github 7 | 8 | 9 | 10 | 11 | github 12 | 13 | 14 | central 15 | Maven Central 16 | https://repo1.maven.org/maven2 17 | 18 | true 19 | 20 | 21 | false 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | foo 38 | true 39 | http 40 | https://proxy.example.com 41 | 443 42 | foo 43 | bar 44 | noproxy1.example.com|noproxy2.example.com 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /test/js/resources/when-servers-with-extended-properties.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | github 7 | 8 | 9 | 10 | 11 | github 12 | 13 | 14 | central 15 | Maven Central 16 | https://repo1.maven.org/maven2 17 | 18 | true 19 | 20 | 21 | false 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | foo 32 | fu 33 | bar 34 | ${user.home}/.ssh/id_dsa 35 | some_passphrase 36 | 664 37 | 775 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /test/js/resources/when-servers-with-extended-configuration.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | github 7 | 8 | 9 | 10 | 11 | github 12 | 13 | 14 | central 15 | Maven Central 16 | https://repo1.maven.org/maven2 17 | 18 | true 19 | 20 | 21 | false 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | foo 32 | fu 33 | bar 34 | 35 | 36 | 37 | true 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /test/js/resources/when-plugin-repositories-present.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | github 7 | 8 | 9 | 10 | 11 | github 12 | 13 | 14 | central 15 | Maven Central 16 | https://repo1.maven.org/maven2 17 | 18 | true 19 | 20 | 21 | false 22 | 23 | 24 | 25 | 26 | 27 | foo.plugin 28 | foo.plugin 29 | http://foo.bar.plugin 30 | 31 | true 32 | 33 | 34 | true 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | var core = require('@actions/core'); 2 | var settings = require('./settings'); 3 | var os = require('os'); 4 | var path = require('path'); 5 | var fs = require('fs'); 6 | 7 | function run() { 8 | try { 9 | // open default template 10 | var templateXml = settings.getSettingsTemplate(); 11 | 12 | // update from action input 13 | settings.update(templateXml); 14 | 15 | // format to xml 16 | var formattedXml = settings.formatSettings(templateXml); 17 | 18 | // get custom output path 19 | var settingsPath = getSettingsPath(); 20 | 21 | // write template to filepath 22 | writeSettings(settingsPath, formattedXml); 23 | 24 | } catch (error) { 25 | core.setFailed(error.message); 26 | } 27 | } 28 | 29 | function getSettingsPath() { 30 | var outputFileInput = core.getInput('output_file'); 31 | 32 | if (!outputFileInput) { 33 | return getDefaultSettingsPath(); 34 | } 35 | 36 | // resolve env variables in path 37 | if (outputFileInput.trim() != '') { 38 | return outputFileInput.trim().replace(/\$([A-Z_]+[A-Z0-9_]*)|\${([A-Z0-9_]*)}/ig, (_, a, b) => process.env[a || b]) 39 | } 40 | 41 | return getDefaultSettingsPath(); 42 | } 43 | 44 | function getDefaultSettingsPath() { 45 | return path.join(os.homedir(), '.m2', 'settings.xml'); 46 | } 47 | 48 | function writeSettings(settingsPath, formattedXml) { 49 | if (!fs.existsSync(path.dirname(settingsPath))) { 50 | core.info("creating directory for settings.xml: " + settingsPath); 51 | fs.mkdirSync(path.dirname(settingsPath)); 52 | } 53 | 54 | core.info("writing settings.xml to path: " + path.resolve(settingsPath)); 55 | fs.writeFileSync(settingsPath, formattedXml); 56 | } 57 | 58 | run(); 59 | 60 | module.exports = { 61 | run, 62 | getSettingsPath, 63 | getDefaultSettingsPath, 64 | writeSettings 65 | } -------------------------------------------------------------------------------- /test/js/update-proxies.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var process = require('process'); 3 | var settings = require('../../src/settings') 4 | 5 | describe('validate proxies', function () { 6 | 7 | describe('when empty input', function () { 8 | it(' should be not be changed when input.proxy is missing', function () { 9 | // given input 10 | process.env['INPUT_PROXIES'] = ''; 11 | 12 | // when 13 | var actualXml = settings.getSettingsTemplate(); 14 | settings.update(actualXml); 15 | var actual = settings.formatSettings(actualXml); 16 | 17 | // then 18 | var expectedXml = settings.getTemplate('../test/js/resources/', 'when-proxies-missing.xml'); 19 | expected = settings.formatSettings(expectedXml); 20 | assert.equal(actual, expected); 21 | 22 | // tear down 23 | process.env['INPUT_PROXIES'] = ''; 24 | }); 25 | }); 26 | 27 | describe('when custom input', function () { 28 | it(' should be appended with when input.proxy is present', function () { 29 | // given input 30 | process.env['INPUT_PROXIES'] = '[{ "id": "foo", "active": "true", "protocol": "http", "host": "https://proxy.example.com", "port": "443", "username": "foo", "password": "bar", "nonProxyHosts": "noproxy1.example.com|noproxy2.example.com" }]'; 31 | 32 | // when 33 | var actualXml = settings.getSettingsTemplate(); 34 | settings.update(actualXml); 35 | var actual = settings.formatSettings(actualXml); 36 | 37 | // then 38 | var expectedXml = settings.getTemplate('../test/js/resources/', 'when-proxies-present.xml'); 39 | expected = settings.formatSettings(expectedXml); 40 | assert.equal(actual, expected); 41 | 42 | // tear down 43 | process.env['INPUT_PROXIES'] = ''; 44 | }); 45 | }); 46 | 47 | }); 48 | 49 | -------------------------------------------------------------------------------- /test/js/update-active-profiles.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var process = require('process'); 3 | var settings = require('../../src/settings') 4 | 5 | describe('validate active profiles', function () { 6 | 7 | describe('when input present', function () { 8 | it(' should be appended with when input.active_profiles is present', function () { 9 | // given input 10 | process.env['INPUT_ACTIVE_PROFILES'] = '[ "foo-bar" ]'; 11 | 12 | // when 13 | var actualXml = settings.getSettingsTemplate(); 14 | settings.update(actualXml); 15 | var actual = settings.formatSettings(actualXml); 16 | 17 | // then 18 | var expectedXml = settings.getTemplate('../test/js/resources/', 'when-active-profiles-present.xml'); 19 | expected = settings.formatSettings(expectedXml); 20 | assert.equal(actual, expected); 21 | 22 | process.env['INPUT_ACTIVE_PROFILES'] = ''; 23 | }); 24 | }); 25 | 26 | describe('when empty input', function () { 27 | it(' should be appended with default when input.active_profiles is empty', function () { 28 | // given input 29 | process.env['INPUT_ACTIVE_PROFILES'] = '[]'; 30 | 31 | // when 32 | var actualXml = settings.getSettingsTemplate(); 33 | settings.update(actualXml); 34 | var actual = settings.formatSettings(actualXml); 35 | 36 | // then 37 | var expectedXml = settings.getTemplate('../test/js/resources/', 'when-active-profiles-empty.xml'); 38 | expected = settings.formatSettings(expectedXml); 39 | assert.equal(actual, expected); 40 | 41 | process.env['INPUT_ACTIVE_PROFILES'] = ''; 42 | }); 43 | }); 44 | 45 | describe('when empty missing', function () { 46 | it(' should be appended with default when input.active_profiles is missing', function () { 47 | // given input 48 | process.env['INPUT_ACTIVE_PROFILES'] = ''; 49 | 50 | // when 51 | var actualXml = settings.getSettingsTemplate(); 52 | settings.update(actualXml); 53 | var actual = settings.formatSettings(actualXml); 54 | 55 | // then 56 | var expectedXml = settings.getTemplate('../test/js/resources/', 'when-active-profiles-missing.xml'); 57 | expected = settings.formatSettings(expectedXml); 58 | assert.equal(actual, expected); 59 | 60 | process.env['INPUT_ACTIVE_PROFILES'] = ''; 61 | }); 62 | }); 63 | 64 | }); 65 | 66 | -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | # 7 | # ******** NOTE ******** 8 | # We have attempted to detect the languages in your repository. Please check 9 | # the `language` matrix defined below to confirm you have the correct set of 10 | # supported CodeQL languages. 11 | # 12 | name: "CodeQL" 13 | 14 | on: 15 | push: 16 | branches: [ main, develop ] 17 | pull_request: 18 | # The branches below must be a subset of the branches above 19 | branches: [ main ] 20 | schedule: 21 | - cron: '15 17 * * 6' 22 | 23 | jobs: 24 | analyze: 25 | name: Analyze 26 | runs-on: ubuntu-latest 27 | permissions: 28 | actions: read 29 | contents: read 30 | security-events: write 31 | 32 | strategy: 33 | fail-fast: false 34 | matrix: 35 | language: [ 'javascript' ] 36 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] 37 | # Learn more: 38 | # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed 39 | 40 | steps: 41 | - name: Checkout repository 42 | uses: actions/checkout@v4 43 | 44 | # Initializes the CodeQL tools for scanning. 45 | - name: Initialize CodeQL 46 | uses: github/codeql-action/init@v3 47 | with: 48 | languages: ${{ matrix.language }} 49 | # If you wish to specify custom queries, you can do so here or in a config file. 50 | # By default, queries listed here will override any specified in a config file. 51 | # Prefix the list here with "+" to use these queries and those in the config file. 52 | # queries: ./path/to/local/query, your-org/your-repo/queries@main 53 | 54 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 55 | # If this step fails, then you should remove it and run the build manually (see below) 56 | - name: Autobuild 57 | uses: github/codeql-action/autobuild@v3 58 | 59 | # ℹ️ Command-line programs to run using the OS shell. 60 | # 📚 https://git.io/JvXDl 61 | 62 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines 63 | # and modify them (or add more) to build your code if your project 64 | # uses a compiled language 65 | 66 | #- run: | 67 | # make bootstrap 68 | # make release 69 | 70 | - name: Perform CodeQL Analysis 71 | uses: github/codeql-action/analyze@v3 72 | -------------------------------------------------------------------------------- /test/js/update-plugin-repositories.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var process = require('process'); 3 | var settings = require('../../src/settings') 4 | 5 | describe('validate plugin repositories', function () { 6 | 7 | describe('when input missing', function () { 8 | it(' should not be appended with when input.pluginRepositories is missing', function () { 9 | // given input 10 | process.env['INPUT_PLUGIN_REPOSITORIES'] = ''; 11 | 12 | // when 13 | var actualXml = settings.getSettingsTemplate(); 14 | settings.update(actualXml); 15 | var actual = settings.formatSettings(actualXml); 16 | 17 | // then 18 | var expectedXml = settings.getTemplate('../test/js/resources/', 'when-plugin-repositories-missing.xml'); 19 | expected = settings.formatSettings(expectedXml); 20 | assert.equal(actual, expected); 21 | 22 | process.env['INPUT_PLUGIN_REPOSITORIES'] = ''; 23 | }); 24 | }); 25 | 26 | describe('when input empty', function () { 27 | it(' should not be appended with when input.pluginRepositories is empty', function () { 28 | // given input 29 | process.env['INPUT_PLUGIN_REPOSITORIES'] = '[]'; 30 | 31 | // when 32 | var actualXml = settings.getSettingsTemplate(); 33 | settings.update(actualXml); 34 | var actual = settings.formatSettings(actualXml); 35 | 36 | // then 37 | var expectedXml = settings.getTemplate('../test/js/resources/', 'when-plugin-repositories-empty.xml'); 38 | expected = settings.formatSettings(expectedXml); 39 | assert.equal(actual, expected); 40 | 41 | process.env['INPUT_PLUGIN_REPOSITORIES'] = ''; 42 | }); 43 | }); 44 | 45 | describe('when input present', function () { 46 | it(' should be appended with when input.pluginRepositories is present', function () { 47 | // given input 48 | process.env['INPUT_PLUGIN_REPOSITORIES'] = '[{ "id": "foo.plugin", "name": "foo.plugin", "url": "http://foo.bar.plugin", "releases": { "enabled": "true" }, "snapshots": { "enabled": "true" } }]'; 49 | 50 | // when 51 | var actualXml = settings.getSettingsTemplate(); 52 | settings.update(actualXml); 53 | var actual = settings.formatSettings(actualXml); 54 | 55 | // then 56 | var expectedXml = settings.getTemplate('../test/js/resources/', 'when-plugin-repositories-present.xml'); 57 | expected = settings.formatSettings(expectedXml); 58 | assert.equal(actual, expected); 59 | 60 | process.env['INPUT_PLUGIN_REPOSITORIES'] = ''; 61 | }); 62 | }); 63 | 64 | }); 65 | 66 | -------------------------------------------------------------------------------- /test/js/update-repositories.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var process = require('process'); 3 | var settings = require('../../src/settings') 4 | 5 | describe('validate repositories', function () { 6 | 7 | describe('when input missing', function () { 8 | it(' should be appended with default when input.repositories is missing', function () { 9 | // given input 10 | process.env['INPUT_REPOSITORIES'] = ''; 11 | 12 | // when 13 | var actualXml = settings.getSettingsTemplate(); 14 | settings.update(actualXml); 15 | var actual = settings.formatSettings(actualXml); 16 | 17 | // then 18 | var expectedXml = settings.getTemplate('../test/js/resources/', 'when-repositories-missing.xml'); 19 | expected = settings.formatSettings(expectedXml); 20 | assert.equal(actual, expected); 21 | 22 | process.env['INPUT_REPOSITORIES'] = ''; 23 | }); 24 | }); 25 | 26 | describe('when input empty', function () { 27 | it(' should be appended with default when input.repositories is empty', function () { 28 | // given input 29 | process.env['INPUT_REPOSITORIES'] = '[]'; 30 | 31 | // when 32 | var actualXml = settings.getSettingsTemplate(); 33 | settings.update(actualXml); 34 | var actual = settings.formatSettings(actualXml); 35 | 36 | // then 37 | var expectedXml = settings.getTemplate('../test/js/resources/', 'when-repositories-missing.xml'); 38 | expected = settings.formatSettings(expectedXml); 39 | assert.equal(actual, expected); 40 | 41 | // tear down 42 | process.env['INPUT_REPOSITORIES'] = ''; 43 | }); 44 | }); 45 | 46 | describe('when input present', function () { 47 | it(' should be appended with when input.repositories is present', function () { 48 | // given input 49 | process.env['INPUT_REPOSITORIES'] = '[{ "id": "foo", "name": "foo", "url": "http://foo.bar", "releases": { "enabled": "true" }, "snapshots": { "enabled": "true" } }]'; 50 | 51 | // when 52 | var actualXml = settings.getSettingsTemplate(); 53 | settings.update(actualXml); 54 | var actual = settings.formatSettings(actualXml); 55 | 56 | // then 57 | var expectedXml = settings.getTemplate('../test/js/resources/', 'when-repositories-present.xml'); 58 | expected = settings.formatSettings(expectedXml); 59 | assert.equal(actual, expected); 60 | 61 | // tear down 62 | process.env['INPUT_REPOSITORIES'] = ''; 63 | }); 64 | }); 65 | 66 | describe('when configuring updatePolicy on repositories', function () { 67 | it(' should be appended with ', function () { 68 | // given input 69 | process.env['INPUT_REPOSITORIES'] = '[{ "id": "foo", "name": "foo", "url": "http://foo.bar", "releases": { "enabled": "true", "updatePolicy": "always" }, "snapshots": { "enabled": "true" } }]'; 70 | 71 | // when 72 | var actualXml = settings.getSettingsTemplate(); 73 | settings.update(actualXml); 74 | var actual = settings.formatSettings(actualXml); 75 | 76 | // then 77 | var expectedXml = settings.getTemplate('../test/js/resources/', 'when-repositories-update-policy.xml'); 78 | expected = settings.formatSettings(expectedXml); 79 | assert.equal(actual, expected); 80 | 81 | process.env['INPUT_REPOSITORIES'] = ''; 82 | }); 83 | }); 84 | 85 | }); 86 | 87 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .project 2 | .classpath 3 | .settings/ 4 | test/maven/target/ 5 | ### JetBrains template 6 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider 7 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 8 | 9 | # User-specific stuff 10 | .idea/**/workspace.xml 11 | .idea/**/tasks.xml 12 | .idea/**/usage.statistics.xml 13 | .idea/**/dictionaries 14 | .idea/**/shelf 15 | 16 | # Generated files 17 | .idea/**/contentModel.xml 18 | 19 | # Sensitive or high-churn files 20 | .idea/**/dataSources/ 21 | .idea/**/dataSources.ids 22 | .idea/**/dataSources.local.xml 23 | .idea/**/sqlDataSources.xml 24 | .idea/**/dynamic.xml 25 | .idea/**/uiDesigner.xml 26 | .idea/**/dbnavigator.xml 27 | 28 | # Gradle 29 | .idea/**/gradle.xml 30 | .idea/**/libraries 31 | 32 | # Gradle and Maven with auto-import 33 | # When using Gradle or Maven with auto-import, you should exclude module files, 34 | # since they will be recreated, and may cause churn. Uncomment if using 35 | # auto-import. 36 | # .idea/artifacts 37 | # .idea/compiler.xml 38 | # .idea/jarRepositories.xml 39 | # .idea/modules.xml 40 | # .idea/*.iml 41 | # .idea/modules 42 | # *.iml 43 | # *.ipr 44 | 45 | # CMake 46 | cmake-build-*/ 47 | 48 | # Mongo Explorer plugin 49 | .idea/**/mongoSettings.xml 50 | 51 | # File-based project format 52 | *.iws 53 | 54 | # IntelliJ 55 | out/ 56 | 57 | # mpeltonen/sbt-idea plugin 58 | .idea_modules/ 59 | 60 | # JIRA plugin 61 | atlassian-ide-plugin.xml 62 | 63 | # Cursive Clojure plugin 64 | .idea/replstate.xml 65 | 66 | # Crashlytics plugin (for Android Studio and IntelliJ) 67 | com_crashlytics_export_strings.xml 68 | crashlytics.properties 69 | crashlytics-build.properties 70 | fabric.properties 71 | 72 | # Editor-based Rest Client 73 | .idea/httpRequests 74 | 75 | # Android studio 3.1+ serialized cache file 76 | .idea/caches/build_file_checksums.ser 77 | 78 | ### Node template 79 | # Logs 80 | logs 81 | *.log 82 | npm-debug.log* 83 | yarn-debug.log* 84 | yarn-error.log* 85 | lerna-debug.log* 86 | 87 | # Diagnostic reports (https://nodejs.org/api/report.html) 88 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 89 | 90 | # Runtime data 91 | pids 92 | *.pid 93 | *.seed 94 | *.pid.lock 95 | 96 | # Directory for instrumented libs generated by jscoverage/JSCover 97 | lib-cov 98 | 99 | # Coverage directory used by tools like istanbul 100 | coverage 101 | *.lcov 102 | 103 | # nyc test coverage 104 | .nyc_output 105 | 106 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 107 | .grunt 108 | 109 | # Bower dependency directory (https://bower.io/) 110 | bower_components 111 | 112 | # node-waf configuration 113 | .lock-wscript 114 | 115 | # Compiled binary addons (https://nodejs.org/api/addons.html) 116 | build/Release 117 | 118 | # Dependency directories 119 | node_modules/ 120 | jspm_packages/ 121 | 122 | # Snowpack dependency directory (https://snowpack.dev/) 123 | web_modules/ 124 | 125 | # TypeScript cache 126 | *.tsbuildinfo 127 | 128 | # Optional npm cache directory 129 | .npm 130 | 131 | # Optional eslint cache 132 | .eslintcache 133 | 134 | # Microbundle cache 135 | .rpt2_cache/ 136 | .rts2_cache_cjs/ 137 | .rts2_cache_es/ 138 | .rts2_cache_umd/ 139 | 140 | # Optional REPL history 141 | .node_repl_history 142 | 143 | # Output of 'npm pack' 144 | *.tgz 145 | 146 | # Yarn Integrity file 147 | .yarn-integrity 148 | 149 | # dotenv environment variables file 150 | .env 151 | .env.test 152 | 153 | # parcel-bundler cache (https://parceljs.org/) 154 | .cache 155 | .parcel-cache 156 | 157 | # Next.js build output 158 | .next 159 | 160 | # Nuxt.js build / generate output 161 | .nuxt 162 | 163 | 164 | # Gatsby files 165 | .cache/ 166 | # Comment in the public line in if your project uses Gatsby and not Next.js 167 | # https://nextjs.org/blog/next-9-1#public-directory-support 168 | # public 169 | 170 | # vuepress build output 171 | .vuepress/dist 172 | 173 | # Serverless directories 174 | .serverless/ 175 | 176 | # FuseBox cache 177 | .fusebox/ 178 | 179 | # DynamoDB Local files 180 | .dynamodb/ 181 | 182 | # TernJS port file 183 | .tern-port 184 | 185 | # Stores VSCode versions used for testing VSCode extensions 186 | .vscode-test 187 | .vscode/ 188 | 189 | # yarn v2 190 | 191 | .yarn/cache 192 | .yarn/unplugged 193 | .yarn/build-state.yml 194 | .pnp.* 195 | .idea 196 | 197 | 198 | -------------------------------------------------------------------------------- /test/js/update-servers.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var process = require('process'); 3 | var settings = require('../../src/settings') 4 | 5 | describe('validate servers', function () { 6 | 7 | describe('when empty input', function () { 8 | it(' should be not be changed when input.server is missing', function () { 9 | // given input 10 | process.env['INPUT_SERVERS'] = ''; 11 | 12 | // when 13 | var actualXml = settings.getSettingsTemplate(); 14 | settings.update(actualXml); 15 | var actual = settings.formatSettings(actualXml); 16 | 17 | // then 18 | var expectedXml = settings.getTemplate('../test/js/resources/', 'when-servers-missing.xml'); 19 | expected = settings.formatSettings(expectedXml); 20 | assert.equal(actual, expected); 21 | 22 | // tear down 23 | process.env['INPUT_SERVERS'] = ''; 24 | }); 25 | }); 26 | 27 | describe('when custom input', function () { 28 | it(' should be appended with when input.server is present', function () { 29 | // given input 30 | process.env['INPUT_SERVERS'] = '[{ "id": "foo", "username": "fu", "password": "bar" }]'; 31 | 32 | // when 33 | var actualXml = settings.getSettingsTemplate(); 34 | settings.update(actualXml); 35 | var actual = settings.formatSettings(actualXml); 36 | 37 | // then 38 | var expectedXml = settings.getTemplate('../test/js/resources/', 'when-servers-present.xml'); 39 | expected = settings.formatSettings(expectedXml); 40 | assert.equal(actual, expected); 41 | 42 | // tear down 43 | process.env['INPUT_SERVERS'] = ''; 44 | }); 45 | }); 46 | 47 | describe('when extended configuration input', function () { 48 | it(' should be appended with when extended configuration is provided', function () { 49 | // given input 50 | process.env['INPUT_SERVERS'] = '[{ "id": "foo", "username": "fu", "password": "bar", "configuration": { "httpConfiguration": { "all" : { "usePreemptive": "true" }}}}]'; 51 | 52 | // when 53 | var actualXml = settings.getSettingsTemplate(); 54 | settings.update(actualXml); 55 | var actual = settings.formatSettings(actualXml); 56 | 57 | // then 58 | var expectedXml = settings.getTemplate('../test/js/resources/', 'when-servers-with-extended-configuration.xml'); 59 | expected = settings.formatSettings(expectedXml); 60 | assert.equal(actual, expected); 61 | 62 | // tear down 63 | process.env['INPUT_SERVERS'] = ''; 64 | }); 65 | }); 66 | 67 | describe('when extended properties input', function () { 68 | it(' should be appended with and include all maven server properties', function () { 69 | // given input 70 | process.env['INPUT_SERVERS'] = '[{ "id": "foo", "username": "fu", "password": "bar", "privateKey": "${user.home}/.ssh/id_dsa", "passphrase": "some_passphrase", "filePermissions": "664", "directoryPermissions": "775" }]'; 71 | 72 | // when 73 | var actualXml = settings.getSettingsTemplate(); 74 | settings.update(actualXml); 75 | var actual = settings.formatSettings(actualXml); 76 | 77 | // then 78 | var expectedXml = settings.getTemplate('../test/js/resources/', 'when-servers-with-extended-properties.xml'); 79 | expected = settings.formatSettings(expectedXml); 80 | assert.equal(actual, expected); 81 | 82 | // tear down 83 | process.env['INPUT_SERVERS'] = ''; 84 | }); 85 | }); 86 | 87 | describe('when environment variables are present', function () { 88 | it(' should be appended with and include all environment variables', function () { 89 | // given input 90 | process.env['INPUT_SERVERS'] = '[{ "id": "foo", "username": "${env.USERNAME}", "password": "${env.PASSWORD}" }]'; 91 | 92 | // when 93 | var actualXml = settings.getSettingsTemplate(); 94 | settings.update(actualXml); 95 | var actual = settings.formatSettings(actualXml); 96 | 97 | // then 98 | var expectedXml = settings.getTemplate('../test/js/resources/', 'when-servers-with-env-variables.xml'); 99 | expected = settings.formatSettings(expectedXml); 100 | assert.equal(actual, expected); 101 | 102 | // tear down 103 | process.env['INPUT_SERVERS'] = ''; 104 | }); 105 | }); 106 | 107 | }); 108 | 109 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: "build-test" 2 | 3 | on: # rebuild any PRs and main branch changes 4 | pull_request: 5 | push: 6 | branches: 7 | - main 8 | - develop 9 | 10 | jobs: 11 | 12 | build: # make sure build/ci work properly 13 | runs-on: ubuntu-latest 14 | steps: 15 | - uses: actions/checkout@v4 16 | - run: | 17 | npm ci 18 | npm test 19 | 20 | test-basic: 21 | runs-on: ubuntu-latest 22 | steps: 23 | - uses: actions/checkout@v4 24 | - uses: ./ 25 | with: 26 | servers: '[{"id": "foo", "username": "fu", "password": "bar" }]' 27 | mirrors: '[{ "id": "nexus", "mirrorOf": "!my-org-snapshots,*", "url": "http://redacted/nexus/content/groups/public" }]' 28 | repositories: '[{"id": "foo", "url": "https://fu.bar"}]' 29 | plugin_repositories: '[{"id": "foo-plugin", "url": "https://fu.bar.plugin"}]' 30 | profiles: '[{ "id": "foo.profile", "name": "foo.profile", "url": "http://foo.bar.profile", "properties": { "foo": "property-1", "bar": "property-2"} }]' 31 | plugin_groups: '[ "some.plugin.group.id", "some.other.plugin.group.id" ]' 32 | active_profiles: '[ "foo.profile" ]' 33 | - run: | 34 | cat ~/.m2/settings.xml 35 | 36 | test-expanded: 37 | runs-on: ubuntu-latest 38 | steps: 39 | - uses: actions/checkout@v4 40 | - uses: ./ 41 | with: 42 | repositories: > 43 | [ 44 | { 45 | "id": "some-repository", 46 | "name": "some-repository-name", 47 | "url": "http://some.repository.url", 48 | "releases": { 49 | "enabled": "true" 50 | }, 51 | "snapshots": { 52 | "enabled": "false" 53 | } 54 | } 55 | ] 56 | plugin_repositories: > 57 | [ 58 | { 59 | "id": "some-plugin-repository", 60 | "name": "some-plugin-repository-name", 61 | "url": "http://some.plugin.repository.url", 62 | "releases": { 63 | "enabled": "true" 64 | }, 65 | "snapshots": { 66 | "enabled": "false" 67 | } 68 | } 69 | ] 70 | servers: > 71 | [ 72 | { 73 | "id": "some-id", 74 | "username": "${env.USER}", 75 | "password": "${env.PASS}", 76 | "configuration": { 77 | "httpConfiguration": { 78 | "all": { 79 | "usePreemptive": "true" 80 | } 81 | } 82 | } 83 | } 84 | ] 85 | mirrors: > 86 | [ 87 | { 88 | "id": "nexus", 89 | "mirrorOf": "!my-org-snapshots,*", 90 | "url": "http://redacted/nexus/content/groups/public" 91 | } 92 | ] 93 | profiles: > 94 | [ 95 | { 96 | "id": "foo.profile", 97 | "name": "foo.profile", 98 | "url": "http://foo.bar.profile", 99 | "properties": { 100 | "foo": "property-1", 101 | "bar": "property-2" 102 | } 103 | } 104 | ] 105 | plugin_groups: > 106 | [ 107 | "some.plugin.group.id", 108 | "some.other.plugin.group.id" 109 | ] 110 | active_profiles: > 111 | [ 112 | "some-profile" 113 | ] 114 | output_file: .m2/settings.xml 115 | - run: | 116 | cat .m2/settings.xml 117 | 118 | test-filepath: 119 | runs-on: ubuntu-latest 120 | steps: 121 | - uses: actions/checkout@v4 122 | - uses: ./ 123 | with: 124 | output_file: custom.xml 125 | - run: | 126 | cat custom.xml 127 | 128 | test-maven: 129 | runs-on: ubuntu-latest 130 | steps: 131 | - uses: actions/checkout@v4 132 | - uses: ./ 133 | with: 134 | output_file: custom.xml 135 | - run: | 136 | cat custom.xml 137 | - uses: actions/setup-java@v4 138 | with: 139 | java-version: 11 140 | distribution: 'adopt' 141 | - run: | 142 | cd test/maven; 143 | ./mvnw -s ../../custom.xml clean test 144 | 145 | test-env-filepath: 146 | runs-on: ubuntu-latest 147 | steps: 148 | - uses: actions/checkout@v4 149 | - uses: ./ 150 | with: 151 | output_file: $GITHUB_WORKSPACE/custom.xml 152 | - run: | 153 | cat $GITHUB_WORKSPACE/custom.xml 154 | - uses: actions/setup-java@v4 155 | with: 156 | java-version: 11 157 | distribution: 'adopt' 158 | - run: | 159 | cd test/maven; 160 | ./mvnw -s $GITHUB_WORKSPACE/custom.xml clean test 161 | -------------------------------------------------------------------------------- /test/maven/.mvn/wrapper/MavenWrapperDownloader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | import java.net.*; 17 | import java.io.*; 18 | import java.nio.channels.*; 19 | import java.util.Properties; 20 | 21 | public class MavenWrapperDownloader { 22 | 23 | private static final String WRAPPER_VERSION = "0.5.6"; 24 | /** 25 | * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. 26 | */ 27 | private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" 28 | + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; 29 | 30 | /** 31 | * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to 32 | * use instead of the default one. 33 | */ 34 | private static final String MAVEN_WRAPPER_PROPERTIES_PATH = 35 | ".mvn/wrapper/maven-wrapper.properties"; 36 | 37 | /** 38 | * Path where the maven-wrapper.jar will be saved to. 39 | */ 40 | private static final String MAVEN_WRAPPER_JAR_PATH = 41 | ".mvn/wrapper/maven-wrapper.jar"; 42 | 43 | /** 44 | * Name of the property which should be used to override the default download url for the wrapper. 45 | */ 46 | private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; 47 | 48 | public static void main(String args[]) { 49 | System.out.println("- Downloader started"); 50 | File baseDirectory = new File(args[0]); 51 | System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); 52 | 53 | // If the maven-wrapper.properties exists, read it and check if it contains a custom 54 | // wrapperUrl parameter. 55 | File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); 56 | String url = DEFAULT_DOWNLOAD_URL; 57 | if(mavenWrapperPropertyFile.exists()) { 58 | FileInputStream mavenWrapperPropertyFileInputStream = null; 59 | try { 60 | mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); 61 | Properties mavenWrapperProperties = new Properties(); 62 | mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); 63 | url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); 64 | } catch (IOException e) { 65 | System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); 66 | } finally { 67 | try { 68 | if(mavenWrapperPropertyFileInputStream != null) { 69 | mavenWrapperPropertyFileInputStream.close(); 70 | } 71 | } catch (IOException e) { 72 | // Ignore ... 73 | } 74 | } 75 | } 76 | System.out.println("- Downloading from: " + url); 77 | 78 | File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); 79 | if(!outputFile.getParentFile().exists()) { 80 | if(!outputFile.getParentFile().mkdirs()) { 81 | System.out.println( 82 | "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); 83 | } 84 | } 85 | System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); 86 | try { 87 | downloadFileFromURL(url, outputFile); 88 | System.out.println("Done"); 89 | System.exit(0); 90 | } catch (Throwable e) { 91 | System.out.println("- Error downloading"); 92 | e.printStackTrace(); 93 | System.exit(1); 94 | } 95 | } 96 | 97 | private static void downloadFileFromURL(String urlString, File destination) throws Exception { 98 | if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) { 99 | String username = System.getenv("MVNW_USERNAME"); 100 | char[] password = System.getenv("MVNW_PASSWORD").toCharArray(); 101 | Authenticator.setDefault(new Authenticator() { 102 | @Override 103 | protected PasswordAuthentication getPasswordAuthentication() { 104 | return new PasswordAuthentication(username, password); 105 | } 106 | }); 107 | } 108 | URL website = new URL(urlString); 109 | ReadableByteChannel rbc; 110 | rbc = Channels.newChannel(website.openStream()); 111 | FileOutputStream fos = new FileOutputStream(destination); 112 | fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); 113 | fos.close(); 114 | rbc.close(); 115 | } 116 | 117 | } 118 | -------------------------------------------------------------------------------- /test/maven/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM https://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 50 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 124 | 125 | FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( 126 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 127 | ) 128 | 129 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 130 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 131 | if exist %WRAPPER_JAR% ( 132 | if "%MVNW_VERBOSE%" == "true" ( 133 | echo Found %WRAPPER_JAR% 134 | ) 135 | ) else ( 136 | if not "%MVNW_REPOURL%" == "" ( 137 | SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 138 | ) 139 | if "%MVNW_VERBOSE%" == "true" ( 140 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 141 | echo Downloading from: %DOWNLOAD_URL% 142 | ) 143 | 144 | powershell -Command "&{"^ 145 | "$webclient = new-object System.Net.WebClient;"^ 146 | "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ 147 | "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ 148 | "}"^ 149 | "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ 150 | "}" 151 | if "%MVNW_VERBOSE%" == "true" ( 152 | echo Finished downloading %WRAPPER_JAR% 153 | ) 154 | ) 155 | @REM End of extension 156 | 157 | @REM Provide a "standardized" way to retrieve the CLI args that will 158 | @REM work with both Windows and non-Windows executions. 159 | set MAVEN_CMD_LINE_ARGS=%* 160 | 161 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 162 | if ERRORLEVEL 1 goto error 163 | goto end 164 | 165 | :error 166 | set ERROR_CODE=1 167 | 168 | :end 169 | @endlocal & set ERROR_CODE=%ERROR_CODE% 170 | 171 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 172 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 173 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 174 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 175 | :skipRcPost 176 | 177 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 178 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 179 | 180 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 181 | 182 | exit /B %ERROR_CODE% 183 | -------------------------------------------------------------------------------- /test/maven/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Mingw, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | fi 118 | 119 | if [ -z "$JAVA_HOME" ]; then 120 | javaExecutable="`which javac`" 121 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 122 | # readlink(1) is not available as standard on Solaris 10. 123 | readLink=`which readlink` 124 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 125 | if $darwin ; then 126 | javaHome="`dirname \"$javaExecutable\"`" 127 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 128 | else 129 | javaExecutable="`readlink -f \"$javaExecutable\"`" 130 | fi 131 | javaHome="`dirname \"$javaExecutable\"`" 132 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 133 | JAVA_HOME="$javaHome" 134 | export JAVA_HOME 135 | fi 136 | fi 137 | fi 138 | 139 | if [ -z "$JAVACMD" ] ; then 140 | if [ -n "$JAVA_HOME" ] ; then 141 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 142 | # IBM's JDK on AIX uses strange locations for the executables 143 | JAVACMD="$JAVA_HOME/jre/sh/java" 144 | else 145 | JAVACMD="$JAVA_HOME/bin/java" 146 | fi 147 | else 148 | JAVACMD="`which java`" 149 | fi 150 | fi 151 | 152 | if [ ! -x "$JAVACMD" ] ; then 153 | echo "Error: JAVA_HOME is not defined correctly." >&2 154 | echo " We cannot execute $JAVACMD" >&2 155 | exit 1 156 | fi 157 | 158 | if [ -z "$JAVA_HOME" ] ; then 159 | echo "Warning: JAVA_HOME environment variable is not set." 160 | fi 161 | 162 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 163 | 164 | # traverses directory structure from process work directory to filesystem root 165 | # first directory with .mvn subdirectory is considered project base directory 166 | find_maven_basedir() { 167 | 168 | if [ -z "$1" ] 169 | then 170 | echo "Path not specified to find_maven_basedir" 171 | return 1 172 | fi 173 | 174 | basedir="$1" 175 | wdir="$1" 176 | while [ "$wdir" != '/' ] ; do 177 | if [ -d "$wdir"/.mvn ] ; then 178 | basedir=$wdir 179 | break 180 | fi 181 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 182 | if [ -d "${wdir}" ]; then 183 | wdir=`cd "$wdir/.."; pwd` 184 | fi 185 | # end of workaround 186 | done 187 | echo "${basedir}" 188 | } 189 | 190 | # concatenates all lines of a file 191 | concat_lines() { 192 | if [ -f "$1" ]; then 193 | echo "$(tr -s '\n' ' ' < "$1")" 194 | fi 195 | } 196 | 197 | BASE_DIR=`find_maven_basedir "$(pwd)"` 198 | if [ -z "$BASE_DIR" ]; then 199 | exit 1; 200 | fi 201 | 202 | ########################################################################################## 203 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 204 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 205 | ########################################################################################## 206 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then 207 | if [ "$MVNW_VERBOSE" = true ]; then 208 | echo "Found .mvn/wrapper/maven-wrapper.jar" 209 | fi 210 | else 211 | if [ "$MVNW_VERBOSE" = true ]; then 212 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." 213 | fi 214 | if [ -n "$MVNW_REPOURL" ]; then 215 | jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 216 | else 217 | jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 218 | fi 219 | while IFS="=" read key value; do 220 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;; 221 | esac 222 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" 223 | if [ "$MVNW_VERBOSE" = true ]; then 224 | echo "Downloading from: $jarUrl" 225 | fi 226 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" 227 | if $cygwin; then 228 | wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` 229 | fi 230 | 231 | if command -v wget > /dev/null; then 232 | if [ "$MVNW_VERBOSE" = true ]; then 233 | echo "Found wget ... using wget" 234 | fi 235 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 236 | wget "$jarUrl" -O "$wrapperJarPath" 237 | else 238 | wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" 239 | fi 240 | elif command -v curl > /dev/null; then 241 | if [ "$MVNW_VERBOSE" = true ]; then 242 | echo "Found curl ... using curl" 243 | fi 244 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 245 | curl -o "$wrapperJarPath" "$jarUrl" -f 246 | else 247 | curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f 248 | fi 249 | 250 | else 251 | if [ "$MVNW_VERBOSE" = true ]; then 252 | echo "Falling back to using Java to download" 253 | fi 254 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" 255 | # For Cygwin, switch paths to Windows format before running javac 256 | if $cygwin; then 257 | javaClass=`cygpath --path --windows "$javaClass"` 258 | fi 259 | if [ -e "$javaClass" ]; then 260 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 261 | if [ "$MVNW_VERBOSE" = true ]; then 262 | echo " - Compiling MavenWrapperDownloader.java ..." 263 | fi 264 | # Compiling the Java class 265 | ("$JAVA_HOME/bin/javac" "$javaClass") 266 | fi 267 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 268 | # Running the downloader 269 | if [ "$MVNW_VERBOSE" = true ]; then 270 | echo " - Running MavenWrapperDownloader.java ..." 271 | fi 272 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") 273 | fi 274 | fi 275 | fi 276 | fi 277 | ########################################################################################## 278 | # End of extension 279 | ########################################################################################## 280 | 281 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 282 | if [ "$MVNW_VERBOSE" = true ]; then 283 | echo $MAVEN_PROJECTBASEDIR 284 | fi 285 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 286 | 287 | # For Cygwin, switch paths to Windows format before running java 288 | if $cygwin; then 289 | [ -n "$M2_HOME" ] && 290 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 291 | [ -n "$JAVA_HOME" ] && 292 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 293 | [ -n "$CLASSPATH" ] && 294 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 295 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 296 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 297 | fi 298 | 299 | # Provide a "standardized" way to retrieve the CLI args that will 300 | # work with both Windows and non-Windows executions. 301 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" 302 | export MAVEN_CMD_LINE_ARGS 303 | 304 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 305 | 306 | exec "$JAVACMD" \ 307 | $MAVEN_OPTS \ 308 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 309 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 310 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 311 | -------------------------------------------------------------------------------- /src/settings.js: -------------------------------------------------------------------------------- 1 | var core = require('@actions/core'); 2 | var path = require('path'); 3 | var fs = require('fs'); 4 | var DOMParser = require('@xmldom/xmldom').DOMParser; 5 | var XMLSerializer = require('@xmldom/xmldom').XMLSerializer; 6 | var format = require('xml-formatter'); 7 | 8 | function getSettingsTemplate() { 9 | return getTemplate('../template', 'settings.xml'); 10 | } 11 | 12 | function getDefaultRepositoryTemplate() { 13 | return getTemplate('../template', 'default-repository.xml'); 14 | } 15 | 16 | function getDefaultActiveProfileTemplate() { 17 | return getTemplate('../template', 'default-active-profile.xml'); 18 | } 19 | 20 | function getTemplate(filepath, filename) { 21 | var templatePath = path.join(__dirname, filepath, filename); 22 | var template = fs.readFileSync(templatePath).toString(); 23 | return new DOMParser().parseFromString(template, 'text/xml'); 24 | } 25 | 26 | function formatSettings(templateXml) { 27 | var settingStr = new XMLSerializer().serializeToString(templateXml); 28 | 29 | // format xml to standard format 30 | return format(settingStr, { 31 | indentation: ' ', 32 | collapsetent: true, 33 | lineSeparator: '\n' 34 | }); 35 | } 36 | 37 | function update(templateXml) { 38 | this.updateActiveProfiles(templateXml); 39 | this.updateServers(templateXml); 40 | this.updateMirrors(templateXml); 41 | this.updateRepositories(templateXml); 42 | this.updatePluginRepositories(templateXml); 43 | this.updateProfiles(templateXml) 44 | this.updatePluginGroups(templateXml) 45 | this.updateProxies(templateXml) 46 | } 47 | 48 | function updateActiveProfiles(templateXml) { 49 | 50 | var activeProfilesInput = core.getInput('active_profiles'); 51 | 52 | if (!activeProfilesInput) { 53 | applyDefaultActiveProfile(templateXml); 54 | return; 55 | } 56 | 57 | var activeProfiles = JSON.parse(activeProfilesInput); 58 | 59 | if (activeProfiles.length == 0) { 60 | applyDefaultActiveProfile(templateXml); 61 | return; 62 | } 63 | 64 | // apply custom repostories 65 | activeProfiles.forEach((activeProfileInput) => { 66 | var activeProfileXml = templateXml.createElement("activeProfile"); 67 | activeProfileXml.textContent = activeProfileInput; 68 | templateXml 69 | .getElementsByTagName('activeProfiles')[0] 70 | .appendChild(activeProfileXml); 71 | }); 72 | 73 | } 74 | 75 | function applyDefaultActiveProfile(templateXml) { 76 | var defaultActiveProfile = getDefaultActiveProfileTemplate(); 77 | 78 | templateXml 79 | .getElementsByTagName('activeProfiles')[0] 80 | .appendChild(defaultActiveProfile); 81 | } 82 | 83 | function updateServers(templateXml) { 84 | var serversInput = core.getInput('servers'); 85 | 86 | if (!serversInput) { 87 | return; 88 | } 89 | 90 | var serversXml = templateXml.getElementsByTagName('servers')[0]; 91 | 92 | JSON.parse(serversInput).forEach((serverInput) => { 93 | var serverXml = templateXml.createElement('server'); 94 | for (var key in serverInput) { 95 | var keyXml = templateXml.createElement(key); 96 | 97 | // convert all json content as xml 98 | var value = objectToXml(serverInput[key]); 99 | var xmlValue = new DOMParser().parseFromString(value, 'text/xml'); 100 | 101 | // append new xml to current node 102 | keyXml.appendChild(xmlValue); 103 | serverXml.appendChild(keyXml); 104 | } 105 | serversXml.appendChild(serverXml); 106 | }); 107 | 108 | } 109 | 110 | function updateMirrors(templateXml) { 111 | var mirrorsInput = core.getInput('mirrors'); 112 | 113 | if (!mirrorsInput) { 114 | return; 115 | } 116 | 117 | var mirrorsXml = templateXml.getElementsByTagName('mirrors')[0]; 118 | 119 | JSON.parse(mirrorsInput).forEach((mirrorInput) => { 120 | var mirrorXml = templateXml.createElement('mirror'); 121 | for (var key in mirrorInput) { 122 | var keyXml = templateXml.createElement(key); 123 | keyXml.textContent = mirrorInput[key]; 124 | mirrorXml.appendChild(keyXml); 125 | } 126 | mirrorsXml.appendChild(mirrorXml); 127 | }); 128 | 129 | } 130 | 131 | function updateRepositories(templateXml) { 132 | var repositoriesInput = core.getInput('repositories'); 133 | 134 | if (!repositoriesInput) { 135 | applyDefaultRepository(templateXml); 136 | return; 137 | } 138 | 139 | var repositories = JSON.parse(repositoriesInput); 140 | 141 | if (repositories.length == 0) { 142 | applyDefaultRepository(templateXml); 143 | return; 144 | } 145 | 146 | // apply custom repostories 147 | repositories.forEach((repositoryInput) => { 148 | var repositoryXml = templateXml.createElement('repository'); 149 | for (var key in repositoryInput) { 150 | var keyXml = templateXml.createElement(key); 151 | var child = repositoryInput[key]; 152 | if (child === Object(child)) { 153 | var childXml = templateXml.createElement(key); 154 | for (var childKey in child) { 155 | if (Object.prototype.hasOwnProperty.call(child, childKey)) { 156 | var childElement = templateXml.createElement(childKey); 157 | childElement.textContent = child[childKey]; 158 | childXml.appendChild(childElement); 159 | } 160 | } 161 | repositoryXml.appendChild(childXml); 162 | } else { 163 | keyXml.textContent = repositoryInput[key]; 164 | repositoryXml.appendChild(keyXml); 165 | } 166 | } 167 | templateXml 168 | .getElementsByTagName('profiles')[0] 169 | .getElementsByTagName('repositories')[0] 170 | .appendChild(repositoryXml); 171 | }); 172 | } 173 | 174 | function applyDefaultRepository(templateXml) { 175 | var defaultRepositoryTemplate = getDefaultRepositoryTemplate(); 176 | 177 | templateXml 178 | .getElementsByTagName('profiles')[0] 179 | .getElementsByTagName('repositories')[0] 180 | .appendChild(defaultRepositoryTemplate); 181 | } 182 | 183 | function updatePluginRepositories(templateXml) { 184 | var pluginRepositoriesInput = core.getInput('plugin_repositories'); 185 | 186 | if (!pluginRepositoriesInput) { 187 | return; 188 | } 189 | 190 | var pluginRepositoriesXml = 191 | templateXml.getElementsByTagName('profiles')[0] 192 | .getElementsByTagName('pluginRepositories')[0]; 193 | 194 | JSON.parse(pluginRepositoriesInput).forEach((pluginRepositoryInput) => { 195 | var pluginRepositoryXml = templateXml.createElement('pluginRepository'); 196 | for (var key in pluginRepositoryInput) { 197 | var keyXml = templateXml.createElement(key); 198 | var child = pluginRepositoryInput[key]; 199 | if (child === Object(child)) { 200 | var childXml = templateXml.createElement(key); 201 | for (var childKey in child) { 202 | if (Object.prototype.hasOwnProperty.call(child, childKey)) { 203 | var childElement = templateXml.createElement(childKey); 204 | childElement.textContent = child[childKey]; 205 | childXml.appendChild(childElement); 206 | } 207 | } 208 | pluginRepositoryXml.appendChild(childXml); 209 | } else { 210 | keyXml.textContent = pluginRepositoryInput[key]; 211 | pluginRepositoryXml.appendChild(keyXml); 212 | } 213 | } 214 | pluginRepositoriesXml.appendChild(pluginRepositoryXml); 215 | }); 216 | } 217 | 218 | function updateProfiles(templateXml) { 219 | var profilesInput = core.getInput('profiles'); 220 | 221 | if (!profilesInput) { 222 | return; 223 | } 224 | 225 | var profilesXml = 226 | templateXml.getElementsByTagName('profiles')[0]; 227 | 228 | JSON.parse(profilesInput).forEach((profileInput) => { 229 | var profileXml = templateXml.createElement('profile'); 230 | for (var key in profileInput) { 231 | var keyXml = templateXml.createElement(key); 232 | var child = profileInput[key]; 233 | if (child === Object(child)) { 234 | var childXml = templateXml.createElement(key); 235 | for (var childKey in child) { 236 | if (Object.prototype.hasOwnProperty.call(child, childKey)) { 237 | var childElement = templateXml.createElement(childKey); 238 | childElement.textContent = child[childKey]; 239 | childXml.appendChild(childElement); 240 | } 241 | } 242 | profileXml.appendChild(childXml); 243 | } else { 244 | keyXml.textContent = profileInput[key]; 245 | profileXml.appendChild(keyXml); 246 | } 247 | } 248 | profilesXml.appendChild(profileXml); 249 | }); 250 | } 251 | 252 | function updatePluginGroups(templateXml) { 253 | var pluginGroupsInput = core.getInput('plugin_groups'); 254 | 255 | if (!pluginGroupsInput) { 256 | return; 257 | } 258 | 259 | var pluginGroupsXml = templateXml.getElementsByTagName('pluginGroups')[0]; 260 | 261 | JSON.parse(pluginGroupsInput).forEach((pluginGroupInput) => { 262 | var pluginGroupXml = templateXml.createElement('pluginGroup'); 263 | pluginGroupXml.textContent = pluginGroupInput; 264 | pluginGroupsXml.appendChild(pluginGroupXml); 265 | }); 266 | 267 | } 268 | 269 | function updateProxies(templateXml) { 270 | var proxiesInput = core.getInput('proxies'); 271 | 272 | if (!proxiesInput) { 273 | return; 274 | } 275 | 276 | var proxiesXml = templateXml.getElementsByTagName('proxies')[0]; 277 | 278 | JSON.parse(proxiesInput).forEach((proxyInput) => { 279 | var proxyXml = templateXml.createElement('proxy'); 280 | for (var key in proxyInput) { 281 | var keyXml = templateXml.createElement(key); 282 | 283 | // convert all json content as xml 284 | var value = objectToXml(proxyInput[key]); 285 | var xmlValue = new DOMParser().parseFromString(value, 'text/xml'); 286 | 287 | // append new xml to current node 288 | keyXml.appendChild(xmlValue); 289 | proxyXml.appendChild(keyXml); 290 | } 291 | proxiesXml.appendChild(proxyXml); 292 | }); 293 | 294 | } 295 | 296 | function objectToXml(obj) { 297 | var xml = ''; 298 | for (var prop in obj) { 299 | xml += obj[prop] instanceof Array ? '' : "<" + prop + ">"; 300 | if (obj[prop] instanceof Array) { 301 | for (var array in obj[prop]) { 302 | xml += "<" + prop + ">"; 303 | xml += objectToXml(new Object(obj[prop][array])); 304 | xml += ""; 305 | } 306 | } else if (typeof obj[prop] == "object") { 307 | xml += objectToXml(new Object(obj[prop])); 308 | } else { 309 | xml += obj[prop]; 310 | } 311 | xml += obj[prop] instanceof Array ? '' : ""; 312 | } 313 | xml = xml.replace(/<\/?[0-9]{1,}>/g, ''); 314 | return xml 315 | } 316 | 317 | module.exports = { 318 | getSettingsTemplate, 319 | getTemplate, 320 | formatSettings, 321 | update, 322 | updateActiveProfiles, 323 | updateServers, 324 | updateMirrors, 325 | updateRepositories, 326 | updatePluginRepositories, 327 | updateProfiles, 328 | updatePluginGroups, 329 | updateProxies 330 | } 331 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # maven-settings-xml-action 2 | 3 | [![CodeFactor](https://www.codefactor.io/repository/github/whelk-io/maven-settings-xml-action/badge)](https://www.codefactor.io/repository/github/whelk-io/maven-settings-xml-action) ![build-test](https://github.com/whelk-io/maven-settings-xml-action/workflows/build-test/badge.svg) [![CodeQL](https://github.com/whelk-io/maven-settings-xml-action/actions/workflows/codeql-analysis.yml/badge.svg?branch=main)](https://github.com/whelk-io/maven-settings-xml-action/actions/workflows/codeql-analysis.yml) 4 | 5 | Github Action to create maven settings (`~/.m2/settings.xml`). 6 | 7 | Supports ``, ``, ``, ``, ``, ``, ``, and ``. 8 | 9 | ## Inputs 10 | 11 | ### `servers` 12 | 13 | **Optional** json array of servers to add to settings.xml. 14 | * **id** - The ID of the server (not of the user to login as) that matches the id element of the repository/mirror that Maven tries to connect to. 15 | * **username**, **password** - These elements appear as a pair denoting the login and password required to authenticate to this server. 16 | * **privateKey**, **passphrase** - Like the previous two elements, this pair specifies a path to a private key (default is `${user.home}/.ssh/id_dsa`) and a `passphrase`, if required. 17 | * **filePermissions**, **directoryPermissions** - When a repository file or directory is created on deployment, these are the permissions to use. The legal values of each is a three digit number corresponding to *nix file permissions, e.g. 664, or 775. 18 | * **configuration** - Any additional custom configuration for server in JSON format. 19 | 20 | Reference: [Maven Settings > Servers](http://maven.apache.org/settings.html#servers) 21 | 22 | ### `mirrors` 23 | 24 | * **id** - The unique identifier of this mirror. The `id` is used to differentiate between mirror elements and to pick the corresponding credentials from the `` section when connecting to the mirror. 25 | * **mirrorOf** - The `id` of the repository that this is a mirror of. For example, to point to a mirror of the Maven central repository (`https://repo.maven.apache.org/maven2/`), set this element to `central`. More advanced mappings like `repo1,repo2` or `*,!inhouse` are also possible. This must not match the mirror `id`. 26 | * **url** - The base URL of this mirror. The build system will use this URL to connect to a repository rather than the original repository URL. 27 | 28 | Reference: [Maven Settings > Mirrors](http://maven.apache.org/settings.html#mirrors) 29 | 30 | ### `repositories` 31 | **Optional** json array of repositories to add to settings.xml 32 | * **id** - The ID of the repository that matches the id element of the server. 33 | * **name** - Name of the repository. 34 | * **url** - URL to connect to repository. 35 | * **releases.enabled** - Enable release policy. 36 | * **snapshots.enabled** - Enable snapshot policy. 37 | 38 | When not `repostories` is empty or null, the Maven Central repository is applied by default: 39 | 40 | ```yaml 41 | repositories: | 42 | [ 43 | { 44 | "id": "central", 45 | "name": "Maven Central", 46 | "url": "https://repo1.maven.org/maven2", 47 | "releases": { 48 | "enabled": "true" 49 | }, 50 | "snapshots": { 51 | "enabled": "false" 52 | } 53 | } 54 | ] 55 | ``` 56 | 57 | Reference: [Maven Settings > Repositories](http://maven.apache.org/settings.html#repositories) 58 | 59 | ### `plugin_repositories` 60 | **Optional** json array of repositories to add to settings.xml 61 | * **id** - The ID of the repository that matches the id element of the server. 62 | * **name** - Name of the repository. 63 | * **url** - URL to connect to repository. 64 | * **releases.enabled** - Enable release policy. 65 | * **snapshots.enabled** - Enable snapshot policy. 66 | 67 | Reference: [Maven Settings > Plugin Repositories](http://maven.apache.org/settings.html#Plugin_Repositories) 68 | 69 | ### `plugin_groups` 70 | **Optional** json array of plugin groups to add to settings.xml 71 | 72 | Reference: [Maven Settings > Plugin Groups](http://maven.apache.org/settings.html#Plugin_Groups) 73 | 74 | ### `profiles` 75 | **Optional** json array of profiles to add to settings.xml 76 | 77 | The `profile` element in the `settings.xml` is a truncated version of the `pom.xml` `profile` element. It consists of the `activation`, `repositories`, `pluginRepositories` and `properties` elements. The `profile` elements only include these four elements because they concerns themselves with the build system as a whole (which is the role of the `settings.xml` file), not about individual project object model settings. 78 | 79 | Reference: [Maven Settings > Profiles](http://maven.apache.org/settings.html#profiles) 80 | 81 | ### `active_profiles` 82 | **Optional** json array of active profiles to add to settings.xml 83 | 84 | Set of `activeProfile` elements, which each have a value of a `profile` `id`. Any `profile` `id` defined as an `activeProfile` will be active, regardless of any environment settings. If no matching profile is found nothing will happen. For example, if `env-test` is an `activeProfile`, a profile in a `pom.xml` (or `profile.xml`) with a corresponding `id` will be active. If no such profile is found then execution will continue as normal. 85 | 86 | Reference: [Maven Settings > Active Profiles](https://maven.apache.org/settings.html#Active_Profiles) 87 | 88 | ### `proxies` 89 | 90 | **Optional** json array of proxies to add to settings.xml. 91 | * **id** - The unique identifier for this proxy. This is used to differentiate between proxy elements. 92 | * **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. 93 | * **protocol, host, port** - The protocol://host:port of the proxy, separated into discrete elements. 94 | * **username, password** - These elements appear as a pair denoting the login and password required to authenticate to this proxy server. 95 | * **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. 96 | 97 | 98 | Reference: [Maven Settings > Proxies](https://maven.apache.org/settings.html#proxies) 99 | 100 | ### `output_file` 101 | **Optional** String path of to generate `settings.xml`. By default, `~/.m2/settings.xml` is used. 102 | 103 | When using a custom `output_file`, for example: 104 | ```yaml 105 | - uses: whelk-io/maven-settings-xml-action@v22 106 | with: 107 | output_file: foo/custom.xml 108 | ``` 109 | 110 | The generated `settings.xml` will be created at `/home/runner/work/{repo}/foo/custom.xml`, which can be referenced in maven steps using `mvn --settings foo/custom.xml {goal}`. 111 | 112 | --- 113 | 114 | ## Basic Usage 115 | 116 | ````yaml 117 | - name: maven-settings-xml-action 118 | uses: whelk-io/maven-settings-xml-action@v22 119 | with: 120 | repositories: '[{ "id": "some-repository", "url": "http://some.repository.url" }]' 121 | plugin_repositories: '[{ "id": "some-plugin-repository", "url": "http://some.plugin.repository.url" }]' 122 | servers: '[{ "id": "some-server", "username": "some.user", "password": "some.password" }]' 123 | ```` 124 | 125 | **Output** 126 | 127 | ````xml 128 | 132 | 133 | 134 | github 135 | 136 | 137 | 138 | 139 | github 140 | 141 | 142 | some-repository 143 | http://some.repository.url 144 | 145 | 146 | 147 | 148 | some-plugin-repository 149 | http://some.plugin.repository.url 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | foo 158 | fu 159 | bar 160 | 161 | 162 | 163 | 164 | ```` 165 | 166 | ---- 167 | 168 | ## Full Usage 169 | 170 | ````yaml 171 | - name: maven-settings-xml-action 172 | uses: whelk-io/maven-settings-xml-action@v22 173 | with: 174 | repositories: > 175 | [ 176 | { 177 | "id": "some-repository", 178 | "name": "some-repository-name", 179 | "url": "http://some.repository.url", 180 | "releases": { 181 | "enabled": "true", 182 | "updatePolicy": "always", 183 | "checksumPolicy": "fail" 184 | }, 185 | "snapshots": { 186 | "enabled": "false", 187 | "updatePolicy": "always", 188 | "checksumPolicy": "fail" 189 | } 190 | } 191 | ] 192 | plugin_repositories: > 193 | [ 194 | { 195 | "id": "some-plugin-repository", 196 | "name": "some-plugin-repository-name", 197 | "url": "http://some.plugin.repository.url", 198 | "releases": { 199 | "enabled": "true" 200 | }, 201 | "snapshots": { 202 | "enabled": "false" 203 | } 204 | } 205 | ] 206 | servers: > 207 | [ 208 | { 209 | "id": "some-id", 210 | "username": "${env.USER}", 211 | "password": "${env.PASS}", 212 | "configuration": { 213 | "httpConfiguration": { 214 | "all": { 215 | "usePreemptive": "true" 216 | } 217 | } 218 | } 219 | } 220 | ] 221 | mirrors: > 222 | [ 223 | { 224 | "id": "nexus", 225 | "mirrorOf": "!my-org-snapshots,*", 226 | "url": "http://redacted/nexus/content/groups/public" 227 | } 228 | ] 229 | profiles: > 230 | [ 231 | { 232 | "id": "foo.profile", 233 | "name": "foo.profile", 234 | "url": "http://foo.bar.profile", 235 | "properties": { 236 | "foo": "property-1", 237 | "bar": "property-2" 238 | } 239 | } 240 | ] 241 | plugin_groups: > 242 | [ 243 | "some.plugin.group.id", 244 | "some.other.plugin.group.id" 245 | ] 246 | proxies: > 247 | [ 248 | { 249 | "id": "foo-proxy", 250 | "active": "true", 251 | "protocol": "http", 252 | "host": "https://proxy.example.com", 253 | "port": "443", 254 | "username": "foo", 255 | "password": "bar", 256 | "nonProxyHosts": "noproxy1.example.com|noproxy2.example.com" 257 | } 258 | ] 259 | active_profiles: > 260 | [ 261 | "some-profile" 262 | ] 263 | output_file: .m2/settings.xml 264 | ```` 265 | 266 | **Output** 267 | 268 | ````xml 269 | 273 | 274 | 275 | some-profile 276 | 277 | 278 | 279 | 280 | github 281 | 282 | 283 | some-repository 284 | some-repository-name 285 | http://some.repository.url 286 | 287 | true 288 | always 289 | fail 290 | 291 | 292 | false 293 | always 294 | fail 295 | 296 | 297 | 298 | 299 | 300 | some-plugin-repository 301 | some-plugin-repository-name 302 | http://some.plugin.repository.url 303 | 304 | true 305 | 306 | 307 | false 308 | 309 | 310 | 311 | 312 | 313 | foo.profile 314 | foo.profile 315 | http://foo.bar.profile 316 | 317 | property-1 318 | property-2 319 | 320 | 321 | 322 | 323 | 324 | 325 | foo 326 | fu 327 | bar 328 | ${user.home}/.ssh/id_dsa 329 | some_passphrase 330 | 664 331 | 775 332 | 333 | 334 | 335 | true 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | nexus 345 | !my-org-snapshots,* 346 | http://redacted/nexus/content/groups/public 347 | 348 | 349 | 350 | 351 | some.plugin.group.id 352 | some.other.plugin.group.id 353 | 354 | 355 | 356 | 357 | foo-proxy 358 | true 359 | http 360 | https://proxy.example.com 361 | 443 362 | foo 363 | bar 364 | noproxy1.example.com|noproxy2.example.com 365 | 366 | 367 | 368 | 369 | ```` 370 | 371 | ---- 372 | 373 | ## Local Setup 374 | 375 | See [Contributing](CONTRIBUTING.md) for guidelines for forking and contributing to this project. 376 | 377 | **Install Dependencies** 378 | 379 | `npm ci` 380 | 381 | **Run Linter** 382 | 383 | `npm run lint` 384 | 385 | **Run Unit-Tests** 386 | 387 | `npm test` 388 | 389 | **Create Distribution** 390 | 391 | `npm run build` 392 | 393 | 394 | ## Run Actions Locally 395 | 396 | **Install [`Act`](https://github.com/nektos/act)** 397 | 398 | `brew install act` 399 | 400 | **Run Step** 401 | 402 | `act -s GITHUB_TOKEN={token} -j {step}` 403 | 404 | Example: `act -s GITHUB_TOKEN=lk34j56lk34j5lk34j5dkllsldf -j test-basic` 405 | --------------------------------------------------------------------------------