Search in sources :

Example 11 with JpsProject

use of org.jetbrains.jps.model.JpsProject in project intellij-elixir by KronicDeth.

the class MixBuilder method build.

@Override
public void build(@NotNull ElixirTarget target, @NotNull DirtyFilesHolder<ElixirSourceRootDescriptor, ElixirTarget> holder, @NotNull BuildOutputConsumer outputConsumer, @NotNull CompileContext context) throws ProjectBuildException, IOException {
    if (!holder.hasDirtyFiles() && !holder.hasRemovedFiles())
        return;
    JpsModule module = target.getModule();
    JpsProject project = module.getProject();
    ElixirCompilerOptions compilerOptions = JpsElixirCompilerOptionsExtension.getOrCreateExtension(project).getOptions();
    if (!compilerOptions.myUseMixCompiler)
        return;
    String mixPath = getMixExecutablePath(project);
    if (mixPath == null) {
        String errorMessage = "Mix path is not set.";
        context.processMessage(new CompilerMessage(NAME, BuildMessage.Kind.ERROR, errorMessage));
        throw new ProjectBuildException(errorMessage);
    }
    JpsSdk<JpsDummyElement> sdk = ElixirTargetBuilderUtil.getSdk(context, module);
    String elixirPath = JpsElixirSdkType.getScriptInterpreterExecutable(sdk.getHomePath()).getAbsolutePath();
    for (String contentRootUrl : module.getContentRootsList().getUrls()) {
        String contentRootPath = new URL(contentRootUrl).getPath();
        File contentRootDir = new File(contentRootPath);
        File mixConfigFile = new File(contentRootDir, MIX_CONFIG_FILE_NAME);
        if (!mixConfigFile.exists())
            continue;
        runMix(elixirPath, mixPath, contentRootPath, compilerOptions.myAttachDebugInfoEnabled, context);
    }
}
Also used : ProjectBuildException(org.jetbrains.jps.incremental.ProjectBuildException) JpsModule(org.jetbrains.jps.model.module.JpsModule) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) JpsProject(org.jetbrains.jps.model.JpsProject) JpsDummyElement(org.jetbrains.jps.model.JpsDummyElement) ElixirCompilerOptions(org.elixir_lang.jps.model.ElixirCompilerOptions) File(java.io.File) URL(java.net.URL)

Example 12 with JpsProject

use of org.jetbrains.jps.model.JpsProject in project intellij-elixir by KronicDeth.

the class Builder method build.

@Override
public void build(@NotNull Target target, @NotNull DirtyFilesHolder<SourceRootDescriptor, Target> holder, @NotNull BuildOutputConsumer outputConsumer, @NotNull CompileContext context) throws ProjectBuildException, IOException {
    LOGGER.info(target.getPresentableName());
    final Set<File> filesToCompile = new THashSet<>(FileUtil.FILE_HASHING_STRATEGY);
    holder.processDirtyFiles((target1, file, root) -> {
        boolean isAcceptFile = target1.isTests() ? ELIXIR_TEST_SOURCE_FILTER.accept(file) : ELIXIR_SOURCE_FILTER.accept(file);
        if (isAcceptFile && ourCompilableModuleTypes.contains(target1.getModule().getModuleType())) {
            filesToCompile.add(file);
        }
        return true;
    });
    if (filesToCompile.isEmpty() && !holder.hasRemovedFiles())
        return;
    JpsModule module = target.getModule();
    JpsProject project = module.getProject();
    CompilerOptions compilerOptions = Extension.getOrCreateExtension(project).getOptions();
    if (compilerOptions.useMixCompiler) {
        doBuildWithMix(target, context, module, compilerOptions);
    } else {
        // elixirc can not compile tests now.
        if (!target.isTests()) {
            doBuildWithElixirc(target, context, module, compilerOptions, filesToCompile);
        }
    }
}
Also used : JpsProject(org.jetbrains.jps.model.JpsProject) File(java.io.File) THashSet(gnu.trove.THashSet)

Example 13 with JpsProject

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

the class AndroidGradleTargetBuilder method build.

/**
   * Builds a Gradle-based Android project using Gradle.
   */
@Override
public void build(@NotNull AndroidGradleBuildTarget target, @NotNull DirtyFilesHolder<AndroidGradleBuildTarget.RootDescriptor, AndroidGradleBuildTarget> holder, @NotNull BuildOutputConsumer outputConsumer, @NotNull CompileContext context) throws ProjectBuildException, IOException {
    JpsProject project = target.getProject();
    checkUnsupportedModules(project, context);
    BuilderExecutionSettings executionSettings;
    try {
        executionSettings = new BuilderExecutionSettings();
    } catch (RuntimeException e) {
        throw new ProjectBuildException(e);
    }
    LOG.info("Using execution settings: " + executionSettings);
    List<String> buildTasks = executionSettings.getGradleTasksToInvoke();
    if (buildTasks.isEmpty()) {
        String format = "No build tasks found for project '%1$s'. Nothing done.";
        LOG.info(String.format(format, project.getName()));
        return;
    }
    context.processMessage(AndroidGradleJps.createCompilerMessage(BuildMessage.Kind.INFO, "Executing tasks: " + buildTasks));
    String msg = "Gradle build using tasks: " + buildTasks;
    context.processMessage(new ProgressMessage(msg));
    LOG.info(msg);
    ensureTempDirExists();
    String androidHome = null;
    if (!AndroidGradleSettings.isAndroidSdkDirInLocalPropertiesFile(executionSettings.getProjectDir())) {
        androidHome = getAndroidHomeFromModuleSdk(project);
    }
    String format = "About to build project '%1$s' located at %2$s";
    LOG.info(String.format(format, project.getName(), executionSettings.getProjectDir().getAbsolutePath()));
    doBuild(context, buildTasks, executionSettings, androidHome);
}
Also used : ProjectBuildException(org.jetbrains.jps.incremental.ProjectBuildException) ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) JpsProject(org.jetbrains.jps.model.JpsProject)

Example 14 with JpsProject

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

the class JavaBuilder method getUsedCompilerId.

@NotNull
public static String getUsedCompilerId(CompileContext context) {
    final JpsProject project = context.getProjectDescriptor().getProject();
    final JpsJavaCompilerConfiguration config = JpsJavaExtensionService.getInstance().getCompilerConfiguration(project);
    return config == null ? JavaCompilers.JAVAC_ID : config.getJavaCompilerId();
}
Also used : JpsProject(org.jetbrains.jps.model.JpsProject) NotNull(org.jetbrains.annotations.NotNull)

Example 15 with JpsProject

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

the class FormsBindingManager method build.

@Override
public ExitCode build(CompileContext context, ModuleChunk chunk, DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget> dirtyFilesHolder, OutputConsumer outputConsumer) throws ProjectBuildException, IOException {
    ExitCode exitCode = ExitCode.NOTHING_DONE;
    final JpsProject project = context.getProjectDescriptor().getProject();
    final JpsUiDesignerConfiguration config = JpsUiDesignerExtensionService.getInstance().getOrCreateUiDesignerConfiguration(project);
    if (!config.isInstrumentClasses() && !config.isCopyFormsRuntimeToOutput()) {
        return exitCode;
    }
    final Map<File, ModuleBuildTarget> filesToCompile = new THashMap<>(FileUtil.FILE_HASHING_STRATEGY);
    final Map<File, ModuleBuildTarget> formsToCompile = new THashMap<>(FileUtil.FILE_HASHING_STRATEGY);
    final Map<File, Collection<File>> srcToForms = new THashMap<>(FileUtil.FILE_HASHING_STRATEGY);
    if (!JavaBuilderUtil.isForcedRecompilationAllJavaModules(context) && config.isInstrumentClasses() && FORCE_FORMS_REBUILD_FLAG.get(context, Boolean.FALSE)) {
        // force compilation of all forms, but only once per chunk
        if (!FORMS_REBUILD_FORCED.get(context, Boolean.FALSE)) {
            FORMS_REBUILD_FORCED.set(context, Boolean.TRUE);
            FSOperations.markDirty(context, CompilationRound.CURRENT, chunk, FORM_SOURCES_FILTER);
        }
    }
    dirtyFilesHolder.processDirtyFiles(new FileProcessor<JavaSourceRootDescriptor, ModuleBuildTarget>() {

        public boolean apply(ModuleBuildTarget target, File file, JavaSourceRootDescriptor descriptor) throws IOException {
            if (JAVA_SOURCES_FILTER.accept(file)) {
                filesToCompile.put(file, target);
            } else if (FORM_SOURCES_FILTER.accept(file)) {
                formsToCompile.put(file, target);
            }
            return true;
        }
    });
    if (config.isInstrumentClasses()) {
        final JpsJavaCompilerConfiguration configuration = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(project);
        final JpsCompilerExcludes excludes = configuration.getCompilerExcludes();
        // force compilation of bound source file if the form is dirty
        for (final Map.Entry<File, ModuleBuildTarget> entry : formsToCompile.entrySet()) {
            final File form = entry.getKey();
            final ModuleBuildTarget target = entry.getValue();
            final Collection<File> sources = findBoundSourceCandidates(context, target, form);
            for (File boundSource : sources) {
                if (!excludes.isExcluded(boundSource)) {
                    addBinding(boundSource, form, srcToForms);
                    FSOperations.markDirty(context, CompilationRound.CURRENT, boundSource);
                    filesToCompile.put(boundSource, target);
                    exitCode = ExitCode.OK;
                }
            }
        }
        // form should be considered dirty if the class it is bound to is dirty
        final OneToManyPathsMapping sourceToFormMap = context.getProjectDescriptor().dataManager.getSourceToFormMap();
        for (Map.Entry<File, ModuleBuildTarget> entry : filesToCompile.entrySet()) {
            final File srcFile = entry.getKey();
            final ModuleBuildTarget target = entry.getValue();
            final Collection<String> boundForms = sourceToFormMap.getState(srcFile.getPath());
            if (boundForms != null) {
                for (String formPath : boundForms) {
                    final File formFile = new File(formPath);
                    if (!excludes.isExcluded(formFile) && formFile.exists()) {
                        addBinding(srcFile, formFile, srcToForms);
                        FSOperations.markDirty(context, CompilationRound.CURRENT, formFile);
                        formsToCompile.put(formFile, target);
                        exitCode = ExitCode.OK;
                    }
                }
            }
        }
    }
    FORMS_TO_COMPILE.set(context, srcToForms.isEmpty() ? null : srcToForms);
    if (config.isCopyFormsRuntimeToOutput() && containsValidForm(formsToCompile.keySet())) {
        for (ModuleBuildTarget target : chunk.getTargets()) {
            if (!target.isTests()) {
                final File outputDir = target.getOutputDir();
                if (outputDir != null) {
                    final String outputRoot = FileUtil.toSystemIndependentName(outputDir.getPath());
                    final List<File> generatedFiles = CopyResourcesUtil.copyFormsRuntime(outputRoot, false);
                    if (!generatedFiles.isEmpty()) {
                        exitCode = ExitCode.OK;
                        // now inform others about files just copied
                        for (File file : generatedFiles) {
                            outputConsumer.registerOutputFile(target, file, Collections.<String>emptyList());
                        }
                    }
                }
            }
        }
    }
    return exitCode;
}
Also used : JpsJavaCompilerConfiguration(org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration) OneToManyPathsMapping(org.jetbrains.jps.incremental.storage.OneToManyPathsMapping) IOException(java.io.IOException) JpsCompilerExcludes(org.jetbrains.jps.model.java.compiler.JpsCompilerExcludes) THashMap(gnu.trove.THashMap) JpsUiDesignerConfiguration(org.jetbrains.jps.uiDesigner.model.JpsUiDesignerConfiguration) JpsProject(org.jetbrains.jps.model.JpsProject) JavaSourceRootDescriptor(org.jetbrains.jps.builders.java.JavaSourceRootDescriptor) File(java.io.File) THashMap(gnu.trove.THashMap)

Aggregations

JpsProject (org.jetbrains.jps.model.JpsProject)17 File (java.io.File)8 IOException (java.io.IOException)4 NotNull (org.jetbrains.annotations.NotNull)4 ProgressMessage (org.jetbrains.jps.incremental.messages.ProgressMessage)4 JpsModule (org.jetbrains.jps.model.module.JpsModule)4 THashSet (gnu.trove.THashSet)3 CompilerMessage (org.jetbrains.jps.incremental.messages.CompilerMessage)3 JpsJavaExtensionService (org.jetbrains.jps.model.java.JpsJavaExtensionService)3 JpsCompilerExcludes (org.jetbrains.jps.model.java.compiler.JpsCompilerExcludes)3 JpsJavaCompilerConfiguration (org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration)3 THashMap (gnu.trove.THashMap)2 FileFilter (java.io.FileFilter)2 ArrayList (java.util.ArrayList)2 Set (java.util.Set)2 ElixirCompilerOptions (org.elixir_lang.jps.model.ElixirCompilerOptions)2 ProjectBuildException (org.jetbrains.jps.incremental.ProjectBuildException)2 ResourcesTarget (org.jetbrains.jps.incremental.ResourcesTarget)2 OneToManyPathsMapping (org.jetbrains.jps.incremental.storage.OneToManyPathsMapping)2 JpsDummyElement (org.jetbrains.jps.model.JpsDummyElement)2