Using Merge Modules in InstallShield:
a merge module bundles a jar into some re-usable object for InstallShield.
So in the pom.xml of my merge module, I have a direct dependency on that
perticular jar file. But that jar file also has it's own dependencies, I
don't want to copy those other dependencies, I only want that jar file.
Taking this further to building the final installer: this bundles all merge
modules. So in the pom.xml of the installer, I have dependencies on merge
modules. I don't want to copy any jar dependencies that are below that also.
I already created a Mojo that does all I want but it would be better if this
also included in the dependency plugin.
This is the code I have:
package com.mycomp.maven.plugin.msm;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.model.Dependency;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.codehaus.plexus.util.FileUtils;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
/**
* @goal process-resources
* @requiresDependencyResolution
* @description Copy the dependencies for the InstallShield Merge Module
*/
public class MsmProcessResourcesMojo extends AbstractMojo
{
/**
* @parameter expression="${project.artifacts}"
* @required
* @read-only
*/
private Collection artifacts;
/**
* @parameter expression="${project.dependencies}
* @required
* @read-only
*/
private Collection dependencies;
/**
* @parameter expression="${project.build.directory}/resources"
* @required
*/
private File targetDirectory;
/**
* @parameter expression="${stripVersions}" default-value="true"
*/
private boolean stripVersions;
/**
* @parameter expression="${limitToExtension}"
*/
private String limitToExtension;
/**
* @parameter expression="${useSubDirectoryPerType}"
default-value="true"
*/
private boolean useSubDirectoryPerType;
public MsmProcessResourcesMojo()
{
}
public void execute() throws MojoExecutionException,
MojoFailureException
{
try
{
getLog().info( "Process Resources for InstallShield Merge
Module..." );
List firstListArtifacts = getFirstLineArtifacts();
Iterator iterator = firstListArtifacts.iterator();
while (iterator.hasNext())
{
Artifact artifact = (Artifact)iterator.next();
if (limitToExtension == null || limitToExtension.equals(
artifact.getType() ))
{
File targetDir;
if( useSubDirectoryPerType )
{
targetDir = new File( targetDirectory,
artifact.getType() + "s" );
}
else
{
targetDir = targetDirectory;
}
getLog().info( "Copying artifact: " + artifact.toString()
);
if (stripVersions)
{
FileUtils.copyFile( artifact.getFile(), new File(
targetDir, artifact.getGroupId() + "." + artifact.getType() ) );
}
else
{
FileUtils.copyFileToDirectory( artifact.getFile(),
targetDir );
}
}
}
}
catch (IOException e)
{
throw new MojoExecutionException( "Error copying artifacts", e
);
}
}
private List getFirstLineArtifacts()
{
List result = new ArrayList( dependencies.size() );
Iterator iterator = artifacts.iterator();
while (iterator.hasNext())
{
Artifact artifact = (Artifact)iterator.next();
if (artifactIsADirectDependency( artifact ))
{
result.add( artifact );
}
}
return result;
}
private boolean artifactIsADirectDependency( Artifact artifact )
{
boolean result = false;
Iterator iterator = dependencies.iterator();
while (iterator.hasNext())
{
Dependency dependency = (Dependency)iterator.next();
if (dependency.getGroupId().equals( artifact.getGroupId() )
&& dependency.getArtifactId().equals(
artifact.getArtifactId() ))
{
result = true;
break;
}
}
return result;
}
}
Note that I have 2 additional options:
- limitToExtension: if you only want to copy dependencies with a certain
extension (e.g. only .msm or .dll files for example)
- useSubDirectoryPerType: this will create a structure as follows (simular
to m1 repo) :
* root dir
* dlls
* mydll.dll
* msms
* mymsm.dll
regards,
Wim
2006/1/4, dan tran <[EMAIL PROTECTED]>:
>
> what is your use case may i ask? can you just do the exclusion?
>
> -D
>
> On 1/4/06, Wim Deblauwe <[EMAIL PROTECTED]> wrote:
> >
> > yep
> >
> > 2006/1/4, dan tran <[EMAIL PROTECTED]>:
> > >
> > > direct = without transitive dependencies?
> > >
> > > -D
> > >
> > >
> > > On 1/4/06, Wim Deblauwe <[EMAIL PROTECTED]> wrote:
> > > >
> > > > I would like to be able to only copy "direct" dependencies. Where
> > should
> > > I
> > > > file a JIRA issue? I looked at
> http://jira.codehaus.org/browse/MOJObut
> > > > there is no component defined for this plugin.
> > > >
> > > > regards,
> > > >
> > > > Wim
> > > >
> > > > 2006/1/4, dan tran <[EMAIL PROTECTED]>:
> > > > >
> > > > > copy mojo copies artifacts specified in plugin's configuration
> > > > >
> > > > > copy-dependencies copies artifacts in your pom dependencies
> > including
> > > > > transitive ones
> > > > >
> > > > > -D
> > > > >
> > > > >
> > > > > On 1/4/06, Wim Deblauwe <[EMAIL PROTECTED]> wrote:
> > > > > >
> > > > > > Cool, I can use that. Does "copy" only copy the direct
> > dependencies
> > > > and
> > > > > > does
> > > > > > copy-dependencies copy the direct and transitive dependencies?
> > > > > >
> > > > > > regards,
> > > > > >
> > > > > > Wim
> > > > > >
> > > > > > 2006/1/4, Brian E. Fox <[EMAIL PROTECTED]>:
> > > > > > >
> > > > > > > The Mojo team would like to announce the 1.0 release of the
> > > > > > > dependency-maven-plugin:
> > > > > > >
> > > > > > > This plugin provides the capability to manipulate artifacts.
> It
> > > can
> > > > > copy
> > > > > > > and/or unpack artifacts from repositories (local and remote)to
> a
> > > > > > > specified location.
> > > > > > >
> > > > > > > The plugin has 4 goals:
> > > > > > >
> > > > > > > *copy: takes a list of artifacts defined in the plugin
> > > configuration
> > > > > > > section and copies them to a specified location, renaming them
> > or
> > > > > > > stripping the version if desired. This goal can resolve the
> > > > artifacts
> > > > > > > from remote repositories if they don't exist in local. This
> goal
> > > can
> > > > > > > also retrieve the version from dependencyManagement.
> > > > > > > *copy-dependencies: takes the list of dependencies and
> > transitive
> > > > > > > dependencies and copies them to a specified location,
> stripping
> > > the
> > > > > > > version if desired. This goal can also be run from the command
> > > line.
> > > > > > > *unpack: like copy but unpacks.
> > > > > > > *unpack-dependencies: like copy-dependencies but unpacks.
> > > > > > >
> > > > > > > All goals are able to detect if the artifacts already exist
> and
> > > > don't
> > > > > > > copy/unpack again
> > > > > > >
> > > > > > > Detailed docs are available at:
> > > > > > > http://mojo.codehaus.org/dependency-maven-plugin/
> > > > > > >
> > > > > > > The plugin is available on ibiblio and ready for use.
> > > > > > >
> > > > > > > Thanks for the Mojo team for helping to make this plugin come
> to
> > > > > > > fruition.
> > > > > > >
> > > > > > >
> > > >
> ---------------------------------------------------------------------
> > > > > > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > > > > > For additional commands, e-mail: [EMAIL PROTECTED]
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>