Search in sources :

Example 31 with JpsModule

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

the class JavaBuilder method addCrossCompilationOptions.

private static void addCrossCompilationOptions(int compilerSdkVersion, List<String> options, CompileContext context, ModuleChunk chunk) {
    final JpsJavaCompilerConfiguration compilerConfiguration = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(context.getProjectDescriptor().getProject());
    final String langLevel = getLanguageLevel(chunk.getModules().iterator().next());
    final int chunkSdkVersion = getChunkSdkVersion(chunk);
    final int targetLanguageLevel = JpsJavaSdkType.parseVersion(langLevel);
    if (shouldUseReleaseOption(context, compilerSdkVersion, chunkSdkVersion, targetLanguageLevel)) {
        options.add(getReleaseOptionName());
        options.add(String.valueOf(targetLanguageLevel));
        return;
    }
    // using older -source, -target and -bootclasspath options
    if (!StringUtil.isEmpty(langLevel)) {
        options.add("-source");
        options.add(langLevel);
    }
    String bytecodeTarget = null;
    for (JpsModule module : chunk.getModules()) {
        final String moduleTarget = compilerConfiguration.getByteCodeTargetLevel(module.getName());
        if (moduleTarget == null) {
            continue;
        }
        if (bytecodeTarget == null) {
            bytecodeTarget = moduleTarget;
        } else {
            if (moduleTarget.compareTo(bytecodeTarget) < 0) {
                // use the lower possible target among modules that form the chunk
                bytecodeTarget = moduleTarget;
            }
        }
    }
    if (bytecodeTarget == null) {
        if (!StringUtil.isEmpty(langLevel)) {
            // according to IDEA rule: if not specified explicitly, set target to be the same as source language level
            bytecodeTarget = langLevel;
        } else {
            // last resort and backward compatibility:
            // check if user explicitly defined bytecode target in additional compiler options
            bytecodeTarget = USER_DEFINED_BYTECODE_TARGET.get(context);
        }
    }
    if (bytecodeTarget != null) {
        options.add("-target");
        if (chunkSdkVersion > 0 && compilerSdkVersion > chunkSdkVersion) {
            // if compiler is newer than module JDK
            final int userSpecifiedTargetVersion = JpsJavaSdkType.parseVersion(bytecodeTarget);
            if (userSpecifiedTargetVersion > 0 && userSpecifiedTargetVersion <= compilerSdkVersion) {
                // if user-specified bytecode version can be determined and is supported by compiler
                if (userSpecifiedTargetVersion > chunkSdkVersion) {
                    // and user-specified bytecode target level is higher than the highest one supported by the target JDK,
                    // force compiler to use highest-available bytecode target version that is supported by the chunk JDK.
                    bytecodeTarget = "1." + chunkSdkVersion;
                }
            }
        // otherwise let compiler display compilation error about incorrectly set bytecode target version
        }
        options.add(bytecodeTarget);
    } else {
        if (chunkSdkVersion > 0 && compilerSdkVersion > chunkSdkVersion) {
            // force lower bytecode target level to match the version of sdk assigned to this chunk
            options.add("-target");
            options.add("1." + chunkSdkVersion);
        }
    }
}
Also used : JpsModule(org.jetbrains.jps.model.module.JpsModule)

Example 32 with JpsModule

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

the class BuildTargetConfiguration method isTargetDirty.

public boolean isTargetDirty(CompileContext context) {
    final String currentState = getCurrentState(context);
    if (!currentState.equals(myConfiguration)) {
        LOG.debug(myTarget + " configuration was changed:");
        LOG.debug("Old:");
        LOG.debug(myConfiguration);
        LOG.debug("New:");
        LOG.debug(currentState);
        LOG.debug(myTarget + " will be recompiled");
        if (myTarget instanceof ModuleBuildTarget) {
            final JpsModule module = ((ModuleBuildTarget) myTarget).getModule();
            synchronized (MODULES_WITH_TARGET_CONFIG_CHANGED_KEY) {
                Set<JpsModule> modules = MODULES_WITH_TARGET_CONFIG_CHANGED_KEY.get(context);
                if (modules == null) {
                    MODULES_WITH_TARGET_CONFIG_CHANGED_KEY.set(context, modules = new THashSet<>());
                }
                modules.add(module);
            }
        }
        return true;
    }
    return false;
}
Also used : JpsModule(org.jetbrains.jps.model.module.JpsModule) ModuleBuildTarget(org.jetbrains.jps.incremental.ModuleBuildTarget) THashSet(gnu.trove.THashSet)

Example 33 with JpsModule

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

the class CommonTest method testMoveClassToDependentModule.

public void testMoveClassToDependentModule() throws Exception {
    JpsModule moduleA = addModule("moduleA", "moduleA/src");
    JpsModule moduleB = addModule("moduleB", "moduleB/src");
    JpsModuleRootModificationUtil.addDependency(moduleB, moduleA);
    doTestBuild(1).assertSuccessful();
}
Also used : JpsModule(org.jetbrains.jps.model.module.JpsModule)

Example 34 with JpsModule

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

the class MarkDirtyTest method testDoNotMarkDirtyCompiledChunks.

public void testDoNotMarkDirtyCompiledChunks() {
    //'b.Client' from production sources of 'b' cannot depend on 'a.ShortName' from module 'a' so it shouldn't be marked as dirty.
    //Otherwise we can get 'dirty' sources after full make if production of 'b' was compiled before 'a'
    JpsModule b = addModule("b", "moduleB/src");
    addTestRoot(b, "moduleB/testSrc");
    JpsModule a = addModule("a", "moduleA/src");
    addTestRoot(a, "moduleA/testSrc");
    JpsModuleRootModificationUtil.addDependency(b, a, JpsJavaDependencyScope.TEST, false);
    doTestBuild(2).assertSuccessful();
}
Also used : JpsModule(org.jetbrains.jps.model.module.JpsModule)

Example 35 with JpsModule

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

the class MarkDirtyTest method testTransitiveRecompile.

public void testTransitiveRecompile() {
    JpsModule module = addModule();
    addTestRoot(module, "testSrc");
    JpsModule util = addModule("util", "util/src");
    addTestRoot(util, "util/testSrc");
    JpsModuleRootModificationUtil.addDependency(module, util);
    JpsModule lib = addModule("lib", "lib/src");
    addTestRoot(lib, "lib/testSrc");
    JpsModuleRootModificationUtil.addDependency(util, lib);
    doTestBuild(1).assertSuccessful();
}
Also used : JpsModule(org.jetbrains.jps.model.module.JpsModule)

Aggregations

JpsModule (org.jetbrains.jps.model.module.JpsModule)128 File (java.io.File)33 NotNull (org.jetbrains.annotations.NotNull)15 CompilerMessage (org.jetbrains.jps.incremental.messages.CompilerMessage)15 JpsAndroidModuleExtension (org.jetbrains.jps.android.model.JpsAndroidModuleExtension)14 JpsAndroidModuleExtensionImpl (org.jetbrains.jps.android.model.impl.JpsAndroidModuleExtensionImpl)13 JpsAndroidModuleProperties (org.jetbrains.jps.android.model.impl.JpsAndroidModuleProperties)13 THashSet (gnu.trove.THashSet)11 JpsLibrary (org.jetbrains.jps.model.library.JpsLibrary)11 ProgressMessage (org.jetbrains.jps.incremental.messages.ProgressMessage)10 JpsSimpleElement (org.jetbrains.jps.model.JpsSimpleElement)10 JpsArtifact (org.jetbrains.jps.model.artifact.JpsArtifact)10 ArrayList (java.util.ArrayList)9 HashMap (com.intellij.util.containers.HashMap)8 IOException (java.io.IOException)8 TObjectLongHashMap (gnu.trove.TObjectLongHashMap)7 JpsDependencyElement (org.jetbrains.jps.model.module.JpsDependencyElement)7 JpsDummyElement (org.jetbrains.jps.model.JpsDummyElement)6 Pair (com.intellij.openapi.util.Pair)5 Nullable (org.jetbrains.annotations.Nullable)5