Java tutorial
/** * Copyright (c) 2010-2011 Martin M Reed * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package org.hardisonbrewing.maven.cxx.generic; import java.io.File; 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.hardisonbrewing.maven.core.ArchiveService; import org.hardisonbrewing.maven.core.JoJoMojoImpl; import org.hardisonbrewing.maven.cxx.TargetDirectoryService; /** * @goal package * @phase package */ public final class PackageMojo extends JoJoMojoImpl { /** * @parameter */ private String classifier; /** * @component * @readonly */ protected MavenProjectHelper projectHelper; @Override public final void execute() throws MojoExecutionException, MojoFailureException { File src = new File(TargetDirectoryService.getTempPackagePath()); File dest = new File(TargetDirectoryService.getTempPackagePath() + ".zip"); getLog().info("Archiving " + src + " to " + dest); try { ArchiveService.archive(src, dest); } catch (ArchiverException e) { throw new IllegalStateException(e); } MavenProject project = getProject(); if (classifier == null) { project.getArtifact().setFile(dest); } else { projectHelper.attachArtifact(project, dest, classifier); } } }