]> source.dussan.org Git - archiva.git/commitdiff
use Files from java.nio
authorOlivier Lamy <olamy@apache.org>
Wed, 16 Apr 2014 07:36:01 +0000 (17:36 +1000)
committerOlivier Lamy <olamy@apache.org>
Wed, 16 Apr 2014 07:36:01 +0000 (17:36 +1000)
archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyConnectors.java
archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/remotedownload/RemoteRepositoryConnectivityCheckTest.java
archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java
archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/AbstractRepositoryServletProxiedTestCase.java
archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/RepositoryModelResolver.java

index c4b8b0f11dc9faabee73f512fb8cfd8e3f413004..151dd61ea4f3664cf91eb0a38232b3e8ba3e2a33 100644 (file)
@@ -19,7 +19,6 @@ package org.apache.archiva.proxy;
  * under the License.
  */
 
-import com.google.common.io.Files;
 import org.apache.archiva.admin.model.RepositoryAdminException;
 import org.apache.archiva.admin.model.beans.NetworkProxy;
 import org.apache.archiva.admin.model.beans.ProxyConnectorRuleType;
@@ -87,6 +86,7 @@ import javax.inject.Inject;
 import javax.inject.Named;
 import java.io.File;
 import java.io.IOException;
+import java.nio.file.Files;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -99,7 +99,7 @@ import java.util.concurrent.ConcurrentHashMap;
 
 /**
  * DefaultRepositoryProxyConnectors
- *
+ * <p/>
  * TODO exception handling needs work - "not modified" is not really an exceptional case, and it has more layers than
  * your average brown onion
  */
@@ -148,7 +148,7 @@ public class DefaultRepositoryProxyConnectors
     private NetworkProxyAdmin networkProxyAdmin;
 
     @Inject
-    @Named( value = "fileLockManager#default" )
+    @Named(value = "fileLockManager#default")
     private FileLockManager fileLockManager;
 
     @PostConstruct
@@ -283,8 +283,7 @@ public class DefaultRepositoryProxyConnectors
                                                                            String targetRepository,
                                                                            List<ProxyConnectorRuleConfiguration> all )
     {
-        List<ProxyConnectorRuleConfiguration> proxyConnectorRuleConfigurations =
-            new ArrayList<>();
+        List<ProxyConnectorRuleConfiguration> proxyConnectorRuleConfigurations = new ArrayList<>();
 
         for ( ProxyConnectorRuleConfiguration proxyConnectorRuleConfiguration : all )
         {
@@ -430,7 +429,8 @@ public class DefaultRepositoryProxyConnectors
                 log.debug( MarkerFactory.getDetachedMarker( "transfer.error" ),
                            "Transfer error from repository \"" + targetRepository.getRepository().getId()
                                + "\" for resource " + path + ", continuing to next repository. Error message: {}",
-                           e.getMessage(), e );
+                           e.getMessage(), e
+                );
             }
             catch ( RepositoryAdminException e )
             {
@@ -1067,7 +1067,15 @@ public class DefaultRepositoryProxyConnectors
      */
     private File createWorkingDirectory( ManagedRepositoryContent repository )
     {
-        return Files.createTempDir();
+        try
+        {
+            return Files.createTempDirectory( "temp" ).toFile();
+        }
+        catch ( IOException e )
+        {
+            throw new RuntimeException( e.getMessage(), e );
+        }
+
     }
 
     /**
@@ -1120,10 +1128,12 @@ public class DefaultRepositoryProxyConnectors
                     FileUtils.deleteQuietly( temp );
                 }
             }
-        } catch( FileLockException e)
+        }
+        catch ( FileLockException e )
         {
             throw new ProxyException( e.getMessage(), e );
-        } catch (FileLockTimeoutException e)
+        }
+        catch ( FileLockTimeoutException e )
         {
             throw new ProxyException( e.getMessage(), e );
         }
index 1b15f06e04e2f78070ac7adebe17d37fb0b70ff5..fabe56808c58be63a01b99a74e05e7d7b372445f 100644 (file)
@@ -19,7 +19,6 @@ package org.apache.archiva.remotedownload;
  * under the License.
  */
 
-import com.google.common.io.Files;
 import org.apache.archiva.admin.model.beans.RemoteRepository;
 import org.apache.archiva.rest.api.services.RemoteRepositoriesService;
 import org.apache.commons.io.FileUtils;
@@ -34,6 +33,7 @@ import org.junit.BeforeClass;
 import org.junit.Test;
 
 import java.io.File;
+import java.nio.file.Files;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
@@ -102,7 +102,7 @@ public class RemoteRepositoryConnectivityCheckTest
         throws Exception
     {
 
-        File tmpDir = Files.createTempDir();
+        File tmpDir = Files.createTempDirectory( "test" ).toFile();
         Server repoServer = buildStaticServer( tmpDir );
         repoServer.start();
 
index b252fe302ed0d11ff59ffed6bce7d0a9fb0e6680..21865cafa318e585b828e39ddae0ec1ad1c4aca0 100644 (file)
@@ -19,7 +19,6 @@ package org.apache.archiva.webdav;
  * under the License.
  */
 
-import com.google.common.io.Files;
 import org.apache.archiva.admin.model.RepositoryAdminException;
 import org.apache.archiva.admin.model.beans.ManagedRepository;
 import org.apache.archiva.admin.model.beans.RemoteRepository;
@@ -106,6 +105,7 @@ import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpSession;
 import java.io.File;
 import java.io.IOException;
+import java.nio.file.Files;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
@@ -1343,7 +1343,7 @@ public class ArchivaDavResourceFactory
             log.info( "generate temporary merged index for repository group '{}' for repositories '{}'",
                       repositoryGroupConfiguration.getId(), authzRepos );
 
-            File tempRepoFile = Files.createTempDir();
+            File tempRepoFile = Files.createTempDirectory("temp").toFile();
             tempRepoFile.deleteOnExit();
 
             IndexMergerRequest indexMergerRequest =
@@ -1374,6 +1374,9 @@ public class ArchivaDavResourceFactory
             throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e );
         }
         catch ( IndexMergerException e )
+        {
+            throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e );
+        } catch ( IOException e )
         {
             throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e );
         }
index c38e33f54313cab6cfb51b0d2c59e6e0d94d7dff..3d8a5e6dcaae31ac138f86eaad0e2b04e2d884a6 100644 (file)
@@ -21,9 +21,6 @@ package org.apache.archiva.webdav;
 
 
 import com.gargoylesoftware.htmlunit.WebClient;
-import com.gargoylesoftware.htmlunit.WebRequest;
-import com.gargoylesoftware.htmlunit.WebResponse;
-import com.google.common.io.Files;
 import org.apache.archiva.configuration.ProxyConnectorConfiguration;
 import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
 import org.apache.archiva.policies.CachedFailuresPolicy;
@@ -36,17 +33,18 @@ import org.eclipse.jetty.server.handler.ContextHandlerCollection;
 import org.eclipse.jetty.servlet.DefaultServlet;
 import org.eclipse.jetty.servlet.ServletContextHandler;
 import org.eclipse.jetty.servlet.ServletHolder;
-import static org.assertj.core.api.Assertions.assertThat;
 import org.junit.After;
 import org.junit.Before;
 
 import javax.servlet.http.HttpServletResponse;
 import java.io.File;
 import java.nio.charset.Charset;
+import java.nio.file.Files;
+
+import static org.assertj.core.api.Assertions.assertThat;
 
 /**
  * AbstractRepositoryServletProxiedTestCase
- *
  */
 public abstract class AbstractRepositoryServletProxiedTestCase
     extends AbstractRepositoryServletTestCase
@@ -121,7 +119,8 @@ public abstract class AbstractRepositoryServletProxiedTestCase
         RemoteRepoInfo repo = new RemoteRepoInfo();
         repo.id = id;
         repo.context = "/" + id;
-        repo.root = Files.createTempDir();// new File( System.getProperty( "basedir" ) + "target/remote-repos/" + id + "/" );
+        repo.root = Files.createTempDirectory(
+            "temp" ).toFile();// new File( System.getProperty( "basedir" ) + "target/remote-repos/" + id + "/" );
 
         // Remove exising root contents.
         if ( repo.root.exists() )
@@ -213,12 +212,12 @@ public abstract class AbstractRepositoryServletProxiedTestCase
         throws Exception
     {
         File destFile = new File( remoteRepo.root, path );
-        if (destFile.exists())
+        if ( destFile.exists() )
         {
             destFile.delete();
         }
         destFile.getParentFile().mkdirs();
-        FileUtils.writeStringToFile( destFile, contents, Charset.defaultCharset()  );
+        FileUtils.writeStringToFile( destFile, contents, Charset.defaultCharset() );
         return destFile;
     }
 
@@ -260,7 +259,6 @@ public abstract class AbstractRepositoryServletProxiedTestCase
     {
         remoteSnapshots = createServer( "snapshots" );
 
-
         assertServerSetupCorrectly( remoteSnapshots );
         RemoteRepositoryConfiguration remoteRepositoryConfiguration =
             archivaConfiguration.getConfiguration().getRemoteRepositoriesAsMap().get( remoteSnapshots.id );
index a419bb91f64916f1b57d5d58ae82a3086e03cc34..99340f3e929c0cf3f33a45b66f61d4aa66453f6f 100644 (file)
@@ -19,7 +19,6 @@ package org.apache.archiva.metadata.repository.storage.maven2;
  * under the License.
  */
 
-import com.google.common.io.Files;
 import org.apache.archiva.admin.model.beans.ManagedRepository;
 import org.apache.archiva.admin.model.beans.NetworkProxy;
 import org.apache.archiva.admin.model.beans.RemoteRepository;
@@ -53,6 +52,7 @@ import org.slf4j.LoggerFactory;
 
 import java.io.File;
 import java.io.IOException;
+import java.nio.file.Files;
 import java.util.List;
 import java.util.Map;
 
@@ -177,8 +177,8 @@ public class RepositoryModelResolver
                     int buildNumber = snapshotVersion.getBuildNumber();
                     String snapshotPath =
                         StringUtils.replaceChars( groupId, '.', '/' ) + '/' + artifactId + '/' + version + '/'
-                            + artifactId + '-' + StringUtils.remove( version, "-" + VersionUtil.SNAPSHOT )
-                            + '-' + lastVersion + '-' + buildNumber + ".pom";
+                            + artifactId + '-' + StringUtils.remove( version, "-" + VersionUtil.SNAPSHOT ) + '-'
+                            + lastVersion + '-' + buildNumber + ".pom";
 
                     log.debug( "use snapshot path {} for maven coordinate {}:{}:{}", snapshotPath, groupId, artifactId,
                                version );
@@ -220,7 +220,7 @@ public class RepositoryModelResolver
     private boolean getModelFromProxy( RemoteRepository remoteRepository, String groupId, String artifactId,
                                        String version, String filename )
         throws AuthorizationException, TransferFailedException, ResourceDoesNotExistException, WagonFactoryException,
-        XMLException
+        XMLException, IOException
     {
         boolean success = false;
         File tmpMd5 = null;
@@ -240,7 +240,8 @@ public class RepositoryModelResolver
 
                 wagon = wagonFactory.getWagon(
                     new WagonFactoryRequest( "wagon#" + protocol, remoteRepository.getExtraHeaders() ).networkProxy(
-                        networkProxy ) );
+                        networkProxy )
+                );
 
                 if ( wagon == null )
                 {
@@ -439,8 +440,9 @@ public class RepositoryModelResolver
     }
 
     private File createWorkingDirectory( String targetRepository )
+        throws IOException
     {
-        return Files.createTempDir();
+        return Files.createTempDirectory( "temp" ).toFile();
     }
 
     private void moveFileIfExists( File fileToMove, File directory )