Search in sources :

Example 6 with SourceProvider

use of com.android.builder.model.SourceProvider in project android by JetBrains.

the class TemplateParameterStep2 method addSourceSetControls.

private void addSourceSetControls(int row) {
    if (mySourceProviders.length > 1) {
        if (mySourceSetLabel == null) {
            mySourceSetLabel = new JLabel("Target Source Set:");
            //noinspection UndesirableClassUsage
            mySourceSet = new JComboBox();
            register(AddAndroidActivityPath.KEY_SOURCE_PROVIDER, mySourceSet);
            setControlDescription(mySourceSet, "The selected folder contains multiple source sets, " + "this can include source sets that do not yet exist on disk. " + "Please select the target source set in which to create the files.");
        }
        mySourceSet.removeAllItems();
        for (SourceProvider sourceProvider : mySourceProviders) {
            //noinspection unchecked
            mySourceSet.addItem(new ApiComboBoxItem(sourceProvider, sourceProvider.getName(), 0, 0));
        }
        addComponent(myTemplateParameters, mySourceSetLabel, row, 0, false);
        addComponent(myTemplateParameters, mySourceSet, row, 1, true);
    }
}
Also used : SourceProvider(com.android.builder.model.SourceProvider) ApiComboBoxItem(com.android.tools.idea.ui.ApiComboBoxItem)

Example 7 with SourceProvider

use of com.android.builder.model.SourceProvider in project android by JetBrains.

the class AddAndroidActivityPath method getDirectories.

private Map<String, Object> getDirectories() {
    Map<String, Object> templateParameters = Maps.newHashMap();
    Module module = getModule();
    assert module != null;
    AndroidFacet facet = AndroidFacet.getInstance(module);
    assert facet != null;
    AndroidPlatform platform = AndroidPlatform.getInstance(module);
    if (platform != null) {
        templateParameters.put(ATTR_BUILD_API, platform.getTarget().getVersion().getFeatureLevel());
        templateParameters.put(ATTR_BUILD_API_STRING, getBuildApiString(platform.getTarget().getVersion()));
    }
    // Read minSdkVersion and package from manifest and/or build.gradle files
    AndroidModuleInfo moduleInfo = AndroidModuleInfo.get(facet);
    AndroidModel androidModel = facet.getAndroidModel();
    SourceProvider sourceProvider1 = myState.get(KEY_SOURCE_PROVIDER);
    if (sourceProvider1 != null && androidModel != null) {
        String packageName = myState.get(KEY_PACKAGE_NAME);
        assert packageName != null;
        templateParameters.putAll(selectSourceProvider(sourceProvider1, androidModel, module, packageName));
    }
    AndroidVersion minSdkVersion = moduleInfo.getMinSdkVersion();
    String minSdkName = minSdkVersion.getApiString();
    templateParameters.put(ATTR_MIN_API, minSdkName);
    templateParameters.put(ATTR_TARGET_API, moduleInfo.getTargetSdkVersion().getApiLevel());
    templateParameters.put(ATTR_MIN_API_LEVEL, minSdkVersion.getFeatureLevel());
    templateParameters.put(ATTR_IS_LIBRARY_MODULE, facet.isLibraryProject());
    try {
        templateParameters.put(ATTR_DEBUG_KEYSTORE_SHA1, KeystoreUtils.sha1(getDebugKeystore(facet)));
    } catch (Exception e) {
        LOG.info("Could not compute SHA1 hash of debug keystore.", e);
        templateParameters.put(ATTR_DEBUG_KEYSTORE_SHA1, "");
    }
    @SuppressWarnings("deprecation") String projectLocation = NewModuleWizardState.ATTR_PROJECT_LOCATION;
    Project project = getProject();
    assert project != null;
    templateParameters.put(projectLocation, project.getBasePath());
    // We're really interested in the directory name on disk, not the module name. These will be different if you give a module the same
    // name as its containing project.
    String moduleName = new File(module.getModuleFilePath()).getParentFile().getName();
    templateParameters.put(FormFactorUtils.ATTR_MODULE_NAME, moduleName);
    return templateParameters;
}
Also used : IdeaSourceProvider(org.jetbrains.android.facet.IdeaSourceProvider) SourceProvider(com.android.builder.model.SourceProvider) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) AndroidVersion(com.android.sdklib.AndroidVersion) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) AndroidModuleInfo(com.android.tools.idea.model.AndroidModuleInfo) Project(com.intellij.openapi.project.Project) AndroidModel(com.android.tools.idea.model.AndroidModel) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 8 with SourceProvider

use of com.android.builder.model.SourceProvider in project android by JetBrains.

the class ThemeEditorUtils method acceptResourceResolverVisitor.

/**
   * Visits every ResourceFolderRepository. It visits every resource in order, meaning that the later calls may override resources from
   * previous ones.
   */
public static void acceptResourceResolverVisitor(@NotNull final AndroidFacet mainFacet, @NotNull final ResourceFolderVisitor visitor) {
    // Get all the dependencies of the module in reverse order (first one is the lowest priority one)
    List<AndroidFacet> dependencies = Lists.reverse(AndroidUtils.getAllAndroidDependencies(mainFacet.getModule(), true));
    // The order of iteration here is important since the resources from the mainFacet will override those in the dependencies.
    for (AndroidFacet dependency : Iterables.concat(dependencies, ImmutableList.of(mainFacet))) {
        AndroidModuleModel androidModel = AndroidModuleModel.get(dependency);
        if (androidModel == null) {
            // For non gradle module, get the main source provider
            SourceProvider provider = dependency.getMainSourceProvider();
            for (LocalResourceRepository resourceRepository : getResourceFolderRepositoriesFromSourceSet(dependency, provider)) {
                visitor.visitResourceFolder(resourceRepository, dependency.getName(), provider.getName(), true);
            }
        } else {
            // For gradle modules, get all source providers and go through them
            // We need to iterate the providers in the returned to make sure that they correctly override each other
            List<SourceProvider> activeProviders = androidModel.getActiveSourceProviders();
            for (SourceProvider provider : activeProviders) {
                for (LocalResourceRepository resourceRepository : getResourceFolderRepositoriesFromSourceSet(dependency, provider)) {
                    visitor.visitResourceFolder(resourceRepository, dependency.getName(), provider.getName(), true);
                }
            }
            // Not go through all the providers that are not in the activeProviders
            ImmutableSet<SourceProvider> selectedProviders = ImmutableSet.copyOf(activeProviders);
            for (SourceProvider provider : androidModel.getAllSourceProviders()) {
                if (!selectedProviders.contains(provider)) {
                    for (LocalResourceRepository resourceRepository : getResourceFolderRepositoriesFromSourceSet(dependency, provider)) {
                        visitor.visitResourceFolder(resourceRepository, dependency.getName(), provider.getName(), false);
                    }
                }
            }
        }
    }
}
Also used : AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) SourceProvider(com.android.builder.model.SourceProvider) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 9 with SourceProvider

use of com.android.builder.model.SourceProvider in project android by JetBrains.

the class NewFormFactorModulePath method init.

@Override
protected void init() {
    myState.put(IS_LIBRARY_KEY, false);
    myState.put(SRC_DIR_KEY, calculateSrcDir());
    myState.put(RES_DIR_KEY, "src/main/res");
    myState.put(AIDL_DIR_KEY, "src/main/aidl");
    myState.put(MANIFEST_DIR_KEY, "src/main");
    myState.put(TEST_DIR_KEY, "src/androidTest");
    myState.put(CREATE_ACTIVITY_KEY, false);
    myState.put(IS_INSTANT_APP_KEY, false);
    String whSdkLocation = System.getenv(WH_SDK_ENV_VAR);
    myState.put(WH_SDK_KEY, whSdkLocation + "/tools/resources/shared-libs");
    myState.put(WH_SDK_ENABLED_KEY, isNotEmpty(whSdkLocation));
    addStep(new ConfigureAndroidModuleStepDynamic(myDisposable, myFormFactor));
    addStep(new ConfigureInstantModuleStep(myDisposable, myFormFactor));
    addStep(new ActivityGalleryStep(myFormFactor, true, KEY_SELECTED_TEMPLATE, null, myDisposable));
    Object packageName = myState.get(PACKAGE_NAME_KEY);
    if (packageName == null) {
        packageName = "";
    }
    Map<String, Object> presetsMap = ImmutableMap.of(PACKAGE_NAME_KEY.name, packageName, ATTR_IS_LAUNCHER, true, ATTR_PARENT_ACTIVITY_CLASS, "");
    myParameterStep = new TemplateParameterStep2(myFormFactor, presetsMap, myDisposable, PACKAGE_NAME_KEY, new SourceProvider[0], AddAndroidActivityPath.CUSTOMIZE_ACTIVITY_TITLE);
    addStep(myParameterStep);
}
Also used : ConfigureInstantModuleStep(com.android.tools.idea.npw.instantapp.ConfigureInstantModuleStep) SourceProvider(com.android.builder.model.SourceProvider)

Example 10 with SourceProvider

use of com.android.builder.model.SourceProvider in project android by JetBrains.

the class IdeaSourceProviderTest method testGetAllSourceProviders.

/** TODO: Move this test to {@link AndroidModuleModelTest}. */
public void testGetAllSourceProviders() throws Exception {
    StringBuilder sb = new StringBuilder();
    File baseDir = new File(getProject().getBaseDir().getPath());
    for (SourceProvider provider : IdeaSourceProvider.getAllSourceProviders(myAppFacet)) {
        sb.append(getStringRepresentation(provider, baseDir));
    }
    assertEquals("Name: main\n" + "Manifest File: app/src/main/AndroidManifest.xml\n" + "Java Directories: [app/src/main/java]\n" + "Res Directories: [app/src/main/res]\n" + "Assets Directories: [app/src/main/assets]\n" + "AIDL Directories: [app/src/main/aidl]\n" + "Renderscript Directories: [app/src/main/rs]\n" + "Jni Directories: [app/src/main/jni]\n" + "Resources Directories: [app/src/main/resources]\n" + "Name: paid\n" + "Manifest File: app/src/paid/AndroidManifest.xml\n" + "Java Directories: [app/src/paid/java]\n" + "Res Directories: [app/src/paid/res]\n" + "Assets Directories: [app/src/paid/assets]\n" + "AIDL Directories: [app/src/paid/aidl]\n" + "Renderscript Directories: [app/src/paid/rs]\n" + "Jni Directories: [app/src/paid/jni]\n" + "Resources Directories: [app/src/paid/resources]\n" + "Name: basic\n" + "Manifest File: app/src/basic/AndroidManifest.xml\n" + "Java Directories: [app/src/basic/java]\n" + "Res Directories: [app/src/basic/res]\n" + "Assets Directories: [app/src/basic/assets]\n" + "AIDL Directories: [app/src/basic/aidl]\n" + "Renderscript Directories: [app/src/basic/rs]\n" + "Jni Directories: [app/src/basic/jni]\n" + "Resources Directories: [app/src/basic/resources]\n" + "Name: debug\n" + "Manifest File: app/src/debug/AndroidManifest.xml\n" + "Java Directories: [app/src/debug/java]\n" + "Res Directories: [app/src/debug/res]\n" + "Assets Directories: [app/src/debug/assets]\n" + "AIDL Directories: [app/src/debug/aidl]\n" + "Renderscript Directories: [app/src/debug/rs]\n" + "Jni Directories: [app/src/debug/jni]\n" + "Resources Directories: [app/src/debug/resources]\n" + "Name: release\n" + "Manifest File: app/src/release/AndroidManifest.xml\n" + "Java Directories: [app/src/release/java]\n" + "Res Directories: [app/src/release/res]\n" + "Assets Directories: [app/src/release/assets]\n" + "AIDL Directories: [app/src/release/aidl]\n" + "Renderscript Directories: [app/src/release/rs]\n" + "Jni Directories: [app/src/release/jni]\n" + "Resources Directories: [app/src/release/resources]\n" + "Name: paidDebug\n" + "Manifest File: app/src/paidDebug/AndroidManifest.xml\n" + "Java Directories: [app/src/paidDebug/java]\n" + "Res Directories: [app/src/paidDebug/res]\n" + "Assets Directories: [app/src/paidDebug/assets]\n" + "AIDL Directories: [app/src/paidDebug/aidl]\n" + "Renderscript Directories: [app/src/paidDebug/rs]\n" + "Jni Directories: [app/src/paidDebug/jni]\n" + "Resources Directories: [app/src/paidDebug/resources]\n" + "Name: paidRelease\n" + "Manifest File: app/src/paidRelease/AndroidManifest.xml\n" + "Java Directories: [app/src/paidRelease/java]\n" + "Res Directories: [app/src/paidRelease/res]\n" + "Assets Directories: [app/src/paidRelease/assets]\n" + "AIDL Directories: [app/src/paidRelease/aidl]\n" + "Renderscript Directories: [app/src/paidRelease/rs]\n" + "Jni Directories: [app/src/paidRelease/jni]\n" + "Resources Directories: [app/src/paidRelease/resources]\n" + "Name: basicDebug\n" + "Manifest File: app/src/basicDebug/AndroidManifest.xml\n" + "Java Directories: [app/src/basicDebug/java]\n" + "Res Directories: [app/src/basicDebug/res]\n" + "Assets Directories: [app/src/basicDebug/assets]\n" + "AIDL Directories: [app/src/basicDebug/aidl]\n" + "Renderscript Directories: [app/src/basicDebug/rs]\n" + "Jni Directories: [app/src/basicDebug/jni]\n" + "Resources Directories: [app/src/basicDebug/resources]\n" + "Name: basicRelease\n" + "Manifest File: app/src/basicRelease/AndroidManifest.xml\n" + "Java Directories: [app/src/basicRelease/java]\n" + "Res Directories: [app/src/basicRelease/res]\n" + "Assets Directories: [app/src/basicRelease/assets]\n" + "AIDL Directories: [app/src/basicRelease/aidl]\n" + "Renderscript Directories: [app/src/basicRelease/rs]\n" + "Jni Directories: [app/src/basicRelease/jni]\n" + "Resources Directories: [app/src/basicRelease/resources]\n", sb.toString());
    sb = new StringBuilder();
    for (SourceProvider provider : IdeaSourceProvider.getAllSourceProviders(myLibFacet)) {
        sb.append(getStringRepresentation(provider, baseDir));
    }
    assertEquals("Name: main\n" + "Manifest File: lib/src/main/AndroidManifest.xml\n" + "Java Directories: [lib/src/main/java]\n" + "Res Directories: [lib/src/main/res]\n" + "Assets Directories: [lib/src/main/assets]\n" + "AIDL Directories: [lib/src/main/aidl]\n" + "Renderscript Directories: [lib/src/main/rs]\n" + "Jni Directories: [lib/src/main/jni]\n" + "Resources Directories: [lib/src/main/resources]\n" + "Name: debug\n" + "Manifest File: lib/src/debug/AndroidManifest.xml\n" + "Java Directories: [lib/src/debug/java]\n" + "Res Directories: [lib/src/debug/res]\n" + "Assets Directories: [lib/src/debug/assets]\n" + "AIDL Directories: [lib/src/debug/aidl]\n" + "Renderscript Directories: [lib/src/debug/rs]\n" + "Jni Directories: [lib/src/debug/jni]\n" + "Resources Directories: [lib/src/debug/resources]\n" + "Name: release\n" + "Manifest File: lib/src/release/AndroidManifest.xml\n" + "Java Directories: [lib/src/release/java]\n" + "Res Directories: [lib/src/release/res]\n" + "Assets Directories: [lib/src/release/assets]\n" + "AIDL Directories: [lib/src/release/aidl]\n" + "Renderscript Directories: [lib/src/release/rs]\n" + "Jni Directories: [lib/src/release/jni]\n" + "Resources Directories: [lib/src/release/resources]\n", sb.toString());
}
Also used : SourceProvider(com.android.builder.model.SourceProvider) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Aggregations

SourceProvider (com.android.builder.model.SourceProvider)15 File (java.io.File)9 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 IdeaSourceProvider (org.jetbrains.android.facet.IdeaSourceProvider)4 AndroidModel (com.android.tools.idea.model.AndroidModel)3 Module (com.intellij.openapi.module.Module)3 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)3 NotNull (org.jetbrains.annotations.NotNull)3 AndroidVersion (com.android.sdklib.AndroidVersion)2 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)2 AndroidModuleInfo (com.android.tools.idea.model.AndroidModuleInfo)2 ApiComboBoxItem (com.android.tools.idea.ui.ApiComboBoxItem)2 Project (com.intellij.openapi.project.Project)2 ArrayList (java.util.ArrayList)2 AndroidPlatform (org.jetbrains.android.sdk.AndroidPlatform)2 ConfigureInstantModuleStep (com.android.tools.idea.npw.instantapp.ConfigureInstantModuleStep)1 TemplateMetadata (com.android.tools.idea.templates.TemplateMetadata)1 ModuleInfo (com.taobao.android.builder.tasks.awo.projectstrucure.ModuleInfo)1 Nullable (org.jetbrains.annotations.Nullable)1 JpsAndroidModuleProperties (org.jetbrains.jps.android.model.impl.JpsAndroidModuleProperties)1