Search in sources :

Example 51 with CompilerMessage

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;
}
Also used : JpsModule(org.jetbrains.jps.model.module.JpsModule) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) JpsAndroidModuleExtension(org.jetbrains.jps.android.model.JpsAndroidModuleExtension) ArrayList(java.util.ArrayList) File(java.io.File)

Example 52 with CompilerMessage

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())));
    }
}
Also used : CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) IOException(java.io.IOException) File(java.io.File)

Example 53 with CompilerMessage

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*/
            }
        }
    });
}
Also used : CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage)

Example 54 with CompilerMessage

use of org.jetbrains.jps.incremental.messages.CompilerMessage in project android by JetBrains.

the class AndroidSourceGeneratingBuilder method checkUnambiguousAndRecursiveArtifacts.

private static boolean checkUnambiguousAndRecursiveArtifacts(CompileContext context, List<JpsArtifact> artifacts) {
    boolean success = true;
    for (JpsArtifact artifact : artifacts) {
        if (artifact.getArtifactType() instanceof AndroidApplicationArtifactType) {
            final List<JpsAndroidModuleExtension> facets = AndroidJpsUtil.getAllPackagedFacets(artifact);
            if (facets.size() > 1) {
                context.processMessage(new CompilerMessage(ANDROID_VALIDATOR, BuildMessage.Kind.ERROR, "Cannot build artifact '" + artifact.getName() + "' because it contains more than one Android package"));
                success = false;
                continue;
            }
            final String artifactOutputPath = artifact.getOutputFilePath();
            if (artifactOutputPath != null && facets.size() > 0) {
                final JpsAndroidModuleExtension facet = facets.get(0);
                final String apkPath = AndroidFinalPackageElementBuilder.getApkPath(facet);
                if (FileUtil.pathsEqual(apkPath, artifactOutputPath)) {
                    context.processMessage(new CompilerMessage(ANDROID_VALIDATOR, BuildMessage.Kind.ERROR, "Incorrect output path for artifact '" + artifact.getName() + "': " + FileUtil.toSystemDependentName(apkPath)));
                    success = false;
                }
            }
        }
    }
    return success;
}
Also used : CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) JpsAndroidModuleExtension(org.jetbrains.jps.android.model.JpsAndroidModuleExtension) JpsArtifact(org.jetbrains.jps.model.artifact.JpsArtifact) AndroidApplicationArtifactType(org.jetbrains.jps.android.model.AndroidApplicationArtifactType)

Example 55 with CompilerMessage

use of org.jetbrains.jps.incremental.messages.CompilerMessage in project android by JetBrains.

the class AndroidSourceGeneratingBuilder method checkArtifacts.

private static boolean checkArtifacts(@NotNull CompileContext context) {
    final List<JpsArtifact> artifacts = AndroidJpsUtil.getAndroidArtifactsToBuild(context);
    if (!checkUnambiguousAndRecursiveArtifacts(context, artifacts)) {
        return false;
    }
    final Set<JpsArtifact> debugArtifacts = new HashSet<JpsArtifact>();
    final Set<JpsArtifact> releaseArtifacts = new HashSet<JpsArtifact>();
    final Map<String, List<JpsArtifact>> moduleName2Artifact = new HashMap<String, List<JpsArtifact>>();
    for (JpsArtifact artifact : artifacts) {
        final JpsElement properties = artifact.getProperties();
        if (!(properties instanceof JpsAndroidApplicationArtifactProperties)) {
            continue;
        }
        final AndroidArtifactSigningMode mode = ((JpsAndroidApplicationArtifactProperties) properties).getSigningMode();
        if (mode == AndroidArtifactSigningMode.DEBUG || mode == AndroidArtifactSigningMode.DEBUG_WITH_CUSTOM_CERTIFICATE) {
            debugArtifacts.add(artifact);
        } else {
            releaseArtifacts.add(artifact);
        }
        final JpsAndroidModuleExtension facet = AndroidJpsUtil.getPackagedFacet(artifact);
        if (facet != null) {
            final String moduleName = facet.getModule().getName();
            List<JpsArtifact> list = moduleName2Artifact.get(moduleName);
            if (list == null) {
                list = new ArrayList<JpsArtifact>();
                moduleName2Artifact.put(moduleName, list);
            }
            list.add(artifact);
        }
    }
    boolean success = true;
    if (debugArtifacts.size() > 0 && releaseArtifacts.size() > 0) {
        final String message = "Cannot build debug and release Android artifacts in the same session\n" + "Debug artifacts: " + artifactsToString(debugArtifacts) + "\n" + "Release artifacts: " + artifactsToString(releaseArtifacts);
        context.processMessage(new CompilerMessage(ANDROID_VALIDATOR, BuildMessage.Kind.ERROR, message));
        success = false;
    }
    if (releaseArtifacts.size() > 0 && AndroidJpsUtil.getRunConfigurationTypeId(context) != null) {
        final String message = "Cannot build release Android artifacts in the 'build before run' session\n" + "Release artifacts: " + artifactsToString(releaseArtifacts);
        context.processMessage(new CompilerMessage(ANDROID_VALIDATOR, BuildMessage.Kind.ERROR, message));
        success = false;
    }
    for (Map.Entry<String, List<JpsArtifact>> entry : moduleName2Artifact.entrySet()) {
        final List<JpsArtifact> list = entry.getValue();
        final String moduleName = entry.getKey();
        if (list.size() > 1) {
            final JpsArtifact firstArtifact = list.get(0);
            final Object[] firstArtifactProGuardOptions = getProGuardOptions(firstArtifact);
            for (int i = 1; i < list.size(); i++) {
                final JpsArtifact artifact = list.get(i);
                if (!Arrays.equals(getProGuardOptions(artifact), firstArtifactProGuardOptions)) {
                    context.processMessage(new CompilerMessage(ANDROID_VALIDATOR, BuildMessage.Kind.ERROR, "Artifacts related to the same module '" + moduleName + "' have different ProGuard options: " + firstArtifact.getName() + ", " + artifact.getName()));
                    success = false;
                    break;
                }
            }
        }
    }
    return success;
}
Also used : JpsElement(org.jetbrains.jps.model.JpsElement) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) HashMap(com.intellij.util.containers.HashMap) TObjectLongHashMap(gnu.trove.TObjectLongHashMap) JpsArtifact(org.jetbrains.jps.model.artifact.JpsArtifact) JpsAndroidApplicationArtifactProperties(org.jetbrains.jps.android.model.JpsAndroidApplicationArtifactProperties) JpsAndroidModuleExtension(org.jetbrains.jps.android.model.JpsAndroidModuleExtension) AndroidArtifactSigningMode(org.jetbrains.android.compiler.artifact.AndroidArtifactSigningMode) HashMap(com.intellij.util.containers.HashMap) TObjectLongHashMap(gnu.trove.TObjectLongHashMap) HashSet(com.intellij.util.containers.HashSet) THashSet(gnu.trove.THashSet)

Aggregations

CompilerMessage (org.jetbrains.jps.incremental.messages.CompilerMessage)75 File (java.io.File)34 IOException (java.io.IOException)22 ProgressMessage (org.jetbrains.jps.incremental.messages.ProgressMessage)18 JpsModule (org.jetbrains.jps.model.module.JpsModule)15 HashMap (com.intellij.util.containers.HashMap)11 JpsAndroidModuleExtension (org.jetbrains.jps.android.model.JpsAndroidModuleExtension)11 TObjectLongHashMap (gnu.trove.TObjectLongHashMap)9 ArrayList (java.util.ArrayList)9 THashSet (gnu.trove.THashSet)8 Nullable (org.jetbrains.annotations.Nullable)8 ProjectBuildException (org.jetbrains.jps.incremental.ProjectBuildException)8 IAndroidTarget (com.android.sdklib.IAndroidTarget)7 NotNull (org.jetbrains.annotations.NotNull)7 BuildMessage (org.jetbrains.jps.incremental.messages.BuildMessage)6 AndroidCompilerMessageKind (org.jetbrains.android.util.AndroidCompilerMessageKind)5 FailSafeClassReader (com.intellij.compiler.instrumentation.FailSafeClassReader)4 JpsDummyElement (org.jetbrains.jps.model.JpsDummyElement)4 Pair (com.intellij.openapi.util.Pair)3 THashMap (gnu.trove.THashMap)3