Skip to content
This repository was 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 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
67 changes: 42 additions & 25 deletions src/main/java/org/lesscss/FileResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,60 @@

/**
* File based implementation of {@link Resource}.
*
*
* @author Anton Pechinsky
*/
public class FileResource implements Resource {

private File file;
private final File file;

public FileResource(File file) {
if (file == null) {
throw new IllegalArgumentException("File must not be null!");
}
this.file = file;
}
private File 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 = 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 String getName() {
return file.getAbsolutePath();
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);
}
}

@Override
public String toString() {
return file.getAbsolutePath();
}

public String getName() {
return file.getAbsolutePath();
}
}
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