Search in sources :

Example 6 with BuildDataPaths

use of org.jetbrains.jps.builders.storage.BuildDataPaths in project intellij-community by JetBrains.

the class BuildRunner method load.

public ProjectDescriptor load(MessageHandler msgHandler, File dataStorageRoot, BuildFSState fsState) throws IOException {
    final JpsModel jpsModel = myModelLoader.loadModel();
    BuildDataPaths dataPaths = new BuildDataPathsImpl(dataStorageRoot);
    BuildTargetRegistryImpl targetRegistry = new BuildTargetRegistryImpl(jpsModel);
    ModuleExcludeIndex index = new ModuleExcludeIndexImpl(jpsModel);
    IgnoredFileIndexImpl ignoredFileIndex = new IgnoredFileIndexImpl(jpsModel);
    BuildRootIndexImpl buildRootIndex = new BuildRootIndexImpl(targetRegistry, jpsModel, index, dataPaths, ignoredFileIndex);
    BuildTargetIndexImpl targetIndex = new BuildTargetIndexImpl(targetRegistry, buildRootIndex);
    BuildTargetsState targetsState = new BuildTargetsState(dataPaths, jpsModel, buildRootIndex);
    ProjectTimestamps projectTimestamps = null;
    BuildDataManager dataManager = null;
    try {
        projectTimestamps = new ProjectTimestamps(dataStorageRoot, targetsState);
        dataManager = new BuildDataManager(dataPaths, targetsState, STORE_TEMP_CACHES_IN_MEMORY);
        if (dataManager.versionDiffers()) {
            myForceCleanCaches = true;
            msgHandler.processMessage(new CompilerMessage("build", BuildMessage.Kind.INFO, "Dependency data format has changed, project rebuild required"));
        }
    } catch (Exception e) {
        // second try
        LOG.info(e);
        if (projectTimestamps != null) {
            projectTimestamps.close();
        }
        if (dataManager != null) {
            dataManager.close();
        }
        myForceCleanCaches = true;
        FileUtil.delete(dataStorageRoot);
        targetsState = new BuildTargetsState(dataPaths, jpsModel, buildRootIndex);
        projectTimestamps = new ProjectTimestamps(dataStorageRoot, targetsState);
        dataManager = new BuildDataManager(dataPaths, targetsState, STORE_TEMP_CACHES_IN_MEMORY);
        // second attempt succeeded
        msgHandler.processMessage(new CompilerMessage("build", BuildMessage.Kind.INFO, "Project rebuild forced: " + e.getMessage()));
    }
    return new ProjectDescriptor(jpsModel, fsState, projectTimestamps, dataManager, BuildLoggingManager.DEFAULT, index, targetsState, targetIndex, buildRootIndex, ignoredFileIndex);
}
Also used : ProjectTimestamps(org.jetbrains.jps.incremental.storage.ProjectTimestamps) BuildTargetRegistryImpl(org.jetbrains.jps.builders.impl.BuildTargetRegistryImpl) JpsModel(org.jetbrains.jps.model.JpsModel) BuildRootIndexImpl(org.jetbrains.jps.builders.impl.BuildRootIndexImpl) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) IgnoredFileIndexImpl(org.jetbrains.jps.indices.impl.IgnoredFileIndexImpl) BuildTargetIndexImpl(org.jetbrains.jps.builders.impl.BuildTargetIndexImpl) BuildTargetsState(org.jetbrains.jps.incremental.storage.BuildTargetsState) IOException(java.io.IOException) BuildDataPaths(org.jetbrains.jps.builders.storage.BuildDataPaths) ModuleExcludeIndex(org.jetbrains.jps.indices.ModuleExcludeIndex) ModuleExcludeIndexImpl(org.jetbrains.jps.indices.impl.ModuleExcludeIndexImpl) BuildDataPathsImpl(org.jetbrains.jps.builders.impl.BuildDataPathsImpl) BuildDataManager(org.jetbrains.jps.incremental.storage.BuildDataManager)

Example 7 with BuildDataPaths

use of org.jetbrains.jps.builders.storage.BuildDataPaths in project intellij-community by JetBrains.

the class MavenResourcesBuilder method build.

@Override
public void build(@NotNull final MavenResourcesTarget target, @NotNull final DirtyFilesHolder<MavenResourceRootDescriptor, MavenResourcesTarget> holder, @NotNull final BuildOutputConsumer outputConsumer, @NotNull final CompileContext context) throws ProjectBuildException, IOException {
    final BuildDataPaths dataPaths = context.getProjectDescriptor().dataManager.getDataPaths();
    final MavenProjectConfiguration projectConfig = JpsMavenExtensionService.getInstance().getMavenProjectConfiguration(dataPaths);
    if (projectConfig == null) {
        context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, "Maven project configuration required for module '" + target.getModule().getName() + "' isn't available. Compilation of Maven projects is supported only if external build is started from an IDE."));
        throw new StopBuildException();
    }
    final MavenModuleResourceConfiguration config = target.getModuleResourcesConfiguration(dataPaths);
    if (config == null) {
        return;
    }
    final Map<MavenResourceRootDescriptor, List<File>> files = new HashMap<>();
    holder.processDirtyFiles(new FileProcessor<MavenResourceRootDescriptor, MavenResourcesTarget>() {

        @Override
        public boolean apply(MavenResourcesTarget t, File file, MavenResourceRootDescriptor rd) throws IOException {
            assert target == t;
            List<File> fileList = files.get(rd);
            if (fileList == null) {
                fileList = new ArrayList<>();
                files.put(rd, fileList);
            }
            fileList.add(file);
            return true;
        }
    });
    MavenResourceRootDescriptor[] roots = files.keySet().toArray(new MavenResourceRootDescriptor[files.keySet().size()]);
    Arrays.sort(roots, (r1, r2) -> {
        int res = r1.getIndexInPom() - r2.getIndexInPom();
        if (r1.isOverwrite()) {
            // 'overwrite' parameters is common for all roots in module.
            assert r2.isOverwrite();
            return res;
        }
        if (r1.getConfiguration().isFiltered && !r2.getConfiguration().isFiltered)
            return 1;
        if (!r1.getConfiguration().isFiltered && r2.getConfiguration().isFiltered)
            return -1;
        if (!r1.getConfiguration().isFiltered) {
            res = -res;
        }
        return res;
    });
    MavenResourceFileProcessor fileProcessor = new MavenResourceFileProcessor(projectConfig, target.getModule().getProject(), config);
    context.processMessage(new ProgressMessage("Copying resources... [" + target.getModule().getName() + "]"));
    for (MavenResourceRootDescriptor rd : roots) {
        for (File file : files.get(rd)) {
            String relPath = FileUtil.getRelativePath(rd.getRootFile(), file);
            if (relPath == null) {
                continue;
            }
            final String outputDirectory = target.isTests() ? config.testOutputDirectory : config.outputDirectory;
            final File outputDir = MavenResourcesTarget.getOutputDir(target.getModuleOutputDir(), rd.getConfiguration(), outputDirectory);
            if (outputDir == null) {
                continue;
            }
            File outputFile = new File(outputDir, relPath);
            String sourcePath = file.getPath();
            try {
                fileProcessor.copyFile(file, outputFile, rd.getConfiguration(), context, FileUtilRt.ALL_FILES);
                outputConsumer.registerOutputFile(outputFile, Collections.singleton(sourcePath));
            } catch (UnsupportedEncodingException e) {
                context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.INFO, "Resource was not copied: " + e.getMessage(), sourcePath));
            } catch (IOException e) {
                context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, "Failed to copy '" + sourcePath + "' to '" + outputFile.getAbsolutePath() + "': " + e.getMessage()));
                LOG.info(e);
            }
            if (context.getCancelStatus().isCanceled()) {
                return;
            }
        }
    }
    context.checkCanceled();
    context.processMessage(new ProgressMessage(""));
}
Also used : ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) BuildDataPaths(org.jetbrains.jps.builders.storage.BuildDataPaths) File(java.io.File) StopBuildException(org.jetbrains.jps.incremental.StopBuildException)

Example 8 with BuildDataPaths

use of org.jetbrains.jps.builders.storage.BuildDataPaths in project intellij-community by JetBrains.

the class MavenResourcesTarget method writeConfiguration.

@Override
public void writeConfiguration(ProjectDescriptor pd, PrintWriter out) {
    final BuildDataPaths dataPaths = pd.getTargetsState().getDataPaths();
    final MavenModuleResourceConfiguration configuration = getModuleResourcesConfiguration(dataPaths);
    if (configuration != null) {
        out.write(Integer.toHexString(configuration.computeConfigurationHash(isTests())));
    }
}
Also used : BuildDataPaths(org.jetbrains.jps.builders.storage.BuildDataPaths)

Example 9 with BuildDataPaths

use of org.jetbrains.jps.builders.storage.BuildDataPaths in project intellij-community by JetBrains.

the class GradleResourcesTarget method writeConfiguration.

@Override
public void writeConfiguration(ProjectDescriptor pd, PrintWriter out) {
    final BuildDataPaths dataPaths = pd.getTargetsState().getDataPaths();
    final GradleModuleResourceConfiguration configuration = getModuleResourcesConfiguration(dataPaths);
    if (configuration != null) {
        out.write(Integer.toHexString(configuration.computeConfigurationHash(isTests())));
    }
}
Also used : BuildDataPaths(org.jetbrains.jps.builders.storage.BuildDataPaths)

Example 10 with BuildDataPaths

use of org.jetbrains.jps.builders.storage.BuildDataPaths in project android by JetBrains.

the class AndroidPackagingBuilder method doPackagingForModule.

private static boolean doPackagingForModule(@NotNull CompileContext context, @NotNull JpsModule module, @NotNull AndroidApkBuilderConfigStateStorage apkBuilderConfigStateStorage, @NotNull AndroidPackagingStateStorage packagingStateStorage, boolean release, boolean hasDirtyFiles, @NotNull BuildOutputConsumer outputConsumer) throws IOException {
    final JpsAndroidModuleExtension extension = AndroidJpsUtil.getExtension(module);
    if (extension == null || extension.isLibrary()) {
        return true;
    }
    final String[] resourceRoots = AndroidJpsUtil.toPaths(AndroidJpsUtil.getJavaOutputRootsForModuleAndDependencies(module));
    Arrays.sort(resourceRoots);
    final File moduleOutputDir = ProjectPaths.getModuleOutputDir(module, false);
    if (moduleOutputDir == null) {
        context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.errors.output.dir.not.specified", module.getName())));
        return false;
    }
    final AndroidPlatform platform = AndroidJpsUtil.getAndroidPlatform(module, context, BUILDER_NAME);
    if (platform == null) {
        return false;
    }
    final Set<String> externalJarsSet = new HashSet<String>();
    for (String jarPath : AndroidJpsUtil.getExternalLibraries(context, module, platform)) {
        if (new File(jarPath).exists()) {
            externalJarsSet.add(jarPath);
        }
    }
    final BuildDataPaths dataPaths = context.getProjectDescriptor().dataManager.getDataPaths();
    final File resPackage = AndroidResourcePackagingBuildTarget.getOutputFile(dataPaths, module);
    final File classesDexFile = AndroidDexBuildTarget.getOutputFile(dataPaths, module);
    final String sdkPath = platform.getSdk().getHomePath();
    final String outputPath = AndroidJpsUtil.getApkPath(extension, moduleOutputDir);
    if (outputPath == null) {
        context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.errors.cannot.compute.output.apk", module.getName())));
        return false;
    }
    final String customKeyStorePath = FileUtil.toSystemDependentName(extension.getCustomDebugKeyStorePath());
    final String[] nativeLibDirs = AndroidPackagingBuildTarget.collectNativeLibsFolders(extension, true);
    final String resPackagePath = resPackage.getPath();
    final String classesDexFilePath = classesDexFile.getPath();
    final String[] externalJars = ArrayUtil.toStringArray(externalJarsSet);
    Arrays.sort(externalJars);
    final List<AndroidNativeLibData> additionalNativeLibs = extension.getAdditionalNativeLibs();
    final AndroidApkBuilderConfigState currentApkBuilderConfigState = new AndroidApkBuilderConfigState(outputPath, customKeyStorePath, additionalNativeLibs);
    if (!hasDirtyFiles) {
        final AndroidApkBuilderConfigState savedApkBuilderConfigState = apkBuilderConfigStateStorage.getState(module.getName());
        final AndroidPackagingStateStorage.MyState packagingState = packagingStateStorage.read();
        if (currentApkBuilderConfigState.equalsTo(savedApkBuilderConfigState) && packagingState != null && packagingState.isRelease() == release) {
            return true;
        }
    }
    context.processMessage(new ProgressMessage(AndroidJpsBundle.message("android.jps.progress.packaging", AndroidJpsUtil.getApkName(module))));
    final Map<AndroidCompilerMessageKind, List<String>> messages = AndroidApkBuilder.execute(resPackagePath, classesDexFilePath, resourceRoots, externalJars, nativeLibDirs, additionalNativeLibs, outputPath, release, sdkPath, platform.getTarget(), customKeyStorePath, new MyExcludedSourcesFilter(context.getProjectDescriptor().getProject()));
    if (messages.get(AndroidCompilerMessageKind.ERROR).size() == 0) {
        final List<String> srcFiles = new ArrayList<String>();
        srcFiles.add(resPackagePath);
        srcFiles.add(classesDexFilePath);
        for (String resourceRoot : resourceRoots) {
            FileUtil.processFilesRecursively(new File(resourceRoot), new Processor<File>() {

                @Override
                public boolean process(File file) {
                    if (file.isFile() && AndroidApkBuilder.checkFileForPackaging(file)) {
                        srcFiles.add(file.getPath());
                    }
                    return true;
                }
            });
        }
        Collections.addAll(srcFiles, externalJars);
        for (String nativeLibDir : nativeLibDirs) {
            FileUtil.processFilesRecursively(new File(nativeLibDir), new Processor<File>() {

                @Override
                public boolean process(File file) {
                    if (file.isFile()) {
                        srcFiles.add(file.getPath());
                    }
                    return true;
                }
            });
        }
        outputConsumer.registerOutputFile(new File(outputPath), srcFiles);
    }
    AndroidJpsUtil.addMessages(context, messages, BUILDER_NAME, module.getName());
    final boolean success = messages.get(AndroidCompilerMessageKind.ERROR).isEmpty();
    apkBuilderConfigStateStorage.update(module.getName(), success ? currentApkBuilderConfigState : null);
    packagingStateStorage.saveState(new AndroidPackagingStateStorage.MyState(release));
    return success;
}
Also used : ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) AndroidCompilerMessageKind(org.jetbrains.android.util.AndroidCompilerMessageKind) AndroidNativeLibData(org.jetbrains.android.util.AndroidNativeLibData) BuildDataPaths(org.jetbrains.jps.builders.storage.BuildDataPaths) JpsAndroidModuleExtension(org.jetbrains.jps.android.model.JpsAndroidModuleExtension) File(java.io.File) HashSet(com.intellij.util.containers.HashSet)

Aggregations

BuildDataPaths (org.jetbrains.jps.builders.storage.BuildDataPaths)11 IOException (java.io.IOException)5 File (java.io.File)4 BuildDataPathsImpl (org.jetbrains.jps.builders.impl.BuildDataPathsImpl)4 BuildRootIndexImpl (org.jetbrains.jps.builders.impl.BuildRootIndexImpl)4 BuildTargetRegistryImpl (org.jetbrains.jps.builders.impl.BuildTargetRegistryImpl)4 ModuleExcludeIndex (org.jetbrains.jps.indices.ModuleExcludeIndex)4 IgnoredFileIndexImpl (org.jetbrains.jps.indices.impl.IgnoredFileIndexImpl)4 ModuleExcludeIndexImpl (org.jetbrains.jps.indices.impl.ModuleExcludeIndexImpl)4 BuildTargetIndexImpl (org.jetbrains.jps.builders.impl.BuildTargetIndexImpl)3 CompilerMessage (org.jetbrains.jps.incremental.messages.CompilerMessage)3 ProgressMessage (org.jetbrains.jps.incremental.messages.ProgressMessage)3 BuildDataManager (org.jetbrains.jps.incremental.storage.BuildDataManager)3 BuildTargetsState (org.jetbrains.jps.incremental.storage.BuildTargetsState)3 ProjectTimestamps (org.jetbrains.jps.incremental.storage.ProjectTimestamps)3 ProjectDescriptor (org.jetbrains.jps.cmdline.ProjectDescriptor)2 BuildFSState (org.jetbrains.jps.incremental.fs.BuildFSState)2 MavenModuleResourceConfiguration (org.jetbrains.jps.maven.model.impl.MavenModuleResourceConfiguration)2 MavenProjectConfiguration (org.jetbrains.jps.maven.model.impl.MavenProjectConfiguration)2 HashSet (com.intellij.util.containers.HashSet)1