Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
01438cd7a8 | |||
d6c69768de | |||
a75429ea40 | |||
c4385d11b4 | |||
6b5dfddd71 | |||
2e6d2a7331 | |||
08a72ff5fd | |||
119c5a54b5 | |||
35a630c2d8 |
3
pom.xml
3
pom.xml
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>com.inteligr8.wildfly</groupId>
|
||||
<artifactId>wildfly-module-plugin</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
<packaging>maven-plugin</packaging>
|
||||
|
||||
<name>A Maven plugin for Wildfly Module handling</name>
|
||||
@@ -238,6 +238,7 @@
|
||||
<goals><goal>jar</goal></goals>
|
||||
<configuration>
|
||||
<show>public</show>
|
||||
<failOnError>false</failOnError>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
|
@@ -19,6 +19,7 @@ import org.apache.maven.model.building.ModelBuilder;
|
||||
import org.apache.maven.plugin.logging.Log;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.ProjectModelResolver;
|
||||
import org.eclipse.aether.impl.ArtifactResolver;
|
||||
|
||||
/**
|
||||
* @author brian@inteligr8.com
|
||||
@@ -33,6 +34,8 @@ public interface DependencyAwareComponent {
|
||||
|
||||
ProjectModelResolver getProjectModelResolver();
|
||||
|
||||
ArtifactResolver getArtifactResolver();
|
||||
|
||||
ModelBuilder getModelBuilder();
|
||||
|
||||
}
|
||||
|
@@ -23,8 +23,14 @@ import org.codehaus.plexus.util.StringUtils;
|
||||
import org.eclipse.aether.artifact.Artifact;
|
||||
import org.eclipse.aether.graph.DependencyNode;
|
||||
|
||||
import com.inteligr8.wildfly.maven.model.Module;
|
||||
import com.inteligr8.wildfly.maven.model.WildflyModule;
|
||||
|
||||
/**
|
||||
* This class indexes dependencies by their ID (sans version). It also stores
|
||||
* other metadata determined by other executions within this library.
|
||||
*
|
||||
* @author brian@inteligr8.com
|
||||
*/
|
||||
public class DependencyIndex {
|
||||
|
||||
public enum DependencyType {
|
||||
@@ -32,31 +38,45 @@ public class DependencyIndex {
|
||||
InSystemModule,
|
||||
Module,
|
||||
InModule,
|
||||
Deployable,
|
||||
Self,
|
||||
Other
|
||||
}
|
||||
|
||||
private final Map<String, DependencyNode> id2node = new HashMap<>();
|
||||
private final Map<String, Artifact> id2node = new HashMap<>();
|
||||
private final Map<String, DependencyType> id2type = new HashMap<>();
|
||||
private final Map<String, Module> id2module = new HashMap<>();
|
||||
private final Map<String, WildflyModule> id2module = new HashMap<>();
|
||||
private final Map<String, Boolean> id2accept = new HashMap<>();
|
||||
private final Set<String> id2topModule = new HashSet<>();
|
||||
|
||||
public String index(DependencyNode node) {
|
||||
String id = this.toId(node);
|
||||
this.id2node.put(id, node);
|
||||
return this.index(node.getArtifact());
|
||||
}
|
||||
|
||||
public String index(Artifact artifact) {
|
||||
String id = this.toId(artifact);
|
||||
if (!this.id2node.containsKey(id))
|
||||
this.id2node.put(id, artifact);
|
||||
return id;
|
||||
}
|
||||
|
||||
public void indexAcceptance(String id, boolean accept) {
|
||||
this.id2accept.put(id, accept);
|
||||
this.id2accept.put(id, accept && Boolean.TRUE.equals(this.id2accept.get(id)));
|
||||
}
|
||||
|
||||
public void indexType(String id, DependencyType dtype) {
|
||||
this.id2type.put(id, dtype);
|
||||
DependencyType existing = this.id2type.get(id);
|
||||
if (existing == null) {
|
||||
this.id2type.put(id, dtype);
|
||||
} else if (dtype.compareTo(existing) < 0) {
|
||||
this.id2type.put(id, dtype);
|
||||
}
|
||||
}
|
||||
|
||||
public void indexModule(String id, Module module) {
|
||||
public void indexModule(String id, WildflyModule module) {
|
||||
WildflyModule existing = this.id2module.get(id);
|
||||
if (existing != null && !existing.equals(module))
|
||||
throw new IllegalStateException();
|
||||
this.id2module.put(id, module);
|
||||
}
|
||||
|
||||
@@ -84,7 +104,7 @@ public class DependencyIndex {
|
||||
return this.id2type.get(id);
|
||||
}
|
||||
|
||||
public Module getModule(String id) {
|
||||
public WildflyModule getModule(String id) {
|
||||
return this.id2module.get(id);
|
||||
}
|
||||
|
||||
|
@@ -18,19 +18,34 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.DefaultArtifact;
|
||||
import org.apache.maven.artifact.handler.DefaultArtifactHandler;
|
||||
import org.apache.maven.artifact.resolver.filter.ExclusionArtifactFilter;
|
||||
import org.apache.maven.model.Exclusion;
|
||||
import org.apache.maven.model.building.ModelBuildingException;
|
||||
import org.apache.maven.model.resolution.UnresolvableModelException;
|
||||
import org.eclipse.aether.RepositoryException;
|
||||
import org.eclipse.aether.collection.DependencyGraphTransformationContext;
|
||||
import org.eclipse.aether.collection.DependencyGraphTransformer;
|
||||
import org.eclipse.aether.graph.DependencyFilter;
|
||||
import org.eclipse.aether.graph.DependencyNode;
|
||||
import org.eclipse.aether.resolution.ArtifactResolutionException;
|
||||
import org.eclipse.aether.util.artifact.JavaScopes;
|
||||
import org.eclipse.aether.util.filter.DependencyFilterUtils;
|
||||
import org.eclipse.aether.util.filter.ScopeDependencyFilter;
|
||||
|
||||
import com.inteligr8.wildfly.maven.DependencyIndex.DependencyType;
|
||||
import com.inteligr8.wildfly.maven.model.Module;
|
||||
import com.inteligr8.wildfly.maven.model.WildflyArtifact;
|
||||
import com.inteligr8.wildfly.maven.model.WildflyDeployable;
|
||||
import com.inteligr8.wildfly.maven.model.WildflyModule;
|
||||
|
||||
public class IndexingDependencyGraphTransformer implements DependencyGraphTransformer {
|
||||
|
||||
private final DependencyFilter filter = DependencyFilterUtils.andFilter(
|
||||
new ScopeDependencyFilter("test")
|
||||
);
|
||||
|
||||
private final DependencyAwareComponent dac;
|
||||
private final DependencyGraphTransformer transfomer;
|
||||
private final DependencyIndex dindex;
|
||||
@@ -44,57 +59,79 @@ public class IndexingDependencyGraphTransformer implements DependencyGraphTransf
|
||||
this.dindex = dindex;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is basically an intercepter for the default
|
||||
* DependencyGraphTransformer. It will make the call to perform the
|
||||
* default expected functions. But before that, it will crawl the
|
||||
* dependencies to index them.
|
||||
*/
|
||||
@Override
|
||||
public DependencyNode transformGraph(DependencyNode node, DependencyGraphTransformationContext context) throws RepositoryException {
|
||||
this.crawl(node, new Stack<DependencyNode>());
|
||||
this.crawl(node, new Stack<DependencyNode>(), new Stack<Exclusion>());
|
||||
|
||||
return this.transfomer.transformGraph(node, context);
|
||||
}
|
||||
|
||||
private void crawl(DependencyNode node, Stack<DependencyNode> ancestors) {
|
||||
/**
|
||||
* This method crawls a dependency and its dependencies, recursively.
|
||||
*
|
||||
* @param node A dependency.
|
||||
* @param ancestors A stack of ancestral artifacts; parent on top; root on bottom; empty if root.
|
||||
*/
|
||||
private void crawl(DependencyNode node, Stack<DependencyNode> ancestors, Stack<Exclusion> exclusions) {
|
||||
if (this.dac.getLog().isDebugEnabled())
|
||||
this.dac.getLog().debug("Crawling: " + ancestors + ": " + node);
|
||||
if (!new ExclusionArtifactFilter(exclusions).include(this.toMavenArtifact(node.getArtifact()))) {
|
||||
if (this.dac.getLog().isDebugEnabled())
|
||||
this.dac.getLog().debug("Excluding: " + node);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.filter.accept(node, ancestors))
|
||||
return;
|
||||
|
||||
boolean doExclude = node.getDependency() != null && node.getDependency().getExclusions() != null && !node.getDependency().getExclusions().isEmpty();
|
||||
int pushedExclusions = 0;
|
||||
if (doExclude) {
|
||||
if (this.dac.getLog().isDebugEnabled())
|
||||
this.dac.getLog().debug("Will start excluding: " + node.getDependency().getExclusions());
|
||||
for (org.eclipse.aether.graph.Exclusion exclusion : node.getDependency().getExclusions()) {
|
||||
exclusions.push(this.toMavenExclusion(exclusion));
|
||||
pushedExclusions++;
|
||||
}
|
||||
}
|
||||
|
||||
this.index(node, Collections.unmodifiableList(ancestors));
|
||||
|
||||
ancestors.push(node);
|
||||
for (DependencyNode child : node.getChildren())
|
||||
this.crawl(child, ancestors);
|
||||
this.crawl(child, ancestors, exclusions);
|
||||
ancestors.pop();
|
||||
|
||||
if (doExclude) {
|
||||
if (this.dac.getLog().isDebugEnabled())
|
||||
this.dac.getLog().debug("Will stop excluding: " + node.getDependency().getExclusions());
|
||||
for (int e = 0; e < pushedExclusions; e++)
|
||||
exclusions.pop();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method indexes a dependency.
|
||||
*
|
||||
* If a dependency encountered more than once, any occurrence inside a
|
||||
* system module will take precedence; then a non-system module.
|
||||
*
|
||||
* @param node A dependency.
|
||||
* @param parents A list of ancestral artifacts; parent is last; root is first; empty if root/self.
|
||||
*/
|
||||
public void index(DependencyNode node, List<DependencyNode> parents) {
|
||||
String nodeId = this.dindex.toId(node);
|
||||
DependencyType type = this.dindex.getType(nodeId);
|
||||
if (type != null) {
|
||||
if (this.dac.getLog().isDebugEnabled())
|
||||
this.dac.getLog().debug(nodeId + ": already determined type: " + type);
|
||||
return;
|
||||
}
|
||||
if (this.dac.getLog().isDebugEnabled())
|
||||
this.dac.getLog().debug("Indexing: " + nodeId);
|
||||
|
||||
this.dindex.index(node);
|
||||
|
||||
for (DependencyNode ancestor : parents) {
|
||||
String ancestorId = this.dindex.toId(ancestor);
|
||||
type = this.dindex.getType(ancestorId);
|
||||
if (type == null)
|
||||
throw new IllegalStateException("The dependency parents are expected to be processed before the children");
|
||||
|
||||
switch (type) {
|
||||
case SystemModule:
|
||||
case InSystemModule:
|
||||
if (this.dac.getLog().isDebugEnabled())
|
||||
this.dac.getLog().debug(nodeId + ": is in a module");
|
||||
this.dindex.indexType(nodeId, DependencyType.InSystemModule);
|
||||
return;
|
||||
case Module:
|
||||
case InModule:
|
||||
if (this.dac.getLog().isDebugEnabled())
|
||||
this.dac.getLog().debug(nodeId + ": is in a module");
|
||||
this.dindex.indexType(nodeId, DependencyType.InModule);
|
||||
return;
|
||||
default:
|
||||
// continue
|
||||
}
|
||||
}
|
||||
|
||||
if (parents == null || parents.isEmpty()) {
|
||||
// root element; the project itself
|
||||
// even if it is a module, we aren't going to consider it one in this context
|
||||
@@ -102,10 +139,44 @@ public class IndexingDependencyGraphTransformer implements DependencyGraphTransf
|
||||
return;
|
||||
}
|
||||
|
||||
ModuleArtifactExtractor extractor = new ModuleArtifactExtractor(this.dac);
|
||||
for (DependencyNode ancestor : parents) {
|
||||
String ancestorId = this.dindex.toId(ancestor);
|
||||
DependencyType type = this.dindex.getType(ancestorId);
|
||||
if (type == null)
|
||||
throw new IllegalStateException("The dependency parents are expected to be processed before the children");
|
||||
|
||||
switch (type) {
|
||||
case SystemModule:
|
||||
if (this.dac.getLog().isDebugEnabled())
|
||||
this.dac.getLog().debug(nodeId + ": is in a module");
|
||||
this.dindex.indexType(nodeId, DependencyType.InSystemModule);
|
||||
return;
|
||||
case InSystemModule:
|
||||
this.dac.getLog().debug(nodeId + ": is a dependency of something in a module, but not yet indexed (was excluded?)");
|
||||
//this.dindex.indexType(nodeId, DependencyType.InSystemModule);
|
||||
return;
|
||||
case Module:
|
||||
if (this.dac.getLog().isDebugEnabled())
|
||||
this.dac.getLog().debug(nodeId + ": is in a module");
|
||||
this.dindex.indexType(nodeId, DependencyType.InModule);
|
||||
return;
|
||||
case InModule:
|
||||
this.dac.getLog().debug(nodeId + ": is a dependency of something in a module, but not yet indexed (was excluded?)");
|
||||
return;
|
||||
default:
|
||||
// continue
|
||||
}
|
||||
}
|
||||
|
||||
WildflyArtifactExtractor extractor = new WildflyArtifactExtractor(this.dac);
|
||||
try {
|
||||
Module module = extractor.extract(node.getArtifact());
|
||||
if (module != null) {
|
||||
WildflyArtifact artifact = extractor.extract(node.getArtifact());
|
||||
if (artifact == null) {
|
||||
this.dindex.indexType(nodeId, DependencyType.Other);
|
||||
} else if (artifact instanceof WildflyDeployable) {
|
||||
this.dindex.indexType(nodeId, DependencyType.Deployable);
|
||||
} else {
|
||||
WildflyModule module = (WildflyModule) artifact;
|
||||
module.export = true;
|
||||
if (JavaScopes.RUNTIME.equals(node.getDependency().getScope()))
|
||||
module.export = false;
|
||||
@@ -113,12 +184,31 @@ public class IndexingDependencyGraphTransformer implements DependencyGraphTransf
|
||||
this.dindex.indexType(nodeId, module.isSystem ? DependencyType.SystemModule : DependencyType.Module);
|
||||
this.dindex.indexModule(nodeId, module);
|
||||
this.dindex.indexTopLevelModule(nodeId);
|
||||
} else {
|
||||
this.dindex.indexType(nodeId, DependencyType.Other);
|
||||
|
||||
if (node.getArtifact().getClassifier().length() > 0) {
|
||||
String shadowedNodeId = node.getArtifact().getGroupId() + ":" + node.getArtifact().getArtifactId() + ":jar";
|
||||
if (this.dac.getLog().isDebugEnabled())
|
||||
this.dac.getLog().debug("Indexing shadowed node: " + shadowedNodeId);
|
||||
this.dindex.indexType(shadowedNodeId, DependencyType.InModule);
|
||||
}
|
||||
}
|
||||
} catch (UnresolvableModelException | ModelBuildingException e) {
|
||||
} catch (UnresolvableModelException | ModelBuildingException | ArtifactResolutionException e) {
|
||||
this.dac.getLog().warn("Filtering out dependency '" + node.getDependency() + "' due to exception", e);
|
||||
}
|
||||
}
|
||||
|
||||
private Artifact toMavenArtifact(org.eclipse.aether.artifact.Artifact aetherArtifact) {
|
||||
Artifact artifact = new DefaultArtifact(aetherArtifact.getGroupId(), aetherArtifact.getArtifactId(), aetherArtifact.getVersion(), DefaultArtifact.SCOPE_COMPILE, aetherArtifact.getExtension(), aetherArtifact.getClassifier(), new DefaultArtifactHandler());
|
||||
artifact.setGroupId(aetherArtifact.getGroupId());
|
||||
artifact.setArtifactId(aetherArtifact.getArtifactId());
|
||||
return artifact;
|
||||
}
|
||||
|
||||
private Exclusion toMavenExclusion(org.eclipse.aether.graph.Exclusion aetherExclusion) {
|
||||
Exclusion exclusion = new Exclusion();
|
||||
exclusion.setGroupId(aetherExclusion.getGroupId());
|
||||
exclusion.setArtifactId(aetherExclusion.getArtifactId());
|
||||
return exclusion;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,113 +0,0 @@
|
||||
/*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.inteligr8.wildfly.maven;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.building.DefaultModelBuildingRequest;
|
||||
import org.apache.maven.model.building.ModelBuildingException;
|
||||
import org.apache.maven.model.building.ModelBuildingRequest;
|
||||
import org.apache.maven.model.building.ModelBuildingResult;
|
||||
import org.apache.maven.model.building.ModelSource;
|
||||
import org.apache.maven.model.resolution.UnresolvableModelException;
|
||||
import org.apache.maven.plugin.logging.Log;
|
||||
import org.eclipse.aether.artifact.Artifact;
|
||||
|
||||
import com.inteligr8.wildfly.maven.model.Module;
|
||||
|
||||
public class ModuleArtifactExtractor {
|
||||
|
||||
private final DependencyAwareComponent dac;
|
||||
private final DefaultModelBuildingRequest modelBuildRequestTemplate;
|
||||
|
||||
public ModuleArtifactExtractor(DependencyAwareComponent dac) {
|
||||
this.dac = dac;
|
||||
|
||||
this.modelBuildRequestTemplate = new DefaultModelBuildingRequest()
|
||||
.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL)
|
||||
.setUserProperties(this.dac.getMavenSession().getUserProperties())
|
||||
.setSystemProperties(this.dac.getMavenSession().getSystemProperties())
|
||||
.setModelResolver(this.dac.getProjectModelResolver());
|
||||
}
|
||||
|
||||
public Module extract(Artifact artifact)
|
||||
throws UnresolvableModelException, ModelBuildingException {
|
||||
if (this.getLog().isDebugEnabled())
|
||||
this.getLog().debug("Inspecting artifact POM: " + artifact);
|
||||
|
||||
if (artifact.getProperty("id", null) != null) {
|
||||
Module module = new Module();
|
||||
module.id = artifact.getProperty("id", null);
|
||||
module.version = artifact.getProperty("version", null);
|
||||
module.exportMetaInf = Boolean.parseBoolean(artifact.getProperty("exportMetaInf", Boolean.FALSE.toString()));
|
||||
module.exportServices = Boolean.parseBoolean(artifact.getProperty("exportServices", Boolean.FALSE.toString()));
|
||||
module.exportAnnotations = Boolean.parseBoolean(artifact.getProperty("exportAnnotations", Boolean.FALSE.toString()));
|
||||
module.isSystem = Boolean.parseBoolean(artifact.getProperty("isSystem", Boolean.FALSE.toString()));
|
||||
return module;
|
||||
}
|
||||
|
||||
ModelSource source = this.dac.getProjectModelResolver().resolveModel(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion());
|
||||
if (this.getLog().isDebugEnabled())
|
||||
this.getLog().debug("Found artifact POM [" + artifact + "]: " + source.getLocation());
|
||||
|
||||
DefaultModelBuildingRequest modelBuildRequest = new DefaultModelBuildingRequest(this.modelBuildRequestTemplate)
|
||||
.setModelSource(source);
|
||||
ModelBuildingResult result = this.dac.getModelBuilder().build(modelBuildRequest);
|
||||
if (this.getLog().isDebugEnabled())
|
||||
this.getLog().debug("Parsed artifact POM [" + artifact + "]: " + result.getModelIds());
|
||||
|
||||
Model model = result.getEffectiveModel();
|
||||
if (this.getLog().isDebugEnabled())
|
||||
this.getLog().debug("Formulated artifact effective POM [" + artifact + "]: " + model.getId());
|
||||
|
||||
Properties modelProps = model.getProperties();
|
||||
String moduleId = modelProps.getProperty("wildfly.module.id");
|
||||
if (moduleId == null) {
|
||||
if (this.getLog().isDebugEnabled())
|
||||
this.getLog().debug("No 'wildfly.module.id' property; not a Wildfly module project; adding as module resource: " + artifact);
|
||||
return null;
|
||||
} else {
|
||||
String moduleVersion = StringUtils.trimToNull(modelProps.getProperty("wildfly.module.version"));
|
||||
|
||||
Module module = new Module();
|
||||
module.id = moduleId;
|
||||
module.version = moduleVersion;
|
||||
module.exportMetaInf = Boolean.parseBoolean(modelProps.getProperty("wildfly.module.meta"));
|
||||
module.exportServices = Boolean.parseBoolean(modelProps.getProperty("wildfly.module.services"));
|
||||
module.exportAnnotations = Boolean.parseBoolean(modelProps.getProperty("wildfly.module.annotations"));
|
||||
module.isSystem = Boolean.parseBoolean(modelProps.getProperty("wildfly.module.system"));
|
||||
|
||||
Map<String, String> props = new HashMap<>();
|
||||
props.put("id", module.id);
|
||||
props.put("version", module.version);
|
||||
props.put("exportMetaInf", String.valueOf(module.exportMetaInf));
|
||||
props.put("exportServices", String.valueOf(module.exportServices));
|
||||
props.put("exportAnnotations", String.valueOf(module.exportAnnotations));
|
||||
props.put("isSystem", String.valueOf(module.isSystem));
|
||||
artifact.setProperties(props);
|
||||
|
||||
return module;
|
||||
}
|
||||
}
|
||||
|
||||
private Log getLog() {
|
||||
return this.dac.getLog();
|
||||
}
|
||||
|
||||
}
|
@@ -68,6 +68,11 @@ public class ModuleExclusionDependencyFilter implements DependencyFilter {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.dindex.getType(nodeId) == null) {
|
||||
this.dac.getLog().warn(nodeId + ": missing from index");
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (this.dindex.getType(nodeId)) {
|
||||
case SystemModule:
|
||||
case Module:
|
||||
|
@@ -14,9 +14,7 @@
|
||||
*/
|
||||
package com.inteligr8.wildfly.maven;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.aether.graph.DependencyFilter;
|
||||
import org.eclipse.aether.graph.DependencyNode;
|
||||
@@ -27,7 +25,6 @@ public class ValidationDependencyFilter implements DependencyFilter {
|
||||
|
||||
private final DependencyAwareComponent dac;
|
||||
private final DependencyIndex dindex;
|
||||
private final Set<String> moduleHasNonPom = new HashSet<>();
|
||||
|
||||
public ValidationDependencyFilter(DependencyAwareComponent dac, DependencyIndex dindex) {
|
||||
this.dac = dac;
|
||||
@@ -41,45 +38,38 @@ public class ValidationDependencyFilter implements DependencyFilter {
|
||||
return true;
|
||||
}
|
||||
|
||||
String parentId = null;
|
||||
if (parents.size() == 1) {
|
||||
parentId = this.dindex.toId(parents.iterator().next());
|
||||
} else {
|
||||
DependencyNode parent = parents.iterator().next();
|
||||
parentId = this.dindex.toId(parent);
|
||||
|
||||
for (DependencyNode parent : parents) {
|
||||
String parentId = this.dindex.toId(parent);
|
||||
|
||||
DependencyType type = this.dindex.getType(parentId);
|
||||
if (type == null)
|
||||
throw new IllegalStateException("The dependency parent is expected to be processed before its children");
|
||||
if (type == null) {
|
||||
if (parent.getDependency() == null) {
|
||||
this.dac.getLog().warn("Has no dependency information: " + parent.getArtifact() + " => " + node.getArtifact());
|
||||
} else {
|
||||
switch (parent.getDependency().getScope()) {
|
||||
case "test":
|
||||
this.dac.getLog().debug("The dependency parent was excluded as a test artifact: " + parent);
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case Module:
|
||||
case SystemModule:
|
||||
if (this.dac.getLog().isDebugEnabled())
|
||||
this.dac.getLog().debug(parentId + " is a module");
|
||||
break;
|
||||
return true;
|
||||
default:
|
||||
// ignore if the node isn't a module
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
this.validateDependencyOrder(node, parentId);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void validateDependencyOrder(DependencyNode node, String parentId) {
|
||||
String ext = node.getArtifact().getExtension();
|
||||
if (this.moduleHasNonPom.contains(parentId)) {
|
||||
if ("pom".equalsIgnoreCase(ext)) {
|
||||
this.dac.getLog().warn("Wildfly module dependency found after non-module dependency: " + node.getArtifact());
|
||||
this.dac.getLog().info("Dependency order impacts library exclusion from packaging");
|
||||
}
|
||||
} else if (!"pom".equalsIgnoreCase(ext)) {
|
||||
if (this.dac.getLog().isDebugEnabled())
|
||||
this.dac.getLog().debug("The project itself or module has a non-pom: " + node.getArtifact());
|
||||
this.moduleHasNonPom.add(parentId);
|
||||
}
|
||||
|
||||
this.dac.getLog().error("None of the dependency parents were processed before the artifact: " + node.getDependency());
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,172 @@
|
||||
/*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.inteligr8.wildfly.maven;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.building.DefaultModelBuildingRequest;
|
||||
import org.apache.maven.model.building.ModelBuildingException;
|
||||
import org.apache.maven.model.building.ModelBuildingRequest;
|
||||
import org.apache.maven.model.building.ModelBuildingResult;
|
||||
import org.apache.maven.model.building.ModelSource;
|
||||
import org.apache.maven.model.resolution.UnresolvableModelException;
|
||||
import org.apache.maven.plugin.logging.Log;
|
||||
import org.eclipse.aether.artifact.Artifact;
|
||||
import org.eclipse.aether.artifact.DefaultArtifact;
|
||||
import org.eclipse.aether.resolution.ArtifactRequest;
|
||||
import org.eclipse.aether.resolution.ArtifactResolutionException;
|
||||
import org.eclipse.aether.resolution.ArtifactResult;
|
||||
|
||||
import com.inteligr8.wildfly.maven.model.WildflyArtifact;
|
||||
import com.inteligr8.wildfly.maven.model.WildflyDeployable;
|
||||
import com.inteligr8.wildfly.maven.model.WildflyModule;
|
||||
|
||||
public class WildflyArtifactExtractor {
|
||||
|
||||
private final DependencyAwareComponent dac;
|
||||
private final DefaultModelBuildingRequest modelBuildRequestTemplate;
|
||||
|
||||
public WildflyArtifactExtractor(DependencyAwareComponent dac) {
|
||||
this.dac = dac;
|
||||
|
||||
this.modelBuildRequestTemplate = new DefaultModelBuildingRequest()
|
||||
.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL)
|
||||
.setUserProperties(this.dac.getMavenSession().getUserProperties())
|
||||
.setSystemProperties(this.dac.getMavenSession().getSystemProperties())
|
||||
.setModelResolver(this.dac.getProjectModelResolver());
|
||||
}
|
||||
|
||||
public WildflyArtifact extract(Artifact artifact)
|
||||
throws UnresolvableModelException, ModelBuildingException, ArtifactResolutionException {
|
||||
if (this.getLog().isDebugEnabled())
|
||||
this.getLog().debug("Inspecting artifact POM: " + artifact);
|
||||
|
||||
if (artifact.getProperty("id", null) != null) {
|
||||
String type = artifact.getProperty("type", null);
|
||||
if (type != null) {
|
||||
WildflyDeployable deployable = new WildflyDeployable();
|
||||
deployable.id = artifact.getProperty("id", null);
|
||||
deployable.version = artifact.getProperty("version", null);
|
||||
deployable.type = type;
|
||||
return deployable;
|
||||
} else {
|
||||
WildflyModule module = new WildflyModule();
|
||||
module.id = artifact.getProperty("id", null);
|
||||
module.version = artifact.getProperty("version", null);
|
||||
module.exportMetaInf = artifact.getProperty("exportMetaInf", null);
|
||||
module.exportServices = artifact.getProperty("exportServices", null);
|
||||
module.exportAnnotations = Boolean.parseBoolean(artifact.getProperty("exportAnnotations", Boolean.FALSE.toString()));
|
||||
module.isSystem = Boolean.parseBoolean(artifact.getProperty("isSystem", Boolean.FALSE.toString()));
|
||||
return module;
|
||||
}
|
||||
}
|
||||
|
||||
DefaultModelBuildingRequest modelBuildRequest = new DefaultModelBuildingRequest(this.modelBuildRequestTemplate);
|
||||
|
||||
// need to go after the artifact as there could be a classifier
|
||||
Artifact pomArtifact = new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), "pom", artifact.getVersion());
|
||||
ArtifactRequest artifactRequest = new ArtifactRequest(pomArtifact, this.dac.getMavenProject().getRemoteProjectRepositories(), null);
|
||||
try {
|
||||
ArtifactResult artifactResult = this.dac.getArtifactResolver().resolveArtifact(this.dac.getMavenSession().getRepositorySession(), artifactRequest);
|
||||
if (this.getLog().isDebugEnabled())
|
||||
this.getLog().debug("Found artifact classifier POM [" + artifact + "]: " + artifactResult.getArtifact().getFile());
|
||||
modelBuildRequest.setPomFile(artifactResult.getArtifact().getFile());
|
||||
} catch (ArtifactResolutionException are) {
|
||||
if (this.getLog().isDebugEnabled())
|
||||
this.getLog().debug("There is no artifact classifier POM [" + artifact + "]: " + are.getMessage());
|
||||
|
||||
ModelSource source = this.dac.getProjectModelResolver().resolveModel(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion());
|
||||
if (this.getLog().isDebugEnabled())
|
||||
this.getLog().debug("Found artifact POM [" + artifact + "]: " + source.getLocation());
|
||||
|
||||
modelBuildRequest.setModelResolver(this.dac.getProjectModelResolver());
|
||||
modelBuildRequest.setModelSource(source);
|
||||
}
|
||||
|
||||
ModelBuildingResult result = this.dac.getModelBuilder().build(modelBuildRequest);
|
||||
if (this.getLog().isDebugEnabled())
|
||||
this.getLog().debug("Parsed artifact POM [" + artifact + "]: " + result.getModelIds());
|
||||
|
||||
Model model = result.getEffectiveModel();
|
||||
if (this.getLog().isDebugEnabled())
|
||||
this.getLog().debug("Formulated artifact effective POM [" + artifact + "]: " + model.getId());
|
||||
|
||||
if (!"client".equals(artifact.getClassifier())) {
|
||||
switch (model.getPackaging().toLowerCase()) {
|
||||
case "ear":
|
||||
case "war":
|
||||
case "ejb":
|
||||
this.getLog().debug("Discovered deployable artifact [" + artifact + "]: " + model.getId());
|
||||
|
||||
WildflyDeployable deployable = new WildflyDeployable();
|
||||
deployable.id = artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getClassifier();
|
||||
deployable.version = artifact.getVersion();
|
||||
deployable.type = model.getPackaging();
|
||||
|
||||
Map<String, String> props = new HashMap<>();
|
||||
props.put("id", deployable.id);
|
||||
props.put("version", deployable.version);
|
||||
props.put("type", deployable.type);
|
||||
artifact.setProperties(props);
|
||||
|
||||
return deployable;
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
Properties modelProps = model.getProperties();
|
||||
String moduleId = modelProps.getProperty("wildfly.module.id");
|
||||
if (moduleId == null) {
|
||||
if (this.getLog().isDebugEnabled())
|
||||
this.getLog().debug("No 'wildfly.module.id' property; not a Wildfly module project; adding as module resource: " + artifact);
|
||||
return null;
|
||||
} else {
|
||||
this.getLog().debug("Discovered module artifact [" + artifact + "]: " + model.getId());
|
||||
String moduleVersion = StringUtils.trimToNull(modelProps.getProperty("wildfly.module.version"));
|
||||
|
||||
WildflyModule module = new WildflyModule();
|
||||
module.id = moduleId;
|
||||
module.version = moduleVersion;
|
||||
module.exportMetaInf = modelProps.getProperty("wildfly.module.meta");
|
||||
module.exportServices = modelProps.getProperty("wildfly.module.services");
|
||||
module.exportAnnotations = Boolean.parseBoolean(modelProps.getProperty("wildfly.module.annotations"));
|
||||
module.isSystem = Boolean.parseBoolean(modelProps.getProperty("wildfly.module.system"));
|
||||
|
||||
// for backward compatibility
|
||||
if ("true".equalsIgnoreCase(module.exportMetaInf))
|
||||
module.exportMetaInf = "export";
|
||||
|
||||
Map<String, String> props = new HashMap<>();
|
||||
props.put("id", module.id);
|
||||
props.put("version", module.version);
|
||||
props.put("exportMetaInf", String.valueOf(module.exportMetaInf));
|
||||
props.put("exportServices", module.exportServices);
|
||||
props.put("exportAnnotations", String.valueOf(module.exportAnnotations));
|
||||
props.put("isSystem", String.valueOf(module.isSystem));
|
||||
artifact.setProperties(props);
|
||||
|
||||
return module;
|
||||
}
|
||||
}
|
||||
|
||||
private Log getLog() {
|
||||
return this.dac.getLog();
|
||||
}
|
||||
|
||||
}
|
@@ -14,19 +14,8 @@
|
||||
*/
|
||||
package com.inteligr8.wildfly.maven.goal;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.FileVisitResult;
|
||||
import java.nio.file.FileVisitor;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugins.annotations.Parameter;
|
||||
|
||||
/**
|
||||
@@ -37,81 +26,15 @@ public abstract class AbstractDeploymentGoal extends AbstractGoal {
|
||||
@Parameter( required = true, defaultValue = "1.3" )
|
||||
protected String deploymentSchemaVersion;
|
||||
|
||||
@Parameter( property = "wildfly.deployment.outputDirectory", required = true, defaultValue = "${project.build.directory}/${project.build.finalName}" )
|
||||
protected File outputDirectory;
|
||||
|
||||
@Parameter( property = "wildfly.deployment.packaging", required = true, defaultValue = "${project.packaging}" )
|
||||
protected String packaging;
|
||||
|
||||
protected File validateAndInitializeDirectory(String extraPath) {
|
||||
File directory = this.validateAndInitializeDirectory(this.outputDirectory);
|
||||
|
||||
File extraDirectory = new File(directory, extraPath);
|
||||
if (extraDirectory.exists() && !extraDirectory.isDirectory())
|
||||
throw new IllegalStateException("The formulated directory is a file: " + extraDirectory);
|
||||
|
||||
extraDirectory.mkdirs();
|
||||
return extraDirectory;
|
||||
return this.directoryAccessor.validateAndInitializeDirectory(this.outputDirectory, extraPath);
|
||||
}
|
||||
|
||||
protected void writePackage(String ext) throws MojoExecutionException {
|
||||
File zipfile = new File(this.project.getBuild().getDirectory(), this.project.getBuild().getFinalName() + "." + ext);
|
||||
try {
|
||||
FileOutputStream fostream = new FileOutputStream(zipfile);
|
||||
try {
|
||||
BufferedOutputStream bostream = new BufferedOutputStream(fostream);
|
||||
ZipOutputStream zostream = new ZipOutputStream(bostream);
|
||||
try {
|
||||
this.zipModule(zostream);
|
||||
} finally {
|
||||
zostream.close();
|
||||
}
|
||||
} finally {
|
||||
fostream.close();
|
||||
}
|
||||
} catch (IOException ie) {
|
||||
throw new MojoExecutionException("An I/O issue occurred", ie);
|
||||
}
|
||||
|
||||
this.project.getArtifact().setFile(zipfile);
|
||||
}
|
||||
|
||||
private void zipModule(ZipOutputStream zostream) throws IOException {
|
||||
Path path = this.outputDirectory.toPath();
|
||||
if (getLog().isDebugEnabled())
|
||||
getLog().debug("Zipping files in: " + path);
|
||||
|
||||
Files.walkFileTree(path, new FileVisitor<Path>() {
|
||||
@Override
|
||||
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
|
||||
if (exc == null) return FileVisitResult.CONTINUE;
|
||||
throw exc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||
Path zippath = path.relativize(file);
|
||||
if (getLog().isDebugEnabled())
|
||||
getLog().debug("Zipping file: " + zippath);
|
||||
|
||||
ZipEntry zentry = new ZipEntry(zippath.toString().replace('\\', '/'));
|
||||
zostream.putNextEntry(zentry);
|
||||
try {
|
||||
Files.copy(file, zostream);
|
||||
} finally {
|
||||
zostream.closeEntry();
|
||||
}
|
||||
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
|
||||
throw exc;
|
||||
}
|
||||
});
|
||||
|
||||
protected boolean isWebApp() {
|
||||
return "war".equals(this.packaging);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -20,6 +20,8 @@ import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.model.building.ModelBuilder;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
@@ -43,13 +45,17 @@ import org.eclipse.aether.impl.ArtifactResolver;
|
||||
import org.eclipse.aether.impl.RemoteRepositoryManager;
|
||||
import org.eclipse.aether.util.artifact.JavaScopes;
|
||||
import org.eclipse.aether.util.filter.DependencyFilterUtils;
|
||||
import org.eclipse.aether.util.filter.ScopeDependencyFilter;
|
||||
|
||||
import com.inteligr8.wildfly.maven.DependencyAwareComponent;
|
||||
import com.inteligr8.wildfly.maven.DependencyIndex;
|
||||
import com.inteligr8.wildfly.maven.IndexingDependencyGraphTransformer;
|
||||
import com.inteligr8.wildfly.maven.ModuleExclusionDependencyFilter;
|
||||
import com.inteligr8.wildfly.maven.ModuleExclusionDependencyFilter.Option;
|
||||
import com.inteligr8.wildfly.maven.ModuleProvidedDependencyFilter;
|
||||
import com.inteligr8.wildfly.maven.ValidationDependencyFilter;
|
||||
import com.inteligr8.wildfly.maven.model.Module;
|
||||
import com.inteligr8.wildfly.maven.model.WildflyModule;
|
||||
import com.inteligr8.wildfly.maven.util.DirectoryAccessor;
|
||||
|
||||
/**
|
||||
* @author brian@inteligr8.com
|
||||
@@ -61,6 +67,9 @@ public abstract class AbstractGoal extends DisablableGoal implements DependencyA
|
||||
|
||||
@Parameter( defaultValue = "${project}", readonly = true )
|
||||
protected MavenProject project;
|
||||
|
||||
@Parameter( property = "wildfly.build.outputDirectory", required = true, defaultValue = "${project.build.directory}/wildfly" )
|
||||
protected File outputDirectory;
|
||||
|
||||
@Requirement
|
||||
private RemoteRepositoryManager rrm;
|
||||
@@ -76,6 +85,9 @@ public abstract class AbstractGoal extends DisablableGoal implements DependencyA
|
||||
|
||||
@Requirement
|
||||
private ProjectDependenciesResolver depResolver;
|
||||
|
||||
@Inject
|
||||
protected DirectoryAccessor directoryAccessor;
|
||||
|
||||
protected ProjectModelResolver pomResolver;
|
||||
protected Set<String> excludeScopes = new HashSet<String>(Arrays.asList(JavaScopes.PROVIDED, JavaScopes.TEST));
|
||||
@@ -109,6 +121,10 @@ public abstract class AbstractGoal extends DisablableGoal implements DependencyA
|
||||
this.executePost();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method creates a Maven RepositorySystemSession that is able to load
|
||||
* our DependencyIndex.
|
||||
*/
|
||||
private RepositorySystemSession injectSession(DependencyIndex dindex) {
|
||||
DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(this.session.getRepositorySession());
|
||||
DependencyGraphTransformer transformer = session.getDependencyGraphTransformer();
|
||||
@@ -122,6 +138,7 @@ public abstract class AbstractGoal extends DisablableGoal implements DependencyA
|
||||
DependencyIndex dindex)
|
||||
throws MojoFailureException, MojoExecutionException {
|
||||
return this.crawlDependencies(session, Arrays.asList(
|
||||
new ScopeDependencyFilter("test"),
|
||||
new ValidationDependencyFilter(this, dindex),
|
||||
new ModuleProvidedDependencyFilter(this, dindex)));
|
||||
}
|
||||
@@ -164,19 +181,31 @@ public abstract class AbstractGoal extends DisablableGoal implements DependencyA
|
||||
case Module:
|
||||
this.handleModuleDependency(dependency, dindex.getModule(id));
|
||||
break;
|
||||
case Deployable:
|
||||
this.handleDeployableDependency(dependency);
|
||||
break;
|
||||
default:
|
||||
this.handleDependency(dependency);
|
||||
if (!"pom".equals(dependency.getArtifact().getExtension()))
|
||||
this.handleDependency(dependency);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract Collection<DependencyFilter> getDependencyFilters(DependencyIndex dindex);
|
||||
protected Collection<DependencyFilter> getDependencyFilters(DependencyIndex dindex) {
|
||||
return Arrays.asList(
|
||||
new ScopeDependencyFilter("test", "provided"),
|
||||
// this filter will remove all Wildfly Module dependencies, recursively
|
||||
new ModuleExclusionDependencyFilter(this, dindex, Option.FilterTopLevelModuleChildren));
|
||||
}
|
||||
|
||||
protected abstract void executePre() throws MojoExecutionException, MojoFailureException;
|
||||
|
||||
protected abstract void handleDependency(Dependency dependency) throws MojoExecutionException, MojoFailureException;
|
||||
|
||||
protected void handleDeployableDependency(Dependency dependency) throws MojoExecutionException, MojoFailureException {
|
||||
}
|
||||
|
||||
protected abstract void handleModuleDependency(Dependency dependency, Module moduleId) throws MojoExecutionException, MojoFailureException;
|
||||
protected abstract void handleModuleDependency(Dependency dependency, WildflyModule moduleId) throws MojoExecutionException, MojoFailureException;
|
||||
|
||||
protected abstract void executePost() throws MojoExecutionException, MojoFailureException;
|
||||
|
||||
@@ -199,13 +228,10 @@ public abstract class AbstractGoal extends DisablableGoal implements DependencyA
|
||||
public ModelBuilder getModelBuilder() {
|
||||
return this.pomBuilder;
|
||||
}
|
||||
|
||||
protected File validateAndInitializeDirectory(File directory) {
|
||||
if (directory.exists() && !directory.isDirectory())
|
||||
throw new IllegalArgumentException("A directory was expected: " + directory);
|
||||
|
||||
directory.mkdirs();
|
||||
return directory;
|
||||
|
||||
@Override
|
||||
public ArtifactResolver getArtifactResolver() {
|
||||
return artifactResolver;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -32,24 +32,8 @@ public abstract class AbstractModuleGoal extends AbstractGoal {
|
||||
@Parameter( property = "wildfly.module.version", required = true, defaultValue = "main" )
|
||||
protected String moduleVersion;
|
||||
|
||||
@Parameter( property = "wildfly.module.outputDirectory", required = true, defaultValue = "${project.build.directory}/wildfly-module" )
|
||||
protected File outputDirectory;
|
||||
|
||||
protected File validateAndInitializeDirectory() {
|
||||
File directory = this.validateAndInitializeDirectory(this.outputDirectory);
|
||||
|
||||
for (String dir : this.moduleId.split("\\.")) {
|
||||
directory = new File(directory, dir);
|
||||
if (directory.exists() && !directory.isDirectory())
|
||||
throw new IllegalStateException("The formulated directory contains a file: " + directory);
|
||||
}
|
||||
|
||||
File versionDirectory = new File(directory, this.moduleVersion);
|
||||
if (versionDirectory.exists() && !versionDirectory.isDirectory())
|
||||
throw new IllegalStateException("The formulated directory contains a file: " + directory);
|
||||
|
||||
versionDirectory.mkdirs();
|
||||
return versionDirectory;
|
||||
return this.directoryAccessor.validateAndInitializeDirectory(this.outputDirectory, this.moduleId, this.moduleVersion);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.inteligr8.wildfly.maven.goal;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugins.annotations.LifecyclePhase;
|
||||
import org.apache.maven.plugins.annotations.Mojo;
|
||||
import org.apache.maven.plugins.annotations.Parameter;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
import org.codehaus.plexus.util.FileUtils;
|
||||
import org.eclipse.aether.graph.Dependency;
|
||||
|
||||
import com.inteligr8.wildfly.maven.model.WildflyModule;
|
||||
|
||||
/**
|
||||
* @author brian@inteligr8.com
|
||||
*/
|
||||
@Mojo( name = "deployment-copy-dependencies", threadSafe = false, defaultPhase = LifecyclePhase.PREPARE_PACKAGE )
|
||||
@Component( role = org.apache.maven.plugin.Mojo.class )
|
||||
public class CopyDeploymentResourcesGoal extends AbstractDeploymentGoal {
|
||||
|
||||
@Parameter( property = "wildfly.deployment.ear.libPath", required = true, defaultValue = "lib" )
|
||||
protected String libPath;
|
||||
|
||||
private File libDirectory;
|
||||
|
||||
private List<String> manifestClassPath = new LinkedList<>();
|
||||
|
||||
@Override
|
||||
protected void executePre() throws MojoExecutionException {
|
||||
if (this.isWebApp()) {
|
||||
File webinfDirectory = this.directoryAccessor.validateAndInitializeDirectory(this.outputDirectory, "WEB-INF");
|
||||
this.libDirectory = this.directoryAccessor.validateAndInitializeDirectory(webinfDirectory, "lib");
|
||||
} else {
|
||||
this.libDirectory = this.directoryAccessor.validateAndInitializeDirectory(this.outputDirectory, this.libPath);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleDependency(Dependency dependency) throws MojoExecutionException {
|
||||
try {
|
||||
FileUtils.copyFileToDirectory(dependency.getArtifact().getFile(), this.libDirectory);
|
||||
this.manifestClassPath.add(this.libPath + "/" + dependency.getArtifact().getFile().getName());
|
||||
} catch (IOException ie) {
|
||||
throw new MojoExecutionException("An I/O related issue occurred", ie);
|
||||
}
|
||||
|
||||
if (this.getLog().isInfoEnabled())
|
||||
this.getLog().info("Copied resource artifact: " + dependency.getArtifact());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleModuleDependency(Dependency dependency, WildflyModule module) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executePost() throws MojoExecutionException {
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -16,8 +16,6 @@ package com.inteligr8.wildfly.maven.goal;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugins.annotations.LifecyclePhase;
|
||||
@@ -25,38 +23,27 @@ import org.apache.maven.plugins.annotations.Mojo;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
import org.codehaus.plexus.util.FileUtils;
|
||||
import org.eclipse.aether.graph.Dependency;
|
||||
import org.eclipse.aether.graph.DependencyFilter;
|
||||
|
||||
import com.inteligr8.wildfly.maven.DependencyIndex;
|
||||
import com.inteligr8.wildfly.maven.ModuleExclusionDependencyFilter;
|
||||
import com.inteligr8.wildfly.maven.model.Module;
|
||||
import com.inteligr8.wildfly.maven.model.WildflyModule;
|
||||
|
||||
/**
|
||||
* @author brian@inteligr8.com
|
||||
*/
|
||||
@Mojo( name = "module-resources", threadSafe = false, defaultPhase = LifecyclePhase.PREPARE_PACKAGE )
|
||||
@Mojo( name = "module-copy-dependencies", threadSafe = false, defaultPhase = LifecyclePhase.PREPARE_PACKAGE )
|
||||
@Component( role = org.apache.maven.plugin.Mojo.class )
|
||||
public class CopyModuleResourcesGoal extends AbstractModuleGoal {
|
||||
|
||||
@Override
|
||||
protected Collection<DependencyFilter> getDependencyFilters(DependencyIndex dindex) {
|
||||
return Arrays.asList(
|
||||
// this filter will remove all Wildfly Module dependencies, recursively
|
||||
new ModuleExclusionDependencyFilter(this, dindex));
|
||||
}
|
||||
|
||||
private File moduleDirectory;
|
||||
|
||||
@Override
|
||||
protected void executePre() {
|
||||
this.moduleDirectory = this.validateAndInitializeDirectory();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleDependency(Dependency dependency) throws MojoExecutionException {
|
||||
File directory = this.validateAndInitializeDirectory();
|
||||
if (!directory.isDirectory())
|
||||
throw new IllegalArgumentException();
|
||||
|
||||
try {
|
||||
FileUtils.copyFileToDirectory(dependency.getArtifact().getFile(), directory);
|
||||
FileUtils.copyFileToDirectory(dependency.getArtifact().getFile(), this.moduleDirectory);
|
||||
} catch (IOException ie) {
|
||||
throw new MojoExecutionException("An I/O related issue occurred", ie);
|
||||
}
|
||||
@@ -66,11 +53,11 @@ public class CopyModuleResourcesGoal extends AbstractModuleGoal {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleModuleDependency(Dependency dependency, Module module) {
|
||||
protected void handleModuleDependency(Dependency dependency, WildflyModule module) {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executePost() {
|
||||
protected void executePost() throws MojoExecutionException {
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -16,8 +16,6 @@ package com.inteligr8.wildfly.maven.goal;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.transform.TransformerException;
|
||||
@@ -26,25 +24,18 @@ import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugins.annotations.LifecyclePhase;
|
||||
import org.apache.maven.plugins.annotations.Mojo;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
import org.codehaus.plexus.util.FileUtils;
|
||||
import org.eclipse.aether.graph.Dependency;
|
||||
import org.eclipse.aether.graph.DependencyFilter;
|
||||
|
||||
import com.inteligr8.wildfly.maven.DependencyIndex;
|
||||
import com.inteligr8.wildfly.maven.ModuleExclusionDependencyFilter;
|
||||
import com.inteligr8.wildfly.maven.ModuleExclusionDependencyFilter.Option;
|
||||
import com.inteligr8.wildfly.maven.model.Module;
|
||||
import com.inteligr8.wildfly.maven.model.WildflyModule;
|
||||
import com.inteligr8.wildfly.maven.xml.DeploymentXmlBuilder;
|
||||
|
||||
/**
|
||||
* @author brian@inteligr8.com
|
||||
*/
|
||||
@Mojo( name = "ear", threadSafe = false, defaultPhase = LifecyclePhase.PACKAGE )
|
||||
@Mojo( name = "deployment-generate-xml", threadSafe = false, defaultPhase = LifecyclePhase.GENERATE_RESOURCES )
|
||||
@Component( role = org.apache.maven.plugin.Mojo.class )
|
||||
public class EarGoal extends AbstractDeploymentGoal {
|
||||
public class GenerateDeploymentXmlGoal extends AbstractDeploymentGoal {
|
||||
|
||||
private DeploymentXmlBuilder deploymentXmlBuilder;
|
||||
private File libDirectory;
|
||||
|
||||
@Override
|
||||
protected void executePre() throws MojoExecutionException {
|
||||
@@ -53,31 +44,14 @@ public class EarGoal extends AbstractDeploymentGoal {
|
||||
} catch (ParserConfigurationException pce) {
|
||||
throw new MojoExecutionException("This should never happen", pce);
|
||||
}
|
||||
|
||||
this.libDirectory = this.validateAndInitializeDirectory("lib");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<DependencyFilter> getDependencyFilters(DependencyIndex dindex) {
|
||||
return Arrays.asList(
|
||||
// this filter will remove all Wildfly Module dependencies, recursively
|
||||
new ModuleExclusionDependencyFilter(this, dindex, Option.FilterTopLevelModuleChildren));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleDependency(Dependency dependency) throws MojoExecutionException {
|
||||
try {
|
||||
FileUtils.copyFileToDirectory(dependency.getArtifact().getFile(), this.libDirectory);
|
||||
} catch (IOException ie) {
|
||||
throw new MojoExecutionException("An I/O related issue occurred", ie);
|
||||
}
|
||||
|
||||
if (this.getLog().isInfoEnabled())
|
||||
this.getLog().info("Copied resource artifact: " + dependency.getArtifact());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleModuleDependency(Dependency dependency, Module module) {
|
||||
protected void handleModuleDependency(Dependency dependency, WildflyModule module) {
|
||||
if (this.getLog().isInfoEnabled())
|
||||
this.getLog().info("Detected module dependency; adding reference to deployment: " + dependency.getArtifact() + " => " + module.id);
|
||||
this.deploymentXmlBuilder.addDependency(module, true);
|
||||
@@ -86,11 +60,10 @@ public class EarGoal extends AbstractDeploymentGoal {
|
||||
@Override
|
||||
public void executePost() throws MojoExecutionException {
|
||||
this.writeDeploymentXml();
|
||||
this.writePackage("ear");
|
||||
}
|
||||
|
||||
private void writeDeploymentXml() throws MojoExecutionException {
|
||||
File directory = this.validateAndInitializeDirectory("META-INF");
|
||||
File directory = this.validateAndInitializeDirectory(this.isWebApp() ? "WEB-INF" : "META-INF");
|
||||
|
||||
try {
|
||||
this.deploymentXmlBuilder.writeTo(directory);
|
@@ -16,8 +16,6 @@ package com.inteligr8.wildfly.maven.goal;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.transform.TransformerException;
|
||||
@@ -26,19 +24,16 @@ import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugins.annotations.LifecyclePhase;
|
||||
import org.apache.maven.plugins.annotations.Mojo;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
import org.eclipse.aether.artifact.DefaultArtifact;
|
||||
import org.eclipse.aether.graph.Dependency;
|
||||
import org.eclipse.aether.graph.DependencyFilter;
|
||||
|
||||
import com.inteligr8.wildfly.maven.DependencyIndex;
|
||||
import com.inteligr8.wildfly.maven.ModuleExclusionDependencyFilter;
|
||||
import com.inteligr8.wildfly.maven.ModuleExclusionDependencyFilter.Option;
|
||||
import com.inteligr8.wildfly.maven.model.Module;
|
||||
import com.inteligr8.wildfly.maven.model.WildflyModule;
|
||||
import com.inteligr8.wildfly.maven.xml.ModuleXmlBuilder;
|
||||
|
||||
/**
|
||||
* @author brian@inteligr8.com
|
||||
*/
|
||||
@Mojo( name = "module-generate", threadSafe = false, defaultPhase = LifecyclePhase.GENERATE_RESOURCES )
|
||||
@Mojo( name = "module-generate-xml", threadSafe = false, defaultPhase = LifecyclePhase.GENERATE_RESOURCES )
|
||||
@Component( role = org.apache.maven.plugin.Mojo.class )
|
||||
public class GenerateModuleXmlGoal extends AbstractModuleGoal {
|
||||
|
||||
@@ -51,11 +46,9 @@ public class GenerateModuleXmlGoal extends AbstractModuleGoal {
|
||||
} catch (ParserConfigurationException pce) {
|
||||
throw new MojoExecutionException("This should never happen", pce);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<DependencyFilter> getDependencyFilters(DependencyIndex dindex) {
|
||||
return Arrays.asList(new ModuleExclusionDependencyFilter(this, dindex, Option.FilterTopLevelModuleChildren));
|
||||
|
||||
if (!"pom".equals(this.project.getPackaging()))
|
||||
this.moduleXmlBuilder.addResource(new DefaultArtifact(this.project.getArtifact().getId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -66,7 +59,7 @@ public class GenerateModuleXmlGoal extends AbstractModuleGoal {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleModuleDependency(Dependency dependency, Module module) throws MojoExecutionException {
|
||||
protected void handleModuleDependency(Dependency dependency, WildflyModule module) throws MojoExecutionException {
|
||||
if (this.getLog().isDebugEnabled())
|
||||
this.getLog().debug("Determined to be module: " + dependency.getArtifact() + " => " + module.id);
|
||||
this.moduleXmlBuilder.addDependency(module, false);
|
||||
|
@@ -1,121 +0,0 @@
|
||||
/*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.inteligr8.wildfly.maven.goal;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.FileVisitResult;
|
||||
import java.nio.file.FileVisitor;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
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.project.MavenProject;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
|
||||
/**
|
||||
* @author brian@inteligr8.com
|
||||
*/
|
||||
@Mojo( name = "module-package", threadSafe = false, defaultPhase = LifecyclePhase.PACKAGE )
|
||||
@Component( role = org.apache.maven.plugin.Mojo.class )
|
||||
public class PackageGoal extends AbstractMojo {
|
||||
|
||||
@Parameter( defaultValue = "${session}", readonly = true )
|
||||
protected MavenSession session;
|
||||
|
||||
@Parameter( defaultValue = "${project}", readonly = true )
|
||||
protected MavenProject project;
|
||||
|
||||
@Parameter( property = "wildfly.module.outputDirectory", required = true, defaultValue = "${project.build.directory}/wildfly-module" )
|
||||
protected File moduleDirectory;
|
||||
|
||||
@Override
|
||||
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||
File buildDirectory = new File(this.project.getBuild().getDirectory());
|
||||
if (!buildDirectory.exists())
|
||||
buildDirectory.mkdirs();
|
||||
|
||||
File zipfile = new File(buildDirectory, this.project.getBuild().getFinalName() + ".zip");
|
||||
try {
|
||||
FileOutputStream fostream = new FileOutputStream(zipfile);
|
||||
try {
|
||||
BufferedOutputStream bostream = new BufferedOutputStream(fostream);
|
||||
ZipOutputStream zostream = new ZipOutputStream(bostream);
|
||||
try {
|
||||
this.zipModule(zostream);
|
||||
} finally {
|
||||
zostream.close();
|
||||
}
|
||||
} finally {
|
||||
fostream.close();
|
||||
}
|
||||
} catch (IOException ie) {
|
||||
throw new MojoExecutionException("An I/O issue occurred", ie);
|
||||
}
|
||||
}
|
||||
|
||||
public void zipModule(ZipOutputStream zostream) throws IOException {
|
||||
Path path = this.moduleDirectory.toPath();
|
||||
if (getLog().isDebugEnabled())
|
||||
getLog().debug("Zipping files in: " + path);
|
||||
|
||||
Files.walkFileTree(path, new FileVisitor<Path>() {
|
||||
@Override
|
||||
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
|
||||
if (exc == null) return FileVisitResult.CONTINUE;
|
||||
throw exc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||
Path zippath = path.relativize(file);
|
||||
if (getLog().isDebugEnabled())
|
||||
getLog().debug("Zipping file: " + zippath);
|
||||
|
||||
ZipEntry zentry = new ZipEntry(zippath.toString().replace('\\', '/'));
|
||||
zostream.putNextEntry(zentry);
|
||||
try {
|
||||
Files.copy(file, zostream);
|
||||
} finally {
|
||||
zostream.closeEntry();
|
||||
}
|
||||
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
|
||||
throw exc;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,227 @@
|
||||
/*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.inteligr8.wildfly.maven.goal;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.FileVisitResult;
|
||||
import java.nio.file.FileVisitor;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.Profile;
|
||||
import org.apache.maven.model.building.DefaultModelBuildingRequest;
|
||||
import org.apache.maven.model.building.ModelBuilder;
|
||||
import org.apache.maven.model.building.ModelBuildingException;
|
||||
import org.apache.maven.model.building.ModelBuildingRequest;
|
||||
import org.apache.maven.model.building.ModelBuildingResult;
|
||||
import org.apache.maven.model.io.ModelWriter;
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
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.project.MavenProject;
|
||||
import org.apache.maven.project.MavenProjectHelper;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
import org.codehaus.plexus.util.FileUtils;
|
||||
|
||||
import com.inteligr8.wildfly.maven.util.DirectoryAccessor;
|
||||
|
||||
/**
|
||||
* @author brian@inteligr8.com
|
||||
*/
|
||||
@Mojo( name = "module-package", threadSafe = false, defaultPhase = LifecyclePhase.PACKAGE )
|
||||
@Component( role = org.apache.maven.plugin.Mojo.class )
|
||||
public class PackageModuleGoal extends AbstractMojo {
|
||||
|
||||
@Parameter( defaultValue = "${session}", readonly = true )
|
||||
protected MavenSession session;
|
||||
|
||||
@Parameter( defaultValue = "${project}", readonly = true )
|
||||
protected MavenProject project;
|
||||
|
||||
@Parameter( property = "wildfly.module.classifier", required = false )
|
||||
protected String moduleClassifier;
|
||||
|
||||
@Parameter( property = "wildfly.module.id" )
|
||||
protected String moduleId;
|
||||
|
||||
@Parameter( property = "wildfly.module.version", defaultValue = "main" )
|
||||
protected String moduleVersion;
|
||||
|
||||
@Parameter( property = "wildfly.build.outputDirectory", required = true, defaultValue = "${project.build.directory}/wildfly" )
|
||||
protected File packageDirectory;
|
||||
|
||||
@Inject
|
||||
protected DirectoryAccessor directoryAccessor;
|
||||
|
||||
@Inject
|
||||
protected MavenProjectHelper helper;
|
||||
|
||||
@Inject
|
||||
protected ModelBuilder modelBuilder;
|
||||
|
||||
@Inject
|
||||
protected ModelWriter modelWriter;
|
||||
|
||||
@Override
|
||||
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||
boolean isModuleOnly = "pom".equals(this.project.getPackaging());
|
||||
|
||||
File buildDirectory = this.directoryAccessor.validateAndInitializeDirectory(new File(this.project.getBuild().getDirectory()));
|
||||
if (!isModuleOnly) {
|
||||
if (this.moduleId == null)
|
||||
throw new MojoExecutionException("A 'moduleId' configuration or 'wildfly.module.id' property is required");
|
||||
this.addThisArtifactToModule(buildDirectory);
|
||||
}
|
||||
|
||||
if (!isModuleOnly) {
|
||||
File zipFile = this.createZip(buildDirectory, this.moduleClassifier, "zip");
|
||||
this.helper.attachArtifact(project, "zip", this.moduleClassifier, zipFile);
|
||||
|
||||
File file = this.createModulePom(buildDirectory);
|
||||
this.helper.attachArtifact(project, "pom", this.moduleClassifier, file);
|
||||
} else {
|
||||
this.createZip(buildDirectory, "zip");
|
||||
}
|
||||
}
|
||||
|
||||
private void addThisArtifactToModule(File buildDirectory) throws MojoExecutionException {
|
||||
File packageDirectory = this.directoryAccessor.validateAndInitializeDirectory(this.packageDirectory, this.moduleId, this.moduleVersion);
|
||||
File file = new File(buildDirectory, this.project.getBuild().getFinalName() + "." + this.project.getPackaging());
|
||||
|
||||
try {
|
||||
FileUtils.copyFileToDirectory(file, packageDirectory);
|
||||
} catch (IOException ie) {
|
||||
throw new MojoExecutionException("An I/O related issue occurred", ie);
|
||||
}
|
||||
|
||||
if (this.getLog().isInfoEnabled())
|
||||
this.getLog().info("Copied artifact: " + this.project.getArtifact().getId());
|
||||
}
|
||||
|
||||
private File createZip(File buildDirectory, String ext) throws MojoExecutionException {
|
||||
File zipfile = new File(buildDirectory, this.project.getBuild().getFinalName() + "." + ext);
|
||||
this.createZip(buildDirectory, zipfile);
|
||||
return zipfile;
|
||||
}
|
||||
|
||||
private File createZip(File buildDirectory, String classifier, String ext) throws MojoExecutionException {
|
||||
File zipfile = new File(buildDirectory, this.project.getBuild().getFinalName() + "-" + classifier + "." + ext);
|
||||
this.createZip(buildDirectory, zipfile);
|
||||
return zipfile;
|
||||
}
|
||||
|
||||
private void createZip(File buildDirectory, File zipfile) throws MojoExecutionException {
|
||||
try {
|
||||
FileOutputStream fostream = new FileOutputStream(zipfile);
|
||||
try {
|
||||
BufferedOutputStream bostream = new BufferedOutputStream(fostream);
|
||||
ZipOutputStream zostream = new ZipOutputStream(bostream);
|
||||
try {
|
||||
this.zipModule(zostream);
|
||||
} finally {
|
||||
zostream.close();
|
||||
}
|
||||
} finally {
|
||||
fostream.close();
|
||||
}
|
||||
} catch (IOException ie) {
|
||||
throw new MojoExecutionException("An I/O issue occurred", ie);
|
||||
}
|
||||
}
|
||||
|
||||
private void zipModule(ZipOutputStream zostream) throws IOException {
|
||||
Path path = this.packageDirectory.toPath();
|
||||
if (getLog().isDebugEnabled())
|
||||
getLog().debug("Zipping files in: " + path);
|
||||
|
||||
Files.walkFileTree(path, new FileVisitor<Path>() {
|
||||
@Override
|
||||
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
|
||||
if (exc == null) return FileVisitResult.CONTINUE;
|
||||
throw exc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||
Path zippath = path.relativize(file);
|
||||
if (getLog().isDebugEnabled())
|
||||
getLog().debug("Zipping file: " + zippath);
|
||||
|
||||
ZipEntry zentry = new ZipEntry(zippath.toString().replace('\\', '/'));
|
||||
zostream.putNextEntry(zentry);
|
||||
try {
|
||||
Files.copy(file, zostream);
|
||||
} finally {
|
||||
zostream.closeEntry();
|
||||
}
|
||||
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
|
||||
throw exc;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private File createModulePom(File buildDirectory) throws MojoExecutionException {
|
||||
ModelBuildingRequest request = new DefaultModelBuildingRequest()
|
||||
.setPomFile(this.project.getFile())
|
||||
.setActiveProfileIds(this.getProfileIds(this.project.getActiveProfiles()));
|
||||
try {
|
||||
ModelBuildingResult result = this.modelBuilder.build(request);
|
||||
Model model = result.getEffectiveModel();
|
||||
model.setPackaging("pom");
|
||||
|
||||
File modulePomFile = new File(buildDirectory, this.project.getBuild().getFinalName() + "-" + moduleClassifier + ".xml");
|
||||
this.modelWriter.write(modulePomFile, null, model);
|
||||
return modulePomFile;
|
||||
} catch (ModelBuildingException mbe) {
|
||||
throw new MojoExecutionException("The module POM failed to generate", mbe);
|
||||
} catch (IOException io) {
|
||||
throw new MojoExecutionException("An I/O issue occurred", io);
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> getProfileIds(Collection<Profile> profiles) {
|
||||
List<String> ids = new ArrayList<>(profiles.size());
|
||||
for (Profile profile : profiles)
|
||||
ids.add(profile.getId());
|
||||
return ids;
|
||||
}
|
||||
|
||||
}
|
@@ -1,155 +0,0 @@
|
||||
/*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.inteligr8.wildfly.maven.goal;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.transform.TransformerException;
|
||||
|
||||
import org.apache.maven.model.Resource;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
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.shared.filtering.MavenFilteringException;
|
||||
import org.apache.maven.shared.filtering.MavenResourcesExecution;
|
||||
import org.apache.maven.shared.filtering.MavenResourcesFiltering;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
import org.codehaus.plexus.component.annotations.Requirement;
|
||||
import org.codehaus.plexus.util.FileUtils;
|
||||
import org.eclipse.aether.graph.Dependency;
|
||||
import org.eclipse.aether.graph.DependencyFilter;
|
||||
|
||||
import com.inteligr8.wildfly.maven.DependencyIndex;
|
||||
import com.inteligr8.wildfly.maven.ModuleExclusionDependencyFilter;
|
||||
import com.inteligr8.wildfly.maven.ModuleExclusionDependencyFilter.Option;
|
||||
import com.inteligr8.wildfly.maven.model.Module;
|
||||
import com.inteligr8.wildfly.maven.xml.DeploymentXmlBuilder;
|
||||
|
||||
/**
|
||||
* @author brian@inteligr8.com
|
||||
*/
|
||||
@Mojo( name = "war", threadSafe = false, defaultPhase = LifecyclePhase.PACKAGE )
|
||||
@Component( role = org.apache.maven.plugin.Mojo.class )
|
||||
public class WarGoal extends AbstractDeploymentGoal {
|
||||
|
||||
@Parameter( property = "wildfly.webapp.directory", required = true, defaultValue = "${basedir}/src/main/webapp" )
|
||||
protected File webappDirectory;
|
||||
|
||||
@Parameter
|
||||
protected List<Resource> resources;
|
||||
|
||||
@Requirement
|
||||
private MavenResourcesFiltering filterer;
|
||||
|
||||
private DeploymentXmlBuilder deploymentXmlBuilder;
|
||||
private File webinfDirectory;
|
||||
private File libDirectory;
|
||||
|
||||
@Override
|
||||
protected void executePre() throws MojoExecutionException {
|
||||
try {
|
||||
this.deploymentXmlBuilder = new DeploymentXmlBuilder(this.deploymentSchemaVersion);
|
||||
} catch (ParserConfigurationException pce) {
|
||||
throw new MojoExecutionException("This should never happen", pce);
|
||||
}
|
||||
|
||||
this.webinfDirectory = this.validateAndInitializeDirectory("WEB-INF");
|
||||
this.libDirectory = new File(this.webinfDirectory, "lib");
|
||||
if (this.libDirectory.exists() && !this.libDirectory.isDirectory())
|
||||
throw new IllegalStateException("The formulated directory is a file: " + this.libDirectory);
|
||||
this.libDirectory.mkdirs();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<DependencyFilter> getDependencyFilters(DependencyIndex dindex) {
|
||||
return Arrays.asList(
|
||||
// this filter will remove all Wildfly Module dependencies, recursively
|
||||
new ModuleExclusionDependencyFilter(this, dindex, Option.FilterTopLevelModuleChildren));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleDependency(Dependency dependency) throws MojoExecutionException {
|
||||
try {
|
||||
FileUtils.copyFileToDirectory(dependency.getArtifact().getFile(), this.libDirectory);
|
||||
} catch (IOException ie) {
|
||||
throw new MojoExecutionException("An I/O related issue occurred", ie);
|
||||
}
|
||||
|
||||
if (this.getLog().isInfoEnabled())
|
||||
this.getLog().info("Copied resource artifact: " + dependency.getArtifact());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleModuleDependency(Dependency dependency, Module module) {
|
||||
if (this.getLog().isInfoEnabled())
|
||||
this.getLog().info("Detected module dependency; adding reference to deployment: " + dependency.getArtifact() + " => " + module.id);
|
||||
this.deploymentXmlBuilder.addDependency(module, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executePost() throws MojoExecutionException {
|
||||
this.writeDeploymentXml();
|
||||
this.copyResources();
|
||||
this.writePackage("war");
|
||||
}
|
||||
|
||||
private void writeDeploymentXml() throws MojoExecutionException {
|
||||
try {
|
||||
this.deploymentXmlBuilder.writeTo(this.webinfDirectory);
|
||||
} catch (TransformerException te) {
|
||||
throw new MojoExecutionException("An XML to file transformation issue occurred", te);
|
||||
} catch (IOException ie) {
|
||||
throw new MojoExecutionException("An I/O issue occurred", ie);
|
||||
}
|
||||
}
|
||||
|
||||
private void copyResources() throws MojoExecutionException {
|
||||
try {
|
||||
File classesSourceDirectory = new File(this.project.getBuild().getOutputDirectory());
|
||||
if (classesSourceDirectory.exists()) {
|
||||
File classesTargetDirectory = new File(this.webinfDirectory, "classes");
|
||||
classesTargetDirectory.mkdirs();
|
||||
FileUtils.copyDirectoryStructure(classesSourceDirectory, classesTargetDirectory);
|
||||
}
|
||||
|
||||
if (this.resources != null) {
|
||||
MavenResourcesExecution execution = new MavenResourcesExecution(
|
||||
this.resources,
|
||||
this.outputDirectory,
|
||||
this.project,
|
||||
"utf-8",
|
||||
Collections.emptyList(),
|
||||
this.filterer.getDefaultNonFilteredFileExtensions(),
|
||||
this.session);
|
||||
this.filterer.filterResources(execution);
|
||||
}
|
||||
|
||||
if (this.webappDirectory.exists())
|
||||
FileUtils.copyDirectoryStructure(this.webappDirectory, this.outputDirectory);
|
||||
} catch (MavenFilteringException mfe) {
|
||||
throw new MojoExecutionException("A filtering issue occurred", mfe);
|
||||
} catch (IOException ie) {
|
||||
throw new MojoExecutionException("An I/O issue occurred", ie);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.inteligr8.wildfly.maven.model;
|
||||
|
||||
public class WildflyArtifact {
|
||||
|
||||
public String id;
|
||||
public String version;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof WildflyArtifact))
|
||||
return false;
|
||||
WildflyArtifact artifact = (WildflyArtifact) obj;
|
||||
return this.id.equals(artifact.id);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.inteligr8.wildfly.maven.model;
|
||||
|
||||
public class WildflyDeployable extends WildflyArtifact {
|
||||
|
||||
public String type;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof WildflyDeployable))
|
||||
return false;
|
||||
return super.equals(obj);
|
||||
}
|
||||
|
||||
}
|
@@ -14,15 +14,20 @@
|
||||
*/
|
||||
package com.inteligr8.wildfly.maven.model;
|
||||
|
||||
public class Module {
|
||||
public class WildflyModule extends WildflyArtifact {
|
||||
|
||||
public String id;
|
||||
public String version;
|
||||
public boolean export;
|
||||
public boolean exportMetaInf;
|
||||
public boolean exportServices;
|
||||
public String exportMetaInf;
|
||||
public String exportServices;
|
||||
public boolean exportAnnotations;
|
||||
public boolean exportOptional;
|
||||
public boolean isSystem;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof WildflyModule))
|
||||
return false;
|
||||
return super.equals(obj);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,46 @@
|
||||
package com.inteligr8.wildfly.maven.util;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
@Singleton
|
||||
public class DirectoryAccessor {
|
||||
|
||||
public File validateAndInitializeDirectory(File directory) {
|
||||
if (directory.exists() && !directory.isDirectory())
|
||||
throw new IllegalArgumentException("A directory was expected: " + directory);
|
||||
|
||||
directory.mkdirs();
|
||||
return directory;
|
||||
}
|
||||
|
||||
public File validateAndInitializeDirectory(File directory, String extraPath) {
|
||||
directory = this.validateAndInitializeDirectory(directory);
|
||||
|
||||
File extraDirectory = new File(directory, extraPath);
|
||||
if (extraDirectory.exists() && !extraDirectory.isDirectory())
|
||||
throw new IllegalStateException("The formulated directory is a file: " + extraDirectory);
|
||||
|
||||
extraDirectory.mkdirs();
|
||||
return extraDirectory;
|
||||
}
|
||||
|
||||
public File validateAndInitializeDirectory(File directory, String moduleId, String moduleVersion) {
|
||||
directory = this.validateAndInitializeDirectory(directory);
|
||||
|
||||
for (String dir : moduleId.split("\\.")) {
|
||||
directory = new File(directory, dir);
|
||||
if (directory.exists() && !directory.isDirectory())
|
||||
throw new IllegalStateException("The formulated directory contains a file: " + directory);
|
||||
}
|
||||
|
||||
File versionDirectory = new File(directory, moduleVersion);
|
||||
if (versionDirectory.exists() && !versionDirectory.isDirectory())
|
||||
throw new IllegalStateException("The formulated directory contains a file: " + directory);
|
||||
|
||||
versionDirectory.mkdirs();
|
||||
return versionDirectory;
|
||||
}
|
||||
|
||||
}
|
@@ -32,7 +32,7 @@ import javax.xml.transform.stream.StreamResult;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import com.inteligr8.wildfly.maven.model.Module;
|
||||
import com.inteligr8.wildfly.maven.model.WildflyModule;
|
||||
|
||||
public abstract class AbstractXmlBuilder {
|
||||
|
||||
@@ -55,7 +55,7 @@ public abstract class AbstractXmlBuilder {
|
||||
|
||||
public abstract String getXmlFilename();
|
||||
|
||||
public void addDependency(Module module, boolean isDeployment) {
|
||||
public void addDependency(WildflyModule module, boolean isDeployment) {
|
||||
String name = module.id;
|
||||
if (!this.enableSlotAttribute && module.version != null && !module.version.equals("main"))
|
||||
name += ":" + module.version;
|
||||
@@ -66,12 +66,12 @@ public abstract class AbstractXmlBuilder {
|
||||
moduleElement.setAttribute("slot", module.version);
|
||||
if (module.export)
|
||||
moduleElement.setAttribute("export", Boolean.TRUE.toString());
|
||||
if (isDeployment && module.exportMetaInf)
|
||||
moduleElement.setAttribute("meta-inf", "export");
|
||||
if (module.exportServices)
|
||||
moduleElement.setAttribute("services", "export");
|
||||
if (isDeployment && module.exportMetaInf != null)
|
||||
moduleElement.setAttribute("meta-inf", module.exportMetaInf);
|
||||
if (module.exportServices != null)
|
||||
moduleElement.setAttribute("services", module.exportServices);
|
||||
if (isDeployment && module.exportAnnotations)
|
||||
moduleElement.setAttribute("annotations", "export");
|
||||
moduleElement.setAttribute("annotations", Boolean.TRUE.toString());
|
||||
this.dependenciesElement.appendChild(moduleElement);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user