Skip to content

Commit

Permalink
Fixed cross projects workspace resolution.
Browse files Browse the repository at this point in the history
  • Loading branch information
ylussaud committed Jan 29, 2024
1 parent bd6082a commit 513bb23
Show file tree
Hide file tree
Showing 12 changed files with 156 additions and 56 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2020, 2023 Obeo.
* Copyright (c) 2020, 2024 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -153,7 +153,7 @@ public AcceleoProject getProject(AcceleoWorkspace workspace, URI resource) {
public IQueryWorkspaceQualifiedNameResolver createResolver(AcceleoProject acceleoProject) {
Objects.nonNull(acceleoProject);

final IProject eclipseProject = synchronizer.getProject(acceleoProject);
final IProject eclipseProject = synchronizer.getOrCreateProject(acceleoProject);
final IQualifiedNameResolver resolver = QueryPlugin.getPlugin().createQualifiedNameResolver(
AcceleoPlugin.getPlugin().getClass().getClassLoader(), eclipseProject,
AcceleoParser.QUALIFIER_SEPARATOR, true);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2020, 2023 Obeo.
* Copyright (c) 2020, 2024 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand All @@ -16,6 +16,7 @@
import org.eclipse.acceleo.aql.ls.AcceleoLanguageServer;
import org.eclipse.acceleo.aql.ls.services.textdocument.AcceleoTextDocument;
import org.eclipse.acceleo.query.runtime.namespace.IQualifiedNameQueryEnvironment;
import org.eclipse.acceleo.query.runtime.namespace.workspace.IQueryProject;
import org.eclipse.acceleo.query.runtime.namespace.workspace.IQueryWorkspaceQualifiedNameResolver;

/**
Expand All @@ -25,7 +26,7 @@
*
* @author Florent Latombe
*/
public class AcceleoProject {
public class AcceleoProject implements IQueryProject {

/**
* The project name.
Expand Down Expand Up @@ -55,11 +56,7 @@ public AcceleoProject(String name, AcceleoWorkspace workspace) {
this.workspace = workspace;
}

/**
* Gets the project name.
*
* @return the project name
*/
@Override
public String getName() {
return name;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2020, 2023 Obeo.
* Copyright (c) 2020, 2024 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -79,11 +79,6 @@ public AcceleoLanguageServer getOwner() {
return owner;
}

@Override
public synchronized void addProject(AcceleoProject project) {
super.addProject(project);
}

@Override
public synchronized String addResource(AcceleoProject project, URI resource) {
final IQueryWorkspaceQualifiedNameResolver resolver = getResolver(project);
Expand Down Expand Up @@ -120,6 +115,7 @@ public String removeResource(AcceleoProject project, URI resource) {
final AcceleoTextDocument removedDocument = uriToDocuments.remove(resource);
if (removedDocument != null) {
project.removeDocument(removedDocument);
uriToDocuments.remove(getResolver(project).getURI(removedDocument.getModuleQualifiedName()));
uriToDocuments.remove(getResolver(project).getSourceURI(removedDocument
.getModuleQualifiedName()));
}
Expand All @@ -132,6 +128,8 @@ public String moveResource(AcceleoProject sourceProject, URI sourceResource, Acc
final AcceleoTextDocument removedDocument = uriToDocuments.remove(sourceResource);
if (removedDocument != null) {
sourceProject.removeDocument(removedDocument);
uriToDocuments.remove(getResolver(sourceProject).getURI(removedDocument
.getModuleQualifiedName()));
uriToDocuments.remove(getResolver(sourceProject).getSourceURI(removedDocument
.getModuleQualifiedName()));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2020, 2023 Obeo.
* Copyright (c) 2020, 2024 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand All @@ -23,6 +23,7 @@
import org.eclipse.acceleo.query.runtime.impl.namespace.ClassLoaderQualifiedNameResolver;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
Expand Down Expand Up @@ -107,7 +108,7 @@ protected static ClassLoader createProjectClassLoader(ClassLoader classLoader, I

if (project.exists() && project.isOpen()) {
final IJavaProject javaProject = JavaCore.create(project);
if (javaProject != null) {
if (javaProject != null && javaProject.exists()) {
try {
final String[] classPathEntries = getClassPathes(javaProject, forWorspace,
dependencyProjectEntries);
Expand Down Expand Up @@ -140,7 +141,7 @@ protected static ClassLoader createProjectClassLoader(ClassLoader classLoader, I

// copied from JavaRuntime.computeDefaultRuntimeClassPath()
private static String[] getClassPathes(IJavaProject javaProject, boolean forWorkspace,
List<String> acceleoRes) throws CoreException {
List<String> dependencyProjectEntries) throws CoreException {
IRuntimeClasspathEntry[] unresolved = JavaRuntime.computeUnresolvedRuntimeClasspath(javaProject);

// 1. remove bootpath entries
Expand All @@ -152,14 +153,11 @@ private static String[] getClassPathes(IJavaProject javaProject, boolean forWork
IRuntimeClasspathEntry[] entries = JavaRuntime.resolveRuntimeClasspathEntry(entry,
javaProject);
for (int j = 0; j < entries.length; j++) {
if (isDependencyProjectEntry(javaProject, forWorkspace, entries[j])) {
String location = entries[j].getLocation();
if (location != null) {
acceleoRes.add(location);
}
}
String location = entries[j].getLocation();
if (location != null) {
if (isDependencyProjectEntry(javaProject, forWorkspace, entries[j])) {
dependencyProjectEntries.add(location);
}
resolved.add(location);
}
}
Expand All @@ -184,8 +182,26 @@ private static String[] getClassPathes(IJavaProject javaProject, boolean forWork
*/
private static boolean isDependencyProjectEntry(IJavaProject javaProject, boolean forWorkspace,
IRuntimeClasspathEntry entry) {
return forWorkspace && entry.getType() == IRuntimeClasspathEntry.PROJECT && javaProject
.getProject() != entry.getResource();
final boolean res;

if (forWorkspace) {
if (entry.getType() == IRuntimeClasspathEntry.PROJECT && javaProject.getProject() != entry
.getResource()) {
res = true;
} else {
final IResource entryResource = entry.getResource();
if (entryResource != null && entryResource.exists() && entryResource.getProject() != null
&& !entryResource.getProject().equals(javaProject.getProject())) {
res = true;
} else {
res = false;
}
}
} else {
res = false;
}

return res;
}

@Override
Expand Down Expand Up @@ -269,7 +285,7 @@ private URI getSourceURI(IJavaProject javaProject, String qualifiedName) throws
break found;
}
}
} else if (!forWorkspace && entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
} else if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
final IProject childProject = ResourcesPlugin.getWorkspace().getRoot().getProject(entry
.getPath().lastSegment());
if (childProject != null) {
Expand Down
Loading

0 comments on commit 513bb23

Please sign in to comment.