Maven 2.x Exec Plugin

Strange encoding of environment variables when using exec plugin

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Critical Critical
  • Resolution: Fixed
  • Affects Version/s: 1.1.1
  • Fix Version/s: 1.2
  • Component/s: exec
  • Labels:
    None
  • Environment:
    Windows XP, czech mutation
  • Number of attachments :
    0

Description

At fist, you must use non-us windows xp ( I have reproduced this on Windows XP Professional CZECH mutation ).

Create simple maven project with one class ( for example test.App ).

Write following code:

App.java
public class App {

    public static void main(String[] args) throws IOException {

        String s = args[0];
        FileWriter w = new FileWriter(new File("c:\\output.txt"), true);

        // get env variable
        String appData = System.getenv("APPDATA");

        // write env variable to file and write if directory where that variable points to exists
        w.write(s + " : " + appData + " : " + new File(appData).exists() + "\n");  

        w.close();
        
    }

Then run this app with exec:exec and directly by following commands:

mvn install
mvn exec:exec -Dexec.executable=java -Dexec.args="-classpath %classpath test.App maven"
java -cp target\mavenExecEncodingBug-1.0-SNAPSHOT.jar test.App jar

We are expecting result like:
maven : C:\Documents and Settings\admin\Data aplikací : true
jar : C:\Documents and Settings\admin\Data aplikací : true

But it is:
maven : C:\Documents and Settings\admin\Data aplikacˇ : false
jar : C:\Documents and Settings\admin\Data aplikací : true

This is a big problem for me, because my applications looks into different folders when running from IDE and in production.
See also https://netbeans.org/bugzilla/show_bug.cgi?id=172265 for more reference.

Issue Links

Activity

Hide
Dusan Zatkovsky added a comment - - edited

I have taked a look into source of exec plugin and it seems that problem is on other place.

I have added into ExecMojo:execute() following code:

Commandline commandLine = new Commandline();

commandLine.setExecutable( getExecutablePath() );

// TEST
try {

for ( String xxx : commandLine.getEnvironmentVariables() ) { System.out.println("TEST:"+ xxx); }
}
catch (CommandLineException ex) { ex.printStackTrace(); }

... and encoding of "APPDATA" was corrupted there too.

Could anybody confirm it is CommandLine class bug?

Show
Dusan Zatkovsky added a comment - - edited I have taked a look into source of exec plugin and it seems that problem is on other place. I have added into ExecMojo:execute() following code: Commandline commandLine = new Commandline(); commandLine.setExecutable( getExecutablePath() ); // TEST try { for ( String xxx : commandLine.getEnvironmentVariables() ) { System.out.println("TEST:"+ xxx); } } catch (CommandLineException ex) { ex.printStackTrace(); } ... and encoding of "APPDATA" was corrupted there too. Could anybody confirm it is CommandLine class bug?
Hide
Dusan Zatkovsky added a comment -
Show
Dusan Zatkovsky added a comment - Reported as http://jira.codehaus.org/browse/PLXUTILS-124
Hide
Dusan Zatkovsky added a comment -

This was fixed in plexus-utils 2.0.2. http://jira.codehaus.org/browse/PLXUTILS/fixforversion/16267.
Please make a new release of this plugin using this version.

Show
Dusan Zatkovsky added a comment - This was fixed in plexus-utils 2.0.2. http://jira.codehaus.org/browse/PLXUTILS/fixforversion/16267. Please make a new release of this plugin using this version.
Hide
Robert Scholte added a comment -

I've tried to upgrade plexus-utils from 1.5.6 to 2.0.2, but since than some unit-test started to fail because of a java.lang.NoClassDefFoundError: (hidden/)org/codehaus/plexus/util/interpolation/ValueSource. At least the maven-profile artifact uses this class, which was part of p-u-1.5.6, but was (re)moved from p-u-2.0.2. The first next maven-version, which executed these tests successfully was maven-2.2.0. But changing the prequisite to 2.2.0 is a pretty huge step. I don't know if we should do that, maybe there's a better solution...

Show
Robert Scholte added a comment - I've tried to upgrade plexus-utils from 1.5.6 to 2.0.2, but since than some unit-test started to fail because of a java.lang.NoClassDefFoundError: (hidden/)org/codehaus/plexus/util/interpolation/ValueSource. At least the maven-profile artifact uses this class, which was part of p-u-1.5.6, but was (re)moved from p-u-2.0.2. The first next maven-version, which executed these tests successfully was maven-2.2.0. But changing the prequisite to 2.2.0 is a pretty huge step. I don't know if we should do that, maybe there's a better solution...
Hide
Olivier Lamy added a comment -

try to add org.codehaus.plexus:plexus-interpolation.

Show
Olivier Lamy added a comment - try to add org.codehaus.plexus:plexus-interpolation.
Hide
Robert Scholte added a comment -

Already tried to add plexus-interpolation. But it hasn't got the same package structure (org.codehaus.plexus.util.interpolation vs. org.codehaus.plexus.interpolation). But I noticed maven-2.0.10 throws the following exception: java.lang.NoClassDefFoundError: hidden/org/codehaus/plexus/interpolation/ValueSource
Looks like some kind of shading happened here, but it's not available...

Show
Robert Scholte added a comment - Already tried to add plexus-interpolation. But it hasn't got the same package structure (org.codehaus.plexus.util.interpolation vs. org.codehaus.plexus.interpolation). But I noticed maven-2.0.10 throws the following exception: java.lang.NoClassDefFoundError: hidden/org/codehaus/plexus/interpolation/ValueSource Looks like some kind of shading happened here, but it's not available...
Hide
Benjamin Bentmann added a comment -

It seems you only need two classes (ValueSource, RegexBasedInterpolator) to satisfy the test requirements, so you could simply copy those and drop them into src/test/java of the plugin.

The bigger issue is that the maven-plugin-testing-harness does not properly isolate the dependencies of the plugin and those of the Maven core. Just another reason to favor integration tests over those problematic unit tests.

Show
Benjamin Bentmann added a comment - It seems you only need two classes (ValueSource, RegexBasedInterpolator) to satisfy the test requirements, so you could simply copy those and drop them into src/test/java of the plugin. The bigger issue is that the maven-plugin-testing-harness does not properly isolate the dependencies of the plugin and those of the Maven core. Just another reason to favor integration tests over those problematic unit tests.
Hide
Robert Scholte added a comment -

Fixed in rev. 12174
I'll add a new issue to convert some of these unit tests to integration tests

Show
Robert Scholte added a comment - Fixed in rev. 12174 I'll add a new issue to convert some of these unit tests to integration tests

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: