diff --git a/playground/eclipse/c/exLibC/src/exLibC.cpp b/playground/eclipse/c/exLibC/src/exLibC.cpp new file mode 100644 index 00000000..b8720ebe --- /dev/null +++ b/playground/eclipse/c/exLibC/src/exLibC.cpp @@ -0,0 +1,13 @@ +#include +#include + +#include + +int check_smaller(int value) { + if (value < HELLO_LIMIT) { + return 0; + } else { + return -1; + } +} + diff --git a/playground/eclipse/c/exLibC/src/include/pkg1/exLibC/exLibC.hpp b/playground/eclipse/c/exLibC/src/include/pkg1/exLibC/exLibC.hpp new file mode 100644 index 00000000..81a1256d --- /dev/null +++ b/playground/eclipse/c/exLibC/src/include/pkg1/exLibC/exLibC.hpp @@ -0,0 +1,4 @@ + +#define HELLO_LIMIT 5 + +int check_smaller(int value); diff --git a/playground/eclipse/c/exProgLinkedC/src/exProgLinkedC.cpp b/playground/eclipse/c/exProgLinkedC/src/exProgLinkedC.cpp new file mode 100644 index 00000000..86dae58c --- /dev/null +++ b/playground/eclipse/c/exProgLinkedC/src/exProgLinkedC.cpp @@ -0,0 +1,16 @@ +#include +#include + +#include + +int main(int argc, char *argv[]) { + printf("Hello world!\n"); + if (argc < 2) { + printf("Too few parameters passed!\n"); + } else { + int val=atoi(argv[1]); + printf("Result is: %d\n",check_smaller(val)); + } + + return 0; +} diff --git a/playground/eclipse/c/wscript b/playground/eclipse/c/wscript new file mode 100644 index 00000000..dbdce20b --- /dev/null +++ b/playground/eclipse/c/wscript @@ -0,0 +1,16 @@ +#! /usr/bin/env python +# encoding: utf-8 + +def options(opt): + # We are using C++ + opt.load('compiler_cxx') + +def configure(conf): + # We are using C++ + conf.load('compiler_cxx') + +def build(bld): + bld.shlib(source='exLibC/src/exLibC.cpp', includes='exLibC/src/include', target='exampleLibC', export_includes='exLibC/src/include/') + bld.program(source=bld.path.ant_glob('exProgLinkedC/src/*.cpp'), target='exampleProgLinkedC', use='exampleLibC') + + diff --git a/playground/eclipse/java/animals/junit/org/example/AnimalTest.java b/playground/eclipse/java/animals/junit/org/example/AnimalTest.java new file mode 100644 index 00000000..64c7a85a --- /dev/null +++ b/playground/eclipse/java/animals/junit/org/example/AnimalTest.java @@ -0,0 +1,13 @@ +package org.example; + +import junit.framework.TestCase; + +public class AnimalTest extends TestCase { + public AnimalTest() { + } + + public void testAnimal() { + System.out.println("Test run successfully!"); + } +} + diff --git a/playground/eclipse/java/animals/manifest b/playground/eclipse/java/animals/manifest new file mode 100644 index 00000000..c6488124 --- /dev/null +++ b/playground/eclipse/java/animals/manifest @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Created-By: Waf 1.6.2 (rev >= 10780) + diff --git a/playground/eclipse/java/animals/src/org/example/Animal.java b/playground/eclipse/java/animals/src/org/example/Animal.java new file mode 100644 index 00000000..c6e7b92c --- /dev/null +++ b/playground/eclipse/java/animals/src/org/example/Animal.java @@ -0,0 +1,9 @@ +package org.example; + +class Animal { + + public String sound() { + return null; + } + +} diff --git a/playground/eclipse/java/animals/wscript b/playground/eclipse/java/animals/wscript new file mode 100644 index 00000000..159f3874 --- /dev/null +++ b/playground/eclipse/java/animals/wscript @@ -0,0 +1,28 @@ +#! /usr/bin/env python + +def build(bld): + + t = bld( + features = 'javac jar', + name = 'animals', + + # javac + srcdir = 'src', + compat = '1.7', + + # jar + basedir = '.', + destfile = '../animals.jar', + manifest = 'manifest', + use = 'NNN', + ) + t.env.JAVACFLAGS = ['-Xlint:unchecked'] + + if bld.env.DO_JUNIT: + t.features += ' junit' + t.srcdir = 'src junit' + t.junitsrc = 'junit' + t.junitclasspath = '.' + t.use += ' JUNIT' + t.env.JUNIT_EXEC_FLAGS = ['-ea'] + diff --git a/playground/eclipse/java/cats/src/org/example/Cat.java b/playground/eclipse/java/cats/src/org/example/Cat.java new file mode 100644 index 00000000..bf937dc9 --- /dev/null +++ b/playground/eclipse/java/cats/src/org/example/Cat.java @@ -0,0 +1,14 @@ + +package org.example; + +import org.example.Animal; + +class Cat extends Animal { + + public String sound() { + return "Meow!"; + } + + +} + diff --git a/playground/eclipse/java/cats/wscript b/playground/eclipse/java/cats/wscript new file mode 100644 index 00000000..5a9bdbfc --- /dev/null +++ b/playground/eclipse/java/cats/wscript @@ -0,0 +1,18 @@ +#! /usr/bin/env python + +def build(bld): + + bld(features = 'javac', + srcdir = 'src', + compat = '1.7', + use = 'animals', + name = 'cats-src', + ) + + bld(features = 'jar', + basedir = '.', + destfile = '../cats.jar', + name = 'cats', + use = 'cats-src' + ) + diff --git a/playground/eclipse/java/junit.py b/playground/eclipse/java/junit.py new file mode 100644 index 00000000..4a271e51 --- /dev/null +++ b/playground/eclipse/java/junit.py @@ -0,0 +1,85 @@ +#! /usr/bin/env python +# encoding: utf-8 + +""" +JUnit test system + + - executes all junit tests in the specified subtree (junitsrc) + - only if --junit is given on the commandline + - method: + - add task to compile junitsrc after compiling srcdir + - additional junit_classpath specifiable + - defaults to classpath + destdir + - add task to run junit tests after they're compiled. +""" + +import os +from waflib import Task, TaskGen, Utils, Options +from waflib.TaskGen import feature, before, after +from waflib.Configure import conf + +JUNIT_RUNNER = 'org.junit.runner.JUnitCore' + +def options(opt): + opt.add_option('--junit', action='store_true', default=False, + help='Run all junit tests', dest='junit') + opt.add_option('--junitpath', action='store', default='', + help='Give a path to the junit jar') + +def configure(ctx): + cp = ctx.options.junitpath + val = ctx.env.JUNIT_RUNNER = ctx.env.JUNIT_RUNNER or JUNIT_RUNNER + if ctx.check_java_class(val, with_classpath=cp): + ctx.fatal('Could not run junit from %r' % val) + ctx.env.CLASSPATH_JUNIT = cp + +#@feature('junit') +#@after('apply_java', 'use_javac_files') +def make_test(self): + """make the unit test task""" + if not getattr(self, 'junitsrc', None): + return + junit_task = self.create_task('junit_test') + try: + junit_task.set_run_after(self.javac_task) + except AttributeError: + pass +feature('junit')(make_test) +after('apply_java', 'use_javac_files')(make_test) + +class junit_test(Task.Task): + color = 'YELLOW' + vars = ['JUNIT_EXEC_FLAGS', 'JUNIT_RUNNER'] + + def runnable_status(self): + """ + Only run if --junit was set as an option + """ + for t in self.run_after: + if not t.hasrun: + return Task.ASK_LATER + + n = self.generator.path.find_dir(self.generator.junitsrc) + if not n: + self.generator.bld.fatal('no such junit directory %r' % self.generator.junitsrc) + self.base = n + + # make sure the tests are executed whenever the .class files change + self.inputs = n.ant_glob('**/*.java') + + ret = super(junit_test, self).runnable_status() + if ret == Task.SKIP_ME: + if getattr(Options.options, 'junit', False): + ret = Task.RUN_ME + return ret + + def run(self): + cmd = [] + cmd.extend(self.env.JAVA) + cmd.append('-classpath') + cmd.append(self.generator.javac_task.env.CLASSPATH + os.pathsep + self.generator.javac_task.env.OUTDIR) + cmd.extend(self.env.JUNIT_EXEC_FLAGS) + cmd.append(self.env.JUNIT_RUNNER) + cmd.extend([x.path_from(self.base).replace('.java', '').replace(os.sep, '.') for x in self.inputs]) + return self.exec_command(cmd) + diff --git a/playground/eclipse/java/src/com/meow/Hello.java b/playground/eclipse/java/src/com/meow/Hello.java new file mode 100644 index 00000000..f685ac58 --- /dev/null +++ b/playground/eclipse/java/src/com/meow/Hello.java @@ -0,0 +1,34 @@ +package com.meow; // obligatory + +public class Hello +{ + int m_var = 0; + public Hello() + { + this.m_var = 2; + } + + class MyHelperClass + { + MyHelperClass() { } + int someHelperMethod(int z, int q) { return 2; } + } + + public Object makeObj(String name) + { + final String objName = "My name is " + name; + + return new Object() { + public String toString() + { + return objName; + } + }; + } + + public static void main(String args[]) + { + System.out.println("Hello, world"); + } +} + diff --git a/playground/eclipse/java/src/com/meow/package-info.java b/playground/eclipse/java/src/com/meow/package-info.java new file mode 100644 index 00000000..116cfb49 --- /dev/null +++ b/playground/eclipse/java/src/com/meow/package-info.java @@ -0,0 +1,2 @@ +package com.meow; + diff --git a/playground/eclipse/java/src/com/meow/truc/bar/Hello.java b/playground/eclipse/java/src/com/meow/truc/bar/Hello.java new file mode 100644 index 00000000..61af11cf --- /dev/null +++ b/playground/eclipse/java/src/com/meow/truc/bar/Hello.java @@ -0,0 +1,34 @@ +package com.meow.truc.bar; // obligatory + +public class Hello +{ + int m_var = 0; + public Hello() + { + this.m_var = 2; + } + + class MyHelperClass + { + MyHelperClass() { } + int someHelperMethod(int z, int q) { return 2; } + } + + public Object makeObj(String name) + { + final String objName = "My name is " + name; + + return new Object() { + public String toString() + { + return objName; + } + }; + } + + public static void main(String args[]) + { + System.out.println("Hello, world"); + } +} + diff --git a/playground/eclipse/java/src/com/meow/truc/foo/Hello.java b/playground/eclipse/java/src/com/meow/truc/foo/Hello.java new file mode 100644 index 00000000..ab45d8c7 --- /dev/null +++ b/playground/eclipse/java/src/com/meow/truc/foo/Hello.java @@ -0,0 +1,34 @@ +package com.meow.truc.foo; // obligatory + +public class Hello +{ + int m_var = 0; + public Hello() + { + this.m_var = 2; + } + + class MyHelperClass + { + MyHelperClass() { } + int someHelperMethod(int z, int q) { return 2; } + } + + public Object makeObj(String name) + { + final String objName = "My name is " + name; + + return new Object() { + public String toString() + { + return objName; + } + }; + } + + public static void main(String args[]) + { + System.out.println("Hello, world"); + } +} + diff --git a/playground/eclipse/java/sup/org/test/Hella.java b/playground/eclipse/java/sup/org/test/Hella.java new file mode 100644 index 00000000..08dcd1c6 --- /dev/null +++ b/playground/eclipse/java/sup/org/test/Hella.java @@ -0,0 +1,10 @@ +package org.test; // obligatory + +public class Hella +{ + public static void main(String args[]) + { + System.out.println("Hella, world"); + } +} + diff --git a/playground/eclipse/java/wscript b/playground/eclipse/java/wscript new file mode 100644 index 00000000..701d1fd6 --- /dev/null +++ b/playground/eclipse/java/wscript @@ -0,0 +1,56 @@ +#! /usr/bin/env python +# encoding: utf-8 +# Thomas Nagy, 2006-2010 (ita) + +""" +java example + +The gcj compiler has a very different command-line - see playground/gcj +""" + +VERSION = '0.0.4' +APPNAME = 'java_test' + +top = '.' +out = 'build' + +def options(opt): + try: + opt.load('junit', tooldir='.') + except: + pass + +def configure(conf): + conf.load('java') + + try: + ret = conf.load('junit', tooldir='.') + conf.env.DO_JUNIT = True + except: + pass + + conf.check_java_class('java.io.FileOutputStream') + conf.check_java_class('FakeClass') + + conf.env.CLASSPATH_NNN = ['aaaa.jar', 'bbbb.jar'] + +def build(bld): + + bld(features = 'javac jar javadoc', + srcdir = 'src/', # folder containing the sources to compile + outdir = 'src', # folder where to output the classes (in the build directory) + compat = '1.6', # java compatibility version number + sourcepath = ['src', 'sup'], + classpath = ['.', '..'], + #jaropts = '-C default/src/ .', # can be used to give files + basedir = 'src', # folder containing the classes and other files to package (must match outdir) + destfile = 'foo.jar', # do not put the destfile in the folder of the java classes! + use = 'NNN', + + # javadoc + javadoc_package = ['com.meow' , 'com.meow.truc.bar', 'com.meow.truc.foo'], + javadoc_output = 'javadoc', + ) + + bld.recurse('animals cats') + diff --git a/playground/eclipse/python/mod1/src/mod1/Mod1ObjOri.py b/playground/eclipse/python/mod1/src/mod1/Mod1ObjOri.py new file mode 100644 index 00000000..9c4ffdf9 --- /dev/null +++ b/playground/eclipse/python/mod1/src/mod1/Mod1ObjOri.py @@ -0,0 +1,30 @@ + +""" +Class mod1 for tests + +Doctest examples: + +>>> a = Mod1Class("pippo") +>>> a.getMyName() +'pippo from obj1 _init_' + +>>> a = Mod1Class("pLuTo") +>>> a.getMyName() +'pLuTo from obj1 _init_' + +""" + +class Mod1Class(object): + + def __init__(self, pName): + """ + Constructor stores pName in myName and appends the class string marker + """ + self.val = 1 + self.myName = pName + " from obj1 _init_" + + def getMyName(self): + """ + getMyName in Mod1Class returns the name as is + """ + return self.myName diff --git a/playground/eclipse/python/mod1/src/mod1/__init__.py b/playground/eclipse/python/mod1/src/mod1/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/playground/eclipse/python/mod2/src/mod2/Mod2ObjOri.py b/playground/eclipse/python/mod2/src/mod2/Mod2ObjOri.py new file mode 100644 index 00000000..aeb2ad78 --- /dev/null +++ b/playground/eclipse/python/mod2/src/mod2/Mod2ObjOri.py @@ -0,0 +1,13 @@ + + +class Mod2Class(object): + def __init__(self, pName): + self.myName = pName + " from obj2 _init_" + self.testVal = 2 + + def getMyName(self): + """ + getMyName in Mod2Class returns the name all uppercase + """ + + return self.myName.upper() diff --git a/playground/eclipse/python/mod2/src/mod2/__init__.py b/playground/eclipse/python/mod2/src/mod2/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/playground/eclipse/python/mod3/src/mod3/Mod3ObjOri.py b/playground/eclipse/python/mod3/src/mod3/Mod3ObjOri.py new file mode 100644 index 00000000..ea213550 --- /dev/null +++ b/playground/eclipse/python/mod3/src/mod3/Mod3ObjOri.py @@ -0,0 +1,11 @@ + + +import mod2.Mod2ObjOri + +class Mod3Class(mod2.Mod2ObjOri.Mod2Class): + + def getMyName(self): + """ + getMyName in Mod3Class returns the name all lowercase + """ + return self.myName.lower() diff --git a/playground/eclipse/python/mod3/src/mod3/__init__.py b/playground/eclipse/python/mod3/src/mod3/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/playground/eclipse/python/prg/src/prg1.py b/playground/eclipse/python/prg/src/prg1.py new file mode 100644 index 00000000..65798c5c --- /dev/null +++ b/playground/eclipse/python/prg/src/prg1.py @@ -0,0 +1,24 @@ +#! /usr/bin/env python +# encoding: utf-8 + +import mod1.Mod1ObjOri +import mod2.Mod2ObjOri +import mod3.Mod3ObjOri + + +if __name__ == '__main__': + print("Creating obj1 with string pippo") + obj1 = mod1.Mod1ObjOri.Mod1Class("pippo") + + a = 1 + + print("Creating obj1 with string pLUto") + obj2 = mod2.Mod2ObjOri.Mod2Class("pLUto") + + print("Creating obj3 with string pLUto") + obj3 = mod3.Mod3ObjOri.Mod3Class("pLUto") + + print("Hello World, this are my results:") + print(obj1.getMyName()) + print(obj2.getMyName()) + print(obj3.getMyName()) diff --git a/playground/eclipse/python/wscript b/playground/eclipse/python/wscript new file mode 100644 index 00000000..232fa756 --- /dev/null +++ b/playground/eclipse/python/wscript @@ -0,0 +1,19 @@ +#! /usr/bin/env python +# encoding: utf-8 + + +def options(opt): + opt.load('python') + +def configure(conf): + conf.load('python') + conf.check_python_version(minver=(2, 7, 0)) + + +def build(bld): + bld(name='mod1', features='py', source=bld.path.ant_glob('mod1/src/**/*.py'), install_from='mod1/src') + bld(name='mod2', features='py', source=bld.path.ant_glob('mod2/src/**/*.py'), install_from='mod2/src') + bld(name='mod3', features='py', source=bld.path.ant_glob('mod3/src/**/*.py'), install_from='mod3/src') + + # Example program with module dependencies + bld(name='prg', features='py', source=bld.path.ant_glob('prg/src/**/*.py'), install_from='prg/src', use='mod1 mod2 mod3') diff --git a/playground/eclipse/wscript b/playground/eclipse/wscript new file mode 100644 index 00000000..f603c387 --- /dev/null +++ b/playground/eclipse/wscript @@ -0,0 +1,56 @@ +#! /usr/bin/env python +# encoding: utf-8 +# Federico Pellegrin 2017 (fedepell) + +""" +Example source tree to be used with eclipse extra. + +First of all load the extra: + +... +def options(opt): + opt.load('eclipse') + +def configure(conf): + conf.load('eclipse') +... + +Then after configuring the project you can anytime run: + +waf eclipse + +This will generate the needed configuration files for Eclipse: +-) .project is generic Eclipse project file +-) .cproject for C/C++ CDT +-) .classpath for Java JDT +-) .pydevproject for Pydev) + +The example contains three directories with different supported languages +to demonstrate the features working for each of them, most importantly the +automatic addition of search paths for each language so referencing objects +or files in the IDE is done correctly. This is equivalent to configure +Eclipse by hand using Project->Properties and then each language menu. + +Also the generic invocation for building and cleaning are redefined so +waf is called correctly when the respective actions are requested. +""" + + +module_list = 'c java python' +out = 'build' + +def options(opt): + opt.load('eclipse') + # We recurse options in our submodules + opt.recurse(module_list) + + +def configure(conf): + conf.load('eclipse') + # We recurse configurations in our submodules + conf.recurse(module_list) + + +def build(bld): + bld.recurse(module_list) +