use of org.jboss.shrinkwrap.resolver.api.maven.MavenResolvedArtifact 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();
}
use of org.jboss.shrinkwrap.resolver.api.maven.MavenResolvedArtifact in project camel by apache.
the class ArquillianPackager method lookForVersionMismatch.
private static void lookForVersionMismatch(ITestConfig config, List<MavenResolvedArtifact> dependencyArtifacts) {
Set<String> ignore = new HashSet<>();
ignore.addAll(config.getIgnoreLibraryMismatch());
// A list of known libraries that don't follow the all-artifacts-same-version convention
ignore.add("com.atlassian.jira:jira-rest-java-client-api");
// latest version not available
ignore.add("com.fasterxml.jackson.module:jackson-module-scala_2.11");
ignore.add("com.github.jnr");
ignore.add("com.sun.xml.bind:jaxb-xjc");
ignore.add("commons-beanutils:commons-beanutils");
ignore.add("io.fabric8:kubernetes-");
// an old version
ignore.add("io.netty:netty:jar");
ignore.add("io.swagger:swagger-parser");
ignore.add("org.apache.commons");
ignore.add("org.apache.curator");
ignore.add("org.apache.cxf:cxf-api");
ignore.add("org.apache.geronimo.specs");
ignore.add("org.apache.maven");
ignore.add("org.apache.parquet");
ignore.add("org.apache.velocity");
ignore.add("org.apache.qpid:qpid-jms-client");
ignore.add("org.opensaml");
// No problem
ignore.add("org.ow2.asm");
ignore.add("org.codehaus.plexus");
ignore.add("org.jboss.arquillian.container");
ignore.add("org.jboss:");
// does not match with hibernate-core
ignore.add("org.hibernate:hibernate-validator");
ignore.add("org.mortbay.jetty:servlet-api-2.5");
ignore.add("org.scala-lang:scala-compiler");
ignore.add("org.easytesting");
ignore.add("net.openhft");
// v 2.21 does not exist
ignore.add("net.sourceforge.htmlunit:htmlunit-core-js");
ignore.add("org.springframework.data");
ignore.add("org.springframework.security:spring-security-jwt");
ignore.add("org.springframework.social");
// No problem
ignore.add("org.webjars");
ignore.add("stax:stax-api");
ignore.add("xml-apis:xml-apis-ext");
Map<String, Map<String, String>> status = new TreeMap<>();
Set<String> mismatches = new TreeSet<>();
for (MavenResolvedArtifact a : dependencyArtifacts) {
boolean ignoreCheck = false;
for (String i : ignore) {
if (getIdentifier(a).startsWith(i)) {
ignoreCheck = true;
break;
}
}
if (ignoreCheck) {
continue;
}
String group = a.getCoordinate().getGroupId();
String artifact = a.getCoordinate().getArtifactId();
String version = a.getCoordinate().getVersion();
String artifactPrefix = artifact;
if (artifactPrefix.contains("-")) {
artifactPrefix = artifactPrefix.substring(0, artifactPrefix.indexOf("-"));
}
String prefixId = group + ":" + artifactPrefix;
if (!status.containsKey(prefixId)) {
status.put(prefixId, new TreeMap<>());
}
for (String anotherVersion : status.get(prefixId).values()) {
if (!sameVersion(anotherVersion, version)) {
mismatches.add(prefixId);
}
}
status.get(prefixId).put(getIdentifier(a), version);
}
StringBuilder message = new StringBuilder();
for (String mismatch : mismatches) {
message.append("Found mismatch for dependency " + mismatch + ":\n");
for (String art : status.get(mismatch).keySet()) {
String ver = status.get(mismatch).get(art);
message.append(" - " + art + " --> " + ver + "\n");
}
}
if (message.length() > 0) {
String alert = "Library version mismatch found.\n" + message;
if (FAIL_ON_RELATED_LIBRARY_MISMATCH) {
throw new RuntimeException(alert);
} else {
debug(alert);
}
}
}
use of org.jboss.shrinkwrap.resolver.api.maven.MavenResolvedArtifact in project camel by apache.
the class ArquillianPackager method merge.
private static List<MavenResolvedArtifact> merge(ITestConfig config, List<MavenResolvedArtifact> runtimeDependencies, List<MavenResolvedArtifact> testDependencies) {
Set<String> runtimeArtifacts = new HashSet<>();
for (MavenResolvedArtifact a : runtimeDependencies) {
runtimeArtifacts.add(getIdentifier(a));
}
Map<String, String> testVersions = new HashMap<>();
for (MavenResolvedArtifact a : testDependencies) {
testVersions.put(getIdentifier(a), a.getCoordinate().getVersion());
}
List<MavenResolvedArtifact> result = new LinkedList<>();
List<String> problems = new LinkedList<>();
for (MavenResolvedArtifact a : runtimeDependencies) {
String version = a.getCoordinate().getVersion();
String testVersion = testVersions.get(getIdentifier(a));
if (testVersion != null && !sameVersion(testVersion, version)) {
problems.add("Versions for artifact " + getIdentifier(a) + " are different between runtime (" + version + ") and test (" + testVersion + ") scopes");
}
result.add(a);
}
for (MavenResolvedArtifact a : testDependencies) {
if (!runtimeArtifacts.contains(getIdentifier(a))) {
result.add(a);
}
}
if (!problems.isEmpty()) {
StringBuilder message = new StringBuilder();
message.append("Some problems found while merging test dependencies:\n");
for (String problem : problems) {
message.append(" - " + problem + "\n");
}
if (FAIL_ON_TEST_LIBRARY_MISMATCH) {
throw new RuntimeException(message.toString());
} else {
debug(message.toString());
}
}
return result;
}
Aggregations