private void removeAllContents(Project project, Content notRemove) { if (project.isDisposed()) { return; } final MessageView messageView = MessageView.SERVICE.getInstance(project); Content[] contents = messageView.getContentManager().getContents(); for (Content content : contents) { if (content.isPinned()) { continue; } if (content == notRemove) { continue; } boolean toRemove = CONTENT_ID_KEY.get(content) == myContentId; if (!toRemove) { final Object contentSessionId = SESSION_ID_KEY.get(content); toRemove = contentSessionId != null && contentSessionId != mySessionId; // the content was added by previous compilation } if (toRemove) { messageView.getContentManager().removeContent(content, true); } } }
@Override public void chunkBuildFinished(CompileContext context, ModuleChunk chunk) { final InstrumentationClassFinder finder = CLASS_FINDER.get(context); if (finder != null) { CLASS_FINDER.set(context, null); finder.releaseResources(); } }
@NotNull @Override public Navigatable createNavigatable(@NotNull Project project) { if (ALTERNATIVE_SOURCE_KEY.get(myFile) != null) { return new OpenFileDescriptor(project, getFile(), getLine(), 0); } return XSourcePositionImpl.doCreateOpenFileDescriptor(project, this); }
@NotNull @Override public VirtualFile getFile() { VirtualFile file = ALTERNATIVE_SOURCE_KEY.get(myFile); if (file != null) { return file; } return myFile; }
private static int getItemToSelect( LookupImpl lookup, List<LookupElement> items, boolean onExplicitAction, @Nullable LookupElement mostRelevant) { if (items.isEmpty() || lookup.getFocusDegree() == LookupImpl.FocusDegree.UNFOCUSED) { return 0; } if (lookup.isSelectionTouched() || !onExplicitAction) { final LookupElement lastSelection = lookup.getCurrentItem(); int old = ContainerUtil.indexOfIdentity(items, lastSelection); if (old >= 0) { return old; } Object selectedValue = ((LookupImpl) lookup).getList().getSelectedValue(); if (selectedValue instanceof EmptyLookupItem && ((EmptyLookupItem) selectedValue).isLoading()) { int index = ((LookupImpl) lookup).getList().getSelectedIndex(); if (index >= 0 && index < items.size()) { return index; } } for (int i = 0; i < items.size(); i++) { String invariant = PRESENTATION_INVARIANT.get(items.get(i)); if (invariant != null && invariant.equals(PRESENTATION_INVARIANT.get(lastSelection))) { return i; } } } String selectedText = lookup.getEditor().getSelectionModel().getSelectedText(); for (int i = 0; i < items.size(); i++) { LookupElement item = items.get(i); if (isPrefixItem(lookup, item, true) && !isLiveTemplate(item) || item.getLookupString().equals(selectedText)) { return i; } } return Math.max(0, ContainerUtil.indexOfIdentity(items, mostRelevant)); }
@NotNull public static StatisticsInfo getBaseStatisticsInfo( LookupElement item, @Nullable CompletionLocation location) { StatisticsInfo info = BASE_STATISTICS_INFO.get(item); if (info == null) { if (location == null) { return StatisticsInfo.EMPTY; } BASE_STATISTICS_INFO.set(item, info = calcBaseInfo(item, location)); } return info; }
public static void deleteTypeAnnotations(@NotNull PsiTypeElement typeElement) { PsiElement left = PsiTreeUtil.skipSiblingsBackward( typeElement, PsiComment.class, PsiWhiteSpace.class, PsiTypeParameterList.class); if (left instanceof PsiModifierList) { for (PsiAnnotation annotation : ((PsiModifierList) left).getAnnotations()) { if (TYPE_ANNO_MARK.get(annotation) == Boolean.TRUE) { annotation.delete(); } } } }
public ExitCode build( final CompileContext context, final ModuleChunk chunk, DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget> dirtyFilesHolder, OutputConsumer outputConsumer) throws ProjectBuildException { if (!IS_ENABLED.get(context, Boolean.TRUE)) { return ExitCode.NOTHING_DONE; } try { final Map<File, ModuleBuildTarget> filesToCompile = new THashMap<File, ModuleBuildTarget>(FileUtil.FILE_HASHING_STRATEGY); 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); } return true; } }); if (context.isMake()) { final ProjectBuilderLogger logger = context.getLoggingManager().getProjectBuilderLogger(); if (logger.isEnabled()) { if (filesToCompile.size() > 0) { logger.logCompiledFiles(filesToCompile.keySet(), BUILDER_NAME, "Compiling files:"); } } } return compile(context, chunk, dirtyFilesHolder, filesToCompile.keySet(), outputConsumer); } catch (ProjectBuildException e) { throw e; } catch (Exception e) { String message = e.getMessage(); if (message == null) { final ByteArrayOutputStream out = new ByteArrayOutputStream(); final PrintStream stream = new PrintStream(out); try { e.printStackTrace(stream); } finally { stream.close(); } message = "Internal error: \n" + out.toString(); } context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, message)); throw new ProjectBuildException(message, e); } }
public void showCompilerContent() { synchronized (myMessageViewLock) { if (myErrorTreeView != null) { final MessageView messageView = MessageView.SERVICE.getInstance(myProject); Content[] contents = messageView.getContentManager().getContents(); for (Content content : contents) { if (CONTENT_ID_KEY.get(content) == myContentId) { messageView.getContentManager().setSelectedContent(content); return; } } } } }
private static boolean checkChunkRebuildNeeded( CompileContext context, GroovycOutputParser parser) { if (JavaBuilderUtil.isForcedRecompilationAllJavaModules(context) || !parser.shouldRetry()) { return false; } if (CHUNK_REBUILD_ORDERED.get(context) != null) { CHUNK_REBUILD_ORDERED.set(context, null); return false; } CHUNK_REBUILD_ORDERED.set(context, Boolean.TRUE); LOG.info("Order chunk rebuild"); return true; }
private static int getCompilerSdkVersion(CompileContext context) { final Integer cached = JAVA_COMPILER_VERSION_KEY.get(context); if (cached != null) { return cached; } int javaVersion = convertToNumber(SystemProperties.getJavaVersion()); if (!USE_EMBEDDED_JAVAC) { // in case of external javac, run compiler from the newest jdk that is used in the project for (JpsSdk<?> sdk : context.getProjectDescriptor().getProjectJavaSdks()) { final String version = sdk.getVersionString(); final int ver = convertToNumber(version); if (ver > javaVersion) { javaVersion = ver; } } } JAVA_COMPILER_VERSION_KEY.set(context, javaVersion); return javaVersion; }
@Override public final ExitCode build( CompileContext context, ModuleChunk chunk, DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget> dirtyFilesHolder, OutputConsumer outputConsumer) throws ProjectBuildException, IOException { if (outputConsumer.getCompiledClasses().isEmpty() || !isEnabled(context, chunk)) { return ExitCode.NOTHING_DONE; } final String progress = getProgressMessage(); final boolean shouldShowProgress = !StringUtil.isEmptyOrSpaces(progress); if (shouldShowProgress) { context.processMessage(new ProgressMessage(progress + " [" + chunk.getName() + "]")); } ExitCode exitCode = ExitCode.NOTHING_DONE; try { InstrumentationClassFinder finder = CLASS_FINDER.get(context); // try using shared finder if (finder == null) { final Collection<File> platformCp = ProjectPaths.getPlatformCompilationClasspath(chunk, false); final Collection<File> classpath = new ArrayList<File>(); classpath.addAll(ProjectPaths.getCompilationClasspath(chunk, false)); classpath.addAll(ProjectPaths.getSourceRootsWithDependents(chunk).keySet()); finder = createInstrumentationClassFinder(platformCp, classpath, outputConsumer); CLASS_FINDER.set(context, finder); } exitCode = performBuild(context, chunk, finder, outputConsumer); } finally { if (shouldShowProgress) { context.processMessage(new ProgressMessage("")); // cleanup progress } } return exitCode; }
public static boolean fileProcessed(VirtualFile file) { return FILE_PROCESSED_KEY.get(file) != null; }
@Override public int compare(LookupElement o1, LookupElement o2) { String invariant = PRESENTATION_INVARIANT.get(o1); assert invariant != null; return invariant.compareToIgnoreCase(PRESENTATION_INVARIANT.get(o2)); }
private Boolean hasFilesToCompileForNextRound(CompileContext context) { return !myForStubs && FILES_MARKED_DIRTY_FOR_NEXT_ROUND.get(context, Boolean.FALSE); }
public ModuleLevelBuilder.ExitCode build(final CompileContext context, ModuleChunk chunk) throws ProjectBuildException { try { final List<File> toCompile = collectChangedFiles(context, chunk); if (toCompile.isEmpty()) { return ExitCode.NOTHING_DONE; } String moduleOutput = getModuleOutput(context, chunk); String compilerOutput = getCompilerOutput(moduleOutput); final Set<String> toCompilePaths = new LinkedHashSet<String>(); for (File file : toCompile) { toCompilePaths.add(FileUtil.toSystemIndependentName(file.getPath())); } Map<String, String> class2Src = buildClassToSourceMap(chunk, context, toCompilePaths, moduleOutput); String ideCharset = chunk.getProject().getProjectCharset(); String encoding = !Comparing.equal(CharsetToolkit.getDefaultSystemCharset().name(), ideCharset) ? ideCharset : null; List<String> patchers = Collections.emptyList(); // todo patchers final File tempFile = GroovycOSProcessHandler.fillFileWithGroovycParameters( compilerOutput, toCompilePaths, FileUtil.toSystemDependentName(moduleOutput), class2Src, encoding, patchers); // todo different outputs in a chunk // todo xmx final List<String> cmd = ExternalProcessUtil.buildJavaCommandLine( getJavaExecutable(chunk), "org.jetbrains.groovy.compiler.rt.GroovycRunner", Collections.<String>emptyList(), new ArrayList<String>(generateClasspath(context, chunk)), Arrays.asList( "-Xmx384m", "-Dfile.encoding=" + CharsetToolkit.getDefaultSystemCharset().name() /*, "-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5239"*/), Arrays.<String>asList(myForStubs ? "stubs" : "groovyc", tempFile.getPath())); final Process process = Runtime.getRuntime().exec(ArrayUtil.toStringArray(cmd)); GroovycOSProcessHandler handler = GroovycOSProcessHandler.runGroovyc( process, new Consumer<String>() { public void consume(String s) { context.processMessage(new ProgressMessage(s)); } }); if (handler.shouldRetry()) { if (CHUNK_REBUILD_ORDERED.get(context) != null) { CHUNK_REBUILD_ORDERED.set(context, null); } else { CHUNK_REBUILD_ORDERED.set(context, Boolean.TRUE); return ExitCode.CHUNK_REBUILD_REQUIRED; } } if (myForStubs) { JavaBuilder.addTempSourcePathRoot(context, new File(compilerOutput)); } for (CompilerMessage message : handler.getCompilerMessages()) { context.processMessage(message); } if (!myForStubs && updateDependencies( context, chunk, toCompile, moduleOutput, handler.getSuccessfullyCompiled())) { return ExitCode.ADDITIONAL_PASS_REQUIRED; } return ExitCode.OK; } catch (Exception e) { throw new ProjectBuildException(e); } }
@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 = GroovyBuilder.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))); } } Map<ModuleBuildTarget, Collection<GroovycOutputParser.OutputItem>> successfullyCompiled = GroovyBuilder.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")); } GroovyBuilder.updateDependencies( context, toCompile, successfullyCompiled, outputConsumer, this); return ExitCode.OK; } catch (Exception e) { throw new ProjectBuildException(e); } }