/** * Find the plugin artifact in the local .m2 directory. * @param m2Dir the maven m2 directory * @param coordinates the coordinates * @return the M2 path */ public static File getM2Path(File m2Dir, PluginCoordinates coordinates) { String artifactSubPath = getMavenPath(coordinates); return new File(m2Dir, artifactSubPath); }
/** * A valid set of remove maven repository URLs. */ protected Set<URI> getMavenRepositories() { return PluginUtils.getDefaultMavenRepositories(); }
public Future<IAsyncResult<Plugin>> loadPlugin(final PluginCoordinates coordinates, final IAsyncResultHandler<Plugin> userHandler) { final PluginFuture future = new PluginFuture(); final boolean isSnapshot = PluginUtils.isSnapshot(coordinates); String pluginRelativePath = PluginUtils.getPluginRelativePath(coordinates); File pluginDir = new File(pluginsDir, pluginRelativePath); if (!pluginDir.exists()) { File m2Dir = PluginUtils.getUserM2Repository(); if (m2Dir != null) { File artifactFile = PluginUtils.getM2Path(m2Dir, coordinates); if (artifactFile.isFile()) { handled = true; } else { try { String pluginRelativePath1 = PluginUtils.getPluginRelativePath(coordinates); File pluginDir1 = new File(pluginsDir, pluginRelativePath1); if (!pluginDir1.exists()) {
boolean isSnapshot = PluginUtils.isSnapshot(coordinates); synchronized (mutex) { if (pluginCache.containsKey(coordinates)) { String pluginRelativePath = PluginUtils.getPluginRelativePath(coordinates); File pluginDir = new File(pluginsDir, pluginRelativePath); if (!pluginDir.exists()) { PluginSpec spec = PluginUtils.readPluginSpecFile(specFile); Plugin plugin = new Plugin(spec, coordinates, pluginClassLoader); pluginCache.put(coordinates, plugin);
/** * Downloads the plugin via its maven GAV information. This will first look in the local * .m2 directory. If the plugin is not found there, then it will try to download the * plugin from one of the configured remote maven repositories. */ protected void downloadPlugin(File pluginFile, PluginCoordinates coordinates) { // First check the .m2 directory File m2Dir = PluginUtils.getUserM2Repository(); if (m2Dir != null) { File artifactFile = PluginUtils.getM2Path(m2Dir, coordinates); if (artifactFile.isFile()) { try { FileUtils.copyFile(artifactFile, pluginFile); return; } catch (IOException e) { artifactFile.delete(); throw new RuntimeException(e); } } } // Didn't find it in .m2, so try downloading it. Set<URI> repositories = getMavenRepositories(); for (URI mavenRepoUrl : repositories) { if (downloadFromMavenRepo(pluginFile, coordinates, mavenRepoUrl)) { return; } } }
bean.getClassifier(), bean.getType()); boolean isSnapshot = PluginUtils.isSnapshot(coordinates); if (isSnapshot) { log.debug("Loading a snapshot version of plugin: " + coordinates); //$NON-NLS-1$
/** * Reads the plugin into an object. This method will fail if the plugin is not valid. * This could happen if the file is not a java archive, or if the plugin spec file is * missing from the archive, etc. */ protected Plugin readPluginFile(PluginCoordinates coordinates, File pluginFile) throws Exception { try { PluginClassLoader pluginClassLoader = createPluginClassLoader(pluginFile); URL specFile = pluginClassLoader.getResource(PluginUtils.PLUGIN_SPEC_PATH); if (specFile == null) { throw new Exception(Messages.i18n.format("DefaultPluginRegistry.MissingPluginSpecFile", PluginUtils.PLUGIN_SPEC_PATH)); //$NON-NLS-1$ } else { PluginSpec spec = PluginUtils.readPluginSpecFile(specFile); Plugin plugin = new Plugin(spec, coordinates, pluginClassLoader); // TODO use logger when available System.out.println("Read apiman plugin: " + spec); //$NON-NLS-1$ return plugin; } } catch (Exception e) { throw new Exception(Messages.i18n.format("DefaultPluginRegistry.InvalidPlugin", pluginFile.getAbsolutePath()), e); //$NON-NLS-1$ } }
public Future<IAsyncResult<Plugin>> loadPlugin(final PluginCoordinates coordinates, final IAsyncResultHandler<Plugin> userHandler) { final PluginFuture future = new PluginFuture(); final boolean isSnapshot = PluginUtils.isSnapshot(coordinates); String pluginRelativePath = PluginUtils.getPluginRelativePath(coordinates); File pluginDir = new File(pluginsDir, pluginRelativePath); if (!pluginDir.exists()) { File m2Dir = PluginUtils.getUserM2Repository(); if (m2Dir != null) { File artifactFile = PluginUtils.getM2Path(m2Dir, coordinates); if (artifactFile.isFile()) { handled = true; } else { try { String pluginRelativePath1 = PluginUtils.getPluginRelativePath(coordinates); File pluginDir1 = new File(pluginsDir, pluginRelativePath1); if (!pluginDir1.exists()) {
bean.getClassifier(), bean.getType()); boolean isSnapshot = PluginUtils.isSnapshot(coordinates); if (isSnapshot) { log.debug("Loading a snapshot version of plugin: " + coordinates); //$NON-NLS-1$
/** * Reads the plugin into an object. This method will fail if the plugin is not valid. * This could happen if the file is not a java archive, or if the plugin spec file is * missing from the archive, etc. */ protected Plugin readPluginFile(PluginCoordinates coordinates, File pluginFile) throws Exception { try { PluginClassLoader pluginClassLoader = createPluginClassLoader(pluginFile); URL specFile = pluginClassLoader.getResource(PluginUtils.PLUGIN_SPEC_PATH); if (specFile == null) { throw new Exception(Messages.i18n.format("DefaultPluginRegistry.MissingPluginSpecFile", PluginUtils.PLUGIN_SPEC_PATH)); //$NON-NLS-1$ } else { PluginSpec spec = PluginUtils.readPluginSpecFile(specFile); Plugin plugin = new Plugin(spec, coordinates, pluginClassLoader); // TODO use logger when available System.out.println("Read apiman plugin: " + spec); //$NON-NLS-1$ return plugin; } } catch (Exception e) { throw new Exception(Messages.i18n.format("DefaultPluginRegistry.InvalidPlugin", pluginFile.getAbsolutePath()), e); //$NON-NLS-1$ } }
/** * Find the plugin artifact in the local .m2 directory. * @param m2Dir the maven m2 directory * @param coordinates the coordinates * @return the M2 path */ public static File getM2Path(File m2Dir, PluginCoordinates coordinates) { String artifactSubPath = getMavenPath(coordinates); return new File(m2Dir, artifactSubPath); }
/** * Constructor. * @param pluginsDir the plugins directory */ public DefaultPluginRegistry(File pluginsDir) { this(pluginsDir, PluginUtils.getDefaultMavenRepositories()); }
/** * @see io.apiman.manager.api.core.plugin.AbstractPluginRegistry#downloadPlugin(java.io.File, io.apiman.common.plugin.PluginCoordinates) */ @Override protected void downloadPlugin(File pluginFile, PluginCoordinates coordinates) { String testM2Path = System.getProperty("apiman.test.m2-path"); //$NON-NLS-1$ if (testM2Path == null) { return; } File testM2Dir = new File(testM2Path).getAbsoluteFile(); File pluginArtifactFile = new File(testM2Dir, PluginUtils.getMavenPath(coordinates)); if (!pluginArtifactFile.isFile()) { return; } try { FileUtils.copyFile(pluginArtifactFile, pluginFile); } catch (IOException e) { pluginArtifactFile.delete(); } }
/** * Constructor. * @param pluginsDir the plugins directory */ public DefaultPluginRegistry(File pluginsDir) { this(pluginsDir, PluginUtils.getDefaultMavenRepositories()); }
/** * Tries to download the plugin from the given remote maven repository. */ protected boolean downloadFromMavenRepo(File pluginFile, PluginCoordinates coordinates, URI mavenRepoUrl) { String artifactSubPath = PluginUtils.getMavenPath(coordinates); InputStream istream = null; OutputStream ostream = null; try { URL artifactUrl = new URL(mavenRepoUrl.toURL(), artifactSubPath); URLConnection connection = artifactUrl.openConnection(); connection.connect(); if (connection instanceof HttpURLConnection) { HttpURLConnection httpConnection = (HttpURLConnection) connection; if (httpConnection.getResponseCode() != 200) { throw new IOException(); } } istream = connection.getInputStream(); ostream = new FileOutputStream(pluginFile); IOUtils.copy(istream, ostream); ostream.flush(); return true; } catch (Exception e) { return false; } finally { IOUtils.closeQuietly(istream); IOUtils.closeQuietly(ostream); } }
/** * Constructor. */ public DefaultPluginRegistry() { this(createTempPluginsDir(), PluginUtils.getDefaultMavenRepositories()); }
/** * Tries to download the plugin from the given remote maven repository. */ protected void downloadFromMavenRepo(PluginCoordinates coordinates, URI mavenRepoUrl, IAsyncResultHandler<File> handler) { String artifactSubPath = PluginUtils.getMavenPath(coordinates); try { File tempArtifactFile = File.createTempFile("_plugin", "dwn"); //$NON-NLS-1$ //$NON-NLS-2$ URL artifactUrl = new URL(mavenRepoUrl.toURL(), artifactSubPath); downloadArtifactTo(artifactUrl, tempArtifactFile, handler); } catch (Exception e) { handler.handle(AsyncResultImpl.<File>create(e)); } }
/** * Constructor. */ public DefaultPluginRegistry() { this(createTempPluginsDir(), PluginUtils.getDefaultMavenRepositories()); }
/** * Tries to download the plugin from the given remote maven repository. */ protected void downloadFromMavenRepo(PluginCoordinates coordinates, URI mavenRepoUrl, IAsyncResultHandler<File> handler) { String artifactSubPath = PluginUtils.getMavenPath(coordinates); try { File tempArtifactFile = File.createTempFile("_plugin", "dwn"); //$NON-NLS-1$ //$NON-NLS-2$ URL artifactUrl = new URL(mavenRepoUrl.toURL(), artifactSubPath); downloadArtifactTo(artifactUrl, tempArtifactFile, handler); } catch (Exception e) { handler.handle(AsyncResultImpl.<File>create(e)); } }
private static Set<URI> getConfiguredPluginRepositories(Map<String, String> configMap) { Set<URI> rval = new HashSet<>(); rval.addAll(PluginUtils.getDefaultMavenRepositories()); String repositories = configMap.get("pluginRepositories"); //$NON-NLS-1$ if (repositories != null) { String[] split = repositories.split(","); //$NON-NLS-1$ for (String repository : split) { try { String trimmedRepo = repository.trim(); if (!trimmedRepo.isEmpty()) { if (trimmedRepo.startsWith("file:")) { //$NON-NLS-1$ trimmedRepo = trimmedRepo.replace('\\', '/'); } rval.add(new URI(trimmedRepo)); } } catch (URISyntaxException e) { throw new RuntimeException(e); } } } return rval; }