Search in sources :

Example 6 with JpsAndroidModuleProperties

use of org.jetbrains.jps.android.model.impl.JpsAndroidModuleProperties in project android by JetBrains.

the class AndroidCompileUtil method getProguardConfigFilePathIfShouldRun.

@Nullable
public static ProguardRunningOptions getProguardConfigFilePathIfShouldRun(@NotNull AndroidFacet facet, CompileContext context) {
    // wizard
    String pathsStr = context.getCompileScope().getUserData(PROGUARD_CFG_PATHS_KEY);
    if (pathsStr != null) {
        final String[] paths = pathsStr.split(File.pathSeparator);
        if (paths.length > 0) {
            return new ProguardRunningOptions(Arrays.asList(paths));
        }
    }
    final AndroidPlatform platform = AndroidPlatform.getInstance(facet.getModule());
    final String sdkHomePath = platform != null ? FileUtil.toCanonicalPath(platform.getSdkData().getPath()) : null;
    // artifact
    final Project project = context.getProject();
    final Set<Artifact> artifacts = ArtifactCompileScope.getArtifactsToBuild(project, context.getCompileScope(), false);
    for (Artifact artifact : artifacts) {
        if (artifact.getArtifactType() instanceof AndroidApplicationArtifactType && facet.equals(AndroidArtifactUtil.getPackagedFacet(project, artifact))) {
            final ArtifactProperties<?> properties = artifact.getProperties(AndroidArtifactPropertiesProvider.getInstance());
            if (properties instanceof AndroidApplicationArtifactProperties) {
                final AndroidApplicationArtifactProperties p = (AndroidApplicationArtifactProperties) properties;
                if (p.isRunProGuard()) {
                    final List<String> paths = AndroidUtils.urlsToOsPaths(p.getProGuardCfgFiles(), sdkHomePath);
                    return new ProguardRunningOptions(paths);
                }
            }
        }
    }
    // facet
    final AndroidFacetConfiguration configuration = facet.getConfiguration();
    final JpsAndroidModuleProperties properties = configuration.getState();
    if (properties != null && properties.RUN_PROGUARD) {
        final List<String> urls = properties.myProGuardCfgFiles;
        final List<String> paths = AndroidUtils.urlsToOsPaths(urls, sdkHomePath);
        return new ProguardRunningOptions(paths);
    }
    return null;
}
Also used : AndroidFacetConfiguration(org.jetbrains.android.facet.AndroidFacetConfiguration) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) JpsAndroidModuleProperties(org.jetbrains.jps.android.model.impl.JpsAndroidModuleProperties) Artifact(com.intellij.packaging.artifacts.Artifact) Project(com.intellij.openapi.project.Project) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with JpsAndroidModuleProperties

use of org.jetbrains.jps.android.model.impl.JpsAndroidModuleProperties in project android by JetBrains.

the class BuildVariantView method updateContents.

public void updateContents() {
    GradleSyncState syncState = GradleSyncState.getInstance(myProject);
    if (syncState.isSyncInProgress() && !syncState.isSyncSkipped()) {
        projectImportStarted();
        return;
    }
    final List<Object[]> rows = Lists.newArrayList();
    final List<BuildVariantItem[]> variantNamesPerRow = Lists.newArrayList();
    for (Module module : getGradleModulesWithAndroidProjects()) {
        AndroidFacet androidFacet = AndroidFacet.getInstance(module);
        NdkFacet ndkFacet = NdkFacet.getInstance(module);
        // getGradleModules() returns only relevant modules.
        assert androidFacet != null || ndkFacet != null;
        String variantName = null;
        if (androidFacet != null) {
            JpsAndroidModuleProperties facetProperties = androidFacet.getProperties();
            variantName = facetProperties.SELECTED_BUILD_VARIANT;
        }
        BuildVariantItem[] variantNames = getVariantItems(module);
        if (variantNames != null) {
            if (androidFacet != null) {
                AndroidModuleModel androidModel = AndroidModuleModel.get(module);
                // AndroidModel may be null when applying a quick fix (e.g. "Fix Gradle version")
                if (androidModel != null) {
                    variantName = androidModel.getSelectedVariant().getName();
                }
            } else {
                // As only the modules backed by either AndroidGradleModel or NativeAndroidGradleModel are shown in the Build Variants View,
                // when a module is not backed by AndroidGradleModel, it surely contains a valid NativeAndroidGradleModel.
                NdkModuleModel ndkModuleModel = NdkModuleModel.get(module);
                if (ndkModuleModel != null) {
                    variantName = ndkModuleModel.getSelectedVariant().getName();
                }
            }
            variantNamesPerRow.add(variantNames);
        }
        if (variantName != null) {
            Object[] row = { module, variantName };
            rows.add(row);
        }
    }
    Runnable setModelTask = () -> getVariantsTable().setModel(rows, variantNamesPerRow);
    Application application = ApplicationManager.getApplication();
    if (application.isDispatchThread()) {
        setModelTask.run();
    } else {
        application.invokeLater(setModelTask);
    }
}
Also used : NdkFacet(com.android.tools.idea.gradle.project.facet.ndk.NdkFacet) JpsAndroidModuleProperties(org.jetbrains.jps.android.model.impl.JpsAndroidModuleProperties) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) GradleSyncState(com.android.tools.idea.gradle.project.sync.GradleSyncState) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) Module(com.intellij.openapi.module.Module) NdkModuleModel(com.android.tools.idea.gradle.project.model.NdkModuleModel) Application(com.intellij.openapi.application.Application)

Example 8 with JpsAndroidModuleProperties

use of org.jetbrains.jps.android.model.impl.JpsAndroidModuleProperties in project android by JetBrains.

the class ResourceFolderManager method computeFolders.

private List<VirtualFile> computeFolders() {
    if (myFacet.requiresAndroidModel()) {
        JpsAndroidModuleProperties state = myFacet.getConfiguration().getState();
        AndroidModel androidModel = myFacet.getAndroidModel();
        List<VirtualFile> resDirectories = new ArrayList<>();
        if (androidModel == null) {
            // Read string property
            if (state != null) {
                String path = state.RES_FOLDERS_RELATIVE_PATH;
                if (path != null) {
                    VirtualFileManager manager = VirtualFileManager.getInstance();
                    // writes the property
                    for (String url : Splitter.on(';').omitEmptyStrings().trimResults().split(path)) {
                        VirtualFile dir = manager.findFileByUrl(url);
                        if (dir != null) {
                            resDirectories.add(dir);
                        }
                    }
                } else {
                    // First time; have not yet computed the res folders
                    // just try the default: src/main/res/ (from Gradle templates), res/ (from exported Eclipse projects)
                    String mainRes = '/' + FD_SOURCES + '/' + FD_MAIN + '/' + FD_RES;
                    VirtualFile dir = AndroidRootUtil.getFileByRelativeModulePath(myFacet.getModule(), mainRes, true);
                    if (dir != null) {
                        resDirectories.add(dir);
                    } else {
                        String res = '/' + FD_RES;
                        dir = AndroidRootUtil.getFileByRelativeModulePath(myFacet.getModule(), res, true);
                        if (dir != null) {
                            resDirectories.add(dir);
                        }
                    }
                }
            }
        } else {
            for (IdeaSourceProvider provider : IdeaSourceProvider.getCurrentSourceProviders(myFacet)) {
                resDirectories.addAll(provider.getResDirectories());
            }
            // before the gradle model has been initialized asynchronously
            if (state != null) {
                StringBuilder path = new StringBuilder(400);
                for (VirtualFile dir : resDirectories) {
                    if (path.length() != 0) {
                        // Deliberately using ';' instead of File.pathSeparator since on Unix File.pathSeparator is ":"
                        // which is also used in URLs, meaning we could end up with something like "file://foo:file://bar"
                        path.append(';');
                    }
                    path.append(dir.getUrl());
                }
                state.RES_FOLDERS_RELATIVE_PATH = path.toString();
            }
            // Also refresh the app resources whenever the variant changes
            if (!myVariantListenerAdded) {
                myVariantListenerAdded = true;
                BuildVariantView.getInstance(myFacet.getModule().getProject()).addListener(this::invalidate);
            }
        }
        // Listen to root change events. Be notified when project is initialized so we can update the
        // resource set, if necessary.
        ProjectResourceRepositoryRootListener.ensureSubscribed(myFacet.getModule().getProject());
        return resDirectories;
    } else {
        return new ArrayList<>(myFacet.getMainIdeaSourceProvider().getResDirectories());
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileManager(com.intellij.openapi.vfs.VirtualFileManager) AndroidModel(com.android.tools.idea.model.AndroidModel) JpsAndroidModuleProperties(org.jetbrains.jps.android.model.impl.JpsAndroidModuleProperties)

Example 9 with JpsAndroidModuleProperties

use of org.jetbrains.jps.android.model.impl.JpsAndroidModuleProperties in project android by JetBrains.

the class AndroidBuilderTest method testManifestMerging.

public void testManifestMerging() throws Exception {
    final MyExecutor executor = new MyExecutor("com.example.simple");
    final JpsSdk<JpsSimpleElement<JpsAndroidSdkProperties>> androidSdk = addJdkAndAndroidSdk();
    addPathPatterns(executor, androidSdk);
    final JpsModule appModule = addAndroidModule("app", new String[] { "src" }, "app", "app", androidSdk).getFirst();
    final JpsModule libModule = addAndroidModule("lib", ArrayUtil.EMPTY_STRING_ARRAY, "lib", "lib", androidSdk).getFirst();
    final JpsAndroidModuleExtension libExtension = AndroidJpsUtil.getExtension(libModule);
    assert libExtension != null;
    final JpsAndroidModuleProperties libProps = ((JpsAndroidModuleExtensionImpl) libExtension).getProperties();
    libProps.PROJECT_TYPE = PROJECT_TYPE_LIBRARY;
    appModule.getDependenciesList().addModuleDependency(libModule);
    final JpsAndroidModuleExtension appExtension = AndroidJpsUtil.getExtension(appModule);
    assert appExtension != null;
    final JpsAndroidModuleProperties appProps = ((JpsAndroidModuleExtensionImpl) appExtension).getProperties();
    appProps.ENABLE_MANIFEST_MERGING = true;
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log");
    checkMakeUpToDate(executor);
    appProps.ENABLE_MANIFEST_MERGING = false;
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log_1");
    checkMakeUpToDate(executor);
    appProps.ENABLE_MANIFEST_MERGING = true;
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log_2");
    checkMakeUpToDate(executor);
    change(getProjectPath("app/AndroidManifest.xml"));
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log_3");
    checkMakeUpToDate(executor);
    change(getProjectPath("lib/AndroidManifest.xml"));
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log_4");
    checkMakeUpToDate(executor);
}
Also used : JpsModule(org.jetbrains.jps.model.module.JpsModule) JpsAndroidModuleExtensionImpl(org.jetbrains.jps.android.model.impl.JpsAndroidModuleExtensionImpl) JpsSimpleElement(org.jetbrains.jps.model.JpsSimpleElement) JpsAndroidModuleProperties(org.jetbrains.jps.android.model.impl.JpsAndroidModuleProperties)

Example 10 with JpsAndroidModuleProperties

use of org.jetbrains.jps.android.model.impl.JpsAndroidModuleProperties in project android by JetBrains.

the class AndroidBuilderTest method testMaven1.

public void testMaven1() throws Exception {
    createMavenConfigFile();
    final MyExecutor executor = new MyExecutor("com.example.simple");
    final JpsSdk<JpsSimpleElement<JpsAndroidSdkProperties>> androidSdk = addJdkAndAndroidSdk();
    addPathPatterns(executor, androidSdk);
    copyToProject(getDefaultTestDataDirForCurrentTest() + "/project/myaar", "root/myaar");
    final JpsModule appModule = addAndroidModule("app", new String[] { "src" }, "app", "app", androidSdk).getFirst();
    final JpsModule libModule = addAndroidModule("lib", new String[] { "src" }, "lib", "lib", androidSdk).getFirst();
    JpsMavenExtensionService.getInstance().getOrCreateExtension(appModule);
    final MavenProjectConfiguration mavenConf = ((JpsMavenExtensionServiceImpl) JpsMavenExtensionService.getInstance()).getMavenProjectConfiguration(myDataStorageRoot);
    addMavenResourcesConf(mavenConf, "app");
    addMavenResourcesConf(mavenConf, "lib");
    final JpsAndroidModuleExtension libExtension = AndroidJpsUtil.getExtension(libModule);
    assert libExtension != null;
    final JpsAndroidModuleProperties libProps = ((JpsAndroidModuleExtensionImpl) libExtension).getProperties();
    libProps.PROJECT_TYPE = PROJECT_TYPE_LIBRARY;
    appModule.getDependenciesList().addModuleDependency(libModule);
    rebuildAll();
    checkMakeUpToDate(executor);
    final JpsLibrary appAarLib = appModule.addModuleLibrary("app_arr", JpsJavaLibraryType.INSTANCE);
    appAarLib.addRoot(getProjectPath("myaar/classes.jar"), JpsOrderRootType.COMPILED);
    appModule.getDependenciesList().addLibraryDependency(appAarLib);
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log");
    checkMakeUpToDate(executor);
    appAarLib.addRoot(getProjectPath("myaar/res"), JpsOrderRootType.COMPILED);
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log_1");
    checkMakeUpToDate(executor);
    final JpsLibrary libAarLib = libModule.addModuleLibrary("lib_arr", JpsJavaLibraryType.INSTANCE);
    libAarLib.addRoot(getProjectPath("myaar/classes.jar"), JpsOrderRootType.COMPILED);
    libAarLib.addRoot(getProjectPath("myaar/res"), JpsOrderRootType.COMPILED);
    libModule.getDependenciesList().addLibraryDependency(libAarLib);
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log_2");
    checkMakeUpToDate(executor);
    final JpsAndroidModuleExtension appExtension = AndroidJpsUtil.getExtension(appModule);
    final JpsAndroidModuleProperties appProps = ((JpsAndroidModuleExtensionImpl) appExtension).getProperties();
    appProps.myIncludeAssetsFromLibraries = true;
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log_3");
    checkMakeUpToDate(executor);
    appAarLib.addRoot(getProjectPath("myaar/libs/myjar.jar"), JpsOrderRootType.COMPILED);
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log_4");
    checkMakeUpToDate(executor);
}
Also used : JpsModule(org.jetbrains.jps.model.module.JpsModule) JpsAndroidModuleExtensionImpl(org.jetbrains.jps.android.model.impl.JpsAndroidModuleExtensionImpl) JpsSimpleElement(org.jetbrains.jps.model.JpsSimpleElement) JpsAndroidModuleProperties(org.jetbrains.jps.android.model.impl.JpsAndroidModuleProperties) JpsLibrary(org.jetbrains.jps.model.library.JpsLibrary)

Aggregations

JpsAndroidModuleProperties (org.jetbrains.jps.android.model.impl.JpsAndroidModuleProperties)23 JpsAndroidModuleExtensionImpl (org.jetbrains.jps.android.model.impl.JpsAndroidModuleExtensionImpl)13 JpsModule (org.jetbrains.jps.model.module.JpsModule)13 JpsSimpleElement (org.jetbrains.jps.model.JpsSimpleElement)7 JpsLibrary (org.jetbrains.jps.model.library.JpsLibrary)5 NotNull (org.jetbrains.annotations.NotNull)4 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)3 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)2 Module (com.intellij.openapi.module.Module)2 File (java.io.File)2 BaseArtifact (com.android.builder.model.BaseArtifact)1 SourceProvider (com.android.builder.model.SourceProvider)1 GradleBuildFile (com.android.tools.idea.gradle.parser.GradleBuildFile)1 GradleSettingsFile (com.android.tools.idea.gradle.parser.GradleSettingsFile)1 GradleFacet (com.android.tools.idea.gradle.project.facet.gradle.GradleFacet)1 JavaFacet (com.android.tools.idea.gradle.project.facet.java.JavaFacet)1 NdkFacet (com.android.tools.idea.gradle.project.facet.ndk.NdkFacet)1 NdkModuleModel (com.android.tools.idea.gradle.project.model.NdkModuleModel)1 GradleSyncState (com.android.tools.idea.gradle.project.sync.GradleSyncState)1 AndroidModel (com.android.tools.idea.model.AndroidModel)1