Search in sources :

Example 11 with JpsElement

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

the class AndroidJpsUtil method getProGuardConfigIfShouldRun.

public static ProGuardOptions getProGuardConfigIfShouldRun(@NotNull CompileContext context, @NotNull JpsAndroidModuleExtension extension) throws IOException {
    if (extension.isRunProguard()) {
        return new ProGuardOptions(extension.getProguardConfigFiles(extension.getModule()));
    }
    final String cfgPathsStrFromContext = context.getBuilderParameter(AndroidCommonUtils.PROGUARD_CFG_PATHS_OPTION);
    if (cfgPathsStrFromContext != null && cfgPathsStrFromContext.length() > 0) {
        final String[] paths = cfgPathsStrFromContext.split(File.pathSeparator);
        if (paths.length > 0) {
            final File[] files = toFiles(paths);
            return new ProGuardOptions(Arrays.asList(files));
        }
    }
    for (JpsArtifact artifact : getAndroidArtifactsToBuild(context)) {
        final JpsAndroidModuleExtension facetFromArtifact = getPackagedFacet(artifact);
        final JpsModule moduleFromArtifact = facetFromArtifact != null ? facetFromArtifact.getModule() : null;
        if (moduleFromArtifact != null && moduleFromArtifact.equals(extension.getModule())) {
            final JpsElement props = artifact.getProperties();
            if (props instanceof JpsAndroidApplicationArtifactProperties) {
                final JpsAndroidApplicationArtifactProperties androidProps = (JpsAndroidApplicationArtifactProperties) props;
                if (androidProps.isRunProGuard()) {
                    final List<String> cfgFileUrls = androidProps.getProGuardCfgFiles(moduleFromArtifact);
                    final List<File> cfgPaths = cfgFileUrls != null ? urlsToFiles(cfgFileUrls) : null;
                    return new ProGuardOptions(cfgPaths);
                }
            }
        }
    }
    return null;
}
Also used : JpsElement(org.jetbrains.jps.model.JpsElement) JpsArtifact(org.jetbrains.jps.model.artifact.JpsArtifact)

Example 12 with JpsElement

use of org.jetbrains.jps.model.JpsElement in project intellij-community by JetBrains.

the class JpsSdkTableSerializer method saveSdk.

private static <P extends JpsElement> void saveSdk(final JpsSdk<P> sdk, Element sdkTag) {
    JpsLibrary library = sdk.getParent();
    sdkTag.setAttribute("version", "2");
    setAttributeValue(sdkTag, NAME_TAG, library.getName());
    JpsSdkPropertiesSerializer<P> serializer = getSdkPropertiesSerializer(sdk.getSdkType());
    setAttributeValue(sdkTag, TYPE_TAG, serializer.getTypeId());
    String versionString = sdk.getVersionString();
    if (versionString != null) {
        setAttributeValue(sdkTag, VERSION_TAG, versionString);
    }
    setAttributeValue(sdkTag, HOME_PATH_TAG, sdk.getHomePath());
    Element rootsTag = new Element(ROOTS_TAG);
    for (JpsLibraryRootTypeSerializer rootTypeSerializer : getRootTypeSerializers()) {
        Element rootTypeTag = new Element(rootTypeSerializer.getTypeId());
        Element compositeTag = new Element(ROOT_TAG);
        compositeTag.setAttribute(TYPE_ATTRIBUTE, COMPOSITE_TYPE);
        List<JpsLibraryRoot> roots = library.getRoots(rootTypeSerializer.getType());
        for (JpsLibraryRoot root : roots) {
            compositeTag.addContent(new Element(ROOT_TAG).setAttribute(TYPE_ATTRIBUTE, SIMPLE_TYPE).setAttribute(URL_ATTRIBUTE, root.getUrl()));
        }
        rootTypeTag.addContent(compositeTag);
        rootsTag.addContent(rootTypeTag);
    }
    sdkTag.addContent(rootsTag);
    Element additionalTag = new Element(ADDITIONAL_TAG);
    serializer.saveProperties(sdk.getSdkProperties(), additionalTag);
    sdkTag.addContent(additionalTag);
}
Also used : JpsElement(org.jetbrains.jps.model.JpsElement) JpsDummyElement(org.jetbrains.jps.model.JpsDummyElement) Element(org.jdom.Element) JpsLibrary(org.jetbrains.jps.model.library.JpsLibrary) JpsLibraryRoot(org.jetbrains.jps.model.library.JpsLibraryRoot)

Example 13 with JpsElement

use of org.jetbrains.jps.model.JpsElement in project intellij-community by JetBrains.

the class JpsSdkTableSerializer method createSdk.

private static <P extends JpsElement> JpsLibrary createSdk(String name, JpsSdkPropertiesSerializer<P> loader, Element sdkElement) {
    String versionString = getAttributeValue(sdkElement, VERSION_TAG);
    String homePath = getAttributeValue(sdkElement, HOME_PATH_TAG);
    Element propertiesTag = sdkElement.getChild(ADDITIONAL_TAG);
    P properties = loader.loadProperties(propertiesTag);
    return JpsElementFactory.getInstance().createSdk(name, homePath, versionString, loader.getType(), properties);
}
Also used : JpsElement(org.jetbrains.jps.model.JpsElement) JpsDummyElement(org.jetbrains.jps.model.JpsDummyElement) Element(org.jdom.Element)

Example 14 with JpsElement

use of org.jetbrains.jps.model.JpsElement 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 15 with JpsElement

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

the class AndroidSourceGeneratingBuilder method getProGuardOptions.

@NotNull
private static Object[] getProGuardOptions(@NotNull JpsArtifact artifact) {
    final JpsElement properties = artifact.getProperties();
    if (properties instanceof JpsAndroidApplicationArtifactProperties) {
        final JpsAndroidApplicationArtifactProperties p = (JpsAndroidApplicationArtifactProperties) properties;
        final boolean runProGuard = p.isRunProGuard();
        return runProGuard ? new Object[] { runProGuard, p.getProGuardCfgFiles() } : new Object[] { runProGuard };
    }
    return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
Also used : JpsElement(org.jetbrains.jps.model.JpsElement) JpsAndroidApplicationArtifactProperties(org.jetbrains.jps.android.model.JpsAndroidApplicationArtifactProperties) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

JpsElement (org.jetbrains.jps.model.JpsElement)15 Element (org.jdom.Element)7 JpsDummyElement (org.jetbrains.jps.model.JpsDummyElement)4 JpsAndroidApplicationArtifactProperties (org.jetbrains.jps.android.model.JpsAndroidApplicationArtifactProperties)3 JpsModuleSourceRoot (org.jetbrains.jps.model.module.JpsModuleSourceRoot)3 JpsContentEntry (com.intellij.project.model.impl.module.content.JpsContentEntry)2 JpsSourceFolder (com.intellij.project.model.impl.module.content.JpsSourceFolder)2 File (java.io.File)2 AndroidArtifactSigningMode (org.jetbrains.android.compiler.artifact.AndroidArtifactSigningMode)2 NotNull (org.jetbrains.annotations.NotNull)2 JpsAndroidModuleExtension (org.jetbrains.jps.android.model.JpsAndroidModuleExtension)2 JpsArtifact (org.jetbrains.jps.model.artifact.JpsArtifact)2 JavaSourceRootProperties (org.jetbrains.jps.model.java.JavaSourceRootProperties)2 JpsLibrary (org.jetbrains.jps.model.library.JpsLibrary)2 SourceFolder (com.intellij.openapi.roots.SourceFolder)1 JpsRootModel (com.intellij.project.model.impl.module.JpsRootModel)1 HashMap (com.intellij.util.containers.HashMap)1 HashSet (com.intellij.util.containers.HashSet)1 THashSet (gnu.trove.THashSet)1 TObjectLongHashMap (gnu.trove.TObjectLongHashMap)1