mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
IDEA: add WebAssembly facet
This commit is contained in:
parent
156e7c98ee
commit
e93a0f1a6e
|
@ -15,21 +15,35 @@
|
|||
*/
|
||||
package org.teavm.idea.jps.model;
|
||||
|
||||
import com.intellij.util.xmlb.annotations.Transient;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jps.model.JpsElementChildRole;
|
||||
import org.jetbrains.jps.model.ex.JpsElementBase;
|
||||
import org.jetbrains.jps.model.ex.JpsElementChildRoleBase;
|
||||
import org.jetbrains.jps.model.module.JpsModule;
|
||||
import org.teavm.tooling.TeaVMTargetType;
|
||||
|
||||
public class TeaVMJpsConfiguration extends JpsElementBase<TeaVMJpsConfiguration> {
|
||||
static final JpsElementChildRole<TeaVMJpsConfiguration> ROLE = JpsElementChildRoleBase.create(
|
||||
"TeaVM configuration");
|
||||
|
||||
@Transient
|
||||
private TeaVMTargetType targetType;
|
||||
|
||||
private String mainClass;
|
||||
private String targetDirectory;
|
||||
private boolean minifying;
|
||||
private boolean sourceMapsFileGenerated = true;
|
||||
private boolean sourceFilesCopied = true;
|
||||
|
||||
public TeaVMTargetType getTargetType() {
|
||||
return targetType;
|
||||
}
|
||||
|
||||
public void setTargetType(TeaVMTargetType targetType) {
|
||||
this.targetType = targetType;
|
||||
}
|
||||
|
||||
public String getMainClass() {
|
||||
return mainClass;
|
||||
}
|
||||
|
|
|
@ -24,21 +24,40 @@ import org.jetbrains.jps.model.JpsElement;
|
|||
import org.jetbrains.jps.model.module.JpsModule;
|
||||
import org.jetbrains.jps.model.serialization.JpsModelSerializerExtension;
|
||||
import org.jetbrains.jps.model.serialization.facet.JpsFacetConfigurationSerializer;
|
||||
import org.teavm.tooling.TeaVMTargetType;
|
||||
|
||||
public class TeaVMModelSerializerService extends JpsModelSerializerExtension {
|
||||
@NotNull
|
||||
@Override
|
||||
public List<? extends JpsFacetConfigurationSerializer<?>> getFacetConfigurationSerializers() {
|
||||
return Arrays.asList(serializer);
|
||||
return Arrays.asList(jsSerializer, wasmSerializer);
|
||||
}
|
||||
|
||||
JpsFacetConfigurationSerializer<TeaVMJpsConfiguration> serializer =
|
||||
JpsFacetConfigurationSerializer<TeaVMJpsConfiguration> jsSerializer =
|
||||
new JpsFacetConfigurationSerializer<TeaVMJpsConfiguration>(TeaVMJpsConfiguration.ROLE,
|
||||
"teavm-js", "TeaVM (JS)") {
|
||||
@Override
|
||||
protected TeaVMJpsConfiguration loadExtension(@NotNull Element element, String s, JpsElement jpsElement,
|
||||
JpsModule jpsModule) {
|
||||
return XmlSerializer.deserialize(element, TeaVMJpsConfiguration.class);
|
||||
TeaVMJpsConfiguration configuration = XmlSerializer.deserialize(element, TeaVMJpsConfiguration.class);
|
||||
configuration.setTargetType(TeaVMTargetType.JAVASCRIPT);
|
||||
return configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveExtension(TeaVMJpsConfiguration configuration, Element element, JpsModule jpsModule) {
|
||||
}
|
||||
};
|
||||
|
||||
JpsFacetConfigurationSerializer<TeaVMJpsConfiguration> wasmSerializer =
|
||||
new JpsFacetConfigurationSerializer<TeaVMJpsConfiguration>(TeaVMJpsConfiguration.ROLE,
|
||||
"teavm-wasm", "TeaVM (WebAssembly)") {
|
||||
@Override
|
||||
protected TeaVMJpsConfiguration loadExtension(@NotNull Element element, String s, JpsElement jpsElement,
|
||||
JpsModule jpsModule) {
|
||||
TeaVMJpsConfiguration configuration = XmlSerializer.deserialize(element, TeaVMJpsConfiguration.class);
|
||||
configuration.setTargetType(TeaVMTargetType.WEBASSEMBLY);
|
||||
return configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -113,6 +113,7 @@ class TeaVMBuild {
|
|||
TeaVMTool tool = new TeaVMTool();
|
||||
tool.setProgressListener(createProgressListener(context));
|
||||
tool.setLog(new EmptyTeaVMToolLog());
|
||||
tool.setTargetType(config.getTargetType());
|
||||
tool.setMainClass(config.getMainClass());
|
||||
tool.setTargetDirectory(new File(config.getTargetDirectory()));
|
||||
tool.setClassLoader(buildClassLoader());
|
||||
|
|
|
@ -16,11 +16,14 @@
|
|||
package org.teavm.idea;
|
||||
|
||||
import com.intellij.facet.Facet;
|
||||
import com.intellij.facet.FacetType;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class TeaVMFacet extends Facet<TeaVMFacetConfiguration> {
|
||||
public TeaVMFacet(@NotNull Module module, @NotNull String name, @NotNull TeaVMFacetConfiguration configuration) {
|
||||
super(TeaVMFacetType.getInstance(), module, name, configuration, null);
|
||||
public TeaVMFacet(@NotNull FacetType<TeaVMFacet, TeaVMFacetConfiguration> facetType, @NotNull Module module,
|
||||
@NotNull String name, @NotNull TeaVMFacetConfiguration configuration, @Nullable Facet<?> underlyingFacet) {
|
||||
super(facetType, module, name, configuration, underlyingFacet);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ public class TeaVMFacetType extends FacetType<TeaVMFacet, TeaVMFacetConfiguratio
|
|||
@Override
|
||||
public TeaVMFacet createFacet(@NotNull Module module, String name, @NotNull TeaVMFacetConfiguration configuration,
|
||||
@Nullable Facet underlyingFacet) {
|
||||
return new TeaVMFacet(module, name, configuration);
|
||||
return new TeaVMFacet(this, module, name, configuration, underlyingFacet);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Copyright 2016 Alexey Andreev.
|
||||
*
|
||||
* 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.teavm.idea;
|
||||
|
||||
import com.intellij.facet.Facet;
|
||||
import com.intellij.facet.FacetType;
|
||||
import com.intellij.facet.FacetTypeId;
|
||||
import com.intellij.facet.FacetTypeRegistry;
|
||||
import com.intellij.openapi.module.JavaModuleType;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleType;
|
||||
import com.intellij.openapi.util.IconLoader;
|
||||
import javax.swing.Icon;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class TeaVMWebAssemblyFacetType extends FacetType<TeaVMFacet, TeaVMFacetConfiguration> {
|
||||
public static final FacetTypeId<TeaVMFacet> TYPE_ID = new FacetTypeId<>("teavm-wasm");
|
||||
private static final Icon icon = IconLoader.getIcon("/teavm-16.png");
|
||||
|
||||
public TeaVMWebAssemblyFacetType() {
|
||||
super(TYPE_ID, "teavm-wasm", "TeaVM (WebAssembly)");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TeaVMFacetConfiguration createDefaultConfiguration() {
|
||||
return new TeaVMFacetConfiguration();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TeaVMFacet createFacet(@NotNull Module module, String name, @NotNull TeaVMFacetConfiguration configuration,
|
||||
@Nullable Facet underlyingFacet) {
|
||||
return new TeaVMFacet(this, module, name, configuration, underlyingFacet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSuitableModuleType(ModuleType moduleType) {
|
||||
return moduleType instanceof JavaModuleType;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Icon getIcon() {
|
||||
return icon;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static TeaVMWebAssemblyFacetType getInstance() {
|
||||
return (TeaVMWebAssemblyFacetType) FacetTypeRegistry.getInstance().findFacetType(TYPE_ID);
|
||||
}
|
||||
}
|
|
@ -16,10 +16,13 @@
|
|||
package org.teavm.idea.maven;
|
||||
|
||||
import com.intellij.facet.FacetManager;
|
||||
import com.intellij.facet.FacetType;
|
||||
import com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.idea.maven.importing.MavenImporter;
|
||||
import org.jetbrains.idea.maven.importing.MavenRootModelAdapter;
|
||||
|
@ -29,8 +32,11 @@ import org.jetbrains.idea.maven.project.MavenProjectChanges;
|
|||
import org.jetbrains.idea.maven.project.MavenProjectsProcessorTask;
|
||||
import org.jetbrains.idea.maven.project.MavenProjectsTree;
|
||||
import org.teavm.idea.TeaVMFacet;
|
||||
import org.teavm.idea.TeaVMFacetConfiguration;
|
||||
import org.teavm.idea.TeaVMFacetType;
|
||||
import org.teavm.idea.TeaVMWebAssemblyFacetType;
|
||||
import org.teavm.idea.jps.model.TeaVMJpsConfiguration;
|
||||
import org.teavm.tooling.TeaVMTargetType;
|
||||
|
||||
public class TeaVMMavenImporter extends MavenImporter {
|
||||
public TeaVMMavenImporter() {
|
||||
|
@ -49,35 +55,53 @@ public class TeaVMMavenImporter extends MavenImporter {
|
|||
List<MavenProjectsProcessorTask> postTasks) {
|
||||
FacetManager facetManager = FacetManager.getInstance(module);
|
||||
|
||||
Set<String> targetTypes = new HashSet<>();
|
||||
for (MavenPlugin mavenPlugin : mavenProject.getPlugins()) {
|
||||
if (mavenPlugin.getGroupId().equals(myPluginGroupID)
|
||||
&& mavenPlugin.getArtifactId().equals(myPluginArtifactID)) {
|
||||
updateConfiguration(mavenPlugin, facetManager, module);
|
||||
updateConfiguration(mavenPlugin, facetManager, module, targetTypes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateConfiguration(MavenPlugin plugin, FacetManager facetManager, Module module) {
|
||||
private void updateConfiguration(MavenPlugin plugin, FacetManager facetManager, Module module,
|
||||
Set<String> targetTypes) {
|
||||
if (plugin.getConfigurationElement() != null) {
|
||||
updateConfiguration(plugin.getConfigurationElement(), facetManager, module);
|
||||
updateConfiguration(plugin.getConfigurationElement(), facetManager, module, targetTypes);
|
||||
}
|
||||
|
||||
for (MavenPlugin.Execution execution : plugin.getExecutions()) {
|
||||
if (execution.getGoals().contains("compile")) {
|
||||
if (execution.getConfigurationElement() != null) {
|
||||
updateConfiguration(execution.getConfigurationElement(), facetManager, module);
|
||||
updateConfiguration(execution.getConfigurationElement(), facetManager, module, targetTypes);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateConfiguration(Element source, FacetManager facetManager, Module module) {
|
||||
TeaVMFacet facet = facetManager.getFacetByType(TeaVMFacetType.TYPE_ID);
|
||||
private void updateConfiguration(Element source, FacetManager facetManager, Module module,
|
||||
Set<String> targetTypes) {
|
||||
FacetType<TeaVMFacet, TeaVMFacetConfiguration> facetType;
|
||||
switch (getTargetType(source)) {
|
||||
case JAVASCRIPT:
|
||||
facetType = TeaVMFacetType.getInstance();
|
||||
break;
|
||||
case WEBASSEMBLY:
|
||||
facetType = TeaVMWebAssemblyFacetType.getInstance();
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
if (!targetTypes.add(facetType.getStringId())) {
|
||||
return;
|
||||
}
|
||||
|
||||
TeaVMFacet facet = facetManager.getFacetByType(facetType.getId());
|
||||
if (facet == null) {
|
||||
TeaVMFacetType type = TeaVMFacetType.getInstance();
|
||||
facet = new TeaVMFacet(module, "TeaVM (JS)", type.createDefaultConfiguration());
|
||||
facetManager.addFacet(type, facet.getName(), facet);
|
||||
facet = new TeaVMFacet(facetType, module, facetType.getDefaultFacetName(),
|
||||
facetType.createDefaultConfiguration(), null);
|
||||
facetManager.addFacet(facetType, facet.getName(), facet);
|
||||
}
|
||||
|
||||
TeaVMJpsConfiguration configuration = facet.getConfiguration().getState();
|
||||
|
@ -104,4 +128,17 @@ public class TeaVMMavenImporter extends MavenImporter {
|
|||
|
||||
facet.getConfiguration().loadState(configuration);
|
||||
}
|
||||
|
||||
private TeaVMTargetType getTargetType(Element source) {
|
||||
for (Element child : source.getChildren()) {
|
||||
if (child.getName().equals("targetType")) {
|
||||
try {
|
||||
return TeaVMTargetType.valueOf(child.getTextTrim());
|
||||
} catch (IllegalArgumentException e) {
|
||||
// do nothing, continue iterating
|
||||
}
|
||||
}
|
||||
}
|
||||
return TeaVMTargetType.JAVASCRIPT;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
<programRunner implementation="org.teavm.idea.debug.TeaVMDebugRunner"/>
|
||||
|
||||
<facetType implementation="org.teavm.idea.TeaVMFacetType"/>
|
||||
<facetType implementation="org.teavm.idea.TeaVMWebAssemblyFacetType"/>
|
||||
</extensions>
|
||||
|
||||
<extensions defaultExtensionNs="org.jetbrains.idea.maven">
|
||||
|
|
Loading…
Reference in New Issue
Block a user