Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
antbuild.sh
2 changes: 1 addition & 1 deletion core/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
<classpathentry kind="src" path="source"/>
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/LO-Classes"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="module" value="true"/>
</attributes>
Expand Down
3 changes: 2 additions & 1 deletion core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ Require-Bundle: org.eclipse.core.runtime;visibility:=reexport,
org.eclipse.ui.forms,
org.eclipse.debug.core;visibility:=reexport,
org.eclipse.debug.ui,
org.eclipse.ui
org.eclipse.ui,
org.eclipse.jdt.core
Export-Package: org.libreoffice.ide.eclipse.core,
org.libreoffice.ide.eclipse.core.actions,
org.libreoffice.ide.eclipse.core.builders,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ public class TypesBuilder extends IncrementalProjectBuilder {

static int sBuildState = NOT_STARTED_STATE;

private static String sExtension = "idl";
private boolean mChangedIdl = false;

/**
Expand Down Expand Up @@ -140,29 +139,26 @@ private void addVisitor(IResourceDelta delta) throws CoreException {
@Override
public boolean visit(IResourceDelta delta) throws CoreException {

boolean visitChildren = false;
boolean visitChild = false;
IProject prj = getProject();
IUnoidlProject unoprj = ProjectsManager.getProject(prj.getName());

if (unoprj != null) {
IPath idlPath = unoprj.getIdlPath();
IPath resPath = delta.getResource().getProjectRelativePath();
int resType = delta.getResource().getType();

if (resType == IResource.PROJECT) {
visitChildren = true;
} else if (resType == IResource.FOLDER &&
resPath.toString().startsWith(idlPath.toString())) {
visitChildren = true;
} else if (resType == IResource.FILE) {
if (sExtension.equalsIgnoreCase(resPath.getFileExtension())) { //$NON-NLS-1$
IUnoidlProject unoPrj = ProjectsManager.getProject(prj.getName());

if (unoPrj != null) {
IResource res = delta.getResource();

if (res.getType() == IResource.PROJECT) {
visitChild = true;
} else if (res.getType() == IResource.FOLDER) {
visitChild = res.getProjectRelativePath().toString().startsWith(unoPrj.getIdlDir());
} else if (res.getType() == IResource.FILE) {
if (res.getFileExtension().equals(IUnoidlProject.IDL_EXTENSION)) {
mChangedIdl = true;
} else if (resPath.toString().endsWith(unoprj.getTypesPath().toString())) {
} else if (res.equals(unoPrj.getTypesFile())) {
sBuildState = COMPLETED_STATE;
}
}
}
return visitChildren;
return visitChild;
}
});
}
Expand Down Expand Up @@ -203,6 +199,9 @@ public static void build(IProject prj, IProgressMonitor monitor) throws Exceptio
languageBuilder.generateFromTypes(unoprj.getSdk(), unoprj.getOOo(), prj, types,
build, unoprj.getRootModule(), monitor);

// Check manifest.xml types file entry
unoprj.checkManifestTypes();

prj.refreshLocal(IResource.DEPTH_INFINITE, monitor);
sBuildState = NOT_STARTED_STATE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public static UnoPackage createPackage(IUnoidlProject project, File destFile, Li
pack.addContent(UnoPackage.getPathRelativeToBase(resFile, prjFile), resFile);
}

IFile componentFile = project.getFile(project.getName() + ".component");
IFile componentFile = project.getComponentsFile();
if (componentFile.exists()) {
File resFile = SystemHelper.getFile(componentFile);
pack.addContent(UnoPackage.getPathRelativeToBase(resFile, prjFile), resFile);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,266 @@
/*************************************************************************
* The Contents of this file are made available subject to the terms of
* the GNU Lesser General Public License Version 2.1
*
* Sun Microsystems Inc., October, 2000
*
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2000 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc..
*
* Copyright: 2002 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
* Contributor(s): Cedric Bosdonnat
*
*
************************************************************************/
package org.libreoffice.ide.eclipse.core.internal.helpers;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.ASTParser;
import org.eclipse.jdt.core.dom.ASTVisitor;
import org.eclipse.jdt.core.dom.BodyDeclaration;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.FieldDeclaration;
import org.eclipse.jdt.core.dom.ImportDeclaration;
import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.Modifier;
import org.eclipse.jdt.core.dom.StringLiteral;
import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.Document;
import org.eclipse.text.edits.MalformedTreeException;
import org.eclipse.text.edits.TextEdit;
import org.libreoffice.ide.eclipse.core.PluginLogger;
import org.libreoffice.ide.eclipse.core.model.IUnoidlProject;

/**
* This class is an helper for modifying the skeleton produced by uno-skeletonmaker
* when it does not support passive registration.
*
*/
public final class UnoSkeletonHelper {

public static boolean supportPassiveRegistration(IUnoidlProject prj, String command, IProgressMonitor monitor) {
String version = "0.4"; //$NON-NLS-1$
Process process = prj.getSdk().runTool(prj, command + " --version", monitor); //$NON-NLS-1$
// To get uno-skeletonmaker version we need to process the error stream
try {
String error = readErrorStream(process);
version = error.substring(error.lastIndexOf(' ') + 1);
} catch (IOException e) { }
return version.compareTo("0.5") > -1; //$NON-NLS-1$
}

public static String readErrorStream(Process process) throws IOException {
String error = null;
try (InputStream input = process.getErrorStream();
Scanner scanner = new Scanner(input).useDelimiter("\\A")) { //$NON-NLS-1$
if (scanner.hasNext()) {
error = scanner.next().trim();
}
}
return error;
}

public static void cleanupJavaSkeleton(IFile file, String serviceName, IProgressMonitor monitor) {
try {
Document document = removeUnneededCode(file, monitor);
addNeededCode(document, serviceName, monitor);
// Save the document
Files.writeString(file.getLocation().toPath(), document.get());
} catch (MalformedTreeException | BadLocationException |
IOException | JavaModelException | IllegalArgumentException e) {
PluginLogger.error("UnoSkeletonHelper.cleanupJavaSkeleton ERROR", e); //$NON-NLS-1$
}
}

private static Document removeUnneededCode(IFile file, IProgressMonitor monitor)
throws MalformedTreeException, BadLocationException,
JavaModelException, IllegalArgumentException {
ICompilationUnit compilationUnit = JavaCore.createCompilationUnitFrom(file);
Document document = new Document(compilationUnit.getSource());
CompilationUnit unit = getCompilationUnit(compilationUnit, monitor);
ASTRewrite rewriter = ASTRewrite.create(unit.getAST());
// Remove all import except XComponentContext and WeakBase
for (ImportDeclaration imp : ImportDeclarationFinder.perform(unit)) {
rewriter.remove(imp, null);
}
// Remove all methods starting with "__"
for (MethodDeclaration method : MethodDeclarationFinder.perform(unit)) {
rewriter.remove(method, null);
}
// Apply changes
TextEdit edits = rewriter.rewriteAST();
edits.apply(document);
return document;
}

@SuppressWarnings("unchecked")
private static void addNeededCode(Document document, String serviceName, IProgressMonitor monitor)
throws MalformedTreeException, BadLocationException {
// Add m_serviceName field
CompilationUnit unit = getCompilationUnit(document.get(), monitor);
unit.recordModifications();
FieldDeclaration serviceNameField = getServiceNameField(unit.getAST(), serviceName);
int indexField = FieldIndexFinder.perform(unit);
TypeDeclaration type = (TypeDeclaration) unit.types().get(0);
type.bodyDeclarations().add(indexField, (BodyDeclaration) serviceNameField);
// Apply changes
TextEdit edits = unit.rewrite(document, null);
edits.apply(document);
}

private static CompilationUnit getCompilationUnit(ICompilationUnit unit, IProgressMonitor monitor) {
ASTParser parser = getParser();
parser.setResolveBindings(true);
parser.setBindingsRecovery(true);
parser.setSource(unit);
return (CompilationUnit) parser.createAST(monitor);
}

private static CompilationUnit getCompilationUnit(String source, IProgressMonitor monitor) {
ASTParser parser = getParser();
parser.setSource(source.toCharArray());
return (CompilationUnit) parser.createAST(monitor);
}

private static ASTParser getParser() {
ASTParser parser = ASTParser.newParser(AST.getJLSLatest());
parser.setKind(ASTParser.K_COMPILATION_UNIT);
return parser;
}

@SuppressWarnings("unchecked")
private static FieldDeclaration getServiceNameField(AST ast, String serviceName) {
VariableDeclarationFragment fragment = ast.newVariableDeclarationFragment();

StringLiteral literal = ast.newStringLiteral();
literal.setLiteralValue(serviceName);

fragment.setInitializer(literal);
fragment.setName(ast.newSimpleName("m_serviceName"));

FieldDeclaration fieldDeclaration = ast.newFieldDeclaration(fragment);
fieldDeclaration.setType(ast.newSimpleType(ast.newSimpleName("String")));

fieldDeclaration.modifiers().addAll(ast.newModifiers(Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL));

return fieldDeclaration;
}

private static final class MethodDeclarationFinder extends ASTVisitor {
private final List <MethodDeclaration> mMethods = new ArrayList <> ();

public static List<MethodDeclaration> perform(ASTNode node) {
MethodDeclarationFinder finder = new MethodDeclarationFinder();
node.accept(finder);
return finder.getMethods();
}

@Override
public boolean visit (final MethodDeclaration method) {
if (method.getName().getIdentifier().startsWith("__")) {
mMethods.add (method);
}
return super.visit(method);
}

/**
* @return an immutable list view of the methods discovered by this visitor
*/
public List <MethodDeclaration> getMethods() {
return Collections.unmodifiableList(mMethods);
}
}

private static final class ImportDeclarationFinder extends ASTVisitor {
private final List <ImportDeclaration> mImports = new ArrayList <> ();

public static List<ImportDeclaration> perform(ASTNode node) {
ImportDeclarationFinder finder = new ImportDeclarationFinder();
node.accept(finder);
return finder.getImports();
}

@Override
public boolean visit (final ImportDeclaration imp) {
String fullName = imp.getName().getFullyQualifiedName();
if (!(fullName.endsWith("XComponentContext") || fullName.endsWith("WeakBase"))) {
mImports.add (imp);
}
return super.visit(imp);
}

/**
* @return an immutable list view of the imports discovered by this visitor
*/
public List <ImportDeclaration> getImports() {
return Collections.unmodifiableList(mImports);
}
}

private static final class FieldIndexFinder extends ASTVisitor {
private int mCount = 0;
private int mIndex = 0;

public static int perform(ASTNode node) {
FieldIndexFinder finder = new FieldIndexFinder();
node.accept(finder);
return finder.getFieldIndex();
}

@Override
public boolean visit (final FieldDeclaration field) {
if (field.toString().contains("m_serviceNames")) {
mIndex = mCount;
}
mCount ++;
return super.visit(field);
}

/**
* @return index of m_serviceNames field discovered by this visitor
*/
public int getFieldIndex() {
return mIndex;
}
}

}
Loading