Search in sources :

Example 1 with BuildRootDescriptor

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

the class ChainedTargetsBuildListener method filesDeleted.

@Override
public void filesDeleted(FileDeletedEvent event) {
    final BuildFSState state = myContext.getProjectDescriptor().fsState;
    final BuildRootIndex rootsIndex = myContext.getProjectDescriptor().getBuildRootIndex();
    for (String path : event.getFilePaths()) {
        final File file = new File(FileUtil.toSystemDependentName(path));
        for (BuildRootDescriptor desc : rootsIndex.findAllParentDescriptors(file, myContext)) {
            state.registerDeleted(myContext, desc.getTarget(), file);
        }
    }
}
Also used : BuildFSState(org.jetbrains.jps.incremental.fs.BuildFSState) BuildRootDescriptor(org.jetbrains.jps.builders.BuildRootDescriptor) BuildRootIndex(org.jetbrains.jps.builders.BuildRootIndex) File(java.io.File)

Example 2 with BuildRootDescriptor

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

the class AndroidDexBuilder method runProguardIfNecessary.

private static Pair<Boolean, AndroidProGuardStateStorage.MyState> runProguardIfNecessary(@NotNull JpsAndroidModuleExtension extension, @NotNull AndroidDexBuildTarget target, @NotNull AndroidPlatform platform, @NotNull CompileContext context, @NotNull String outputJarPath, @NotNull String[] proguardCfgPaths, boolean hasDirtyFiles, @Nullable AndroidProGuardStateStorage.MyState oldState) throws IOException {
    final JpsModule module = extension.getModule();
    final File[] proguardCfgFiles = new File[proguardCfgPaths.length];
    for (int i = 0; i < proguardCfgFiles.length; i++) {
        proguardCfgFiles[i] = new File(proguardCfgPaths[i]);
        if (!proguardCfgFiles[i].exists()) {
            context.processMessage(new CompilerMessage(PRO_GUARD_BUILDER_NAME, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.cannot.find.file", proguardCfgPaths[i])));
            return null;
        }
    }
    final File mainContentRoot = AndroidJpsUtil.getMainContentRoot(extension);
    if (mainContentRoot == null) {
        context.processMessage(new CompilerMessage(PRO_GUARD_BUILDER_NAME, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.errors.main.content.root.not.found", module.getName())));
        return null;
    }
    final String javaExecutable = getJavaExecutable(platform, context, PRO_GUARD_BUILDER_NAME);
    if (javaExecutable == null) {
        return null;
    }
    final File proguardLogsDir = extension.getProguardLogsDir();
    final File logsDir;
    if (proguardLogsDir != null) {
        logsDir = proguardLogsDir;
    } else {
        logsDir = new File(mainContentRoot.getPath() + '/' + AndroidCommonUtils.DIRECTORY_FOR_LOGS_NAME);
    }
    final AndroidProGuardStateStorage.MyState newState = new AndroidProGuardStateStorage.MyState(proguardCfgFiles);
    if (!hasDirtyFiles && newState.equals(oldState)) {
        return Pair.create(false, null);
    }
    final List<String> classesDirs = new ArrayList<String>();
    final List<String> libClassesDirs = new ArrayList<String>();
    final List<String> externalJars = new ArrayList<String>();
    final List<String> providedJars = new ArrayList<String>();
    final List<BuildRootDescriptor> roots = context.getProjectDescriptor().getBuildRootIndex().getTargetRoots(target, context);
    for (BuildRootDescriptor root : roots) {
        final File rootFile = root.getRootFile();
        if (!rootFile.exists()) {
            continue;
        }
        if (root instanceof AndroidDexBuildTarget.MyClassesDirBuildRootDescriptor) {
            final AndroidDexBuildTarget.ClassesDirType type = ((AndroidDexBuildTarget.MyClassesDirBuildRootDescriptor) root).getClassesDirType();
            if (type == AndroidDexBuildTarget.ClassesDirType.JAVA || type == AndroidDexBuildTarget.ClassesDirType.ANDROID_APP) {
                AndroidJpsUtil.addSubdirectories(rootFile, classesDirs);
            } else {
                AndroidJpsUtil.addSubdirectories(rootFile, libClassesDirs);
            }
        } else if (root instanceof AndroidDexBuildTarget.MyJarBuildRootDescriptor) {
            final AndroidDexBuildTarget.MyJarBuildRootDescriptor jarRoot = (AndroidDexBuildTarget.MyJarBuildRootDescriptor) root;
            if (!jarRoot.isLibPackage() && !jarRoot.isPreDexed()) {
                externalJars.add(rootFile.getPath());
            }
        } else if (root instanceof AndroidDexBuildTarget.MyProvidedJarBuildRootDescriptor) {
            providedJars.add(rootFile.getPath());
        }
    }
    final String[] classFilesDirOsPaths = ArrayUtil.toStringArray(classesDirs);
    final String[] libClassFilesDirOsPaths = ArrayUtil.toStringArray(libClassesDirs);
    final String[] externalJarOsPaths = ArrayUtil.toStringArray(externalJars);
    final String[] providedJarOsPaths = ArrayUtil.toStringArray(providedJars);
    final String inputJarOsPath = AndroidCommonUtils.buildTempInputJar(classFilesDirOsPaths, libClassFilesDirOsPaths);
    final AndroidBuildTestingManager testingManager = AndroidBuildTestingManager.getTestingManager();
    if (testingManager != null) {
        testingManager.getCommandExecutor().checkJarContent("proguard_input_jar", inputJarOsPath);
    }
    if (!logsDir.exists()) {
        if (!logsDir.mkdirs()) {
            context.processMessage(new CompilerMessage(PRO_GUARD_BUILDER_NAME, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.cannot.create.directory", FileUtil.toSystemDependentName(logsDir.getPath()))));
            return null;
        }
    }
    final JpsAndroidDexCompilerConfiguration configuration = JpsAndroidExtensionService.getInstance().getDexCompilerConfiguration(module.getProject());
    String proguardVmOptions = configuration != null ? configuration.getProguardVmOptions() : null;
    if (proguardVmOptions == null) {
        proguardVmOptions = "";
    }
    context.processMessage(new ProgressMessage(AndroidJpsBundle.message("android.jps.progress.proguard", module.getName())));
    final Map<AndroidCompilerMessageKind, List<String>> messages = AndroidCommonUtils.launchProguard(platform.getTarget(), platform.getSdkToolsRevision(), platform.getSdk().getHomePath(), javaExecutable, proguardVmOptions, proguardCfgPaths, inputJarOsPath, externalJarOsPaths, providedJarOsPaths, outputJarPath, logsDir.getPath());
    AndroidJpsUtil.addMessages(context, messages, PRO_GUARD_BUILDER_NAME, module.getName());
    return messages.get(AndroidCompilerMessageKind.ERROR).isEmpty() ? Pair.create(true, newState) : null;
}
Also used : ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) AndroidCompilerMessageKind(org.jetbrains.android.util.AndroidCompilerMessageKind) JpsAndroidDexCompilerConfiguration(org.jetbrains.jps.android.model.JpsAndroidDexCompilerConfiguration) AndroidDexBuildTarget(org.jetbrains.jps.android.builder.AndroidDexBuildTarget) BuildRootDescriptor(org.jetbrains.jps.builders.BuildRootDescriptor) AndroidBuildTestingManager(org.jetbrains.android.util.AndroidBuildTestingManager) JpsModule(org.jetbrains.jps.model.module.JpsModule) File(java.io.File)

Example 3 with BuildRootDescriptor

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

the class FilesDelta method load.

public void load(DataInput in, @NotNull BuildTarget<?> target, BuildRootIndex buildRootIndex) throws IOException {
    lockData();
    try {
        myDeletedPaths.clear();
        int deletedCount = in.readInt();
        while (deletedCount-- > 0) {
            myDeletedPaths.add(IOUtil.readString(in));
        }
        myFilesToRecompile.clear();
        int recompileCount = in.readInt();
        while (recompileCount-- > 0) {
            String rootId = IOUtil.readString(in);
            BuildRootDescriptor descriptor = target.findRootDescriptor(rootId, buildRootIndex);
            Set<File> files;
            if (descriptor != null) {
                files = myFilesToRecompile.get(descriptor);
                if (files == null) {
                    files = new THashSet<>(FileUtil.FILE_HASHING_STRATEGY);
                    myFilesToRecompile.put(descriptor, files);
                }
            } else {
                LOG.debug("Cannot find root by " + rootId + ", delta will be skipped");
                files = new THashSet<>(FileUtil.FILE_HASHING_STRATEGY);
            }
            int filesCount = in.readInt();
            while (filesCount-- > 0) {
                final File file = new File(IOUtil.readString(in));
                if (Utils.IS_TEST_MODE) {
                    LOG.info("Loaded " + file.getPath());
                }
                files.add(file);
            }
        }
    } finally {
        unlockData();
    }
}
Also used : BuildRootDescriptor(org.jetbrains.jps.builders.BuildRootDescriptor) File(java.io.File)

Example 4 with BuildRootDescriptor

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

the class FilesDelta method save.

public void save(DataOutput out) throws IOException {
    lockData();
    try {
        out.writeInt(myDeletedPaths.size());
        for (String path : myDeletedPaths) {
            IOUtil.writeString(path, out);
        }
        out.writeInt(myFilesToRecompile.size());
        for (Map.Entry<BuildRootDescriptor, Set<File>> entry : myFilesToRecompile.entrySet()) {
            IOUtil.writeString(entry.getKey().getRootId(), out);
            final Set<File> files = entry.getValue();
            out.writeInt(files.size());
            for (File file : files) {
                IOUtil.writeString(FileUtil.toSystemIndependentName(file.getPath()), out);
            }
        }
    } finally {
        unlockData();
    }
}
Also used : BuildRootDescriptor(org.jetbrains.jps.builders.BuildRootDescriptor) THashSet(gnu.trove.THashSet) File(java.io.File)

Example 5 with BuildRootDescriptor

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

the class AndroidResourceCachingBuildTarget method doComputeRootDescriptors.

@NotNull
@Override
protected List<BuildRootDescriptor> doComputeRootDescriptors(JpsModel model, ModuleExcludeIndex index, IgnoredFileIndex ignoredFileIndex, BuildDataPaths dataPaths) {
    final JpsAndroidModuleExtension extension = AndroidJpsUtil.getExtension(myModule);
    if (extension != null) {
        final List<BuildRootDescriptor> result = new ArrayList<BuildRootDescriptor>();
        for (File resOverlayDir : extension.getResourceOverlayDirs()) {
            result.add(new BuildRootDescriptorImpl(this, resOverlayDir));
        }
        final File resourceDir = AndroidJpsUtil.getResourceDirForCompilationPath(extension);
        if (resourceDir != null) {
            result.add(new BuildRootDescriptorImpl(this, resourceDir));
        }
        if (!extension.isLibrary()) {
            final Set<String> aarResDirPaths = new HashSet<String>();
            AndroidJpsUtil.collectResDirectoriesFromAarDeps(myModule, aarResDirPaths);
            for (JpsAndroidModuleExtension depExtension : AndroidJpsUtil.getAllAndroidDependencies(myModule, true)) {
                AndroidJpsUtil.collectResDirectoriesFromAarDeps(depExtension.getModule(), aarResDirPaths);
            }
            for (String path : aarResDirPaths) {
                result.add(new BuildRootDescriptorImpl(this, new File(path)));
            }
        }
        return result;
    }
    return Collections.emptyList();
}
Also used : BuildRootDescriptorImpl(org.jetbrains.jps.builders.impl.BuildRootDescriptorImpl) BuildRootDescriptor(org.jetbrains.jps.builders.BuildRootDescriptor) JpsAndroidModuleExtension(org.jetbrains.jps.android.model.JpsAndroidModuleExtension) File(java.io.File) HashSet(com.intellij.util.containers.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

BuildRootDescriptor (org.jetbrains.jps.builders.BuildRootDescriptor)16 File (java.io.File)15 JpsAndroidModuleExtension (org.jetbrains.jps.android.model.JpsAndroidModuleExtension)7 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 NotNull (org.jetbrains.annotations.NotNull)5 JpsModule (org.jetbrains.jps.model.module.JpsModule)5 BuildRootDescriptorImpl (org.jetbrains.jps.builders.impl.BuildRootDescriptorImpl)4 CompilerMessage (org.jetbrains.jps.incremental.messages.CompilerMessage)4 ProgressMessage (org.jetbrains.jps.incremental.messages.ProgressMessage)4 JpsFlexBuildConfiguration (com.intellij.flex.model.bc.JpsFlexBuildConfiguration)2 THashSet (gnu.trove.THashSet)2 AndroidBuildTestingManager (org.jetbrains.android.util.AndroidBuildTestingManager)2 AndroidCompilerMessageKind (org.jetbrains.android.util.AndroidCompilerMessageKind)2 AndroidDexBuildTarget (org.jetbrains.jps.android.builder.AndroidDexBuildTarget)2 BuildFSState (org.jetbrains.jps.incremental.fs.BuildFSState)2 IAndroidTarget (com.android.sdklib.IAndroidTarget)1 FlexBuildTarget (com.intellij.flex.build.FlexBuildTarget)1 FlexResourceBuildTarget (com.intellij.flex.build.FlexResourceBuildTarget)1 HashMap (com.intellij.util.containers.HashMap)1