All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.newmainsoftech.ant.taskdefs.JavaTaskExt Maven / Gradle / Ivy

Go to download

Ant utilities for stand-alone Ant environment and maven-antrun-plugin environment.

There is a newer version: 1.0.1
Show newest version
/*
 * Copyright (C) 2012 NewMain Softech
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */
package com.newmainsoftech.ant.taskdefs;

import java.util.List;

import org.apache.tools.ant.Task;
import org.apache.tools.ant.taskdefs.Java;
import org.apache.tools.ant.types.CommandlineJava;
import org.apache.tools.ant.types.Environment.Variable;

import com.newmainsoftech.ant.types.ArgumentExtContract;
import com.newmainsoftech.ant.types.CommandlineJavaExt;
import com.newmainsoftech.ant.types.SysPropExt;

/**
 * Wrapper of Ant's {@link Java} class to allow multi-line arguments for application and JVM. 
* This overrides {@link Java#getCommandLine()} method to return {@link CommandlineJavaExt} object, * in order to accept multi-line arguments. *
    *
  • Usage example

    * Use javaext tag in Ant's target tag (what can be defined in * configuration tag of manve-antrun-plugin's execution tag as well * as in an Ant file). *
      *
    • To use multi-line arguments *
        *
      • For JVM arguments, use jvmargext tag *
        * * <javaext classname="com.newmainsoftech.ant.taskdefs.DummyAppForTestingJavaTaskExt">
        *     <jvmargext>
        *         -Xmx768m -Xss4M
        *         -javaagent:${agent_path}=nbjdk=JDK6u24;profile=java;
        *         -Xbootclasspath:${some_path}
        *     </jvmargext>
        *     ...
        * </javaext>
        *

        * This jvmargext tag is equivalent of:
        * *     <jvmarg value="-Xmx768m" />
        *     <jvmarg value="-Xss4M" />
        *     <jvmarg value="-javaagent:${agent_path}=nbjdk=JDK6u24;profile=java;" />
        *     <jvmarg value="-Xbootclasspath:${some_path}" />
        *
        *
        *
      • *
      • For arguments to target application, use argext tag *
        * * <javaext classname="com.newmainsoftech.ant.taskdefs.DummyAppForTestingJavaTaskExt">
        *     <argext>
        *         -Dmulti-line-arg1=argext1 -Dmulti-line-arg2=argext2
        *         -Dmulti-line-arg3=${arg3_value}
        *         "some other argument"
        *     </argext>
        *     ...
        * </javaext>
        *

        * This argext tag is equivalent of:
        * *     <arg value="-Dmulti-line-arg1=argext1" >
        *     <arg value="-Dmulti-line-arg2=argext2" >
        *     <arg value="-Dmulti-line-arg3=${arg3_value}" >
        *     <arg value="some other argument" >
        *
        *
        *
      • *
      • For system properties, use syspropext tag *
        * * <junitext>
        *     <syspropext>
        *         gwt.args=-standardsMode -war ${war_dir} -logLevel WARN
        *         java.awt.headless=true
        *         gwt.devjar=${com.google.gwt:gwt-dev:jar}
        *         java.util.logging.config.file=test/com/inetools/gwetons/client/devModeTest.logging.properties
        *     </syspropext>
        *     ...
        * </javaext>
        *

        * This syspropext tag is equivalent of:
        * *     <sysproperty
        *       key="gwt.args"
        *       value="-standardsMode -war ${war_dir} -logLevel WARN" />
        *     <sysproperty key="java.awt.headless" value="true" />
        *     <sysproperty key="gwt.devjar" value="${com.google.gwt:gwt-dev:jar}" />
        *     <sysproperty
        *       key="java.util.logging.config.file"
        *       value="test/com/inetools/gwetons/client/devModeTest.logging.properties" />
        *
        *
        *
      • *
      * Usage note: *
        *
      • Only one each of argext tag and jvmargext tag is supported within single * javaext tag.
        *
      • *
      • Each argument is extracted as delimited by white space(s) except the case that argument value * containing space(s) is surrounded by double quotation characters. *
      • *
      • As shown in the above examples, it also resolves ${property_name_or_reference_id} * token in each line in multiple-line arguments to actual value. Regarding that, please be advised * the following points: *
          *
        • Such expression will be resolved to actual string value even the expression is inside of * surrounding quotation characters. *
        • *
        • Effort of resolving property name and reference name to actual value will * be occurred recursively.
          * So, take the jvmargext example above, all arguments could be defined in single property * (let's say jvmargprop for now) then the text content of the jvmargext tag could be simply * stated as below and the ${agent_path} and ${some_path} property expressions would still be * resolved to actual property values. *
          * * <jvmargext>
          *     ${jvmargext}
          * </jvmargext>
          *
          *
          *
        • *
        *
      • *
      *
    • *
    * Of course, you can use the parameters of Ant's regular java tag with javaext * tag too. *
  • * *
  • Configuration

    *
      *
    1. Define path tag for this project's archive ant-util.jar file and sub-dependencies. *
        *
      • In the case of using maven-antrun-plugin and you can define com.newmainsoftech:ant-util:jar * as a dependency of maven-antrun-plugin, you can do like below.
        *
        * * <property
        *     name="plugin_classpath"
        *     refid="maven.plugin.classpath" />
        * <path id="antutil_path"
        *     path="${plugin_classpath}" /> *
        *
        *
      • *
      • If you cannot define com.newmainsoftech:ant-util:jar as a dependency of maven-antrun-plugin * in project's pom.xml, or the case of stand alone Ant environment, then you need to provide path to * com.newmainsoftech:ant-util:jar. And define path tag with that path: *
        * <path id="antutil_path"
        *     path="${lengthy_path_to_antutil_jar}" />
        *
        *
      • *
      *
    2. *
    3. Define taskdef tag for the ant-util's antlib.xml *
      * * <taskdef
      *     resource="com/newmainsoftech/ant/antlib.xml"
      *     classpathref="antutil_path" /> *
      *
      *
    4. *
    *
  • *
* * @author Arata Y. * @see CommandlineJavaExt */ public class JavaTaskExt extends Java { CommandlineJavaExt commandlineJavaExt = new CommandlineJavaExt(); public JavaTaskExt() { super(); } public JavaTaskExt( Task owner) { super( owner); } @Override public CommandlineJava getCommandLine() { return commandlineJavaExt; } public ArgumentExtContract createArgext() { return ((CommandlineJavaExt)getCommandLine()).createArgext(); } public ArgumentExtContract createJvmargext() { return ((CommandlineJavaExt)getCommandLine()).createVmargext(); } /** * To add system property parameters to command line being used at execution of java app. * * @param sysPropExt */ public void addConfiguredSysPropExt( SysPropExt sysPropExt) { List propertyList = sysPropExt.getEnvVarList(); CommandlineJava commandlineJava = getCommandLine(); for( Variable evnVar : propertyList) { commandlineJava.addSysproperty( evnVar); } // for } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy