Search in sources :

Example 26 with JpsAndroidModuleExtension

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

the class AndroidSourceGeneratingBuilder method checkUnambiguousAndRecursiveArtifacts.

private static boolean checkUnambiguousAndRecursiveArtifacts(CompileContext context, List<JpsArtifact> artifacts) {
    boolean success = true;
    for (JpsArtifact artifact : artifacts) {
        if (artifact.getArtifactType() instanceof AndroidApplicationArtifactType) {
            final List<JpsAndroidModuleExtension> facets = AndroidJpsUtil.getAllPackagedFacets(artifact);
            if (facets.size() > 1) {
                context.processMessage(new CompilerMessage(ANDROID_VALIDATOR, BuildMessage.Kind.ERROR, "Cannot build artifact '" + artifact.getName() + "' because it contains more than one Android package"));
                success = false;
                continue;
            }
            final String artifactOutputPath = artifact.getOutputFilePath();
            if (artifactOutputPath != null && facets.size() > 0) {
                final JpsAndroidModuleExtension facet = facets.get(0);
                final String apkPath = AndroidFinalPackageElementBuilder.getApkPath(facet);
                if (FileUtil.pathsEqual(apkPath, artifactOutputPath)) {
                    context.processMessage(new CompilerMessage(ANDROID_VALIDATOR, BuildMessage.Kind.ERROR, "Incorrect output path for artifact '" + artifact.getName() + "': " + FileUtil.toSystemDependentName(apkPath)));
                    success = false;
                }
            }
        }
    }
    return success;
}
Also used : CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) JpsAndroidModuleExtension(org.jetbrains.jps.android.model.JpsAndroidModuleExtension) JpsArtifact(org.jetbrains.jps.model.artifact.JpsArtifact) AndroidApplicationArtifactType(org.jetbrains.jps.android.model.AndroidApplicationArtifactType)

Example 27 with JpsAndroidModuleExtension

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

the class AndroidSourceGeneratingBuilder method checkArtifacts.

private static boolean checkArtifacts(@NotNull CompileContext context) {
    final List<JpsArtifact> artifacts = AndroidJpsUtil.getAndroidArtifactsToBuild(context);
    if (!checkUnambiguousAndRecursiveArtifacts(context, artifacts)) {
        return false;
    }
    final Set<JpsArtifact> debugArtifacts = new HashSet<JpsArtifact>();
    final Set<JpsArtifact> releaseArtifacts = new HashSet<JpsArtifact>();
    final Map<String, List<JpsArtifact>> moduleName2Artifact = new HashMap<String, List<JpsArtifact>>();
    for (JpsArtifact artifact : artifacts) {
        final JpsElement properties = artifact.getProperties();
        if (!(properties instanceof JpsAndroidApplicationArtifactProperties)) {
            continue;
        }
        final AndroidArtifactSigningMode mode = ((JpsAndroidApplicationArtifactProperties) properties).getSigningMode();
        if (mode == AndroidArtifactSigningMode.DEBUG || mode == AndroidArtifactSigningMode.DEBUG_WITH_CUSTOM_CERTIFICATE) {
            debugArtifacts.add(artifact);
        } else {
            releaseArtifacts.add(artifact);
        }
        final JpsAndroidModuleExtension facet = AndroidJpsUtil.getPackagedFacet(artifact);
        if (facet != null) {
            final String moduleName = facet.getModule().getName();
            List<JpsArtifact> list = moduleName2Artifact.get(moduleName);
            if (list == null) {
                list = new ArrayList<JpsArtifact>();
                moduleName2Artifact.put(moduleName, list);
            }
            list.add(artifact);
        }
    }
    boolean success = true;
    if (debugArtifacts.size() > 0 && releaseArtifacts.size() > 0) {
        final String message = "Cannot build debug and release Android artifacts in the same session\n" + "Debug artifacts: " + artifactsToString(debugArtifacts) + "\n" + "Release artifacts: " + artifactsToString(releaseArtifacts);
        context.processMessage(new CompilerMessage(ANDROID_VALIDATOR, BuildMessage.Kind.ERROR, message));
        success = false;
    }
    if (releaseArtifacts.size() > 0 && AndroidJpsUtil.getRunConfigurationTypeId(context) != null) {
        final String message = "Cannot build release Android artifacts in the 'build before run' session\n" + "Release artifacts: " + artifactsToString(releaseArtifacts);
        context.processMessage(new CompilerMessage(ANDROID_VALIDATOR, BuildMessage.Kind.ERROR, message));
        success = false;
    }
    for (Map.Entry<String, List<JpsArtifact>> entry : moduleName2Artifact.entrySet()) {
        final List<JpsArtifact> list = entry.getValue();
        final String moduleName = entry.getKey();
        if (list.size() > 1) {
            final JpsArtifact firstArtifact = list.get(0);
            final Object[] firstArtifactProGuardOptions = getProGuardOptions(firstArtifact);
            for (int i = 1; i < list.size(); i++) {
                final JpsArtifact artifact = list.get(i);
                if (!Arrays.equals(getProGuardOptions(artifact), firstArtifactProGuardOptions)) {
                    context.processMessage(new CompilerMessage(ANDROID_VALIDATOR, BuildMessage.Kind.ERROR, "Artifacts related to the same module '" + moduleName + "' have different ProGuard options: " + firstArtifact.getName() + ", " + artifact.getName()));
                    success = false;
                    break;
                }
            }
        }
    }
    return success;
}
Also used : JpsElement(org.jetbrains.jps.model.JpsElement) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) HashMap(com.intellij.util.containers.HashMap) TObjectLongHashMap(gnu.trove.TObjectLongHashMap) JpsArtifact(org.jetbrains.jps.model.artifact.JpsArtifact) JpsAndroidApplicationArtifactProperties(org.jetbrains.jps.android.model.JpsAndroidApplicationArtifactProperties) JpsAndroidModuleExtension(org.jetbrains.jps.android.model.JpsAndroidModuleExtension) AndroidArtifactSigningMode(org.jetbrains.android.compiler.artifact.AndroidArtifactSigningMode) HashMap(com.intellij.util.containers.HashMap) TObjectLongHashMap(gnu.trove.TObjectLongHashMap) HashSet(com.intellij.util.containers.HashSet) THashSet(gnu.trove.THashSet)

Example 28 with JpsAndroidModuleExtension

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

the class AndroidSourceGeneratingBuilder method doBuild.

private static ModuleLevelBuilder.ExitCode doBuild(CompileContext context, ModuleChunk chunk, DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget> dirtyFilesHolder) throws IOException {
    final Map<JpsModule, MyModuleData> moduleDataMap = computeModuleDatas(chunk.getModules(), context);
    if (moduleDataMap == null || moduleDataMap.size() == 0) {
        return ExitCode.ABORT;
    }
    if (!checkVersions(moduleDataMap, context)) {
        return ExitCode.ABORT;
    }
    checkAndroidDependencies(moduleDataMap, context);
    if (!checkArtifacts(context)) {
        return ExitCode.ABORT;
    }
    if (JavaBuilderUtil.isForcedRecompilationAllJavaModules(context)) {
        if (!clearAndroidStorages(context, chunk.getModules())) {
            return ExitCode.ABORT;
        }
    }
    final Map<File, ModuleBuildTarget> idlFilesToCompile = new HashMap<File, ModuleBuildTarget>();
    final Map<File, ModuleBuildTarget> rsFilesToCompile = new HashMap<File, ModuleBuildTarget>();
    dirtyFilesHolder.processDirtyFiles(new FileProcessor<JavaSourceRootDescriptor, ModuleBuildTarget>() {

        @Override
        public boolean apply(ModuleBuildTarget target, File file, JavaSourceRootDescriptor sourceRoot) throws IOException {
            final JpsAndroidModuleExtension extension = AndroidJpsUtil.getExtension(target.getModule());
            if (extension == null) {
                return true;
            }
            String fileName = file.getName();
            if (FileUtilRt.extensionEquals(fileName, AIDL_EXTENSION)) {
                idlFilesToCompile.put(file, target);
            } else if (FileUtilRt.extensionEquals(fileName, RENDERSCRIPT_EXTENSION)) {
                rsFilesToCompile.put(file, target);
            }
            return true;
        }
    });
    boolean success = true;
    final BuildDataManager dataManager = context.getProjectDescriptor().dataManager;
    if (JavaBuilderUtil.isForcedRecompilationAllJavaModules(context)) {
        for (JpsModule module : moduleDataMap.keySet()) {
            final File generatedSourcesStorage = AndroidJpsUtil.getGeneratedSourcesStorage(module, dataManager);
            if (generatedSourcesStorage.exists() && !deleteAndMarkRecursively(generatedSourcesStorage, context, BUILDER_NAME)) {
                success = false;
            }
            final File generatedResourcesStorage = AndroidJpsUtil.getGeneratedResourcesStorage(module, dataManager);
            if (generatedResourcesStorage.exists() && !deleteAndMarkRecursively(generatedResourcesStorage, context, BUILDER_NAME)) {
                success = false;
            }
        }
    }
    if (!success) {
        return ExitCode.ABORT;
    }
    boolean didSomething = false;
    if (idlFilesToCompile.size() > 0) {
        if (!runAidlCompiler(context, idlFilesToCompile, moduleDataMap)) {
            success = false;
        }
        didSomething = true;
    }
    if (rsFilesToCompile.size() > 0) {
        if (!runRenderscriptCompiler(context, rsFilesToCompile, moduleDataMap)) {
            success = false;
        }
        didSomething = true;
    }
    MyExitStatus status = runAaptCompiler(context, moduleDataMap);
    if (status == MyExitStatus.FAIL) {
        success = false;
    } else if (status == MyExitStatus.OK) {
        didSomething = true;
    }
    status = runBuildConfigGeneration(context, moduleDataMap);
    if (status == MyExitStatus.FAIL) {
        success = false;
    } else if (status == MyExitStatus.OK) {
        didSomething = true;
    }
    if (!success) {
        return ExitCode.ABORT;
    }
    status = copyGeneratedSources(moduleDataMap, dataManager, context);
    if (status == MyExitStatus.FAIL) {
        return ExitCode.ABORT;
    } else if (status == MyExitStatus.OK) {
        didSomething = true;
    }
    if (didSomething) {
        return ExitCode.OK;
    }
    return ExitCode.NOTHING_DONE;
}
Also used : HashMap(com.intellij.util.containers.HashMap) TObjectLongHashMap(gnu.trove.TObjectLongHashMap) JpsModule(org.jetbrains.jps.model.module.JpsModule) JpsAndroidModuleExtension(org.jetbrains.jps.android.model.JpsAndroidModuleExtension) JavaSourceRootDescriptor(org.jetbrains.jps.builders.java.JavaSourceRootDescriptor) BuildDataManager(org.jetbrains.jps.incremental.storage.BuildDataManager)

Example 29 with JpsAndroidModuleExtension

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

the class AndroidPackagingBuildTarget method fillDependencies.

@Override
protected void fillDependencies(List<BuildTarget<?>> result) {
    final JpsAndroidModuleExtension extension = AndroidJpsUtil.getExtension(myModule);
    if (extension != null && !extension.isLibrary()) {
        // todo: remove this when AndroidPackagingBuilder will be fully target-based
        result.add(new AndroidDexBuildTarget(myModule));
        result.add(new AndroidResourcePackagingBuildTarget(myModule));
    }
}
Also used : JpsAndroidModuleExtension(org.jetbrains.jps.android.model.JpsAndroidModuleExtension)

Example 30 with JpsAndroidModuleExtension

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

the class AndroidResourcePackagingBuildTarget method doComputeRootDescriptors.

@NotNull
@Override
protected List<BuildRootDescriptor> doComputeRootDescriptors(JpsModel model, ModuleExcludeIndex index, IgnoredFileIndex ignoredFileIndex, BuildDataPaths dataPaths) {
    final JpsAndroidModuleExtension extension = AndroidJpsUtil.getExtension(myModule);
    assert extension != null;
    final String[] resourceDirs = AndroidJpsUtil.collectResourceDirsForCompilation(extension, true, dataPaths, false);
    final List<String> assertDirs = new ArrayList<String>();
    collectAssetDirs(extension, assertDirs, false);
    final File manifestFile = AndroidJpsUtil.getPreprocessedManifestFile(extension, dataPaths);
    final List<BuildRootDescriptor> result = new ArrayList<BuildRootDescriptor>();
    for (String resourceDir : resourceDirs) {
        result.add(new BuildRootDescriptorImpl(this, new File(resourceDir)));
    }
    for (String assetDir : assertDirs) {
        result.add(new BuildRootDescriptorImpl(this, new File(assetDir)));
    }
    if (manifestFile != null) {
        result.add(new BuildRootDescriptorImpl(this, manifestFile));
    }
    return result;
}
Also used : BuildRootDescriptorImpl(org.jetbrains.jps.builders.impl.BuildRootDescriptorImpl) BuildRootDescriptor(org.jetbrains.jps.builders.BuildRootDescriptor) JpsAndroidModuleExtension(org.jetbrains.jps.android.model.JpsAndroidModuleExtension) ArrayList(java.util.ArrayList) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

JpsAndroidModuleExtension (org.jetbrains.jps.android.model.JpsAndroidModuleExtension)30 File (java.io.File)16 JpsModule (org.jetbrains.jps.model.module.JpsModule)14 CompilerMessage (org.jetbrains.jps.incremental.messages.CompilerMessage)11 NotNull (org.jetbrains.annotations.NotNull)9 HashMap (com.intellij.util.containers.HashMap)8 ArrayList (java.util.ArrayList)8 BuildRootDescriptor (org.jetbrains.jps.builders.BuildRootDescriptor)7 ProgressMessage (org.jetbrains.jps.incremental.messages.ProgressMessage)7 HashSet (com.intellij.util.containers.HashSet)6 TObjectLongHashMap (gnu.trove.TObjectLongHashMap)6 IAndroidTarget (com.android.sdklib.IAndroidTarget)3 THashSet (gnu.trove.THashSet)3 IOException (java.io.IOException)3 AndroidBuildTestingManager (org.jetbrains.android.util.AndroidBuildTestingManager)3 AndroidCompilerMessageKind (org.jetbrains.android.util.AndroidCompilerMessageKind)3 BuildRootDescriptorImpl (org.jetbrains.jps.builders.impl.BuildRootDescriptorImpl)3 AndroidArtifactSigningMode (org.jetbrains.android.compiler.artifact.AndroidArtifactSigningMode)2 Nullable (org.jetbrains.annotations.Nullable)2 AndroidPlatform (org.jetbrains.jps.android.AndroidPlatform)2