Search in sources :

Example 1 with JpsDummyElement

use of org.jetbrains.jps.model.JpsDummyElement 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 JpsDummyElement

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

the class IdeaJdk method setupSdkPathsFromIDEAProject.

private static void setupSdkPathsFromIDEAProject(Sdk sdk, SdkModificator sdkModificator, SdkModel sdkModel) throws IOException {
    ProgressIndicator indicator = ObjectUtils.assertNotNull(ProgressManager.getInstance().getProgressIndicator());
    String sdkHome = ObjectUtils.notNull(sdk.getHomePath());
    JpsModel model = JpsSerializationManager.getInstance().loadModel(sdkHome, PathManager.getOptionsPath());
    JpsSdkReference<JpsDummyElement> sdkRef = model.getProject().getSdkReferencesTable().getSdkReference(JpsJavaSdkType.INSTANCE);
    String sdkName = sdkRef == null ? null : sdkRef.getSdkName();
    Sdk internalJava = sdkModel.findSdk(sdkName);
    if (internalJava != null && isValidInternalJdk(sdk, internalJava)) {
        setInternalJdk(sdk, sdkModificator, internalJava);
    }
    Set<VirtualFile> addedRoots = ContainerUtil.newTroveSet();
    VirtualFileManager vfsManager = VirtualFileManager.getInstance();
    JpsJavaExtensionService javaService = JpsJavaExtensionService.getInstance();
    boolean isUltimate = vfsManager.findFileByUrl(VfsUtilCore.pathToUrl(sdkHome + "/ultimate/ultimate-resources")) != null;
    Set<String> suppressedModules = ContainerUtil.newTroveSet("jps-plugin-system");
    Set<String> ultimateModules = ContainerUtil.newTroveSet("platform-ultimate", "ultimate-resources", "ultimate-verifier", "diagram-api", "diagram-impl", "uml-plugin");
    List<JpsModule> modules = JBIterable.from(model.getProject().getModules()).filter(o -> {
        if (suppressedModules.contains(o.getName()))
            return false;
        if (o.getName().endsWith("-ide"))
            return false;
        String contentUrl = ContainerUtil.getFirstItem(o.getContentRootsList().getUrls());
        if (contentUrl == null)
            return true;
        return !isUltimate || contentUrl.contains("/community/") || ultimateModules.contains(o.getName());
    }).toList();
    indicator.setIndeterminate(false);
    double delta = 1 / (2 * Math.max(0.5, modules.size()));
    for (JpsModule o : modules) {
        indicator.setFraction(indicator.getFraction() + delta);
        for (JpsDependencyElement dep : o.getDependenciesList().getDependencies()) {
            ProgressManager.checkCanceled();
            JpsLibrary library = dep instanceof JpsLibraryDependency ? ((JpsLibraryDependency) dep).getLibrary() : null;
            JpsLibraryType<?> libraryType = library == null ? null : library.getType();
            if (!(libraryType instanceof JpsJavaLibraryType))
                continue;
            JpsJavaDependencyExtension extension = javaService.getDependencyExtension(dep);
            if (extension == null)
                continue;
            // do not check extension.getScope(), plugin projects need tests too
            for (JpsLibraryRoot jps : library.getRoots(JpsOrderRootType.COMPILED)) {
                VirtualFile root = vfsManager.findFileByUrl(jps.getUrl());
                if (root == null || !addedRoots.add(root))
                    continue;
                sdkModificator.addRoot(root, OrderRootType.CLASSES);
            }
            for (JpsLibraryRoot jps : library.getRoots(JpsOrderRootType.SOURCES)) {
                VirtualFile root = vfsManager.findFileByUrl(jps.getUrl());
                if (root == null || !addedRoots.add(root))
                    continue;
                sdkModificator.addRoot(root, OrderRootType.SOURCES);
            }
        }
    }
    for (JpsModule o : modules) {
        indicator.setFraction(indicator.getFraction() + delta);
        String outputUrl = javaService.getOutputUrl(o, false);
        VirtualFile outputRoot = outputUrl == null ? null : vfsManager.findFileByUrl(outputUrl);
        if (outputRoot == null)
            continue;
        sdkModificator.addRoot(outputRoot, OrderRootType.CLASSES);
        for (JpsModuleSourceRoot jps : o.getSourceRoots()) {
            ProgressManager.checkCanceled();
            VirtualFile root = vfsManager.findFileByUrl(jps.getUrl());
            if (root == null || !addedRoots.add(root))
                continue;
            sdkModificator.addRoot(root, OrderRootType.SOURCES);
        }
    }
    indicator.setFraction(1.0);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Arrays(java.util.Arrays) JBIterable(com.intellij.util.containers.JBIterable) VirtualFile(com.intellij.openapi.vfs.VirtualFile) JpsJavaLibraryType(org.jetbrains.jps.model.java.JpsJavaLibraryType) VirtualFileManager(com.intellij.openapi.vfs.VirtualFileManager) Messages(com.intellij.openapi.ui.Messages) ZipFile(java.util.zip.ZipFile) FileUtil(com.intellij.openapi.util.io.FileUtil) Logger(com.intellij.openapi.diagnostic.Logger) ZipEntry(java.util.zip.ZipEntry) JpsLibrary(org.jetbrains.jps.model.library.JpsLibrary) ProgressManager(com.intellij.openapi.progress.ProgressManager) LanguageLevel(com.intellij.pom.java.LanguageLevel) OrderRootType(com.intellij.openapi.roots.OrderRootType) Set(java.util.Set) JpsLibraryDependency(org.jetbrains.jps.model.module.JpsLibraryDependency) JpsJavaDependencyExtension(org.jetbrains.jps.model.java.JpsJavaDependencyExtension) JpsModule(org.jetbrains.jps.model.module.JpsModule) ThrowableComputable(com.intellij.openapi.util.ThrowableComputable) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) ApplicationStarter(com.intellij.openapi.application.ApplicationStarter) JavaDependentSdkType(com.intellij.openapi.projectRoots.impl.JavaDependentSdkType) JpsSerializationManager(org.jetbrains.jps.model.serialization.JpsSerializationManager) WriteExternalException(com.intellij.openapi.util.WriteExternalException) NotNull(org.jetbrains.annotations.NotNull) DataInputStream(java.io.DataInputStream) JpsDummyElement(org.jetbrains.jps.model.JpsDummyElement) ArrayUtil(com.intellij.util.ArrayUtil) JpsOrderRootType(org.jetbrains.jps.model.library.JpsOrderRootType) PathManager(com.intellij.openapi.application.PathManager) DevkitIcons(icons.DevkitIcons) NonNls(org.jetbrains.annotations.NonNls) InvalidDataException(com.intellij.openapi.util.InvalidDataException) ContainerUtil(com.intellij.util.containers.ContainerUtil) JavadocOrderRootType(com.intellij.openapi.roots.JavadocOrderRootType) JpsLibraryType(org.jetbrains.jps.model.library.JpsLibraryType) ClsParsingUtil(com.intellij.psi.impl.compiled.ClsParsingUtil) ArrayList(java.util.ArrayList) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) JpsSdkReference(org.jetbrains.jps.model.library.sdk.JpsSdkReference) com.intellij.openapi.projectRoots(com.intellij.openapi.projectRoots) JpsJavaExtensionService(org.jetbrains.jps.model.java.JpsJavaExtensionService) JpsModel(org.jetbrains.jps.model.JpsModel) JpsDependencyElement(org.jetbrains.jps.model.module.JpsDependencyElement) JpsJavaSdkType(org.jetbrains.jps.model.java.JpsJavaSdkType) JpsModuleSourceRoot(org.jetbrains.jps.model.module.JpsModuleSourceRoot) VfsUtilCore(com.intellij.openapi.vfs.VfsUtilCore) JpsLibraryRoot(org.jetbrains.jps.model.library.JpsLibraryRoot) IOException(java.io.IOException) SystemInfo(com.intellij.openapi.util.SystemInfo) File(java.io.File) DevKitBundle(org.jetbrains.idea.devkit.DevKitBundle) AnnotationOrderRootType(com.intellij.openapi.roots.AnnotationOrderRootType) JarFileSystem(com.intellij.openapi.vfs.JarFileSystem) ObjectUtils(com.intellij.util.ObjectUtils) Element(org.jdom.Element) javax.swing(javax.swing) JpsLibraryDependency(org.jetbrains.jps.model.module.JpsLibraryDependency) JpsModel(org.jetbrains.jps.model.JpsModel) VirtualFileManager(com.intellij.openapi.vfs.VirtualFileManager) JpsDependencyElement(org.jetbrains.jps.model.module.JpsDependencyElement) JpsJavaLibraryType(org.jetbrains.jps.model.java.JpsJavaLibraryType) JpsModule(org.jetbrains.jps.model.module.JpsModule) JpsModuleSourceRoot(org.jetbrains.jps.model.module.JpsModuleSourceRoot) JpsJavaExtensionService(org.jetbrains.jps.model.java.JpsJavaExtensionService) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) JpsJavaDependencyExtension(org.jetbrains.jps.model.java.JpsJavaDependencyExtension) JpsDummyElement(org.jetbrains.jps.model.JpsDummyElement) JpsLibrary(org.jetbrains.jps.model.library.JpsLibrary) JpsLibraryRoot(org.jetbrains.jps.model.library.JpsLibraryRoot)

Example 3 with JpsDummyElement

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

the class AppEngineEnhancerBuilder method processModule.

private static boolean processModule(final CompileContext context, DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget> dirtyFilesHolder, JpsAppEngineModuleExtension extension) throws IOException, ProjectBuildException {
    final Set<File> roots = new THashSet<>(FileUtil.FILE_HASHING_STRATEGY);
    for (String path : extension.getFilesToEnhance()) {
        roots.add(new File(FileUtil.toSystemDependentName(path)));
    }
    final List<String> pathsToProcess = new ArrayList<>();
    dirtyFilesHolder.processDirtyFiles(new FileProcessor<JavaSourceRootDescriptor, ModuleBuildTarget>() {

        @Override
        public boolean apply(ModuleBuildTarget target, File file, JavaSourceRootDescriptor root) throws IOException {
            if (JpsPathUtil.isUnder(roots, file)) {
                Collection<String> outputs = context.getProjectDescriptor().dataManager.getSourceToOutputMap(target).getOutputs(file.getAbsolutePath());
                if (outputs != null) {
                    pathsToProcess.addAll(outputs);
                }
            }
            return true;
        }
    });
    if (pathsToProcess.isEmpty()) {
        return false;
    }
    JpsModule module = extension.getModule();
    JpsSdk<JpsDummyElement> sdk = JavaBuilderUtil.ensureModuleHasJdk(module, context, NAME);
    context.processMessage(new ProgressMessage("Enhancing classes in module '" + module.getName() + "'..."));
    List<String> vmParams = Collections.singletonList("-Xmx256m");
    List<String> classpath = new ArrayList<>();
    classpath.add(extension.getToolsApiJarPath());
    classpath.add(PathManager.getJarPathForClass(EnhancerRunner.class));
    boolean removeOrmJars = Boolean.parseBoolean(System.getProperty("jps.appengine.enhancer.remove.orm.jars", "true"));
    for (File file : JpsJavaExtensionService.dependencies(module).recursively().compileOnly().productionOnly().classes().getRoots()) {
        if (removeOrmJars && FileUtil.isAncestor(new File(extension.getOrmLibPath()), file, true)) {
            continue;
        }
        classpath.add(file.getAbsolutePath());
    }
    List<String> programParams = new ArrayList<>();
    final File argsFile = FileUtil.createTempFile("appEngineEnhanceFiles", ".txt");
    PrintWriter writer = new PrintWriter(argsFile);
    try {
        for (String path : pathsToProcess) {
            writer.println(FileUtil.toSystemDependentName(path));
        }
    } finally {
        writer.close();
    }
    programParams.add(argsFile.getAbsolutePath());
    programParams.add("com.google.appengine.tools.enhancer.Enhance");
    programParams.add("-api");
    PersistenceApi api = extension.getPersistenceApi();
    programParams.add(api.getEnhancerApiName());
    if (api.getEnhancerVersion() == 2) {
        programParams.add("-enhancerVersion");
        programParams.add("v2");
    }
    programParams.add("-v");
    List<String> commandLine = ExternalProcessUtil.buildJavaCommandLine(JpsJavaSdkType.getJavaExecutable(sdk), EnhancerRunner.class.getName(), Collections.<String>emptyList(), classpath, vmParams, programParams);
    Process process = new ProcessBuilder(commandLine).start();
    ExternalEnhancerProcessHandler handler = new ExternalEnhancerProcessHandler(process, commandLine, context);
    handler.startNotify();
    handler.waitFor();
    ProjectBuilderLogger logger = context.getLoggingManager().getProjectBuilderLogger();
    if (logger.isEnabled()) {
        logger.logCompiledPaths(pathsToProcess, NAME, "Enhancing classes:");
    }
    return true;
}
Also used : ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) IOException(java.io.IOException) THashSet(gnu.trove.THashSet) EnhancerRunner(com.intellij.appengine.rt.EnhancerRunner) JpsModule(org.jetbrains.jps.model.module.JpsModule) PersistenceApi(org.jetbrains.jps.appengine.model.PersistenceApi) ProjectBuilderLogger(org.jetbrains.jps.builders.logging.ProjectBuilderLogger) JpsDummyElement(org.jetbrains.jps.model.JpsDummyElement) JavaSourceRootDescriptor(org.jetbrains.jps.builders.java.JavaSourceRootDescriptor) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 4 with JpsDummyElement

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

the class JpsGroovycRunner method runGroovycOrContinuation.

@NotNull
private GroovycOutputParser runGroovycOrContinuation(CompileContext context, ModuleChunk chunk, JpsGroovySettings settings, Map<T, String> finalOutputs, String compilerOutput, List<File> toCompile, boolean hasStubExcludes) throws Exception {
    GroovycContinuation continuation = takeContinuation(context, chunk);
    if (continuation != null) {
        if (Utils.IS_TEST_MODE || LOG.isDebugEnabled()) {
            LOG.info("using continuation for " + chunk);
        }
        return continuation.continueCompilation();
    }
    final Set<String> toCompilePaths = getPathsToCompile(toCompile);
    JpsSdk<JpsDummyElement> jdk = GroovyBuilder.getJdk(chunk);
    String version = jdk == null ? SystemInfo.JAVA_RUNTIME_VERSION : jdk.getVersionString();
    boolean inProcess = "true".equals(System.getProperty("groovyc.in.process", "true"));
    boolean mayDependOnUtilJar = version != null && StringUtil.compareVersionNumbers(version, "1.6") >= 0;
    boolean optimizeClassLoading = !inProcess && mayDependOnUtilJar && ourOptimizeThreshold != 0 && toCompilePaths.size() >= ourOptimizeThreshold;
    Map<String, String> class2Src = buildClassToSourceMap(chunk, context, toCompilePaths, finalOutputs);
    final String encoding = context.getProjectDescriptor().getEncodingConfiguration().getPreferredModuleChunkEncoding(chunk);
    List<String> patchers = new ArrayList<>();
    for (GroovyBuilderExtension extension : JpsServiceManager.getInstance().getExtensions(GroovyBuilderExtension.class)) {
        patchers.addAll(extension.getCompilationUnitPatchers(context, chunk));
    }
    Collection<String> classpath = generateClasspath(context, chunk);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Optimized class loading: " + optimizeClassLoading);
        LOG.debug("Groovyc classpath: " + classpath);
    }
    final File tempFile = GroovycOutputParser.fillFileWithGroovycParameters(compilerOutput, toCompilePaths, finalOutputs.values(), class2Src, encoding, patchers, optimizeClassLoading ? StringUtil.join(classpath, File.pathSeparator) : "");
    GroovycFlavor groovyc = inProcess ? new InProcessGroovyc(finalOutputs.values(), hasStubExcludes) : new ForkedGroovyc(optimizeClassLoading, chunk);
    GroovycOutputParser parser = new GroovycOutputParser(chunk, context);
    continuation = groovyc.runGroovyc(classpath, myForStubs, settings, tempFile, parser);
    setContinuation(context, chunk, continuation);
    return parser;
}
Also used : JpsDummyElement(org.jetbrains.jps.model.JpsDummyElement) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with JpsDummyElement

use of org.jetbrains.jps.model.JpsDummyElement in project intellij-elixir by KronicDeth.

the class ElixirTargetBuilderUtil method getSdk.

@NotNull
public static JpsSdk<JpsDummyElement> getSdk(@NotNull CompileContext context, @NotNull JpsModule module) throws ProjectBuildException {
    JpsSdk<JpsDummyElement> sdk = module.getSdk(JpsElixirSdkType.INSTANCE);
    if (sdk == null) {
        String errorMessage = "No SDK for module " + module.getName();
        context.processMessage(new CompilerMessage(ElixirBuilder.BUILDER_NAME, BuildMessage.Kind.ERROR, errorMessage));
        throw new ProjectBuildException(errorMessage);
    }
    return sdk;
}
Also used : ProjectBuildException(org.jetbrains.jps.incremental.ProjectBuildException) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) JpsDummyElement(org.jetbrains.jps.model.JpsDummyElement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

JpsDummyElement (org.jetbrains.jps.model.JpsDummyElement)11 File (java.io.File)7 NotNull (org.jetbrains.annotations.NotNull)4 CompilerMessage (org.jetbrains.jps.incremental.messages.CompilerMessage)4 JpsModule (org.jetbrains.jps.model.module.JpsModule)4 ProjectBuildException (org.jetbrains.jps.incremental.ProjectBuildException)3 ProgressMessage (org.jetbrains.jps.incremental.messages.ProgressMessage)3 InstrumentationClassFinder (com.intellij.compiler.instrumentation.InstrumentationClassFinder)2 THashSet (gnu.trove.THashSet)2 IOException (java.io.IOException)2 ProjectBuilderLogger (org.jetbrains.jps.builders.logging.ProjectBuilderLogger)2 JpsProject (org.jetbrains.jps.model.JpsProject)2 EnhancerRunner (com.intellij.appengine.rt.EnhancerRunner)1 ApplicationStarter (com.intellij.openapi.application.ApplicationStarter)1 PathManager (com.intellij.openapi.application.PathManager)1 Logger (com.intellij.openapi.diagnostic.Logger)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 ProgressManager (com.intellij.openapi.progress.ProgressManager)1 com.intellij.openapi.projectRoots (com.intellij.openapi.projectRoots)1