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

Removed code duplication when calling commands #373

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 27 additions & 0 deletions server/scripts/publish-greenmini-stage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash -e

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SOURCE_DIR=${SCRIPT_DIR}/../..

VERSION=$(date "+%Y%m%d_%H%M")

PRODUCTION_VARIANT=stage
TARGET_HOST_URL=45.148.170.135
TARGET_HOST=${TARGET_HOST_URL}
TARGET_USER=bjorn
TARGET_DIR=/usr/local/extender-${PRODUCTION_VARIANT}
# TARGET_KEY=~/.ssh/defold2_ec2.pem

source ${SCRIPT_DIR}/standalone/publish-standalone.sh

# check_uncommitted_changes ${SOURCE_DIR}
build_artifact ${SOURCE_DIR}
deploy_artifact ${SOURCE_DIR} ${TARGET_DIR} ${VERSION} ${TARGET_HOST} ${TARGET_USER} ${PRODUCTION_VARIANT}

SERVER=https://${TARGET_HOST_URL}

echo "**********************************"
echo "Checking the server version at ${SERVER}:"
wget -q -O - $SERVER
echo ""
echo "**********************************"
145 changes: 55 additions & 90 deletions server/src/main/java/com/defold/extender/Extender.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,19 @@ private File uniqueTmpFile(String pattern) {
return createBuildFile(String.format(pattern, getNameUUID()));
}

private String executeCommand(String template, Map<String, Object> context) throws ExtenderException {
String command = templateExecutor.execute(template, context);
try {
if (processExecutor.execute(command) != 0) {
throw new ExtenderException(processExecutor.getOutput());
}
} catch (IOException | InterruptedException e) {
throw new ExtenderException(e, processExecutor.getOutput());
}

return processExecutor.getOutput();
}

private static int countLines(String str) {
String[] lines = str.split("\r\n|\r|\n");
return lines.length;
Expand Down Expand Up @@ -668,8 +681,7 @@ private File linkCppShared(File extBuildDir, List<String> objs, Map<String, Obje
context.put("src", objs);
context.put("tgt", ExtenderUtil.getRelativePath(jobDirectory, output));

String command = templateExecutor.execute(cmd, context);
processExecutor.execute(command);
executeCommand(cmd, context);

return output;
}
Expand All @@ -681,8 +693,7 @@ private File compileMain(File maincpp, Map<String, Object> manifestContext) thro
context.put("extension_name_upper", "ENGINE_MAIN");
context.put("src", ExtenderUtil.getRelativePath(jobDirectory, maincpp));
context.put("tgt", ExtenderUtil.getRelativePath(jobDirectory, o));
String command = templateExecutor.execute(platformConfig.compileCmd, context);
processExecutor.execute(command);
executeCommand(platformConfig.compileCmd, context);
return o;
}

Expand Down Expand Up @@ -720,8 +731,7 @@ private List<File> generateProtoCxxForEngine(File extDir, Map<String, Object> ma
context.put("src", ExtenderUtil.getRelativePath(jobDirectory, protoFile));
context.put("ext", ImmutableMap.of("includes", includes));
context.put("out_dir", extBuildDir);
String command = templateExecutor.execute(platformConfig.protoEngineCxxCmd, context);
processExecutor.execute(command);
executeCommand(platformConfig.protoEngineCxxCmd, context);

LOGGER.info("Generated {}", tgtCpp);

Expand Down Expand Up @@ -764,8 +774,7 @@ else if (language.equals("python"))
// Adding the source folderpath, so the output relative path gets stripped and the output becomes "extBuildDir/proto_file_name.pb.cc"
context.put("proto_path", ExtenderUtil.getRelativePath(jobDirectory, protoFile.getParentFile()));

String command = templateExecutor.execute(platformConfig.protoPipelineCmd, context);
processExecutor.execute(command);
executeCommand(platformConfig.protoPipelineCmd, context);

LOGGER.info("Generated {}", tgtFile);

Expand Down Expand Up @@ -929,8 +938,7 @@ private List<File> buildPods() throws IOException, InterruptedException, Extende
Map<String, Object> context = createContext(manifestContext);
context.put("tgt", lib);
context.put("objs", objs);
String command = templateExecutor.execute(platformConfig.libCmd, context);
processExecutor.execute(command);
executeCommand(platformConfig.libCmd, context);
}
}

Expand Down Expand Up @@ -1022,8 +1030,7 @@ private List<File> buildExtensionInternal(File manifest, Map<String, Object> man
Map<String, Object> context = createContext(manifestContext);
context.put("tgt", lib);
context.put("objs", objs);
String command = templateExecutor.execute(platformConfig.libCmd, context);
processExecutor.execute(command);
executeCommand(platformConfig.libCmd, context);

return outputFiles;
}
Expand Down Expand Up @@ -1131,8 +1138,7 @@ private List<File> buildPipelineExtension(File manifest, Map<String, Object> man
context.put("classesDir", classesDir.getAbsolutePath());
context.put("classPath", classPath);
context.put("sourcesListFile", sourcesListFile.getAbsolutePath());
String command = templateExecutor.execute(platformConfig.javacCmd, context);
processExecutor.execute(command);
executeCommand(platformConfig.javacCmd, context);
}

// Collect all classes into a Jar file
Expand All @@ -1141,8 +1147,7 @@ private List<File> buildPipelineExtension(File manifest, Map<String, Object> man

context.put("outputJar", outputJar.getAbsolutePath());
context.put("classesDir", classesDir.getAbsolutePath());
String command = templateExecutor.execute(platformConfig.jarCmd, context);
processExecutor.execute(command);
executeCommand(platformConfig.jarCmd, context);

outputFiles.add(outputJar);
}
Expand Down Expand Up @@ -1305,8 +1310,7 @@ private List<File> linkEngine(List<String> symbols, Map<String, Object> linkCont
Map<String, Object> symbolContext = createContext(linkContext);
symbolContext.put("src", ExtenderUtil.getRelativePath(jobDirectory, exe));

symbolCmd = templateExecutor.execute(symbolCmd, symbolContext);
processExecutor.execute(symbolCmd);
executeCommand(symbolCmd, symbolContext);
}
}
else {
Expand Down Expand Up @@ -1435,14 +1439,12 @@ private File compileAndroidResources(List<String> resourceDirectories, Map<Strin
for (File resourceFile : resourceTypeDir.listFiles()) {
context.put("resourceFile", resourceFile.getAbsolutePath());

String command = templateExecutor.execute(platformConfig.aapt2compileCmd, context);
processExecutor.execute(command);
executeCommand(platformConfig.aapt2compileCmd, context);
}
}
}

} catch (IOException | InterruptedException e) {
throw new ExtenderException(e, processExecutor.getOutput());
} catch (IOException e) {
throw new ExtenderException(e, "Compiling Android resources");
}

return outputDirectory;
Expand Down Expand Up @@ -1497,11 +1499,9 @@ private Map<String, File> linkAndroidResources(File compiledResourcesDir, Map<St
files.put("outApkFile", outApkFile);
files.put("outJavaDirectory", outputJavaDirectory);

String command = templateExecutor.execute(platformConfig.aapt2linkCmd, context);
processExecutor.execute(command);
}
catch (IOException | InterruptedException e) {
throw new ExtenderException(e, processExecutor.getOutput());
executeCommand(platformConfig.aapt2linkCmd, context);
} catch (IOException e) {
throw new ExtenderException(e, "Linking Android resources");
}

return files;
Expand All @@ -1519,31 +1519,25 @@ private File generateRJava(List<String> resourceDirectories, Map<String, Object>

// From 1.2.165
rJavaDir = new File(buildDirectory, "rjava");
try {
rJavaDir.mkdir();
rJavaDir.mkdir();

if (platformConfig.rjavaCmd == null) {
LOGGER.info("No rjavaCmd found. Skipping");
return rJavaDir;
}
if (platformConfig.rjavaCmd == null) {
LOGGER.info("No rjavaCmd found. Skipping");
return rJavaDir;
}

Map<String, Object> context = createContext(mergedAppContext);
if (mergedAppContext.containsKey("aaptExtraPackages")) {
context.put("extraPackages", String.join(":", (List<String>)mergedAppContext.get("aaptExtraPackages")));
}
Map<String, Object> context = createContext(mergedAppContext);
if (mergedAppContext.containsKey("aaptExtraPackages")) {
context.put("extraPackages", String.join(":", (List<String>)mergedAppContext.get("aaptExtraPackages")));
}

// Use the merged manifest
File manifestFile = new File(buildDirectory, MANIFEST_ANDROID);
context.put("manifestFile", manifestFile.getAbsolutePath());
context.put("outputDirectory", rJavaDir.getAbsolutePath());
context.put("resourceDirectories", resourceDirectories);
// Use the merged manifest
File manifestFile = new File(buildDirectory, MANIFEST_ANDROID);
context.put("manifestFile", manifestFile.getAbsolutePath());
context.put("outputDirectory", rJavaDir.getAbsolutePath());
context.put("resourceDirectories", resourceDirectories);

String command = templateExecutor.execute(platformConfig.rjavaCmd, context);
processExecutor.execute(command);

} catch (IOException | InterruptedException e) {
throw new ExtenderException(e, processExecutor.getOutput());
}
executeCommand(platformConfig.rjavaCmd, context);

return rJavaDir;
}
Expand Down Expand Up @@ -1583,20 +1577,18 @@ private File buildRJar(File rJavaDir) throws ExtenderException {
context.put("classesDir", classesDir.getAbsolutePath());
context.put("classPath", classesDir.getAbsolutePath());
context.put("sourcesListFile", sourcesListFile.getAbsolutePath());
String command = templateExecutor.execute(platformConfig.javacCmd, context);
processExecutor.execute(command);
executeCommand(platformConfig.javacCmd, context);

// Collect all classes into a Jar file
context = createContext(mergedAppContext);
context.put("outputJar", outputJar.getAbsolutePath());
context.put("classesDir", classesDir.getAbsolutePath());
command = templateExecutor.execute(platformConfig.jarCmd, context);
processExecutor.execute(command);
executeCommand(platformConfig.jarCmd, context);

return outputJar;
}
} catch (IOException | InterruptedException e) {
throw new ExtenderException(e, processExecutor.getOutput());
} catch (IOException e) {
throw new ExtenderException(e, "Building Android resources (R.java)");
}

return null;
Expand Down Expand Up @@ -1698,20 +1690,18 @@ private Map.Entry<File, ProGuardContext> buildJavaExtension(File manifest, Map<S

context.put("classPath", classPath);
context.put("sourcesListFile", sourcesListFile.getAbsolutePath());
String command = templateExecutor.execute(platformConfig.javacCmd, context);
processExecutor.execute(command);
executeCommand(platformConfig.javacCmd, context);

// Collect all classes into a Jar file
context = createContext(manifestContext);
context.put("outputJar", outputJar.getAbsolutePath());
context.put("classesDir", classesDir.getAbsolutePath());
command = templateExecutor.execute(platformConfig.jarCmd, context);
processExecutor.execute(command);
executeCommand(platformConfig.jarCmd, context);

return new AbstractMap.SimpleEntry<File, ProGuardContext>(outputJar, proGuardContext);

} catch (IOException | InterruptedException e) {
throw new ExtenderException(e, processExecutor.getOutput());
} catch (IOException e) {
throw new ExtenderException(e, "Building java extension");
}
}

Expand Down Expand Up @@ -1871,13 +1861,7 @@ private Map.Entry<File,File> buildProGuard(List<String> allJars, Map<String,ProG
context.put("tgt", targetFile.getAbsolutePath());
context.put("mapping", mappingFile.getAbsolutePath());

String command = templateExecutor.execute(proGuardCmd, context);

try {
processExecutor.execute(command);
} catch (IOException | InterruptedException e) {
throw new ExtenderException(e, processExecutor.getOutput());
}
executeCommand(proGuardCmd, context);

return new AbstractMap.SimpleEntry<File, File>(targetFile, mappingFile);
}
Expand Down Expand Up @@ -1956,15 +1940,7 @@ private File[] buildClassesDex(List<String> jars, File mainDexList) throws Exten
context.put("engineJars", empty_list);
context.put("mainDexList", mainDexList.getAbsolutePath());

String command = platformConfig.dxCmd;

command = templateExecutor.execute(command, context);

try {
processExecutor.execute(command);
} catch (IOException | InterruptedException e) {
throw new ExtenderException(e, processExecutor.getOutput());
}
executeCommand(platformConfig.dxCmd, context);

File[] classes = ExtenderUtil.listFilesMatching(buildDirectory, "^classes(|[0-9]+)\\.dex$");
return classes;
Expand Down Expand Up @@ -2405,13 +2381,7 @@ private List<File> buildApple(String platform) throws ExtenderException {
context.put("platform", getBasePlatform(platform));
context.put("libraries", privacyManifests);

try {
String command = templateExecutor.execute(platformConfig.manifestMergeCmd, context);
processExecutor.execute(command);
}
catch (IOException | InterruptedException e) {
throw new ExtenderException(e, processExecutor.getOutput());
}
executeCommand(platformConfig.manifestMergeCmd, context);

return outputFiles;
}
Expand Down Expand Up @@ -2491,12 +2461,7 @@ private List<File> buildManifests(String platform) throws ExtenderException {
.collect(Collectors.toList());
context.put("libraries", libraries);

try {
String command = templateExecutor.execute(platformConfig.manifestMergeCmd, context);
processExecutor.execute(command);
} catch (IOException | InterruptedException e) {
throw new ExtenderException(e, processExecutor.getOutput());
}
executeCommand(platformConfig.manifestMergeCmd, context);
}
return out;
}
Expand Down