[exec] How to ensure a subprocess ends with the parent application

2012-04-22 Thread Robert Heumüller
Hello,

this is my first post on the apache-commons mailing list - actually
it's my first venture into mailing lists in general :)

I currently use commons-exec in order to start instances of
avahi-browse and avahi-publish. Everything seems to work neatly
excepting the fact that avahi-publish does not quit when the
application ends (for example when I kill via stop button in eclipse).
How can I ensure that a subprocess started by exec is terminated when
the parent process dies? My code looks like this:

http://privatepaste.com/a6b0a35a3c

Thank you for your assistance

-
To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
For additional commands, e-mail: user-h...@commons.apache.org



[jexl] Unified jexl throws exception when processing white space in file

2012-04-22 Thread Clay Bruce
First off Thank you for the excellent library, it has been very useful
in my current project. 

However there are a couple of issues I have found.

 

Using UnifiedJexl with the following script will fail at line 2 and line
4 and line 5. 

Note: line numbers are only for reference, they are not in script 

 

1:report

2:

3:$$ var x = 2;

4:

5: $$ var y = 9;

7:/report

 

The offending code is the method startsWith which can be found at line
1345  in UnifiedJEXL.java

 

protected int startsWith(CharSequence sequence, CharSequence
pattern) {

int s = 0;

while (Character.isSpaceChar(sequence.charAt(s))) {

s += 1;

}

sequence = sequence.subSequence(s, sequence.length());

if (pattern.length() = sequence.length()

 sequence.subSequence(0,
pattern.length()).equals(pattern)) {

return s + pattern.length();

} else {

return -1;

}

}

 

Problem is that sequence is not tested to see if the index is available
before trying to access it.

 

 

Using this non optimized code fixes the issue:

 

protected int startsWith(CharSequence sequence, CharSequence
pattern) {



String tempString = sequence.toString();

int patternFoundAt =
tempString.indexOf(pattern.toString());

if(patternFoundAt != -1 ){

int result = patternFoundAt +
pattern.length();

if( result = sequence.length() )

return  -1;

else

return result;


}  

return patternFoundAt;

}

 

Code used to load the report is: 

String templatePath  =
template.rpt;

JexlEngine   engine  = new
JexlEngine();

UnifiedJEXL processor   = new UnifiedJEXL(engine);

Reader scriptReader   = new
FileReader(templatePath);

 

UnifiedJEXL.Template template =
PreProcessor.getInstance().prepareTemplate(scriptReader);

 

JexlContext context = new MapContext();

 

StringWriter preprocessed = new StringWriter();

template.evaluate(context, preprocessed );

 

 

This seems like a bug unless I am not using the library correctly?

Thank you once again for great library.

 

Clay

 

 

 

 

 

Clay Bruce

Web Developer

Quiktrak, Inc.

 

Direct Line:  503-214-3199

Private Fax:  800-998-4142

Toll-Free: 800-927-8725 x3199

 

 


 

 

The information contained in this electronic mail message is
confidential information intended only for the use of the individual or
entity named above, and may be privileged. If the reader of this message
is not the intended recipient or the employee or agent responsible to
deliver it to the intended recipient, you are hereby notified that any
dissemination, distribution or copying of this communication is strictly
prohibited. If you have received this communication in error, please
immediately notify us by telephone and delete the original message.
Thank You



Re: [configuration] Problem with XMLConfiguration.setProperty(String, Object) and setDelimiterParsingDisabled

2012-04-22 Thread Oliver Heger
Thank you for reporting this. I agree with you that the output of the 
configuration should be independent on the value of the delimiter 
parsing flag.


If you are convinced that this is an error, please open a ticket in our 
bug tracking system [1].


I hope to find some time in the next days to have a look at this issue.

Oliver

[1] http://commons.apache.org/configuration/issue-tracking.html

Am 22.04.2012 13:38, schrieb thc...@gmail.com:

Hi.

Sorry for the code not properly indented (content of DelimiterExample.java).

Here it goes again:

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.XMLConfiguration;

public class DelimiterExample
{
   // Configuration file that will have the
   // setDelimiterParsingDisabled as _false_.
   private static final String CONF_DELIMITER_ENABLED_XML =
 ConfDelimiterEnabled.xml;

   // Configuration file that will have the
   // setDelimiterParsingDisabled as_true_.
   private static final String CONF_DELIMITER_DISABLED_XML =
 ConfDelimiterDisabled.xml;

   // Key of the data used in the configuration files.
   private static final String LIST_ELEMENT_KEY = list.element;

   public static void main(String[] args) throws ConfigurationException
   {
 // Data that will be saved in the configuration files.
 ListString  data = new ArrayListString(3);
 data.add(value 1);
 data.add(value 2);
 data.add(value 3);


 // First using setDelimiterParsingDisabled as false.

 XMLConfiguration confDelimiterEnabledWrite =
   new XMLConfiguration(CONF_DELIMITER_ENABLED_XML);

 confDelimiterEnabledWrite.setProperty(LIST_ELEMENT_KEY, data);
 // Writes:
 //list
 //elementvalue 1/element
 //elementvalue 2/element
 //elementvalue 3/element
 ///list

 confDelimiterEnabledWrite.save();

 XMLConfiguration confDelimiterEnabledRead =
   new XMLConfiguration(CONF_DELIMITER_ENABLED_XML);
 String[] values =
   confDelimiterEnabledRead.getStringArray(LIST_ELEMENT_KEY);

 // Doesn't output anything as they are equals. Expected behaviour.
 if (!Arrays.equals(values, data.toArray()))
 {
   System.out.println(
 setDelimiterParsingDisabled(false): Data not equal!);
 }


 // Now using setDelimiterParsingDisabled as true.

 XMLConfiguration confDelimiterDisabledWrite = new XMLConfiguration();
 confDelimiterDisabledWrite.setDelimiterParsingDisabled(true);
 confDelimiterDisabledWrite.setFileName(CONF_DELIMITER_DISABLED_XML);
 confDelimiterDisabledWrite.load();

 confDelimiterDisabledWrite.setProperty(LIST_ELEMENT_KEY, data);
 // Writes:
 //list
 //element[value 1, value 2, value 3]/element
 ///list

 // Unexpected behaviour!
 // Shouldn't it write the same as with
 // setDelimiterParsingDisabled as false? as it is a list.

 confDelimiterDisabledWrite.save();

 XMLConfiguration confDelimiterDisabledRead = new XMLConfiguration();
 confDelimiterDisabledRead.setDelimiterParsingDisabled(true);
 confDelimiterDisabledRead.setFileName(CONF_DELIMITER_DISABLED_XML);
 confDelimiterDisabledRead.load();

 values = confDelimiterDisabledRead.getStringArray(LIST_ELEMENT_KEY);

 // As it writes other thing this will output that they are not equals.
 if (!Arrays.equals(values, data.toArray()))
 {
   System.out.println(
 setDelimiterParsingDisabled(true): Data not equal!);
 }
   }

}


Best regards.




-
To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
For additional commands, e-mail: user-h...@commons.apache.org



Re: [exec] How to ensure a subprocess ends with the parent application

2012-04-22 Thread Siegfried Goeschl

Hi Robert,

welcome at the Apache Commons mailing list  then ... :-)

Can you check out ProcessDestroyer and its implementation 
ShutdownHookProcessDestroyer - ShutdownHookProcessDestroyer 
registers a shutdown hook at JVM level and should do the trick in your 
case. Some test code is found at DefaultExecutorTest.java


Cheers,

Siegfried Goeschl


On 22.04.12 11:59, Robert Heumüller wrote:

Hello,

this is my first post on the apache-commons mailing list - actually
it's my first venture into mailing lists in general :)

I currently use commons-exec in order to start instances of
avahi-browse and avahi-publish. Everything seems to work neatly
excepting the fact that avahi-publish does not quit when the
application ends (for example when I kill via stop button in eclipse).
How can I ensure that a subprocess started by exec is terminated when
the parent process dies? My code looks like this:

http://privatepaste.com/a6b0a35a3c

Thank you for your assistance

-
To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
For additional commands, e-mail: user-h...@commons.apache.org



-
To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
For additional commands, e-mail: user-h...@commons.apache.org