Search in sources :

Example 1 with SourceProvider

use of com.android.builder.model.SourceProvider in project atlas by alibaba.

the class ModuleInfoWriter method write.

public void write() {
    //生成项目的基本信息
    try {
        ModuleInfo moduleInfo = new ModuleInfo();
        moduleInfo.group = project.getGroup().toString();
        moduleInfo.name = project.getName();
        moduleInfo.version = project.getVersion().toString();
        moduleInfo.path = project.getProjectDir().getAbsolutePath().replace(project.getRootDir().getAbsolutePath(), "").substring(1);
        //获取android manifst
        moduleInfo.packageName = libraryVariant.getApplicationId();
        List<SourceProvider> sourceProviders = libraryVariant.getSourceSets();
        for (SourceProvider sourceProvider : sourceProviders) {
            for (File java : sourceProvider.getJavaDirectories()) {
                if (java.exists()) {
                    moduleInfo.java_SrcDirs.add(java.getAbsolutePath());
                }
            }
            for (File res : sourceProvider.getResDirectories()) {
                if (res.exists()) {
                    moduleInfo.res_srcDirs.add(res.getAbsolutePath());
                }
            }
            for (File assets : sourceProvider.getAssetsDirectories()) {
                if (assets.exists()) {
                    moduleInfo.assets_srcDirs.add(assets.getAbsolutePath());
                }
            }
        }
        File moduleInfoFile = new File(project.getRootDir(), ".awo/" + moduleInfo.name + ".mi");
        moduleInfoFile.getParentFile().mkdirs();
        FileUtils.write(moduleInfoFile, JSON.toJSONString(moduleInfo, true));
    } catch (Throwable e) {
        e.printStackTrace();
    }
}
Also used : ModuleInfo(com.taobao.android.builder.tasks.awo.projectstrucure.ModuleInfo) SourceProvider(com.android.builder.model.SourceProvider) File(java.io.File)

Example 2 with SourceProvider

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

the class IntellijLintUtils method getResourceDirectories.

/** Returns the resource directories to use for the given module */
@NotNull
public static List<File> getResourceDirectories(@NotNull AndroidFacet facet) {
    if (facet.requiresAndroidModel()) {
        AndroidModel androidModel = facet.getAndroidModel();
        if (androidModel != null) {
            List<File> resDirectories = new ArrayList<File>();
            List<SourceProvider> sourceProviders = androidModel.getActiveSourceProviders();
            for (SourceProvider provider : sourceProviders) {
                for (File file : provider.getResDirectories()) {
                    if (file.isDirectory()) {
                        resDirectories.add(file);
                    }
                }
            }
            return resDirectories;
        }
    }
    return new ArrayList<File>(facet.getMainSourceProvider().getResDirectories());
}
Also used : AndroidModel(com.android.tools.idea.model.AndroidModel) ArrayList(java.util.ArrayList) SourceProvider(com.android.builder.model.SourceProvider) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with SourceProvider

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

the class AndroidFacetModuleSetupStep method configureFacet.

private static void configureFacet(@NotNull AndroidFacet facet, @NotNull AndroidModuleModel androidModel) {
    JpsAndroidModuleProperties facetProperties = facet.getProperties();
    facetProperties.ALLOW_USER_CONFIGURATION = false;
    facetProperties.PROJECT_TYPE = androidModel.getProjectType();
    File modulePath = androidModel.getRootDirPath();
    SourceProvider sourceProvider = androidModel.getDefaultSourceProvider();
    facetProperties.MANIFEST_FILE_RELATIVE_PATH = relativePath(modulePath, sourceProvider.getManifestFile());
    facetProperties.RES_FOLDER_RELATIVE_PATH = relativePath(modulePath, sourceProvider.getResDirectories());
    facetProperties.ASSETS_FOLDER_RELATIVE_PATH = relativePath(modulePath, sourceProvider.getAssetsDirectories());
    syncSelectedVariant(facetProperties, androidModel);
    facet.setAndroidModel(androidModel);
    androidModel.syncSelectedVariantAndTestArtifact(facet);
}
Also used : SourceProvider(com.android.builder.model.SourceProvider) JpsAndroidModuleProperties(org.jetbrains.jps.android.model.impl.JpsAndroidModuleProperties) File(java.io.File)

Example 4 with SourceProvider

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

the class IconStep method getResourceFolders.

private List<File> getResourceFolders() {
    SourceProvider provider = myState.get(mySourceProviderKey);
    if (provider == null) {
        return Collections.emptyList();
    }
    List<File> dirs = Lists.newLinkedList();
    dirs.addAll(provider.getResDirectories());
    return dirs;
}
Also used : SourceProvider(com.android.builder.model.SourceProvider) File(java.io.File)

Example 5 with SourceProvider

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

the class AddAndroidActivityPath method getInitialPackageName.

/**
   * Initial package name is either a package user selected when invoking the wizard or default package for the module.
   */
private String getInitialPackageName(Module module, AndroidFacet facet) {
    if (myTargetFolder != null) {
        List<SourceProvider> sourceProviders = IdeaSourceProvider.getSourceProvidersForFile(facet, myTargetFolder, facet.getMainSourceProvider());
        File targetDirectoryFile = VfsUtilCore.virtualToIoFile(myTargetFolder);
        if (sourceProviders.size() > 0 && IdeaSourceProvider.containsFile(sourceProviders.get(0), targetDirectoryFile)) {
            File srcDirectory = findSrcDirectory(sourceProviders.get(0));
            if (srcDirectory != null) {
                String packageName = ProjectRootManager.getInstance(module.getProject()).getFileIndex().getPackageNameByDirectory(myTargetFolder);
                if (packageName != null) {
                    return packageName;
                }
            }
        }
    }
    return getApplicationPackageName();
}
Also used : IdeaSourceProvider(org.jetbrains.android.facet.IdeaSourceProvider) 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