com.android.utils.StringHelper Java Examples

The following examples show how to use com.android.utils.StringHelper. 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 File: VariantConfiguration.java    From javaide with 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 #2
Source File: VariantConfiguration.java    From javaide with 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 #3
Source File: VariantConfiguration.java    From javaide with 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 #4
Source File: VariantConfiguration.java    From javaide with 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 #5
Source File: ProductFlavorCombo.java    From javaide with 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 #6
Source File: InjectTransformManager.java    From atlas with 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 #7
Source File: ProductFlavorData.java    From javaide with 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 #8
Source File: BaseVariantOutputData.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@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 #9
Source File: AndroidExtension.java    From javafxmobile-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private File getGeneratedResourcesDirectory(String name) {
    return FileUtils.join(
            getGeneratedDirectory(),
            StringHelper.toStrings(
                    "res",
                    name,
                    Collections.singletonList("android")));
}
 
Example #10
Source File: BuildTypeData.java    From javaide with 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 #11
Source File: VariantManager.java    From javaide with 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 #12
Source File: TaskManager.java    From javaide with 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 #13
Source File: AndroidComponentModelPlugin.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 #14
Source File: AndroidComponentModelPlugin.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
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
Source File: PackageApplication.java    From javaide with 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 #16
Source File: Lint.java    From javaide with 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 #17
Source File: VariantContext.java    From atlas with 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 #18
Source File: VariantContext.java    From atlas with 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 #19
Source File: PrepareDependenciesTask.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
@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 #20
Source File: BaseVariantData.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
@NonNull
protected String getCapitalizedBuildTypeName() {
    return StringHelper.capitalize(variantConfiguration.getBuildType().getName());
}
 
Example #21
Source File: BaseVariantData.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
@NonNull
protected String getCapitalizedFlavorName() {
    return StringHelper.capitalize(variantConfiguration.getFlavorName());
}
 
Example #22
Source File: VariantOutputScope.java    From javaide with 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 #23
Source File: VariantScope.java    From javaide with 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;
}
 
Example #24
Source File: VariantContext.java    From atlas with 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
Source File: VariantContext.java    From atlas with 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 #26
Source File: VariantContext.java    From atlas with 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 #27
Source File: VariantContext.java    From atlas with 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 #28
Source File: Dex.java    From atlas with 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 #29
Source File: AndroidExtension.java    From javafxmobile-plugin with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public File getResourceBlameLogDirectory() {
    return FileUtils.join(
            getIntermediatesDirectory(),
            StringHelper.toStrings(
                    "blame", "res", Collections.singletonList("android")));
}