Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better support for custom packaging types (#12) #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.commons.io.FilenameUtils;
Expand All @@ -30,6 +32,7 @@
import org.codehaus.plexus.util.interpolation.RegexBasedInterpolator;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.sonatype.plexus.build.incremental.BuildContext;
import org.zeroturnaround.javarebel.maven.model.PackagingTypeMapping;
import org.zeroturnaround.javarebel.maven.model.RebelClasspath;
import org.zeroturnaround.javarebel.maven.model.RebelClasspathResource;
import org.zeroturnaround.javarebel.maven.model.RebelResource;
Expand Down Expand Up @@ -73,6 +76,13 @@ public class GenerateRebelMojo extends AbstractMojo {
*/
private String packaging;

/**
* Packaging type mappings to apply.
*
* @parameter
*/
private List<PackagingTypeMapping> packagingTypeMappings;

/**
* The directory containing generated classes.
*
Expand Down Expand Up @@ -283,13 +293,22 @@ public void execute() throws MojoExecutionException, MojoFailureException {

getLog().info("Processing " + getProject().getGroupId() + ":" + getProject().getArtifactId() + " with packaging " + packaging);

Map<String, String> processedPackagingTypeMappings = processPackagingTypeMappings();
String mappedPackaging = processedPackagingTypeMappings.get(packaging);
if (mappedPackaging == null) {
mappedPackaging = packaging;
} else {
getLog().debug("Mapped packaging type " + packaging + " to type " + mappedPackaging);
}

RebelXmlBuilder builder = null;
if (WAR_PACKAGING.contains(packaging)) {
if (WAR_PACKAGING.contains(mappedPackaging)) {
builder = buildWar();
} else if (JAR_PACKAGING.contains(packaging)) {
} else if (JAR_PACKAGING.contains(mappedPackaging)) {
builder = buildJar();
} else {
getLog().warn("Unsupported packaging type: " + packaging);
// the mapping logic guarantees that (packaging == mappedPackaging) if this statement is reached
getLog().warn("Unsupported packaging type: " + mappedPackaging);
}

if (builder != null) {
Expand Down Expand Up @@ -322,6 +341,34 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}
}

/**
* Process the packaging type mapping configuration. The values in the
* returned map are guaranteed to be supported by the plugin.
*/
private Map<String, String> processPackagingTypeMappings() {
Set<String> allStandardPackagingTypes = new HashSet<String>();
allStandardPackagingTypes.addAll(JAR_PACKAGING);
allStandardPackagingTypes.addAll(WAR_PACKAGING);

Map<String, String> processedPackagingTypeMappings = new HashMap<String, String>();
for (PackagingTypeMapping packagingTypeMapping : packagingTypeMappings) {
String type = packagingTypeMapping.getType();
String mapping = packagingTypeMapping.getMapping();

if (allStandardPackagingTypes.contains(mapping)) {
String existingMapping = processedPackagingTypeMappings.get(type);
if (existingMapping == null) {
processedPackagingTypeMappings.put(type, mapping);
} else {
getLog().warn("Packaging type " + type + " is already mapped to type " + existingMapping + "; ignoring conflicting mapping: " + type + " -> " + mapping);
}
} else {
getLog().warn("Ignoring packaging type mapping with unsupported target type: " + type + " -> " + mapping);
}
}
return processedPackagingTypeMappings;
}

/**
* Build war configuration.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.zeroturnaround.javarebel.maven.model;

/**
* Packaging type mapping configuration.
*/
public class PackagingTypeMapping {
/**
* Custom packaging type to map.
*
* @parameter
* @required
*/
private String type;

/**
* Standard packaging type to be mapped to.
*
* @parameter
* @required
*/
private String mapping;

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public String getMapping() {
return mapping;
}

public void setMapping(String mapping) {
this.mapping = mapping;
}
}