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

The following examples show how to use org.jboss.shrinkwrap.resolver.api.maven.ScopeType. 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: JWTOrFormAuthenticationFilterTest.java    From shiro-jwt with MIT License 6 votes vote down vote up
@Deployment
public static Archive<?> deployment() {

    File[] filesCompile = Maven.resolver().loadPomFromFile("pom.xml").importDependencies(ScopeType.COMPILE).resolve().withTransitivity().asFile();
    File[] filestest = Maven.resolver().loadPomFromFile("pom.xml")
            .resolve("com.fasterxml.jackson.core:jackson-annotations", "com.fasterxml.jackson.core:jackson-databind", "com.fasterxml.jackson.core:jackson-core").withTransitivity().asFile();

    JavaArchive jar = ShrinkWrap.create(MavenImporter.class)
            .loadPomFromFile("pom.xml")
            .importBuildOutput()
            .as(JavaArchive.class);

    WebArchive war = ShrinkWrap.create(WebArchive.class)
            .addAsLibraries(filestest)
            .addAsLibraries(jar)
            .addAsLibraries(filesCompile)
            .addClasses(UserDefaultExample.class, UserRepositoryExample.class)
            .addClasses(JAXRSConfigurationExample.class, ObjectMapperProviderExample.class, ResourceExample.class)
            .addAsWebInfResource("WEB-INF/test.shiro.ini", "shiro.ini")
            .addAsWebInfResource("WEB-INF/web.xml", "web.xml")
            .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");

    System.out.println(war.toString(true));

    return war;
}
 
Example #2
Source File: EarWebAppFirstClassLoaderTest.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Deployment(testable = false)
public static Archive<?> ear() {
    final File[] joda = Maven.configureResolver()
            .workOffline()
            .withClassPathResolution(true)
            .resolve("joda-time:joda-time:2.5")
            .using(new AcceptScopesStrategy(ScopeType.COMPILE, ScopeType.RUNTIME))
            .asFile();
    return ShrinkWrap.create(EnterpriseArchive.class, "broken.ear")
            .addAsLibraries(joda)
            .addAsModule(ShrinkWrap.create(WebArchive.class, "broken-web.war")
                    .addClasses(LoadJodaFromTheWebAppResource.class)
                    .addAsManifestResource(new StringAsset(
                            "<Context>" +
                                    "<Loader className=\"" + TomEEWebappLoader.class.getName() +
                                    "\" loaderClass=\"" + WebAppFirstEarClassLoader.class.getName() + "\" />" +
                                    "</Context>"), "context.xml")
                    .addAsLibraries(joda));
}
 
Example #3
Source File: EarClassLoaderTest.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Deployment(testable = false)
public static Archive<?> ear() {
    return ShrinkWrap.create(EnterpriseArchive.class, "broken.ear")
            .addAsModule(
                    ShrinkWrap.create(WebArchive.class, "broken-web.war")
                            .addClasses(LoadJodaFromTheWebAppResource.class)
                            .addAsLibraries(
                                    Maven.configureResolver()
                                            .workOffline()
                                            .withClassPathResolution(true)
                                            .resolve("joda-time:joda-time:2.5")
                                            .using(new AcceptScopesStrategy(ScopeType.COMPILE, ScopeType.RUNTIME))
                                            .asFile()
                            )
            );
}
 
Example #4
Source File: KeycloakDependenciesResolver.java    From keycloak with Apache License 2.0 6 votes vote down vote up
public static File[] resolveDependencies(String canonicalForm) {
    if (dependencies.containsKey(canonicalForm)) {
        return dependencies.get(canonicalForm);
    }

    log.info("Resolving " + canonicalForm + "'s dependencies");
    PomEquippedResolveStage resolver = Maven.configureResolverViaPlugin();

    File[] files = resolver.addDependency(MavenDependencies.createDependency(canonicalForm, ScopeType.COMPILE, false))
            .resolve().withTransitivity().asFile();

    dependencies.put(canonicalForm, files);

    log.info("Resolving dependencies is finished with " + files.length + " files");

    return dependencies.get(canonicalForm);
}
 
Example #5
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 #6
Source File: ShrinkwrapArtifactResolvingHelper.java    From thorntail with Apache License 2.0 5 votes vote down vote up
public MavenDependency createMavenDependency(final ArtifactSpec spec) {
    final MavenCoordinate newCoordinate = MavenCoordinates.createCoordinate(
            spec.groupId(),
            spec.artifactId(),
            spec.version(),
            PackagingType.of(spec.type()),
            spec.classifier());
    return MavenDependencies.createDependency(newCoordinate, ScopeType.fromScopeType(spec.scope), false);
}
 
Example #7
Source File: Utils.java    From arquillian-container-chameleon with Apache License 2.0 5 votes vote down vote up
public static MavenDependency[] toMavenDependencies(String[] dependencies, String[] exclusions) {
    MavenDependencyExclusion[] mavenExclusions = toMavenExclusions(exclusions);
    MavenDependency[] mavenDependencies = new MavenDependency[dependencies.length];
    for (int i = 0; i < dependencies.length; i++) {
        mavenDependencies[i] = MavenDependencies.createDependency(
            dependencies[i],
            ScopeType.COMPILE,
            false,
            mavenExclusions);
    }
    return mavenDependencies;
}
 
Example #8
Source File: ResteasyTomcatServerBootstrap.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
protected void addRuntimeSpecificLibraries(WebArchive wa, PomEquippedResolveStage resolver) {
  // inject rest easy version to differentiate between resteasy and wildfly-compatibility profile
  String restEasyVersion = System.getProperty("restEasyVersion");

  wa.addAsLibraries(resolver.addDependencies(
    MavenDependencies.createDependency("org.jboss.resteasy:resteasy-jaxrs:" + restEasyVersion, ScopeType.TEST, false,
      MavenDependencies.createExclusion("org.apache.httpcomponents:httpclient"))).resolve()
    .withTransitivity().asFile());
}
 
Example #9
Source File: DeploymentHelper.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public static JavaArchive[] getEngineSpring() {
  if(CACHED_SPRING_ASSETS != null) {
    return CACHED_SPRING_ASSETS;
  } else {

    JavaArchive[] resolvedArchives = Maven.configureResolver()
        .workOffline()
        .loadPomFromFile("pom.xml")
        .addDependencies(
            MavenDependencies.createDependency("org.camunda.bpm:camunda-engine-spring", ScopeType.COMPILE, false,
                MavenDependencies.createExclusion("org.camunda.bpm:camunda-engine")),
                MavenDependencies.createDependency("org.springframework:spring-context", ScopeType.COMPILE, false),
                MavenDependencies.createDependency("org.springframework:spring-jdbc", ScopeType.COMPILE, false),
                MavenDependencies.createDependency("org.springframework:spring-tx", ScopeType.COMPILE, false),
                MavenDependencies.createDependency("org.springframework:spring-orm", ScopeType.COMPILE, false),
                MavenDependencies.createDependency("org.springframework:spring-web", ScopeType.COMPILE, false))
        .resolve()
        .withTransitivity()
        .as(JavaArchive.class);

    if(resolvedArchives.length == 0) {
      throw new RuntimeException("could not resolve org.camunda.bpm:camunda-engine-spring");
    } else {
      CACHED_SPRING_ASSETS = resolvedArchives;
      return CACHED_SPRING_ASSETS;
    }
  }

}
 
Example #10
Source File: WebArchiveBuilder.java    From krazo with Apache License 2.0 4 votes vote down vote up
public WebArchiveBuilder addDependency(String coordinates) {
    addDependencies(MavenDependencies.createDependency(coordinates, ScopeType.RUNTIME,false));
    return this;
}
 
Example #11
Source File: WebArchiveBuilder.java    From ozark with Apache License 2.0 4 votes vote down vote up
public WebArchiveBuilder addDependency(String coordinates) {
    addDependencies(MavenDependencies.createDependency(coordinates, ScopeType.RUNTIME,false));
    return this;
}
 
Example #12
Source File: DeploymentFactory.java    From pnc with Apache License 2.0 4 votes vote down vote up
public static Archive<?> createDatastoreDeployment() {

        JavaArchive datastoreJar = ShrinkWrap.create(JavaArchive.class, "datastore.jar")
                .addPackages(true, "org.jboss.pnc.datastore")
                .addAsManifestResource("test-persistence.xml", "persistence.xml")
                .addAsManifestResource("logback.xml");

        logger.info("Deployment datastoreJar: {}", datastoreJar.toString(true));

        File[] dependencies = Maven.resolver()
                .loadPomFromFile("pom.xml")
                .importDependencies(
                        ScopeType.RUNTIME,
                        ScopeType.COMPILE,
                        ScopeType.TEST,
                        ScopeType.IMPORT,
                        ScopeType.SYSTEM)
                .resolve()
                .withTransitivity()
                .asFile();

        // remove "model-<version>.jar" from the archive and add it as "model.jar" so we can reference it in the
        // test-persistence.xml
        ObjectWrapper<File> modelJarWrapper = new ObjectWrapper();
        List<File> dependenciesFiltered = Arrays.stream(dependencies)
                .filter(jar -> extractModelJar(jar, modelJarWrapper))
                .filter(jar -> !mockJarMatches(jar))
                .collect(Collectors.toList());
        File modelJar = modelJarWrapper.get();
        if (modelJar == null) {
            throw new RuntimeException(new DeploymentException("Cannot find model*.jar"));
        }

        Optional<File> mockJarOptional = Arrays.stream(dependencies).filter(jar -> mockJarMatches(jar)).findAny();
        if (!mockJarOptional.isPresent()) {
            throw new RuntimeException(new DeploymentException("Cannot find mock*.jar"));
        }

        JavaArchive mockJar = ShrinkWrap.createFromZipFile(JavaArchive.class, mockJarOptional.get());
        mockJar.addAsManifestResource("mock-beans.xml", "beans.xml");

        logger.info("Deployment mockJar: {}", mockJar.toString(true));

        EnterpriseArchive enterpriseArchive = ShrinkWrap.create(EnterpriseArchive.class, "datastore-test.ear")
                .addAsModule(datastoreJar)
                .addAsLibraries(dependenciesFiltered.toArray(new File[dependenciesFiltered.size()]))
                .addAsLibrary(mockJar)
                .addAsLibrary(modelJar, "model.jar");

        addManifestDependencies(enterpriseArchive, "com.google.guava  export meta-inf");

        logger.info("Deployment: {}", enterpriseArchive.toString(true));

        return enterpriseArchive;
    }
 
Example #13
Source File: TomcatServerBootstrap.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public void start() {
  Properties serverProperties = readProperties();
  int port = Integer.parseInt(serverProperties.getProperty(PORT_PROPERTY));

  tomcat = new Tomcat();
  tomcat.setPort(port);
  tomcat.setBaseDir(getWorkingDir());

  tomcat.getHost().setAppBase(getWorkingDir());
  tomcat.getHost().setAutoDeploy(true);
  tomcat.getHost().setDeployOnStartup(true);

  String contextPath = "/" + getContextPath();

  // 1) Must not use shrinkwrap offline mode (see longer explanation at the end of the file)
  // 2) Must use configuration via Shrinkwrap Maven plugin (see pom.xml for plugin definition);
  //    This forwards things like the location of the settings.xml file to Shrinkwrap. We need
  //    that for our CI where settings.xml is not in the default location.
  PomEquippedResolveStage resolver = Maven.configureResolver()
    .useLegacyLocalRepo(true).configureViaPlugin();

  WebArchive wa = ShrinkWrap.create(WebArchive.class, "rest-test.war").setWebXML(webXmlPath)
      .addAsLibraries(resolver.resolve("org.codehaus.jackson:jackson-jaxrs:1.6.5").withTransitivity().asFile())
      .addAsLibraries(resolver.addDependencies(
          MavenDependencies.createDependency("org.mockito:mockito-core", ScopeType.TEST, false,
          MavenDependencies.createExclusion("org.hamcrest:hamcrest-core"))).resolve()
            .withTransitivity().asFile())

      .addAsServiceProvider(ProcessEngineProvider.class, MockedProcessEngineProvider.class)
      .add(new ClassLoaderAsset("runtime/tomcat/context.xml"), "META-INF/context.xml")
      .addPackages(true, "org.camunda.bpm.engine.rest");

  addRuntimeSpecificLibraries(wa, resolver);
  wa.setWebXML(webXmlPath);

  String webAppPath = getWorkingDir() + "/" + getContextPath() + ".war";

  wa.as(ZipExporter.class).exportTo(new File(webAppPath), true);

  tomcat.addWebapp(tomcat.getHost(), contextPath, webAppPath);

  try {
    tomcat.start();
  } catch (LifecycleException e) {
    throw new RuntimeException(e);
  }
}
 
Example #14
Source File: Mvn.java    From tomee with Apache License 2.0 2 votes vote down vote up
/**
 * Server war without tests clases.
 *
 * @return create a war with src/main/resources, src/main/webapp and all compile, runtime and test dependencies
 */
public static Archive<?> testWar() {
    return new Builder().scopes(ScopeType.COMPILE, ScopeType.RUNTIME, ScopeType.TEST).build();
}