mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
importing from maven model
This commit is contained in:
@@ -252,19 +252,20 @@ public class AddModuleWizard extends AbstractWizard<ModuleWizardStep> {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected final int getNextStep(int step) {
|
||||
ModuleWizardStep nextStep = null;
|
||||
final StepSequence stepSequence = getSequence();
|
||||
if (stepSequence != null) {
|
||||
if (myRootStep == mySteps.get(step)) {
|
||||
return mySteps.indexOf(stepSequence.getFirstStep());
|
||||
}
|
||||
nextStep = stepSequence.getNextStep(mySteps.get(step));
|
||||
while (nextStep != null && !nextStep.isStepVisible()) {
|
||||
nextStep = stepSequence.getNextStep(nextStep);
|
||||
}
|
||||
protected final int getNextStep(final int step) {
|
||||
ModuleWizardStep nextStep = null;
|
||||
final StepSequence stepSequence = getSequence();
|
||||
if (stepSequence != null) {
|
||||
ModuleWizardStep current = mySteps.get(step);
|
||||
if (myRootStep == current) {
|
||||
return mySteps.indexOf(stepSequence.getFirstStep());
|
||||
}
|
||||
return nextStep == null ? step : mySteps.indexOf(nextStep);
|
||||
nextStep = stepSequence.getNextStep(current);
|
||||
while (nextStep != null && !nextStep.isStepVisible()) {
|
||||
nextStep = stepSequence.getNextStep(nextStep);
|
||||
}
|
||||
}
|
||||
return nextStep == null ? step : mySteps.indexOf(nextStep);
|
||||
}
|
||||
|
||||
private StepSequence getSequence() {
|
||||
|
||||
@@ -67,7 +67,7 @@ public class ProjectNameStep extends ModuleWizardStep {
|
||||
myNamePathComponent.add(myFormatPanel.getStorageFormatComboBox(), new GridBagConstraints(1, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
|
||||
}
|
||||
|
||||
myNamePathComponent.setVisible(myWizardContext.getProject() == null);
|
||||
myNamePathComponent.setVisible(isStepVisible());
|
||||
myAdditionalContentPanel = new JPanel(new GridBagLayout());
|
||||
myPanel.add(myAdditionalContentPanel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
|
||||
}
|
||||
@@ -76,6 +76,11 @@ public class ProjectNameStep extends ModuleWizardStep {
|
||||
return myPanel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStepVisible() {
|
||||
return myWizardContext.getProject() == null;
|
||||
}
|
||||
|
||||
public void updateDataModel() {
|
||||
myWizardContext.setProjectName(getProjectName());
|
||||
final String projectFileDirectory = getProjectFileDirectory();
|
||||
|
||||
@@ -335,6 +335,11 @@ public class ProjectNameWithTypeStep extends ProjectNameStep {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStepVisible() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public JComponent getPreferredFocusedComponent() {
|
||||
return myWizardContext.isCreatingNewProject() ? super.getPreferredFocusedComponent() : myModuleName;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
package com.intellij.ide.util.projectWizard;
|
||||
|
||||
import com.intellij.ide.IdeBundle;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.options.ConfigurationException;
|
||||
import com.intellij.openapi.project.ProjectManager;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
@@ -88,7 +89,7 @@ public class ProjectJdkStep extends ModuleWizardStep {
|
||||
|
||||
public boolean validate() throws ConfigurationException {
|
||||
final Sdk jdk = myProjectJdksConfigurable.getSelectedJdk();
|
||||
if (jdk == null) {
|
||||
if (jdk == null && !ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
int result = Messages.showOkCancelDialog(IdeBundle.message("prompt.confirm.project.no.jdk"),
|
||||
IdeBundle.message("title.no.jdk.specified"), Messages.getWarningIcon());
|
||||
if (result != 0) {
|
||||
|
||||
@@ -0,0 +1,161 @@
|
||||
package com.intellij.ide.projectWizard;
|
||||
|
||||
import com.intellij.ide.impl.NewProjectUtil;
|
||||
import com.intellij.ide.util.newProjectWizard.AddModuleWizard;
|
||||
import com.intellij.ide.util.newProjectWizard.SelectTemplateStep;
|
||||
import com.intellij.ide.util.projectWizard.ModuleWizardStep;
|
||||
import com.intellij.ide.wizard.Step;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ui.configuration.DefaultModulesProvider;
|
||||
import com.intellij.openapi.roots.ui.configuration.actions.NewModuleAction;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.platform.ProjectTemplate;
|
||||
import com.intellij.projectImport.ProjectImportProvider;
|
||||
import com.intellij.testFramework.PlatformTestCase;
|
||||
import com.intellij.util.Consumer;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
* Date: 10/29/12
|
||||
*/
|
||||
public abstract class ProjectWizardTestCase extends PlatformTestCase {
|
||||
|
||||
protected TestWizard myWizard;
|
||||
@Nullable
|
||||
private Project myCreatedProject;
|
||||
|
||||
protected Project createProjectFromTemplate(String group, String name, @Nullable Consumer<ModuleWizardStep> adjuster) {
|
||||
runWizard(group, name, adjuster);
|
||||
try {
|
||||
myCreatedProject = NewProjectUtil.doCreate(myWizard, null);
|
||||
}
|
||||
catch (IOException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
assertNotNull(myCreatedProject);
|
||||
|
||||
Project[] projects = myProjectManager.getOpenProjects();
|
||||
assertEquals(2, projects.length);
|
||||
System.out.println(myCreatedProject.getBasePath());
|
||||
return myCreatedProject;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected Module createModuleFromTemplate(String group, String name, @Nullable Consumer<ModuleWizardStep> adjuster) {
|
||||
runWizard(group, name, adjuster);
|
||||
return createModuleFromWizard();
|
||||
}
|
||||
|
||||
protected Module createModuleFromWizard() {
|
||||
return new NewModuleAction().createModuleFromWizard(myProject, null, myWizard);
|
||||
}
|
||||
|
||||
protected void runWizard(String group, String name, @Nullable Consumer<ModuleWizardStep> adjuster) {
|
||||
SelectTemplateStep step = (SelectTemplateStep)myWizard.getCurrentStepObject();
|
||||
assertTrue(step.setSelectedTemplate(group, name));
|
||||
ProjectTemplate template = step.getSelectedTemplate();
|
||||
assertNotNull(template);
|
||||
System.out.println(template.getName());
|
||||
|
||||
if (adjuster != null) {
|
||||
adjuster.consume(step);
|
||||
}
|
||||
|
||||
runWizard(adjuster);
|
||||
}
|
||||
|
||||
protected void runWizard(Consumer<ModuleWizardStep> adjuster) {
|
||||
while (!myWizard.isLast()) {
|
||||
myWizard.doNextAction();
|
||||
if (adjuster != null) {
|
||||
adjuster.consume(myWizard.getCurrentStepObject());
|
||||
}
|
||||
}
|
||||
myWizard.doOk();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
File directory = FileUtil.createTempDirectory(getName(), "new", false);
|
||||
myFilesToDelete.add(directory);
|
||||
|
||||
myWizard = createWizard(directory.getPath());
|
||||
|
||||
if (myWizard != null) {
|
||||
myWizard.navigateToStep(new Function<Step, Boolean>() {
|
||||
@Override
|
||||
public Boolean fun(Step step) {
|
||||
return step instanceof SelectTemplateStep;
|
||||
}
|
||||
});
|
||||
UIUtil.dispatchAllInvocationEvents(); // to make default selection applied
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected TestWizard createWizard(String directory) {
|
||||
return new TestWizard(null, directory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tearDown() throws Exception {
|
||||
if (myWizard != null) {
|
||||
Disposer.dispose(myWizard.getDisposable());
|
||||
}
|
||||
if (myCreatedProject != null) {
|
||||
myProjectManager.closeProject(myCreatedProject);
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Disposer.dispose(myCreatedProject);
|
||||
}
|
||||
});
|
||||
}
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
protected Module importFrom(ProjectImportProvider provider, String path) {
|
||||
VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByPath(path);
|
||||
assertNotNull("Can't find " + path, file);
|
||||
assertTrue(provider.canImport(file, getProject()));
|
||||
myWizard = new TestWizard(getProject(), path, provider);
|
||||
runWizard(null);
|
||||
return createModuleFromWizard();
|
||||
}
|
||||
|
||||
protected static class TestWizard extends AddModuleWizard {
|
||||
|
||||
public TestWizard(@Nullable Project project, String defaultPath) {
|
||||
super(project, DefaultModulesProvider.createForProject(project), defaultPath);
|
||||
}
|
||||
|
||||
public TestWizard(Project project, String filePath, ProjectImportProvider... importProvider) {
|
||||
super(null, project, filePath, importProvider);
|
||||
}
|
||||
|
||||
void doOk() {
|
||||
doOKAction();
|
||||
}
|
||||
|
||||
boolean isLast() {
|
||||
return isLastStep();
|
||||
}
|
||||
|
||||
void commit() {
|
||||
commitStepData(getCurrentStepObject());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,7 +20,7 @@
|
||||
<orderEntry type="library" name="Groovy" level="project" />
|
||||
<orderEntry type="module" module-name="testFramework" exported="" />
|
||||
<orderEntry type="module" module-name="relaxng" exported="" scope="TEST" />
|
||||
<orderEntry type="module" module-name="idea-ui" exported="" scope="TEST" />
|
||||
<orderEntry type="module" module-name="idea-ui" exported="" />
|
||||
</component>
|
||||
<component name="copyright">
|
||||
<Base>
|
||||
|
||||
@@ -70,4 +70,9 @@ public abstract class ModuleWizardStep extends StepAdapter {
|
||||
fieldPanel.getFieldLabel().setFont(UIUtil.getLabelFont().deriveFont(Font.BOLD));
|
||||
return fieldPanel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getName();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -285,4 +285,10 @@ public class MavenProjectBuilder extends ProjectImportBuilder<MavenProject> {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFileToImport(String path) {
|
||||
VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByPath(path);
|
||||
getParameters().myImportRoot = file == null || file.isDirectory() ? file : file.getParent();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -365,7 +365,7 @@ public abstract class MavenTestCase extends UsefulTestCase {
|
||||
}
|
||||
|
||||
@NonNls @Language(value="XML")
|
||||
protected static String createPomXml(@NonNls @Language(value="XML", prefix="<xml>", suffix="</xml>") String xml) {
|
||||
public static String createPomXml(@NonNls @Language(value="XML", prefix="<xml>", suffix="</xml>") String xml) {
|
||||
return "<?xml version=\"1.0\"?>" +
|
||||
"<project xmlns=\"http://maven.apache.org/POM/4.0.0\"" +
|
||||
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" +
|
||||
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2000-2012 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.idea.maven.wizards;
|
||||
|
||||
import com.intellij.ide.projectWizard.ProjectWizardTestCase;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import org.jetbrains.idea.maven.MavenTestCase;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
* Date: 11/6/12
|
||||
*/
|
||||
public class MavenImportWizardTest extends ProjectWizardTestCase {
|
||||
|
||||
public void testImport() throws Exception {
|
||||
File directory = createTempDirectory();
|
||||
File pom = new File(directory, "pom.xml");
|
||||
pom.createNewFile();
|
||||
FileUtil.writeToFile(pom, MavenTestCase.createPomXml("<groupId>test</groupId>" +
|
||||
"<artifactId>project</artifactId>" +
|
||||
"<version>1</version>"));
|
||||
importFrom(new MavenProjectImportProvider(new MavenProjectBuilder()), pom.getPath());
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user