Skip to content

Commit 483027f

Browse files
committed
Merge pull request #1 from jstrachan/master
added support for library files (.d.ts) along with a watch option to recompile files when they change
2 parents 40ef386 + aa121fd commit 483027f

File tree

4 files changed

+316
-59
lines changed

4 files changed

+316
-59
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ target
22
/.project
33
/.classpath
44
/.settings
5+
.idea
6+
*.iml
7+
*.ipr

pom.xml

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212

1313
<properties>
1414
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15-
</properties>
15+
<maven-version>2.0.9</maven-version>
16+
</properties>
1617

1718
<distributionManagement>
1819
<repository>
@@ -22,12 +23,20 @@
2223
</distributionManagement>
2324

2425
<dependencies>
25-
<dependency>
26-
<groupId>org.apache.maven</groupId>
27-
<artifactId>maven-plugin-api</artifactId>
28-
<version>2.0</version>
29-
</dependency>
30-
<dependency>
26+
<dependency>
27+
<groupId>org.apache.maven</groupId>
28+
<artifactId>maven-plugin-api</artifactId>
29+
<version>${maven-version}</version>
30+
<scope>provided</scope>
31+
</dependency>
32+
<dependency>
33+
<groupId>org.apache.maven</groupId>
34+
<artifactId>maven-project</artifactId>
35+
<version>${maven-version}</version>
36+
<scope>provided</scope>
37+
</dependency>
38+
39+
<dependency>
3140
<groupId>junit</groupId>
3241
<artifactId>junit</artifactId>
3342
<version>3.8.1</version>
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package com.ppedregal.typescript.maven;
2+
3+
import java.io.File;
4+
import java.util.ArrayList;
5+
import java.util.HashMap;
6+
import java.util.List;
7+
import java.util.Map;
8+
9+
import org.codehaus.plexus.util.DirectoryScanner;
10+
11+
public class FileSetChangeMonitor
12+
{
13+
private DirectoryScanner scanner = new DirectoryScanner();
14+
15+
private File baseDir;
16+
17+
private Map<String, File> fileCache = new HashMap<String, File>();
18+
private Map<String, Long> fileTimestamps = new HashMap<String, Long>();
19+
20+
public FileSetChangeMonitor(File baseDir, String includePattern) {
21+
this.baseDir = baseDir;
22+
23+
scanner.setBasedir( baseDir );
24+
scanner.setIncludes(new String[] { includePattern } );
25+
26+
for(String path : getPaths()) {
27+
rememberLastModifiedFor( path );
28+
}
29+
}
30+
31+
public List<String> getModifiedFilesSinceLastTimeIAsked() {
32+
List<String> modified = new ArrayList<String>();
33+
34+
for(String path : getPaths()) {
35+
if(hasBeenChangedSinceLastTimeIChecked(path)) {
36+
modified.add( path );
37+
}
38+
39+
rememberLastModifiedFor(path);
40+
}
41+
42+
return modified;
43+
}
44+
45+
private boolean hasSeen(String path) {
46+
return fileCache.containsKey( path );
47+
}
48+
49+
private boolean hasBeenChangedSinceLastTimeIChecked(String path) {
50+
return !hasSeen(path) || fileTimestamps.get( path ) < getLastModifiedFor( path );
51+
}
52+
53+
private void rememberLastModifiedFor(String path) {
54+
fileTimestamps.put( path, getLastModifiedFor(path) );
55+
}
56+
57+
private long getLastModifiedFor(String relativePath) {
58+
return fileFrom(relativePath).lastModified();
59+
}
60+
61+
private File fileFrom(String relativePath) {
62+
if(!fileCache.containsKey( relativePath )) {
63+
fileCache.put( relativePath, new File(baseDir, relativePath));
64+
}
65+
return fileCache.get( relativePath );
66+
}
67+
68+
private String[] getPaths() {
69+
scanner.scan();
70+
return scanner.getIncludedFiles();
71+
}
72+
}

0 commit comments

Comments
 (0)