Disable javascript facet in a m2e project - javascript

I'd like to disable the Javascript Facet (and remove the Javascript builder) from a Maven-driven Eclipse project.
Is there any way I can configure the maven-eclipse-plugin to do so?

First of all, clean the configuration with mvn eclipse:clean, it will remove all configuration from the .project file.
Then make a new one with mvn eclipse:eclipse, just with the configuration and dependencies on your pom.xml.
EDIT:
And configure the project natures that you need:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<projectnatures>
<projectnature>org.eclipse.jdt.core.javanature</projectnature>
<projectnature>org.eclipse.wst.common.modulecore.ModuleCoreNature</projectnature>
</projectnatures>
<additionalProjectnatures>
[... the ones you need or empty...]
<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
</additionalProjectnatures>
</configuration>
</plugin>

Related

Sonar javascript static code analyze - javascript riport missing. Maven project

Help me, please. I don't know why missing only javascript static code analyze riports.
So, I have a maven project with multiple modules and the javascript codes in the frontend project.
SonarJS plugin installed
i'm running: mvn clean install sonar:sonar
i have configure sonar from pom.xml instead of sonar-project.properties
sonar version: 6.7 community edition
In the sonar overview it has java static code analyze riport both of modules, but nothin about javascript codes.
Here is my pom.xml settings in the parent project.
<?xml version="1.0" encoding="UTF-8"?>
<project ... >
...
<version>0.0.1-SNAPSHOT</version>
<modules>
<module>backend</module>
<module>frontend</module>
</modules>
<properties>
...
<!-- sonar -->
<sonar.version>3.4.0.905</sonar.version>
<sonar.host.url>http://my.sonar.domain.url</sonar.host.url>
<sonar.login>asdsd43f8g7fs498u9s8df7s97zf9er97zf7</sonar.login>
<sonar.javascript.file.suffixes>.js,.jsx,.vue</sonar.javascript.file.suffixes>
<sonar.sources>src/main/</sonar.sources>
<sonar.test>src/test/</sonar.test>
<sonar.jacoco.itReportPath>${project.testresult.directory}/coverage/jacoco/jacoco-it.exec</sonar.jacoco.itReportPath>
<sonar.jacoco.reportPath>${project.testresult.directory}/coverage/jacoco/jacoco.exec</sonar.jacoco.reportPath>
<sonar.java.codeCoveragePlugin>jacoco</sonar.java.codeCoveragePlugin>
<!-- For Java -->
<sonar.junit.reportsPath>reports/java/surefire-reports</sonar.junit.reportsPath>
<!-- For JavaScript -->
<sonar.javascript.lcov.reportPath>reports/js/lcov.dat</sonar.javascript.lcov.reportPath>
...
</properties>
<dependencies> ... </dependencies>
<build>
<pluginManagement>
<plugins>
...
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>${sonar.version}</version>
<executions>
<execution>
<id>sonar-run</id>
<phase>verify</phase>
<goals>
<goal>sonar</goal>
</goals>
</execution>
</executions>
</plugin>
....
</plugins>
</pluginManagement>
</build>
</project>
UPDATE:
I have run sonar analyze with -X debug. The logs below:
[DEBUG] 15:08:27.144 'src/main/resources/static/js/template/template.js' excluded by org.sonar.plugins.javascript.JavaScriptExclusionsFileFilter
[DEBUG] 15:08:27.145 'src/main/resources/static/js/navigation/navigationEvents.js' excluded by org.sonar.plugins.javascript.JavaScriptExclusionsFileFilter
[DEBUG] 15:08:27.145 'src/main/resources/static/js/navigation/navigation.js' excluded by org.sonar.plugins.javascript.JavaScriptExclusionsFileFilter
[DEBUG] 15:08:27.145 'src/main/resources/static/js/navigation/moduleLoader.js' excluded by org.sonar.plugins.javascript.JavaScriptExclusionsFileFilter
But doesn't have any exculde settings.
You wrote in the comment that:
sonar.javascript.exclusions=**/node_modules/**,**/bower_components/**,**/js/**
If you didn't specify it in any pom.xml file, then that value is taken from the server. You can see the configuration by opening: https://sonar.host/admin/settings?category=javascript or Administration → Configuration → JavaSctript. Next you have to find the JavaScript Exclusions section:
Probably you will also see **/js/**. From my point of view you should delete that entry because it has no sense. If you cannot then you have to overwrite the default value by adding:
<sonar.javascript.exclusions>**/node_modules/**,**/bower_components/**</sonar.javascript.exclusions>
or
<sonar.javascript.exclusions></sonar.javascript.exclusions>
In pom of maven module containing JS code, set sonar.sources (and tests if you want) of your JS code
I'd say that first you want to try to execute coverage with sonar.properties file just to figure out - which keys you are still missing, preferably for js exclusively. Also, correct setting may depend on actual Sonar version that you are using.
One thing I see is that you have sonar.lcov.javascript.reportPath twice. Which one is the correct one (to start with use the hardcoded path, to make sure, you are getting the reports)
Secondly,in my project file I also had to specify the plugin to use (something like sonar.js.coveragePlugin = lcov ). Pehaps that you also want to add, since you are using lcov.
Finally, I also have the following flag set:
sonar.dynamicAnalysis=reuseReports
That was needed to reuse the reports that were generated during the build.
On a side note, my configuration was created a 3 years back, for sonar version that was latest back then. There might have been some changes with the new releases of Sonar.

How to generate JavaScript file from Java Properties with Maven in Eclipse?

In an old Java web application there are many keys in properties files for internationalization. JavaScript functions also use this key to show some messages.
Actually this file is inline in HTML, dynamicly generated on JSPs, causing an increase of approximately 400 KB on each page request.
To improve performance slightly I generated JavaScript files with key|value with content like this:
var b = {
keys: {
"key.one": "value.one",
"key.two": "value.two"
}
};
The JavaScript file path look like this:
The message properties files are in the directory like this:
I need to read the message property files in the build to create the JavaScript files.
To do this, I am using exec-maven-plugin, set up this way:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.3.2</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<arguments>
<argument>${project.build.directory}/${project.build.finalName}</argument>
</arguments>
<mainClass>com.brunocesar.build.GenerateI18NJSFiles</mainClass>
</configuration>
</plugin>
GenerateI18NJSFiles reads the properties files and generates the JavaScript files, but only when running maven build (e.g.: mvn clean compile war:exploded).
I need to generate them also in Eclipse.
SO, I set up the Eclipse lifecycle-mapping plugin like this:
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<versionRange>[${exec-maven-plugin.version},)</versionRange>
<goals>
<goal>java</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute>
<runOnIncremental>false</runOnIncremental>
</execute>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
But it still is not generating the files in the Eclipse build, but only by Maven.
Is there is a way to set up Eclipse (maybe in m2e-wtp, maybe using another plugin) to generate the files and deploy in a container (such as JBoss, Tomcat, etc.)?

jasmine-maven-plugin load source files and their dependencies

I've got a bunch of javascript files I'd like to test, located in src/main/webapp/js, but when I try to build on the command line, I get a bunch of errors due to the missing library files that each of my source scripts depend upon. I am trying to include them within the "sourceIncludes" tag, but this seems to do nothing. I can, however, place them all, one at a time, in the "preloadSources" tags, but I'd rather not do this.
Also, some of my sources files have functions that interact with the DOM, and including the .html file that contains the elements that these functions need just gives me:
"net.sourceforge.htmlunit.corejs.javascript.EcmaError: ReferenceError: "XML" is not defined"
my pom.xml below:
<plugin>
<groupId>com.github.searls</groupId>
<artifactId>jasmine-maven-plugin</artifactId>
<version>1.1.0</version>
<executions>
<execution>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
<configuration>
<jsSrcDir>src/main/webapp/js</jsSrcDir>
<jsTestSrcDir>src/test/javascript/js</jsTestSrcDir>
<sourceIncludes>
<include>src/main/webapp/js/lib/**/*.js</include>
<include>**/*.js</include>
</sourceIncludes>
<preloadSources>
<preloadSource>src/main/webapp/js/lib/jquery/jquery-1.7.2.js</preloadSource>
</preloadSources>
</configuration>
</plugin>
I hate having to list my dependencies in order. That's why I use a dependency loader like Require.js. I wrote a quick post summarizing my experience with jasmine-maven-plugin, but using require.js to load dependencies. It keeps my pom.xml clean, and I let my JavaScript files load their own dependencies. jasmine+maven+requirejs+code coverage

jasmine-maven-plugin and require-js result in path issues

I am using require-js to model dependencies in my java script project. I also use jasmine to write BDD styled test cases and the jasmine-maven-plugin:1.1.0 to execute these tests in headless mode.
This is my source project structure
project/
| src/main/javascript
| | api/*.js
| | main.js
| src/test/javascript
| | spec/*spec.js
This is my webapp pom jasmine configuration:
<plugin>
<groupId>com.github.searls</groupId>
<artifactId>jasmine-maven-plugin</artifactId>
<version>1.1.0</version>
<executions>
<execution>
<goals>
<goal>generateManualRunner</goal>
<goal>resources</goal>
<goal>testResources</goal>
<goal>test</goal>
<goal>preparePackage</goal>
</goals>
</execution>
</executions>
<configuration>
<specRunnerTemplate>REQUIRE_JS</specRunnerTemplate>
<scriptLoaderPath>lib/require-jquery.js</scriptLoaderPath>
<sourceIncludes>
<include>lib/require-jquery.js</include>
<include>lib/underscore.js</include>
<include>lib/backbone.js</include>
<include>lib/d3.js</include>
<include>lib/d3.layout.js</include>
<include>lib/bootstrap.js</include>
<include>main.js</include>
</sourceIncludes>
<preloadSources>
<source>lib/require-jquery.js</source>
<source>lib/underscore.js</source>
<source>lib/backbone.js</source>
<source>lib/d3.js</source>
<source>lib/d3.layout.js</source>
<source>lib/bootstrap.js</source>
<source>main.js</source>
</preloadSources>
<browserVersion>FIREFOX_3_6</browserVersion>
</configuration>
</plugin>
During the maven build all js sources are copied to target/jasmine/src. The runner.html that refers to my main.js is at target/jasmine.
Now the problem is that my require-js modules define their dependencies relative to the main.js, whereas in the maven test run, the runner assumes them to be relative to target/jasmine/runner.html. Since my modules are not (and must not be) aware of the additional jasmine/src folder, IMHO that is an issue.
I receive the following error message when I run mvn clean install:
Failed to execute goal
com.github.searls:jasmine-maven-plugin:1.1.0:test (default) on project
mywebapp: The jasmine-maven-plugin encountered an
exception: java.lang.RuntimeException:
org.openqa.selenium.WebDriverException:
com.gargoylesoftware.htmlunit.ScriptException: Wrapped
com.gargoylesoftware.htmlunit.ScriptException: Wrapped
com.gargoylesoftware.htmlunit.ScriptException: Wrapped
com.gargoylesoftware.htmlunit.ScriptException: Wrapped
com.gargoylesoftware.htmlunit.ScriptException: Wrapped
java.lang.RuntimeException: java.io.FileNotFoundException:
C:\Jenkins\jobs\job1\workspace\mywebapp\target\jasmine\api\data-util.js
(The system cannot find the path specified)
Anybody out there having some idea to work around or configure that?
I faced the same problem:
java.io.FileNotFoundException
with requireJS and jasmine
but you don't have to use the maven-resources-plugin and hack the js files to a second output directory.
I used 'srcDirectoryName'
you can find all possible params at https://github.com/searls/jasmine-maven-plugin/blob/master/src/main/java/com/github/searls/jasmine/mojo/AbstractJasmineMojo.java
and advanced examples under https://github.com/searls/jasmine-maven-plugin/tree/master/src/test/resources/examples
In the meantime I found a workaround or a fix (not sure) by configuring the maven-resources-plugin
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-js-files</id>
<phase>generate-test-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/jasmine</outputDirectory>
<resources>
<resource>
<directory>src/main/javascript</directory>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/webapp</directory>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/test/webapp</directory>
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
I put that configuration in a separate profile which I activate during testing.
I see that you've got lib/require-jquery.js, but your file tree doesn't show where "lib" is located. is loaded relative to , but you don't have one. Maybe that's your problem. I wrote a quick post summarizing my experience with the jasmine-maven-plugin and using Require.js. In it I've got my pom.xml. My pom.xml seems quite a bit smaller than yours but the plugin works fine for me. Maybe my post will help. Jasmine+Maven+Requirejs+Coverage

Maven YUI Compressor: compress after aggregation

Can I setup Maven YUI Compressor for compression files after aggregation, because I want to exclude "sources" directory, which contain files for aggregation and then compress aggregated files.
For example I have some .js-files inside of /js/sources/mylib/ and all this files merged into one file /js/mylib.js while yui-compressor aggregation stage. In pom.xml I configure yui-compressor to exclude whole /js/sources/ and compress files only within /js library, but yui-compressor execute "compress" goal before aggregation, so I have uncompressed merged files. And I need to fix this somehow
Can we turn it around and say: Aggregate after compression? If so, I had the same issue and with the following it worked out for me.
The trick seemed to be to put the output file in the target dir instead of in the source. That way you can include files that got minified in the aggregation.
Files that were already minified I then approach through the basedir var.
<executions>
<execution>
<goals>
<goal>compress</goal>
</goals>
</execution>
</executions>
<configuration>
<excludes>
<exclude>**/*-min.js</exclude>
<exclude>**/*.min.js</exclude>
<exclude>**/*.css</exclude>
</excludes>
<removeIncluded>false</removeIncluded>
<jswarn>false</jswarn>
<aggregations>
<aggregation>
<insertNewLine>true</insertNewLine>
<removeIncluded>false</removeIncluded>
<includes>
<!-- these exist only in target dir. the original was json2.js & bootstrap.tabs.js -->
<include>**/bootstrap-tabs-min.js</include>
<include>**/json2-min.js</include>
<!-- use originals for the ones already minified -->
<include>${basedir}/src/main/webapp/js/backbone-min.js</include>
</includes>
<output>${project.build.directory}/${project.build.finalName}/js/test.js</output>
</aggregation>
</aggregations>
</configuration>

Categories