-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for opening openFL/lime nme and hxml files as projects
- Loading branch information
Showing
13 changed files
with
514 additions
and
11 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
src/main/java/com/intellij/plugins/haxe/haxelib/HaxeSdkFinder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright 2000-2013 JetBrains s.r.o. | ||
* Copyright 2014-2014 AS3Boyan | ||
* Copyright 2014-2014 Elias Ku | ||
* Copyright 2017 Eric Bishton | ||
* | ||
* 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 com.intellij.plugins.haxe.haxelib; | ||
|
||
import com.intellij.openapi.projectRoots.ProjectJdkTable; | ||
import com.intellij.openapi.projectRoots.Sdk; | ||
import com.intellij.openapi.roots.impl.SdkFinder; | ||
import com.intellij.plugins.haxe.config.sdk.HaxeSdkType; | ||
import lombok.CustomLog; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
@CustomLog | ||
public class HaxeSdkFinder extends SdkFinder { | ||
|
||
@Override | ||
public @Nullable Sdk findSdk(@NotNull String name, @NotNull String sdkType) { | ||
if (HaxeSdkType.getInstance().getName().equals(sdkType)) { | ||
return ProjectJdkTable.getInstance().findJdk(name, sdkType); | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
src/main/java/com/intellij/plugins/haxe/ide/projectStructure/HaxeProjectImportBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package com.intellij.plugins.haxe.ide.projectStructure; | ||
|
||
import com.intellij.ide.highlighter.ModuleFileType; | ||
import com.intellij.ide.util.projectWizard.ModuleBuilder; | ||
import com.intellij.openapi.application.ApplicationManager; | ||
import com.intellij.openapi.module.ModifiableModuleModel; | ||
import com.intellij.openapi.module.Module; | ||
import com.intellij.openapi.module.ModuleManager; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.openapi.projectRoots.ProjectJdkTable; | ||
import com.intellij.openapi.projectRoots.Sdk; | ||
import com.intellij.openapi.roots.ContentEntry; | ||
import com.intellij.openapi.roots.ModifiableRootModel; | ||
import com.intellij.openapi.roots.ModuleRootManager; | ||
import com.intellij.openapi.roots.impl.ModifiableModelCommitter; | ||
import com.intellij.openapi.roots.ui.configuration.ModulesProvider; | ||
import com.intellij.openapi.vfs.LocalFileSystem; | ||
import com.intellij.packaging.artifacts.ModifiableArtifactModel; | ||
import com.intellij.plugins.haxe.HaxeBundle; | ||
import com.intellij.plugins.haxe.config.HaxeConfiguration; | ||
import com.intellij.plugins.haxe.config.sdk.HaxeSdkType; | ||
import com.intellij.plugins.haxe.ide.module.HaxeModuleSettings; | ||
import com.intellij.plugins.haxe.ide.module.HaxeModuleType; | ||
import com.intellij.plugins.haxe.ide.projectStructure.detection.HaxeProjectData; | ||
import com.intellij.projectImport.ProjectImportBuilder; | ||
import icons.HaxeIcons; | ||
import org.jetbrains.annotations.Nls; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import javax.swing.*; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class HaxeProjectImportBuilder extends ProjectImportBuilder<Object> { | ||
|
||
@Override | ||
public @NotNull @Nls(capitalization = Nls.Capitalization.Sentence) String getName() { | ||
return HaxeBundle.message("haxe.project"); | ||
} | ||
|
||
|
||
@Override | ||
public Icon getIcon() { | ||
return HaxeIcons.HAXE_LOGO; | ||
} | ||
|
||
@Override | ||
public boolean isMarked(Object element) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public void setOpenProjectSettingsAfter(boolean on) { | ||
|
||
} | ||
|
||
|
||
@Override | ||
public @Nullable List<Module> commit(Project project, | ||
ModifiableModuleModel model, | ||
ModulesProvider modulesProvider, | ||
ModifiableArtifactModel artifactModel) { | ||
final ModifiableModuleModel moduleModel = model != null ? model : ModuleManager.getInstance(project).getModifiableModel(); | ||
|
||
|
||
final Map<Module, ModifiableRootModel> moduleToModifiableModelMap = new HashMap<>(); | ||
|
||
final HaxeProjectData haxeProjectData = new HaxeProjectData(getFileToImport()); | ||
final String moduleName = haxeProjectData.getName(); | ||
|
||
final String moduleFilePath = haxeProjectData.getProjectRootPath() + "/" + moduleName + ModuleFileType.DOT_DEFAULT_EXTENSION; | ||
final Module module = moduleModel.newModule(moduleFilePath, HaxeModuleType.getInstance().getId()); | ||
|
||
if (LocalFileSystem.getInstance().findFileByPath(moduleFilePath) != null) { | ||
ApplicationManager.getApplication().runWriteAction(() -> ModuleBuilder.deleteModuleFile(moduleFilePath)); | ||
} | ||
|
||
final ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel(); | ||
final HaxeModuleSettings instance = HaxeModuleSettings.getInstance(module); | ||
|
||
configureProjectSettings(haxeProjectData, instance); | ||
configureContentRoots(haxeProjectData, rootModel); | ||
moduleToModifiableModelMap.put(module, rootModel); | ||
|
||
final Sdk mostRecentSdk = ProjectJdkTable.getInstance().findMostRecentSdkOfType(HaxeSdkType.getInstance()); | ||
rootModel.setSdk(mostRecentSdk); | ||
|
||
ApplicationManager.getApplication() | ||
.runWriteAction(() -> ModifiableModelCommitter.multiCommit(moduleToModifiableModelMap.values(), moduleModel)); | ||
|
||
|
||
return List.of(module); | ||
} | ||
|
||
private static void configureProjectSettings(HaxeProjectData haxeProjectData, HaxeModuleSettings instance) { | ||
HaxeConfiguration type = haxeProjectData.getProjectType(); | ||
instance.setOutputFolder(haxeProjectData.getOutputFolder()); | ||
instance.setBuildConfig(type.asBuildConfigValue()); | ||
switch (type) { | ||
case OPENFL -> instance.setOpenFLPath(haxeProjectData.getProjectFilePath()); | ||
case HXML -> instance.setHxmlPath(haxeProjectData.getProjectFilePath()); | ||
case NMML -> instance.setNmmlPath(haxeProjectData.getProjectFilePath()); | ||
} | ||
} | ||
|
||
private static void configureContentRoots(HaxeProjectData haxeProjectData, ModifiableRootModel rootModel) { | ||
ContentEntry contentRoot = rootModel.addContentEntry(haxeProjectData.getProjectRoot()); | ||
haxeProjectData.getSourcePaths().forEach(source -> contentRoot.addSourceFolder(source, false)); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
src/main/java/com/intellij/plugins/haxe/ide/projectStructure/detection/HaxeProjectData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.intellij.plugins.haxe.ide.projectStructure.detection; | ||
|
||
import com.intellij.openapi.vfs.VfsUtil; | ||
import com.intellij.openapi.vfs.VirtualFile; | ||
import com.intellij.plugins.haxe.config.HaxeConfiguration; | ||
|
||
import java.io.File; | ||
import java.nio.file.Path; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
public class HaxeProjectData { | ||
|
||
private String projectFile; | ||
|
||
public HaxeProjectData(String projectFile) { | ||
this.projectFile = projectFile; | ||
} | ||
|
||
public String getName() { | ||
return getProjectRoot().getName(); | ||
} | ||
|
||
public String getProjectRootPath() { | ||
return new File(projectFile).getParent(); | ||
} | ||
|
||
public VirtualFile getProjectRoot() { | ||
return VfsUtil.findFile(Path.of(getProjectRootPath()), true); | ||
} | ||
public VirtualFile getProjectFile() { | ||
return VfsUtil.findFile(Path.of(getProjectFilePath()), true); | ||
} | ||
|
||
public List<VirtualFile> getSourcePaths() { | ||
VirtualFile root = getProjectRoot(); | ||
VirtualFile projectFile = VfsUtil.findFile(Path.of(getProjectFilePath()), true); | ||
|
||
List<String> paths = HaxeProjectFileDetectionUtil.sourcePaths(projectFile); | ||
return paths.stream().map(root::findChild).filter(Objects::nonNull).toList(); | ||
|
||
} | ||
|
||
public HaxeConfiguration getProjectType() { | ||
VirtualFile file = getProjectFile(); | ||
if (HaxeProjectFileDetectionUtil.isLimeProject(file) | ||
|| HaxeProjectFileDetectionUtil.isOpenFLProject(file)) { | ||
return HaxeConfiguration.OPENFL; | ||
} | ||
if (HaxeProjectFileDetectionUtil.isHxmlProject(file)) { | ||
return HaxeConfiguration.HXML; | ||
} | ||
if (HaxeProjectFileDetectionUtil.isNMMLProject(file)) { | ||
return HaxeConfiguration.NMML; | ||
} | ||
|
||
return HaxeConfiguration.CUSTOM; | ||
} | ||
|
||
public String getProjectFilePath() { | ||
return projectFile; | ||
} | ||
|
||
public String getOutputFolder() { | ||
String path = getProjectRootPath(); | ||
assert path.length() > 0; | ||
return path + "/out"; | ||
} | ||
} |
Oops, something went wrong.