Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.sling.maven.projectsupport;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Properties;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.BundleList;
import org.codehaus.plexus.archiver.ArchiverException;
import org.codehaus.plexus.archiver.UnArchiver;
import org.codehaus.plexus.archiver.jar.JarArchiver;
import org.codehaus.plexus.archiver.manager.ArchiverManager;
import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
import org.codehaus.plexus.util.FileUtils;
/**
* Initialize a Sling application project by extracting bundles into the correct
* locations.
*
* @goal prepare-package
* @requiresDependencyResolution test
* @phase process-sources
* @description initialize a Sling application project
*/
public class PreparePackageMojo extends AbstractLaunchpadFrameworkMojo {
/**
* The output directory for the default bundles in a WAR-packaged project,
* the base JAR (in the subdirectory named in the baseDestination
* parameter), and any additional bundles.
*
* @parameter default-value="${project.build.directory}/launchpad-bundles"
*/
private File warOutputDirectory;
/**
* The project's packaging type.
*
* @parameter expression="${project.packaging}"
*/
private String packaging;
/**
* The definition of the base JAR.
*
* @parameter
*/
private ArtifactDefinition base;
/**
* The definition of the package to be included to provide web support for
* JAR-packaged projects (i.e. pax-web).
*
* @parameter
*/
private ArtifactDefinition jarWebSupport;
/**
* The project's build output directory (i.e. target/classes).
*
* @parameter expression="${project.build.outputDirectory}"
* @readonly
*/
private File buildOutputDirectory;
/**
* The temp directory (i.e. target/maven-launchpad-plugintmp).
*
* @parameter expression="${project.build.directory}/maven-launchpad-plugintmp"
* @readonly
*/
private File tempDirectory;
/**
* To look up Archiver/UnArchiver implementations
*
* @component
*/
private ArchiverManager archiverManager;
/**
* The Jar archiver.
*
* @component role="org.codehaus.plexus.archiver.Archiver" roleHint="jar"
*/
private JarArchiver jarArchiver;
public void executeWithArtifacts() throws MojoExecutionException, MojoFailureException {
copyBaseArtifact();
copyBundles(getBundleList(), getOutputDirectory());
copyConfigurationFiles();
if (JAR.equals(packaging)) {
unpackBaseArtifact();
}
}
protected void initArtifactDefinitions(Properties dependencies) {
if (base == null) {
base = new ArtifactDefinition();
}
base.initDefaults(dependencies.getProperty("base"));
if (jarWebSupport == null) {
jarWebSupport = new ArtifactDefinition();
}
jarWebSupport.initDefaults(dependencies.getProperty("jarWebSupport"));
}
/**
* Add the JAR Web Support bundle to the bundle list.
*/
@Override
protected void initBundleList(BundleList bundleList) {
if (packaging.equals(JAR)) {
bundleList.add(jarWebSupport.toBundle());
}
}
/**
* Patch the sling properties
*/
private void patchSlingProperties(final File dest, final Properties additionalProps)
throws MojoExecutionException {
final File origSlingProps = new File(dest, "sling.properties");
if ( !origSlingProps.exists() ) {
throw new MojoExecutionException("sling.properties not found at " + origSlingProps);
}
// read original properties
final Properties orig = new Properties();
FileInputStream fis = null;
try {
fis = new FileInputStream(origSlingProps);
orig.load(fis);
} catch (final IOException ioe) {
throw new MojoExecutionException("Unable to read " + origSlingProps, ioe);
} finally {
if ( fis != null ) {
try { fis.close(); } catch (final IOException ignore) {}
}
}
// patch
final Enumeration