Skip to content
Browse files

Added Maven plugin support

  • Loading branch information...
1 parent 6c47fa7 commit 61db777b90c4a6c1e2edc7e43dfab1d40641b262 @gastaldi gastaldi committed Apr 9, 2013
Showing with 1,965 additions and 0 deletions.
  1. +50 −0 maven/api/src/main/java/org/jboss/forge/maven/plugins/Configuration.java
  2. +108 −0 maven/api/src/main/java/org/jboss/forge/maven/plugins/ConfigurationBuilder.java
  3. +103 −0 maven/api/src/main/java/org/jboss/forge/maven/plugins/ConfigurationElement.java
  4. +212 −0 maven/api/src/main/java/org/jboss/forge/maven/plugins/ConfigurationElementBuilder.java
  5. +201 −0 maven/api/src/main/java/org/jboss/forge/maven/plugins/ConfigurationElementImpl.java
  6. +18 −0 maven/api/src/main/java/org/jboss/forge/maven/plugins/ConfigurationElementNotFoundException.java
  7. +21 −0 maven/api/src/main/java/org/jboss/forge/maven/plugins/ConfigurationException.java
  8. +136 −0 maven/api/src/main/java/org/jboss/forge/maven/plugins/ConfigurationImpl.java
  9. +17 −0 maven/api/src/main/java/org/jboss/forge/maven/plugins/Execution.java
  10. +70 −0 maven/api/src/main/java/org/jboss/forge/maven/plugins/ExecutionBuilder.java
  11. +69 −0 maven/api/src/main/java/org/jboss/forge/maven/plugins/ExecutionImpl.java
  12. +32 −0 maven/api/src/main/java/org/jboss/forge/maven/plugins/MavenPlugin.java
  13. +186 −0 maven/api/src/main/java/org/jboss/forge/maven/plugins/MavenPluginAdapter.java
  14. +127 −0 maven/api/src/main/java/org/jboss/forge/maven/plugins/MavenPluginBuilder.java
  15. +178 −0 maven/api/src/main/java/org/jboss/forge/maven/plugins/MavenPluginImpl.java
  16. +15 −0 maven/api/src/main/java/org/jboss/forge/maven/plugins/PluginElement.java
  17. +69 −0 maven/api/src/main/java/org/jboss/forge/maven/projects/MavenPluginFacet.java
  18. +353 −0 maven/impl-projects/src/main/java/org/jboss/forge/maven/projects/MavenPluginFacetImpl.java
View
50 maven/api/src/main/java/org/jboss/forge/maven/plugins/Configuration.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2012 Red Hat, Inc. and/or its affiliates.
+ *
+ * Licensed under the Eclipse Public License version 1.0, available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.jboss.forge.maven.plugins;
+
+import java.util.List;
+
+/**
+ * A Maven plugin Configuration object.
+ *
+ * @author <a href="mailto:paul.bakker.nl@gmail.com">Paul Bakker</a>
+ */
+public interface Configuration extends PluginElement
+{
+ /**
+ * Return true if this {@link Configuration} has any elements; otherwise, return false.
+ */
+ boolean hasConfigurationElements();
+
+ /**
+ * Return true if this {@link Configuration} contains the given element; otherwise, return false;
+ */
+ boolean hasConfigurationElement(String element);
+
+ /**
+ * Get the specified {@link ConfigurationElement}, if it exists; otherwise, return null.
+ */
+ ConfigurationElement getConfigurationElement(String element);
+
+ /**
+ * List all {@link ConfigurationElement}s contained in this {@link Configuration}. Returns an empty list if none
+ * exist.
+ */
+ List<ConfigurationElement> listConfigurationElements();
+
+ /**
+ * Add a {@link ConfigurationElement} to this {@link Configuration}.
+ */
+ Configuration addConfigurationElement(ConfigurationElement element);
+
+ /**
+ * Remove the specified {@link ConfigurationElement}.
+ */
+ void removeConfigurationElement(String elementName);
+
+}
View
108 maven/api/src/main/java/org/jboss/forge/maven/plugins/ConfigurationBuilder.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright 2012 Red Hat, Inc. and/or its affiliates.
+ *
+ * Licensed under the Eclipse Public License version 1.0, available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.jboss.forge.maven.plugins;
+
+import java.util.List;
+
+/**
+ * @author <a href="mailto:paul.bakker.nl@gmail.com">Paul Bakker</a>
+ */
+public class ConfigurationBuilder implements Configuration
+{
+ private final ConfigurationImpl mavenPluginConfiguration = new ConfigurationImpl();
+ private MavenPluginBuilder origin;
+
+ @Override
+ public ConfigurationElement getConfigurationElement(final String element)
+ {
+ return mavenPluginConfiguration.getConfigurationElement(element);
+ }
+
+ @Override
+ public boolean hasConfigurationElement(final String configElement)
+ {
+ return mavenPluginConfiguration.hasConfigurationElement(configElement);
+ }
+
+ @Override
+ public boolean hasConfigurationElements()
+ {
+ return mavenPluginConfiguration.hasConfigurationElements();
+ }
+
+ @Override
+ public List<ConfigurationElement> listConfigurationElements()
+ {
+ return mavenPluginConfiguration.listConfigurationElements();
+ }
+
+ @Override
+ public Configuration addConfigurationElement(final ConfigurationElement element)
+ {
+ return mavenPluginConfiguration.addConfigurationElement(element);
+ }
+
+ @Override
+ public void removeConfigurationElement(final String elementName)
+ {
+ mavenPluginConfiguration.removeConfigurationElement(elementName);
+ }
+
+ @Override
+ public String toString()
+ {
+ return mavenPluginConfiguration.toString();
+ }
+
+ private ConfigurationBuilder()
+ {
+
+ }
+
+ public ConfigurationElementBuilder createConfigurationElement(final String name)
+ {
+ ConfigurationElementBuilder builder = ConfigurationElementBuilder.create(this);
+ builder.setName(name);
+ mavenPluginConfiguration.addConfigurationElement(builder);
+ return builder;
+ }
+
+ private ConfigurationBuilder(final MavenPluginBuilder pluginBuilder)
+ {
+ origin = pluginBuilder;
+ }
+
+ private ConfigurationBuilder(final Configuration existingConfig, final MavenPluginBuilder pluginBuilder)
+ {
+ origin = pluginBuilder;
+ for (ConfigurationElement element : existingConfig.listConfigurationElements())
+ {
+ mavenPluginConfiguration.addConfigurationElement(element);
+ }
+ }
+
+ public static ConfigurationBuilder create()
+ {
+ return new ConfigurationBuilder();
+ }
+
+ public static ConfigurationBuilder create(final MavenPluginBuilder pluginBuilder)
+ {
+ return new ConfigurationBuilder(pluginBuilder);
+ }
+
+ public static ConfigurationBuilder create(final Configuration existingConfig, final MavenPluginBuilder pluginBuilder)
+ {
+ return new ConfigurationBuilder(existingConfig, pluginBuilder);
+ }
+
+ public MavenPluginBuilder getOrigin()
+ {
+ return origin;
+ }
+}
View
103 maven/api/src/main/java/org/jboss/forge/maven/plugins/ConfigurationElement.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2012 Red Hat, Inc. and/or its affiliates.
+ *
+ * Licensed under the Eclipse Public License version 1.0, available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.jboss.forge.maven.plugins;
+
+import java.util.List;
+
+/**
+ * @author <a href="mailto:paul.bakker.nl@gmail.com">Paul Bakker</a>
+ */
+public interface ConfigurationElement extends PluginElement
+{
+ String getName();
+
+ boolean isPlugin();
+
+ boolean hasChilderen();
+
+ String getText();
+
+ List<PluginElement> getChildren();
+
+ /**
+ * Checks if a child element is present with the given content.
+ *
+ * @param content The content to filter on.
+ * @param directChildsOnly True if only direct elements should be matched
+ * @return True if an element was found containing the given content
+ */
+ boolean hasChildByContent(String content, boolean directChildsOnly);
+
+ /**
+ * Checks if a child element is present with the given content. Also search indirect child elements.
+ *
+ * @param content The content to filter on.
+ * @return True if an element was found containing the given content
+ * @see ConfigurationElement#hasChildByContent(String, boolean)
+ */
+ boolean hasChildByContent(String content);
+
+ /**
+ * Returns the child element that contains the given content.
+ *
+ * @param content The content to filter on.
+ * @param directChildsOnly True if only direct elements should be matched
+ * @return The element found, or raises an {@link ConfigurationElementNotFoundException} if the element was not
+ * found.
+ */
+ ConfigurationElement getChildByContent(String content, boolean directChildsOnly);
+
+ /**
+ * Returns the child element that contains the given content. Also search indirect child elements.
+ *
+ * @param content The content to filter on.
+ * @return The element found, or raises an {@link ConfigurationElementNotFoundException} if the element was not
+ * found.
+ * @see ConfigurationElement#getChildByContent(String, boolean)
+ */
+ ConfigurationElement getChildByContent(String content);
+
+ /**
+ * Checks if the child element that has the given name exists.
+ *
+ * @param name The element name to filter on.
+ * @param directChildsOnly True if only direct elements should be matched
+ * @return The element found, or raises an {@link ConfigurationElementNotFoundException} if the element was not
+ * found.
+ */
+ boolean hasChildByName(String name, boolean directChildsOnly);
+
+ /**
+ * Checks if the child element that has the given name exists. Also search indirect child elements.
+ *
+ * @param name The element name to filter on.
+ * @return The element found, or raises an {@link ConfigurationElementNotFoundException} if the element was not
+ * found.
+ */
+ boolean hasChildByName(String name);
+
+ /**
+ * Returns the child element that has the given name exists.
+ *
+ * @param name The element name to filter on.
+ * @param directChildsOnly True if only direct elements should be matched
+ * @return The element found, or raises an {@link ConfigurationElementNotFoundException} if the element was not
+ * found.
+ */
+ ConfigurationElement getChildByName(String name, boolean directChildsOnly);
+
+ /**
+ * Checks if the child element that has the given name exists. Also search indirect child elements.
+ *
+ * @param name The element name to filter on.
+ * @return The element found, or raises an {@link ConfigurationElementNotFoundException} if the element was not
+ * found.
+ */
+ ConfigurationElement getChildByName(String name);
+
+}
View
212 maven/api/src/main/java/org/jboss/forge/maven/plugins/ConfigurationElementBuilder.java
@@ -0,0 +1,212 @@
+/*
+ * Copyright 2012 Red Hat, Inc. and/or its affiliates.
+ *
+ * Licensed under the Eclipse Public License version 1.0, available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.jboss.forge.maven.plugins;
+
+import java.util.List;
+
+/**
+ * @author <a href="mailto:paul.bakker.nl@gmail.com">Paul Bakker</a>
+ */
+public class ConfigurationElementBuilder implements ConfigurationElement
+{
+ private ConfigurationElementImpl configurationElement;
+ private ConfigurationBuilder configurationBuilder;
+ private ConfigurationElementBuilder elementBuilder;
+
+ @Override
+ public String getName()
+ {
+ return configurationElement.getName();
+ }
+
+ @Override
+ public boolean isPlugin()
+ {
+ return configurationElement.isPlugin();
+ }
+
+ @Override
+ public boolean hasChilderen()
+ {
+ return configurationElement.hasChilderen();
+ }
+
+ @Override
+ public String getText()
+ {
+ return configurationElement.getText();
+ }
+
+ public ConfigurationElementBuilder setText(String text)
+ {
+ configurationElement.setText(text);
+ return this;
+ }
+
+ public ConfigurationElementBuilder addChild(String configElement)
+ {
+ ConfigurationElementBuilder builder =
+ ConfigurationElementBuilder.create(this)
+ .setName(configElement);
+ configurationElement.addChild(builder);
+ return builder;
+ }
+
+ public ConfigurationElementBuilder addChild(PluginElement element)
+ {
+ configurationElement.addChild(element);
+ return this;
+ }
+
+ public ConfigurationBuilder getParentPluginConfig()
+ {
+ return configurationBuilder;
+ }
+
+ public ConfigurationElementBuilder getParentElement()
+ {
+ return elementBuilder;
+ }
+
+ private ConfigurationElementBuilder()
+ {
+ configurationElement = new ConfigurationElementImpl();
+ }
+
+ private ConfigurationElementBuilder(ConfigurationBuilder configurationBuilder)
+ {
+ configurationElement = new ConfigurationElementImpl();
+ this.configurationBuilder = configurationBuilder;
+ }
+
+ private ConfigurationElementBuilder(ConfigurationElementBuilder elementBuilder)
+ {
+ configurationElement = new ConfigurationElementImpl();
+ this.elementBuilder = elementBuilder;
+ }
+
+ public static ConfigurationElementBuilder create()
+ {
+ return new ConfigurationElementBuilder();
+ }
+
+ public static ConfigurationElementBuilder create(ConfigurationBuilder configurationBuilder)
+ {
+ ConfigurationElementBuilder builder = new ConfigurationElementBuilder(configurationBuilder);
+ builder.configurationBuilder = configurationBuilder;
+ return builder;
+ }
+
+ public static ConfigurationElementBuilder create(ConfigurationElementBuilder elementBuilder)
+ {
+ ConfigurationElementBuilder builder = new ConfigurationElementBuilder(elementBuilder);
+ builder.elementBuilder = elementBuilder;
+ return builder;
+ }
+
+ public static ConfigurationElementBuilder createFromExisting(ConfigurationElement element)
+ {
+
+ if (element instanceof ConfigurationElementBuilder)
+ {
+ ConfigurationElementBuilder elementBuilder = (ConfigurationElementBuilder) element;
+ ConfigurationElementBuilder builder = new ConfigurationElementBuilder(elementBuilder);
+
+ builder.configurationElement.setName(element.getName());
+ builder.configurationElement.setText(element.getText());
+ builder.configurationElement.setChildren(element.getChildren());
+ return builder;
+
+ }
+ else if (element instanceof ConfigurationElementImpl)
+ {
+ ConfigurationElementBuilder builder = new ConfigurationElementBuilder();
+
+ builder.configurationElement = (ConfigurationElementImpl) element;
+ return builder;
+ }
+ else
+ {
+ throw new IllegalArgumentException("Unsupported type: " + element.getClass());
+ }
+ }
+
+ public ConfigurationElementBuilder setName(String name)
+ {
+ configurationElement.setName(name);
+ return this;
+ }
+
+ public ConfigurationElementBuilder createConfigurationElement(String name)
+ {
+ ConfigurationElementBuilder builder = ConfigurationElementBuilder.create(this);
+ builder.setName(name);
+ configurationElement.addChild(builder);
+ return builder;
+ }
+
+ @Override
+ public List<PluginElement> getChildren()
+ {
+ return configurationElement.getChildren();
+ }
+
+ @Override
+ public boolean hasChildByContent(String content, boolean directChildsOnly)
+ {
+ return configurationElement.hasChildByContent(content, directChildsOnly);
+ }
+
+ @Override
+ public boolean hasChildByContent(String content)
+ {
+ return configurationElement.hasChildByContent(content);
+ }
+
+ @Override
+ public ConfigurationElement getChildByContent(String content, boolean directChildsOnly)
+ {
+ return configurationElement.getChildByContent(content, directChildsOnly);
+ }
+
+ @Override
+ public ConfigurationElement getChildByContent(String content)
+ {
+ return configurationElement.getChildByContent(content);
+ }
+
+ @Override
+ public boolean hasChildByName(String name, boolean directChildsOnly)
+ {
+ return configurationElement.hasChildByName(name, directChildsOnly);
+ }
+
+ @Override
+ public boolean hasChildByName(String name)
+ {
+ return configurationElement.hasChildByName(name);
+ }
+
+ @Override
+ public ConfigurationElement getChildByName(String name, boolean directChildsOnly)
+ {
+ return configurationElement.getChildByName(name, directChildsOnly);
+ }
+
+ @Override
+ public ConfigurationElement getChildByName(String name)
+ {
+ return configurationElement.getChildByName(name);
+ }
+
+ @Override
+ public String toString()
+ {
+ return configurationElement.toString();
+ }
+}
View
201 maven/api/src/main/java/org/jboss/forge/maven/plugins/ConfigurationElementImpl.java
@@ -0,0 +1,201 @@
+/*
+ * Copyright 2012 Red Hat, Inc. and/or its affiliates.
+ *
+ * Licensed under the Eclipse Public License version 1.0, available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.jboss.forge.maven.plugins;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:paul.bakker.nl@gmail.com">Paul Bakker</a>
+ */
+public class ConfigurationElementImpl implements ConfigurationElement
+{
+ private String name;
+ private String text;
+ private List<PluginElement> children = new ArrayList<PluginElement>();
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ public void setText(String text)
+ {
+ this.text = text;
+ }
+
+ @Override
+ public String getName()
+ {
+ return name;
+ }
+
+ @Override
+ public boolean isPlugin()
+ {
+ return name.equals("plugin");
+ }
+
+ @Override
+ public boolean hasChilderen()
+ {
+ return children != null && children.size() > 0;
+ }
+
+ @Override
+ public String getText()
+ {
+ return text;
+ }
+
+ public void addChild(PluginElement element)
+ {
+ children.add(element);
+ }
+
+ @Override
+ public List<PluginElement> getChildren()
+ {
+ return children;
+ }
+
+ public void setChildren(List<PluginElement> children)
+ {
+ this.children = children;
+ }
+
+ @Override
+ public boolean hasChildByContent(String content, boolean directChildsOnly)
+ {
+ return hasConfigElementByContentRecursive(this, content, FilterType.CONTENT, directChildsOnly);
+ }
+
+ @Override
+ public boolean hasChildByContent(String content)
+ {
+ return hasChildByContent(content, false);
+ }
+
+ @Override
+ public ConfigurationElement getChildByContent(String content, boolean directChildsOnly)
+ {
+ return getConfigElementRecursiveByContent(this, content, FilterType.CONTENT, directChildsOnly);
+ }
+
+ @Override
+ public ConfigurationElement getChildByContent(String content)
+ {
+ return getConfigElementRecursiveByContent(this, content, FilterType.CONTENT, false);
+ }
+
+ @Override
+ public boolean hasChildByName(String name, boolean directChildsOnly)
+ {
+ return hasConfigElementByContentRecursive(this, name, FilterType.CONTENT, directChildsOnly);
+ }
+
+ @Override
+ public boolean hasChildByName(String name)
+ {
+ return hasConfigElementByContentRecursive(this, name, FilterType.NAME, false);
+ }
+
+ @Override
+ public ConfigurationElement getChildByName(String name, boolean directChildsOnly)
+ {
+ return getConfigElementRecursiveByContent(this, name, FilterType.NAME, directChildsOnly);
+ }
+
+ @Override
+ public ConfigurationElement getChildByName(String name)
+ {
+ return getConfigElementRecursiveByContent(this, name, FilterType.NAME, false);
+ }
+
+ @Override
+ public String toString()
+ {
+ StringBuilder b = new StringBuilder();
+ b.append("<").append(name).append(">");
+ for (PluginElement child : children)
+ {
+ b.append(child.toString());
+ }
+
+ if (text != null)
+ {
+ b.append(text);
+ }
+
+ b.append("</").append(name).append(">");
+ return b.toString();
+ }
+
+ private ConfigurationElement getConfigElementRecursiveByContent(ConfigurationElement parent, String filter,
+ FilterType filterType, boolean directChildsOnly)
+ {
+ List<PluginElement> children = parent.getChildren();
+ for (PluginElement child : children)
+ {
+ if (child instanceof ConfigurationElement)
+ {
+
+ ConfigurationElement element = (ConfigurationElement) child;
+
+ if (filterType.equals(FilterType.CONTENT) && filter.equals(element.getText()))
+ {
+ return parent;
+ }
+ else if (filterType.equals(FilterType.NAME) && filter.equals(element.getName()))
+ {
+ return element;
+ }
+
+ if (!directChildsOnly && element.hasChilderen())
+ {
+ try
+ {
+ return getConfigElementRecursiveByContent(element, filter, filterType, directChildsOnly);
+ }
+ catch (ConfigurationElementNotFoundException ex)
+ {
+ // Do nothing, first check other childs
+ }
+ }
+
+ }
+ else
+ {
+ throw new RuntimeException("Unexpected type " + child.getClass() + " found as a child of "
+ + parent.getName());
+ }
+ }
+
+ throw new ConfigurationElementNotFoundException(filter);
+ }
+
+ private boolean hasConfigElementByContentRecursive(ConfigurationElement configurationElement, String filter,
+ FilterType filterType, boolean directChildsOnly)
+ {
+ try
+ {
+ getConfigElementRecursiveByContent(configurationElement, filter, filterType, directChildsOnly);
+ return true;
+ }
+ catch (ConfigurationElementNotFoundException ex)
+ {
+ return false;
+ }
+
+ }
+
+ private enum FilterType
+ {
+ NAME, CONTENT
+ }
+}
View
18 ...pi/src/main/java/org/jboss/forge/maven/plugins/ConfigurationElementNotFoundException.java
@@ -0,0 +1,18 @@
+/*
+ * Copyright 2012 Red Hat, Inc. and/or its affiliates.
+ *
+ * Licensed under the Eclipse Public License version 1.0, available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.jboss.forge.maven.plugins;
+
+public class ConfigurationElementNotFoundException extends RuntimeException
+{
+ private static final long serialVersionUID = -443270510723493609L;
+
+ public ConfigurationElementNotFoundException(final String elementName)
+ {
+ super("Configuration element with name '" + elementName + "' doesn't exist");
+ }
+}
View
21 maven/api/src/main/java/org/jboss/forge/maven/plugins/ConfigurationException.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2012 Red Hat, Inc. and/or its affiliates.
+ *
+ * Licensed under the Eclipse Public License version 1.0, available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.jboss.forge.maven.plugins;
+
+/**
+ * @author <a href="mailto:paul.bakker.nl@gmail.com">Paul Bakker</a>
+ */
+public class ConfigurationException extends RuntimeException
+{
+ private static final long serialVersionUID = -1348437184032449458L;
+
+ public ConfigurationException(final String s, final Exception ex)
+ {
+ super(s, ex);
+ }
+}
View
136 maven/api/src/main/java/org/jboss/forge/maven/plugins/ConfigurationImpl.java
@@ -0,0 +1,136 @@
+/*
+ * Copyright 2012 Red Hat, Inc. and/or its affiliates.
+ *
+ * Licensed under the Eclipse Public License version 1.0, available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.jboss.forge.maven.plugins;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+
+/**
+ * @author <a href="mailto:paul.bakker.nl@gmail.com">Paul Bakker</a>
+ */
+public class ConfigurationImpl implements Configuration
+{
+ private final Xpp3Dom configuration;
+ private final List<ConfigurationElement> configurationElements = new ArrayList<ConfigurationElement>();
+
+ public ConfigurationImpl()
+ {
+ configuration = new Xpp3Dom("configuration");
+ }
+
+ public ConfigurationImpl(final Xpp3Dom configXml)
+ {
+ this.configuration = configXml;
+ if (configuration != null)
+ {
+
+ for (Xpp3Dom xpp3Dom : configuration.getChildren())
+ {
+ ConfigurationElementBuilder builder = ConfigurationElementBuilder.create()
+ .setName(xpp3Dom.getName()).setText(xpp3Dom.getValue());
+ addChilds(xpp3Dom, builder);
+ configurationElements.add(builder);
+
+ }
+
+ }
+ }
+
+ @Override
+ public ConfigurationElement getConfigurationElement(final String configElement)
+ {
+ for (ConfigurationElement configurationElement : configurationElements)
+ {
+ if (configurationElement.getName().equals(configElement))
+ {
+ return configurationElement;
+ }
+ }
+
+ throw new RuntimeException("Configuration '" + configElement + "' not found");
+ }
+
+ @Override
+ public boolean hasConfigurationElement(final String configElement)
+ {
+
+ for (ConfigurationElement configurationElement : configurationElements)
+ {
+ if (configurationElement.getName().equals(configElement))
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ @Override
+ public boolean hasConfigurationElements()
+ {
+ return !listConfigurationElements().isEmpty();
+ }
+
+ @Override
+ public List<ConfigurationElement> listConfigurationElements()
+ {
+ return configurationElements;
+ }
+
+ private void addChilds(final Xpp3Dom xpp3Dom, final ConfigurationElementBuilder builder)
+ {
+ builder.setText(xpp3Dom.getValue());
+
+ for (Xpp3Dom child : xpp3Dom.getChildren())
+ {
+
+ ConfigurationElementBuilder elementBuilder = builder.addChild(child.getName());
+ addChilds(child, elementBuilder);
+
+ }
+ }
+
+ @Override
+ public Configuration addConfigurationElement(final ConfigurationElement element)
+ {
+
+ configurationElements.add(element);
+
+ return this;
+ }
+
+ @Override
+ public void removeConfigurationElement(final String elementName)
+ {
+ for (ConfigurationElement configurationElement : configurationElements)
+ {
+ if (configurationElement.getName().equals(elementName))
+ {
+ configurationElements.remove(configurationElement);
+ break;
+ }
+ }
+ }
+
+ @Override
+ public String toString()
+ {
+ StringBuilder b = new StringBuilder();
+ b.append("<configuration>");
+
+ for (ConfigurationElement configurationElement : configurationElements)
+ {
+ b.append(configurationElement.toString());
+ }
+
+ b.append("</configuration>");
+ return b.toString();
+ }
+}
View
17 maven/api/src/main/java/org/jboss/forge/maven/plugins/Execution.java
@@ -0,0 +1,17 @@
+/*
+ * Copyright 2012 Red Hat, Inc. and/or its affiliates.
+ *
+ * Licensed under the Eclipse Public License version 1.0, available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.jboss.forge.maven.plugins;
+
+import java.util.List;
+
+public interface Execution {
+ String getId();
+ String getPhase();
+ List<String> getGoals();
+ Configuration getConfig();
+}
View
70 maven/api/src/main/java/org/jboss/forge/maven/plugins/ExecutionBuilder.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2012 Red Hat, Inc. and/or its affiliates.
+ *
+ * Licensed under the Eclipse Public License version 1.0, available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.jboss.forge.maven.plugins;
+
+import java.util.List;
+
+public class ExecutionBuilder implements Execution{
+ private ExecutionImpl execution;
+
+ private ExecutionBuilder() {
+ execution = new ExecutionImpl();
+ }
+
+ private ExecutionBuilder(ExecutionImpl execution) {
+ this.execution = execution;
+ }
+
+ public static ExecutionBuilder create() {
+ return new ExecutionBuilder();
+ }
+
+ public static ExecutionBuilder create(ExecutionImpl execution) {
+ return new ExecutionBuilder(execution);
+ }
+
+ public ExecutionBuilder setId(String id) {
+ execution.setId(id);
+ return this;
+ }
+
+ public ExecutionBuilder setPhase(String phase) {
+ execution.setPhase(phase);
+ return this;
+ }
+
+ public ExecutionBuilder addGoal(String goal) {
+ execution.addGoal(goal);
+ return this;
+ }
+
+ @Override public String getId() {
+ return execution.getId();
+ }
+
+ @Override public String getPhase() {
+ return execution.getPhase();
+ }
+
+ @Override public List<String> getGoals() {
+ return execution.getGoals();
+ }
+
+ @Override public String toString() {
+ return execution.toString();
+ }
+
+ @Override public Configuration getConfig() {
+ return execution.getConfig();
+ }
+
+ public ExecutionBuilder setConfig(Configuration configuration) {
+ execution.setConfiguration(configuration);
+ return this;
+ }
+}
View
69 maven/api/src/main/java/org/jboss/forge/maven/plugins/ExecutionImpl.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2012 Red Hat, Inc. and/or its affiliates.
+ *
+ * Licensed under the Eclipse Public License version 1.0, available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.jboss.forge.maven.plugins;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ExecutionImpl implements Execution {
+ private String id;
+ private String phase;
+ private List<String> goals = new ArrayList<String>();
+ private Configuration configuration;
+
+ @Override public String getId() {
+ return id;
+ }
+
+ @Override public String getPhase() {
+ return phase;
+ }
+
+ @Override public List<String> getGoals() {
+ return goals;
+ }
+
+ @Override public Configuration getConfig() {
+ return configuration;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public void setPhase(String phase) {
+ this.phase = phase;
+ }
+
+ public void addGoal(String goal) {
+ goals.add(goal);
+ }
+
+ public void setConfiguration(Configuration configuration) {
+ this.configuration = configuration;
+ }
+
+ @Override public String toString() {
+ StringBuilder b = new StringBuilder();
+ b.append("<execution>")
+ .append("<id>").append(id).append("</id>")
+ .append("<phase>").append(phase).append("</phase>");
+ for (String goal : goals) {
+ b.append("<goal>").append(goal).append("</goal>");
+ }
+
+ if(configuration != null) {
+ b.append(configuration.toString());
+ }
+
+ b.append("</execution>");
+
+
+ return b.toString();
+ }
+}
View
32 maven/api/src/main/java/org/jboss/forge/maven/plugins/MavenPlugin.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2012 Red Hat, Inc. and/or its affiliates.
+ *
+ * Licensed under the Eclipse Public License version 1.0, available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.jboss.forge.maven.plugins;
+
+import java.util.List;
+
+import org.jboss.forge.dependencies.Dependency;
+
+/**
+ * Represents a Maven plugin
+ *
+ * @author <a href="mailto:paul.bakker.nl@gmail.com">Paul Bakker</a>
+ */
+
+public interface MavenPlugin extends PluginElement
+{
+ Dependency getDependency();
+
+ Configuration getConfig();
+
+ List<Execution> listExecutions();
+
+ boolean isExtensionsEnabled();
+
+ List<Dependency> getDirectDependencies();
+
+}
View
186 maven/api/src/main/java/org/jboss/forge/maven/plugins/MavenPluginAdapter.java
@@ -0,0 +1,186 @@
+/*
+ * Copyright 2012 Red Hat, Inc. and/or its affiliates.
+ *
+ * Licensed under the Eclipse Public License version 1.0, available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.jboss.forge.maven.plugins;
+
+import java.io.ByteArrayInputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.maven.model.Exclusion;
+import org.apache.maven.model.PluginExecution;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
+import org.jboss.forge.dependencies.Coordinate;
+import org.jboss.forge.dependencies.Dependency;
+import org.jboss.forge.dependencies.builder.DependencyBuilder;
+
+/**
+ * @author <a href="mailto:paul.bakker.nl@gmail.com">Paul Bakker</a>
+ */
+
+public class MavenPluginAdapter extends org.apache.maven.model.Plugin implements MavenPlugin
+{
+ private static final long serialVersionUID = 2502801162956631981L;
+
+ public MavenPluginAdapter(final MavenPlugin mavenPlugin)
+ {
+ Dependency dependency = mavenPlugin.getDependency();
+
+ setGroupId(dependency.getCoordinate().getGroupId());
+ setArtifactId(dependency.getCoordinate().getArtifactId());
+ setVersion(dependency.getCoordinate().getVersion());
+ setConfiguration(parseConfig(mavenPlugin.getConfig()));
+ setExecutions(transformExecutions(mavenPlugin));
+ if (mavenPlugin.isExtensionsEnabled())
+ {
+ setExtensions(true);
+ }
+ setDependencies(transformDependencies(mavenPlugin));
+ }
+
+ private List<org.apache.maven.model.Dependency> transformDependencies(MavenPlugin mavenPlugin)
+ {
+ List<org.apache.maven.model.Dependency> dependencies = new ArrayList<org.apache.maven.model.Dependency>();
+ for (Dependency dependency : mavenPlugin.getDirectDependencies())
+ {
+ org.apache.maven.model.Dependency pluginDependency = new org.apache.maven.model.Dependency();
+ pluginDependency.setArtifactId(dependency.getCoordinate().getArtifactId());
+ pluginDependency.setGroupId(dependency.getCoordinate().getGroupId());
+ pluginDependency.setVersion(dependency.getCoordinate().getVersion());
+ pluginDependency.setScope(dependency.getScopeType());
+ pluginDependency.setExclusions(transformExclusions(dependency.getExcludedCoordinates()));
+ dependencies.add(pluginDependency);
+ }
+ return dependencies;
+ }
+
+ private List<Exclusion> transformExclusions(List<Coordinate> excludedDependencies)
+ {
+ List<Exclusion> result = new ArrayList<Exclusion>(excludedDependencies.size());
+ for (Coordinate dependency : excludedDependencies)
+ {
+ Exclusion exclusion = new Exclusion();
+ exclusion.setArtifactId(dependency.getArtifactId());
+ exclusion.setGroupId(dependency.getGroupId());
+ result.add(exclusion);
+ }
+ return result;
+ }
+
+ private List<PluginExecution> transformExecutions(final MavenPlugin mavenPlugin)
+ {
+ List<PluginExecution> executions = new ArrayList<PluginExecution>();
+
+ for (Execution execution : mavenPlugin.listExecutions())
+ {
+ PluginExecution pluginExecution = new PluginExecution();
+ pluginExecution.setId(execution.getId());
+ pluginExecution.setPhase(execution.getPhase());
+ pluginExecution.setGoals(execution.getGoals());
+ pluginExecution.setConfiguration(parseConfig(execution.getConfig()));
+ executions.add(pluginExecution);
+ }
+
+ return executions;
+
+ }
+
+ private Xpp3Dom parseConfig(final Configuration configuration)
+ {
+ if ((configuration == null) || (!configuration.hasConfigurationElements()))
+ {
+ return null;
+ }
+
+ try
+ {
+ return Xpp3DomBuilder.build(
+ new ByteArrayInputStream(configuration.toString().getBytes()), "UTF-8");
+ }
+ catch (Exception ex)
+ {
+ throw new RuntimeException("Exception while parsing configuration", ex);
+ }
+ }
+
+ public MavenPluginAdapter(final org.apache.maven.model.Plugin plugin)
+ {
+ org.apache.maven.model.Plugin clone = plugin.clone();
+
+ setGroupId(clone.getGroupId());
+ setArtifactId(clone.getArtifactId());
+ setVersion(clone.getVersion());
+ setConfiguration(plugin.getConfiguration());
+ setExecutions(clone.getExecutions());
+ setExtensions(clone.getExtensions());
+ }
+
+ @Override
+ public List<Execution> listExecutions()
+ {
+ List<Execution> executions = new ArrayList<Execution>();
+
+ for (PluginExecution pluginExecution : getExecutions())
+ {
+ ExecutionBuilder executionBuilder = ExecutionBuilder.create()
+ .setId(pluginExecution.getId()).setPhase(pluginExecution.getPhase());
+ for (String goal : pluginExecution.getGoals())
+ {
+ executionBuilder.addGoal(goal);
+ }
+ if (pluginExecution.getConfiguration() != null)
+ {
+ executionBuilder.setConfig(new ConfigurationImpl((Xpp3Dom) pluginExecution.getConfiguration()));
+ }
+ executions.add(executionBuilder);
+ }
+
+ return executions;
+ }
+
+ @Override
+ public Configuration getConfig()
+ {
+ Xpp3Dom dom = (Xpp3Dom) super.getConfiguration();
+
+ return new ConfigurationImpl(dom);
+ }
+
+ @Override
+ public Dependency getDependency()
+ {
+ return DependencyBuilder.create()
+ .setGroupId(getGroupId())
+ .setArtifactId(getArtifactId())
+ .setVersion(getVersion());
+ }
+
+ @Override
+ public boolean isExtensionsEnabled()
+ {
+ return isExtensions();
+ }
+
+ @Override
+ public List<Dependency> getDirectDependencies()
+ {
+ List<Dependency> dependencies = new ArrayList<Dependency>();
+ for (org.apache.maven.model.Dependency pluginDependency : getDependencies())
+ {
+ DependencyBuilder builder = DependencyBuilder.create()
+ .setArtifactId(pluginDependency.getArtifactId())
+ .setGroupId(pluginDependency.getGroupId())
+ .setVersion(pluginDependency.getVersion())
+ .setPackaging(pluginDependency.getType())
+ .setScopeType(pluginDependency.getScope());
+ dependencies.add(builder);
+ }
+ return dependencies;
+ }
+
+}
View
127 maven/api/src/main/java/org/jboss/forge/maven/plugins/MavenPluginBuilder.java
@@ -0,0 +1,127 @@
+/*
+ * Copyright 2012 Red Hat, Inc. and/or its affiliates.
+ *
+ * Licensed under the Eclipse Public License version 1.0, available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.jboss.forge.maven.plugins;
+
+import java.util.List;
+
+import org.jboss.forge.dependencies.Dependency;
+
+/**
+ * @author <a href="mailto:paul.bakker.nl@gmail.com">Paul Bakker</a>
+ */
+public class MavenPluginBuilder implements MavenPlugin, PluginElement
+{
+ private MavenPluginImpl plugin = new MavenPluginImpl();
+
+ private MavenPluginBuilder()
+ {
+ }
+
+ private MavenPluginBuilder(final MavenPlugin plugin)
+ {
+ this.plugin = new MavenPluginImpl(plugin);
+ }
+
+ public static MavenPluginBuilder create()
+ {
+ return new MavenPluginBuilder();
+ }
+
+ public static MavenPluginBuilder create(final MavenPlugin plugin)
+ {
+ return new MavenPluginBuilder(plugin);
+ }
+
+ public MavenPluginBuilder setConfiguration(final Configuration configuration)
+ {
+ plugin.setConfiguration(configuration);
+ return this;
+ }
+
+ @Override
+ public Dependency getDependency()
+ {
+ return plugin.getDependency();
+ }
+
+ public MavenPluginBuilder setDependency(final Dependency dependency)
+ {
+ plugin.setDependency(dependency);
+ return this;
+ }
+
+ @Override
+ public Configuration getConfig()
+ {
+ if (plugin.getConfig() == null)
+ {
+ plugin.setConfiguration(ConfigurationBuilder.create());
+ }
+ return plugin.getConfig();
+ }
+
+ @Override
+ public List<Execution> listExecutions()
+ {
+ return plugin.listExecutions();
+ }
+
+ public MavenPluginBuilder addExecution(final Execution execution)
+ {
+ plugin.addExecution(execution);
+ return this;
+ }
+
+ public MavenPluginBuilder addPluginDependency(final Dependency pluginDependency)
+ {
+ plugin.addPluginDependency(pluginDependency);
+ return this;
+ }
+
+ public MavenPluginBuilder setExtensions(boolean extensions)
+ {
+ plugin.setExtenstions(extensions);
+ return this;
+ }
+
+ @Override
+ public boolean isExtensionsEnabled()
+ {
+ return plugin.isExtensionsEnabled();
+ }
+
+ @Override
+ public String toString()
+ {
+ return plugin.toString();
+ }
+
+ public ConfigurationBuilder createConfiguration()
+ {
+ ConfigurationBuilder builder;
+ if (plugin.getConfig() != null)
+ {
+ builder = ConfigurationBuilder.create(plugin.getConfig(), this);
+ }
+ else
+ {
+ builder = ConfigurationBuilder.create(this);
+ }
+
+ plugin.setConfiguration(builder);
+
+ return builder;
+ }
+
+ @Override
+ public List<Dependency> getDirectDependencies()
+ {
+ return plugin.getDirectDependencies();
+ }
+
+}
View
178 maven/api/src/main/java/org/jboss/forge/maven/plugins/MavenPluginImpl.java
@@ -0,0 +1,178 @@
+/*
+ * Copyright 2012 Red Hat, Inc. and/or its affiliates.
+ *
+ * Licensed under the Eclipse Public License version 1.0, available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.jboss.forge.maven.plugins;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.forge.dependencies.Coordinate;
+import org.jboss.forge.dependencies.Dependency;
+
+/**
+ * @author <a href="mailto:paul.bakker.nl@gmail.com">Paul Bakker</a>
+ */
+public class MavenPluginImpl implements MavenPlugin
+{
+
+ private Dependency dependency;
+ private Configuration configuration;
+ private final List<Execution> executions = new ArrayList<Execution>();
+ private boolean extensions;
+ private List<Dependency> pluginDependencies = new ArrayList<Dependency>();
+
+ public MavenPluginImpl()
+ {
+ }
+
+ public MavenPluginImpl(final MavenPlugin plugin)
+ {
+ this.dependency = plugin.getDependency();
+ this.configuration = plugin.getConfig();
+ }
+
+ @Override
+ public Dependency getDependency()
+ {
+ return dependency;
+ }
+
+ public void setDependency(final Dependency dependency)
+ {
+ this.dependency = dependency;
+ }
+
+ @Override
+ public Configuration getConfig()
+ {
+ if (configuration == null)
+ {
+ configuration = ConfigurationBuilder.create();
+ }
+ return configuration;
+ }
+
+ @Override
+ public List<Execution> listExecutions()
+ {
+ return executions;
+ }
+
+ @Override
+ public boolean isExtensionsEnabled()
+ {
+ return extensions;
+ }
+
+ @Override
+ public List<Dependency> getDirectDependencies()
+ {
+ return pluginDependencies;
+ }
+
+ @Override
+ public String toString()
+ {
+ StringBuilder b = new StringBuilder("<plugin>");
+ appendDependency(b, dependency);
+
+ if (extensions)
+ {
+ b.append("<extensions>true</extensions>");
+ }
+
+ if (configuration != null)
+ {
+ b.append(configuration.toString());
+ }
+
+ if (executions.size() > 0)
+ {
+ b.append("<executions>");
+ for (Execution execution : executions)
+ {
+ b.append(execution.toString());
+ }
+ b.append("</executions>");
+ }
+
+ if (pluginDependencies.size() > 0)
+ {
+ b.append("<dependencies>");
+ for (Dependency pluginDependency : pluginDependencies)
+ {
+ b.append("<dependency>");
+ appendDependency(b, pluginDependency);
+ b.append("</dependency>");
+ }
+ b.append("</dependencies>");
+ }
+
+ b.append("</plugin>");
+ return b.toString();
+ }
+
+ public void setConfiguration(final Configuration configuration)
+ {
+ this.configuration = configuration;
+ }
+
+ public void addExecution(final Execution execution)
+ {
+ executions.add(execution);
+ }
+
+ public void setExtenstions(boolean extenstions)
+ {
+ this.extensions = extenstions;
+ }
+
+ public void addPluginDependency(final Dependency dependency)
+ {
+ pluginDependencies.add(dependency);
+ }
+
+ private void appendDependency(StringBuilder builder, Dependency appendDependency)
+ {
+ appendDependencyData(builder, appendDependency.getCoordinate(), true);
+ if (!appendDependency.getExcludedCoordinates().isEmpty())
+ {
+ builder.append("<exclusions>");
+ for (Coordinate exclusion : appendDependency.getExcludedCoordinates())
+ {
+ appendExclusion(builder, exclusion);
+ }
+ builder.append("</exclusions>");
+ }
+ }
+
+ private void appendExclusion(StringBuilder builder, Coordinate exclusion)
+ {
+ builder.append("<exclusion>");
+ appendDependencyData(builder, exclusion, false);
+ builder.append("</exclusion>");
+ }
+
+ private void appendDependencyData(StringBuilder builder, Coordinate coordinate, boolean withVersion)
+ {
+ if (coordinate.getGroupId() != null)
+ {
+ builder.append("<groupId>").append(coordinate.getGroupId()).append("</groupId>");
+ }
+
+ if (coordinate.getArtifactId() != null)
+ {
+ builder.append("<artifactId>").append(coordinate.getArtifactId()).append("</artifactId>");
+ }
+
+ if (withVersion && coordinate.getVersion() != null)
+ {
+ builder.append("<version>").append(coordinate.getVersion()).append("</version>");
+ }
+ }
+
+}
View
15 maven/api/src/main/java/org/jboss/forge/maven/plugins/PluginElement.java
@@ -0,0 +1,15 @@
+/*
+ * Copyright 2012 Red Hat, Inc. and/or its affiliates.
+ *
+ * Licensed under the Eclipse Public License version 1.0, available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.jboss.forge.maven.plugins;
+
+/**
+ * @author <a href="mailto:paul.bakker.nl@gmail.com">Paul Bakker</a>
+ */
+public interface PluginElement
+{
+}
View
69 maven/api/src/main/java/org/jboss/forge/maven/projects/MavenPluginFacet.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2012 Red Hat, Inc. and/or its affiliates.
+ *
+ * Licensed under the Eclipse Public License version 1.0, available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.jboss.forge.maven.projects;
+
+import java.util.List;
+
+import org.jboss.forge.dependencies.Dependency;
+import org.jboss.forge.dependencies.DependencyRepository;
+import org.jboss.forge.maven.plugins.MavenPlugin;
+import org.jboss.forge.projects.ProjectFacet;
+
+/**
+ * @author <a href="mailto:paul.bakker.nl@gmail.com">Paul Bakker</a>
+ */
+public interface MavenPluginFacet extends ProjectFacet
+{
+
+ List<MavenPlugin> listConfiguredPlugins();
+
+ boolean hasPlugin(Dependency dependency);
+
+ MavenPlugin getPlugin(Dependency dependency);
+
+ void addPlugin(MavenPlugin plugin);
+
+ void removePlugin(Dependency dependency);
+
+ void updatePlugin(final MavenPlugin plugin);
+
+ List<MavenPlugin> listConfiguredManagedPlugins();
+
+ boolean hasManagedPlugin(Dependency dependency);
+
+ MavenPlugin getManagedPlugin(Dependency dependency);
+
+ void addManagedPlugin(MavenPlugin plugin);
+
+ void removeManagedPlugin(Dependency dependency);
+
+ void updateManagedPlugin(final MavenPlugin plugin);
+
+ /**
+ * Add a repository to the project build system. This is where dependencies can be found, downloaded, and installed
+ * to the project build script.
+ */
+ public void addPluginRepository(String name, String url);
+
+ /**
+ * Return true if the given repository URL is already registered in this project's build system.
+ */
+ public boolean hasPluginRepository(String url);
+
+ /**
+ * Remove the given {@link org.jboss.forge.project.dependencies.DependencyRepository} from the current project.
+ * Return true if the repository was removed; return false otherwise. Return the removed repository, or null if no
+ * repository was removed.
+ */
+ public DependencyRepository removePluginRepository(String url);
+
+ /**
+ * Get the list of plugin repositories for which this project is currently configured to use in dependency
+ * resolution.
+ */
+ public List<DependencyRepository> getPluginRepositories();
+}
View
353 maven/impl-projects/src/main/java/org/jboss/forge/maven/projects/MavenPluginFacetImpl.java
@@ -0,0 +1,353 @@
+/*
+ * Copyright 2012 Red Hat, Inc. and/or its affiliates.
+ *
+ * Licensed under the Eclipse Public License version 1.0, available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.jboss.forge.maven.projects;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.enterprise.context.Dependent;
+
+import org.apache.maven.model.Build;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.Plugin;
+import org.apache.maven.model.PluginManagement;
+import org.apache.maven.model.Repository;
+import org.jboss.forge.container.exception.ContainerException;
+import org.jboss.forge.dependencies.Dependency;
+import org.jboss.forge.dependencies.DependencyRepository;
+import org.jboss.forge.dependencies.builder.DependencyBuilder;
+import org.jboss.forge.dependencies.util.Dependencies;
+import org.jboss.forge.facets.AbstractFacet;
+import org.jboss.forge.maven.plugins.Execution;
+import org.jboss.forge.maven.plugins.MavenPlugin;
+import org.jboss.forge.maven.plugins.MavenPluginAdapter;
+import org.jboss.forge.maven.plugins.MavenPluginBuilder;
+import org.jboss.forge.projects.Project;
+
+/**
+ * @author <a href="mailto:paul.bakker.nl@gmail.com">Paul Bakker</a>
+ */
+
+@Dependent
+public class MavenPluginFacetImpl extends AbstractFacet<Project> implements MavenPluginFacet
+{
+ private static final String DEFAULT_GROUPID = "org.apache.maven.plugins";
+
+ @Override
+ public boolean install()
+ {
+ return true;
+ }
+
+ @Override
+ public boolean isInstalled()
+ {
+ return getOrigin().hasFacet(MavenFacet.class);
+ }
+
+ private List<org.apache.maven.model.Plugin> getPluginsPOM(Build build, boolean managedPlugin)
+ {
+ if (build != null)
+ {
+ if (managedPlugin)
+ {
+ PluginManagement pluginManagement = build.getPluginManagement();
+ if (pluginManagement != null)
+ {
+ return pluginManagement.getPlugins();
+ }
+ }
+ else
+ {
+ return build.getPlugins();
+ }
+ }
+ return Collections.emptyList();
+ }
+
+ private List<MavenPlugin> listConfiguredPlugins(boolean managedPlugin)
+ {
+ List<MavenPlugin> plugins = new ArrayList<MavenPlugin>();
+ MavenFacet mavenCoreFacet = getOrigin().getFacet(MavenFacet.class);
+ Build build = mavenCoreFacet.getPOM().getBuild();
+ List<org.apache.maven.model.Plugin> pomPlugins = getPluginsPOM(build, managedPlugin);
+ for (org.apache.maven.model.Plugin plugin : pomPlugins)
+ {
+ MavenPluginAdapter adapter = new MavenPluginAdapter(plugin);
+ MavenPluginBuilder pluginBuilder = MavenPluginBuilder
+ .create()
+ .setDependency(
+ DependencyBuilder.create().setGroupId(plugin.getGroupId())
+ .setArtifactId(plugin.getArtifactId()).setVersion(plugin.getVersion()))
+
+ .setConfiguration(adapter.getConfig());
+ for (Execution execution : adapter.listExecutions())
+ {
+ pluginBuilder.addExecution(execution);
+ }
+ plugins.add(pluginBuilder);
+ }
+ return plugins;
+ }
+
+ private void addPlugin(final MavenPlugin plugin, boolean managedPlugin)
+ {
+ MavenFacet maven = getOrigin().getFacet(MavenFacet.class);
+ Model pom = maven.getPOM();
+ Build build = pom.getBuild();
+ if (build == null)
+ build = new Build();
+ if (managedPlugin)
+ {
+ PluginManagement pluginManagement = build.getPluginManagement();
+ if (pluginManagement == null)
+ {
+ pluginManagement = new PluginManagement();
+ build.setPluginManagement(pluginManagement);
+ }
+ pluginManagement.addPlugin(new MavenPluginAdapter(plugin));
+ }
+ else
+ {
+ build.addPlugin(new MavenPluginAdapter(plugin));
+ }
+ pom.setBuild(build);
+ maven.setPOM(pom);
+ }
+
+ private MavenPlugin getPlugin(final Dependency dependency, boolean managedPlugin)
+ {
+ String groupId = dependency.getCoordinate().getGroupId();
+ groupId = (groupId == null) || groupId.equals("") ? DEFAULT_GROUPID : groupId;
+
+ for (MavenPlugin mavenPlugin : listConfiguredPlugins(managedPlugin))
+ {
+ Dependency temp = mavenPlugin.getDependency();
+ if (Dependencies.areEquivalent(temp, DependencyBuilder.create(dependency).setGroupId(groupId)))
+ {
+ return mavenPlugin;
+ }
+ }
+
+ throw new ContainerException("Plugin " + dependency.getCoordinate() + " was not found");
+ }
+
+ public boolean hasPlugin(final Dependency dependency, boolean managedPlugin)
+ {
+ try
+ {
+ getPlugin(dependency, managedPlugin);
+ return true;
+ }
+ catch (ContainerException ex)
+ {
+ return false;
+ }
+ }
+
+ private void removePlugin(final Dependency dependency, boolean managedPlugin)
+ {
+ MavenFacet maven = getOrigin().getFacet(MavenFacet.class);
+ Model pom = maven.getPOM();
+ Build build = pom.getBuild();
+ List<org.apache.maven.model.Plugin> pomPlugins = getPluginsPOM(build, managedPlugin);
+ Iterator<Plugin> it = pomPlugins.iterator();
+ while (it.hasNext())
+ {
+ org.apache.maven.model.Plugin pomPlugin = it.next();
+ Dependency pluginDep = DependencyBuilder.create().setGroupId(pomPlugin.getGroupId())
+ .setArtifactId(pomPlugin.getArtifactId());
+
+ if (Dependencies.areEquivalent(pluginDep, dependency))
+ {
+ it.remove();
+ }
+ }
+ maven.setPOM(pom);
+ }
+
+ private void updatePlugin(final MavenPlugin plugin, boolean managedPlugin)
+ {
+ MavenFacet maven = getOrigin().getFacet(MavenFacet.class);
+ Model pom = maven.getPOM();
+ Build build = pom.getBuild();
+ List<org.apache.maven.model.Plugin> pomPlugins = getPluginsPOM(build, managedPlugin);
+ for (org.apache.maven.model.Plugin pomPlugin : pomPlugins)
+ {
+ Dependency pluginDep = DependencyBuilder.create().setGroupId(pomPlugin.getGroupId())
+ .setArtifactId(pomPlugin.getArtifactId());
+
+ if (Dependencies.areEquivalent(pluginDep, plugin.getDependency()))
+ {
+ MavenPluginAdapter adapter = new MavenPluginAdapter(plugin);
+ pomPlugin.setConfiguration(adapter.getConfiguration());
+ maven.setPOM(pom);
+ break;
+ }
+ }
+ }
+
+ @Override
+ public List<MavenPlugin> listConfiguredPlugins()
+ {
+ return listConfiguredPlugins(false);
+ }
+
+ @Override
+ public List<MavenPlugin> listConfiguredManagedPlugins()
+ {
+ return listConfiguredPlugins(true);
+ }
+
+ @Override
+ public void addPlugin(final MavenPlugin plugin)
+ {
+ addPlugin(plugin, false);
+ }
+
+ @Override
+ public void addManagedPlugin(final MavenPlugin plugin)
+ {
+ addPlugin(plugin, true);
+ }
+
+ @Override
+ public MavenPlugin getPlugin(final Dependency dependency)
+ {
+ return getPlugin(dependency, false);
+ }
+
+ @Override
+ public MavenPlugin getManagedPlugin(final Dependency dependency)
+ {
+ return getPlugin(dependency, true);
+ }
+
+ @Override
+ public boolean hasPlugin(final Dependency dependency)
+ {
+ return hasPlugin(dependency, false);
+ }
+
+ @Override
+ public boolean hasManagedPlugin(final Dependency dependency)
+ {
+ return hasPlugin(dependency, true);
+ }
+
+ @Override
+ public void removePlugin(final Dependency dependency)
+ {
+ removePlugin(dependency, false);
+ }
+
+ @Override
+ public void removeManagedPlugin(final Dependency dependency)
+ {
+ removePlugin(dependency, true);
+ }
+
+ @Override
+ public void updatePlugin(final MavenPlugin plugin)
+ {
+ updatePlugin(plugin, false);
+ }
+
+ @Override
+ public void updateManagedPlugin(final MavenPlugin plugin)
+ {
+ updatePlugin(plugin, true);
+ }
+
+ @Override
+ public void addPluginRepository(final String name, final String url)
+ {
+ if (!hasPluginRepository(url))
+ {
+ MavenFacet maven = getOrigin().getFacet(MavenFacet.class);
+ Model pom = maven.getPOM();
+ Repository repo = new Repository();
+ repo.setId(name);
+ repo.setUrl(url);
+ pom.getPluginRepositories().add(repo);
+ maven.setPOM(pom);
+ }
+ }
+
+ @Override
+ public boolean hasPluginRepository(final String url)
+ {
+ if (url != null)
+ {
+ MavenFacet maven = getOrigin().getFacet(MavenFacet.class);
+ Model pom = maven.getPOM();
+ List<Repository> repositories = pom.getPluginRepositories();
+ if (repositories != null)
+ {
+ for (Repository repo : repositories)
+ {
+ if (repo.getUrl().trim().equals(url.trim()))
+ {
+ repositories.remove(repo);
+ maven.setPOM(pom);
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public DependencyRepository removePluginRepository(final String url)
+ {
+ if (url != null)
+ {
+ MavenFacet maven = getOrigin().getFacet(MavenFacet.class);
+ Model pom = maven.getPOM();
+ List<Repository> repos = pom.getPluginRepositories();
+ for (Repository repo : repos)
+ {
+ if (repo.getUrl().equals(url.trim()))
+ {
+ repos.remove(repo);
+ maven.setPOM(pom);
+ return new DependencyRepository(repo.getId(), repo.getUrl());
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public List<DependencyRepository> getPluginRepositories()
+ {
+ List<DependencyRepository> results = new ArrayList<DependencyRepository>();
+ MavenFacet maven = getOrigin().getFacet(MavenFacet.class);
+ Model pom = maven.getPOM();
+ List<Repository> repos = pom.getPluginRepositories();
+
+ if (repos != null)
+ {
+ for (Repository repo : repos)
+ {
+ results.add(new DependencyRepository(repo.getId(), repo.getUrl()));
+ }
+ }
+ return Collections.unmodifiableList(results);
+ }
+
+ @Override
+ public void setOrigin(final Project project)
+ {
+ super.setOrigin(project);
+ }
+
+}

0 comments on commit 61db777

Please sign in to comment.
Something went wrong with that request. Please try again.