Skip to content
Open
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
16 changes: 16 additions & 0 deletions scanpipe/pipelines/deploy_to_develop.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ def steps(cls):
cls.find_grammar_packages,
cls.map_grammar_to_class,
cls.map_jar_to_grammar_source,
cls.find_xtend_packages,
cls.map_xtend_to_class,
cls.map_javascript,
cls.map_javascript_symbols,
cls.map_javascript_strings,
Expand Down Expand Up @@ -259,6 +261,20 @@ def map_jar_to_grammar_source(self):
project=self.project, jvm_lang=jvm.GrammarLanguage, logger=self.log
)

@optional_step("Xtend")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should extend be an optional step or be part of all JVM based languages like Scala, Java and Kotlin ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aren't the code for Java, Scala and Koltin also treat as an optional step


@optional_step("Scala")

@optional_step("Kotlin")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, they are. Coz they all are independent of each other. We won't run the same thing for Scala that we are running for Java. But if we are running same things then it wouldn't have been a separate optional step.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the background.

Xtend is a flexible and expressive dialect of Java (https://eclipse.dev/Xtext/xtend/)
It compiles .xtend files into readable .java source code, which is then compiled into JVM bytecode (.class files).
Xtend uses a source-to-source compiler, meaning it translates Xtend code into Java before passing it to a standard Java compiler.

There are couple ways to compile .xtend such as

Maven

mvn compile

OR

Gradle

gradle build

Xtend plugin will generate .java files for the above

OR

Eclipse IDE

Just save the .xtend file (Eclipse automatically generates the corresponding .java file)

def find_xtend_packages(self):
"""Find the java package of the xtend source files."""
d2d.find_jvm_packages(
project=self.project, jvm_lang=jvm.XtendLanguage, logger=self.log
)

@optional_step("Xtend")
def map_xtend_to_class(self):
"""Map a .class compiled file to its xtend source."""
d2d.map_jvm_to_class(
project=self.project, jvm_lang=jvm.XtendLanguage, logger=self.log
)

@optional_step("JavaScript")
def map_javascript(self):
"""
Expand Down
9 changes: 9 additions & 0 deletions scanpipe/pipes/jvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,15 @@ class GrammarLanguage(JvmLanguage):
binary_map_type = "grammar_to_class"


class XtendLanguage(JvmLanguage):
name = "xtend"
source_extensions = (".xtend",)
binary_extensions = (".class",)
source_package_attribute_name = "xtend_package"
package_regex = re.compile(r"^\s*package\s+([\w\.]+)\s*;?")
binary_map_type = "xtend_to_class"


def get_fully_qualified_path(jvm_package, filename):
"""
Return a fully qualified path of a ``filename`` in a
Expand Down
28 changes: 28 additions & 0 deletions scanpipe/tests/pipes/test_d2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,34 @@ def test_scanpipe_pipes_d2d_map_grammar_to_class(self):
expected = {"from_source_root": "from/antlr4-4.5.1-beta-1/tool/src/"}
self.assertEqual(expected, r1.extra_data)

def test_scanpipe_pipes_d2d_map_xtend_to_class(self):
from1 = make_resource_file(
self.project1,
path="from/org.openhab.binding.urtsi/src/main/java/org/openhab/"
+ "binding/urtsi/internal/UrtsiDevice.xtend",
extra_data={"xtend_package": "org.openhab.binding.urtsi.internal"},
)

to1 = make_resource_file(
self.project1,
path="to/org.openhab.binding.urtsi-1.6.2.jar-extract/org/"
+ "openhab/binding/urtsi/internal/UrtsiDevice.class",
)

buffer = io.StringIO()
d2d.map_jvm_to_class(
self.project1, logger=buffer.write, jvm_lang=jvm.XtendLanguage
)

expected = "Mapping 1 .class resources to 1 ('.xtend',)"
self.assertIn(expected, buffer.getvalue())
self.assertEqual(1, self.project1.codebaserelations.count())

r1 = self.project1.codebaserelations.get(to_resource=to1, from_resource=from1)
self.assertEqual("xtend_to_class", r1.map_type)
expected = {"from_source_root": "from/org.openhab.binding.urtsi/src/main/java/"}
self.assertEqual(expected, r1.extra_data)

def test_scanpipe_pipes_d2d_map_java_to_class_no_java(self):
make_resource_file(self.project1, path="to/Abstract.class")
buffer = io.StringIO()
Expand Down
Loading