Java Code Examples for com.android.utils.StringHelper

The following examples show how to use com.android.utils.StringHelper. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: atlas   Source File: InjectTransformManager.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Get the task outputStream
 *
 * @param injectTransform
 * @param scope
 * @param taskName
 * @param <T>
 * @return
 */
@NotNull
private <T extends Transform> IntermediateStream getOutputStream(T injectTransform,
                                                                 @NonNull VariantScope scope,
                                                                 String taskName) {
    File outRootFolder = FileUtils.join(project.getBuildDir(),
                                        StringHelper.toStrings(AndroidProject.FD_INTERMEDIATES,
                                                               FD_TRANSFORMS,
                                                               injectTransform.getName(),
                                                               scope.getDirectorySegments()));

    Set<? super Scope> requestedScopes = injectTransform.getScopes();

    // create the output
    return IntermediateStream.builder(project,injectTransform.getName())
            .addContentTypes(injectTransform.getOutputTypes())
            .addScopes(requestedScopes)
            .setTaskName(taskName)
            .setRootLocation(outRootFolder).build();

}
 
Example 2
@NonNull
private String getFilterName() {
    if (mainApkOutputFile.getFilters().isEmpty()) {
        return UNIVERSAL;
    }

    StringBuilder sb = new StringBuilder();
    String densityFilter = mainApkOutputFile.getFilter(OutputFile.DENSITY);
    if (densityFilter != null) {
        sb.append(densityFilter);
    }
    String abiFilter = mainApkOutputFile.getFilter(OutputFile.ABI);
    if (abiFilter != null) {
        if (sb.length() > 0) {
            sb.append(StringHelper.capitalize(abiFilter));
        } else {
            sb.append(abiFilter);
        }
    }

    return sb.toString();
}
 
Example 3
Source Project: javaide   Source File: ProductFlavorData.java    License: GNU General Public License v3.0 6 votes vote down vote up
ProductFlavorData(
        @NonNull T productFlavor,
        @NonNull DefaultAndroidSourceSet sourceSet,
        @NonNull Project project) {
    super(sourceSet, project);

    this.productFlavor = productFlavor;

    if (!BuilderConstants.MAIN.equals(sourceSet.getName())) {
        String sourceSetName = StringHelper.capitalize(sourceSet.getName());
        assembleTask = project.getTasks().create("assemble" + sourceSetName);
        assembleTask.setDescription("Assembles all " + sourceSetName + " builds.");
        assembleTask.setGroup(BasePlugin.BUILD_GROUP);
    } else {
        assembleTask = null;
    }
}
 
Example 4
Source Project: javaide   Source File: ProductFlavorCombo.java    License: GNU General Public License v3.0 6 votes vote down vote up
@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;
}
 
Example 5
Source Project: javaide   Source File: VariantConfiguration.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the full, unique name of the variant in camel case (starting with a lower case),
 * including BuildType, Flavors and Test (if applicable).
 *
 * @return the name of the variant
 */
@NonNull
public String getFullName() {
    if (mFullName == null) {
        StringBuilder sb = new StringBuilder();
        String flavorName = getFlavorName();
        if (!flavorName.isEmpty()) {
            sb.append(flavorName);
            sb.append(StringHelper.capitalize(mBuildType.getName()));
        } else {
            sb.append(mBuildType.getName());
        }

        mFullName = sb.toString();
    }

    return mFullName;
}
 
Example 6
Source Project: javaide   Source File: VariantConfiguration.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns a full name that includes the given splits name.
 *
 * @param splitName the split name
 * @return a unique name made up of the variant and split names.
 */
@NonNull
public String computeFullNameWithSplits(@NonNull String splitName) {
    StringBuilder sb = new StringBuilder();
    String flavorName = getFlavorName();
    if (!flavorName.isEmpty()) {
        sb.append(flavorName);
        sb.append(StringHelper.capitalize(splitName));
    } else {
        sb.append(splitName);
    }

    sb.append(StringHelper.capitalize(mBuildType.getName()));

    return sb.toString();
}
 
Example 7
Source Project: javaide   Source File: VariantConfiguration.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the flavor name of the variant, including all flavors in camel case (starting
 * with a lower case). If the variant has no flavor, then an empty string is returned.
 *
 * @return the flavor name or an empty string.
 */
@NonNull
public String getFlavorName() {
    if (mFlavorName == null) {
        if (mFlavors.isEmpty()) {
            mFlavorName = "";
        } else {
            StringBuilder sb = new StringBuilder();
            boolean first = true;
            for (F flavor : mFlavors) {
                sb.append(first ? flavor.getName() : StringHelper.capitalize(flavor.getName()));
                first = false;
            }

            mFlavorName = sb.toString();
        }
    }

    return mFlavorName;
}
 
Example 8
Source Project: javaide   Source File: VariantConfiguration.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns a unique directory name (can include multiple folders) for the variant,
 * based on build type, flavor and test.
 * <p>
 * <p>This always uses forward slashes ('/') as separator on all platform.
 *
 * @return the directory name for the variant
 */
@NonNull
public String getDirName() {
    if (mDirName == null) {
        StringBuilder sb = new StringBuilder();

        if (!mFlavors.isEmpty()) {
            boolean first = true;
            for (F flavor : mFlavors) {
                sb.append(first ? flavor.getName() : StringHelper.capitalize(flavor.getName()));
                first = false;
            }

            sb.append('/').append(mBuildType.getName());

        } else {
            sb.append(mBuildType.getName());
        }

        mDirName = sb.toString();

    }

    return mDirName;
}
 
Example 9
private File getGeneratedResourcesDirectory(String name) {
    return FileUtils.join(
            getGeneratedDirectory(),
            StringHelper.toStrings(
                    "res",
                    name,
                    Collections.singletonList("android")));
}
 
Example 10
Source Project: atlas   Source File: VariantContext.java    License: Apache License 2.0 5 votes vote down vote up
public File getAwbResourceBlameLogDir(AwbBundle awbBundle) {
    return FileUtils.join(
            scope.getGlobalScope().getIntermediatesDir(),
            StringHelper.toStrings(
                    "awb-blame", "res", scope.getDirectorySegments(),awbBundle.getName()));

}
 
Example 11
Source Project: atlas   Source File: VariantContext.java    License: Apache License 2.0 5 votes vote down vote up
public File getAwbShadersOutputDir(AwbBundle awbBundle) {
    return FileUtils.join(new File(
            scope.getGlobalScope().getGeneratedDir().getParentFile(),"/awb-generated/"),
            StringHelper.toStrings(
                    "assets", "shaders", scope.getDirectorySegments(),awbBundle.getName()));

}
 
Example 12
Source Project: javaide   Source File: Lint.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void execute(Lint lint) {
    lint.setLintOptions(scope.getGlobalScope().getExtension().getLintOptions());
    lint.setSdkHome(scope.getGlobalScope().getSdkHandler().getSdkFolder());
    lint.setVariantName(scope.getVariantConfiguration().getFullName());
    lint.setToolingRegistry(scope.getGlobalScope().getToolingRegistry());
    lint.setDescription(("Runs lint on the " +
            StringHelper.capitalize(scope.getVariantConfiguration().getFullName()) + " build."));
    lint.setGroup(JavaBasePlugin.VERIFICATION_GROUP);
}
 
Example 13
Source Project: javaide   Source File: PackageApplication.java    License: GNU General Public License v3.0 5 votes vote down vote up
private ShrinkResources createShrinkResourcesTask(
        final ApkVariantOutputData variantOutputData) {
    BaseVariantData<?> variantData = (BaseVariantData<?>) variantOutputData.variantData;
    ShrinkResources task = scope.getGlobalScope().getProject().getTasks()
            .create("shrink" + StringHelper
                    .capitalize(variantOutputData.getFullName())
                    + "Resources", ShrinkResources.class);
    task.setAndroidBuilder(scope.getGlobalScope().getAndroidBuilder());
    task.setVariantName(scope.getVariantScope().getVariantConfiguration().getFullName());
    task.variantOutputData = variantOutputData;

    final String outputBaseName = variantOutputData.getBaseName();
    task.setCompressedResources(new File(
            scope.getGlobalScope().getBuildDir() + "/" + FD_INTERMEDIATES + "/res/" +
                    "resources-" + outputBaseName + "-stripped.ap_"));

    ConventionMappingHelper.map(task, "uncompressedResources", new Callable<File>() {
        @Override
        public File call() {
            return variantOutputData.processResourcesTask.getPackageOutputFile();
        }
    });

    task.dependsOn(
            scope.getVariantScope().getObfuscationTask().getName(),
            scope.getManifestProcessorTask().getName(),
            variantOutputData.processResourcesTask);

    return task;
}
 
Example 14
private static String getBinaryName(BuildType buildType, ProductFlavorCombo flavorCombo) {
    if (flavorCombo.getFlavorList().isEmpty()) {
        return buildType.getName();
    } else {
        return flavorCombo.getName() + StringHelper.capitalize(buildType.getName());
    }

}
 
Example 15
/**
 * Create all source sets for each AndroidBinary.
 */
@Mutate
public void createVariantSourceSet(
        @Path("android.sources") final AndroidComponentModelSourceSet sources,
        @Path("android.buildTypes") final ModelMap<BuildType> buildTypes,
        @Path("android.productFlavors") ModelMap<ProductFlavor> flavors,
        List<ProductFlavorCombo<ProductFlavor>> flavorGroups, ProjectSourceSet projectSourceSet,
        LanguageRegistry languageRegistry) {
    sources.setProjectSourceSet(projectSourceSet);
    for (LanguageRegistration languageRegistration : languageRegistry) {
        sources.registerLanguage(languageRegistration);
    }

    // Create main source set.
    sources.create("main");

    for (BuildType buildType : buildTypes.values()) {
        sources.maybeCreate(buildType.getName());

        for (ProductFlavorCombo group : flavorGroups) {
            sources.maybeCreate(group.getName());
            if (!group.getFlavorList().isEmpty()) {
                sources.maybeCreate(
                        group.getName() + StringHelper.capitalize(buildType.getName()));
            }

        }

    }
    if (flavorGroups.size() != flavors.size()) {
        // If flavorGroups and flavors are the same size, there is at most 1 flavor
        // dimension.  So we don't need to reconfigure the source sets for flavorGroups.
        for (ProductFlavor flavor : flavors.values()) {
            sources.maybeCreate(flavor.getName());
        }
    }
}
 
Example 16
Source Project: javaide   Source File: TaskManager.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void createLintVitalTask(@NonNull ApkVariantData variantData) {
    checkState(getExtension().getLintOptions().isCheckReleaseBuilds());
    // TODO: re-enable with Jack when possible
    if (!variantData.getVariantConfiguration().getBuildType().isDebuggable()) {
        String variantName = variantData.getVariantConfiguration().getFullName();
        String capitalizedVariantName = StringHelper.capitalize(variantName);
        String taskName = "lintVital" + capitalizedVariantName;
        final Lint lintReleaseCheck = project.getTasks().create(taskName, Lint.class);
        // TODO: Make this task depend on lintCompile too (resolve initialization order first)
        optionalDependsOn(lintReleaseCheck, variantData.javacTask);
        lintReleaseCheck.setLintOptions(getExtension().getLintOptions());
        lintReleaseCheck.setSdkHome(sdkHandler.getSdkFolder());
        lintReleaseCheck.setVariantName(variantName);
        lintReleaseCheck.setToolingRegistry(toolingRegistry);
        lintReleaseCheck.setFatalOnly(true);
        lintReleaseCheck.setDescription(
                "Runs lint on just the fatal issues in the " + capitalizedVariantName
                        + " build.");
        //variantData.assembleVariantTask.dependsOn lintReleaseCheck

        // If lint is being run, we do not need to run lint vital.
        // TODO: Find a better way to do this.
        project.getGradle().getTaskGraph().whenReady(new Closure<Void>(this, this) {
            public void doCall(TaskExecutionGraph taskGraph) {
                if (taskGraph.hasTask(LINT)) {
                    lintReleaseCheck.setEnabled(false);
                }
            }
        });
    }
}
 
Example 17
Source Project: javaide   Source File: VariantManager.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Turns a string into a valid source set name for the given {@link VariantType}, e.g.
 * "fooBarUnitTest" becomes "testFooBar".
 */
@NonNull
private static String computeSourceSetName(
        @NonNull String name,
        @NonNull VariantType variantType) {
    if (name.endsWith(variantType.getSuffix())) {
        name = name.substring(0, name.length() - variantType.getSuffix().length());
    }

    if (!variantType.getPrefix().isEmpty()) {
        name = variantType.getPrefix() + StringHelper.capitalize(name);
    }

    return name;
}
 
Example 18
Source Project: javaide   Source File: BuildTypeData.java    License: GNU General Public License v3.0 5 votes vote down vote up
BuildTypeData(
        @NonNull CoreBuildType buildType,
        @NonNull Project project,
        @NonNull DefaultAndroidSourceSet sourceSet) {
    super(sourceSet, project);

    this.buildType = buildType;

    String sourceSetName = StringHelper.capitalize(buildType.getName());

    assembleTask = project.getTasks().create("assemble" + sourceSetName);
    assembleTask.setDescription("Assembles all " + sourceSetName + " builds.");
    assembleTask.setGroup(BasePlugin.BUILD_GROUP);
}
 
Example 19
public File getResourceBlameLogDirectory() {
    return FileUtils.join(
            getIntermediatesDirectory(),
            StringHelper.toStrings(
                    "blame", "res", Collections.singletonList("android")));
}
 
Example 20
Source Project: atlas   Source File: Dex.java    License: Apache License 2.0 4 votes vote down vote up
public String getTaskName(@NonNull String prefix, @NonNull String suffix) {
    return scope.getTaskName(prefix, StringHelper.capitalize(awbBundle.getName()) + suffix);
}
 
Example 21
Source Project: atlas   Source File: VariantContext.java    License: Apache License 2.0 4 votes vote down vote up
public File getGenerateResValue(AwbBundle awbBundle){
    return new File(scope.getGlobalScope().getGeneratedDir().getParentFile(),
            "/awb-generated/" + StringHelper.toStrings("res", "resValue", scope.getDirectorySegments(),
                    awbBundle.getName()));
}
 
Example 22
Source Project: atlas   Source File: VariantContext.java    License: Apache License 2.0 4 votes vote down vote up
public File getGenerateRs(AwbBundle awbBundle){
    return new File(scope.getGlobalScope().getGeneratedDir().getParentFile(),
            "/awb-generated/" + StringHelper.toStrings("res", "rs", scope.getDirectorySegments(),
                    awbBundle.getName()));
}
 
Example 23
Source Project: atlas   Source File: VariantContext.java    License: Apache License 2.0 4 votes vote down vote up
public File getPngsOutputDir(AwbBundle awbBundle) {
    return FileUtils.join(new File(scope.getGlobalScope().getGeneratedDir().getParentFile(),
                    "awb-generated"),
            StringHelper.toStrings("res", "pngs", scope.getDirectorySegments(),
                    awbBundle.getName()));
}
 
Example 24
Source Project: atlas   Source File: VariantContext.java    License: Apache License 2.0 4 votes vote down vote up
public File getRenderOutputDir(AwbBundle awbBundle) {
    return FileUtils.join(new File(scope.getGlobalScope().getGeneratedDir().getParentFile(),
                    "awb-generated"),
            StringHelper.toStrings("res","renderscript", scope.getDirectorySegments(),
                    awbBundle.getName()));
}
 
Example 25
@TaskAction
protected void prepare() {
    ApiVersion minSdkVersion = variant.getVariantConfiguration().getMinSdkVersion();
    int minSdk = 1;
    if (minSdkVersion.getCodename() != null) {
        minSdk = SdkVersionInfo.getApiByBuildCode(minSdkVersion.getCodename(), true);
    } else {
        minSdk = minSdkVersion.getApiLevel();
    }

    boolean foundError = false;

    for (DependencyChecker checker : checkers) {
        for (Map.Entry<ModuleVersionIdentifier, Integer> entry :
                checker.getLegacyApiLevels().entrySet()) {
            ModuleVersionIdentifier mavenVersion = entry.getKey();
            int api = entry.getValue();
            if (api > minSdk) {
                foundError = true;
                String configurationName = checker.getConfigurationDependencies().getName();
                getLogger().error(
                        "Variant {} has a dependency on version {} of the legacy {} Maven " +
                                "artifact, which corresponds to API level {}. This is not " +
                                "compatible with min SDK of this module, which is {}. " +
                                "Please use the 'gradle dependencies' task to debug your " +
                                "dependencies graph.",
                        StringHelper.capitalize(configurationName),
                        mavenVersion.getVersion(),
                        mavenVersion.getGroup(),
                        api,
                        minSdk);
            }
        }

        for (SyncIssue syncIssue : checker.getSyncIssues()) {
            foundError = true;
            getLogger().error(syncIssue.getMessage());
        }
    }

    if (foundError) {
        throw new GradleException("Dependency Error. See console for details.");
    }

}
 
Example 26
Source Project: javaide   Source File: BaseVariantData.java    License: GNU General Public License v3.0 4 votes vote down vote up
@NonNull
protected String getCapitalizedBuildTypeName() {
    return StringHelper.capitalize(variantConfiguration.getBuildType().getName());
}
 
Example 27
Source Project: javaide   Source File: BaseVariantData.java    License: GNU General Public License v3.0 4 votes vote down vote up
@NonNull
protected String getCapitalizedFlavorName() {
    return StringHelper.capitalize(variantConfiguration.getFlavorName());
}
 
Example 28
Source Project: javaide   Source File: VariantOutputScope.java    License: GNU General Public License v3.0 4 votes vote down vote up
@NonNull
public String getTaskName(@NonNull String prefix, @NonNull String suffix) {
    return prefix + StringHelper.capitalize(getVariantOutputData().getFullName()) + suffix;
}
 
Example 29
Source Project: javaide   Source File: VariantScope.java    License: GNU General Public License v3.0 4 votes vote down vote up
@NonNull
public String getTaskName(@NonNull String prefix, @NonNull String suffix) {
    return prefix + StringHelper.capitalize(getVariantConfiguration().getFullName()) + suffix;
}