use of org.jetbrains.jps.incremental.messages.CompilerMessage in project intellij-community by JetBrains.
the class BuildRunner method load.
public ProjectDescriptor load(MessageHandler msgHandler, File dataStorageRoot, BuildFSState fsState) throws IOException {
final JpsModel jpsModel = myModelLoader.loadModel();
BuildDataPaths dataPaths = new BuildDataPathsImpl(dataStorageRoot);
BuildTargetRegistryImpl targetRegistry = new BuildTargetRegistryImpl(jpsModel);
ModuleExcludeIndex index = new ModuleExcludeIndexImpl(jpsModel);
IgnoredFileIndexImpl ignoredFileIndex = new IgnoredFileIndexImpl(jpsModel);
BuildRootIndexImpl buildRootIndex = new BuildRootIndexImpl(targetRegistry, jpsModel, index, dataPaths, ignoredFileIndex);
BuildTargetIndexImpl targetIndex = new BuildTargetIndexImpl(targetRegistry, buildRootIndex);
BuildTargetsState targetsState = new BuildTargetsState(dataPaths, jpsModel, buildRootIndex);
ProjectTimestamps projectTimestamps = null;
BuildDataManager dataManager = null;
try {
projectTimestamps = new ProjectTimestamps(dataStorageRoot, targetsState);
dataManager = new BuildDataManager(dataPaths, targetsState, STORE_TEMP_CACHES_IN_MEMORY);
if (dataManager.versionDiffers()) {
myForceCleanCaches = true;
msgHandler.processMessage(new CompilerMessage("build", BuildMessage.Kind.INFO, "Dependency data format has changed, project rebuild required"));
}
} catch (Exception e) {
// second try
LOG.info(e);
if (projectTimestamps != null) {
projectTimestamps.close();
}
if (dataManager != null) {
dataManager.close();
}
myForceCleanCaches = true;
FileUtil.delete(dataStorageRoot);
targetsState = new BuildTargetsState(dataPaths, jpsModel, buildRootIndex);
projectTimestamps = new ProjectTimestamps(dataStorageRoot, targetsState);
dataManager = new BuildDataManager(dataPaths, targetsState, STORE_TEMP_CACHES_IN_MEMORY);
// second attempt succeeded
msgHandler.processMessage(new CompilerMessage("build", BuildMessage.Kind.INFO, "Project rebuild forced: " + e.getMessage()));
}
return new ProjectDescriptor(jpsModel, fsState, projectTimestamps, dataManager, BuildLoggingManager.DEFAULT, index, targetsState, targetIndex, buildRootIndex, ignoredFileIndex);
}
use of org.jetbrains.jps.incremental.messages.CompilerMessage in project intellij-community by JetBrains.
the class JavaBuilder method doBuild.
public ExitCode doBuild(@NotNull CompileContext context, @NotNull ModuleChunk chunk, @NotNull DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget> dirtyFilesHolder, @NotNull OutputConsumer outputConsumer, @NotNull JavaCompilingTool compilingTool) throws ProjectBuildException, IOException {
try {
final Set<File> filesToCompile = new THashSet<>(FileUtil.FILE_HASHING_STRATEGY);
dirtyFilesHolder.processDirtyFiles(new FileProcessor<JavaSourceRootDescriptor, ModuleBuildTarget>() {
@Override
public boolean apply(ModuleBuildTarget target, File file, JavaSourceRootDescriptor descriptor) throws IOException {
if (JAVA_SOURCES_FILTER.accept(file) && ourCompilableModuleTypes.contains(target.getModule().getModuleType())) {
filesToCompile.add(file);
}
return true;
}
});
if ((!filesToCompile.isEmpty() || dirtyFilesHolder.hasRemovedFiles()) && JpsJavaSdkType.parseVersion(getLanguageLevel(ContainerUtil.getFirstItem(chunk.getModules()))) >= 9) {
// at the moment, there is no incremental compilation for module-info files, so they should be rebuilt on every change
JavaModuleIndex index = getJavaModuleIndex(context);
for (JpsModule module : chunk.getModules()) {
ContainerUtil.addIfNotNull(filesToCompile, index.getModuleInfoFile(module));
}
}
if (JavaBuilderUtil.isCompileJavaIncrementally(context)) {
ProjectBuilderLogger logger = context.getLoggingManager().getProjectBuilderLogger();
if (logger.isEnabled() && !filesToCompile.isEmpty()) {
logger.logCompiledFiles(filesToCompile, BUILDER_NAME, "Compiling files:");
}
}
return compile(context, chunk, dirtyFilesHolder, filesToCompile, outputConsumer, compilingTool);
} catch (BuildDataCorruptedException | PersistentEnumeratorBase.CorruptedException | ProjectBuildException e) {
throw e;
} catch (Exception e) {
LOG.info(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;
}
context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, message));
throw new StopBuildException();
}
}
use of org.jetbrains.jps.incremental.messages.CompilerMessage in project intellij-community by JetBrains.
the class ResourcesBuilder method build.
@Override
public void build(@NotNull ResourcesTarget target, @NotNull DirtyFilesHolder<ResourceRootDescriptor, ResourcesTarget> holder, @NotNull final BuildOutputConsumer outputConsumer, @NotNull final CompileContext context) throws ProjectBuildException, IOException {
if (!isResourceProcessingEnabled(target.getModule())) {
return;
}
try {
holder.processDirtyFiles(new FileProcessor<ResourceRootDescriptor, ResourcesTarget>() {
private final Map<ResourceRootDescriptor, Boolean> mySkippedRoots = new HashMap<>();
public boolean apply(ResourcesTarget target, final File file, final ResourceRootDescriptor sourceRoot) throws IOException {
Boolean isSkipped = mySkippedRoots.get(sourceRoot);
if (isSkipped == null) {
final File outputDir = target.getOutputDir();
isSkipped = Boolean.valueOf(outputDir == null || FileUtil.filesEqual(outputDir, sourceRoot.getRootFile()));
mySkippedRoots.put(sourceRoot, isSkipped);
}
if (isSkipped.booleanValue()) {
return true;
}
try {
copyResource(context, sourceRoot, file, outputConsumer);
} catch (IOException e) {
LOG.info(e);
context.processMessage(new CompilerMessage("resources", BuildMessage.Kind.ERROR, e.getMessage(), FileUtil.toSystemIndependentName(file.getPath())));
return false;
}
return !context.getCancelStatus().isCanceled();
}
});
context.checkCanceled();
context.processMessage(new ProgressMessage(""));
} catch (BuildDataCorruptedException | ProjectBuildException e) {
throw e;
} catch (Exception e) {
throw new ProjectBuildException(e.getMessage(), e);
}
}
use of org.jetbrains.jps.incremental.messages.CompilerMessage in project intellij-community by JetBrains.
the class BaseInstrumentingBuilder method performBuild.
@Override
protected final ExitCode performBuild(CompileContext context, ModuleChunk chunk, InstrumentationClassFinder finder, OutputConsumer outputConsumer) {
ExitCode exitCode = ExitCode.NOTHING_DONE;
for (CompiledClass compiledClass : outputConsumer.getCompiledClasses().values()) {
if (Utils.IS_TEST_MODE || LOG.isDebugEnabled()) {
LOG.info("checking " + compiledClass + " by " + getClass());
}
final BinaryContent originalContent = compiledClass.getContent();
final ClassReader reader = new FailSafeClassReader(originalContent.getBuffer(), originalContent.getOffset(), originalContent.getLength());
final int version = getClassFileVersion(reader);
if (IS_INSTRUMENTED_KEY.get(compiledClass, Boolean.FALSE) || !canInstrument(compiledClass, version)) {
// do not instrument the same content twice
continue;
}
final ClassWriter writer = new InstrumenterClassWriter(reader, getAsmClassWriterFlags(version), finder);
try {
if (Utils.IS_TEST_MODE || LOG.isDebugEnabled()) {
LOG.info("instrumenting " + compiledClass + " by " + getClass());
}
final BinaryContent instrumented = instrument(context, compiledClass, reader, writer, finder);
if (instrumented != null) {
compiledClass.setContent(instrumented);
finder.cleanCachedData(compiledClass.getClassName());
IS_INSTRUMENTED_KEY.set(compiledClass, Boolean.TRUE);
exitCode = ExitCode.OK;
}
} catch (Throwable e) {
LOG.info(e);
final String message = e.getMessage();
if (message != null) {
context.processMessage(new CompilerMessage(getPresentableName(), BuildMessage.Kind.ERROR, message, ContainerUtil.getFirstItem(compiledClass.getSourceFilesPaths())));
} else {
context.processMessage(new CompilerMessage(getPresentableName(), e));
}
}
}
return exitCode;
}
use of org.jetbrains.jps.incremental.messages.CompilerMessage in project intellij-community by JetBrains.
the class GroovycOutputParser method parseOutput.
private void parseOutput(String text) {
final String trimmed = text.trim();
if (trimmed.startsWith(GroovyRtConstants.PRESENTABLE_MESSAGE)) {
updateStatus(trimmed.substring(GroovyRtConstants.PRESENTABLE_MESSAGE.length()));
return;
}
if (GroovyRtConstants.CLEAR_PRESENTABLE.equals(trimmed)) {
updateStatus(GROOVY_COMPILER_IN_OPERATION);
return;
}
if (StringUtil.isNotEmpty(text)) {
outputBuffer.append(text);
//compiled start marker have to be in the beginning on each string
if (outputBuffer.indexOf(GroovyRtConstants.COMPILED_START) != -1) {
if (outputBuffer.indexOf(GroovyRtConstants.COMPILED_END) == -1) {
return;
}
final String compiled = handleOutputBuffer(GroovyRtConstants.COMPILED_START, GroovyRtConstants.COMPILED_END);
final List<String> list = splitAndTrim(compiled);
String outputPath = list.get(0);
String sourceFile = list.get(1);
OutputItem item = new OutputItem(outputPath, sourceFile);
if (LOG.isDebugEnabled()) {
LOG.debug("Output: " + item);
}
myCompiledItems.add(item);
} else if (outputBuffer.indexOf(GroovyRtConstants.MESSAGES_START) != -1) {
if (outputBuffer.indexOf(GroovyRtConstants.MESSAGES_END) == -1) {
return;
}
text = handleOutputBuffer(GroovyRtConstants.MESSAGES_START, GroovyRtConstants.MESSAGES_END);
List<String> tokens = splitAndTrim(text);
LOG.assertTrue(tokens.size() > 4, "Wrong number of output params");
String category = tokens.get(0);
String message = tokens.get(1);
String url = tokens.get(2);
String lineNum = tokens.get(3);
String columnNum = tokens.get(4);
int lineInt;
int columnInt;
try {
lineInt = Integer.parseInt(lineNum);
columnInt = Integer.parseInt(columnNum);
} catch (NumberFormatException e) {
LOG.error(e);
lineInt = 0;
columnInt = 0;
}
BuildMessage.Kind kind = category.equals(GroovyCompilerMessageCategories.ERROR) ? BuildMessage.Kind.ERROR : category.equals(GroovyCompilerMessageCategories.WARNING) ? BuildMessage.Kind.WARNING : BuildMessage.Kind.INFO;
if (StringUtil.isEmpty(url) || "null".equals(url)) {
url = null;
message = "While compiling " + myChunk.getPresentableShortName() + ": " + message;
}
CompilerMessage compilerMessage = new CompilerMessage("Groovyc", kind, message, url, -1, -1, -1, lineInt, columnInt);
if (LOG.isDebugEnabled()) {
LOG.debug("Message: " + compilerMessage);
}
addCompilerMessage(compilerMessage);
}
}
}
Aggregations