Skip to content

Commit b2f9de9

Browse files
committed
Refactoring
1 parent c23b8b1 commit b2f9de9

File tree

3 files changed

+21
-21
lines changed

3 files changed

+21
-21
lines changed

pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
<groupId>org.mozilla</groupId>
5353
<artifactId>rhino</artifactId>
5454
<version>1.7R4</version>
55+
<optional>true</optional>
5556
</dependency>
5657
<dependency>
5758
<groupId>commons-logging</groupId>
@@ -88,7 +89,7 @@
8889
<plugin>
8990
<groupId>org.apache.maven.plugins</groupId>
9091
<artifactId>maven-compiler-plugin</artifactId>
91-
<version>3.0</version>
92+
<version>3.1</version>
9293
<configuration>
9394
<source>1.6</source>
9495
<target>1.6</target>
@@ -155,7 +156,6 @@
155156
<plugin>
156157
<groupId>org.apache.maven.plugins</groupId>
157158
<artifactId>maven-release-plugin</artifactId>
158-
<version>2.4</version>
159159
</plugin>
160160
</plugins>
161161
</build>

src/main/java/com/asual/lesscss/LessOptions.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,19 @@ public void setCharset(String charset) {
5656
this.charset = charset;
5757
}
5858

59-
public boolean isCss() {
59+
public Boolean isCss() {
6060
return css;
6161
}
6262

63-
public void setCss(boolean css) {
63+
public void setCss(Boolean css) {
6464
this.css = css;
6565
}
6666

67-
public boolean isCompress() {
67+
public Boolean isCompress() {
6868
return compress;
6969
}
7070

71-
public void setCompress(boolean compress) {
71+
public void setCompress(Boolean compress) {
7272
this.compress = compress;
7373
}
7474

src/main/java/com/asual/lesscss/compiler/RhinoCompiler.java

+15-15
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@
1919
import com.asual.lesscss.loader.ResourceLoader;
2020
import org.apache.commons.logging.Log;
2121
import org.apache.commons.logging.LogFactory;
22-
import org.mozilla.javascript.*;
22+
import org.mozilla.javascript.Context;
23+
import org.mozilla.javascript.Function;
24+
import org.mozilla.javascript.JavaScriptException;
25+
import org.mozilla.javascript.NativeArray;
26+
import org.mozilla.javascript.Scriptable;
27+
import org.mozilla.javascript.ScriptableObject;
28+
import org.mozilla.javascript.UniqueTag;
2329
import org.mozilla.javascript.tools.shell.Global;
2430

2531
import java.io.IOException;
@@ -30,10 +36,9 @@
3036

3137
public class RhinoCompiler implements LessCompiler {
3238

33-
private Scriptable scope;
34-
private final Function compile;
35-
3639
private final Log logger = LogFactory.getLog(getClass());
40+
private final Scriptable scope;
41+
private final Function compile;
3742

3843
public RhinoCompiler(LessOptions options, ResourceLoader loader, URL less, URL env, URL engine, URL cssmin, URL sourceMap) throws IOException {
3944
Context cx = Context.enter();
@@ -78,24 +83,19 @@ public RhinoCompiler(LessOptions options, ResourceLoader loader, URL less, URL e
7883
@Override
7984
public String compile(String input, String location, boolean compress) throws LessException {
8085
try {
81-
return call(compile, new Object[]{input, location, compress});
82-
}
83-
catch (Exception e){
86+
return (String) Context.call(null, compile, scope, scope,
87+
new Object[]{input, location, compress});
88+
} catch (Exception e) {
8489
throw new LessException(parseLessException(e));
8590
}
8691
}
8792

88-
private String call(Function fn, Object[] args) {
89-
return (String) Context.call(null, fn, scope, scope, args);
90-
}
91-
9293
private boolean hasProperty(Scriptable value, String name) {
9394
Object property = ScriptableObject.getProperty(value, name);
9495
return property != null && !property.equals(UniqueTag.NOT_FOUND);
9596
}
9697

97-
private LessException parseLessException(Exception root)
98-
throws LessException {
98+
private Exception parseLessException(Exception root) {
9999
logger.debug("Parsing LESS Exception", root);
100100
if (root instanceof JavaScriptException) {
101101
Scriptable value = (Scriptable) ((JavaScriptException) root)
@@ -130,10 +130,10 @@ private LessException parseLessException(Exception root)
130130
}
131131
}
132132
}
133-
throw new LessException(message, type, filename, line, column,
133+
return new LessException(message, type, filename, line, column,
134134
extractList);
135135
}
136-
throw new LessException(root);
136+
return root;
137137
}
138138

139139
}

0 commit comments

Comments
 (0)