Search in sources :

Example 11 with JpsJavaCompilerConfiguration

use of org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration 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 12 with JpsJavaCompilerConfiguration

use of org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration in project android by JetBrains.

the class AndroidBuilderTest method testGeneratedSources.

public void testGeneratedSources() throws Exception {
    final MyExecutor executor = new MyExecutor("com.example.simple");
    final JpsModule module = setUpSimpleAndroidStructure(new String[] { "src", "gen" }, executor, null).getFirst();
    rebuildAll();
    checkBuildLog(executor, "expected_log");
    checkMakeUpToDate(executor);
    change(getProjectPath("gen/com/example/simple/R.java"), AndroidCommonUtils.AUTOGENERATED_JAVA_FILE_HEADER + "\n\n" + "package com.example.simple;\n" + "public class R {}");
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log_1");
    assertCompiled(JavaBuilder.BUILDER_NAME, "targets/java-production/module/android/copied_sources/com/example/simple/MyGeneratedClass.java");
    checkMakeUpToDate(executor);
    change(getProjectPath("gen/com/example/simple/R.java"));
    checkMakeUpToDate(executor);
    change(getProjectPath("gen/com/example/simple/MyGeneratedClass.java"));
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log_3");
    assertCompiled(JavaBuilder.BUILDER_NAME, "targets/java-production/module/android/copied_sources/com/example/simple/MyGeneratedClass.java");
    checkMakeUpToDate(executor);
    change(getProjectPath("gen/com/example/simple/MyGeneratedClass.java"), AndroidCommonUtils.AUTOGENERATED_JAVA_FILE_HEADER + "\n\n" + "package com.example.simple;\n" + "public class MyGeneratedClass {}");
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log_4");
    assertCompiled(JavaBuilder.BUILDER_NAME);
    checkMakeUpToDate(executor);
    change(getProjectPath("gen/com/example/simple/MyGeneratedClass.java"), "package com.example.simple;\n" + "public class MyGeneratedClass {}");
    change(getProjectPath("src/com/example/simple/MyActivity.java"), "package com.example.simple;\n" + "import android.app.Activity;\n" + "import android.os.Bundle;\n" + "public class MyActivity extends Activity {\n" + "    public void onCreate(Bundle savedInstanceState) {\n" + "        super.onCreate(savedInstanceState);\n" + "        new MyGeneratedClass();" + "    }\n" + "}\n");
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log_5");
    assertCompiled(JavaBuilder.BUILDER_NAME, "root/src/com/example/simple/MyActivity.java", "targets/java-production/module/android/copied_sources/com/example/simple/MyGeneratedClass.java");
    checkMakeUpToDate(executor);
    final JpsJavaCompilerConfiguration compilerConfig = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(myProject);
    final ProcessorConfigProfile profile = compilerConfig.getAnnotationProcessingProfile(module);
    profile.setEnabled(true);
    profile.setOutputRelativeToContentRoot(true);
    profile.setGeneratedSourcesDirectoryName("gen", false);
    final BuildResult result = makeAll();
    result.assertFailed();
    final List<BuildMessage> warnMessages = result.getMessages(BuildMessage.Kind.WARNING);
    boolean containsForciblyExcludedRootWarn = false;
    for (BuildMessage message : warnMessages) {
        if (message.getMessageText().endsWith("was forcibly excluded by the IDE, so custom generated files won't be compiled")) {
            containsForciblyExcludedRootWarn = true;
        }
    }
    assertTrue(containsForciblyExcludedRootWarn);
}
Also used : BuildMessage(org.jetbrains.jps.incremental.messages.BuildMessage) JpsModule(org.jetbrains.jps.model.module.JpsModule) JpsJavaCompilerConfiguration(org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration) BuildResult(org.jetbrains.jps.builders.BuildResult) ProcessorConfigProfile(org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile)

Example 13 with JpsJavaCompilerConfiguration

use of org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration in project intellij-plugins by JetBrains.

the class FlexResourceBuilder method build.

public void build(@NotNull final FlexResourceBuildTarget target, @NotNull final DirtyFilesHolder<BuildRootDescriptor, FlexResourceBuildTarget> holder, @NotNull final BuildOutputConsumer outputConsumer, @NotNull final CompileContext context) throws ProjectBuildException, IOException {
    final JpsJavaCompilerConfiguration configuration = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(target.getModule().getProject());
    final JpsCompilerExcludes excludes = configuration.getCompilerExcludes();
    try {
        holder.processDirtyFiles(new FileProcessor<BuildRootDescriptor, FlexResourceBuildTarget>() {

            public boolean apply(final FlexResourceBuildTarget target, final File file, final BuildRootDescriptor root) throws IOException {
                if (excludes.isExcluded(file))
                    return true;
                final String relativePath = FileUtil.toSystemIndependentName(FileUtil.getRelativePath(root.getRootFile(), file));
                if (target.isTests()) {
                    if (!FlexCommonUtils.isSourceFile(file.getName())) {
                        final String outputRootUrl = JpsJavaExtensionService.getInstance().getOutputUrl(target.getModule(), target.isTests());
                        if (outputRootUrl == null)
                            return true;
                        final String targetPath = JpsPathUtil.urlToPath(outputRootUrl) + '/' + relativePath;
                        context.processMessage(new ProgressMessage("Copying " + file.getPath()));
                        copyResource(context, file, Collections.singleton(targetPath), outputConsumer);
                    }
                } else {
                    final Collection<String> targetPaths = new ArrayList<>();
                    for (JpsFlexBuildConfiguration bc : target.getModule().getProperties().getBuildConfigurations()) {
                        if (bc.isSkipCompile() || !FlexCommonUtils.canHaveResourceFiles(bc.getNature()) || bc.getCompilerOptions().getResourceFilesMode() == JpsFlexCompilerOptions.ResourceFilesMode.None) {
                            continue;
                        }
                        final JpsFlexCompilerOptions.ResourceFilesMode mode = bc.getCompilerOptions().getResourceFilesMode();
                        if (mode == JpsFlexCompilerOptions.ResourceFilesMode.All && !FlexCommonUtils.isSourceFile(file.getName()) || mode == JpsFlexCompilerOptions.ResourceFilesMode.ResourcePatterns && configuration.isResourceFile(file, root.getRootFile())) {
                            final String outputFolder = PathUtilRt.getParentPath(bc.getActualOutputFilePath());
                            targetPaths.add(outputFolder + "/" + relativePath);
                        }
                    }
                    if (!targetPaths.isEmpty()) {
                        context.processMessage(new ProgressMessage("Copying " + file.getPath()));
                        copyResource(context, file, targetPaths, outputConsumer);
                    }
                }
                return true;
            }
        });
    } catch (Exception e) {
        throw new ProjectBuildException(e.getMessage(), e);
    }
}
Also used : ProjectBuildException(org.jetbrains.jps.incremental.ProjectBuildException) JpsJavaCompilerConfiguration(org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration) BuildRootDescriptor(org.jetbrains.jps.builders.BuildRootDescriptor) ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) IOException(java.io.IOException) FlexResourceBuildTarget(com.intellij.flex.build.FlexResourceBuildTarget) IOException(java.io.IOException) ProjectBuildException(org.jetbrains.jps.incremental.ProjectBuildException) JpsCompilerExcludes(org.jetbrains.jps.model.java.compiler.JpsCompilerExcludes) Collection(java.util.Collection) JpsFlexBuildConfiguration(com.intellij.flex.model.bc.JpsFlexBuildConfiguration) File(java.io.File)

Example 14 with JpsJavaCompilerConfiguration

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

the class IncProjectBuilder method cleanOutputRoots.

private void cleanOutputRoots(CompileContext context, boolean cleanCaches) throws ProjectBuildException {
    final ProjectDescriptor projectDescriptor = context.getProjectDescriptor();
    ProjectBuildException ex = null;
    try {
        final JpsJavaCompilerConfiguration configuration = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(projectDescriptor.getProject());
        final boolean shouldClear = configuration.isClearOutputDirectoryOnRebuild();
        if (shouldClear) {
            clearOutputs(context);
        } else {
            for (BuildTarget<?> target : projectDescriptor.getBuildTargetIndex().getAllTargets()) {
                context.checkCanceled();
                if (context.getScope().isBuildForced(target)) {
                    clearOutputFilesUninterruptibly(context, target);
                }
            }
        }
    } catch (ProjectBuildException e) {
        ex = e;
    } finally {
        if (cleanCaches) {
            try {
                projectDescriptor.timestamps.getStorage().clean();
            } catch (IOException e) {
                if (ex == null) {
                    ex = new ProjectBuildException("Error cleaning timestamps storage", e);
                } else {
                    LOG.info("Error cleaning timestamps storage", e);
                }
            } finally {
                try {
                    projectDescriptor.dataManager.clean();
                } catch (IOException e) {
                    if (ex == null) {
                        ex = new ProjectBuildException("Error cleaning compiler storages", e);
                    } else {
                        LOG.info("Error cleaning compiler storages", e);
                    }
                } finally {
                    projectDescriptor.fsState.clearAll();
                    if (ex != null) {
                        throw ex;
                    }
                }
            }
        }
    }
}
Also used : JpsJavaCompilerConfiguration(org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration) ProjectDescriptor(org.jetbrains.jps.cmdline.ProjectDescriptor) IOException(java.io.IOException)

Example 15 with JpsJavaCompilerConfiguration

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

the class ModuleBuildTarget method getOutputRoots.

@NotNull
@Override
public Collection<File> getOutputRoots(CompileContext context) {
    Collection<File> result = new SmartList<>();
    final File outputDir = getOutputDir();
    if (outputDir != null) {
        result.add(outputDir);
    }
    final JpsModule module = getModule();
    final JpsJavaCompilerConfiguration configuration = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(module.getProject());
    final ProcessorConfigProfile profile = configuration.getAnnotationProcessingProfile(module);
    if (profile.isEnabled()) {
        final File annotationOut = ProjectPaths.getAnnotationProcessorGeneratedSourcesOutputDir(module, isTests(), profile);
        if (annotationOut != null) {
            result.add(annotationOut);
        }
    }
    return result;
}
Also used : JpsModule(org.jetbrains.jps.model.module.JpsModule) JpsJavaCompilerConfiguration(org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration) ProcessorConfigProfile(org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile) SmartList(com.intellij.util.SmartList) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

JpsJavaCompilerConfiguration (org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration)24 File (java.io.File)9 ProcessorConfigProfile (org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile)6 IOException (java.io.IOException)5 JpsCompilerExcludes (org.jetbrains.jps.model.java.compiler.JpsCompilerExcludes)4 JpsModule (org.jetbrains.jps.model.module.JpsModule)4 NotNull (org.jetbrains.annotations.NotNull)3 JavaSourceRootDescriptor (org.jetbrains.jps.builders.java.JavaSourceRootDescriptor)3 JpsProject (org.jetbrains.jps.model.JpsProject)3 JpsJavaCompilerOptions (org.jetbrains.jps.model.java.compiler.JpsJavaCompilerOptions)3 JpsFlexBuildConfiguration (com.intellij.flex.model.bc.JpsFlexBuildConfiguration)2 Set (java.util.Set)2 Element (org.jdom.Element)2 ProgressMessage (org.jetbrains.jps.incremental.messages.ProgressMessage)2 JpsJavaExtensionService (org.jetbrains.jps.model.java.JpsJavaExtensionService)2 EclipseCompilerOptions (org.jetbrains.jps.model.java.compiler.EclipseCompilerOptions)2 RmicCompilerOptions (org.jetbrains.jps.model.java.compiler.RmicCompilerOptions)2 FlexResourceBuildTarget (com.intellij.flex.build.FlexResourceBuildTarget)1 SmartList (com.intellij.util.SmartList)1 THashMap (gnu.trove.THashMap)1