-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e8301f1
commit c7f9172
Showing
4 changed files
with
174 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,9 @@ | ||
<<<<<<< HEAD | ||
.classpath | ||
.project | ||
.settings/ | ||
branch.sh | ||
release.sh | ||
sign-and-deploy.sh | ||
|
||
======= | ||
/target/ | ||
>>>>>>> bf958dd87dd0dcd79c32815f3cdbafbfc8f350a5 | ||
/issue47.txt | ||
target/ | ||
issue47.txt | ||
pom.xml.versionsBackup |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
src/main/java/org/bsc/maven/plugin/processor/ZipFileObject.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package org.bsc.maven.plugin.processor; | ||
|
||
import javax.tools.JavaFileObject; | ||
import javax.tools.SimpleJavaFileObject; | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.io.Reader; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.util.zip.ZipEntry; | ||
import java.util.zip.ZipFile; | ||
|
||
/** | ||
* | ||
* @author Heiko Braun | ||
*/ | ||
public class ZipFileObject extends SimpleJavaFileObject | ||
{ | ||
private ZipEntry zipEntry; | ||
private ZipFile zipFile; | ||
|
||
public ZipFileObject(ZipFile zipFile, ZipEntry zipEntry, URI uri) | ||
{ | ||
super(uri, JavaFileObject.Kind.SOURCE); | ||
this.zipEntry = zipEntry; | ||
this.zipFile = zipFile; | ||
} | ||
|
||
@Override | ||
public InputStream openInputStream() throws IOException | ||
{ | ||
return this.zipFile.getInputStream(this.zipEntry); | ||
} | ||
|
||
@Override | ||
public String getName() | ||
{ | ||
return this.zipEntry.getName(); | ||
} | ||
|
||
@Override | ||
public CharSequence getCharContent(boolean b) | ||
throws IOException | ||
{ | ||
InputStreamReader is = new InputStreamReader(openInputStream()); | ||
StringBuilder sb = new StringBuilder(); | ||
BufferedReader br = new BufferedReader(is); | ||
String read = br.readLine(); | ||
|
||
while (read != null) { | ||
sb.append(read).append("\n"); | ||
read = br.readLine(); | ||
} | ||
|
||
return sb.toString(); | ||
} | ||
|
||
@Override | ||
public Reader openReader(boolean b) throws IOException | ||
{ | ||
return new BufferedReader(new InputStreamReader(openInputStream())); | ||
} | ||
|
||
@Override | ||
public long getLastModified() | ||
{ | ||
return this.zipEntry.getTime(); | ||
} | ||
|
||
public static ZipFileObject create(ZipFile zipFile, ZipEntry entry) { | ||
try { | ||
final String uri = String.format("jar://%s!%s", zipFile.getName(), entry.getName() ); | ||
return new ZipFileObject(zipFile, entry, new URI(uri)); | ||
} | ||
catch (URISyntaxException e) | ||
{ | ||
throw new RuntimeException("Invalid zip entry:" + e.getMessage()); | ||
} | ||
} | ||
} |