mirror of
https://github.com/LibreOffice/loeclipse.git
synced 2025-08-16 15:31:06 +00:00
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
This commit is contained in:
@ -184,7 +184,7 @@ public class PackageContentSelector extends Composite {
|
||||
// Create the package model
|
||||
pack = UnoidlProjectHelper.createMinimalUnoPackage(pProject, pDestFile);
|
||||
|
||||
if (library.exists()) {
|
||||
if (library != null && library.exists()) {
|
||||
pack.addToClean(SystemHelper.getFile(library));
|
||||
File libraryFile = SystemHelper.getFile(library);
|
||||
pack.addFile(UnoPackage.getPathRelativeToBase(libraryFile, prjFile), libraryFile);
|
||||
|
@ -68,7 +68,7 @@ public class Language extends AbstractLanguage {
|
||||
*/
|
||||
@Override
|
||||
public ILanguageBuilder getLanguageBuilder() {
|
||||
return new PythonBuilder(this);
|
||||
return new PythonBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -57,26 +57,13 @@ import org.libreoffice.plugin.core.model.UnoPackage;
|
||||
* The language builder implementation for Python.
|
||||
*/
|
||||
public class PythonBuilder implements ILanguageBuilder {
|
||||
|
||||
private Language mLanguage;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param pLanguage the Python Language object
|
||||
*/
|
||||
public PythonBuilder(Language pLanguage) {
|
||||
mLanguage = pLanguage;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public IFile createLibrary(IUnoidlProject pUnoProject) throws Exception {
|
||||
IFile jarFile = ((PythonProjectHandler) mLanguage.getProjectHandler()).getJarFile(pUnoProject);
|
||||
|
||||
return jarFile;
|
||||
// Nothing to do for Python
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -85,7 +72,7 @@ public class PythonBuilder implements ILanguageBuilder {
|
||||
@Override
|
||||
public void generateFromTypes(ISdk pSdk, IOOo pOoo, IProject pPrj, File pTypesFile,
|
||||
File pBuildFolder, String pRootModule, IProgressMonitor pMonitor) {
|
||||
|
||||
// Nothing to do for Python
|
||||
}
|
||||
|
||||
/**
|
||||
@ -93,7 +80,6 @@ public class PythonBuilder implements ILanguageBuilder {
|
||||
*/
|
||||
@Override
|
||||
public String[] getBuildEnv(IUnoidlProject pUnoProject) {
|
||||
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
@ -102,20 +88,24 @@ public class PythonBuilder implements ILanguageBuilder {
|
||||
*/
|
||||
@Override
|
||||
public void fillUnoPackage(UnoPackage pUnoPackage, IUnoidlProject pUnoPrj) {
|
||||
File prjFile = SystemHelper.getFile(pUnoPrj);
|
||||
|
||||
// Add the "main" python file as component
|
||||
String mainPythonFilePath = pUnoPrj.getSourcePath() + "/" + pUnoPrj.getName().replace(" ", "") + ".py";
|
||||
File mainPythonFile = SystemHelper.getFile(pUnoPrj.getFile(mainPythonFilePath));
|
||||
pUnoPackage.addComponentFile(
|
||||
UnoPackage.getPathRelativeToBase(mainPythonFile, prjFile),
|
||||
mainPythonFile, "Python");
|
||||
|
||||
//All the constituent Python files of the project are added
|
||||
File prjFile = SystemHelper.getFile(pUnoPrj);
|
||||
IFolder sourceFolder = pUnoPrj.getFolder(pUnoPrj.getSourcePath());
|
||||
ArrayList<IFile> pythonFiles = new ArrayList<IFile>();
|
||||
getPythonFiles(sourceFolder, pythonFiles, pUnoPrj);
|
||||
|
||||
for (IFile pythonFile : pythonFiles) {
|
||||
File eachFile = SystemHelper.getFile(pythonFile);
|
||||
pUnoPackage.addComponentFile(
|
||||
UnoPackage.getPathRelativeToBase(eachFile, prjFile),
|
||||
eachFile, "Python"); //$NON-NLS-1$
|
||||
pUnoPackage.addOtherFile(UnoPackage.getPathRelativeToBase(eachFile, prjFile), eachFile);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -131,17 +121,14 @@ public class PythonBuilder implements ILanguageBuilder {
|
||||
if (member.getType() == 2) { // '1' is for file and '2' is for folder
|
||||
IFolder subSourceFolder = ResourcesPlugin.getWorkspace().getRoot().getFolder(member.getFullPath());
|
||||
getPythonFiles(subSourceFolder, pythonFiles, pUnoPrj);
|
||||
} else {
|
||||
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(member.getFullPath());
|
||||
pythonFiles.add(file);
|
||||
continue;
|
||||
}
|
||||
|
||||
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(member.getFullPath());
|
||||
pythonFiles.add(file);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
PluginLogger.error(
|
||||
Messages.getString("PythonExport.SourceFolderError"), e);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,6 @@
|
||||
************************************************************************/
|
||||
package org.libreoffice.ide.eclipse.python;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@ -46,16 +45,10 @@ import org.eclipse.core.resources.IFolder;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IProjectDescription;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IWorkspaceRoot;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.jdt.core.IClasspathEntry;
|
||||
import org.eclipse.jdt.core.IJavaProject;
|
||||
import org.eclipse.jdt.core.JavaCore;
|
||||
import org.eclipse.jdt.core.JavaModelException;
|
||||
import org.eclipse.ui.IWorkbenchWindow;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.libreoffice.ide.eclipse.core.PluginLogger;
|
||||
@ -83,8 +76,7 @@ public class PythonProjectHandler implements IProjectHandler {
|
||||
*/
|
||||
@Override
|
||||
public void addOOoDependencies(IOOo pOoo, IProject pProject) {
|
||||
|
||||
PluginLogger.debug("For a Python project 'No' OOo dependencies are added"); //$NON-NLS-1$
|
||||
// Nothing to do for Python
|
||||
}
|
||||
|
||||
/**
|
||||
@ -188,7 +180,7 @@ public class PythonProjectHandler implements IProjectHandler {
|
||||
@Override
|
||||
public IPath getImplementationFile(String pImplementationName) {
|
||||
|
||||
return new Path(pImplementationName.replace(".", "/") + ".java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
return new Path(pImplementationName.replace(".", "/") + ".py"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
}
|
||||
|
||||
/**
|
||||
@ -211,45 +203,12 @@ public class PythonProjectHandler implements IProjectHandler {
|
||||
*/
|
||||
@Override
|
||||
public String getLibraryPath(IUnoidlProject pProject) {
|
||||
return getJarFile(pProject).getLocation().toOSString();
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a handle to the project jar file. Beware that this handle may refer to a non-existing file. Users have to
|
||||
* create it if necessary.
|
||||
*
|
||||
* @param pProject
|
||||
* the concerned UNO project
|
||||
* @return a handle to the jar file of the project
|
||||
*/
|
||||
public IFile getJarFile(IUnoidlProject pProject) {
|
||||
String filename = pProject.getName().replace(" ", "") + ".jar"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
return pProject.getFile(filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public IFolder[] getBinFolders(IUnoidlProject pUnoidlProject) {
|
||||
ArrayList<IFolder> folders = new ArrayList<IFolder>();
|
||||
|
||||
IWorkspaceRoot workspace = ResourcesPlugin.getWorkspace().getRoot();
|
||||
IProject prj = workspace.getProject(pUnoidlProject.getName());
|
||||
IJavaProject javaPrj = JavaCore.create(prj);
|
||||
try {
|
||||
folders.add(workspace.getFolder(javaPrj.getOutputLocation()));
|
||||
|
||||
IClasspathEntry[] entries = javaPrj.getRawClasspath();
|
||||
for (IClasspathEntry entry : entries) {
|
||||
if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE && entry.getOutputLocation() != null) {
|
||||
folders.add(workspace.getFolder(entry.getOutputLocation()));
|
||||
}
|
||||
}
|
||||
} catch (JavaModelException e) {
|
||||
}
|
||||
|
||||
return folders.toArray(new IFolder[folders.size()]);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -37,7 +37,6 @@
|
||||
package org.libreoffice.ide.eclipse.python;
|
||||
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IResourceDelta;
|
||||
import org.eclipse.core.resources.IResourceDeltaVisitor;
|
||||
import org.eclipse.core.resources.IWorkspaceRoot;
|
||||
@ -88,19 +87,7 @@ public class PythonResourceDeltaVisitor implements IResourceDeltaVisitor {
|
||||
*/
|
||||
private void removeImplementation(IResourceDelta pDelta,
|
||||
IUnoidlProject pUnoprj) {
|
||||
// IResource res = pDelta.getResource();
|
||||
// if (res.getName().endsWith(".java")) { //$NON-NLS-1$
|
||||
// String prjPath = pDelta.getProjectRelativePath().toString();
|
||||
// prjPath = prjPath.replace(".java", ""); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
// prjPath = prjPath.replace("/", "."); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
//
|
||||
// Vector<String> classes = RegistrationHelper.readClassesList(pUnoprj);
|
||||
// for (String implName : classes) {
|
||||
// if (prjPath.endsWith(implName)) {
|
||||
// RegistrationHelper.removeImplementation(pUnoprj, implName);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// Nothing to do for Python
|
||||
}
|
||||
|
||||
/**
|
||||
@ -110,10 +97,7 @@ public class PythonResourceDeltaVisitor implements IResourceDeltaVisitor {
|
||||
* @param pUnoProject the concerned UNO project
|
||||
*/
|
||||
private void addImplementation(IResourceDelta pDelta, IUnoidlProject pUnoProject) {
|
||||
// String className = isJavaServiceImpl(pDelta.getResource());
|
||||
// if (className != null) {
|
||||
// RegistrationHelper.addImplementation(pUnoProject, className);
|
||||
// }
|
||||
// Nothing to do for Python
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user