use of org.jetbrains.jps.incremental.messages.CompilerMessage in project android by JetBrains.
the class AndroidManifestMergingBuilder method doManifestMerging.
private static boolean doManifestMerging(AndroidManifestMergingTarget target, CompileContext context, BuildOutputConsumer outputConsumer) throws IOException {
final JpsModule module = target.getModule();
final JpsAndroidModuleExtension extension = AndroidJpsUtil.getExtension(module);
assert extension != null;
assert !extension.isLibrary();
assert extension.isManifestMergingEnabled();
final File outputDir = target.getOutputDirectory(context);
if (!outputDir.exists() && !outputDir.mkdirs()) {
context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.cannot.create.directory", outputDir.getPath())));
return false;
}
File manifestFile = null;
final List<File> libManifests = new ArrayList<File>();
final List<AndroidManifestMergingTarget.MyRootDescriptor> roots = context.getProjectDescriptor().getBuildRootIndex().getTargetRoots(target, context);
for (AndroidManifestMergingTarget.MyRootDescriptor root : roots) {
if (root.isLibManifestRoot()) {
libManifests.add(root.getRootFile());
} else {
manifestFile = root.getRootFile();
}
}
if (manifestFile == null) {
context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.errors.manifest.not.found", module.getName())));
return false;
}
final File outputFile = new File(outputDir, SdkConstants.FN_ANDROID_MANIFEST_XML);
if (!doMergeManifests(context, manifestFile, libManifests, outputFile)) {
context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, "[" + module.getName() + "] Cannot perform manifest merging"));
return false;
}
final List<String> srcPaths = new ArrayList<String>();
srcPaths.add(manifestFile.getPath());
for (File libManifest : libManifests) {
srcPaths.add(libManifest.getPath());
}
outputConsumer.registerOutputFile(outputFile, srcPaths);
return true;
}
use of org.jetbrains.jps.incremental.messages.CompilerMessage in project intellij-plugins by JetBrains.
the class FlexResourceBuilder method copyResource.
private static void copyResource(final CompileContext context, final File file, final Collection<String> targetPaths, final BuildOutputConsumer outputConsumer) {
try {
for (String targetPath : targetPaths) {
final File targetFile = new File(targetPath);
FileUtil.copyContent(file, targetFile);
outputConsumer.registerOutputFile(targetFile, Collections.singletonList(file.getPath()));
}
} catch (IOException e) {
context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, e.getMessage(), FileUtil.toSystemIndependentName(file.getPath())));
}
}
use of org.jetbrains.jps.incremental.messages.CompilerMessage in project intellij-plugins by JetBrains.
the class JpsBuiltInFlexCompilerHandler method readInputStreamUntilConnected.
private void readInputStreamUntilConnected(final Process process, final CompileContext context, final String compilerName) {
SharedThreadPool.getInstance().executeOnPooledThread(() -> {
final InputStreamReader reader = FlexCommonUtils.createInputStreamReader(process.getInputStream());
try {
char[] buf = new char[1024];
int read;
while ((read = reader.read(buf, 0, buf.length)) >= 0) {
final String output = new String(buf, 0, read);
if (output.startsWith(CONNECTION_SUCCESSFUL)) {
break;
} else {
closeSocket();
context.processMessage(new CompilerMessage(compilerName, BuildMessage.Kind.ERROR, output));
}
}
} catch (IOException e) {
closeSocket();
context.processMessage(new CompilerMessage(compilerName, BuildMessage.Kind.ERROR, "Failed to start Flex compiler: " + e.toString()));
} finally {
try {
reader.close();
} catch (IOException e) {
/*ignore*/
}
}
});
}
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;
}
}
Aggregations