Search in sources :

Example 1 with JpsProject

use of org.jetbrains.jps.model.JpsProject in project intellij-community by JetBrains.

the class FormsInstrumenter method build.

@Override
public ExitCode build(CompileContext context, ModuleChunk chunk, DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget> dirtyFilesHolder, OutputConsumer outputConsumer) throws ProjectBuildException, IOException {
    final JpsProject project = context.getProjectDescriptor().getProject();
    final JpsUiDesignerConfiguration config = JpsUiDesignerExtensionService.getInstance().getOrCreateUiDesignerConfiguration(project);
    if (!config.isInstrumentClasses()) {
        return ExitCode.NOTHING_DONE;
    }
    final Map<File, Collection<File>> srcToForms = FORMS_TO_COMPILE.get(context);
    FORMS_TO_COMPILE.set(context, null);
    if (srcToForms == null || srcToForms.isEmpty()) {
        return ExitCode.NOTHING_DONE;
    }
    final Set<File> formsToCompile = new THashSet<>(FileUtil.FILE_HASHING_STRATEGY);
    for (Collection<File> files : srcToForms.values()) {
        formsToCompile.addAll(files);
    }
    if (JavaBuilderUtil.isCompileJavaIncrementally(context)) {
        final ProjectBuilderLogger logger = context.getLoggingManager().getProjectBuilderLogger();
        if (logger.isEnabled()) {
            logger.logCompiledFiles(formsToCompile, getPresentableName(), "Compiling forms:");
        }
    }
    try {
        final Collection<File> platformCp = ProjectPaths.getPlatformCompilationClasspath(chunk, false);
        final List<File> classpath = new ArrayList<>();
        classpath.addAll(ProjectPaths.getCompilationClasspath(chunk, false));
        // forms_rt.jar
        classpath.add(getResourcePath(GridConstraints.class));
        final Map<File, String> chunkSourcePath = ProjectPaths.getSourceRootsWithDependents(chunk);
        // sourcepath for loading forms resources
        classpath.addAll(chunkSourcePath.keySet());
        final JpsSdk<JpsDummyElement> sdk = chunk.representativeTarget().getModule().getSdk(JpsJavaSdkType.INSTANCE);
        final InstrumentationClassFinder finder = ClassProcessingBuilder.createInstrumentationClassFinder(sdk, platformCp, classpath, outputConsumer);
        try {
            final Map<File, Collection<File>> processed = instrumentForms(context, chunk, chunkSourcePath, finder, formsToCompile, outputConsumer);
            final OneToManyPathsMapping sourceToFormMap = context.getProjectDescriptor().dataManager.getSourceToFormMap();
            for (Map.Entry<File, Collection<File>> entry : processed.entrySet()) {
                final File src = entry.getKey();
                final Collection<File> forms = entry.getValue();
                final Collection<String> formPaths = new ArrayList<>(forms.size());
                for (File form : forms) {
                    formPaths.add(form.getPath());
                }
                sourceToFormMap.update(src.getPath(), formPaths);
                srcToForms.remove(src);
            }
            // clean mapping
            for (File srcFile : srcToForms.keySet()) {
                sourceToFormMap.remove(srcFile.getPath());
            }
        } finally {
            finder.releaseResources();
        }
    } finally {
        context.processMessage(new ProgressMessage("Finished instrumenting forms [" + chunk.getPresentableShortName() + "]"));
    }
    return ExitCode.OK;
}
Also used : ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) OneToManyPathsMapping(org.jetbrains.jps.incremental.storage.OneToManyPathsMapping) InstrumentationClassFinder(com.intellij.compiler.instrumentation.InstrumentationClassFinder) THashSet(gnu.trove.THashSet) ProjectBuilderLogger(org.jetbrains.jps.builders.logging.ProjectBuilderLogger) JpsUiDesignerConfiguration(org.jetbrains.jps.uiDesigner.model.JpsUiDesignerConfiguration) GridConstraints(com.intellij.uiDesigner.core.GridConstraints) JpsProject(org.jetbrains.jps.model.JpsProject) JpsDummyElement(org.jetbrains.jps.model.JpsDummyElement) THashMap(gnu.trove.THashMap)

Example 2 with JpsProject

use of org.jetbrains.jps.model.JpsProject in project intellij-community by JetBrains.

the class JpsLibraryOrderEntry method getLibraryLevel.

@Override
public String getLibraryLevel() {
    final JpsElementReference<? extends JpsCompositeElement> reference = myDependencyElement.getLibraryReference().getParentReference();
    final JpsCompositeElement parent = reference.resolve();
    if (parent instanceof JpsGlobal)
        return LibraryTablesRegistrar.APPLICATION_LEVEL;
    if (parent instanceof JpsProject)
        return LibraryTablesRegistrar.PROJECT_LEVEL;
    if (parent instanceof JpsModule)
        return LibraryTableImplUtil.MODULE_LEVEL;
    return LibraryTablesRegistrar.PROJECT_LEVEL;
}
Also used : JpsModule(org.jetbrains.jps.model.module.JpsModule) JpsGlobal(org.jetbrains.jps.model.JpsGlobal) JpsProject(org.jetbrains.jps.model.JpsProject) JpsCompositeElement(org.jetbrains.jps.model.JpsCompositeElement)

Example 3 with JpsProject

use of org.jetbrains.jps.model.JpsProject in project intellij-community by JetBrains.

the class FilteredResourceRootDescriptor method createFileFilter.

@NotNull
@Override
public FileFilter createFileFilter() {
    final JpsProject project = getTarget().getModule().getProject();
    final JpsJavaCompilerConfiguration configuration = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(project);
    final JpsCompilerExcludes excludes = configuration.getCompilerExcludes();
    return file -> !excludes.isExcluded(file) && configuration.isResourceFile(file, getRootFile());
}
Also used : JpsProject(org.jetbrains.jps.model.JpsProject) JpsCompilerExcludes(org.jetbrains.jps.model.java.compiler.JpsCompilerExcludes) FileFilter(java.io.FileFilter) JpsJavaCompilerConfiguration(org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration) ResourcesTarget(org.jetbrains.jps.incremental.ResourcesTarget) Set(java.util.Set) JpsJavaExtensionService(org.jetbrains.jps.model.java.JpsJavaExtensionService) NotNull(org.jetbrains.annotations.NotNull) File(java.io.File) JpsJavaCompilerConfiguration(org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration) JpsCompilerExcludes(org.jetbrains.jps.model.java.compiler.JpsCompilerExcludes) JpsProject(org.jetbrains.jps.model.JpsProject) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with JpsProject

use of org.jetbrains.jps.model.JpsProject in project intellij-plugins by JetBrains.

the class FlexBuildTargetType method computeAllTargets.

@NotNull
public List<FlexBuildTarget> computeAllTargets(@NotNull final JpsModel model) {
    final List<FlexBuildTarget> result = new ArrayList<>();
    final JpsProject project = model.getProject();
    for (JpsTypedRunConfiguration<JpsFlashRunnerParameters> runConfig : project.getRunConfigurations(JpsFlashRunConfigurationType.INSTANCE)) {
        ContainerUtilRt.addIfNotNull(result, FlexBuildTarget.create(project, runConfig.getType(), runConfig.getName()));
    }
    for (JpsTypedRunConfiguration<JpsFlexUnitRunnerParameters> runConfig : project.getRunConfigurations(JpsFlexUnitRunConfigurationType.INSTANCE)) {
        ContainerUtilRt.addIfNotNull(result, FlexBuildTarget.create(project, runConfig.getType(), runConfig.getName()));
    }
    for (JpsTypedModule<JpsFlexBuildConfigurationManager> module : project.getModules(JpsFlexModuleType.INSTANCE)) {
        for (JpsFlexBuildConfiguration bc : module.getProperties().getBuildConfigurations()) {
            result.add(FlexBuildTarget.create(bc, null));
            final BuildConfigurationNature nature = bc.getNature();
            if (nature.isApp() && (nature.isDesktopPlatform() || nature.isMobilePlatform())) {
                result.add(FlexBuildTarget.create(bc, Boolean.TRUE));
                result.add(FlexBuildTarget.create(bc, Boolean.FALSE));
            }
        }
    }
    return result;
}
Also used : BuildConfigurationNature(com.intellij.flex.model.bc.BuildConfigurationNature) JpsFlashRunnerParameters(com.intellij.flex.model.run.JpsFlashRunnerParameters) JpsFlexUnitRunnerParameters(com.intellij.flex.model.run.JpsFlexUnitRunnerParameters) JpsProject(org.jetbrains.jps.model.JpsProject) ArrayList(java.util.ArrayList) JpsFlexBuildConfiguration(com.intellij.flex.model.bc.JpsFlexBuildConfiguration) JpsFlexBuildConfigurationManager(com.intellij.flex.model.bc.JpsFlexBuildConfigurationManager) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with JpsProject

use of org.jetbrains.jps.model.JpsProject in project android by JetBrains.

the class AndroidPreDexBuilder method doBuild.

private static boolean doBuild(@NotNull AndroidPreDexBuildTarget target, @NotNull DirtyFilesHolder<AndroidPreDexBuildTarget.MyRootDescriptor, AndroidPreDexBuildTarget> holder, @NotNull BuildOutputConsumer outputConsumer, @NotNull CompileContext context) throws IOException, ProjectBuildException {
    final List<Pair<File, String>> filesToPreDex = new ArrayList<Pair<File, String>>();
    holder.processDirtyFiles(new FileProcessor<AndroidPreDexBuildTarget.MyRootDescriptor, AndroidPreDexBuildTarget>() {

        @Override
        public boolean apply(AndroidPreDexBuildTarget target, File file, AndroidPreDexBuildTarget.MyRootDescriptor root) throws IOException {
            if (canBePreDexed(file) && file.isFile()) {
                filesToPreDex.add(Pair.create(file, root.getModuleName()));
            }
            return true;
        }
    });
    final JpsProject project = target.getProject();
    AndroidPlatform platform = null;
    for (JpsModule module : project.getModules()) {
        if (AndroidJpsUtil.getExtension(module) != null) {
            platform = AndroidJpsUtil.getAndroidPlatform(module, context, BUILDER_NAME);
            break;
        }
    }
    if (platform == null) {
        return false;
    }
    if (!filesToPreDex.isEmpty()) {
        final File outputDir = target.getOutputFile(context);
        for (Pair<File, String> pair : filesToPreDex) {
            context.checkCanceled();
            final File srcFile = pair.getFirst();
            final String moduleName = pair.getSecond();
            final String srcFilePath = srcFile.getAbsolutePath();
            final File outputFile;
            if (moduleName != null) {
                context.processMessage(new ProgressMessage("Pre-dex [" + moduleName + "]"));
                outputFile = new File(new File(outputDir, moduleName), srcFile.getName());
            } else {
                context.processMessage(new ProgressMessage("Pre-dex: " + srcFile.getName()));
                final String outputFileName = getOutputFileNameForExternalJar(srcFile);
                if (outputFileName == null) {
                    context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, "Cannot pre-dex file " + srcFilePath + ": incorrect path", srcFilePath));
                    return false;
                }
                outputFile = new File(outputDir, outputFileName);
            }
            if (AndroidJpsUtil.createDirIfNotExist(outputFile.getParentFile(), context, BUILDER_NAME) == null) {
                return false;
            }
            if (!AndroidDexBuilder.runDex(platform, outputFile.getPath(), new String[] { srcFilePath }, context, project, outputConsumer, BUILDER_NAME, srcFile.getName(), null)) {
                return false;
            }
        }
    }
    return true;
}
Also used : ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) AndroidPreDexBuildTarget(org.jetbrains.jps.android.builder.AndroidPreDexBuildTarget) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) ArrayList(java.util.ArrayList) IOException(java.io.IOException) JpsModule(org.jetbrains.jps.model.module.JpsModule) JpsProject(org.jetbrains.jps.model.JpsProject) File(java.io.File) Pair(com.intellij.openapi.util.Pair)

Aggregations

JpsProject (org.jetbrains.jps.model.JpsProject)17 File (java.io.File)8 IOException (java.io.IOException)4 NotNull (org.jetbrains.annotations.NotNull)4 ProgressMessage (org.jetbrains.jps.incremental.messages.ProgressMessage)4 JpsModule (org.jetbrains.jps.model.module.JpsModule)4 THashSet (gnu.trove.THashSet)3 CompilerMessage (org.jetbrains.jps.incremental.messages.CompilerMessage)3 JpsJavaExtensionService (org.jetbrains.jps.model.java.JpsJavaExtensionService)3 JpsCompilerExcludes (org.jetbrains.jps.model.java.compiler.JpsCompilerExcludes)3 JpsJavaCompilerConfiguration (org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration)3 THashMap (gnu.trove.THashMap)2 FileFilter (java.io.FileFilter)2 ArrayList (java.util.ArrayList)2 Set (java.util.Set)2 ElixirCompilerOptions (org.elixir_lang.jps.model.ElixirCompilerOptions)2 ProjectBuildException (org.jetbrains.jps.incremental.ProjectBuildException)2 ResourcesTarget (org.jetbrains.jps.incremental.ResourcesTarget)2 OneToManyPathsMapping (org.jetbrains.jps.incremental.storage.OneToManyPathsMapping)2 JpsDummyElement (org.jetbrains.jps.model.JpsDummyElement)2