All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.codehaus.mojo.nbm.NetBeansManifestUpdateMojo Maven / Gradle / Ivy

Go to download

Maven plugin for creating NetBeans modules. It defines a custom lifecycle called "nbm". During packaging, the module JAR is enhanced with NetBeans-specific manifest entries and, along with other required files, packed into a *.nbm file, ready for distribution. Additionally the plugin provides aggregator goals to create an update site or cluster for your module projects.

The newest version!
/* ==========================================================================
 * 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, threadSafe = 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; /** * Deployment type of the module, allowed values are normal,eager,autoload, * disabled. *

* autoload - Such a module is * automatically enabled when some other module requires it and * automatically disabled otherwise.

*

eager - This module type gets * automatically enabled when all it's dependencies are * satisfied. Disabled otherwise.

*

normal - This is the default * value. This kind of module is enabled/disabled manually by * the user. It installs enabled.

*

disabled - This kind of module is enabled/disabled manually by * the user. It installs disabled. Since 3.11

* * For details, see Netbeans Module system docs * * Since 3.14, for autoload and eager modules, we automatically set AutoUpdate-Show-In-Client manifest entry to false, if not defined already otherwise in the manifest. * See issue MNBMODULE-194 * * @since 3.8 (3.14 in manifest goal) */ @Parameter(defaultValue="normal") protected String moduleType; // /** * 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 MojoExecutionException if an unexpected problem occurs * @throws MojoFailureException if an expected problem occurs */ 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 mtype = moduleType; //same moduleType related code in CreateNetBeansFileStructure.java if ("normal".equals(mtype) && module.getModuleType() != null) { mtype = module.getModuleType(); getLog().warn( "moduleType in module descriptor is deprecated, use the plugin's parameter moduleType"); } if (!"normal".equals(mtype) && !"autoload".equals(mtype) && !"eager".equals(mtype) && !"disabled".equals(mtype)) { getLog().error( "Only 'normal,autoload,eager,disabled' are allowed values in the moduleType parameter"); } boolean autoload = "autoload".equals( mtype ); boolean eager = "eager".equals( mtype ); 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( "-", "." ); //