Search in sources :

Example 1 with RmicCompilerOptions

use of org.jetbrains.jps.model.java.compiler.RmicCompilerOptions in project intellij-community by JetBrains.

the class RmicCompilerOptionsSerializer method loadExtensionWithDefaultSettings.

@Override
public void loadExtensionWithDefaultSettings(@NotNull JpsProject project) {
    JpsJavaCompilerConfiguration configuration = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(project);
    configuration.setCompilerOptions(myCompilerId, new RmicCompilerOptions());
}
Also used : JpsJavaCompilerConfiguration(org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration) RmicCompilerOptions(org.jetbrains.jps.model.java.compiler.RmicCompilerOptions)

Example 2 with RmicCompilerOptions

use of org.jetbrains.jps.model.java.compiler.RmicCompilerOptions in project intellij-community by JetBrains.

the class RmiStubsGenerator method generateRmiStubs.

private ExitCode generateRmiStubs(final CompileContext context, Map<ModuleBuildTarget, Collection<ClassItem>> remoteClasses, ModuleChunk chunk, OutputConsumer outputConsumer) {
    ExitCode exitCode = ExitCode.NOTHING_DONE;
    final Collection<File> classpath = ProjectPaths.getCompilationClasspath(chunk, false);
    final StringBuilder buf = new StringBuilder();
    for (File file : classpath) {
        if (buf.length() > 0) {
            buf.append(File.pathSeparator);
        }
        buf.append(file.getPath());
    }
    final String classpathString = buf.toString();
    final String rmicPath = getPathToRmic(chunk);
    final RmicCompilerOptions options = getOptions(context);
    final List<ModuleBuildTarget> targetsProcessed = new ArrayList<>(remoteClasses.size());
    for (Map.Entry<ModuleBuildTarget, Collection<ClassItem>> entry : remoteClasses.entrySet()) {
        try {
            final ModuleBuildTarget target = entry.getKey();
            final Collection<String> cmdLine = createStartupCommand(target, rmicPath, classpathString, options, entry.getValue());
            final Process process = Runtime.getRuntime().exec(ArrayUtil.toStringArray(cmdLine));
            final BaseOSProcessHandler handler = new BaseOSProcessHandler(process, StringUtil.join(cmdLine, " "), null) {

                @NotNull
                @Override
                protected Future<?> executeOnPooledThread(@NotNull Runnable task) {
                    return SharedThreadPool.getInstance().executeOnPooledThread(task);
                }
            };
            final RmicOutputParser stdOutParser = new RmicOutputParser(context, getPresentableName());
            final RmicOutputParser stdErrParser = new RmicOutputParser(context, getPresentableName());
            handler.addProcessListener(new ProcessAdapter() {

                @Override
                public void onTextAvailable(ProcessEvent event, Key outputType) {
                    if (outputType == ProcessOutputTypes.STDOUT) {
                        stdOutParser.append(event.getText());
                    } else if (outputType == ProcessOutputTypes.STDERR) {
                        stdErrParser.append(event.getText());
                    }
                }

                @Override
                public void processTerminated(ProcessEvent event) {
                    super.processTerminated(event);
                }
            });
            handler.startNotify();
            handler.waitFor();
            targetsProcessed.add(target);
            if (stdErrParser.isErrorsReported() || stdOutParser.isErrorsReported()) {
                break;
            } else {
                final int exitValue = handler.getProcess().exitValue();
                if (exitValue != 0) {
                    context.processMessage(new CompilerMessage(getPresentableName(), BuildMessage.Kind.ERROR, "RMI stub generation failed"));
                    break;
                }
            }
        } catch (IOException e) {
            context.processMessage(new CompilerMessage(getPresentableName(), e));
            break;
        }
    }
    // registering generated files
    final Map<File, File[]> fsCache = new THashMap<>(FileUtil.FILE_HASHING_STRATEGY);
    for (ModuleBuildTarget target : targetsProcessed) {
        final Collection<ClassItem> items = remoteClasses.get(target);
        for (ClassItem item : items) {
            File[] children = fsCache.get(item.parentDir);
            if (children == null) {
                children = item.parentDir.listFiles();
                if (children == null) {
                    children = EMPTY_FILE_ARRAY;
                }
                fsCache.put(item.parentDir, children);
            }
            final Collection<File> files = item.selectGeneratedFiles(children);
            if (!files.isEmpty()) {
                final Collection<String> sources = item.compiledClass.getSourceFilesPaths();
                for (File generated : files) {
                    try {
                        outputConsumer.registerOutputFile(target, generated, sources);
                    } catch (IOException e) {
                        context.processMessage(new CompilerMessage(getPresentableName(), e));
                    }
                }
            }
        }
    }
    return exitCode;
}
Also used : CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) NotNull(org.jetbrains.annotations.NotNull) THashMap(gnu.trove.THashMap) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) RmicCompilerOptions(org.jetbrains.jps.model.java.compiler.RmicCompilerOptions) IOException(java.io.IOException) BaseOSProcessHandler(com.intellij.execution.process.BaseOSProcessHandler) File(java.io.File) THashMap(gnu.trove.THashMap) Key(com.intellij.openapi.util.Key)

Example 3 with RmicCompilerOptions

use of org.jetbrains.jps.model.java.compiler.RmicCompilerOptions in project intellij-community by JetBrains.

the class RmiStubsGenerator method buildStarted.

@Override
public void buildStarted(CompileContext context) {
    super.buildStarted(context);
    final RmicCompilerOptions rmicOptions = getOptions(context);
    IS_ENABLED.set(context, rmicOptions != null && rmicOptions.IS_EANABLED);
}
Also used : RmicCompilerOptions(org.jetbrains.jps.model.java.compiler.RmicCompilerOptions)

Example 4 with RmicCompilerOptions

use of org.jetbrains.jps.model.java.compiler.RmicCompilerOptions in project intellij-community by JetBrains.

the class RmicCompilerOptionsSerializer method loadExtension.

@Override
public void loadExtension(@NotNull JpsProject project, @NotNull Element componentTag) {
    JpsJavaCompilerConfiguration configuration = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(project);
    RmicCompilerOptions options = XmlSerializer.deserialize(componentTag, RmicCompilerOptions.class);
    configuration.setCompilerOptions(myCompilerId, options);
}
Also used : JpsJavaCompilerConfiguration(org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration) RmicCompilerOptions(org.jetbrains.jps.model.java.compiler.RmicCompilerOptions)

Aggregations

RmicCompilerOptions (org.jetbrains.jps.model.java.compiler.RmicCompilerOptions)4 JpsJavaCompilerConfiguration (org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration)2 BaseOSProcessHandler (com.intellij.execution.process.BaseOSProcessHandler)1 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)1 ProcessEvent (com.intellij.execution.process.ProcessEvent)1 Key (com.intellij.openapi.util.Key)1 THashMap (gnu.trove.THashMap)1 File (java.io.File)1 IOException (java.io.IOException)1 NotNull (org.jetbrains.annotations.NotNull)1 CompilerMessage (org.jetbrains.jps.incremental.messages.CompilerMessage)1