private URL getUrl(File file) { try { return file.toURI().toURL(); } catch (MalformedURLException e) { throw new ArtifactDescriptorCreateException(format("There was an exception obtaining the URL for the service: [%s]", file.getAbsolutePath()), e); } }
private URL getUrl(File artifactFile, File file) { try { return file.toURI().toURL(); } catch (MalformedURLException e) { throw new ArtifactDescriptorCreateException(format("There was an exception obtaining the URL for the artifact [%s], file [%s]", artifactFile.getAbsolutePath(), file.getAbsolutePath()), e); } }
public static File lookupPomPropertiesMavenLocation(File artifactFolder) { File mulePropertiesPom = null; File lookupFolder = new File(artifactFolder, "META-INF" + separator + "maven"); while (lookupFolder != null && lookupFolder.exists()) { File possiblePomPropertiesLocation = new File(lookupFolder, MULE_POM_PROPERTIES); if (possiblePomPropertiesLocation.exists()) { mulePropertiesPom = possiblePomPropertiesLocation; break; } File[] directories = lookupFolder.listFiles((FileFilter) DIRECTORY); checkState(directories != null || directories.length == 0, format("No directories under %s so pom.properties file for artifact in folder %s could not be found", lookupFolder.getAbsolutePath(), artifactFolder.getAbsolutePath())); checkState(directories.length == 1, format("More than one directory under %s so pom.properties file for artifact in folder %s could not be found", lookupFolder.getAbsolutePath(), artifactFolder.getAbsolutePath())); lookupFolder = directories[0]; } // final File mulePropertiesPom = new File(artifactFolder, MULE_ARTIFACT_FOLDER + separator + MULE_PLUGIN_POM); if (mulePropertiesPom == null || !mulePropertiesPom.exists()) { throw new ArtifactDescriptorCreateException(format("The maven bundle loader requires the file pom.properties (error found while reading artifact '%s')", artifactFolder.getName())); } return mulePropertiesPom; }
public static File lookupPomFromMavenLocation(File artifactFolder) { File artifactPomFile = null; File lookupFolder = new File(artifactFolder, "META-INF" + separator + "maven"); while (lookupFolder != null && lookupFolder.exists()) { File possiblePomLocation = new File(lookupFolder, MULE_POM); if (possiblePomLocation.exists()) { artifactPomFile = possiblePomLocation; break; } File[] directories = lookupFolder.listFiles((FileFilter) DIRECTORY); checkState(directories != null || directories.length == 0, format("No directories under %s so pom.xml file for artifact in folder %s could not be found", lookupFolder.getAbsolutePath(), artifactFolder.getAbsolutePath())); checkState(directories.length == 1, format("More than one directory under %s so pom.xml file for artifact in folder %s could not be found", lookupFolder.getAbsolutePath(), artifactFolder.getAbsolutePath())); lookupFolder = directories[0]; } // final File artifactPomFile = new File(artifactFolder, MULE_ARTIFACT_FOLDER + separator + MULE_POM); if (artifactPomFile == null || !artifactPomFile.exists()) { throw new ArtifactDescriptorCreateException(format("The maven bundle loader requires the file pom.xml (error found while reading artifact '%s')", artifactFolder.getName())); } return artifactPomFile; }
protected M createArtifactModel(File artifactFolder) { final File artifactJsonFile = new File(artifactFolder, MULE_ARTIFACT_FOLDER + separator + getDescriptorFileName()); if (!artifactJsonFile.exists()) { throw new ArtifactDescriptorCreateException(ARTIFACT_DESCRIPTOR_DOES_NOT_EXISTS_ERROR + artifactJsonFile); } return loadModelFromJson(getDescriptorContent(artifactJsonFile)); }
/** * Returns the {@link Properties} with the content of {@code pom.properties} from a given artifact folder. * * @param artifactFolder folder containing the exploded artifact file. * @return the {@link Properties} from the {@value DeployableArtifactDescriptor#MULE_POM_PROPERTIES} file if available * @throws ArtifactDescriptorCreateException if the folder does not contain a {@value DeployableArtifactDescriptor#MULE_POM_PROPERTIES} * file or the file can' be loaded */ public static Properties getPomPropertiesFolder(File artifactFolder) { final File artifactPomProperties = lookupPomPropertiesMavenLocation(artifactFolder); Properties properties; try (InputStream artifactPomPropertiesInputStream = new FileInputStream(artifactPomProperties)) { properties = PropertiesUtils.loadProperties(artifactPomPropertiesInputStream); } catch (IOException e) { throw new ArtifactDescriptorCreateException(format("There was an issue reading '%s' for the artifact '%s'", artifactPomProperties.getName(), artifactFolder.getAbsolutePath()), e); } return properties; }
@Override public ArtifactPluginDescriptor create(File pluginJarFile, Optional<Properties> deploymentProperties) throws ArtifactDescriptorCreateException { try { checkArgument(pluginJarFile.isDirectory() || pluginJarFile.getName().endsWith(".jar"), "provided file is not a plugin: " + pluginJarFile.getAbsolutePath()); // Use / instead of File.separator as the file is going to be accessed inside the jar as a URL String mulePluginJsonPathInsideJarFile = MULE_ARTIFACT_PATH_INSIDE_JAR + "/" + MULE_ARTIFACT_JSON_DESCRIPTOR; Optional<byte[]> jsonDescriptorContentOptional = loadFileContentFrom(pluginJarFile, mulePluginJsonPathInsideJarFile); return jsonDescriptorContentOptional .map(jsonDescriptorContent -> loadFromJsonDescriptor(pluginJarFile, loadModelFromJson(new String(jsonDescriptorContent)), deploymentProperties)) .orElseThrow(() -> new ArtifactDescriptorCreateException(pluginDescriptorNotFound(pluginJarFile, mulePluginJsonPathInsideJarFile))); } catch (ArtifactDescriptorCreateException e) { throw e; } catch (IOException e) { throw new ArtifactDescriptorCreateException(e); } }
/** * Returns the {@link Properties} with the content of {@code pom.properties} from a given artifact jar file. * * @param artifactFile the artifact file to search for the pom file. * @return the {@link Properties} from the {@value DeployableArtifactDescriptor#MULE_POM_PROPERTIES} file if available * @throws ArtifactDescriptorCreateException if the folder does not contain a {@value DeployableArtifactDescriptor#MULE_POM_PROPERTIES} * file or the file can' be loaded */ public static Properties getPomPropertiesFromJar(File artifactFile) { String pomPropertiesFilePath = MULE_ARTIFACT_PATH_INSIDE_JAR + "/" + MULE_POM_PROPERTIES; try { return PropertiesUtils .loadProperties(new ByteArrayInputStream(loadFileContentFrom(getPomPropertiesUrlFromJar(artifactFile)).get())); } catch (IOException e) { throw new ArtifactDescriptorCreateException(format("There was an issue reading '%s' for the artifact '%s'", pomPropertiesFilePath, artifactFile.getAbsolutePath()), e); } }
/** * Returns the {@link Model} from a given artifact folder * * @param artifactFolder folder containing the exploded artifact file. * @return the {@link Model} from the {@value DeployableArtifactDescriptor#MULE_POM} file if available * @throws ArtifactDescriptorCreateException if the folder does not contain a {@value DeployableArtifactDescriptor#MULE_POM} * file or the file can' be loaded */ public static Model getPomModelFolder(File artifactFolder) { final File artifactPom = lookupPomFromMavenLocation(artifactFolder); MavenXpp3Reader reader = new MavenXpp3Reader(); Model model; try (FileReader artifactPomFileReader = new FileReader(artifactPom)) { model = reader.read(artifactPomFileReader); } catch (IOException | XmlPullParserException e) { throw new ArtifactDescriptorCreateException(format("There was an issue reading '%s' for the artifact '%s'", artifactPom.getName(), artifactFolder.getAbsolutePath()), e); } return model; }
/** * Returns the {@link Model} from a given artifact folder * * @param artifactFile file containing the artifact content. * @return the {@link Model} from the {@value ArtifactPluginDescriptor#MULE_PLUGIN_POM} file if available * @throws ArtifactDescriptorCreateException if the artifact jar does not contain a * {@value ArtifactPluginDescriptor#MULE_PLUGIN_POM} file or the file can' be loaded */ public static Model getPomModelFromJar(File artifactFile) { String pomFilePath = MULE_ARTIFACT_PATH_INSIDE_JAR + "/" + MULE_PLUGIN_POM; try { MavenXpp3Reader reader = new MavenXpp3Reader(); return reader.read(new ByteArrayInputStream(loadFileContentFrom(getPomUrlFromJar(artifactFile)).get())); } catch (IOException | XmlPullParserException e) { throw new ArtifactDescriptorCreateException(format("There was an issue reading '%s' for the artifact '%s'", pomFilePath, artifactFile.getAbsolutePath()), e); } }
private static URL lookMavenMetadataFileUrlFromJar(File artifactFile, String mavenMetadataFileName) { String mavenMetadataFilePath = MULE_ARTIFACT_PATH_INSIDE_JAR + "/" + mavenMetadataFileName; URL possibleUrl; try { possibleUrl = getUrlWithinJar(artifactFile, mavenMetadataFilePath); /* * A specific implementation of JarURLConnection is required to read jar content because not all implementations * support ways to disable connection caching. Disabling connection caching is necessary to avoid file descriptor leaks. */ JarURLConnection jarConnection = new sun.net.www.protocol.jar.JarURLConnection(possibleUrl, new sun.net.www.protocol.jar.Handler()); jarConnection.setUseCaches(false); try (InputStream ignored = jarConnection.getInputStream()) { return possibleUrl; } catch (Exception e) { List<URL> jarMavenUrls = getUrlsWithinJar(artifactFile, META_INF + "/" + "maven"); Optional<URL> mavenMetadataUrl = jarMavenUrls.stream().filter(url -> url.toString().endsWith(mavenMetadataFileName)).findAny(); if (!mavenMetadataUrl.isPresent()) { throw new ArtifactDescriptorCreateException(format("The identifier '%s' requires the file '%s' within the artifact(error found while reading artifact '%s')", artifactFile.getName(), mavenMetadataFileName, artifactFile.getAbsolutePath())); } return mavenMetadataUrl.get(); } } catch (IOException e) { throw new MuleRuntimeException(e); } }
public void includeAdditionalPluginDependencies() { if (deployableArtifactDescriptor != null) { deployableArtifactDescriptor.getClassLoaderModel().getDependencies().stream() .filter(bundleDescriptor -> bundleDescriptor.getDescriptor().isPlugin()) .filter(bundleDescriptor -> bundleDescriptor.getDescriptor().getGroupId() .equals(this.artifactBundleDescriptor.getGroupId()) && bundleDescriptor.getDescriptor().getArtifactId().equals(this.artifactBundleDescriptor.getArtifactId())) .filter(bundleDependency -> bundleDependency.getAdditionalDependencies() != null && !bundleDependency.getAdditionalDependencies().isEmpty()) .forEach( bundleDependency -> processPluginAdditionalDependenciesURIs(bundleDependency) .forEach(uri -> { try { containing(uri.toURL()); } catch (MalformedURLException e) { throw new ArtifactDescriptorCreateException( format("There was an exception obtaining the URL for the artifact [%s], file [%s]", artifactFolder.getAbsolutePath(), uri), e); } })); } }
private ClassLoaderModel getClassLoaderModel(File artifactFolder, Optional<Properties> deploymentProperties, MuleArtifactLoaderDescriptor classLoaderModelLoaderDescriptor, BundleDescriptor bundleDescriptor) { ClassLoaderModelLoader classLoaderModelLoader; try { classLoaderModelLoader = descriptorLoaderRepository.get(classLoaderModelLoaderDescriptor.getId(), getArtifactType(), ClassLoaderModelLoader.class); } catch (LoaderNotFoundException e) { throw new ArtifactDescriptorCreateException(invalidClassLoaderModelIdError(artifactFolder, classLoaderModelLoaderDescriptor)); } final ClassLoaderModel classLoaderModel; try { classLoaderModel = classLoaderModelLoader.load(artifactFolder, getClassLoaderModelAttributes(deploymentProperties, classLoaderModelLoaderDescriptor, bundleDescriptor), getArtifactType()); } catch (InvalidDescriptorLoaderException e) { throw new ArtifactDescriptorCreateException(e); } return classLoaderModel; }
private BundleDescriptor getBundleDescriptor(File appFolder, M artifactModel) { BundleDescriptorLoader bundleDescriptorLoader; try { bundleDescriptorLoader = descriptorLoaderRepository.get(artifactModel.getBundleDescriptorLoader().getId(), getArtifactType(), BundleDescriptorLoader.class); } catch (LoaderNotFoundException e) { throw new ArtifactDescriptorCreateException(invalidBundleDescriptorLoaderIdError(appFolder, artifactModel .getBundleDescriptorLoader())); } try { return bundleDescriptorLoader.load(appFolder, artifactModel.getBundleDescriptorLoader().getAttributes(), getArtifactType()); } catch (InvalidDescriptorLoaderException e) { throw new ArtifactDescriptorCreateException(e); } }
private URL getUrl(File file) { try { return file.toURI().toURL(); } catch (MalformedURLException e) { throw new ArtifactDescriptorCreateException(format("There was an exception obtaining the URL for the service: [%s]", file.getAbsolutePath()), e); } }
private URL getUrl(File pluginFile, File file) { try { return file.toURI().toURL(); } catch (MalformedURLException e) { throw new ArtifactDescriptorCreateException(format("There was an exception obtaining the URL for the plugin [%s], file [%s]", pluginFile.getAbsolutePath(), file.getAbsolutePath()), e); } }
public static File lookupPomFromMavenLocation(File artifactFolder) { File mulePluginPom = null; File lookupFolder = new File(artifactFolder, "META-INF" + separator + "maven"); while (lookupFolder != null && lookupFolder.exists()) { File possiblePomLocation = new File(lookupFolder, MULE_PLUGIN_POM); if (possiblePomLocation.exists()) { mulePluginPom = possiblePomLocation; break; } File[] directories = lookupFolder.listFiles((FileFilter) DIRECTORY); checkState(directories != null || directories.length == 0, format("No directories under %s so pom.xml file for artifact in folder %s could not be found", lookupFolder.getAbsolutePath(), artifactFolder.getAbsolutePath())); checkState(directories.length == 1, format("More than one directory under %s so pom.xml file for artifact in folder %s could not be found", lookupFolder.getAbsolutePath(), artifactFolder.getAbsolutePath())); lookupFolder = directories[0]; } // final File mulePluginPom = new File(artifactFolder, MULE_ARTIFACT_FOLDER + separator + MULE_PLUGIN_POM); if (mulePluginPom == null || !mulePluginPom.exists()) { throw new ArtifactDescriptorCreateException(format("The maven bundle loader requires the file pom.xml (error found while reading plugin '%s')", artifactFolder.getName())); } return mulePluginPom; }
protected M createArtifactModel(File artifactFolder) { final File artifactJsonFile = new File(artifactFolder, MULE_ARTIFACT_FOLDER + separator + getDescriptorFileName()); if (!artifactJsonFile.exists()) { throw new ArtifactDescriptorCreateException(ARTIFACT_DESCRIPTOR_DOES_NOT_EXISTS_ERROR + artifactJsonFile); } return loadModelFromJson(getDescriptorContent(artifactJsonFile)); }
/** * Finds the URL of the pom file within the artifact file. * * @param artifactFile the artifact file to search for the pom file. * @return the URL to the pom file. */ public static URL getPomUrlFromJar(File artifactFile) { String pomFilePath = MULE_ARTIFACT_PATH_INSIDE_JAR + "/" + MULE_PLUGIN_POM; URL possibleUrl; try { possibleUrl = getUrlWithinJar(artifactFile, pomFilePath); try (InputStream ignored = possibleUrl.openStream()) { return possibleUrl; } catch (Exception e) { List<URL> jarMavenUrls = getUrlsWithinJar(artifactFile, META_INF + "/" + "maven"); Optional<URL> pomUrl = jarMavenUrls.stream().filter(url -> url.toString().endsWith("pom.xml")).findAny(); if (!pomUrl.isPresent()) { throw new ArtifactDescriptorCreateException(format("The identifier '%s' requires the file '%s' within the artifact(error found while reading plugin '%s')", artifactFile.getName(), "pom.xml", artifactFile.getAbsolutePath())); } return pomUrl.get(); } } catch (IOException e) { throw new MuleRuntimeException(e); } }
@Override public ArtifactPluginDescriptor create(File pluginJarFile, Optional<Properties> deploymentProperties) throws ArtifactDescriptorCreateException { try { checkArgument(pluginJarFile.isDirectory() || pluginJarFile.getName().endsWith(".jar"), "provided file is not a plugin: " + pluginJarFile.getAbsolutePath()); // Use / instead of File.separator as the file is going to be accessed inside the jar as a URL String mulePluginJsonPathInsideJarFile = MULE_ARTIFACT_PATH_INSIDE_JAR + "/" + MULE_ARTIFACT_JSON_DESCRIPTOR; Optional<byte[]> jsonDescriptorContentOptional = loadFileContentFrom(pluginJarFile, mulePluginJsonPathInsideJarFile); return jsonDescriptorContentOptional .map(jsonDescriptorContent -> loadFromJsonDescriptor(pluginJarFile, loadModelFromJson(new String(jsonDescriptorContent)), deploymentProperties)) .orElseThrow(() -> new ArtifactDescriptorCreateException(pluginDescriptorNotFound(pluginJarFile, mulePluginJsonPathInsideJarFile))); } catch (ArtifactDescriptorCreateException e) { throw e; } catch (IOException e) { throw new ArtifactDescriptorCreateException(e); } }