You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by GitBox <gi...@apache.org> on 2020/07/06 21:14:26 UTC

[GitHub] [maven-assembly-plugin] elharo commented on a change in pull request #31: remove dependency on maven-shared-io

elharo commented on a change in pull request #31:
URL: https://github.com/apache/maven-assembly-plugin/pull/31#discussion_r450482291



##########
File path: src/main/java/org/apache/maven/plugins/assembly/io/ClasspathResourceLocatorStrategy.java
##########
@@ -0,0 +1,67 @@
+package org.apache.maven.plugins.assembly.io;
+
+/*
+ * 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.
+ */
+
+import java.net.URL;
+
+/**
+ * classpath resource locator strategy.
+ */
+class ClasspathResourceLocatorStrategy
+    implements LocatorStrategy
+{
+
+    private String tempFilePrefix = "location.";
+
+    private String tempFileSuffix = ".cpurl";
+
+    private boolean tempFileDeleteOnExit = true;
+
+    /**
+     * Create instance.
+     */
+    ClasspathResourceLocatorStrategy()
+    {
+    }
+
+    /** {@inheritDoc} */
+    public Location resolve( String locationSpecification, MessageHolder messageHolder )
+    {
+        ClassLoader cloader = Thread.currentThread().getContextClassLoader();
+
+        URL resource = cloader.getResource( locationSpecification );
+
+        Location location = null;
+
+        if ( resource != null )
+        {
+            location = new URLLocation( resource, locationSpecification, tempFilePrefix, tempFileSuffix,
+                                        tempFileDeleteOnExit );
+        }
+        else
+        {
+            messageHolder.addMessage( "Failed to resolve classpath resource: " + locationSpecification

Review comment:
       perhaps it should be. For now this just tries to maintain existing behavior.

##########
File path: src/main/java/org/apache/maven/plugins/assembly/io/MessageLevels.java
##########
@@ -0,0 +1,117 @@
+package org.apache.maven.plugins.assembly.io;
+
+/*
+ * 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.
+ */
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * 
+ */
+final class MessageLevels
+{
+
+    /**
+     * Debug.
+     */
+    public static final int LEVEL_DEBUG = 0;
+    /**
+     * Info
+     */
+    public static final int LEVEL_INFO = 1;
+    /**
+     * Warning.
+     */
+    public static final int LEVEL_WARNING = 2;
+    /**
+     * Error
+     */
+    public static final int LEVEL_ERROR = 3;

Review comment:
       I suspect this code predates Java 5. 

##########
File path: src/main/java/org/apache/maven/plugins/assembly/io/FileLocation.java
##########
@@ -0,0 +1,175 @@
+package org.apache.maven.plugins.assembly.io;
+
+/*
+ * 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.
+ */
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.ByteBuffer;
+import java.nio.channels.FileChannel;
+
+
+/**
+ * file location implementation.
+ *
+ */
+class FileLocation
+    implements Location
+{
+
+    private File file;
+    private FileChannel channel;
+    private final String specification;
+    private FileInputStream stream;
+
+    /**
+     * @param file {@link File}
+     * @param specification spec
+     */
+    FileLocation( File file, String specification )
+    {
+        this.file = file;
+        this.specification = specification;
+    }
+
+    /**
+     * @param specification spec
+     */
+    FileLocation( String specification )
+    {
+        this.specification = specification;
+    }
+
+    /** {@inheritDoc} */
+    public void close()
+    {
+        if ( ( channel != null ) && channel.isOpen() )
+        {
+            try
+            {
+                channel.close();
+            }
+            catch ( IOException e )
+            {
+                //swallow it.

Review comment:
       In general, yes. Exceptions are often swallowed when closing a resource though, under the assumption that nothing else important will happen with it.
   
   Also, note that most of this code is just moved over from maven-shared-io. It's not actually new. I just wanted eliminate the dependencies on the much larger parts of maven-sahred-io we're not using here. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org