use of org.jetbrains.jps.incremental.messages.CompilerMessage in project intellij-elixir by KronicDeth.
the class ElixirTargetBuilderUtil method getSdk.
@NotNull
public static JpsSdk<JpsDummyElement> getSdk(@NotNull CompileContext context, @NotNull JpsModule module) throws ProjectBuildException {
JpsSdk<JpsDummyElement> sdk = module.getSdk(JpsElixirSdkType.INSTANCE);
if (sdk == null) {
String errorMessage = "No SDK for module " + module.getName();
context.processMessage(new CompilerMessage(ElixirBuilder.BUILDER_NAME, BuildMessage.Kind.ERROR, errorMessage));
throw new ProjectBuildException(errorMessage);
}
return sdk;
}
use of org.jetbrains.jps.incremental.messages.CompilerMessage 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);
}
}
use of org.jetbrains.jps.incremental.messages.CompilerMessage in project intellij-elixir by KronicDeth.
the class ElixirBuilder method addModuleToCodePath.
private static void addModuleToCodePath(@NotNull GeneralCommandLine commandLine, @NotNull JpsModule module, boolean forTests, @NotNull CompileContext context) throws ProjectBuildException {
File outputDirectory = getBuildOutputDirectory(module, forTests, context);
commandLine.addParameters(ADD_PATH_TO_FRONT_OF_CODE_PATH, outputDirectory.getPath());
for (String rootUrl : module.getContentRootsList().getUrls()) {
try {
String path = new URL(rootUrl).getPath();
commandLine.addParameters(ADD_PATH_TO_FRONT_OF_CODE_PATH, path);
} catch (MalformedURLException e) {
context.processMessage(new CompilerMessage(ElIXIRC_NAME, BuildMessage.Kind.ERROR, "Failed to find content root for module: " + module.getName()));
}
}
}
use of org.jetbrains.jps.incremental.messages.CompilerMessage in project intellij-community by JetBrains.
the class DependencyResolvingBuilder method build.
@Override
public ExitCode build(CompileContext context, ModuleChunk chunk, DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget> dirtyFilesHolder, OutputConsumer outputConsumer) throws ProjectBuildException, IOException {
final Exception error = context.getUserData(RESOLVE_ERROR_KEY);
if (error != null) {
final StringBuilder builder = new StringBuilder().append("Error resolving dependencies for ").append(chunk.getPresentableShortName());
Throwable th = error;
final Set<Throwable> processed = new HashSet<>();
final Set<String> detailsMessage = new HashSet<>();
while (th != null && processed.add(th)) {
String details = th.getMessage();
if (th instanceof UnknownHostException) {
// hack for UnknownHostException
details = "Unknown host: " + details;
}
if (details != null && detailsMessage.add(details)) {
builder.append(":\n").append(details);
}
th = th.getCause();
}
final String msg = builder.toString();
LOG.info(msg, error);
context.processMessage(new CompilerMessage(NAME, BuildMessage.Kind.ERROR, msg));
return ExitCode.ABORT;
}
return ExitCode.OK;
}
use of org.jetbrains.jps.incremental.messages.CompilerMessage in project intellij-community by JetBrains.
the class FormsInstrumenter method instrumentForms.
private Map<File, Collection<File>> instrumentForms(CompileContext context, ModuleChunk chunk, final Map<File, String> chunkSourcePath, final InstrumentationClassFinder finder, Collection<File> forms, OutputConsumer outConsumer) throws ProjectBuildException {
final Map<File, Collection<File>> instrumented = new THashMap<>(FileUtil.FILE_HASHING_STRATEGY);
final Map<String, File> class2form = new HashMap<>();
final MyNestedFormLoader nestedFormsLoader = new MyNestedFormLoader(chunkSourcePath, ProjectPaths.getOutputPathsWithDependents(chunk), finder);
for (File formFile : forms) {
final LwRootContainer rootContainer;
try {
rootContainer = Utils.getRootContainer(formFile.toURI().toURL(), new CompiledClassPropertiesProvider(finder.getLoader()));
} catch (AlienFormFileException e) {
// ignore non-IDEA forms
continue;
} catch (UnexpectedFormElementException e) {
context.processMessage(new CompilerMessage(getPresentableName(), BuildMessage.Kind.ERROR, e.getMessage(), formFile.getPath()));
LOG.info(e);
continue;
} catch (UIDesignerException e) {
context.processMessage(new CompilerMessage(getPresentableName(), BuildMessage.Kind.ERROR, e.getMessage(), formFile.getPath()));
LOG.info(e);
continue;
} catch (Exception e) {
throw new ProjectBuildException("Cannot process form file " + formFile.getAbsolutePath(), e);
}
final String classToBind = rootContainer.getClassToBind();
if (classToBind == null) {
continue;
}
final CompiledClass compiled = findClassFile(outConsumer, classToBind);
if (compiled == null) {
context.processMessage(new CompilerMessage(getPresentableName(), BuildMessage.Kind.WARNING, "Class to bind does not exist: " + classToBind, formFile.getAbsolutePath()));
continue;
}
final File alreadyProcessedForm = class2form.get(classToBind);
if (alreadyProcessedForm != null) {
context.processMessage(new CompilerMessage(getPresentableName(), BuildMessage.Kind.WARNING, formFile.getAbsolutePath() + ": The form is bound to the class " + classToBind + ".\nAnother form " + alreadyProcessedForm.getAbsolutePath() + " is also bound to this class", formFile.getAbsolutePath()));
continue;
}
class2form.put(classToBind, formFile);
for (File file : compiled.getSourceFiles()) {
addBinding(file, formFile, instrumented);
}
try {
context.processMessage(new ProgressMessage("Instrumenting forms... [" + chunk.getPresentableShortName() + "]"));
final BinaryContent originalContent = compiled.getContent();
final ClassReader classReader = new FailSafeClassReader(originalContent.getBuffer(), originalContent.getOffset(), originalContent.getLength());
final int version = ClassProcessingBuilder.getClassFileVersion(classReader);
final InstrumenterClassWriter classWriter = new InstrumenterClassWriter(classReader, ClassProcessingBuilder.getAsmClassWriterFlags(version), finder);
final AsmCodeGenerator codeGenerator = new AsmCodeGenerator(rootContainer, finder, nestedFormsLoader, false, classWriter);
final byte[] patchedBytes = codeGenerator.patchClass(classReader);
if (patchedBytes != null) {
compiled.setContent(new BinaryContent(patchedBytes));
}
final FormErrorInfo[] warnings = codeGenerator.getWarnings();
for (final FormErrorInfo warning : warnings) {
context.processMessage(new CompilerMessage(getPresentableName(), BuildMessage.Kind.WARNING, warning.getErrorMessage(), formFile.getAbsolutePath()));
}
final FormErrorInfo[] errors = codeGenerator.getErrors();
if (errors.length > 0) {
StringBuilder message = new StringBuilder();
for (final FormErrorInfo error : errors) {
if (message.length() > 0) {
message.append("\n");
}
message.append(formFile.getAbsolutePath()).append(": ").append(error.getErrorMessage());
}
context.processMessage(new CompilerMessage(getPresentableName(), BuildMessage.Kind.ERROR, message.toString()));
}
} catch (Exception e) {
context.processMessage(new CompilerMessage(getPresentableName(), BuildMessage.Kind.ERROR, "Forms instrumentation failed" + e.getMessage(), formFile.getAbsolutePath()));
}
}
return instrumented;
}
Aggregations