Java Code Examples for org.codehaus.plexus.archiver.zip.ZipArchiver#createArchive()
The following examples show how to use
org.codehaus.plexus.archiver.zip.ZipArchiver#createArchive() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MavenUtil.java From jkube with Eclipse Public License 2.0 | 5 votes |
public static void createArchive(File sourceDir, File destinationFile, ZipArchiver archiver) throws IOException { try { archiver.addDirectory(sourceDir); archiver.setDestFile(destinationFile); archiver.createArchive(); } catch (IOException e) { throw new IOException("Failed to create archive " + destinationFile + ": " + e, e); } }
Example 2
Source File: NativeJavahMojo.java From maven-native with MIT License | 5 votes |
private void attachGeneratedIncludeFilesAsIncZip() throws MojoExecutionException { try { ZipArchiver archiver = new ZipArchiver(); DefaultFileSet fileSet = new DefaultFileSet(); fileSet.setUsingDefaultExcludes( true ); fileSet.setDirectory( javahOutputDirectory ); archiver.addFileSet( fileSet ); archiver.setDestFile( this.incZipFile ); archiver.createArchive(); if ( StringUtils.isBlank( this.classifier ) ) { projectHelper.attachArtifact( this.project, INCZIP_TYPE, null, this.incZipFile ); } else { projectHelper.attachArtifact( this.project, INCZIP_TYPE, this.classifier, this.incZipFile ); } } catch ( Exception e ) { throw new MojoExecutionException( "Unable to archive/deploy generated include files", e ); } }
Example 3
Source File: Utils.java From usergrid with Apache License 2.0 | 5 votes |
/** * @param jarFile Jar file to be created * @param sourceFolder Jar file will be created out of the contents of this folder. This corresponds to the root * folder of the jar file once it is created. */ public static void archiveWar( File jarFile, String sourceFolder ) throws MojoExecutionException { try { ZipArchiver archiver = new ZipArchiver(); archiver.enableLogging( new ConsoleLogger( org.codehaus.plexus.logging.Logger.LEVEL_INFO, "console" ) ); archiver.setDestFile( jarFile ); archiver.addDirectory( new File( sourceFolder ), "", new String[] { "**/*" }, null ); archiver.createArchive(); } catch ( Exception e ) { throw new MojoExecutionException( "Error while creating WAR file", e ); } }
Example 4
Source File: NativeBundleIncludeFilesMojo.java From maven-native with MIT License | 4 votes |
public void execute() throws MojoExecutionException { if ( skipIncludeDeployment ) { return; } if ( this.sources.length != 0 ) { try { ZipArchiver archiver = new ZipArchiver(); boolean zipIt = false; for ( int i = 0; i < sources.length; ++i ) { if ( sources[i].isDeployable() ) { DefaultFileSet fileSet = new DefaultFileSet(); fileSet.setUsingDefaultExcludes( true ); fileSet.setDirectory( sources[i].getDirectory() ); fileSet.setIncludes( sources[i].getIncludes() ); fileSet.setExcludes( sources[i].getExcludes() ); archiver.addFileSet( fileSet ); zipIt = true; } } if ( zipIt ) { archiver.setDestFile( this.incZipFile ); archiver.createArchive(); projectHelper.attachArtifact( this.project, INCZIP_TYPE, null, this.incZipFile ); } } catch ( Exception e ) { throw new MojoExecutionException( e.getMessage(), e ); } } }
Example 5
Source File: ResolveMojoTest.java From roboconf-platform with Apache License 2.0 | 4 votes |
@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<RemoteRepository>( 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> ()); 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()); }