Added: felix/trunk/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/cli/UnrecognizedOptionException.java URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/cli/UnrecognizedOptionException.java?rev=806255&view=auto ============================================================================== --- felix/trunk/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/cli/UnrecognizedOptionException.java (added) +++ felix/trunk/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/cli/UnrecognizedOptionException.java Thu Aug 20 17:03:06 2009 @@ -0,0 +1,67 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.felix.sigil.common.runtime.cli; + +/** + * Exception thrown during parsing signalling an unrecognized + * option was seen. + * + * @author bob mcwhiter (bob @ werken.com) + * @version $Revision: 680644 $, $Date: 2008-07-29 01:13:48 -0700 (Tue, 29 Jul 2008) $ + */ +public class UnrecognizedOptionException extends ParseException +{ + /** The unrecognized option */ + private String option; + + /** + * Construct a new <code>UnrecognizedArgumentException</code> + * with the specified detail message. + * + * @param message the detail message + */ + public UnrecognizedOptionException(String message) + { + super(message); + } + + /** + * Construct a new <code>UnrecognizedArgumentException</code> + * with the specified option and detail message. + * + * @param message the detail message + * @param option the unrecognized option + * @since 1.2 + */ + public UnrecognizedOptionException(String message, String option) + { + this(message); + this.option = option; + } + + /** + * Returns the unrecognized option. + * + * @return the related option + * @since 1.2 + */ + public String getOption() + { + return option; + } +}
Added: felix/trunk/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/cli/Util.java URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/cli/Util.java?rev=806255&view=auto ============================================================================== --- felix/trunk/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/cli/Util.java (added) +++ felix/trunk/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/cli/Util.java Thu Aug 20 17:03:06 2009 @@ -0,0 +1,75 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.felix.sigil.common.runtime.cli; + +/** + * Contains useful helper methods for classes within this package. + * + * @author John Keyes (john at integralsource.com) + * @version $Revision: 680644 $, $Date: 2008-07-29 01:13:48 -0700 (Tue, 29 Jul 2008) $ + */ +class Util +{ + /** + * Remove the hyphens from the begining of <code>str</code> and + * return the new String. + * + * @param str The string from which the hyphens should be removed. + * + * @return the new String. + */ + static String stripLeadingHyphens(String str) + { + if (str == null) + { + return null; + } + if (str.startsWith("--")) + { + return str.substring(2, str.length()); + } + else if (str.startsWith("-")) + { + return str.substring(1, str.length()); + } + + return str; + } + + /** + * Remove the leading and trailing quotes from <code>str</code>. + * E.g. if str is '"one two"', then 'one two' is returned. + * + * @param str The string from which the leading and trailing quotes + * should be removed. + * + * @return The string without the leading and trailing quotes. + */ + static String stripLeadingAndTrailingQuotes(String str) + { + if (str.startsWith("\"")) + { + str = str.substring(1, str.length()); + } + if (str.endsWith("\"")) + { + str = str.substring(0, str.length() - 1); + } + return str; + } +} Added: felix/trunk/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/cli/overview.html URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/cli/overview.html?rev=806255&view=auto ============================================================================== --- felix/trunk/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/cli/overview.html (added) +++ felix/trunk/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/cli/overview.html Thu Aug 20 17:03:06 2009 @@ -0,0 +1,43 @@ +<!-- +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +--> +<body> + + <p>Commons CLI -- version 1.2</p> + + <p>The commons-cli package aides in parsing command-line arguments.</p> + + <p>Allow command-line arguments to be parsed against a descriptor of + valid options (long and short), potentially with arguments.</p> + + <p>command-line arguments may be of the typical <code>String[]</code> + form, but also may be a <code>java.util.List</code>. Indexes allow + for parsing only a portion of the command-line. Also, functionality + for parsing the command-line in phases is built in, allowing for + 'cvs-style' command-lines, where some global options are specified + before a 'command' argument, and command-specific options are + specified after the command argument: + + <code> + <pre> + myApp -p <port> command -p <printer> + </pre> + </code> + + + <p>The homepage for the project is + <a href="http://commons.apache.org">Apache Commons/</a> +</body> Added: felix/trunk/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/cli/package.html URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/cli/package.html?rev=806255&view=auto ============================================================================== --- felix/trunk/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/cli/package.html (added) +++ felix/trunk/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/cli/package.html Thu Aug 20 17:03:06 2009 @@ -0,0 +1,21 @@ +<!-- +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +--> +<body> + + Commons CLI 1.2 + +</body> Modified: felix/trunk/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/io/Action.java URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/io/Action.java?rev=806255&r1=806254&r2=806255&view=diff ============================================================================== --- felix/trunk/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/io/Action.java (original) +++ felix/trunk/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/io/Action.java Thu Aug 20 17:03:06 2009 @@ -23,14 +23,10 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.net.URLConnection; import org.osgi.framework.BundleException; import org.osgi.framework.launch.Framework; -import org.apache.commons.io.input.CountingInputStream; import org.apache.felix.sigil.common.runtime.Main; import static org.apache.felix.sigil.common.runtime.io.Constants.OK; @@ -143,62 +139,6 @@ return in.readBoolean(); } - protected void writeStream( String location ) throws IOException { - URL url = new URL( location ); - URLConnection conn = url.openConnection(); - conn.connect(); - - int l = conn.getContentLength(); - writeInt( l ); - InputStream uin = conn.getInputStream(); - byte[] buf = new byte[1024*1024]; - for (;;) { - int r = uin.read( buf ); - if ( r == -1 ) break; - out.write( buf, 0, r ); - } - } - - protected InputStream readStream() throws IOException { - final int length = readInt(); - return new CountingInputStream(in) { - @Override - public int read() throws IOException - { - if ( getCount() < length ) - return super.read(); - else - return -1; - } - - @Override - public int read( byte[] b, int off, int len ) throws IOException - { - len = (getCount() + len) > length ? (length - getCount()) : len; - if ( len == 0 ) - return -1; - else - return super.read( b, off, len ); - } - - @Override - public int read( byte[] b ) throws IOException - { - return read( b, 0, b.length ); - } - - @Override - public long skip( long len ) throws IOException - { - len = (getCount() + len) > length ? (length - getCount()) : len; - if ( len == 0 ) - return -1; - else - return super.skip( len ); - } - }; - } - protected void flush() throws IOException { out.flush(); Modified: felix/trunk/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/io/UpdateAction.java URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/io/UpdateAction.java?rev=806255&r1=806254&r2=806255&view=diff ============================================================================== --- felix/trunk/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/io/UpdateAction.java (original) +++ felix/trunk/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/io/UpdateAction.java Thu Aug 20 17:03:06 2009 @@ -24,6 +24,7 @@ import java.io.DataOutputStream; import java.io.IOException; import java.io.InputStream; +import java.net.URL; import org.osgi.framework.Bundle; import org.osgi.framework.BundleException; @@ -71,8 +72,9 @@ else { writeBoolean( true ); - writeStream( update.location ); + writeString( update.location ); } + flush(); if ( !checkOk() ) { @@ -101,8 +103,21 @@ boolean remote = readBoolean(); if ( remote ) { - InputStream in = readStream(); - b.update(in); + String loc = readString(); + try { + InputStream in = open( loc ); + try { + b.update(in); + writeOk(); + } + finally { + in.close(); + } + } + catch (IOException e) { + writeError(); + writeString(e.getMessage()); + } } else { @@ -117,5 +132,13 @@ } } + flush(); + } + + + private InputStream open( String loc ) throws IOException + { + URL url = new URL( loc ); + return url.openStream(); } }
