/
WindupRuleProvider.java
106 lines (92 loc) · 3.04 KB
/
WindupRuleProvider.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
* Copyright 2014 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.windup.config;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import javax.inject.Inject;
import org.jboss.forge.furnace.addons.Addon;
import org.jboss.windup.config.metadata.RuleMetadata;
import org.jboss.windup.graph.GraphContext;
import org.jboss.windup.log.jul.config.Logging;
import org.ocpsoft.rewrite.config.ConfigurationProvider;
import org.ocpsoft.rewrite.context.Context;
/**
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*
*/
public abstract class WindupRuleProvider implements ConfigurationProvider<GraphContext>
{
@Inject
private Addon addon;
public String getID()
{
return addon.getId().getName() + "." + getClass().getName();
}
/**
* Return the {@link RulePhase} in which the rules from this provider should be executed.
*/
public abstract RulePhase getPhase();
/**
* Specify additional meta-data about the {@link Rule} instances originating from this {@link WindupRuleProvider}.
*/
public void enhanceMetadata(Context context)
{
if (!context.containsKey(RuleMetadata.CATEGORY))
context.put(RuleMetadata.CATEGORY, "none");
if (!context.containsKey(RuleMetadata.ORIGIN))
context.put(RuleMetadata.ORIGIN, this.getClass().getName());
}
/**
* Returns a list of WindupRuleProvider classes that this instance depends on.
*
* Dependencies can also be specified based on id ({@link #getIDDependencies}).
*/
public List<Class<? extends WindupRuleProvider>> getClassDependencies()
{
return Collections.emptyList();
}
/**
* Returns a list of the WindupRuleProvider dependencies for this configuration provider.
*
* This is returned as a list of Rule IDs in order to support extensions that cannot depend on each other via class
* names. For example, in the case of the Groovy rules extension, a single class covers many rules with their own
* IDs.
*
* For depending upon Java-based rules, getClassDependencies is preferred. Dependencies of both types can be
* returned by a single WindupRuleProvider.
*/
public List<String> getIDDependencies()
{
return Collections.emptyList();
}
@Override
public int priority()
{
return getPhase().getPriority();
}
@Override
public boolean handles(Object payload)
{
return payload instanceof GraphContext;
}
@SafeVarargs
protected final List<Class<? extends WindupRuleProvider>> generateDependencies(
Class<? extends WindupRuleProvider>... deps)
{
return Arrays.asList(deps);
}
@SafeVarargs
protected final List<String> generateDependencies(
String... deps)
{
return Arrays.asList(deps);
}
static {
Logging.init();
}
}