Skip to content

Commit

Permalink
šŸµšŸ¶šŸ»
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsuter committed Jul 29, 2024
1 parent fc74324 commit 11b9a11
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,6 @@ private void writeDependencyIarJar(Collection<File> iarJarDepenencies) throws IO
return;
}
var jar = new SharedFile(project).getIarDependencyClasspathJar();
new ClasspathJar(jar.toFile()).createFileEntries(iarJarDepenencies);
new ClasspathJar(jar).createFileEntries(iarJarDepenencies);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private List<File> getDependencyIarJars() {
if (!Files.exists(iarJarClasspath)) {
return Collections.emptyList();
}
var iarJars = new ClasspathJar(iarJarClasspath.toFile()).getFiles();
var iarJars = new ClasspathJar(iarJarClasspath).getFiles();
return iarJars;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public void writeEngineClasspathJar(Path engineDirectory) throws IOException {
}

private void writeEngineClasspathJar(List<File> ivyEngineClassPathFiles) throws IOException {
File classPathJar = new SharedFile(maven.project).getEngineClasspathJar().toFile();
var classPathJar = new SharedFile(maven.project).getEngineClasspathJar();
ClasspathJar jar = new ClasspathJar(classPathJar);
jar.setMainClass("ch.ivyteam.ivy.server.ServerLauncher");
jar.createFileEntries(ivyEngineClassPathFiles);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private Path setupEngineClasspathJarIfNotExists() {
if (!Files.exists(classpathJar)) {
try {
log.info("Creating a classpath jar for starting the engine");
new ClasspathJar(classpathJar.toFile())
new ClasspathJar(classpathJar)
.createFileEntries(EngineClassLoaderFactory.getOsgiBootstrapClasspath(engineDirectory));
} catch (Exception ex) {
throw new RuntimeException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,6 @@ private void setTestOutputDirectory() {
}

private static String getClasspath(Path jar) {
return new ClasspathJar(jar.toFile()).getClasspathFiles();
return new ClasspathJar(jar).getClasspathFiles();
}
}
21 changes: 11 additions & 10 deletions src/main/java/ch/ivyteam/ivy/maven/util/ClasspathJar.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@

import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -44,11 +44,12 @@
* @since 6.0.2
*/
public class ClasspathJar {

private static final String MANIFEST_MF = "META-INF/MANIFEST.MF";
private final File jar;
private final Path jar;
private String mainClass;

public ClasspathJar(File jar) {
public ClasspathJar(Path jar) {
this.jar = jar;
}

Expand All @@ -57,10 +58,10 @@ public void setMainClass(String fqClassName) {
}

public void create(List<String> classpathEntries) throws IOException {
jar.getParentFile().mkdir();
try (ZipOutputStream zipStream = new ZipOutputStream(new FileOutputStream(jar))) {
String name = StringUtils.substringBeforeLast(jar.getName(), ".");
writeManifest(name, zipStream, classpathEntries);
Files.createDirectories(jar.getParent());
try (var out = new ZipOutputStream(Files.newOutputStream(jar))) {
String name = StringUtils.substringBeforeLast(jar.getFileName().toString(), ".");
writeManifest(name, out, classpathEntries);
}
}

Expand Down Expand Up @@ -115,8 +116,8 @@ private static String uriToAbsoluteFilePath(String entry) {
}

public String getClasspathUrlEntries() {
try (ZipInputStream is = new ZipInputStream(new FileInputStream(jar))) {
Manifest manifest = new Manifest(getInputStream(is, MANIFEST_MF));
try (var in = new ZipInputStream(Files.newInputStream(jar))) {
Manifest manifest = new Manifest(getInputStream(in, MANIFEST_MF));
return manifest.getMainAttributes().getValue(Attributes.Name.CLASS_PATH);
} catch (IOException ex) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ protected void before() throws Throwable {

private void provideClasspathJar() throws IOException {
var cpJar = new SharedFile(project).getEngineOSGiBootClasspathJar();
new ClasspathJar(cpJar.toFile()).createFileEntries(EngineClassLoaderFactory
new ClasspathJar(cpJar).createFileEntries(EngineClassLoaderFactory
.getOsgiBootstrapClasspath(installUpToDateEngineRule.getMojo().getRawEngineDirectory()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class TestClasspathJar {
void readWriteClasspath() throws IOException {
var jarFile = tempDir.resolve("my.jar");
Files.createFile(jarFile);
var jar = new ClasspathJar(jarFile.toFile());
var jar = new ClasspathJar(jarFile);
var content = tempDir.resolve("content.jar");
Files.createFile(content);
jar.createFileEntries(List.of(content.toFile()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ protected void before() throws Throwable {

private void writeTestClasspathJar() throws IOException {
var classPathJar = new SharedFile(getMojo().project).getEngineClasspathJar();
new ClasspathJar(classPathJar.toFile()).createFileEntries(List.of(
new ClasspathJar(classPathJar).createFileEntries(List.of(
Files.createTempFile("dummy", ".jar").toFile(),
Files.createTempFile("dummy2", ".jar").toFile()));
}
Expand Down

0 comments on commit 11b9a11

Please sign in to comment.