-
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 21 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/CIInfo.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 CIInfo { | ||
| /** | ||
| * 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 isVerbose() { | ||
| 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.CIInfo; | ||
|
|
||
| /** | ||
| * 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<CIInfo> detectCI(); | ||
| } |
49 changes: 49 additions & 0 deletions
49
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,49 @@ | ||
| /* | ||
| * 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.CIInfo; | ||
|
|
||
| /** | ||
| * CI detector helper: it uses service discovery to discover {@link CIDetector}s. If resulting list has more than | ||
| * one element, it will remove the {@link GenericCIDetector} result, assuming a more specific one is also present. | ||
| */ | ||
| public final class CIDetectorHelper { | ||
| private CIDetectorHelper() {} | ||
|
|
||
| public static List<CIInfo> detectCI() { | ||
| List<CIInfo> result = new ArrayList<>(ServiceLoader.load(CIDetector.class).stream() | ||
| .map(ServiceLoader.Provider::get) | ||
| .map(CIDetector::detectCI) | ||
| .filter(Optional::isPresent) | ||
| .map(Optional::get) | ||
| .toList()); | ||
|
|
||
| if (result.size() > 1) { | ||
| // remove generic | ||
| result.removeIf(c -> GenericCIDetector.NAME.equals(c.name())); | ||
| } | ||
| return result; | ||
| } | ||
| } | ||
46 changes: 46 additions & 0 deletions
46
impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/cisupport/CircleCIDetector.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,46 @@ | ||
| /* | ||
| * 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.CIInfo; | ||
|
|
||
| /** | ||
| * Circle CI support. | ||
| */ | ||
| public class CircleCIDetector implements CIDetector { | ||
| public static final String NAME = "CircleCI"; | ||
|
|
||
| private static final String CIRCLECI = "CIRCLECI"; | ||
|
|
||
| @Override | ||
| public Optional<CIInfo> detectCI() { | ||
| String ciEnv = System.getenv(CIRCLECI); | ||
| if ("true".equals(ciEnv)) { | ||
| return Optional.of(new CIInfo() { | ||
| @Override | ||
| public String name() { | ||
| return NAME; | ||
| } | ||
| }); | ||
| } | ||
| return Optional.empty(); | ||
| } | ||
| } |
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.
https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/stream/Stream.html#toList():
so not sure about
removeIflater.Maybe
Collectors.toCollection(ArrayList::new)?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.
I think is fine, this happens "on boot", is not some sort of "hot" spot. The reason why I remove "generic" if there are 2 or more is that I assume there is more specific hit (like GH, sets
CI=truebut also setsGITHUB_RUNNER=true)... we can refine this later anyway.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.
Also, to keep things simple I don't want to fiddle with order, as other solution would be to test all, and THEN as last, if no hit, "generic"... but that would assume there is no (and never will be) overlap between all CI systems, which IMO we never know and cannot know (future wise).