private static void checkName(@NonNull String name, @NonNull String displayName) { checkPrefix(name, displayName, ANDROID_TEST.getPrefix()); checkPrefix(name, displayName, UNIT_TEST.getPrefix()); if (LINT.equals(name)) { throw new RuntimeException(String.format( "%1$s names cannot be %2$s", displayName, LINT)); } }
private static void checkName(@NonNull String name, @NonNull String displayName) { checkPrefix(name, displayName, ANDROID_TEST.getPrefix()); checkPrefix(name, displayName, UNIT_TEST.getPrefix()); if (LINT.equals(name)) { throw new RuntimeException(String.format( "%1$s names cannot be %2$s", displayName, LINT)); } }
@NonNull @Override public String getName() { return scope.getTaskName(UNIT_TEST.getPrefix()); }
/** * Returns a base 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 computeBaseNameWithSplits(@NonNull String splitName) { StringBuilder sb = new StringBuilder(); if (!mFlavors.isEmpty()) { for (ProductFlavor pf : mFlavors) { sb.append(pf.getName()).append('-'); } } sb.append(splitName).append('-'); sb.append(mBuildType.getName()); if (mType.isForTesting()) { sb.append('-').append(mType.getPrefix()); } return sb.toString(); }
/** * 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; }
/** * Returns a base 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 computeBaseNameWithSplits(@NonNull String splitName) { StringBuilder sb = new StringBuilder(); if (!mFlavors.isEmpty()) { for (ProductFlavor pf : mFlavors) { sb.append(pf.getName()).append('-'); } } sb.append(splitName).append('-'); sb.append(mBuildType.getName()); if (mType.isForTesting()) { sb.append('-').append(mType.getPrefix()); } return sb.toString(); }
/** * 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; }
/** * Returns the full, unique name of the variant, including BuildType, flavors and test, * dash separated. (similar to full name but with dashes) * * @return the name of the variant */ @NonNull public String getBaseName() { if (mBaseName == null) { StringBuilder sb = new StringBuilder(); if (!mFlavors.isEmpty()) { for (ProductFlavor pf : mFlavors) { sb.append(pf.getName()).append('-'); } } sb.append(mBuildType.getName()); if (mType.isForTesting()) { sb.append('-').append(mType.getPrefix()); } mBaseName = sb.toString(); } return mBaseName; }
/** * Returns the full, unique name of the variant, including BuildType, flavors and test, * dash separated. (similar to full name but with dashes) * * @return the name of the variant */ @NonNull public String getBaseName() { if (mBaseName == null) { StringBuilder sb = new StringBuilder(); if (!mFlavors.isEmpty()) { for (ProductFlavor pf : mFlavors) { sb.append(pf.getName()).append('-'); } } sb.append(mBuildType.getName()); if (mType.isForTesting()) { sb.append('-').append(mType.getPrefix()); } mBaseName = sb.toString(); } return mBaseName; }
/** * Returns a unique directory name (can include multiple folders) for the variant, * based on build type, flavor and test, and splits. * * <p>This always uses forward slashes ('/') as separator on all platform. * * @return the directory name for the variant */ @NonNull public String computeDirNameWithSplits(@NonNull String... splitNames) { StringBuilder sb = new StringBuilder(); if (mType.isForTesting()) { sb.append(mType.getPrefix()).append("/"); } if (!mFlavors.isEmpty()) { for (F flavor : mFlavors) { sb.append(flavor.getName()); } sb.append('/'); } for (String splitName : splitNames) { if (splitName != null) { sb.append(splitName).append('/'); } } sb.append(mBuildType.getName()); return sb.toString(); }
/** * Returns a unique directory name (can include multiple folders) for the variant, * based on build type, flavor and test, and splits. * * <p>This always uses forward slashes ('/') as separator on all platform. * * @return the directory name for the variant */ @NonNull public String computeDirNameWithSplits(@NonNull String... splitNames) { StringBuilder sb = new StringBuilder(); if (mType.isForTesting()) { sb.append(mType.getPrefix()).append("/"); } if (!mFlavors.isEmpty()) { for (F flavor : mFlavors) { sb.append(flavor.getName()); } sb.append('/'); } for (String splitName : splitNames) { if (splitName != null) { sb.append(splitName).append('/'); } } sb.append(mBuildType.getName()); return sb.toString(); }
/** * Returns a unique directory name (can include multiple folders) for the variant, * based on build type, flavor and test. * * <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 (mType.isForTesting()) { sb.append(mType.getPrefix()).append("/"); } if (!mFlavors.isEmpty()) { for (F flavor : mFlavors) { sb.append(flavor.getName()); } sb.append('/').append(mBuildType.getName()); } else { sb.append(mBuildType.getName()); } mDirName = sb.toString(); } return mDirName; }
/** * 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; } /**
/** * Returns a unique directory name (can include multiple folders) for the variant, * based on build type, flavor and test. * * <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 (mType.isForTesting()) { sb.append(mType.getPrefix()).append("/"); } 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; }
public VariantManager( @NonNull Project project, @NonNull AndroidBuilder androidBuilder, @NonNull AndroidConfig extension, @NonNull VariantFactory variantFactory, @NonNull TaskManager taskManager, @NonNull Instantiator instantiator) { this.extension = extension; this.androidBuilder = androidBuilder; this.project = project; this.variantFactory = variantFactory; this.taskManager = taskManager; this.instantiator = instantiator; DefaultAndroidSourceSet mainSourceSet = (DefaultAndroidSourceSet) extension.getSourceSets().getByName(extension.getDefaultConfig().getName()); DefaultAndroidSourceSet androidTestSourceSet = null; DefaultAndroidSourceSet unitTestSourceSet = null; if (variantFactory.hasTestScope()) { androidTestSourceSet = (DefaultAndroidSourceSet) extension.getSourceSets() .getByName(ANDROID_TEST.getPrefix()); unitTestSourceSet = (DefaultAndroidSourceSet) extension.getSourceSets() .getByName(UNIT_TEST.getPrefix()); } defaultConfigData = new ProductFlavorData<CoreProductFlavor>( extension.getDefaultConfig(), mainSourceSet, androidTestSourceSet, unitTestSourceSet, project); signingOverride = createSigningOverride(); }
variantData.getScope().getTaskName(UNIT_TEST.getPrefix()), Test.class); runTestsTask.setGroup(JavaBasePlugin.VERIFICATION_GROUP);
@Override protected void generate(Project project) throws IOException { if (config != null) { for (AndroidSourceSet sourceSet : config.getSourceSets()) { mRenderer.getBuilder().subheading(sourceSet.getName()); renderKeyValue("Compile configuration: ", sourceSet.getCompileConfigurationName()); renderKeyValue("build.gradle name: ", "android.sourceSets." + sourceSet.getName()); renderDirectorySet("Java sources", sourceSet.getJava(), project); if (!sourceSet.getName().startsWith(VariantType.UNIT_TEST.getPrefix())) { renderKeyValue( "Manifest file: ", project.getRootProject().relativePath( sourceSet.getManifest().getSrcFile())); renderDirectorySet("Android resources", sourceSet.getRes(), project); renderDirectorySet("Assets", sourceSet.getAssets(), project); renderDirectorySet("AIDL sources", sourceSet.getAidl(), project); renderDirectorySet("RenderScript sources", sourceSet.getRenderscript(), project); renderDirectorySet("JNI sources", sourceSet.getJni(), project); renderDirectorySet("JNI libraries", sourceSet.getJniLibs(), project); } renderDirectorySet("Java-style resources", sourceSet.getResources(), project); mRenderer.getTextOutput().println(); } } mRenderer.complete(); }
@Override protected void generate(Project project) throws IOException { if (config != null) { for (AndroidSourceSet sourceSet : config.getSourceSets()) { mRenderer.getBuilder().subheading(sourceSet.getName()); renderKeyValue("Compile configuration: ", sourceSet.getCompileConfigurationName()); renderKeyValue("build.gradle name: ", "android.sourceSets." + sourceSet.getName()); renderDirectorySet("Java sources", sourceSet.getJava(), project); if (!sourceSet.getName().startsWith(VariantType.UNIT_TEST.getPrefix())) { renderKeyValue( "Manifest file: ", project.getRootProject().relativePath( sourceSet.getManifest().getSrcFile())); renderDirectorySet("Android resources", sourceSet.getRes(), project); renderDirectorySet("Assets", sourceSet.getAssets(), project); renderDirectorySet("AIDL sources", sourceSet.getAidl(), project); renderDirectorySet("RenderScript sources", sourceSet.getRenderscript(), project); renderDirectorySet("JNI sources", sourceSet.getJni(), project); renderDirectorySet("JNI libraries", sourceSet.getJniLibs(), project); } renderDirectorySet("Java-style resources", sourceSet.getResources(), project); mRenderer.getTextOutput().println(); } } mRenderer.complete(); }