Skip to content

Commit cb2e19c

Browse files
committed
Fixes ocpsoft#133 - Improper wrapping of ConfigurationBuilder types. Some other minor fixes.
1 parent 4712841 commit cb2e19c

45 files changed

Lines changed: 1938 additions & 1427 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎annotations-impl/src/main/java/org/ocpsoft/rewrite/annotation/config/AnnotationConfigProvider.java‎

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
import java.lang.annotation.Annotation;
1919
import java.util.ArrayList;
20-
import java.util.HashSet;
2120
import java.util.Iterator;
21+
import java.util.LinkedHashSet;
2222
import java.util.List;
2323
import java.util.Set;
2424

@@ -54,8 +54,7 @@ public Configuration getConfiguration(ServletContext servletContext)
5454
{
5555

5656
/*
57-
* ======================================================
58-
* ============[ Configuration parameters ]==============
57+
* ====================================================== ============[ Configuration parameters ]==============
5958
* ======================================================
6059
*/
6160

@@ -65,32 +64,34 @@ public Configuration getConfiguration(ServletContext servletContext)
6564
// does the user want to scan the WEB-INF/lib directory
6665
boolean scanLibDir = false;
6766
String jarConfig = servletContext.getInitParameter(CONFIG_SCAN_LIB_DIR);
68-
if ((jarConfig != null) && jarConfig.trim().equalsIgnoreCase("true")) {
67+
if ((jarConfig != null) && jarConfig.trim().equalsIgnoreCase("true"))
68+
{
6969
scanLibDir = true;
7070
}
7171

7272
// users can disable annotation scanning
73-
if ((packageFilters != null) && packageFilters.trim().equalsIgnoreCase("none")) {
73+
if ((packageFilters != null) && packageFilters.trim().equalsIgnoreCase("none"))
74+
{
7475
log.debug("Annotation scanning is disabled!");
7576
return null;
7677
}
7778

7879
/*
79-
* ======================================================
80-
* ============[ Prepare scanning process ]==============
80+
* ====================================================== ============[ Prepare scanning process ]==============
8181
* ======================================================
8282
*/
8383

8484
// the byte code filter needs to know the annotations to look for
85-
Set<Class<? extends Annotation>> annotationType = new HashSet<Class<? extends Annotation>>();
85+
Set<Class<? extends Annotation>> annotationType = new LinkedHashSet<Class<? extends Annotation>>();
8686

8787
// list of annotation handlers for the ClassVisitor
8888
List<AnnotationHandler<Annotation>> annotationHandlers = new ArrayList<AnnotationHandler<Annotation>>();
8989

9090
// load the implementations of the AnnotationHandler SPI
9191
@SuppressWarnings("unchecked")
9292
Iterator<AnnotationHandler<Annotation>> handlerIterator = ServiceLoader.load(AnnotationHandler.class).iterator();
93-
while (handlerIterator.hasNext()) {
93+
while (handlerIterator.hasNext())
94+
{
9495
AnnotationHandler<Annotation> handler = handlerIterator.next();
9596
annotationHandlers.add(handler);
9697
annotationType.add(handler.handles());
@@ -107,26 +108,28 @@ public Configuration getConfiguration(ServletContext servletContext)
107108

108109
// fallback to some other classloder if there is no context class loader
109110
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
110-
if (classloader == null) {
111+
if (classloader == null)
112+
{
111113
classloader = this.getClass().getClassLoader();
112114
}
113115

114116
/*
115-
* ======================================================
116-
* =============[ Scanning process starts ]==============
117+
* ====================================================== =============[ Scanning process starts ]==============
117118
* ======================================================
118119
*/
119120

120121
// TODO this should be pulled out into a utility allowing it to run in Java SE
121122
// compile a list of class finders to run
122123
List<ClassFinder> classFinders = new ArrayList<ClassFinder>();
123124
classFinders.add(new WebClassesFinder(servletContext, classloader, packageFilter, byteCodeFilter));
124-
if (scanLibDir) {
125+
if (scanLibDir)
126+
{
125127
classFinders.add(new WebLibFinder(servletContext, classloader, packageFilter, byteCodeFilter));
126128
}
127129

128130
// start the scanning process
129-
for (ClassFinder finder : classFinders) {
131+
for (ClassFinder finder : classFinders)
132+
{
130133
finder.findClasses(classVisitor);
131134
}
132135

‎annotations-impl/src/main/java/org/ocpsoft/rewrite/annotation/scan/ByteCodeFilter.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.io.InputStream;
2121
import java.lang.annotation.Annotation;
2222
import java.util.HashSet;
23+
import java.util.LinkedHashSet;
2324
import java.util.Set;
2425

2526
import org.ocpsoft.logging.Logger;
@@ -69,7 +70,7 @@ public class ByteCodeFilter
6970
/**
7071
* The strings to look for in the constants table
7172
*/
72-
private final Set<String> fieldDescriptors = new HashSet<String>();
73+
private final Set<String> fieldDescriptors = new LinkedHashSet<String>();
7374

7475
/**
7576
* The filter must be initialized with a list of types to look for when scanning the class files. If a class files

‎annotations-impl/src/main/java/org/ocpsoft/rewrite/annotation/scan/PackageFilter.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package org.ocpsoft.rewrite.annotation.scan;
1717

18-
import java.util.HashSet;
18+
import java.util.LinkedHashSet;
1919
import java.util.Set;
2020

2121
import org.ocpsoft.logging.Logger;
@@ -33,7 +33,7 @@ public class PackageFilter
3333

3434
private final static Logger log = Logger.getLogger(PackageFilter.class);
3535

36-
private final Set<String> packageSet = new HashSet<String>();
36+
private final Set<String> packageSet = new LinkedHashSet<String>();
3737

3838
/**
3939
* Creates a new {@link PackageFilter}

‎annotations-impl/src/main/java/org/ocpsoft/rewrite/annotation/scan/WebClassesFinder.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import java.io.InputStream;
2020
import java.net.MalformedURLException;
2121
import java.net.URL;
22-
import java.util.HashSet;
22+
import java.util.LinkedHashSet;
2323
import java.util.Set;
2424

2525
import javax.servlet.ServletContext;
@@ -45,7 +45,7 @@ public class WebClassesFinder extends AbstractClassFinder
4545
/**
4646
* Manage a set of classes already processed
4747
*/
48-
private final Set<String> processedClasses = new HashSet<String>();
48+
private final Set<String> processedClasses = new LinkedHashSet<String>();
4949

5050
/**
5151
* Initialization

‎api/src/main/java/org/ocpsoft/rewrite/config/ConfigurationLoader.java‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import java.util.ArrayList;
1919
import java.util.Arrays;
2020
import java.util.Collections;
21-
import java.util.HashMap;
21+
import java.util.LinkedHashMap;
2222
import java.util.List;
2323
import java.util.Map;
2424
import java.util.Set;
@@ -33,6 +33,7 @@
3333
import org.ocpsoft.rewrite.param.Parameter;
3434
import org.ocpsoft.rewrite.param.ParameterStore;
3535
import org.ocpsoft.rewrite.param.Parameterized;
36+
import org.ocpsoft.rewrite.param.ParameterizedRule;
3637
import org.ocpsoft.rewrite.spi.ConfigurationCacheProvider;
3738
import org.ocpsoft.rewrite.util.Visitor;
3839

@@ -129,7 +130,7 @@ private Configuration buildCached(Object context)
129130
private Configuration build(Object context)
130131
{
131132

132-
Map<Integer, List<Rule>> priorityMap = new HashMap<Integer, List<Rule>>();
133+
Map<Integer, List<Rule>> priorityMap = new LinkedHashMap<Integer, List<Rule>>();
133134
for (ConfigurationProvider provider : providers) {
134135
if (provider.handles(context))
135136
{
@@ -178,13 +179,13 @@ private Configuration build(Object context)
178179
for (final Rule rule : list) {
179180
result.addRule(rule);
180181

181-
if (rule instanceof RuleBuilder) {
182+
if (rule instanceof ParameterizedRule) {
182183
ParameterizedCallback callback = new ParameterizedCallback() {
183184
@Override
184185
public void call(Parameterized parameterized)
185186
{
186187
Set<String> names = parameterized.getRequiredParameterNames();
187-
ParameterStore store = ((RuleBuilder) rule).getParameterStore();
188+
ParameterStore store = ((ParameterizedRule) rule).getParameterStore();
188189

189190
if (names != null)
190191
for (String name : names) {

‎api/src/main/java/org/ocpsoft/rewrite/config/ConfigurationRuleBuilder.java‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,19 @@
1717

1818
import java.util.List;
1919

20+
import org.ocpsoft.rewrite.context.EvaluationContext;
21+
import org.ocpsoft.rewrite.event.Rewrite;
2022
import org.ocpsoft.rewrite.param.Parameter;
23+
import org.ocpsoft.rewrite.param.ParameterStore;
24+
import org.ocpsoft.rewrite.param.ParameterizedRule;
2125

2226
/**
2327
* An intermediate stage {@link Rule} configuration.
2428
*
2529
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
2630
*/
2731
public class ConfigurationRuleBuilder extends ConfigurationBuilder implements
32+
ParameterizedRule,
2833
ConfigurationRuleBuilderCustom,
2934
ConfigurationRuleBuilderWhen,
3035
ConfigurationRuleBuilderPerform,
@@ -131,4 +136,34 @@ public List<Rule> getRules()
131136
{
132137
return wrapped.getRules();
133138
}
139+
140+
@Override
141+
public List<RuleBuilder> getRuleBuilders()
142+
{
143+
return wrapped.getRuleBuilders();
144+
}
145+
146+
@Override
147+
public ParameterStore getParameterStore()
148+
{
149+
return rule.getParameterStore();
150+
}
151+
152+
@Override
153+
public String getId()
154+
{
155+
return rule.getId();
156+
}
157+
158+
@Override
159+
public boolean evaluate(Rewrite event, EvaluationContext context)
160+
{
161+
return rule.evaluate(event, context);
162+
}
163+
164+
@Override
165+
public void perform(Rewrite event, EvaluationContext context)
166+
{
167+
rule.perform(event, context);
168+
}
134169
}

‎api/src/main/java/org/ocpsoft/rewrite/config/ConfigurationRuleParameterBuilder.java‎

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
*
3333
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
3434
*/
35-
public class ConfigurationRuleParameterBuilder extends ParameterBuilder<ConfigurationRuleParameterBuilder>
35+
public class ConfigurationRuleParameterBuilder
3636
implements
37-
37+
ConfigurableParameter<ConfigurationRuleParameterBuilder>,
3838
ConfigurationRuleParameter,
3939
ConfigurationRuleParameterMatches,
4040
ConfigurationRuleParameterWhere,
@@ -47,7 +47,6 @@ public class ConfigurationRuleParameterBuilder extends ParameterBuilder<Configur
4747
public ConfigurationRuleParameterBuilder(ConfigurationRuleBuilder parent,
4848
final ConfigurableParameter<?> param)
4949
{
50-
super(param.getName());
5150
this.parent = parent;
5251
this.param = param;
5352

@@ -132,4 +131,46 @@ public ConfigurationRuleBuilderWithPriority withPriority(int priority)
132131
return parent.withPriority(priority);
133132
}
134133

134+
@Override
135+
public List<Binding> getBindings()
136+
{
137+
return param.getBindings();
138+
}
139+
140+
@Override
141+
public String getName()
142+
{
143+
return param.getName();
144+
}
145+
146+
@Override
147+
public Converter<?> getConverter()
148+
{
149+
return param.getConverter();
150+
}
151+
152+
@Override
153+
public Validator<?> getValidator()
154+
{
155+
return param.getValidator();
156+
}
157+
158+
@Override
159+
public List<Constraint<String>> getConstraints()
160+
{
161+
return param.getConstraints();
162+
}
163+
164+
@Override
165+
public List<Transposition<String>> getTranspositions()
166+
{
167+
return param.getTranspositions();
168+
}
169+
170+
@Override
171+
public String toString()
172+
{
173+
return param.toString();
174+
}
175+
135176
}

‎api/src/main/java/org/ocpsoft/rewrite/config/ConfigurationRuleParameterMatches.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public interface ConfigurationRuleParameterMatches extends ConfigurationBuilderR
3333
/**
3434
* Configure the {@link Parameter} with the given name.
3535
*/
36+
@Override
3637
ConfigurationRuleParameterWhere where(String string);
3738

3839
/**

‎api/src/main/java/org/ocpsoft/rewrite/config/Filesystem.java‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.ocpsoft.rewrite.param.ParameterStore;
2626
import org.ocpsoft.rewrite.param.Parameterized;
2727
import org.ocpsoft.rewrite.param.ParameterizedPattern;
28+
import org.ocpsoft.rewrite.param.ParameterizedPatternBuilder;
2829
import org.ocpsoft.rewrite.param.ParameterizedPatternParser;
2930
import org.ocpsoft.rewrite.param.RegexParameterizedPatternParser;
3031

@@ -51,9 +52,13 @@ public boolean evaluate(final Rewrite event, final EvaluationContext context)
5152
{
5253
if (resource != null)
5354
{
54-
String filePath = resource.getBuilder().build(event, context);
55-
File file = new File(filePath);
56-
return filter.accept(file);
55+
ParameterizedPatternBuilder builder = resource.getBuilder();
56+
if (builder.isParameterComplete(event, context))
57+
{
58+
String filePath = builder.build(event, context);
59+
File file = new File(filePath);
60+
return filter.accept(file);
61+
}
5762
}
5863
return false;
5964
}
@@ -78,7 +83,8 @@ public boolean evaluate(final Rewrite event, final EvaluationContext context)
7883
*/
7984
public static Filesystem fileExists(final File resource)
8085
{
81-
return new Filesystem(resource, new FileFilter() {
86+
return new Filesystem(resource, new FileFilter()
87+
{
8288
@Override
8389
public boolean accept(File file)
8490
{
@@ -107,7 +113,8 @@ public boolean accept(File file)
107113
*/
108114
public static Filesystem directoryExists(final File resource)
109115
{
110-
return new Filesystem(resource, new FileFilter() {
116+
return new Filesystem(resource, new FileFilter()
117+
{
111118
@Override
112119
public boolean accept(File file)
113120
{

0 commit comments

Comments
 (0)