mirror of https://github.com/apache/archiva.git
And another one for moving to java.nio
This commit is contained in:
parent
4781155596
commit
90250dc304
|
@ -51,8 +51,10 @@ import org.springframework.stereotype.Service;
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
@ -95,6 +97,8 @@ public class DefaultArchivaConfiguration
|
||||||
{
|
{
|
||||||
private Logger log = LoggerFactory.getLogger( DefaultArchivaConfiguration.class );
|
private Logger log = LoggerFactory.getLogger( DefaultArchivaConfiguration.class );
|
||||||
|
|
||||||
|
private static String FILE_ENCODING = "UTF-8";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plexus registry to read the configuration from.
|
* Plexus registry to read the configuration from.
|
||||||
*/
|
*/
|
||||||
|
@ -684,21 +688,21 @@ public class DefaultArchivaConfiguration
|
||||||
*/
|
*/
|
||||||
private boolean writeFile( String filetype, String path, String contents )
|
private boolean writeFile( String filetype, String path, String contents )
|
||||||
{
|
{
|
||||||
File file = new File( path );
|
Path file = Paths.get( path );
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Check parent directory (if it is declared)
|
// Check parent directory (if it is declared)
|
||||||
if ( file.getParentFile() != null )
|
if ( file.getParent() != null )
|
||||||
{
|
{
|
||||||
// Check that directory exists
|
// Check that directory exists
|
||||||
if ( !file.getParentFile().isDirectory() )
|
if ( !Files.isDirectory( file.getParent() ) )
|
||||||
{
|
{
|
||||||
// Directory to file must exist for file to be created
|
// Directory to file must exist for file to be created
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FileUtils.writeStringToFile( file, contents, "UTF-8" );
|
FileUtils.writeStringToFile( file.toFile(), contents, FILE_ENCODING);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch ( IOException e )
|
catch ( IOException e )
|
||||||
|
@ -950,9 +954,9 @@ public class DefaultArchivaConfiguration
|
||||||
for ( ManagedRepositoryConfiguration repo : (List<ManagedRepositoryConfiguration>) config.getManagedRepositories() )
|
for ( ManagedRepositoryConfiguration repo : (List<ManagedRepositoryConfiguration>) config.getManagedRepositories() )
|
||||||
{
|
{
|
||||||
String repoPath = repo.getLocation();
|
String repoPath = repo.getLocation();
|
||||||
File repoLocation = new File( repoPath );
|
Path repoLocation = Paths.get( repoPath );
|
||||||
|
|
||||||
if ( repoLocation.exists() && repoLocation.isDirectory() && !repoPath.endsWith(
|
if ( Files.exists(repoLocation) && Files.isDirectory(repoLocation) && !repoPath.endsWith(
|
||||||
"data/repositories/" + repo.getId() ) )
|
"data/repositories/" + repo.getId() ) )
|
||||||
{
|
{
|
||||||
repo.setLocation( repoPath + "/data/repositories/" + repo.getId() );
|
repo.setLocation( repoPath + "/data/repositories/" + repo.getId() );
|
||||||
|
|
|
@ -19,8 +19,10 @@ package org.apache.archiva.configuration;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import org.apache.archiva.common.utils.FileUtil;
|
import org.apache.archiva.common.utils.FileUtil;
|
||||||
|
@ -41,15 +43,17 @@ import org.springframework.test.context.ContextConfiguration;
|
||||||
public class ArchivaConfigurationMRM789Test
|
public class ArchivaConfigurationMRM789Test
|
||||||
{
|
{
|
||||||
|
|
||||||
|
private static String FILE_ENCODING = "UTF-8";
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected ApplicationContext applicationContext;
|
protected ApplicationContext applicationContext;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
FileTypes filetypes;
|
FileTypes filetypes;
|
||||||
|
|
||||||
public static File getTestFile( String path )
|
public static Path getTestFile( String path )
|
||||||
{
|
{
|
||||||
return new File( FileUtil.getBasedir(), path );
|
return Paths.get( FileUtil.getBasedir(), path );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected <T> T lookup( Class<T> clazz, String hint )
|
protected <T> T lookup( Class<T> clazz, String hint )
|
||||||
|
@ -62,22 +66,22 @@ public class ArchivaConfigurationMRM789Test
|
||||||
public void testGetConfigurationFromDefaultsWithDefaultRepoLocationAlreadyExisting()
|
public void testGetConfigurationFromDefaultsWithDefaultRepoLocationAlreadyExisting()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
File repo = new File( FileUtil.getBasedir(), "target/test-classes/existing_snapshots" );
|
Path repo = Paths.get( FileUtil.getBasedir(), "target/test-classes/existing_snapshots" );
|
||||||
repo.mkdirs();
|
Files.createDirectories(repo);
|
||||||
|
|
||||||
repo = new File( FileUtil.getBasedir(), "target/test-classes/existing_internal" );
|
repo = Paths.get( FileUtil.getBasedir(), "target/test-classes/existing_internal" );
|
||||||
repo.mkdirs();
|
Files.createDirectories(repo);
|
||||||
|
|
||||||
String existingTestDefaultArchivaConfigFile = FileUtils.readFileToString(
|
String existingTestDefaultArchivaConfigFile = FileUtils.readFileToString(
|
||||||
getTestFile( "target/test-classes/org/apache/archiva/configuration/test-default-archiva.xml" ) );
|
getTestFile( "target/test-classes/org/apache/archiva/configuration/test-default-archiva.xml" ).toFile(), FILE_ENCODING );
|
||||||
existingTestDefaultArchivaConfigFile =
|
existingTestDefaultArchivaConfigFile =
|
||||||
StringUtils.replace( existingTestDefaultArchivaConfigFile, "${appserver.base}", FileUtil.getBasedir() );
|
StringUtils.replace( existingTestDefaultArchivaConfigFile, "${appserver.base}", FileUtil.getBasedir() );
|
||||||
|
|
||||||
File generatedTestDefaultArchivaConfigFile = new File( FileUtil.getBasedir(),
|
Path generatedTestDefaultArchivaConfigFile = Paths.get( FileUtil.getBasedir(),
|
||||||
"target/test-classes/org/apache/archiva/configuration/default-archiva.xml" );
|
"target/test-classes/org/apache/archiva/configuration/default-archiva.xml" );
|
||||||
|
|
||||||
FileUtils.writeStringToFile( generatedTestDefaultArchivaConfigFile, existingTestDefaultArchivaConfigFile,
|
FileUtils.writeStringToFile( generatedTestDefaultArchivaConfigFile.toFile(), existingTestDefaultArchivaConfigFile,
|
||||||
Charset.forName("UTF-8") );
|
Charset.forName(FILE_ENCODING) );
|
||||||
|
|
||||||
ArchivaConfiguration archivaConfiguration =
|
ArchivaConfiguration archivaConfiguration =
|
||||||
lookup( ArchivaConfiguration.class, "test-defaults-default-repo-location-exists" );
|
lookup( ArchivaConfiguration.class, "test-defaults-default-repo-location-exists" );
|
||||||
|
@ -87,8 +91,8 @@ public class ArchivaConfigurationMRM789Test
|
||||||
ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 );
|
ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 );
|
||||||
assertTrue( "check managed repositories", repository.getLocation().endsWith( "data/repositories/internal" ) );
|
assertTrue( "check managed repositories", repository.getLocation().endsWith( "data/repositories/internal" ) );
|
||||||
|
|
||||||
generatedTestDefaultArchivaConfigFile.delete();
|
Files.deleteIfExists(generatedTestDefaultArchivaConfigFile);
|
||||||
assertFalse( generatedTestDefaultArchivaConfigFile.exists() );
|
assertFalse( Files.exists(generatedTestDefaultArchivaConfigFile) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -34,8 +34,10 @@ import org.springframework.test.annotation.DirtiesContext.ClassMode;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import java.io.File;
|
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -59,9 +61,9 @@ public class ArchivaConfigurationTest
|
||||||
@Inject
|
@Inject
|
||||||
FileTypes filetypes;
|
FileTypes filetypes;
|
||||||
|
|
||||||
public static File getTestFile( String path )
|
public static Path getTestFile( String path )
|
||||||
{
|
{
|
||||||
return new File( FileUtil.getBasedir(), path );
|
return Paths.get( FileUtil.getBasedir(), path );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected <T> T lookup( Class<T> clazz, String hint )
|
protected <T> T lookup( Class<T> clazz, String hint )
|
||||||
|
@ -197,9 +199,9 @@ public class ArchivaConfigurationTest
|
||||||
public void testStoreConfiguration()
|
public void testStoreConfiguration()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
File file = getTestFile( "target/test/test-file.xml" );
|
Path file = getTestFile( "target/test/test-file.xml" );
|
||||||
file.delete();
|
Files.deleteIfExists(file);
|
||||||
assertFalse( file.exists() );
|
assertFalse( Files.exists(file) );
|
||||||
|
|
||||||
// TODO: remove with commons-configuration 1.4
|
// TODO: remove with commons-configuration 1.4
|
||||||
//file.getParentFile().mkdirs();
|
//file.getParentFile().mkdirs();
|
||||||
|
@ -228,7 +230,7 @@ public class ArchivaConfigurationTest
|
||||||
|
|
||||||
verify( listener );
|
verify( listener );
|
||||||
|
|
||||||
assertTrue( "Check file exists", file.exists() );
|
assertTrue( "Check file exists", Files.exists(file) );
|
||||||
|
|
||||||
// check it
|
// check it
|
||||||
configuration = archivaConfiguration.getConfiguration();
|
configuration = archivaConfiguration.getConfiguration();
|
||||||
|
@ -251,16 +253,16 @@ public class ArchivaConfigurationTest
|
||||||
public void testStoreConfigurationUser()
|
public void testStoreConfigurationUser()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
File baseFile = getTestFile( "target/test/test-file.xml" );
|
Path baseFile = getTestFile( "target/test/test-file.xml" );
|
||||||
baseFile.delete();
|
Files.deleteIfExists( baseFile );
|
||||||
assertFalse( baseFile.exists() );
|
assertFalse( Files.exists(baseFile) );
|
||||||
|
|
||||||
File userFile = getTestFile( "target/test/test-file-user.xml" );
|
Path userFile = getTestFile( "target/test/test-file-user.xml" );
|
||||||
userFile.delete();
|
Files.deleteIfExists( userFile );
|
||||||
assertFalse( userFile.exists() );
|
assertFalse( Files.exists(userFile) );
|
||||||
|
|
||||||
userFile.getParentFile().mkdirs();
|
Files.createDirectories(userFile.getParent());
|
||||||
FileUtils.writeStringToFile( userFile, "<configuration/>", Charset.forName( "UTF-8" ) );
|
FileUtils.writeStringToFile( userFile.toFile(), "<configuration/>", Charset.forName( "UTF-8" ) );
|
||||||
|
|
||||||
ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-save-user" );
|
ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-save-user" );
|
||||||
|
|
||||||
|
@ -271,8 +273,8 @@ public class ArchivaConfigurationTest
|
||||||
|
|
||||||
archivaConfiguration.save( configuration );
|
archivaConfiguration.save( configuration );
|
||||||
|
|
||||||
assertTrue( "Check file exists", userFile.exists() );
|
assertTrue( "Check file exists", Files.exists(userFile) );
|
||||||
assertFalse( "Check file not created", baseFile.exists() );
|
assertFalse( "Check file not created", Files.exists(baseFile) );
|
||||||
|
|
||||||
// check it
|
// check it
|
||||||
configuration = archivaConfiguration.getConfiguration();
|
configuration = archivaConfiguration.getConfiguration();
|
||||||
|
@ -283,13 +285,13 @@ public class ArchivaConfigurationTest
|
||||||
public void testStoreConfigurationLoadedFromDefaults()
|
public void testStoreConfigurationLoadedFromDefaults()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
File baseFile = getTestFile( "target/test/test-file.xml" );
|
Path baseFile = getTestFile( "target/test/test-file.xml" );
|
||||||
baseFile.delete();
|
Files.delete(baseFile);
|
||||||
assertFalse( baseFile.exists() );
|
assertFalse( Files.exists(baseFile) );
|
||||||
|
|
||||||
File userFile = getTestFile( "target/test/test-file-user.xml" );
|
Path userFile = getTestFile( "target/test/test-file-user.xml" );
|
||||||
userFile.delete();
|
Files.deleteIfExists(userFile);
|
||||||
assertFalse( userFile.exists() );
|
assertFalse( Files.exists(userFile) );
|
||||||
|
|
||||||
ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-save-user-defaults" );
|
ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-save-user-defaults" );
|
||||||
|
|
||||||
|
@ -312,8 +314,8 @@ public class ArchivaConfigurationTest
|
||||||
|
|
||||||
verify( listener );
|
verify( listener );
|
||||||
|
|
||||||
assertTrue( "Check file exists", userFile.exists() );
|
assertTrue( "Check file exists", Files.exists(userFile) );
|
||||||
assertFalse( "Check file not created", baseFile.exists() );
|
assertFalse( "Check file not created", Files.exists(baseFile) );
|
||||||
|
|
||||||
// check it
|
// check it
|
||||||
configuration = archivaConfiguration.getConfiguration();
|
configuration = archivaConfiguration.getConfiguration();
|
||||||
|
@ -339,16 +341,16 @@ public class ArchivaConfigurationTest
|
||||||
public void testStoreConfigurationFallback()
|
public void testStoreConfigurationFallback()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
File baseFile = getTestFile( "target/test/test-file.xml" );
|
Path baseFile = getTestFile( "target/test/test-file.xml" );
|
||||||
baseFile.delete();
|
Files.deleteIfExists(baseFile);
|
||||||
assertFalse( baseFile.exists() );
|
assertFalse( Files.exists(baseFile) );
|
||||||
|
|
||||||
File userFile = getTestFile( "target/test/test-file-user.xml" );
|
Path userFile = getTestFile( "target/test/test-file-user.xml" );
|
||||||
userFile.delete();
|
Files.deleteIfExists(userFile);
|
||||||
assertFalse( userFile.exists() );
|
assertFalse( Files.exists(userFile) );
|
||||||
|
|
||||||
baseFile.getParentFile().mkdirs();
|
Files.createDirectories( baseFile.getParent());
|
||||||
FileUtils.writeStringToFile( baseFile, "<configuration/>", Charset.forName( "UTF-8" ) );
|
FileUtils.writeStringToFile( baseFile.toFile(), "<configuration/>", Charset.forName( "UTF-8" ) );
|
||||||
|
|
||||||
ArchivaConfiguration archivaConfiguration =
|
ArchivaConfiguration archivaConfiguration =
|
||||||
(ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user-fallback" );
|
(ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-save-user-fallback" );
|
||||||
|
@ -362,8 +364,8 @@ public class ArchivaConfigurationTest
|
||||||
|
|
||||||
archivaConfiguration.save( configuration );
|
archivaConfiguration.save( configuration );
|
||||||
|
|
||||||
assertTrue( "Check file exists", baseFile.exists() );
|
assertTrue( "Check file exists", Files.exists(baseFile) );
|
||||||
assertFalse( "Check file not created", userFile.exists() );
|
assertFalse( "Check file not created", Files.exists(userFile) );
|
||||||
|
|
||||||
// check it
|
// check it
|
||||||
configuration = archivaConfiguration.getConfiguration();
|
configuration = archivaConfiguration.getConfiguration();
|
||||||
|
@ -374,19 +376,19 @@ public class ArchivaConfigurationTest
|
||||||
public void testStoreConfigurationFailsWhenReadFromBothLocationsNoLists()
|
public void testStoreConfigurationFailsWhenReadFromBothLocationsNoLists()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
File baseFile = getTestFile( "target/test/test-file.xml" );
|
Path baseFile = getTestFile( "target/test/test-file.xml" );
|
||||||
baseFile.delete();
|
Files.deleteIfExists(baseFile);
|
||||||
assertFalse( baseFile.exists() );
|
assertFalse( Files.exists(baseFile) );
|
||||||
|
|
||||||
File userFile = getTestFile( "target/test/test-file-user.xml" );
|
Path userFile = getTestFile( "target/test/test-file-user.xml" );
|
||||||
userFile.delete();
|
Files.deleteIfExists(userFile);
|
||||||
assertFalse( userFile.exists() );
|
assertFalse( Files.exists(userFile) );
|
||||||
|
|
||||||
baseFile.getParentFile().mkdirs();
|
Files.createDirectories( baseFile.getParent() );
|
||||||
FileUtils.writeStringToFile( baseFile, "<configuration/>", Charset.forName( "UTF-8" ) );
|
FileUtils.writeStringToFile( baseFile.toFile(), "<configuration/>", Charset.forName( "UTF-8" ) );
|
||||||
|
|
||||||
userFile.getParentFile().mkdirs();
|
Files.createDirectories( userFile.getParent());
|
||||||
FileUtils.writeStringToFile( userFile, "<configuration/>", Charset.forName( "UTF-8" ) );
|
FileUtils.writeStringToFile( userFile.toFile(), "<configuration/>", Charset.forName( "UTF-8" ) );
|
||||||
|
|
||||||
ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-save-user" );
|
ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-save-user" );
|
||||||
|
|
||||||
|
@ -399,12 +401,12 @@ public class ArchivaConfigurationTest
|
||||||
|
|
||||||
archivaConfiguration.save( configuration );
|
archivaConfiguration.save( configuration );
|
||||||
|
|
||||||
assertTrue( "Check file exists", baseFile.exists() );
|
assertTrue( "Check file exists", Files.exists(baseFile) );
|
||||||
assertEquals( "Check base file is unchanged", "<configuration/>",
|
assertEquals( "Check base file is unchanged", "<configuration/>",
|
||||||
FileUtils.readFileToString( baseFile, Charset.forName( "UTF-8" ) ) );
|
FileUtils.readFileToString( baseFile.toFile(), Charset.forName( "UTF-8" ) ) );
|
||||||
assertTrue( "Check file exists", userFile.exists() );
|
assertTrue( "Check file exists", Files.exists(userFile) );
|
||||||
assertFalse( "Check base file is changed",
|
assertFalse( "Check base file is changed",
|
||||||
"<configuration/>".equals( FileUtils.readFileToString( userFile, Charset.forName( "UTF-8" ) ) ) );
|
"<configuration/>".equals( FileUtils.readFileToString( userFile.toFile(), Charset.forName( "UTF-8" ) ) ) );
|
||||||
|
|
||||||
// check it
|
// check it
|
||||||
configuration = archivaConfiguration.getConfiguration();
|
configuration = archivaConfiguration.getConfiguration();
|
||||||
|
@ -415,19 +417,19 @@ public class ArchivaConfigurationTest
|
||||||
public void testStoreConfigurationFailsWhenReadFromBothLocationsUserHasLists()
|
public void testStoreConfigurationFailsWhenReadFromBothLocationsUserHasLists()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
File baseFile = getTestFile( "target/test/test-file.xml" );
|
Path baseFile = getTestFile( "target/test/test-file.xml" );
|
||||||
baseFile.delete();
|
Files.deleteIfExists(baseFile);
|
||||||
assertFalse( baseFile.exists() );
|
assertFalse( Files.exists(baseFile) );
|
||||||
|
|
||||||
File userFile = getTestFile( "target/test/test-file-user.xml" );
|
Path userFile = getTestFile( "target/test/test-file-user.xml" );
|
||||||
userFile.delete();
|
Files.deleteIfExists(userFile);
|
||||||
assertFalse( userFile.exists() );
|
assertFalse( Files.exists(userFile) );
|
||||||
|
|
||||||
userFile.getParentFile().mkdirs();
|
Files.createDirectories( userFile.getParent() );
|
||||||
FileUtils.copyFile( getTestFile( "src/test/conf/conf-user.xml" ), userFile );
|
FileUtils.copyFile( getTestFile( "src/test/conf/conf-user.xml" ).toFile(), userFile.toFile() );
|
||||||
|
|
||||||
baseFile.getParentFile().mkdirs();
|
Files.createDirectories(baseFile.getParent());
|
||||||
FileUtils.writeStringToFile( baseFile, "<configuration/>", Charset.forName( "UTF-8" ) );
|
FileUtils.writeStringToFile( baseFile.toFile(), "<configuration/>", Charset.forName( "UTF-8" ) );
|
||||||
|
|
||||||
ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-save-user" );
|
ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-save-user" );
|
||||||
|
|
||||||
|
@ -440,12 +442,12 @@ public class ArchivaConfigurationTest
|
||||||
|
|
||||||
archivaConfiguration.save( configuration );
|
archivaConfiguration.save( configuration );
|
||||||
|
|
||||||
assertTrue( "Check file exists", baseFile.exists() );
|
assertTrue( "Check file exists", Files.exists(baseFile) );
|
||||||
assertEquals( "Check base file is unchanged", "<configuration/>",
|
assertEquals( "Check base file is unchanged", "<configuration/>",
|
||||||
FileUtils.readFileToString( baseFile, Charset.forName( "UTF-8" ) ) );
|
FileUtils.readFileToString( baseFile.toFile(), Charset.forName( "UTF-8" ) ) );
|
||||||
assertTrue( "Check file exists", userFile.exists() );
|
assertTrue( "Check file exists", Files.exists(userFile) );
|
||||||
assertFalse( "Check base file is changed",
|
assertFalse( "Check base file is changed",
|
||||||
"<configuration/>".equals( FileUtils.readFileToString( userFile, Charset.forName( "UTF-8" ) ) ) );
|
"<configuration/>".equals( FileUtils.readFileToString( userFile.toFile(), Charset.forName( "UTF-8" ) ) ) );
|
||||||
|
|
||||||
// check it
|
// check it
|
||||||
configuration = archivaConfiguration.getConfiguration();
|
configuration = archivaConfiguration.getConfiguration();
|
||||||
|
@ -456,19 +458,19 @@ public class ArchivaConfigurationTest
|
||||||
public void testStoreConfigurationFailsWhenReadFromBothLocationsAppserverHasLists()
|
public void testStoreConfigurationFailsWhenReadFromBothLocationsAppserverHasLists()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
File baseFile = getTestFile( "target/test/test-file.xml" );
|
Path baseFile = getTestFile( "target/test/test-file.xml" );
|
||||||
baseFile.delete();
|
Files.deleteIfExists(baseFile);
|
||||||
assertFalse( baseFile.exists() );
|
assertFalse( Files.exists(baseFile) );
|
||||||
|
|
||||||
File userFile = getTestFile( "target/test/test-file-user.xml" );
|
Path userFile = getTestFile( "target/test/test-file-user.xml" );
|
||||||
userFile.delete();
|
Files.deleteIfExists(userFile);
|
||||||
assertFalse( userFile.exists() );
|
assertFalse( Files.exists(userFile) );
|
||||||
|
|
||||||
baseFile.getParentFile().mkdirs();
|
Files.createDirectories(baseFile.getParent());
|
||||||
FileUtils.copyFile( getTestFile( "src/test/conf/conf-base.xml" ), baseFile );
|
FileUtils.copyFile( getTestFile( "src/test/conf/conf-base.xml" ).toFile(), baseFile.toFile() );
|
||||||
|
|
||||||
userFile.getParentFile().mkdirs();
|
Files.createDirectories(userFile.getParent());
|
||||||
FileUtils.writeStringToFile( userFile, "<configuration/>", Charset.forName( "UTF-8" ) );
|
FileUtils.writeStringToFile( userFile.toFile(), "<configuration/>", Charset.forName( "UTF-8" ) );
|
||||||
|
|
||||||
ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-save-user" );
|
ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-save-user" );
|
||||||
|
|
||||||
|
@ -515,8 +517,8 @@ public class ArchivaConfigurationTest
|
||||||
public void testLoadConfigurationFromInvalidUserLocationOnDisk()
|
public void testLoadConfigurationFromInvalidUserLocationOnDisk()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
File testConfDir = getTestFile( "target/test-appserver-base/conf/" );
|
Path testConfDir = getTestFile( "target/test-appserver-base/conf/" );
|
||||||
testConfDir.mkdirs();
|
Files.createDirectories( testConfDir );
|
||||||
|
|
||||||
ArchivaConfiguration archivaConfiguration =
|
ArchivaConfiguration archivaConfiguration =
|
||||||
lookup( ArchivaConfiguration.class, "test-not-allowed-to-write-to-user" );
|
lookup( ArchivaConfiguration.class, "test-not-allowed-to-write-to-user" );
|
||||||
|
@ -587,12 +589,12 @@ public class ArchivaConfigurationTest
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
// Setup the autodetect-v1.xml file in the target directory (so we can save/load it)
|
// Setup the autodetect-v1.xml file in the target directory (so we can save/load it)
|
||||||
File userFile = getTestFile( "target/test-autodetect-v1/archiva-user.xml" );
|
Path userFile = getTestFile( "target/test-autodetect-v1/archiva-user.xml" );
|
||||||
userFile.delete();
|
Files.deleteIfExists(userFile);
|
||||||
assertFalse( userFile.exists() );
|
assertFalse( Files.exists(userFile) );
|
||||||
|
|
||||||
userFile.getParentFile().mkdirs();
|
Files.createDirectories(userFile.getParent());
|
||||||
FileUtils.copyFile( getTestFile( "src/test/conf/autodetect-v1.xml" ), userFile );
|
FileUtils.copyFile( getTestFile( "src/test/conf/autodetect-v1.xml" ).toFile(), userFile.toFile());
|
||||||
|
|
||||||
// Load the original (unconverted) archiva.xml
|
// Load the original (unconverted) archiva.xml
|
||||||
ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-autodetect-v1" );
|
ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-autodetect-v1" );
|
||||||
|
@ -631,7 +633,7 @@ public class ArchivaConfigurationTest
|
||||||
assertEquals( "check remote repositories size.", 2, configuration.getRemoteRepositoriesAsMap().size() );
|
assertEquals( "check remote repositories size.", 2, configuration.getRemoteRepositoriesAsMap().size() );
|
||||||
assertEquals( "check v1 repositories size.", 0, configuration.getRepositories().size() );
|
assertEquals( "check v1 repositories size.", 0, configuration.getRepositories().size() );
|
||||||
|
|
||||||
String actualXML = FileUtils.readFileToString( userFile, Charset.forName( "UTF-8" ) );
|
String actualXML = FileUtils.readFileToString( userFile.toFile(), Charset.forName( "UTF-8" ) );
|
||||||
XMLAssert.assertXpathNotExists( "//configuration/repositories/repository", actualXML );
|
XMLAssert.assertXpathNotExists( "//configuration/repositories/repository", actualXML );
|
||||||
XMLAssert.assertXpathNotExists( "//configuration/repositories", actualXML );
|
XMLAssert.assertXpathNotExists( "//configuration/repositories", actualXML );
|
||||||
}
|
}
|
||||||
|
@ -674,19 +676,19 @@ public class ArchivaConfigurationTest
|
||||||
public void testCronExpressionsWithComma()
|
public void testCronExpressionsWithComma()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
File baseFile = getTestFile( "target/test/test-file.xml" );
|
Path baseFile = getTestFile( "target/test/test-file.xml" );
|
||||||
baseFile.delete();
|
Files.deleteIfExists(baseFile);
|
||||||
assertFalse( baseFile.exists() );
|
assertFalse( Files.exists(baseFile) );
|
||||||
|
|
||||||
File userFile = getTestFile( "target/test/test-file-user.xml" );
|
Path userFile = getTestFile( "target/test/test-file-user.xml" );
|
||||||
userFile.delete();
|
Files.deleteIfExists(userFile);
|
||||||
assertFalse( userFile.exists() );
|
assertFalse( Files.exists(userFile) );
|
||||||
|
|
||||||
baseFile.getParentFile().mkdirs();
|
Files.createDirectories(baseFile.getParent());
|
||||||
FileUtils.copyFile( getTestFile( "src/test/conf/escape-cron-expressions.xml" ), baseFile );
|
FileUtils.copyFile( getTestFile( "src/test/conf/escape-cron-expressions.xml" ).toFile(), baseFile.toFile() );
|
||||||
|
|
||||||
userFile.getParentFile().mkdirs();
|
Files.createDirectories(userFile.getParent());
|
||||||
FileUtils.writeStringToFile( userFile, "<configuration/>", Charset.defaultCharset() );
|
FileUtils.writeStringToFile( userFile.toFile(), "<configuration/>", Charset.defaultCharset() );
|
||||||
|
|
||||||
final ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-cron-expressions" );
|
final ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-cron-expressions" );
|
||||||
|
|
||||||
|
@ -728,19 +730,19 @@ public class ArchivaConfigurationTest
|
||||||
public void testRemoveLastElements()
|
public void testRemoveLastElements()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
File baseFile = getTestFile( "target/test/test-file.xml" );
|
Path baseFile = getTestFile( "target/test/test-file.xml" );
|
||||||
baseFile.delete();
|
Files.deleteIfExists(baseFile);
|
||||||
assertFalse( baseFile.exists() );
|
assertFalse( Files.exists(baseFile) );
|
||||||
|
|
||||||
File userFile = getTestFile( "target/test/test-file-user.xml" );
|
Path userFile = getTestFile( "target/test/test-file-user.xml" );
|
||||||
userFile.delete();
|
Files.deleteIfExists(userFile);
|
||||||
assertFalse( userFile.exists() );
|
assertFalse( Files.exists(userFile) );
|
||||||
|
|
||||||
baseFile.getParentFile().mkdirs();
|
Files.createDirectories( baseFile.getParent() );
|
||||||
FileUtils.copyFile( getTestFile( "src/test/conf/conf-single-list-elements.xml" ), baseFile );
|
FileUtils.copyFile( getTestFile( "src/test/conf/conf-single-list-elements.xml" ).toFile(), baseFile.toFile() );
|
||||||
|
|
||||||
userFile.getParentFile().mkdirs();
|
Files.createDirectories( userFile.getParent());
|
||||||
FileUtils.writeStringToFile( userFile, "<configuration/>", Charset.forName( "UTF-8" ) );
|
FileUtils.writeStringToFile( userFile.toFile(), "<configuration/>", Charset.forName( "UTF-8" ) );
|
||||||
|
|
||||||
ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-remove-central" );
|
ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-remove-central" );
|
||||||
|
|
||||||
|
|
|
@ -19,10 +19,9 @@ package org.apache.archiva.configuration;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
|
import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
|
||||||
|
@ -42,14 +41,14 @@ public class MavenProxyPropertyLoaderTest
|
||||||
public void testLoadValidMavenProxyConfiguration()
|
public void testLoadValidMavenProxyConfiguration()
|
||||||
throws IOException, InvalidConfigurationException
|
throws IOException, InvalidConfigurationException
|
||||||
{
|
{
|
||||||
File confFile = ArchivaConfigurationTest.getTestFile( "src/test/conf/maven-proxy-complete.conf" );
|
Path confFile = ArchivaConfigurationTest.getTestFile( "src/test/conf/maven-proxy-complete.conf" );
|
||||||
|
|
||||||
Configuration configuration = new Configuration();
|
Configuration configuration = new Configuration();
|
||||||
NetworkProxyConfiguration proxy = new NetworkProxyConfiguration();
|
NetworkProxyConfiguration proxy = new NetworkProxyConfiguration();
|
||||||
proxy.setHost( "original-host" );
|
proxy.setHost( "original-host" );
|
||||||
configuration.addNetworkProxy( proxy ); // overwritten
|
configuration.addNetworkProxy( proxy ); // overwritten
|
||||||
|
|
||||||
loader.load( Files.newInputStream(confFile.toPath()), configuration );
|
loader.load( Files.newInputStream(confFile), configuration );
|
||||||
|
|
||||||
Map<String, ManagedRepositoryConfiguration> repositoryIdMap = configuration.getManagedRepositoriesAsMap();
|
Map<String, ManagedRepositoryConfiguration> repositoryIdMap = configuration.getManagedRepositoriesAsMap();
|
||||||
assertEquals( "Count repositories", 1, repositoryIdMap.size() );
|
assertEquals( "Count repositories", 1, repositoryIdMap.size() );
|
||||||
|
|
Loading…
Reference in New Issue