org.jboss.shrinkwrap.resolver.api.maven.ConfigurableMavenResolverSystem Java Examples

The following examples show how to use org.jboss.shrinkwrap.resolver.api.maven.ConfigurableMavenResolverSystem. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Dependencies.java    From component-runtime with Apache License 2.0 6 votes vote down vote up
public static URL[] resolve(final MavenDependency dep) {
    return CACHE.computeIfAbsent(dep, d -> {
        final ConfigurableMavenResolverSystem resolver = Maven
                .configureResolver()
                .withClassPathResolution(true)
                .workOffline(Boolean.getBoolean("talend.component.junit.maven.offline"));
        REPOSITORIES.forEach(resolver::withRemoteRepo);
        resolver.addDependency(dep);
        return Stream.of(resolver.resolve().using(STRATEGY).asFile()).distinct().map(f -> {
            try {
                return f.toURI().toURL();
            } catch (final MalformedURLException e) {
                throw new IllegalStateException(e);
            }
        }).toArray(URL[]::new);
    });
}
 
Example #2
Source File: Main.java    From thorntail with Apache License 2.0 6 votes vote down vote up
private static ArtifactResolvingHelper getResolvingHelper(final List<String> repos) {
    final ConfigurableMavenResolverSystem resolver = Maven.configureResolver()
            .withMavenCentralRepo(true)
            .withRemoteRepo(MavenRemoteRepositories.createRemoteRepository("jboss-public-repository-group",
                                                                           "https://repository.jboss.org/nexus/content/groups/public/",
                                                                           "default")
                                    .setChecksumPolicy(MavenChecksumPolicy.CHECKSUM_POLICY_IGNORE)
                                    .setUpdatePolicy(MavenUpdatePolicy.UPDATE_POLICY_NEVER))
            .withRemoteRepo(MavenRemoteRepositories.createRemoteRepository("redhat-ga",
                                                                           "https://maven.repository.redhat.com/ga/",
                                                                           "default")
                                    .setChecksumPolicy(MavenChecksumPolicy.CHECKSUM_POLICY_IGNORE)
                                    .setUpdatePolicy(MavenUpdatePolicy.UPDATE_POLICY_NEVER));

    repos.forEach(r -> resolver.withRemoteRepo(MavenRemoteRepositories.createRemoteRepository(r, r, "default")
                                                       .setChecksumPolicy(MavenChecksumPolicy.CHECKSUM_POLICY_IGNORE)
                                                       .setUpdatePolicy(MavenUpdatePolicy.UPDATE_POLICY_NEVER)));

    return new ShrinkwrapArtifactResolvingHelper(resolver);
}
 
Example #3
Source File: shrinkwrap.java    From jbang with MIT License 5 votes vote down vote up
@Override
public Integer call() throws Exception { // your business logic goes here...
    System.out.println("Hello " + greeting);

    ConfigurableMavenResolverSystem resolver = Maven.configureResolver()
            .withRemoteRepo("jcenter", "https://jcenter.bintray.com/", "default")
            .withMavenCentralRepo(false);
    
    //System.setProperty("maven.repo.local", Settings.getLocalMavenRepo().toPath().toAbsolutePath().toString());

    List<File> artifacts = resolver.resolve("log4j:log4j:1.2.17")
            .using(new MavenResolutionStrategy() {

                @Override
                public TransitiveExclusionPolicy getTransitiveExclusionPolicy() {
                    return new TransitiveExclusionPolicy() {
                        @Override
                        public boolean allowOptional() {
                            return true;
                        }

                        @Override
                        public ScopeType[] getFilteredScopes() {
                            return new ScopeType[]{ScopeType.PROVIDED, ScopeType.TEST};
                        }
                    };
                }

                @Override
                public MavenResolutionFilter[] getResolutionFilters() {
                    return new MavenResolutionFilter[0];
                }
            })
            .asList(File.class);

    artifacts.forEach(System.out::println);

    return CommandLine.ExitCode.OK;
}
 
Example #4
Source File: DependencyUtil.java    From jbang with MIT License 5 votes vote down vote up
public List<File> resolveDependenciesViaAether(List<String> depIds, List<MavenRepo> customRepos,
		boolean offline, boolean loggingEnabled) {

	ConfigurableMavenResolverSystem resolver = Maven.configureResolver()
													.withMavenCentralRepo(false)
													.workOffline(offline);

	customRepos.stream().forEach(mavenRepo -> {
		mavenRepo.apply(resolver);
	});

	System.setProperty("maven.repo.local", Settings.getLocalMavenRepo().toPath().toAbsolutePath().toString());

	return depIds.stream().flatMap(it -> {

		if (loggingEnabled)
			System.err.print(String.format("[jbang]     Resolving %s...", it));

		List<File> artifacts;
		try {
			artifacts = resolver.resolve(depIdToArtifact(it).toCanonicalForm())
								.withTransitivity()
								.asList(File.class); // , RUNTIME);
		} catch (RuntimeException e) {
			throw new ExitException(1, "Could not resolve dependency", e);
		}

		if (loggingEnabled)
			System.err.println("Done");

		return artifacts.stream();
	}).collect(Collectors.toList());
}
 
Example #5
Source File: DependencyUtil.java    From jbang with MIT License 5 votes vote down vote up
static public MavenRepo toMavenRepo(String repoReference) {
	String[] split = repoReference.split("=");
	String reporef = null;
	String repoid = null;

	if (split.length == 1) {
		reporef = split[0];
	} else if (split.length == 2) {
		repoid = split[0];
		reporef = split[1];
	} else {
		throw new IllegalStateException("Invalid Maven repository reference: " + repoReference);
	}

	if (ALIAS_JCENTER.equalsIgnoreCase(reporef)) {
		return new MavenRepo(Optional.ofNullable(repoid).orElse(ALIAS_JCENTER), REPO_JCENTER);
	} else if (ALIAS_GOOGLE.equalsIgnoreCase(reporef)) {
		return new MavenRepo(Optional.ofNullable(repoid).orElse(ALIAS_GOOGLE), REPO_GOOGLE);
	} else if (ALIAS_REDHAT.equalsIgnoreCase(reporef)) {
		return new MavenRepo(Optional.ofNullable(repoid).orElse(ALIAS_REDHAT), REPO_REDHAT);
	} else if (ALIAS_JBOSS.equalsIgnoreCase(reporef)) {
		return new MavenRepo(Optional.ofNullable(repoid).orElse(ALIAS_JBOSS), REPO_JBOSS);
	} else if (ALIAS_MAVEN_CENTRAL.equalsIgnoreCase(reporef)) {
		return new MavenRepo("", "") {
			@Override
			public void apply(ConfigurableMavenResolverSystem resolver) {
				resolver.withMavenCentralRepo(true);
			}
		};
	} else if (ALIAS_JITPACK.equalsIgnoreCase(reporef)) {
		return new MavenRepo(Optional.ofNullable(repoid).orElse(ALIAS_JITPACK), REPO_JITPACK);
	} else {
		return new MavenRepo(repoid, reporef);
	}
}
 
Example #6
Source File: Main.java    From wildfly-swarm with Apache License 2.0 5 votes vote down vote up
private static ArtifactResolvingHelper getResolvingHelper(final List<String> repos) {
    final ConfigurableMavenResolverSystem resolver = Maven.configureResolver()
            .withMavenCentralRepo(true)
            .withRemoteRepo(MavenRemoteRepositories.createRemoteRepository("jboss-public-repository-group",
                                                                           "http://repository.jboss.org/nexus/content/groups/public/",
                                                                           "default")
                                    .setChecksumPolicy(MavenChecksumPolicy.CHECKSUM_POLICY_IGNORE)
                                    .setUpdatePolicy(MavenUpdatePolicy.UPDATE_POLICY_NEVER));

    repos.forEach(r -> resolver.withRemoteRepo(MavenRemoteRepositories.createRemoteRepository(r, r, "default")
                                                       .setChecksumPolicy(MavenChecksumPolicy.CHECKSUM_POLICY_IGNORE)
                                                       .setUpdatePolicy(MavenUpdatePolicy.UPDATE_POLICY_NEVER)));

    return new ShrinkwrapArtifactResolvingHelper(resolver);
}
 
Example #7
Source File: LibraryResolverMaven.java    From jqm with Apache License 2.0 4 votes vote down vote up
ConfigurableMavenResolverSystem getMavenResolver()
{
    // Retrieve resolver configuration
    if (REPO_LIST == null)
    {
        REPO_LIST = new ArrayList<>(5);
        for (String gp : mavenRepos)
        {
            REPO_LIST.add(gp);
        }

        MAVEN_SETTINGS_CL = mavenSettingsClPath;
        MAVEN_SETTINGS_FILE = mavenSettingsFilePath;
    }

    // Resolver
    ConfigurableMavenResolverSystem resolver = Maven.configureResolver();

    // settings.xml?
    if (MAVEN_SETTINGS_CL != null && MAVEN_SETTINGS_FILE == null)
    {
        jqmlogger.trace("Custom settings file from class-path will be used: " + MAVEN_SETTINGS_CL);
        resolver.fromClassloaderResource(MAVEN_SETTINGS_CL);
    }
    if (MAVEN_SETTINGS_FILE != null)
    {
        jqmlogger.trace("Custom settings file from file system will be used: " + MAVEN_SETTINGS_FILE);
        resolver.fromFile(MAVEN_SETTINGS_FILE);
    }

    // Repositories to use.
    boolean withCentral = false;
    for (String repo : REPO_LIST)
    {
        if (repo.contains("repo1.maven.org"))
        {
            withCentral = true;
            jqmlogger.trace("Using Maven central as a Maven repository");
            continue;
        }
        jqmlogger.trace("Using Maven repository {}", repo);
        resolver = resolver
                .withRemoteRepo(MavenRemoteRepositories.createRemoteRepository("repo" + Math.abs(repo.hashCode()), repo, "default")
                        .setUpdatePolicy(MavenUpdatePolicy.UPDATE_POLICY_NEVER));
    }
    resolver.withMavenCentralRepo(withCentral);
    return resolver;
}
 
Example #8
Source File: ArquillianPackager.java    From camel-spring-boot with Apache License 2.0 4 votes vote down vote up
private static ConfigurableMavenResolverSystem resolver(ITestConfig config) {
    return Maven.configureResolver().workOffline(config.getMavenOfflineResolution());
}
 
Example #9
Source File: Build.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 4 votes vote down vote up
public File run() throws Exception {
    final String[] parts = this.source.getName().split("\\.(?=[^\\.]+$)");
    final String baseName = parts[0];
    final String type = parts[1] == null ? "jar" : parts[1];
    final MavenRemoteRepository jbossPublic =
            MavenRemoteRepositories.createRemoteRepository("jboss-public-repository-group",
                    "http://repository.jboss.org/nexus/content/groups/public/",
                    "default");
    jbossPublic.setChecksumPolicy(MavenChecksumPolicy.CHECKSUM_POLICY_IGNORE);
    jbossPublic.setUpdatePolicy(MavenUpdatePolicy.UPDATE_POLICY_NEVER);

    final ConfigurableMavenResolverSystem resolver = Maven.configureResolver()
            .withMavenCentralRepo(true)
            .withRemoteRepo(jbossPublic);

    final BuildTool tool = new BuildTool()
            .artifactResolvingHelper(new ShrinkwrapArtifactResolvingHelper(resolver))
            .projectArtifact("", baseName, "", type, this.source)
            .resolveTransitiveDependencies(true)
            .properties(this.properties);

    if (this.autoDetectFractions) {
        this.swarmDependencies.addAll(new PackageAnalyzer(this.source).detectNeededFractions());
    } else {
        System.err.println("Skipping fraction auto-detection");
    }

    for (String dep : this.swarmDependencies) {
        tool.dependency("compile", "org.wildfly.swarm", dep, this.version, "jar", null, null, true);
    }

    final String jarName = this.name != null ? this.name : baseName;
    final String outDir = this.outputDir.getCanonicalPath();
    System.err.println(String.format("Building %s/%s-swarm.jar with fractions: %s",
            outDir,
            jarName,
            String.join(", ",
                    allRequiredFractions()
                            .stream()
                            .sorted()
                            .collect(Collectors.toList()))));

    return tool.build(jarName, Paths.get(outDir));
}
 
Example #10
Source File: ShrinkwrapArtifactResolvingHelper.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 4 votes vote down vote up
public ShrinkwrapArtifactResolvingHelper(ConfigurableMavenResolverSystem resolver) {
    this.resolver = resolver;
    transferListener(new FailureReportingTransferListener());
}
 
Example #11
Source File: ShrinkwrapArtifactResolvingHelper.java    From thorntail with Apache License 2.0 4 votes vote down vote up
public ShrinkwrapArtifactResolvingHelper(ConfigurableMavenResolverSystem resolver) {
    this.resolver = resolver;
    transferListener(new FailureReportingTransferListener());
}
 
Example #12
Source File: ShrinkwrapArtifactResolvingHelper.java    From thorntail with Apache License 2.0 4 votes vote down vote up
public ConfigurableMavenResolverSystem getResolver() {
    return resolver;
}
 
Example #13
Source File: ShrinkwrapArtifactResolvingHelper.java    From thorntail with Apache License 2.0 4 votes vote down vote up
public static ShrinkwrapArtifactResolvingHelper defaultInstance() {
    return INSTANCE.updateAndGet(e -> {
        if (e != null) {
            return e;
        }

        MavenRemoteRepository jbossPublic =
                MavenRemoteRepositories.createRemoteRepository("jboss-public-repository-group",
                                                               "https://repository.jboss.org/nexus/content/groups/public/",
                                                               MAVEN_LAYOUT_DEFAULT);
        jbossPublic.setChecksumPolicy(MavenChecksumPolicy.CHECKSUM_POLICY_IGNORE);
        jbossPublic.setUpdatePolicy(MavenUpdatePolicy.UPDATE_POLICY_NEVER);

        MavenRemoteRepository redhatGa =
                MavenRemoteRepositories.createRemoteRepository("redhat-ga",
                                                               "https://maven.repository.redhat.com/ga/",
                                                               MAVEN_LAYOUT_DEFAULT);
        redhatGa.setChecksumPolicy(MavenChecksumPolicy.CHECKSUM_POLICY_IGNORE);
        redhatGa.setUpdatePolicy(MavenUpdatePolicy.UPDATE_POLICY_NEVER);

        MavenRemoteRepository gradleTools =
                MavenRemoteRepositories.createRemoteRepository("gradle",
                                                               "https://repo.gradle.org/gradle/libs-releases-local",
                                                               MAVEN_LAYOUT_DEFAULT);
        gradleTools.setChecksumPolicy(MavenChecksumPolicy.CHECKSUM_POLICY_IGNORE);
        gradleTools.setUpdatePolicy(MavenUpdatePolicy.UPDATE_POLICY_NEVER);

        Boolean offline = Boolean.valueOf(System.getProperty("thorntail.resolver.offline", "false"));
        final ConfigurableMavenResolverSystem resolver = Maven.configureResolver()
                .withMavenCentralRepo(true)
                .withRemoteRepo(jbossPublic)
                .withRemoteRepo(redhatGa)
                .withRemoteRepo(gradleTools)
                .workOffline(offline);

        final String additionalRepos = System.getProperty(SwarmInternalProperties.BUILD_REPOS);
        if (additionalRepos != null) {
            Arrays.asList(additionalRepos.split(","))
                    .forEach(r -> {
                        MavenRemoteRepository repo =
                                MavenRemoteRepositories.createRemoteRepository(r, r, MAVEN_LAYOUT_DEFAULT);
                        repo.setChecksumPolicy(MavenChecksumPolicy.CHECKSUM_POLICY_IGNORE);
                        repo.setUpdatePolicy(MavenUpdatePolicy.UPDATE_POLICY_NEVER);
                        resolver.withRemoteRepo(repo);
                    });
        }


        ShrinkwrapArtifactResolvingHelper helper = new ShrinkwrapArtifactResolvingHelper(resolver);
        helper.session().setCache(new SimpleRepositoryCache());
        helper.session().setUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_DAILY);
        helper.session().setChecksumPolicy(RepositoryPolicy.CHECKSUM_POLICY_IGNORE);

        return helper;
    });
}
 
Example #14
Source File: MavenProfileLoader.java    From thorntail with Apache License 2.0 4 votes vote down vote up
public static PomEquippedResolveStage loadPom(ConfigurableMavenResolverSystem resolver) {
    return resolver.loadPomFromFile(FileSystemLayout.resolveMavenBuildFileName(), determineProfiles());
}
 
Example #15
Source File: MicroOuterDeployer.java    From piranha with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@SuppressWarnings("unchecked")
public Set<String> deploy(Archive<?> archive) {
    Set<String> servletNames = new HashSet<>();
    
    if (!archive.contains("WEB-INF/beans.xml")) {
        archive.add(EmptyAsset.INSTANCE, "WEB-INF/beans.xml");
    }
    
    ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        
        // Resolve all the dependencies that make up a Piranha runtime configuration
        
        ConfigurableMavenResolverSystem mavenResolver = Maven.configureResolver();
        
        configuration.getRepositoriesList().stream().forEach(repoUrl ->
            mavenResolver.withRemoteRepo(createRepo(repoUrl)));
        
        JavaArchive[] piranhaArchives = 
            mavenResolver
                 .workOffline(configuration.isOffline())
                 .resolve(configuration.getMergedDependencies())
                 .withTransitivity()
                 .as(JavaArchive.class);

        // Make all those dependencies available to the Piranha class loader
        ClassLoader piranhaClassLoader = getPiranhaClassLoader(piranhaArchives);
        
        // Make the web application archive (the .war) available to a separate classloader
        // The webInfClassLoader delegates to the Piranha class loader.
        
        // The class loading hierarchy looks as follows:
        
        // Web-inf class loader (application classes)
        //        |
        //        |--- System class loader (Pass-through for Shrinkwrap classes only)
        //        |--- java.lang.ClassLoader (super class, Weld, Javasist etc hack-in their classes here) 
        //        |
        // Piranha class loader (Piranha classes)
        //        |
        //        |
        // Platform class loader (JDK classes)
        
        ClassLoader webInfClassLoader = getWebInfClassLoader(archive, piranhaClassLoader);
        
        Thread.currentThread().setContextClassLoader(webInfClassLoader);
        
        try {
            URL.setURLStreamHandlerFactory(new StaticURLStreamHandlerFactory());
        } catch (Error error) { // Yes, we know...
            // Ignore
        }
        
        System.setProperty("micro.version", getClass().getPackage().getImplementationVersion());
    
        microInnerDeployer = 
            Class.forName(
                    "cloud.piranha.micro.MicroInnerDeployer", 
                    true,
                    webInfClassLoader)
                 .getDeclaredConstructor()
                 .newInstance();
        
        servletNames.addAll((Set<String>) 
            microInnerDeployer
                .getClass()
                .getMethod("start", Archive.class, ClassLoader.class, Map.class, Integer.class)
                .invoke(microInnerDeployer, 
                    archive, 
                           webInfClassLoader, 
                           StaticURLStreamHandlerFactory.getHandlers(),
                           configuration.getPort()));
        
        return servletNames;
    
    } catch (InstantiationException | IllegalAccessException | ClassNotFoundException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
        throw new IllegalStateException("", e);
    } finally {
        Thread.currentThread().setContextClassLoader(oldClassLoader);
    }
}
 
Example #16
Source File: MavenRepo.java    From jbang with MIT License 4 votes vote down vote up
public void apply(ConfigurableMavenResolverSystem resolver) {
	resolver.withRemoteRepo(getId(), getUrl(), "default");
}
 
Example #17
Source File: ShrinkwrapArtifactResolvingHelper.java    From thorntail with Apache License 2.0 votes vote down vote up
MavenResolvedArtifact[] resolve(ConfigurableMavenResolverSystem resolver); 
Example #18
Source File: ShrinkwrapArtifactResolvingHelper.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 votes vote down vote up
MavenResolvedArtifact[] resolve(ConfigurableMavenResolverSystem resolver);