Monday, December 28, 2015

Print angular module dependencies

Here is a simple function to print angular module dependencies:

    angular.__moduleDependencies__ = function (moduleName, indent, nonlast, seen) {
        var module, suffix;
        indent = indent || '';
        seen = seen || [];
        suffix = (indent === '' ? '' : (nonlast ? '├─ ' : '└─ '));
        if (seen.indexOf(moduleName) !== -1) {
            console.log(indent + suffix + moduleName + ' ^');
            return;
        }
        seen.push(moduleName);
        module = angular.module(moduleName);
        if (angular.isDefined(module)) {
            console.log(indent + suffix + moduleName);
            angular.forEach(module.requires, function(requiredModuleName, key){
                var requiredMod = angular.module(requiredModuleName);
                if (angular.isDefined(requiredMod)) {
                    
                    angular.__moduleDependencies__(requiredModuleName,
                        indent + '| ', key < (module.requires.length - 1), seen);
                } else {
                    console.error(indent + requiredModuleName);
                }
            });
        } else {
            console.error(indent + suffix + moduleName);
        }
    };

Usage

angular.__moduleDependencies__('todomvc')


Output

todomvc
 | ├─ ngRoute
 | | └─ ng
 | | | └─ ngLocale
 | └─ ngResource
 | | └─ ng ^

Sunday, December 27, 2015

Filed Eclipse enhancement

Many time I copy a file and the only difference is that I need to map a noun to another.e.g.

firstName -> lastName

getFirstName() -> getLastName()

FIRSTNAME -> LASTNAME

and even better:

FIRST_NAME -> LAST_NAME

FIRST-NAME -> LAST-NAME

This is supported by emacs to some extent. See below.

The Eclipse find/replace dialog should support this using a Case mapping chekbox option like this:

__ Options ____________________

[ ] Case sensitive

    [X] Case mapping

Some languages use camel case, some use hyphen or underscore. The dialog could take that into account.

Support Emacs style case matching replace behavior.

"
15.10.3 Replace Commands and Case
:
:
In addition, when the newstring argument is all or partly lower case, replacement commands try to preserve the case pattern of each occurrence. Thus, the command

M-x replace-string RET foo RET bar RET

replaces a lower case ‘foo’ with a lower case ‘bar’, an all-caps ‘FOO’ with ‘BAR’, and a capitalized ‘Foo’ with ‘Bar’. (These three alternatives—lower case, all caps, and capitalized, are the only ones that replace-string can distinguish.)

If upper-case letters are used in the replacement string, they remain upper case every time that text is inserted. If upper-case letters are used in the first argument, the second argument is always substituted exactly as given, with no case conversion. Likewise, if either case-replace or case-fold-search is set to nil, replacement is done without case conversion.
"

REF: http://www.gnu.org/software/emacs/manual/html_node/emacs/Replacement-and-Case.html#Replacement-and-Case

Sunday, December 13, 2015

TIP: Track window innerWidth using AngularJS

Here is a simple Plumkr to track the window innerWidth using AngularJS:

Try it

Tuesday, July 07, 2015

Eclipse Console Support for Frontend builds

If you use Eclipse of frontend development and use any of the front end tools such as ESLint or JSHint to do static analysis of your Java Script code, then Frontend Maven Plugin Console Support is the plugin for you.

This plugin parses the messages in Eclipse consoles (Process Console or Maven Console) and converts them to hyperlinks. It also adds warnings and error markers as applicable.


Install it using Help > Install New Software in your Eclipse IDE and specifying this update site:

http://cdn.rawgit.com/sandipchitale/frontend.maven.plugin.console.support/1.0.9/frontend.maven.plugin.console.support.updatesite/site.xml

I will soon add this to Eclipse Marketplace.

Enjoy!

Sunday, July 05, 2015

A simple Maven Event Spy

In the context of this blog entry I developed a simple Maven Event Spy. However it works by itself too.

Simply drop mavenbuildspy.jar into your Maven installation's lib/ext folder and run your Maven build and you will see something like:



Alternatively download it somewhere and invoke it on-demand in your Maven build with:

mvn -Dmaven.ext.class.path=path-to/mavenbuildspy.jar ....

Feedback welcome!

Tuesday, June 09, 2015

Selectively run Maven phases and goals from Eclipse IDE

CALL FOR ACTION: If you like this feature please vote up on 470138.


1129 installs from Eclipse Marketplace so far.



This kinda answers this SO question.

Recent updates:
  • Save named configurations
  • The dialog is now mode less, thus allowing multiple invocations. If there is are multiple Maven projects in the workspace, a selector to invoke Phases and Goals on selected other project is shown.
  • Run goals in selection order instead of build agenda order. Using this mode you can run goals in any order. An astute reader may note that you can also type goals in text area before running them. This allows you to even run goals not associated with any phase.
  • Selecting a phase selects the associated goals
  • Expand all Phases
  • Expand all/Collapse all
  • If there is only one Maven project in the workspace, that is always selected.
  • Added a simple Maven Build Spy. It shows the success or failure of the goals, the timing and the exception message as a tooltip for failed goals.


You can even use the spy in your maven builds by:
  • Downloading the Maven Build Spy jar.
  • And then passing the following parameter to your mvn build like so:
> mvn -Dmaven.ext.class.path=path-to/mavenbuildspy.jar ....

When you run a phase, Maven runs all the preceding phases as per the lifecycle definition. However, sometimes I only want to run a selective subset of phases. The only way to do that is to actually run the goals associated with those phases explicitly. However how to get that list of goals? One would think that running:

> mvn help:describe -Dcmd=deploy

would do the trick. But alas it does not. It only lists the statically associated goals as per the static lifecycle definition - and not the actual goals you may configured in the pom's plugin configuration section. IMO this is simply - unimplemented yet useful functionality of Maven.

In this blog entry I talked about listing phases and actual associated goals of a maven lifecycle of a maven pom. In it I talked about an Eclipse plugin based on m2e code. I have improved it further. Now you can show the phases and goals in a checked tree dialog using the Project > Phases and Goals command.

You can run the selected phases or goals using the Launch selected goals command. When a phase is selected all goals associated with that phase are run. In Single Selection Mode the goals simply get added to the set in the order in which they were selected. This allows execution of orders in any order you want.

Maven 3.3.1 or greater is required to run the goals.

NOTE: If you install external Maven 3.3.1+ and try to use it as the installed Maven using Window > Preferences > Maven > Installations you may see an error during the build:

-Dmaven.multiModuleProjectDirectory system property is not set...

To fix that configure the property in your JDK/JRE installation using Window > Preferences > Java > Installed JREs > select default JDK/JRE > edit.

- See more at: http://marketplace.eclipse.org/content/phases-and-goals

You can print the listing to the Maven Console using the Log All command.


To use
  • Make sure you have m2e plugins installed into your Eclipse.
  • Then install the fragement from this update site URL:
https://cdn.rawgit.com/sandipchitale/m2e-phasesandgoals/1.0.28/org.eclipse.m2e.core.ui.phasesandgoals.updatesite/site.xml

or use:

Drag to your running Eclipse workspace to install Phases and GOals

button.


Current standing see: Eclipse Marketplace

  • Restart Eclipse
  • Select a maven project node and invoke Project > Show Phases and Goals command. You will see the output like above in the Maven Console. If a resource from Maven Project is not selected you are prompted to select on.
Github

https://github.com/sandipchitale/m2e-phasesandgoals


BTW This is implemented as a fragment for https://github.com/eclipse/m2e-core/tree/master/org.eclipse.m2e.core.ui

Enjoy!