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.
/*
* Copyright (c) Paremus and others (2015, 2016). All Rights Reserved.
*
* Licensed 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 aQute.bnd.maven.plugin;
import static aQute.bnd.maven.lib.executions.PluginExecutions.isPackagingGoal;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
import java.util.Set;
import java.util.jar.Manifest;
import java.util.stream.Stream;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;
import aQute.bnd.build.Project;
import aQute.bnd.exceptions.Exceptions;
import aQute.bnd.header.OSGiHeader;
import aQute.bnd.maven.PomPropertiesResource;
import aQute.bnd.maven.lib.configuration.BeanProperties;
import aQute.bnd.maven.lib.configuration.BndConfiguration;
import aQute.bnd.osgi.Builder;
import aQute.bnd.osgi.Constants;
import aQute.bnd.osgi.FileResource;
import aQute.bnd.osgi.Jar;
import aQute.bnd.osgi.Processor;
import aQute.bnd.osgi.Resource;
import aQute.bnd.version.MavenVersion;
import aQute.bnd.version.Version;
import aQute.lib.io.IO;
import aQute.lib.strings.Strings;
import aQute.service.reporter.Report.Location;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
import org.apache.maven.model.Developer;
import org.apache.maven.model.License;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectHelper;
import org.apache.maven.settings.Settings;
import org.apache.maven.shared.mapping.MappingUtils;
import org.codehaus.plexus.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonatype.plexus.build.incremental.BuildContext;
/**
* Abstract base class for all bnd-maven-plugin mojos.
*/
public abstract class AbstractBndMavenPlugin extends AbstractMojo {
protected final Logger logger = LoggerFactory.getLogger(getClass());
static final String LAST_MODIFIED = "aQute.bnd.maven.plugin.BndMavenPlugin.lastModified";
static final String MARKED_FILES = "aQute.bnd.maven.plugin.BndMavenPlugin.markedFiles";
static final String PACKAGING_JAR = "jar";
static final String PACKAGING_WAR = "war";
static final String TSTAMP = "${tstamp}";
static final String SNAPSHOT = "SNAPSHOT";
/**
* Whether to include the contents of the {@code classesDir} directory
* in the generated bundle.
*/
@Parameter(defaultValue = "true")
boolean includeClassesDir;
/**
* Whether to delete an existing {@link #getManifestPath()} before execution.
*/
@Parameter(defaultValue = "false")
boolean deleteExistingManifest;
/**
* The directory where the webapp is built when packaging is {@code war}.
*/
@Parameter(alias = "warOutputDir", defaultValue = "${project.build.directory}/${project.build.finalName}")
File webappDirectory;
/**
* The name of the created artifact (excluding extension and classifier).
*/
@Parameter(defaultValue = "${project.build.finalName}", readonly = true)
String finalName;
@Parameter(defaultValue = "${project}", required = true, readonly = true)
MavenProject project;
@Parameter(defaultValue = "${settings}", readonly = true)
Settings settings;
@Parameter(defaultValue = "${mojoExecution}", readonly = true)
MojoExecution mojoExecution;
/**
* The list of maven packaging types for which the plugin will execute.
*/
@Parameter(property = "bnd.packagingTypes", defaultValue = PACKAGING_JAR + "," + PACKAGING_WAR)
List packagingTypes;
/**
* Skip processing if {@link #includeClassesDir} is {@code true} and the
* {@code classesDir} directory is empty.
*/
@Parameter(property = "bnd.skipIfEmpty", defaultValue = "false")
boolean skipIfEmpty;
/**
* Timestamp for reproducible output archive entries, either formatted as ISO 8601
* {@code yyyy-MM-dd'T'HH:mm:ssXXX} or as an int representing seconds since the epoch.
*
* @see Configuring
* for Reproducible Builds
*/
@Parameter(defaultValue = "${project.build.outputTimestamp}")
String outputTimestamp;
/**
* File path to a bnd file containing bnd instructions for this project.
* Defaults to {@code bnd.bnd}. The file path can be an absolute or relative
* to the project directory.
*
* The bnd instructions for this project are merged with the bnd
* instructions, if any, for the parent project.
*/
@Parameter(defaultValue = Project.BNDFILE)
// This is not used and is for doc only; see {@link
// BndConfiguration#loadProperties(Processor)}
@SuppressWarnings("unused")
String bndfile;
/**
* Bnd instructions for this project specified directly in the pom file.
* This is generally be done using a {@code } section. If the
* project has a {@link #bndfile}, then this configuration element
* is ignored.
*
* The bnd instructions for this project are merged with the bnd
* instructions, if any, for the parent project.
*/
@Parameter
// This is not used and is for doc only; See {@link
// BndConfiguration#loadProperties(Processor)}
@SuppressWarnings("unused")
String bnd;
@Component
BuildContext buildContext;
@Component
MavenProjectHelper projectHelper;
@Component
ArtifactHandlerManager artifactHandlerManager;
File propertiesFile;
public abstract File getSourceDir();
public abstract List getResources();
public abstract File getClassesDir();
public abstract File getOutputDir();
public abstract File getManifestPath();
public abstract boolean isSkip();
public Optional getClassifier() {
return Optional.empty();
}
public Optional getType() {
return Optional.empty();
}
File getWebappDirectory() {
return webappDirectory;
}
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
// Exit without generating anything if the project packaging is not a
// packaging type. Probably it's just a parent project.
if (!packagingTypes.contains(project.getPackaging())) {
logger.debug("skip project with packaging=" + project.getPackaging());
return;
}
if (isSkip()) {
logger.info("skip project as configured");
return;
}
File classesDir = getClassesDir();
if (skipIfEmpty && includeClassesDir && isEmpty(classesDir)) {
logger.info(
"skip project because includeClassesDir=true, compiler output directory is empty and skipIfEmpty=true");
return;
}
Properties beanProperties = new BeanProperties();
beanProperties.put("project", project);
beanProperties.put("settings", settings);
Properties mavenProperties = new Properties(beanProperties);
Properties projectProperties = project.getProperties();
for (Enumeration> propertyNames = projectProperties.propertyNames(); propertyNames.hasMoreElements();) {
Object key = propertyNames.nextElement();
mavenProperties.put(key, projectProperties.get(key));
}
try (Builder builder = new Builder(new Processor(mavenProperties, false))) {
builder.setTrace(logger.isDebugEnabled());
builder.setBase(project.getBasedir());
propertiesFile = new BndConfiguration(project, mojoExecution).loadProperties(builder);
builder.setProperty("project.output", getClassesDir().getCanonicalPath());
// If no bundle to be built, we have nothing to do
if (Processor.isTrue(builder.getProperty(Constants.NOBUNDLES))) {
logger.debug(Constants.NOBUNDLES + ": true");
return;
}
// Reject sub-bundle projects
List subs = builder.getSubBuilders();
if ((subs.size() != 1) || !builder.equals(subs.get(0))) {
throw new MojoExecutionException("Sub-bundles not permitted in a maven build");
}
if (deleteExistingManifest) {
// delete existing MANIFEST.MF
// e.g. from previous build to avoid that this MANIFEST.MF
// becomes input to the bnd process (which could lead to
// suprising results in some cases)
File existingMetaInf = getManifestPath();
logger.info("Delete existing manifest: {}", existingMetaInf);
IO.delete(existingMetaInf);
}
// always add the outputDirectory to the classpath, but
// handle projects with no output directory, like
// 'test-wrapper-bundle'
if (classesDir.isDirectory()) {
builder.addClasspath(classesDir);
Jar classesDirJar;
if (includeClassesDir) {
classesDirJar = new Jar(project.getName(), classesDir);
} else {
classesDirJar = new Jar(project.getName()); // empty jar
}
classesDirJar.setManifest(new Manifest());
builder.setJar(classesDirJar);
}
boolean isWab = PACKAGING_WAR.equals(project.getPackaging());
boolean hasWablibs = builder.getProperty(Constants.WABLIB) != null;
String wabProperty = builder.getProperty(Constants.WAB);
if (isWab) {
if (wabProperty == null) {
builder.setProperty(Constants.WAB, "");
}
logger
.info("WAB mode enabled. Bnd output will be expanded into the 'maven-war-plugin' :"
+ getWebappDirectory());
} else if ((wabProperty != null) || hasWablibs) {
throw new MojoFailureException(
Constants.WAB + " & " + Constants.WABLIB + " are not supported with packaging 'jar'");
}
// Compute bnd classpath
Set artifacts = project.getArtifacts();
List