Search in sources :

Example 16 with JavaSourceRootDescriptor

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

the class FormsBindingManager method findBoundSourceCandidates.

@NotNull
private static Collection<File> findBoundSourceCandidates(CompileContext context, final ModuleBuildTarget target, File form) throws IOException {
    final List<JavaSourceRootDescriptor> targetRoots = context.getProjectDescriptor().getBuildRootIndex().getTargetRoots(target, context);
    if (targetRoots.isEmpty()) {
        return Collections.emptyList();
    }
    final String className = FormsParsing.readBoundClassName(form);
    if (className == null) {
        return Collections.emptyList();
    }
    for (JavaSourceRootDescriptor rd : targetRoots) {
        final File boundSource = findSourceForClass(rd, className);
        if (boundSource != null) {
            return Collections.singleton(boundSource);
        }
    }
    final Set<File> candidates = new THashSet<>(FileUtil.FILE_HASHING_STRATEGY);
    for (JavaSourceRootDescriptor rd : targetRoots) {
        candidates.addAll(findPossibleSourcesForClass(rd, className));
    }
    return candidates;
}
Also used : JavaSourceRootDescriptor(org.jetbrains.jps.builders.java.JavaSourceRootDescriptor) File(java.io.File) THashSet(gnu.trove.THashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 17 with JavaSourceRootDescriptor

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

the class AndroidSourceGeneratingBuilder method doBuild.

private static ModuleLevelBuilder.ExitCode doBuild(CompileContext context, ModuleChunk chunk, DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget> dirtyFilesHolder) throws IOException {
    final Map<JpsModule, MyModuleData> moduleDataMap = computeModuleDatas(chunk.getModules(), context);
    if (moduleDataMap == null || moduleDataMap.size() == 0) {
        return ExitCode.ABORT;
    }
    if (!checkVersions(moduleDataMap, context)) {
        return ExitCode.ABORT;
    }
    checkAndroidDependencies(moduleDataMap, context);
    if (!checkArtifacts(context)) {
        return ExitCode.ABORT;
    }
    if (JavaBuilderUtil.isForcedRecompilationAllJavaModules(context)) {
        if (!clearAndroidStorages(context, chunk.getModules())) {
            return ExitCode.ABORT;
        }
    }
    final Map<File, ModuleBuildTarget> idlFilesToCompile = new HashMap<File, ModuleBuildTarget>();
    final Map<File, ModuleBuildTarget> rsFilesToCompile = new HashMap<File, ModuleBuildTarget>();
    dirtyFilesHolder.processDirtyFiles(new FileProcessor<JavaSourceRootDescriptor, ModuleBuildTarget>() {

        @Override
        public boolean apply(ModuleBuildTarget target, File file, JavaSourceRootDescriptor sourceRoot) throws IOException {
            final JpsAndroidModuleExtension extension = AndroidJpsUtil.getExtension(target.getModule());
            if (extension == null) {
                return true;
            }
            String fileName = file.getName();
            if (FileUtilRt.extensionEquals(fileName, AIDL_EXTENSION)) {
                idlFilesToCompile.put(file, target);
            } else if (FileUtilRt.extensionEquals(fileName, RENDERSCRIPT_EXTENSION)) {
                rsFilesToCompile.put(file, target);
            }
            return true;
        }
    });
    boolean success = true;
    final BuildDataManager dataManager = context.getProjectDescriptor().dataManager;
    if (JavaBuilderUtil.isForcedRecompilationAllJavaModules(context)) {
        for (JpsModule module : moduleDataMap.keySet()) {
            final File generatedSourcesStorage = AndroidJpsUtil.getGeneratedSourcesStorage(module, dataManager);
            if (generatedSourcesStorage.exists() && !deleteAndMarkRecursively(generatedSourcesStorage, context, BUILDER_NAME)) {
                success = false;
            }
            final File generatedResourcesStorage = AndroidJpsUtil.getGeneratedResourcesStorage(module, dataManager);
            if (generatedResourcesStorage.exists() && !deleteAndMarkRecursively(generatedResourcesStorage, context, BUILDER_NAME)) {
                success = false;
            }
        }
    }
    if (!success) {
        return ExitCode.ABORT;
    }
    boolean didSomething = false;
    if (idlFilesToCompile.size() > 0) {
        if (!runAidlCompiler(context, idlFilesToCompile, moduleDataMap)) {
            success = false;
        }
        didSomething = true;
    }
    if (rsFilesToCompile.size() > 0) {
        if (!runRenderscriptCompiler(context, rsFilesToCompile, moduleDataMap)) {
            success = false;
        }
        didSomething = true;
    }
    MyExitStatus status = runAaptCompiler(context, moduleDataMap);
    if (status == MyExitStatus.FAIL) {
        success = false;
    } else if (status == MyExitStatus.OK) {
        didSomething = true;
    }
    status = runBuildConfigGeneration(context, moduleDataMap);
    if (status == MyExitStatus.FAIL) {
        success = false;
    } else if (status == MyExitStatus.OK) {
        didSomething = true;
    }
    if (!success) {
        return ExitCode.ABORT;
    }
    status = copyGeneratedSources(moduleDataMap, dataManager, context);
    if (status == MyExitStatus.FAIL) {
        return ExitCode.ABORT;
    } else if (status == MyExitStatus.OK) {
        didSomething = true;
    }
    if (didSomething) {
        return ExitCode.OK;
    }
    return ExitCode.NOTHING_DONE;
}
Also used : HashMap(com.intellij.util.containers.HashMap) TObjectLongHashMap(gnu.trove.TObjectLongHashMap) JpsModule(org.jetbrains.jps.model.module.JpsModule) JpsAndroidModuleExtension(org.jetbrains.jps.android.model.JpsAndroidModuleExtension) JavaSourceRootDescriptor(org.jetbrains.jps.builders.java.JavaSourceRootDescriptor) BuildDataManager(org.jetbrains.jps.incremental.storage.BuildDataManager)

Example 18 with JavaSourceRootDescriptor

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

the class AndroidSourceGeneratingBuilder method computePackageForFile.

@Nullable
private static String computePackageForFile(@NotNull CompileContext context, @NotNull File file) throws IOException {
    final JavaSourceRootDescriptor descriptor = context.getProjectDescriptor().getBuildRootIndex().findJavaRootDescriptor(context, file);
    if (descriptor == null) {
        return null;
    }
    final String relPath = FileUtil.getRelativePath(descriptor.root, FileUtilRt.getParentFile(file));
    if (relPath == null) {
        return null;
    }
    return FileUtil.toSystemIndependentName(relPath).replace('/', '.');
}
Also used : JavaSourceRootDescriptor(org.jetbrains.jps.builders.java.JavaSourceRootDescriptor) Nullable(org.jetbrains.annotations.Nullable)

Example 19 with JavaSourceRootDescriptor

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

the class AndroidSourceGeneratingBuilder method getDependencyFolder.

@Nullable
private static String getDependencyFolder(@NotNull CompileContext context, @NotNull File sourceFile, @NotNull File genFolder) {
    final JavaSourceRootDescriptor descriptor = context.getProjectDescriptor().getBuildRootIndex().findJavaRootDescriptor(context, sourceFile);
    if (descriptor == null) {
        return null;
    }
    final File sourceRoot = descriptor.root;
    final File parent = FileUtilRt.getParentFile(sourceFile);
    if (parent == null) {
        return null;
    }
    if (FileUtil.filesEqual(parent, sourceRoot)) {
        return genFolder.getPath();
    }
    final String relativePath = FileUtil.getRelativePath(sourceRoot, parent);
    assert relativePath != null;
    return genFolder.getPath() + '/' + relativePath;
}
Also used : JavaSourceRootDescriptor(org.jetbrains.jps.builders.java.JavaSourceRootDescriptor) Nullable(org.jetbrains.annotations.Nullable)

Example 20 with JavaSourceRootDescriptor

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

the class AndroidAdditionalRootProviderService method getAdditionalRoots.

@NotNull
@Override
public List<JavaSourceRootDescriptor> getAdditionalRoots(@NotNull BuildTarget<JavaSourceRootDescriptor> target, BuildDataPaths dataPaths) {
    ModuleBuildTarget buildTarget = (ModuleBuildTarget) target;
    final File generatedSourcesRoot = AndroidJpsUtil.getGeneratedSourcesStorage(buildTarget.getModule(), dataPaths);
    final List<JavaSourceRootDescriptor> result = new ArrayList<JavaSourceRootDescriptor>();
    addRoot(result, buildTarget, new File(generatedSourcesRoot, AndroidJpsUtil.AAPT_GENERATED_SOURCE_ROOT_NAME));
    addRoot(result, buildTarget, new File(generatedSourcesRoot, AndroidJpsUtil.AIDL_GENERATED_SOURCE_ROOT_NAME));
    addRoot(result, buildTarget, new File(generatedSourcesRoot, AndroidJpsUtil.RENDERSCRIPT_GENERATED_SOURCE_ROOT_NAME));
    addRoot(result, buildTarget, new File(generatedSourcesRoot, AndroidJpsUtil.BUILD_CONFIG_GENERATED_SOURCE_ROOT_NAME));
    addRoot(result, buildTarget, AndroidJpsUtil.getCopiedSourcesStorage(buildTarget.getModule(), dataPaths));
    return result;
}
Also used : ModuleBuildTarget(org.jetbrains.jps.incremental.ModuleBuildTarget) ArrayList(java.util.ArrayList) JavaSourceRootDescriptor(org.jetbrains.jps.builders.java.JavaSourceRootDescriptor) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

JavaSourceRootDescriptor (org.jetbrains.jps.builders.java.JavaSourceRootDescriptor)20 File (java.io.File)9 THashSet (gnu.trove.THashSet)7 JpsModule (org.jetbrains.jps.model.module.JpsModule)5 THashMap (gnu.trove.THashMap)4 IOException (java.io.IOException)4 NotNull (org.jetbrains.annotations.NotNull)4 ProjectDescriptor (org.jetbrains.jps.cmdline.ProjectDescriptor)4 ProgressMessage (org.jetbrains.jps.incremental.messages.ProgressMessage)3 JpsJavaCompilerConfiguration (org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration)3 ArrayList (java.util.ArrayList)2 Nullable (org.jetbrains.annotations.Nullable)2 BuildRootIndex (org.jetbrains.jps.builders.BuildRootIndex)2 ProjectBuilderLogger (org.jetbrains.jps.builders.logging.ProjectBuilderLogger)2 BuildDataCorruptedException (org.jetbrains.jps.builders.storage.BuildDataCorruptedException)2 ModuleBuildTarget (org.jetbrains.jps.incremental.ModuleBuildTarget)2 CompilerMessage (org.jetbrains.jps.incremental.messages.CompilerMessage)2 EnhancerRunner (com.intellij.appengine.rt.EnhancerRunner)1 FailSafeClassReader (com.intellij.compiler.instrumentation.FailSafeClassReader)1 SmartList (com.intellij.util.SmartList)1