Skip to content

Commit

Permalink
Add Temporary Binary Directory field
Browse files Browse the repository at this point in the history
  • Loading branch information
Yann Diorcet authored and Cyrille Le Clerc committed Dec 3, 2018
1 parent 889d9c0 commit 9185cc2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
public class WithMavenStep extends Step {


private String tempBinDir;
private String mavenSettingsConfig;
private String mavenSettingsFilePath = "";
private String globalMavenSettingsConfig;
Expand All @@ -81,7 +82,15 @@ public class WithMavenStep extends Step {
public WithMavenStep() {
}


public String getTempBinDir() {
return tempBinDir;
}

@DataBoundSetter
public void setTempBinDir(String tempBinDir) {
this.tempBinDir = tempBinDir;
}

public String getMavenSettingsConfig() {
return mavenSettingsConfig;
}
Expand Down Expand Up @@ -216,7 +225,7 @@ public Set<Class<?>> getRequiredContext() {
public SettingsProvider getDefaultSettingsProvider() {
return GlobalMavenConfig.get().getSettingsProvider();
}

private Maven.DescriptorImpl getMavenDescriptor() {
return Jenkins.getInstance().getDescriptorByType(Maven.DescriptorImpl.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@
import org.jenkinsci.plugins.workflow.steps.EnvironmentExpander;
import org.jenkinsci.plugins.workflow.steps.StepContext;
import org.jenkinsci.plugins.workflow.steps.StepExecution;
import org.jenkinsci.plugins.tokenmacro.MacroEvaluationException;
import org.jenkinsci.plugins.tokenmacro.TokenMacro;
import org.springframework.util.ClassUtils;

@SuppressFBWarnings(value = "SE_TRANSIENT_FIELD_NOT_RESTORED", justification = "Contextual fields used only in start(); no onResume needed")
Expand Down Expand Up @@ -166,6 +168,7 @@ public boolean start() throws Exception {
LOGGER.log(Level.FINE, "Maven: {0}", step.getMaven());
LOGGER.log(Level.FINE, "Jdk: {0}", step.getJdk());
LOGGER.log(Level.FINE, "MavenOpts: {0}", step.getMavenOpts());
LOGGER.log(Level.FINE, "Temporary Binary Directory: {0}", step.getTempBinDir());
LOGGER.log(Level.FINE, "Settings Config: {0}", step.getMavenSettingsConfig());
LOGGER.log(Level.FINE, "Settings FilePath: {0}", step.getMavenSettingsFilePath());
LOGGER.log(Level.FINE, "Global settings Config: {0}", step.getGlobalMavenSettingsConfig());
Expand Down Expand Up @@ -306,7 +309,18 @@ private void setupJDK() throws AbortException, IOException, InterruptedException
*/
private void setupMaven(@Nonnull Collection<Credentials> credentials) throws IOException, InterruptedException {
// Temp dir with the wrapper that will be prepended to the path and the temporary files used by withMaven (settings files...)
tempBinDir = tempDir(ws).child("withMaven" + Util.getDigestOf(UUID.randomUUID().toString()).substring(0, 8));
if (step.getTempBinDir() != null && !step.getTempBinDir().isEmpty()) {
String expandedTargetLocation = step.getTempBinDir();
try {
expandedTargetLocation = TokenMacro.expandAll(build, ws, listener, expandedTargetLocation);
} catch (MacroEvaluationException e) {
listener.getLogger().println("[ERROR] failed to expand variables in target location '" + expandedTargetLocation + "' : " + e.getMessage());
}
tempBinDir = new FilePath(ws, expandedTargetLocation);
}
if (tempBinDir == null) {
tempBinDir = tempDir(ws).child("withMaven" + Util.getDigestOf(UUID.randomUUID().toString()).substring(0, 8));
}
tempBinDir.mkdirs();
envOverride.put("MVN_CMD_DIR", tempBinDir.getRemote());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ THE SOFTWARE.
<f:entry title="${%JDK}" field="jdk">
<f:select/>
</f:entry>
<f:entry title="${%Temporary Binary Directory}" field="tempBinDir">
<f:textbox/>
</f:entry>
<f:entry title="${%Maven Settings Config}" field="mavenSettingsConfig">
<f:select/>
</f:entry>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div>
Specify a custom temporary binaries directory.
Allow to have a constant path to the maven binaries, then a constant environment for reproducible compilations. Some tools detect an environment change as a sources change, which will retrigger the compilation of all sources.
</div>

0 comments on commit 9185cc2

Please sign in to comment.