public GoPluginBundleDescriptor build(BundleOrPluginFileDetails bundleOrPluginJarFile) {
        if (!bundleOrPluginJarFile.exists()) {
            throw new RuntimeException(format("Plugin or bundle jar does not exist: %s", bundleOrPluginJarFile.file()));
        }

        String defaultId = bundleOrPluginJarFile.file().getName();
        GoPluginBundleDescriptor goPluginBundleDescriptor = new GoPluginBundleDescriptor(GoPluginDescriptor.builder()
                .version("1")
                .id(defaultId)
                .bundleLocation(bundleOrPluginJarFile.extractionLocation())
                .pluginJarFileLocation(bundleOrPluginJarFile.file().getAbsolutePath())
                .isBundledPlugin(bundleOrPluginJarFile.isBundledPlugin())
                .build());

        try {
            if (bundleOrPluginJarFile.isBundleJar()) {
                return GoPluginBundleDescriptorParser.parseXML(bundleOrPluginJarFile.getBundleXml(), bundleOrPluginJarFile);
            }

            if (bundleOrPluginJarFile.isPluginJar()) {
                return GoPluginDescriptorParser.parseXML(bundleOrPluginJarFile.getPluginXml(), bundleOrPluginJarFile);
            }

            goPluginBundleDescriptor.markAsInvalid(List.of(format("Plugin with ID (%s) is not valid. The plugin does not seem to contain plugin.xml or gocd-bundle.xml", defaultId)), new RuntimeException("The plugin does not seem to contain plugin.xml or gocd-bundle.xml"));
        } catch (Exception e) {
            log.warn("Unable to load the jar file {}", bundleOrPluginJarFile.file(), e);
            final String message = requireNonNullElse(e.getMessage(), e.getClass().getCanonicalName());
            String cause = e.getCause() != null ? format("%s. Cause: %s", message, e.getCause().getMessage()) : message;
            goPluginBundleDescriptor.markAsInvalid(List.of(format("Plugin with ID (%s) is not valid: %s", defaultId, cause)), e);
        }

        return goPluginBundleDescriptor;
    }
@Test
    void shouldCreateInvalidPluginDescriptorEvenIfPluginXMLIsNotFound() throws Exception {
        String pluginJarName = "descriptor-aware-test-plugin-with-no-plugin-xml.jar";
        copyPluginToThePluginDirectory(pluginDirectory, pluginJarName);
        File pluginJarFile = new File(pluginDirectory, pluginJarName);
        BundleOrPluginFileDetails bundleOrPluginFileDetails = new BundleOrPluginFileDetails(pluginJarFile, true, pluginDirectory);

        final GoPluginBundleDescriptor bundleDescriptor = goPluginBundleDescriptorBuilder.build(bundleOrPluginFileDetails);

        final List<GoPluginDescriptor> descriptors = bundleDescriptor.descriptors();
        assertThat(descriptors.size()).isEqualTo(1);
        assertThat(descriptors.get(0).isInvalid()).isTrue();
        assertThat(descriptors.get(0).id()).isEqualTo(pluginJarName);
    }