Class MavenHelper
java.lang.Object
org.glassfish.build.utils.MavenHelper
Helper for common Maven Plugin tasks.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringClean the pattern string for future regexp usage.static org.apache.maven.artifact.ArtifactcreateArtifact(String groupId, String artifactId, String version, String type) Creates an artifact instance for the supplied coordinates.static org.apache.maven.artifact.ArtifactCreates an artifact instance for the supplied coordinates.static org.apache.maven.artifact.ArtifactcreateArtifact(String dir, org.apache.maven.model.Model model) Create an artifact and its associated file by searching fortarget/${project.build.finalName}.${project.packaging}.static org.apache.maven.artifact.ArtifactcreateArtifact(org.apache.maven.model.Dependency dep) Creates an artifact instance from a dependency object.static org.apache.maven.artifact.ArtifactcreateArtifact(org.apache.maven.model.Model model) Creates an artifact instance for the supplied model.static org.apache.maven.artifact.ArtifactcreateArtifact(org.apache.maven.model.Model model, String type, String classifier) Creates an artifact instance for the supplied model.static List<org.apache.maven.artifact.Artifact> createAttachedArtifacts(String dir, org.apache.maven.artifact.Artifact artifact, org.apache.maven.model.Model model) Create a list of attached artifacts and their associated files by searching fortarget/${project.build.finalName}-*.*.static FilecreateZip(Properties props, org.apache.maven.plugin.logging.Log log, String duplicate, List<org.apache.tools.ant.types.ZipFileSet> fsets, File target) Create a zip file.static org.apache.tools.ant.types.ZipFileSetcreateZipFileSet(File dir, String includePatterns, String excludePatterns) Create an AntZipFileSet.static org.apache.tools.ant.types.ZipFileSetCreate an AntZipFileSet.static Set<org.apache.maven.artifact.Artifact> excludeTransitive(Set<org.apache.maven.artifact.Artifact> artifacts, Set<org.apache.maven.artifact.Artifact> dependencyArtifacts) Filters a set of artifacts.static Set<org.apache.maven.artifact.Artifact> filterArtifacts(Set<org.apache.maven.artifact.Artifact> artifacts, Set<org.apache.maven.artifact.Artifact> dependencyArtifacts, boolean excludeTransitive, String includeScope, String excludeScope, String excludeTypes, String includeTypes) Filters a set of artifacts.static Set<org.apache.maven.artifact.Artifact> filterArtifacts(Set<org.apache.maven.artifact.Artifact> artifacts, Set<org.apache.maven.artifact.Artifact> dependencyArtifacts, boolean excludeTransitive, String includeScope, String excludeScope, String excludeTypes, String includeTypes, String includeClassifiers, String excludeClassifiers, String includeGroupIds, String excludeGroupIds, String includeArtifactIds, String excludeArtifactIds) Filters a set of artifacts.private static org.apache.maven.artifact.ArtifactgetArtifactFile(String dir, String finalName, org.apache.maven.model.Model model) Search for a file matching an artifact for the givenfinalNameand model.getCommaSeparatedList(String list) Convert a comma separated string into a list.Return the files contained in the directory, using inclusion and exclusion ant patterns.private static StringgetFinalName(org.apache.maven.model.Model model) Get the final name of a project artifact from aModelinstance.static FilegetPomInTarget(String dir) Returns the pom installed in target or null if not found.private static StringlistToString(List<String> list) Convert a to a comma separatedString.private static StringCreate the logging message for an unpack invocation.static StringmodelAsString(org.apache.maven.model.Model model) Read a model as aString.static org.apache.maven.model.ModelReads a given model.static org.eclipse.aether.resolution.ArtifactResultresolveArtifact(String groupId, String artifactId, String classifier, String type, String version, org.eclipse.aether.RepositorySystem repoSystem, org.eclipse.aether.RepositorySystemSession repoSession, List<org.eclipse.aether.repository.RemoteRepository> remoteRepos) Resolve a remote artifact using aether.static voidunpack(File file, File location, String includes, String excludes, boolean silent, org.apache.maven.plugin.logging.Log log, org.codehaus.plexus.archiver.manager.ArchiverManager archiverManager) Unpacks a given file.static voidwriteFile(File outfile, StringBuilder input) Write the given input to a file.static voidWrite a model tobuildDir/${project.build.finalName}.pom.static voidWrite the model tobuildDir/${project.build.finalName}.pom.
-
Constructor Details
-
MavenHelper
private MavenHelper()Cannot be instantiated.
-
-
Method Details
-
readModel
public static org.apache.maven.model.Model readModel(File pom) throws org.apache.maven.plugin.MojoExecutionException Reads a given model.- Parameters:
pom- the pom File- Returns:
- an instance of Model
- Throws:
org.apache.maven.plugin.MojoExecutionException- if anIOExceptionoccurs
-
getFinalName
Get the final name of a project artifact from aModelinstance.- Parameters:
model- the model- Returns:
- the final name of the artifact
-
createAttachedArtifacts
public static List<org.apache.maven.artifact.Artifact> createAttachedArtifacts(String dir, org.apache.maven.artifact.Artifact artifact, org.apache.maven.model.Model model) throws org.apache.maven.plugin.MojoExecutionException Create a list of attached artifacts and their associated files by searching fortarget/${project.build.finalName}-*.*.- Parameters:
dir- ${project.build.directory}artifact- the main artifact for which corresponding attached artifacts will be searchedmodel- an instance of model- Returns:
- the list of attached artifacts
- Throws:
org.apache.maven.plugin.MojoExecutionException- if an error occurred while searching files
-
getArtifactFile
private static org.apache.maven.artifact.Artifact getArtifactFile(String dir, String finalName, org.apache.maven.model.Model model) throws org.apache.maven.plugin.MojoExecutionException Search for a file matching an artifact for the givenfinalNameand model.- Parameters:
dir- the directory to searchfinalName- the artifact final namemodel- the project model- Returns:
- the
Artifactinstance - Throws:
org.apache.maven.plugin.MojoExecutionException- if an error occurred while searching files
-
createArtifact
public static org.apache.maven.artifact.Artifact createArtifact(String dir, org.apache.maven.model.Model model) throws org.apache.maven.plugin.MojoExecutionException Create an artifact and its associated file by searching fortarget/${project.build.finalName}.${project.packaging}.- Parameters:
dir- ${project.build.directory}model- an instance of model- Returns:
- the created
Artifactinstance - Throws:
org.apache.maven.plugin.MojoExecutionException- if an error occurred while searching files
-
getPomInTarget
Returns the pom installed in target or null if not found.- Parameters:
dir- ${project.build.directory}- Returns:
- an instance of the pom file or null if not found
- Throws:
org.apache.maven.plugin.MojoExecutionException- if an error occurred while searching files
-
getFiles
public static List<File> getFiles(String dirPath, String includes, String excludes) throws org.apache.maven.plugin.MojoExecutionException Return the files contained in the directory, using inclusion and exclusion ant patterns.- Parameters:
dirPath- the directory to scanincludes- the includes pattern, comma separatedexcludes- the excludes pattern, comma separated- Returns:
- the list of files found
- Throws:
org.apache.maven.plugin.MojoExecutionException- if an IOException occurred
-
createArtifact
public static org.apache.maven.artifact.Artifact createArtifact(String groupId, String artifactId, String version, String type, String classifier) Creates an artifact instance for the supplied coordinates.- Parameters:
groupId- The groupIdartifactId- The artifactIdversion- The versiontype- The type of the artifact. e.g "jar", "war" or "zip"classifier- The classifier- Returns:
- the created artifact
-
createArtifact
public static org.apache.maven.artifact.Artifact createArtifact(org.apache.maven.model.Model model, String type, String classifier) Creates an artifact instance for the supplied model.- Parameters:
model- the modeltype- the type of the artifactclassifier- the classifier to use- Returns:
- the created artifact
-
createArtifact
public static org.apache.maven.artifact.Artifact createArtifact(org.apache.maven.model.Model model) Creates an artifact instance for the supplied model.- Parameters:
model- the model- Returns:
- the created artifact
-
createArtifact
public static org.apache.maven.artifact.Artifact createArtifact(String groupId, String artifactId, String version, String type) Creates an artifact instance for the supplied coordinates.- Parameters:
groupId- The groupIdartifactId- The artifactIdversion- The versiontype- The type of the artifact. e.g "jar", "war" or "zip"- Returns:
- the created artifact
-
createArtifact
public static org.apache.maven.artifact.Artifact createArtifact(org.apache.maven.model.Dependency dep) Creates an artifact instance from a dependency object.- Parameters:
dep- the dependency object- Returns:
- the created artifact
-
writePom
Write a model tobuildDir/${project.build.finalName}.pom.- Parameters:
model- an instance of modelbuildDir- the directory in which to write the pom- Throws:
IOException- if an error occurred while writing the file
-
writePom
public static void writePom(org.apache.maven.model.Model model, File buildDir, String pomFileName) throws IOException Write the model tobuildDir/${project.build.finalName}.pom.- Parameters:
model- an instance of modelbuildDir- the directory in which to write the pompomFileName- the name of the written pom- Throws:
IOException- if an error occurred while writing the file
-
modelAsString
public static String modelAsString(org.apache.maven.model.Model model) throws org.apache.maven.plugin.MojoExecutionException Read a model as aString.- Parameters:
model- the model- Returns:
- the model as a
String - Throws:
org.apache.maven.plugin.MojoExecutionException- if an IOException occurred
-
filterArtifacts
public static Set<org.apache.maven.artifact.Artifact> filterArtifacts(Set<org.apache.maven.artifact.Artifact> artifacts, Set<org.apache.maven.artifact.Artifact> dependencyArtifacts, boolean excludeTransitive, String includeScope, String excludeScope, String excludeTypes, String includeTypes) throws org.apache.maven.plugin.MojoExecutionException Filters a set of artifacts.- Parameters:
artifacts- the set of artifacts to filterdependencyArtifacts- the set of artifact representing direct dependenciesexcludeTransitive- exclude transitive dependenciesincludeScope- the scopes to include, comma separated, can be nullexcludeScope- the scopes to exclude, comma separated, can be nullexcludeTypes- the types to include, comma separated, can be nullincludeTypes- the types to exclude, comma separated, can be null- Returns:
- the set of filtered artifacts
- Throws:
org.apache.maven.plugin.MojoExecutionException- if an error occurred while filtering
-
excludeTransitive
public static Set<org.apache.maven.artifact.Artifact> excludeTransitive(Set<org.apache.maven.artifact.Artifact> artifacts, Set<org.apache.maven.artifact.Artifact> dependencyArtifacts) throws org.apache.maven.plugin.MojoExecutionException Filters a set of artifacts.- Parameters:
artifacts- the set of artifacts to filterdependencyArtifacts- the set of artifact representing direct dependencies- Returns:
- the set of filtered artifacts
- Throws:
org.apache.maven.plugin.MojoExecutionException- if an error occurred while filtering
-
filterArtifacts
public static Set<org.apache.maven.artifact.Artifact> filterArtifacts(Set<org.apache.maven.artifact.Artifact> artifacts, Set<org.apache.maven.artifact.Artifact> dependencyArtifacts, boolean excludeTransitive, String includeScope, String excludeScope, String excludeTypes, String includeTypes, String includeClassifiers, String excludeClassifiers, String includeGroupIds, String excludeGroupIds, String includeArtifactIds, String excludeArtifactIds) throws org.apache.maven.plugin.MojoExecutionException Filters a set of artifacts.- Parameters:
artifacts- the set of artifacts to filterdependencyArtifacts- the set of artifact representing direct dependenciesexcludeTransitive- exclude transitive dependenciesincludeScope- the scopes to include, comma separated, can benullexcludeScope- the scopes to exclude, comma separated, can benullexcludeTypes- the types to exclude, comma separated, can benullincludeTypes- the types to include, comma separated, can benullincludeClassifiers- the classifiers to include, comma separated, can benullexcludeClassifiers- the classifiers to exclude, comma separated, can benullincludeGroupIds- the groupIds to include, comma separated, can benullexcludeGroupIds- the groupIds to exclude, comma separated, can benullincludeArtifactIds- the artifactIds to include, comma separated, can benullexcludeArtifactIds- the artifactIds to exclude, comma separated, can benull- Returns:
- the set of filtered artifacts
- Throws:
org.apache.maven.plugin.MojoExecutionException- if an error occurred while filtering
-
unpack
public static void unpack(File file, File location, String includes, String excludes, boolean silent, org.apache.maven.plugin.logging.Log log, org.codehaus.plexus.archiver.manager.ArchiverManager archiverManager) throws org.apache.maven.plugin.MojoExecutionException Unpacks a given file.- Parameters:
file- the file to unpacklocation- the directory where to unpackincludes- includes pattern for the files to unpackexcludes- exclude pattern for the files to unpacksilent- log unpack or notlog- the Maven logger instance, can be nullarchiverManager- an instance of ArchiveManager- Throws:
org.apache.maven.plugin.MojoExecutionException- if an error occurred while unpacking
-
logUnpack
Create the logging message for an unpack invocation.- Parameters:
file- the file being unpackedlocation- the target directory for the unpackincludes- the include patternsexcludes- the exclude patterns- Returns:
- the created
String
-
resolveArtifact
public static org.eclipse.aether.resolution.ArtifactResult resolveArtifact(String groupId, String artifactId, String classifier, String type, String version, org.eclipse.aether.RepositorySystem repoSystem, org.eclipse.aether.RepositorySystemSession repoSession, List<org.eclipse.aether.repository.RemoteRepository> remoteRepos) throws org.apache.maven.plugin.MojoExecutionException Resolve a remote artifact using aether.- Parameters:
groupId- the group identifier of the artifact, may benullartifactId- the artifact identifier of the artifact, may benullclassifier- the classifier of the artifact, may benulltype- the type of the artifact, may benullversion- the version of the artifact, may benullrepoSystem- the repository system componentrepoSession- the repository session componentremoteRepos- the remote repositories to use- Returns:
- the resolved artifact
- Throws:
org.apache.maven.plugin.MojoExecutionException- if an error occurred while resolving the artifact
-
cleanToBeTokenizedString
-
writeFile
Write the given input to a file.- Parameters:
outfile- the file to write toinput- the input to write- Throws:
IOException- if an error occurs while writing to the file
-
getCommaSeparatedList
-
listToString
-
createZipFileSet
public static org.apache.tools.ant.types.ZipFileSet createZipFileSet(File dir, List<String> includes, List<String> excludes) Create an AntZipFileSet.- Parameters:
dir- the resource directoryincludes- the list of include patternsexcludes- the list of exclude patterns- Returns:
- the create
ZipFileSet
-
createZipFileSet
public static org.apache.tools.ant.types.ZipFileSet createZipFileSet(File dir, String includePatterns, String excludePatterns) Create an AntZipFileSet.- Parameters:
dir- the resource directoryincludePatterns- the include patterns in comma separated listexcludePatterns- the exclude patterns in comma separate list- Returns:
- the create
ZipFileSet
-
createZip
public static File createZip(Properties props, org.apache.maven.plugin.logging.Log log, String duplicate, List<org.apache.tools.ant.types.ZipFileSet> fsets, File target) Create a zip file.- Parameters:
props- Ant project propertieslog- Maven loggerduplicate- behavior for duplicate file, one of "add", "preserve" or "fail"fsets- list ofZipFileSetthat describe the resources to ziptarget- theFileinstance for the zip file to create- Returns:
- the target file
-