Search in sources :

Example 16 with ProgressMessage

use of org.jetbrains.jps.incremental.messages.ProgressMessage in project intellij-community by JetBrains.

the class OutputFilesSink method save.

public void save(@NotNull final OutputFileObject fileObject) {
    final BinaryContent content = fileObject.getContent();
    final File srcFile = fileObject.getSourceFile();
    boolean isTemp = false;
    final JavaFileObject.Kind outKind = fileObject.getKind();
    if (srcFile != null && content != null) {
        final String sourcePath = FileUtil.toSystemIndependentName(srcFile.getPath());
        final JavaSourceRootDescriptor rootDescriptor = myContext.getProjectDescriptor().getBuildRootIndex().findJavaRootDescriptor(myContext, srcFile);
        try {
            if (rootDescriptor != null) {
                isTemp = rootDescriptor.isTemp;
                if (!isTemp) {
                    // first, handle [src->output] mapping and register paths for files_generated event
                    if (outKind == JavaFileObject.Kind.CLASS) {
                        // todo: avoid array copying?
                        myOutputConsumer.registerCompiledClass(rootDescriptor.target, new CompiledClass(fileObject.getFile(), srcFile, fileObject.getClassName(), content));
                    } else {
                        myOutputConsumer.registerOutputFile(rootDescriptor.target, fileObject.getFile(), Collections.<String>singleton(sourcePath));
                    }
                }
            } else {
                // was not able to determine the source root descriptor or the source root is excluded from compilation (e.g. for annotation processors)
                if (outKind == JavaFileObject.Kind.CLASS) {
                    myOutputConsumer.registerCompiledClass(null, new CompiledClass(fileObject.getFile(), srcFile, fileObject.getClassName(), content));
                }
            }
        } catch (IOException e) {
            myContext.processMessage(new CompilerMessage(JavaBuilder.BUILDER_NAME, e));
        }
        if (!isTemp && outKind == JavaFileObject.Kind.CLASS) {
            // register in mappings any non-temp class file
            try {
                final ClassReader reader = new FailSafeClassReader(content.getBuffer(), content.getOffset(), content.getLength());
                myMappingsCallback.associate(FileUtil.toSystemIndependentName(fileObject.getFile().getPath()), sourcePath, reader);
            } catch (Throwable e) {
                // need this to make sure that unexpected errors in, for example, ASM will not ruin the compilation  
                final String message = "Class dependency information may be incomplete! Error parsing generated class " + fileObject.getFile().getPath();
                LOG.info(message, e);
                myContext.processMessage(new CompilerMessage(JavaBuilder.BUILDER_NAME, BuildMessage.Kind.WARNING, message + "\n" + CompilerMessage.getTextFromThrowable(e), sourcePath));
            }
        }
    }
    if (outKind == JavaFileObject.Kind.CLASS) {
        myContext.processMessage(new ProgressMessage("Writing classes... " + myChunkName));
        if (!isTemp && srcFile != null) {
            mySuccessfullyCompiled.add(srcFile);
        }
    }
}
Also used : ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) CompiledClass(org.jetbrains.jps.incremental.CompiledClass) IOException(java.io.IOException) BinaryContent(org.jetbrains.jps.incremental.BinaryContent) FailSafeClassReader(com.intellij.compiler.instrumentation.FailSafeClassReader) ClassReader(org.jetbrains.org.objectweb.asm.ClassReader) JavaSourceRootDescriptor(org.jetbrains.jps.builders.java.JavaSourceRootDescriptor) File(java.io.File) FailSafeClassReader(com.intellij.compiler.instrumentation.FailSafeClassReader)

Example 17 with ProgressMessage

use of org.jetbrains.jps.incremental.messages.ProgressMessage in project intellij-community by JetBrains.

the class ResourcesBuilder method copyResource.

private static void copyResource(CompileContext context, ResourceRootDescriptor rd, File file, BuildOutputConsumer outputConsumer) throws IOException {
    final File outputRoot = rd.getTarget().getOutputDir();
    if (outputRoot == null) {
        return;
    }
    final String sourceRootPath = FileUtil.toSystemIndependentName(rd.getRootFile().getAbsolutePath());
    final String relativePath = FileUtil.getRelativePath(sourceRootPath, FileUtil.toSystemIndependentName(file.getPath()), '/');
    final String prefix = rd.getPackagePrefix();
    final StringBuilder targetPath = new StringBuilder();
    targetPath.append(FileUtil.toSystemIndependentName(outputRoot.getPath()));
    if (prefix.length() > 0) {
        targetPath.append('/').append(prefix.replace('.', '/'));
    }
    targetPath.append('/').append(relativePath);
    context.processMessage(new ProgressMessage("Copying resources... [" + rd.getTarget().getModule().getName() + "]"));
    final String outputPath = targetPath.toString();
    final File targetFile = new File(outputPath);
    FileUtil.copyContent(file, targetFile);
    try {
        outputConsumer.registerOutputFile(targetFile, Collections.singletonList(file.getPath()));
    } catch (Exception e) {
        context.processMessage(new CompilerMessage(BUILDER_NAME, e));
    }
}
Also used : ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) File(java.io.File) IOException(java.io.IOException) ProjectBuildException(org.jetbrains.jps.incremental.ProjectBuildException) BuildDataCorruptedException(org.jetbrains.jps.builders.storage.BuildDataCorruptedException)

Example 18 with ProgressMessage

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

the class AndroidGradleTargetBuilder method build.

/**
   * Builds a Gradle-based Android project using Gradle.
   */
@Override
public void build(@NotNull AndroidGradleBuildTarget target, @NotNull DirtyFilesHolder<AndroidGradleBuildTarget.RootDescriptor, AndroidGradleBuildTarget> holder, @NotNull BuildOutputConsumer outputConsumer, @NotNull CompileContext context) throws ProjectBuildException, IOException {
    JpsProject project = target.getProject();
    checkUnsupportedModules(project, context);
    BuilderExecutionSettings executionSettings;
    try {
        executionSettings = new BuilderExecutionSettings();
    } catch (RuntimeException e) {
        throw new ProjectBuildException(e);
    }
    LOG.info("Using execution settings: " + executionSettings);
    List<String> buildTasks = executionSettings.getGradleTasksToInvoke();
    if (buildTasks.isEmpty()) {
        String format = "No build tasks found for project '%1$s'. Nothing done.";
        LOG.info(String.format(format, project.getName()));
        return;
    }
    context.processMessage(AndroidGradleJps.createCompilerMessage(BuildMessage.Kind.INFO, "Executing tasks: " + buildTasks));
    String msg = "Gradle build using tasks: " + buildTasks;
    context.processMessage(new ProgressMessage(msg));
    LOG.info(msg);
    ensureTempDirExists();
    String androidHome = null;
    if (!AndroidGradleSettings.isAndroidSdkDirInLocalPropertiesFile(executionSettings.getProjectDir())) {
        androidHome = getAndroidHomeFromModuleSdk(project);
    }
    String format = "About to build project '%1$s' located at %2$s";
    LOG.info(String.format(format, project.getName(), executionSettings.getProjectDir().getAbsolutePath()));
    doBuild(context, buildTasks, executionSettings, androidHome);
}
Also used : ProjectBuildException(org.jetbrains.jps.incremental.ProjectBuildException) ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) JpsProject(org.jetbrains.jps.model.JpsProject)

Example 19 with ProgressMessage

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

the class AndroidAarDepsBuilder method doBuild.

private static boolean doBuild(final CompileContext context, AndroidAarDepsBuildTarget target, BuildOutputConsumer outputConsumer) {
    final JpsModule module = target.getModule();
    final JpsAndroidModuleExtension extension = AndroidJpsUtil.getExtension(module);
    if (extension == null || extension.isLibrary()) {
        return true;
    }
    File outputDir = AndroidJpsUtil.getDirectoryForIntermediateArtifacts(context, module);
    outputDir = AndroidJpsUtil.createDirIfNotExist(outputDir, context, BUILDER_NAME);
    if (outputDir == null) {
        return false;
    }
    final List<String> srcJarFiles = new ArrayList<String>();
    for (BuildRootDescriptor descriptor : context.getProjectDescriptor().getBuildRootIndex().getTargetRoots(target, context)) {
        final File file = descriptor.getRootFile();
        if (file.exists()) {
            srcJarFiles.add(file.getPath());
        }
    }
    if (srcJarFiles.size() == 0) {
        return true;
    }
    context.processMessage(new ProgressMessage(AndroidJpsBundle.message("android.jps.progress.aar.dependencies.packaging", module.getName())));
    File tempDir = null;
    try {
        tempDir = FileUtil.createTempDirectory("extracted_aar_deps", "tmp");
        for (int i = srcJarFiles.size() - 1; i >= 0; i--) {
            ZipUtil.extract(new File(srcJarFiles.get(i)), tempDir, null, true);
        }
        final File outputJarFile = new File(outputDir, AndroidCommonUtils.AAR_DEPS_JAR_FILE_NAME);
        if (!packDirectoryIntoJar(tempDir, outputJarFile, context)) {
            return false;
        }
        final AndroidBuildTestingManager testingManager = AndroidBuildTestingManager.getTestingManager();
        if (testingManager != null && outputJarFile.isFile()) {
            testingManager.getCommandExecutor().checkJarContent("aar_dependencies_package_jar", outputJarFile.getPath());
        }
        outputConsumer.registerOutputFile(outputJarFile, srcJarFiles);
        return true;
    } catch (IOException e) {
        AndroidJpsUtil.reportExceptionError(context, null, e, BUILDER_NAME);
        return false;
    } finally {
        if (tempDir != null) {
            FileUtil.delete(tempDir);
        }
    }
}
Also used : JpsModule(org.jetbrains.jps.model.module.JpsModule) BuildRootDescriptor(org.jetbrains.jps.builders.BuildRootDescriptor) ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) AndroidBuildTestingManager(org.jetbrains.android.util.AndroidBuildTestingManager) JpsAndroidModuleExtension(org.jetbrains.jps.android.model.JpsAndroidModuleExtension) ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File)

Example 20 with ProgressMessage

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

the class AndroidResourcePackagingBuilder method packageResources.

private static boolean packageResources(@NotNull AndroidResourcePackagingBuildTarget target, @NotNull CompileContext context, @NotNull BuildOutputConsumer outputConsumer, boolean releaseBuild) {
    final JpsModule module = target.getModule();
    final JpsAndroidModuleExtension extension = AndroidJpsUtil.getExtension(module);
    assert extension != null && !extension.isLibrary();
    context.processMessage(new ProgressMessage(AndroidJpsBundle.message("android.jps.progress.packaging.resources", module.getName())));
    final File manifestFile = AndroidJpsUtil.getPreprocessedManifestFile(extension, context.getProjectDescriptor().dataManager.getDataPaths());
    if (manifestFile == null || !manifestFile.exists()) {
        context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.errors.manifest.not.found", module.getName())));
        return false;
    }
    final ArrayList<String> assetsDirPaths = new ArrayList<String>();
    AndroidResourcePackagingBuildTarget.collectAssetDirs(extension, assetsDirPaths, true);
    final String outputFilePath = target.getOutputFile(context).getPath();
    File outputDir = new File(outputFilePath).getParentFile();
    assert outputDir != null;
    outputDir = AndroidJpsUtil.createDirIfNotExist(outputDir, context, BUILDER_NAME);
    if (outputDir == null) {
        return false;
    }
    final AndroidPlatform platform = AndroidJpsUtil.getAndroidPlatform(module, context, BUILDER_NAME);
    if (platform == null) {
        return false;
    }
    final IAndroidTarget androidTarget = platform.getTarget();
    final String[] resourceDirPaths = AndroidJpsUtil.collectResourceDirsForCompilation(extension, true, context, true);
    final String customManifestPackage = extension.isUseCustomManifestPackage() ? extension.getCustomManifestPackage() : null;
    final String additionalParameters = extension.getAdditionalPackagingCommandLineParameters();
    return doPackageResources(context, manifestFile, androidTarget, resourceDirPaths, ArrayUtil.toStringArray(assetsDirPaths), outputFilePath, releaseBuild, module.getName(), outputConsumer, customManifestPackage, additionalParameters);
}
Also used : JpsModule(org.jetbrains.jps.model.module.JpsModule) ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) JpsAndroidModuleExtension(org.jetbrains.jps.android.model.JpsAndroidModuleExtension) ArrayList(java.util.ArrayList) IAndroidTarget(com.android.sdklib.IAndroidTarget) File(java.io.File)

Aggregations

ProgressMessage (org.jetbrains.jps.incremental.messages.ProgressMessage)32 File (java.io.File)20 CompilerMessage (org.jetbrains.jps.incremental.messages.CompilerMessage)17 IOException (java.io.IOException)14 JpsModule (org.jetbrains.jps.model.module.JpsModule)10 THashSet (gnu.trove.THashSet)8 JpsAndroidModuleExtension (org.jetbrains.jps.android.model.JpsAndroidModuleExtension)7 ProjectBuildException (org.jetbrains.jps.incremental.ProjectBuildException)5 IAndroidTarget (com.android.sdklib.IAndroidTarget)4 HashMap (com.intellij.util.containers.HashMap)4 TObjectLongHashMap (gnu.trove.TObjectLongHashMap)4 ArrayList (java.util.ArrayList)4 ProjectBuilderLogger (org.jetbrains.jps.builders.logging.ProjectBuilderLogger)4 Pair (com.intellij.openapi.util.Pair)3 HashSet (com.intellij.util.containers.HashSet)3 AndroidBuildTestingManager (org.jetbrains.android.util.AndroidBuildTestingManager)3 BuildRootDescriptor (org.jetbrains.jps.builders.BuildRootDescriptor)3 JavaSourceRootDescriptor (org.jetbrains.jps.builders.java.JavaSourceRootDescriptor)3 BuildDataCorruptedException (org.jetbrains.jps.builders.storage.BuildDataCorruptedException)3 JpsProject (org.jetbrains.jps.model.JpsProject)3