CPP-434 Split [python-community-plugin] into [python-community-core-plugin] and [python-community-java-plugin] #4, isolation [PythonConsoleRunnerFactory] as single point export, move [PyForceStepIntoAction] export to owner module

This commit is contained in:
Alexey Utkin
2015-12-15 18:42:17 +03:00
parent ec996bc56c
commit 79408f2821
22 changed files with 31 additions and 44 deletions

View File

@@ -2,7 +2,15 @@
<!-- Components and extensions declared in this file work ONLY in the Python plugin,
both Community and Professional versions. -->
<extensions defaultExtensionNs="com.intellij">
<moduleType id="PYTHON_MODULE" implementationClass="com.jetbrains.python.module.PythonModuleType"/>
<facetType implementation="com.jetbrains.python.facet.PythonFacetType"/>
<framework.detector implementation="com.jetbrains.python.facet.PythonFacetType$PythonFrameworkDetector"/>
<frameworkSupport implementation="com.jetbrains.python.facet.PythonFrameworkSupportProvider"/>
<projectStructureDetector implementation="com.jetbrains.python.module.PyProjectStructureDetector"/>
<moduleConfigurationEditorProvider implementation="com.jetbrains.python.module.PythonModuleConfigurationEditorProvider"/>
<completion.contributor language="Python" implementationClass="com.jetbrains.python.psi.impl.PyConstructorArgumentCompletionContributor"/>
<!-- Console folding for Jython only, thus it's located in python-plugin only -->
<stacktrace.fold substring="*sys-package-mgr*:"/>
</extensions>
<extensions defaultExtensionNs="Pythonid">
@@ -11,4 +19,16 @@
<pySuperMethodsSearch implementation="com.jetbrains.python.psi.impl.PyJavaSuperMethodsSearchExecutor"/>
<importCandidateProvider implementation="com.jetbrains.python.psi.impl.PyJavaImportCandidateProvider"/>
</extensions>
<application-components>
<component>
<implementation-class>com.jetbrains.python.facet.PythonSdkTableListener</implementation-class>
</component>
</application-components>
<module-components>
<component>
<implementation-class>com.jetbrains.python.facet.PythonFacetListener</implementation-class>
</component>
</module-components>
</idea-plugin>

View File

@@ -0,0 +1,123 @@
/*
* 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.jetbrains.python.facet;
import com.intellij.facet.Facet;
import com.intellij.facet.FacetType;
import com.intellij.facet.FacetTypeId;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.roots.*;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.libraries.LibraryTable;
import org.jetbrains.annotations.NotNull;
/**
* @author yole
*/
public class PythonFacet extends Facet<PythonFacetConfiguration> implements LibraryContributingFacet {
public static final FacetTypeId<PythonFacet> ID = new FacetTypeId<PythonFacet>("python");
public PythonFacet(@NotNull final FacetType facetType, @NotNull final Module module, final @NotNull String name, @NotNull final PythonFacetConfiguration configuration,
Facet underlyingFacet) {
super(facetType, module, name, configuration, underlyingFacet);
}
public void updateLibrary() {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
public void run() {
final Module module = getModule();
final ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
final ModifiableRootModel model = rootManager.getModifiableModel();
boolean modelChanged = false;
try {
// Just remove all old facet libraries except one, that is necessary
final Sdk sdk = getConfiguration().getSdk();
final String name = (sdk != null) ? getFacetLibraryName(sdk.getName()) : null;
boolean librarySeen = false;
for (OrderEntry entry : model.getOrderEntries()) {
if (entry instanceof LibraryOrderEntry) {
final String libraryName = ((LibraryOrderEntry)entry).getLibraryName();
if (name != null && name.equals(libraryName)) {
librarySeen = true;
continue;
}
if (libraryName != null && libraryName.endsWith(PYTHON_FACET_LIBRARY_NAME_SUFFIX)) {
model.removeOrderEntry(entry);
modelChanged = true;
}
}
}
if (name != null) {
final ModifiableModelsProvider provider = ModifiableModelsProvider.SERVICE.getInstance();
final LibraryTable.ModifiableModel libraryTableModifiableModel = provider.getLibraryTableModifiableModel();
Library library = libraryTableModifiableModel.getLibraryByName(name);
provider.disposeLibraryTableModifiableModel(libraryTableModifiableModel);
if (library == null) {
// we just create new project library
library = PythonSdkTableListener.addLibrary(sdk);
}
if (!librarySeen) {
model.addLibraryEntry(library);
modelChanged = true;
}
}
}
finally {
if (modelChanged){
model.commit();
}
else {
model.dispose();
}
}
}
});
}
public void removeLibrary() {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
public void run() {
final Module module = getModule();
final ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
final ModifiableRootModel model = rootManager.getModifiableModel();
// Just remove all old facet libraries
for (OrderEntry entry : model.getOrderEntries()) {
if (entry instanceof LibraryOrderEntry) {
final Library library = ((LibraryOrderEntry)entry).getLibrary();
if (library != null) {
final String libraryName = library.getName();
if (libraryName!=null && libraryName.endsWith(PYTHON_FACET_LIBRARY_NAME_SUFFIX)) {
model.removeOrderEntry(entry);
//PyBuiltinCache.clearInstanceCache();
}
}
}
}
model.commit();
}
});
}
public static String getFacetLibraryName(final String sdkName) {
return sdkName + PYTHON_FACET_LIBRARY_NAME_SUFFIX;
}
public void initFacet() {
updateLibrary();
}
}

View File

@@ -0,0 +1,50 @@
/*
* 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.jetbrains.python.facet;
import com.intellij.facet.FacetConfiguration;
import com.intellij.facet.ui.FacetEditorContext;
import com.intellij.facet.ui.FacetEditorTab;
import com.intellij.facet.ui.FacetValidatorsManager;
import com.intellij.openapi.projectRoots.ProjectJdkTable;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.openapi.util.text.StringUtil;
import com.jetbrains.python.sdk.PythonSdkType;
import org.jdom.Element;
/**
* @author yole
*/
public class PythonFacetConfiguration extends PythonFacetSettings implements FacetConfiguration {
private static final String SDK_NAME = "sdkName";
public FacetEditorTab[] createEditorTabs(FacetEditorContext editorContext, FacetValidatorsManager validatorsManager) {
return new FacetEditorTab[] {
new PythonSdkEditorTab(editorContext)
};
}
public void readExternal(Element element) throws InvalidDataException {
String sdkName = element.getAttributeValue(SDK_NAME);
mySdk = StringUtil.isEmpty(sdkName) ? null : ProjectJdkTable.getInstance().findJdk(sdkName, PythonSdkType.getInstance().getName());
}
public void writeExternal(Element element) throws WriteExternalException {
element.setAttribute(SDK_NAME, mySdk == null ? "" : mySdk.getName());
}
}

View File

@@ -0,0 +1,73 @@
/*
* 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.jetbrains.python.facet;
import com.intellij.facet.Facet;
import com.intellij.facet.FacetManager;
import com.intellij.facet.FacetManagerAdapter;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleComponent;
import com.intellij.util.messages.MessageBusConnection;
import org.jetbrains.annotations.NotNull;
/**
* @author yole
*/
public class PythonFacetListener implements ModuleComponent {
private MessageBusConnection myConnection;
private final Module myModule;
public PythonFacetListener(Module module) {
myModule = module;
}
public void initComponent() {
myConnection = myModule.getMessageBus().connect();
myConnection.subscribe(FacetManager.FACETS_TOPIC, new FacetManagerAdapter() {
@Override
public void beforeFacetRemoved(@NotNull Facet facet) {
if (facet instanceof LibraryContributingFacet) {
((LibraryContributingFacet) facet).removeLibrary();
}
}
@Override
public void facetConfigurationChanged(@NotNull Facet facet) {
if (facet instanceof LibraryContributingFacet) {
((LibraryContributingFacet) facet).updateLibrary();
}
}
});
}
public void projectOpened() {
}
public void projectClosed() {
}
public void moduleAdded() {
}
@NotNull
public String getComponentName() {
return "PythonFacetListener";
}
public void disposeComponent() {
myConnection.disconnect();
}
}

View File

@@ -0,0 +1,100 @@
/*
* 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.jetbrains.python.facet;
import com.intellij.facet.Facet;
import com.intellij.facet.FacetType;
import com.intellij.framework.detection.FacetBasedFrameworkDetector;
import com.intellij.framework.detection.FileContentPattern;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleType;
import com.intellij.openapi.projectRoots.ProjectJdkTable;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.patterns.ElementPattern;
import com.intellij.util.indexing.FileContent;
import com.jetbrains.python.PythonFileType;
import com.jetbrains.python.module.PythonModuleType;
import com.jetbrains.python.sdk.PythonSdkType;
import icons.PythonIcons;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.util.List;
/**
* @author yole
*/
public class PythonFacetType extends FacetType<PythonFacet, PythonFacetConfiguration> {
@NonNls
private static final String ID = "Python";
public static PythonFacetType getInstance() {
return findInstance(PythonFacetType.class);
}
public PythonFacetType() {
super(PythonFacet.ID, ID, "Python");
}
public PythonFacetConfiguration createDefaultConfiguration() {
PythonFacetConfiguration result = new PythonFacetConfiguration();
List<Sdk> sdks = ProjectJdkTable.getInstance().getSdksOfType(PythonSdkType.getInstance());
if (sdks.size() > 0) {
result.setSdk(sdks.get(0));
}
return result;
}
public PythonFacet createFacet(@NotNull Module module, String name, @NotNull PythonFacetConfiguration configuration, @Nullable Facet underlyingFacet) {
return new PythonFacet(this, module, name, configuration, underlyingFacet);
}
public boolean isSuitableModuleType(ModuleType moduleType) {
return !(moduleType instanceof PythonModuleType);
}
@Override
public Icon getIcon() {
return PythonIcons.Python.Python;
}
public static class PythonFrameworkDetector extends FacetBasedFrameworkDetector<PythonFacet, PythonFacetConfiguration> {
public PythonFrameworkDetector() {
super("python");
}
@Override
public FacetType<PythonFacet, PythonFacetConfiguration> getFacetType() {
return PythonFacetType.getInstance();
}
@NotNull
@Override
public FileType getFileType() {
return PythonFileType.INSTANCE;
}
@NotNull
@Override
public ElementPattern<FileContent> createSuitableFilePattern() {
return FileContentPattern.fileContent();
}
}
}

View File

@@ -0,0 +1,58 @@
/*
* 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.jetbrains.python.facet;
import com.intellij.facet.FacetManager;
import com.intellij.facet.ModifiableFacetModel;
import com.intellij.ide.util.frameworkSupport.FrameworkSupportConfigurable;
import com.intellij.ide.util.frameworkSupport.FrameworkSupportModel;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.ui.LabeledComponent;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.awt.*;
/**
* @author yole
*/
public class PythonFrameworkSupportConfigurable extends FrameworkSupportConfigurable {
private final JComponent myMainPanel;
private final PythonSdkComboBox mySdkComboBox;
public PythonFrameworkSupportConfigurable(FrameworkSupportModel model) {
mySdkComboBox = new PythonSdkComboBox();
mySdkComboBox.setProject(model.getProject());
myMainPanel = LabeledComponent.create(mySdkComboBox, "Python SDK:");
((LabeledComponent)myMainPanel).setLabelLocation(BorderLayout.WEST);
}
public JComponent getComponent() {
return myMainPanel;
}
public void addSupport(@NotNull Module module, @NotNull ModifiableRootModel model, @Nullable Library library) {
final FacetManager facetManager = FacetManager.getInstance(module);
ModifiableFacetModel facetModel = facetManager.createModifiableModel();
PythonFacet facet = facetManager.createFacet(PythonFacetType.getInstance(), "Python", null);
facet.getConfiguration().setSdk(mySdkComboBox.getSelectedSdk());
facetModel.addFacet(facet);
facetModel.commit();
}
}

View File

@@ -0,0 +1,57 @@
/*
* 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.jetbrains.python.facet;
import com.intellij.facet.FacetManager;
import com.intellij.ide.util.frameworkSupport.FrameworkSupportConfigurable;
import com.intellij.ide.util.frameworkSupport.FrameworkSupportModel;
import com.intellij.ide.util.frameworkSupport.FrameworkSupportProvider;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleType;
import com.jetbrains.python.module.PythonModuleType;
import icons.PythonIcons;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
/**
* @author yole
*/
public class PythonFrameworkSupportProvider extends FrameworkSupportProvider {
public PythonFrameworkSupportProvider() {
super("Python", PythonFacetType.getInstance().getPresentableName());
}
@Override
public Icon getIcon() {
return PythonIcons.Python.Python;
}
@NotNull
@Override
public FrameworkSupportConfigurable createConfigurable(@NotNull FrameworkSupportModel model) {
return new PythonFrameworkSupportConfigurable(model);
}
public boolean isEnabledForModuleType(@NotNull ModuleType moduleType) {
return !(moduleType instanceof PythonModuleType);
}
@Override
public boolean isSupportAlreadyAdded(@NotNull Module module) {
return FacetManager.getInstance(module).getFacetsByType(PythonFacetType.getInstance().getId()).size() > 0;
}
}

View File

@@ -0,0 +1,75 @@
/*
* 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.jetbrains.python.facet;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.projectRoots.ProjectJdkTable;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.ui.ProjectJdksEditor;
import com.intellij.ui.ComboboxWithBrowseButton;
import com.jetbrains.python.sdk.PySdkListCellRenderer;
import com.jetbrains.python.sdk.PythonSdkType;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
/**
* @author yole
*/
public class PythonSdkComboBox extends ComboboxWithBrowseButton {
private Project myProject;
public PythonSdkComboBox() {
getComboBox().setRenderer(new PySdkListCellRenderer("<No Interpreter>", null));
addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Sdk selectedSdk = getSelectedSdk();
final Project project = myProject != null ? myProject : ProjectManager.getInstance().getDefaultProject();
ProjectJdksEditor editor = new ProjectJdksEditor(selectedSdk, project, PythonSdkComboBox.this);
if (editor.showAndGet()) {
selectedSdk = editor.getSelectedJdk();
updateSdkList(selectedSdk, false);
}
}
});
updateSdkList(null, true);
}
public void setProject(Project project) {
myProject = project;
}
public void updateSdkList(Sdk sdkToSelect, boolean selectAnySdk) {
final List<Sdk> sdkList = ProjectJdkTable.getInstance().getSdksOfType(PythonSdkType.getInstance());
if (selectAnySdk && sdkList.size() > 0) {
sdkToSelect = sdkList.get(0);
}
sdkList.add(0, null);
getComboBox().setModel(new DefaultComboBoxModel(sdkList.toArray(new Sdk[sdkList.size()])));
getComboBox().setSelectedItem(sdkToSelect);
}
public void updateSdkList() {
updateSdkList((Sdk) getComboBox().getSelectedItem(), false);
}
public Sdk getSelectedSdk() {
return (Sdk) getComboBox().getSelectedItem();
}
}

View File

@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.jetbrains.python.facet.PythonSdkEditorTab">
<grid id="27dc6" binding="myMainPanel" layout-manager="GridLayoutManager" row-count="2" column-count="2" 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="empty">
<size top="5" left="10" bottom="10" right="10"/>
</border>
<children>
<component id="5b600" class="com.jetbrains.python.facet.PythonSdkComboBox" binding="mySdkComboBox">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</component>
<vspacer id="c2f6b">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="cbe79" class="javax.swing.JLabel">
<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="Python Interpreter:"/>
</properties>
</component>
</children>
</grid>
</form>

View File

@@ -0,0 +1,91 @@
/*
* 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.jetbrains.python.facet;
import com.intellij.facet.ui.FacetEditorContext;
import com.intellij.facet.ui.FacetEditorTab;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.ProjectJdkTable;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.util.Disposer;
import com.intellij.util.messages.MessageBusConnection;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
/**
* @author yole
*/
public class PythonSdkEditorTab extends FacetEditorTab {
private JPanel myMainPanel;
private PythonSdkComboBox mySdkComboBox;
private final FacetEditorContext myEditorContext;
private final MessageBusConnection myConnection;
public PythonSdkEditorTab(final FacetEditorContext editorContext) {
myEditorContext = editorContext;
final Project project = editorContext.getProject();
mySdkComboBox.setProject(project);
myConnection = project.getMessageBus().connect();
myConnection.subscribe(ProjectJdkTable.JDK_TABLE_TOPIC, new ProjectJdkTable.Listener() {
@Override
public void jdkAdded(Sdk jdk) {
mySdkComboBox.updateSdkList();
}
@Override
public void jdkRemoved(Sdk jdk) {
mySdkComboBox.updateSdkList();
}
@Override
public void jdkNameChanged(Sdk jdk, String previousName) {
mySdkComboBox.updateSdkList();
}
});
}
@Nls
public String getDisplayName() {
return "Python SDK";
}
@NotNull
public JComponent createComponent() {
return myMainPanel;
}
public boolean isModified() {
return mySdkComboBox.getSelectedSdk() != getFacetConfiguration().getSdk();
}
private PythonFacetConfiguration getFacetConfiguration() {
return ((PythonFacetConfiguration) myEditorContext.getFacet().getConfiguration());
}
public void apply() {
getFacetConfiguration().setSdk(mySdkComboBox.getSelectedSdk());
}
public void reset() {
mySdkComboBox.updateSdkList(getFacetConfiguration().getSdk(), false);
}
public void disposeUIResources() {
Disposer.dispose(myConnection);
}
}

View File

@@ -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.jetbrains.python.facet;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.components.ApplicationComponent;
import com.intellij.openapi.projectRoots.ProjectJdkTable;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.roots.ModifiableModelsProvider;
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.libraries.LibraryTable;
import com.intellij.util.messages.MessageBus;
import com.jetbrains.python.sdk.PythonSdkType;
import org.jetbrains.annotations.NotNull;
/**
* @author yole
*/
public class PythonSdkTableListener implements ApplicationComponent {
public PythonSdkTableListener(MessageBus messageBus) {
ProjectJdkTable.Listener jdkTableListener = new ProjectJdkTable.Listener() {
public void jdkAdded(final Sdk sdk) {
if (sdk.getSdkType() instanceof PythonSdkType) {
ApplicationManager.getApplication().invokeLater(new Runnable() {
public void run() {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
public void run() {
addLibrary(sdk);
}
});
}
});
}
}
public void jdkRemoved(final Sdk sdk) {
if (sdk.getSdkType() instanceof PythonSdkType) {
removeLibrary(sdk);
}
}
public void jdkNameChanged(final Sdk sdk, final String previousName) {
if (sdk.getSdkType() instanceof PythonSdkType) {
renameLibrary(sdk, previousName);
}
}
};
messageBus.connect().subscribe(ProjectJdkTable.JDK_TABLE_TOPIC, jdkTableListener);
}
static Library addLibrary(Sdk sdk) {
final LibraryTable.ModifiableModel libraryTableModel = ModifiableModelsProvider.SERVICE.getInstance().getLibraryTableModifiableModel();
final Library library = libraryTableModel.createLibrary(PythonFacet.getFacetLibraryName(sdk.getName()));
final Library.ModifiableModel model = library.getModifiableModel();
for (String url : sdk.getRootProvider().getUrls(OrderRootType.CLASSES)) {
model.addRoot(url, OrderRootType.CLASSES);
model.addRoot(url, OrderRootType.SOURCES);
}
model.commit();
libraryTableModel.commit();
return library;
}
private static void removeLibrary(final Sdk sdk) {
ApplicationManager.getApplication().invokeLater(new Runnable() {
public void run() {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
public void run() {
final LibraryTable.ModifiableModel libraryTableModel =
ModifiableModelsProvider.SERVICE.getInstance().getLibraryTableModifiableModel();
final Library library = libraryTableModel.getLibraryByName(PythonFacet.getFacetLibraryName(sdk.getName()));
if (library != null) {
libraryTableModel.removeLibrary(library);
}
libraryTableModel.commit();
}
});
}
}, ModalityState.NON_MODAL);
}
private static void renameLibrary(final Sdk sdk, final String previousName) {
ApplicationManager.getApplication().invokeLater(new Runnable() {
public void run() {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
public void run() {
final LibraryTable.ModifiableModel libraryTableModel =
ModifiableModelsProvider.SERVICE.getInstance().getLibraryTableModifiableModel();
final Library library = libraryTableModel.getLibraryByName(PythonFacet.getFacetLibraryName(previousName));
if (library != null) {
final Library.ModifiableModel model = library.getModifiableModel();
model.setName(PythonFacet.getFacetLibraryName(sdk.getName()));
model.commit();
}
libraryTableModel.commit();
}
});
}
}, ModalityState.NON_MODAL);
}
@NotNull
public String getComponentName() {
return "PythonSdkTableListener";
}
public void initComponent() {
}
public void disposeComponent() {
}
}

View File

@@ -0,0 +1,76 @@
/*
* 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.jetbrains.python.module;
import com.intellij.ide.util.importProject.ProjectDescriptor;
import com.intellij.ide.util.projectWizard.ModuleWizardStep;
import com.intellij.ide.util.projectWizard.ProjectWizardStepFactory;
import com.intellij.ide.util.projectWizard.importSources.DetectedContentRoot;
import com.intellij.ide.util.projectWizard.importSources.DetectedProjectRoot;
import com.intellij.ide.util.projectWizard.importSources.ProjectFromSourcesBuilder;
import com.intellij.ide.util.projectWizard.importSources.ProjectStructureDetector;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.module.WebModuleType;
import com.intellij.openapi.util.io.FileUtilRt;
import com.jetbrains.python.PythonModuleTypeBase;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.io.File;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
/**
* @author yole
*/
public class PyProjectStructureDetector extends ProjectStructureDetector {
private static final Logger LOG = Logger.getInstance("#com.jetbrains.python.module.PyProjectStructureDetector");
@NotNull
@Override
public DirectoryProcessingResult detectRoots(@NotNull File dir,
@NotNull File[] children,
@NotNull File base,
@NotNull List<DetectedProjectRoot> result) {
LOG.info("Detecting roots under " + dir);
for (File child : children) {
final String name = child.getName();
if (FileUtilRt.extensionEquals(name, "py")) {
LOG.info("Found Python file " + child.getPath());
result.add(new DetectedContentRoot(dir, "Python", PythonModuleTypeBase.getInstance(), WebModuleType.getInstance()));
return DirectoryProcessingResult.SKIP_CHILDREN;
}
if ("node_modules".equals(name)) {
return DirectoryProcessingResult.SKIP_CHILDREN;
}
}
return DirectoryProcessingResult.PROCESS_CHILDREN;
}
@Override
public void setupProjectStructure(@NotNull Collection<DetectedProjectRoot> roots,
@NotNull ProjectDescriptor projectDescriptor,
@NotNull ProjectFromSourcesBuilder builder) {
builder.setupModulesByContentRoots(projectDescriptor, roots);
}
@Override
public List<ModuleWizardStep> createWizardSteps(ProjectFromSourcesBuilder builder, ProjectDescriptor projectDescriptor, Icon stepIcon) {
return Collections.singletonList(ProjectWizardStepFactory.getInstance().createProjectJdkStep(builder.getContext()));
}
}

View File

@@ -0,0 +1,67 @@
/*
* 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.jetbrains.python.module;
import com.intellij.ide.util.projectWizard.ModuleWizardStep;
import com.intellij.ide.util.projectWizard.SdkSettingsStep;
import com.intellij.ide.util.projectWizard.SettingsStep;
import com.intellij.ide.util.projectWizard.SourcePathsBuilder;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.SdkTypeId;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.Pair;
import com.jetbrains.python.sdk.PythonSdkType;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
/**
* @author yole
*/
public class PythonModuleBuilder extends PythonModuleBuilderBase implements SourcePathsBuilder {
private List<Pair<String, String>> mySourcePaths;
public List<Pair<String, String>> getSourcePaths() {
return mySourcePaths;
}
public void setSourcePaths(final List<Pair<String, String>> sourcePaths) {
mySourcePaths = sourcePaths;
}
public void addSourcePath(final Pair<String, String> sourcePathInfo) {
if (mySourcePaths == null) {
mySourcePaths = new ArrayList<Pair<String, String>>();
}
mySourcePaths.add(sourcePathInfo);
}
@Override
public ModuleWizardStep modifyProjectTypeStep(@NotNull SettingsStep settingsStep) {
return new SdkSettingsStep(settingsStep, this, new Condition<SdkTypeId>() {
@Override
public boolean value(SdkTypeId id) {
return PythonSdkType.getInstance() == id;
}
}) {
@Override
protected void onSdkSelected(Sdk sdk) {
setSdk(sdk);
}
};
}
}

View File

@@ -0,0 +1,42 @@
/*
* 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.jetbrains.python.module;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleConfigurationEditor;
import com.intellij.openapi.module.ModuleType;
import com.intellij.openapi.roots.ui.configuration.DefaultModuleConfigurationEditorFactory;
import com.intellij.openapi.roots.ui.configuration.ModuleConfigurationEditorProvider;
import com.intellij.openapi.roots.ui.configuration.ModuleConfigurationState;
import org.jetbrains.jps.model.java.JavaSourceRootType;
import java.util.ArrayList;
import java.util.List;
/**
* @author yole
*/
public class PythonModuleConfigurationEditorProvider implements ModuleConfigurationEditorProvider {
public ModuleConfigurationEditor[] createEditors(final ModuleConfigurationState state) {
final Module module = state.getRootModel().getModule();
if (!(ModuleType.get(module) instanceof PythonModuleType)) return ModuleConfigurationEditor.EMPTY;
final DefaultModuleConfigurationEditorFactory editorFactory = DefaultModuleConfigurationEditorFactory.getInstance();
final List<ModuleConfigurationEditor> editors = new ArrayList<ModuleConfigurationEditor>();
editors.add(new PyContentEntriesEditor(module, state, JavaSourceRootType.SOURCE));
editors.add(editorFactory.createClasspathEditor(state));
return editors.toArray(new ModuleConfigurationEditor[editors.size()]);
}
}

View File

@@ -0,0 +1,30 @@
/*
* 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.jetbrains.python.module;
import com.jetbrains.python.PythonModuleTypeBase;
import org.jetbrains.annotations.NotNull;
/**
* @author yole
*/
public class PythonModuleType extends PythonModuleTypeBase<PythonModuleBuilderBase> {
@NotNull
public PythonModuleBuilder createModuleBuilder() {
return new PythonModuleBuilder();
}
}

View File

@@ -8,9 +8,12 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="lang-api" />
<orderEntry type="module" module-name="java-psi-api" />
<orderEntry type="module" module-name="lang-impl" />
<orderEntry type="module" module-name="python-psi-api" />
<orderEntry type="module" module-name="python-community" />
<orderEntry type="module" module-name="openapi" />
<orderEntry type="module" module-name="java-psi-api" />
<orderEntry type="module" module-name="java-indexing-api" />
<orderEntry type="module" module-name="idea-ui" />
</component>
</module>