Search in sources :

Example 11 with ProgressMessage

use of org.jetbrains.jps.incremental.messages.ProgressMessage in project android by JetBrains.

the class AndroidGradleTargetBuilder method doBuild.

private static void doBuild(@NotNull CompileContext context, @NotNull List<String> buildTasks, @NotNull BuilderExecutionSettings executionSettings, @Nullable String androidHome) throws ProjectBuildException {
    GradleConnector connector = getGradleConnector(executionSettings);
    ProjectConnection connection = connector.connect();
    ByteArrayOutputStream stdout = new ByteArrayOutputStream(BUFFER_SIZE);
    ByteArrayOutputStream stderr = new ByteArrayOutputStream(BUFFER_SIZE);
    try {
        BuildLauncher launcher = connection.newBuild();
        launcher.forTasks(toStringArray(buildTasks));
        List<String> jvmArgs = Lists.newArrayList();
        BuildMode buildMode = executionSettings.getBuildMode();
        if (BuildMode.ASSEMBLE_TRANSLATE == buildMode) {
            String arg = AndroidGradleSettings.createJvmArg(GradleBuilds.ENABLE_TRANSLATION_JVM_ARG, true);
            jvmArgs.add(arg);
        }
        if (androidHome != null && !androidHome.isEmpty()) {
            String androidSdkArg = AndroidGradleSettings.createAndroidHomeJvmArg(androidHome);
            jvmArgs.add(androidSdkArg);
        }
        jvmArgs.addAll(executionSettings.getJvmOptions());
        LOG.info("Build JVM args: " + jvmArgs);
        if (!jvmArgs.isEmpty()) {
            launcher.setJvmArguments(toStringArray(jvmArgs));
        }
        List<String> commandLineArgs = Lists.newArrayList();
        commandLineArgs.addAll(executionSettings.getCommandLineOptions());
        commandLineArgs.add(AndroidGradleSettings.createProjectProperty(AndroidProject.PROPERTY_INVOKED_FROM_IDE, true));
        if (executionSettings.isParallelBuild() && !commandLineArgs.contains(PARALLEL_BUILD_OPTION)) {
            commandLineArgs.add(PARALLEL_BUILD_OPTION);
        }
        if (executionSettings.isOfflineBuild() && !commandLineArgs.contains(OFFLINE_MODE_OPTION)) {
            commandLineArgs.add(OFFLINE_MODE_OPTION);
        }
        if (executionSettings.isConfigureOnDemand() && !commandLineArgs.contains(CONFIGURE_ON_DEMAND_OPTION)) {
            commandLineArgs.add(CONFIGURE_ON_DEMAND_OPTION);
        }
        LOG.info("Build command line args: " + commandLineArgs);
        if (!commandLineArgs.isEmpty()) {
            launcher.withArguments(toStringArray(commandLineArgs));
        }
        File javaHomeDir = executionSettings.getJavaHomeDir();
        if (javaHomeDir != null) {
            launcher.setJavaHome(javaHomeDir);
        }
        launcher.setStandardOutput(stdout);
        launcher.setStandardError(stderr);
        launcher.run();
    } catch (BuildException e) {
        handleBuildException(e, context, stderr.toString());
    } finally {
        String outText = stdout.toString();
        context.processMessage(new ProgressMessage(outText, 1.0f));
        try {
            Closeables.close(stdout, true);
            Closeables.close(stderr, true);
        } catch (IOException e) {
            LOG.debug(e);
        }
        connection.close();
    }
}
Also used : ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) BuildLauncher(org.gradle.tooling.BuildLauncher) ProjectConnection(org.gradle.tooling.ProjectConnection) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ProjectBuildException(org.jetbrains.jps.incremental.ProjectBuildException) BuildException(org.gradle.tooling.BuildException) IOException(java.io.IOException) BuildMode(com.android.tools.idea.gradle.util.BuildMode) File(java.io.File) GradleConnector(org.gradle.tooling.GradleConnector) DefaultGradleConnector(org.gradle.tooling.internal.consumer.DefaultGradleConnector)

Example 12 with ProgressMessage

use of org.jetbrains.jps.incremental.messages.ProgressMessage 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 13 with ProgressMessage

use of org.jetbrains.jps.incremental.messages.ProgressMessage in project intellij-community by JetBrains.

the class GradleResourcesBuilder method build.

@Override
public void build(@NotNull final GradleResourcesTarget target, @NotNull final DirtyFilesHolder<GradleResourceRootDescriptor, GradleResourcesTarget> holder, @NotNull final BuildOutputConsumer outputConsumer, @NotNull final CompileContext context) throws ProjectBuildException, IOException {
    if (!JavaBuilder.IS_ENABLED.get(context, Boolean.TRUE)) {
        return;
    }
    final BuildDataPaths dataPaths = context.getProjectDescriptor().dataManager.getDataPaths();
    final GradleProjectConfiguration projectConfig = JpsGradleExtensionService.getInstance().getGradleProjectConfiguration(dataPaths);
    final GradleModuleResourceConfiguration config = target.getModuleResourcesConfiguration(dataPaths);
    if (config == null)
        return;
    final Map<GradleResourceRootDescriptor, List<File>> files = new HashMap<>();
    holder.processDirtyFiles(new FileProcessor<GradleResourceRootDescriptor, GradleResourcesTarget>() {

        @Override
        public boolean apply(GradleResourcesTarget t, File file, GradleResourceRootDescriptor rd) throws IOException {
            assert target == t;
            List<File> fileList = files.get(rd);
            if (fileList == null) {
                fileList = new ArrayList<>();
                files.put(rd, fileList);
            }
            fileList.add(file);
            return true;
        }
    });
    GradleResourceRootDescriptor[] roots = files.keySet().toArray(new GradleResourceRootDescriptor[files.keySet().size()]);
    Arrays.sort(roots, (r1, r2) -> {
        int res = r1.getIndexInPom() - r2.getIndexInPom();
        if (r1.isOverwrite()) {
            assert r2.isOverwrite();
            return res;
        }
        if (r1.getConfiguration().isFiltered && !r2.getConfiguration().isFiltered)
            return 1;
        if (!r1.getConfiguration().isFiltered && r2.getConfiguration().isFiltered)
            return -1;
        if (!r1.getConfiguration().isFiltered) {
            res = -res;
        }
        return res;
    });
    GradleResourceFileProcessor fileProcessor = new GradleResourceFileProcessor(projectConfig, target.getModule().getProject(), config);
    for (GradleResourceRootDescriptor rd : roots) {
        for (File file : files.get(rd)) {
            String relPath = FileUtil.getRelativePath(rd.getRootFile(), file);
            if (relPath == null)
                continue;
            final File outputDir = GradleResourcesTarget.getOutputDir(target.getModuleOutputDir(), rd.getConfiguration(), config.outputDirectory);
            if (outputDir == null)
                continue;
            context.processMessage(new ProgressMessage("Copying resources... [" + target.getModule().getName() + "]"));
            final Ref<File> fileRef = Ref.create(new File(outputDir, relPath));
            fileProcessor.copyFile(file, fileRef, rd.getConfiguration(), context, FileUtilRt.ALL_FILES);
            outputConsumer.registerOutputFile(fileRef.get(), Collections.singleton(file.getPath()));
            if (context.getCancelStatus().isCanceled())
                return;
        }
    }
    context.checkCanceled();
    context.processMessage(new ProgressMessage(""));
}
Also used : ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) IOException(java.io.IOException) BuildDataPaths(org.jetbrains.jps.builders.storage.BuildDataPaths) File(java.io.File)

Example 14 with ProgressMessage

use of org.jetbrains.jps.incremental.messages.ProgressMessage 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 15 with ProgressMessage

use of org.jetbrains.jps.incremental.messages.ProgressMessage in project intellij-community by JetBrains.

the class JavaBuilder method compile.

private ExitCode compile(CompileContext context, ModuleChunk chunk, DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget> dirtyFilesHolder, Collection<File> files, OutputConsumer outputConsumer, JavaCompilingTool compilingTool) throws Exception {
    ExitCode exitCode = ExitCode.NOTHING_DONE;
    final boolean hasSourcesToCompile = !files.isEmpty();
    if (!hasSourcesToCompile && !dirtyFilesHolder.hasRemovedFiles()) {
        return exitCode;
    }
    final ProjectDescriptor pd = context.getProjectDescriptor();
    JavaBuilderUtil.ensureModuleHasJdk(chunk.representativeTarget().getModule(), context, BUILDER_NAME);
    final Collection<File> classpath = ProjectPaths.getCompilationClasspath(chunk, false);
    final Collection<File> platformCp = ProjectPaths.getPlatformCompilationClasspath(chunk, false);
    // begin compilation round
    final OutputFilesSink outputSink = new OutputFilesSink(context, outputConsumer, JavaBuilderUtil.getDependenciesRegistrar(context), chunk.getPresentableShortName());
    Collection<File> filesWithErrors = null;
    try {
        if (hasSourcesToCompile) {
            exitCode = ExitCode.OK;
            final Set<File> srcPath = new HashSet<>();
            final BuildRootIndex index = pd.getBuildRootIndex();
            for (ModuleBuildTarget target : chunk.getTargets()) {
                for (JavaSourceRootDescriptor rd : index.getTempTargetRoots(target, context)) {
                    srcPath.add(rd.root);
                }
            }
            final DiagnosticSink diagnosticSink = new DiagnosticSink(context);
            final String chunkName = chunk.getName();
            context.processMessage(new ProgressMessage("Parsing java... [" + chunk.getPresentableShortName() + "]"));
            final int filesCount = files.size();
            boolean compiledOk = true;
            if (filesCount > 0) {
                LOG.info("Compiling " + filesCount + " java files; module: " + chunkName + (chunk.containsTests() ? " (tests)" : ""));
                if (LOG.isDebugEnabled()) {
                    for (File file : files) {
                        LOG.debug("Compiling " + file.getPath());
                    }
                    LOG.debug(" classpath for " + chunkName + ":");
                    for (File file : classpath) {
                        LOG.debug("  " + file.getAbsolutePath());
                    }
                    LOG.debug(" platform classpath for " + chunkName + ":");
                    for (File file : platformCp) {
                        LOG.debug("  " + file.getAbsolutePath());
                    }
                }
                try {
                    compiledOk = compileJava(context, chunk, files, classpath, platformCp, srcPath, diagnosticSink, outputSink, compilingTool);
                } finally {
                    // heuristic: incorrect paths data recovery, so that the next make should not contain non-existing sources in 'recompile' list
                    filesWithErrors = diagnosticSink.getFilesWithErrors();
                    for (File file : filesWithErrors) {
                        if (!file.exists()) {
                            FSOperations.markDeleted(context, file);
                        }
                    }
                }
            }
            context.checkCanceled();
            if (!compiledOk && diagnosticSink.getErrorCount() == 0) {
                diagnosticSink.report(new PlainMessageDiagnostic(Diagnostic.Kind.ERROR, "Compilation failed: internal java compiler error"));
            }
            if (!Utils.PROCEED_ON_ERROR_KEY.get(context, Boolean.FALSE) && diagnosticSink.getErrorCount() > 0) {
                if (!compiledOk) {
                    diagnosticSink.report(new JpsInfoDiagnostic("Errors occurred while compiling module '" + chunkName + "'"));
                }
                throw new StopBuildException("Compilation failed: errors: " + diagnosticSink.getErrorCount() + "; warnings: " + diagnosticSink.getWarningCount());
            }
        }
    } finally {
        JavaBuilderUtil.registerFilesToCompile(context, files);
        if (filesWithErrors != null) {
            JavaBuilderUtil.registerFilesWithErrors(context, filesWithErrors);
        }
        JavaBuilderUtil.registerSuccessfullyCompiled(context, outputSink.getSuccessfullyCompiled());
    }
    return exitCode;
}
Also used : ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) BuildRootIndex(org.jetbrains.jps.builders.BuildRootIndex) ProjectDescriptor(org.jetbrains.jps.cmdline.ProjectDescriptor) JavaSourceRootDescriptor(org.jetbrains.jps.builders.java.JavaSourceRootDescriptor) THashSet(gnu.trove.THashSet)

Aggregations

ProgressMessage (org.jetbrains.jps.incremental.messages.ProgressMessage)32 File (java.io.File)20 CompilerMessage (org.jetbrains.jps.incremental.messages.CompilerMessage)17 IOException (java.io.IOException)14 JpsModule (org.jetbrains.jps.model.module.JpsModule)10 THashSet (gnu.trove.THashSet)8 JpsAndroidModuleExtension (org.jetbrains.jps.android.model.JpsAndroidModuleExtension)7 ProjectBuildException (org.jetbrains.jps.incremental.ProjectBuildException)5 IAndroidTarget (com.android.sdklib.IAndroidTarget)4 HashMap (com.intellij.util.containers.HashMap)4 TObjectLongHashMap (gnu.trove.TObjectLongHashMap)4 ArrayList (java.util.ArrayList)4 ProjectBuilderLogger (org.jetbrains.jps.builders.logging.ProjectBuilderLogger)4 Pair (com.intellij.openapi.util.Pair)3 HashSet (com.intellij.util.containers.HashSet)3 AndroidBuildTestingManager (org.jetbrains.android.util.AndroidBuildTestingManager)3 BuildRootDescriptor (org.jetbrains.jps.builders.BuildRootDescriptor)3 JavaSourceRootDescriptor (org.jetbrains.jps.builders.java.JavaSourceRootDescriptor)3 BuildDataCorruptedException (org.jetbrains.jps.builders.storage.BuildDataCorruptedException)3 JpsProject (org.jetbrains.jps.model.JpsProject)3