mirror of https://github.com/apache/archiva.git
use Files from java.nio
This commit is contained in:
parent
67985e0486
commit
767e00c182
|
@ -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 );
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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 )
|
||||
|
|
Loading…
Reference in New Issue