├── .gitignore
├── LICENSE.txt
├── README.md
├── bom
├── pom.xml
└── src
│ └── main
│ └── resources
│ └── bom-template.xml
├── fraction-list
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── org
│ │ │ └── wildfly
│ │ │ └── swarm
│ │ │ └── fractionlist
│ │ │ └── FractionList.java
│ └── resources
│ │ └── org
│ │ └── wildfly
│ │ └── swarm
│ │ └── fractionlist
│ │ └── fraction-packages.properties
│ └── test
│ └── java
│ └── org
│ └── wildfly
│ └── swarm
│ └── fractionlist
│ └── FractionListTest.java
├── plugin
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── org
│ │ │ └── wildfly
│ │ │ └── swarm
│ │ │ └── plugin
│ │ │ ├── gradle
│ │ │ ├── GradleArtifactResolvingHelper.java
│ │ │ ├── PackagePlugin.java
│ │ │ ├── PackageTask.java
│ │ │ └── SwarmExtension.java
│ │ │ └── maven
│ │ │ ├── AbstractSwarmMojo.java
│ │ │ ├── AnalyzeMojo.java
│ │ │ ├── DumpGraphVisitor.java
│ │ │ ├── Graph.java
│ │ │ ├── GraphVisitor.java
│ │ │ ├── MavenArtifactResolvingHelper.java
│ │ │ ├── MultiStartMojo.java
│ │ │ ├── NewestVersionSelector.java
│ │ │ ├── PackageMojo.java
│ │ │ ├── RepositorySystemSessionWrapper.java
│ │ │ ├── RunMojo.java
│ │ │ ├── StartMojo.java
│ │ │ └── StopMojo.java
│ └── resources
│ │ └── META-INF
│ │ └── gradle-plugins
│ │ └── wildfly-swarm.properties
│ └── test
│ └── java
│ └── org
│ ├── eclipse
│ └── aether
│ │ └── util
│ │ └── version
│ │ └── TestHelper.java
│ └── wildfly
│ └── swarm
│ └── plugin
│ └── maven
│ └── NewestVersionSelectorTest.java
├── pom.xml
├── public-javadoc
├── pom.xml
└── src
│ └── main
│ ├── ruby
│ ├── collect_src.rb
│ └── group_packages.rb
│ └── sh
│ └── publish_docs.sh
└── swarmtool
├── pom.xml
└── src
├── main
├── assembly
│ └── genexe.sh
├── java
│ └── org
│ │ └── wildfly
│ │ └── swarm
│ │ └── swarmtool
│ │ └── Main.java
└── resources
│ └── org
│ └── wildfly
│ └── swarm
│ └── swarmtool
│ └── version.properties
└── test
├── java
└── org
│ └── wildfly
│ └── swarm
│ └── swarmtool
│ └── MainTest.java
└── resources
├── modules
└── sun
│ └── jdk
│ └── main
│ └── module.xml
├── simple-servlet.war
└── test.properties
/.gitignore:
--------------------------------------------------------------------------------
1 | # ignore .svn metadata files
2 | .svn
3 | # ignore Maven generated target folders
4 | ~
5 | target
6 | # ignore eclipse files
7 | .project
8 | .classpath
9 | .settings
10 | .metadata
11 | # ignore m2e annotation processing files
12 | .factorypath
13 | # ignore IDEA files
14 | *.iml
15 | *.ipr
16 | *.iws
17 | .idea
18 | # ignore NetBeans files
19 | nbactions.xml
20 | nb-configuration.xml
21 | catalog.xml
22 | #
23 | maven-ant-tasks.jar
24 | test-output
25 | transaction.log
26 | # vim files
27 | *.swp
28 | /.gitk-tmp.*
29 | atlassian-ide-plugin.xml
30 | # temp files
31 | *~
32 | # maven versions plugin
33 | pom.xml.versionsBackup
34 | # hprof dumps
35 | /*.hprof
36 | # ignore 'randomly' strewn around logs
37 | server.log
38 | # ignore java crashes
39 | hs_err_pid*.log
40 | # H2 databases produced by tests
41 | *.h2.db
42 | *.trace.db
43 | *.lock.db
44 | # JBoss transaction generated files
45 | PutObjectStoreDirHere
46 | # ignore mvn-rpmbuild repo
47 | /.m2
48 | # ignore eap repo
49 | local-repo-eap
50 | # Dependency reduced pom
51 | */dependency-reduced-pom.xml
52 | #OS X index files
53 | .DS_Store
54 | testsuite-core/standalone/cli_output
55 | tmp
56 | log
57 | *.log
58 | embedded-cassandra.log*
59 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 |
2 |
3 | Apache License
4 | Version 2.0, January 2004
5 | http://www.apache.org/licenses/
6 |
7 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8 |
9 | 1. Definitions.
10 |
11 | "License" shall mean the terms and conditions for use, reproduction,
12 | and distribution as defined by Sections 1 through 9 of this document.
13 |
14 | "Licensor" shall mean the copyright owner or entity authorized by
15 | the copyright owner that is granting the License.
16 |
17 | "Legal Entity" shall mean the union of the acting entity and all
18 | other entities that control, are controlled by, or are under common
19 | control with that entity. For the purposes of this definition,
20 | "control" means (i) the power, direct or indirect, to cause the
21 | direction or management of such entity, whether by contract or
22 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
23 | outstanding shares, or (iii) beneficial ownership of such entity.
24 |
25 | "You" (or "Your") shall mean an individual or Legal Entity
26 | exercising permissions granted by this License.
27 |
28 | "Source" form shall mean the preferred form for making modifications,
29 | including but not limited to software source code, documentation
30 | source, and configuration files.
31 |
32 | "Object" form shall mean any form resulting from mechanical
33 | transformation or translation of a Source form, including but
34 | not limited to compiled object code, generated documentation,
35 | and conversions to other media types.
36 |
37 | "Work" shall mean the work of authorship, whether in Source or
38 | Object form, made available under the License, as indicated by a
39 | copyright notice that is included in or attached to the work
40 | (an example is provided in the Appendix below).
41 |
42 | "Derivative Works" shall mean any work, whether in Source or Object
43 | form, that is based on (or derived from) the Work and for which the
44 | editorial revisions, annotations, elaborations, or other modifications
45 | represent, as a whole, an original work of authorship. For the purposes
46 | of this License, Derivative Works shall not include works that remain
47 | separable from, or merely link (or bind by name) to the interfaces of,
48 | the Work and Derivative Works thereof.
49 |
50 | "Contribution" shall mean any work of authorship, including
51 | the original version of the Work and any modifications or additions
52 | to that Work or Derivative Works thereof, that is intentionally
53 | submitted to Licensor for inclusion in the Work by the copyright owner
54 | or by an individual or Legal Entity authorized to submit on behalf of
55 | the copyright owner. For the purposes of this definition, "submitted"
56 | means any form of electronic, verbal, or written communication sent
57 | to the Licensor or its representatives, including but not limited to
58 | communication on electronic mailing lists, source code control systems,
59 | and issue tracking systems that are managed by, or on behalf of, the
60 | Licensor for the purpose of discussing and improving the Work, but
61 | excluding communication that is conspicuously marked or otherwise
62 | designated in writing by the copyright owner as "Not a Contribution."
63 |
64 | "Contributor" shall mean Licensor and any individual or Legal Entity
65 | on behalf of whom a Contribution has been received by Licensor and
66 | subsequently incorporated within the Work.
67 |
68 | 2. Grant of Copyright License. Subject to the terms and conditions of
69 | this License, each Contributor hereby grants to You a perpetual,
70 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
71 | copyright license to reproduce, prepare Derivative Works of,
72 | publicly display, publicly perform, sublicense, and distribute the
73 | Work and such Derivative Works in Source or Object form.
74 |
75 | 3. Grant of Patent License. Subject to the terms and conditions of
76 | this License, each Contributor hereby grants to You a perpetual,
77 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
78 | (except as stated in this section) patent license to make, have made,
79 | use, offer to sell, sell, import, and otherwise transfer the Work,
80 | where such license applies only to those patent claims licensable
81 | by such Contributor that are necessarily infringed by their
82 | Contribution(s) alone or by combination of their Contribution(s)
83 | with the Work to which such Contribution(s) was submitted. If You
84 | institute patent litigation against any entity (including a
85 | cross-claim or counterclaim in a lawsuit) alleging that the Work
86 | or a Contribution incorporated within the Work constitutes direct
87 | or contributory patent infringement, then any patent licenses
88 | granted to You under this License for that Work shall terminate
89 | as of the date such litigation is filed.
90 |
91 | 4. Redistribution. You may reproduce and distribute copies of the
92 | Work or Derivative Works thereof in any medium, with or without
93 | modifications, and in Source or Object form, provided that You
94 | meet the following conditions:
95 |
96 | (a) You must give any other recipients of the Work or
97 | Derivative Works a copy of this License; and
98 |
99 | (b) You must cause any modified files to carry prominent notices
100 | stating that You changed the files; and
101 |
102 | (c) You must retain, in the Source form of any Derivative Works
103 | that You distribute, all copyright, patent, trademark, and
104 | attribution notices from the Source form of the Work,
105 | excluding those notices that do not pertain to any part of
106 | the Derivative Works; and
107 |
108 | (d) If the Work includes a "NOTICE" text file as part of its
109 | distribution, then any Derivative Works that You distribute must
110 | include a readable copy of the attribution notices contained
111 | within such NOTICE file, excluding those notices that do not
112 | pertain to any part of the Derivative Works, in at least one
113 | of the following places: within a NOTICE text file distributed
114 | as part of the Derivative Works; within the Source form or
115 | documentation, if provided along with the Derivative Works; or,
116 | within a display generated by the Derivative Works, if and
117 | wherever such third-party notices normally appear. The contents
118 | of the NOTICE file are for informational purposes only and
119 | do not modify the License. You may add Your own attribution
120 | notices within Derivative Works that You distribute, alongside
121 | or as an addendum to the NOTICE text from the Work, provided
122 | that such additional attribution notices cannot be construed
123 | as modifying the License.
124 |
125 | You may add Your own copyright statement to Your modifications and
126 | may provide additional or different license terms and conditions
127 | for use, reproduction, or distribution of Your modifications, or
128 | for any such Derivative Works as a whole, provided Your use,
129 | reproduction, and distribution of the Work otherwise complies with
130 | the conditions stated in this License.
131 |
132 | 5. Submission of Contributions. Unless You explicitly state otherwise,
133 | any Contribution intentionally submitted for inclusion in the Work
134 | by You to the Licensor shall be under the terms and conditions of
135 | this License, without any additional terms or conditions.
136 | Notwithstanding the above, nothing herein shall supersede or modify
137 | the terms of any separate license agreement you may have executed
138 | with Licensor regarding such Contributions.
139 |
140 | 6. Trademarks. This License does not grant permission to use the trade
141 | names, trademarks, service marks, or product names of the Licensor,
142 | except as required for reasonable and customary use in describing the
143 | origin of the Work and reproducing the content of the NOTICE file.
144 |
145 | 7. Disclaimer of Warranty. Unless required by applicable law or
146 | agreed to in writing, Licensor provides the Work (and each
147 | Contributor provides its Contributions) on an "AS IS" BASIS,
148 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
149 | implied, including, without limitation, any warranties or conditions
150 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
151 | PARTICULAR PURPOSE. You are solely responsible for determining the
152 | appropriateness of using or redistributing the Work and assume any
153 | risks associated with Your exercise of permissions under this License.
154 |
155 | 8. Limitation of Liability. In no event and under no legal theory,
156 | whether in tort (including negligence), contract, or otherwise,
157 | unless required by applicable law (such as deliberate and grossly
158 | negligent acts) or agreed to in writing, shall any Contributor be
159 | liable to You for damages, including any direct, indirect, special,
160 | incidental, or consequential damages of any character arising as a
161 | result of this License or out of the use or inability to use the
162 | Work (including but not limited to damages for loss of goodwill,
163 | work stoppage, computer failure or malfunction, or any and all
164 | other commercial damages or losses), even if such Contributor
165 | has been advised of the possibility of such damages.
166 |
167 | 9. Accepting Warranty or Additional Liability. While redistributing
168 | the Work or Derivative Works thereof, You may choose to offer,
169 | and charge a fee for, acceptance of support, warranty, indemnity,
170 | or other liability obligations and/or rights consistent with this
171 | License. However, in accepting such obligations, You may act only
172 | on Your own behalf and on Your sole responsibility, not on behalf
173 | of any other Contributor, and only if You agree to indemnify,
174 | defend, and hold each Contributor harmless for any liability
175 | incurred by, or claims asserted against, such Contributor by reason
176 | of your accepting any such warranty or additional liability.
177 |
178 | END OF TERMS AND CONDITIONS
179 |
180 | APPENDIX: How to apply the Apache License to your work.
181 |
182 | To apply the Apache License to your work, attach the following
183 | boilerplate notice, with the fields enclosed by brackets "[]"
184 | replaced with your own identifying information. (Don't include
185 | the brackets!) The text should be enclosed in the appropriate
186 | comment syntax for the file format. We also recommend that a
187 | file or class name and description of purpose be included on the
188 | same "printed page" as the copyright notice for easier
189 | identification within third-party archives.
190 |
191 | Copyright [yyyy] [name of copyright owner]
192 |
193 | Licensed under the Apache License, Version 2.0 (the "License");
194 | you may not use this file except in compliance with the License.
195 | You may obtain a copy of the License at
196 |
197 | http://www.apache.org/licenses/LICENSE-2.0
198 |
199 | Unless required by applicable law or agreed to in writing, software
200 | distributed under the License is distributed on an "AS IS" BASIS,
201 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
202 | See the License for the specific language governing permissions and
203 | limitations under the License.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # WildFly Swarm
2 |
3 | [](https://projectodd.ci.cloudbees.com/job/wildfly-swarm)
4 | [](http://www.apache.org/licenses/LICENSE-2.0)
5 | [](https://maven-badges.herokuapp.com/maven-central/org.wildfly.swarm/bom-parent)
6 |
7 | This repository includes:
8 |
9 | * BOM - All project artifacts with their respective versions. Main use is for dependency management import into user applications
10 | * fraction-list - Generates all fractions with their dependencies, and provides a way to read it programmatically
11 | * plugin - Maven plugin for packaging, and starting/stopping the container for running tests
12 | * swarmtool - Command line tool for building a WildFly Swarm uber jar
13 |
--------------------------------------------------------------------------------
/bom/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 | 4.0.0
9 |
10 |
11 | org.wildfly.swarm
12 | bom-parent
13 | 1.0.1-SNAPSHOT
14 | ../
15 |
16 |
17 | bom
18 |
19 | WildFly Swarm: BOM Generator
20 | WildFly Swarm: BOM Generator
21 |
22 | jar
23 |
24 |
25 |
26 |
27 | src/main/resources
28 | true
29 |
30 |
31 |
32 |
33 | org.wildfly.swarm
34 | wildfly-swarm-fraction-plugin
35 |
36 |
37 | generate-bom
38 | prepare-package
39 |
40 | generate-bom
41 |
42 |
43 | ${project.build.outputDirectory}/bom-template.xml
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 | org.apache.maven.wagon
53 | wagon-webdav-jackrabbit
54 | 2.10
55 |
56 |
57 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/bom/src/main/resources/bom-template.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 | 4.0.0
9 |
10 |
11 | org.wildfly.swarm
12 | parent
13 | ${project.parent.parent.version}
14 |
15 |
16 |
17 | org.wildfly.swarm
18 | bom
19 | ${project.version}
20 |
21 | WildFly Swarm: BOM for Fractions
22 | WildFly Swarm: BOM for Fractions
23 |
24 | pom
25 |
26 | http://wildfly-swarm.io/
27 |
28 |
29 | wildfly-swarm.io
30 | WildFly Swarm Community
31 | WildFly Swarm
32 | http://wildfly-swarm.io/
33 |
34 |
35 |
36 |
37 | scm:git:git@github.com:wildfly-swarm/wildfly-swarm.git
38 | scm:git:git@github.com:wildfly-swarm/wildfly-swarm.git
39 | https://github.com/wildfly-swarm/wildfly-swarm
40 | ${project.scm.tag}
41 |
42 |
43 |
44 |
45 | AL2
46 |
47 |
48 |
49 |
50 | 1.2.6
51 | 2.0.0-alpha-9
52 |
53 |
54 |
55 |
56 | #{dependencies}
57 |
58 | org.jboss.shrinkwrap
59 | shrinkwrap-bom
60 | ${version.shrinkwrap}
61 | pom
62 | import
63 |
64 |
65 | org.jboss.shrinkwrap.descriptors
66 | shrinkwrap-descriptors-bom
67 | ${version.shrinkwrap-descriptors}
68 | pom
69 | import
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 | org.apache.maven.wagon
78 | wagon-webdav-jackrabbit
79 | 2.10
80 |
81 |
82 |
83 |
84 |
85 |
--------------------------------------------------------------------------------
/fraction-list/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 | 4.0.0
9 |
10 |
11 | org.wildfly.swarm
12 | bom-parent
13 | 1.0.1-SNAPSHOT
14 | ../
15 |
16 |
17 | org.wildfly.swarm
18 | fraction-list
19 |
20 | WildFly Swarm: Fraction List
21 | WildFly Swarm: Fraction List
22 |
23 | jar
24 |
25 |
26 |
27 | org.wildfly.swarm
28 | tools
29 |
30 |
31 | com.eclipsesource.minimal-json
32 | minimal-json
33 | 0.9.4
34 |
35 |
36 |
37 |
38 |
39 |
40 | org.wildfly.swarm
41 | wildfly-swarm-fraction-plugin
42 |
43 |
44 | fraction-list
45 | generate-resources
46 |
47 | fraction-list
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/fraction-list/src/main/java/org/wildfly/swarm/fractionlist/FractionList.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2015-2016 Red Hat, Inc, and individual contributors.
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 | * http://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 | package org.wildfly.swarm.fractionlist;
17 |
18 | import java.io.BufferedReader;
19 | import java.io.IOException;
20 | import java.io.InputStream;
21 | import java.io.InputStreamReader;
22 | import java.util.Collection;
23 | import java.util.Collections;
24 | import java.util.HashMap;
25 | import java.util.Map;
26 | import java.util.TreeMap;
27 | import java.util.concurrent.atomic.AtomicReference;
28 | import java.util.stream.Collectors;
29 |
30 | import com.eclipsesource.json.Json;
31 | import com.eclipsesource.json.JsonObject;
32 | import com.eclipsesource.json.JsonValue;
33 | import org.wildfly.swarm.tools.FractionDescriptor;
34 | import org.wildfly.swarm.tools.PropertiesUtil;
35 |
36 | /**
37 | * @author Bob McWhirter
38 | */
39 | public class FractionList implements org.wildfly.swarm.tools.FractionList {
40 |
41 | private final Map descriptors = new TreeMap<>();
42 |
43 | private static final AtomicReference INSTANCE = new AtomicReference<>();
44 |
45 | public static FractionList get() {
46 | return INSTANCE.updateAndGet(old -> old != null ? old : new FractionList());
47 | }
48 |
49 | private FractionList() {
50 | try (InputStreamReader reader = new InputStreamReader(getClass().getClassLoader().getResourceAsStream("fraction-list.json"))) {
51 | Json.parse(reader).asArray().forEach(entry -> {
52 | JsonObject fraction = entry.asObject();
53 | String groupId = toString(fraction.get("groupId"));
54 | String artifactId = toString(fraction.get("artifactId"));
55 | String version = toString(fraction.get("version"));
56 | String name = toString(fraction.get("name"));
57 | String description = toString(fraction.get("description"));
58 | String tags = toString(fraction.get("tags"));
59 | boolean internal = toBoolean(fraction.get("internal"));
60 | FractionDescriptor fd = new FractionDescriptor(groupId, artifactId, version, name, description, tags, internal);
61 | descriptors.put(groupId + ":" + artifactId, fd);
62 | });
63 | } catch (IOException e) {
64 | throw new RuntimeException(e);
65 | }
66 | // Set up dependencies
67 | try (BufferedReader reader = new BufferedReader(new InputStreamReader(getClass().getClassLoader().getResourceAsStream("fraction-list.txt")))) {
68 |
69 | String line = null;
70 |
71 | while ((line = reader.readLine()) != null) {
72 | line = line.trim();
73 | if (line.isEmpty()) {
74 | continue;
75 | }
76 |
77 | String[] sides = line.split("=");
78 |
79 | String lhs = sides[0].trim();
80 | String lhsKey = toKey(lhs);
81 | FractionDescriptor desc = this.descriptors.get(lhsKey);
82 | if (desc == null) {
83 | String[] gavParts = lhs.split(":");
84 | desc = new FractionDescriptor(gavParts[0], gavParts[1], gavParts[2]);
85 | this.descriptors.put(lhsKey, desc);
86 | }
87 |
88 | if (sides.length > 1) {
89 | String rhs = sides[1].trim();
90 | String[] deps = rhs.split(",");
91 |
92 | for (String dep : deps) {
93 | dep = dep.trim();
94 | if (dep.isEmpty()) {
95 | continue;
96 | }
97 | String depKey = toKey(dep);
98 | FractionDescriptor depDesc = this.descriptors.get(depKey);
99 | if (depDesc == null) {
100 | String[] gavParts = dep.split(":");
101 | depDesc = new FractionDescriptor(gavParts[0], gavParts[1], gavParts[2]);
102 | this.descriptors.put(depKey, depDesc);
103 | }
104 | desc.addDependency(depDesc);
105 | }
106 | }
107 | }
108 | } catch (IOException e) {
109 | throw new RuntimeException(e);
110 | }
111 | }
112 |
113 | private boolean toBoolean(JsonValue jsonValue) {
114 | return jsonValue.isNull() ? false : jsonValue.asBoolean();
115 | }
116 |
117 | private String toString(JsonValue jsonValue) {
118 | return jsonValue.isNull() ? null : jsonValue.asString();
119 | }
120 | /**
121 | * @param a groupId:artifactId:version string
122 | * @return the groupId:artifactId
123 | */
124 | private String toKey(String gav) {
125 | return gav.substring(0, gav.lastIndexOf(':'));
126 | }
127 |
128 | @Override
129 | public Collection getFractionDescriptors() {
130 | return Collections.unmodifiableCollection(this.descriptors.values());
131 | }
132 |
133 | @Override
134 | public FractionDescriptor getFractionDescriptor(final String groupId, final String artifactId) {
135 | return this.descriptors.get(groupId + ":" + artifactId);
136 | }
137 |
138 | @Override
139 | public Map getPackageSpecs() {
140 | final Map packageSpecs = loadPackageSpecs();
141 |
142 | return this.descriptors.values().stream()
143 | .filter(fd -> packageSpecs.containsKey(fd.getArtifactId()))
144 | .collect(Collectors.toMap(fd -> packageSpecs.get(fd.getArtifactId()),
145 | fd -> fd));
146 | }
147 |
148 | @SuppressWarnings({ "unchecked", "rawtypes" })
149 | private static Map loadPackageSpecs() {
150 | try {
151 | final InputStream in = FractionList.class.getClassLoader()
152 | .getResourceAsStream("org/wildfly/swarm/fractionlist/fraction-packages.properties");
153 |
154 | return new HashMap<>((Map) PropertiesUtil.loadProperties(in));
155 | } catch (IOException e) {
156 | throw new RuntimeException("Failed to load fraction-packages.properties", e);
157 | }
158 |
159 | }
160 | }
161 |
--------------------------------------------------------------------------------
/fraction-list/src/main/resources/org/wildfly/swarm/fractionlist/fraction-packages.properties:
--------------------------------------------------------------------------------
1 | # matchers can be foo+bar, if both are required to activate the fraction, or foo,bar if either will requires the fraction
2 | # can be mixed and matched: some-fraction=foo+bar,baz, with + taking precedence
3 | # If the package ends with *, it is checked as a prefix
4 | # specific-class matchers can be specified with foo.bar:ClassName
5 | batch-jberet=javax.batch
6 | bean-validation=javax.validation*
7 | cdi=javax.inject,javax.enterprise.inject,javax.enterprise.context,javax.enterprise.event
8 | ejb=javax.ejb
9 | ejb-remote=javax.ejb:Remote
10 | infinispan=org.infinispan
11 | javafx=javafx*
12 | jaxrs=javax.ws.rs
13 | jaxrs-cdi=javax.ws.rs+javax.inject
14 | jaxrs-jaxb=javax.ws.rs+javax.xml.bind*
15 | jaxrs-jsonp=javax.ws.rs+javax.json
16 | jpa=javax.persistence
17 | jsf=javax.faces*
18 | mail=javax.mail
19 | messaging=javax.jms
20 | spring=org.springframework*
21 | swagger=io.swagger.annotations
22 | transactions=javax.transaction
23 | undertow=javax.servlet
24 | webservices=javax.jws
25 |
--------------------------------------------------------------------------------
/fraction-list/src/test/java/org/wildfly/swarm/fractionlist/FractionListTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2015-2016 Red Hat, Inc, and individual contributors.
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 | * http://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 | package org.wildfly.swarm.fractionlist;
17 |
18 | import java.io.IOException;
19 | import java.util.Collection;
20 | import java.util.Set;
21 | import java.util.stream.Collectors;
22 |
23 | import org.fest.assertions.ObjectAssert;
24 | import org.junit.Test;
25 | import org.wildfly.swarm.tools.FractionDescriptor;
26 |
27 | import static org.fest.assertions.Assertions.assertThat;
28 |
29 | /**
30 | * @author Bob McWhirter
31 | */
32 | public class FractionListTest {
33 |
34 | @Test
35 | public void testList() throws IOException {
36 | FractionList list = FractionList.get();
37 |
38 | Collection descriptors = list.getFractionDescriptors();
39 |
40 | FractionDescriptor logstash = descriptors.stream().filter(e -> e.getArtifactId().equals("logstash")).findFirst().get();
41 |
42 | assertThat(list.getFractionDescriptor("org.wildfly.swarm", "logstash")).isEqualTo(logstash);
43 |
44 | assertThat(logstash.getGroupId()).isEqualTo("org.wildfly.swarm");
45 | assertThat(logstash.getArtifactId()).isEqualTo("logstash");
46 | assertThat(logstash.getDependencies()).hasSize(2);
47 |
48 | assertThat(logstash.getDependencies().stream().filter(e -> e.getArtifactId().equals("container")).collect(Collectors.toList())).isNotEmpty();
49 | assertThat(logstash.getDependencies().stream().filter(e -> e.getArtifactId().equals("logging")).collect(Collectors.toList())).isNotEmpty();
50 | }
51 |
52 | @Test
53 | public void testMultipleGets() throws IOException {
54 | FractionList l1 = FractionList.get();
55 | FractionList l2 = FractionList.get();
56 | FractionList l3 = FractionList.get();
57 |
58 | assertThat(l1).isNotNull();
59 | assertThat(l1).isSameAs(l2);
60 | assertThat(l2).isSameAs(l3);
61 | }
62 |
63 | @Test
64 | public void testGroupIdAndArtifactIdAndNameAndDescriptionAreNeverNull() throws Exception {
65 | Collection descriptors = FractionList.get().getFractionDescriptors();
66 | assertThat(descriptors).onProperty("groupId").isNotNull();
67 | assertThat(descriptors).onProperty("artifactId").isNotNull();
68 | assertThat(descriptors).onProperty("version").isNotNull();
69 | assertThat(descriptors).onProperty("name").isNotNull();
70 | assertThat(descriptors).onProperty("description").isNotNull();
71 | }
72 | @Test
73 | public void testNameAndDescription() throws Exception {
74 | FractionDescriptor cdi = FractionList.get().getFractionDescriptor("org.wildfly.swarm", "cdi");
75 | assertThat(cdi.getName()).isEqualTo("CDI");
76 | assertThat(cdi.getDescription()).isEqualTo("CDI with Weld");
77 | }
78 |
79 | @Test
80 | public void testEEFractionDependsOnNamingAndContainer() {
81 | FractionDescriptor ee = FractionList.get().getFractionDescriptor("org.wildfly.swarm", "ee");
82 | FractionDescriptor naming = FractionList.get().getFractionDescriptor("org.wildfly.swarm", "naming");
83 | FractionDescriptor container = FractionList.get().getFractionDescriptor("org.wildfly.swarm", "container");
84 | Set dependencies = ee.getDependencies();
85 | assertThat(dependencies).contains(naming, container);
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/plugin/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 | 4.0.0
9 |
10 |
11 | org.wildfly.swarm
12 | bom-parent
13 | 1.0.1-SNAPSHOT
14 | ../
15 |
16 |
17 | org.wildfly.swarm
18 | wildfly-swarm-plugin
19 |
20 | WildFly Swarm: Plugin
21 | WildFly Swarm: Plugin
22 |
23 | maven-plugin
24 |
25 |
26 |
27 | spring-releases
28 | http://repo.spring.io/libs-release-remote/
29 |
30 |
31 | public-jboss
32 | https://repository.jboss.org/nexus/content/groups/public-jboss
33 |
34 |
35 | spring-plugin-releases
36 | http://repo.spring.io/plugins-release/
37 |
38 |
39 |
40 |
41 |
42 |
43 | org.apache.maven.plugins
44 | maven-surefire-plugin
45 |
46 | 0
47 | never
48 |
49 |
50 |
51 | org.apache.maven.plugins
52 | maven-plugin-plugin
53 |
54 |
55 | default-descriptor
56 | process-classes
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 | org.wildfly.swarm
66 | fraction-list
67 | ${project.version}
68 |
69 |
70 | org.wildfly.swarm
71 | tools
72 |
73 |
74 | org.wildfly.swarm
75 | spi-api
76 |
77 |
78 | org.apache.maven
79 | maven-plugin-api
80 | provided
81 |
82 |
83 | org.apache.maven.plugin-tools
84 | maven-plugin-annotations
85 | provided
86 |
87 |
88 | org.apache.maven
89 | maven-core
90 | provided
91 |
92 |
93 | org.gradle
94 | gradle-core
95 | provided
96 |
97 |
98 | org.gradle
99 | gradle-base-services
100 | provided
101 |
102 |
103 | org.gradle
104 | gradle-plugins
105 | provided
106 |
107 |
108 | org.codehaus.groovy
109 | groovy
110 | provided
111 |
112 |
113 | org.codehaus.plexus
114 | plexus-utils
115 | 3.0.20
116 |
117 |
118 | org.eclipse.aether
119 | aether-util
120 | 1.0.0.v20140518
121 |
122 |
123 |
124 |
125 |
--------------------------------------------------------------------------------
/plugin/src/main/java/org/wildfly/swarm/plugin/gradle/GradleArtifactResolvingHelper.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2015-2016 Red Hat, Inc, and individual contributors.
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 | * http://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 | package org.wildfly.swarm.plugin.gradle;
17 |
18 | import java.util.Collection;
19 | import java.util.Collections;
20 | import java.util.HashSet;
21 | import java.util.Iterator;
22 | import java.util.Map;
23 | import java.util.Set;
24 | import java.util.stream.Collectors;
25 |
26 | import org.gradle.api.Action;
27 | import org.gradle.api.Project;
28 | import org.gradle.api.artifacts.Configuration;
29 | import org.gradle.api.artifacts.DependencySet;
30 | import org.gradle.api.artifacts.ResolvedDependency;
31 | import org.gradle.api.artifacts.repositories.MavenArtifactRepository;
32 | import org.gradle.api.internal.artifacts.DefaultExcludeRule;
33 | import org.gradle.api.internal.artifacts.dependencies.DefaultDependencyArtifact;
34 | import org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency;
35 | import org.gradle.api.internal.artifacts.dependencies.DefaultProjectDependency;
36 | import org.gradle.api.internal.project.DefaultProjectAccessListener;
37 | import org.gradle.api.internal.project.ProjectInternal;
38 | import org.wildfly.swarm.tools.ArtifactResolvingHelper;
39 | import org.wildfly.swarm.tools.ArtifactSpec;
40 |
41 | /**
42 | * @author Bob McWhirter
43 | */
44 | public class GradleArtifactResolvingHelper implements ArtifactResolvingHelper {
45 |
46 |
47 | private final Project project;
48 | Map projects;
49 |
50 | public GradleArtifactResolvingHelper(Project project) {
51 | this.project = project;
52 | this.projects = project.getRootProject().getAllprojects().stream().collect(Collectors.toMap(p -> p.getGroup() + ":" + p.getName() + ":" + p.getVersion(), p -> p));
53 | this.project.getRepositories().maven(new Action() {
54 | @Override
55 | public void execute(MavenArtifactRepository repo) {
56 | repo.setName("jboss-public");
57 | repo.setUrl("http://repository.jboss.org/nexus/content/groups/public/");
58 | }
59 | });
60 | }
61 |
62 |
63 | @Override
64 | public ArtifactSpec resolve(final ArtifactSpec spec) {
65 | if (spec.file != null) {
66 | return spec;
67 | }
68 |
69 | final Iterator iterator =
70 | doResolve(new HashSet<>(Collections.singletonList(spec))).iterator();
71 | if (iterator.hasNext()) {
72 | spec.file = iterator.next()
73 | .getModuleArtifacts()
74 | .iterator().next()
75 | .getFile();
76 |
77 | return spec;
78 | }
79 |
80 | return null;
81 | }
82 |
83 | @Override
84 | public Set resolveAll(final Set specs) throws Exception {
85 | if (specs.isEmpty()) {
86 |
87 | return specs;
88 | }
89 |
90 | final Set resolvedSpecs = new HashSet<>();
91 |
92 | doResolve(specs).forEach(dep -> dep.getModuleArtifacts()
93 | .forEach(artifact -> resolvedSpecs
94 | .add(new ArtifactSpec(dep.getConfiguration(),
95 | dep.getModuleGroup(),
96 | artifact.getName(),
97 | dep.getModuleVersion(),
98 | artifact.getExtension(),
99 | artifact.getClassifier(),
100 | artifact.getFile()))));
101 |
102 | return resolvedSpecs.stream()
103 | .filter(a -> !"system".equals(a.scope))
104 | .collect(Collectors.toSet());
105 | }
106 |
107 | private Set doResolve(final Collection deps) {
108 | final Configuration config = this.project.getConfigurations().detachedConfiguration();
109 | final DependencySet dependencySet = config.getDependencies();
110 |
111 | deps.stream()
112 | .forEach(spec -> {
113 | if (projects.containsKey(spec.groupId() + ":" + spec.artifactId() + ":" + spec.version())) {
114 | dependencySet.add(new DefaultProjectDependency((ProjectInternal) projects.get(spec.groupId() + ":" + spec.artifactId() + ":" + spec.version()), new DefaultProjectAccessListener(), false));
115 | } else {
116 | final DefaultExternalModuleDependency d =
117 | new DefaultExternalModuleDependency(spec.groupId(), spec.artifactId(), spec.version());
118 | final DefaultDependencyArtifact da =
119 | new DefaultDependencyArtifact(spec.artifactId(), spec.type(), spec.type(), spec.classifier(), null);
120 | d.addArtifact(da);
121 | d.getExcludeRules().add(new DefaultExcludeRule());
122 | dependencySet.add(d);
123 | }
124 | });
125 |
126 | return config.getResolvedConfiguration().getFirstLevelModuleDependencies();
127 | }
128 |
129 | }
130 |
--------------------------------------------------------------------------------
/plugin/src/main/java/org/wildfly/swarm/plugin/gradle/PackagePlugin.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2015-2016 Red Hat, Inc, and individual contributors.
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 | * http://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 | package org.wildfly.swarm.plugin.gradle;
17 |
18 | import org.gradle.api.Plugin;
19 | import org.gradle.api.Project;
20 | import org.gradle.api.tasks.TaskContainer;
21 | import org.gradle.api.tasks.bundling.Jar;
22 |
23 | /**
24 | * @author Bob McWhirter
25 | */
26 | public class PackagePlugin implements Plugin {
27 |
28 | @Override
29 | public void apply(Project project) {
30 | project.getExtensions().create("swarm", SwarmExtension.class);
31 | project.afterEvaluate(__ -> {
32 | final TaskContainer tasks = project.getTasks();
33 | final PackageTask packageTask = tasks.create("wildfly-swarm-package", PackageTask.class);
34 | tasks.withType(Jar.class, task -> packageTask.jarTask(task).dependsOn(task));
35 | tasks.getByName("build").dependsOn(packageTask);
36 | });
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/plugin/src/main/java/org/wildfly/swarm/plugin/gradle/PackageTask.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2015-2016 Red Hat, Inc, and individual contributors.
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 | * http://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 | package org.wildfly.swarm.plugin.gradle;
17 |
18 | import java.io.File;
19 | import java.io.IOException;
20 | import java.util.Properties;
21 | import java.util.Set;
22 | import java.util.stream.Collectors;
23 |
24 | import org.gradle.api.DefaultTask;
25 | import org.gradle.api.Project;
26 | import org.gradle.api.Task;
27 | import org.gradle.api.artifacts.ResolvedArtifact;
28 | import org.gradle.api.artifacts.ResolvedDependency;
29 | import org.gradle.api.plugins.ApplicationPluginConvention;
30 | import org.gradle.api.tasks.TaskAction;
31 | import org.gradle.api.tasks.bundling.Jar;
32 | import org.wildfly.swarm.fractionlist.FractionList;
33 | import org.wildfly.swarm.tools.PropertiesUtil;
34 | import org.wildfly.swarm.tools.BuildTool;
35 |
36 | /**
37 | * @author Bob McWhirter
38 | */
39 | public class PackageTask extends DefaultTask {
40 |
41 | private BuildTool tool;
42 |
43 | private Jar jarTask;
44 |
45 | public Task jarTask(Jar jarTask) {
46 | this.jarTask = jarTask;
47 |
48 | return this;
49 | }
50 |
51 |
52 | @TaskAction
53 | public void packageForSwarm() throws Exception {
54 | final Project project = getProject();
55 | final SwarmExtension ext = (SwarmExtension) project.getExtensions().getByName("swarm");
56 |
57 | if (ext.getMainClassName() == null) {
58 | if (project.getConvention().getPlugins().containsKey("application")) {
59 | ApplicationPluginConvention app = (ApplicationPluginConvention) project.getConvention().getPlugins().get("application");
60 | ext.setMainClassName(app.getMainClassName());
61 | }
62 | }
63 |
64 | final Properties fromFile = new Properties();
65 | if (ext.getPropertiesFile() != null) {
66 | try {
67 | fromFile.putAll(PropertiesUtil.loadProperties(ext.getPropertiesFile()));
68 | } catch (IOException e) {
69 | getLogger().error("Failed to load properties from " + ext.getPropertiesFile(), e);
70 | }
71 | }
72 |
73 | this.tool = new BuildTool()
74 | .artifactResolvingHelper(new GradleArtifactResolvingHelper(project))
75 | .projectArtifact(project.getGroup().toString(), project.getName(), project.getVersion().toString(),
76 | jarTask.getExtension(), jarTask.getArchivePath())
77 | .mainClass(ext.getMainClassName())
78 | .bundleDependencies(ext.getBundleDependencies())
79 | .executable(ext.getExecutable())
80 | .executableScript(ext.getExecutableScript())
81 | .properties(ext.getProperties())
82 | .properties(fromFile)
83 | .properties(PropertiesUtil.filteredSystemProperties(ext.getProperties(), false))
84 | .fractionList(FractionList.get())
85 | .fractionDetectionMode(BuildTool.FractionDetectionMode.when_missing)
86 | .additionalModules(ext.getModuleDirs().stream()
87 | .map(File::getAbsolutePath)
88 | .collect(Collectors.toList()))
89 | .logger(new BuildTool.SimpleLogger() {
90 | @Override
91 | public void info(String msg) {
92 | getLogger().info(msg);
93 | }
94 |
95 | @Override
96 | public void error(String msg) {
97 | getLogger().error(msg);
98 | }
99 |
100 | @Override
101 | public void error(String msg, Throwable t) {
102 | getLogger().error(msg, t);
103 | }
104 | });
105 |
106 | project.getConfigurations()
107 | .getByName("compile")
108 | .getResolvedConfiguration()
109 | .getFirstLevelModuleDependencies()
110 | .forEach(this::walk);
111 |
112 | final Boolean bundleDependencies = ext.getBundleDependencies();
113 | if (bundleDependencies != null) {
114 | this.tool.bundleDependencies(bundleDependencies);
115 | }
116 |
117 | this.tool.build(project.getName(), project.getBuildDir().toPath().resolve("libs"));
118 | }
119 |
120 | private void walk(final ResolvedDependency dep) {
121 | Set artifacts = dep.getModuleArtifacts();
122 | for (ResolvedArtifact each : artifacts) {
123 | String[] parts = dep.getName().split(":");
124 | String groupId = parts[0];
125 | String artifactId = parts[1];
126 | String version = parts[2];
127 | this.tool.dependency("compile", groupId, artifactId, version, each.getExtension(),
128 | each.getClassifier(), each.getFile());
129 | }
130 |
131 | dep.getChildren().forEach(this::walk);
132 | }
133 | }
134 |
--------------------------------------------------------------------------------
/plugin/src/main/java/org/wildfly/swarm/plugin/gradle/SwarmExtension.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2015-2016 Red Hat, Inc, and individual contributors.
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 | * http://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 | package org.wildfly.swarm.plugin.gradle;
17 |
18 | import java.io.File;
19 | import java.util.ArrayList;
20 | import java.util.List;
21 | import java.util.Properties;
22 |
23 | import groovy.lang.Closure;
24 | import groovy.util.ConfigObject;
25 |
26 | /**
27 | * @author Bob McWhirter
28 | */
29 | public class SwarmExtension {
30 | private String mainClass;
31 |
32 | private Boolean bundleDependencies = true;
33 |
34 | private Boolean executable = false;
35 |
36 | private File executableScript;
37 |
38 | private Properties properties = new Properties();
39 |
40 | private File propertiesFile;
41 |
42 | private List moduleDirs = new ArrayList<>();
43 |
44 | public SwarmExtension() {
45 |
46 | }
47 |
48 | public void properties(Closure closure) {
49 | ConfigObject config = new ConfigObject();
50 | closure.setResolveStrategy(Closure.DELEGATE_ONLY);
51 | closure.setDelegate(config);
52 | closure.call();
53 | config.flatten(this.properties);
54 | }
55 |
56 | public Properties getProperties() {
57 | return this.properties;
58 | }
59 |
60 | public String getMainClassName() {
61 | return this.mainClass;
62 | }
63 |
64 | public void setMainClassName(String mainClass) {
65 | this.mainClass = mainClass;
66 | }
67 |
68 | public Boolean getBundleDependencies() {
69 | return bundleDependencies;
70 | }
71 |
72 | public void setBundleDependencies(Boolean bundleDependencies) {
73 | this.bundleDependencies = bundleDependencies;
74 | }
75 |
76 | public Boolean getExecutable() {
77 | return executable;
78 | }
79 |
80 | public void setExecutable(Boolean executable) {
81 | this.executable = executable;
82 | }
83 |
84 | public File getExecutableScript() {
85 | return executableScript;
86 | }
87 |
88 | public void setExecutableScript(File executableScript) {
89 | this.executableScript = executableScript;
90 | }
91 |
92 | public File getPropertiesFile() {
93 | return propertiesFile;
94 | }
95 |
96 | public void setPropertiesFile(final File propertiesFile) {
97 | this.propertiesFile = propertiesFile;
98 | }
99 |
100 | public List getModuleDirs() {
101 | return moduleDirs;
102 | }
103 |
104 | public void setModuleDirs(final List moduleDirs) {
105 | this.moduleDirs.clear();
106 | this.moduleDirs.addAll(moduleDirs);
107 | }
108 | }
109 |
--------------------------------------------------------------------------------
/plugin/src/main/java/org/wildfly/swarm/plugin/maven/AbstractSwarmMojo.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2015-2016 Red Hat, Inc, and individual contributors.
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 | * http://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 | package org.wildfly.swarm.plugin.maven;
17 |
18 | import java.io.IOException;
19 | import java.util.ArrayList;
20 | import java.util.List;
21 | import java.util.Properties;
22 |
23 | import javax.inject.Inject;
24 |
25 | import org.apache.maven.artifact.Artifact;
26 | import org.apache.maven.artifact.repository.ArtifactRepository;
27 | import org.apache.maven.execution.MavenSession;
28 | import org.apache.maven.plugin.AbstractMojo;
29 | import org.apache.maven.plugin.MojoFailureException;
30 | import org.apache.maven.plugins.annotations.Component;
31 | import org.apache.maven.plugins.annotations.Parameter;
32 | import org.apache.maven.project.MavenProject;
33 | import org.apache.maven.settings.Proxy;
34 | import org.eclipse.aether.DefaultRepositorySystemSession;
35 | import org.eclipse.aether.RepositorySystem;
36 | import org.eclipse.aether.impl.ArtifactResolver;
37 | import org.eclipse.aether.util.repository.AuthenticationBuilder;
38 | import org.wildfly.swarm.tools.ArtifactSpec;
39 | import org.wildfly.swarm.tools.BuildTool;
40 | import org.wildfly.swarm.tools.PropertiesUtil;
41 |
42 | /**
43 | * @author Bob McWhirter
44 | */
45 | public abstract class AbstractSwarmMojo extends AbstractMojo {
46 |
47 | @Parameter(defaultValue = "${project}", readonly = true)
48 | protected MavenProject project;
49 |
50 | @Parameter(defaultValue = "${repositorySystemSession}", readonly = true)
51 | protected DefaultRepositorySystemSession repositorySystemSession;
52 |
53 | @Parameter(alias = "remoteRepositories", defaultValue = "${project.remoteArtifactRepositories}", readonly = true)
54 | protected List remoteRepositories;
55 |
56 | @Parameter(defaultValue = "${project.build.directory}")
57 | protected String projectBuildDir;
58 |
59 | @Parameter(defaultValue = "${session}", readonly = true)
60 | protected MavenSession mavenSession;
61 |
62 | @Parameter(alias = "mainClass", property = "swarm.mainClass")
63 | protected String mainClass;
64 |
65 | @Parameter(alias = "properties")
66 | protected Properties properties;
67 |
68 | @Parameter(alias = "propertiesFile", property = "swarm.propertiesFile")
69 | protected String propertiesFile;
70 |
71 | @Parameter(alias = "environment")
72 | protected Properties environment;
73 |
74 | @Parameter(alias = "environmentFile", property = "swarm.environmentFile")
75 | protected String environmentFile;
76 |
77 | @Parameter(alias = "modules")
78 | protected List additionalModules = new ArrayList<>();
79 |
80 | @Parameter(alias = "fractions")
81 | protected List additionalFractions = new ArrayList<>();
82 |
83 | @Parameter(defaultValue = "when_missing", property = "swarm.detect.mode")
84 | protected BuildTool.FractionDetectionMode fractionDetectMode;
85 |
86 | @Inject
87 | protected ArtifactResolver resolver;
88 |
89 | @Component
90 | protected RepositorySystem repositorySystem;
91 |
92 | AbstractSwarmMojo() {
93 | if (this.additionalModules.isEmpty()) {
94 | this.additionalModules.add("modules");
95 | }
96 | }
97 |
98 | protected void initProperties(final boolean withMaven) {
99 | if (this.properties == null) {
100 | this.properties = new Properties();
101 | }
102 |
103 | if (this.propertiesFile != null) {
104 | try {
105 | this.properties.putAll(PropertiesUtil.loadProperties(this.propertiesFile));
106 | } catch (IOException e) {
107 | getLog().error("Failed to load properties from " + this.propertiesFile, e);
108 | }
109 | }
110 |
111 | this.properties.putAll(PropertiesUtil.filteredSystemProperties(this.properties, withMaven));
112 | }
113 |
114 | protected void initEnvironment() throws MojoFailureException {
115 | if (this.environment == null) {
116 | this.environment = new Properties();
117 | }
118 | if (this.environmentFile != null) {
119 | try {
120 | this.environment.putAll(PropertiesUtil.loadProperties(this.environmentFile));
121 | } catch (IOException e) {
122 | getLog().error("Failed to load environment from " + this.environmentFile, e);
123 | }
124 | }
125 | }
126 |
127 | // borrowed from https://github.com/forge/furnace/blob/master/manager/resolver/maven/src/main/java/org/jboss/forge/furnace/manager/maven/MavenContainer.java#L216
128 | public static org.eclipse.aether.repository.Proxy convertFromMavenProxy(Proxy proxy) {
129 | if (proxy != null) {
130 | return new org.eclipse.aether.repository.Proxy(proxy.getProtocol(),
131 | proxy.getHost(),
132 | proxy.getPort(),
133 | new AuthenticationBuilder()
134 | .addUsername(proxy.getUsername())
135 | .addPassword(proxy.getPassword())
136 | .build());
137 | }
138 |
139 | return null;
140 | }
141 | protected MavenArtifactResolvingHelper mavenArtifactResolvingHelper() {
142 | MavenArtifactResolvingHelper resolvingHelper =
143 | new MavenArtifactResolvingHelper(this.resolver,
144 | this.repositorySystem,
145 | this.repositorySystemSession,
146 | convertFromMavenProxy(this.mavenSession.getSettings().getActiveProxy()));
147 | this.remoteRepositories.forEach(resolvingHelper::remoteRepository);
148 |
149 | return resolvingHelper;
150 | }
151 |
152 | protected ArtifactSpec artifactToArtifactSpec(Artifact dep) {
153 | return new ArtifactSpec(dep.getScope(),
154 | dep.getGroupId(),
155 | dep.getArtifactId(),
156 | dep.getBaseVersion(),
157 | dep.getType(),
158 | dep.getClassifier(),
159 | dep.getFile());
160 | }
161 | }
162 |
--------------------------------------------------------------------------------
/plugin/src/main/java/org/wildfly/swarm/plugin/maven/AnalyzeMojo.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2015-2016 Red Hat, Inc, and individual contributors.
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 | * http://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 | package org.wildfly.swarm.plugin.maven;
17 |
18 | import java.io.BufferedReader;
19 | import java.io.File;
20 | import java.io.FileInputStream;
21 | import java.io.IOException;
22 | import java.io.InputStream;
23 | import java.io.InputStreamReader;
24 | import java.nio.file.FileVisitResult;
25 | import java.nio.file.Files;
26 | import java.nio.file.Path;
27 | import java.nio.file.Paths;
28 | import java.nio.file.SimpleFileVisitor;
29 | import java.nio.file.attribute.BasicFileAttributes;
30 | import java.util.Enumeration;
31 | import java.util.Set;
32 | import java.util.jar.JarEntry;
33 | import java.util.jar.JarFile;
34 | import java.util.regex.Matcher;
35 | import java.util.regex.Pattern;
36 |
37 | import org.apache.maven.artifact.Artifact;
38 | import org.apache.maven.plugin.AbstractMojo;
39 | import org.apache.maven.plugin.MojoExecutionException;
40 | import org.apache.maven.plugin.MojoFailureException;
41 | import org.apache.maven.plugins.annotations.Execute;
42 | import org.apache.maven.plugins.annotations.LifecyclePhase;
43 | import org.apache.maven.plugins.annotations.Mojo;
44 | import org.apache.maven.plugins.annotations.Parameter;
45 | import org.apache.maven.plugins.annotations.ResolutionScope;
46 | import org.apache.maven.project.MavenProject;
47 |
48 | /**
49 | * @author Bob McWhirter
50 | */
51 | @Mojo(name = "analyze",
52 | requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME,
53 | requiresDependencyCollection = ResolutionScope.COMPILE_PLUS_RUNTIME)
54 | @Execute(phase = LifecyclePhase.PACKAGE)
55 | public class AnalyzeMojo extends AbstractMojo {
56 |
57 | private static Pattern ARTIFACT = Pattern.compile("() {
102 | @Override
103 | public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
104 | if (file.getFileName().toString().equals("module.xml")) {
105 | Path dir = file.getParent();
106 | Path relative = modulesDir.relativize(dir);
107 | String slot = relative.getFileName().toString();
108 | String module = relative.getParent().toString().replace(File.separatorChar, '.');
109 | analyzeModuleXml(module, slot, new FileInputStream(file.toFile()));
110 | }
111 | return super.visitFile(file, attrs);
112 | }
113 | });
114 | }
115 |
116 | protected void walkDependencies() throws IOException {
117 | Set deps = this.project.getArtifacts();
118 |
119 | for (Artifact each : deps) {
120 | walkDependency(each);
121 | }
122 | }
123 |
124 | protected void walkDependency(Artifact artifact) throws IOException {
125 |
126 | if (artifact.getFile() != null && artifact.getType().equals("jar")) {
127 |
128 | try (JarFile jar = new JarFile(artifact.getFile())) {
129 | Enumeration entries = jar.entries();
130 |
131 | while (entries.hasMoreElements()) {
132 | JarEntry entry = entries.nextElement();
133 | if (entry.getName().startsWith("modules/") && entry.getName().endsWith("module.xml")) {
134 | String[] parts = entry.getName().split("/");
135 |
136 | String slot = parts[parts.length - 2];
137 | String module = null;
138 | for (int i = 1; i < parts.length - 2; ++i) {
139 | if (module != null) {
140 | module = module + ".";
141 | ;
142 | } else {
143 | module = "";
144 | }
145 | module = module + parts[i];
146 | }
147 |
148 | analyzeModuleXml(module, slot, jar.getInputStream(entry));
149 | }
150 | }
151 | }
152 | }
153 |
154 | }
155 |
156 | protected void analyzeModuleXml(String module, String slot, InputStream in) throws IOException {
157 | Graph.Module curModule = this.graph.getModule(module, slot);
158 | try (BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {
159 | String line = null;
160 | while ((line = reader.readLine()) != null) {
161 | Matcher matcher = null;
162 |
163 | matcher = ARTIFACT.matcher(line);
164 | if (matcher.find()) {
165 | String gav = matcher.group(1);
166 | String parts[] = gav.split(":");
167 |
168 | String groupId = parts[0];
169 | String artifactId = parts[1];
170 | String version = parts[2];
171 | String classifier = null;
172 | if (parts.length >= 4) {
173 | classifier = parts[3];
174 | }
175 |
176 | curModule.addArtifact(this.graph.getArtifact(groupId, artifactId, version, classifier));
177 | } else {
178 | matcher = MODULE.matcher(line);
179 | if (matcher.find()) {
180 | String depModule = matcher.group(1);
181 | String depSlot = "main";
182 | if (matcher.groupCount() >= 3) {
183 | depSlot = matcher.group(3);
184 | }
185 | curModule.addDependency(this.graph.getModule(depModule, depSlot));
186 | }
187 | }
188 | }
189 | }
190 | }
191 |
192 | }
193 |
--------------------------------------------------------------------------------
/plugin/src/main/java/org/wildfly/swarm/plugin/maven/DumpGraphVisitor.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2015-2016 Red Hat, Inc, and individual contributors.
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 | * http://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 | package org.wildfly.swarm.plugin.maven;
17 |
18 | import java.util.HashSet;
19 | import java.util.Set;
20 |
21 | /**
22 | * @author Bob McWhirter
23 | */
24 | public class DumpGraphVisitor implements GraphVisitor {
25 |
26 | private int indent;
27 |
28 | private Set seen = new HashSet<>();
29 |
30 | public DumpGraphVisitor() {
31 | this.indent = 0;
32 | }
33 |
34 | @Override
35 | public void visit(Graph graph) {
36 |
37 | }
38 |
39 | @Override
40 | public void visit(Graph.Module module) {
41 | System.err.println(spacer() + module.getID());
42 |
43 | if (this.seen.contains(module)) {
44 | return;
45 | }
46 |
47 | this.seen.add(module);
48 |
49 | ++this.indent;
50 |
51 | for (Graph.Module each : module.getDependents()) {
52 | each.accept(this);
53 | }
54 |
55 | --this.indent;
56 | }
57 |
58 | @Override
59 | public void visit(Graph.Artifact artifact) {
60 | System.err.println(spacer() + artifact.getGAV());
61 |
62 | ++this.indent;
63 |
64 | for (Graph.Module each : artifact.getDependents()) {
65 | each.accept(this);
66 | }
67 |
68 | --this.indent;
69 |
70 | }
71 |
72 | private String spacer() {
73 | String spacer = "";
74 | for (int i = 0; i < this.indent; ++i) {
75 | spacer = spacer + " ";
76 | }
77 |
78 | return spacer;
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/plugin/src/main/java/org/wildfly/swarm/plugin/maven/Graph.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2015-2016 Red Hat, Inc, and individual contributors.
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 | * http://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 | package org.wildfly.swarm.plugin.maven;
17 |
18 | import java.util.HashMap;
19 | import java.util.HashSet;
20 | import java.util.Map;
21 | import java.util.Set;
22 |
23 | /**
24 | * @author Bob McWhirter
25 | */
26 | public class Graph {
27 |
28 | private Map modules = new HashMap<>();
29 |
30 | private Map artifacts = new HashMap<>();
31 |
32 | public Graph() {
33 |
34 | }
35 |
36 | public void accept(GraphVisitor visitor) {
37 | visitor.visit(this);
38 | }
39 |
40 | public Artifact getClosestArtifact(String gav) {
41 |
42 | Set keys = this.artifacts.keySet();
43 | for (String each : keys) {
44 | if (each.startsWith(gav)) {
45 | return this.artifacts.get(each);
46 | }
47 | }
48 |
49 | return null;
50 | }
51 |
52 | public Artifact getArtifact(String groupId, String artifactId, String version, String classifier) {
53 | String key = groupId + ":" + artifactId + ":" + version;
54 | if (classifier != null) {
55 | key = key + ":" + classifier;
56 | }
57 |
58 | Artifact a = this.artifacts.get(key);
59 | if (a == null) {
60 | a = new Artifact(groupId, artifactId, version, classifier);
61 | this.artifacts.put(key, a);
62 | }
63 |
64 | return a;
65 | }
66 |
67 | public Module getModule(String module, String slot) {
68 |
69 | Module m = this.modules.get(module + ":" + slot);
70 | if (m == null) {
71 | m = new Module(module, slot);
72 | this.modules.put(module + ":" + slot, m);
73 | }
74 |
75 | return m;
76 |
77 | }
78 |
79 | public class Module {
80 |
81 | private final String module;
82 |
83 | private final String slot;
84 |
85 | private Set artifacts = new HashSet<>();
86 |
87 | private Set dependencies = new HashSet<>();
88 |
89 | private Set dependents = new HashSet<>();
90 |
91 | public Module(String module, String slot) {
92 | this.module = module;
93 | this.slot = slot;
94 | }
95 |
96 | public String getID() {
97 | return this.module + ":" + this.slot;
98 | }
99 |
100 | public void addArtifact(Artifact artifact) {
101 | this.artifacts.add(artifact);
102 | artifact.addDependent(this);
103 | }
104 |
105 | public void addDependency(Module module) {
106 | this.dependencies.add(module);
107 | module.addDependent(this);
108 | }
109 |
110 | void addDependent(Module module) {
111 | this.dependents.add(module);
112 | }
113 |
114 | public Set getDependents() {
115 | return this.dependents;
116 | }
117 |
118 | public void accept(GraphVisitor visitor) {
119 | visitor.visit(this);
120 | }
121 | }
122 |
123 | public class Artifact {
124 |
125 | private final String groupId;
126 |
127 | private final String artifactId;
128 |
129 | private final String version;
130 |
131 | private final String classifier;
132 |
133 | private Set dependents = new HashSet<>();
134 |
135 | public Artifact(String groupId, String artifactId, String version, String classifier) {
136 | this.groupId = groupId;
137 | this.artifactId = artifactId;
138 | this.version = version;
139 | this.classifier = classifier;
140 | }
141 |
142 | public String getGAV() {
143 | String gav = this.groupId + ":" + this.artifactId + ":" + this.version;
144 | if (this.classifier != null) {
145 | gav = gav + ":" + this.classifier;
146 | }
147 |
148 | return gav;
149 | }
150 |
151 | void addDependent(Module module) {
152 | this.dependents.add(module);
153 | }
154 |
155 | public Set getDependents() {
156 | return this.dependents;
157 | }
158 |
159 | public void accept(GraphVisitor visitor) {
160 | visitor.visit(this);
161 | }
162 | }
163 |
164 |
165 | }
166 |
--------------------------------------------------------------------------------
/plugin/src/main/java/org/wildfly/swarm/plugin/maven/GraphVisitor.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2015-2016 Red Hat, Inc, and individual contributors.
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 | * http://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 | package org.wildfly.swarm.plugin.maven;
17 |
18 | /**
19 | * @author Bob McWhirter
20 | */
21 | public interface GraphVisitor {
22 |
23 | void visit(Graph graph);
24 |
25 | void visit(Graph.Module module);
26 |
27 | void visit(Graph.Artifact artifact);
28 | }
29 |
--------------------------------------------------------------------------------
/plugin/src/main/java/org/wildfly/swarm/plugin/maven/MavenArtifactResolvingHelper.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2015-2016 Red Hat, Inc, and individual contributors.
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 | * http://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 | package org.wildfly.swarm.plugin.maven;
17 |
18 | import java.util.ArrayList;
19 | import java.util.List;
20 | import java.util.Set;
21 | import java.util.stream.Collectors;
22 |
23 | import org.apache.maven.artifact.repository.ArtifactRepository;
24 | import org.apache.maven.artifact.repository.Authentication;
25 | import org.eclipse.aether.RepositorySystem;
26 | import org.eclipse.aether.RepositorySystemSession;
27 | import org.eclipse.aether.artifact.Artifact;
28 | import org.eclipse.aether.artifact.DefaultArtifact;
29 | import org.eclipse.aether.collection.CollectRequest;
30 | import org.eclipse.aether.collection.CollectResult;
31 | import org.eclipse.aether.graph.Dependency;
32 | import org.eclipse.aether.graph.DependencyNode;
33 | import org.eclipse.aether.impl.ArtifactResolver;
34 | import org.eclipse.aether.repository.LocalArtifactRequest;
35 | import org.eclipse.aether.repository.LocalArtifactResult;
36 | import org.eclipse.aether.repository.Proxy;
37 | import org.eclipse.aether.repository.RemoteRepository;
38 | import org.eclipse.aether.resolution.ArtifactRequest;
39 | import org.eclipse.aether.resolution.ArtifactResolutionException;
40 | import org.eclipse.aether.resolution.ArtifactResult;
41 | import org.eclipse.aether.util.graph.transformer.ConflictResolver;
42 | import org.eclipse.aether.util.graph.transformer.JavaScopeDeriver;
43 | import org.eclipse.aether.util.graph.transformer.JavaScopeSelector;
44 | import org.eclipse.aether.util.graph.transformer.SimpleOptionalitySelector;
45 | import org.eclipse.aether.util.graph.visitor.PreorderNodeListGenerator;
46 | import org.eclipse.aether.util.repository.AuthenticationBuilder;
47 | import org.wildfly.swarm.tools.ArtifactResolvingHelper;
48 | import org.wildfly.swarm.tools.ArtifactSpec;
49 |
50 | /**
51 | * @author Bob McWhirter
52 | */
53 | public class MavenArtifactResolvingHelper implements ArtifactResolvingHelper {
54 |
55 | public MavenArtifactResolvingHelper(ArtifactResolver resolver,
56 | RepositorySystem system,
57 | RepositorySystemSession session,
58 | Proxy proxy) {
59 | this.resolver = resolver;
60 | this.system = system;
61 | this.session = session;
62 | this.proxy = proxy;
63 | this.remoteRepositories.add(buildRemoteRepository("jboss-public-repository-group",
64 | "http://repository.jboss.org/nexus/content/groups/public/",
65 | null,
66 | this.proxy));
67 | }
68 |
69 | public void remoteRepository(ArtifactRepository repo) {
70 | remoteRepository(buildRemoteRepository(repo.getId(), repo.getUrl(), repo.getAuthentication(), this.proxy));
71 | }
72 |
73 | public void remoteRepository(RemoteRepository repo) {
74 | this.remoteRepositories.add(repo);
75 | }
76 |
77 | @Override
78 | public ArtifactSpec resolve(ArtifactSpec spec) {
79 | if (spec.file == null) {
80 | final DefaultArtifact artifact = new DefaultArtifact(spec.groupId(), spec.artifactId(), spec.classifier(),
81 | spec.type(), spec.version());
82 |
83 | final LocalArtifactResult localResult = this.session.getLocalRepositoryManager()
84 | .find(this.session, new LocalArtifactRequest(artifact, this.remoteRepositories, null));
85 | if (localResult.isAvailable()) {
86 | spec.file = localResult.getFile();
87 | } else {
88 | try {
89 | final ArtifactResult result = resolver.resolveArtifact(this.session,
90 | new ArtifactRequest(artifact,
91 | this.remoteRepositories,
92 | null));
93 | if (result.isResolved()) {
94 | spec.file = result.getArtifact().getFile();
95 | }
96 | } catch (ArtifactResolutionException e) {
97 | System.err.println("ERR " + e);
98 | e.printStackTrace();
99 | }
100 | }
101 | }
102 |
103 | return spec.file != null ? spec : null;
104 |
105 | }
106 |
107 | @Override
108 | public Set resolveAll(Set specs) throws Exception {
109 | if (specs.isEmpty()) {
110 |
111 | return specs;
112 | }
113 |
114 | final CollectRequest request = new CollectRequest();
115 | request.setRepositories(this.remoteRepositories);
116 |
117 | specs.forEach(spec -> request
118 | .addDependency(new Dependency(new DefaultArtifact(spec.groupId(),
119 | spec.artifactId(),
120 | spec.classifier(),
121 | spec.type(),
122 | spec.version()),
123 | "compile")));
124 |
125 | RepositorySystemSession tempSession =
126 | new RepositorySystemSessionWrapper(this.session,
127 | new ConflictResolver(new NewestVersionSelector(),
128 | new JavaScopeSelector(),
129 | new SimpleOptionalitySelector(),
130 | new JavaScopeDeriver()
131 | )
132 | );
133 |
134 | CollectResult result = this.system.collectDependencies(tempSession, request);
135 |
136 | PreorderNodeListGenerator gen = new PreorderNodeListGenerator();
137 | result.getRoot().accept(gen);
138 | List nodes = gen.getNodes();
139 |
140 | resolveDependenciesInParallel(nodes);
141 |
142 | return nodes.stream()
143 | .filter(node -> !"system".equals(node.getDependency().getScope()))
144 | .map(node -> {
145 | final Artifact artifact = node.getArtifact();
146 |
147 | return new ArtifactSpec(node.getDependency().getScope(),
148 | artifact.getGroupId(),
149 | artifact.getArtifactId(),
150 | artifact.getVersion(),
151 | artifact.getExtension(),
152 | artifact.getClassifier(),
153 | null);
154 | })
155 | .map(this::resolve)
156 | .filter(x -> x != null)
157 | .collect(Collectors.toSet());
158 | }
159 |
160 | private void resolveDependenciesInParallel(List nodes) {
161 | List artifactRequests = nodes.stream()
162 | .map(node -> new ArtifactRequest(node.getArtifact(), this.remoteRepositories, null))
163 | .collect(Collectors.toList());
164 |
165 | try {
166 | this.resolver.resolveArtifacts(this.session, artifactRequests);
167 | } catch (ArtifactResolutionException e) {
168 | // ignore, error will be printed by resolve(ArtifactSpec)
169 | }
170 | }
171 |
172 | protected static RemoteRepository buildRemoteRepository(final String id, final String url,
173 | final Authentication auth, final Proxy proxy) {
174 | RemoteRepository.Builder builder = new RemoteRepository.Builder(id, "default", url);
175 | if (auth != null &&
176 | auth.getUsername() != null &&
177 | auth.getPassword() != null) {
178 | builder.setAuthentication(new AuthenticationBuilder()
179 | .addUsername(auth.getUsername())
180 | .addPassword(auth.getPassword()).build());
181 | }
182 |
183 | if (proxy != null) {
184 | builder.setProxy(proxy);
185 | }
186 |
187 | return builder.build();
188 | }
189 |
190 | final protected RepositorySystemSession session;
191 |
192 | final protected List remoteRepositories = new ArrayList<>();
193 |
194 | final private ArtifactResolver resolver;
195 |
196 | final private RepositorySystem system;
197 |
198 | final private Proxy proxy;
199 | }
200 |
--------------------------------------------------------------------------------
/plugin/src/main/java/org/wildfly/swarm/plugin/maven/MultiStartMojo.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2015-2016 Red Hat, Inc, and individual contributors.
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 | * http://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 | package org.wildfly.swarm.plugin.maven;
17 |
18 | import java.io.IOException;
19 | import java.util.ArrayList;
20 | import java.util.List;
21 | import java.util.concurrent.TimeUnit;
22 |
23 | import org.apache.maven.artifact.Artifact;
24 | import org.apache.maven.model.Plugin;
25 | import org.apache.maven.model.PluginExecution;
26 | import org.apache.maven.plugin.BuildPluginManager;
27 | import org.apache.maven.plugin.InvalidPluginDescriptorException;
28 | import org.apache.maven.plugin.MojoExecution;
29 | import org.apache.maven.plugin.MojoExecutionException;
30 | import org.apache.maven.plugin.MojoFailureException;
31 | import org.apache.maven.plugin.PluginConfigurationException;
32 | import org.apache.maven.plugin.PluginDescriptorParsingException;
33 | import org.apache.maven.plugin.PluginManagerException;
34 | import org.apache.maven.plugin.PluginNotFoundException;
35 | import org.apache.maven.plugin.PluginResolutionException;
36 | import org.apache.maven.plugin.descriptor.MojoDescriptor;
37 | import org.apache.maven.plugin.descriptor.PluginDescriptor;
38 | import org.apache.maven.plugins.annotations.Component;
39 | import org.apache.maven.plugins.annotations.Mojo;
40 | import org.apache.maven.plugins.annotations.Parameter;
41 | import org.apache.maven.plugins.annotations.ResolutionScope;
42 | import org.apache.maven.project.MavenProject;
43 | import org.codehaus.plexus.configuration.PlexusConfiguration;
44 | import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
45 | import org.codehaus.plexus.util.xml.Xpp3Dom;
46 | import org.codehaus.plexus.util.xml.Xpp3DomUtils;
47 | import org.wildfly.swarm.tools.exec.SwarmExecutor;
48 | import org.wildfly.swarm.tools.exec.SwarmProcess;
49 |
50 | /**
51 | * @author Bob McWhirter
52 | * @author Ken Finnigan
53 | */
54 | @Mojo(name = "multistart",
55 | aggregator = true,
56 | requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME,
57 | requiresDependencyCollection = ResolutionScope.COMPILE_PLUS_RUNTIME)
58 | public class MultiStartMojo extends AbstractSwarmMojo {
59 |
60 | @Parameter(alias = "processes")
61 | protected List processes;
62 |
63 | @Component
64 | protected BuildPluginManager pluginManager;
65 |
66 | @Override
67 | public void execute() throws MojoExecutionException, MojoFailureException {
68 | initProperties(true);
69 | initEnvironment();
70 |
71 | for (XmlPlexusConfiguration process : this.processes) {
72 | try {
73 | start(process);
74 | } catch (Exception e) {
75 | throw new MojoFailureException("Unable to start", e);
76 | }
77 | }
78 | }
79 |
80 | protected void start(XmlPlexusConfiguration process) throws PluginConfigurationException, MojoFailureException, MojoExecutionException, PluginManagerException, InvalidPluginDescriptorException, PluginResolutionException, PluginDescriptorParsingException, PluginNotFoundException {
81 |
82 | String groupId = process.getChild("groupId").getValue(this.project.getGroupId());
83 | String artifactId = process.getChild("artifactId").getValue(this.project.getArtifactId());
84 | String executionId = process.getChild("executionId").getValue();
85 |
86 | MavenProject project = findProject(groupId, artifactId);
87 |
88 | if (project != null) {
89 | startProject(project, executionId, process);
90 | return;
91 | }
92 |
93 | String classifier = process.getChild("classifier").getValue();
94 | Artifact artifact = findArtifact(groupId, artifactId, classifier);
95 |
96 | if (artifact != null) {
97 | startArtifact(artifact, process);
98 | return;
99 | }
100 |
101 | throw new MojoFailureException("Unable to start process");
102 | }
103 |
104 | @SuppressWarnings("unchecked")
105 | protected void startProject(MavenProject project, String executionId, XmlPlexusConfiguration process) throws InvalidPluginDescriptorException, PluginResolutionException, PluginDescriptorParsingException, PluginNotFoundException, PluginConfigurationException, MojoFailureException, MojoExecutionException, PluginManagerException {
106 | Plugin plugin = this.project.getPlugin("org.wildfly.swarm:wildfly-swarm-plugin");
107 |
108 | Xpp3Dom config = getConfiguration(project, executionId);
109 | Xpp3Dom processConfig = getProcessConfiguration(process);
110 |
111 | Xpp3Dom globalConfig = getGlobalConfig();
112 | Xpp3Dom mergedConfig = Xpp3DomUtils.mergeXpp3Dom(processConfig, config);
113 | mergedConfig = Xpp3DomUtils.mergeXpp3Dom(mergedConfig, globalConfig);
114 |
115 | PluginDescriptor pluginDescriptor = this.pluginManager.loadPlugin(plugin, project.getRemotePluginRepositories(), this.repositorySystemSession);
116 | MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo("start");
117 | MojoExecution mojoExecution = new MojoExecution(mojoDescriptor, mergedConfig);
118 | mavenSession.setCurrentProject(project);
119 | this.pluginManager.executeMojo(mavenSession, mojoExecution);
120 |
121 | List launched = (List) mavenSession.getPluginContext(pluginDescriptor, project).get("swarm-process");
122 |
123 | List procs = (List) getPluginContext().get("swarm-process");
124 |
125 | if (procs == null) {
126 | procs = new ArrayList<>();
127 | getPluginContext().put("swarm-process", procs);
128 | }
129 |
130 | procs.addAll(launched);
131 |
132 | mavenSession.setCurrentProject(this.project);
133 | }
134 |
135 | @SuppressWarnings("unchecked")
136 | protected void startArtifact(Artifact artifact, XmlPlexusConfiguration process) throws InvalidPluginDescriptorException, PluginResolutionException, PluginDescriptorParsingException, PluginNotFoundException, PluginConfigurationException, MojoFailureException, MojoExecutionException, PluginManagerException {
137 | List procs = (List) getPluginContext().get("swarm-process");
138 |
139 | if (procs == null) {
140 | procs = new ArrayList<>();
141 | getPluginContext().put("swarm-process", procs);
142 | }
143 |
144 | SwarmExecutor executor = new SwarmExecutor();
145 |
146 | executor.withExecutableJar(artifact.getFile().toPath());
147 |
148 | executor.withProperties(this.properties);
149 | executor.withEnvironment(this.environment);
150 |
151 | PlexusConfiguration props = process.getChild("properties");
152 |
153 | for (PlexusConfiguration each : props.getChildren()) {
154 | executor.withProperty(each.getName(), each.getValue());
155 | }
156 |
157 |
158 | PlexusConfiguration env = process.getChild("environment");
159 |
160 | for (PlexusConfiguration each : env.getChildren()) {
161 | executor.withEnvironment(each.getName(), each.getValue());
162 | }
163 |
164 | try {
165 | SwarmProcess launched = executor.execute();
166 | launched.awaitDeploy(30, TimeUnit.SECONDS);
167 | procs.add(launched);
168 | } catch (IOException | InterruptedException e) {
169 | throw new MojoFailureException("Unable to execute: " + artifact, e);
170 | }
171 | }
172 |
173 | protected MavenProject findProject(String groupId, String artifactId) {
174 | if (groupId.equals(this.project.getGroupId()) && artifactId.equals(this.project.getArtifactId())) {
175 | return this.project;
176 | }
177 | return this.project.getCollectedProjects()
178 | .stream()
179 | .filter(e -> (e.getGroupId().equals(groupId) && e.getArtifactId().equals(artifactId)))
180 | .findFirst()
181 | .orElse(null);
182 | }
183 |
184 | protected Artifact findArtifact(String groupId, String artifactId, String classifier) {
185 | return this.project.getArtifacts()
186 | .stream()
187 | .filter(e -> (e.getGroupId().equals(groupId) && e.getArtifactId().equals(artifactId) && e.getClassifier().equals(classifier)))
188 | .findFirst()
189 | .orElseGet(null);
190 | }
191 |
192 | protected Xpp3Dom getGlobalConfig() {
193 | Xpp3Dom config = new Xpp3Dom("configuration");
194 |
195 | Xpp3Dom properties = new Xpp3Dom("properties");
196 | config.addChild(properties);
197 |
198 | for (String name : this.properties.stringPropertyNames()) {
199 | Xpp3Dom prop = new Xpp3Dom(name);
200 | prop.setValue(this.properties.getProperty(name));
201 | properties.addChild(prop);
202 | }
203 |
204 | Xpp3Dom environment = new Xpp3Dom("environment");
205 | config.addChild(environment);
206 |
207 | for (String name : this.environment.stringPropertyNames()) {
208 | Xpp3Dom env = new Xpp3Dom(name);
209 | env.setValue(this.environment.getProperty(name));
210 | environment.addChild(env);
211 | }
212 |
213 | return config;
214 | }
215 |
216 | protected Xpp3Dom getConfiguration(MavenProject project, String executionId) {
217 | Plugin plugin = project.getPlugin("org.wildfly.swarm:wildfly-swarm-plugin");
218 |
219 | PluginExecution execution = null;
220 |
221 | for (PluginExecution each : plugin.getExecutions()) {
222 | if (executionId != null) {
223 | if (each.getId().equals(executionId)) {
224 | execution = each;
225 | break;
226 | }
227 | } else if (each.getGoals().contains("start")) {
228 | execution = each;
229 | break;
230 | }
231 | }
232 |
233 | Xpp3Dom config;
234 |
235 | if (execution == null) {
236 | config = new Xpp3Dom("configuration");
237 | } else {
238 | config = (Xpp3Dom) execution.getConfiguration();
239 | }
240 | Xpp3Dom pdom = new Xpp3Dom("project");
241 | pdom.setValue("${project}");
242 | config.addChild(pdom);
243 |
244 | pdom = new Xpp3Dom("repositorySystemSession");
245 | pdom.setValue("${repositorySystemSession}");
246 | config.addChild(pdom);
247 |
248 | pdom = new Xpp3Dom("remoteRepositories");
249 | pdom.setValue("${project.remoteArtifactRepositories}");
250 | config.addChild(pdom);
251 |
252 | return config;
253 | }
254 |
255 | protected Xpp3Dom getProcessConfiguration(XmlPlexusConfiguration process) {
256 | Xpp3Dom config = new Xpp3Dom("configuration");
257 |
258 | config.addChild(convert(process.getChild("properties")));
259 | config.addChild(convert(process.getChild("environment")));
260 | config.addChild(convert(process.getChild("jvmArguments")));
261 |
262 | return config;
263 | }
264 |
265 |
266 | protected Xpp3Dom convert(PlexusConfiguration config) {
267 |
268 | Xpp3Dom dom = new Xpp3Dom(config.getName());
269 |
270 | dom.setValue(config.getValue());
271 |
272 | for (String each : config.getAttributeNames()) {
273 | dom.setAttribute(each, config.getAttribute(each));
274 | }
275 |
276 | for (PlexusConfiguration each : config.getChildren()) {
277 | dom.addChild(convert(each));
278 | }
279 |
280 | return dom;
281 | }
282 | }
283 |
--------------------------------------------------------------------------------
/plugin/src/main/java/org/wildfly/swarm/plugin/maven/NewestVersionSelector.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2015-2016 Red Hat, Inc, and individual contributors.
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 | * http://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 | package org.wildfly.swarm.plugin.maven;
17 |
18 | import java.util.ArrayList;
19 | import java.util.Collection;
20 | import java.util.HashSet;
21 | import java.util.Iterator;
22 | import java.util.List;
23 |
24 | import org.eclipse.aether.RepositoryException;
25 | import org.eclipse.aether.collection.UnsolvableVersionConflictException;
26 | import org.eclipse.aether.graph.DependencyFilter;
27 | import org.eclipse.aether.graph.DependencyNode;
28 | import org.eclipse.aether.util.graph.transformer.ConflictResolver;
29 | import org.eclipse.aether.util.graph.visitor.PathRecordingDependencyVisitor;
30 | import org.eclipse.aether.version.Version;
31 | import org.eclipse.aether.version.VersionConstraint;
32 |
33 | /**
34 | * @author Ken Finnigan
35 | */
36 | public class NewestVersionSelector extends ConflictResolver.VersionSelector {
37 | @Override
38 | public void selectVersion(ConflictResolver.ConflictContext context) throws RepositoryException {
39 | ConflictGroup group = new ConflictGroup();
40 | for (ConflictResolver.ConflictItem item : context.getItems()) {
41 | DependencyNode node = item.getNode();
42 | VersionConstraint constraint = node.getVersionConstraint();
43 |
44 | boolean backtrack = false;
45 | boolean hardConstraint = constraint.getRange() != null;
46 |
47 | if (hardConstraint) {
48 | if (group.constraints.add(constraint)) {
49 | if (group.winner != null && !constraint.containsVersion(group.winner.getNode().getVersion())) {
50 | backtrack = true;
51 | }
52 | }
53 | }
54 |
55 | if (isAcceptable(group, node.getVersion())) {
56 | group.candidates.add(item);
57 |
58 | if (backtrack) {
59 | backtrack(group, context);
60 | } else if (group.winner == null || isNewer(item, group.winner)) {
61 | group.winner = item;
62 | }
63 | } else if (backtrack) {
64 | backtrack(group, context);
65 | }
66 | }
67 | context.setWinner(group.winner);
68 | }
69 |
70 | private boolean isNewer(ConflictResolver.ConflictItem item1, ConflictResolver.ConflictItem item2) {
71 | return item1.getNode().getVersion().compareTo(item2.getNode().getVersion()) > 0;
72 | }
73 |
74 | private void backtrack(ConflictGroup group, ConflictResolver.ConflictContext context)
75 | throws UnsolvableVersionConflictException {
76 | group.winner = null;
77 |
78 | for (Iterator it = group.candidates.iterator(); it.hasNext(); ) {
79 | ConflictResolver.ConflictItem candidate = it.next();
80 |
81 | if (!isAcceptable(group, candidate.getNode().getVersion())) {
82 | it.remove();
83 | } else if (group.winner == null || isNewer(candidate, group.winner)) {
84 | group.winner = candidate;
85 | }
86 | }
87 |
88 | if (group.winner == null) {
89 | throw newFailure(context);
90 | }
91 | }
92 |
93 | private UnsolvableVersionConflictException newFailure(final ConflictResolver.ConflictContext context) {
94 | DependencyFilter filter = new DependencyFilter() {
95 | public boolean accept(DependencyNode node, List parents) {
96 | return context.isIncluded(node);
97 | }
98 | };
99 | PathRecordingDependencyVisitor visitor = new PathRecordingDependencyVisitor(filter);
100 | context.getRoot().accept(visitor);
101 | return new UnsolvableVersionConflictException(visitor.getPaths());
102 | }
103 |
104 | private boolean isAcceptable(ConflictGroup group, Version version) {
105 | for (VersionConstraint constraint : group.constraints) {
106 | if (!constraint.containsVersion(version)) {
107 | return false;
108 | }
109 | }
110 | return true;
111 | }
112 |
113 | static final class ConflictGroup {
114 |
115 | public ConflictGroup() {
116 | constraints = new HashSet();
117 | candidates = new ArrayList(64);
118 | }
119 |
120 | @Override
121 | public String toString() {
122 | return String.valueOf(winner);
123 | }
124 |
125 | final Collection constraints;
126 |
127 | final Collection candidates;
128 |
129 | ConflictResolver.ConflictItem winner;
130 | }
131 | }
132 |
--------------------------------------------------------------------------------
/plugin/src/main/java/org/wildfly/swarm/plugin/maven/PackageMojo.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2015-2016 Red Hat, Inc, and individual contributors.
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 | * http://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 | package org.wildfly.swarm.plugin.maven;
17 |
18 | import java.io.File;
19 | import java.nio.file.Paths;
20 |
21 | import org.apache.maven.artifact.Artifact;
22 | import org.apache.maven.artifact.DefaultArtifact;
23 | import org.apache.maven.artifact.handler.ArtifactHandler;
24 | import org.apache.maven.artifact.handler.DefaultArtifactHandler;
25 | import org.apache.maven.plugin.MojoExecutionException;
26 | import org.apache.maven.plugin.MojoFailureException;
27 | import org.apache.maven.plugins.annotations.LifecyclePhase;
28 | import org.apache.maven.plugins.annotations.Mojo;
29 | import org.apache.maven.plugins.annotations.Parameter;
30 | import org.apache.maven.plugins.annotations.ResolutionScope;
31 | import org.wildfly.swarm.fractionlist.FractionList;
32 | import org.wildfly.swarm.tools.BuildTool;
33 | import org.wildfly.swarm.tools.FractionDescriptor;
34 |
35 | /**
36 | * @author Bob McWhirter
37 | * @author Ken Finnigan
38 | */
39 | @Mojo(
40 | name = "package",
41 | defaultPhase = LifecyclePhase.PACKAGE,
42 | requiresDependencyCollection = ResolutionScope.COMPILE_PLUS_RUNTIME,
43 | requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME
44 | )
45 | public class PackageMojo extends AbstractSwarmMojo {
46 |
47 | @Parameter(alias = "bundleDependencies", defaultValue = "true", property = "swarm.bundleDependencies")
48 | protected boolean bundleDependencies;
49 |
50 | /**
51 | * Make a fully executable jar for *nix machines by prepending a launch script to the jar.
52 | */
53 | @Parameter(alias = "executable", defaultValue = "false", property = "swarm.executable")
54 | protected boolean executable;
55 |
56 | /**
57 | * A custom script for *nix machines by prepending a launch script to the jar. Added only when executable = true
58 | */
59 | @Parameter(alias = "executableScript")
60 | protected File executableScript;
61 |
62 | @Override
63 | public void execute() throws MojoExecutionException, MojoFailureException {
64 | initProperties(false);
65 | final Artifact primaryArtifact = this.project.getArtifact();
66 | final String finalName = this.project.getBuild().getFinalName();
67 | final String type = primaryArtifact.getType();
68 | final BuildTool tool = new BuildTool()
69 | .projectArtifact(primaryArtifact.getGroupId(),
70 | primaryArtifact.getArtifactId(),
71 | primaryArtifact.getBaseVersion(),
72 | type,
73 | primaryArtifact.getFile(),
74 | finalName.endsWith("." + type) ?
75 | finalName :
76 | String.format("%s.%s", finalName, type))
77 | .fractionList(FractionList.get())
78 | .properties(this.properties)
79 | .mainClass(this.mainClass)
80 | .bundleDependencies(this.bundleDependencies)
81 | .executable(executable)
82 | .executableScript(executableScript)
83 | .fractionDetectionMode(fractionDetectMode)
84 | .artifactResolvingHelper(mavenArtifactResolvingHelper())
85 | .logger(new BuildTool.SimpleLogger() {
86 | @Override
87 | public void info(String msg) {
88 | getLog().info(msg);
89 | }
90 |
91 | @Override
92 | public void error(String msg) {
93 | getLog().error(msg);
94 | }
95 |
96 | @Override
97 | public void error(String msg, Throwable t) {
98 | getLog().error(msg, t);
99 | }
100 | });
101 |
102 | this.additionalFractions.stream()
103 | .map(f -> FractionDescriptor.fromGav(FractionList.get(), f))
104 | .map(FractionDescriptor::toArtifactSpec)
105 | .forEach(tool::fraction);
106 |
107 | this.project.getArtifacts()
108 | .forEach(dep -> tool.dependency(artifactToArtifactSpec(dep)));
109 |
110 | this.project.getResources()
111 | .forEach(r -> tool.resourceDirectory(r.getDirectory()));
112 |
113 |
114 | this.additionalModules.stream()
115 | .map(m -> new File(this.project.getBuild().getOutputDirectory(), m))
116 | .filter(File::exists)
117 | .map(File::getAbsolutePath)
118 | .forEach(tool::additionalModule);
119 |
120 | try {
121 | File jar = tool.build(finalName, Paths.get(this.projectBuildDir));
122 |
123 | ArtifactHandler handler = new DefaultArtifactHandler("jar");
124 | Artifact swarmJarArtifact = new DefaultArtifact(
125 | primaryArtifact.getGroupId(),
126 | primaryArtifact.getArtifactId(),
127 | primaryArtifact.getBaseVersion(),
128 | primaryArtifact.getScope(),
129 | "jar",
130 | "swarm",
131 | handler
132 | );
133 |
134 | swarmJarArtifact.setFile(jar);
135 |
136 | this.project.addAttachedArtifact(swarmJarArtifact);
137 | } catch (Exception e) {
138 | throw new MojoFailureException("Unable to create -swarm.jar", e);
139 | }
140 | }
141 |
142 | }
143 |
144 |
--------------------------------------------------------------------------------
/plugin/src/main/java/org/wildfly/swarm/plugin/maven/RepositorySystemSessionWrapper.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2015-2016 Red Hat, Inc, and individual contributors.
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 | * http://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 | package org.wildfly.swarm.plugin.maven;
17 |
18 | import java.util.Map;
19 |
20 | import org.eclipse.aether.RepositoryCache;
21 | import org.eclipse.aether.RepositoryListener;
22 | import org.eclipse.aether.RepositorySystemSession;
23 | import org.eclipse.aether.SessionData;
24 | import org.eclipse.aether.artifact.ArtifactTypeRegistry;
25 | import org.eclipse.aether.collection.DependencyGraphTransformer;
26 | import org.eclipse.aether.collection.DependencyManager;
27 | import org.eclipse.aether.collection.DependencySelector;
28 | import org.eclipse.aether.collection.DependencyTraverser;
29 | import org.eclipse.aether.collection.VersionFilter;
30 | import org.eclipse.aether.repository.AuthenticationSelector;
31 | import org.eclipse.aether.repository.LocalRepository;
32 | import org.eclipse.aether.repository.LocalRepositoryManager;
33 | import org.eclipse.aether.repository.MirrorSelector;
34 | import org.eclipse.aether.repository.ProxySelector;
35 | import org.eclipse.aether.repository.WorkspaceReader;
36 | import org.eclipse.aether.resolution.ArtifactDescriptorPolicy;
37 | import org.eclipse.aether.resolution.ResolutionErrorPolicy;
38 | import org.eclipse.aether.transfer.TransferListener;
39 |
40 | /**
41 | * @author Ken Finnigan
42 | */
43 | final class RepositorySystemSessionWrapper implements RepositorySystemSession {
44 |
45 | RepositorySystemSessionWrapper(RepositorySystemSession delegate, DependencyGraphTransformer transformer) {
46 | this.delegate = delegate;
47 | this.transformer = transformer;
48 | }
49 |
50 | @Override
51 | public boolean isOffline() {
52 | return delegate.isOffline();
53 | }
54 |
55 | @Override
56 | public boolean isIgnoreArtifactDescriptorRepositories() {
57 | return delegate.isIgnoreArtifactDescriptorRepositories();
58 | }
59 |
60 | @Override
61 | public ResolutionErrorPolicy getResolutionErrorPolicy() {
62 | return delegate.getResolutionErrorPolicy();
63 | }
64 |
65 | @Override
66 | public ArtifactDescriptorPolicy getArtifactDescriptorPolicy() {
67 | return delegate.getArtifactDescriptorPolicy();
68 | }
69 |
70 | @Override
71 | public String getChecksumPolicy() {
72 | return delegate.getChecksumPolicy();
73 | }
74 |
75 | @Override
76 | public String getUpdatePolicy() {
77 | return delegate.getUpdatePolicy();
78 | }
79 |
80 | @Override
81 | public LocalRepository getLocalRepository() {
82 | return delegate.getLocalRepository();
83 | }
84 |
85 | @Override
86 | public LocalRepositoryManager getLocalRepositoryManager() {
87 | return delegate.getLocalRepositoryManager();
88 | }
89 |
90 | @Override
91 | public WorkspaceReader getWorkspaceReader() {
92 | return delegate.getWorkspaceReader();
93 | }
94 |
95 | @Override
96 | public RepositoryListener getRepositoryListener() {
97 | return delegate.getRepositoryListener();
98 | }
99 |
100 | @Override
101 | public TransferListener getTransferListener() {
102 | return delegate.getTransferListener();
103 | }
104 |
105 | @Override
106 | public Map getSystemProperties() {
107 | return delegate.getSystemProperties();
108 | }
109 |
110 | @Override
111 | public Map getUserProperties() {
112 | return delegate.getUserProperties();
113 | }
114 |
115 | @Override
116 | public Map getConfigProperties() {
117 | return delegate.getConfigProperties();
118 | }
119 |
120 | @Override
121 | public MirrorSelector getMirrorSelector() {
122 | return delegate.getMirrorSelector();
123 | }
124 |
125 | @Override
126 | public ProxySelector getProxySelector() {
127 | return delegate.getProxySelector();
128 | }
129 |
130 | @Override
131 | public AuthenticationSelector getAuthenticationSelector() {
132 | return delegate.getAuthenticationSelector();
133 | }
134 |
135 | @Override
136 | public ArtifactTypeRegistry getArtifactTypeRegistry() {
137 | return delegate.getArtifactTypeRegistry();
138 | }
139 |
140 | @Override
141 | public DependencyTraverser getDependencyTraverser() {
142 | return delegate.getDependencyTraverser();
143 | }
144 |
145 | @Override
146 | public DependencyManager getDependencyManager() {
147 | return delegate.getDependencyManager();
148 | }
149 |
150 | @Override
151 | public DependencySelector getDependencySelector() {
152 | return delegate.getDependencySelector();
153 | }
154 |
155 | @Override
156 | public VersionFilter getVersionFilter() {
157 | return delegate.getVersionFilter();
158 | }
159 |
160 | @Override
161 | public DependencyGraphTransformer getDependencyGraphTransformer() {
162 | return transformer;
163 | }
164 |
165 | @Override
166 | public SessionData getData() {
167 | return delegate.getData();
168 | }
169 |
170 | @Override
171 | public RepositoryCache getCache() {
172 | return delegate.getCache();
173 | }
174 |
175 | private RepositorySystemSession delegate;
176 |
177 | private DependencyGraphTransformer transformer;
178 | }
179 |
--------------------------------------------------------------------------------
/plugin/src/main/java/org/wildfly/swarm/plugin/maven/RunMojo.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2015-2016 Red Hat, Inc, and individual contributors.
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 | * http://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 | package org.wildfly.swarm.plugin.maven;
17 |
18 | import org.apache.maven.plugins.annotations.Execute;
19 | import org.apache.maven.plugins.annotations.LifecyclePhase;
20 | import org.apache.maven.plugins.annotations.Mojo;
21 | import org.apache.maven.plugins.annotations.ResolutionScope;
22 |
23 | @Mojo(name = "run",
24 | requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME,
25 | requiresDependencyCollection = ResolutionScope.COMPILE_PLUS_RUNTIME)
26 | @Execute(phase = LifecyclePhase.PACKAGE)
27 | public class RunMojo extends StartMojo {
28 | public RunMojo() {
29 | waitForProcess = true;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/plugin/src/main/java/org/wildfly/swarm/plugin/maven/StartMojo.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2015-2016 Red Hat, Inc, and individual contributors.
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 | * http://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 | package org.wildfly.swarm.plugin.maven;
17 |
18 | import java.io.File;
19 | import java.io.IOException;
20 | import java.nio.file.Path;
21 | import java.nio.file.Paths;
22 | import java.util.ArrayList;
23 | import java.util.HashSet;
24 | import java.util.List;
25 | import java.util.Set;
26 | import java.util.StringTokenizer;
27 | import java.util.concurrent.TimeUnit;
28 | import java.util.function.Predicate;
29 | import java.util.stream.Collectors;
30 |
31 | import org.apache.maven.artifact.Artifact;
32 | import org.apache.maven.plugin.MojoExecutionException;
33 | import org.apache.maven.plugin.MojoFailureException;
34 | import org.apache.maven.plugins.annotations.Mojo;
35 | import org.apache.maven.plugins.annotations.Parameter;
36 | import org.apache.maven.plugins.annotations.ResolutionScope;
37 | import org.eclipse.aether.repository.RemoteRepository;
38 | import org.wildfly.swarm.bootstrap.util.BootstrapProperties;
39 | import org.wildfly.swarm.fractionlist.FractionList;
40 | import org.wildfly.swarm.spi.api.SwarmProperties;
41 | import org.wildfly.swarm.tools.ArtifactSpec;
42 | import org.wildfly.swarm.tools.BuildTool;
43 | import org.wildfly.swarm.tools.DependencyManager;
44 | import org.wildfly.swarm.tools.FractionDescriptor;
45 | import org.wildfly.swarm.tools.FractionUsageAnalyzer;
46 | import org.wildfly.swarm.tools.exec.SwarmExecutor;
47 | import org.wildfly.swarm.tools.exec.SwarmProcess;
48 |
49 | /**
50 | * @author Bob McWhirter
51 | * @author Ken Finnigan
52 | */
53 | @Mojo(name = "start",
54 | requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME,
55 | requiresDependencyCollection = ResolutionScope.COMPILE_PLUS_RUNTIME)
56 | public class StartMojo extends AbstractSwarmMojo {
57 |
58 | @Parameter(alias = "stdoutFile", property = "swarm.stdout")
59 | public File stdoutFile;
60 |
61 | @Parameter(alias = "stderrFile", property = "swarm.stderr" )
62 | public File stderrFile;
63 |
64 | @Parameter(alias = "useUberJar", defaultValue = "${wildfly-swarm.useUberJar}")
65 | public boolean useUberJar;
66 |
67 | @Parameter(alias = "debug", property = SwarmProperties.DEBUG_PORT)
68 | public Integer debugPort;
69 |
70 | @Parameter(alias = "jvmArguments", property = "swarm.jvmArguments")
71 | public List jvmArguments = new ArrayList<>();
72 |
73 | @Parameter(alias = "arguments" )
74 | public List arguments = new ArrayList<>();
75 |
76 | @Parameter(property = "swarm.arguments", defaultValue = "")
77 | public String argumentsProp;
78 |
79 | boolean waitForProcess;
80 |
81 | @SuppressWarnings({"unchecked", "ThrowableResultOfMethodCallIgnored"})
82 | @Override
83 | public void execute() throws MojoExecutionException, MojoFailureException {
84 | initProperties(true);
85 | initEnvironment();
86 |
87 | final SwarmExecutor executor;
88 |
89 | if (this.useUberJar) {
90 | executor = uberJarExecutor();
91 | } else if (this.project.getPackaging().equals("war")) {
92 | executor = warExecutor();
93 | } else if (this.project.getPackaging().equals("jar")) {
94 | executor = jarExecutor();
95 | } else {
96 | throw new MojoExecutionException("Unsupported packaging: " + this.project.getPackaging());
97 | }
98 |
99 | executor.withJVMArguments( this.jvmArguments );
100 |
101 | if ( this.argumentsProp != null ) {
102 | StringTokenizer args = new StringTokenizer(this.argumentsProp);
103 | while ( args.hasMoreTokens() ) {
104 | this.arguments.add( args.nextToken() );
105 | }
106 | }
107 |
108 | executor.withArguments( this.arguments );
109 |
110 | final SwarmProcess process;
111 | try {
112 | process = executor.withDebug(debugPort)
113 | .withProperties(this.properties)
114 | .withStdoutFile(this.stdoutFile != null ? this.stdoutFile.toPath() : null)
115 | .withStderrFile(this.stderrFile != null ? this.stderrFile.toPath() : null)
116 | .withEnvironment(this.environment)
117 | .withWorkingDirectory(this.project.getBasedir().toPath())
118 | .withProperty("remote.maven.repo",
119 | String.join(",",
120 | this.project.getRemoteProjectRepositories().stream()
121 | .map(RemoteRepository::getUrl)
122 | .collect(Collectors.toList())))
123 | .execute();
124 |
125 | Runtime.getRuntime().addShutdownHook( new Thread(()->{
126 | try {
127 | // Sleeping for a few millis will give time to shutdown gracefully
128 | Thread.sleep(100L);
129 | process.stop( 10, TimeUnit.SECONDS );
130 | } catch (InterruptedException e) {
131 | }
132 | }));
133 |
134 | process.awaitDeploy(2, TimeUnit.MINUTES);
135 |
136 | if (!process.isAlive()) {
137 | throw new MojoFailureException("Process failed to start");
138 | }
139 | if (process.getError() != null) {
140 | throw new MojoFailureException("Error starting process", process.getError());
141 | }
142 |
143 | } catch (IOException e) {
144 | throw new MojoFailureException("unable to execute", e);
145 | } catch (InterruptedException e) {
146 | throw new MojoFailureException("Error waiting for deployment", e);
147 | }
148 |
149 | List procs = (List) getPluginContext().get("swarm-process");
150 | if (procs == null) {
151 | procs = new ArrayList<>();
152 | getPluginContext().put("swarm-process", procs);
153 | }
154 | procs.add(process);
155 |
156 | if (waitForProcess) {
157 | try {
158 | process.waitFor();
159 | } catch (InterruptedException e) {
160 | try {
161 | process.stop( 10, TimeUnit.SECONDS );
162 | } catch (InterruptedException ie) {
163 | // Do nothing
164 | }
165 | } finally {
166 | process.destroyForcibly();
167 | }
168 | }
169 | }
170 |
171 | protected SwarmExecutor uberJarExecutor() throws MojoFailureException {
172 | getLog().info("Starting -swarm.jar");
173 |
174 | String finalName = this.project.getBuild().getFinalName();
175 |
176 | if (finalName.endsWith(".war") || finalName.endsWith(".jar")) {
177 | finalName = finalName.substring(0, finalName.length() - 4);
178 | }
179 |
180 | return new SwarmExecutor()
181 | .withExecutableJar(Paths.get(this.projectBuildDir, finalName + "-swarm.jar"));
182 | }
183 |
184 | protected SwarmExecutor warExecutor() throws MojoFailureException {
185 | getLog().info("Starting .war");
186 |
187 | String finalName = this.project.getBuild().getFinalName();
188 | if (!finalName.endsWith(".war")) {
189 | finalName = finalName + ".war";
190 | }
191 |
192 | return executor(Paths.get(this.projectBuildDir, finalName), finalName, false);
193 | }
194 |
195 |
196 | protected SwarmExecutor jarExecutor() throws MojoFailureException {
197 | getLog().info("Starting .jar");
198 |
199 | final String finalName = this.project.getBuild().getFinalName();
200 |
201 | return executor(Paths.get(this.project.getBuild().getOutputDirectory()),
202 | finalName.endsWith(".jar") ? finalName : finalName + ".jar",
203 | true);
204 | }
205 |
206 | protected SwarmExecutor executor(final Path appPath, final String name,
207 | final boolean scanDependencies) throws MojoFailureException {
208 | final SwarmExecutor executor = new SwarmExecutor()
209 | .withModules(expandModules())
210 | .withProperty(BootstrapProperties.APP_NAME, name)
211 | .withClassPathEntries(dependencies(appPath, scanDependencies));
212 |
213 | if (this.mainClass != null) {
214 | executor.withMainClass(this.mainClass);
215 | } else {
216 | executor.withDefaultMainClass();
217 | }
218 |
219 | return executor;
220 | }
221 |
222 | List findNeededFractions(final Set existingDeps,
223 | final Path source,
224 | final boolean scanDeps) throws MojoFailureException {
225 | getLog().info("Scanning for needed WildFly Swarm fractions with mode: " + fractionDetectMode);
226 |
227 | final Set existingDepGASet = existingDeps.stream()
228 | .map(d -> String.format("%s:%s", d.getGroupId(), d.getArtifactId()))
229 | .collect(Collectors.toSet());
230 |
231 | final Set fractions;
232 | final FractionUsageAnalyzer analyzer = new FractionUsageAnalyzer(FractionList.get()).source(source);
233 | if (scanDeps) {
234 | existingDeps.forEach(d -> analyzer.source(d.getFile()));
235 | }
236 | final Predicate notExistingDep =
237 | d -> !existingDepGASet.contains(String.format("%s:%s", d.groupId(), d.artifactId()));
238 | try {
239 | fractions = analyzer.detectNeededFractions().stream()
240 | .filter(notExistingDep)
241 | .collect(Collectors.toSet());
242 | } catch (IOException e) {
243 | throw new MojoFailureException("failed to scan for fractions", e);
244 | }
245 |
246 | getLog().info("Detected fractions: " + String.join(", ", fractions.stream()
247 | .map(FractionDescriptor::av)
248 | .sorted()
249 | .collect(Collectors.toList())));
250 |
251 | fractions.addAll(this.additionalFractions.stream()
252 | .map(f -> FractionDescriptor.fromGav(FractionList.get(), f))
253 | .collect(Collectors.toSet()));
254 |
255 | final Set allFractions = new HashSet<>(fractions);
256 | allFractions.addAll(fractions.stream()
257 | .flatMap(f -> f.getDependencies().stream())
258 | .filter(notExistingDep)
259 | .collect(Collectors.toSet()));
260 |
261 |
262 | getLog().info("Using fractions: " +
263 | String.join(", ", allFractions.stream()
264 | .map(FractionDescriptor::gavOrAv)
265 | .sorted()
266 | .collect(Collectors.toList())));
267 |
268 | final Set specs = new HashSet<>();
269 | specs.addAll(existingDeps.stream()
270 | .map(this::artifactToArtifactSpec)
271 | .collect(Collectors.toList()));
272 | specs.addAll(allFractions.stream()
273 | .map(FractionDescriptor::toArtifactSpec)
274 | .collect(Collectors.toList()));
275 | try {
276 | return mavenArtifactResolvingHelper().resolveAll(specs).stream()
277 | .map(s -> s.file.toPath())
278 | .collect(Collectors.toList());
279 | } catch (Exception e) {
280 | throw new MojoFailureException("failed to resolve fraction dependencies", e);
281 | }
282 | }
283 |
284 | List dependencies(final Path archiveContent,
285 | final boolean scanDependencies) throws MojoFailureException {
286 | final List elements = new ArrayList<>();
287 | final Set artifacts = this.project.getArtifacts();
288 | boolean hasSwarmDeps = false;
289 | for (Artifact each : artifacts) {
290 | if (each.getGroupId().equals(DependencyManager.WILDFLY_SWARM_GROUP_ID)
291 | && each.getArtifactId().equals(DependencyManager.WILDFLY_SWARM_BOOTSTRAP_ARTIFACT_ID)) {
292 | hasSwarmDeps = true;
293 | }
294 | if (each.getGroupId().equals("org.jboss.logmanager")
295 | && each.getArtifactId().equals("jboss-logmanager")) {
296 | continue;
297 | }
298 | if (each.getScope().equals("provided")) {
299 | continue;
300 | }
301 | elements.add(each.getFile().toPath());
302 | }
303 |
304 | elements.add(Paths.get(this.project.getBuild().getOutputDirectory()));
305 |
306 | if (fractionDetectMode != BuildTool.FractionDetectionMode.never) {
307 | if (fractionDetectMode == BuildTool.FractionDetectionMode.force ||
308 | !hasSwarmDeps) {
309 | elements.addAll(findNeededFractions(artifacts, archiveContent, scanDependencies));
310 | }
311 | } else if (!hasSwarmDeps) {
312 | getLog().warn("No WildFly Swarm dependencies found and fraction detection disabled");
313 | }
314 |
315 | return elements;
316 | }
317 |
318 | List expandModules() {
319 | return this.additionalModules.stream()
320 | .map(m -> Paths.get(this.project.getBuild().getOutputDirectory(), m))
321 | .collect(Collectors.toList());
322 | }
323 | }
--------------------------------------------------------------------------------
/plugin/src/main/java/org/wildfly/swarm/plugin/maven/StopMojo.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2015-2016 Red Hat, Inc, and individual contributors.
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 | * http://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 | package org.wildfly.swarm.plugin.maven;
17 |
18 | import java.util.List;
19 | import java.util.concurrent.TimeUnit;
20 |
21 | import org.apache.maven.plugin.AbstractMojo;
22 | import org.apache.maven.plugin.MojoExecution;
23 | import org.apache.maven.plugin.MojoExecutionException;
24 | import org.apache.maven.plugin.MojoFailureException;
25 | import org.apache.maven.plugins.annotations.Mojo;
26 | import org.apache.maven.plugins.annotations.Parameter;
27 | import org.wildfly.swarm.tools.exec.SwarmProcess;
28 |
29 | /**
30 | * @author Thomas Meyer
31 | */
32 | @Mojo(name = "stop")
33 | public class StopMojo extends AbstractMojo {
34 |
35 | @Parameter(defaultValue = "${mojoExecution}")
36 | protected MojoExecution execution;
37 |
38 | @SuppressWarnings("unchecked")
39 | @Override
40 | public void execute() throws MojoExecutionException, MojoFailureException {
41 | if ( this.execution.getExecutionId().equals( "default-cli" ) ) {
42 | getLog().error( "wildfly-swarm:stop is not usable from the CLI" );
43 | return;
44 | }
45 |
46 | List value = (List) getPluginContext().get("swarm-process");
47 |
48 | if ( value == null ) {
49 | getLog().error( "No known processes to stop" );
50 | return;
51 | }
52 |
53 | for (SwarmProcess each : value) {
54 | stop(each);
55 | }
56 | }
57 |
58 |
59 | protected void stop(SwarmProcess process) throws MojoFailureException {
60 | if (process != null) {
61 | try {
62 | process.stop(10, TimeUnit.SECONDS);
63 | } catch (InterruptedException e) {
64 | throw new MojoFailureException("unable to stop process", e);
65 | }
66 | }
67 | }
68 | }
69 |
70 |
--------------------------------------------------------------------------------
/plugin/src/main/resources/META-INF/gradle-plugins/wildfly-swarm.properties:
--------------------------------------------------------------------------------
1 | implementation-class=org.wildfly.swarm.plugin.gradle.PackagePlugin
--------------------------------------------------------------------------------
/plugin/src/test/java/org/eclipse/aether/util/version/TestHelper.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2015-2016 Red Hat, Inc, and individual contributors.
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 | * http://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 | package org.eclipse.aether.util.version;
17 |
18 | /**
19 | * @author Ken Finnigan
20 | */
21 | public class TestHelper {
22 | public static GenericVersion version(String version) {
23 | return new GenericVersion(version);
24 | }
25 |
26 | public static GenericVersionConstraint versionConstraint(String version) {
27 | return new GenericVersionConstraint(version(version));
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/plugin/src/test/java/org/wildfly/swarm/plugin/maven/NewestVersionSelectorTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2015-2016 Red Hat, Inc, and individual contributors.
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 | * http://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 | package org.wildfly.swarm.plugin.maven;
17 |
18 | import java.util.ArrayList;
19 | import java.util.Collection;
20 | import java.util.List;
21 | import java.util.Map;
22 |
23 | import org.eclipse.aether.artifact.Artifact;
24 | import org.eclipse.aether.graph.Dependency;
25 | import org.eclipse.aether.graph.DependencyNode;
26 | import org.eclipse.aether.graph.DependencyVisitor;
27 | import org.eclipse.aether.repository.RemoteRepository;
28 | import org.eclipse.aether.util.graph.transformer.ConflictResolver;
29 | import org.eclipse.aether.util.version.TestHelper;
30 | import org.eclipse.aether.version.Version;
31 | import org.eclipse.aether.version.VersionConstraint;
32 | import org.junit.Test;
33 |
34 | import static org.fest.assertions.Assertions.assertThat;
35 |
36 | /**
37 | * @author Ken Finnigan
38 | */
39 | public class NewestVersionSelectorTest {
40 |
41 | @Test
42 | public void betaVersionComparison() throws Exception {
43 | NewestVersionSelector selector = new NewestVersionSelector();
44 | List items = new ArrayList<>();
45 |
46 | items.add(new ConflictResolver.ConflictItem(null, createNode("1.0.0.Beta3"), 0, 0));
47 | items.add(new ConflictResolver.ConflictItem(null, createNode("1.0.0.Beta5-SNAPSHOT"), 0, 0));
48 |
49 | ConflictResolver.ConflictContext context = new ConflictResolver.ConflictContext(null, null, null, items);
50 | selector.selectVersion(context);
51 |
52 | assertThat(context.getWinner().getNode().getVersion().toString()).isEqualTo("1.0.0.Beta5-SNAPSHOT");
53 | }
54 |
55 | @Test
56 | public void snapshotVersionComparison() throws Exception {
57 | NewestVersionSelector selector = new NewestVersionSelector();
58 | List items = new ArrayList<>();
59 |
60 | items.add(new ConflictResolver.ConflictItem(null, createNode("1.0.0.Beta3"), 0, 0));
61 | items.add(new ConflictResolver.ConflictItem(null, createNode("1.0.0.Beta3-SNAPSHOT"), 0, 0));
62 |
63 | ConflictResolver.ConflictContext context = new ConflictResolver.ConflictContext(null, null, null, items);
64 | selector.selectVersion(context);
65 |
66 | assertThat(context.getWinner().getNode().getVersion().toString()).isEqualTo("1.0.0.Beta3");
67 | }
68 |
69 | @Test
70 | public void alphaToBetaVersionComparison() throws Exception {
71 | NewestVersionSelector selector = new NewestVersionSelector();
72 | List items = new ArrayList<>();
73 |
74 | items.add(new ConflictResolver.ConflictItem(null, createNode("1.0.0.Alpha8"), 0, 0));
75 | items.add(new ConflictResolver.ConflictItem(null, createNode("1.0.0.Beta3"), 0, 0));
76 |
77 | ConflictResolver.ConflictContext context = new ConflictResolver.ConflictContext(null, null, null, items);
78 | selector.selectVersion(context);
79 |
80 | assertThat(context.getWinner().getNode().getVersion().toString()).isEqualTo("1.0.0.Beta3");
81 | }
82 |
83 | @Test
84 | public void finalVersionComparison() throws Exception {
85 | NewestVersionSelector selector = new NewestVersionSelector();
86 | List items = new ArrayList<>();
87 |
88 | items.add(new ConflictResolver.ConflictItem(null, createNode("1.0.0.CR1"), 0, 0));
89 | items.add(new ConflictResolver.ConflictItem(null, createNode("1.0.0.Final"), 0, 0));
90 |
91 | ConflictResolver.ConflictContext context = new ConflictResolver.ConflictContext(null, null, null, items);
92 | selector.selectVersion(context);
93 |
94 | assertThat(context.getWinner().getNode().getVersion().toString()).isEqualTo("1.0.0.Final");
95 | }
96 |
97 | @Test
98 | public void differentVersionComparison() throws Exception {
99 | NewestVersionSelector selector = new NewestVersionSelector();
100 | List items = new ArrayList<>();
101 |
102 | items.add(new ConflictResolver.ConflictItem(null, createNode("1.0.1.Alpha4"), 0, 0));
103 | items.add(new ConflictResolver.ConflictItem(null, createNode("1.0.0.Final"), 0, 0));
104 |
105 | ConflictResolver.ConflictContext context = new ConflictResolver.ConflictContext(null, null, null, items);
106 | selector.selectVersion(context);
107 |
108 | assertThat(context.getWinner().getNode().getVersion().toString()).isEqualTo("1.0.1.Alpha4");
109 | }
110 |
111 | private DependencyNode createNode(String version) {
112 | return new DependencyNode() {
113 | @Override
114 | public List getChildren() {
115 | return null;
116 | }
117 |
118 | @Override
119 | public void setChildren(List children) {
120 |
121 | }
122 |
123 | @Override
124 | public Dependency getDependency() {
125 | return null;
126 | }
127 |
128 | @Override
129 | public Artifact getArtifact() {
130 | return null;
131 | }
132 |
133 | @Override
134 | public void setArtifact(Artifact artifact) {
135 |
136 | }
137 |
138 | @Override
139 | public List extends Artifact> getRelocations() {
140 | return null;
141 | }
142 |
143 | @Override
144 | public Collection extends Artifact> getAliases() {
145 | return null;
146 | }
147 |
148 | @Override
149 | public VersionConstraint getVersionConstraint() {
150 | return TestHelper.versionConstraint(version);
151 | }
152 |
153 | @Override
154 | public Version getVersion() {
155 | return TestHelper.version(version);
156 | }
157 |
158 | @Override
159 | public void setScope(String scope) {
160 |
161 | }
162 |
163 | @Override
164 | public void setOptional(Boolean optional) {
165 |
166 | }
167 |
168 | @Override
169 | public int getManagedBits() {
170 | return 0;
171 | }
172 |
173 | @Override
174 | public List getRepositories() {
175 | return null;
176 | }
177 |
178 | @Override
179 | public String getRequestContext() {
180 | return null;
181 | }
182 |
183 | @Override
184 | public void setRequestContext(String context) {
185 |
186 | }
187 |
188 | @Override
189 | public Map, ?> getData() {
190 | return null;
191 | }
192 |
193 | @Override
194 | public void setData(Map