-
Notifications
You must be signed in to change notification settings - Fork 126
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
Disable injection when custom extensions are detected #398
Merged
Merged
Changes from 1 commit
Commits
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 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 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 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 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
32 changes: 32 additions & 0 deletions
32
src/main/java/hudson/plugins/gradle/injection/MavenExtClasspathUtils.java
This file contains 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,32 @@ | ||
package hudson.plugins.gradle.injection; | ||
|
||
import hudson.FilePath; | ||
import hudson.model.Computer; | ||
import hudson.model.Node; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
class MavenExtClasspathUtils { | ||
static final String SPACE = " "; | ||
|
||
static String constructExtClasspath(List<FilePath> extensions, boolean isUnix) { | ||
return extensions | ||
.stream() | ||
.map(FilePath::getRemote) | ||
.collect(Collectors.joining(getDelimiter(isUnix))); | ||
} | ||
|
||
static String getDelimiter(boolean isUnix) { | ||
return isUnix ? ":" : ";"; | ||
} | ||
|
||
static boolean isUnix(Node node) { | ||
Computer computer = node.toComputer(); | ||
return isUnix(computer); | ||
} | ||
|
||
static boolean isUnix(Computer computer) { | ||
return computer == null || Boolean.TRUE.equals(computer.isUnix()); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd also make this class final and add private constructor |
||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/hudson/plugins/gradle/injection/MavenExtension.java
This file contains 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,32 @@ | ||
package hudson.plugins.gradle.injection; | ||
|
||
public enum MavenExtension { | ||
GRADLE_ENTERPRISE("gradle-enterprise-maven-extension", ExtensionsVersions.GE_EXTENSION_VERSION, new MavenCoordinates("com.gradle", "gradle-enterprise-maven-extension")), | ||
CCUD("common-custom-user-data-maven-extension", ExtensionsVersions.CCUD_EXTENSION_VERSION, new MavenCoordinates("com.gradle", "common-custom-user-data-maven-extension")), | ||
CONFIGURATION("configuration-maven-extension", "1.0.0", new MavenCoordinates("com.gradle", "configuration-maven-extension")); | ||
|
||
private static final String JAR_EXTENSION = ".jar"; | ||
|
||
private final String name; | ||
private final String version; | ||
|
||
private final MavenCoordinates coordinates; | ||
|
||
MavenExtension(String name, String version, MavenCoordinates coordinates) { | ||
this.name = name; | ||
this.version = version; | ||
this.coordinates = coordinates; | ||
} | ||
|
||
public String getTargetJarName() { | ||
return name + JAR_EXTENSION; | ||
} | ||
|
||
public String getEmbeddedJarName() { | ||
return name + "-" + version + JAR_EXTENSION; | ||
} | ||
|
||
public MavenCoordinates getCoordinates() { | ||
return coordinates; | ||
} | ||
} |
This file contains 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
43 changes: 43 additions & 0 deletions
43
src/main/java/hudson/plugins/gradle/injection/MavenExtensionsDetector.java
This file contains 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,43 @@ | ||
package hudson.plugins.gradle.injection; | ||
|
||
import hudson.FilePath; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.IOException; | ||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
public class MavenExtensionsDetector { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(MavenExtensionsDetector.class); | ||
|
||
static Set<MavenExtension> detect(InjectionConfig config, FilePath workspace) throws IOException, InterruptedException { | ||
if (!config.isInjectMavenExtension()) { | ||
return Collections.emptySet(); | ||
} | ||
|
||
FilePath extensionsFile = workspace.child(".mvn/extensions.xml"); | ||
|
||
if (extensionsFile.exists()) { | ||
LOGGER.debug("Found extensions file: {}", extensionsFile); | ||
|
||
MavenExtensions mavenExtensions = MavenExtensions.fromFilePath(extensionsFile); | ||
|
||
Set<MavenExtension> knownExtensions = new HashSet<>(); | ||
if (mavenExtensions.hasExtension(MavenExtension.GRADLE_ENTERPRISE.getCoordinates()) || | ||
mavenExtensions.hasExtension(MavenCoordinates.parseCoordinates(config.getMavenExtensionCustomCoordinates()))) { | ||
knownExtensions.add(MavenExtension.GRADLE_ENTERPRISE); | ||
} | ||
if (mavenExtensions.hasExtension(MavenExtension.CCUD.getCoordinates()) || | ||
mavenExtensions.hasExtension(MavenCoordinates.parseCoordinates(config.getCcudExtensionCustomCoordinates())) | ||
) { | ||
knownExtensions.add(MavenExtension.CCUD); | ||
} | ||
return knownExtensions; | ||
} else { | ||
LOGGER.debug("Extensions file not found: {}", extensionsFile); | ||
return Collections.emptySet(); | ||
} | ||
} | ||
} |
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.
I believe we can extract the logic of both of these methods into a private method and reuse it