YUI fails to compress in Confluence plugin - yui

I'm developing a confluence plugin and I'm using bower as my package manager.
When I try to compile and package the plugin the SDK tries to minify all the JS files using YUI compressor.
The minification process fails due to various reasons (reserved words, syntax errors), all caused by the packages installed by bower.
When I don't minify the code everything passes, and the plugin works fine.
I tried atlas-compile --fail-never, didn't help.
Any idea on how I can minify the code without having to modify the packages code? Or maybe put a flag that will cause only the files that are in atlassian-plugin.xml to be minified?
Thanks!

In the pom.xml, ensure that you don't compress JS with <compressResources>false</compressResources> e.g. around here...
<build>
...
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-confluence-plugin</artifactId>
<version>${amps.version}</version>
<extensions>true</extensions>
<configuration>
...
<compressResources>false</compressResources>
...
</configuration>
</plugin>
...

I am trying to solve the same issue and I came to believe this is not possible. (It's 2016, people. This is not rocket science.)
The error I am getting is:
[INFO] --- maven-confluence-plugin:6.2.4:compress-resources (default-compress-resources) # confluence-tagging ---
[INFO] Compiling javascript using YUI
[ERROR] illegal character
And then errors in some file deep in node_modules that should definitely not be included in the plugin build.
I tried to list all available options for the compressor plugin using this command:
atlas-mvn help:describe -Dplugin=com.atlassian.maven.plugins:maven-confluence-plugin -Dgoal=compress-resources -Ddetail=true
The list says that there is no such option. I tried to configure it to use Closure Compiler instead, but it did not help much. The configuration is this:
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-confluence-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>compress-resources</goal>
</goals>
</execution>
</executions>
<configuration>
<closureJsCompiler>true</closureJsCompiler>
</configuration>
</plugin>
Which just gives me even longer list of errors.
At this point, I am giving up.
Here are some relevant links:
https://developer.atlassian.com/docs/advanced-topics/supporting-minification-of-javascript-and-css-resources - desperately outdated
https://answers.atlassian.com/questions/221949/how-to-select-which-resources-are-compressed

Related

vaadin-maven-plugin npm registry configuration

For context, I'm running a jenkins build which has no direct internet access. We have a nexus with proxy repositories for maven, nodejs and npm.
I'm using the recommended frontend-maven-plugin to download and install node and npm. This step works fine. Afterwards the vaadin-maven-plugin is used with the prepare-frontend and build-frontend goals.
Apparently, this triggers the actual npm install so I need it to contact the private npm registry, yet I can't find any setting to specify this. I did find a npmRegistryURL variable in the vaadin-maven-plugin configuration, but apparently this isn't used for the build-frontend goal.
My pom setup looks like this:
<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<executions>
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<phase>generate-resources</phase>
</execution>
</executions>
<configuration>
<nodeVersion>v12.13.0</nodeVersion>
<nodeDownloadRoot>https://nexusrepo.com/repository/nodejs/</nodeDownloadRoot>
<npmDownloadRoot>https://nexusrepo.com/repository/npmjs/</npmDownloadRoot>
</configuration>
</plugin>
<plugin>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-maven-plugin</artifactId>
<executions>
<execution>
<id>prep</id>
<goals>
<goal>prepare-frontend</goal>
<goal>build-frontend</goal>
</goals>
</execution>
</executions>
<configuration>
<npmRegistryURL>https://nexusrepo.com/repository/npmjs/</npmRegistryURL>
</configuration>
</plugin>
</plugins>
</build>
I've also tried to let the frontend-maven-plugin handle the npm install but that doesn't work because the vaadin-maven-plugin is manually adding extras to the node_modules/#vaadin folder.
So I got the same Error: Cannot find module '#vaadin/stats-plugin' as specified in Vaadin issue 10306
I've also tried to add a .npmrc file to the root of my project to specify the npm registry, but that had no effect. Should this work or is it simply not checked by the vaadin-maven-plugin?
Some help would be greatly appreciated. I can't manually configure the node installation by using npm config set registry because it's not a static node installation, so the configuration needs to happen inside of the actual maven build.
After quite a bit of searching and testing, there seem to be 2 ways of solving this problem.
Option 1 is to configure the frontend-maven-plugin with an npm execution/goal.
The default argument is install, but it doesn't have to be. That way you can use this execution to run the npm config set registry command.
<execution>
<id>npm config</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>config set registry https://nexusrepo.com/repository/npmjs/</arguments>
</configuration>
<phase>generate-resources</phase>
</execution>
WARNING: from my experience, this saves the given registry in a user folder .npmrc file, which would probably affect every npm build on your jenkins, since it would save it for the default jenkins-user. Therefore, this did not seem like a proper solution.
Option 2 is adding a .npmrc file to the root of your project.
I tried doing this at first but it didn't work (as specified in the question). This only seemed to be the case on my local workstation, probably because I also had nodejs and npm actually installed and the settings were being overridden somewhere else. During the jenkins build this worked as intended.
Option 2 definitely seemed like the better way to go forward, so that's what I did for now. Still annoyed by the lack of vaadin-maven-plugin documentation, but at least I got it to work.

How to include the spark-examples.jar as a dependency within a maven/sbt project?

The spark-examples.jar is apparently not published to maven. That is a complication when attempting to build atop those classes in an maven /sbt project.
Further compounding this problem is that it seems that mvn install were set up to skip when going through the process of downloading spark, building from source, and installing locally:
mvn -pl examples install
[INFO] --- maven-install-plugin:2.5.2:install (default-install) # spark-examples_2.11 ---
[INFO] Skipping artifact installation
It seems I will have to spelunk into the spark examples pom.xml to see how to re-enable installation? Overall this is a non trivial process: any pointers to a quicker path appreciated.
It appears that a band-aid would be as hinted in the OP: remove the skip from the install plugin invocation:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<configuration>
<!-- <skip>true</skip> -->
</configuration>
A more straightforward approach to adding the spark-examples dependency would still be appreciated (and likely awarded).

Cannot run program "npm" in directory

When i am traversing the to src/main/app/ folder structure where i have the package.JSON & gruntfile, i am able to run npm install and grunt command. But when i am trying to run the mvn jetty:run and a property file in the root folder of the project when POM file is present, it is throwing error that it cannot run npm install in the folder structure src/main/app/.
This is the exact error:
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (n
pminstall) on project my-abc-web: Command execution failed. Cannot
run program "npm" (in directory "C:\Users\Achyut_J01\Documents\GitHub\infras\my-abc\my-abc-web\src\main\app"): CreatePro
cess error=2, The system cannot find the file specified -> [Help 1]
It's a Windows Machine.
I used this workaround to have a cross-platform Maven build : declare the npm executable name as a Maven variable, and use Maven filters to modify this executable name when running on Windows.
It can work the same for Grunt, Bower etc.
This workaround is not necessary any more if you use exec-maven-plugin >=1.6.0 (thanks Manmay for the information in the comments): it was a bug of this plugin (see https://github.com/mojohaus/exec-maven-plugin/issues/42), that has been fixed in 1.6.0 (see https://github.com/mojohaus/exec-maven-plugin/pull/46)
<properties>
<npm.executable>npm</npm.executable>
</properties>
(...)
<build>
<plugins>
(...)
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.5.0</version>
<executions>
<execution>
<id>exec-npm</id>
<phase>process-resources</phase>
<configuration>
<executable>${npm.executable}</executable>
<arguments>
<argument>install</argument>
</arguments>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
(...)
</plugins>
</build>
<profiles>
<profile>
<id>platform-windows</id>
<activation>
<os>
<family>windows</family>
</os>
</activation>
<properties>
<!-- Override the executable names for Windows -->
<npm.executable>npm.cmd</npm.executable>
<grunt.executable>grunt.cmd</grunt.executable>
<bower.executable>bower.cmd</bower.executable>
</properties>
</profile>
</profiles>
In Windows Platform, use npm.cmd to replace npm
Evidently you are on a Windows system. npm is a batch file and not an executable. There are issues running a batch file from maven exec plugin. You may want to explore the workaround suggested in the link, like
deconstruct the .bat script into its actual commands
use cmd.exe and pass node as parameter - refer to this.
See the link for details: https://stackoverflow.com/a/48184182/4282901
In the directory where node is installed rename the batch file so that the existing npm.cmd file is picked. See screenshot below:
This method is preferable if you build the projects targeting linux and windows both. Moreover, also if the no. of pom files is also large.
Make sure that the directory in which node and npm are installed is added to your PATH variable. If it is, you shouldn't have to change your .pom files at all. This is tested on 1.6.0, so you may have to use the workaround mentioned by #Mossroy if you use 1.5.0.
npm is a shell script.
renaming it npm.sh on windows worked for me.
Windows searched 'npm' and did not find,
it then tries npm.bat which exists

How to use cobertura.ser generated by ant to be used while running maven integration test

I run integration-test with cucumber cases (say: with tag#abc in feature files) with following command and pom.xml snippet -
pom.xml snippet:
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.11</version>
<configuration>
<skip>true</skip>
</configuration>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
<includes>
<include>**/*.class</include>
</includes>
<systemPropertyVariables>
<job.host.name>server-t10</job.host.name>
<job.email.notification>abc#abc.com</job.email.notification>
<cucumber.options>--format pretty --format
html:target/cucumber/cucumber-html</cucumber.options>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
...
mvn command to run the test case:
mvn clean integration-test -Dcucumber.options="--format pretty --format html:target/cucumber/cucumber-html1 --tags #abc" -Djob.host.name=server-t10
Every thing works fine with cases being executed and all reports produced. The problem arises when I try to get the coverage of the test cases.
I tried all possible combinations to generate a cobertura coverage report with cobertura-maven-plugin and version2.5.2 (without using ant instrumnet/report), but it just does not create any report, nor any .ser file or anything. Only logs say that - No files to instrument and does nothing.
Losing the battle, I finally downloaded cobertura (1.9.4.1) and created custom cobertura.xml. And when I run the following ant commands for ex -
ant -f cobertura.xml instrument
mvn clean integration-test -Dcucumber.options="--format pretty --format html:target/cucumber/cucumber-html1 --tags #abc" -Djob.host.name=server-t10
ant -f cobertura.xml report
Luckily though, it creates all the reports/.ser file etc. However, after running all of it, it shows as zero coverage in the final coverage report for all used classes. That could be because (as I think) the mvn command did not use/manipulate the cobertura.ser created by ant instrument.
So, please help me out in this, that what and where I put something in my pom.xml so that when I run the mvn command, it uses the instrumented file (output generated by ant insturment command) and update it. so that i can use that file for my report generation using ant report. I tried putting all possible entries in pom.xml. but it did not help.
Note: I am looking for this particular solution because all my efforts have gone wastedtrying to make cobertura-maven-plugin work. I dont' know the reason, but this plugin just doesn't work for me for creating report or even running the cases.

How to make maven build platform independent?

When building using Maven on my mac, on mvn install i get
[WARNING] Using platform encoding (MacRoman actually) to copy filtered
resources, i.e. build is platform dependent!
Is it possible to either build for a given platform (Linux) or otherwise make build platform independent?
It happens when you have not provided following in your pom.xml
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
Absence of this means you are using platform specific encoding and that's why the warning.
And if #Kal's answer doesn't work for you, perhaps you can learn from my last 30 minutes... below link adds an additional line to the above answer and solved my problem. My problem was related to the maven-resources-plugin 2.6, but the provider of the following solution had a different problem it solved...
https://stackoverflow.com/a/3018152/2485075
For specific needs:
<!-- https://maven.apache.org/plugins/maven-resources-plugin/index.html -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
If the plugin is already configured one should merely add
<encoding>UTF-8</encoding>

Resources