diff --git a/core/src/main/java/org/jboss/migration/core/jboss/ManifestProductInfo.java b/core/src/main/java/org/jboss/migration/core/jboss/ManifestProductInfo.java index 9e904b7af..ff88434ba 100644 --- a/core/src/main/java/org/jboss/migration/core/jboss/ManifestProductInfo.java +++ b/core/src/main/java/org/jboss/migration/core/jboss/ManifestProductInfo.java @@ -34,17 +34,29 @@ private ManifestProductInfo(String name, String version) { } /** - * Retrieves the product info from the specified manifest. + * Retrieves the product info from the specified manifest, with default attr names "JBoss-Product-Release-Name","JBoss-Product-Release-Version". * @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(Manifest manifest) throws ServerMigrationFailureException { - final String productName = manifest.getMainAttributes().getValue("JBoss-Product-Release-Name"); + return from(manifest, "JBoss-Product-Release-Name","JBoss-Product-Release-Version"); + } + + /** + * Retrieves the product info from the specified manifest, from attributes with the specified prefix. + * @param manifest the manifest file + * @param productNameAttr the product name's attribute name + * @param productVersionAttr the product version's attribute name + * @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(Manifest manifest, String productNameAttr, String productVersionAttr) throws ServerMigrationFailureException { + final String productName = manifest.getMainAttributes().getValue(productNameAttr); if (productName == null) { throw new IllegalArgumentException(); } - final String productVersion = manifest.getMainAttributes().getValue("JBoss-Product-Release-Version"); + final String productVersion = manifest.getMainAttributes().getValue(productVersionAttr); if (productVersion == null) { throw new IllegalArgumentException(); } diff --git a/servers/eap8.0/src/main/java/org/jboss/migration/eap/EAPServerProvider8_0.java b/servers/eap8.0/src/main/java/org/jboss/migration/eap/EAPServerProvider8_0.java index 5d999d520..608c237a9 100644 --- a/servers/eap8.0/src/main/java/org/jboss/migration/eap/EAPServerProvider8_0.java +++ b/servers/eap8.0/src/main/java/org/jboss/migration/eap/EAPServerProvider8_0.java @@ -55,23 +55,31 @@ protected ProductInfo getProductInfo(Path baseDir, MigrationEnvironment migratio @Override protected String getProductVersionRegex() { - return "8.0\\..*"; + return "8\\.0.*"; } @Override protected Server constructServer(String migrationName, ProductInfo productInfo, Path baseDir, MigrationEnvironment migrationEnvironment) { - return isXp(baseDir) ? new EAPXPServer8_0(migrationName, new ProductInfo("JBoss EAP XP", productInfo.getVersion()), baseDir, migrationEnvironment) : new EAPServer8_0(migrationName, productInfo, baseDir, migrationEnvironment); + final ManifestProductInfo xpManifestProductInfo = getXpManifestProductInfo(baseDir); + return xpManifestProductInfo != null ? new EAPXPServer8_0(migrationName, new ProductInfo("JBoss EAP XP", xpManifestProductInfo.getVersion()), baseDir, migrationEnvironment) : new EAPServer8_0(migrationName, productInfo, baseDir, migrationEnvironment); } - protected boolean isXp(Path baseDir) { - if (Files.exists(baseDir.resolve(".installation").resolve("jboss-eap-xp-5.0.conf"))) { - return true; + protected ManifestProductInfo getXpManifestProductInfo(Path baseDir) { + final JBossServer.Module module = new JBossServer.Modules(baseDir).getModule("org.jboss.eap.expansion.pack:main"); + if (module == null) { + return null; } - // fallback for internal XP builds - if (Files.isDirectory(baseDir.resolve("modules").resolve("system").resolve("layers").resolve("microprofile").resolve("org").resolve("wildfly").resolve("extension").resolve("microprofile"))) { - return true; + 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(), "Implementation-Title", "Implementation-Version"); + } + } catch (IOException e) { + throw new ServerMigrationFailureException(e); } - return false; } @Override