Skip to content

Commit

Permalink
Some beginning experiments with groovy
Browse files Browse the repository at this point in the history
  • Loading branch information
jsight committed Jun 6, 2014
1 parent b984bc6 commit b97e97b
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 14 deletions.
2 changes: 1 addition & 1 deletion ext/groovy/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<version>${project.version}</version>
<classifier>forge-addon</classifier>
<scope>provided</scope>
</dependency>
</dependency>


<dependency>
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private void handleDirectory(File file, String path, List<String> discoveredFile

protected void handle(String name, URL url, List<String> discoveredFiles)
{
if (name.endsWith(".wrl")) // TODO handlers should be extensible
if (name.endsWith(".wrl") || name.endsWith(".windup.groovy")) // TODO handlers should be extensible
{
discoveredFiles.add(name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,21 @@
import org.jboss.forge.furnace.addons.AddonFilter;
import org.jboss.windup.config.RulePhase;
import org.jboss.windup.config.WindupConfigurationProvider;
import org.jboss.windup.util.exception.WindupException;
import org.jboss.windup.graph.GraphContext;
import org.ocpsoft.rewrite.config.Configuration;
import org.ocpsoft.rewrite.config.ConfigurationBuilder;
import org.ocpsoft.rewrite.config.Rule;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*
*
*/
public class GroovyConfigurationProvider extends WindupConfigurationProvider
{
private static Logger LOG = LoggerFactory.getLogger(GroovyConfigurationProvider.class);

@Inject
private FurnaceGroovyRuleScanner scanner;
@Inject
Expand Down Expand Up @@ -64,14 +67,18 @@ public Configuration getConfiguration(GraphContext context)
{
@SuppressWarnings("unchecked")
List<Rule> rules = (List<Rule>) shell.evaluate(reader);
for (Rule rule : rules)
if (rules != null)
{
builder.addRule(rule);
for (Rule rule : rules)
{
builder.addRule(rule);
}
}
}
catch (Exception e)
{
throw new WindupException("Failed to evaluate configuration: ", e);
LOG.error("Error evaluating groovy script: " + resource.getFile() + " due to: " + e.getMessage(), e);
// throw new WindupException("Failed to evaluate configuration: ", e);
}
}

Expand All @@ -90,12 +97,12 @@ public boolean accept(Addon addon)
return true;
}
};

for (Addon addon : furnace.getAddonRegistry().getAddons(filter))
{
loaders.add(addon.getClassLoader());
}

return new FurnaceCompositeClassLoader(getClass().getClassLoader(), loaders);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.jboss.windup.ext.groovy;

import javax.enterprise.event.Observes;

import org.jboss.forge.furnace.Furnace;
import org.jboss.forge.furnace.event.PostStartup;
import org.jboss.forge.furnace.services.Imported;
import org.jboss.windup.graph.GraphContext;
import org.jboss.windup.util.exception.WindupException;

public class GroovyDSLSupport
{
private static Furnace furnace;

public void setFurnace(@Observes PostStartup event, Furnace furnace)
{
GroovyDSLSupport.furnace = furnace;
}

private static GraphContext getGraphContext()
{
Imported<GraphContext> contexts = furnace.getAddonRegistry().getServices(GraphContext.class);
return contexts.get();
}

public static void registerInterest(String className, String importance, String hint)
{
GraphContext graphContext = GroovyDSLSupport.getGraphContext();

if (graphContext == null)
{
throw new WindupException("Failed miserably");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.jboss.windup.addon.groovy;

import org.jboss.windup.ext.groovy.GroovyConfigurationProvider;
import java.util.List;

import javax.inject.Inject;
Expand All @@ -12,9 +11,9 @@
import org.jboss.forge.arquillian.archive.ForgeArchive;
import org.jboss.forge.furnace.repositories.AddonDependencyEntry;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.windup.ext.groovy.GroovyConfigurationProvider;
import org.jboss.windup.graph.GraphContext;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ocpsoft.rewrite.config.Configuration;
Expand All @@ -24,13 +23,12 @@
/**
*
*/
@Ignore
public class LoadGroovyRulesTest
{
@Deployment
@Dependencies({
@AddonDependency(name = "org.jboss.forge.furnace.container:cdi"),
@AddonDependency(name = "org.jboss.windup.engine.ext:groovy"),
@AddonDependency(name = "org.jboss.windup.ext:windup-config-groovy"),
@AddonDependency(name = "org.jboss.windup.graph:windup-graph")
})
public static ForgeArchive getDeployment()
Expand All @@ -40,7 +38,7 @@ public static ForgeArchive getDeployment()
.addBeansXML()
.addAsAddonDependencies(
AddonDependencyEntry.create("org.jboss.forge.furnace.container:cdi"),
AddonDependencyEntry.create("org.jboss.windup.engine.ext:groovy"),
AddonDependencyEntry.create("org.jboss.windup.ext:windup-config-groovy"),
AddonDependencyEntry.create("org.jboss.windup.graph:windup-graph")
);
return archive;
Expand Down

0 comments on commit b97e97b

Please sign in to comment.