-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[MNG-8685] Better support for CI systems #2254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
2b9bf9c
[MNG-8685] Better support for CI systems
cstamas 7b29963
Tie things up
cstamas 090f2d1
Reformat
cstamas 6332c22
Tisy up
cstamas c8dfcde
Tidy up more
cstamas 236b902
Cover Jenkins and GH
cstamas 37511de
Make UT work on CIs as well
cstamas 64ce8bd
Tidy up UT
cstamas 7f0153f
Do nut use OS spec newline, just a semicolon delimited list instead
cstamas 2674e64
Fix the 3 ITs: they want CI-less env
cstamas 7092957
Align check and message.
cstamas 2d91c68
Add more
cstamas c9590d1
Add them as services as well
cstamas 3eab3b1
Align "existence" check (and not empty)
cstamas 1a6d10d
Reformat
cstamas 7c2834d
Cannot remove what is not there.
cstamas d08a41c
CI must be "false"
cstamas a82a4c0
Missed this one
cstamas c248157
Tidy up, rename stuff
cstamas 89ab0da
Merge remote-tracking branch 'upstream/master' into MNG-8685
cstamas f0a0de3
PR comments
cstamas 9e588c5
Simpify
cstamas ff07b12
Remove collect
cstamas e234dfb
PR comments + reformat
cstamas b0cad08
Minor things
cstamas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
api/maven-api-cli/src/main/java/org/apache/maven/api/cli/cisupport/CISupport.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.maven.api.cli.cisupport; | ||
|
|
||
| import org.apache.maven.api.annotations.Nonnull; | ||
|
|
||
| /** | ||
| * CI support: this class contains gathered information and more from CI that Maven process runs on. | ||
| */ | ||
| public interface CISupport { | ||
| /** | ||
| * Short distinct name of CI system: "GH", "Jenkins", etc. | ||
| */ | ||
| @Nonnull | ||
| String name(); | ||
|
|
||
| /** | ||
| * May return a message that will be logged by Maven explaining why it was detected (and possibly more). | ||
| */ | ||
| @Nonnull | ||
| default String message() { | ||
| return ""; | ||
| } | ||
|
|
||
| /** | ||
| * Some CI systems may allow running jobs in "debug" (or some equivalent) mode. | ||
| */ | ||
| default boolean isDebug() { | ||
| return false; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/cisupport/CIDetector.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.maven.cling.invoker.cisupport; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| import org.apache.maven.api.cli.cisupport.CISupport; | ||
|
|
||
| /** | ||
| * Service interface to detect CI system process runs on, if any. | ||
| */ | ||
| public interface CIDetector { | ||
| /** | ||
| * Returns non-empty optional with CI information, if CI is detected, empty otherwise. | ||
| */ | ||
| Optional<CISupport> detectCI(); | ||
| } |
51 changes: 51 additions & 0 deletions
51
impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/cisupport/CIDetectorHelper.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.maven.cling.invoker.cisupport; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import java.util.ServiceLoader; | ||
|
|
||
| import org.apache.maven.api.cli.cisupport.CISupport; | ||
|
|
||
| /** | ||
| * CI detector helper: it uses service discovery (one is always present: {@link GenericCIDetector}) to detect CI, if | ||
| * present and returns a list of detections. If result has 2 or more results, it will return the generic result before. | ||
| */ | ||
| public final class CIDetectorHelper { | ||
| private CIDetectorHelper() {} | ||
|
|
||
| public static List<CISupport> detectCI() { | ||
| List<CIDetector> detectors = ServiceLoader.load(CIDetector.class).stream() | ||
| .map(ServiceLoader.Provider::get) | ||
| .toList(); | ||
|
|
||
| ArrayList<CISupport> result = new ArrayList<>(); | ||
| for (CIDetector detector : detectors) { | ||
| Optional<CISupport> detected = detector.detectCI(); | ||
| detected.ifPresent(result::add); | ||
| } | ||
| if (result.size() > 1) { | ||
| // remove generic | ||
| result.removeIf(c -> GenericCIDetector.NAME.equals(c.name())); | ||
| } | ||
| return result; | ||
| } | ||
| } | ||
50 changes: 50 additions & 0 deletions
50
impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/cisupport/GenericCIDetector.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.maven.cling.invoker.cisupport; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| import org.apache.maven.api.cli.cisupport.CISupport; | ||
|
|
||
| /** | ||
| * Generic CI support. This offers same support as Maven 3 always had. Is also special, as code will reject this | ||
| * detector result IF there are also any other returned via discovered services. | ||
| */ | ||
| public class GenericCIDetector implements CIDetector { | ||
| public static final String NAME = "generic"; | ||
|
|
||
| @Override | ||
| public Optional<CISupport> detectCI() { | ||
| String ciEnv = System.getenv("CI"); | ||
| if (ciEnv != null && !"false".equals(ciEnv)) { | ||
| return Optional.of(new CISupport() { | ||
| @Override | ||
| public String name() { | ||
| return NAME; | ||
| } | ||
|
|
||
| @Override | ||
| public String message() { | ||
| return "Environment variable CI equals \"true\". Disable detection by removing that variable or by setting it to any other value"; | ||
cstamas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| }); | ||
| } | ||
| return Optional.empty(); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not continue with this stream to get
List<CIInfo>and get rid of the loop?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed