Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-14780] fix permission and move makeExecutable as an option
  • Loading branch information
ndeloof committed Aug 20, 2012
1 parent e3671d9 commit a3dc7bc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
26 changes: 23 additions & 3 deletions src/main/java/hudson/plugins/gradle/Gradle.java
Expand Up @@ -14,6 +14,7 @@
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;


/**
Expand All @@ -28,17 +29,19 @@ public class Gradle extends Builder implements DryRun {
private final String buildFile;
private final String gradleName;
private final boolean useWrapper;
private final boolean makeExecutable;

@DataBoundConstructor
public Gradle(String description, String switches, String tasks, String rootBuildScriptDir, String buildFile,
String gradleName, boolean useWrapper) {
String gradleName, boolean useWrapper, boolean makeExecutable) {
this.description = description;
this.switches = switches;
this.tasks = tasks;
this.gradleName = gradleName;
this.rootBuildScriptDir = rootBuildScriptDir;
this.buildFile = buildFile;
this.useWrapper = !useWrapper;
this.useWrapper = useWrapper;
this.makeExecutable = makeExecutable;
}


Expand Down Expand Up @@ -77,6 +80,11 @@ public String getRootBuildScriptDir() {
return rootBuildScriptDir;
}

@SuppressWarnings("unused")
public boolean isMakeExecutable() {
return makeExecutable;
}

public GradleInstallation getGradle() {
for (GradleInstallation i : getDescriptor().getInstallations()) {
if (gradleName != null && i.getName().equals(gradleName)) {
Expand Down Expand Up @@ -141,7 +149,9 @@ private boolean performTask(boolean dryRun, AbstractBuild<?, ?> build, Launcher
if (useWrapper) {
String execName = (launcher.isUnix()) ? GradleInstallation.UNIX_GRADLE_WRAPPER_COMMAND : GradleInstallation.WINDOWS_GRADLE_WRAPPER_COMMAND;
FilePath gradleWrapperFile = new FilePath(build.getModuleRoot(), execName);
gradleWrapperFile.chmod(744);
if (makeExecutable) {
gradleWrapperFile.chmod(0744);
}
args.add(gradleWrapperFile.getRemote());
} else {
args.add(launcher.isUnix() ? GradleInstallation.UNIX_GRADLE_COMMAND : GradleInstallation.WINDOWS_GRADLE_COMMAND);
Expand Down Expand Up @@ -303,6 +313,16 @@ public void setInstallations(GradleInstallation... installations) {

@Override
public Gradle newInstance(StaplerRequest request, JSONObject formData) throws FormException {

// "flatten" formData for useWrapper radioBlocks
JSONObject useWrapper = formData.getJSONObject("useWrapper");
boolean wrapper = useWrapper.getBoolean("value");
useWrapper.remove("value");
for (String key : (Set<String>) useWrapper.keySet()) {
formData.put(key, useWrapper.get(key));
}
formData.put("useWrapper", wrapper);

return (Gradle) request.bindJSON(clazz, formData);
}
}
Expand Down
14 changes: 9 additions & 5 deletions src/main/resources/hudson/plugins/gradle/Gradle/config.jelly
@@ -1,17 +1,21 @@
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout"
xmlns:t="/lib/hudson" xmlns:f="/lib/form">

<f:optionalBlock name="useWrapper" checked="${instance.useWrapper}"
title="Use Gradle Wrapper" inline="true" negative="true">
<f:entry title="${%Gradle Version}">
<select class="setting-input" name="gradle.gradleName">
<f:radioBlock name="useWrapper" checked="${!instance.useWrapper}" value="false" title="${%Invoke Gradle}">
<f:entry title="${%Gradle Version}" field="gradleName">
<select class="setting-input">
<option>(Default)</option>
<j:forEach var="inst" items="${descriptor.installations}">
<f:option selected="${inst.name==instance.gradle.name}">${inst.name}</f:option>
</j:forEach>
</select>
</f:entry>
</f:optionalBlock>
</f:radioBlock>
<f:radioBlock name="useWrapper" checked="${instance.useWrapper}" value="true" title="${%Use Gradle Wrapper}">
<f:entry title="${%Make gradlew executable}" field="makeExecutable">
<f:checkbox />
</f:entry>
</f:radioBlock>

<f:entry title="${%Build step description}" field="description">
<f:expandableTextbox/>
Expand Down

0 comments on commit a3dc7bc

Please sign in to comment.