/** * Creates and returns a new {@link ConfigurableMavenResolverSystem} instance which may be used to create new * {@link MavenResolverSystem} instances * * @return A new {@link ConfigurableMavenResolverSystem} instance which may be used to create new * {@link MavenResolverSystem} instances */ public static ConfigurableMavenResolverSystem configureResolver() { return Resolvers.configure(ConfigurableMavenResolverSystem.class); }
/** * Creates a new instance of Invokable. Class itself is reloaded by provider classloader * * @param cl classloader * @param classType class object. Class with the same fully qualified name will be loader from provided classloader */ Invokable(ClassLoader cl, Class<?> classType) { this.classType = reloadClass(cl, classType); }
/** * Creates and returns a new {@link MavenResolverSystem} instance * * @return A new {@link MavenResolverSystem} instance */ public static MavenResolverSystem resolver() { return Resolvers.use(MavenResolverSystem.class); }
private static PackagingType toPackagingType(final String type) { assert type != null : "Should not be fed a null type via internals (regardless of user input)"; PackagingType parsedPackagingType = null; try { parsedPackagingType = PackagingType.of(type); } catch (final IllegalArgumentException iae) { // Exception translate throw new CoordinateParseException(iae.getMessage()); } return parsedPackagingType; }
/** * Specifies a POM file the EmbeddedMaven should be used for. * <p> * This method offers you to use a Resolver EmbeddedMaven API for additional easy setting of Maven Invoker that * is internally used. * </p> * <p> * If you prefer more powerful approach that is less comfortable and more boilerplate, then use the method * {@link #withMavenInvokerSet(InvocationRequest, Invoker)} * </p> * * @param pomFile POM file the EmbeddedMaven should be used for * @return Set EmbeddedMaven instance */ public static PomEquippedEmbeddedMaven forProject(File pomFile) { PomUnequippedEmbeddedMaven embeddedMaven = Resolvers.use(PomUnequippedEmbeddedMaven.class); return embeddedMaven.setPom(pomFile); }
/** * Specifies an {@link InvocationRequest} and an {@link Invoker} the EmbeddedMaven should be used with. * <p> * When you use this approach, it is expected that both instances are properly set by you and no additional * parameters (such as -DskipTests) is added by Resolver. You can also observe some limited functionality * provided by Resolver API. * </p> * <p> * If you prefer more comfortable and less boilerplate approach, then use the method {@link #forProject(String)} * </p> * * @param request An {@link InvocationRequest} the EmbeddedMaven should be used with * @param invoker An {@link Invoker} the EmbeddedMaven should be used with * @return Set EmbeddedMaven instance */ public static MavenInvokerEquippedEmbeddedMaven withMavenInvokerSet(InvocationRequest request, Invoker invoker) { MavenInvokerUnequippedEmbeddedMaven embeddedMaven = Resolvers.use(MavenInvokerUnequippedEmbeddedMaven.class); return embeddedMaven.setMavenInvoker(request, invoker); } }
/** * Configures the {@link MavenResolverSystem} with <code>settings.xml</code> and POM metadata as picked up from the * environment (these properties are set by the ShrinkWrap Maven Resolver Plugin). * * @param cl The {@link ClassLoader} used to create the new instance; required * @return The {@link MavenResolverSystem} configured with <code>settings.xml</code> and POM metadata as picked up * from the environment * @throws IllegalArgumentException * If the {@link ClassLoader} is not specified * @throws InvalidEnvironmentException * If this is executed outside the context of the ShrinkWrap Maven Resolver Plugin Environment */ public static PomEquippedResolveStage configureResolverViaPlugin(final ClassLoader cl) throws InvalidEnvironmentException, IllegalArgumentException { final ConfigurableMavenResolverSystem resolverSystem = Resolvers.use(ConfigurableMavenResolverSystem.class, cl); return resolverSystem.configureViaPlugin(); }
/** * Creates a new {@link ResolverSystem} instance of the specified user view type using the {@link Thread} Context * {@link ClassLoader}. Will consult a configuration file visible to the {@link Thread} Context {@link ClassLoader} named * "META-INF/services/$fullyQualfiedClassName" which should contain a key=value format with the key * {@link ResolverSystemFactory#KEY_IMPL_CLASS_NAME}. The implementation class name must have a no-arg constructor. * * @param userViewClass The user view type * @return The new {@link ResolverSystem} instance of the specified user view type created by using the {@link Thread} * Context {@link ClassLoader}. * @throws IllegalArgumentException * If the user view class was not specified */ static <RESOLVERSYSTEMTYPE extends ResolverSystem> RESOLVERSYSTEMTYPE createFromUserView( final Class<RESOLVERSYSTEMTYPE> userViewClass) throws IllegalArgumentException { return createFromUserView(userViewClass, SecurityActions.getThreadContextClassLoader()); }
@Override public MavenWorkingSession execute(final MavenWorkingSession session) { try { Validate.isReadable(settingsXmlFile, "Path to the settings.xml ('" + settingsXmlFile + "') must be defined and accessible"); } // rewrap exception catch (IllegalArgumentException e) { throw new InvalidConfigurationFileException(e.getMessage()); } return session.configureSettingsFromFile(null, settingsXmlFile); }
/** * Creates and returns a new instance of the specified view type. * * @param <RESOLVERSYSTEMTYPE> The {@link ResolverSystem} type. * @param clazz The view type * @return A new instance of the specified view type. * @throws IllegalArgumentException * If the type is not specified */ public static <RESOLVERSYSTEMTYPE extends ResolverSystem> RESOLVERSYSTEMTYPE use( final Class<RESOLVERSYSTEMTYPE> clazz) throws IllegalArgumentException { return ResolverSystemFactory.createFromUserView(clazz); }
/** * Loads a class from classloader * * @param cl classloader to be used * @param classTypeName fully qualified class name * @return * @throws InvocationException if class was not found in classloader */ static Class<?> loadClass(ClassLoader cl, String classTypeName) throws InvocationException { try { return cl.loadClass(classTypeName); } catch (ClassNotFoundException e) { throw new InvocationException(e, "Unable to load class {0} with class loader {1}", classTypeName, cl); } }
/** * Creates a new instance of Invokable. Class itself is loaded by provided classloader * * @param cl classloader * @param className fully qualified class name */ Invokable(ClassLoader cl, String className) { this.classType = loadClass(cl, className); }
/** * Specifies a POM file the EmbeddedMaven should be used for. * <p> * This method offers you to use a Resolver EmbeddedMaven API for additional easy setting of Maven Invoker that * is internally used. * </p> * <p> * If you prefer more powerful approach that is less comfortable and more boilerplate, then use the method * {@link #withMavenInvokerSet(InvocationRequest, Invoker)} * </p> * * @param pomFile POM file the EmbeddedMaven should be used for * @return Set EmbeddedMaven instance */ public static PomEquippedEmbeddedMaven forProject(File pomFile) { PomUnequippedEmbeddedMaven embeddedMaven = Resolvers.use(PomUnequippedEmbeddedMaven.class); return embeddedMaven.setPom(pomFile); }
/** * Specifies an {@link InvocationRequest} and an {@link Invoker} the EmbeddedMaven should be used with. * <p> * When you use this approach, it is expected that both instances are properly set by you and no additional * parameters (such as -DskipTests) is added by Resolver. You can also observe some limited functionality * provided by Resolver API. * </p> * <p> * If you prefer more comfortable and less boilerplate approach, then use the method {@link #forProject(String)} * </p> * * @param request An {@link InvocationRequest} the EmbeddedMaven should be used with * @param invoker An {@link Invoker} the EmbeddedMaven should be used with * @return Set EmbeddedMaven instance */ public static MavenInvokerEquippedEmbeddedMaven withMavenInvokerSet(InvocationRequest request, Invoker invoker) { MavenInvokerUnequippedEmbeddedMaven embeddedMaven = Resolvers.use(MavenInvokerUnequippedEmbeddedMaven.class); return embeddedMaven.setMavenInvoker(request, invoker); } }
public MavenImporterImpl(Archive<?> archive) { // this is needed to boostrap session Resolvers.use(MavenResolverSystem.class); this.session = new MavenWorkingSessionImpl(); this.archive = archive; }
/** * Returns a factory to create configured {@link ResolverSystem} instances of the specified type. New instances will * be created using the specified {@link ClassLoader}. * * @param <RESOLVERSYSTEMTYPE> The {@link ResolverSystem} type. * @param <CONFIGURABLERESOLVERSYSTEMTYPE> The {@link ConfigurableResolverSystem} type. * @param clazz The type * @param cl The {@link ClassLoader} * @return A factory to create configured {@link ResolverSystem} instances of the specified type. The factory will * be created by using the specified {@link ClassLoader}. * @throws IllegalArgumentException * If the type or {@link ClassLoader} is not specified */ public static <RESOLVERSYSTEMTYPE extends ResolverSystem, CONFIGURABLERESOLVERSYSTEMTYPE extends ConfigurableResolverSystem<RESOLVERSYSTEMTYPE, CONFIGURABLERESOLVERSYSTEMTYPE>> CONFIGURABLERESOLVERSYSTEMTYPE configure( final Class<CONFIGURABLERESOLVERSYSTEMTYPE> clazz, final ClassLoader cl) throws IllegalArgumentException { return ResolverSystemFactory.createFromUserView(clazz, cl); }
/** * Reloads a class from classloader using same fully qualified class name * * @param cl classloader to be used * @param classType class object * @return * @throws InvocationException if class was not found in classloader */ static Class<?> reloadClass(ClassLoader cl, Class<?> classType) throws InvocationException { try { return cl.loadClass(classType.getName()); } catch (ClassNotFoundException e) { throw new InvocationException(e, "Unable to reload class {0} with class loader {1}, previously loaded with {2}", classType.getName(), cl, classType.getClassLoader()); } }
public MavenImporterImpl(Archive<?> archive) { // this is needed to boostrap session Resolvers.use(MavenResolverSystem.class); this.session = new MavenWorkingSessionImpl(); this.archive = archive; }
/** * Returns a factory to create configured {@link ResolverSystem} instances of the specified type. New instances will * be created using the current {@link Thread#getContextClassLoader()}. * * @param <RESOLVERSYSTEMTYPE> The {@link ResolverSystem} type. * @param <CONFIGURABLERESOLVERSYSTEMTYPE> The {@link ConfigurableResolverSystem} type. * @param clazz The type * @return A factory to create configured {@link ResolverSystem} instances of the specified type. * @throws IllegalArgumentException * If the type is not specified */ public static <RESOLVERSYSTEMTYPE extends ResolverSystem, CONFIGURABLERESOLVERSYSTEMTYPE extends ConfigurableResolverSystem<RESOLVERSYSTEMTYPE, CONFIGURABLERESOLVERSYSTEMTYPE>> CONFIGURABLERESOLVERSYSTEMTYPE configure( final Class<CONFIGURABLERESOLVERSYSTEMTYPE> clazz) throws IllegalArgumentException { return ResolverSystemFactory.createFromUserView(clazz); }
/** * Creates and returns a new instance of the specified view type. New instances will be created by using the * specified {@link ClassLoader}. * * @param <RESOLVERSYSTEMTYPE> The {@link ResolverSystem} type. * @param clazz The view type. * @param cl The {@link ClassLoader}. * @return A new instance of the specified view type created by using the specified {@link ClassLoader}. * @throws IllegalArgumentException * If either argument is not supplied */ public static <RESOLVERSYSTEMTYPE extends ResolverSystem> RESOLVERSYSTEMTYPE use( final Class<RESOLVERSYSTEMTYPE> clazz, final ClassLoader cl) throws IllegalArgumentException { return ResolverSystemFactory.createFromUserView(clazz, cl); } }