public static void appendCamelCase(@NonNull StringBuilder sb, @Nullable String word) { if (word != null) { if (sb.length() == 0) { sb.append(word); } else { sb.append(StringHelper.capitalize(word)); } } }
private File getGeneratedResourcesDirectory(String name) { return FileUtils.join( getGeneratedDirectory(), StringHelper.toStrings( "res", name, Collections.singletonList("android"))); }
/** * Returns a unique directory name (can include multiple folders) for the variant, * based on build type, flavor and test. * * @return the directory name for the variant */ @NonNull public Collection<String> getDirectorySegments() { if (mDirSegments == null) { ImmutableList.Builder<String> builder = ImmutableList.builder(); if (mType.isForTesting()) { builder.add(mType.getPrefix()); } if (!mFlavors.isEmpty()) { StringBuilder sb = new StringBuilder(mFlavors.size() * 10); for (F flavor : mFlavors) { StringHelper.appendCamelCase(sb, flavor.getName()); } builder.add(sb.toString()); builder.add(mBuildType.getName()); } else { builder.add(mBuildType.getName()); } mDirSegments = builder.build(); } return mDirSegments; } /**
@NonNull private static List<String> convertFlagFormat(@NonNull String flags) { return NativeCompilerArgsUtil.transform(StringHelper.tokenizeString(flags)); }
/** * Return the name of the combined list of flavors. */ @NonNull public static String getFlavorComboName(List<? extends Named> flavorList) { return StringHelper.combineAsCamelCase( flavorList.stream() .map(namedObject -> namedObject.getName()) .collect(Collectors.toList())); }
file.flags = StringHelper.quoteAndJoinTokens(flags);
/** * Given a list of build commands, execute each. If there is a failure, processing is stopped at * that point. */ protected void executeProcessBatch(@NonNull List<String> commands, @NonNull List<String> targetNames) throws ProcessException, IOException { for (int commandIndex = 0; commandIndex < commands.size(); ++commandIndex) { String command = commands.get(commandIndex); String target = targetNames.get(commandIndex); getLogger().lifecycle(String.format("Clean %s", target)); List<String> tokens = StringHelper.tokenizeString(command); ProcessInfoBuilder processBuilder = new ProcessInfoBuilder(); processBuilder.setExecutable(tokens.get(0)); for (int i = 1; i < tokens.size(); ++i) { processBuilder.addArgs(tokens.get(i)); } diagnostic("%s", processBuilder); ExternalNativeBuildTaskUtils.executeBuildProcessAndLogError( getBuilder(), processBuilder, true /* logStdioToInfo */); } }
StringHelper.combineAsCamelCase( ImmutableList.of( "transformJackWith",
@NonNull public static String combineAsCamelCase(@NonNull Iterable<String> stringList) { StringBuilder sb = new StringBuilder(); boolean first = true; for (String str : stringList) { if (first) { sb.append(str); first = false; } else { sb.append(StringHelper.capitalize(str)); } } return sb.toString(); }
public File getResourceBlameLogDirectory() { return FileUtils.join( getIntermediatesDirectory(), StringHelper.toStrings( "blame", "res", Collections.singletonList("android"))); }
/** * Given a list of build commands, execute each. If there is a failure, processing is stopped at * that point. */ protected void executeProcessBatch( @NonNull List<String> libraryNames, @NonNull List<String> commands) throws BuildCommandException, IOException { // Order of building doesn't matter to final result but building in reverse order causes // the dependencies to be built first for CMake and ndk-build. This gives better progress // visibility to the user because they will see "building XXXXX.a" before // "building XXXXX.so". Nicer still would be to have the dependency information in the JSON // so we can build in toposort order. for (int library = libraryNames.size() - 1; library >= 0; --library) { String libraryName = libraryNames.get(library); getLogger().lifecycle(String.format("Build %s", libraryName)); String command = commands.get(library); List<String> tokens = StringHelper.tokenizeString(command); ProcessInfoBuilder processBuilder = new ProcessInfoBuilder(); processBuilder.setExecutable(tokens.get(0)); for (int i = 1; i < tokens.size(); ++i) { processBuilder.addArgs(tokens.get(i)); } diagnostic("%s", processBuilder); ExternalNativeBuildTaskUtils.executeBuildProcessAndLogError( getBuilder(), processBuilder, true /* logStdioToInfo */); } }
@Override public String getName() { return "uninstall" + StringHelper.capitalize(scope.getVariantConfiguration().getFullName()); }
@NonNull private File getGeneratedResourcesDir(String name) { return FileUtils.join( globalScope.getGeneratedDir(), StringHelper.toStrings( "res", name, getDirectorySegments())); }
@NonNull protected String getCapitalizedFlavorName() { return StringHelper.capitalize(variantConfiguration.getFlavorName()); }
@NonNull @Override public File getResourceBlameLogDir() { return FileUtils.join( globalScope.getIntermediatesDir(), StringHelper.toStrings( "blame", "res", getDirectorySegments())); }
@NonNull protected String getCapitalizedFlavorName() { return StringHelper.capitalize(variantConfiguration.getFlavorName()); }
@NonNull private File getGeneratedAssetsDir(String name) { return FileUtils.join( globalScope.getGeneratedDir(), StringHelper.toStrings( "assets", name, getDirectorySegments())); }
@NonNull public String getName() { if (name == null) { boolean first = true; StringBuilder sb = new StringBuilder(); for (T flavor : flavorList) { if (first) { sb.append(flavor.getName()); first = false; } else { sb.append(StringHelper.capitalize(flavor.getName())); } } name = sb.toString(); } return name; }
@NonNull @Override public File getRenderscriptObjOutputDir() { return FileUtils.join( globalScope.getIntermediatesDir(), StringHelper.toStrings( "rs", getDirectorySegments(), "obj")); }
@VisibleForTesting @NonNull static String getTaskNamePrefix(@NonNull Transform transform) { StringBuilder sb = new StringBuilder(100); sb.append("transform"); sb.append( transform.getInputTypes() .stream() .map(inputType -> CaseFormat.UPPER_UNDERSCORE.to( CaseFormat.UPPER_CAMEL, inputType.name())) .sorted() // Keep the order stable. .collect(Collectors.joining("And"))) .append("With") .append(capitalize(transform.getName())) .append("For"); return sb.toString(); }