Search in sources :

Example 1 with MavenCoordinate

use of org.jboss.shrinkwrap.resolver.api.maven.coordinate.MavenCoordinate in project camel by apache.

the class ArquillianPackager method springBootPackage.

public static Archive<?> springBootPackage(ITestConfig config) throws Exception {
    if (!new File(".").getCanonicalFile().getName().equals("camel-itest-spring-boot")) {
        throw new IllegalStateException("In order to run the integration tests, 'camel-itest-spring-boot' must be the working directory. Check your configuration.");
    }
    ExtensionLoader extensionLoader = new ServiceExtensionLoader(Collections.singleton(getExtensionClassloader()));
    extensionLoader.addOverride(ZipExporter.class, SpringBootZipExporterImpl.class);
    ConfigurationBuilder builder = new ConfigurationBuilder().extensionLoader(extensionLoader);
    Configuration conf = builder.build();
    Domain domain = ShrinkWrap.createDomain(conf);
    JavaArchive ark = domain.getArchiveFactory().create(JavaArchive.class, "test.jar");
    ark = ark.addAsManifestResource("BOOT-MANIFEST.MF", "MANIFEST.MF");
    ark = ark.addAsDirectories(LIB_FOLDER);
    if (!CLASSES_FOLDER.equals("")) {
        ark = ark.addAsDirectories(CLASSES_FOLDER);
    }
    if (config.getUseCustomLog()) {
        ark = ark.addAsResource("spring-logback.xml", CLASSES_FOLDER + "/spring-logback.xml");
    }
    for (Map.Entry<String, String> res : config.getResources().entrySet()) {
        ark = ark.addAsResource(res.getKey(), CLASSES_FOLDER + "/" + res.getValue());
    }
    String version = System.getProperty("version_org.apache.camel:camel-core");
    if (version == null) {
        config.getMavenVersion();
    }
    if (version == null) {
        // It is missing when launching from IDE
        List<MavenResolvedArtifact> resolved = Arrays.asList(resolver(config).loadPomFromFile("pom.xml").importRuntimeDependencies().resolve().withoutTransitivity().asResolvedArtifact());
        for (MavenResolvedArtifact dep : resolved) {
            if (dep.getCoordinate().getGroupId().equals("org.apache.camel")) {
                version = dep.getCoordinate().getVersion();
                break;
            }
        }
    }
    debug("Resolved version: " + version);
    if (version == null) {
        throw new IllegalStateException("Cannot determine the current version of the camel component");
    }
    List<MavenDependencyExclusion> commonExclusions = new LinkedList<>();
    commonExclusions.add(MavenDependencies.createExclusion("commons-logging", "commons-logging"));
    commonExclusions.add(MavenDependencies.createExclusion("org.slf4j", "slf4j-log4j12"));
    commonExclusions.add(MavenDependencies.createExclusion("log4j", "log4j"));
    commonExclusions.add(MavenDependencies.createExclusion("log4j", "log4j-slf4j-impl"));
    commonExclusions.add(MavenDependencies.createExclusion("org.apache.logging.log4j", "log4j"));
    commonExclusions.add(MavenDependencies.createExclusion("org.apache.logging.log4j", "log4j-core"));
    commonExclusions.add(MavenDependencies.createExclusion("org.apache.logging.log4j", "log4j-slf4j-impl"));
    commonExclusions.add(MavenDependencies.createExclusion("log4j", "apache-log4j-extras"));
    commonExclusions.add(MavenDependencies.createExclusion("org.slf4j", "slf4j-simple"));
    commonExclusions.add(MavenDependencies.createExclusion("org.slf4j", "slf4j-jdk14"));
    commonExclusions.add(MavenDependencies.createExclusion("ch.qos.logback", "logback-classic"));
    commonExclusions.add(MavenDependencies.createExclusion("ch.qos.logback", "logback-core"));
    for (String ex : config.getMavenExclusions()) {
        commonExclusions.add(MavenDependencies.createExclusion(ex));
    }
    // Module dependencies
    List<MavenDependency> additionalDependencies = new LinkedList<>();
    for (String canonicalForm : config.getAdditionalDependencies()) {
        MavenCoordinate coord = MavenCoordinates.createCoordinate(canonicalForm);
        MavenDependency dep = MavenDependencies.createDependency(coord, ScopeType.RUNTIME, false);
        additionalDependencies.add(dep);
    }
    //        String mainArtifactId = config.getModuleName() + "-starter";
    //        MavenCoordinate mainJar = MavenCoordinates.createCoordinate(config.getMavenGroup(), mainArtifactId, version, PackagingType.JAR, null);
    //        // Add exclusions only when not using the starters
    //        MavenDependency mainDep = MavenDependencies.createDependency(mainJar, ScopeType.COMPILE, false);
    //        moduleDependencies.add(mainDep);
    List<String> testProvidedDependenciesXml = new LinkedList<>();
    List<ScopeType> scopes = new LinkedList<>();
    if (config.getIncludeProvidedDependencies() || config.getIncludeTestDependencies() || config.getUnitTestEnabled()) {
        if (config.getIncludeTestDependencies() || config.getUnitTestEnabled()) {
            testProvidedDependenciesXml.addAll(DependencyResolver.getDependencies(config.getModuleBasePath() + "/pom.xml", ScopeType.TEST.toString()));
            scopes.add(ScopeType.TEST);
        }
        if (config.getIncludeProvidedDependencies()) {
            testProvidedDependenciesXml.addAll(DependencyResolver.getDependencies(config.getModuleBasePath() + "/pom.xml", ScopeType.PROVIDED.toString()));
            scopes.add(ScopeType.PROVIDED);
        }
    }
    List<String> cleanTestProvidedDependenciesXml = new LinkedList<>();
    for (String depXml : testProvidedDependenciesXml) {
        if (validTestDependency(config, depXml, commonExclusions)) {
            depXml = useBOMVersionIfPresent(config, depXml);
            depXml = enforceExclusions(config, depXml, commonExclusions);
            depXml = switchToStarterIfPresent(config, depXml);
            cleanTestProvidedDependenciesXml.add(depXml);
        }
    }
    //        List<MavenResolvedArtifact> testDependencies = new LinkedList<>();
    //        if (!cleanTestProvidedDependenciesXml.isEmpty()) {
    //
    //            File testProvidedResolverPom = createResolverPom(config, cleanTestProvidedDependenciesXml);
    //
    //            testDependencies.addAll(Arrays.asList(resolver(config)
    //                    .loadPomFromFile(testProvidedResolverPom)
    //                    .importDependencies(scopes.toArray(new ScopeType[0]))
    //                    .resolve()
    //                    .withTransitivity()
    //                    .asResolvedArtifact()));
    //        }
    File moduleSpringBootPom = createUserPom(config, cleanTestProvidedDependenciesXml);
    List<ScopeType> resolvedScopes = new LinkedList<>();
    resolvedScopes.add(ScopeType.COMPILE);
    resolvedScopes.add(ScopeType.RUNTIME);
    resolvedScopes.addAll(scopes);
    List<MavenResolvedArtifact> runtimeDependencies = new LinkedList<>();
    runtimeDependencies.addAll(Arrays.asList(resolver(config).loadPomFromFile(moduleSpringBootPom).importDependencies(resolvedScopes.toArray(new ScopeType[0])).addDependencies(additionalDependencies).resolve().withTransitivity().asResolvedArtifact()));
    //merge(config, runtimeDependencies, testDependencies);
    List<MavenResolvedArtifact> dependencyArtifacts = runtimeDependencies;
    lookForVersionMismatch(config, dependencyArtifacts);
    List<File> dependencies = new LinkedList<>();
    for (MavenResolvedArtifact a : dependencyArtifacts) {
        dependencies.add(a.asFile());
    }
    // The spring boot-loader dependency will be added to the main jar, so it should be excluded from the embedded ones
    excludeDependencyRegex(dependencies, "^spring-boot-loader-[0-9].*");
    // Add all dependencies as spring-boot nested jars
    ark = addDependencies(ark, dependencies);
    // Add common packages to main jar
    ark = ark.addPackages(true, "org.jboss.shrinkwrap");
    // Add current classes to both location to be used by different classloaders
    ark = ark.addPackages(true, "org.apache.camel.itest.springboot");
    ark = addSpringbootPackage(ark, "org.apache.camel.itest.springboot");
    // CAMEL-10060 is resolved since 2.18 but some unit tests use custom (non spring-boot enabled) camel contexts
    ark = ark.addPackages(true, "org.apache.camel.converter.myconverter");
    ark = ark.addPackages(true, "org.springframework.boot.loader");
    ClassPath.Builder external = ClassPath.builder().add(ark);
    // overcome limitations of some JDKs
    external.addSystemProperty("javax.xml.accessExternalDTD", "all");
    external.addSystemProperty("javax.xml.accessExternalSchema", "all");
    if (config.getUnitTestEnabled()) {
        external.addSystemProperty("container.user.dir", new File(config.getModuleBasePath()).getCanonicalPath());
        external.addSystemProperty("container.test.resources.dir", new File(config.getModuleBasePath()).getCanonicalPath() + "/target/test-classes");
    }
    // Adding configuration properties
    for (Map.Entry<Object, Object> e : System.getProperties().entrySet()) {
        if (e.getKey() instanceof String && e.getValue() instanceof String) {
            String key = (String) e.getKey();
            if (key.startsWith(ITestConfigBuilder.CONFIG_PREFIX)) {
                external.addSystemProperty(key, (String) e.getValue());
            }
        }
    }
    for (Map.Entry<String, String> e : config.getSystemProperties().entrySet()) {
        external.addSystemProperty(e.getKey(), e.getValue());
    }
    return external.build();
}
Also used : ConfigurationBuilder(org.jboss.shrinkwrap.api.ConfigurationBuilder) ClassPath(org.jboss.arquillian.container.se.api.ClassPath) Configuration(org.jboss.shrinkwrap.api.Configuration) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) ServiceExtensionLoader(org.jboss.shrinkwrap.impl.base.ServiceExtensionLoader) MavenDependencyExclusion(org.jboss.shrinkwrap.resolver.api.maven.coordinate.MavenDependencyExclusion) MavenDependency(org.jboss.shrinkwrap.resolver.api.maven.coordinate.MavenDependency) ScopeType(org.jboss.shrinkwrap.resolver.api.maven.ScopeType) MavenResolvedArtifact(org.jboss.shrinkwrap.resolver.api.maven.MavenResolvedArtifact) LinkedList(java.util.LinkedList) MavenCoordinate(org.jboss.shrinkwrap.resolver.api.maven.coordinate.MavenCoordinate) Domain(org.jboss.shrinkwrap.api.Domain) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) ServiceExtensionLoader(org.jboss.shrinkwrap.impl.base.ServiceExtensionLoader) ExtensionLoader(org.jboss.shrinkwrap.api.ExtensionLoader)

Example 2 with MavenCoordinate

use of org.jboss.shrinkwrap.resolver.api.maven.coordinate.MavenCoordinate in project syndesis by syndesisio.

the class RepackageExtensionMojo method getAdditionalFilters.

@Override
protected Collection<ArtifactsFilter> getAdditionalFilters() {
    Collection<MavenDependency> dependencies = new HashSet<>();
    if (StringUtils.isNotBlank(blackListedBoms)) {
        addCustomBoms(dependencies);
    } else {
        addDefaultBOMs(dependencies);
    }
    if (StringUtils.isNotBlank(blackListedGAVs)) {
        addCustomGAVs(dependencies);
    } else {
        addDefaultGAVs(dependencies);
    }
    if (getLog().isDebugEnabled()) {
        getLog().debug("Filtering out dependencies from the following BOMs: " + bomsUsed);
        getLog().debug("Dependencies to be filtered out:");
        dependencies.stream().sorted(Comparator.comparing(MavenCoordinate::toCanonicalForm)).forEach(mavenDependency -> getLog().debug(mavenDependency.toCanonicalForm()));
    }
    List<ArtifactsFilter> filters = new ArrayList<>(dependencies.size());
    for (MavenCoordinate dep : dependencies) {
        filters.add(newExcludeFilter(dep));
    }
    return filters;
}
Also used : MavenCoordinate(org.jboss.shrinkwrap.resolver.api.maven.coordinate.MavenCoordinate) ArrayList(java.util.ArrayList) ArtifactsFilter(org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter) MavenDependency(org.jboss.shrinkwrap.resolver.api.maven.coordinate.MavenDependency) HashSet(java.util.HashSet)

Example 3 with MavenCoordinate

use of org.jboss.shrinkwrap.resolver.api.maven.coordinate.MavenCoordinate in project wildfly-swarm by wildfly-swarm.

the class ShrinkwrapArtifactResolvingHelper method resolveAll.

@Override
public Set<ArtifactSpec> resolveAll(final Collection<ArtifactSpec> specs, boolean transitive, boolean defaultExcludes) {
    if (specs.isEmpty()) {
        return Collections.emptySet();
    }
    MavenResolutionStrategy transitivityStrategy = (transitive ? TransitiveStrategy.INSTANCE : NonTransitiveStrategy.INSTANCE);
    resetListeners();
    final MavenResolvedArtifact[] artifacts = withResolver(r -> {
        specs.forEach(spec -> r.addDependency(createMavenDependency(spec)));
        return r.resolve().using(transitivityStrategy).as(MavenResolvedArtifact.class);
    });
    return Arrays.stream(artifacts).map(artifact -> {
        final MavenCoordinate coord = artifact.getCoordinate();
        return new ArtifactSpec(artifact.getScope().toString(), coord.getGroupId(), coord.getArtifactId(), coord.getVersion(), coord.getPackaging().getId(), coord.getClassifier(), artifact.asFile());
    }).collect(Collectors.toSet());
}
Also used : Arrays(java.util.Arrays) MavenResolutionStrategy(org.jboss.shrinkwrap.resolver.api.maven.strategy.MavenResolutionStrategy) MavenChecksumPolicy(org.jboss.shrinkwrap.resolver.api.maven.repository.MavenChecksumPolicy) Settings(org.apache.maven.settings.Settings) PackagingType(org.jboss.shrinkwrap.resolver.api.maven.PackagingType) AtomicReference(java.util.concurrent.atomic.AtomicReference) Maven(org.jboss.shrinkwrap.resolver.api.maven.Maven) MavenRemoteRepository(org.jboss.shrinkwrap.resolver.api.maven.repository.MavenRemoteRepository) ConfigurableMavenWorkingSessionImpl(org.jboss.shrinkwrap.resolver.impl.maven.ConfigurableMavenWorkingSessionImpl) TransitiveStrategy(org.jboss.shrinkwrap.resolver.api.maven.strategy.TransitiveStrategy) MavenDependency(org.jboss.shrinkwrap.resolver.api.maven.coordinate.MavenDependency) MavenCoordinates(org.jboss.shrinkwrap.resolver.api.maven.coordinate.MavenCoordinates) Method(java.lang.reflect.Method) ScopeType(org.jboss.shrinkwrap.resolver.api.maven.ScopeType) MavenRemoteRepositories(org.jboss.shrinkwrap.resolver.api.maven.repository.MavenRemoteRepositories) RepositoryPolicy(org.eclipse.aether.repository.RepositoryPolicy) Collection(java.util.Collection) SwarmInternalProperties(org.wildfly.swarm.spi.api.internal.SwarmInternalProperties) Set(java.util.Set) Collectors(java.util.stream.Collectors) File(java.io.File) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) InvocationTargetException(java.lang.reflect.InvocationTargetException) MavenDependencies(org.jboss.shrinkwrap.resolver.api.maven.coordinate.MavenDependencies) MavenWorkingSessionContainer(org.jboss.shrinkwrap.resolver.impl.maven.MavenWorkingSessionContainer) ArtifactResolvingHelper(org.wildfly.swarm.tools.ArtifactResolvingHelper) RepositoryListener(org.eclipse.aether.RepositoryListener) ConfigurableMavenResolverSystem(org.jboss.shrinkwrap.resolver.api.maven.ConfigurableMavenResolverSystem) MavenResolvedArtifact(org.jboss.shrinkwrap.resolver.api.maven.MavenResolvedArtifact) MavenUpdatePolicy(org.jboss.shrinkwrap.resolver.api.maven.repository.MavenUpdatePolicy) NonTransitiveStrategy(org.jboss.shrinkwrap.resolver.api.maven.strategy.NonTransitiveStrategy) MavenCoordinate(org.jboss.shrinkwrap.resolver.api.maven.coordinate.MavenCoordinate) Collections(java.util.Collections) ArtifactSpec(org.wildfly.swarm.tools.ArtifactSpec) MavenResolutionStrategy(org.jboss.shrinkwrap.resolver.api.maven.strategy.MavenResolutionStrategy) MavenResolvedArtifact(org.jboss.shrinkwrap.resolver.api.maven.MavenResolvedArtifact) ArtifactSpec(org.wildfly.swarm.tools.ArtifactSpec) MavenCoordinate(org.jboss.shrinkwrap.resolver.api.maven.coordinate.MavenCoordinate)

Aggregations

MavenCoordinate (org.jboss.shrinkwrap.resolver.api.maven.coordinate.MavenCoordinate)3 MavenDependency (org.jboss.shrinkwrap.resolver.api.maven.coordinate.MavenDependency)3 File (java.io.File)2 MavenResolvedArtifact (org.jboss.shrinkwrap.resolver.api.maven.MavenResolvedArtifact)2 ScopeType (org.jboss.shrinkwrap.resolver.api.maven.ScopeType)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 Set (java.util.Set)1 TreeMap (java.util.TreeMap)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Collectors (java.util.stream.Collectors)1 Settings (org.apache.maven.settings.Settings)1