mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-120027 - Import Git-cloud apps from sources - Heroku
This commit is contained in:
@@ -6,3 +6,4 @@ failed.reset.remote=Failed to set {0} repository as remote
|
||||
cloning.existing.application=Cloning existing {0} application
|
||||
fetching.application=Fetching {0} application
|
||||
run.configuration.name={0} - {1}
|
||||
choose.account.title=Choose {0} account\:
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
<orderEntry type="module" module-name="remote-servers-impl" />
|
||||
<orderEntry type="module" module-name="lang-api" />
|
||||
<orderEntry type="module" module-name="lang-impl" />
|
||||
<orderEntry type="module" module-name="idea-ui" />
|
||||
<orderEntry type="module" module-name="openapi" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.remoteServer.util.importProject.CloudGitChooseAccountStep">
|
||||
<grid id="27dc6" binding="myMainPanel" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="500" height="400"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="f7812" class="javax.swing.JLabel" binding="myTitleLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Choose <cloud> account:"/>
|
||||
</properties>
|
||||
</component>
|
||||
<vspacer id="610f7">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<grid id="1c3f2" binding="myAccountSelectionPanelPlaceHolder" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* Copyright 2000-2014 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 com.intellij.remoteServer.util.importProject;
|
||||
|
||||
import com.intellij.ide.util.importProject.ModuleDescriptor;
|
||||
import com.intellij.ide.util.importProject.ProjectDescriptor;
|
||||
import com.intellij.ide.util.projectWizard.ModuleBuilder;
|
||||
import com.intellij.ide.util.projectWizard.ModuleWizardStep;
|
||||
import com.intellij.ide.util.projectWizard.importSources.DetectedProjectRoot;
|
||||
import com.intellij.ide.util.projectWizard.importSources.DetectedSourceRoot;
|
||||
import com.intellij.ide.util.projectWizard.importSources.ProjectFromSourcesBuilder;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.StdModuleTypes;
|
||||
import com.intellij.openapi.options.ConfigurationException;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.remoteServer.util.CloudAccountSelectionEditor;
|
||||
import com.intellij.remoteServer.util.CloudBundle;
|
||||
import com.intellij.remoteServer.util.CloudDeploymentNameConfiguration;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author michael.golubev
|
||||
*/
|
||||
public class CloudGitChooseAccountStep<DC extends CloudDeploymentNameConfiguration> extends ModuleWizardStep {
|
||||
|
||||
private JPanel myAccountSelectionPanelPlaceHolder;
|
||||
private JPanel myMainPanel;
|
||||
private JLabel myTitleLabel;
|
||||
|
||||
private final CloudGitProjectStructureDetectorBase<DC> myDetector;
|
||||
private final ProjectFromSourcesBuilder myBuilder;
|
||||
private final ProjectDescriptor myProjectDescriptor;
|
||||
|
||||
private CloudAccountSelectionEditor<?, DC, ?> myEditor;
|
||||
|
||||
public CloudGitChooseAccountStep(CloudGitProjectStructureDetectorBase<DC> detector,
|
||||
ProjectFromSourcesBuilder builder,
|
||||
ProjectDescriptor projectDescriptor) {
|
||||
myDetector = detector;
|
||||
myBuilder = builder;
|
||||
myProjectDescriptor = projectDescriptor;
|
||||
|
||||
myTitleLabel.setText(CloudBundle.getText("choose.account.title", detector.getDetectorId()));
|
||||
|
||||
myEditor = detector.createAccountSelectionEditor();
|
||||
myAccountSelectionPanelPlaceHolder.add(myEditor.getMainPanel());
|
||||
myEditor.initUI();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JComponent getComponent() {
|
||||
return myMainPanel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDataModel() {
|
||||
Collection<DetectedProjectRoot> roots = myBuilder.getProjectRoots(myDetector);
|
||||
|
||||
CloudGitProjectRoot lastProjectRoot = null;
|
||||
MultiMap<CloudGitProjectRoot, DetectedSourceRoot> project2sourceRoots = new MultiMap<CloudGitProjectRoot, DetectedSourceRoot>();
|
||||
|
||||
for (DetectedProjectRoot root : roots) {
|
||||
if (root instanceof CloudGitProjectRoot) {
|
||||
lastProjectRoot = (CloudGitProjectRoot)root;
|
||||
project2sourceRoots.put(lastProjectRoot, new ArrayList<DetectedSourceRoot>());
|
||||
}
|
||||
else if (root instanceof DetectedSourceRoot) {
|
||||
project2sourceRoots.putValue(lastProjectRoot, (DetectedSourceRoot)root);
|
||||
}
|
||||
}
|
||||
|
||||
List<ModuleDescriptor> modules = new ArrayList<ModuleDescriptor>();
|
||||
for (Map.Entry<CloudGitProjectRoot, Collection<DetectedSourceRoot>> project2sourceRootsEntry : project2sourceRoots.entrySet()) {
|
||||
CloudGitProjectRoot projectRoot = project2sourceRootsEntry.getKey();
|
||||
ModuleDescriptor moduleDescriptor
|
||||
= new ModuleDescriptor(projectRoot.getDirectory(), StdModuleTypes.JAVA, project2sourceRootsEntry.getValue());
|
||||
final String applicationName = projectRoot.getApplicationName();
|
||||
moduleDescriptor.addConfigurationUpdater(new ModuleBuilder.ModuleConfigurationUpdater() {
|
||||
|
||||
@Override
|
||||
public void update(@NotNull Module module, @NotNull ModifiableRootModel rootModel) {
|
||||
createRunConfiguration(module, applicationName);
|
||||
}
|
||||
});
|
||||
modules.add(moduleDescriptor);
|
||||
}
|
||||
myProjectDescriptor.setModules(modules);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validate() throws ConfigurationException {
|
||||
myEditor.validate();
|
||||
return super.validate();
|
||||
}
|
||||
|
||||
private void createRunConfiguration(Module module, String applicationName) {
|
||||
DC deploymentConfiguration = myDetector.createDeploymentConfiguration();
|
||||
|
||||
boolean defaultName = module.getName().equals(applicationName);
|
||||
deploymentConfiguration.setDefaultDeploymentName(defaultName);
|
||||
if (!defaultName) {
|
||||
deploymentConfiguration.setDeploymentName(applicationName);
|
||||
}
|
||||
|
||||
myEditor.createRunConfiguration(module, deploymentConfiguration);
|
||||
}
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2000-2014 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 com.intellij.remoteServer.util.importProject;
|
||||
|
||||
import com.intellij.ide.util.projectWizard.importSources.DetectedSourceRoot;
|
||||
import com.intellij.ide.util.projectWizard.importSources.JavaModuleSourceRoot;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author michael.golubev
|
||||
*/
|
||||
public class CloudGitJavaSourceRoot extends DetectedSourceRoot {
|
||||
|
||||
private final String myRootTypeName;
|
||||
|
||||
public CloudGitJavaSourceRoot(String rootTypeName, JavaModuleSourceRoot javaSourceRoot) {
|
||||
super(javaSourceRoot.getDirectory(), javaSourceRoot.getPackagePrefix());
|
||||
myRootTypeName = rootTypeName;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getRootTypeName() {
|
||||
return myRootTypeName;
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2000-2014 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 com.intellij.remoteServer.util.importProject;
|
||||
|
||||
import com.intellij.ide.util.projectWizard.importSources.DetectedProjectRoot;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @author michael.golubev
|
||||
*/
|
||||
public class CloudGitProjectRoot extends DetectedProjectRoot {
|
||||
|
||||
private final String myRootTypeName;
|
||||
private final String myJavaSourceRootTypeName;
|
||||
private final String myApplicationName;
|
||||
|
||||
public CloudGitProjectRoot(String rootTypeName, String javaSourceRootTypeName, @NotNull File directory, String applicationName) {
|
||||
super(directory);
|
||||
myRootTypeName = rootTypeName;
|
||||
myJavaSourceRootTypeName = javaSourceRootTypeName;
|
||||
myApplicationName = applicationName;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getRootTypeName() {
|
||||
return myRootTypeName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canContainRoot(@NotNull DetectedProjectRoot root) {
|
||||
return myJavaSourceRootTypeName.equals(root.getRootTypeName());
|
||||
}
|
||||
|
||||
public String getApplicationName() {
|
||||
return myApplicationName;
|
||||
}
|
||||
}
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* Copyright 2000-2014 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 com.intellij.remoteServer.util.importProject;
|
||||
|
||||
import com.intellij.ide.util.importProject.ProjectDescriptor;
|
||||
import com.intellij.ide.util.projectWizard.ModuleWizardStep;
|
||||
import com.intellij.ide.util.projectWizard.importSources.DetectedProjectRoot;
|
||||
import com.intellij.ide.util.projectWizard.importSources.JavaModuleSourceRoot;
|
||||
import com.intellij.ide.util.projectWizard.importSources.ProjectFromSourcesBuilder;
|
||||
import com.intellij.ide.util.projectWizard.importSources.ProjectStructureDetector;
|
||||
import com.intellij.ide.util.projectWizard.importSources.impl.JavaProjectStructureDetector;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectManager;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.remoteServer.ServerType;
|
||||
import com.intellij.remoteServer.util.CloudAccountSelectionEditor;
|
||||
import com.intellij.remoteServer.util.CloudDeploymentNameConfiguration;
|
||||
import com.intellij.remoteServer.util.CloudGitDeploymentDetector;
|
||||
import git4idea.GitPlatformFacade;
|
||||
import git4idea.GitUtil;
|
||||
import git4idea.repo.GitRepository;
|
||||
import git4idea.repo.GitRepositoryImpl;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author michael.golubev
|
||||
*/
|
||||
public abstract class CloudGitProjectStructureDetectorBase<DC extends CloudDeploymentNameConfiguration> extends ProjectStructureDetector {
|
||||
|
||||
private final JavaProjectStructureDetector myJavaDetector = new JavaProjectStructureDetector();
|
||||
|
||||
private final String myId;
|
||||
private final String myJavaSourceRootTypeName;
|
||||
private final CloudGitDeploymentDetector myDeploymentDetector;
|
||||
|
||||
protected CloudGitProjectStructureDetectorBase(ServerType serverType, CloudGitDeploymentDetector deploymentDetector) {
|
||||
myId = serverType.getPresentableName();
|
||||
myJavaSourceRootTypeName = "Java/" + myId;
|
||||
myDeploymentDetector = deploymentDetector;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DirectoryProcessingResult detectRoots(@NotNull File dir,
|
||||
@NotNull File[] children,
|
||||
@NotNull File base,
|
||||
@NotNull List<DetectedProjectRoot> result) {
|
||||
detectApplicationRoot(dir, result);
|
||||
|
||||
for (DetectedProjectRoot projectRoot : result) {
|
||||
if ((projectRoot instanceof CloudGitProjectRoot) && FileUtil.isAncestor(projectRoot.getDirectory(), dir, true)) {
|
||||
return detectJavaRoots(dir, children, base, result);
|
||||
}
|
||||
}
|
||||
|
||||
return DirectoryProcessingResult.PROCESS_CHILDREN;
|
||||
}
|
||||
|
||||
private void detectApplicationRoot(@NotNull File dir, @NotNull List<DetectedProjectRoot> result) {
|
||||
VirtualFile contentRoot = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(dir);
|
||||
if (contentRoot == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final File gitDir = new File(dir, GitUtil.DOT_GIT);
|
||||
if (!gitDir.exists()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Project project = ProjectManager.getInstance().getDefaultProject();
|
||||
GitRepository repository
|
||||
= GitRepositoryImpl.getLightInstance(contentRoot, project, ServiceManager.getService(project, GitPlatformFacade.class), project);
|
||||
repository.update();
|
||||
|
||||
List<String> applicationNames = myDeploymentDetector.collectApplicationNames(repository);
|
||||
if (applicationNames.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
result.add(new CloudGitProjectRoot(myId, myJavaSourceRootTypeName, dir, applicationNames.get(0)));
|
||||
}
|
||||
|
||||
private DirectoryProcessingResult detectJavaRoots(@NotNull File dir,
|
||||
@NotNull File[] children,
|
||||
@NotNull File base,
|
||||
@NotNull List<DetectedProjectRoot> result) {
|
||||
List<DetectedProjectRoot> detectedJavaRoots = new ArrayList<DetectedProjectRoot>();
|
||||
DirectoryProcessingResult processingResult = myJavaDetector.detectRoots(dir, children, base, detectedJavaRoots);
|
||||
for (DetectedProjectRoot detectedJavaRoot : detectedJavaRoots) {
|
||||
if (detectedJavaRoot instanceof JavaModuleSourceRoot) {
|
||||
result.add(new CloudGitJavaSourceRoot(myJavaSourceRootTypeName, (JavaModuleSourceRoot)detectedJavaRoot));
|
||||
}
|
||||
}
|
||||
return processingResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDetectorId() {
|
||||
return myId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ModuleWizardStep> createWizardSteps(ProjectFromSourcesBuilder builder,
|
||||
ProjectDescriptor projectDescriptor,
|
||||
Icon stepIcon) {
|
||||
return Collections.<ModuleWizardStep>singletonList(new CloudGitChooseAccountStep<DC>(this, builder, projectDescriptor));
|
||||
}
|
||||
|
||||
public abstract CloudAccountSelectionEditor<?, DC, ?> createAccountSelectionEditor();
|
||||
|
||||
public abstract DC createDeploymentConfiguration();
|
||||
}
|
||||
Reference in New Issue
Block a user