Class UnpackPluginMojo

java.lang.Object
org.apache.maven.plugin.AbstractMojo
org.apache.maven.plugins.dependency.AbstractDependencyMojo
org.apache.maven.plugins.dependency.fromConfiguration.AbstractFromConfigurationMojo
org.apache.maven.plugins.dependency.fromConfiguration.UnpackMojo
de.iip_ecosphere.platform.tools.maven.dependencies.CleaningUnpackMojo
de.iip_ecosphere.platform.tools.maven.dependencies.UnpackPluginMojo
All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo

@Mojo(name="unpack-plugins", defaultPhase=TEST_COMPILE, requiresProject=false, threadSafe=true, requiresDependencyResolution=RUNTIME, requiresDependencyCollection=RUNTIME) public class UnpackPluginMojo extends CleaningUnpackMojo
Extended unpack Mojo for plugins.
Author:
Holger Eichelberger, SSE
  • Field Details

    • NAME_CLASSPATH_FILE

      private static final String NAME_CLASSPATH_FILE
      See Also:
    • plugins

      @Parameter(property="unpack.plugins", required=false) private List<UnpackPluginMojo.PluginItem> plugins
    • version

      @Parameter(property="unpack.version", required=false, defaultValue="") private String version
    • relocate

      @Parameter(property="unpack.relocate", required=false, defaultValue="false") private boolean relocate
    • always

      @Parameter(property="unpack.always", required=false, defaultValue="false") private boolean always
    • relocateTarget

      @Parameter(property="unpack.relocateTarget", required=false, defaultValue="jars") private File relocateTarget
    • forceResolve

      @Parameter(property="unpack.forceResolve", required=false, defaultValue="false") private boolean forceResolve
    • resolveAndCopy

      @Parameter(property="unpack.resolveAndCopy", required=false, defaultValue="false") private boolean resolveAndCopy
    • targetDirectory

      @Parameter(defaultValue="${project.build.directory}", readonly=true) private File targetDirectory
    • classpathFiles

      private List<String> classpathFiles
    • remoteArtifactRepositories

      @Parameter(defaultValue="${project.remoteArtifactRepositories}", readonly=true, required=true) private List<org.apache.maven.artifact.repository.ArtifactRepository> remoteArtifactRepositories
    • remoteRepositories

      @Parameter(defaultValue="${project.remoteProjectRepositories}", readonly=true) private List<org.eclipse.aether.repository.RemoteRepository> remoteRepositories
    • repoSession

      @Parameter(defaultValue="${repositorySystemSession}", readonly=true) private org.eclipse.aether.RepositorySystemSession repoSession
    • session

      @Parameter(defaultValue="${session}", readonly=true, required=true) private org.apache.maven.execution.MavenSession session
    • repoSystem

      @Component private org.eclipse.aether.RepositorySystem repoSystem
    • pluginAppends

      private Map<String,List<String>> pluginAppends
    • resolver

      private Resolver resolver
  • Constructor Details

    • UnpackPluginMojo

      public UnpackPluginMojo()
  • Method Details

    • doExecute

      public void doExecute() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException
      Overrides:
      doExecute in class CleaningUnpackMojo
      Throws:
      org.apache.maven.plugin.MojoExecutionException
      org.apache.maven.plugin.MojoFailureException
    • getOutputDir

      private File getOutputDir(String name)
      Returns the output directory for a plugin/classpath file name.
      Parameters:
      name - the name
      Returns:
      the output directory
    • getCpFile

      private File getCpFile(String name)
      Returns the path to a (more qualified) classpath file based on the output directory for a plugin/classpath file name.
      Parameters:
      name - the name
      Returns:
      the output directory
    • handleAppends

      private void handleAppends()
      Handles the appends.
    • handleSetupDescriptors

      private void handleSetupDescriptors()
      Handles explicit setup descriptors by rewriting the classpath files.
    • mergeFiles

      private void mergeFiles(File src, File tgt) throws IOException
      Merges files from src into tgt by only copying those that do not already exist.
      Parameters:
      src - the source folder
      tgt - the target folder
      Throws:
      IOException - if copying fails
    • extractSuffix

      private static String extractSuffix(String prefix, String line, String dflt)
      Extracts the suffix after removing the prefix.
      Parameters:
      prefix - the prefix to look for, may be null
      line - the line to extract the suffix from
      dflt - the default value if there is no prefix, usually line
      Returns:
      line or the line without the prefix
    • fixPrefix

      private String fixPrefix(String prefix, UnpackPluginMojo.Tokenizer tokenizer)
      Fixes the prefix by appending a path separator if needed.
      Parameters:
      prefix - the prefix
      tokenizer - the tokenizer determining the path separator
      Returns:
      the fixed prefix
    • stripPrefix

      private String stripPrefix(String prefix, String cpToken)
      Strips a prefix from a classpath token.
      Parameters:
      prefix - the prefix
      cpToken - the classpath token
      Returns:
      the stripped cpToken if there is something to strip
    • relocate

      private void relocate() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException
      Relocates the unpacked files.
      Throws:
      org.apache.maven.plugin.MojoExecutionException - if the execution fails
      org.apache.maven.plugin.MojoFailureException - if a remarkable processing failure occurred
    • processCpLineRelocation

      private void processCpLineRelocation(String name, String mode, PrintStream out, UnpackPluginMojo.Tokenizer tokenizer, String prefix, File jarFolder)
      Processes a classpath line while plugin relocation.
      Parameters:
      name - the name of the plugin
      mode - the unpack mode, may be null
      out - the output stream for the rewritten classpath file
      tokenizer - the tokenizer
      prefix - the classpath token prefix
      jarFolder - the folder where to copy the jars to
    • processCpLineNoRelocation

      private void processCpLineNoRelocation(String name, String mode, String line, PrintStream out, UnpackPluginMojo.Tokenizer tokenizer, String prefix)
      Processes a classpath line without plugin relocation.
      Parameters:
      name - the name of the plugin
      mode - the unpack mode, may be null
      line - the classpath line
      out - the output stream for the rewritten classpath file
      tokenizer - the tokenizer
      prefix - the classpath token prefix (for forceResolve)
    • rewriteToken

      private String rewriteToken(String token, String mode, String prefix, File jarFolder, UnpackPluginMojo.Tokenizer tokenizer)
      Rewrites a classpath token.
      Parameters:
      token - the token
      mode - the unpack mode, may be null
      prefix - the classpath token prefix (for forceResolve)
      jarFolder - the folder where to copy the jars to (considerd only for resolveAndCopy, may be null considered as if resolveAndCopy is false)
      tokenizer - the tokenizer
      Returns:
      token or the rewritten token
    • isModeResolve

      private boolean isModeResolve(String mode)
      Returns whether we are in resolve mode, i.e., either mode indicates "resolve" or forceResolve.
      Parameters:
      mode - the unpack mode, may be null
      Returns:
      true for resolve, false else
    • handleAppends

      private void handleAppends(String name, Set<String> knownTokens, Consumer<String> handler)
      Handles appends, if specified, by passing elements that are not yet in knownTokens to handler.
      Parameters:
      name - the name of the plugin
      knownTokens - the tokens known so far (classpath entries), modified as a side effect
      handler - the handler to be called
    • parsePath

      private org.eclipse.aether.artifact.DefaultArtifact parsePath(String path)
      Parses a classpath path back into a maven artifact.
      Parameters:
      path - the path
      Returns:
      the artifact
    • findArtifactId

      private int findArtifactId(String name)
      Returns the position of the "." after the groupId in name.
      Parameters:
      name - the name to analyze
      Returns:
      the position
    • resolve

      private String resolve(String path, File jarFolder)
      Tries to resolve the path.
      Parameters:
      path - the given classpath path
      jarFolder - the folder where to copy the jars to (considerd only for resolveAndCopy, may be null considered as if resolveAndCopy is false)
      Returns:
      path or the resolved path (in the local maven repo)
    • newResolveArtifactProjectBuildingRequest

      public org.apache.maven.project.ProjectBuildingRequest newResolveArtifactProjectBuildingRequest()
      Overrides:
      newResolveArtifactProjectBuildingRequest in class org.apache.maven.plugins.dependency.AbstractDependencyMojo