import junit.framework.TestCase;
import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
import org.apache.commons.io.FileUtils;
+import org.apache.maven.archiva.common.utils.FileUtil;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
public static File getTestFile( String path )
{
- return new File( getBasedir(), path );
- }
-
- public static String getBasedir()
- {
- String basedir = System.getProperty( "basedir" );
- if ( basedir == null )
- {
- basedir = new File( "" ).getAbsolutePath();
- }
-
- return basedir;
+ return new File( FileUtil.getBasedir(), path );
}
private void copyDirectoryStructure( File sourceDirectory, File destinationDirectory )
Artifact artifact =
createArtifact( "org.apache.maven.plugins", "maven-foo-plugin", "1.0", "1.0", "maven-plugin" );
artifact.setFile(
- new File( getBasedir(), "src/test/source-repository/test/plugins/maven-foo-plugin-1.0.jar" ) );
+ new File( FileUtil.getBasedir(), "src/test/source-repository/test/plugins/maven-foo-plugin-1.0.jar" ) );
artifactConverter.convert( artifact, targetRepository );
// There is a warning but I can't figure out how to look at it. Eyeballing the results it appears
// the plugin is being coverted correctly.
</build>
<dependencies>
+ <dependency>
+ <groupId>org.apache.archiva</groupId>
+ <artifactId>archiva-common</artifactId>
+ </dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
import java.io.File;
import junit.framework.TestCase;
+import org.apache.maven.archiva.common.utils.FileUtil;
/**
* AbstractChecksumTestCase
public abstract class AbstractChecksumTestCase
extends TestCase
{
- private File basedir;
-
- public File getBasedir()
- {
- if ( basedir == null )
- {
- String sysprop = System.getProperty( "basedir" );
- if ( sysprop != null )
- {
- basedir = new File( sysprop );
- }
- else
- {
- basedir = new File( System.getProperty( "user.dir" ) );
- }
- }
- return basedir;
- }
-
public File getTestOutputDir()
{
- File dir = new File( getBasedir(), "target/test-output/" + getName() );
+ File dir = new File( FileUtil.getBasedir(), "target/test-output/" + getName() );
if ( dir.exists() == false )
{
if ( dir.mkdirs() == false )
public File getTestResource( String filename )
{
- File dir = new File( getBasedir(), "src/test/resources" );
+ File dir = new File( FileUtil.getBasedir(), "src/test/resources" );
File file = new File( dir, filename );
if ( file.exists() == false )
{
import junit.framework.TestCase;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
+import org.apache.maven.archiva.common.utils.FileUtil;
import org.codehaus.plexus.registry.RegistryException;
import org.codehaus.redback.components.springutils.ComponentContainer;
import org.custommonkey.xmlunit.XMLAssert;
@Inject
private ComponentContainer componentContainer;
- public static String getBasedir()
- {
- String basedir = System.getProperty( "basedir" );
- if ( basedir == null )
- {
- basedir = new File( "" ).getAbsolutePath();
- }
-
- return basedir;
- }
-
public static File getTestFile( String path )
{
- return new File( getBasedir(), path );
+ return new File( FileUtil.getBasedir(), path );
}
/**
public void testGetConfigurationFromDefaultsWithDefaultRepoLocationAlreadyExisting()
throws Exception
{
- File repo = new File( getBasedir(), "/target/test-classes/existing_snapshots" );
+ File repo = new File( FileUtil.getBasedir(), "/target/test-classes/existing_snapshots" );
repo.mkdirs();
- repo = new File( getBasedir(), "/target/test-classes/existing_internal" );
+ repo = new File( FileUtil.getBasedir(), "/target/test-classes/existing_internal" );
repo.mkdirs();
String existingTestDefaultArchivaConfigFile = FileUtils.readFileToString(
getTestFile( "target/test-classes/org/apache/maven/archiva/configuration/test-default-archiva.xml" ) );
existingTestDefaultArchivaConfigFile =
- StringUtils.replace( existingTestDefaultArchivaConfigFile, "${appserver.base}", getBasedir() );
+ StringUtils.replace( existingTestDefaultArchivaConfigFile, "${appserver.base}", FileUtil.getBasedir() );
File generatedTestDefaultArchivaConfigFile =
- new File( getBasedir(), "target/test-classes/org/apache/maven/archiva/configuration/default-archiva.xml" );
+ new File( FileUtil.getBasedir(), "target/test-classes/org/apache/maven/archiva/configuration/default-archiva.xml" );
FileUtils.writeStringToFile( generatedTestDefaultArchivaConfigFile, existingTestDefaultArchivaConfigFile,
null );
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-plexus-bridge</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.archiva</groupId>
+ <artifactId>archiva-common</artifactId>
+ </dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-i18n</artifactId>
import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
import org.apache.commons.io.FileUtils;
import org.apache.maven.archiva.common.utils.ArchivaNexusIndexerUtil;
+import org.apache.maven.archiva.common.utils.FileUtil;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
config.addManagedRepository( createRepositoryConfig( TEST_REPO_2 ) );
}
- public static String getBasedir()
- {
- String basedir = System.getProperty( "basedir" );
- if ( basedir == null )
- {
- basedir = new File( "" ).getAbsolutePath();
- }
-
- return basedir;
- }
-
private void createSimpleIndex()
throws IOException, UnsupportedExistingLuceneIndexException, IllegalArtifactCoordinateException
{
List<File> files = new ArrayList<File>();
- files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1
+ files.add( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_1
+ "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ) );
- files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1
+ files.add( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_1
+ "/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.jar" ) );
- files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1
+ files.add( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_1
+ "/org/apache/archiva/archiva-test/2.0/archiva-test-2.0.jar" ) );
createIndex( TEST_REPO_1, files );
throws IOException, UnsupportedExistingLuceneIndexException, IllegalArtifactCoordinateException
{
List<File> files = new ArrayList<File>();
- files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1
+ files.add( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_1
+ "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ) );
- files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1
+ files.add( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_1
+ "/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.jar" ) );
- files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1
+ files.add( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_1
+ "/org/apache/archiva/archiva-test/2.0/archiva-test-2.0.jar" ) );
- files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1
+ files.add( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_1
+ "/org/apache/archiva/archiva-webapp/1.0/archiva-webapp-1.0.war" ) );
- files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1
+ files.add( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_1
+ "/com/artifactid-numeric/1.0/artifactid-numeric-1.0.jar" ) );
- files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1
+ files.add( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_1
+ "/com/artifactid-numeric123/1.0/artifactid-numeric123-1.0.jar" ) );
- files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1
+ files.add( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_1
+ "/com/classname-search/1.0/classname-search-1.0.jar" ) );
createIndex( TEST_REPO_1, files );
{
ManagedRepositoryConfiguration repositoryConfig = new ManagedRepositoryConfiguration();
repositoryConfig.setId( repository );
- repositoryConfig.setLocation( getBasedir() + "/target/test-classes/" + repository );
+ repositoryConfig.setLocation( FileUtil.getBasedir() + "/target/test-classes/" + repository );
repositoryConfig.setLayout( "default" );
repositoryConfig.setName( repository );
repositoryConfig.setScanned( true );
public void tearDown()
throws Exception
{
- FileUtils.deleteDirectory( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 + "/.indexer" ) );
- assertFalse( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 + "/.indexer" ).exists() );
+ FileUtils.deleteDirectory( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_1 + "/.indexer" ) );
+ assertFalse( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_1 + "/.indexer" ).exists() );
- FileUtils.deleteDirectory( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_2 + "/.indexer" ) );
- assertFalse( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_2 + "/.indexer" ).exists() );
+ FileUtils.deleteDirectory( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_2 + "/.indexer" ) );
+ assertFalse( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_2 + "/.indexer" ).exists() );
super.tearDown();
}
throws IOException, UnsupportedExistingLuceneIndexException, IllegalArtifactCoordinateException
{
context = new DefaultIndexingContext( repository, repository,
- new File( getBasedir(), "/target/test-classes/" + repository ),
- new File( getBasedir(),
+ new File( FileUtil.getBasedir(), "/target/test-classes/" + repository ),
+ new File( FileUtil.getBasedir(),
"/target/test-classes/" + repository + "/.indexer" ), null,
null, ArchivaNexusIndexerUtil.FULL_INDEX, false );
//indexer.addIndexingContext( repository, repository, new File( getBasedir(), "/target/test-classes/" +
//indexerEngine.endIndexing( context );
//indexer.removeIndexingContext( context, false );
- assertTrue( new File( getBasedir(), "/target/test-classes/" + repository + "/.indexer" ).exists() );
+ assertTrue( new File( FileUtil.getBasedir(), "/target/test-classes/" + repository + "/.indexer" ).exists() );
}
@Test
createSimpleIndex();
List<File> files = new ArrayList<File>();
- files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_2
+ files.add( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_2
+ "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ) );
- files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_2
+ files.add( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_2
+ "/org/apache/archiva/archiva-search/1.1/archiva-search-1.1.jar" ) );
createIndex( TEST_REPO_2, files );
throws Exception
{
List<File> files = new ArrayList<File>();
- files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_2
+ files.add( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_2
+ "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ) );
- files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_2
+ files.add( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_2
+ "/org/apache/archiva/archiva-search/1.1/archiva-search-1.1.jar" ) );
createIndex( TEST_REPO_2, files );
throws Exception
{
List<File> files = new ArrayList<File>();
- files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1
+ files.add( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_1
+ "/com/artifactid-numeric/1.0/artifactid-numeric-1.0.jar" ) );
- files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1
+ files.add( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_1
+ "/com/artifactid-numeric123/1.0/artifactid-numeric123-1.0.jar" ) );
createIndex( TEST_REPO_1, files );
import junit.framework.TestCase;
import org.apache.commons.io.FileUtils;
+import org.apache.maven.archiva.common.utils.FileUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
return localFile;
}
-
-
- public static String getBasedir()
- {
- String basedir = System.getProperty( "basedir" );
- if ( basedir == null )
- {
- basedir = new File( "" ).getAbsolutePath();
- }
-
- return basedir;
- }
-
public static File getTestFile( String path )
{
- return new File( getBasedir(), path );
+ return new File( FileUtil.getBasedir(), path );
}
}
extends TestCase
{
- public static String getBasedir()
- {
- String basedir = System.getProperty( "basedir" );
- if ( basedir == null )
- {
- basedir = new File( "" ).getAbsolutePath();
- }
-
- return basedir;
- }
-
@Inject
protected ApplicationContext applicationContext;
*/
import org.apache.commons.lang.StringUtils;
+import org.apache.maven.archiva.common.utils.FileUtil;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.model.ArtifactReference;
import org.apache.maven.archiva.repository.AbstractRepositoryLayerTestCase;
private ManagedRepositoryContent createManagedRepo( String layout )
throws Exception
{
- File repoRoot = new File( getBasedir() + "/target/test-repo" );
+ File repoRoot = new File( FileUtil.getBasedir() + "/target/test-repo" );
return createManagedRepositoryContent( "test-internal", "Internal Test Repo", repoRoot, layout );
}
<name>Archiva Transactions</name>
<description>API for managing transaction.</description>
<dependencies>
+ <dependency>
+ <groupId>org.apache.archiva</groupId>
+ <artifactId>archiva-common</artifactId>
+ </dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
{
protected List<Digester> digesters;
- public static String getBasedir()
- {
-
- String basedir = System.getProperty( "basedir" );
- if (basedir == null)
- {
- basedir = new File( "" ).getAbsolutePath();
- }
- return basedir;
-
- }
-
@SuppressWarnings( "unchecked" )
public void setUp()
throws Exception
*/
import org.apache.commons.io.FileUtils;
+import org.apache.maven.archiva.common.utils.FileUtil;
import java.io.File;
import java.io.IOException;
public class CopyFileEventTest
extends AbstractFileEventTest
{
- private File testDir = new File( getBasedir(), "target/transaction-tests/copy-file" );
+ private File testDir = new File( FileUtil.getBasedir(), "target/transaction-tests/copy-file" );
private File testDest = new File( testDir, "test-file.txt" );
- private File testSource = new File( getBasedir(), "target/transaction-tests/test-file.txt" );
+ private File testSource = new File( FileUtil.getBasedir(), "target/transaction-tests/test-file.txt" );
private File testDestChecksum;
{
super.tearDown();
- FileUtils.deleteDirectory( new File( getBasedir(), "target/transaction-tests" ) );
+ FileUtils.deleteDirectory( new File( FileUtil.getBasedir(), "target/transaction-tests" ) );
}
protected void assertChecksumCommit( File file )
import java.io.File;
import org.apache.commons.io.FileUtils;
+import org.apache.maven.archiva.common.utils.FileUtil;
/**
*/
public class CreateFileEventTest
extends AbstractFileEventTest
{
- private File testDir = new File( getBasedir(), "target/transaction-tests/create-file" );
+ private File testDir = new File( FileUtil.getBasedir(), "target/transaction-tests/create-file" );
public void testCreateCommitRollback()
throws Exception
assertChecksumRollback( testFile );
assertFalse( "Test file parent directories has been rolledback too", testDir.exists() );
- assertTrue( "target directory still exists", new File( getBasedir(), "target" ).exists() );
+ assertTrue( "target directory still exists", new File( FileUtil.getBasedir(), "target" ).exists() );
}
public void testCreateCommitRollbackWithBackup()
{
super.tearDown();
- FileUtils.deleteDirectory( new File( getBasedir(), "target/transaction-tests" ) );
+ FileUtils.deleteDirectory( new File( FileUtil.getBasedir(), "target/transaction-tests" ) );
}
}
stack.getContext().put( ActionContext.CONTAINER, container );
ActionContext.setContext( new ActionContext( stack.getContext() ) );
}
-
- public static String getBasedir()
- {
- String basedir = System.getProperty( "basedir" );
- if ( basedir == null )
- {
- basedir = new File( "" ).getAbsolutePath();
- }
-
- return basedir;
- }
}
import org.apache.archiva.scheduler.ArchivaTaskScheduler;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
+import org.apache.maven.archiva.common.utils.FileUtil;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
uploadAction.setConfiguration( archivaConfig );
uploadAction.setRepositoryFactory( repoFactory );
- File testRepo = new File( getBasedir(), "target/test-classes/test-repo" );
+ File testRepo = new File( FileUtil.getBasedir(), "target/test-classes/test-repo" );
testRepo.mkdirs();
assertTrue( testRepo.exists() );
public void testArtifactUploadWithPomSuccessful()
throws Exception
{
- setUploadParameters( "1.0", null, new File( getBasedir(),
+ setUploadParameters( "1.0", null, new File( FileUtil.getBasedir(),
"target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ),
- new File( getBasedir(), "target/test-classes/upload-artifact-test/pom.xml" ), false );
+ new File( FileUtil.getBasedir(), "target/test-classes/upload-artifact-test/pom.xml" ), false );
ManagedRepositoryContent content = new ManagedDefaultRepositoryContent();
content.setRepository( config.findManagedRepositoryById( REPOSITORY_ID ) );
public void testArtifactUploadWithClassifier()
throws Exception
{
- setUploadParameters( "1.0", "tests", new File( getBasedir(),
+ setUploadParameters( "1.0", "tests", new File( FileUtil.getBasedir(),
"target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ),
- new File( getBasedir(), "target/test-classes/upload-artifact-test/pom.xml" ), false );
+ new File( FileUtil.getBasedir(), "target/test-classes/upload-artifact-test/pom.xml" ), false );
ManagedRepositoryContent content = new ManagedDefaultRepositoryContent();
content.setRepository( config.findManagedRepositoryById( REPOSITORY_ID ) );
public void testArtifactUploadGeneratePomSuccessful()
throws Exception
{
- setUploadParameters( "1.0", null, new File( getBasedir(),
+ setUploadParameters( "1.0", null, new File( FileUtil.getBasedir(),
"target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ),
null, true );
public void testArtifactUploadNoPomSuccessful()
throws Exception
{
- setUploadParameters( "1.0", null, new File( getBasedir(),
+ setUploadParameters( "1.0", null, new File( FileUtil.getBasedir(),
"target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ),
null, false );
public void testArtifactUploadFailedRepositoryNotFound()
throws Exception
{
- setUploadParameters( "1.0", null, new File( getBasedir(),
+ setUploadParameters( "1.0", null, new File( FileUtil.getBasedir(),
"target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ),
null, false );
public void testArtifactUploadSnapshots()
throws Exception
{
- setUploadParameters( "1.0-SNAPSHOT", null, new File( getBasedir(),
+ setUploadParameters( "1.0-SNAPSHOT", null, new File( FileUtil.getBasedir(),
"target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ),
null, true );
// MRM-1353
// upload snapshot artifact again and check if build number was incremented
setUploadParameters( "1.0-SNAPSHOT", null,
- new File( getBasedir(),
+ new File( FileUtil.getBasedir(),
"target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ), null,
true );
public void testChecksumIsCorrectWhenArtifactIsReUploaded()
throws Exception
{
- setUploadParameters( "1.0", null, new File( getBasedir(),
+ setUploadParameters( "1.0", null, new File( FileUtil.getBasedir(),
"target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ),
null, true );
verifyProjectMetadataChecksums( repoLocation );
// RE-upload artifact
- setUploadParameters( "1.0", null, new File( getBasedir(),
+ setUploadParameters( "1.0", null, new File( FileUtil.getBasedir(),
"target/test-classes/upload-artifact-test/artifact-to-be-reuploaded.jar" ),
null, true );
public void testUploadArtifactAlreadyExistingRedeploymentsBlocked()
throws Exception
{
- setUploadParameters( "1.0", null, new File( getBasedir(),
+ setUploadParameters( "1.0", null, new File( FileUtil.getBasedir(),
"target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ),
null, true );
String returnString = uploadAction.doUpload();
assertEquals( Action.SUCCESS, returnString );
- setUploadParameters( "1.0", null, new File( getBasedir(),
+ setUploadParameters( "1.0", null, new File( FileUtil.getBasedir(),
"target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ),
null, true );
public void testUploadArtifactAlreadyExistingRedeploymentsAllowed()
throws Exception
{
- setUploadParameters( "1.0", null, new File( getBasedir(),
+ setUploadParameters( "1.0", null, new File( FileUtil.getBasedir(),
"target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ),
null, true );
String returnString = uploadAction.doUpload();
assertEquals( Action.SUCCESS, returnString );
- setUploadParameters( "1.0", null, new File( getBasedir(),
+ setUploadParameters( "1.0", null, new File( FileUtil.getBasedir(),
"target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ),
null, true );