Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
TYCHO-258 Explicit creation of packaged site
Browse files Browse the repository at this point in the history
Avoid creation of artifact with undefined content.
Main artifact of eclipse-update-site is always a zip containing exactly the site.xml.
When providing the optional parameter archiveSite=true an additional zip archive
"site_assembly.zip" classified as assembly containing a full packaged update site is created.
Implements option 3 proposed by Eckart Langhuth on
https://issues.sonatype.org/browse/TYCHO-258
  • Loading branch information
eckart47 authored and jsievers committed Jun 15, 2010
1 parent c4a261c commit c543e32
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 46 deletions.
Expand Up @@ -7,6 +7,7 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectHelper;
import org.codehaus.plexus.archiver.ArchiverException;
import org.codehaus.plexus.archiver.zip.ZipArchiver;

Expand All @@ -28,40 +29,52 @@ public class PackageUpdateSiteMojo extends AbstractMojo {
private File target;

/**
* If true, create site zip file. If false (the default), do not create site zip file.
* If true, create site assembly zip file. If false (the default), do not create site assembly
* zip file.
*
* Please note that due to limitations of maven-deploy-plugin and maven-install-plugin
* plugins, site.zip will always be set as project's main artifact and will be
* deployed/installed to maven repository as a result. However, site.zip will only
* contain site.xml file if this parameter is set to false (the default), so overhead
* will be minimal.
* Please note that the project's main artifact that will be deployed/installed to maven
* repository is a zip only containing the site.xml. However, if this parameter is set to true
* an additional result file classified as 'assembly' containing a full packaged update site
* will be created and installed.
*
* @parameter default-value="false"
*/
private boolean archiveSite;

/**
* Used for attaching assembled update site to the project.
*
* @component
*/
private MavenProjectHelper projectHelper;

public void execute() throws MojoExecutionException, MojoFailureException {
if (target == null || !target.isDirectory()) {
throw new MojoExecutionException(
"Update site folder does not exist at: " + target != null ? target.getAbsolutePath() : "null");
}

ZipArchiver zipper = new ZipArchiver();
File destFile = new File(target.getParentFile(), "site.zip");
try {
ZipArchiver siteZipper = new ZipArchiver();
File siteDestination = new File(target.getParentFile(), "site.zip");
siteZipper.addFile(new File(target, "site.xml"), "site.xml");
siteZipper.setDestFile(siteDestination);
siteZipper.createArchive();
project.getArtifact().setFile(siteDestination);
if (archiveSite) {
zipper.addDirectory(target);
} else {
zipper.addFile(new File(target, "site.xml"), "site.xml");
ZipArchiver asssemblyZipper = new ZipArchiver();
File asssemblyDestFile = new File(target.getParentFile(), "site_assembly.zip");
asssemblyZipper.addDirectory(target);
asssemblyZipper.setDestFile(asssemblyDestFile);
asssemblyZipper.createArchive();
projectHelper.attachArtifact(project, "zip", "assembly", asssemblyDestFile);
}
zipper.setDestFile(destFile);
zipper.createArchive();

} catch (IOException e) {
throw new MojoExecutionException("Error packing update site", e);
} catch (ArchiverException e) {
throw new MojoExecutionException("Error packing update site", e);
}
project.getArtifact().setFile(destFile);
}

}
@@ -1,11 +1,14 @@
package org.codehaus.tycho.buildnumber.test;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;

import junit.framework.Assert;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.project.MavenProject;
import org.codehaus.tycho.eclipsepackaging.PackageUpdateSiteMojo;
import org.codehaus.tycho.testing.AbstractTychoMojoTestCase;
Expand Down Expand Up @@ -48,49 +51,45 @@ protected void setUp()
setVariableValueToObject( packagemojo, "target", siteFolder );
}

public void testArchiveSite()
throws Exception
{
setVariableValueToObject( packagemojo, "archiveSite", Boolean.TRUE );
public void testArchiveSite() throws Exception {
setVariableValueToObject(packagemojo, "archiveSite", Boolean.TRUE);

packagemojo.execute();

File resultzip = new File( targetFolder, "site.zip" );
Assert.assertTrue( resultzip.exists() );
Assert.assertEquals( project.getArtifact().getFile(), resultzip );

ZipFile zip = new ZipFile( resultzip );
try
{
assertNotNull( zip.getEntry( "site.xml" ) );
assertNotNull( zip.getEntry( "content.xml" ) );
}
finally
{
checkSiteZip();

File assemblyZip = new File(targetFolder, "site_assembly.zip");
Assert.assertTrue(assemblyZip.exists());
List<Artifact> attachedArtifacts = project.getAttachedArtifacts();
Assert.assertTrue(attachedArtifacts.size()==1);
Assert.assertTrue(attachedArtifacts.get(0).getFile().equals(assemblyZip));
Assert.assertTrue(attachedArtifacts.get(0).getClassifier().equals("assembly"));
Assert.assertTrue(attachedArtifacts.get(0).getType().equals("zip"));
ZipFile zip = new ZipFile(assemblyZip);
try {
assertNotNull(zip.getEntry("site.xml"));
assertNotNull(zip.getEntry("content.xml"));
} finally {
zip.close();
}
}

public void testNoArchiveSite()
throws Exception
{
public void testNoArchiveSite() throws Exception {
// this is the default
// setVariableValueToObject( packagemojo, "archiveSite", Boolean.FALSE );

packagemojo.execute();
checkSiteZip();
}

File resultzip = new File( targetFolder, "site.zip" );
Assert.assertTrue( resultzip.exists() );
Assert.assertEquals( project.getArtifact().getFile(), resultzip );
private void checkSiteZip() throws ZipException, IOException {
File resultzip = new File(targetFolder, "site.zip");
Assert.assertTrue(resultzip.exists());
Assert.assertEquals(project.getArtifact().getFile(), resultzip);

ZipFile zip = new ZipFile( resultzip );
try
{
assertNotNull( zip.getEntry( "site.xml" ) );
assertNull( zip.getEntry( "content.xml" ) );
}
finally
{
ZipFile zip = new ZipFile(resultzip);
try {
assertNotNull(zip.getEntry("site.xml"));
assertNull(zip.getEntry("content.xml"));
} finally {
zip.close();
}
}
Expand Down

0 comments on commit c543e32

Please sign in to comment.