Search in sources :

Example 26 with JpsModule

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

the class IdeaJdk method setupSdkPathsFromIDEAProject.

private static void setupSdkPathsFromIDEAProject(Sdk sdk, SdkModificator sdkModificator, SdkModel sdkModel) throws IOException {
    ProgressIndicator indicator = ObjectUtils.assertNotNull(ProgressManager.getInstance().getProgressIndicator());
    String sdkHome = ObjectUtils.notNull(sdk.getHomePath());
    JpsModel model = JpsSerializationManager.getInstance().loadModel(sdkHome, PathManager.getOptionsPath());
    JpsSdkReference<JpsDummyElement> sdkRef = model.getProject().getSdkReferencesTable().getSdkReference(JpsJavaSdkType.INSTANCE);
    String sdkName = sdkRef == null ? null : sdkRef.getSdkName();
    Sdk internalJava = sdkModel.findSdk(sdkName);
    if (internalJava != null && isValidInternalJdk(sdk, internalJava)) {
        setInternalJdk(sdk, sdkModificator, internalJava);
    }
    Set<VirtualFile> addedRoots = ContainerUtil.newTroveSet();
    VirtualFileManager vfsManager = VirtualFileManager.getInstance();
    JpsJavaExtensionService javaService = JpsJavaExtensionService.getInstance();
    boolean isUltimate = vfsManager.findFileByUrl(VfsUtilCore.pathToUrl(sdkHome + "/ultimate/ultimate-resources")) != null;
    Set<String> suppressedModules = ContainerUtil.newTroveSet("jps-plugin-system");
    Set<String> ultimateModules = ContainerUtil.newTroveSet("platform-ultimate", "ultimate-resources", "ultimate-verifier", "diagram-api", "diagram-impl", "uml-plugin");
    List<JpsModule> modules = JBIterable.from(model.getProject().getModules()).filter(o -> {
        if (suppressedModules.contains(o.getName()))
            return false;
        if (o.getName().endsWith("-ide"))
            return false;
        String contentUrl = ContainerUtil.getFirstItem(o.getContentRootsList().getUrls());
        if (contentUrl == null)
            return true;
        return !isUltimate || contentUrl.contains("/community/") || ultimateModules.contains(o.getName());
    }).toList();
    indicator.setIndeterminate(false);
    double delta = 1 / (2 * Math.max(0.5, modules.size()));
    for (JpsModule o : modules) {
        indicator.setFraction(indicator.getFraction() + delta);
        for (JpsDependencyElement dep : o.getDependenciesList().getDependencies()) {
            ProgressManager.checkCanceled();
            JpsLibrary library = dep instanceof JpsLibraryDependency ? ((JpsLibraryDependency) dep).getLibrary() : null;
            JpsLibraryType<?> libraryType = library == null ? null : library.getType();
            if (!(libraryType instanceof JpsJavaLibraryType))
                continue;
            JpsJavaDependencyExtension extension = javaService.getDependencyExtension(dep);
            if (extension == null)
                continue;
            // do not check extension.getScope(), plugin projects need tests too
            for (JpsLibraryRoot jps : library.getRoots(JpsOrderRootType.COMPILED)) {
                VirtualFile root = vfsManager.findFileByUrl(jps.getUrl());
                if (root == null || !addedRoots.add(root))
                    continue;
                sdkModificator.addRoot(root, OrderRootType.CLASSES);
            }
            for (JpsLibraryRoot jps : library.getRoots(JpsOrderRootType.SOURCES)) {
                VirtualFile root = vfsManager.findFileByUrl(jps.getUrl());
                if (root == null || !addedRoots.add(root))
                    continue;
                sdkModificator.addRoot(root, OrderRootType.SOURCES);
            }
        }
    }
    for (JpsModule o : modules) {
        indicator.setFraction(indicator.getFraction() + delta);
        String outputUrl = javaService.getOutputUrl(o, false);
        VirtualFile outputRoot = outputUrl == null ? null : vfsManager.findFileByUrl(outputUrl);
        if (outputRoot == null)
            continue;
        sdkModificator.addRoot(outputRoot, OrderRootType.CLASSES);
        for (JpsModuleSourceRoot jps : o.getSourceRoots()) {
            ProgressManager.checkCanceled();
            VirtualFile root = vfsManager.findFileByUrl(jps.getUrl());
            if (root == null || !addedRoots.add(root))
                continue;
            sdkModificator.addRoot(root, OrderRootType.SOURCES);
        }
    }
    indicator.setFraction(1.0);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Arrays(java.util.Arrays) JBIterable(com.intellij.util.containers.JBIterable) VirtualFile(com.intellij.openapi.vfs.VirtualFile) JpsJavaLibraryType(org.jetbrains.jps.model.java.JpsJavaLibraryType) VirtualFileManager(com.intellij.openapi.vfs.VirtualFileManager) Messages(com.intellij.openapi.ui.Messages) ZipFile(java.util.zip.ZipFile) FileUtil(com.intellij.openapi.util.io.FileUtil) Logger(com.intellij.openapi.diagnostic.Logger) ZipEntry(java.util.zip.ZipEntry) JpsLibrary(org.jetbrains.jps.model.library.JpsLibrary) ProgressManager(com.intellij.openapi.progress.ProgressManager) LanguageLevel(com.intellij.pom.java.LanguageLevel) OrderRootType(com.intellij.openapi.roots.OrderRootType) Set(java.util.Set) JpsLibraryDependency(org.jetbrains.jps.model.module.JpsLibraryDependency) JpsJavaDependencyExtension(org.jetbrains.jps.model.java.JpsJavaDependencyExtension) JpsModule(org.jetbrains.jps.model.module.JpsModule) ThrowableComputable(com.intellij.openapi.util.ThrowableComputable) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) ApplicationStarter(com.intellij.openapi.application.ApplicationStarter) JavaDependentSdkType(com.intellij.openapi.projectRoots.impl.JavaDependentSdkType) JpsSerializationManager(org.jetbrains.jps.model.serialization.JpsSerializationManager) WriteExternalException(com.intellij.openapi.util.WriteExternalException) NotNull(org.jetbrains.annotations.NotNull) DataInputStream(java.io.DataInputStream) JpsDummyElement(org.jetbrains.jps.model.JpsDummyElement) ArrayUtil(com.intellij.util.ArrayUtil) JpsOrderRootType(org.jetbrains.jps.model.library.JpsOrderRootType) PathManager(com.intellij.openapi.application.PathManager) DevkitIcons(icons.DevkitIcons) NonNls(org.jetbrains.annotations.NonNls) InvalidDataException(com.intellij.openapi.util.InvalidDataException) ContainerUtil(com.intellij.util.containers.ContainerUtil) JavadocOrderRootType(com.intellij.openapi.roots.JavadocOrderRootType) JpsLibraryType(org.jetbrains.jps.model.library.JpsLibraryType) ClsParsingUtil(com.intellij.psi.impl.compiled.ClsParsingUtil) ArrayList(java.util.ArrayList) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) JpsSdkReference(org.jetbrains.jps.model.library.sdk.JpsSdkReference) com.intellij.openapi.projectRoots(com.intellij.openapi.projectRoots) JpsJavaExtensionService(org.jetbrains.jps.model.java.JpsJavaExtensionService) JpsModel(org.jetbrains.jps.model.JpsModel) JpsDependencyElement(org.jetbrains.jps.model.module.JpsDependencyElement) JpsJavaSdkType(org.jetbrains.jps.model.java.JpsJavaSdkType) JpsModuleSourceRoot(org.jetbrains.jps.model.module.JpsModuleSourceRoot) VfsUtilCore(com.intellij.openapi.vfs.VfsUtilCore) JpsLibraryRoot(org.jetbrains.jps.model.library.JpsLibraryRoot) IOException(java.io.IOException) SystemInfo(com.intellij.openapi.util.SystemInfo) File(java.io.File) DevKitBundle(org.jetbrains.idea.devkit.DevKitBundle) AnnotationOrderRootType(com.intellij.openapi.roots.AnnotationOrderRootType) JarFileSystem(com.intellij.openapi.vfs.JarFileSystem) ObjectUtils(com.intellij.util.ObjectUtils) Element(org.jdom.Element) javax.swing(javax.swing) JpsLibraryDependency(org.jetbrains.jps.model.module.JpsLibraryDependency) JpsModel(org.jetbrains.jps.model.JpsModel) VirtualFileManager(com.intellij.openapi.vfs.VirtualFileManager) JpsDependencyElement(org.jetbrains.jps.model.module.JpsDependencyElement) JpsJavaLibraryType(org.jetbrains.jps.model.java.JpsJavaLibraryType) JpsModule(org.jetbrains.jps.model.module.JpsModule) JpsModuleSourceRoot(org.jetbrains.jps.model.module.JpsModuleSourceRoot) JpsJavaExtensionService(org.jetbrains.jps.model.java.JpsJavaExtensionService) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) JpsJavaDependencyExtension(org.jetbrains.jps.model.java.JpsJavaDependencyExtension) JpsDummyElement(org.jetbrains.jps.model.JpsDummyElement) JpsLibrary(org.jetbrains.jps.model.library.JpsLibrary) JpsLibraryRoot(org.jetbrains.jps.model.library.JpsLibraryRoot)

Example 27 with JpsModule

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

the class AppEngineEnhancerBuilder method processModule.

private static boolean processModule(final CompileContext context, DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget> dirtyFilesHolder, JpsAppEngineModuleExtension extension) throws IOException, ProjectBuildException {
    final Set<File> roots = new THashSet<>(FileUtil.FILE_HASHING_STRATEGY);
    for (String path : extension.getFilesToEnhance()) {
        roots.add(new File(FileUtil.toSystemDependentName(path)));
    }
    final List<String> pathsToProcess = new ArrayList<>();
    dirtyFilesHolder.processDirtyFiles(new FileProcessor<JavaSourceRootDescriptor, ModuleBuildTarget>() {

        @Override
        public boolean apply(ModuleBuildTarget target, File file, JavaSourceRootDescriptor root) throws IOException {
            if (JpsPathUtil.isUnder(roots, file)) {
                Collection<String> outputs = context.getProjectDescriptor().dataManager.getSourceToOutputMap(target).getOutputs(file.getAbsolutePath());
                if (outputs != null) {
                    pathsToProcess.addAll(outputs);
                }
            }
            return true;
        }
    });
    if (pathsToProcess.isEmpty()) {
        return false;
    }
    JpsModule module = extension.getModule();
    JpsSdk<JpsDummyElement> sdk = JavaBuilderUtil.ensureModuleHasJdk(module, context, NAME);
    context.processMessage(new ProgressMessage("Enhancing classes in module '" + module.getName() + "'..."));
    List<String> vmParams = Collections.singletonList("-Xmx256m");
    List<String> classpath = new ArrayList<>();
    classpath.add(extension.getToolsApiJarPath());
    classpath.add(PathManager.getJarPathForClass(EnhancerRunner.class));
    boolean removeOrmJars = Boolean.parseBoolean(System.getProperty("jps.appengine.enhancer.remove.orm.jars", "true"));
    for (File file : JpsJavaExtensionService.dependencies(module).recursively().compileOnly().productionOnly().classes().getRoots()) {
        if (removeOrmJars && FileUtil.isAncestor(new File(extension.getOrmLibPath()), file, true)) {
            continue;
        }
        classpath.add(file.getAbsolutePath());
    }
    List<String> programParams = new ArrayList<>();
    final File argsFile = FileUtil.createTempFile("appEngineEnhanceFiles", ".txt");
    PrintWriter writer = new PrintWriter(argsFile);
    try {
        for (String path : pathsToProcess) {
            writer.println(FileUtil.toSystemDependentName(path));
        }
    } finally {
        writer.close();
    }
    programParams.add(argsFile.getAbsolutePath());
    programParams.add("com.google.appengine.tools.enhancer.Enhance");
    programParams.add("-api");
    PersistenceApi api = extension.getPersistenceApi();
    programParams.add(api.getEnhancerApiName());
    if (api.getEnhancerVersion() == 2) {
        programParams.add("-enhancerVersion");
        programParams.add("v2");
    }
    programParams.add("-v");
    List<String> commandLine = ExternalProcessUtil.buildJavaCommandLine(JpsJavaSdkType.getJavaExecutable(sdk), EnhancerRunner.class.getName(), Collections.<String>emptyList(), classpath, vmParams, programParams);
    Process process = new ProcessBuilder(commandLine).start();
    ExternalEnhancerProcessHandler handler = new ExternalEnhancerProcessHandler(process, commandLine, context);
    handler.startNotify();
    handler.waitFor();
    ProjectBuilderLogger logger = context.getLoggingManager().getProjectBuilderLogger();
    if (logger.isEnabled()) {
        logger.logCompiledPaths(pathsToProcess, NAME, "Enhancing classes:");
    }
    return true;
}
Also used : ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) IOException(java.io.IOException) THashSet(gnu.trove.THashSet) EnhancerRunner(com.intellij.appengine.rt.EnhancerRunner) JpsModule(org.jetbrains.jps.model.module.JpsModule) PersistenceApi(org.jetbrains.jps.appengine.model.PersistenceApi) ProjectBuilderLogger(org.jetbrains.jps.builders.logging.ProjectBuilderLogger) JpsDummyElement(org.jetbrains.jps.model.JpsDummyElement) JavaSourceRootDescriptor(org.jetbrains.jps.builders.java.JavaSourceRootDescriptor) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 28 with JpsModule

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

the class GreclipseBuilder method build.

@Override
public ExitCode build(final CompileContext context, ModuleChunk chunk, DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget> dirtyFilesHolder, OutputConsumer outputConsumer) throws ProjectBuildException, IOException {
    if (!useGreclipse(context))
        return ModuleLevelBuilder.ExitCode.NOTHING_DONE;
    try {
        final List<File> toCompile = myHelper.collectChangedFiles(context, dirtyFilesHolder, false, true, Ref.create(false));
        if (toCompile.isEmpty()) {
            return ExitCode.NOTHING_DONE;
        }
        Map<ModuleBuildTarget, String> outputDirs = GroovyBuilder.getCanonicalModuleOutputs(context, chunk, this);
        if (outputDirs == null) {
            return ExitCode.ABORT;
        }
        JpsProject project = context.getProjectDescriptor().getProject();
        GreclipseSettings greclipseSettings = GreclipseJpsCompilerSettings.getSettings(project);
        if (greclipseSettings == null) {
            String message = "Compiler settings component not initialized for " + project;
            LOG.error(message);
            context.processMessage(new CompilerMessage(getPresentableName(), BuildMessage.Kind.ERROR, message));
            return ExitCode.ABORT;
        }
        ClassLoader loader = createGreclipseLoader(greclipseSettings.greclipsePath);
        if (loader == null) {
            context.processMessage(new CompilerMessage(getPresentableName(), BuildMessage.Kind.ERROR, "Invalid jar path in the compiler settings: '" + greclipseSettings.greclipsePath + "'"));
            return ExitCode.ABORT;
        }
        final JpsJavaExtensionService javaExt = JpsJavaExtensionService.getInstance();
        final JpsJavaCompilerConfiguration compilerConfig = javaExt.getCompilerConfiguration(project);
        assert compilerConfig != null;
        final Set<JpsModule> modules = chunk.getModules();
        ProcessorConfigProfile profile = null;
        if (modules.size() == 1) {
            profile = compilerConfig.getAnnotationProcessingProfile(modules.iterator().next());
        } else {
            String message = JavaBuilder.validateCycle(chunk, javaExt, compilerConfig, modules);
            if (message != null) {
                context.processMessage(new CompilerMessage(getPresentableName(), BuildMessage.Kind.ERROR, message));
                return ExitCode.ABORT;
            }
        }
        String mainOutputDir = outputDirs.get(chunk.representativeTarget());
        final List<String> args = createCommandLine(context, chunk, toCompile, mainOutputDir, profile, greclipseSettings);
        if (Utils.IS_TEST_MODE || LOG.isDebugEnabled()) {
            LOG.debug("Compiling with args: " + args);
        }
        Boolean notified = COMPILER_VERSION_INFO.get(context);
        if (notified != Boolean.TRUE) {
            context.processMessage(new CompilerMessage("", BuildMessage.Kind.INFO, "Using Groovy-Eclipse to compile Java & Groovy sources"));
            COMPILER_VERSION_INFO.set(context, Boolean.TRUE);
        }
        context.processMessage(new ProgressMessage("Compiling java & groovy [" + chunk.getPresentableShortName() + "]"));
        StringWriter out = new StringWriter();
        StringWriter err = new StringWriter();
        HashMap<String, List<String>> outputMap = ContainerUtil.newHashMap();
        boolean success = performCompilation(args, out, err, outputMap, context, chunk);
        List<GroovycOutputParser.OutputItem> items = ContainerUtil.newArrayList();
        for (String src : outputMap.keySet()) {
            //noinspection ConstantConditions
            for (String classFile : outputMap.get(src)) {
                items.add(new GroovycOutputParser.OutputItem(FileUtil.toSystemIndependentName(mainOutputDir + classFile), FileUtil.toSystemIndependentName(src)));
            }
        }
        MultiMap<ModuleBuildTarget, GroovycOutputParser.OutputItem> successfullyCompiled = myHelper.processCompiledFiles(context, chunk, outputDirs, mainOutputDir, items);
        EclipseOutputParser parser = new EclipseOutputParser(getPresentableName(), chunk);
        List<CompilerMessage> messages = ContainerUtil.concat(parser.parseMessages(out.toString()), parser.parseMessages(err.toString()));
        boolean hasError = false;
        for (CompilerMessage message : messages) {
            if (message.getKind() == BuildMessage.Kind.ERROR) {
                hasError = true;
            }
            context.processMessage(message);
        }
        if (!success && !hasError) {
            context.processMessage(new CompilerMessage(getPresentableName(), BuildMessage.Kind.ERROR, "Compilation failed"));
        }
        myHelper.updateDependencies(context, toCompile, successfullyCompiled, new DefaultOutputConsumer(outputConsumer), this);
        return ExitCode.OK;
    } catch (Exception e) {
        throw new ProjectBuildException(e);
    }
}
Also used : JpsJavaCompilerConfiguration(org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration) ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) JpsJavaExtensionService(org.jetbrains.jps.model.java.JpsJavaExtensionService) StringWriter(java.io.StringWriter) JpsProject(org.jetbrains.jps.model.JpsProject) URLClassLoader(java.net.URLClassLoader) IOException(java.io.IOException) JpsModule(org.jetbrains.jps.model.module.JpsModule) ProcessorConfigProfile(org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile) File(java.io.File)

Example 29 with JpsModule

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

the class JavaBuilder method compileJava.

private boolean compileJava(CompileContext context, ModuleChunk chunk, Collection<File> files, Collection<File> originalClassPath, Collection<File> originalPlatformCp, Collection<File> sourcePath, DiagnosticOutputConsumer diagnosticSink, OutputFileConsumer outputSink, JavaCompilingTool compilingTool) throws Exception {
    final TasksCounter counter = new TasksCounter();
    COUNTER_KEY.set(context, counter);
    final JpsJavaExtensionService javaExt = JpsJavaExtensionService.getInstance();
    final JpsJavaCompilerConfiguration compilerConfig = javaExt.getCompilerConfiguration(context.getProjectDescriptor().getProject());
    assert compilerConfig != null;
    final Set<JpsModule> modules = chunk.getModules();
    ProcessorConfigProfile profile = null;
    if (modules.size() == 1) {
        profile = compilerConfig.getAnnotationProcessingProfile(modules.iterator().next());
    } else {
        String message = validateCycle(chunk, javaExt, compilerConfig, modules);
        if (message != null) {
            diagnosticSink.report(new PlainMessageDiagnostic(Diagnostic.Kind.ERROR, message));
            return true;
        }
    }
    final Map<File, Set<File>> outs = buildOutputDirectoriesMap(context, chunk);
    try {
        final int targetLanguageLevel = JpsJavaSdkType.parseVersion(getLanguageLevel(chunk.getModules().iterator().next()));
        final boolean shouldForkJavac = shouldForkCompilerProcess(context, chunk, targetLanguageLevel);
        final boolean hasModules = targetLanguageLevel >= 9 && getJavaModuleIndex(context).hasJavaModules(modules);
        // when forking external javac, compilers from SDK 1.6 and higher are supported
        Pair<String, Integer> forkSdk = null;
        if (shouldForkJavac) {
            forkSdk = getForkedJavacSdk(chunk, targetLanguageLevel);
            if (forkSdk == null) {
                String text = "Cannot start javac process for " + chunk.getName() + ": unknown JDK home path.\nPlease check project configuration.";
                diagnosticSink.report(new PlainMessageDiagnostic(Diagnostic.Kind.ERROR, text));
                return true;
            }
        }
        final int compilerSdkVersion = forkSdk == null ? getCompilerSdkVersion(context) : forkSdk.getSecond();
        final List<String> options = getCompilationOptions(compilerSdkVersion, context, chunk, profile, compilingTool);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Compiling chunk [" + chunk.getName() + "] with options: \"" + StringUtil.join(options, " ") + "\"");
        }
        Collection<File> platformCp = calcEffectivePlatformCp(originalPlatformCp, options, compilingTool);
        if (platformCp == null) {
            String text = "Compact compilation profile was requested, but target platform for module \"" + chunk.getName() + "\"" + " differs from javac's platform (" + System.getProperty("java.version") + ")\n" + "Compilation profiles are not supported for such configuration";
            context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, text));
            return true;
        }
        Collection<File> classPath = originalClassPath;
        Collection<File> modulePath = Collections.emptyList();
        if (hasModules) {
            // in Java 9, named modules are not allowed to read classes from the classpath
            // moreover, the compiler requires all transitive dependencies to be on the module path
            modulePath = ProjectPaths.getCompilationModulePath(chunk, false);
            classPath = Collections.emptyList();
        }
        if (!platformCp.isEmpty()) {
            final int chunkSdkVersion;
            if (hasModules) {
                modulePath = newArrayList(concat(platformCp, modulePath));
                platformCp = Collections.emptyList();
            } else if ((chunkSdkVersion = getChunkSdkVersion(chunk)) >= 9) {
                // if chunk's SDK is 9 or higher, there is no way to specify full platform classpath
                // because platform classes are stored in jimage binary files with unknown format.
                // Because of this we are clearing platform classpath so that javac will resolve against its own boot classpath
                // and prepending additional jars from the JDK configuration to compilation classpath
                classPath = newArrayList(concat(platformCp, classPath));
                platformCp = Collections.emptyList();
            } else if (shouldUseReleaseOption(context, compilerSdkVersion, chunkSdkVersion, targetLanguageLevel)) {
                final Collection<File> joined = new ArrayList<>(classPath.size() + 1);
                for (File file : platformCp) {
                    // include only additional jars from sdk distribution, e.g. tools.jar
                    if (!FileUtil.toSystemIndependentName(file.getAbsolutePath()).contains("/jre/")) {
                        joined.add(file);
                    }
                }
                joined.addAll(classPath);
                classPath = joined;
                platformCp = Collections.emptyList();
            }
        }
        final ClassProcessingConsumer classesConsumer = new ClassProcessingConsumer(context, outputSink);
        final boolean rc;
        if (!shouldForkJavac) {
            updateCompilerUsageStatistics(context, compilingTool.getDescription(), chunk);
            rc = JavacMain.compile(options, files, classPath, platformCp, modulePath, sourcePath, outs, diagnosticSink, classesConsumer, context.getCancelStatus(), compilingTool);
        } else {
            updateCompilerUsageStatistics(context, "javac " + forkSdk.getSecond(), chunk);
            final List<String> vmOptions = getCompilationVMOptions(context, compilingTool);
            final ExternalJavacManager server = ensureJavacServerStarted(context);
            rc = server.forkJavac(forkSdk.getFirst(), getExternalJavacHeapSize(context), vmOptions, options, platformCp, classPath, modulePath, sourcePath, files, outs, diagnosticSink, classesConsumer, compilingTool, context.getCancelStatus());
        }
        return rc;
    } finally {
        counter.await();
    }
}
Also used : THashSet(gnu.trove.THashSet) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) ContainerUtil.newArrayList(com.intellij.util.containers.ContainerUtil.newArrayList) JpsModule(org.jetbrains.jps.model.module.JpsModule) JpsJavaExtensionService(org.jetbrains.jps.model.java.JpsJavaExtensionService)

Example 30 with JpsModule

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

the class JavaBuilder method getCompilationOptions.

private static List<String> getCompilationOptions(int compilerSdkVersion, CompileContext context, ModuleChunk chunk, @Nullable ProcessorConfigProfile profile, @NotNull JavaCompilingTool compilingTool) {
    List<String> cached = JAVAC_OPTIONS.get(context);
    if (cached == null) {
        loadCommonJavacOptions(context, compilingTool);
        cached = JAVAC_OPTIONS.get(context);
        assert cached != null : context;
    }
    List<String> options = new ArrayList<>();
    JpsModule module = chunk.representativeTarget().getModule();
    File baseDirectory = JpsModelSerializationDataService.getBaseDirectory(module);
    if (baseDirectory != null) {
        //this is a temporary workaround to allow passing per-module compiler options for Eclipse compiler in form
        // -properties $MODULE_DIR$/.settings/org.eclipse.jdt.core.prefs
        String stringToReplace = "$" + PathMacroUtil.MODULE_DIR_MACRO_NAME + "$";
        String moduleDirPath = FileUtil.toCanonicalPath(baseDirectory.getAbsolutePath());
        for (String s : cached) {
            options.add(StringUtil.replace(s, stringToReplace, moduleDirPath));
        }
    } else {
        options.addAll(cached);
    }
    addCompilationOptions(compilerSdkVersion, options, context, chunk, profile);
    return options;
}
Also used : JpsModule(org.jetbrains.jps.model.module.JpsModule) ContainerUtil.newArrayList(com.intellij.util.containers.ContainerUtil.newArrayList)

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