orctom/was-maven-plugin

Can't use scriptArgs option

Opened this issue · 1 comments

Hi and thanks for the great job, it saved me a lot of time and headaches!

I wrote a new method (update()) in a custom script (using yours as a base) to update an ear instead to uninstall and install it from scratch, and it worked fine, but...
When I try to use the scriptArgs option inside my pom.xml I always get a NullPointerException before the call to the script.
I've tryed with different syntax (update, -o update, "-o update"...) but simply inserting that option in pom.xml it throws that exception, always the same...

Do you have any suggestion?

pom.xml plugin configuration

<plugin>
    <groupId>com.orctom.mojo</groupId>
    <artifactId>was-maven-plugin</artifactId>
    <version>1.1.3.3</version>
    <executions>
        <execution>
            <id>deploy</id>
            <phase>install</phase>
            <goals>
                <goal>deploy</goal>
            </goals>
            <configuration>
                <wasHome>${env.WAS_HOME}</wasHome>
                <user>myuser</user>
                <password>mypwd</password>
                <applicationName>${project.artifactId}</applicationName>
                <host>localhost</host>
                <port>11111</port>
                <server>WebSphere_Portal</server>
                <node>node01</node>
                <virtualHost>default_host</virtualHost>
                <verbose>true</verbose>
                <restartAfterDeploy>false</restartAfterDeploy>
                <script>deploy.py</script>
                <scriptArgs>-o update</scriptArgs><!-- "-o deploy" will be appended if not specified. -->
                <deployOptions>-update.ignore.new</deployOptions>
            </configuration>
        </execution>
    </executions>
</plugin>

error trace

[INFO] --- was-maven-plugin:1.1.3.3:deploy (deploy) @ my.app.ear ---
[INFO] was-maven-plugin - deploy
[INFO] Single target: localhost
[INFO] ============================================================
[INFO] [DEPLOY] localhost my.app.ear
[INFO] ============================================================
[INFO] ====================    pre-steps    =======================
[INFO] Skipped, not configured.
[INFO] ======================    deploy    ========================
Using customized script: D:\workspace\my.app.ear\deploy.py
wsadmin location: D:\WebSphere\AppServer\bin\wsadmin.bat
[ERROR] ##############  Exception occurred during deploying to WebSphere  ###############
[ERROR] com.orctom.was.model.WebSphereServiceException
        at com.orctom.was.service.impl.AbstractWebSphereServiceImpl.execute(AbstractWebSphereServiceImpl.java:68)
        at com.orctom.was.service.impl.AbstractWebSphereServiceImpl.deploy(AbstractWebSphereServiceImpl.java:60)
        at com.orctom.mojo.was.WASDeployMojo.execute(WASDeployMojo.java:81)
        at com.orctom.mojo.was.WASDeployMojo.execute(WASDeployMojo.java:67)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
        at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:309)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:194)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:107)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:955)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:290)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:194)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:95)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
        at java.lang.reflect.Method.invoke(Method.java:508)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: java.lang.NullPointerException
        at com.orctom.was.model.Command.escapeWhitespace(Command.java:66)
        at com.orctom.was.model.Command.addArg(Command.java:54)
        at com.orctom.was.service.impl.AbstractWebSphereServiceImpl.getCommand(AbstractWebSphereServiceImpl.java:100)
        at com.orctom.was.service.impl.AbstractWebSphereServiceImpl.execute(AbstractWebSphereServiceImpl.java:65)
        ... 25 more

Hi there,
thanks for this amazing job.

I experience the very same issue as MarcoMerlo. It is impossible to add an argument via to a custom script.

In AbstractWebsphereServiceImpl line 96 :

    if (!Strings.isNullOrEmpty(model.getScript()) && !Strings.isNullOrEmpty(model.getScriptArgs())) {
      for (String scriptArg : Splitter.on(" ").split(model.getScriptArgs())) {
        command.addArg(scriptArg, null);
      }
    } else {
      command.addArg("-o", task);
    }

The script argument is added with a null value, which is then parsed through Command.escapeWhitespace() which doesn't support a null parameter :

  private String escapeWhitespace(String path) {
    if (path.contains(" ")) { // check null value here ?
      return "\"" + path + "\"";
    }
    return path;
  }

If the project is still maintained, would it be possible to add a null check on Command.escapeWhitespace() line 66 ?

Regards