--- /dev/null
+package org.apache.archiva.common.utils;
+/*
+ * 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.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Comparator;
+
+/**
+ *
+ * Utility class for file manipulation
+ *
+ * @author Martin Stockhammer <martin_s@apache.org>
+ */
+public class FileUtils
+{
+ public static void deleteQuietly(Path dir) {
+ try
+ {
+ Files.walk(dir)
+ .sorted( Comparator.reverseOrder())
+ .forEach( file -> {
+ try
+ {
+ Files.delete( file );
+ }
+ catch ( IOException e )
+ {
+ // Ignore this
+ }
+
+ });
+ }
+ catch ( IOException e )
+ {
+ // Ignore this
+ }
+
+
+ }
+}
log.error( "Error during metadata retrieval {}: {}", metaBaseId, e.getMessage( ) );
}
}
- Path artifactFile = repository.toFile( reference ).toPath( );
+ Path artifactFile = repository.toFile( reference );
for ( RepositoryListener listener : listeners )
{
import org.apache.commons.lang.time.DateUtils;
import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
artifactFile.getAbsolutePath( ) );
newArtifactReference.setVersion( version );
- File newArtifactFile = repository.toFile( newArtifactReference );
+ Path newArtifactFile = repository.toFile( newArtifactReference );
// Is this a generic snapshot "1.0-SNAPSHOT" ?
if ( VersionUtil.isGenericSnapshot( newArtifactReference.getVersion( ) ) )
{
- if ( newArtifactFile.lastModified( ) < olderThanThisDate.getTimeInMillis( ) )
+ if ( Files.getLastModifiedTime( newArtifactFile ).toMillis() < olderThanThisDate.getTimeInMillis( ) )
{
artifactsToDelete.addAll( repository.getRelatedArtifacts( newArtifactReference ) );
}
}
purge( artifactsToDelete );
}
- catch ( ContentNotFoundException e )
+ catch ( ContentNotFoundException | IOException e )
{
throw new RepositoryPurgeException( e.getMessage( ), e );
}
private File toLocalFile( ManagedRepositoryContent repository, ArtifactReference artifact )
{
- return repository.toFile( artifact );
+ return repository.toFile( artifact ).toFile();
}
/**
import org.apache.archiva.model.VersionedReference;
import org.apache.archiva.repository.layout.LayoutException;
-import java.io.File;
+import java.nio.file.Path;
import java.util.Set;
/**
* @param reference the artifact reference to use.
* @return the relative path to the artifact.
*/
- File toFile( ArtifactReference reference );
+ Path toFile( ArtifactReference reference );
/**
* Given an {@link ArchivaArtifact}, return the file reference to the artifact.
* @param reference the archiva artifact to use.
* @return the relative path to the artifact.
*/
- File toFile( ArchivaArtifact reference );
+ Path toFile( ArchivaArtifact reference );
/**
* Given a {@link ProjectReference}, return the path to the metadata for
import org.apache.archiva.checksum.ChecksumAlgorithm;
import org.apache.archiva.checksum.ChecksummedFile;
+import org.apache.archiva.common.utils.FileUtils;
import org.apache.archiva.common.utils.PathUtil;
import org.apache.archiva.common.utils.VersionComparator;
import org.apache.archiva.common.utils.VersionUtil;
import org.apache.archiva.repository.layout.LayoutException;
import org.apache.archiva.xml.XMLException;
import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.apache.commons.lang.time.DateUtils;
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.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.Set;
import java.util.regex.Matcher;
+import java.util.stream.Stream;
/**
* MetadataTools
ProjectReference reference, String proxyId )
{
String metadataPath = getRepositorySpecificName( proxyId, toPath( reference ) );
- File metadataFile = new File( managedRepository.getRepoRoot(), metadataPath );
+ Path metadataFile = Paths.get( managedRepository.getRepoRoot(), metadataPath );
- if ( !metadataFile.exists() || !metadataFile.isFile() )
+ if ( !Files.exists(metadataFile) || !Files.isRegularFile( metadataFile ))
{
// Nothing to do. return null.
return null;
try
{
- return MavenMetadataReader.read( metadataFile );
+ return MavenMetadataReader.read( metadataFile.toFile() );
}
catch ( XMLException e )
{
// TODO: [monitor] consider a monitor for this event.
// TODO: consider a read-redo on monitor return code?
- log.warn( "Unable to read metadata: {}", metadataFile.getAbsolutePath(), e );
+ log.warn( "Unable to read metadata: {}", metadataFile.toAbsolutePath(), e );
return null;
}
}
String logicalResource, String proxyId )
{
String metadataPath = getRepositorySpecificName( proxyId, logicalResource );
- File metadataFile = new File( managedRepository.getRepoRoot(), metadataPath );
+ Path metadataFile = Paths.get( managedRepository.getRepoRoot(), metadataPath );
- if ( !metadataFile.exists() || !metadataFile.isFile() )
+ if ( !Files.exists(metadataFile) || !Files.isRegularFile( metadataFile))
{
// Nothing to do. return null.
return null;
try
{
- return MavenMetadataReader.read( metadataFile );
+ return MavenMetadataReader.read( metadataFile.toFile() );
}
catch ( XMLException e )
{
// TODO: [monitor] consider a monitor for this event.
// TODO: consider a read-redo on monitor return code?
- log.warn( "Unable to read metadata: {}", metadataFile.getAbsolutePath(), e );
+ log.warn( "Unable to read metadata: {}", metadataFile.toAbsolutePath(), e );
return null;
}
}
VersionedReference reference, String proxyId )
{
String metadataPath = getRepositorySpecificName( proxyId, toPath( reference ) );
- File metadataFile = new File( managedRepository.getRepoRoot(), metadataPath );
+ Path metadataFile = Paths.get( managedRepository.getRepoRoot(), metadataPath );
- if ( !metadataFile.exists() || !metadataFile.isFile() )
+ if ( !Files.exists(metadataFile) || !Files.isRegularFile(metadataFile))
{
// Nothing to do. return null.
return null;
try
{
- return MavenMetadataReader.read( metadataFile );
+ return MavenMetadataReader.read( metadataFile.toFile() );
}
catch ( XMLException e )
{
// TODO: [monitor] consider a monitor for this event.
// TODO: consider a read-redo on monitor return code?
- log.warn( "Unable to read metadata: {}", metadataFile.getAbsolutePath(), e );
+ log.warn( "Unable to read metadata: {}", metadataFile.toAbsolutePath(), e );
return null;
}
}
public void updateMetadata( ManagedRepositoryContent managedRepository, String logicalResource )
throws RepositoryMetadataException
{
- final File metadataFile = new File( managedRepository.getRepoRoot(), logicalResource );
+ final Path metadataFile = Paths.get( managedRepository.getRepoRoot(), logicalResource );
ArchivaRepositoryMetadata metadata = null;
//Gather and merge all metadata available
{
availableVersions.addAll( metadataAvailableVersions );
}
- availableVersions = findPossibleVersions( availableVersions, metadataFile.getParentFile() );
+ availableVersions = findPossibleVersions( availableVersions, metadataFile.getParent() );
if ( availableVersions.size() > 0 )
{
RepositoryMetadataWriter.write( metadata, metadataFile );
- ChecksummedFile checksum = new ChecksummedFile( metadataFile );
+ ChecksummedFile checksum = new ChecksummedFile( metadataFile.toFile() );
checksum.fixChecksums( algorithms );
}
* subdirectories that contain poms.
*
* @param metadataParentDirectory
- * @return origional set plus newley found versions
+ * @return origional set plus newly found versions
*/
- private Set<String> findPossibleVersions( Set<String> versions, File metadataParentDirectory )
+ private Set<String> findPossibleVersions( Set<String> versions, Path metadataParentDirectory )
{
+
Set<String> result = new HashSet<String>( versions );
- for ( File directory : metadataParentDirectory.listFiles() )
- {
- if ( directory.isDirectory() )
- {
- for ( File possiblePom : directory.listFiles() )
+
+ try (Stream<Path> stream = Files.list( metadataParentDirectory )) {
+ stream.filter( Files::isDirectory ).filter(
+ p ->
{
- if ( possiblePom.getName().endsWith( ".pom" ) )
+ try(Stream<Path> substream = Files.list(p))
{
- result.add( directory.getName() );
+ return substream.anyMatch( f -> Files.isRegularFile( f ) && f.endsWith( ".pom" ));
+ }
+ catch ( IOException e )
+ {
+ return false;
}
}
- }
+ ).forEach(
+ p -> result.add(p.getFileName().toString())
+ );
+ } catch (IOException e) {
+ //
}
return result;
}
ManagedRepositoryContent managedRepository, String logicalResource )
{
List<ArchivaRepositoryMetadata> metadatas = new ArrayList<>();
- File file = new File( managedRepository.getRepoRoot(), logicalResource );
- if ( file.exists() )
+ Path file = Paths.get( managedRepository.getRepoRoot(), logicalResource );
+ if ( Files.exists(file) )
{
try
{
- ArchivaRepositoryMetadata existingMetadata = MavenMetadataReader.read( file );
+ ArchivaRepositoryMetadata existingMetadata = MavenMetadataReader.read( file.toFile() );
if ( existingMetadata != null )
{
metadatas.add( existingMetadata );
}
catch ( XMLException e )
{
- log.debug( "Could not read metadata at {}. Metadata will be removed.", file.getAbsolutePath() );
+ log.debug( "Could not read metadata at {}. Metadata will be removed.", file.toAbsolutePath() );
FileUtils.deleteQuietly( file );
}
}
public void updateMetadata( ManagedRepositoryContent managedRepository, ProjectReference reference )
throws LayoutException, RepositoryMetadataException, IOException, ContentNotFoundException
{
- File metadataFile = new File( managedRepository.getRepoRoot(), toPath( reference ) );
+ Path metadataFile = Paths.get( managedRepository.getRepoRoot(), toPath( reference ) );
long lastUpdated = getExistingLastUpdated( metadataFile );
// TODO: do we know this information instead?
// Set<Plugin> allPlugins = managedRepository.getPlugins( reference );
Set<Plugin> allPlugins;
- if ( metadataFile.exists() )
+ if ( Files.exists(metadataFile))
{
try
{
- allPlugins = new LinkedHashSet<Plugin>( MavenMetadataReader.read( metadataFile ).getPlugins() );
+ allPlugins = new LinkedHashSet<Plugin>( MavenMetadataReader.read( metadataFile.toFile() ).getPlugins() );
}
catch ( XMLException e )
{
// Save the metadata model to disk.
RepositoryMetadataWriter.write( metadata, metadataFile );
- ChecksummedFile checksum = new ChecksummedFile( metadataFile );
+ ChecksummedFile checksum = new ChecksummedFile( metadataFile.toFile() );
checksum.fixChecksums( algorithms );
}
}
}
- private long getExistingLastUpdated( File metadataFile )
+ private long getExistingLastUpdated( Path metadataFile )
{
- if ( !metadataFile.exists() )
+ if ( !Files.exists(metadataFile) )
{
// Doesn't exist.
return 0;
try
{
- ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( metadataFile );
+ ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( metadataFile.toFile() );
return getLastUpdated( metadata );
}
public void updateMetadata( ManagedRepositoryContent managedRepository, VersionedReference reference )
throws LayoutException, RepositoryMetadataException, IOException, ContentNotFoundException
{
- File metadataFile = new File( managedRepository.getRepoRoot(), toPath( reference ) );
+ Path metadataFile = Paths.get( managedRepository.getRepoRoot(), toPath( reference ) );
long lastUpdated = getExistingLastUpdated( metadataFile );
// Save the metadata model to disk.
RepositoryMetadataWriter.write( metadata, metadataFile );
- ChecksummedFile checksum = new ChecksummedFile( metadataFile );
+ ChecksummedFile checksum = new ChecksummedFile( metadataFile.toFile() );
checksum.fixChecksums( algorithms );
}
path = path.substring( 0, idx );
}
- File repoDir = new File( managedRepository.getRepoRoot(), path );
+ Path repoDir = Paths.get( managedRepository.getRepoRoot(), path );
- if ( !repoDir.exists() )
+ if ( !Files.exists(repoDir))
{
throw new IOException( "Unable to gather the list of snapshot versions on a non-existant directory: "
- + repoDir.getAbsolutePath() );
+ + repoDir.toAbsolutePath() );
}
- if ( !repoDir.isDirectory() )
+ if ( !Files.isDirectory( repoDir ))
{
throw new IOException(
- "Unable to gather the list of snapshot versions on a non-directory: " + repoDir.getAbsolutePath() );
+ "Unable to gather the list of snapshot versions on a non-directory: " + repoDir.toAbsolutePath() );
}
- File repoFiles[] = repoDir.listFiles();
- for ( int i = 0; i < repoFiles.length; i++ )
- {
- if ( repoFiles[i].isDirectory() )
- {
- // Skip it. it's a directory.
- continue;
- }
-
- String relativePath = PathUtil.getRelative( managedRepository.getRepoRoot(), repoFiles[i] );
-
- if ( filetypes.matchesArtifactPattern( relativePath ) )
- {
- ArtifactReference artifact = managedRepository.toArtifactReference( relativePath );
-
- return artifact;
+ try(Stream<Path> stream = Files.list(repoDir)) {
+ String result = stream.filter( Files::isRegularFile ).map( path1 ->
+ PathUtil.getRelative( managedRepository.getRepoRoot(), path1.toFile() )
+ ).filter( filetypes::matchesArtifactPattern ).findFirst().orElse( null );
+ if (result!=null) {
+ return managedRepository.toArtifactReference( result );
}
}
-
// No artifact was found.
return null;
}
* under the License.
*/
+import org.apache.archiva.common.utils.FileUtils;
import org.apache.archiva.model.ArchivaRepositoryMetadata;
import org.apache.archiva.model.Plugin;
import org.apache.archiva.xml.XMLException;
import org.apache.archiva.xml.XMLWriter;
import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
-import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
+import java.nio.file.Path;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
*/
public class RepositoryMetadataWriter
{
- public static void write( ArchivaRepositoryMetadata metadata, File outputFile )
+ public static void write( ArchivaRepositoryMetadata metadata, Path outputFile )
throws RepositoryMetadataException
{
boolean thrown = false;
- try (FileWriter writer = new FileWriter( outputFile ))
+ try (FileWriter writer = new FileWriter( outputFile.toFile() ))
{
write( metadata, writer );
writer.flush();
{
thrown = true;
throw new RepositoryMetadataException(
- "Unable to write metadata file: " + outputFile.getAbsolutePath() + " - " + e.getMessage(), e );
+ "Unable to write metadata file: " + outputFile.toAbsolutePath() + " - " + e.getMessage(), e );
}
finally
{
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.nio.charset.Charset;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
implements BrowseService
{
+ private Charset ARTIFACT_CONTENT_ENCODING=Charset.forName( "UTF-8" );
+
@Inject
private DependencyTreeBuilder dependencyTreeBuilder;
ArchivaArtifact archivaArtifact = new ArchivaArtifact( groupId, artifactId, version, classifier,
StringUtils.isEmpty( type ) ? "jar" : type,
repoId );
- File file = managedRepositoryContent.toFile( archivaArtifact );
- if ( file.exists() )
+ Path file = managedRepositoryContent.toFile( archivaArtifact );
+ if ( Files.exists(file) )
{
return readFileEntries( file, path, repoId );
}
ArchivaArtifact archivaArtifact = new ArchivaArtifact( groupId, artifactId, version, classifier,
StringUtils.isEmpty( type ) ? "jar" : type,
repoId );
- File file = managedRepositoryContent.toFile( archivaArtifact );
- if ( !file.exists() )
+ Path file = managedRepositoryContent.toFile( archivaArtifact );
+ if ( !Files.exists(file) )
{
log.debug( "file: {} not exists for repository: {} try next repository", file, repoId );
continue;
if ( StringUtils.isNotBlank( path ) )
{
// zip entry of the path -> path must a real file entry of the archive
- JarFile jarFile = new JarFile( file );
+ JarFile jarFile = new JarFile( file.toFile() );
ZipEntry zipEntry = jarFile.getEntry( path );
try (InputStream inputStream = jarFile.getInputStream( zipEntry ))
{
- return new ArtifactContent( IOUtils.toString( inputStream ), repoId );
+ return new ArtifactContent( IOUtils.toString( inputStream, ARTIFACT_CONTENT_ENCODING ), repoId );
}
finally
{
closeQuietly( jarFile );
}
}
- return new ArtifactContent( FileUtils.readFileToString( file ), repoId );
+ return new ArtifactContent( new String(Files.readAllBytes( file ), ARTIFACT_CONTENT_ENCODING), repoId );
}
}
catch ( IOException e )
StringUtils.isEmpty( classifier )
? ""
: classifier, "jar", repoId );
- File file = managedRepositoryContent.toFile( archivaArtifact );
+ Path file = managedRepositoryContent.toFile( archivaArtifact );
- if ( file != null && file.exists() )
+ if ( file != null && Files.exists(file) )
{
return true;
}
// in case of SNAPSHOT we can have timestamped version locally !
if ( StringUtils.endsWith( version, VersionUtil.SNAPSHOT ) )
{
- File metadataFile = new File( file.getParent(), MetadataTools.MAVEN_METADATA );
- if ( metadataFile.exists() )
+ Path metadataFile = file.getParent().resolve(MetadataTools.MAVEN_METADATA );
+ if ( Files.exists(metadataFile) )
{
try
{
ArchivaRepositoryMetadata archivaRepositoryMetadata =
- MavenMetadataReader.read( metadataFile );
+ MavenMetadataReader.read( metadataFile.toFile() );
int buildNumber = archivaRepositoryMetadata.getSnapshotVersion().getBuildNumber();
String timeStamp = archivaRepositoryMetadata.getSnapshotVersion().getTimestamp();
// rebuild file name with timestamped version and build number
.append( ( StringUtils.isEmpty( classifier ) ? "" : "-" + classifier ) ) //
.append( ".jar" ).toString();
- File timeStampFile = new File( file.getParent(), timeStampFileName );
- log.debug( "try to find timestamped snapshot version file: {}", timeStampFile.getPath() );
- if ( timeStampFile.exists() )
+ Path timeStampFile = file.getParent().resolve( timeStampFileName );
+ log.debug( "try to find timestamped snapshot version file: {}", timeStampFile.toAbsolutePath() );
+ if ( Files.exists(timeStampFile) )
{
return true;
}
String path = managedRepositoryContent.toPath( archivaArtifact );
- file = connectors.fetchFromProxies( managedRepositoryContent, path );
+ file = connectors.fetchFromProxies( managedRepositoryContent, path ).toPath();
- if ( file != null && file.exists() )
+ if ( file != null && Files.exists(file) )
{
// download pom now
String pomPath = StringUtils.substringBeforeLast( path, ".jar" ) + ".pom";
}
}
- protected List<ArtifactContentEntry> readFileEntries(final File file, final String filterPath, final String repoId )
+ protected List<ArtifactContentEntry> readFileEntries(final Path file, final String filterPath, final String repoId )
throws IOException
{
String cleanedfilterPath = filterPath==null ? "" : (StringUtils.startsWith(filterPath, "/") ?
if (!StringUtils.endsWith(cleanedfilterPath,"/") && !StringUtils.isEmpty(cleanedfilterPath)) {
filterDepth++;
}
- JarFile jarFile = new JarFile( file );
+ JarFile jarFile = new JarFile( file.toFile() );
try
{
Enumeration<JarEntry> jarEntryEnumeration = jarFile.entries();
projectMetadata.setReleasedVersion( latestVersion );
}
- RepositoryMetadataWriter.write( projectMetadata, projectMetadataFile );
+ RepositoryMetadataWriter.write( projectMetadata, projectMetadataFile.toPath() );
if ( fixChecksums )
{
metadata.setLastUpdatedTimestamp( lastUpdatedTimestamp );
metadata.setAvailableVersions( availableVersions );
- RepositoryMetadataWriter.write( metadata, metadataFile );
+ RepositoryMetadataWriter.write( metadata, metadataFile.toPath() );
ChecksummedFile checksum = new ChecksummedFile( metadataFile );
checksum.fixChecksums( algorithms );
}
import org.apache.commons.io.FilenameUtils;
import java.io.File;
+import java.nio.file.Path;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.Locale;
ref.setClassifier( classifier );
ref.setType( type );
- File file = managedRepositoryContent.toFile( ref );
+ Path file = managedRepositoryContent.toFile( ref );
String extension = getExtensionFromFile(file);
/**
* Extract file extension
*/
- String getExtensionFromFile( File file )
+ String getExtensionFromFile( Path file )
{
// we are just interested in the section after the last -
- String[] parts = file.getName().split( "-" );
+ String[] parts = file.getFileName().toString().split( "-" );
if ( parts.length > 0 )
{
// get anything after a dot followed by a letter a-z, including other dots
}
}
// just in case
- return FilenameUtils.getExtension( file.getName() );
+ return FilenameUtils.getExtension( file.toFile().getName() );
}
}
import org.slf4j.LoggerFactory;
import java.io.File;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
throws Exception
{
- File file = new File( getBasedir(),
+ Path file = Paths.get( getBasedir(),
"src/test/repo-with-osgi/commons-logging/commons-logging/1.1/commons-logging-1.1.jar" );
List<ArtifactContentEntry> artifactContentEntries = browseService.readFileEntries( file, null, "foo" );
throws Exception
{
- File file = new File( getBasedir(),
+ Path file = Paths.get( getBasedir(),
"src/test/repo-with-osgi/commons-logging/commons-logging/1.1/commons-logging-1.1.jar" );
List<ArtifactContentEntry> artifactContentEntries = browseService.readFileEntries( file, "", "foo" );
throws Exception
{
- File file = new File( getBasedir(),
+ Path file = Paths.get( getBasedir(),
"src/test/repo-with-osgi/commons-logging/commons-logging/1.1/commons-logging-1.1.jar" );
List<ArtifactContentEntry> artifactContentEntries = browseService.readFileEntries( file, "/", "foo" );
throws Exception
{
- File file = new File( getBasedir(),
+ Path file = Paths.get( getBasedir(),
"src/test/repo-with-osgi/commons-logging/commons-logging/1.1/commons-logging-1.1.jar" );
List<ArtifactContentEntry> artifactContentEntries = browseService.readFileEntries( file, "org", "foo" );
throws Exception
{
- File file = new File( getBasedir(),
+ Path file = Paths.get( getBasedir(),
"src/test/repo-with-osgi/commons-logging/commons-logging/1.1/commons-logging-1.1.jar" );
List<ArtifactContentEntry> artifactContentEntries =
throws Exception
{
- File file = new File( getBasedir(),
+ Path file = Paths.get( getBasedir(),
"src/test/repo-with-osgi/commons-logging/commons-logging/1.1/commons-logging-1.1.jar" );
List<ArtifactContentEntry> artifactContentEntries =
import static org.assertj.core.api.Assertions.*;
import java.io.File;
+import java.nio.file.Paths;
import org.easymock.TestSubject;
import org.junit.Test;
@Test
public void testBuildSnapshot()
{
- assertThat( builder.getExtensionFromFile( new File( "/tmp/foo-2.3-20141119.064321-40.jar" ) ) ).isEqualTo( "jar" );
+ assertThat( builder.getExtensionFromFile( Paths.get( "/tmp/foo-2.3-20141119.064321-40.jar" ) ) ).isEqualTo( "jar" );
}
@Test
public void testBuildPom()
{
- assertThat( builder.getExtensionFromFile( new File( "/tmp/foo-1.0.pom" ) ) ).isEqualTo( "pom" );
+ assertThat( builder.getExtensionFromFile( Paths.get( "/tmp/foo-1.0.pom" ) ) ).isEqualTo( "pom" );
}
@Test
public void testBuildJar()
{
- assertThat( builder.getExtensionFromFile( new File( "/tmp/foo-1.0-sources.jar" ) ) ).isEqualTo( "jar" );
+ assertThat( builder.getExtensionFromFile( Paths.get( "/tmp/foo-1.0-sources.jar" ) ) ).isEqualTo( "jar" );
}
@Test
public void testBuildTarGz()
{
- assertThat( builder.getExtensionFromFile( new File( "/tmp/foo-1.0.tar.gz" ) ) ).isEqualTo( "tar.gz" );
+ assertThat( builder.getExtensionFromFile( Paths.get( "/tmp/foo-1.0.tar.gz" ) ) ).isEqualTo( "tar.gz" );
}
@Test
public void testBuildPomZip()
{
- assertThat( builder.getExtensionFromFile( new File( "/tmp/foo-1.0.pom.zip" ) ) ).isEqualTo( "pom.zip" );
+ assertThat( builder.getExtensionFromFile( Paths.get( "/tmp/foo-1.0.pom.zip" ) ) ).isEqualTo( "pom.zip" );
}
@Test
public void testBuildR00()
{
- assertThat( builder.getExtensionFromFile( new File( "/tmp/foo-1.0.r00" ) ) ).isEqualTo( "r00" );
+ assertThat( builder.getExtensionFromFile( Paths.get( "/tmp/foo-1.0.r00" ) ) ).isEqualTo( "r00" );
}
}
projectMetadata.setReleasedVersion( latestVersion );
}
- RepositoryMetadataWriter.write( projectMetadata, projectMetadataFile );
+ RepositoryMetadataWriter.write( projectMetadata, projectMetadataFile.toPath() );
if ( fixChecksums )
{
metadata.getSnapshotVersion().setTimestamp( timestamp );
metadata.setLastUpdatedTimestamp( lastUpdatedTimestamp );
- RepositoryMetadataWriter.write( metadata, metadataFile );
+ RepositoryMetadataWriter.write( metadata, metadataFile.toPath() );
if ( fixChecksums )
{
}
outputFile.getParentFile().mkdirs();
- RepositoryMetadataWriter.write( mergedMetadata, outputFile );
+ RepositoryMetadataWriter.write( mergedMetadata, outputFile.toPath() );
createChecksumFile( outputFilename, digestSha1 );
createChecksumFile( outputFilename, digestMd5 );
import java.io.Reader;
import java.nio.charset.Charset;
import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
connectors.fetchFromProxies( managedRepository, pomReference );
// Open and read the POM from the managed repo
- File pom = managedRepository.toFile( pomReference );
+ Path pom = managedRepository.toFile( pomReference );
- if ( !pom.exists() )
+ if ( !Files.exists(pom) )
{
return;
}
// MavenXpp3Reader leaves the file open, so we need to close it ourselves.
Model model = null;
- try (Reader reader = Files.newBufferedReader( pom.toPath(), Charset.defaultCharset() ))
+ try (Reader reader = Files.newBufferedReader( pom, Charset.defaultCharset() ))
{
model = MAVEN_XPP_3_READER.read( reader );
}
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.Collections;
import java.util.HashSet;
import java.util.Set;
public Set<ArtifactReference> getRelatedArtifacts( ArtifactReference reference )
throws ContentNotFoundException
{
- File artifactFile = toFile( reference );
- File repoDir = artifactFile.getParentFile();
+ Path artifactFile = toFile( reference );
+ Path repoDir = artifactFile.getParent();
- if ( !repoDir.exists() )
+ if ( !Files.exists(repoDir))
{
throw new ContentNotFoundException(
- "Unable to get related artifacts using a non-existant directory: " + repoDir.getAbsolutePath() );
+ "Unable to get related artifacts using a non-existant directory: " + repoDir.toAbsolutePath() );
}
- if ( !repoDir.isDirectory() )
+ if ( !Files.isDirectory( repoDir ) )
{
throw new ContentNotFoundException(
- "Unable to get related artifacts using a non-directory: " + repoDir.getAbsolutePath() );
+ "Unable to get related artifacts using a non-directory: " + repoDir.toAbsolutePath() );
}
Set<ArtifactReference> foundArtifacts = new HashSet<>();
// First gather up the versions found as artifacts in the managed repository.
- File repoFiles[] = repoDir.listFiles();
+ File repoFiles[] = repoDir.toFile().listFiles();
for (File repoFile : repoFiles)
{
if (repoFile.isDirectory()) {
@Override
public boolean hasContent( ArtifactReference reference )
{
- File artifactFile = toFile( reference );
- return artifactFile.exists() && artifactFile.isFile();
+ Path artifactFile = toFile( reference );
+ return Files.exists(artifactFile) && Files.isRegularFile( artifactFile );
}
@Override
}
@Override
- public File toFile( ArtifactReference reference )
+ public Path toFile( ArtifactReference reference )
{
- return new File( repository.getLocation(), toPath( reference ) );
+ return Paths.get( repository.getLocation(), toPath( reference ) );
}
@Override
- public File toFile( ArchivaArtifact reference )
+ public Path toFile( ArchivaArtifact reference )
{
- return new File( repository.getLocation(), toPath( reference ) );
+ return Paths.get( repository.getLocation(), toPath( reference ) );
}
/**
projectMetadata.setReleasedVersion( latestVersion );
}
- RepositoryMetadataWriter.write( projectMetadata, projectMetaDataFileIntargetRepo );
+ RepositoryMetadataWriter.write( projectMetadata, projectMetaDataFileIntargetRepo.toPath() );
}
}
versionMetadata.setLastUpdatedTimestamp( lastUpdatedTimestamp );
- RepositoryMetadataWriter.write( versionMetadata, versionMetaDataFileInTargetRepo );
+ RepositoryMetadataWriter.write( versionMetadata, versionMetaDataFileInTargetRepo.toPath() );
}
private ArchivaRepositoryMetadata getMetadata( File metadataFile )