throws XMLException
{
- XMLReader xml = new XMLReader( "metadata", metadataFile.toFile() );
+ XMLReader xml = new XMLReader( "metadata", metadataFile );
// invoke this to remove namespaces, see MRM-1136
xml.removeNamespaces();
import org.apache.archiva.common.filelock.FileLockManager;
import org.apache.archiva.common.filelock.FileLockTimeoutException;
import org.apache.archiva.common.filelock.Lock;
-import org.apache.archiva.configuration.ArchivaConfiguration;
-import org.apache.archiva.configuration.Configuration;
-import org.apache.archiva.configuration.ConfigurationNames;
-import org.apache.archiva.configuration.NetworkProxyConfiguration;
-import org.apache.archiva.configuration.ProxyConnectorConfiguration;
-import org.apache.archiva.configuration.ProxyConnectorRuleConfiguration;
+import org.apache.archiva.configuration.*;
import org.apache.archiva.model.ArtifactReference;
import org.apache.archiva.model.Keys;
import org.apache.archiva.model.RepositoryURL;
-import org.apache.archiva.policies.DownloadErrorPolicy;
-import org.apache.archiva.policies.DownloadPolicy;
-import org.apache.archiva.policies.PolicyConfigurationException;
-import org.apache.archiva.policies.PolicyViolationException;
-import org.apache.archiva.policies.PostDownloadPolicy;
-import org.apache.archiva.policies.PreDownloadPolicy;
-import org.apache.archiva.policies.ProxyDownloadException;
+import org.apache.archiva.policies.*;
import org.apache.archiva.policies.urlcache.UrlFailureCache;
import org.apache.archiva.proxy.common.WagonFactory;
import org.apache.archiva.proxy.common.WagonFactoryException;
import org.apache.archiva.redback.components.registry.Registry;
import org.apache.archiva.redback.components.registry.RegistryListener;
import org.apache.archiva.redback.components.taskqueue.TaskQueueException;
-import org.apache.archiva.repository.ManagedRepositoryContent;
-import org.apache.archiva.repository.RemoteRepositoryContent;
-import org.apache.archiva.repository.RepositoryContentFactory;
-import org.apache.archiva.repository.RepositoryException;
-import org.apache.archiva.repository.RepositoryNotFoundException;
+import org.apache.archiva.repository.*;
import org.apache.archiva.repository.metadata.MetadataTools;
import org.apache.archiva.repository.metadata.RepositoryMetadataException;
import org.apache.archiva.scheduler.ArchivaTaskScheduler;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Named;
-import java.io.File;
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.Collections;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
import java.util.Map.Entry;
-import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
import java.io.BufferedReader;
-import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.attribute.FileTime;
import java.text.ParseException;
import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Collection;
-import java.util.Date;
-import java.util.Locale;
+import java.util.*;
import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
import static org.junit.Assert.*;
// Setup target (proxied to) repository.
saveRemoteRepositoryConfig( ID_PROXIED1, "Proxied Repository 1",
- new File( REPOPATH_PROXIED1 ).toURL().toExternalForm(), "default" );
+ Paths.get( REPOPATH_PROXIED1 ).toUri().toURL().toExternalForm(), "default" );
// Setup target (proxied to) repository.
saveRemoteRepositoryConfig( ID_PROXIED2, "Proxied Repository 2",
- new File( REPOPATH_PROXIED2 ).toURL().toExternalForm(), "default" );
+ Paths.get( REPOPATH_PROXIED2 ).toUri().toURL().toExternalForm(), "default" );
// Setup the proxy handler.
//proxyHandler = applicationContext.getBean (RepositoryProxyConnectors) lookup( RepositoryProxyConnectors.class.getName() );
return;
}
- Collection<File> tmpFiles =
- org.apache.commons.io.FileUtils.listFiles( workingDir.toFile(), new String[]{ "tmp" }, false );
- if ( !tmpFiles.isEmpty() )
+ Collection<Path> tmpFiles = null;
+ try {
+ tmpFiles = Files.list(workingDir).filter(path -> Files.isRegularFile(path) && path.getFileName().toString().endsWith(".tmp")).collect(Collectors.toList());
+ } catch (IOException e) {
+ log.error("Could not retrieve tmpFiles {}", workingDir);
+ }
+ if ( tmpFiles!=null && !tmpFiles.isEmpty() )
{
StringBuilder emsg = new StringBuilder();
emsg.append( "Found Temp Files in dir: " ).append( workingDir.toString() );
- for ( File tfile : tmpFiles )
+ for ( Path tfile : tmpFiles )
{
- emsg.append( "\n " ).append( tfile.getName() );
+ emsg.append( "\n " ).append( tfile.getFileName().toString());
}
fail( emsg.toString() );
}
throw new IOException( "Source directory doesn't exists (" + sourceDirectory.toAbsolutePath() + ")." );
}
- File[] files = sourceDirectory.toFile().listFiles();
+ Path[] files = Files.list(sourceDirectory).filter(path -> Files.isRegularFile(path)).toArray(Path[]::new);
String sourcePath = sourceDirectory.toAbsolutePath().toString();
for ( int i = 0; i < files.length; i++ )
{
- File file = files[i];
+ Path file = files[i];
- String dest = file.getAbsolutePath();
+ String dest = file.toAbsolutePath().toString();
dest = dest.substring( sourcePath.length() + 1 );
- File destination = new File( destDirectory.toFile(), dest );
+ Path destination = destDirectory.resolve( dest );
- if ( file.isFile() )
+ if ( Files.isRegularFile(file) )
{
- destination = destination.getParentFile();
+ destination = destination.getParent();
- org.apache.commons.io.FileUtils.copyFile( file, new File( destination, file.getName() ), false );
+ org.apache.commons.io.FileUtils.copyFile( file.toFile(), destination.resolve( file.getFileName() ).toFile(), false );
// TODO: Change when there is a FileUtils.copyFileToDirectory(file, destination, boolean) option
//FileUtils.copyFileToDirectory( file, destination );
}
- else if ( file.isDirectory() )
+ else if ( Files.isDirectory(file) )
{
- if ( !".svn".equals( file.getName() ) )
+ if ( !".svn".equals( file.getFileName().toString() ) )
{
- if ( !destination.exists() && !destination.mkdirs() )
+ if ( !Files.exists(destination))
{
- throw new IOException(
- "Could not create destination directory '" + destination.getAbsolutePath() + "'." );
+ Files.createDirectories(destination);
}
- copyDirectoryStructure( file.toPath(), destination.toPath() );
+ copyDirectoryStructure( file, destination );
}
}
else
{
- throw new IOException( "Unknown file type: " + file.getAbsolutePath() );
+ throw new IOException( "Unknown file type: " + file.toAbsolutePath() );
}
}
}
import org.junit.Test;
import java.io.File;
-import java.nio.file.CopyOption;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.apache.archiva.common.utils.VersionUtil;
import org.apache.archiva.configuration.ProxyConnectorConfiguration;
import org.apache.archiva.maven2.metadata.MavenMetadataReader;
-import org.apache.archiva.model.ArchivaRepositoryMetadata;
-import org.apache.archiva.model.Plugin;
-import org.apache.archiva.model.ProjectReference;
-import org.apache.archiva.model.SnapshotVersion;
-import org.apache.archiva.model.VersionedReference;
+import org.apache.archiva.model.*;
import org.apache.archiva.policies.CachedFailuresPolicy;
import org.apache.archiva.policies.ChecksumPolicy;
import org.apache.archiva.policies.ReleasesPolicy;
import org.apache.archiva.policies.SnapshotsPolicy;
-import org.apache.archiva.proxy.model.ProxyFetchResult;
import org.apache.archiva.repository.metadata.MetadataTools;
import org.apache.archiva.repository.metadata.RepositoryMetadataException;
import org.apache.archiva.repository.metadata.RepositoryMetadataWriter;
import org.apache.commons.lang.StringUtils;
-import org.apache.maven.wagon.ResourceDoesNotExistException;
import org.apache.maven.wagon.TransferFailedException;
import org.custommonkey.xmlunit.DetailedDiff;
import org.custommonkey.xmlunit.Diff;
* under the License.
*/
-import org.apache.commons.io.FileUtils;
import org.apache.maven.wagon.ConnectionException;
import org.apache.maven.wagon.ResourceDoesNotExistException;
import org.apache.maven.wagon.TransferFailedException;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.List;
/**
{
log.debug( ".get({}, {})", resourceName, destination );
delegate.get( resourceName, destination );
- create( destination );
+ create( destination.toPath() );
}
@Override
log.info( ".getIfNewer({}, {}, {})", resourceName, destination, timestamp );
boolean result = delegate.getIfNewer( resourceName, destination, timestamp );
- createIfMissing( destination );
+ createIfMissing( destination.toPath() );
return result;
}
contentToGet = content;
}
- private void createIfMissing( File destination )
+ private void createIfMissing( Path destination )
{
// since the mock won't actually copy a file, create an empty one to simulate file existence
- if ( !destination.exists() )
+ if ( !Files.exists(destination) )
{
create( destination );
}
}
- private void create( File destination )
+ private void create( Path destination )
{
try
{
- destination.getParentFile().mkdirs();
+ Files.createDirectories(destination.getParent());
if ( contentToGet == null )
{
- destination.createNewFile();
+ Files.createFile(destination);
}
else
{
- FileUtils.writeStringToFile( new File( destination.getAbsolutePath() ), contentToGet,
- Charset.defaultCharset() );
+ org.apache.archiva.common.utils.FileUtils.writeStringToFile(destination, Charset.defaultCharset(), contentToGet);
}
}
catch ( IOException e )
*/
import org.apache.commons.lang.StringUtils;
-import org.dom4j.Attribute;
-import org.dom4j.Document;
-import org.dom4j.DocumentException;
-import org.dom4j.Element;
-import org.dom4j.Namespace;
-import org.dom4j.Node;
-import org.dom4j.QName;
-import org.dom4j.XPath;
+import org.dom4j.*;
import org.dom4j.io.SAXReader;
-import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.Charset;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.*;
/**
* XMLReader - a set of common xml utility methods for reading content out of an xml file.
private Map<String, String> namespaceMap = new HashMap<>();
- public XMLReader( String type, File file )
+ public XMLReader( String type, Path file )
throws XMLException
{
- if ( !file.exists() )
+ if ( !Files.exists(file) )
{
- throw new XMLException( "file does not exist: " + file.getAbsolutePath() );
+ throw new XMLException( "file does not exist: " + file.toAbsolutePath() );
}
- if ( !file.isFile() )
+ if ( !Files.isRegularFile(file) )
{
- throw new XMLException( "path is not a file: " + file.getAbsolutePath() );
+ throw new XMLException( "path is not a file: " + file.toAbsolutePath() );
}
- if ( !file.canRead() )
+ if ( !Files.isReadable(file) )
{
- throw new XMLException( "Cannot read xml file due to permissions: " + file.getAbsolutePath() );
+ throw new XMLException( "Cannot read xml file due to permissions: " + file.toAbsolutePath() );
}
try
{
- init( type, file.toURL() );
+ init( type, file.toUri().toURL() );
}
catch ( MalformedURLException e )
{
* under the License.
*/
-import java.io.File;
-
import junit.framework.TestCase;
import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
import org.junit.runner.RunWith;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
/**
* AbstractArchivaXmlTestCase
*
protected static final String INFINITE_ARCHIVA = "The " + INFIN + " Archiva";
- protected File getExampleXml( String filename )
+ protected Path getExampleXml(String filename )
{
- File examplesDir = new File( "src/test/examples" );
- if ( !examplesDir.exists() )
+ Path examplesDir = Paths.get("src/test/examples");
+ if ( !Files.exists(examplesDir) )
{
- fail( "Missing the examples directory: " + examplesDir.getAbsolutePath() );
+ fail( "Missing the examples directory: " + examplesDir.toAbsolutePath() );
}
- File exampleFile = new File( examplesDir, filename );
- if ( !exampleFile.exists() )
+ Path exampleFile = examplesDir.resolve( filename );
+ if ( !Files.exists(exampleFile) )
{
- fail( "Missing the example xml file: " + exampleFile.getAbsolutePath() );
+ fail( "Missing the example xml file: " + exampleFile.toAbsolutePath() );
}
return exampleFile;
}
import org.junit.Test;
import java.io.BufferedReader;
-import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import java.net.URL;
import java.nio.charset.Charset;
+import java.nio.file.Path;
/**
* LatinEntityResolutionReaderTest
private String toStringFromExample( String examplePath )
throws IOException
{
- File exampleFile = getExampleXml( examplePath );
- FileReader fileReader = new FileReader( exampleFile );
+ Path exampleFile = getExampleXml( examplePath );
+ FileReader fileReader = new FileReader( exampleFile.toFile() );
BufferedReader lineReader = new BufferedReader( fileReader );
StringBuilder sb = new StringBuilder();
{
try
{
- File inputFile = getExampleXml( sourcePath );
+ Path inputFile = getExampleXml( sourcePath );
- FileReader fileReader = new FileReader( inputFile );
+ FileReader fileReader = new FileReader( inputFile.toFile() );
LatinEntityResolutionReader testReader = new LatinEntityResolutionReader( fileReader );
String actualOutput = toStringFromReader( testReader, bufsize );
{
try
{
- File inputFile = getExampleXml( sourcePath );
+ Path inputFile = getExampleXml( sourcePath );
- FileReader fileReader = new FileReader( inputFile );
+ FileReader fileReader = new FileReader( inputFile.toFile() );
LatinEntityResolutionReader testReader = new LatinEntityResolutionReader( fileReader );
String actualOutput = toStringFromReader( testReader, bufSize );
public void testReaderLeftOver()
throws IOException
{
- File inputFile = getExampleXml( "maven-metadata-leftover.xml" );
+ Path inputFile = getExampleXml( "maven-metadata-leftover.xml" );
//Bits from RepositoryMetadataReader.read
InputStream in = null;
SAXReader reader = new SAXReader();
- URL url = inputFile.toURL();
+ URL url = inputFile.toUri().toURL();
in = url.openStream();
InputStreamReader inReader = new InputStreamReader( in, Charset.forName( "UTF-8" ) );
LatinEntityResolutionReader latinReader = new LatinEntityResolutionReader( inReader );
* under the License.
*/
-import java.io.File;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
public void testNoPrologBasicRead()
throws XMLException
{
- File xmlFile = getExampleXml( "no-prolog-basic.xml" );
+ Path xmlFile = getExampleXml( "no-prolog-basic.xml" );
XMLReader reader = new XMLReader( "basic", xmlFile );
List<Element> fruits = reader.getElementList( "//basic/fruits/fruit" );
public void testNoPrologEntitiesRead()
throws XMLException
{
- File xmlFile = getExampleXml( "no-prolog-with-entities.xml" );
+ Path xmlFile = getExampleXml( "no-prolog-with-entities.xml" );
XMLReader reader = new XMLReader( "basic", xmlFile );
List<Element> names = reader.getElementList( "//basic/names/name" );
public void testNoPrologUtf8Read()
throws XMLException
{
- File xmlFile = getExampleXml( "no-prolog-with-utf8.xml" );
+ Path xmlFile = getExampleXml( "no-prolog-with-utf8.xml" );
XMLReader reader = new XMLReader( "basic", xmlFile );
List<Element> names = reader.getElementList( "//basic/names/name" );
public void testPrologUtf8Read()
throws XMLException
{
- File xmlFile = getExampleXml( "prolog-with-utf8.xml" );
+ Path xmlFile = getExampleXml( "prolog-with-utf8.xml" );
XMLReader reader = new XMLReader( "basic", xmlFile );
List<Element> names = reader.getElementList( "//basic/names/name" );
public void testProxiedMetadataRead()
throws XMLException
{
- File xmlFile = getExampleXml( "maven-metadata-codehaus-snapshots.xml" );
- XMLReader reader = new XMLReader( "metadata", xmlFile );
+ Path xmlFile = getExampleXml( "maven-metadata-codehaus-snapshots.xml" );
+ XMLReader reader = new XMLReader( "metadata", xmlFile );
reader.removeNamespaces();
Element groupId = reader.getElement( "//metadata/groupId" );