nit.git
7 years agorta: drop local `is_valid_type` and use `is_legal_in` from `model`
Jean Privat [Tue, 9 Aug 2016 15:19:21 +0000 (11:19 -0400)]
rta: drop local `is_valid_type` and use `is_legal_in` from `model`

Signed-off-by: Jean Privat <jean@pryen.org>

7 years agomodel: add `MType::is_legal_in` to check the legality of a given complex type
Jean Privat [Tue, 9 Aug 2016 15:17:53 +0000 (11:17 -0400)]
model: add `MType::is_legal_in` to check the legality of a given complex type

Signed-off-by: Jean Privat <jean@pryen.org>

7 years agomodel: returns more MErrorType instead of aborting
Jean Privat [Tue, 9 Aug 2016 15:16:08 +0000 (11:16 -0400)]
model: returns more MErrorType instead of aborting

Signed-off-by: Jean Privat <jean@pryen.org>

7 years agomodel: add MType::is_ok to check MErrorType in depth
Jean Privat [Tue, 9 Aug 2016 15:15:21 +0000 (11:15 -0400)]
model: add MType::is_ok to check MErrorType in depth

Signed-off-by: Jean Privat <jean@pryen.org>

7 years agomodel: new class MErrorType as using MBottomType was abuse
Jean Privat [Tue, 9 Aug 2016 15:13:28 +0000 (11:13 -0400)]
model: new class MErrorType as using MBottomType was abuse

Signed-off-by: Jean Privat <jean@pryen.org>

7 years agoMerge: Faster lookup
Jean Privat [Tue, 9 Aug 2016 01:18:27 +0000 (21:18 -0400)]
Merge: Faster lookup

This series improves the lookup strategies:

* special fast track for the virtual type SELF
* choose to iterate on the mclassdefs instead of the mpropdefs if they are less numerous.

This mainly limit the degenerative cases that where discovered while investigating the slowdown of #2223

with nitc/nitc/nitc:
before: 0m7.168s
after: 0m6.232s

with nitpick ../contrib:
before: 0m20.928s
after: 0m19.432s

Pull-Request: #2245
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>

7 years agoMerge: popcorn: enhance ConsoleLog
Jean Privat [Tue, 9 Aug 2016 01:17:58 +0000 (21:17 -0400)]
Merge: popcorn: enhance ConsoleLog

Add some logger capabilities to ConsoleLog so it can be shared with the rest of the popcorn app as a classic logger.

Pull-Request: #2244
Reviewed-by: Jean Privat <jean@pryen.org>

7 years agoMerge: Popcorn auth
Jean Privat [Tue, 9 Aug 2016 01:17:55 +0000 (21:17 -0400)]
Merge: Popcorn auth

## Authentification handlers.

For now, only Github OAuth is provided.

### Github

See https://developer.github.com/v3/oauth/.

This module provide 4 base classes that can be used to implement a Github
OAuth handshake.

~~~nit
import popcorn
import popcorn::pop_auth

var client_id = "github client id"
var client_secret = "github client secret"

var app = new App
app.use("/login", new GithubLogin(client_id))
app.use("/oauth", new GithubOAuthCallBack(client_id, client_secret))
app.use("/logout", new GithubLogout)
app.listen("localhost", 3000)
~~~

Optionaly, you can use the `GithubUser` handler to provide access to the
Github user stored in session:

~~~nit
app.use("/api/user", new GithubUser)
~~~

Pull-Request: #2238
Reviewed-by: Jean Privat <jean@pryen.org>

7 years agorta: fast fix to avoid resolving illegal types.
Jean Privat [Tue, 9 Aug 2016 00:44:00 +0000 (20:44 -0400)]
rta: fast fix to avoid resolving illegal types.

This requires a more in-depth work to improve the model.
Another improvement can also to teach RTA the context of object mechanism
so that only legal receivers are attempted.

Signed-off-by: Jean Privat <jean@pryen.org>

7 years agoMerge: lib/github: introduce GithubWallet
Jean Privat [Mon, 8 Aug 2016 22:24:05 +0000 (18:24 -0400)]
Merge: lib/github: introduce GithubWallet

## Github OAuth tokens management

When using batch mode with the `github` API, we can rapidly reach the rate
limit allowed by Github.

One solution consists in using a wallet of tokens so we can rely on more than
one token and switch them when one become exhausted.

### Using the Github wallet to check tokens

One functionality of the wallet is to check the validity of a token against
the API. `check_token` will return false if a token is invalid or exhausted.

~~~nit
var wallet = new GithubWallet
assert not wallet.check_token("this is a bad token")
~~~

### Storing tokens

The wallet can also be used to store tokens and check all of them.

~~~nit
wallet = new GithubWallet
wallet.add "some token"
wallet.add "some other token"
~~~

or

~~~nit
wallet = new GithubWallet.from_tokens(["token 1", "token 2"])
~~~

The `show_status` method can be used to display a summary of the validity of
each token in the wallet.

~~~nit
wallet.show_status
~~~

Will display something like this:

~~~raw
Wallet (2 tokens):
 * [OK] token 1
 * [KO] token 2
~~~

### Using the wallet to obtain a Github API client

Using the wallet you can cycle through tokens and obtain a new Github API client
instance with a fresh rate limit.

~~~nit
wallet = new GithubWallet.from_tokens(["token 1", "token 2"])
var api = wallet.api
~~~

The wallet will automatically cycle through the registered tokens to find one
that works.

To avoid infinite loop, if not valid token is found after all of them was tried,
the wallet returns an client based on the last tried token.

Pull-Request: #2243
Reviewed-by: Jean Privat <jean@pryen.org>

7 years agoMerge: gamnit: intro pinch to zoom gesture for Android
Jean Privat [Mon, 8 Aug 2016 22:24:03 +0000 (18:24 -0400)]
Merge: gamnit: intro pinch to zoom gesture for Android

Intro a service to manipulate the perspective cameras with two fingers gestures: move the camera and the classic pinch to zoom.

This feature mainly targets the `flat` API. It should also somewhat work with `depth`,  even when the camera looks around, but the fingers won't fit precisely with a world object/layer.

Pull-Request: #2242
Reviewed-by: Jean Privat <jean@pryen.org>

7 years agoMerge: Popcorn repos
Jean Privat [Mon, 8 Aug 2016 22:23:52 +0000 (18:23 -0400)]
Merge: Popcorn repos

## Repositories for data management.

 Repositories are used to apply persistence on instances (or **documents**).
 Using repositories one can store and retrieve instance in a clean and maintenable
 way.

 This module provides the base interface `Repository` that defines the persistence
 services available in all kind of repos.
 `JsonRepository` factorizes all repositories dedicated to Json data or objects
 serializable to Json.

 `MongoRepository` is provided as a concrete example of repository.
 It implements all the services from `Repository` using a Mongo database as backend.

 Repositories can be used in Popcorn app to manage your data persistence.
 Here an example with a book management app:

 ~~~nit
 # First we declare the `Book` class. It has to be serializable so it can be used
 # within a `Repository`.

 import popcorn
 import popcorn::pop_repos

 # Serializable book representation.
 class Book
serialize
super Jsonable

# Book uniq ID
var id: String = (new MongoObjectId).id is serialize_as "_id"

# Book title
var title: String

# ... Other fields

redef fun to_s do return title
redef fun ==(o) do return o isa SELF and id == o.id
redef fun hash do return id.hash
redef fun to_json do return serialize_to_json
 end

 # We then need to subclass the `MongoRepository` to provide Book specific services.

 # Book repository for Mongo
 class BookRepo
super MongoRepository[Book]

# Find books by title
fun find_by_title(title: String): Array[Book] do
var q = new JsonObject
q["title"] = title
return find_all(q)
end
 end

 # The repository can be used in a Handler to manage book in a REST API.

 class BookHandler
super Handler

var repo: BookRepo

# Return a json array of all books
#
# If the get parameters `title` is provided, returns a json array of books
# matching the `title`.
redef fun get(req, res) do
var title = req.string_arg("title")
if title == null then
res.json new JsonArray.from(repo.find_all)
else
res.json new JsonArray.from(repo.find_by_title(title))
end
end

# Insert a new Book
redef fun post(req, res) do
var title = req.string_arg("title")
if title == null then
res.error 400
return
end
var book = new Book(title)
repo.save book
res.json book
end
 end

 # Let's wrap it all together in a Popcorn app:

 # Init database
 var mongo = new MongoClient("mongodb://localhost:27017/")
 var db = mongo.database("tests_app_{100000.rand}")
 var coll = db.collection("books")

 # Init app
 var app = new App
 var repo = new BookRepo(coll)
 app.use("/books", new BookHandler(repo))
 app.listen("localhost", 3000)
 ~~~

Pull-Request: #2241
Reviewed-by: Jean Privat <jean@pryen.org>

7 years agoMerge: Popcorn valid
Jean Privat [Mon, 8 Aug 2016 22:23:50 +0000 (18:23 -0400)]
Merge: Popcorn valid

## Quick and easy validation framework for Json inputs

Validators can be used in Popcorn apps to valid your json inputs before
data processing and persistence.

Here an example with a Book management app. We use an ObjectValidator to validate
the books passed to the API in the `POST /books` handler.

~~~nit
import popcorn
import serialization

# Serializable book representation.
class Book
super Jsonable

# Book ISBN
var isbn: String

# Book title
var title: String

# Book image (optional)
var img: nullable String

# Book price
var price: Float
 end

 class BookValidator
super ObjectValidator

redef init do
add new ISBNField("isbn")
add new StringField("title", min_size=1, max_size=255)
add new StringField("img", required=false)
add new FloatField("price", min=0.0, max=999.0)
end
 end

 class BookHandler
super Handler

# Insert a new Book
redef fun post(req, res) do
var validator = new BookValidator
if not validator.validate(req.body) then
res.json_error(validator.validation, 400)
return
end
# TODO data persistence
end
 end
 ~~~

Pull-Request: #2240
Reviewed-by: Jean Privat <jean@pryen.org>

7 years agoMerge: lib/popcorn: introduce `pop_config` module
Jean Privat [Mon, 8 Aug 2016 22:23:47 +0000 (18:23 -0400)]
Merge: lib/popcorn: introduce `pop_config` module

## Configuration file and options for Popcorn apps

`pop_config` provide a configuration framework for Popcorn apps based on ini
files.

By default `AppConfig` provides `app.host` and `app.port` keys, it's all we
need to start an app:

~~~nit
import popcorn
import popcorn::pop_config

# Parse app options
var opts = new AppOptions.from_args(args)

# Build config from options
var config = new AppConfig.from_options(opts)

# Use options
var app = new App
app.listen(config.app_host, config.app_port)
~~~

For more advanced uses, `AppConfig` and `AppOptions` can be specialized to
offer additional config options:

~~~nit
import popcorn
import popcorn::pop_config

class MyConfig
super AppConfig

# My secret code I don't want to share in my source repository
var secret: String = value_or_default("secret", "my-secret")

redef init from_options(options) do
super
if options isa MyOptions then
var secret = options.opt_secret.value
if secret != null then self["secret"] = secret
end
end
 end

 class MyOptions
super AppOptions

var opt_secret = new OptionString("My secret string", "--secret")

redef init do
super
add_option opt_secret
end
 end

 class SecretHandler
super Handler

# Config to use to access `secret`
var config: MyConfig

redef fun get(req, res) do
res.send config.secret
end
 end

 var opts = new MyOptions.from_args(args)
 var config = new MyConfig.from_options(opts)

 var app = new App
 app.use("/secret", new SecretHandler(config))
 app.listen(config.app_host, config.app_port)
 ~~~

Pull-Request: #2239
Reviewed-by: Jean Privat <jean@pryen.org>

7 years agoMerge: Serialization fixes and hardening
Jean Privat [Mon, 8 Aug 2016 22:23:42 +0000 (18:23 -0400)]
Merge: Serialization fixes and hardening

Improve the serialization services on multiple points:

* Fix JSON serialization of `DefaultMap` by writing its attributes. (Not only the "special" length, keys and values)
* Remove type casts and the like that would crash the program on invalid format of collections and maps, raise errors instead and return an empty instance.
* Improve (from horrible to bad) the type name used in deserialization errors when the type of an attribute is not in the AST. (This is pretty much the best we can do without moving the serialization phase after the model has been built.)
* Fix a test which failed on silent errors, and print errors so it doesn't happen again. Note that the errors with nitce are expected as it doesn't have the same `class_name` than the other engines.
* Update nitserial to silence `property-conflict` warnings in the generated module. This effectively hides the conflicts between the JSON and binary serialization because all conflicts are on generic types.

Pull-Request: #2234
Reviewed-by: Jean Privat <jean@pryen.org>

7 years agoMerge: `mendel_metrics`: Fix documentation
Jean Privat [Mon, 8 Aug 2016 22:23:40 +0000 (18:23 -0400)]
Merge: `mendel_metrics`: Fix documentation

Some minor fixes for the documentation of the `mendel_metrics` module.

Pull-Request: #2230
Reviewed-by: Jean Privat <jean@pryen.org>
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>

7 years agotests: update sav of `test_binary_deserialization`
Alexis Laferrière [Mon, 8 Aug 2016 20:19:27 +0000 (16:19 -0400)]
tests: update sav of `test_binary_deserialization`

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

7 years agolib/popcorn: introduce Github Auth handlers
Alexandre Terrasa [Mon, 8 Aug 2016 19:45:18 +0000 (15:45 -0400)]
lib/popcorn: introduce Github Auth handlers

Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

7 years agogithub_api: load user from access_token
Alexandre Terrasa [Tue, 2 Aug 2016 17:39:28 +0000 (13:39 -0400)]
github_api: load user from access_token

Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

7 years agolib/popcorn: introduce `pop_config` module
Alexandre Terrasa [Mon, 8 Aug 2016 19:26:45 +0000 (15:26 -0400)]
lib/popcorn: introduce `pop_config` module

Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

7 years agomodel: MVirtualType fast resolution for the special type `SELF`
Jean Privat [Mon, 8 Aug 2016 17:39:00 +0000 (13:39 -0400)]
model: MVirtualType fast resolution for the special type `SELF`

Signed-off-by: Jean Privat <jean@pryen.org>

7 years agomodel: lookup_definitions gains an *iterate the classdefs* strategy
Jean Privat [Mon, 8 Aug 2016 17:37:18 +0000 (13:37 -0400)]
model: lookup_definitions gains an *iterate the classdefs* strategy

Signed-off-by: Jean Privat <jean@pryen.org>

7 years agomodel: MClassDef register property definitions by its associated property
Jean Privat [Mon, 8 Aug 2016 17:35:38 +0000 (13:35 -0400)]
model: MClassDef register property definitions by its associated property

Signed-off-by: Jean Privat <jean@pryen.org>

7 years agopopcorn: enhance ConsoleLog
Alexandre Terrasa [Mon, 8 Aug 2016 19:11:07 +0000 (15:11 -0400)]
popcorn: enhance ConsoleLog

Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

7 years agolib/github: introduce GithubWallet
Alexandre Terrasa [Mon, 8 Aug 2016 19:08:28 +0000 (15:08 -0400)]
lib/github: introduce GithubWallet

Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

7 years agolib/popcorn: introduce Repository concept
Alexandre Terrasa [Fri, 5 Aug 2016 17:56:13 +0000 (13:56 -0400)]
lib/popcorn: introduce Repository concept

Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

7 years agolib/mongodb: allow new MongoObjectId instances
Alexandre Terrasa [Mon, 8 Aug 2016 16:44:57 +0000 (12:44 -0400)]
lib/mongodb: allow new MongoObjectId instances

Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

7 years agoMerge: mongodb: wrap `Collection::aggregate` function
Jean Privat [Mon, 8 Aug 2016 14:35:10 +0000 (10:35 -0400)]
Merge: mongodb: wrap `Collection::aggregate` function

Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

Pull-Request: #2237
Reviewed-by: Jean Privat <jean@pryen.org>

7 years agoMerge: lib/popcorn: generalize colors for status codes
Jean Privat [Mon, 8 Aug 2016 14:35:08 +0000 (10:35 -0400)]
Merge: lib/popcorn: generalize colors for status codes

Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

Pull-Request: #2236
Reviewed-by: Jean Privat <jean@pryen.org>

7 years agoMerge: modelize_class: Force `Object` to be an interface
Jean Privat [Mon, 8 Aug 2016 14:35:03 +0000 (10:35 -0400)]
Merge: modelize_class: Force `Object` to be an interface

Signed-off-by: Jean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>

Pull-Request: #2235
Reviewed-by: Jean Privat <jean@pryen.org>

7 years agoMerge: modelize_class: Remove an unnecessary pre-condition
Jean Privat [Mon, 8 Aug 2016 14:35:00 +0000 (10:35 -0400)]
Merge: modelize_class: Remove an unnecessary pre-condition

`build_classes` calls itself recursively on imported modules. So, there is no point to specify that imported modules must be processed first.

Signed-off-by: Jean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>

Pull-Request: #2233
Reviewed-by: Jean Privat <jean@pryen.org>

7 years agoMerge: modelize_class: Remove a dead check
Jean Privat [Mon, 8 Aug 2016 14:34:56 +0000 (10:34 -0400)]
Merge: modelize_class: Remove a dead check

Dead at aa64312 (PR #2047).

Signed-off-by: Jean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>

Pull-Request: #2232
Reviewed-by: Jean Privat <jean@pryen.org>

7 years agogamnit: flat imports android_two_fingers_motion with android
Alexis Laferrière [Sun, 7 Aug 2016 16:41:47 +0000 (12:41 -0400)]
gamnit: flat imports android_two_fingers_motion with android

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

7 years agogamnit: intro two fingers motion service on EulerCamera
Alexis Laferrière [Sun, 7 Aug 2016 13:59:15 +0000 (09:59 -0400)]
gamnit: intro two fingers motion service on EulerCamera

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

7 years agolib/popcorn: generalize colors for status codes
Alexandre Terrasa [Fri, 5 Aug 2016 19:30:56 +0000 (15:30 -0400)]
lib/popcorn: generalize colors for status codes

Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

7 years agolib/popcorn: introduce Validation concept
Alexandre Terrasa [Thu, 4 Aug 2016 04:53:22 +0000 (00:53 -0400)]
lib/popcorn: introduce Validation concept

Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

7 years agolib/popcorn: add `json_error` to return a Json formatted error
Alexandre Terrasa [Thu, 4 Aug 2016 04:53:54 +0000 (00:53 -0400)]
lib/popcorn: add `json_error` to return a Json formatted error

Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

7 years agomodelize_class: Do not crash if `Pointer` is not defined
Jean-Christophe Beaupré [Thu, 4 Aug 2016 16:39:53 +0000 (12:39 -0400)]
modelize_class: Do not crash if `Pointer` is not defined

Signed-off-by: Jean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>

7 years agomodelize_class: Force `Object` to be an interface
Jean-Christophe Beaupré [Thu, 4 Aug 2016 16:38:53 +0000 (12:38 -0400)]
modelize_class: Force `Object` to be an interface

Signed-off-by: Jean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>

7 years agojson::serialization: report duplicated keys
Alexis Laferrière [Thu, 4 Aug 2016 16:33:55 +0000 (12:33 -0400)]
json::serialization: report duplicated keys

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

7 years agoAdd a test for the class kind of `Object`
Jean-Christophe Beaupré [Thu, 4 Aug 2016 16:32:56 +0000 (12:32 -0400)]
Add a test for the class kind of `Object`

Signed-off-by: Jean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>

7 years agotests: report deserialization errors
Alexis Laferrière [Thu, 4 Aug 2016 14:40:05 +0000 (10:40 -0400)]
tests: report deserialization errors

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

7 years agotests: fix deserialization test on pretty json with generics
Alexis Laferrière [Thu, 4 Aug 2016 14:39:52 +0000 (10:39 -0400)]
tests: fix deserialization test on pretty json with generics

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

7 years agonitserial: silence property-conflict warning in generated module
Alexis Laferrière [Thu, 4 Aug 2016 13:44:04 +0000 (09:44 -0400)]
nitserial: silence property-conflict warning in generated module

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

7 years agolib/gen_nit: support writing annotations of the module declaration
Alexis Laferrière [Thu, 4 Aug 2016 13:43:29 +0000 (09:43 -0400)]
lib/gen_nit: support writing annotations of the module declaration

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

7 years agojson::serialization: check format and consistency of Map at deserialization
Alexis Laferrière [Thu, 4 Aug 2016 14:21:08 +0000 (10:21 -0400)]
json::serialization: check format and consistency of Map at deserialization

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

7 years agojson::serialization: don't crash on deserializing malformed simple collections
Alexis Laferrière [Thu, 4 Aug 2016 14:20:42 +0000 (10:20 -0400)]
json::serialization: don't crash on deserializing malformed simple collections

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

7 years agojson::serialization: fix indentation
Alexis Laferrière [Thu, 4 Aug 2016 13:41:03 +0000 (09:41 -0400)]
json::serialization: fix indentation

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

7 years agojson::serialization: fix serializing extra attributes of collections and maps
Alexis Laferrière [Thu, 4 Aug 2016 13:38:49 +0000 (09:38 -0400)]
json::serialization: fix serializing extra attributes of collections and maps

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

7 years agojson::serialization: refactor some duplicated code
Alexis Laferrière [Thu, 4 Aug 2016 13:37:53 +0000 (09:37 -0400)]
json::serialization: refactor some duplicated code

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

7 years agofrontend: use a prettier "Unknown type" when the type is not in the AST
Alexis Laferrière [Thu, 4 Aug 2016 14:53:37 +0000 (10:53 -0400)]
frontend: use a prettier "Unknown type" when the type is not in the AST

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

7 years agoserialization: AttributeTypeError doesn't need the message attribute, fix TODO
Alexis Laferrière [Thu, 4 Aug 2016 14:22:34 +0000 (10:22 -0400)]
serialization: AttributeTypeError doesn't need the message attribute, fix TODO

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

7 years agofrontend: don't type check values for attributes typed with `nullable Object`
Alexis Laferrière [Thu, 4 Aug 2016 13:45:11 +0000 (09:45 -0400)]
frontend: don't type check values for attributes typed with `nullable Object`

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

7 years agoMerge: app.nit: improve apps life-cycle
Jean Privat [Wed, 3 Aug 2016 16:38:46 +0000 (12:38 -0400)]
Merge: app.nit: improve apps life-cycle

Modify the _app.nit_ life-cycle callbacks to add `on_restart`, and to remove `on_start` and `on_destroy`. `on_restart` is called when the app goes comes back from a `on_stop`. `on_start` duplicated other callbacks (`on_create` and the new `on_restart`), plus it didn't have a direct equivalent  in iOS. `on_destroy` also didn't have an iOS equivalent. These changes simplify the life-cycle and use only callbacks existing on both platforms.

This PR also improves the documentation of the _app.nit_ life-cycle with a nice little graph and references to the platform specific triggers.

Pull-Request: #2229
Reviewed-by: Ait younes Mehdi Adel <overpex@gmail.com>

7 years agoMerge: app.nit: Intro the `app_files` annotation, and use it in calculator
Jean Privat [Wed, 3 Aug 2016 16:38:43 +0000 (12:38 -0400)]
Merge: app.nit: Intro the `app_files` annotation, and use it in calculator

Intro `app_files`, an annotation to specify where to find more Android and iOS specific files. This effectively associates resources to a specific Nit module. It can be used to have different icons per branding, or to package graphical assets with a module from the lib.

It is used in the calculator to assign a different icon to the scientific calculator variant.

Pull-Request: #2228
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Reviewed-by: Romain Chanoir <romain.chanoir@viacesi.fr>

7 years agoMerge: Android: import the R class
Jean Privat [Wed, 3 Aug 2016 16:38:33 +0000 (12:38 -0400)]
Merge: Android: import the R class

The R class is generated by the Android toolchain and acts as a static way to identify resources in Java code. The ID of each values from the `android/res` folder is sorted in a category and accessible through a static field. An example of a generated R class is shown at the bottom of this description.

This PR import the R class in all Java classes generated from the Java FFI. This creates a similar effect as having the R class in the same package. Previously, the user could not reliably import the R class manually as the package name changes between the debug and release version.

~~~
/* AUTO-GENERATED FILE.  DO NOT MODIFY.
 *
 * This class was automatically generated by the
 * aapt tool from the resource data it found.  It
 * should not be modified by hand.
 */

package net.xymus.benitlux_debug;

public final class R {
    public static final class attr {
    }
    public static final class color {
        public static final int item_background=0x7f050000;
    }
    public static final class drawable {
        public static final int ic_launcher=0x7f020000;
        public static final int icon=0x7f020001;
        public static final int notif=0x7f020002;
    }
    public static final class layout {
        public static final int main=0x7f030000;
    }
    public static final class string {
        public static final int app_name=0x7f040000;
    }
}

~~~

Pull-Request: #2227
Reviewed-by: Ait younes Mehdi Adel <overpex@gmail.com>
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>

7 years agoMerge: nitweb: show metrics
Jean Privat [Wed, 3 Aug 2016 16:38:26 +0000 (12:38 -0400)]
Merge: nitweb: show metrics

This PR introduce the metrics displaying in nitweb.

For now, only classes and modules metrics are shown (mclass_metrics.nit, mmodules_metrics.nit, inheritance_metrics.nit).

Some examples (may be long to load on my little server):
* [core::Array](http://nitweb.moz-code.org/doc/core::Array)
* [core::array](http://nitweb.moz-code.org/doc/core::array)
* [core>collection>](http://nitweb.moz-code.org/doc/core%3Ecollection%3E)
* [core](http://nitweb.moz-code.org/doc/core)

Pull-Request: #2219
Reviewed-by: Jean Privat <jean@pryen.org>

7 years agomodelize_class: Remove a dead check
Jean-Christophe Beaupré [Tue, 2 Aug 2016 17:32:15 +0000 (13:32 -0400)]
modelize_class: Remove a dead check

Dead at aa6431294837f7a4734f8b73c2559404b416c924 (PR #2047).

Signed-off-by: Jean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>

7 years agomendel_metrics: Fix the bibliographical reference
Jean-Christophe Beaupré [Tue, 2 Aug 2016 19:49:17 +0000 (15:49 -0400)]
mendel_metrics: Fix the bibliographical reference

Signed-off-by: Jean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>

7 years agomendel_metrics: Fix a spelling mistake
Jean-Christophe Beaupré [Wed, 13 Jul 2016 16:26:30 +0000 (12:26 -0400)]
mendel_metrics: Fix a spelling mistake

Signed-off-by: Jean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>

7 years agomodelize_class: Remove an unnecessary pre-condition
Jean-Christophe Beaupré [Tue, 2 Aug 2016 18:09:49 +0000 (14:09 -0400)]
modelize_class: Remove an unnecessary pre-condition

`build_classes` calls itself recursively on imported modules. So, there is
no point to specify that imported modules must be processed first.

Signed-off-by: Jean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>

7 years agolinux: update lifecycle
Alexis Laferrière [Fri, 29 Jul 2016 18:38:38 +0000 (14:38 -0400)]
linux: update lifecycle

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

7 years agoapp.nit: document platform specific triggers for each app.nit callbacks
Alexis Laferrière [Fri, 29 Jul 2016 15:49:24 +0000 (11:49 -0400)]
app.nit: document platform specific triggers for each app.nit callbacks

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

7 years agoapp.nit: update README and add graph image
Alexis Laferrière [Fri, 29 Jul 2016 13:18:36 +0000 (09:18 -0400)]
app.nit: update README and add graph image

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

7 years agolib & contrib: remove references to on_start and on_destroy
Alexis Laferrière [Thu, 28 Jul 2016 20:14:04 +0000 (16:14 -0400)]
lib & contrib: remove references to on_start and on_destroy

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

7 years agoandroid: call on_restart
Alexis Laferrière [Fri, 29 Jul 2016 12:59:29 +0000 (08:59 -0400)]
android: call on_restart

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

7 years agolib/ios: update lifecycle
Alexis Laferrière [Thu, 28 Jul 2016 20:14:39 +0000 (16:14 -0400)]
lib/ios: update lifecycle

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

7 years agoapp.nit: intro `on_restart`
Alexis Laferrière [Fri, 29 Jul 2016 12:55:00 +0000 (08:55 -0400)]
app.nit: intro `on_restart`

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

7 years agoapp.nit & android: move on_create & on_destroy to Android only
Alexis Laferrière [Thu, 28 Jul 2016 20:13:23 +0000 (16:13 -0400)]
app.nit & android: move on_create & on_destroy to Android only

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

7 years agobenitlux: fix typo in `ItemView::set_background`
Alexis Laferrière [Fri, 22 Jul 2016 17:12:07 +0000 (13:12 -0400)]
benitlux: fix typo in `ItemView::set_background`

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

7 years agocalculator: separate Android variants between the simple calc and the sci one
Alexis Laferrière [Fri, 22 Jul 2016 13:37:27 +0000 (09:37 -0400)]
calculator: separate Android variants between the simple calc and the sci one

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

7 years agocalculator: have a different icon and app name for the scientific variant
Alexis Laferrière [Fri, 22 Jul 2016 13:29:28 +0000 (09:29 -0400)]
calculator: have a different icon and app name for the scientific variant

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

7 years agocalculator: shorter name and bump up the version number
Alexis Laferrière [Fri, 22 Jul 2016 13:36:11 +0000 (09:36 -0400)]
calculator: shorter name and bump up the version number

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

7 years agocalculator: name icon rules to real files
Alexis Laferrière [Fri, 22 Jul 2016 13:08:50 +0000 (09:08 -0400)]
calculator: name icon rules to real files

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

7 years agocalculator: move `scientific_calculator` to its own folder `scientific`
Alexis Laferrière [Fri, 22 Jul 2016 13:07:42 +0000 (09:07 -0400)]
calculator: move `scientific_calculator` to its own folder `scientific`

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

7 years agoiOS: use `app_files`
Alexis Laferrière [Fri, 22 Jul 2016 03:22:20 +0000 (23:22 -0400)]
iOS: use `app_files`

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

7 years agoAndroid: use `app_files` to find android specific files
Alexis Laferrière [Fri, 22 Jul 2016 03:09:47 +0000 (23:09 -0400)]
Android: use `app_files` to find android specific files

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

7 years agoAndroid: move up assets and resources logic
Alexis Laferrière [Fri, 22 Jul 2016 01:51:59 +0000 (21:51 -0400)]
Android: move up assets and resources logic

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

7 years agoAndroid & iOS: collect the arguments from the `app_files` annotation
Alexis Laferrière [Fri, 22 Jul 2016 01:53:29 +0000 (21:53 -0400)]
Android & iOS: collect the arguments from the `app_files` annotation

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

7 years agolib: intro and doc the `app_files` annotation
Alexis Laferrière [Fri, 22 Jul 2016 01:52:47 +0000 (21:52 -0400)]
lib: intro and doc the `app_files` annotation

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

7 years agobenitlux: use the R class
Alexis Laferrière [Thu, 21 Jul 2016 22:52:54 +0000 (18:52 -0400)]
benitlux: use the R class

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

7 years agoAndroid support: import the R class at the top of all java files from the FFI
Alexis Laferrière [Thu, 21 Jul 2016 22:42:49 +0000 (18:42 -0400)]
Android support: import the R class at the top of all java files from the FFI

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

7 years agoJava FFI: make `MModule::java_file` public
Alexis Laferrière [Thu, 21 Jul 2016 22:51:55 +0000 (18:51 -0400)]
Java FFI: make `MModule::java_file` public

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

7 years agonitweb/angular: add metrics tab for packages, groups, modules and classes
Alexandre Terrasa [Mon, 4 Jul 2016 23:32:12 +0000 (19:32 -0400)]
nitweb/angular: add metrics tab for packages, groups, modules and classes

Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

7 years agonitweb/angular: add metrics directives
Alexandre Terrasa [Mon, 4 Jul 2016 23:31:50 +0000 (19:31 -0400)]
nitweb/angular: add metrics directives

Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

7 years agonitweb/angular: import d3pie js lib
Alexandre Terrasa [Mon, 4 Jul 2016 23:31:27 +0000 (19:31 -0400)]
nitweb/angular: import d3pie js lib

Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

7 years agonitweb/angular: model load metrics
Alexandre Terrasa [Mon, 4 Jul 2016 23:27:11 +0000 (19:27 -0400)]
nitweb/angular: model load metrics

Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

7 years agonitweb: introduce metrics API
Alexandre Terrasa [Mon, 4 Jul 2016 23:26:29 +0000 (19:26 -0400)]
nitweb: introduce metrics API

Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

7 years agomodel_collect: collect accessible methods and VTs
Alexandre Terrasa [Mon, 4 Jul 2016 23:23:01 +0000 (19:23 -0400)]
model_collect: collect accessible methods and VTs

Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

7 years agotests: update nitmetrics output
Alexandre Terrasa [Wed, 20 Jul 2016 16:04:26 +0000 (12:04 -0400)]
tests: update nitmetrics output

Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

7 years agometrics: add metric about abstract class inheritance
Alexandre Terrasa [Mon, 4 Jul 2016 23:22:45 +0000 (19:22 -0400)]
metrics: add metric about abstract class inheritance

Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

7 years agometrics: add Number of Accessible Definition metric for mmodule
Alexandre Terrasa [Mon, 4 Jul 2016 23:22:09 +0000 (19:22 -0400)]
metrics: add Number of Accessible Definition metric for mmodule

Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

7 years agometrics: add metrics about class content kind
Alexandre Terrasa [Mon, 4 Jul 2016 23:21:34 +0000 (19:21 -0400)]
metrics: add metrics about class content kind

Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

7 years agometrics: factorize `mainmodule` and `model_view` for all MModule metrics
Alexandre Terrasa [Mon, 4 Jul 2016 22:01:26 +0000 (18:01 -0400)]
metrics: factorize `mainmodule` and `model_view` for all MModule metrics

Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

7 years agometrics: factorize `mainmodule` and `model_view` attributes for all MClass metrics
Alexandre Terrasa [Mon, 4 Jul 2016 22:00:39 +0000 (18:00 -0400)]
metrics: factorize `mainmodule` and `model_view` attributes for all MClass metrics

Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

7 years agomongodb: wrap `Collection::aggregate` function
Alexandre Terrasa [Wed, 20 Jul 2016 15:35:16 +0000 (11:35 -0400)]
mongodb: wrap `Collection::aggregate` function

Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

7 years agoMerge: Improve (and fix) Docker
Jean Privat [Mon, 11 Jul 2016 17:02:48 +0000 (13:02 -0400)]
Merge: Improve (and fix) Docker

#2181 broke the initial bootstrap because nitc was not found to build nitmd thus failed the `make man`

This PR also cleanup the dockerfiles so the root/ directory is not more used (this cause issue for non-root users)

Pull-Request: #2226
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>

7 years agodocker: do not install in /root as it is not accessible to unprivileged user
Jean Privat [Mon, 11 Jul 2016 14:21:31 +0000 (10:21 -0400)]
docker: do not install in /root as it is not accessible to unprivileged user

Signed-off-by: Jean Privat <jean@pryen.org>

7 years agofix nitc path when making manpages
Jean Privat [Mon, 11 Jul 2016 14:19:52 +0000 (10:19 -0400)]
fix nitc path when making manpages

This broke Docker

Signed-off-by: Jean Privat <jean@pryen.org>

7 years agoMerge: global_compiler: Write errors to stderr
Jean Privat [Mon, 11 Jul 2016 13:48:50 +0000 (09:48 -0400)]
Merge: global_compiler: Write errors to stderr

Signed-off-by: Jean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>

Pull-Request: #2225