From d6ac13eedade56325db2e17bd7ae439935fc1037 Mon Sep 17 00:00:00 2001 From: "marco.semiao" Date: Fri, 25 Apr 2014 17:26:21 +0200 Subject: [PATCH 1/4] bug fix with absolute uri IMPORT exemple : @import "/less/styles_variables.less"; if the source file is not present into root directory --- src/main/java/org/lesscss/FileResource.java | 17 ++++++++++++++++- src/main/java/org/lesscss/LessSource.java | 6 +++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/lesscss/FileResource.java b/src/main/java/org/lesscss/FileResource.java index 5de1ce1..7eacf05 100644 --- a/src/main/java/org/lesscss/FileResource.java +++ b/src/main/java/org/lesscss/FileResource.java @@ -14,6 +14,9 @@ public class FileResource implements Resource { private File file; + private File sourceDirectory; + + public FileResource(File file) { if (file == null) { throw new IllegalArgumentException("File must not be null!"); @@ -21,6 +24,10 @@ public FileResource(File file) { this.file = file; } + public FileResource(File sourceDirectory,File file) { + this(file); + this.sourceDirectory=sourceDirectory; + } public boolean exists() { return file.exists(); } @@ -34,7 +41,15 @@ public long lastModified() { } public Resource createRelative(String relativePath) { - File relativeFile = new File(file.getParentFile(), relativePath); + + File relativeFile; + if (relativePath.startsWith("/")) + { + relativeFile = new File(sourceDirectory, relativePath); + }else + { + relativeFile = new File(file.getParentFile(), relativePath); + } return new FileResource(relativeFile); } diff --git a/src/main/java/org/lesscss/LessSource.java b/src/main/java/org/lesscss/LessSource.java index 30b6f98..a7e4ef5 100644 --- a/src/main/java/org/lesscss/LessSource.java +++ b/src/main/java/org/lesscss/LessSource.java @@ -100,7 +100,11 @@ public LessSource(Resource resource, Charset charset) throws IOException { public LessSource(File input) throws IOException { this( new FileResource(input) ); } - + + public LessSource(File sourceDirectory, File input) throws IOException { + this( new FileResource(sourceDirectory, input) ); + } + private String loadResource(Resource resource, Charset charset) throws IOException { BOMInputStream inputStream = new BOMInputStream( resource.getInputStream() ); try { From 91b36f40944f9b62dcaf38cbd668de354257c62d Mon Sep 17 00:00:00 2001 From: Marco Semiao Date: Mon, 5 May 2014 09:59:28 +0200 Subject: [PATCH 2/4] bug fix with absolute uri IMPORT --- src/main/java/org/lesscss/FileResource.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/lesscss/FileResource.java b/src/main/java/org/lesscss/FileResource.java index 7eacf05..1355056 100644 --- a/src/main/java/org/lesscss/FileResource.java +++ b/src/main/java/org/lesscss/FileResource.java @@ -43,7 +43,7 @@ public long lastModified() { public Resource createRelative(String relativePath) { File relativeFile; - if (relativePath.startsWith("/")) + if (sourceDirectory != null && relativePath.startsWith("/")) { relativeFile = new File(sourceDirectory, relativePath); }else From 50c6d06bb21881c6df6fd28f42822934fbc44f6d Mon Sep 17 00:00:00 2001 From: Marco Semiao Date: Fri, 16 May 2014 16:43:21 +0200 Subject: [PATCH 3/4] buf fix with many recursive absolute path --- src/main/java/org/lesscss/FileResource.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/lesscss/FileResource.java b/src/main/java/org/lesscss/FileResource.java index 1355056..6dd4bd9 100644 --- a/src/main/java/org/lesscss/FileResource.java +++ b/src/main/java/org/lesscss/FileResource.java @@ -46,11 +46,12 @@ public Resource createRelative(String relativePath) { if (sourceDirectory != null && relativePath.startsWith("/")) { relativeFile = new File(sourceDirectory, relativePath); + return new FileResource(sourceDirectory, relativeFile); }else { relativeFile = new File(file.getParentFile(), relativePath); + return new FileResource(relativeFile); } - return new FileResource(relativeFile); } @Override From e1e1ed18c9e463fff91feb23e3c706af6b03d67f Mon Sep 17 00:00:00 2001 From: Marco Semiao Date: Wed, 2 Jul 2014 17:05:44 +0200 Subject: [PATCH 4/4] correct test with new constructor LessSource (sourceDirectory) --- src/main/java/org/lesscss/FileResource.java | 83 +++++++++++---------- 1 file changed, 42 insertions(+), 41 deletions(-) diff --git a/src/main/java/org/lesscss/FileResource.java b/src/main/java/org/lesscss/FileResource.java index 6dd4bd9..2c21a71 100644 --- a/src/main/java/org/lesscss/FileResource.java +++ b/src/main/java/org/lesscss/FileResource.java @@ -7,59 +7,60 @@ /** * File based implementation of {@link Resource}. - * + * * @author Anton Pechinsky */ public class FileResource implements Resource { - private File file; + private final File file; - private File sourceDirectory; - - - public FileResource(File file) { - if (file == null) { - throw new IllegalArgumentException("File must not be null!"); - } - this.file = file; - } + private File sourceDirectory; - public FileResource(File sourceDirectory,File file) { - this(file); - this.sourceDirectory=sourceDirectory; - } - public boolean exists() { - return file.exists(); + public FileResource(File file) { + if (file == null) { + throw new IllegalArgumentException("File must not be null!"); } + this.file = file; + } - public InputStream getInputStream() throws IOException { - return new FileInputStream(file); + public FileResource(File sourceDirectory, File file) { + this(file); + if (sourceDirectory == null) { + throw new IllegalArgumentException("sourceDirectory must not be null!"); } + this.sourceDirectory = sourceDirectory; + } - public long lastModified() { - return file.lastModified(); - } + public boolean exists() { + return file.exists(); + } - public Resource createRelative(String relativePath) { - - File relativeFile; - if (sourceDirectory != null && relativePath.startsWith("/")) - { - relativeFile = new File(sourceDirectory, relativePath); - return new FileResource(sourceDirectory, relativeFile); - }else - { - relativeFile = new File(file.getParentFile(), relativePath); - return new FileResource(relativeFile); - } - } + public InputStream getInputStream() throws IOException { + return new FileInputStream(file); + } - @Override - public String toString() { - return file.getAbsolutePath(); - } + public long lastModified() { + return file.lastModified(); + } + + public Resource createRelative(String relativePath) { - public String getName() { - return file.getAbsolutePath(); + File relativeFile; + if (sourceDirectory != null && relativePath.startsWith("/")) { + relativeFile = new File(sourceDirectory, relativePath); + return new FileResource(sourceDirectory, relativeFile); + } else { + relativeFile = new File(file.getParentFile(), relativePath); + return new FileResource(relativeFile); } + } + + @Override + public String toString() { + return file.getAbsolutePath(); + } + + public String getName() { + return file.getAbsolutePath(); + } }