diff --git a/jps/jps-plugin/src/META-INF/services/org.jetbrains.jps.model.serialization.JpsModelSerializerExtension b/jps/jps-plugin/src/META-INF/services/org.jetbrains.jps.model.serialization.JpsModelSerializerExtension new file mode 100644 index 00000000000..6026c57ec4b --- /dev/null +++ b/jps/jps-plugin/src/META-INF/services/org.jetbrains.jps.model.serialization.JpsModelSerializerExtension @@ -0,0 +1 @@ +org.jetbrains.jet.jps.model.KotlinModelSerializerService diff --git a/jps/jps-plugin/src/org/jetbrains/jet/jps/JpsKotlinCompilerSettings.java b/jps/jps-plugin/src/org/jetbrains/jet/jps/JpsKotlinCompilerSettings.java new file mode 100644 index 00000000000..b46de016e22 --- /dev/null +++ b/jps/jps-plugin/src/org/jetbrains/jet/jps/JpsKotlinCompilerSettings.java @@ -0,0 +1,121 @@ +/* + * Copyright 2010-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.jps; + +import com.intellij.util.xmlb.Accessor; +import com.intellij.util.xmlb.XmlSerializerUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.cli.common.arguments.CommonCompilerArguments; +import org.jetbrains.jet.cli.common.arguments.K2JSCompilerArguments; +import org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments; +import org.jetbrains.jps.model.JpsElementChildRole; +import org.jetbrains.jps.model.JpsProject; +import org.jetbrains.jps.model.ex.JpsElementBase; +import org.jetbrains.jps.model.ex.JpsElementChildRoleBase; + +public class JpsKotlinCompilerSettings extends JpsElementBase { + static final JpsElementChildRole ROLE = JpsElementChildRoleBase.create("Kotlin Compiler Settings"); + + @NotNull + public CommonCompilerArguments commonCompilerSettings = CommonCompilerArguments.DUMMY; + @NotNull + public K2JVMCompilerArguments k2JvmCompilerSettings = new K2JVMCompilerArguments(); + @NotNull + public K2JSCompilerArguments k2JsCompilerSettings = new K2JSCompilerArguments(); + + @NotNull + @Override + public JpsKotlinCompilerSettings createCopy() { + JpsKotlinCompilerSettings copy = new JpsKotlinCompilerSettings(); + copy.commonCompilerSettings = this.commonCompilerSettings; + copy.k2JvmCompilerSettings = this.k2JvmCompilerSettings; + copy.k2JsCompilerSettings = this.k2JsCompilerSettings; + return copy; + } + + @Override + public void applyChanges(@NotNull JpsKotlinCompilerSettings modified) { + // do nothing + } + + @NotNull + public static JpsKotlinCompilerSettings getSettings(@NotNull JpsProject project) { + JpsKotlinCompilerSettings settings = project.getContainer().getChild(ROLE); + if (settings == null) { + settings = new JpsKotlinCompilerSettings(); + } + return settings; + } + + @NotNull + public static JpsKotlinCompilerSettings getOrCreateSettings(@NotNull JpsProject project) { + JpsKotlinCompilerSettings settings = project.getContainer().getChild(ROLE); + if (settings == null) { + settings = new JpsKotlinCompilerSettings(); + project.getContainer().setChild(ROLE, settings); + } + return settings; + } + + @NotNull + public static CommonCompilerArguments getCommonSettings(@NotNull JpsProject project) { + JpsKotlinCompilerSettings settings = getSettings(project); + return settings.commonCompilerSettings; + } + + public static void setCommonSettings(@NotNull JpsProject project, @NotNull CommonCompilerArguments commonCompilerSettings) { + JpsKotlinCompilerSettings settings = getOrCreateSettings(project); + settings.commonCompilerSettings = commonCompilerSettings; + } + + @NotNull + public static K2JVMCompilerArguments getMergedK2JvmSettings(@NotNull JpsProject project) { + JpsKotlinCompilerSettings settings = getSettings(project); + return merge(settings.commonCompilerSettings, settings.k2JvmCompilerSettings); + } + + public static void setK2JvmSettings(@NotNull JpsProject project, @NotNull K2JVMCompilerArguments k2JvmCompilerSettings) { + JpsKotlinCompilerSettings settings = getOrCreateSettings(project); + settings.k2JvmCompilerSettings = k2JvmCompilerSettings; + } + + @NotNull + public static K2JSCompilerArguments getMergedK2JsSettings(@NotNull JpsProject project) { + JpsKotlinCompilerSettings settings = getSettings(project); + return merge(settings.commonCompilerSettings, settings.k2JsCompilerSettings); + } + + public static void setK2JsSettings(@NotNull JpsProject project, @NotNull K2JSCompilerArguments k2JsCompilerSettings) { + JpsKotlinCompilerSettings settings = getOrCreateSettings(project); + settings.k2JsCompilerSettings = k2JsCompilerSettings; + } + + @NotNull + private static T merge(@NotNull CommonCompilerArguments from, @NotNull T to) { + Class fromClass = CommonCompilerArguments.class; + + assert fromClass.isAssignableFrom(to.getClass()) : to.getClass() + " is not assignable to " + fromClass; + + T mergedCopy = XmlSerializerUtil.createCopy(to); + + for (Accessor accessor : XmlSerializerUtil.getAccessors(fromClass)) { + accessor.write(mergedCopy, accessor.read(from)); + } + + return mergedCopy; + } +} diff --git a/jps/jps-plugin/src/org/jetbrains/jet/jps/model/Kotlin2JsCompilerSettingsSerializer.java b/jps/jps-plugin/src/org/jetbrains/jet/jps/model/Kotlin2JsCompilerSettingsSerializer.java new file mode 100644 index 00000000000..e0d061646bd --- /dev/null +++ b/jps/jps-plugin/src/org/jetbrains/jet/jps/model/Kotlin2JsCompilerSettingsSerializer.java @@ -0,0 +1,48 @@ +/* + * Copyright 2010-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.jps.model; + +import com.intellij.util.xmlb.XmlSerializer; +import org.jdom.Element; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.cli.common.arguments.K2JSCompilerArguments; +import org.jetbrains.jet.jps.JpsKotlinCompilerSettings; +import org.jetbrains.jps.model.JpsProject; +import org.jetbrains.jps.model.serialization.JpsProjectExtensionSerializer; + +import static org.jetbrains.jet.compiler.SettingConstants.KOTLIN_COMPILER_SETTINGS_FILE; +import static org.jetbrains.jet.compiler.SettingConstants.KOTLIN_TO_JS_COMPILER_SETTINGS_SECTION; + +class Kotlin2JsCompilerSettingsSerializer extends JpsProjectExtensionSerializer { + Kotlin2JsCompilerSettingsSerializer() { + super(KOTLIN_COMPILER_SETTINGS_FILE, KOTLIN_TO_JS_COMPILER_SETTINGS_SECTION); + } + + @Override + public void loadExtension(@NotNull JpsProject project, @NotNull Element componentTag) { + K2JSCompilerArguments settings = XmlSerializer.deserialize(componentTag, K2JSCompilerArguments.class); + if (settings == null) { + settings = new K2JSCompilerArguments(); + } + + JpsKotlinCompilerSettings.setK2JsSettings(project, settings); + } + + @Override + public void saveExtension(@NotNull JpsProject project, @NotNull Element componentTag) { + } +} diff --git a/jps/jps-plugin/src/org/jetbrains/jet/jps/model/Kotlin2JvmCompilerSettingsSerializer.java b/jps/jps-plugin/src/org/jetbrains/jet/jps/model/Kotlin2JvmCompilerSettingsSerializer.java new file mode 100644 index 00000000000..8f9752b55a3 --- /dev/null +++ b/jps/jps-plugin/src/org/jetbrains/jet/jps/model/Kotlin2JvmCompilerSettingsSerializer.java @@ -0,0 +1,48 @@ +/* + * Copyright 2010-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.jps.model; + +import com.intellij.util.xmlb.XmlSerializer; +import org.jdom.Element; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments; +import org.jetbrains.jet.jps.JpsKotlinCompilerSettings; +import org.jetbrains.jps.model.JpsProject; +import org.jetbrains.jps.model.serialization.JpsProjectExtensionSerializer; + +import static org.jetbrains.jet.compiler.SettingConstants.KOTLIN_COMPILER_SETTINGS_FILE; +import static org.jetbrains.jet.compiler.SettingConstants.KOTLIN_TO_JVM_COMPILER_SETTINGS_SECTION; + +class Kotlin2JvmCompilerSettingsSerializer extends JpsProjectExtensionSerializer { + Kotlin2JvmCompilerSettingsSerializer() { + super(KOTLIN_COMPILER_SETTINGS_FILE, KOTLIN_TO_JVM_COMPILER_SETTINGS_SECTION); + } + + @Override + public void loadExtension(@NotNull JpsProject project, @NotNull Element componentTag) { + K2JVMCompilerArguments settings = XmlSerializer.deserialize(componentTag, K2JVMCompilerArguments.class); + if (settings == null) { + settings = new K2JVMCompilerArguments(); + } + + JpsKotlinCompilerSettings.setK2JvmSettings(project, settings); + } + + @Override + public void saveExtension(@NotNull JpsProject project, @NotNull Element componentTag) { + } +} \ No newline at end of file diff --git a/jps/jps-plugin/src/org/jetbrains/jet/jps/model/KotlinCommonCompilerSettingsSerializer.java b/jps/jps-plugin/src/org/jetbrains/jet/jps/model/KotlinCommonCompilerSettingsSerializer.java new file mode 100644 index 00000000000..9a284e1ebad --- /dev/null +++ b/jps/jps-plugin/src/org/jetbrains/jet/jps/model/KotlinCommonCompilerSettingsSerializer.java @@ -0,0 +1,48 @@ +/* + * Copyright 2010-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.jps.model; + +import com.intellij.util.xmlb.XmlSerializer; +import org.jdom.Element; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.cli.common.arguments.CommonCompilerArguments; +import org.jetbrains.jet.jps.JpsKotlinCompilerSettings; +import org.jetbrains.jps.model.JpsProject; +import org.jetbrains.jps.model.serialization.JpsProjectExtensionSerializer; + +import static org.jetbrains.jet.compiler.SettingConstants.KOTLIN_COMMON_COMPILER_SETTINGS_SECTION; +import static org.jetbrains.jet.compiler.SettingConstants.KOTLIN_COMPILER_SETTINGS_FILE; + +class KotlinCommonCompilerSettingsSerializer extends JpsProjectExtensionSerializer { + KotlinCommonCompilerSettingsSerializer() { + super(KOTLIN_COMPILER_SETTINGS_FILE, KOTLIN_COMMON_COMPILER_SETTINGS_SECTION); + } + + @Override + public void loadExtension(@NotNull JpsProject project, @NotNull Element componentTag) { + CommonCompilerArguments settings = XmlSerializer.deserialize(componentTag, CommonCompilerArguments.DummyImpl.class); + if (settings == null) { + settings = CommonCompilerArguments.DUMMY; + } + + JpsKotlinCompilerSettings.setCommonSettings(project, settings); + } + + @Override + public void saveExtension(@NotNull JpsProject project, @NotNull Element componentTag) { + } +} diff --git a/jps/jps-plugin/src/org/jetbrains/jet/jps/model/KotlinModelSerializerService.java b/jps/jps-plugin/src/org/jetbrains/jet/jps/model/KotlinModelSerializerService.java new file mode 100644 index 00000000000..7ce881cc715 --- /dev/null +++ b/jps/jps-plugin/src/org/jetbrains/jet/jps/model/KotlinModelSerializerService.java @@ -0,0 +1,34 @@ +/* + * Copyright 2010-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.jps.model; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jps.model.serialization.JpsModelSerializerExtension; +import org.jetbrains.jps.model.serialization.JpsProjectExtensionSerializer; + +import java.util.Arrays; +import java.util.List; + +public class KotlinModelSerializerService extends JpsModelSerializerExtension { + @NotNull + @Override + public List getProjectExtensionSerializers() { + return Arrays.asList(new KotlinCommonCompilerSettingsSerializer(), + new Kotlin2JvmCompilerSettingsSerializer(), + new Kotlin2JsCompilerSettingsSerializer()); + } +}