JPS: transferring compiler settings to the JPS
Original commit: 1176d58f40
This commit is contained in:
+1
@@ -0,0 +1 @@
|
|||||||
|
org.jetbrains.jet.jps.model.KotlinModelSerializerService
|
||||||
@@ -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<JpsKotlinCompilerSettings> {
|
||||||
|
static final JpsElementChildRole<JpsKotlinCompilerSettings> 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 extends CommonCompilerArguments> T merge(@NotNull CommonCompilerArguments from, @NotNull T to) {
|
||||||
|
Class<CommonCompilerArguments> 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
+48
@@ -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) {
|
||||||
|
}
|
||||||
|
}
|
||||||
+48
@@ -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) {
|
||||||
|
}
|
||||||
|
}
|
||||||
+48
@@ -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) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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<? extends JpsProjectExtensionSerializer> getProjectExtensionSerializers() {
|
||||||
|
return Arrays.asList(new KotlinCommonCompilerSettingsSerializer(),
|
||||||
|
new Kotlin2JvmCompilerSettingsSerializer(),
|
||||||
|
new Kotlin2JsCompilerSettingsSerializer());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user