Search in sources :

Example 6 with ProjectBuildException

use of org.jetbrains.jps.incremental.ProjectBuildException 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 7 with ProjectBuildException

use of org.jetbrains.jps.incremental.ProjectBuildException in project intellij-plugins by JetBrains.

the class FlexResourceBuilder method build.

public void build(@NotNull final FlexResourceBuildTarget target, @NotNull final DirtyFilesHolder<BuildRootDescriptor, FlexResourceBuildTarget> holder, @NotNull final BuildOutputConsumer outputConsumer, @NotNull final CompileContext context) throws ProjectBuildException, IOException {
    final JpsJavaCompilerConfiguration configuration = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(target.getModule().getProject());
    final JpsCompilerExcludes excludes = configuration.getCompilerExcludes();
    try {
        holder.processDirtyFiles(new FileProcessor<BuildRootDescriptor, FlexResourceBuildTarget>() {

            public boolean apply(final FlexResourceBuildTarget target, final File file, final BuildRootDescriptor root) throws IOException {
                if (excludes.isExcluded(file))
                    return true;
                final String relativePath = FileUtil.toSystemIndependentName(FileUtil.getRelativePath(root.getRootFile(), file));
                if (target.isTests()) {
                    if (!FlexCommonUtils.isSourceFile(file.getName())) {
                        final String outputRootUrl = JpsJavaExtensionService.getInstance().getOutputUrl(target.getModule(), target.isTests());
                        if (outputRootUrl == null)
                            return true;
                        final String targetPath = JpsPathUtil.urlToPath(outputRootUrl) + '/' + relativePath;
                        context.processMessage(new ProgressMessage("Copying " + file.getPath()));
                        copyResource(context, file, Collections.singleton(targetPath), outputConsumer);
                    }
                } else {
                    final Collection<String> targetPaths = new ArrayList<>();
                    for (JpsFlexBuildConfiguration bc : target.getModule().getProperties().getBuildConfigurations()) {
                        if (bc.isSkipCompile() || !FlexCommonUtils.canHaveResourceFiles(bc.getNature()) || bc.getCompilerOptions().getResourceFilesMode() == JpsFlexCompilerOptions.ResourceFilesMode.None) {
                            continue;
                        }
                        final JpsFlexCompilerOptions.ResourceFilesMode mode = bc.getCompilerOptions().getResourceFilesMode();
                        if (mode == JpsFlexCompilerOptions.ResourceFilesMode.All && !FlexCommonUtils.isSourceFile(file.getName()) || mode == JpsFlexCompilerOptions.ResourceFilesMode.ResourcePatterns && configuration.isResourceFile(file, root.getRootFile())) {
                            final String outputFolder = PathUtilRt.getParentPath(bc.getActualOutputFilePath());
                            targetPaths.add(outputFolder + "/" + relativePath);
                        }
                    }
                    if (!targetPaths.isEmpty()) {
                        context.processMessage(new ProgressMessage("Copying " + file.getPath()));
                        copyResource(context, file, targetPaths, outputConsumer);
                    }
                }
                return true;
            }
        });
    } catch (Exception e) {
        throw new ProjectBuildException(e.getMessage(), e);
    }
}
Also used : ProjectBuildException(org.jetbrains.jps.incremental.ProjectBuildException) JpsJavaCompilerConfiguration(org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration) BuildRootDescriptor(org.jetbrains.jps.builders.BuildRootDescriptor) ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) IOException(java.io.IOException) FlexResourceBuildTarget(com.intellij.flex.build.FlexResourceBuildTarget) IOException(java.io.IOException) ProjectBuildException(org.jetbrains.jps.incremental.ProjectBuildException) JpsCompilerExcludes(org.jetbrains.jps.model.java.compiler.JpsCompilerExcludes) Collection(java.util.Collection) JpsFlexBuildConfiguration(com.intellij.flex.model.bc.JpsFlexBuildConfiguration) File(java.io.File)

Example 8 with ProjectBuildException

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

the class FileBasedArtifactRootDescriptor method copyFromRoot.

public void copyFromRoot(String filePath, int rootIndex, String outputPath, CompileContext context, BuildOutputConsumer outputConsumer, ArtifactOutputToSourceMapping outSrcMapping) throws IOException, ProjectBuildException {
    final File file = new File(filePath);
    if (!file.exists())
        return;
    String targetPath;
    if (!FileUtil.filesEqual(file, getRootFile())) {
        final String relativePath = FileUtil.getRelativePath(FileUtil.toSystemIndependentName(getRootFile().getPath()), filePath, '/');
        if (relativePath == null || relativePath.startsWith("..")) {
            throw new ProjectBuildException(new AssertionError(filePath + " is not under " + getRootFile().getPath()));
        }
        targetPath = JpsArtifactPathUtil.appendToPath(outputPath, relativePath);
    } else {
        targetPath = outputPath;
    }
    final File targetFile = new File(targetPath);
    if (FileUtil.filesEqual(file, targetFile)) {
        //do not process file if should be copied to itself. Otherwise the file will be included to source-to-output mapping and will be deleted by rebuild
        return;
    }
    if (outSrcMapping.getState(targetPath) == null) {
        ProjectBuilderLogger logger = context.getLoggingManager().getProjectBuilderLogger();
        if (logger.isEnabled()) {
            logger.logCompiledFiles(Collections.singletonList(file), IncArtifactBuilder.BUILDER_NAME, "Copying file:");
        }
        myCopyingHandler.copyFile(file, targetFile, context);
        outputConsumer.registerOutputFile(targetFile, Collections.singletonList(filePath));
    } else if (LOG.isDebugEnabled()) {
        LOG.debug("Target path " + targetPath + " is already registered so " + filePath + " won't be copied");
    }
    outSrcMapping.appendData(targetPath, rootIndex, filePath);
}
Also used : ProjectBuildException(org.jetbrains.jps.incremental.ProjectBuildException) ProjectBuilderLogger(org.jetbrains.jps.builders.logging.ProjectBuilderLogger) File(java.io.File)

Example 9 with ProjectBuildException

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

the class ResourcesBuilder method build.

@Override
public void build(@NotNull ResourcesTarget target, @NotNull DirtyFilesHolder<ResourceRootDescriptor, ResourcesTarget> holder, @NotNull final BuildOutputConsumer outputConsumer, @NotNull final CompileContext context) throws ProjectBuildException, IOException {
    if (!isResourceProcessingEnabled(target.getModule())) {
        return;
    }
    try {
        holder.processDirtyFiles(new FileProcessor<ResourceRootDescriptor, ResourcesTarget>() {

            private final Map<ResourceRootDescriptor, Boolean> mySkippedRoots = new HashMap<>();

            public boolean apply(ResourcesTarget target, final File file, final ResourceRootDescriptor sourceRoot) throws IOException {
                Boolean isSkipped = mySkippedRoots.get(sourceRoot);
                if (isSkipped == null) {
                    final File outputDir = target.getOutputDir();
                    isSkipped = Boolean.valueOf(outputDir == null || FileUtil.filesEqual(outputDir, sourceRoot.getRootFile()));
                    mySkippedRoots.put(sourceRoot, isSkipped);
                }
                if (isSkipped.booleanValue()) {
                    return true;
                }
                try {
                    copyResource(context, sourceRoot, file, outputConsumer);
                } catch (IOException e) {
                    LOG.info(e);
                    context.processMessage(new CompilerMessage("resources", BuildMessage.Kind.ERROR, e.getMessage(), FileUtil.toSystemIndependentName(file.getPath())));
                    return false;
                }
                return !context.getCancelStatus().isCanceled();
            }
        });
        context.checkCanceled();
        context.processMessage(new ProgressMessage(""));
    } catch (BuildDataCorruptedException | ProjectBuildException e) {
        throw e;
    } catch (Exception e) {
        throw new ProjectBuildException(e.getMessage(), e);
    }
}
Also used : ProjectBuildException(org.jetbrains.jps.incremental.ProjectBuildException) ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) IOException(java.io.IOException) IOException(java.io.IOException) ProjectBuildException(org.jetbrains.jps.incremental.ProjectBuildException) BuildDataCorruptedException(org.jetbrains.jps.builders.storage.BuildDataCorruptedException) BuildDataCorruptedException(org.jetbrains.jps.builders.storage.BuildDataCorruptedException) ResourcesTarget(org.jetbrains.jps.incremental.ResourcesTarget) ResourceRootDescriptor(org.jetbrains.jps.builders.java.ResourceRootDescriptor) File(java.io.File)

Example 10 with ProjectBuildException

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

the class JpsGroovycRunner method doBuild.

@NotNull
ExitCode doBuild(CompileContext context, ModuleChunk chunk, DirtyFilesHolder<R, T> dirtyFilesHolder, Builder builder, GroovyOutputConsumer outputConsumer) throws ProjectBuildException {
    long start = 0;
    try {
        JpsGroovySettings settings = JpsGroovySettings.getSettings(context.getProjectDescriptor().getProject());
        Ref<Boolean> hasStubExcludes = Ref.create(false);
        final List<File> toCompile = collectChangedFiles(context, dirtyFilesHolder, myForStubs, false, hasStubExcludes);
        if (toCompile.isEmpty()) {
            return ExitCode.NOTHING_DONE;
        }
        if (Utils.IS_TEST_MODE || LOG.isDebugEnabled()) {
            LOG.info("forStubs=" + myForStubs);
        }
        Map<T, String> finalOutputs = getCanonicalOutputs(context, chunk, builder);
        if (finalOutputs == null) {
            return ExitCode.ABORT;
        }
        start = System.currentTimeMillis();
        Map<T, String> generationOutputs = getGenerationOutputs(context, chunk, finalOutputs);
        String compilerOutput = generationOutputs.get(representativeTarget(generationOutputs));
        GroovycOutputParser parser = runGroovycOrContinuation(context, chunk, settings, finalOutputs, compilerOutput, toCompile, hasStubExcludes.get());
        MultiMap<T, GroovycOutputParser.OutputItem> compiled = processCompiledFiles(context, chunk, generationOutputs, compilerOutput, parser.getSuccessfullyCompiled());
        if (checkChunkRebuildNeeded(context, parser)) {
            clearContinuation(context, chunk);
            return ExitCode.CHUNK_REBUILD_REQUIRED;
        }
        for (CompilerMessage message : parser.getCompilerMessages()) {
            context.processMessage(message);
        }
        if (myForStubs) {
            stubsGenerated(context, generationOutputs, compiled);
        } else {
            updateDependencies(context, toCompile, compiled, outputConsumer, builder);
        }
        return ExitCode.OK;
    } catch (Exception e) {
        throw new ProjectBuildException(e);
    } finally {
        if (start > 0 && LOG.isDebugEnabled()) {
            LOG.debug(builder.getPresentableName() + " took " + (System.currentTimeMillis() - start) + " on " + chunk.getName());
        }
    }
}
Also used : ProjectBuildException(org.jetbrains.jps.incremental.ProjectBuildException) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) IOException(java.io.IOException) ProjectBuildException(org.jetbrains.jps.incremental.ProjectBuildException) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ProjectBuildException (org.jetbrains.jps.incremental.ProjectBuildException)14 File (java.io.File)8 CompilerMessage (org.jetbrains.jps.incremental.messages.CompilerMessage)7 IOException (java.io.IOException)5 ProgressMessage (org.jetbrains.jps.incremental.messages.ProgressMessage)5 BaseOSProcessHandler (com.intellij.execution.process.BaseOSProcessHandler)3 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)3 NotNull (org.jetbrains.annotations.NotNull)3 JpsDummyElement (org.jetbrains.jps.model.JpsDummyElement)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 URL (java.net.URL)2 JpsProject (org.jetbrains.jps.model.JpsProject)2 Message (com.android.ide.common.blame.Message)1 PatternAwareOutputParser (com.android.ide.common.blame.parser.PatternAwareOutputParser)1 BuildOutputParser (com.android.tools.idea.gradle.output.parser.BuildOutputParser)1 BuildMode (com.android.tools.idea.gradle.util.BuildMode)1 ExecutionException (com.intellij.execution.ExecutionException)1 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)1 FlexResourceBuildTarget (com.intellij.flex.build.FlexResourceBuildTarget)1 JpsFlexBuildConfiguration (com.intellij.flex.model.bc.JpsFlexBuildConfiguration)1