-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
10 changed files
with
146 additions
and
4 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,6 +1,2 @@ | ||
*.class | ||
|
||
# Package Files # | ||
*.jar | ||
*.war | ||
*.ear |
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,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> | ||
<classpathentry kind="lib" path="lib/ant-1.7.0-jar.jar" sourcepath="lib/ant-1.7.0-source.jar"/> | ||
<classpathentry kind="lib" path="lib/ant-launcher-1.7.0-jar.jar"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
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,3 @@ | ||
bin | ||
build | ||
|
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,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>merge-jar-services</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
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,11 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 | ||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | ||
org.eclipse.jdt.core.compiler.compliance=1.6 | ||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate | ||
org.eclipse.jdt.core.compiler.debug.localVariable=generate | ||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate | ||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||
org.eclipse.jdt.core.compiler.source=1.6 |
Binary file not shown.
Binary file not shown.
Binary file not shown.
103 changes: 103 additions & 0 deletions
103
merge-jar-services/src/org/pescuma/mergeservices/MergeServicesTask.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,103 @@ | ||
package org.pescuma.mergeservices; | ||
|
||
import java.io.Closeable; | ||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import java.util.ArrayList; | ||
import java.util.Enumeration; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.zip.ZipEntry; | ||
import java.util.zip.ZipFile; | ||
|
||
import org.apache.tools.ant.BuildException; | ||
import org.apache.tools.ant.DirectoryScanner; | ||
import org.apache.tools.ant.Task; | ||
import org.apache.tools.ant.types.FileSet; | ||
import org.apache.tools.ant.types.resources.FileResource; | ||
import org.apache.tools.ant.types.resources.FileResourceIterator; | ||
|
||
public class MergeServicesTask extends Task { | ||
|
||
private File dest; | ||
private final List<FileSet> filesets = new ArrayList<FileSet>(); | ||
|
||
public void setDest(File dest) { | ||
this.dest = dest; | ||
} | ||
|
||
public void addFileset(FileSet set) { | ||
filesets.add(set); | ||
} | ||
|
||
@Override | ||
public void execute() throws BuildException { | ||
for (FileSet fileSet : filesets) { | ||
process(fileSet); | ||
} | ||
} | ||
|
||
private void process(FileSet fileSet) { | ||
DirectoryScanner ds = fileSet.getDirectoryScanner(); | ||
Iterator<?> iter = new FileResourceIterator(fileSet.getDir(), ds.getIncludedFiles()); | ||
|
||
while (iter.hasNext()) { | ||
FileResource resource = (FileResource) iter.next(); | ||
process(resource.getFile()); | ||
} | ||
|
||
} | ||
|
||
private void process(File file) { | ||
try { | ||
|
||
ZipFile zip = new ZipFile(file); | ||
for (Enumeration<? extends ZipEntry> e = zip.entries(); e.hasMoreElements();) { | ||
ZipEntry entry = e.nextElement(); | ||
if (!entry.isDirectory() && entry.getName().startsWith("META-INF/services/")) | ||
process(zip, entry); | ||
} | ||
|
||
} catch (IOException e) { | ||
throw new BuildException(e); | ||
} | ||
} | ||
|
||
private void process(ZipFile zip, ZipEntry entry) throws IOException { | ||
File result = new File(dest, entry.getName()); | ||
|
||
if (!result.getParentFile().exists() && !result.getParentFile().mkdirs()) | ||
throw new BuildException("Could not create dir " + result.getParent()); | ||
|
||
InputStream in = null; | ||
OutputStream out = null; | ||
try { | ||
|
||
in = zip.getInputStream(entry); | ||
out = new FileOutputStream(result, true); | ||
|
||
byte[] buf = new byte[1024]; | ||
int len; | ||
while ((len = in.read(buf)) > 0) | ||
out.write(buf, 0, len); | ||
|
||
} finally { | ||
close(out); | ||
close(in); | ||
} | ||
} | ||
|
||
private void close(Closeable writer) { | ||
try { | ||
|
||
if (writer != null) | ||
writer.close(); | ||
|
||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
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,4 @@ | ||
<?xml version="1.0"?> | ||
<antlib> | ||
<typedef name="merge-services" classname="org.pescuma.mergeservices.MergeServicesTask" /> | ||
</antlib> |