Skip to content

Commit 58d4f5b

Browse files
committed
Improve python project support
* Only add one python component (file name equals project name) * Add other py files just as normal files to package * Cleanups
1 parent 5310fc6 commit 58d4f5b

File tree

5 files changed

+23
-93
lines changed

5 files changed

+23
-93
lines changed

core/source/org/libreoffice/ide/eclipse/core/gui/PackageContentSelector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public static UnoPackage createPackage(IUnoidlProject pProject, File pDestFile,
184184
// Create the package model
185185
pack = UnoidlProjectHelper.createMinimalUnoPackage(pProject, pDestFile);
186186

187-
if (library.exists()) {
187+
if (library != null && library.exists()) {
188188
pack.addToClean(SystemHelper.getFile(library));
189189
File libraryFile = SystemHelper.getFile(library);
190190
pack.addFile(UnoPackage.getPathRelativeToBase(libraryFile, prjFile), libraryFile);

python/source/org/libreoffice/ide/eclipse/python/Language.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public class Language extends AbstractLanguage {
6868
*/
6969
@Override
7070
public ILanguageBuilder getLanguageBuilder() {
71-
return new PythonBuilder(this);
71+
return new PythonBuilder();
7272
}
7373

7474
/**

python/source/org/libreoffice/ide/eclipse/python/PythonBuilder.java

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -57,26 +57,13 @@
5757
* The language builder implementation for Python.
5858
*/
5959
public class PythonBuilder implements ILanguageBuilder {
60-
61-
private Language mLanguage;
62-
63-
/**
64-
* Constructor.
65-
*
66-
* @param pLanguage the Python Language object
67-
*/
68-
public PythonBuilder(Language pLanguage) {
69-
mLanguage = pLanguage;
70-
}
71-
7260
/**
7361
* {@inheritDoc}
7462
*/
7563
@Override
7664
public IFile createLibrary(IUnoidlProject pUnoProject) throws Exception {
77-
IFile jarFile = ((PythonProjectHandler) mLanguage.getProjectHandler()).getJarFile(pUnoProject);
78-
79-
return jarFile;
65+
// Nothing to do for Python
66+
return null;
8067
}
8168

8269
/**
@@ -85,15 +72,14 @@ public IFile createLibrary(IUnoidlProject pUnoProject) throws Exception {
8572
@Override
8673
public void generateFromTypes(ISdk pSdk, IOOo pOoo, IProject pPrj, File pTypesFile,
8774
File pBuildFolder, String pRootModule, IProgressMonitor pMonitor) {
88-
75+
// Nothing to do for Python
8976
}
9077

9178
/**
9279
* {@inheritDoc}
9380
*/
9481
@Override
9582
public String[] getBuildEnv(IUnoidlProject pUnoProject) {
96-
9783
return new String[0];
9884
}
9985

@@ -102,20 +88,24 @@ public String[] getBuildEnv(IUnoidlProject pUnoProject) {
10288
*/
10389
@Override
10490
public void fillUnoPackage(UnoPackage pUnoPackage, IUnoidlProject pUnoPrj) {
91+
File prjFile = SystemHelper.getFile(pUnoPrj);
92+
93+
// Add the "main" python file as component
94+
String mainPythonFilePath = pUnoPrj.getSourcePath() + "/" + pUnoPrj.getName().replace(" ", "") + ".py";
95+
File mainPythonFile = SystemHelper.getFile(pUnoPrj.getFile(mainPythonFilePath));
96+
pUnoPackage.addComponentFile(
97+
UnoPackage.getPathRelativeToBase(mainPythonFile, prjFile),
98+
mainPythonFile, "Python");
10599

106100
//All the constituent Python files of the project are added
107-
File prjFile = SystemHelper.getFile(pUnoPrj);
108101
IFolder sourceFolder = pUnoPrj.getFolder(pUnoPrj.getSourcePath());
109102
ArrayList<IFile> pythonFiles = new ArrayList<IFile>();
110103
getPythonFiles(sourceFolder, pythonFiles, pUnoPrj);
111104

112105
for (IFile pythonFile : pythonFiles) {
113106
File eachFile = SystemHelper.getFile(pythonFile);
114-
pUnoPackage.addComponentFile(
115-
UnoPackage.getPathRelativeToBase(eachFile, prjFile),
116-
eachFile, "Python"); //$NON-NLS-1$
107+
pUnoPackage.addOtherFile(UnoPackage.getPathRelativeToBase(eachFile, prjFile), eachFile);
117108
}
118-
119109
}
120110

121111
/**
@@ -131,17 +121,14 @@ private void getPythonFiles(IFolder sourceFolder, ArrayList<IFile> pythonFiles,
131121
if (member.getType() == 2) { // '1' is for file and '2' is for folder
132122
IFolder subSourceFolder = ResourcesPlugin.getWorkspace().getRoot().getFolder(member.getFullPath());
133123
getPythonFiles(subSourceFolder, pythonFiles, pUnoPrj);
134-
} else {
135-
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(member.getFullPath());
136-
pythonFiles.add(file);
124+
continue;
137125
}
138-
126+
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(member.getFullPath());
127+
pythonFiles.add(file);
139128
}
140129
} catch (Exception e) {
141130
PluginLogger.error(
142131
Messages.getString("PythonExport.SourceFolderError"), e);
143-
144132
}
145-
146133
}
147134
}

python/source/org/libreoffice/ide/eclipse/python/PythonProjectHandler.java

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
************************************************************************/
3737
package org.libreoffice.ide.eclipse.python;
3838

39-
import java.util.ArrayList;
4039
import java.util.Arrays;
4140
import java.util.List;
4241

@@ -46,16 +45,10 @@
4645
import org.eclipse.core.resources.IProject;
4746
import org.eclipse.core.resources.IProjectDescription;
4847
import org.eclipse.core.resources.IResource;
49-
import org.eclipse.core.resources.IWorkspaceRoot;
50-
import org.eclipse.core.resources.ResourcesPlugin;
5148
import org.eclipse.core.runtime.CoreException;
5249
import org.eclipse.core.runtime.IPath;
5350
import org.eclipse.core.runtime.IProgressMonitor;
5451
import org.eclipse.core.runtime.Path;
55-
import org.eclipse.jdt.core.IClasspathEntry;
56-
import org.eclipse.jdt.core.IJavaProject;
57-
import org.eclipse.jdt.core.JavaCore;
58-
import org.eclipse.jdt.core.JavaModelException;
5952
import org.eclipse.ui.IWorkbenchWindow;
6053
import org.eclipse.ui.PlatformUI;
6154
import org.libreoffice.ide.eclipse.core.PluginLogger;
@@ -83,8 +76,7 @@ public class PythonProjectHandler implements IProjectHandler {
8376
*/
8477
@Override
8578
public void addOOoDependencies(IOOo pOoo, IProject pProject) {
86-
87-
PluginLogger.debug("For a Python project 'No' OOo dependencies are added"); //$NON-NLS-1$
79+
// Nothing to do for Python
8880
}
8981

9082
/**
@@ -188,7 +180,7 @@ public String getImplementationName(IUnoidlProject pPrj, String pService) throws
188180
@Override
189181
public IPath getImplementationFile(String pImplementationName) {
190182

191-
return new Path(pImplementationName.replace(".", "/") + ".java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
183+
return new Path(pImplementationName.replace(".", "/") + ".py"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
192184
}
193185

194186
/**
@@ -211,45 +203,12 @@ public void removeOOoDependencies(IOOo pOoo, IProject pProject) {
211203
*/
212204
@Override
213205
public String getLibraryPath(IUnoidlProject pProject) {
214-
return getJarFile(pProject).getLocation().toOSString();
215-
}
216-
217-
/**
218-
* Returns a handle to the project jar file. Beware that this handle may refer to a non-existing file. Users have to
219-
* create it if necessary.
220-
*
221-
* @param pProject
222-
* the concerned UNO project
223-
* @return a handle to the jar file of the project
224-
*/
225-
public IFile getJarFile(IUnoidlProject pProject) {
226-
String filename = pProject.getName().replace(" ", "") + ".jar"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
227-
return pProject.getFile(filename);
206+
return "";
228207
}
229208

230-
/**
231-
* {@inheritDoc}
232-
*/
233209
@Override
234210
public IFolder[] getBinFolders(IUnoidlProject pUnoidlProject) {
235-
ArrayList<IFolder> folders = new ArrayList<IFolder>();
236-
237-
IWorkspaceRoot workspace = ResourcesPlugin.getWorkspace().getRoot();
238-
IProject prj = workspace.getProject(pUnoidlProject.getName());
239-
IJavaProject javaPrj = JavaCore.create(prj);
240-
try {
241-
folders.add(workspace.getFolder(javaPrj.getOutputLocation()));
242-
243-
IClasspathEntry[] entries = javaPrj.getRawClasspath();
244-
for (IClasspathEntry entry : entries) {
245-
if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE && entry.getOutputLocation() != null) {
246-
folders.add(workspace.getFolder(entry.getOutputLocation()));
247-
}
248-
}
249-
} catch (JavaModelException e) {
250-
}
251-
252-
return folders.toArray(new IFolder[folders.size()]);
211+
return null;
253212
}
254213

255214
}

python/source/org/libreoffice/ide/eclipse/python/PythonResourceDeltaVisitor.java

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
package org.libreoffice.ide.eclipse.python;
3838

3939
import org.eclipse.core.resources.IProject;
40-
import org.eclipse.core.resources.IResource;
4140
import org.eclipse.core.resources.IResourceDelta;
4241
import org.eclipse.core.resources.IResourceDeltaVisitor;
4342
import org.eclipse.core.resources.IWorkspaceRoot;
@@ -88,19 +87,7 @@ public boolean visit(IResourceDelta pDelta) throws CoreException {
8887
*/
8988
private void removeImplementation(IResourceDelta pDelta,
9089
IUnoidlProject pUnoprj) {
91-
// IResource res = pDelta.getResource();
92-
// if (res.getName().endsWith(".java")) { //$NON-NLS-1$
93-
// String prjPath = pDelta.getProjectRelativePath().toString();
94-
// prjPath = prjPath.replace(".java", ""); //$NON-NLS-1$ //$NON-NLS-2$
95-
// prjPath = prjPath.replace("/", "."); //$NON-NLS-1$ //$NON-NLS-2$
96-
//
97-
// Vector<String> classes = RegistrationHelper.readClassesList(pUnoprj);
98-
// for (String implName : classes) {
99-
// if (prjPath.endsWith(implName)) {
100-
// RegistrationHelper.removeImplementation(pUnoprj, implName);
101-
// }
102-
// }
103-
// }
90+
// Nothing to do for Python
10491
}
10592

10693
/**
@@ -110,10 +97,7 @@ private void removeImplementation(IResourceDelta pDelta,
11097
* @param pUnoProject the concerned UNO project
11198
*/
11299
private void addImplementation(IResourceDelta pDelta, IUnoidlProject pUnoProject) {
113-
// String className = isJavaServiceImpl(pDelta.getResource());
114-
// if (className != null) {
115-
// RegistrationHelper.addImplementation(pUnoProject, className);
116-
// }
100+
// Nothing to do for Python
117101
}
118102

119103
}

0 commit comments

Comments
 (0)