Skip to content

Commit a012d36

Browse files
committed
Updates for
(1) project discover (#3) and (2) execution ( #4)
1 parent be04fee commit a012d36

27 files changed

Lines changed: 1754 additions & 540 deletions

SECURITY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Security Policy
22

33

4-
Python4NB is in early development so limited sercurity support is available at
4+
Python4NB is in early development so limited security support is available at
55
the moment.
66

77
The Python4NB project leverages github workflow dependabot checks
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
/*
2-
* Licensed to the Apache Software Foundation (ASF) under one
3-
* or more contributor license agreements. See the NOTICE file
4-
* distributed with this work for additional information
5-
* regarding copyright ownership. The ASF licenses this file
6-
* to you under the Apache License, Version 2.0 (the
7-
* "License"); you may not use this file except in compliance
8-
* with the License. You may obtain a copy of the License at
2+
* Copyright 2022 Eric Bresie and friends. All rights reserved.
93
*
10-
* http://www.apache.org/licenses/LICENSE-2.0
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
117
*
12-
* Unless required by applicable law or agreed to in writing,
13-
* software distributed under the License is distributed on an
14-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15-
* KIND, either express or implied. See the License for the
16-
* specific language governing permissions and limitations
17-
* under the License.
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
1815
*/
1916
package org.apache.netbeans.modules.python4nb.editor.file;
2017

@@ -35,4 +32,7 @@ private MIMETypes() {
3532
public static final String PY_EXT = "py";
3633
public static final String PYC_EXT = "pyc";
3734
public static final String PYO_EXT = "pyo";
35+
36+
public static final String PYTHON_MIME_TYPE = "text/x-python"; // NOI18N
37+
public static final String PYTHON_EXTENSION ="py";
3838
}

src/main/java/org/apache/netbeans/modules/python4nb/platform/PythonAutoDetector.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022 ebres.
2+
* Copyright 2022 Eric Bresie and friends. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,13 +25,7 @@
2525
import org.openide.util.Exceptions;
2626
import org.openide.util.Utilities;
2727

28-
/**
29-
* The code here is based on nbPython Code.
30-
*
31-
* TODO: Need to determine how to handle this. This code is available from
32-
* nbpython sourceforge repository (as well as Oracle donation) but need to
33-
* ensure inclusion is within appropriate licensing constraints.
34-
*/
28+
// Portions of this code are based on nbPython Code.
3529

3630
class PythonAutoDetector {
3731
private static final Logger LOGGER = Logger.getLogger(PythonAutoDetector.class.getName());
@@ -265,8 +259,9 @@ private static boolean isPythonExecutableFile(String spath) {
265259
spath.toLowerCase().contains("python3") ||
266260
spath.toLowerCase().contains("anaconda") ||
267261
spath.toLowerCase().contains("pypy")||
268-
spath.toLowerCase().contains("pypy3")) &&
269-
!(spath.toLowerCase().contains("uninstall"));
262+
spath.toLowerCase().contains("pypy3")) && !(
263+
(spath.toLowerCase().contains("uninstall")) ||
264+
(spath.toLowerCase().contains("pythonw")));
270265
}
271266

272267
public void traverse(File dir, boolean recersive) {

src/main/java/org/apache/netbeans/modules/python4nb/project/PythonActionProvider.java

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022 ebres.
2+
* Copyright 2022 Eric Bresie and friends. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -13,22 +13,28 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.apache.netbeans.modules.python4nb.project;
1718

18-
import java.util.Collection;
1919
import java.util.LinkedHashMap;
2020
import java.util.Map;
2121
import java.util.Set;
22-
import org.netbeans.api.lsp.Command;
22+
import org.apache.netbeans.modules.python4nb.ui.actions.Command;
23+
//import org.netbeans.api.lsp.Command;
2324
import org.netbeans.spi.project.ActionProvider;
2425
import org.apache.netbeans.modules.python4nb.ui.actions.RunCommand;
2526
import org.openide.LifecycleManager;
2627
import org.openide.util.Lookup;
2728
import org.openide.util.RequestProcessor;
2829

30+
// Portions of this code are based on nbPython Code.
31+
2932
/**
30-
*
31-
* TODO: Based on nbPython code
33+
* This code identified possible actions provided for use in
34+
* project actions.
35+
*
36+
* As more functionality is implemented additional commands will
37+
* be added.
3238
*/
3339
public class PythonActionProvider implements ActionProvider {
3440
PythonProject project;
@@ -39,24 +45,25 @@ public PythonActionProvider(PythonProject project) {
3945
assert project != null;
4046
commands = new LinkedHashMap<>();
4147
Command[] commandArray = new Command[] {
42-
// new DeleteCommand(project),
43-
// new CopyCommand(project),
44-
// new MoveCommand(project),
45-
// new RenameCommand(project),
46-
// new CleanCommand(project),
47-
// new RunSingleCommand(project, false),
48-
// new RunSingleCommand(project, true), // Run as Test
4948
new RunCommand(project, false),
5049
new RunCommand(project, true), // Run project as Test
51-
// new DebugCommand(project) ,
52-
// new DebugSingleCommand(project, false),
53-
// new DebugSingleCommand(project, true), // Debug as Test
54-
// new BuildCommand(project), //Build Egg
55-
// new CleanBuildCommand(project) //Clean and Build Egg
50+
// TODO: Add applicable commands for additional functionality
51+
// new DeleteCommand(project),
52+
// new CopyCommand(project),
53+
// new MoveCommand(project),
54+
// new RenameCommand(project),
55+
// new CleanCommand(project),
56+
// new RunSingleCommand(project, false),
57+
// new RunSingleCommand(project, true), // Run as Test
58+
// new DebugCommand(project) ,
59+
// new DebugSingleCommand(project, false),
60+
// new DebugSingleCommand(project, true), // Debug as Test
61+
// new BuildCommand(project), //Build Egg
62+
// new CleanBuildCommand(project) //Clean and Build Egg
5663
};
5764
for (Command command : commandArray) {
58-
// commands.put(command.getCommandId(), command);
59-
commands.put(command.getTitle(), command);
65+
commands.put(command.getCommandId(), command);
66+
// commands.put(command.getTitle(), command);
6067
}
6168
}
6269

src/main/java/org/apache/netbeans/modules/python4nb/project/PythonProject.java

Lines changed: 83 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022 ebres.
2+
* Copyright 2022 Eric Bresie and friends. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,24 +15,26 @@
1515
*/
1616
package org.apache.netbeans.modules.python4nb.project;
1717

18-
/**
19-
*
20-
* @author ebres
21-
*/
2218
import java.awt.Image;
2319
import java.beans.PropertyChangeListener;
20+
import java.io.File;
21+
import java.util.Map;
2422
import javax.swing.Action;
2523
import javax.swing.Icon;
2624
import javax.swing.ImageIcon;
25+
import org.apache.netbeans.modules.python4nb.project.PythonSources;
2726
import org.netbeans.api.annotations.common.StaticResource;
2827
import org.netbeans.api.project.Project;
2928
import org.netbeans.api.project.ProjectInformation;
29+
import org.netbeans.spi.project.AuxiliaryConfiguration;
3030
import org.netbeans.spi.project.ProjectState;
3131
import org.netbeans.spi.project.support.ant.AntProjectHelper;
3232
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
33+
import org.netbeans.spi.project.support.ant.ReferenceHelper;
3334
import org.netbeans.spi.project.ui.LogicalViewProvider;
3435
import org.netbeans.spi.project.ui.support.CommonProjectActions;
3536
import org.openide.filesystems.FileObject;
37+
import org.openide.filesystems.FileUtil;
3638
import org.openide.loaders.DataFolder;
3739
import org.openide.loaders.DataObjectNotFoundException;
3840
import org.openide.nodes.AbstractNode;
@@ -45,22 +47,45 @@
4547
import org.openide.util.lookup.Lookups;
4648
import org.openide.util.lookup.ProxyLookup;
4749

50+
// Portions of this code are based on nbPython Code.
51+
52+
/**
53+
* This class is to reflect details and applicable attributes
54+
* about a given Python Project for use in NetBeans IDE.
55+
*/
4856
public class PythonProject implements Project {
4957

58+
public static final String SOURCES_TYPE_PYTHON = "python"; //NOI18N
59+
5060
private final FileObject projectDir;
51-
private final ProjectState state;
5261
protected SourceRoots sourceRoots;
5362
protected SourceRoots testRoots;
54-
private Lookup lkp;
55-
56-
protected PropertyEvaluator evaluator;
57-
protected AntProjectHelper helper;
63+
protected Lookup lkp;
64+
protected PythonProjectProperties properties;
65+
//TODO Determine if needed for future enhancements; remove if not needed
66+
// private final ProjectState state; // XXX May need
67+
// protected AntProjectHelper helper; // XXX May need some form of Helper
68+
// protected UpdateHelper updateHelper;
69+
// protected LogicalViewProvider logicalView = new PythonLogicalView(this);
70+
// protected PropertyEvaluator evaluator;
71+
// protected ReferenceHelper refHelper;
72+
// protected AuxiliaryConfiguration aux;
5873

5974
@StaticResource()
6075
public static final String PYTHON_PROJECT_ICON = "org/apache/netbeans/modules/python4nb/editor/py_module.png";
6176
PythonProject(FileObject dir, ProjectState state) {
6277
this.projectDir = dir;
63-
this.state = state;
78+
this.lkp = getLookup();
79+
this.sourceRoots = getSourceRoots();
80+
this.properties = getProperties();
81+
// this.state = state;
82+
}
83+
84+
PythonProject(File dir) {
85+
this.projectDir = FileUtil.toFileObject(dir);
86+
this.lkp = getLookup(); //createLookup();
87+
this.sourceRoots = getSourceRoots();
88+
// this.state = ProjectState.state;
6489
}
6590

6691
@Override
@@ -75,7 +100,9 @@ public Lookup getLookup() {
75100
this,
76101
new PythonActionProvider(this),
77102
new PythonInfo(),
78-
new PythonProjectLogicalView(this)
103+
new PythonProjectLogicalView(this),
104+
new PythonSources(this)
105+
//TODO Determine if needed for future enhancements; remove if not needed
79106
// , new CustomizerProvider() {
80107
// @Override
81108
// public void showCustomizer() {
@@ -85,34 +112,68 @@ public Lookup getLookup() {
85112
// getProjectDirectory().getName());
86113
// }
87114
// }
115+
// new ClassPathProviderImpl(this),
116+
// new Info(), // Project information Implementation
117+
// logicalView, // Logical view if project implementation
118+
// new PythonOpenedHook(), //Called by project framework when project is opened (closed)
119+
// new PythonProjectXmlSavedHook(), //Called when project.xml changes
120+
// new PythonSources(this, helper, evaluator, sourceRoots, testRoots), //Python source grops - used by package view, factories, refactoring, ...
121+
// new PythonProjectOperations(this), //move, rename, copy of project
122+
// new RecommendedTemplatesImpl(this.updateHelper), // Recommended Templates
123+
// new PythonCustomizerProvider(this), //Project custmoizer
124+
// new PythonFileEncodingQuery(),
125+
// new PythonProjectTemplateAttributesProvider(getEvaluator()),
126+
// new PythonSharabilityQuery(helper, getEvaluator(), getSourceRoots(), getTestRoots()), //Sharabilit info - used by VCS
127+
// helper.createCacheDirectoryProvider(), //Cache provider
128+
// helper.createAuxiliaryProperties(), // AuxiliaryConfiguraion provider - used by bookmarks, project Preferences, etc
129+
// new PythonPlatformProvider(getEvaluator()),
130+
// new PythonCoverageProvider(this),
131+
// new PythonProjectSourceLevelQuery(evaluator, "")
88132
});
89133
}
90134
return lkp;
91135
}
92136

93-
public PropertyEvaluator getEvaluator() {
94-
return evaluator;
137+
public SourceRoots getSourceRoots() {
138+
// if source root has not been established yet, try to set based on project directory
139+
if (this.sourceRoots == null) {
140+
this.sourceRoots = SourceRoots.create(this);
141+
}
142+
return this.sourceRoots;
143+
}
144+
145+
public SourceRoots getTestRoots() {
146+
return this.testRoots;
95147
}
96148

97-
AntProjectHelper getHelper() {
98-
return this.helper;
149+
public FileObject[] getSourceRootFiles() {
150+
return getSourceRoots().getRoots();
99151
}
100152

101-
public SourceRoots getSourceRoots() {
102-
return this.sourceRoots;
153+
public FileObject[] getTestSourceRootFiles() {
154+
return getTestRoots().getRoots();
103155
}
156+
157+
public Object getName() {
158+
PythonInfo pi = lkp.lookup(PythonInfo.class);
159+
return pi.getName();
160+
}
161+
162+
public PythonProjectProperties getProperties() {
163+
if (this.properties == null) {
164+
this.properties = new PythonProjectProperties(this);
165+
this.properties.loadProperties();
166+
}
167+
return properties;
168+
}
104169

105170

106171

107172
private final class PythonInfo implements ProjectInformation {
108173

109-
//@StaticResource()
110-
// public static final String PYTHON_ICON = "org/apache/netbeans/modules/python4nb/editor/py.png";
111-
112174
@Override
113175
public Icon getIcon() {
114176
return new ImageIcon(ImageUtilities.loadImage(PYTHON_PROJECT_ICON));
115-
// return new ImageIcon(ImageUtilities.loadImage(PYTHON_ICON));
116177
}
117178

118179
@Override
@@ -143,12 +204,6 @@ public Project getProject() {
143204

144205
class PythonProjectLogicalView implements LogicalViewProvider {
145206

146-
// @StaticResource()
147-
// public static final String PYTHON_ICON = "org/apache/netbeans/modules/python4nb/editor/py.png";
148-
//
149-
// @StaticResource()
150-
// public static final String PYTHON_PROJECT_ICON = "org/apache/netbeans/modules/python4nb/editor/py_module.png";
151-
152207
private final PythonProject project;
153208

154209
public PythonProjectLogicalView(PythonProject project) {
@@ -203,7 +258,6 @@ public Action[] getActions(boolean arg0) {
203258

204259
@Override
205260
public Image getIcon(int type) {
206-
// return ImageUtilities.loadImage(PYTHON_ICON);
207261
return ImageUtilities.loadImage(PYTHON_PROJECT_ICON);
208262
}
209263

0 commit comments

Comments
 (0)