Skip to content
This repository has been archived by the owner on Jan 9, 2019. It is now read-only.

bug fix with absolute uri IMPORT #47

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 16 additions & 1 deletion src/main/java/org/lesscss/FileResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,20 @@ 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!");
}
this.file = file;
}

public FileResource(File sourceDirectory,File file) {
this(file);
this.sourceDirectory=sourceDirectory;
}
public boolean exists() {
return file.exists();
}
Expand All @@ -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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it backwards compatible, if the constructor is invoked without the sourceDirectory?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oups i missed a test condition for this case :( sorry

}else
{
relativeFile = new File(file.getParentFile(), relativePath);
}
return new FileResource(relativeFile);
}

Expand Down
6 changes: 5 additions & 1 deletion src/main/java/org/lesscss/LessSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down