Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switched to Gradle for language and diagram server build #1469

Merged
merged 9 commits into from
Nov 15, 2022
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 gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ shadowJarVersion=7.1.2
spotlessVersion=6.11.0
xtextGradleVersion=3.0.0
xtextVersion=2.28.0
klighdVersion=2.2.1-SNAPSHOT

[manifestPropertyNames]
org.eclipse.xtext=xtextVersion
Expand Down
1 change: 1 addition & 0 deletions org.lflang.diagram/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Bundle-ActivationPolicy: lazy
Require-Bundle: de.cau.cs.kieler.klighd;bundle-version="2.2.0",
de.cau.cs.kieler.klighd.krendering.extensions;bundle-version="2.2.0",
de.cau.cs.kieler.klighd.lsp;bundle-version="2.2.0",
de.cau.cs.kieler.kgraph.text;bundle-version="2.2.0",
com.google.guava,
org.eclipse.xtext,
org.eclipse.xtext.xbase.lib,
Expand Down
108 changes: 108 additions & 0 deletions org.lflang.diagram/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

repositories {
mavenCentral()
// TODO Remove this in-official maven repository as soon as Klighd is released to maven central in the future.
maven {
url "https://rtsys.informatik.uni-kiel.de/~kieler/files/repo/"
}
}
dependencies {
implementation project(':org.lflang')
implementation project(':org.lflang.ide')
implementation "org.eclipse.xtext:org.eclipse.xtext.ide:${xtextVersion}"
implementation ("de.cau.cs.kieler.klighd:de.cau.cs.kieler.klighd.lsp:${klighdVersion}") {
exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt.*'
exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt'
}
implementation ("de.cau.cs.kieler.klighd:de.cau.cs.kieler.klighd.standalone:${klighdVersion}") {
exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt.*'
exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt'
}
}

apply plugin: 'application'
apply plugin: 'com.github.johnrengelman.shadow'

task generateLanguageDiagramServer {
description 'Creates a jar that implements a language server with diagram support for LF.'

apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'com.github.johnrengelman.shadow'

mainClassName = "org.lflang.diagram.lsp.LanguageDiagramServer"

compileJava {
options.compilerArgs << '-Xlint:unchecked'
}

shadowJar {
classifier = 'lds'

// Handling of service loader registrations via META-INF/services/*
mergeServiceFiles()

// Merge properties
transform(com.github.jengelman.gradle.plugins.shadow.transformers.AppendingTransformer){
resource = 'plugin.properties'
}

// Exclude files that are known to be dispensable for a language server
exclude(
'*._trace',
'*.ecore',
'*.ecorediag',
'*.g',
'*.genmodel',
'*.html',
'*.mwe2',
'*.profile',
'*.xtext',
'*readme.txt',
'.api_description',
'.options',
'about.*',
'about_*',
'about_files/*',
'ant_tasks/*',
'cheatsheets/*',
'com/*/*.java',
'de/*/*.java',
'docs/*',
'log4j.properties',
'META-INF/*.DSA',
'META-INF/*.RSA',
'META-INF/*.SF',
'META-INF/changelog.txt',
'META-INF/DEPENDENCIES',
'META-INF/eclipse.inf',
'META-INF/INDEX.LIST',
'META-INF/maven/*',
'META-INF/NOTICE',
'META-INF/NOTICE.txt',
'META-INF/p2.inf',
'META-INF/versions/*/module-info.class',
'modeling32.png',
'module-info.class',
'org/*/*.java',
'OSGI-INF/l10n/bundle.properties',
'plugin.xml',
'profile.list',
'schema/*',
'systembundle.properties',
'xtend-gen/*',
'xtext32.png',
)

// Minimizing should be enabled with caution because some classes are only
// loaded via services (e.g. diagram syntheses and some xtext aspects)
// and would be removed when minimized
// minimize() {
// exclude(dependency('log4j:log4j:.*'))
// exclude(dependency('org.eclipse.xtext:.*ide:.*'))
// }
}
}

generateLanguageDiagramServer.finalizedBy shadowJar
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@

import java.util.List;

import org.eclipse.xtext.ide.server.LanguageServerImpl;
import org.eclipse.xtext.Constants;
import org.eclipse.xtext.IGrammarAccess;
import org.eclipse.xtext.ide.server.ILanguageServerExtension;
import org.eclipse.xtext.ide.server.LanguageServerImpl;
import org.eclipse.xtext.service.AbstractGenericModule;
import org.eclipse.xtext.util.Modules2;
import org.lflang.generator.LanguageServerErrorReporter;
import org.lflang.ide.LFIdeSetup;

import com.google.inject.Module;
import com.google.inject.name.Names;
import com.google.inject.util.Modules;

import de.cau.cs.kieler.kgraph.text.services.KGraphGrammarAccess;
import de.cau.cs.kieler.klighd.lsp.KGraphLanguageClient;
import de.cau.cs.kieler.klighd.lsp.interactive.layered.LayeredInteractiveLanguageServerExtension;
import de.cau.cs.kieler.klighd.lsp.interactive.rectpacking.RectpackingInteractiveLanguageServerExtension;
Expand All @@ -16,9 +25,6 @@
import de.cau.cs.kieler.klighd.lsp.launch.ILanguageRegistration;
import de.cau.cs.kieler.klighd.lsp.launch.Language;

import org.lflang.ide.LFIdeSetup;
import org.lflang.generator.LanguageServerErrorReporter;

/**
* Language server with extended diagram communication.
*
Expand All @@ -30,10 +36,14 @@ private static class LFLsCreator extends AbstractLsCreator {

@Override
public Module createLSModules(boolean socket) {
return Modules.override(super.createLSModules(socket)).with(new AbstractGenericModule() {
return Modules2.mixin(Modules.override(super.createLSModules(socket)).with(new AbstractGenericModule() {
public Class<? extends LanguageServerImpl> bindLanguageServerImpl() {
return LFLanguageServer.class;
}
}), it -> {
// Temporary fix for an issue of Klighd with Xtext 2.28 (https://github.com/kieler/KLighD/issues/144)
lhstrh marked this conversation as resolved.
Show resolved Hide resolved
it.bind(IGrammarAccess.class).to(KGraphGrammarAccess.class);
it.bind(String.class).annotatedWith(Names.named(Constants.LANGUAGE_NAME)).toInstance("de.cau.cs.kieler.kgraph.text.KGraph");
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import java.io.InputStream;
import java.util.HashMap;

import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.ImageLoader;
//import org.eclipse.swt.graphics.ImageData;
//import org.eclipse.swt.graphics.ImageLoader;
import org.eclipse.xtext.xbase.lib.Extension;
import org.lflang.ASTUtils;
import org.lflang.AttributeUtils;
Expand Down Expand Up @@ -57,10 +57,10 @@ public class ReactorIcons extends AbstractSynthesisExtensions {
@Inject @Extension private KRenderingExtensions _kRenderingExtensions;
@Inject @Extension private KContainerRenderingExtensions _kContainerRenderingExtensions;

private static final ImageLoader LOADER = new ImageLoader();
// private static final ImageLoader LOADER = new ImageLoader();

// Image cache during synthesis
private final HashMap<java.net.URI, ImageData> cache = new HashMap<>();
// private final HashMap<java.net.URI, ImageData> cache = new HashMap<>();

// Error message
private String error = null;
Expand All @@ -83,68 +83,74 @@ public void handleIcon(KContainerRendering rendering, ReactorDecl reactor, boole
if (iconLocation == null) {
error = "Cannot find given icon file.";
} else {
ImageData data = loadImage(iconLocation);
if (data != null) {
KRectangle figure = _kContainerRenderingExtensions.addRectangle(rendering);
_kRenderingExtensions.setInvisible(figure, true);
KGridPlacementData figurePlacement = _kRenderingExtensions.setGridPlacementData(figure, data.width, data.height);
_kRenderingExtensions.to(
_kRenderingExtensions.from(
figurePlacement,
_kRenderingExtensions.LEFT, 3, 0,
_kRenderingExtensions.TOP, 0, 0),
_kRenderingExtensions.RIGHT, 3, 0,
_kRenderingExtensions.BOTTOM, 3, 0);

KRectangle icon = _kContainerRenderingExtensions.addRectangle(figure);
_kRenderingExtensions.setInvisible(icon, true);
_kContainerRenderingExtensions.addImage(icon, data);
_kRenderingExtensions.setPointPlacementData(icon,
_kRenderingExtensions.createKPosition(
_kRenderingExtensions.LEFT, 0, 0.5f,
_kRenderingExtensions.TOP, 0, 0.5f),
_kRenderingExtensions.H_CENTRAL, _kRenderingExtensions.V_CENTRAL, 0,
0, data.width, data.height);
}
if (error != null) {
var errorText = _kContainerRenderingExtensions.addText(rendering, "Icon not found!\n"+error);
_kRenderingExtensions.setForeground(errorText, Colors.RED);
_kRenderingExtensions.setFontBold(errorText, true);
_kRenderingExtensions.setSurroundingSpaceGrid(errorText, 8, 0);
}
/*
lhstrh marked this conversation as resolved.
Show resolved Hide resolved
* This code was disabled because it cannot be compiled for the language server with Gradle.
* As soon as the Klighd API is extended to support URI-based images in both Eclipse and VSCode,
* this code should be reactivated and adapted.
* See: https://github.com/kieler/KLighD/issues/146
*/
// ImageData data = loadImage(iconLocation);
// if (data != null) {
// KRectangle figure = _kContainerRenderingExtensions.addRectangle(rendering);
// _kRenderingExtensions.setInvisible(figure, true);
// KGridPlacementData figurePlacement = _kRenderingExtensions.setGridPlacementData(figure, data.width, data.height);
// _kRenderingExtensions.to(
// _kRenderingExtensions.from(
// figurePlacement,
// _kRenderingExtensions.LEFT, 3, 0,
// _kRenderingExtensions.TOP, 0, 0),
// _kRenderingExtensions.RIGHT, 3, 0,
// _kRenderingExtensions.BOTTOM, 3, 0);
//
// KRectangle icon = _kContainerRenderingExtensions.addRectangle(figure);
// _kRenderingExtensions.setInvisible(icon, true);
// _kContainerRenderingExtensions.addImage(icon, data);
// _kRenderingExtensions.setPointPlacementData(icon,
// _kRenderingExtensions.createKPosition(
// _kRenderingExtensions.LEFT, 0, 0.5f,
// _kRenderingExtensions.TOP, 0, 0.5f),
// _kRenderingExtensions.H_CENTRAL, _kRenderingExtensions.V_CENTRAL, 0,
// 0, data.width, data.height);
// }
// if (error != null) {
// var errorText = _kContainerRenderingExtensions.addText(rendering, "Icon not found!\n"+error);
// _kRenderingExtensions.setForeground(errorText, Colors.RED);
// _kRenderingExtensions.setFontBold(errorText, true);
// _kRenderingExtensions.setSurroundingSpaceGrid(errorText, 8, 0);
// }
}
}
}

private ImageData loadImage(final java.net.URI uri) {
try {
if (cache.containsKey(uri)) {
return cache.get(uri);
}
synchronized (LOADER) {
InputStream inStream = null;
try {
inStream = uri.toURL().openStream();
ImageData[] data = LOADER.load(inStream);
if (data != null && data.length > 0) {
ImageData img = data[0];
cache.put(uri, img);
return img;
} else {
error = "Could not load icon image.";
return null;
}
} finally {
if (inStream != null) {
inStream.close();
}
}
}
} catch (Exception ex) {
ex.printStackTrace();
error = "Could not load icon image.";
return null;
}
}
// private ImageData loadImage(final java.net.URI uri) {
// try {
// if (cache.containsKey(uri)) {
// return cache.get(uri);
// }
// synchronized (LOADER) {
// InputStream inStream = null;
// try {
// inStream = uri.toURL().openStream();
// ImageData[] data = LOADER.load(inStream);
// if (data != null && data.length > 0) {
// ImageData img = data[0];
// cache.put(uri, img);
// return img;
// } else {
// error = "Could not load icon image.";
// return null;
// }
// } finally {
// if (inStream != null) {
// inStream.close();
// }
// }
// }
// } catch (Exception ex) {
// ex.printStackTrace();
// error = "Could not load icon image.";
// return null;
// }
// }

}
45 changes: 0 additions & 45 deletions org.lflang.ide/build.gradle
Original file line number Diff line number Diff line change
@@ -1,52 +1,7 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
dependencies {
implementation project(':org.lflang')
implementation "org.eclipse.xtext:org.eclipse.xtext.ide:${xtextVersion}"
implementation "org.eclipse.xtext:org.eclipse.xtext.xbase.ide:${xtextVersion}"
lhstrh marked this conversation as resolved.
Show resolved Hide resolved
}

apply plugin: 'application'
apply plugin: 'com.github.johnrengelman.shadow'

task generateLanguageServer {
description 'Creates a jar file that implements a language server.'

apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'com.github.johnrengelman.shadow'
mainClassName = "org.eclipse.xtext.ide.server.ServerLauncher"

shadowJar {
classifier = 'ls'
minimize() {
exclude(dependency('log4j:log4j:.*'))
exclude(dependency('org.eclipse.xtext:.*ide:.*'))
}

exclude('META-INF/INDEX.LIST', 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA', 'schema/*',
'.options', '.api_description', '*.profile', '*.html', 'about.*', 'about_files/*', 'ant_tasks/*',
'plugin.xml', 'modeling32.png', 'xtext32.png', 'systembundle.properties', 'profile.list')

transform(com.github.jengelman.gradle.plugins.shadow.transformers.AppendingTransformer){
resource = 'plugin.properties'
}
}

compileJava {
options.compilerArgs << '-Xlint:unchecked'
}
}

generateLanguageServer.finalizedBy shadowJar

task testJar(type: ShadowJar) {
mainClassName = "org.eclipse.xtext.ide.server.ServerLauncher"
//minimize() // Minimizing might cause problems because it could delete classes that are not referenced but loaded by name (service loader)
from(project.convention.getPlugin(JavaPluginConvention).sourceSets.main.output)
configurations = [project.configurations.runtime]
exclude('META-INF/INDEX.LIST', 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA','schema/*',
'.options', '.api_description', '*.profile', '*.html', 'about.*', 'about_files/*',
'plugin.xml', 'modeling32.png', 'systembundle.properties', 'profile.list')
classifier = 'ls'
append('plugin.properties')
}
11 changes: 0 additions & 11 deletions org.lflang.lds/.project

This file was deleted.

Loading