Search in sources :

Example 1 with FlexBuildConfiguration

use of com.intellij.lang.javascript.flex.build.FlexBuildConfiguration in project intellij-plugins by JetBrains.

the class FlexModuleConverter method readNamespaceAndManifestInfoList.

private static void readNamespaceAndManifestInfoList(final Element element, final FlexBuildConfiguration oldConfig) throws InvalidDataException {
    final List<FlexBuildConfiguration.NamespaceAndManifestFileInfo> namespaceAndManifestFileInfoList = new ArrayList<>();
    final Element namespaceAndManifestFileInfoListElement = element.getChild(NAMESPACE_AND_MANIFEST_FILE_INFO_LIST_ELEMENT_NAME);
    if (namespaceAndManifestFileInfoListElement != null) {
        for (final Object namespaceAndManifestFileInfoElement : namespaceAndManifestFileInfoListElement.getChildren(FlexBuildConfiguration.NamespaceAndManifestFileInfo.class.getSimpleName())) {
            final FlexBuildConfiguration.NamespaceAndManifestFileInfo namespaceAndManifestFileInfo = new FlexBuildConfiguration.NamespaceAndManifestFileInfo();
            DefaultJDOMExternalizer.readExternal(namespaceAndManifestFileInfo, (Element) namespaceAndManifestFileInfoElement);
            namespaceAndManifestFileInfoList.add(namespaceAndManifestFileInfo);
        }
    }
    oldConfig.NAMESPACE_AND_MANIFEST_FILE_INFO_LIST = namespaceAndManifestFileInfoList;
}
Also used : Element(org.jdom.Element) FlexBuildConfiguration(com.intellij.lang.javascript.flex.build.FlexBuildConfiguration)

Example 2 with FlexBuildConfiguration

use of com.intellij.lang.javascript.flex.build.FlexBuildConfiguration in project intellij-plugins by JetBrains.

the class FlexModuleConverter method processConfiguration.

private void processConfiguration(@Nullable FlexBuildConfiguration oldConfiguration, ModifiableFlexBuildConfiguration newBuildConfiguration, final ModuleSettings module, boolean facet, @Nullable String facetSdkName, Set<String> usedSdksNames, Collection<Element> orderEntriesToAdd, Set<Element> usedModuleLibrariesEntries) throws CannotConvertException {
    if (oldConfiguration == null) {
        newBuildConfiguration.setOutputType(OutputType.Application);
    } else {
        if (FlexBuildConfiguration.LIBRARY.equals(oldConfiguration.OUTPUT_TYPE)) {
            newBuildConfiguration.setOutputType(OutputType.Library);
        } else {
            newBuildConfiguration.setOutputType(OutputType.Application);
        }
        if (newBuildConfiguration.getOutputType() == OutputType.Application) {
            newBuildConfiguration.setMainClass(oldConfiguration.MAIN_CLASS);
            myParams.addAppModuleAndBCName(module.getModuleName(), newBuildConfiguration.getName());
        }
        newBuildConfiguration.setOutputFileName(oldConfiguration.OUTPUT_FILE_NAME);
        newBuildConfiguration.setSkipCompile(!oldConfiguration.DO_BUILD);
        final ModifiableCompilerOptions newCompilerOptions = newBuildConfiguration.getCompilerOptions();
        newCompilerOptions.setAllOptions(convertCompilerOptions(oldConfiguration, module, newCompilerOptions));
    }
    String outputFolder;
    if (facet && oldConfiguration != null && oldConfiguration.USE_FACET_COMPILE_OUTPUT_PATH) {
        outputFolder = PathUtil.getCanonicalPath(module.expandPath(oldConfiguration.FACET_COMPILE_OUTPUT_PATH));
    } else {
        outputFolder = getOutputFolder(module);
    }
    newBuildConfiguration.setOutputFolder(outputFolder);
    Collection<Element> orderEntriesToRemove = new ArrayList<>();
    // TODO filter out java libraries and remove their order entries
    for (Element orderEntry : module.getOrderEntries()) {
        String orderEntryType = orderEntry.getAttributeValue(OrderEntryFactory.ORDER_ENTRY_TYPE_ATTR);
        if (ModuleLibraryOrderEntryImpl.ENTRY_TYPE.equals(orderEntryType)) {
            Element library = orderEntry.getChild(LibraryImpl.ELEMENT);
            if (!isApplicableLibrary(library, s -> module.expandPath(s))) {
                // ignore non-flex module library
                orderEntriesToRemove.add(orderEntry);
                continue;
            }
            if (facet && isAutogeneratedLibrary(library)) {
                orderEntriesToRemove.add(orderEntry);
                continue;
            }
            Element libraryProperties;
            if (!usedModuleLibrariesEntries.add(orderEntry)) {
                // this library is already used by another build configuration, create new entry with new library
                Element newEntry = orderEntry.clone();
                orderEntriesToAdd.add(newEntry);
                library = orderEntry.getChild(LibraryImpl.ELEMENT);
                libraryProperties = library.getChild(LibraryImpl.PROPERTIES_ELEMENT);
            } else {
                library.setAttribute(LibraryImpl.LIBRARY_TYPE_ATTR, FlexLibraryType.FLEX_LIBRARY.getKindId());
                libraryProperties = new Element(LibraryImpl.PROPERTIES_ELEMENT);
                //noinspection unchecked
                library.getChildren().add(0, libraryProperties);
            }
            String libraryId = FlexLibraryIdGenerator.generateId();
            XmlSerializer.serializeInto(new FlexLibraryProperties(libraryId), libraryProperties);
            ModifiableModuleLibraryEntry moduleLibraryEntry = ConversionHelper.createModuleLibraryEntry(libraryId);
            convertDependencyType(orderEntry, moduleLibraryEntry.getDependencyType());
            newBuildConfiguration.getDependencies().getModifiableEntries().add(moduleLibraryEntry);
        } else if ("library".equals(orderEntryType)) {
            String libraryName = orderEntry.getAttributeValue("name");
            String libraryLevel = orderEntry.getAttributeValue("level");
            if (myParams.libraryExists(libraryName, libraryLevel)) {
                myParams.changeLibraryTypeToFlex(libraryName, libraryLevel);
                ModifiableSharedLibraryEntry sharedLibraryEntry = ConversionHelper.createSharedLibraryEntry(libraryName, libraryLevel);
                convertDependencyType(orderEntry, sharedLibraryEntry.getDependencyType());
                newBuildConfiguration.getDependencies().getModifiableEntries().add(sharedLibraryEntry);
            } else {
                orderEntriesToRemove.add(orderEntry);
            }
        } else if (ModuleOrderEntryImpl.ENTRY_TYPE.equals(orderEntryType)) {
            String moduleName = orderEntry.getAttributeValue(ModuleOrderEntryImpl.MODULE_NAME_ATTR);
            Collection<String> bcNames = myParams.getBcNamesForDependency(moduleName, newBuildConfiguration.getNature());
            for (String bcName : bcNames) {
                ModifiableBuildConfigurationEntry bcEntry = ConversionHelper.createBuildConfigurationEntry(moduleName, bcName);
                convertDependencyType(orderEntry, bcEntry.getDependencyType());
                newBuildConfiguration.getDependencies().getModifiableEntries().add(bcEntry);
            }
            if (bcNames.isEmpty()) {
                orderEntriesToRemove.add(orderEntry);
            }
        } else if (ModuleJdkOrderEntryImpl.ENTRY_TYPE.equals(orderEntryType)) {
            if (!facet) {
                String sdkName = orderEntry.getAttributeValue(ModuleJdkOrderEntryImpl.JDK_NAME_ATTR);
                String newSdkName = processSdkEntry(newBuildConfiguration, oldConfiguration, sdkName);
                ContainerUtil.addIfNotNull(usedSdksNames, newSdkName);
            }
            orderEntriesToRemove.add(orderEntry);
        } else if (InheritedJdkOrderEntryImpl.ENTRY_TYPE.equals(orderEntryType)) {
            if (!facet) {
                String newSdkName = processSdkEntry(newBuildConfiguration, oldConfiguration, myParams.projectSdkName);
                ContainerUtil.addIfNotNull(usedSdksNames, newSdkName);
            }
            orderEntriesToRemove.add(orderEntry);
        }
    }
    if (facetSdkName != null) {
        String newSdkName = processSdkEntry(newBuildConfiguration, oldConfiguration, facetSdkName);
        ContainerUtil.addIfNotNull(usedSdksNames, newSdkName);
    }
    if (!orderEntriesToRemove.isEmpty()) {
        module.getOrderEntries().removeAll(orderEntriesToRemove);
    }
    if (BCUtils.canHaveRLMsAndRuntimeStylesheets(newBuildConfiguration) && oldConfiguration != null && !oldConfiguration.CSS_FILES_LIST.isEmpty()) {
        final Collection<String> cssFilesToCompile = new ArrayList<>();
        for (String cssPath : oldConfiguration.CSS_FILES_LIST) {
            cssFilesToCompile.add(PathUtil.getCanonicalPath(module.expandPath(cssPath)));
        }
        newBuildConfiguration.setCssFilesToCompile(cssFilesToCompile);
    }
}
Also used : FlexCompositeSdk(com.intellij.lang.javascript.flex.projectStructure.FlexCompositeSdk) DependencyScope(com.intellij.openapi.roots.DependencyScope) THashMap(gnu.trove.THashMap) TargetPlatform(com.intellij.flex.model.bc.TargetPlatform) FacetManagerImpl(com.intellij.facet.FacetManagerImpl) BCUtils(com.intellij.lang.javascript.flex.projectStructure.options.BCUtils) FileUtil(com.intellij.openapi.util.io.FileUtil) Logger(com.intellij.openapi.diagnostic.Logger) FlexLibraryType(com.intellij.lang.javascript.flex.library.FlexLibraryType) CompilerModuleExtension(com.intellij.openapi.roots.CompilerModuleExtension) StdModuleTypes(com.intellij.openapi.module.StdModuleTypes) OrderRootType(com.intellij.openapi.roots.OrderRootType) Attribute(org.jdom.Attribute) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) FileFilters(com.intellij.openapi.util.io.FileFilters) Nullable(org.jetbrains.annotations.Nullable) JpsFacetSerializer(org.jetbrains.jps.model.serialization.facet.JpsFacetSerializer) JpsJavaModelSerializerExtension(org.jetbrains.jps.model.serialization.java.JpsJavaModelSerializerExtension) FlexLibraryIdGenerator(com.intellij.lang.javascript.flex.projectStructure.model.impl.FlexLibraryIdGenerator) ProjectJdkTable(com.intellij.openapi.projectRoots.ProjectJdkTable) Function(com.intellij.util.Function) FlexUtils(com.intellij.lang.javascript.flex.FlexUtils) XmlSerializer(com.intellij.util.xmlb.XmlSerializer) java.util(java.util) OutputType(com.intellij.flex.model.bc.OutputType) ArrayUtil(com.intellij.util.ArrayUtil) FlexModuleType(com.intellij.lang.javascript.flex.FlexModuleType) JarDirectories(com.intellij.openapi.roots.impl.libraries.JarDirectories) NonNls(org.jetbrains.annotations.NonNls) InvalidDataException(com.intellij.openapi.util.InvalidDataException) ContainerUtil(com.intellij.util.containers.ContainerUtil) ConversionHelper(com.intellij.lang.javascript.flex.projectStructure.model.impl.ConversionHelper) FlexBuildConfiguration(com.intellij.lang.javascript.flex.build.FlexBuildConfiguration) DefaultJDOMExternalizer(com.intellij.openapi.util.DefaultJDOMExternalizer) LibraryImpl(com.intellij.openapi.roots.impl.libraries.LibraryImpl) Factory(com.intellij.lang.javascript.flex.projectStructure.model.impl.Factory) JDOMUtil(com.intellij.openapi.util.JDOMUtil) FlexSdkUtils(com.intellij.lang.javascript.flex.sdk.FlexSdkUtils) FlexBuildConfigurationManagerImpl(com.intellij.lang.javascript.flex.projectStructure.model.impl.FlexBuildConfigurationManagerImpl) VfsUtilCore(com.intellij.openapi.vfs.VfsUtilCore) JDomSerializationUtil(org.jetbrains.jps.model.serialization.JDomSerializationUtil) com.intellij.lang.javascript.flex.projectStructure.model(com.intellij.lang.javascript.flex.projectStructure.model) Sdk(com.intellij.openapi.projectRoots.Sdk) File(java.io.File) ConversionProcessor(com.intellij.conversion.ConversionProcessor) ModuleSettings(com.intellij.conversion.ModuleSettings) CannotConvertException(com.intellij.conversion.CannotConvertException) JarFileSystem(com.intellij.openapi.vfs.JarFileSystem) com.intellij.openapi.roots.impl(com.intellij.openapi.roots.impl) PathUtil(com.intellij.util.PathUtil) CompilerOptionInfo(com.intellij.flex.model.bc.CompilerOptionInfo) Element(org.jdom.Element) FlexLibraryProperties(com.intellij.lang.javascript.flex.library.FlexLibraryProperties) FlexLibraryProperties(com.intellij.lang.javascript.flex.library.FlexLibraryProperties) Element(org.jdom.Element)

Example 3 with FlexBuildConfiguration

use of com.intellij.lang.javascript.flex.build.FlexBuildConfiguration in project intellij-plugins by JetBrains.

the class ConversionParams method getBcNamesForDependency.

public Collection<String> getBcNamesForDependency(String moduleName, final BuildConfigurationNature dependantNature) {
    ModuleSettings moduleSettings = myContext.getModuleSettings(moduleName);
    // module is missing
    if (moduleSettings == null)
        return Collections.emptyList();
    if (FlexModuleConverter.isFlexModule(moduleSettings)) {
        Element flexBuildConfigurationElement = moduleSettings.getComponentElement(FlexBuildConfiguration.COMPONENT_NAME);
        if (flexBuildConfigurationElement != null) {
            FlexBuildConfiguration oldConfiguration = XmlSerializer.deserialize(flexBuildConfigurationElement, FlexBuildConfiguration.class);
            if (FlexBuildConfiguration.LIBRARY.equals(oldConfiguration.OUTPUT_TYPE)) {
                return Collections.singletonList(FlexModuleConverter.generateModuleBcName(moduleSettings));
            }
        } else {
            // this module might have already been processed
            Element buildConfigManagerElement = moduleSettings.getComponentElement(FlexBuildConfigurationManagerImpl.COMPONENT_NAME);
            if (buildConfigManagerElement != null) {
                FlexBuildConfigurationManagerImpl.State s = XmlSerializer.deserialize(buildConfigManagerElement, FlexBuildConfigurationManagerImpl.State.class);
                return ContainerUtil.mapNotNull(s.CONFIGURATIONS, bcState -> bcState.OUTPUT_TYPE == OutputType.Library ? bcState.NAME : null);
            }
        }
        return Collections.emptyList();
    }
    final List<Element> facets = FlexModuleConverter.getFlexFacets(moduleSettings);
    return ContainerUtil.mapNotNull(facets, facet -> {
        Element oldConfigurationElement = facet.getChild(JpsFacetSerializer.CONFIGURATION_TAG);
        if (oldConfigurationElement != null) {
            FlexBuildConfiguration oldConfiguration = XmlSerializer.deserialize(oldConfigurationElement, FlexBuildConfiguration.class);
            if (FlexBuildConfiguration.LIBRARY.equals(oldConfiguration.OUTPUT_TYPE)) {
                return FlexModuleConverter.generateFacetBcName(facets, facet);
            }
        }
        return null;
    });
}
Also used : FlexBuildConfigurationManagerImpl(com.intellij.lang.javascript.flex.projectStructure.model.impl.FlexBuildConfigurationManagerImpl) ModuleSettings(com.intellij.conversion.ModuleSettings) Element(org.jdom.Element) FlexBuildConfiguration(com.intellij.lang.javascript.flex.build.FlexBuildConfiguration)

Example 4 with FlexBuildConfiguration

use of com.intellij.lang.javascript.flex.build.FlexBuildConfiguration in project intellij-plugins by JetBrains.

the class FlexModuleConverter method readConditionalCompilerDefinitionList.

private static void readConditionalCompilerDefinitionList(final Element element, final FlexBuildConfiguration oldConfig) throws InvalidDataException {
    final List<FlexBuildConfiguration.ConditionalCompilationDefinition> conditionalCompilationDefinitionList = new ArrayList<>();
    final Element conditionalCompilerDefinitionListElement = element.getChild(CONDITIONAL_COMPILER_DEFINITION_LIST_ELEMENT_NAME);
    if (conditionalCompilerDefinitionListElement != null) {
        for (final Object conditionalCompilerDefinitionElement : conditionalCompilerDefinitionListElement.getChildren(FlexBuildConfiguration.ConditionalCompilationDefinition.class.getSimpleName())) {
            final FlexBuildConfiguration.ConditionalCompilationDefinition conditionalCompilationDefinition = new FlexBuildConfiguration.ConditionalCompilationDefinition();
            DefaultJDOMExternalizer.readExternal(conditionalCompilationDefinition, (Element) conditionalCompilerDefinitionElement);
            conditionalCompilationDefinitionList.add(conditionalCompilationDefinition);
        }
    }
    oldConfig.CONDITIONAL_COMPILATION_DEFINITION_LIST = conditionalCompilationDefinitionList;
}
Also used : Element(org.jdom.Element) FlexBuildConfiguration(com.intellij.lang.javascript.flex.build.FlexBuildConfiguration)

Example 5 with FlexBuildConfiguration

use of com.intellij.lang.javascript.flex.build.FlexBuildConfiguration in project intellij-plugins by JetBrains.

the class FlexModuleConverter method process.

@Override
public void process(ModuleSettings moduleSettings) throws CannotConvertException {
    FlexBuildConfigurationManagerImpl configurationManager = ConversionHelper.createBuildConfigurationManager();
    Collection<Element> orderEntriesToAdd = new ArrayList<>();
    Set<String> usedSdksNames = new HashSet<>();
    final Set<Element> usedModuleLibrariesEntries = new HashSet<>();
    if (isFlexModule(moduleSettings)) {
        ModifiableFlexBuildConfiguration newConfiguration = (ModifiableFlexBuildConfiguration) configurationManager.getBuildConfigurations()[0];
        newConfiguration.setName(generateModuleBcName(moduleSettings));
        Element oldConfigurationElement = moduleSettings.getComponentElement(FlexBuildConfiguration.COMPONENT_NAME);
        FlexBuildConfiguration oldConfiguration = oldConfigurationElement != null ? XmlSerializer.deserialize(oldConfigurationElement, FlexBuildConfiguration.class) : null;
        processConfiguration(oldConfiguration, newConfiguration, moduleSettings, false, null, usedSdksNames, orderEntriesToAdd, usedModuleLibrariesEntries);
        if (oldConfigurationElement != null) {
            oldConfigurationElement.detach();
        }
    } else {
        List<Element> flexFacets = getFlexFacets(moduleSettings);
        for (int i = 0; i < flexFacets.size(); i++) {
            Element facet = flexFacets.get(i);
            ModifiableFlexBuildConfiguration newConfiguration;
            if (i == 0) {
                newConfiguration = (ModifiableFlexBuildConfiguration) configurationManager.getBuildConfigurations()[0];
            } else {
                newConfiguration = ConversionHelper.createBuildConfiguration(configurationManager);
            }
            newConfiguration.setName(generateFacetBcName(flexFacets, facet));
            Element oldConfigurationElement = facet.getChild(JpsFacetSerializer.CONFIGURATION_TAG);
            if (oldConfigurationElement != null) {
                FlexBuildConfiguration oldConfiguration = XmlSerializer.deserialize(oldConfigurationElement, FlexBuildConfiguration.class);
                try {
                    readNamespaceAndManifestInfoList(oldConfigurationElement, oldConfiguration);
                    readConditionalCompilerDefinitionList(oldConfigurationElement, oldConfiguration);
                    readCssFilesList(oldConfigurationElement, oldConfiguration);
                } catch (InvalidDataException ignore) {
                /* unlucky */
                }
                final String facetSdkName = oldConfigurationElement.getAttributeValue(FLEX_SDK_ATTR_NAME);
                processConfiguration(oldConfiguration, newConfiguration, moduleSettings, true, facetSdkName, usedSdksNames, orderEntriesToAdd, usedModuleLibrariesEntries);
            } else {
                processConfiguration(null, newConfiguration, moduleSettings, true, null, usedSdksNames, orderEntriesToAdd, usedModuleLibrariesEntries);
            }
        }
        moduleSettings.setModuleType(FlexModuleType.MODULE_TYPE_ID);
        moduleSettings.getComponentElement(FacetManagerImpl.COMPONENT_NAME).getChildren(JpsFacetSerializer.FACET_TAG).removeAll(flexFacets);
    }
    Collection<Element> allEntries = new ArrayList<>();
    allEntries.addAll(usedModuleLibrariesEntries);
    allEntries.addAll(orderEntriesToAdd);
    for (Element orderEntry : allEntries) {
        if (DependencyScope.readExternal(orderEntry) == DependencyScope.TEST) {
            orderEntry.removeAttribute(DependencyScope.SCOPE_ATTR);
        }
    }
    if (!usedSdksNames.isEmpty()) {
        Element sdkEntryElement = new Element(OrderEntryFactory.ORDER_ENTRY_ELEMENT_NAME);
        sdkEntryElement.setAttribute(OrderEntryFactory.ORDER_ENTRY_TYPE_ATTR, "jdk");
        final String compositeSdkName = FlexCompositeSdk.getCompositeName(ArrayUtil.toStringArray(usedSdksNames));
        sdkEntryElement.setAttribute(ModuleJdkOrderEntryImpl.JDK_NAME_ATTR, compositeSdkName);
        sdkEntryElement.setAttribute(ModuleJdkOrderEntryImpl.JDK_TYPE_ATTR, FlexCompositeSdk.TYPE_ID);
        moduleSettings.getOrderEntries().add(sdkEntryElement);
    }
    Element rootManagerElement = JDomSerializationUtil.findOrCreateComponentElement(moduleSettings.getRootElement(), ModuleSettings.MODULE_ROOT_MANAGER_COMPONENT);
    rootManagerElement.addContent(orderEntriesToAdd);
    Element componentElement = JDomSerializationUtil.findOrCreateComponentElement(moduleSettings.getRootElement(), FlexBuildConfigurationManagerImpl.COMPONENT_NAME);
    addContent(ConversionHelper.serialize(configurationManager), componentElement);
    ignoreInapplicableFacets(moduleSettings);
}
Also used : FlexBuildConfigurationManagerImpl(com.intellij.lang.javascript.flex.projectStructure.model.impl.FlexBuildConfigurationManagerImpl) Element(org.jdom.Element) FlexBuildConfiguration(com.intellij.lang.javascript.flex.build.FlexBuildConfiguration) InvalidDataException(com.intellij.openapi.util.InvalidDataException)

Aggregations

FlexBuildConfiguration (com.intellij.lang.javascript.flex.build.FlexBuildConfiguration)5 Element (org.jdom.Element)5 FlexBuildConfigurationManagerImpl (com.intellij.lang.javascript.flex.projectStructure.model.impl.FlexBuildConfigurationManagerImpl)3 ModuleSettings (com.intellij.conversion.ModuleSettings)2 InvalidDataException (com.intellij.openapi.util.InvalidDataException)2 CannotConvertException (com.intellij.conversion.CannotConvertException)1 ConversionProcessor (com.intellij.conversion.ConversionProcessor)1 FacetManagerImpl (com.intellij.facet.FacetManagerImpl)1 CompilerOptionInfo (com.intellij.flex.model.bc.CompilerOptionInfo)1 OutputType (com.intellij.flex.model.bc.OutputType)1 TargetPlatform (com.intellij.flex.model.bc.TargetPlatform)1 FlexModuleType (com.intellij.lang.javascript.flex.FlexModuleType)1 FlexUtils (com.intellij.lang.javascript.flex.FlexUtils)1 FlexLibraryProperties (com.intellij.lang.javascript.flex.library.FlexLibraryProperties)1 FlexLibraryType (com.intellij.lang.javascript.flex.library.FlexLibraryType)1 FlexCompositeSdk (com.intellij.lang.javascript.flex.projectStructure.FlexCompositeSdk)1 com.intellij.lang.javascript.flex.projectStructure.model (com.intellij.lang.javascript.flex.projectStructure.model)1 ConversionHelper (com.intellij.lang.javascript.flex.projectStructure.model.impl.ConversionHelper)1 Factory (com.intellij.lang.javascript.flex.projectStructure.model.impl.Factory)1 FlexLibraryIdGenerator (com.intellij.lang.javascript.flex.projectStructure.model.impl.FlexLibraryIdGenerator)1