Skip to content
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

Added a scriptable option for selecting Unity installation #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions src/main/java/org/jenkinsci/plugins/unity3d/Unity3dBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,12 @@ public class Unity3dBuilder extends Builder {
private String argLine;
private String unstableReturnCodes;

private String scriptableUnity3dName;

@DataBoundConstructor
public Unity3dBuilder(String unity3dName, String argLine, String unstableReturnCodes) {
public Unity3dBuilder(String unity3dName, String scriptableUnity3dName, String argLine, String unstableReturnCodes) {
this.unity3dName = unity3dName;
this.scriptableUnity3dName = scriptableUnity3dName;
this.argLine = argLine;
this.unstableReturnCodes = unstableReturnCodes;
}
Expand Down Expand Up @@ -106,6 +109,10 @@ public String getUnity3dName() {
return unity3dName;
}

public String getScriptableUnity3dName() {
return scriptableUnity3dName;
}


private static class PerformException extends Exception {
private static final long serialVersionUID = 1L;
Expand Down Expand Up @@ -134,7 +141,7 @@ public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListene
private void _perform(AbstractBuild<?,?> build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException, PerformException {
EnvVars env = build.getEnvironment(listener);

Unity3dInstallation ui = getAndConfigureUnity3dInstallation(listener, env);
Unity3dInstallation ui = getAndConfigureUnity3dInstallation(build, listener, env);

ArgumentListBuilder args = prepareCommandlineArguments(build, launcher, ui, env);

Expand Down Expand Up @@ -225,8 +232,9 @@ private ArgumentListBuilder prepareCommandlineArguments(AbstractBuild<?,?> build
return createCommandlineArgs(exe, moduleRootRemote, vars, buildParameters);
}

private Unity3dInstallation getAndConfigureUnity3dInstallation(BuildListener listener, EnvVars env) throws PerformException, IOException, InterruptedException {
Unity3dInstallation ui = getUnity3dInstallation();
private Unity3dInstallation getAndConfigureUnity3dInstallation(AbstractBuild<?,?> build, BuildListener listener, EnvVars env) throws PerformException, IOException, InterruptedException {
Map<String,String> buildParameters = build.getBuildVariables();
Unity3dInstallation ui = getUnity3dInstallation(env, buildParameters);

if(ui==null) {
throw new PerformException(Messages.Unity3d_NoUnity3dInstallation());
Expand Down Expand Up @@ -259,9 +267,20 @@ ArgumentListBuilder createCommandlineArgs(String exe, String moduleRootRemote, E
* @return the Unity3d to invoke,
* or null to invoke the default one.
*/
private Unity3dInstallation getUnity3dInstallation() {
private Unity3dInstallation getUnity3dInstallation(EnvVars env, Map<String,String> buildVariables) {
String installationToUse;
if (scriptableUnity3dName != null && scriptableUnity3dName.length() > 0) {
installationToUse = scriptableUnity3dName;
installationToUse = Util.replaceMacro(installationToUse, buildVariables);
installationToUse = Util.replaceMacro(installationToUse, env);
installationToUse = Util.replaceMacro(installationToUse, buildVariables);
}
else {
installationToUse = unity3dName;
}

for( Unity3dInstallation i : getDescriptor().getInstallations() ) {
if(unity3dName!=null && unity3dName.equals(i.getName()))
if(installationToUse!=null && installationToUse.equals(i.getName()))
return i;
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
</j:forEach>
</select>
</f:entry>
<f:entry title="${%Scriptable Unity3d installation name}" field="scriptableUnity3dName">
<f:textbox />
</f:entry>
<f:entry title="${%Editor command line arguments}" field="argLine">
<f:textbox />
</f:entry>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void buildOSXPlayerAddMissingProjectPath() {
}

private void ensureCreateCommandlineArgs(List<String> expectedArgs1) {
Unity3dBuilder builder = new Unity3dBuilder("Unity 3.5", argLine, "");
Unity3dBuilder builder = new Unity3dBuilder("Unity 3.5", "", argLine, "");
ArgumentListBuilder commandlineArgs = builder.createCommandlineArgs(exe, moduleRootRemote, new EnvVars(), new Hashtable<String,String>());
assertEquals(expectedArgs1, commandlineArgs.toList());
}
Expand All @@ -73,7 +73,7 @@ public void environmentAndBuildVariablesParsing() {
argLine = "-param1 $param1 -param2 $param2 -projectPath XXXX";
expectedArgs = asList(exe, "-param1", "value1", "-param2", param2overwrittenValue, "-projectPath", "XXXX");

Unity3dBuilder builder = new Unity3dBuilder("Unity 3.5", argLine, "");
Unity3dBuilder builder = new Unity3dBuilder("Unity 3.5", "", argLine, "");
ArgumentListBuilder commandlineArgs = builder.createCommandlineArgs(exe, moduleRootRemote, vars, buildParameters);
assertEquals(expectedArgs, commandlineArgs.toList());
assertEquals("Serialized arg line not modified", argLine, builder.getArgLine());
Expand All @@ -90,7 +90,7 @@ public void environmentAndBuildVariablesParsingWithEnvVarsThatReferencesBuildPar
argLine = "-p1 v1 $ARGS";
expectedArgs = asList(exe, "-p1", "v1", "-projectPath", "XXXX");

Unity3dBuilder builder = new Unity3dBuilder("Unity 3.5", argLine, "");
Unity3dBuilder builder = new Unity3dBuilder("Unity 3.5", "", argLine, "");
ArgumentListBuilder commandlineArgs = builder.createCommandlineArgs(exe, moduleRootRemote, vars, buildParameters);
assertEquals(expectedArgs, commandlineArgs.toList());
assertEquals("Serialized arg line not modified", argLine, builder.getArgLine());
Expand All @@ -108,11 +108,11 @@ public void unstableErrorCodesParsing() throws Exception {
}

private void ensureUnstableReturnCodesParsingWorks(Integer[] expectedResultCodes, String unstableReturnCodes) throws Exception {
Unity3dBuilder builder = new Unity3dBuilder("Unity 3.5", argLine, unstableReturnCodes);
Unity3dBuilder builder = new Unity3dBuilder("Unity 3.5", "", argLine, unstableReturnCodes);
assertEquals(new HashSet<Integer>(asList(expectedResultCodes)), builder.toUnstableReturnCodesSet());
}
private void ensureUnstableReturnCodesParsingFails(String unstableReturnCodes) {
Unity3dBuilder builder = new Unity3dBuilder("Unity 3.5", argLine, unstableReturnCodes);
Unity3dBuilder builder = new Unity3dBuilder("Unity 3.5", "", argLine, unstableReturnCodes);
try {
builder.toUnstableReturnCodesSet();
Assert.fail("Expected failure");
Expand Down