Skip to content

Commit

Permalink
Merge pull request #304 from emmartins/CMTOOL-358
Browse files Browse the repository at this point in the history
[CMTOOL-358] fixes EAP 8.0 GA server detection
  • Loading branch information
emmartins committed Jan 16, 2024
2 parents 94297b4 + 657b995 commit 588bcfe
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,12 @@ private ManifestProductInfo(String name, String version) {
}

/**
* Retrieves the product info from the specified's manifest inputstream.
* @param inputStream the inputstream to read the manifest file
* @return the product info from the specified's manifest inputstream
* Retrieves the product info from the specified manifest.
* @param manifest the manifest file
* @return the product info from the specified manifest inputstream
* @throws ServerMigrationFailureException if there is an error reading the manifest input stream
*/
public static ManifestProductInfo from(InputStream inputStream) throws ServerMigrationFailureException {
final Manifest manifest;
try {
manifest = new Manifest(inputStream);
} catch (IOException e) {
throw new ServerMigrationFailureException("MANIFEST load failure.", e);
}
public static ManifestProductInfo from(Manifest manifest) throws ServerMigrationFailureException {
final String productName = manifest.getMainAttributes().getValue("JBoss-Product-Release-Name");
if (productName == null) {
throw new IllegalArgumentException();
Expand All @@ -57,6 +51,20 @@ public static ManifestProductInfo from(InputStream inputStream) throws ServerMig
return new ManifestProductInfo(productName.trim(), productVersion.trim());
}

/**
* Retrieves the product info from the specified's manifest inputstream.
* @param inputStream the inputstream to read the manifest file
* @return the product info from the specified's manifest inputstream
* @throws ServerMigrationFailureException if there is an error reading the manifest input stream
*/
public static ManifestProductInfo from(InputStream inputStream) throws ServerMigrationFailureException {
try {
return from(new Manifest(inputStream));
} catch (IOException e) {
throw new ServerMigrationFailureException("MANIFEST stream load failure.", e);
}
}

/**
* Retrieves the product info from the specified's manifest file path.
* @param path the path pointing to the manifest file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
import org.jboss.migration.core.jboss.JBossServer;
import org.jboss.migration.core.jboss.ManifestProductInfo;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.jar.JarInputStream;

/**
* The JBoss EAP 8.0 {@link org.jboss.migration.core.ServerProvider}.
Expand All @@ -37,9 +39,18 @@ protected ProductInfo getProductInfo(Path baseDir, MigrationEnvironment migratio
if (module == null) {
return null;
}
final Path manifestPath = module.getModuleDir().resolve("dir").resolve("META-INF").resolve("MANIFEST.MF");
final ManifestProductInfo productInfo = ManifestProductInfo.from(manifestPath);
return productInfo;
// Starting with EAP 8.0 GA, manifest is inside the module's jar
try {
Path moduleJar = Files.list(module.getModuleDir()).filter(path -> path.toString().endsWith(".jar")).findFirst().get();
if (moduleJar == null || !Files.isRegularFile(moduleJar)) {
return null;
}
try (JarInputStream jarStream = new JarInputStream(Files.newInputStream(moduleJar))) {
return ManifestProductInfo.from(jarStream.getManifest());
}
} catch (IOException e) {
throw new ServerMigrationFailureException(e);
}
}

@Override
Expand Down

0 comments on commit 588bcfe

Please sign in to comment.