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-plugins by JetBrains.
the class FlexBuilder method build.
@Override
public void build(@NotNull final FlexBuildTarget buildTarget, @NotNull final DirtyFilesHolder<BuildRootDescriptor, FlexBuildTarget> holder, @NotNull final BuildOutputConsumer outputConsumer, @NotNull final CompileContext context) throws ProjectBuildException, IOException {
final Collection<String> dirtyFilePaths = new ArrayList<>();
holder.processDirtyFiles(new FileProcessor<BuildRootDescriptor, FlexBuildTarget>() {
@Override
public boolean apply(final FlexBuildTarget target, final File file, final BuildRootDescriptor root) throws IOException {
assert target == buildTarget;
dirtyFilePaths.add(file.getPath());
return true;
}
});
if (LOG.isDebugEnabled()) {
final StringBuilder b = new StringBuilder();
b.append(buildTarget.getId()).append(", ").append("dirty files: ").append(dirtyFilePaths.size());
if (dirtyFilePaths.size() < 10) {
for (String path : dirtyFilePaths) {
b.append('\n').append(path);
}
}
LOG.debug(b.toString());
}
final JpsFlexBuildConfiguration mainBC = buildTarget.getBC();
final List<JpsFlexBuildConfiguration> bcsToCompile = getAllBCsToCompile(mainBC);
if (!FlexCommonUtils.isFlexUnitBC(mainBC) && !isFlexmojosBCWithUpdatedConfigFile(mainBC)) {
if (dirtyFilePaths.isEmpty()) {
boolean outputFilesExist = true;
for (JpsFlexBuildConfiguration bc : bcsToCompile) {
if (!new File(bc.getActualOutputFilePath()).isFile()) {
outputFilesExist = false;
LOG.debug("recompile because output file doesn't exist: " + bc.getActualOutputFilePath());
break;
}
}
if (outputFilesExist) {
return;
}
} else if (mainBC.getNature().isApp() && isOnlyWrapperFilesDirty(mainBC, dirtyFilePaths)) {
LOG.debug("only wrapper files dirty");
FlexBuilderUtils.performPostCompileActions(context, mainBC, dirtyFilePaths, outputConsumer);
return;
}
}
for (JpsFlexBuildConfiguration bc : bcsToCompile) {
final Status status = compileBuildConfiguration(context, bc, myBuiltInCompilerHandler);
switch(status) {
case Ok:
outputConsumer.registerOutputFile(new File(mainBC.getActualOutputFilePath()), dirtyFilePaths);
FlexBuilderUtils.performPostCompileActions(context, bc, dirtyFilePaths, outputConsumer);
context.processMessage(new CompilerMessage(FlexBuilderUtils.getCompilerName(bc), BuildMessage.Kind.INFO, FlexCommonBundle.message("compilation.successful")));
break;
case Failed:
final String message = bc.getOutputType() == OutputType.Application ? FlexCommonBundle.message("compilation.failed") : FlexCommonBundle.message("compilation.failed.dependent.will.be.skipped");
context.processMessage(new CompilerMessage(FlexBuilderUtils.getCompilerName(bc), BuildMessage.Kind.INFO, message));
throw new StopBuildException();
case Cancelled:
context.processMessage(new CompilerMessage(FlexBuilderUtils.getCompilerName(bc), BuildMessage.Kind.INFO, FlexCommonBundle.message("compilation.cancelled")));
return;
}
}
}
use of org.jetbrains.jps.incremental.messages.CompilerMessage in project intellij-plugins by JetBrains.
the class FlexBuilder method doCompile.
private static Status doCompile(final CompileContext context, final JpsFlexBuildConfiguration bc, final List<File> configFiles, final String compilerName, final JpsBuiltInFlexCompilerHandler builtInCompilerHandler) {
final boolean app = bc.getOutputType() != OutputType.Library;
final JpsSdk<?> sdk = bc.getSdk();
assert sdk != null;
final boolean asc20 = bc.isPureAs() && FlexCommonUtils.containsASC20(sdk.getHomePath()) && (JpsFlexCompilerProjectExtension.getInstance(bc.getModule().getProject()).PREFER_ASC_20 || FlexCommonUtils.isAirSdkWithoutFlex(sdk));
final boolean builtIn = !asc20 && JpsFlexCompilerProjectExtension.getInstance(bc.getModule().getProject()).USE_BUILT_IN_COMPILER && builtInCompilerHandler.canBeUsedForSdk(sdk.getHomePath());
if (builtIn) {
return doCompileWithBuiltInCompiler(context, bc, configFiles, compilerName, builtInCompilerHandler);
}
final List<String> compilerCommand = asc20 ? getASC20Command(bc.getModule().getProject(), sdk, app) : getMxmlcCompcCommand(bc.getModule().getProject(), sdk, app);
final List<String> command = buildCommand(compilerCommand, configFiles, bc);
final ProcessBuilder processBuilder = new ProcessBuilder(command);
processBuilder.redirectErrorStream(true);
processBuilder.directory(new File(FlexCommonUtils.getFlexCompilerWorkDirPath(bc.getModule().getProject())));
try {
final Process process = processBuilder.start();
final FlexCompilerProcessHandler processHandler = new FlexCompilerProcessHandler(context, process, asc20, compilerName, StringUtil.join(command, " "));
processHandler.startNotify();
processHandler.waitFor();
return processHandler.isCancelled() ? Status.Cancelled : processHandler.isCompilationFailed() ? Status.Failed : Status.Ok;
} catch (IOException e) {
context.processMessage(new CompilerMessage(compilerName, BuildMessage.Kind.ERROR, e.getMessage()));
return Status.Failed;
}
}
use of org.jetbrains.jps.incremental.messages.CompilerMessage in project intellij-plugins by JetBrains.
the class FlexBuilderUtils method handleHtmlWrapper.
private static void handleHtmlWrapper(final CompileContext context, final JpsFlexBuildConfiguration bc, final BuildOutputConsumer outputConsumer) {
final File templateDir = new File(bc.getWrapperTemplatePath());
if (!templateDir.isDirectory()) {
context.processMessage(new CompilerMessage(getCompilerName(bc), BuildMessage.Kind.ERROR, FlexCommonBundle.message("html.wrapper.dir.not.found", bc.getWrapperTemplatePath())));
return;
}
final File templateFile = new File(templateDir, FlexCommonUtils.HTML_WRAPPER_TEMPLATE_FILE_NAME);
if (!templateFile.isFile()) {
context.processMessage(new CompilerMessage(getCompilerName(bc), BuildMessage.Kind.ERROR, FlexCommonBundle.message("no.index.template.html.file", bc.getWrapperTemplatePath())));
return;
}
final InfoFromConfigFile info = InfoFromConfigFile.getInfoFromConfigFile(bc.getCompilerOptions().getAdditionalConfigFilePath());
final String outputFolderPath = StringUtil.notNullize(info.getOutputFolderPath(), bc.getOutputFolder());
final String outputFileName = bc.isTempBCForCompilation() ? bc.getOutputFileName() : StringUtil.notNullize(info.getOutputFileName(), bc.getOutputFileName());
final String targetPlayer = StringUtil.notNullize(info.getTargetPlayer(), bc.getDependencies().getTargetPlayer());
final File outputDir = new File(outputFolderPath);
if (!outputDir.isDirectory()) {
context.processMessage(new CompilerMessage(getCompilerName(bc), BuildMessage.Kind.ERROR, FlexCommonBundle.message("output.folder.does.not.exist", outputFolderPath)));
return;
}
for (File file : templateDir.listFiles()) {
if (FlexCommonUtils.HTML_WRAPPER_TEMPLATE_FILE_NAME.equals(file.getName())) {
final JpsEncodingProjectConfiguration encodingConfiguration = JpsEncodingConfigurationService.getInstance().getEncodingConfiguration(bc.getModule().getProject());
final String encoding = encodingConfiguration == null ? null : encodingConfiguration.getEncoding(file);
String wrapperText;
try {
try {
wrapperText = FileUtil.loadFile(file, encoding);
} catch (UnsupportedEncodingException e) {
wrapperText = FileUtil.loadFile(file);
}
} catch (IOException e) {
context.processMessage(new CompilerMessage(getCompilerName(bc), BuildMessage.Kind.ERROR, FlexCommonBundle.message("failed.to.load.template.file", file.getPath(), e.getMessage())));
return;
}
if (!wrapperText.contains(FlexCommonUtils.SWF_MACRO)) {
context.processMessage(new CompilerMessage(getCompilerName(bc), BuildMessage.Kind.ERROR, FlexCommonBundle.message("no.swf.macro", file.getPath())));
return;
}
final String mainClass = StringUtil.notNullize(info.getMainClass(bc.getModule()), bc.getMainClass());
final String fixedText = replaceMacros(wrapperText, FileUtil.getNameWithoutExtension(outputFileName), targetPlayer, FlexCommonUtils.getPathToMainClassFile(mainClass, bc.getModule()));
final String wrapperFileName = FlexCommonUtils.getWrapperFileName(bc);
try {
byte[] bytes;
try {
bytes = encoding == null ? fixedText.getBytes() : fixedText.getBytes(encoding);
} catch (UnsupportedEncodingException e) {
bytes = fixedText.getBytes();
}
final File outputFile = new File(outputDir, wrapperFileName);
FileUtil.writeToFile(outputFile, bytes);
outputConsumer.registerOutputFile(outputFile, Collections.singletonList(file.getPath()));
} catch (IOException e) {
context.processMessage(new CompilerMessage(getCompilerName(bc), BuildMessage.Kind.ERROR, FlexCommonBundle.message("failed.to.create.file.in", wrapperFileName, outputDir.getPath(), e.getMessage())));
}
} else {
try {
final File outputFile = new File(outputDir, file.getName());
if (file.isDirectory()) {
FileUtil.createDirectory(outputFile);
FileUtil.copyDir(file, outputFile);
} else {
FileUtil.copy(file, outputFile);
}
outputConsumer.registerOutputFile(outputFile, Collections.singletonList(file.getPath()));
} catch (IOException e) {
context.processMessage(new CompilerMessage(getCompilerName(bc), BuildMessage.Kind.ERROR, FlexCommonBundle.message("failed.to.copy.file", file.getName(), templateDir.getPath(), outputDir.getPath(), e.getMessage())));
}
}
}
}
Aggregations