You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by eb...@apache.org on 2020/04/06 13:34:53 UTC

[tomcat-jakartaee-migration] 01/03: Replaced NonClosing{In, Out}putStream with the equivalent classes from Commons IO

This is an automated email from the ASF dual-hosted git repository.

ebourg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat-jakartaee-migration.git

commit 29ea1891489060f3b3e40259098def5ae47645ef
Author: Emmanuel Bourg <eb...@apache.org>
AuthorDate: Mon Apr 6 15:24:35 2020 +0200

    Replaced NonClosing{In,Out}putStream with the equivalent classes from Commons IO
---
 pom.xml                                            |  5 ++
 .../org/apache/tomcat/jakartaee/Migration.java     |  7 +-
 .../tomcat/jakartaee/NonClosingInputStream.java    | 84 ----------------------
 .../tomcat/jakartaee/NonClosingOutputStream.java   | 60 ----------------
 4 files changed, 10 insertions(+), 146 deletions(-)

diff --git a/pom.xml b/pom.xml
index cf7f18b..ab74cfe 100644
--- a/pom.xml
+++ b/pom.xml
@@ -71,6 +71,11 @@
       <artifactId>bcel</artifactId>
       <version>6.4.1</version>
     </dependency>
+    <dependency>
+      <groupId>commons-io</groupId>
+      <artifactId>commons-io</artifactId>
+      <version>2.6</version>
+    </dependency>
   </dependencies>
 
   <build>
diff --git a/src/main/java/org/apache/tomcat/jakartaee/Migration.java b/src/main/java/org/apache/tomcat/jakartaee/Migration.java
index 734ebd8..5d8fdf1 100644
--- a/src/main/java/org/apache/tomcat/jakartaee/Migration.java
+++ b/src/main/java/org/apache/tomcat/jakartaee/Migration.java
@@ -36,6 +36,9 @@ import java.util.jar.Manifest;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import org.apache.commons.io.input.CloseShieldInputStream;
+import org.apache.commons.io.output.CloseShieldOutputStream;
+
 public class Migration {
 
     private static final Logger logger = Logger.getLogger(Migration.class.getCanonicalName());
@@ -131,8 +134,8 @@ public class Migration {
 
     private boolean migrateArchive(InputStream src, OutputStream dest) throws IOException {
         boolean result = true;
-        try (JarInputStream jarIs = new JarInputStream(new NonClosingInputStream(src));
-                JarOutputStream jarOs = new JarOutputStream(new NonClosingOutputStream(dest))) {
+        try (JarInputStream jarIs = new JarInputStream(new CloseShieldInputStream(src));
+                JarOutputStream jarOs = new JarOutputStream(new CloseShieldOutputStream(dest))) {
             Manifest manifest = jarIs.getManifest();
             if (manifest != null) {
                 // Make a safe copy to leave original manifest untouched.
diff --git a/src/main/java/org/apache/tomcat/jakartaee/NonClosingInputStream.java b/src/main/java/org/apache/tomcat/jakartaee/NonClosingInputStream.java
deleted file mode 100644
index 53f883c..0000000
--- a/src/main/java/org/apache/tomcat/jakartaee/NonClosingInputStream.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * 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.tomcat.jakartaee;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-public class NonClosingInputStream extends InputStream {
-
-    private InputStream wrapped;
-
-
-    public NonClosingInputStream(InputStream wrapped) {
-        this.wrapped = wrapped;
-    }
-
-
-    @Override
-    public int read() throws IOException {
-        return wrapped.read();
-    }
-
-
-    @Override
-    public int read(byte[] b) throws IOException {
-        return wrapped.read(b);
-    }
-
-
-    @Override
-    public int read(byte[] b, int off, int len) throws IOException {
-        return wrapped.read(b, off, len);
-    }
-
-
-    @Override
-    public long skip(long n) throws IOException {
-        return wrapped.skip(n);
-    }
-
-
-    @Override
-    public int available() throws IOException {
-        return wrapped.available();
-    }
-
-
-    @Override
-    public void close() throws IOException {
-        // NO-OP
-    }
-
-
-    @Override
-    public synchronized void mark(int readlimit) {
-        wrapped.mark(readlimit);
-    }
-
-
-    @Override
-    public synchronized void reset() throws IOException {
-        wrapped.reset();
-    }
-
-
-    @Override
-    public boolean markSupported() {
-        return wrapped.markSupported();
-    }
-}
diff --git a/src/main/java/org/apache/tomcat/jakartaee/NonClosingOutputStream.java b/src/main/java/org/apache/tomcat/jakartaee/NonClosingOutputStream.java
deleted file mode 100644
index b4ee198..0000000
--- a/src/main/java/org/apache/tomcat/jakartaee/NonClosingOutputStream.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * 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.tomcat.jakartaee;
-
-import java.io.IOException;
-import java.io.OutputStream;
-
-public class NonClosingOutputStream extends OutputStream {
-
-    private OutputStream wrapped;
-
-
-    public NonClosingOutputStream(OutputStream wrapped) {
-        this.wrapped = wrapped;
-    }
-
-
-    @Override
-    public void write(int b) throws IOException {
-        wrapped.write(b);
-    }
-
-
-    @Override
-    public void write(byte[] b) throws IOException {
-        wrapped.write(b);
-    }
-
-
-    @Override
-    public void write(byte[] b, int off, int len) throws IOException {
-        wrapped.write(b, off, len);
-    }
-
-
-    @Override
-    public void flush() throws IOException {
-        wrapped.flush();
-    }
-
-
-    @Override
-    public void close() throws IOException {
-        // NO-OP
-    }
-}


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: [tomcat-jakartaee-migration] 01/03: Replaced NonClosing{In, Out}putStream with the equivalent classes from Commons IO

Posted by Rémy Maucherat <re...@apache.org>.
On Tue, Apr 7, 2020 at 11:05 AM Emmanuel Bourg <eb...@apache.org> wrote:

> Le 07/04/2020 à 09:41, Rémy Maucherat a écrit :
>
> > Reimplemeting ... It was already done, and this was a better trivial
> > solution. This is a veto (unlike Mark I will not withdraw it), so please
> > revert this commit.
>
> Remy, this is honestly more a rant on an insignificant detail than a
> reasonably justified veto. It doesn't affect the correctness, the
> performance or the maintainability of the tool. I'm tempted to translate
> this as "Don't touch my project" and an incitation to go work on
> something else.
>
> The dependency graph of this tool is very likely to grow as its features
> expand (think about adding a CLI parser, providing the tool as a
> Maven/Gradle plugin or an Ant task), and I wouldn't be surprised to see
> Commons IO brought to the classpath sooner or later anyway (or the
> overhead diluted).
>

This is exactly the reason why we don't use Maven in Tomcat, dependencies
creep up because it is "normal".

Rémy

Re: [tomcat-jakartaee-migration] 01/03: Replaced NonClosing{In, Out}putStream with the equivalent classes from Commons IO

Posted by Emmanuel Bourg <eb...@apache.org>.
Le 07/04/2020 à 09:41, Rémy Maucherat a écrit :

> Reimplemeting ... It was already done, and this was a better trivial
> solution. This is a veto (unlike Mark I will not withdraw it), so please
> revert this commit.

Remy, this is honestly more a rant on an insignificant detail than a
reasonably justified veto. It doesn't affect the correctness, the
performance or the maintainability of the tool. I'm tempted to translate
this as "Don't touch my project" and an incitation to go work on
something else.

The dependency graph of this tool is very likely to grow as its features
expand (think about adding a CLI parser, providing the tool as a
Maven/Gradle plugin or an Ant task), and I wouldn't be surprised to see
Commons IO brought to the classpath sooner or later anyway (or the
overhead diluted).

Emmanuel Bourg

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: [tomcat-jakartaee-migration] 01/03: Replaced NonClosing{In, Out}putStream with the equivalent classes from Commons IO

Posted by Rémy Maucherat <re...@apache.org>.
On Mon, Apr 6, 2020 at 3:45 PM Emmanuel Bourg <eb...@apache.org> wrote:

> Le 06/04/2020 à 15:38, Rémy Maucherat a écrit :
>
> >     commit 29ea1891489060f3b3e40259098def5ae47645ef
> >     Author: Emmanuel Bourg <ebourg@apache.org <mailto:ebourg@apache.org
> >>
> >     AuthorDate: Mon Apr 6 15:24:35 2020 +0200
> >
> >         Replaced NonClosing{In,Out}putStream with the equivalent classes
> >     from Commons IO
> >
> >
> > Ah, the beauty of having Maven. Actual benefit: zero. Trouble with
> > updating dependencies: one. Possible incompatibilities: one.
> > So I think it's a total of -2 for the commit.
>
> Sorry but I'm not sure to understand your objection. Commons IO is dead
> stable, these classes have been around for over 10 years and haven't
> changed much since. There is really no point reimplementing them.
>

Reimplemeting ... It was already done, and this was a better trivial
solution. This is a veto (unlike Mark I will not withdraw it), so please
revert this commit.

Rémy

Re: [tomcat-jakartaee-migration] 01/03: Replaced NonClosing{In, Out}putStream with the equivalent classes from Commons IO

Posted by Emmanuel Bourg <eb...@apache.org>.
Le 06/04/2020 à 15:38, Rémy Maucherat a écrit :

>     commit 29ea1891489060f3b3e40259098def5ae47645ef
>     Author: Emmanuel Bourg <ebourg@apache.org <ma...@apache.org>>
>     AuthorDate: Mon Apr 6 15:24:35 2020 +0200
> 
>         Replaced NonClosing{In,Out}putStream with the equivalent classes
>     from Commons IO
> 
> 
> Ah, the beauty of having Maven. Actual benefit: zero. Trouble with
> updating dependencies: one. Possible incompatibilities: one.
> So I think it's a total of -2 for the commit.

Sorry but I'm not sure to understand your objection. Commons IO is dead
stable, these classes have been around for over 10 years and haven't
changed much since. There is really no point reimplementing them.

Emmanuel Bourg

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: [tomcat-jakartaee-migration] 01/03: Replaced NonClosing{In, Out}putStream with the equivalent classes from Commons IO

Posted by Rémy Maucherat <re...@apache.org>.
On Mon, Apr 6, 2020 at 3:34 PM <eb...@apache.org> wrote:

> This is an automated email from the ASF dual-hosted git repository.
>
> ebourg pushed a commit to branch master
> in repository
> https://gitbox.apache.org/repos/asf/tomcat-jakartaee-migration.git
>
> commit 29ea1891489060f3b3e40259098def5ae47645ef
> Author: Emmanuel Bourg <eb...@apache.org>
> AuthorDate: Mon Apr 6 15:24:35 2020 +0200
>
>     Replaced NonClosing{In,Out}putStream with the equivalent classes from
> Commons IO
>

Ah, the beauty of having Maven. Actual benefit: zero. Trouble with updating
dependencies: one. Possible incompatibilities: one.
So I think it's a total of -2 for the commit.

Rémy


> ---
>  pom.xml                                            |  5 ++
>  .../org/apache/tomcat/jakartaee/Migration.java     |  7 +-
>  .../tomcat/jakartaee/NonClosingInputStream.java    | 84
> ----------------------
>  .../tomcat/jakartaee/NonClosingOutputStream.java   | 60 ----------------
>  4 files changed, 10 insertions(+), 146 deletions(-)
>
> diff --git a/pom.xml b/pom.xml
> index cf7f18b..ab74cfe 100644
> --- a/pom.xml
> +++ b/pom.xml
> @@ -71,6 +71,11 @@
>        <artifactId>bcel</artifactId>
>        <version>6.4.1</version>
>      </dependency>
> +    <dependency>
> +      <groupId>commons-io</groupId>
> +      <artifactId>commons-io</artifactId>
> +      <version>2.6</version>
> +    </dependency>
>    </dependencies>
>
>    <build>
> diff --git a/src/main/java/org/apache/tomcat/jakartaee/Migration.java
> b/src/main/java/org/apache/tomcat/jakartaee/Migration.java
> index 734ebd8..5d8fdf1 100644
> --- a/src/main/java/org/apache/tomcat/jakartaee/Migration.java
> +++ b/src/main/java/org/apache/tomcat/jakartaee/Migration.java
> @@ -36,6 +36,9 @@ import java.util.jar.Manifest;
>  import java.util.logging.Level;
>  import java.util.logging.Logger;
>
> +import org.apache.commons.io.input.CloseShieldInputStream;
> +import org.apache.commons.io.output.CloseShieldOutputStream;
> +
>  public class Migration {
>
>      private static final Logger logger =
> Logger.getLogger(Migration.class.getCanonicalName());
> @@ -131,8 +134,8 @@ public class Migration {
>
>      private boolean migrateArchive(InputStream src, OutputStream dest)
> throws IOException {
>          boolean result = true;
> -        try (JarInputStream jarIs = new JarInputStream(new
> NonClosingInputStream(src));
> -                JarOutputStream jarOs = new JarOutputStream(new
> NonClosingOutputStream(dest))) {
> +        try (JarInputStream jarIs = new JarInputStream(new
> CloseShieldInputStream(src));
> +                JarOutputStream jarOs = new JarOutputStream(new
> CloseShieldOutputStream(dest))) {
>              Manifest manifest = jarIs.getManifest();
>              if (manifest != null) {
>                  // Make a safe copy to leave original manifest untouched.
> diff --git
> a/src/main/java/org/apache/tomcat/jakartaee/NonClosingInputStream.java
> b/src/main/java/org/apache/tomcat/jakartaee/NonClosingInputStream.java
> deleted file mode 100644
> index 53f883c..0000000
> --- a/src/main/java/org/apache/tomcat/jakartaee/NonClosingInputStream.java
> +++ /dev/null
> @@ -1,84 +0,0 @@
> -/*
> - * 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.tomcat.jakartaee;
> -
> -import java.io.IOException;
> -import java.io.InputStream;
> -
> -public class NonClosingInputStream extends InputStream {
> -
> -    private InputStream wrapped;
> -
> -
> -    public NonClosingInputStream(InputStream wrapped) {
> -        this.wrapped = wrapped;
> -    }
> -
> -
> -    @Override
> -    public int read() throws IOException {
> -        return wrapped.read();
> -    }
> -
> -
> -    @Override
> -    public int read(byte[] b) throws IOException {
> -        return wrapped.read(b);
> -    }
> -
> -
> -    @Override
> -    public int read(byte[] b, int off, int len) throws IOException {
> -        return wrapped.read(b, off, len);
> -    }
> -
> -
> -    @Override
> -    public long skip(long n) throws IOException {
> -        return wrapped.skip(n);
> -    }
> -
> -
> -    @Override
> -    public int available() throws IOException {
> -        return wrapped.available();
> -    }
> -
> -
> -    @Override
> -    public void close() throws IOException {
> -        // NO-OP
> -    }
> -
> -
> -    @Override
> -    public synchronized void mark(int readlimit) {
> -        wrapped.mark(readlimit);
> -    }
> -
> -
> -    @Override
> -    public synchronized void reset() throws IOException {
> -        wrapped.reset();
> -    }
> -
> -
> -    @Override
> -    public boolean markSupported() {
> -        return wrapped.markSupported();
> -    }
> -}
> diff --git
> a/src/main/java/org/apache/tomcat/jakartaee/NonClosingOutputStream.java
> b/src/main/java/org/apache/tomcat/jakartaee/NonClosingOutputStream.java
> deleted file mode 100644
> index b4ee198..0000000
> --- a/src/main/java/org/apache/tomcat/jakartaee/NonClosingOutputStream.java
> +++ /dev/null
> @@ -1,60 +0,0 @@
> -/*
> - * 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.tomcat.jakartaee;
> -
> -import java.io.IOException;
> -import java.io.OutputStream;
> -
> -public class NonClosingOutputStream extends OutputStream {
> -
> -    private OutputStream wrapped;
> -
> -
> -    public NonClosingOutputStream(OutputStream wrapped) {
> -        this.wrapped = wrapped;
> -    }
> -
> -
> -    @Override
> -    public void write(int b) throws IOException {
> -        wrapped.write(b);
> -    }
> -
> -
> -    @Override
> -    public void write(byte[] b) throws IOException {
> -        wrapped.write(b);
> -    }
> -
> -
> -    @Override
> -    public void write(byte[] b, int off, int len) throws IOException {
> -        wrapped.write(b, off, len);
> -    }
> -
> -
> -    @Override
> -    public void flush() throws IOException {
> -        wrapped.flush();
> -    }
> -
> -
> -    @Override
> -    public void close() throws IOException {
> -        // NO-OP
> -    }
> -}
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: dev-help@tomcat.apache.org
>
>