org.codehaus.mojo.nbm.NetBeansManifestUpdateMojo Maven / Gradle / Ivy
Show all versions of nbm-maven-plugin Show documentation
/* ==========================================================================
* Copyright 2003-2007 Mevenide Team
*
* 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 org.codehaus.mojo.nbm;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.Reader;
import java.net.URL;
import java.text.BreakIterator;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TimeZone;
import java.util.regex.Pattern;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactCollector;
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.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.codehaus.mojo.nbm.model.Dependency;
import org.codehaus.mojo.nbm.model.NetBeansModule;
import org.apache.maven.project.MavenProject;
import org.apache.maven.shared.dependency.analyzer.DefaultClassAnalyzer;
import org.apache.maven.shared.dependency.analyzer.asm.ASMDependencyAnalyzer;
import org.apache.maven.shared.dependency.graph.DependencyGraphBuilder;
import org.apache.maven.shared.dependency.graph.DependencyNode;
import org.apache.tools.ant.taskdefs.Manifest;
import org.apache.tools.ant.taskdefs.ManifestException;
import org.codehaus.mojo.nbm.utils.ExamineManifest;
import org.codehaus.plexus.util.IOUtil;
/**
* Goal for generating NetBeans module system specific manifest entries, part of nbm
lifecycle/packaging.
*
* In order to have the generated manifest picked up by the maven-jar-plugin,
* one shall add the following configuration snippet to maven-jar-plugin.
*
*
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.2</version>
<configuration>
<useDefaultManifestFile>true</useDefaultManifestFile>
</configuration>
</plugin>
*
*
* @author Milos Kleint
*/
@Mojo(name="manifest",
defaultPhase= LifecyclePhase.PROCESS_CLASSES,
requiresProject=true,
requiresDependencyResolution= ResolutionScope.RUNTIME )
public class NetBeansManifestUpdateMojo
extends AbstractNbmMojo
{
/**
* NetBeans module assembly build directory.
* directory where the the NetBeans jar and nbm file get constructed.
*/
@Parameter(defaultValue="${project.build.directory}/nbm", property="maven.nbm.buildDir")
protected File nbmBuildDir;
/**
* a NetBeans module descriptor containing dependency information and more
* @deprecated all content from the module descriptor can be defined as plugin configuration now, will be removed in 4.0 entirely
*/
@Parameter(defaultValue="${basedir}/src/main/nbm/module.xml")
protected File descriptor;
/**
* maven project
*/
@Parameter(required=true, readonly=true, property="project")
private MavenProject project;
/**
* The location of JavaHelp sources for the project. The documentation
* itself is expected to be in the directory structure based on codenamebase of the module.
* eg. if your codenamebase is "org.netbeans.modules.apisupport", then the actual docs
* files shall go to ${basedir}/src/main/javahelp/org/netbeans/modules/apisupport/docs.
* Obsolete as of NetBeans 7.0 with @HelpSetRegistration.
* @since 2.7
*/
@Parameter(defaultValue="${basedir}/src/main/javahelp")
protected File nbmJavahelpSource;
/**
* Path to manifest file that will be used as base and enhanced with generated content. Any entry specified in the original file
* will not be overwritten
* @since 3.0
*/
@Parameter(required=true, defaultValue="${basedir}/src/main/nbm/manifest.mf")
private File sourceManifestFile;
/**
* Path to the generated MANIFEST file to use. It will be used by jar:jar plugin.
* @since 3.0
*/
@Parameter(required=true, readonly=true, defaultValue="${project.build.outputDirectory}/META-INF/MANIFEST.MF")
private File targetManifestFile;
/**
* Verify the runtime NetBeans module dependencies and Class-Path items
* generated from Maven dependencies. The check is done by matching classes used
* in current project. Allowed values for the parameter are fail
, warn
and skip
.
* The default is fail
in which case the validation failure results in a failed build,
* in the vast majority of cases the module would fail at runtime anyway.
*
* @since 3.0
*/
@Parameter(property="maven.nbm.verify", defaultValue="fail")
private String verifyRuntime;
private static final String FAIL = "fail";
private static final String WARN = "warn";
private static final String SKIP = "skip";
/**
* A list of module's public packages. If not defined, no packages are exported as public.
* Allowed values are single package names
* or package names ending with .* which represent the package and all subpackages.
*
* Eg. "org.kleint.milos.api" designates just the one package, while "org.kleint.milos.spi.*"
* denotes the spi package an all it's subpackages.
* @since 3.0
*/
@Parameter
private List publicPackages;
/**
* When encountering an OSGi bundle among dependencies, the plugin will generate a direct dependency
* on the bundle and will not include the bundle's jar into the nbm. Will only work with NetBeans 6.9+ runtime.
* Therefore it is off by default.
* WARNING: Additionally existing applications/modules need to check modules wrapping
* external libraries for library jars that are also OSGi bundles. Such modules will no longer include the OSGi bundles
* as part of the module but will include a modular dependency on the bundle. Modules depending on these old wrappers
* shall depend directly on the bundle, eventually rendering the old library wrapper module obsolete.
*
* @since 3.2
*/
@Parameter(defaultValue="false")
private boolean useOSGiDependencies;
/**
* codename base of the module, uniquely identifying the module within the NetBeans runtime. usually the package name equivalent.
* Can include the major release version.
* See NetBeans Module system docs
* @since 3.8
*/
@Parameter(defaultValue="${project.groupId}.${project.artifactId}")
private String codeNameBase;
/**
* List of explicit module dependency declarations overriding the default specification dependency. Useful when depending on a range of major versions,
* depending on implementation version etc.
* The format is:
*
* <dependency>
* <id>groupId:artifactId</id>
* <type>spec|impl|loose</type>
* <explicitValue>the entire dependency token</explicitValue>
* </dependency>
*
*
*
* where id
is composed of grouId and artifactId of a dependency defined in effective pom, separated by double colon. This is mandatory.
*
* Then there are 2 exclusively optional fields type
and explicitValue
, if both are defined explicitValue
gets applied.
*
* type
values: spec
means specification dependency.That's the default.
* impl
means implementation dependency, only the exact version match will satisfy the constraint.
* loose
means loose dependency, no requirement on version, the module just has to be present. Not very common option.
*
* @since 3.8
*/
@Parameter
private Dependency[] moduleDependencies;
//
/**
* The artifact repository to use.
*/
@Parameter(required=true, readonly=true, defaultValue="${localRepository}")
private ArtifactRepository localRepository;
/**
* The artifact factory to use.
*/
@Component
private ArtifactFactory artifactFactory;
/**
* The artifact metadata source to use.
*/
@Component
private ArtifactMetadataSource artifactMetadataSource;
/**
* The artifact collector to use.
*/
@Component
private ArtifactCollector artifactCollector;
/**
* The dependency tree builder to use.
*/
@Component( hint = "default" )
private DependencyGraphBuilder dependencyGraphBuilder;
// end of component params custom code folding
//
/**
* execute plugin
* @throws org.apache.maven.plugin.MojoExecutionException
* @throws org.apache.maven.plugin.MojoFailureException
*/
public void execute()
throws MojoExecutionException, MojoFailureException
{
//need to do this to chekc for javahelp on CP.
super.registerNbmAntTasks();
NetBeansModule module;
if ( descriptor != null && descriptor.exists() )
{
module = readModuleDescriptor( descriptor );
getLog().warn( "descriptor parameter is deprecated, use equivalent mojo parameters instead.");
}
else
{
module = createDefaultDescriptor( project, false );
}
String moduleName = codeNameBase;
if (module.getCodeNameBase() != null) {
moduleName = module.getCodeNameBase();
getLog().warn( "codeNameBase in module descriptor is deprecated, use the plugin's parameter codeNameBase");
}
moduleName = moduleName.replaceAll( "-", "." );
//