@@ -22,6 +22,7 @@ import java.io.IOException; | |||
import com.sun.org.apache.bcel.internal.classfile.ClassParser; | |||
import com.sun.org.apache.bcel.internal.classfile.ConstantValue; | |||
import com.sun.org.apache.bcel.internal.classfile.Field; | |||
import com.sun.org.apache.bcel.internal.classfile.JavaClass; | |||
// CheckStyle:HideUtilityClassConstructorCheck OFF - bc | |||
@@ -40,7 +41,7 @@ public final class JavaClassHelper { | |||
* @return a StringBuffer contains the name=value pairs | |||
* @exception IOException if an error occurs | |||
*/ | |||
public static StringBuffer getConstants(byte[] bytes) | |||
public static StringBuffer getConstants(final byte[] bytes) | |||
throws IOException { | |||
final StringBuffer sb = new StringBuffer(); | |||
final ByteArrayInputStream bis = new ByteArrayInputStream(bytes); | |||
@@ -20,6 +20,7 @@ package org.apache.tools.ant.listener; | |||
import java.io.PrintStream; | |||
import org.apache.commons.logging.Log; | |||
import org.apache.commons.logging.LogConfigurationException; | |||
import org.apache.commons.logging.LogFactory; | |||
import org.apache.tools.ant.BuildEvent; | |||
@@ -29,7 +30,6 @@ import org.apache.tools.ant.Project; | |||
import org.apache.tools.ant.Task; | |||
import org.apache.tools.ant.UnknownElement; | |||
import sun.rmi.runtime.Log; | |||
/** | |||
* Jakarta Commons Logging listener. | |||
@@ -80,31 +80,31 @@ public class CommonsLoggingListener implements BuildListener, BuildLogger { | |||
suffix = suffix.replace(' ', '-'); | |||
cat = cat + "." + suffix; | |||
} | |||
PrintStream tmpOut = System.out; | |||
PrintStream tmpErr = System.err; | |||
final PrintStream tmpOut = System.out; | |||
final PrintStream tmpErr = System.err; | |||
System.setOut(out); | |||
System.setErr(err); | |||
if (!initialized) { | |||
try { | |||
logFactory = LogFactory.getFactory(); | |||
} catch (LogConfigurationException e) { | |||
} catch (final LogConfigurationException e) { | |||
e.printStackTrace(System.err); | |||
return null; | |||
} | |||
} | |||
initialized = true; | |||
Log log = logFactory.getInstance(cat); | |||
final Log log = logFactory.getInstance(cat); | |||
System.setOut(tmpOut); | |||
System.setErr(tmpErr); | |||
return log; | |||
} | |||
/** {@inheritDoc}. */ | |||
public void buildStarted(BuildEvent event) { | |||
String categoryString = PROJECT_LOG; | |||
Log log = getLog(categoryString, null); | |||
public void buildStarted(final BuildEvent event) { | |||
final String categoryString = PROJECT_LOG; | |||
final Log log = getLog(categoryString, null); | |||
if (initialized) { | |||
realLog(log, "Build started.", Project.MSG_INFO, null); | |||
@@ -112,10 +112,10 @@ public class CommonsLoggingListener implements BuildListener, BuildLogger { | |||
} | |||
/** {@inheritDoc}. */ | |||
public void buildFinished(BuildEvent event) { | |||
public void buildFinished(final BuildEvent event) { | |||
if (initialized) { | |||
String categoryString = PROJECT_LOG; | |||
Log log = getLog(categoryString, event.getProject().getName()); | |||
final String categoryString = PROJECT_LOG; | |||
final Log log = getLog(categoryString, event.getProject().getName()); | |||
if (event.getException() == null) { | |||
realLog(log, "Build finished.", Project.MSG_INFO, null); | |||
@@ -130,9 +130,9 @@ public class CommonsLoggingListener implements BuildListener, BuildLogger { | |||
* @see BuildListener#targetStarted | |||
*/ | |||
/** {@inheritDoc}. */ | |||
public void targetStarted(BuildEvent event) { | |||
public void targetStarted(final BuildEvent event) { | |||
if (initialized) { | |||
Log log = getLog(TARGET_LOG, | |||
final Log log = getLog(TARGET_LOG, | |||
event.getTarget().getName()); | |||
// Since task log category includes target, we don't really | |||
// need this message | |||
@@ -145,10 +145,10 @@ public class CommonsLoggingListener implements BuildListener, BuildLogger { | |||
* @see BuildListener#targetFinished | |||
*/ | |||
/** {@inheritDoc}. */ | |||
public void targetFinished(BuildEvent event) { | |||
public void targetFinished(final BuildEvent event) { | |||
if (initialized) { | |||
String targetName = event.getTarget().getName(); | |||
Log log = getLog(TARGET_LOG, | |||
final String targetName = event.getTarget().getName(); | |||
final Log log = getLog(TARGET_LOG, | |||
event.getTarget().getName()); | |||
if (event.getException() == null) { | |||
realLog(log, "Target end: " + targetName, Project.MSG_DEBUG, null); | |||
@@ -164,17 +164,17 @@ public class CommonsLoggingListener implements BuildListener, BuildLogger { | |||
* @see BuildListener#taskStarted | |||
*/ | |||
/** {@inheritDoc}. */ | |||
public void taskStarted(BuildEvent event) { | |||
public void taskStarted(final BuildEvent event) { | |||
if (initialized) { | |||
Task task = event.getTask(); | |||
final Task task = event.getTask(); | |||
Object real = task; | |||
if (task instanceof UnknownElement) { | |||
Object realObj = ((UnknownElement) task).getTask(); | |||
final Object realObj = ((UnknownElement) task).getTask(); | |||
if (realObj != null) { | |||
real = realObj; | |||
} | |||
} | |||
Log log = getLog(real.getClass().getName(), null); | |||
final Log log = getLog(real.getClass().getName(), null); | |||
if (log.isTraceEnabled()) { | |||
realLog(log, "Task \"" + task.getTaskName() + "\" started ", | |||
Project.MSG_VERBOSE, null); | |||
@@ -186,17 +186,17 @@ public class CommonsLoggingListener implements BuildListener, BuildLogger { | |||
* @see BuildListener#taskFinished | |||
*/ | |||
/** {@inheritDoc}. */ | |||
public void taskFinished(BuildEvent event) { | |||
public void taskFinished(final BuildEvent event) { | |||
if (initialized) { | |||
Task task = event.getTask(); | |||
final Task task = event.getTask(); | |||
Object real = task; | |||
if (task instanceof UnknownElement) { | |||
Object realObj = ((UnknownElement) task).getTask(); | |||
final Object realObj = ((UnknownElement) task).getTask(); | |||
if (realObj != null) { | |||
real = realObj; | |||
} | |||
} | |||
Log log = getLog(real.getClass().getName(), null); | |||
final Log log = getLog(real.getClass().getName(), null); | |||
if (event.getException() == null) { | |||
if (log.isTraceEnabled()) { | |||
realLog(log, "Task \"" + task.getTaskName() + "\" finished.", | |||
@@ -215,7 +215,7 @@ public class CommonsLoggingListener implements BuildListener, BuildLogger { | |||
* @see BuildListener#messageLogged | |||
*/ | |||
/** {@inheritDoc}. */ | |||
public void messageLogged(BuildEvent event) { | |||
public void messageLogged(final BuildEvent event) { | |||
if (initialized) { | |||
Object categoryObject = event.getTask(); | |||
String categoryString = null; | |||
@@ -242,16 +242,16 @@ public class CommonsLoggingListener implements BuildListener, BuildLogger { | |||
} | |||
Log log = getLog(categoryString, categoryDetail); | |||
int priority = event.getPriority(); | |||
String message = event.getMessage(); | |||
final Log log = getLog(categoryString, categoryDetail); | |||
final int priority = event.getPriority(); | |||
final String message = event.getMessage(); | |||
realLog(log, message, priority , null); | |||
} | |||
} | |||
private void realLog(Log log, String message, int priority, Throwable t) { | |||
PrintStream tmpOut = System.out; | |||
PrintStream tmpErr = System.err; | |||
private void realLog(final Log log, final String message, final int priority, final Throwable t) { | |||
final PrintStream tmpOut = System.out; | |||
final PrintStream tmpErr = System.err; | |||
System.setOut(out); | |||
System.setErr(err); | |||
switch (priority) { | |||
@@ -300,7 +300,7 @@ public class CommonsLoggingListener implements BuildListener, BuildLogger { | |||
* This is not used, the logger config is used instead. | |||
* @param level ignored | |||
*/ | |||
public void setMessageOutputLevel(int level) { | |||
public void setMessageOutputLevel(final int level) { | |||
// Use the logger config | |||
} | |||
@@ -308,7 +308,7 @@ public class CommonsLoggingListener implements BuildListener, BuildLogger { | |||
* Set the output print stream. | |||
* @param output the output stream | |||
*/ | |||
public void setOutputPrintStream(PrintStream output) { | |||
public void setOutputPrintStream(final PrintStream output) { | |||
this.out = output; | |||
} | |||
@@ -317,7 +317,7 @@ public class CommonsLoggingListener implements BuildListener, BuildLogger { | |||
* This is ignored. | |||
* @param emacsMode ignored | |||
*/ | |||
public void setEmacsMode(boolean emacsMode) { | |||
public void setEmacsMode(final boolean emacsMode) { | |||
// Doesn't make sense for c-l. Use the logger config | |||
} | |||
@@ -325,7 +325,7 @@ public class CommonsLoggingListener implements BuildListener, BuildLogger { | |||
* Set the error print stream. | |||
* @param err the error stream | |||
*/ | |||
public void setErrorPrintStream(PrintStream err) { | |||
public void setErrorPrintStream(final PrintStream err) { | |||
this.err = err; | |||
} | |||
@@ -18,6 +18,7 @@ | |||
package org.apache.tools.ant.listener; | |||
import org.apache.log4j.Logger; | |||
import org.apache.log4j.helpers.NullEnumeration; | |||
import org.apache.tools.ant.BuildEvent; | |||
import org.apache.tools.ant.BuildListener; | |||
@@ -44,8 +45,8 @@ public class Log4jListener implements BuildListener { | |||
* Construct the listener and make sure there is a valid appender. | |||
*/ | |||
public Log4jListener() { | |||
Logger log = Logger.getLogger(LOG_ANT); | |||
Logger rootLog = Logger.getRootLogger(); | |||
final Logger log = Logger.getLogger(LOG_ANT); | |||
final Logger rootLog = Logger.getRootLogger(); | |||
initialized = !(rootLog.getAllAppenders() instanceof NullEnumeration); | |||
if (!initialized) { | |||
log.error("No log4j.properties in build area"); | |||
@@ -56,9 +57,9 @@ public class Log4jListener implements BuildListener { | |||
* @see BuildListener#buildStarted | |||
*/ | |||
/** {@inheritDoc}. */ | |||
public void buildStarted(BuildEvent event) { | |||
public void buildStarted(final BuildEvent event) { | |||
if (initialized) { | |||
Logger log = Logger.getLogger(Project.class.getName()); | |||
final Logger log = Logger.getLogger(Project.class.getName()); | |||
log.info("Build started."); | |||
} | |||
} | |||
@@ -67,9 +68,9 @@ public class Log4jListener implements BuildListener { | |||
* @see BuildListener#buildFinished | |||
*/ | |||
/** {@inheritDoc}. */ | |||
public void buildFinished(BuildEvent event) { | |||
public void buildFinished(final BuildEvent event) { | |||
if (initialized) { | |||
Logger log = Logger.getLogger(Project.class.getName()); | |||
final Logger log = Logger.getLogger(Project.class.getName()); | |||
if (event.getException() == null) { | |||
log.info("Build finished."); | |||
} else { | |||
@@ -82,9 +83,9 @@ public class Log4jListener implements BuildListener { | |||
* @see BuildListener#targetStarted | |||
*/ | |||
/** {@inheritDoc}. */ | |||
public void targetStarted(BuildEvent event) { | |||
public void targetStarted(final BuildEvent event) { | |||
if (initialized) { | |||
Logger log = Logger.getLogger(Target.class.getName()); | |||
final Logger log = Logger.getLogger(Target.class.getName()); | |||
log.info("Target \"" + event.getTarget().getName() + "\" started."); | |||
} | |||
} | |||
@@ -93,10 +94,10 @@ public class Log4jListener implements BuildListener { | |||
* @see BuildListener#targetFinished | |||
*/ | |||
/** {@inheritDoc}. */ | |||
public void targetFinished(BuildEvent event) { | |||
public void targetFinished(final BuildEvent event) { | |||
if (initialized) { | |||
String targetName = event.getTarget().getName(); | |||
Logger cat = Logger.getLogger(Target.class.getName()); | |||
final String targetName = event.getTarget().getName(); | |||
final Logger cat = Logger.getLogger(Target.class.getName()); | |||
if (event.getException() == null) { | |||
cat.info("Target \"" + targetName + "\" finished."); | |||
} else { | |||
@@ -110,10 +111,10 @@ public class Log4jListener implements BuildListener { | |||
* @see BuildListener#taskStarted | |||
*/ | |||
/** {@inheritDoc}. */ | |||
public void taskStarted(BuildEvent event) { | |||
public void taskStarted(final BuildEvent event) { | |||
if (initialized) { | |||
Task task = event.getTask(); | |||
Logger log = Logger.getLogger(task.getClass().getName()); | |||
final Task task = event.getTask(); | |||
final Logger log = Logger.getLogger(task.getClass().getName()); | |||
log.info("Task \"" + task.getTaskName() + "\" started."); | |||
} | |||
} | |||
@@ -122,10 +123,10 @@ public class Log4jListener implements BuildListener { | |||
* @see BuildListener#taskFinished | |||
*/ | |||
/** {@inheritDoc}. */ | |||
public void taskFinished(BuildEvent event) { | |||
public void taskFinished(final BuildEvent event) { | |||
if (initialized) { | |||
Task task = event.getTask(); | |||
Logger log = Logger.getLogger(task.getClass().getName()); | |||
final Task task = event.getTask(); | |||
final Logger log = Logger.getLogger(task.getClass().getName()); | |||
if (event.getException() == null) { | |||
log.info("Task \"" + task.getTaskName() + "\" finished."); | |||
} else { | |||
@@ -139,7 +140,7 @@ public class Log4jListener implements BuildListener { | |||
* @see BuildListener#messageLogged | |||
*/ | |||
/** {@inheritDoc}. */ | |||
public void messageLogged(BuildEvent event) { | |||
public void messageLogged(final BuildEvent event) { | |||
if (initialized) { | |||
Object categoryObject = event.getTask(); | |||
if (categoryObject == null) { | |||
@@ -149,7 +150,7 @@ public class Log4jListener implements BuildListener { | |||
} | |||
} | |||
Logger log | |||
final Logger log | |||
= Logger.getLogger(categoryObject.getClass().getName()); | |||
switch (event.getPriority()) { | |||
case Project.MSG_ERR: | |||
@@ -25,7 +25,6 @@ import java.io.InputStream; | |||
import java.io.OutputStream; | |||
import java.io.PrintStream; | |||
import java.io.UnsupportedEncodingException; | |||
import java.net.PasswordAuthentication; | |||
import java.security.Provider; | |||
import java.security.Security; | |||
import java.util.Enumeration; | |||
@@ -37,19 +36,23 @@ import java.util.Vector; | |||
import javax.activation.DataHandler; | |||
import javax.activation.FileDataSource; | |||
import javax.mail.Address; | |||
import javax.mail.Authenticator; | |||
import javax.mail.Message; | |||
import javax.mail.MessagingException; | |||
import javax.mail.PasswordAuthentication; | |||
import javax.mail.SendFailedException; | |||
import javax.mail.Session; | |||
import javax.mail.Transport; | |||
import javax.mail.internet.AddressException; | |||
import javax.mail.internet.InternetAddress; | |||
import javax.mail.internet.MimeBodyPart; | |||
import javax.mail.internet.MimeMessage; | |||
import javax.mail.internet.MimeMultipart; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.Project; | |||
import sun.rmi.transport.Transport; | |||
import com.sun.xml.internal.messaging.saaj.packaging.mime.MessagingException; | |||
import com.sun.xml.internal.messaging.saaj.packaging.mime.internet.MimeBodyPart; | |||
import com.sun.xml.internal.messaging.saaj.packaging.mime.internet.MimeMultipart; | |||
/** | |||
* Uses the JavaMail classes to send Mime format email. | |||
@@ -83,7 +86,7 @@ public class MimeMailer extends Mailer { | |||
throw new IOException("No data"); | |||
} | |||
if (out != null) { | |||
String encodedOut = out.toString(charset); | |||
final String encodedOut = out.toString(charset); | |||
data = (data != null) ? data.concat(encodedOut) : encodedOut; | |||
out = null; | |||
} | |||
@@ -95,7 +98,7 @@ public class MimeMailer extends Mailer { | |||
return out; | |||
} | |||
public void setContentType(String type) { | |||
public void setContentType(final String type) { | |||
this.type = type.toLowerCase(Locale.ENGLISH); | |||
} | |||
@@ -113,7 +116,7 @@ public class MimeMailer extends Mailer { | |||
return "StringDataSource"; | |||
} | |||
public void setCharset(String charset) { | |||
public void setCharset(final String charset) { | |||
this.charset = charset; | |||
} | |||
@@ -129,7 +132,7 @@ public class MimeMailer extends Mailer { | |||
*/ | |||
public void send() { | |||
try { | |||
Properties props = new Properties(); | |||
final Properties props = new Properties(); | |||
props.put("mail.smtp.host", host); | |||
props.put("mail.smtp.port", String.valueOf(port)); | |||
@@ -141,10 +144,10 @@ public class MimeMailer extends Mailer { | |||
Authenticator auth = null; | |||
if (SSL) { | |||
try { | |||
Provider p = (Provider) Class.forName( | |||
final Provider p = (Provider) Class.forName( | |||
"com.sun.net.ssl.internal.ssl.Provider").newInstance(); | |||
Security.addProvider(p); | |||
} catch (Exception e) { | |||
} catch (final Exception e) { | |||
throw new BuildException("could not instantiate ssl " | |||
+ "security provider, check that you have JSSE in " | |||
+ "your classpath"); | |||
@@ -169,8 +172,8 @@ public class MimeMailer extends Mailer { | |||
sesh = Session.getInstance(props, auth); | |||
//create the message | |||
MimeMessage msg = new MimeMessage(sesh); | |||
MimeMultipart attachments = new MimeMultipart(); | |||
final MimeMessage msg = new MimeMessage(sesh); | |||
final MimeMultipart attachments = new MimeMultipart(); | |||
//set the sender | |||
if (from.getName() == null) { | |||
@@ -204,7 +207,7 @@ public class MimeMailer extends Mailer { | |||
} | |||
} | |||
// Using javax.activation.DataSource paradigm | |||
StringDataSource sds = new StringDataSource(); | |||
final StringDataSource sds = new StringDataSource(); | |||
sds.setContentType(message.getMimeType()); | |||
sds.setCharset(charset); | |||
@@ -214,23 +217,23 @@ public class MimeMailer extends Mailer { | |||
msg.addHeader("Date", getDate()); | |||
if (headers != null) { | |||
for (Iterator iter = headers.iterator(); iter.hasNext();) { | |||
Header h = (Header) iter.next(); | |||
for (final Iterator iter = headers.iterator(); iter.hasNext();) { | |||
final Header h = (Header) iter.next(); | |||
msg.addHeader(h.getName(), h.getValue()); | |||
} | |||
} | |||
PrintStream out = new PrintStream(sds.getOutputStream()); | |||
final PrintStream out = new PrintStream(sds.getOutputStream()); | |||
message.print(out); | |||
out.close(); | |||
MimeBodyPart textbody = new MimeBodyPart(); | |||
final MimeBodyPart textbody = new MimeBodyPart(); | |||
textbody.setDataHandler(new DataHandler(sds)); | |||
attachments.addBodyPart(textbody); | |||
Enumeration e = files.elements(); | |||
final Enumeration e = files.elements(); | |||
while (e.hasMoreElements()) { | |||
File file = (File) e.nextElement(); | |||
final File file = (File) e.nextElement(); | |||
MimeBodyPart body; | |||
@@ -240,8 +243,8 @@ public class MimeMailer extends Mailer { | |||
+ "\" does not exist or is not " | |||
+ "readable."); | |||
} | |||
FileDataSource fileData = new FileDataSource(file); | |||
DataHandler fileDataHandler = new DataHandler(fileData); | |||
final FileDataSource fileData = new FileDataSource(file); | |||
final DataHandler fileDataHandler = new DataHandler(fileData); | |||
body.setDataHandler(fileDataHandler); | |||
body.setFileName(file.getName()); | |||
@@ -250,10 +253,10 @@ public class MimeMailer extends Mailer { | |||
msg.setContent(attachments); | |||
try { | |||
// Send the message using SMTP, or SMTPS if the host uses SSL | |||
Transport transport = sesh.getTransport(SSL ? "smtps" : "smtp"); | |||
final Transport transport = sesh.getTransport(SSL ? "smtps" : "smtp"); | |||
transport.connect(host, user, password); | |||
transport.sendMessage(msg, msg.getAllRecipients()); | |||
} catch (SendFailedException sfe) { | |||
} catch (final SendFailedException sfe) { | |||
if (!shouldIgnoreInvalidRecipients()) { | |||
throw new BuildException(GENERIC_ERROR, sfe); | |||
} else if (sfe.getValidSentAddresses() == null | |||
@@ -277,22 +280,22 @@ public class MimeMailer extends Mailer { | |||
} | |||
} | |||
} | |||
} catch (MessagingException e) { | |||
} catch (final MessagingException e) { | |||
throw new BuildException(GENERIC_ERROR, e); | |||
} catch (IOException e) { | |||
} catch (final IOException e) { | |||
throw new BuildException(GENERIC_ERROR, e); | |||
} | |||
} | |||
private static InternetAddress[] internetAddresses(Vector list) | |||
private static InternetAddress[] internetAddresses(final Vector list) | |||
throws AddressException, UnsupportedEncodingException { | |||
final int size = list.size(); | |||
InternetAddress[] addrs = new InternetAddress[size]; | |||
final InternetAddress[] addrs = new InternetAddress[size]; | |||
for (int i = 0; i < size; ++i) { | |||
EmailAddress addr = (EmailAddress) list.elementAt(i); | |||
final EmailAddress addr = (EmailAddress) list.elementAt(i); | |||
String name = addr.getName(); | |||
final String name = addr.getName(); | |||
addrs[i] = (name == null) | |||
? new InternetAddress(addr.getAddress()) | |||
: new InternetAddress(addr.getAddress(), name); | |||
@@ -300,23 +303,23 @@ public class MimeMailer extends Mailer { | |||
return addrs; | |||
} | |||
private String parseCharSetFromMimeType(String type) { | |||
private String parseCharSetFromMimeType(final String type) { | |||
if (type == null) { | |||
return null; | |||
} | |||
int pos = type.indexOf("charset"); | |||
final int pos = type.indexOf("charset"); | |||
if (pos < 0) { | |||
return null; | |||
} | |||
// Assuming mime type in form "text/XXXX; charset=XXXXXX" | |||
StringTokenizer token = new StringTokenizer(type.substring(pos), "=; "); | |||
final StringTokenizer token = new StringTokenizer(type.substring(pos), "=; "); | |||
token.nextToken(); // Skip 'charset=' | |||
return token.nextToken(); | |||
} | |||
private void didntReach(Address addr, String category, | |||
MessagingException ex) { | |||
String msg = "Failed to send mail to " + category + " address " | |||
private void didntReach(final Address addr, final String category, | |||
final MessagingException ex) { | |||
final String msg = "Failed to send mail to " + category + " address " | |||
+ addr + " because of " + ex.getMessage(); | |||
if (task != null) { | |||
task.log(msg, Project.MSG_WARN); | |||
@@ -328,12 +331,11 @@ public class MimeMailer extends Mailer { | |||
static class SimpleAuthenticator extends Authenticator { | |||
private String user = null; | |||
private String password = null; | |||
public SimpleAuthenticator(String user, String password) { | |||
public SimpleAuthenticator(final String user, final String password) { | |||
this.user = user; | |||
this.password = password; | |||
} | |||
public PasswordAuthentication getPasswordAuthentication() { | |||
return new PasswordAuthentication(user, password); | |||
} | |||
} | |||
@@ -26,8 +26,8 @@ import javax.xml.transform.Transformer; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.taskdefs.XSLTProcess; | |||
import org.apache.xalan.trace.PrintTraceListener; | |||
import org.apache.xalan.transformer.TransformerImpl; | |||
import com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl; | |||
/** | |||
* Sets up trace support for a given transformer. | |||
@@ -35,11 +35,11 @@ import com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl; | |||
* @since Ant 1.8.0 | |||
*/ | |||
public class Xalan2TraceSupport implements XSLTTraceSupport { | |||
public void configureTrace(Transformer t, | |||
XSLTProcess.TraceConfiguration conf) { | |||
public void configureTrace(final Transformer t, | |||
final XSLTProcess.TraceConfiguration conf) { | |||
if (t instanceof TransformerImpl && conf != null) { | |||
PrintWriter w = new PrintWriter(conf.getOutputStream(), false); | |||
PrintTraceListener tl = new PrintTraceListener(w); | |||
final PrintWriter w = new PrintWriter(conf.getOutputStream(), false); | |||
final PrintTraceListener tl = new PrintTraceListener(w); | |||
tl.m_traceElements = conf.getElements(); | |||
tl.m_traceExtension = conf.getExtension(); | |||
tl.m_traceGeneration = conf.getGeneration(); | |||
@@ -47,7 +47,7 @@ public class Xalan2TraceSupport implements XSLTTraceSupport { | |||
tl.m_traceTemplates = conf.getTemplates(); | |||
try { | |||
((TransformerImpl) t).getTraceManager().addTraceListener(tl); | |||
} catch (TooManyListenersException tml) { | |||
} catch (final TooManyListenersException tml) { | |||
throw new BuildException(tml); | |||
} | |||
} | |||
@@ -61,7 +61,7 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan | |||
private static DocumentBuilder getDocumentBuilder() { | |||
try { | |||
return DocumentBuilderFactory.newInstance().newDocumentBuilder(); | |||
} catch (Exception exc) { | |||
} catch (final Exception exc) { | |||
throw new ExceptionInInitializerError(exc); | |||
} | |||
} | |||
@@ -70,10 +70,12 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan | |||
* The XML document. | |||
*/ | |||
private Document doc; | |||
/** | |||
* The wrapper for the whole testsuite. | |||
*/ | |||
private Element rootElement; | |||
/** | |||
* Element for the current test. | |||
* | |||
@@ -82,23 +84,25 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan | |||
* so we can't easily match Test objects without manually iterating over all keys and checking | |||
* individual fields. | |||
*/ | |||
private Hashtable<String, Element> testElements = new Hashtable<String, Element>(); | |||
private final Hashtable<String, Element> testElements = new Hashtable<String, Element>(); | |||
/** | |||
* tests that failed. | |||
*/ | |||
private Hashtable failedTests = new Hashtable(); | |||
private final Hashtable failedTests = new Hashtable(); | |||
/** | |||
* Tests that were skipped. | |||
*/ | |||
private Hashtable<String, Test> skippedTests = new Hashtable<String, Test>(); | |||
private final Hashtable<String, Test> skippedTests = new Hashtable<String, Test>(); | |||
/** | |||
* Tests that were ignored. See the note above about the key being a bit of a hack. | |||
*/ | |||
private Hashtable<String, Test> ignoredTests = new Hashtable<String, Test>(); | |||
private final Hashtable<String, Test> ignoredTests = new Hashtable<String, Test>(); | |||
/** | |||
* Timing helper. | |||
*/ | |||
private Hashtable<String, Long> testStarts = new Hashtable<String, Long>(); | |||
private final Hashtable<String, Long> testStarts = new Hashtable<String, Long>(); | |||
/** | |||
* Where to write the log to. | |||
*/ | |||
@@ -109,17 +113,17 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan | |||
} | |||
/** {@inheritDoc}. */ | |||
public void setOutput(OutputStream out) { | |||
public void setOutput(final OutputStream out) { | |||
this.out = out; | |||
} | |||
/** {@inheritDoc}. */ | |||
public void setSystemOutput(String out) { | |||
public void setSystemOutput(final String out) { | |||
formatOutput(SYSTEM_OUT, out); | |||
} | |||
/** {@inheritDoc}. */ | |||
public void setSystemError(String out) { | |||
public void setSystemError(final String out) { | |||
formatOutput(SYSTEM_ERR, out); | |||
} | |||
@@ -127,10 +131,10 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan | |||
* The whole testsuite started. | |||
* @param suite the testsuite. | |||
*/ | |||
public void startTestSuite(JUnitTest suite) { | |||
public void startTestSuite(final JUnitTest suite) { | |||
doc = getDocumentBuilder().newDocument(); | |||
rootElement = doc.createElement(TESTSUITE); | |||
String n = suite.getName(); | |||
final String n = suite.getName(); | |||
rootElement.setAttribute(ATTR_NAME, n == null ? UNKNOWN : n); | |||
//add the timestamp | |||
@@ -141,14 +145,14 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan | |||
rootElement.setAttribute(HOSTNAME, getHostname()); | |||
// Output properties | |||
Element propsElement = doc.createElement(PROPERTIES); | |||
final Element propsElement = doc.createElement(PROPERTIES); | |||
rootElement.appendChild(propsElement); | |||
Properties props = suite.getProperties(); | |||
final Properties props = suite.getProperties(); | |||
if (props != null) { | |||
Enumeration e = props.propertyNames(); | |||
final Enumeration e = props.propertyNames(); | |||
while (e.hasMoreElements()) { | |||
String name = (String) e.nextElement(); | |||
Element propElement = doc.createElement(PROPERTY); | |||
final String name = (String) e.nextElement(); | |||
final Element propElement = doc.createElement(PROPERTY); | |||
propElement.setAttribute(ATTR_NAME, name); | |||
propElement.setAttribute(ATTR_VALUE, props.getProperty(name)); | |||
propsElement.appendChild(propElement); | |||
@@ -163,11 +167,11 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan | |||
private String getHostname() { | |||
String hostname = "localhost"; | |||
try { | |||
InetAddress localHost = InetAddress.getLocalHost(); | |||
final InetAddress localHost = InetAddress.getLocalHost(); | |||
if (localHost != null) { | |||
hostname = localHost.getHostName(); | |||
} | |||
} catch (UnknownHostException e) { | |||
} catch (final UnknownHostException e) { | |||
// fall back to default 'localhost' | |||
} | |||
return hostname; | |||
@@ -178,7 +182,7 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan | |||
* @param suite the testsuite. | |||
* @throws BuildException on error. | |||
*/ | |||
public void endTestSuite(JUnitTest suite) throws BuildException { | |||
public void endTestSuite(final JUnitTest suite) throws BuildException { | |||
rootElement.setAttribute(ATTR_TESTS, "" + suite.runCount()); | |||
rootElement.setAttribute(ATTR_FAILURES, "" + suite.failureCount()); | |||
rootElement.setAttribute(ATTR_ERRORS, "" + suite.errorCount()); | |||
@@ -191,13 +195,13 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan | |||
wri = new BufferedWriter(new OutputStreamWriter(out, "UTF8")); | |||
wri.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"); | |||
(new DOMElementWriter()).write(rootElement, wri, 0, " "); | |||
} catch (IOException exc) { | |||
} catch (final IOException exc) { | |||
throw new BuildException("Unable to write log file", exc); | |||
} finally { | |||
if (wri != null) { | |||
try { | |||
wri.flush(); | |||
} catch (IOException ex) { | |||
} catch (final IOException ex) { | |||
// ignore | |||
} | |||
} | |||
@@ -214,11 +218,11 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan | |||
* <p>A new Test is started. | |||
* @param t the test. | |||
*/ | |||
public void startTest(Test t) { | |||
public void startTest(final Test t) { | |||
testStarts.put(createDescription(t), System.currentTimeMillis()); | |||
} | |||
private static String createDescription(Test test) throws BuildException { | |||
private static String createDescription(final Test test) throws BuildException { | |||
return JUnitVersionHelper.getTestCaseName(test) + "(" + JUnitVersionHelper.getTestCaseClassName(test) + ")"; | |||
} | |||
@@ -228,8 +232,8 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan | |||
* <p>A Test is finished. | |||
* @param test the test. | |||
*/ | |||
public void endTest(Test test) { | |||
String testDescription = createDescription(test); | |||
public void endTest(final Test test) { | |||
final String testDescription = createDescription(test); | |||
// Fix for bug #5637 - if a junit.extensions.TestSetup is | |||
// used and throws an exception during setUp then startTest | |||
@@ -240,7 +244,7 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan | |||
Element currentTest; | |||
if (!failedTests.containsKey(test) && !skippedTests.containsKey(testDescription) && !ignoredTests.containsKey(testDescription)) { | |||
currentTest = doc.createElement(TESTCASE); | |||
String n = JUnitVersionHelper.getTestCaseName(test); | |||
final String n = JUnitVersionHelper.getTestCaseName(test); | |||
currentTest.setAttribute(ATTR_NAME, | |||
n == null ? UNKNOWN : n); | |||
// a TestSuite can contain Tests from multiple classes, | |||
@@ -253,7 +257,7 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan | |||
currentTest = testElements.get(testDescription); | |||
} | |||
Long l = testStarts.get(createDescription(test)); | |||
final Long l = testStarts.get(createDescription(test)); | |||
currentTest.setAttribute(ATTR_TIME, | |||
"" + ((System.currentTimeMillis() - l) / ONE_SECOND)); | |||
} | |||
@@ -265,7 +269,7 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan | |||
* @param test the test. | |||
* @param t the exception. | |||
*/ | |||
public void addFailure(Test test, Throwable t) { | |||
public void addFailure(final Test test, final Throwable t) { | |||
formatError(FAILURE, test, t); | |||
} | |||
@@ -276,7 +280,7 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan | |||
* @param test the test. | |||
* @param t the assertion. | |||
*/ | |||
public void addFailure(Test test, AssertionFailedError t) { | |||
public void addFailure(final Test test, final AssertionFailedError t) { | |||
addFailure(test, (Throwable) t); | |||
} | |||
@@ -287,17 +291,17 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan | |||
* @param test the test. | |||
* @param t the error. | |||
*/ | |||
public void addError(Test test, Throwable t) { | |||
public void addError(final Test test, final Throwable t) { | |||
formatError(ERROR, test, t); | |||
} | |||
private void formatError(String type, Test test, Throwable t) { | |||
private void formatError(final String type, final Test test, final Throwable t) { | |||
if (test != null) { | |||
endTest(test); | |||
failedTests.put(test, test); | |||
} | |||
Element nested = doc.createElement(type); | |||
final Element nested = doc.createElement(type); | |||
Element currentTest; | |||
if (test != null) { | |||
currentTest = testElements.get(createDescription(test)); | |||
@@ -307,24 +311,24 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan | |||
currentTest.appendChild(nested); | |||
String message = t.getMessage(); | |||
final String message = t.getMessage(); | |||
if (message != null && message.length() > 0) { | |||
nested.setAttribute(ATTR_MESSAGE, t.getMessage()); | |||
} | |||
nested.setAttribute(ATTR_TYPE, t.getClass().getName()); | |||
String strace = JUnitTestRunner.getFilteredTrace(t); | |||
Text trace = doc.createTextNode(strace); | |||
final String strace = JUnitTestRunner.getFilteredTrace(t); | |||
final Text trace = doc.createTextNode(strace); | |||
nested.appendChild(trace); | |||
} | |||
private void formatOutput(String type, String output) { | |||
Element nested = doc.createElement(type); | |||
private void formatOutput(final String type, final String output) { | |||
final Element nested = doc.createElement(type); | |||
rootElement.appendChild(nested); | |||
nested.appendChild(doc.createCDATASection(output)); | |||
} | |||
public void testIgnored(Test test) { | |||
public void testIgnored(final Test test) { | |||
formatSkip(test, JUnitVersionHelper.getIgnoreMessage(test)); | |||
if (test != null) { | |||
ignoredTests.put(createDescription(test), test); | |||
@@ -332,12 +336,12 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan | |||
} | |||
public void formatSkip(Test test, String message) { | |||
public void formatSkip(final Test test, final String message) { | |||
if (test != null) { | |||
endTest(test); | |||
} | |||
Element nested = doc.createElement("skipped"); | |||
final Element nested = doc.createElement("skipped"); | |||
if (message != null) { | |||
nested.setAttribute("message", message); | |||
@@ -354,7 +358,7 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan | |||
} | |||
public void testAssumptionFailure(Test test, Throwable failure) { | |||
public void testAssumptionFailure(final Test test, final Throwable failure) { | |||
formatSkip(test, failure.getMessage()); | |||
skippedTests.put(createDescription(test), test); | |||
@@ -25,9 +25,11 @@ import java.text.NumberFormat; | |||
import org.apache.tools.ant.BuildException; | |||
import com.jcraft.jsch.Channel; | |||
import com.jcraft.jsch.ChannelExec; | |||
import com.jcraft.jsch.ChannelSftp; | |||
import com.jcraft.jsch.JSchException; | |||
import com.jcraft.jsch.Session; | |||
import com.jcraft.jsch.SftpProgressMonitor; | |||
/** | |||
@@ -36,10 +38,10 @@ import com.jcraft.jsch.SftpProgressMonitor; | |||
public abstract class AbstractSshMessage { | |||
private static final double ONE_SECOND = 1000.0; | |||
private Session session; | |||
private boolean verbose; | |||
private final Session session; | |||
private final boolean verbose; | |||
private LogListener listener = new LogListener() { | |||
public void log(String message) { | |||
public void log(final String message) { | |||
// do nothing; | |||
} | |||
}; | |||
@@ -48,7 +50,7 @@ public abstract class AbstractSshMessage { | |||
* Constructor for AbstractSshMessage | |||
* @param session the ssh session to use | |||
*/ | |||
public AbstractSshMessage(Session session) { | |||
public AbstractSshMessage(final Session session) { | |||
this(false, session); | |||
} | |||
@@ -58,7 +60,7 @@ public abstract class AbstractSshMessage { | |||
* @param session the ssh session to use | |||
* @since Ant 1.6.2 | |||
*/ | |||
public AbstractSshMessage(boolean verbose, Session session) { | |||
public AbstractSshMessage(final boolean verbose, final Session session) { | |||
this.verbose = verbose; | |||
this.session = session; | |||
} | |||
@@ -69,8 +71,8 @@ public abstract class AbstractSshMessage { | |||
* @return the channel | |||
* @throws JSchException on error | |||
*/ | |||
protected Channel openExecChannel(String command) throws JSchException { | |||
ChannelExec channel = (ChannelExec) session.openChannel("exec"); | |||
protected Channel openExecChannel(final String command) throws JSchException { | |||
final ChannelExec channel = (ChannelExec) session.openChannel("exec"); | |||
channel.setCommand(command); | |||
return channel; | |||
@@ -82,7 +84,7 @@ public abstract class AbstractSshMessage { | |||
* @throws JSchException on error | |||
*/ | |||
protected ChannelSftp openSftpChannel() throws JSchException { | |||
ChannelSftp channel = (ChannelSftp) session.openChannel("sftp"); | |||
final ChannelSftp channel = (ChannelSftp) session.openChannel("sftp"); | |||
return channel; | |||
} | |||
@@ -92,8 +94,8 @@ public abstract class AbstractSshMessage { | |||
* @param out the output stream to use | |||
* @throws IOException on error | |||
*/ | |||
protected void sendAck(OutputStream out) throws IOException { | |||
byte[] buf = new byte[1]; | |||
protected void sendAck(final OutputStream out) throws IOException { | |||
final byte[] buf = new byte[1]; | |||
buf[0] = 0; | |||
out.write(buf); | |||
out.flush(); | |||
@@ -106,9 +108,9 @@ public abstract class AbstractSshMessage { | |||
* @throws IOException on I/O error | |||
* @throws BuildException on other errors | |||
*/ | |||
protected void waitForAck(InputStream in) | |||
protected void waitForAck(final InputStream in) | |||
throws IOException, BuildException { | |||
int b = in.read(); | |||
final int b = in.read(); | |||
// b may be 0 for success, | |||
// 1 for error, | |||
@@ -118,7 +120,7 @@ public abstract class AbstractSshMessage { | |||
// didn't receive any response | |||
throw new BuildException("No response from server"); | |||
} else if (b != 0) { | |||
StringBuffer sb = new StringBuffer(); | |||
final StringBuffer sb = new StringBuffer(); | |||
int c = in.read(); | |||
while (c > 0 && c != '\n') { | |||
@@ -150,7 +152,7 @@ public abstract class AbstractSshMessage { | |||
* Set a log listener. | |||
* @param aListener the log listener | |||
*/ | |||
public void setLogListener(LogListener aListener) { | |||
public void setLogListener(final LogListener aListener) { | |||
listener = aListener; | |||
} | |||
@@ -158,7 +160,7 @@ public abstract class AbstractSshMessage { | |||
* Log a message to the log listener. | |||
* @param message the message to log | |||
*/ | |||
protected void log(String message) { | |||
protected void log(final String message) { | |||
listener.log(message); | |||
} | |||
@@ -168,11 +170,11 @@ public abstract class AbstractSshMessage { | |||
* @param timeEnded the finishing time | |||
* @param totalLength the total length | |||
*/ | |||
protected void logStats(long timeStarted, | |||
long timeEnded, | |||
long totalLength) { | |||
double duration = (timeEnded - timeStarted) / ONE_SECOND; | |||
NumberFormat format = NumberFormat.getNumberInstance(); | |||
protected void logStats(final long timeStarted, | |||
final long timeEnded, | |||
final long totalLength) { | |||
final double duration = (timeEnded - timeStarted) / ONE_SECOND; | |||
final NumberFormat format = NumberFormat.getNumberInstance(); | |||
format.setMaximumFractionDigits(2); | |||
format.setMinimumFractionDigits(1); | |||
listener.log("File transfer time: " + format.format(duration) | |||
@@ -197,11 +199,11 @@ public abstract class AbstractSshMessage { | |||
* @param percentTransmitted the current percent transmitted | |||
* @return the percent that the file is of the total | |||
*/ | |||
protected final int trackProgress(long filesize, long totalLength, | |||
int percentTransmitted) { | |||
protected final int trackProgress(final long filesize, final long totalLength, | |||
final int percentTransmitted) { | |||
// CheckStyle:MagicNumber OFF | |||
int percent = (int) Math.round(Math.floor((totalLength | |||
final int percent = (int) Math.round(Math.floor((totalLength | |||
/ (double) filesize) * 100)); | |||
if (percent > percentTransmitted) { | |||
@@ -246,13 +248,13 @@ public abstract class AbstractSshMessage { | |||
private long totalLength = 0; | |||
private int percentTransmitted = 0; | |||
public void init(int op, String src, String dest, long max) { | |||
public void init(final int op, final String src, final String dest, final long max) { | |||
initFileSize = max; | |||
totalLength = 0; | |||
percentTransmitted = 0; | |||
} | |||
public boolean count(long len) { | |||
public boolean count(final long len) { | |||
totalLength += len; | |||
percentTransmitted = trackProgress(initFileSize, | |||
totalLength, | |||
@@ -24,6 +24,7 @@ import org.apache.tools.ant.Task; | |||
import com.jcraft.jsch.JSch; | |||
import com.jcraft.jsch.JSchException; | |||
import com.jcraft.jsch.Session; | |||
/** | |||
* Base class for Ant tasks using jsch. | |||
@@ -40,7 +41,7 @@ public abstract class SSHBase extends Task implements LogListener { | |||
private int port = SSH_PORT; | |||
private boolean failOnError = true; | |||
private boolean verbose; | |||
private SSHUserInfo userInfo; | |||
private final SSHUserInfo userInfo; | |||
/** | |||
* Constructor for SSHBase. | |||
@@ -55,7 +56,7 @@ public abstract class SSHBase extends Task implements LogListener { | |||
* | |||
* @param host The new host value | |||
*/ | |||
public void setHost(String host) { | |||
public void setHost(final String host) { | |||
this.host = host; | |||
} | |||
@@ -73,7 +74,7 @@ public abstract class SSHBase extends Task implements LogListener { | |||
* @param failure if true throw a build exception when a failure occuries, | |||
* otherwise just log the failure and continue | |||
*/ | |||
public void setFailonerror(boolean failure) { | |||
public void setFailonerror(final boolean failure) { | |||
failOnError = failure; | |||
} | |||
@@ -90,7 +91,7 @@ public abstract class SSHBase extends Task implements LogListener { | |||
* @param verbose if true output more verbose logging | |||
* @since Ant 1.6.2 | |||
*/ | |||
public void setVerbose(boolean verbose) { | |||
public void setVerbose(final boolean verbose) { | |||
this.verbose = verbose; | |||
} | |||
@@ -108,7 +109,7 @@ public abstract class SSHBase extends Task implements LogListener { | |||
* | |||
* @param username The new username value | |||
*/ | |||
public void setUsername(String username) { | |||
public void setUsername(final String username) { | |||
userInfo.setName(username); | |||
} | |||
@@ -118,7 +119,7 @@ public abstract class SSHBase extends Task implements LogListener { | |||
* | |||
* @param password The new password value | |||
*/ | |||
public void setPassword(String password) { | |||
public void setPassword(final String password) { | |||
userInfo.setPassword(password); | |||
} | |||
@@ -127,7 +128,7 @@ public abstract class SSHBase extends Task implements LogListener { | |||
* | |||
* @param keyfile The new keyfile value | |||
*/ | |||
public void setKeyfile(String keyfile) { | |||
public void setKeyfile(final String keyfile) { | |||
userInfo.setKeyfile(keyfile); | |||
} | |||
@@ -136,7 +137,7 @@ public abstract class SSHBase extends Task implements LogListener { | |||
* | |||
* @param passphrase The new passphrase value | |||
*/ | |||
public void setPassphrase(String passphrase) { | |||
public void setPassphrase(final String passphrase) { | |||
userInfo.setPassphrase(passphrase); | |||
} | |||
@@ -148,7 +149,7 @@ public abstract class SSHBase extends Task implements LogListener { | |||
* | |||
* @param knownHosts a path to the known hosts file. | |||
*/ | |||
public void setKnownhosts(String knownHosts) { | |||
public void setKnownhosts(final String knownHosts) { | |||
this.knownHosts = knownHosts; | |||
} | |||
@@ -157,7 +158,7 @@ public abstract class SSHBase extends Task implements LogListener { | |||
* | |||
* @param yesOrNo if true trust the identity of unknown hosts. | |||
*/ | |||
public void setTrust(boolean yesOrNo) { | |||
public void setTrust(final boolean yesOrNo) { | |||
userInfo.setTrust(yesOrNo); | |||
} | |||
@@ -166,7 +167,7 @@ public abstract class SSHBase extends Task implements LogListener { | |||
* | |||
* @param port port number of remote host. | |||
*/ | |||
public void setPort(int port) { | |||
public void setPort(final int port) { | |||
this.port = port; | |||
} | |||
@@ -195,14 +196,14 @@ public abstract class SSHBase extends Task implements LogListener { | |||
* @throws JSchException on error | |||
*/ | |||
protected Session openSession() throws JSchException { | |||
JSch jsch = new JSch(); | |||
final JSch jsch = new JSch(); | |||
final SSHBase base = this; | |||
if(verbose) { | |||
JSch.setLogger(new com.jcraft.jsch.Logger(){ | |||
public boolean isEnabled(int level){ | |||
public boolean isEnabled(final int level){ | |||
return true; | |||
} | |||
public void log(int level, String message){ | |||
public void log(final int level, final String message){ | |||
base.log(message, Project.MSG_INFO); | |||
} | |||
}); | |||
@@ -216,7 +217,7 @@ public abstract class SSHBase extends Task implements LogListener { | |||
jsch.setKnownHosts(knownHosts); | |||
} | |||
Session session = jsch.getSession(userInfo.getName(), host, port); | |||
final Session session = jsch.getSession(userInfo.getName(), host, port); | |||
session.setConfig("PreferredAuthentications", | |||
"publickey,keyboard-interactive,password"); | |||
session.setUserInfo(userInfo); | |||
@@ -41,6 +41,7 @@ import org.apache.tools.ant.util.TeeOutputStream; | |||
import com.jcraft.jsch.ChannelExec; | |||
import com.jcraft.jsch.JSchException; | |||
import com.jcraft.jsch.Session; | |||
/** | |||
* Executes a command on a remote machine via ssh. | |||
@@ -31,6 +31,8 @@ import org.apache.tools.ant.Task; | |||
import org.apache.tools.ant.TaskContainer; | |||
import com.jcraft.jsch.JSchException; | |||
import com.jcraft.jsch.Session; | |||
/** | |||
* Establishes an ssh session with a remote machine, optionally | |||
@@ -43,10 +45,10 @@ public class SSHSession extends SSHBase { | |||
/** units are milliseconds, default is 0=infinite */ | |||
private long maxwait = 0; | |||
private Vector localTunnels = new Vector(); | |||
private Set localPortsUsed = new TreeSet(); | |||
private Vector remoteTunnels = new Vector(); | |||
private Set remotePortsUsed = new TreeSet(); | |||
private final Vector localTunnels = new Vector(); | |||
private final Set localPortsUsed = new TreeSet(); | |||
private final Vector remoteTunnels = new Vector(); | |||
private final Set remotePortsUsed = new TreeSet(); | |||
private NestedSequential nestedSequential = null; | |||
private static final String TIMEOUT_MESSAGE = | |||
@@ -54,7 +56,7 @@ public class SSHSession extends SSHBase { | |||
/** Optional Vector holding the nested tasks */ | |||
private Vector nestedTasks = new Vector(); | |||
private final Vector nestedTasks = new Vector(); | |||
/** | |||
* Add a nested task to Sequential. | |||
@@ -62,7 +64,7 @@ public class SSHSession extends SSHBase { | |||
* @param nestedTask Nested task to execute Sequential | |||
* <p> | |||
*/ | |||
public void addTask(Task nestedTask) { | |||
public void addTask(final Task nestedTask) { | |||
nestedTasks.addElement(nestedTask); | |||
} | |||
@@ -73,7 +75,7 @@ public class SSHSession extends SSHBase { | |||
* | |||
* @param timeout The new timeout value in seconds | |||
*/ | |||
public void setTimeout(long timeout) { | |||
public void setTimeout(final long timeout) { | |||
maxwait = timeout; | |||
} | |||
@@ -84,15 +86,15 @@ public class SSHSession extends SSHBase { | |||
* @param tunnels a comma-delimited list of lport:rhost:rport | |||
* tunnel specifications | |||
*/ | |||
public void setLocaltunnels(String tunnels) { | |||
String[] specs = tunnels.split(", "); | |||
public void setLocaltunnels(final String tunnels) { | |||
final String[] specs = tunnels.split(", "); | |||
for (int i = 0; i < specs.length; i++) { | |||
if (specs[i].length() > 0) { | |||
String[] spec = specs[i].split(":", 3); | |||
int lport = Integer.parseInt(spec[0]); | |||
String rhost = spec[1]; | |||
int rport = Integer.parseInt(spec[2]); | |||
LocalTunnel tunnel = createLocalTunnel(); | |||
final String[] spec = specs[i].split(":", 3); | |||
final int lport = Integer.parseInt(spec[0]); | |||
final String rhost = spec[1]; | |||
final int rport = Integer.parseInt(spec[2]); | |||
final LocalTunnel tunnel = createLocalTunnel(); | |||
tunnel.setLPort(lport); | |||
tunnel.setRHost(rhost); | |||
tunnel.setRPort(rport); | |||
@@ -107,15 +109,15 @@ public class SSHSession extends SSHBase { | |||
* @param tunnels a comma-delimited list of rport:lhost:lport | |||
* tunnel specifications | |||
*/ | |||
public void setRemotetunnels(String tunnels) { | |||
String[] specs = tunnels.split(", "); | |||
public void setRemotetunnels(final String tunnels) { | |||
final String[] specs = tunnels.split(", "); | |||
for (int i = 0; i < specs.length; i++) { | |||
if (specs[i].length() > 0) { | |||
String[] spec = specs[i].split(":", 3); | |||
int rport = Integer.parseInt(spec[0]); | |||
String lhost = spec[1]; | |||
int lport = Integer.parseInt(spec[2]); | |||
RemoteTunnel tunnel = createRemoteTunnel(); | |||
final String[] spec = specs[i].split(":", 3); | |||
final int rport = Integer.parseInt(spec[0]); | |||
final String lhost = spec[1]; | |||
final int lport = Integer.parseInt(spec[2]); | |||
final RemoteTunnel tunnel = createRemoteTunnel(); | |||
tunnel.setRPort(rport); | |||
tunnel.setLHost(lhost); | |||
tunnel.setLPort(lport); | |||
@@ -153,28 +155,28 @@ public class SSHSession extends SSHBase { | |||
session = openSession(); | |||
session.setTimeout((int) maxwait); | |||
for (Iterator i = localTunnels.iterator(); i.hasNext();) { | |||
LocalTunnel tunnel = (LocalTunnel) i.next(); | |||
for (final Iterator i = localTunnels.iterator(); i.hasNext();) { | |||
final LocalTunnel tunnel = (LocalTunnel) i.next(); | |||
session.setPortForwardingL(tunnel.getLPort(), | |||
tunnel.getRHost(), | |||
tunnel.getRPort()); | |||
} | |||
for (Iterator i = remoteTunnels.iterator(); i.hasNext();) { | |||
RemoteTunnel tunnel = (RemoteTunnel) i.next(); | |||
for (final Iterator i = remoteTunnels.iterator(); i.hasNext();) { | |||
final RemoteTunnel tunnel = (RemoteTunnel) i.next(); | |||
session.setPortForwardingR(tunnel.getRPort(), | |||
tunnel.getLHost(), | |||
tunnel.getLPort()); | |||
} | |||
for (Iterator i = nestedSequential.getNested().iterator(); | |||
for (final Iterator i = nestedSequential.getNested().iterator(); | |||
i.hasNext();) { | |||
Task nestedTask = (Task) i.next(); | |||
final Task nestedTask = (Task) i.next(); | |||
nestedTask.perform(); | |||
} | |||
// completed successfully | |||
} catch (JSchException e) { | |||
} catch (final JSchException e) { | |||
if (e.getMessage().indexOf("session is down") >= 0) { | |||
if (getFailonerror()) { | |||
throw new BuildException(TIMEOUT_MESSAGE, e); | |||
@@ -189,10 +191,10 @@ public class SSHSession extends SSHBase { | |||
Project.MSG_ERR); | |||
} | |||
} | |||
} catch (BuildException e) { | |||
} catch (final BuildException e) { | |||
// avoid wrapping it into yet another BuildException further down | |||
throw e; | |||
} catch (Exception e) { | |||
} catch (final Exception e) { | |||
if (getFailonerror()) { | |||
throw new BuildException(e); | |||
} else { | |||
@@ -206,13 +208,13 @@ public class SSHSession extends SSHBase { | |||
} | |||
public LocalTunnel createLocalTunnel() { | |||
LocalTunnel tunnel = new LocalTunnel(); | |||
final LocalTunnel tunnel = new LocalTunnel(); | |||
localTunnels.add(tunnel); | |||
return tunnel; | |||
} | |||
public RemoteTunnel createRemoteTunnel() { | |||
RemoteTunnel tunnel = new RemoteTunnel(); | |||
final RemoteTunnel tunnel = new RemoteTunnel(); | |||
remoteTunnels.add(tunnel); | |||
return tunnel; | |||
} | |||
@@ -223,8 +225,8 @@ public class SSHSession extends SSHBase { | |||
int lport = 0; | |||
String rhost = null; | |||
int rport = 0; | |||
public void setLPort(int lport) { | |||
Integer portKey = new Integer(lport); | |||
public void setLPort(final int lport) { | |||
final Integer portKey = new Integer(lport); | |||
if (localPortsUsed.contains(portKey)) { | |||
throw new BuildException("Multiple local tunnels defined to" | |||
+ " use same local port " + lport); | |||
@@ -232,8 +234,8 @@ public class SSHSession extends SSHBase { | |||
localPortsUsed.add(portKey); | |||
this.lport = lport; | |||
} | |||
public void setRHost(String rhost) { this.rhost = rhost; } | |||
public void setRPort(int rport) { this.rport = rport; } | |||
public void setRHost(final String rhost) { this.rhost = rhost; } | |||
public void setRPort(final int rport) { this.rport = rport; } | |||
public int getLPort() { | |||
if (lport == 0) { | |||
throw new BuildException("lport is required for LocalTunnel."); | |||
@@ -260,10 +262,10 @@ public class SSHSession extends SSHBase { | |||
int lport = 0; | |||
String lhost = null; | |||
int rport = 0; | |||
public void setLPort(int lport) { this.lport = lport; } | |||
public void setLHost(String lhost) { this.lhost = lhost; } | |||
public void setRPort(int rport) { | |||
Integer portKey = new Integer(rport); | |||
public void setLPort(final int lport) { this.lport = lport; } | |||
public void setLHost(final String lhost) { this.lhost = lhost; } | |||
public void setRPort(final int rport) { | |||
final Integer portKey = new Integer(rport); | |||
if (remotePortsUsed.contains(portKey)) { | |||
throw new BuildException("Multiple remote tunnels defined to" | |||
+ " use same remote port " + rport); | |||
@@ -309,15 +311,14 @@ public class SSHSession extends SSHBase { | |||
* This is a simple task container. | |||
*/ | |||
public static class NestedSequential implements TaskContainer { | |||
private List<Task> nested = new ArrayList<Task>(); | |||
private final List<Task> nested = new ArrayList<Task>(); | |||
/** | |||
* Add a task or type to the container. | |||
* | |||
* @param task an unknown element. | |||
*/ | |||
@Override | |||
public void addTask(Task task) { | |||
public void addTask(final Task task) { | |||
nested.add(task); | |||
} | |||
@@ -31,6 +31,7 @@ import org.apache.tools.ant.Project; | |||
import org.apache.tools.ant.types.FileSet; | |||
import com.jcraft.jsch.JSchException; | |||
import com.jcraft.jsch.Session; | |||
/** | |||
* Ant task for sending files to remote machine over ssh/scp. | |||
@@ -61,7 +62,7 @@ public class Scp extends SSHBase { | |||
* <i>user:password@host:/directory/path/*</i><br> | |||
* @param aFromUri a string representing the file to transfer. | |||
*/ | |||
public void setFile(String aFromUri) { | |||
public void setFile(final String aFromUri) { | |||
setFromUri(aFromUri); | |||
this.isFromRemote = isRemoteUri(this.fromUri); | |||
} | |||
@@ -75,7 +76,7 @@ public class Scp extends SSHBase { | |||
* @param aToUri a string representing the target of the copy. | |||
*/ | |||
public void setTodir(String aToUri) { | |||
public void setTodir(final String aToUri) { | |||
setToUri(aToUri); | |||
this.isToRemote = isRemoteUri(this.toUri); | |||
} | |||
@@ -87,7 +88,7 @@ public class Scp extends SSHBase { | |||
* @param aFromUri a string representing the source of the copy. | |||
* @since Ant 1.6.2 | |||
*/ | |||
public void setLocalFile(String aFromUri) { | |||
public void setLocalFile(final String aFromUri) { | |||
setFromUri(aFromUri); | |||
this.isFromRemote = false; | |||
} | |||
@@ -98,7 +99,7 @@ public class Scp extends SSHBase { | |||
* @param aFromUri a string representing the source of the copy. | |||
* @since Ant 1.6.2 | |||
*/ | |||
public void setRemoteFile(String aFromUri) { | |||
public void setRemoteFile(final String aFromUri) { | |||
validateRemoteUri("remoteFile", aFromUri); | |||
setFromUri(aFromUri); | |||
this.isFromRemote = true; | |||
@@ -111,7 +112,7 @@ public class Scp extends SSHBase { | |||
* @param aToUri a string representing the target of the copy. | |||
* @since Ant 1.6.2 | |||
*/ | |||
public void setLocalTodir(String aToUri) { | |||
public void setLocalTodir(final String aToUri) { | |||
setToUri(aToUri); | |||
this.isToRemote = false; | |||
} | |||
@@ -121,7 +122,7 @@ public class Scp extends SSHBase { | |||
* remote system is to be preserved during copy. | |||
* @since Ant 1.8.0 | |||
*/ | |||
public void setPreservelastmodified(boolean yesOrNo) { | |||
public void setPreservelastmodified(final boolean yesOrNo) { | |||
this.preserveLastModified = yesOrNo; | |||
} | |||
@@ -131,13 +132,13 @@ public class Scp extends SSHBase { | |||
* @param aToUri a string representing the target of the copy. | |||
* @since Ant 1.6.2 | |||
*/ | |||
public void setRemoteTodir(String aToUri) { | |||
public void setRemoteTodir(final String aToUri) { | |||
validateRemoteUri("remoteToDir", aToUri); | |||
setToUri(aToUri); | |||
this.isToRemote = true; | |||
} | |||
private static void validateRemoteUri(String type, String aToUri) { | |||
private static void validateRemoteUri(final String type, final String aToUri) { | |||
if (!isRemoteUri(aToUri)) { | |||
throw new BuildException(type + " '" + aToUri + "' is invalid. " | |||
+ "The 'remoteToDir' attribute must " | |||
@@ -153,7 +154,7 @@ public class Scp extends SSHBase { | |||
* @param aToUri a string representing the target of the copy. | |||
* @since Ant 1.6.2 | |||
*/ | |||
public void setLocalTofile(String aToUri) { | |||
public void setLocalTofile(final String aToUri) { | |||
setToUri(aToUri); | |||
this.isToRemote = false; | |||
} | |||
@@ -164,7 +165,7 @@ public class Scp extends SSHBase { | |||
* @param aToUri a string representing the target of the copy. | |||
* @since Ant 1.6.2 | |||
*/ | |||
public void setRemoteTofile(String aToUri) { | |||
public void setRemoteTofile(final String aToUri) { | |||
validateRemoteUri("remoteToFile", aToUri); | |||
setToUri(aToUri); | |||
this.isToRemote = true; | |||
@@ -175,7 +176,7 @@ public class Scp extends SSHBase { | |||
* | |||
* @param yesOrNo if true sftp protocol will be used. | |||
*/ | |||
public void setSftp(boolean yesOrNo) { | |||
public void setSftp(final boolean yesOrNo) { | |||
isSftp = yesOrNo; | |||
} | |||
@@ -185,7 +186,7 @@ public class Scp extends SSHBase { | |||
* | |||
* @param set FileSet to send to remote host. | |||
*/ | |||
public void addFileset(FileSet set) { | |||
public void addFileset(final FileSet set) { | |||
if (fileSets == null) { | |||
fileSets = new LinkedList(); | |||
} | |||
@@ -233,10 +234,10 @@ public class Scp extends SSHBase { | |||
+ "must have syntax like the following: " | |||
+ "user:password@host:/path"); | |||
} | |||
} catch (Exception e) { | |||
} catch (final Exception e) { | |||
if (getFailonerror()) { | |||
if(e instanceof BuildException) { | |||
BuildException be = (BuildException) e; | |||
final BuildException be = (BuildException) e; | |||
if(be.getLocation() == null) { | |||
be.setLocation(getLocation()); | |||
} | |||
@@ -250,9 +251,9 @@ public class Scp extends SSHBase { | |||
} | |||
} | |||
private void download(String fromSshUri, String toPath) | |||
private void download(final String fromSshUri, final String toPath) | |||
throws JSchException, IOException { | |||
String file = parseUri(fromSshUri); | |||
final String file = parseUri(fromSshUri); | |||
Session session = null; | |||
try { | |||
@@ -281,16 +282,16 @@ public class Scp extends SSHBase { | |||
} | |||
} | |||
private void upload(List fileSet, String toSshUri) | |||
private void upload(final List fileSet, final String toSshUri) | |||
throws IOException, JSchException { | |||
String file = parseUri(toSshUri); | |||
final String file = parseUri(toSshUri); | |||
Session session = null; | |||
try { | |||
List list = new ArrayList(fileSet.size()); | |||
for (Iterator i = fileSet.iterator(); i.hasNext();) { | |||
FileSet set = (FileSet) i.next(); | |||
Directory d = createDirectory(set); | |||
final List list = new ArrayList(fileSet.size()); | |||
for (final Iterator i = fileSet.iterator(); i.hasNext();) { | |||
final FileSet set = (FileSet) i.next(); | |||
final Directory d = createDirectory(set); | |||
if (d != null) { | |||
list.add(d); | |||
} | |||
@@ -315,9 +316,9 @@ public class Scp extends SSHBase { | |||
} | |||
} | |||
private void upload(String fromPath, String toSshUri) | |||
private void upload(final String fromPath, final String toSshUri) | |||
throws IOException, JSchException { | |||
String file = parseUri(toSshUri); | |||
final String file = parseUri(toSshUri); | |||
Session session = null; | |||
try { | |||
@@ -342,17 +343,17 @@ public class Scp extends SSHBase { | |||
} | |||
} | |||
private String parseUri(String uri) { | |||
private String parseUri(final String uri) { | |||
int indexOfAt = uri.indexOf('@'); | |||
int indexOfColon = uri.indexOf(':'); | |||
final int indexOfColon = uri.indexOf(':'); | |||
if (indexOfColon > -1 && indexOfColon < indexOfAt) { | |||
// user:password@host:/path notation | |||
// everything upto the last @ before the last : is considered | |||
// password. (so if the path contains an @ and a : it will not work) | |||
int indexOfCurrentAt = indexOfAt; | |||
int indexOfLastColon = uri.lastIndexOf(':'); | |||
final int indexOfLastColon = uri.lastIndexOf(':'); | |||
while (indexOfCurrentAt > -1 && indexOfCurrentAt < indexOfLastColon) | |||
{ | |||
indexOfAt = indexOfCurrentAt; | |||
@@ -374,7 +375,7 @@ public class Scp extends SSHBase { | |||
+ "given. Can't authenticate."); | |||
} | |||
int indexOfPath = uri.indexOf(':', indexOfAt + 1); | |||
final int indexOfPath = uri.indexOf(':', indexOfAt + 1); | |||
if (indexOfPath == -1) { | |||
throw new BuildException("no remote path in " + uri); | |||
} | |||
@@ -387,26 +388,26 @@ public class Scp extends SSHBase { | |||
return remotePath; | |||
} | |||
private static boolean isRemoteUri(String uri) { | |||
private static boolean isRemoteUri(final String uri) { | |||
boolean isRemote = true; | |||
int indexOfAt = uri.indexOf('@'); | |||
final int indexOfAt = uri.indexOf('@'); | |||
if (indexOfAt < 0) { | |||
isRemote = false; | |||
} | |||
return isRemote; | |||
} | |||
private Directory createDirectory(FileSet set) { | |||
DirectoryScanner scanner = set.getDirectoryScanner(getProject()); | |||
private Directory createDirectory(final FileSet set) { | |||
final DirectoryScanner scanner = set.getDirectoryScanner(getProject()); | |||
Directory root = new Directory(scanner.getBasedir()); | |||
String[] files = scanner.getIncludedFiles(); | |||
final String[] files = scanner.getIncludedFiles(); | |||
if (files.length != 0) { | |||
for (int j = 0; j < files.length; j++) { | |||
String[] path = Directory.getPath(files[j]); | |||
final String[] path = Directory.getPath(files[j]); | |||
Directory current = root; | |||
File currentParent = scanner.getBasedir(); | |||
for (int i = 0; i < path.length; i++) { | |||
File file = new File(currentParent, path[i]); | |||
final File file = new File(currentParent, path[i]); | |||
if (file.isDirectory()) { | |||
current.addDirectory(new Directory(file)); | |||
current = current.getChild(file); | |||
@@ -423,26 +424,26 @@ public class Scp extends SSHBase { | |||
return root; | |||
} | |||
private void setFromUri(String fromUri) { | |||
private void setFromUri(final String fromUri) { | |||
if (this.fromUri != null) { | |||
throw exactlyOne(FROM_ATTRS); | |||
} | |||
this.fromUri = fromUri; | |||
} | |||
private void setToUri(String toUri) { | |||
private void setToUri(final String toUri) { | |||
if (this.toUri != null) { | |||
throw exactlyOne(TO_ATTRS); | |||
} | |||
this.toUri = toUri; | |||
} | |||
private BuildException exactlyOne(String[] attrs) { | |||
private BuildException exactlyOne(final String[] attrs) { | |||
return exactlyOne(attrs, null); | |||
} | |||
private BuildException exactlyOne(String[] attrs, String alt) { | |||
StringBuffer buf = new StringBuffer("Exactly one of ").append( | |||
private BuildException exactlyOne(final String[] attrs, final String alt) { | |||
final StringBuffer buf = new StringBuffer("Exactly one of ").append( | |||
'[').append(attrs[0]); | |||
for (int i = 1; i < attrs.length; i++) { | |||
buf.append('|').append(attrs[i]); | |||
@@ -28,8 +28,10 @@ import java.io.OutputStream; | |||
import org.apache.tools.ant.util.FileUtils; | |||
import com.jcraft.jsch.Channel; | |||
import com.jcraft.jsch.ChannelSftp; | |||
import com.jcraft.jsch.JSchException; | |||
import com.jcraft.jsch.Session; | |||
import com.jcraft.jsch.SftpATTRS; | |||
import com.jcraft.jsch.SftpException; | |||
@@ -51,7 +53,7 @@ public class ScpFromMessage extends AbstractSshMessage { | |||
* Constructor for ScpFromMessage | |||
* @param session the ssh session to use | |||
*/ | |||
public ScpFromMessage(Session session) { | |||
public ScpFromMessage(final Session session) { | |||
super(session); | |||
} | |||
@@ -61,7 +63,7 @@ public class ScpFromMessage extends AbstractSshMessage { | |||
* @param session the ssh session to use | |||
* @since Ant 1.7 | |||
*/ | |||
public ScpFromMessage(boolean verbose, Session session) { | |||
public ScpFromMessage(final boolean verbose, final Session session) { | |||
super(verbose, session); | |||
} | |||
@@ -74,11 +76,11 @@ public class ScpFromMessage extends AbstractSshMessage { | |||
* @param recursive if true use recursion (-r option to scp) | |||
* @since Ant 1.6.2 | |||
*/ | |||
public ScpFromMessage(boolean verbose, | |||
Session session, | |||
String aRemoteFile, | |||
File aLocalFile, | |||
boolean recursive) { | |||
public ScpFromMessage(final boolean verbose, | |||
final Session session, | |||
final String aRemoteFile, | |||
final File aLocalFile, | |||
final boolean recursive) { | |||
this(false, session, aRemoteFile, aLocalFile, recursive, false); | |||
} | |||
@@ -89,10 +91,10 @@ public class ScpFromMessage extends AbstractSshMessage { | |||
* @param aLocalFile the local file | |||
* @param recursive if true use recursion (-r option to scp) | |||
*/ | |||
public ScpFromMessage(Session session, | |||
String aRemoteFile, | |||
File aLocalFile, | |||
boolean recursive) { | |||
public ScpFromMessage(final Session session, | |||
final String aRemoteFile, | |||
final File aLocalFile, | |||
final boolean recursive) { | |||
this(false, session, aRemoteFile, aLocalFile, recursive); | |||
} | |||
@@ -107,12 +109,12 @@ public class ScpFromMessage extends AbstractSshMessage { | |||
* modification times | |||
* @since Ant 1.8.0 | |||
*/ | |||
public ScpFromMessage(boolean verbose, | |||
Session session, | |||
String aRemoteFile, | |||
File aLocalFile, | |||
boolean recursive, | |||
boolean preserveLastModified) { | |||
public ScpFromMessage(final boolean verbose, | |||
final Session session, | |||
final String aRemoteFile, | |||
final File aLocalFile, | |||
final boolean recursive, | |||
final boolean preserveLastModified) { | |||
super(verbose, session); | |||
this.remoteFile = aRemoteFile; | |||
this.localFile = aLocalFile; | |||
@@ -131,11 +133,11 @@ public class ScpFromMessage extends AbstractSshMessage { | |||
command += "-r "; | |||
} | |||
command += remoteFile; | |||
Channel channel = openExecChannel(command); | |||
final Channel channel = openExecChannel(command); | |||
try { | |||
// get I/O streams for remote scp | |||
OutputStream out = channel.getOutputStream(); | |||
InputStream in = channel.getInputStream(); | |||
final OutputStream out = channel.getOutputStream(); | |||
final InputStream in = channel.getInputStream(); | |||
channel.connect(); | |||
@@ -153,18 +155,18 @@ public class ScpFromMessage extends AbstractSshMessage { | |||
return preserveLastModified; | |||
} | |||
private void startRemoteCpProtocol(InputStream in, | |||
OutputStream out, | |||
File localFile) | |||
private void startRemoteCpProtocol(final InputStream in, | |||
final OutputStream out, | |||
final File localFile) | |||
throws IOException, JSchException { | |||
File startFile = localFile; | |||
while (true) { | |||
// C0644 filesize filename - header for a regular file | |||
// T time 0 time 0\n - present if perserve time. | |||
// D directory - this is the header for a directory. | |||
ByteArrayOutputStream stream = new ByteArrayOutputStream(); | |||
final ByteArrayOutputStream stream = new ByteArrayOutputStream(); | |||
while (true) { | |||
int read = in.read(); | |||
final int read = in.read(); | |||
if (read < 0) { | |||
return; | |||
} | |||
@@ -173,7 +175,7 @@ public class ScpFromMessage extends AbstractSshMessage { | |||
} | |||
stream.write(read); | |||
} | |||
String serverResponse = stream.toString("UTF-8"); | |||
final String serverResponse = stream.toString("UTF-8"); | |||
if (serverResponse.charAt(0) == 'C') { | |||
parseAndFetchFile(serverResponse, startFile, out, in); | |||
} else if (serverResponse.charAt(0) == 'D') { | |||
@@ -191,14 +193,14 @@ public class ScpFromMessage extends AbstractSshMessage { | |||
} | |||
} | |||
private File parseAndCreateDirectory(String serverResponse, | |||
File localFile) { | |||
private File parseAndCreateDirectory(final String serverResponse, | |||
final File localFile) { | |||
int start = serverResponse.indexOf(" "); | |||
// appears that the next token is not used and it's zero. | |||
start = serverResponse.indexOf(" ", start + 1); | |||
String directoryName = serverResponse.substring(start + 1); | |||
final String directoryName = serverResponse.substring(start + 1); | |||
if (localFile.isDirectory()) { | |||
File dir = new File(localFile, directoryName); | |||
final File dir = new File(localFile, directoryName); | |||
dir.mkdir(); | |||
log("Creating: " + dir); | |||
return dir; | |||
@@ -206,19 +208,19 @@ public class ScpFromMessage extends AbstractSshMessage { | |||
return null; | |||
} | |||
private void parseAndFetchFile(String serverResponse, | |||
File localFile, | |||
OutputStream out, | |||
InputStream in) | |||
private void parseAndFetchFile(final String serverResponse, | |||
final File localFile, | |||
final OutputStream out, | |||
final InputStream in) | |||
throws IOException, JSchException { | |||
int start = 0; | |||
int end = serverResponse.indexOf(" ", start + 1); | |||
start = end + 1; | |||
end = serverResponse.indexOf(" ", start + 1); | |||
long filesize = Long.parseLong(serverResponse.substring(start, end)); | |||
String filename = serverResponse.substring(end + 1); | |||
final long filesize = Long.parseLong(serverResponse.substring(start, end)); | |||
final String filename = serverResponse.substring(end + 1); | |||
log("Receiving: " + filename + " : " + filesize); | |||
File transferFile = (localFile.isDirectory()) | |||
final File transferFile = (localFile.isDirectory()) | |||
? new File(localFile, filename) | |||
: localFile; | |||
fetchFile(transferFile, filesize, out, in); | |||
@@ -226,25 +228,25 @@ public class ScpFromMessage extends AbstractSshMessage { | |||
sendAck(out); | |||
} | |||
private void fetchFile(File localFile, | |||
private void fetchFile(final File localFile, | |||
long filesize, | |||
OutputStream out, | |||
InputStream in) | |||
final OutputStream out, | |||
final InputStream in) | |||
throws IOException, JSchException { | |||
byte[] buf = new byte[BUFFER_SIZE]; | |||
final byte[] buf = new byte[BUFFER_SIZE]; | |||
sendAck(out); | |||
// read a content of lfile | |||
FileOutputStream fos = new FileOutputStream(localFile); | |||
final FileOutputStream fos = new FileOutputStream(localFile); | |||
int length; | |||
long totalLength = 0; | |||
long startTime = System.currentTimeMillis(); | |||
final long startTime = System.currentTimeMillis(); | |||
// only track progress for files larger than 100kb in verbose mode | |||
boolean trackProgress = getVerbose() && filesize > HUNDRED_KILOBYTES; | |||
final boolean trackProgress = getVerbose() && filesize > HUNDRED_KILOBYTES; | |||
// since filesize keeps on decreasing we have to store the | |||
// initial filesize | |||
long initFilesize = filesize; | |||
final long initFilesize = filesize; | |||
int percentTransmitted = 0; | |||
try { | |||
@@ -269,7 +271,7 @@ public class ScpFromMessage extends AbstractSshMessage { | |||
} | |||
} | |||
} finally { | |||
long endTime = System.currentTimeMillis(); | |||
final long endTime = System.currentTimeMillis(); | |||
logStats(startTime, endTime, totalLength); | |||
fos.flush(); | |||
fos.close(); | |||
@@ -280,14 +282,14 @@ public class ScpFromMessage extends AbstractSshMessage { | |||
} | |||
} | |||
private void setLastModified(File localFile) throws JSchException { | |||
private void setLastModified(final File localFile) throws JSchException { | |||
SftpATTRS fileAttributes = null; | |||
ChannelSftp channel = openSftpChannel(); | |||
final ChannelSftp channel = openSftpChannel(); | |||
channel.connect(); | |||
try { | |||
fileAttributes = channel.lstat(remoteDir(remoteFile) | |||
+ localFile.getName()); | |||
} catch (SftpException e) { | |||
} catch (final SftpException e) { | |||
throw new JSchException("failed to stat remote file", e); | |||
} | |||
FileUtils.getFileUtils().setFileLastModified(localFile, | |||
@@ -299,7 +301,7 @@ public class ScpFromMessage extends AbstractSshMessage { | |||
/** | |||
* returns the directory part of the remote file, if any. | |||
*/ | |||
private static String remoteDir(String remoteFile) { | |||
private static String remoteDir(final String remoteFile) { | |||
int index = remoteFile.lastIndexOf("/"); | |||
if (index < 0) { | |||
index = remoteFile.lastIndexOf("\\"); | |||
@@ -25,6 +25,7 @@ import org.apache.tools.ant.util.FileUtils; | |||
import com.jcraft.jsch.ChannelSftp; | |||
import com.jcraft.jsch.JSchException; | |||
import com.jcraft.jsch.Session; | |||
import com.jcraft.jsch.SftpATTRS; | |||
import com.jcraft.jsch.SftpException; | |||
import com.jcraft.jsch.SftpProgressMonitor; | |||
@@ -37,7 +38,7 @@ public class ScpFromMessageBySftp extends ScpFromMessage { | |||
private static final int HUNDRED_KILOBYTES = 102400; | |||
private String remoteFile; | |||
private File localFile; | |||
private final File localFile; | |||
private boolean isRecursive = false; | |||
private boolean verbose = false; | |||
@@ -50,11 +51,11 @@ public class ScpFromMessageBySftp extends ScpFromMessage { | |||
* @param recursive if true use recursion | |||
* @since Ant 1.7 | |||
*/ | |||
public ScpFromMessageBySftp(boolean verbose, | |||
Session session, | |||
String aRemoteFile, | |||
File aLocalFile, | |||
boolean recursive) { | |||
public ScpFromMessageBySftp(final boolean verbose, | |||
final Session session, | |||
final String aRemoteFile, | |||
final File aLocalFile, | |||
final boolean recursive) { | |||
this(verbose, session, aRemoteFile, aLocalFile, recursive, false); | |||
} | |||
@@ -65,10 +66,10 @@ public class ScpFromMessageBySftp extends ScpFromMessage { | |||
* @param aLocalFile the local file | |||
* @param recursive if true use recursion | |||
*/ | |||
public ScpFromMessageBySftp(Session session, | |||
String aRemoteFile, | |||
File aLocalFile, | |||
boolean recursive) { | |||
public ScpFromMessageBySftp(final Session session, | |||
final String aRemoteFile, | |||
final File aLocalFile, | |||
final boolean recursive) { | |||
this(false, session, aRemoteFile, aLocalFile, recursive); | |||
} | |||
@@ -83,12 +84,12 @@ public class ScpFromMessageBySftp extends ScpFromMessage { | |||
* modification times | |||
* @since Ant 1.8.0 | |||
*/ | |||
public ScpFromMessageBySftp(boolean verbose, | |||
Session session, | |||
String aRemoteFile, | |||
File aLocalFile, | |||
boolean recursive, | |||
boolean preserveLastModified) { | |||
public ScpFromMessageBySftp(final boolean verbose, | |||
final Session session, | |||
final String aRemoteFile, | |||
final File aLocalFile, | |||
final boolean recursive, | |||
final boolean preserveLastModified) { | |||
super(verbose, session, aRemoteFile, aLocalFile, recursive, | |||
preserveLastModified); | |||
this.verbose = verbose; | |||
@@ -103,20 +104,20 @@ public class ScpFromMessageBySftp extends ScpFromMessage { | |||
* @throws JSchException on errors detected by scp | |||
*/ | |||
public void execute() throws IOException, JSchException { | |||
ChannelSftp channel = openSftpChannel(); | |||
final ChannelSftp channel = openSftpChannel(); | |||
try { | |||
channel.connect(); | |||
try { | |||
SftpATTRS attrs = channel.stat(remoteFile); | |||
final SftpATTRS attrs = channel.stat(remoteFile); | |||
if (attrs.isDir() && !remoteFile.endsWith("/")) { | |||
remoteFile = remoteFile + "/"; | |||
} | |||
} catch (SftpException ee) { | |||
} catch (final SftpException ee) { | |||
// Ignored | |||
} | |||
getDir(channel, remoteFile, localFile); | |||
} catch (SftpException e) { | |||
JSchException schException = new JSchException("Could not get '"+ remoteFile | |||
} catch (final SftpException e) { | |||
final JSchException schException = new JSchException("Could not get '"+ remoteFile | |||
+"' to '"+localFile+"' - " | |||
+e.toString()); | |||
schException.initCause(e); | |||
@@ -129,9 +130,9 @@ public class ScpFromMessageBySftp extends ScpFromMessage { | |||
log("done\n"); | |||
} | |||
private void getDir(ChannelSftp channel, | |||
String remoteFile, | |||
File localFile) throws IOException, SftpException { | |||
private void getDir(final ChannelSftp channel, | |||
final String remoteFile, | |||
final File localFile) throws IOException, SftpException { | |||
String pwd = remoteFile; | |||
if (remoteFile.lastIndexOf('/') != -1) { | |||
if (remoteFile.length() > 1) { | |||
@@ -142,11 +143,11 @@ public class ScpFromMessageBySftp extends ScpFromMessage { | |||
if (!localFile.exists()) { | |||
localFile.mkdirs(); | |||
} | |||
java.util.Vector files = channel.ls(remoteFile); | |||
final java.util.Vector files = channel.ls(remoteFile); | |||
final int size = files.size(); | |||
for (int i = 0; i < size; i++) { | |||
ChannelSftp.LsEntry le = (ChannelSftp.LsEntry) files.elementAt(i); | |||
String name = le.getFilename(); | |||
final ChannelSftp.LsEntry le = (ChannelSftp.LsEntry) files.elementAt(i); | |||
final String name = le.getFilename(); | |||
if (le.getAttrs().isDir()) { | |||
if (name.equals(".") || name.equals("..")) { | |||
continue; | |||
@@ -161,13 +162,13 @@ public class ScpFromMessageBySftp extends ScpFromMessage { | |||
channel.cd(".."); | |||
} | |||
private void getFile(ChannelSftp channel, | |||
ChannelSftp.LsEntry le, | |||
private void getFile(final ChannelSftp channel, | |||
final ChannelSftp.LsEntry le, | |||
File localFile) throws IOException, SftpException { | |||
String remoteFile = le.getFilename(); | |||
final String remoteFile = le.getFilename(); | |||
if (!localFile.exists()) { | |||
String path = localFile.getAbsolutePath(); | |||
int i = path.lastIndexOf(File.pathSeparator); | |||
final String path = localFile.getAbsolutePath(); | |||
final int i = path.lastIndexOf(File.pathSeparator); | |||
if (i != -1) { | |||
if (path.length() > File.pathSeparator.length()) { | |||
new File(path.substring(0, i)).mkdirs(); | |||
@@ -179,11 +180,11 @@ public class ScpFromMessageBySftp extends ScpFromMessage { | |||
localFile = new File(localFile, remoteFile); | |||
} | |||
long startTime = System.currentTimeMillis(); | |||
long totalLength = le.getAttrs().getSize(); | |||
final long startTime = System.currentTimeMillis(); | |||
final long totalLength = le.getAttrs().getSize(); | |||
SftpProgressMonitor monitor = null; | |||
boolean trackProgress = getVerbose() && totalLength > HUNDRED_KILOBYTES; | |||
final boolean trackProgress = getVerbose() && totalLength > HUNDRED_KILOBYTES; | |||
if (trackProgress) { | |||
monitor = getProgressMonitor(); | |||
} | |||
@@ -191,7 +192,7 @@ public class ScpFromMessageBySftp extends ScpFromMessage { | |||
log("Receiving: " + remoteFile + " : " + le.getAttrs().getSize()); | |||
channel.get(remoteFile, localFile.getAbsolutePath(), monitor); | |||
} finally { | |||
long endTime = System.currentTimeMillis(); | |||
final long endTime = System.currentTimeMillis(); | |||
logStats(startTime, endTime, (int) totalLength); | |||
} | |||
if (getPreserveLastModified()) { | |||
@@ -26,7 +26,9 @@ import java.io.OutputStream; | |||
import java.util.Iterator; | |||
import java.util.List; | |||
import com.jcraft.jsch.Channel; | |||
import com.jcraft.jsch.JSchException; | |||
import com.jcraft.jsch.Session; | |||
/** | |||
* Utility class to carry out an upload scp transfer. | |||
@@ -44,7 +46,7 @@ public class ScpToMessage extends AbstractSshMessage { | |||
* Constructor for ScpToMessage | |||
* @param session the ssh session to use | |||
*/ | |||
public ScpToMessage(Session session) { | |||
public ScpToMessage(final Session session) { | |||
super(session); | |||
} | |||
@@ -54,7 +56,7 @@ public class ScpToMessage extends AbstractSshMessage { | |||
* @param session the ssh session to use | |||
* @since Ant 1.7 | |||
*/ | |||
public ScpToMessage(boolean verbose, Session session) { | |||
public ScpToMessage(final boolean verbose, final Session session) { | |||
super(verbose, session); | |||
} | |||
@@ -66,10 +68,10 @@ public class ScpToMessage extends AbstractSshMessage { | |||
* @param aRemotePath the remote path | |||
* @since Ant 1.6.2 | |||
*/ | |||
public ScpToMessage(boolean verbose, | |||
Session session, | |||
File aLocalFile, | |||
String aRemotePath) { | |||
public ScpToMessage(final boolean verbose, | |||
final Session session, | |||
final File aLocalFile, | |||
final String aRemotePath) { | |||
this(verbose, session, aRemotePath); | |||
this.localFile = aLocalFile; | |||
@@ -83,10 +85,10 @@ public class ScpToMessage extends AbstractSshMessage { | |||
* @param aRemotePath the remote path | |||
* @since Ant 1.6.2 | |||
*/ | |||
public ScpToMessage(boolean verbose, | |||
Session session, | |||
List aDirectoryList, | |||
String aRemotePath) { | |||
public ScpToMessage(final boolean verbose, | |||
final Session session, | |||
final List aDirectoryList, | |||
final String aRemotePath) { | |||
this(verbose, session, aRemotePath); | |||
this.directoryList = aDirectoryList; | |||
@@ -99,9 +101,9 @@ public class ScpToMessage extends AbstractSshMessage { | |||
* @param aRemotePath the remote path | |||
* @since Ant 1.6.2 | |||
*/ | |||
private ScpToMessage(boolean verbose, | |||
Session session, | |||
String aRemotePath) { | |||
private ScpToMessage(final boolean verbose, | |||
final Session session, | |||
final String aRemotePath) { | |||
super(verbose, session); | |||
this.remotePath = aRemotePath; | |||
} | |||
@@ -112,9 +114,9 @@ public class ScpToMessage extends AbstractSshMessage { | |||
* @param aLocalFile the local file | |||
* @param aRemotePath the remote path | |||
*/ | |||
public ScpToMessage(Session session, | |||
File aLocalFile, | |||
String aRemotePath) { | |||
public ScpToMessage(final Session session, | |||
final File aLocalFile, | |||
final String aRemotePath) { | |||
this(false, session, aLocalFile, aRemotePath); | |||
} | |||
@@ -124,9 +126,9 @@ public class ScpToMessage extends AbstractSshMessage { | |||
* @param aDirectoryList a list of directories | |||
* @param aRemotePath the remote path | |||
*/ | |||
public ScpToMessage(Session session, | |||
List aDirectoryList, | |||
String aRemotePath) { | |||
public ScpToMessage(final Session session, | |||
final List aDirectoryList, | |||
final String aRemotePath) { | |||
this(false, session, aDirectoryList, aRemotePath); | |||
} | |||
@@ -146,12 +148,12 @@ public class ScpToMessage extends AbstractSshMessage { | |||
} | |||
private void doSingleTransfer() throws IOException, JSchException { | |||
String cmd = "scp -t " + remotePath; | |||
Channel channel = openExecChannel(cmd); | |||
final String cmd = "scp -t " + remotePath; | |||
final Channel channel = openExecChannel(cmd); | |||
try { | |||
OutputStream out = channel.getOutputStream(); | |||
InputStream in = channel.getInputStream(); | |||
final OutputStream out = channel.getOutputStream(); | |||
final InputStream in = channel.getInputStream(); | |||
channel.connect(); | |||
@@ -165,16 +167,16 @@ public class ScpToMessage extends AbstractSshMessage { | |||
} | |||
private void doMultipleTransfer() throws IOException, JSchException { | |||
Channel channel = openExecChannel("scp -r -d -t " + remotePath); | |||
final Channel channel = openExecChannel("scp -r -d -t " + remotePath); | |||
try { | |||
OutputStream out = channel.getOutputStream(); | |||
InputStream in = channel.getInputStream(); | |||
final OutputStream out = channel.getOutputStream(); | |||
final InputStream in = channel.getInputStream(); | |||
channel.connect(); | |||
waitForAck(in); | |||
for (Iterator i = directoryList.iterator(); i.hasNext();) { | |||
Directory current = (Directory) i.next(); | |||
for (final Iterator i = directoryList.iterator(); i.hasNext();) { | |||
final Directory current = (Directory) i.next(); | |||
sendDirectory(current, in, out); | |||
} | |||
} finally { | |||
@@ -184,21 +186,21 @@ public class ScpToMessage extends AbstractSshMessage { | |||
} | |||
} | |||
private void sendDirectory(Directory current, | |||
InputStream in, | |||
OutputStream out) throws IOException { | |||
for (Iterator fileIt = current.filesIterator(); fileIt.hasNext();) { | |||
private void sendDirectory(final Directory current, | |||
final InputStream in, | |||
final OutputStream out) throws IOException { | |||
for (final Iterator fileIt = current.filesIterator(); fileIt.hasNext();) { | |||
sendFileToRemote((File) fileIt.next(), in, out); | |||
} | |||
for (Iterator dirIt = current.directoryIterator(); dirIt.hasNext();) { | |||
Directory dir = (Directory) dirIt.next(); | |||
for (final Iterator dirIt = current.directoryIterator(); dirIt.hasNext();) { | |||
final Directory dir = (Directory) dirIt.next(); | |||
sendDirectoryToRemote(dir, in, out); | |||
} | |||
} | |||
private void sendDirectoryToRemote(Directory directory, | |||
InputStream in, | |||
OutputStream out) throws IOException { | |||
private void sendDirectoryToRemote(final Directory directory, | |||
final InputStream in, | |||
final OutputStream out) throws IOException { | |||
String command = "D0755 0 "; | |||
command += directory.getDirectory().getName(); | |||
command += "\n"; | |||
@@ -213,11 +215,11 @@ public class ScpToMessage extends AbstractSshMessage { | |||
waitForAck(in); | |||
} | |||
private void sendFileToRemote(File localFile, | |||
InputStream in, | |||
OutputStream out) throws IOException { | |||
private void sendFileToRemote(final File localFile, | |||
final InputStream in, | |||
final OutputStream out) throws IOException { | |||
// send "C0644 filesize filename", where filename should not include '/' | |||
long filesize = localFile.length(); | |||
final long filesize = localFile.length(); | |||
String command = "C0644 " + filesize + " "; | |||
command += localFile.getName(); | |||
command += "\n"; | |||
@@ -228,16 +230,16 @@ public class ScpToMessage extends AbstractSshMessage { | |||
waitForAck(in); | |||
// send a content of lfile | |||
FileInputStream fis = new FileInputStream(localFile); | |||
byte[] buf = new byte[BUFFER_SIZE]; | |||
long startTime = System.currentTimeMillis(); | |||
final FileInputStream fis = new FileInputStream(localFile); | |||
final byte[] buf = new byte[BUFFER_SIZE]; | |||
final long startTime = System.currentTimeMillis(); | |||
long totalLength = 0; | |||
// only track progress for files larger than 100kb in verbose mode | |||
boolean trackProgress = getVerbose() && filesize > HUNDRED_KILOBYTES; | |||
final boolean trackProgress = getVerbose() && filesize > HUNDRED_KILOBYTES; | |||
// since filesize keeps on decreasing we have to store the | |||
// initial filesize | |||
long initFilesize = filesize; | |||
final long initFilesize = filesize; | |||
int percentTransmitted = 0; | |||
try { | |||
@@ -245,7 +247,7 @@ public class ScpToMessage extends AbstractSshMessage { | |||
log("Sending: " + localFile.getName() + " : " + localFile.length()); | |||
} | |||
while (true) { | |||
int len = fis.read(buf, 0, buf.length); | |||
final int len = fis.read(buf, 0, buf.length); | |||
if (len <= 0) { | |||
break; | |||
} | |||
@@ -263,7 +265,7 @@ public class ScpToMessage extends AbstractSshMessage { | |||
waitForAck(in); | |||
} finally { | |||
if (this.getVerbose()) { | |||
long endTime = System.currentTimeMillis(); | |||
final long endTime = System.currentTimeMillis(); | |||
logStats(startTime, endTime, totalLength); | |||
} | |||
fis.close(); | |||
@@ -25,6 +25,7 @@ import java.util.List; | |||
import com.jcraft.jsch.ChannelSftp; | |||
import com.jcraft.jsch.JSchException; | |||
import com.jcraft.jsch.Session; | |||
import com.jcraft.jsch.SftpException; | |||
import com.jcraft.jsch.SftpProgressMonitor; | |||
@@ -36,7 +37,7 @@ public class ScpToMessageBySftp extends ScpToMessage/*AbstractSshMessage*/ { | |||
private static final int HUNDRED_KILOBYTES = 102400; | |||
private File localFile; | |||
private String remotePath; | |||
private final String remotePath; | |||
private List directoryList; | |||
/** | |||
@@ -47,10 +48,10 @@ public class ScpToMessageBySftp extends ScpToMessage/*AbstractSshMessage*/ { | |||
* @param aRemotePath the remote path | |||
* @since Ant 1.7 | |||
*/ | |||
public ScpToMessageBySftp(boolean verbose, | |||
Session session, | |||
File aLocalFile, | |||
String aRemotePath) { | |||
public ScpToMessageBySftp(final boolean verbose, | |||
final Session session, | |||
final File aLocalFile, | |||
final String aRemotePath) { | |||
this(verbose, session, aRemotePath); | |||
this.localFile = aLocalFile; | |||
@@ -64,10 +65,10 @@ public class ScpToMessageBySftp extends ScpToMessage/*AbstractSshMessage*/ { | |||
* @param aRemotePath the remote path | |||
* @since Ant 1.7 | |||
*/ | |||
public ScpToMessageBySftp(boolean verbose, | |||
Session session, | |||
List aDirectoryList, | |||
String aRemotePath) { | |||
public ScpToMessageBySftp(final boolean verbose, | |||
final Session session, | |||
final List aDirectoryList, | |||
final String aRemotePath) { | |||
this(verbose, session, aRemotePath); | |||
this.directoryList = aDirectoryList; | |||
@@ -80,9 +81,9 @@ public class ScpToMessageBySftp extends ScpToMessage/*AbstractSshMessage*/ { | |||
* @param aRemotePath the remote path | |||
* @since Ant 1.6.2 | |||
*/ | |||
private ScpToMessageBySftp(boolean verbose, | |||
Session session, | |||
String aRemotePath) { | |||
private ScpToMessageBySftp(final boolean verbose, | |||
final Session session, | |||
final String aRemotePath) { | |||
super(verbose, session); | |||
this.remotePath = aRemotePath; | |||
} | |||
@@ -93,9 +94,9 @@ public class ScpToMessageBySftp extends ScpToMessage/*AbstractSshMessage*/ { | |||
* @param aLocalFile the local file | |||
* @param aRemotePath the remote path | |||
*/ | |||
public ScpToMessageBySftp(Session session, | |||
File aLocalFile, | |||
String aRemotePath) { | |||
public ScpToMessageBySftp(final Session session, | |||
final File aLocalFile, | |||
final String aRemotePath) { | |||
this(false, session, aLocalFile, aRemotePath); | |||
} | |||
@@ -105,9 +106,9 @@ public class ScpToMessageBySftp extends ScpToMessage/*AbstractSshMessage*/ { | |||
* @param aDirectoryList a list of directories | |||
* @param aRemotePath the remote path | |||
*/ | |||
public ScpToMessageBySftp(Session session, | |||
List aDirectoryList, | |||
String aRemotePath) { | |||
public ScpToMessageBySftp(final Session session, | |||
final List aDirectoryList, | |||
final String aRemotePath) { | |||
this(false, session, aDirectoryList, aRemotePath); | |||
} | |||
@@ -127,13 +128,13 @@ public class ScpToMessageBySftp extends ScpToMessage/*AbstractSshMessage*/ { | |||
} | |||
private void doSingleTransfer() throws IOException, JSchException { | |||
ChannelSftp channel = openSftpChannel(); | |||
final ChannelSftp channel = openSftpChannel(); | |||
try { | |||
channel.connect(); | |||
try { | |||
sendFileToRemote(channel, localFile, remotePath); | |||
} catch (SftpException e) { | |||
JSchException schException = new JSchException("Could not send '" + localFile | |||
} catch (final SftpException e) { | |||
final JSchException schException = new JSchException("Could not send '" + localFile | |||
+ "' to '" + remotePath + "' - " | |||
+ e.toString()); | |||
schException.initCause(e); | |||
@@ -147,14 +148,14 @@ public class ScpToMessageBySftp extends ScpToMessage/*AbstractSshMessage*/ { | |||
} | |||
private void doMultipleTransfer() throws IOException, JSchException { | |||
ChannelSftp channel = openSftpChannel(); | |||
final ChannelSftp channel = openSftpChannel(); | |||
try { | |||
channel.connect(); | |||
try { | |||
try { | |||
channel.stat(remotePath); | |||
} catch (SftpException e) { | |||
} catch (final SftpException e) { | |||
if (e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE) { | |||
// dir does not exist. | |||
channel.mkdir(remotePath); | |||
@@ -164,20 +165,20 @@ public class ScpToMessageBySftp extends ScpToMessage/*AbstractSshMessage*/ { | |||
} | |||
} | |||
channel.cd(remotePath); | |||
} catch (SftpException e) { | |||
} catch (final SftpException e) { | |||
throw new JSchException("Could not CD to '" + remotePath | |||
+ "' - " + e.toString(), e); | |||
} | |||
Directory current = null; | |||
try { | |||
for (Iterator i = directoryList.iterator(); i.hasNext();) { | |||
for (final Iterator i = directoryList.iterator(); i.hasNext();) { | |||
current = (Directory) i.next(); | |||
if (getVerbose()) { | |||
log("Sending directory " + current); | |||
} | |||
sendDirectory(channel, current); | |||
} | |||
} catch (SftpException e) { | |||
} catch (final SftpException e) { | |||
String msg = "Error sending directory"; | |||
if (current != null && current.getDirectory() != null) { | |||
msg += " '" + current.getDirectory().getName() + "'"; | |||
@@ -191,25 +192,25 @@ public class ScpToMessageBySftp extends ScpToMessage/*AbstractSshMessage*/ { | |||
} | |||
} | |||
private void sendDirectory(ChannelSftp channel, | |||
Directory current) | |||
private void sendDirectory(final ChannelSftp channel, | |||
final Directory current) | |||
throws IOException, SftpException { | |||
for (Iterator fileIt = current.filesIterator(); fileIt.hasNext();) { | |||
for (final Iterator fileIt = current.filesIterator(); fileIt.hasNext();) { | |||
sendFileToRemote(channel, (File) fileIt.next(), null); | |||
} | |||
for (Iterator dirIt = current.directoryIterator(); dirIt.hasNext();) { | |||
Directory dir = (Directory) dirIt.next(); | |||
for (final Iterator dirIt = current.directoryIterator(); dirIt.hasNext();) { | |||
final Directory dir = (Directory) dirIt.next(); | |||
sendDirectoryToRemote(channel, dir); | |||
} | |||
} | |||
private void sendDirectoryToRemote(ChannelSftp channel, | |||
Directory directory) | |||
private void sendDirectoryToRemote(final ChannelSftp channel, | |||
final Directory directory) | |||
throws IOException, SftpException { | |||
String dir = directory.getDirectory().getName(); | |||
final String dir = directory.getDirectory().getName(); | |||
try { | |||
channel.stat(dir); | |||
} catch (SftpException e) { | |||
} catch (final SftpException e) { | |||
// dir does not exist. | |||
if (e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE) { | |||
channel.mkdir(dir); | |||
@@ -220,21 +221,21 @@ public class ScpToMessageBySftp extends ScpToMessage/*AbstractSshMessage*/ { | |||
channel.cd(".."); | |||
} | |||
private void sendFileToRemote(ChannelSftp channel, | |||
File localFile, | |||
private void sendFileToRemote(final ChannelSftp channel, | |||
final File localFile, | |||
String remotePath) | |||
throws IOException, SftpException { | |||
long filesize = localFile.length(); | |||
final long filesize = localFile.length(); | |||
if (remotePath == null) { | |||
remotePath = localFile.getName(); | |||
} | |||
long startTime = System.currentTimeMillis(); | |||
long totalLength = filesize; | |||
final long startTime = System.currentTimeMillis(); | |||
final long totalLength = filesize; | |||
// only track progress for files larger than 100kb in verbose mode | |||
boolean trackProgress = getVerbose() && filesize > HUNDRED_KILOBYTES; | |||
final boolean trackProgress = getVerbose() && filesize > HUNDRED_KILOBYTES; | |||
SftpProgressMonitor monitor = null; | |||
if (trackProgress) { | |||
@@ -248,7 +249,7 @@ public class ScpToMessageBySftp extends ScpToMessage/*AbstractSshMessage*/ { | |||
channel.put(localFile.getAbsolutePath(), remotePath, monitor); | |||
} finally { | |||
if (this.getVerbose()) { | |||
long endTime = System.currentTimeMillis(); | |||
final long endTime = System.currentTimeMillis(); | |||
logStats(startTime, endTime, (int) totalLength); | |||
} | |||
} | |||
@@ -18,9 +18,10 @@ | |||
package org.apache.tools.ant.types.resolver; | |||
import com.sun.org.apache.xml.internal.resolver.Catalog; | |||
import com.sun.org.apache.xml.internal.resolver.CatalogEntry; | |||
import com.sun.org.apache.xml.internal.resolver.helpers.PublicId; | |||
import org.apache.xml.resolver.Catalog; | |||
import org.apache.xml.resolver.CatalogEntry; | |||
import org.apache.xml.resolver.helpers.PublicId; | |||
/** | |||
* This class extends the Catalog class provided by Norman Walsh's | |||
@@ -54,7 +55,7 @@ public class ApacheCatalog extends Catalog { | |||
* @return the catalog. | |||
*/ | |||
protected Catalog newCatalog() { | |||
ApacheCatalog cat = (ApacheCatalog) super.newCatalog(); | |||
final ApacheCatalog cat = (ApacheCatalog) super.newCatalog(); | |||
cat.setResolver(resolver); | |||
return cat; | |||
} | |||
@@ -63,7 +64,7 @@ public class ApacheCatalog extends Catalog { | |||
* Set the resolver object to callback. | |||
* @param resolver the apache catalog resolver. | |||
*/ | |||
public void setResolver(ApacheCatalogResolver resolver) { | |||
public void setResolver(final ApacheCatalogResolver resolver) { | |||
this.resolver = resolver; | |||
} | |||
@@ -84,14 +85,14 @@ public class ApacheCatalog extends Catalog { | |||
* | |||
* @param entry The CatalogEntry to process. | |||
*/ | |||
public void addEntry(CatalogEntry entry) { | |||
public void addEntry(final CatalogEntry entry) { | |||
int type = entry.getEntryType(); | |||
final int type = entry.getEntryType(); | |||
if (type == PUBLIC) { | |||
String publicid = PublicId.normalize(entry.getEntryArg(0)); | |||
String systemid = normalizeURI(entry.getEntryArg(1)); | |||
final String publicid = PublicId.normalize(entry.getEntryArg(0)); | |||
final String systemid = normalizeURI(entry.getEntryArg(1)); | |||
if (resolver == null) { | |||
catalogManager.debug | |||
@@ -102,8 +103,8 @@ public class ApacheCatalog extends Catalog { | |||
} else if (type == URI) { | |||
String uri = normalizeURI(entry.getEntryArg(0)); | |||
String altURI = normalizeURI(entry.getEntryArg(1)); | |||
final String uri = normalizeURI(entry.getEntryArg(0)); | |||
final String altURI = normalizeURI(entry.getEntryArg(1)); | |||
if (resolver == null) { | |||
catalogManager.debug | |||
@@ -25,10 +25,10 @@ import java.net.URL; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.types.ResourceLocation; | |||
import org.apache.tools.ant.types.XMLCatalog; | |||
import org.apache.xml.resolver.Catalog; | |||
import org.apache.xml.resolver.CatalogManager; | |||
import org.apache.xml.resolver.tools.CatalogResolver; | |||
import com.sun.org.apache.xml.internal.resolver.Catalog; | |||
import com.sun.org.apache.xml.internal.resolver.CatalogManager; | |||
import com.sun.org.apache.xml.internal.resolver.tools.CatalogResolver; | |||
/** | |||
* <p>This class extends the CatalogResolver class provided by Norman | |||
@@ -91,7 +91,7 @@ public class ApacheCatalogResolver extends CatalogResolver { | |||
* Set the XMLCatalog object to callback. | |||
* @param xmlCatalog the XMLCatalog to use. | |||
*/ | |||
public void setXMLCatalog(XMLCatalog xmlCatalog) { | |||
public void setXMLCatalog(final XMLCatalog xmlCatalog) { | |||
this.xmlCatalog = xmlCatalog; | |||
} | |||
@@ -100,22 +100,22 @@ public class ApacheCatalogResolver extends CatalogResolver { | |||
* file within a <code><catalogfiles></code> fileset. | |||
* @param file the external catalog file. | |||
*/ | |||
public void parseCatalog(String file) { | |||
public void parseCatalog(final String file) { | |||
Catalog catalog = getCatalog(); | |||
final Catalog catalog = getCatalog(); | |||
if (!(catalog instanceof ApacheCatalog)) { | |||
throw new BuildException("Wrong catalog type found: " + catalog.getClass().getName()); | |||
} | |||
ApacheCatalog apacheCatalog = (ApacheCatalog) catalog; | |||
final ApacheCatalog apacheCatalog = (ApacheCatalog) catalog; | |||
// Pass in reference to ourselves so we can be called back. | |||
apacheCatalog.setResolver(this); | |||
try { | |||
apacheCatalog.parseCatalog(file); | |||
} catch (MalformedURLException ex) { | |||
} catch (final MalformedURLException ex) { | |||
throw new BuildException(ex); | |||
} catch (IOException ex) { | |||
} catch (final IOException ex) { | |||
throw new BuildException(ex); | |||
} | |||
} | |||
@@ -133,11 +133,11 @@ public class ApacheCatalogResolver extends CatalogResolver { | |||
* directory in which the catalog is located. | |||
* | |||
*/ | |||
public void addPublicEntry(String publicid, | |||
String systemid, | |||
URL base) { | |||
public void addPublicEntry(final String publicid, | |||
final String systemid, | |||
final URL base) { | |||
ResourceLocation dtd = new ResourceLocation(); | |||
final ResourceLocation dtd = new ResourceLocation(); | |||
dtd.setBase(base); | |||
dtd.setPublicId(publicid); | |||
dtd.setLocation(systemid); | |||
@@ -159,11 +159,11 @@ public class ApacheCatalogResolver extends CatalogResolver { | |||
* directory in which the catalog is located. | |||
* | |||
*/ | |||
public void addURIEntry(String uri, | |||
String altURI, | |||
URL base) { | |||
public void addURIEntry(final String uri, | |||
final String altURI, | |||
final URL base) { | |||
ResourceLocation entity = new ResourceLocation(); | |||
final ResourceLocation entity = new ResourceLocation(); | |||
entity.setBase(base); | |||
entity.setPublicId(uri); | |||
entity.setLocation(altURI); | |||
@@ -23,7 +23,11 @@ import java.util.StringTokenizer; | |||
import com.sun.org.apache.bcel.internal.classfile.ConstantClass; | |||
import com.sun.org.apache.bcel.internal.classfile.ConstantNameAndType; | |||
import com.sun.org.apache.bcel.internal.classfile.ConstantPool; | |||
import com.sun.org.apache.bcel.internal.classfile.EmptyVisitor; | |||
import com.sun.org.apache.bcel.internal.classfile.Field; | |||
import com.sun.org.apache.bcel.internal.classfile.JavaClass; | |||
import com.sun.org.apache.bcel.internal.classfile.Method; | |||
/** | |||
* A BCEL visitor implementation to collect class dependency information | |||
@@ -31,7 +35,7 @@ import com.sun.org.apache.bcel.internal.classfile.JavaClass; | |||
*/ | |||
public class DependencyVisitor extends EmptyVisitor { | |||
/** The collected dependencies */ | |||
private Hashtable<String, String> dependencies = new Hashtable<String, String>(); | |||
private final Hashtable<String, String> dependencies = new Hashtable<String, String>(); | |||
/** | |||
* The current class's constant pool - used to determine class names | |||
* from class references. | |||
@@ -58,7 +62,7 @@ public class DependencyVisitor extends EmptyVisitor { | |||
* | |||
* @param constantPool the constant pool of the class being visited. | |||
*/ | |||
public void visitConstantPool(ConstantPool constantPool) { | |||
public void visitConstantPool(final ConstantPool constantPool) { | |||
this.constantPool = constantPool; | |||
} | |||
@@ -67,8 +71,8 @@ public class DependencyVisitor extends EmptyVisitor { | |||
* | |||
* @param constantClass the constantClass entry for the class reference | |||
*/ | |||
public void visitConstantClass(ConstantClass constantClass) { | |||
String classname | |||
public void visitConstantClass(final ConstantClass constantClass) { | |||
final String classname | |||
= constantClass.getConstantValue(constantPool).toString(); | |||
addSlashClass(classname); | |||
} | |||
@@ -80,18 +84,18 @@ public class DependencyVisitor extends EmptyVisitor { | |||
* | |||
* @param obj the name and type reference being visited. | |||
*/ | |||
public void visitConstantNameAndType(ConstantNameAndType obj) { | |||
String name = obj.getName(constantPool); | |||
public void visitConstantNameAndType(final ConstantNameAndType obj) { | |||
final String name = obj.getName(constantPool); | |||
if (obj.getSignature(constantPool).equals("Ljava/lang/Class;") | |||
&& name.startsWith("class$")) { | |||
String classname | |||
= name.substring("class$".length()).replace('$', '.'); | |||
// does the class have a package structure | |||
int index = classname.lastIndexOf("."); | |||
final int index = classname.lastIndexOf("."); | |||
if (index > 0) { | |||
char start; | |||
// check if the package structure is more than 1 level deep | |||
int index2 = classname.lastIndexOf(".", index - 1); | |||
final int index2 = classname.lastIndexOf(".", index - 1); | |||
if (index2 != -1) { | |||
// class name has more than 1 package level 'com.company.Class' | |||
start = classname.charAt(index2 + 1); | |||
@@ -124,7 +128,7 @@ public class DependencyVisitor extends EmptyVisitor { | |||
* | |||
* @param field the field being visited | |||
*/ | |||
public void visitField(Field field) { | |||
public void visitField(final Field field) { | |||
addClasses(field.getSignature()); | |||
} | |||
@@ -133,7 +137,7 @@ public class DependencyVisitor extends EmptyVisitor { | |||
* | |||
* @param javaClass the class being visited. | |||
*/ | |||
public void visitJavaClass(JavaClass javaClass) { | |||
public void visitJavaClass(final JavaClass javaClass) { | |||
addClass(javaClass.getClassName()); | |||
} | |||
@@ -142,9 +146,9 @@ public class DependencyVisitor extends EmptyVisitor { | |||
* | |||
* @param method the method being visited. | |||
*/ | |||
public void visitMethod(Method method) { | |||
String signature = method.getSignature(); | |||
int pos = signature.indexOf(")"); | |||
public void visitMethod(final Method method) { | |||
final String signature = method.getSignature(); | |||
final int pos = signature.indexOf(")"); | |||
addClasses(signature.substring(1, pos)); | |||
addClasses(signature.substring(pos + 1)); | |||
} | |||
@@ -154,7 +158,7 @@ public class DependencyVisitor extends EmptyVisitor { | |||
* | |||
* @param classname the class to be added to the list of dependencies. | |||
*/ | |||
void addClass(String classname) { | |||
void addClass(final String classname) { | |||
dependencies.put(classname, classname); | |||
} | |||
@@ -164,11 +168,11 @@ public class DependencyVisitor extends EmptyVisitor { | |||
* @param string the descriptor string, being descriptors separated by | |||
* ';' characters. | |||
*/ | |||
private void addClasses(String string) { | |||
StringTokenizer tokens = new StringTokenizer(string, ";"); | |||
private void addClasses(final String string) { | |||
final StringTokenizer tokens = new StringTokenizer(string, ";"); | |||
while (tokens.hasMoreTokens()) { | |||
String descriptor = tokens.nextToken(); | |||
int pos = descriptor.indexOf('L'); | |||
final String descriptor = tokens.nextToken(); | |||
final int pos = descriptor.indexOf('L'); | |||
if (pos != -1) { | |||
addSlashClass(descriptor.substring(pos + 1)); | |||
} | |||
@@ -181,7 +185,7 @@ public class DependencyVisitor extends EmptyVisitor { | |||
* | |||
* @param classname the class name in slash format | |||
*/ | |||
private void addSlashClass(String classname) { | |||
private void addSlashClass(final String classname) { | |||
addClass(classname.replace('/', '.')); | |||
} | |||
} | |||
@@ -19,12 +19,14 @@ | |||
package org.apache.tools.ant.util.regexp; | |||
import java.util.Vector; | |||
import java.util.regex.MatchResult; | |||
import org.apache.oro.text.regex.MatchResult; | |||
import org.apache.oro.text.regex.Pattern; | |||
import org.apache.oro.text.regex.Perl5Compiler; | |||
import org.apache.oro.text.regex.Perl5Matcher; | |||
import org.apache.tools.ant.BuildException; | |||
/** | |||
* Implementation of RegexpMatcher for Jakarta-ORO. | |||
* | |||
@@ -47,7 +49,7 @@ public class JakartaOroMatcher implements RegexpMatcher { | |||
* Set the regexp pattern from the String description. | |||
* @param pattern the pattern to match | |||
*/ | |||
public void setPattern(String pattern) { | |||
public void setPattern(final String pattern) { | |||
this.pattern = pattern; | |||
} | |||
@@ -65,13 +67,13 @@ public class JakartaOroMatcher implements RegexpMatcher { | |||
* @return the compiled pattern | |||
* @throws BuildException on error | |||
*/ | |||
protected Pattern getCompiledPattern(int options) | |||
protected Pattern getCompiledPattern(final int options) | |||
throws BuildException { | |||
try { | |||
// compute the compiler options based on the input options first | |||
Pattern p = compiler.compile(pattern, getCompilerOptions(options)); | |||
final Pattern p = compiler.compile(pattern, getCompilerOptions(options)); | |||
return p; | |||
} catch (Exception e) { | |||
} catch (final Exception e) { | |||
throw new BuildException(e); | |||
} | |||
} | |||
@@ -82,7 +84,7 @@ public class JakartaOroMatcher implements RegexpMatcher { | |||
* @return true if the pattern matches | |||
* @throws BuildException on error | |||
*/ | |||
public boolean matches(String argument) throws BuildException { | |||
public boolean matches(final String argument) throws BuildException { | |||
return matches(argument, MATCH_DEFAULT); | |||
} | |||
@@ -93,9 +95,9 @@ public class JakartaOroMatcher implements RegexpMatcher { | |||
* @return true if the pattern matches | |||
* @throws BuildException on error | |||
*/ | |||
public boolean matches(String input, int options) | |||
public boolean matches(final String input, final int options) | |||
throws BuildException { | |||
Pattern p = getCompiledPattern(options); | |||
final Pattern p = getCompiledPattern(options); | |||
return matcher.contains(input, p); | |||
} | |||
@@ -110,7 +112,7 @@ public class JakartaOroMatcher implements RegexpMatcher { | |||
* @return the vector of groups | |||
* @throws BuildException on error | |||
*/ | |||
public Vector getGroups(String argument) throws BuildException { | |||
public Vector getGroups(final String argument) throws BuildException { | |||
return getGroups(argument, MATCH_DEFAULT); | |||
} | |||
@@ -125,14 +127,14 @@ public class JakartaOroMatcher implements RegexpMatcher { | |||
* @return the vector of groups | |||
* @throws BuildException on error | |||
*/ | |||
public Vector getGroups(String input, int options) | |||
public Vector getGroups(final String input, final int options) | |||
throws BuildException { | |||
if (!matches(input, options)) { | |||
return null; | |||
} | |||
Vector v = new Vector(); | |||
MatchResult mr = matcher.getMatch(); | |||
int cnt = mr.groups(); | |||
final Vector v = new Vector(); | |||
final MatchResult mr = matcher.getMatch(); | |||
final int cnt = mr.groups(); | |||
for (int i = 0; i < cnt; i++) { | |||
String match = mr.group(i); | |||
// treat non-matching groups as empty matches | |||
@@ -149,7 +151,7 @@ public class JakartaOroMatcher implements RegexpMatcher { | |||
* @param options the generic options | |||
* @return the specific options | |||
*/ | |||
protected int getCompilerOptions(int options) { | |||
protected int getCompilerOptions(final int options) { | |||
int cOptions = Perl5Compiler.DEFAULT_MASK; | |||
if (RegexpUtil.hasFlag(options, MATCH_CASE_INSENSITIVE)) { | |||
@@ -18,6 +18,8 @@ | |||
package org.apache.tools.ant.util.regexp; | |||
import org.apache.oro.text.regex.Perl5Substitution; | |||
import org.apache.oro.text.regex.Substitution; | |||
import org.apache.oro.text.regex.Util; | |||
import org.apache.tools.ant.BuildException; | |||
/*** | |||
@@ -40,10 +42,10 @@ public class JakartaOroRegexp extends JakartaOroMatcher implements Regexp { | |||
* @return the result of the operation | |||
* @throws BuildException on error | |||
*/ | |||
public String substitute(String input, String argument, int options) | |||
public String substitute(final String input, final String argument, final int options) | |||
throws BuildException { | |||
// translate \1 to $1 so that the Perl5Substitution will work | |||
StringBuffer subst = new StringBuffer(); | |||
final StringBuffer subst = new StringBuffer(); | |||
for (int i = 0; i < argument.length(); i++) { | |||
char c = argument.charAt(i); | |||
if (c == '$') { | |||
@@ -52,7 +54,7 @@ public class JakartaOroRegexp extends JakartaOroMatcher implements Regexp { | |||
} else if (c == '\\') { | |||
if (++i < argument.length()) { | |||
c = argument.charAt(i); | |||
int value = Character.digit(c, DECIMAL); | |||
final int value = Character.digit(c, DECIMAL); | |||
if (value > -1) { | |||
subst.append("$").append(value); | |||
} else { | |||
@@ -68,7 +70,7 @@ public class JakartaOroRegexp extends JakartaOroMatcher implements Regexp { | |||
} | |||
// Do the substitution | |||
Substitution s = | |||
final Substitution s = | |||
new Perl5Substitution(subst.toString(), | |||
Perl5Substitution.INTERPOLATE_ALL); | |||
return Util.substitute(matcher, | |||
@@ -84,8 +86,8 @@ public class JakartaOroRegexp extends JakartaOroMatcher implements Regexp { | |||
* @param options the ant regexp options | |||
* @return the oro substition options | |||
*/ | |||
protected int getSubsOptions(int options) { | |||
boolean replaceAll = RegexpUtil.hasFlag(options, REPLACE_ALL); | |||
protected int getSubsOptions(final int options) { | |||
final boolean replaceAll = RegexpUtil.hasFlag(options, REPLACE_ALL); | |||
int subsOptions = 1; | |||
if (replaceAll) { | |||
subsOptions = Util.SUBSTITUTE_ALL; | |||