Search in sources :

Example 1 with CompileContext

use of com.intellij.openapi.compiler.CompileContext in project intellij-community by JetBrains.

the class MavenTasksManager method initComponent.

@Override
public void initComponent() {
    if (!isNormalProject())
        return;
    if (isInitialized.getAndSet(true))
        return;
    CompilerManager compilerManager = CompilerManager.getInstance(myProject);
    class MyCompileTask implements CompileTask {

        private final boolean myBefore;

        MyCompileTask(boolean before) {
            myBefore = before;
        }

        @Override
        public boolean execute(CompileContext context) {
            return doExecute(myBefore, context);
        }
    }
    compilerManager.addBeforeTask(new MyCompileTask(true));
    compilerManager.addAfterTask(new MyCompileTask(false));
}
Also used : CompileTask(com.intellij.openapi.compiler.CompileTask) CompilerManager(com.intellij.openapi.compiler.CompilerManager) CompileContext(com.intellij.openapi.compiler.CompileContext)

Example 2 with CompileContext

use of com.intellij.openapi.compiler.CompileContext in project intellij-community by JetBrains.

the class MavenProjectsManager method initComponent.

@Override
public void initComponent() {
    if (!isNormalProject())
        return;
    StartupManagerEx startupManager = StartupManagerEx.getInstanceEx(myProject);
    startupManager.registerStartupActivity(() -> {
        boolean wasMavenized = !myState.originalFiles.isEmpty();
        if (!wasMavenized)
            return;
        initMavenized();
    });
    startupManager.registerPostStartupActivity(() -> {
        if (!isMavenizedProject()) {
            showNotificationOrphanMavenProject(myProject);
        }
        CompilerManager.getInstance(myProject).addBeforeTask(new CompileTask() {

            @Override
            public boolean execute(CompileContext context) {
                AccessToken token = ReadAction.start();
                try {
                    new MavenResourceCompilerConfigurationGenerator(myProject, myProjectsTree).generateBuildConfiguration(context.isRebuild());
                } finally {
                    token.finish();
                }
                return true;
            }
        });
    });
}
Also used : CompileTask(com.intellij.openapi.compiler.CompileTask) StartupManagerEx(com.intellij.ide.startup.StartupManagerEx) AccessToken(com.intellij.openapi.application.AccessToken) CompileContext(com.intellij.openapi.compiler.CompileContext)

Example 3 with CompileContext

use of com.intellij.openapi.compiler.CompileContext in project intellij-community by JetBrains.

the class PreviewFormAction method showPreviewFrame.

private static void showPreviewFrame(@NotNull final Module module, @NotNull final VirtualFile formFile, @Nullable final Locale stringDescriptorLocale) {
    final String tempPath;
    try {
        final File tempDirectory = FileUtil.createTempDirectory("FormPreview", "");
        tempPath = tempDirectory.getAbsolutePath();
        CopyResourcesUtil.copyFormsRuntime(tempPath, true);
    } catch (IOException e) {
        Messages.showErrorDialog(module.getProject(), UIDesignerBundle.message("error.cannot.preview.form", formFile.getPath().replace('/', File.separatorChar), e.toString()), CommonBundle.getErrorTitle());
        return;
    }
    final PathsList sources = OrderEnumerator.orderEntries(module).withoutSdk().withoutLibraries().withoutDepModules().getSourcePathsList();
    final String classPath = OrderEnumerator.orderEntries(module).recursively().getPathsList().getPathsString() + File.pathSeparator + sources.getPathsString() + File.pathSeparator + /* resources bundles */
    tempPath;
    final InstrumentationClassFinder finder = createClassFinder(classPath);
    try {
        final Document doc = FileDocumentManager.getInstance().getDocument(formFile);
        final LwRootContainer rootContainer;
        try {
            rootContainer = Utils.getRootContainer(doc.getText(), new CompiledClassPropertiesProvider(finder.getLoader()));
        } catch (Exception e) {
            Messages.showErrorDialog(module.getProject(), UIDesignerBundle.message("error.cannot.read.form", formFile.getPath().replace('/', File.separatorChar), e.getMessage()), CommonBundle.getErrorTitle());
            return;
        }
        if (rootContainer.getComponentCount() == 0) {
            Messages.showErrorDialog(module.getProject(), UIDesignerBundle.message("error.cannot.preview.empty.form", formFile.getPath().replace('/', File.separatorChar)), CommonBundle.getErrorTitle());
            return;
        }
        setPreviewBindings(rootContainer, CLASS_TO_BIND_NAME);
        // 2. Copy previewer class and all its superclasses into TEMP directory and instrument it.
        try {
            PreviewNestedFormLoader nestedFormLoader = new PreviewNestedFormLoader(module, tempPath, finder);
            final File tempFile = CopyResourcesUtil.copyClass(tempPath, CLASS_TO_BIND_NAME, true);
            //CopyResourcesUtil.copyClass(tempPath, CLASS_TO_BIND_NAME + "$1", true);
            CopyResourcesUtil.copyClass(tempPath, CLASS_TO_BIND_NAME + "$MyExitAction", true);
            CopyResourcesUtil.copyClass(tempPath, CLASS_TO_BIND_NAME + "$MyPackAction", true);
            CopyResourcesUtil.copyClass(tempPath, CLASS_TO_BIND_NAME + "$MySetLafAction", true);
            Locale locale = Locale.getDefault();
            if (locale.getCountry().length() > 0 && locale.getLanguage().length() > 0) {
                CopyResourcesUtil.copyProperties(tempPath, RUNTIME_BUNDLE_PREFIX + "_" + locale.getLanguage() + "_" + locale.getCountry() + PropertiesFileType.DOT_DEFAULT_EXTENSION);
            }
            if (locale.getLanguage().length() > 0) {
                CopyResourcesUtil.copyProperties(tempPath, RUNTIME_BUNDLE_PREFIX + "_" + locale.getLanguage() + PropertiesFileType.DOT_DEFAULT_EXTENSION);
            }
            CopyResourcesUtil.copyProperties(tempPath, RUNTIME_BUNDLE_PREFIX + "_" + locale.getLanguage() + PropertiesFileType.DOT_DEFAULT_EXTENSION);
            CopyResourcesUtil.copyProperties(tempPath, RUNTIME_BUNDLE_PREFIX + PropertiesFileType.DOT_DEFAULT_EXTENSION);
            final AsmCodeGenerator codeGenerator = new AsmCodeGenerator(rootContainer, finder, nestedFormLoader, true, new PsiClassWriter(module));
            codeGenerator.patchFile(tempFile);
            final FormErrorInfo[] errors = codeGenerator.getErrors();
            if (errors.length != 0) {
                Messages.showErrorDialog(module.getProject(), UIDesignerBundle.message("error.cannot.preview.form", formFile.getPath().replace('/', File.separatorChar), errors[0].getErrorMessage()), CommonBundle.getErrorTitle());
                return;
            }
        } catch (Exception e) {
            LOG.debug(e);
            Messages.showErrorDialog(module.getProject(), UIDesignerBundle.message("error.cannot.preview.form", formFile.getPath().replace('/', File.separatorChar), e.getMessage() != null ? e.getMessage() : e.toString()), CommonBundle.getErrorTitle());
            return;
        }
        // 2.5. Copy up-to-date properties files to the output directory.
        final HashSet<String> bundleSet = new HashSet<>();
        FormEditingUtil.iterateStringDescriptors(rootContainer, new FormEditingUtil.StringDescriptorVisitor<IComponent>() {

            public boolean visit(final IComponent component, final StringDescriptor descriptor) {
                if (descriptor.getBundleName() != null) {
                    bundleSet.add(descriptor.getDottedBundleName());
                }
                return true;
            }
        });
        if (bundleSet.size() > 0) {
            HashSet<VirtualFile> virtualFiles = new HashSet<>();
            HashSet<Module> modules = new HashSet<>();
            PropertiesReferenceManager manager = PropertiesReferenceManager.getInstance(module.getProject());
            for (String bundleName : bundleSet) {
                for (PropertiesFile propFile : manager.findPropertiesFiles(module, bundleName)) {
                    virtualFiles.add(propFile.getVirtualFile());
                    final Module moduleForFile = ModuleUtil.findModuleForFile(propFile.getVirtualFile(), module.getProject());
                    if (moduleForFile != null) {
                        modules.add(moduleForFile);
                    }
                }
            }
            FileSetCompileScope scope = new FileSetCompileScope(virtualFiles, modules.toArray(new Module[modules.size()]));
            CompilerManager.getInstance(module.getProject()).make(scope, new CompileStatusNotification() {

                public void finished(boolean aborted, int errors, int warnings, final CompileContext compileContext) {
                    if (!aborted && errors == 0) {
                        runPreviewProcess(tempPath, sources, module, formFile, stringDescriptorLocale);
                    }
                }
            });
        } else {
            runPreviewProcess(tempPath, sources, module, formFile, stringDescriptorLocale);
        }
    } finally {
        finder.releaseResources();
    }
}
Also used : Locale(java.util.Locale) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiClassWriter(com.intellij.compiler.PsiClassWriter) PreviewNestedFormLoader(com.intellij.uiDesigner.make.PreviewNestedFormLoader) Document(com.intellij.openapi.editor.Document) CompileContext(com.intellij.openapi.compiler.CompileContext) CompileStatusNotification(com.intellij.openapi.compiler.CompileStatusNotification) FormErrorInfo(com.intellij.uiDesigner.compiler.FormErrorInfo) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) PropertiesReferenceManager(com.intellij.lang.properties.PropertiesReferenceManager) HashSet(com.intellij.util.containers.HashSet) InstrumentationClassFinder(com.intellij.compiler.instrumentation.InstrumentationClassFinder) IOException(java.io.IOException) ExecutionException(com.intellij.execution.ExecutionException) IOException(java.io.IOException) CantRunException(com.intellij.execution.CantRunException) PathsList(com.intellij.util.PathsList) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) File(java.io.File) AsmCodeGenerator(com.intellij.uiDesigner.compiler.AsmCodeGenerator) FormEditingUtil(com.intellij.uiDesigner.FormEditingUtil) FileSetCompileScope(com.intellij.compiler.impl.FileSetCompileScope)

Example 4 with CompileContext

use of com.intellij.openapi.compiler.CompileContext in project intellij-community by JetBrains.

the class JavaCoverageEngine method recompileProjectAndRerunAction.

@Override
public boolean recompileProjectAndRerunAction(@NotNull final Module module, @NotNull final CoverageSuitesBundle suite, @NotNull final Runnable chooseSuiteAction) {
    final VirtualFile outputpath = CompilerModuleExtension.getInstance(module).getCompilerOutputPath();
    final VirtualFile testOutputpath = CompilerModuleExtension.getInstance(module).getCompilerOutputPathForTests();
    if ((outputpath == null && isModuleOutputNeeded(module, JavaSourceRootType.SOURCE)) || (suite.isTrackTestFolders() && testOutputpath == null && isModuleOutputNeeded(module, JavaSourceRootType.TEST_SOURCE))) {
        final Project project = module.getProject();
        if (suite.isModuleChecked(module))
            return false;
        suite.checkModule(module);
        final Runnable runnable = () -> {
            if (Messages.showOkCancelDialog("Project class files are out of date. Would you like to recompile? The refusal to do it will result in incomplete coverage information", "Project is out of date", Messages.getWarningIcon()) == Messages.OK) {
                final CompilerManager compilerManager = CompilerManager.getInstance(project);
                compilerManager.make(compilerManager.createProjectCompileScope(project), new CompileStatusNotification() {

                    public void finished(final boolean aborted, final int errors, final int warnings, final CompileContext compileContext) {
                        if (aborted || errors != 0)
                            return;
                        ApplicationManager.getApplication().invokeLater(() -> {
                            if (project.isDisposed())
                                return;
                            CoverageDataManager.getInstance(project).chooseSuitesBundle(suite);
                        });
                    }
                });
            } else if (!project.isDisposed()) {
                CoverageDataManager.getInstance(project).chooseSuitesBundle(null);
            }
        };
        ApplicationManager.getApplication().invokeLater(runnable);
        return true;
    }
    return false;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) CompileStatusNotification(com.intellij.openapi.compiler.CompileStatusNotification) CompilerManager(com.intellij.openapi.compiler.CompilerManager) CompileContext(com.intellij.openapi.compiler.CompileContext)

Example 5 with CompileContext

use of com.intellij.openapi.compiler.CompileContext in project intellij-community by JetBrains.

the class PrepareToDeployAction method doPrepare.

public void doPrepare(final List<Module> pluginModules, final Project project) {
    final List<String> errorMessages = new ArrayList<>();
    final List<String> successMessages = new ArrayList<>();
    final CompilerManager compilerManager = CompilerManager.getInstance(project);
    compilerManager.make(compilerManager.createModulesCompileScope(pluginModules.toArray(new Module[pluginModules.size()]), true), new CompileStatusNotification() {

        public void finished(final boolean aborted, final int errors, final int warnings, final CompileContext compileContext) {
            if (aborted || errors != 0)
                return;
            ApplicationManager.getApplication().invokeLater(() -> {
                for (Module aModule : pluginModules) {
                    if (!doPrepare(aModule, errorMessages, successMessages)) {
                        return;
                    }
                }
                if (!errorMessages.isEmpty()) {
                    Messages.showErrorDialog(errorMessages.iterator().next(), DevKitBundle.message("error.occurred"));
                } else if (!successMessages.isEmpty()) {
                    StringBuilder messageBuf = new StringBuilder();
                    for (String message : successMessages) {
                        if (messageBuf.length() != 0) {
                            messageBuf.append('\n');
                        }
                        messageBuf.append(message);
                    }
                    final String title = pluginModules.size() == 1 ? DevKitBundle.message("success.deployment.message", pluginModules.get(0).getName()) : DevKitBundle.message("success.deployment.message.all");
                    NOTIFICATION_GROUP.createNotification(title, messageBuf.toString(), NotificationType.INFORMATION, null).notify(project);
                }
            }, project.getDisposed());
        }
    });
}
Also used : CompileStatusNotification(com.intellij.openapi.compiler.CompileStatusNotification) CompilerManager(com.intellij.openapi.compiler.CompilerManager) Module(com.intellij.openapi.module.Module) CompileContext(com.intellij.openapi.compiler.CompileContext)

Aggregations

CompileContext (com.intellij.openapi.compiler.CompileContext)17 CompilerManager (com.intellij.openapi.compiler.CompilerManager)9 CompileStatusNotification (com.intellij.openapi.compiler.CompileStatusNotification)7 CompileTask (com.intellij.openapi.compiler.CompileTask)6 Module (com.intellij.openapi.module.Module)5 Project (com.intellij.openapi.project.Project)5 AccessToken (com.intellij.openapi.application.AccessToken)3 CompileScope (com.intellij.openapi.compiler.CompileScope)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 FileSetCompileScope (com.intellij.compiler.impl.FileSetCompileScope)2 CompilationStatusListener (com.intellij.openapi.compiler.CompilationStatusListener)2 ArtifactCompileScope (com.intellij.packaging.impl.compiler.ArtifactCompileScope)2 NotNull (org.jetbrains.annotations.NotNull)2 GradleResourceCompilerConfigurationGenerator (org.jetbrains.plugins.gradle.config.GradleResourceCompilerConfigurationGenerator)2 AndroidGradleBuildConfiguration (com.android.tools.idea.gradle.project.build.compiler.AndroidGradleBuildConfiguration)1 PsiClassWriter (com.intellij.compiler.PsiClassWriter)1 CompileContextImpl (com.intellij.compiler.impl.CompileContextImpl)1 ModuleCompileScope (com.intellij.compiler.impl.ModuleCompileScope)1 InstrumentationClassFinder (com.intellij.compiler.instrumentation.InstrumentationClassFinder)1 CompilerTask (com.intellij.compiler.progress.CompilerTask)1