Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 49 additions & 70 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.asual.lesscss</groupId>
<artifactId>lesscss-servlet</artifactId>
<version>1.5.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>LESS Servlet</name>
<version>1.3.4-SNAPSHOT</version>
<description>A Servlet wrapper for LESS (http://lesscss.org). LESS extends CSS with: variables, mixins, operations and nested rules.</description>
<url>http://www.asual.com/lesscss</url>

<organization>
<name>Ontotext AD</name>
</organization>

<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
Expand All @@ -19,33 +23,21 @@
</licenses>

<scm>
<url>http://github.com/asual/lesscss-servlet</url>
<connection>scm:git:git://github.com:asual/lesscss-servlet.git</connection>
<developerConnection>scm:git:git@github.com:asual/lesscss-servlet.git</developerConnection>
<tag>HEAD</tag>
<url>https://svn.ontotext.com/svn/forest/lesscss-servlet/trunk</url>
<connection>scm:svn:https://svn.ontotext.com/svn/forest/lesscss-servlet/trunk</connection>
<developerConnection>scm:svn:https://svn.ontotext.com/svn/forest/lesscss-servlet/trunk</developerConnection>
</scm>

<developers>
<developer>
<name>Rostislav Hristov</name>
<email>rostislav@asual.com</email>
</developer>
</developers>

<organization>
<name>Asual DZZD</name>
</organization>

<distributionManagement>
<repository>
<id>com.asual.repositories.releases</id>
<name>Asual Releases Repository</name>
<url>http://www.asual.com/maven/content/repositories/releases</url>
<id>internal</id>
<name>Ontotext Internal Repository</name>
<url>http://maven.ontotext.com/archiva/repository/internal</url>
</repository>
<snapshotRepository>
<id>com.asual.repositories.snapshots</id>
<name>Asual Snapshots Repository</name>
<url>http://www.asual.com/maven/content/repositories/snapshots</url>
<id>snapshots</id>
<name>Ontotext Snapshots Repository</name>
<url>http://maven.ontotext.com/archiva/repository/snapshots</url>
</snapshotRepository>
</distributionManagement>

Expand All @@ -58,7 +50,7 @@
<dependency>
<groupId>com.asual.lesscss</groupId>
<artifactId>lesscss-engine</artifactId>
<version>1.5.0-SNAPSHOT</version>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
Expand All @@ -84,7 +76,7 @@
<dependency>
<groupId>com.google.javascript</groupId>
<artifactId>closure-compiler</artifactId>
<version>rr2079.1</version>
<version>r1918</version>
<exclusions>
<exclusion>
<groupId>args4j</groupId>
Expand Down Expand Up @@ -124,10 +116,16 @@
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>8.1.2.v20120308</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>test-jetty-servlet</artifactId>
<version>8.1.5.v20120716</version>
<version>8.1.2.v20120308</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand All @@ -148,7 +146,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
Expand All @@ -157,17 +155,12 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9</version>
<version>2.4.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<version>2.1.2</version>
<configuration>
<attach>true</attach>
</configuration>
Expand All @@ -182,49 +175,35 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
<version>2.3.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.4</version>
<version>2.2.2</version>
<dependencies>
<dependency>
<groupId>com.google.code.maven-scm-provider-svnjava</groupId>
<artifactId>maven-scm-provider-svnjava</artifactId>
<version>2.0.5</version>
</dependency>
<dependency>
<groupId>org.tmatesoft.svnkit</groupId>
<artifactId>svnkit</artifactId>
<version>1.7.4-v1</version>
</dependency>
</dependencies>
<configuration>
<providerImplementations>
<svn>javasvn</svn>
</providerImplementations>
<autoVersionSubmodules>true</autoVersionSubmodules>
<goals>deploy</goals>
<tagBase>https://svn.ontotext.com/svn/forest/lesscss-servlet/tags</tagBase>
<tagNameFormat>lesscss-servlet-@{project.version}</tagNameFormat>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>release-sign-artifacts</id>
<activation>
<property>
<name>performRelease</name>
<value>true</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
53 changes: 36 additions & 17 deletions src/main/java/com/asual/lesscss/LessResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,49 +20,68 @@
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.servlet.ServletContext;

/**
* @author Rostislav Hristov
*/
public class LessResource extends StyleResource {

private final Log logger = LogFactory.getLog(getClass());
private LessEngine engine;

public LessResource(LessEngine engine, ServletContext servletContext,
String uri, String charset, boolean cache, boolean compress)
throws ResourceNotFoundException {

public LessResource(LessEngine engine, ServletContext servletContext, String uri, String charset, boolean cache, boolean compress) throws ResourceNotFoundException {
super(servletContext, uri, charset, cache, compress);
this.engine = engine;
}

public byte[] getContent() throws LessException, IOException {
if (content == null || !cache) {
if (content == null || (!cache && lastModified < getLastModified())) {
logger.debug("Not using cache.");
if (engine != null) {
logger.debug("LessEngine available, compiling.");
content = (resource instanceof URL ? engine
.compile((URL) resource) : engine
.compile((File) resource)).replaceAll("\\\\n", "\n")
.getBytes(charset);
content = (resource instanceof URL ?
engine.compile((URL) resource) : engine.compile((File) resource))
.replaceAll("\\\\n", "\n").getBytes(charset);
} else {
logger.debug("LessEngine not available, treating as regular resource.");
content = resource instanceof URL ? ResourceUtils.readTextUrl(
(URL) resource, charset) : ResourceUtils.readTextFile(
(File) resource, charset);
content = resource instanceof URL ? ResourceUtils.readTextUrl((URL) resource, charset) : ResourceUtils.readTextFile((File) resource, charset);
}
lastModified = super.getLastModified();
lastModified = getLastModified();
if (compress) {
logger.debug("Compressing resource.");
compress();
}
} else {
logger.debug("Using cache, since lastModified: " + lastModified
+ " and getLastModified: " + getLastModified());
logger.debug("Using cache, since lastModified: " + lastModified + " and getLastModified: " + getLastModified());
}
return content;
}

public long getLastModified() throws IOException {
if (lastModified == null || !cache) {
lastModified = super.getLastModified();
String content = new String(resource instanceof URL ? ResourceUtils.readTextUrl((URL) resource, charset) : ResourceUtils.readTextFile((File) resource, charset));
String folder = path.substring(0, path.lastIndexOf(System.getProperty("file.separator")) + 1);
Pattern p = Pattern.compile("@import\\s+(\"[^\"]*\"|'[^']*')");
Matcher m = p.matcher(content);
while (m.find()) {
String path = folder + m.group(1).replaceAll("\"|'", "");
File includedFile = new File(path);
if (!includedFile.exists()) {
includedFile = new File(path + ".less");
}
long importLastModified = includedFile.lastModified();
if (importLastModified > lastModified) {
lastModified = importLastModified;
}
}
}
logger.debug("getLastModified() in LessResource: " + lastModified);
return lastModified;
}

}
16 changes: 3 additions & 13 deletions src/main/java/com/asual/lesscss/LessServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ public class LessServlet extends ResourceServlet {
private final Log logger = LogFactory.getLog(getClass());

protected LessEngine engine;
protected boolean css;
protected String lineNumbers;

protected boolean css = false;

public void init() {
if (getServletConfig() != null) {
if (getInitParameter("charset") != null) {
Expand All @@ -45,9 +44,6 @@ public void init() {
if (getInitParameter("css") != null) {
css = Boolean.valueOf(getInitParameter("css"));
}
if (getInitParameter("lineNumbers") != null) {
lineNumbers = getInitParameter("lineNumbers");
}
}
try {
initialContext = new javax.naming.InitialContext();
Expand All @@ -67,15 +63,10 @@ public void init() {
if (getJndiParameter("/less/Css") != null) {
css = (Boolean) getJndiParameter("/less/Css");
}
if (getJndiParameter("/less/LineNumbers") != null) {
lineNumbers = (String) getJndiParameter("/less/LineNumbers");
}
}
LessOptions options = new LessOptions();
options.setCharset(charset);
options.setCss(css);
options.setLineNumbers(lineNumbers);
options.setOptimization(cache ? 3 : 0);
engine = new LessEngine(options);
}

Expand All @@ -84,8 +75,7 @@ protected Resource getResource(String uri) throws ResourceNotFoundException {
if (!resources.containsKey(uri)) {
logger.debug("Using new LessResource for uri " + uri);
if ("text/css".equals(mimeType)) {
resources.put(uri, new LessResource(engine,
getServletContext(), uri, charset, cache, compress));
resources.put(uri, new LessResource(engine, getServletContext(), uri, charset, cache, compress));
return resources.get(uri);
} else {
return super.getResource(uri);
Expand Down
Loading