java archive file怎么_Java ZipArchiver.setDestFile方法代码示例

import org.codehaus.plexus.archiver.zip.ZipArchiver; //导入方法依赖的package包/类

@Test

public void testWithValidRoboconfDependencies() throws Exception {

// Prepare the project

final String projectName = "project--valid";

File baseDir = this.resources.getBasedir( projectName );

Assert.assertNotNull( baseDir );

Assert.assertTrue( baseDir.isDirectory());

AbstractMojo mojo = findMojo( projectName, "resolve" );

this.rule.setVariableValueToObject( mojo, "repoSystem", newRepositorySystem());

this.rule.setVariableValueToObject( mojo, "repositories", new ArrayList( 0 ));

// Create a Roboconf application

File dir = this.folder.newFolder();

File targetZipFile = this.folder.newFile();

Assert.assertTrue( targetZipFile.delete());

CreationBean bean = new CreationBean()

.projectDescription( "some desc" ).projectName( "my-project" )

.groupId( "net.roboconf" ).projectVersion( "1.0-SNAPSHOT" ).mavenProject( false );

ProjectUtils.createProjectSkeleton( dir, bean );

ZipArchiver zipArchiver = new ZipArchiver();

zipArchiver.addDirectory( dir );

zipArchiver.setCompress( true );

zipArchiver.setDestFile( targetZipFile );

zipArchiver.createArchive();

Assert.assertTrue( targetZipFile.isFile());

// Add dependencies

MavenProject project = (MavenProject) this.rule.getVariableValueFromObject( mojo, "project" );

project.setDependencyArtifacts( new HashSet ());

Artifact rbcfArtifact3 = new DefaultArtifact( "net.roboconf", "roboconf-core", "0.2", "runtime", "jar", null, new DefaultArtifactHandler());

rbcfArtifact3.setFile( targetZipFile );

project.getDependencyArtifacts().add( rbcfArtifact3 );

// Add it to our "local" repository

this.artifactIdToArtifact.put( rbcfArtifact3.getArtifactId(), rbcfArtifact3 );

// Execute it

File targetDir = new File( baseDir, MavenPluginConstants.TARGET_MODEL_DIRECTORY + "/" + Constants.PROJECT_DIR_GRAPH );

Assert.assertFalse( targetDir.isDirectory());

mojo.execute();

// Verify the import was copied in the right location

File importDir = new File( targetDir, "net.roboconf/roboconf-core" );

Assert.assertTrue( importDir.isDirectory());

Assert.assertTrue( new File( importDir, "main.graph" ).isFile());

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值