org.wildfly.swarm.bootstrap.util.BootstrapProperties Java Examples
The following examples show how to use
org.wildfly.swarm.bootstrap.util.BootstrapProperties.
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: DefaultDeploymentFactory.java From ARCHIVE-wildfly-swarm with Apache License 2.0 | 6 votes |
protected boolean setupUsingAppPath(Archive<?> archive) throws IOException { final String appPath = System.getProperty(BootstrapProperties.APP_PATH); if (appPath != null) { final Path path = Paths.get(appPath); if (Files.isDirectory(path)) { Files.walkFileTree(path, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Path simple = path.relativize(file); archive.add(new FileAsset(file.toFile()), convertSeparators(simple)); return super.visitFile(file, attrs); } }); } else { archive.as(ZipImporter.class) .importFrom(path.toFile()); } return true; } return false; }
Example #2
Source File: ApplicationEnvironment.java From thorntail with Apache License 2.0 | 6 votes |
/** * Do not construct directly. */ private ApplicationEnvironment() { try { if (System.getProperty(BootstrapProperties.IS_UBERJAR) != null) { this.mode = Mode.UBERJAR; if (!loadWildFlySwarmApplicationManifestFromClasspath()) { loadWildFlySwarmApplicationManifestFromTCCL(); } } else { this.mode = Mode.CLASSPATH; loadDependencyTree(); loadFractionManifestsFromClasspath(); } } catch (IOException e) { throw new RuntimeException(e); } }
Example #3
Source File: WildFlySwarmManifest.java From thorntail with Apache License 2.0 | 6 votes |
private void setupProperties() { // enumerate all properties, not just those with string // values, because Gradle (and others) can set non-string // values for things like swarm.http.port (integer) Enumeration<?> names = this.properties.propertyNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); Object value = this.properties.get(name); if (value != null) { if (System.getProperty(name) == null) { System.setProperty(name, value.toString()); } } } if (this.bundleDependencies != null && this.bundleDependencies) { System.setProperty(BootstrapProperties.BUNDLED_DEPENDENCIES, this.bundleDependencies.toString()); } }
Example #4
Source File: DefaultDeploymentFactory.java From ARCHIVE-wildfly-swarm with Apache License 2.0 | 6 votes |
protected static String determineName(final String suffix) { String prop = System.getProperty(BootstrapProperties.APP_PATH); if (prop != null) { final File file = new File(prop); final String name = file.getName(); if (name.endsWith(suffix)) { return name; } return name + suffix; } prop = System.getProperty(BootstrapProperties.APP_ARTIFACT); if (prop != null) { return prop; } return UUID.randomUUID().toString() + suffix; }
Example #5
Source File: StartTask.java From thorntail with Apache License 2.0 | 6 votes |
private SwarmExecutor warExecutor() { getLogger().info("Creating WAR Thorntail executor."); final String finalName = ThorntailUtils.getArchiveTask(getProject()).getArchiveName(); final SwarmExecutor executor = new SwarmExecutor() .withModules(getModules()) .withProperty(BootstrapProperties.APP_NAME, finalName) .withClassPathEntries(getClassPathEntries(Collections.singletonList(getArchivePath().toPath()), false)); if (extension.getMainClassName() != null) { getLogger().info("With Thorntail app main class " + extension.getMainClassName()); executor.withMainClass(extension.getMainClassName()); } else { getLogger().info("With default Thorntail app main class."); executor.withDefaultMainClass(); } executor.withProperty(BootstrapProperties.APP_PATH, getArchivePath().getPath()); return executor; }
Example #6
Source File: DaemonServiceActivator.java From ARCHIVE-wildfly-swarm with Apache License 2.0 | 6 votes |
@Override public void start(StartContext context) throws StartException { try { final String artifactName = System.getProperty(BootstrapProperties.APP_ARTIFACT); if (artifactName == null) { throw new StartException("Failed to find artifact name under " + BootstrapProperties.APP_ARTIFACT); } final ModuleLoader serviceLoader = this.serviceLoader.getValue(); final String moduleName = "deployment." + artifactName; final Module module = serviceLoader.loadModule(ModuleIdentifier.create(moduleName)); if (module == null) { throw new StartException("Failed to find deployment module under " + moduleName); } //TODO: allow overriding the default port? this.server = Server.create("localhost", 12345, module.getClassLoader()); this.server.start(); } catch (ModuleLoadException | ServerLifecycleException e) { throw new StartException(e); } }
Example #7
Source File: StartMojo.java From ARCHIVE-wildfly-swarm with Apache License 2.0 | 6 votes |
@SuppressWarnings("ThrowableResultOfMethodCallIgnored") protected SwarmExecutor warExecutor() throws MojoFailureException { getLog().info("Starting .war"); String finalName = this.project.getBuild().getFinalName(); if (!finalName.endsWith(".war")) { finalName = finalName + ".war"; } return new SwarmExecutor() .withModules(expandModules()) .withClassPathEntries(dependencies(false)) .withProperty(BootstrapProperties.APP_PATH, Paths.get(this.projectBuildDir, finalName).toString()) .withDefaultMainClass(); }
Example #8
Source File: BuildTool.java From ARCHIVE-wildfly-swarm with Apache License 2.0 | 6 votes |
private void addWildFlySwarmProperties() throws IOException { Properties props = new Properties(); Enumeration<?> propNames = this.properties.propertyNames(); while (propNames.hasMoreElements()) { String eachName = (String) propNames.nextElement(); String eachValue = this.properties.get(eachName).toString(); props.put(eachName, eachValue); } props.setProperty(BootstrapProperties.APP_ARTIFACT, this.projectAsset.getSimpleName()); if (this.bundleDependencies) { props.setProperty(BootstrapProperties.BUNDLED_DEPENDENCIES, "true"); } ByteArrayOutputStream propsBytes = new ByteArrayOutputStream(); props.store(propsBytes, "Generated by WildFly Swarm"); this.archive.addAsManifestResource(new ByteArrayAsset(propsBytes.toByteArray()), "wildfly-swarm.properties"); }
Example #9
Source File: InVMSimpleContainer.java From ARCHIVE-wildfly-swarm with Apache License 2.0 | 6 votes |
@Override public void start(Archive<?> archive) throws Exception { archive.as(ServiceActivatorArchive.class) .addServiceActivator(DaemonServiceActivator.class) .as(JARArchive.class) .addModule("org.wildfly.swarm.arquillian.daemon"); System.setProperty(BootstrapProperties.APP_ARTIFACT, archive.getName()); if (isContainerFactory(this.testClass)) { archive.as(JARArchive.class) .addModule("org.wildfly.swarm.container") .addModule("org.wildfly.swarm.configuration"); Object factory = this.testClass.newInstance(); this.container = ((ContainerFactory) factory).newContainer(); } else { this.container = new Container(); } this.container.start().deploy(archive); }
Example #10
Source File: StartMojo.java From thorntail with Apache License 2.0 | 5 votes |
protected SwarmExecutor warExecutor() throws MojoFailureException { getLog().info("Starting .war"); String finalName = this.project.getBuild().getFinalName(); if (!finalName.endsWith(WAR_FILE_EXTENSION)) { finalName = finalName + WAR_FILE_EXTENSION; } Path warPath = Paths.get(this.projectBuildDir, finalName); SwarmExecutor executor = executor(warPath, finalName, false); // Specify swarm.app.path property so that repackaged war is used executor.withProperty(BootstrapProperties.APP_PATH, warPath.toString()); return executor; }
Example #11
Source File: AbstractBootstrapIntegrationTestCase.java From ARCHIVE-wildfly-swarm with Apache License 2.0 | 5 votes |
protected JavaArchive createBootstrapArchive(String mainClassName, String appArtifact) throws IOException { JavaArchive archive = ShrinkWrap.create(JavaArchive.class); archive.as(ZipImporter.class).importFrom(new JarFile(findBootstrapJar())); Properties props = new Properties(); if (appArtifact != null) { props.put(BootstrapProperties.APP_ARTIFACT, appArtifact); } ByteArrayOutputStream propsOut = new ByteArrayOutputStream(); props.store(propsOut, ""); propsOut.close(); archive.addAsManifestResource(new ByteArrayAsset(propsOut.toByteArray()), "wildfly-swarm.properties"); if (appArtifact != null) { String conf = "path:" + appArtifact + "\n"; archive.addAsManifestResource(new ByteArrayAsset(conf.getBytes()), "wildfly-swarm-application.conf"); } if (mainClassName != null) { Manifest manifest = new Manifest(); manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0"); manifest.getMainAttributes().put(new Attributes.Name("Wildfly-Swarm-Main-Class"), mainClassName); ByteArrayOutputStream out = new ByteArrayOutputStream(); manifest.write(out); out.close(); archive.addAsManifestResource(new ByteArrayAsset(out.toByteArray()), "MANIFEST.MF"); } return archive; }
Example #12
Source File: DefaultDeploymentFactory.java From ARCHIVE-wildfly-swarm with Apache License 2.0 | 5 votes |
protected boolean setupUsingAppArtifact(Archive<?> archive) throws IOException { final String appArtifact = System.getProperty(BootstrapProperties.APP_ARTIFACT); if (appArtifact != null) { try (InputStream in = ClassLoader.getSystemClassLoader().getResourceAsStream("_bootstrap/" + appArtifact)) { archive.as(ZipImporter.class) .importFrom(in); } return true; } return false; }
Example #13
Source File: Container.java From ARCHIVE-wildfly-swarm with Apache License 2.0 | 5 votes |
public static boolean isFatJar() throws IOException { URL location = Container.class.getProtectionDomain().getCodeSource().getLocation(); Path root = null; if (location.getProtocol().equals("file")) { try { root = Paths.get(location.toURI()); } catch (URISyntaxException e) { throw new IOException(e); } } else if (location.toExternalForm().startsWith("jar:file:")) { return true; } if (Files.isRegularFile(root)) { try (JarFile jar = new JarFile(root.toFile())) { ZipEntry propsEntry = jar.getEntry("META-INF/wildfly-swarm.properties"); if (propsEntry != null) { try (InputStream in = jar.getInputStream(propsEntry)) { Properties props = new Properties(); props.load(in); if (props.containsKey(BootstrapProperties.APP_ARTIFACT)) { System.setProperty(BootstrapProperties.APP_ARTIFACT, props.getProperty(BootstrapProperties.APP_ARTIFACT)); } Set<String> names = props.stringPropertyNames(); for (String name : names) { String value = props.getProperty(name); if (System.getProperty(name) == null) { System.setProperty(name, value); } } } return true; } } } return false; }
Example #14
Source File: BuildTool.java From thorntail with Apache License 2.0 | 5 votes |
private void addWildFlySwarmApplicationManifest() { WildFlySwarmManifest manifest = this.dependencyManager.getWildFlySwarmManifest(); this.properties.put("thorntail.uberjar.build.user", System.getProperty("user.name")); if (!this.hollow) { this.properties.put(BootstrapProperties.APP_ARTIFACT, this.projectAsset.getSimpleName()); } manifest.setProperties(this.properties); manifest.bundleDependencies(this.bundleDependencies); manifest.setMainClass(this.mainClass); manifest.setHollow(this.hollow); this.archive.add(new ByteArrayAsset(manifest.toString().getBytes(StandardCharsets.UTF_8)), WildFlySwarmManifest.CLASSPATH_LOCATION); }
Example #15
Source File: StartTask.java From thorntail with Apache License 2.0 | 5 votes |
private SwarmExecutor jarExecutor() { getLogger().info("Creating WAR Thorntail executor."); final String finalName = ThorntailUtils.getArchiveTask(getProject()).getArchiveName(); // TODO: application path could possibly contain more classesDirs // TODO: getClassesDir() no longer exists in gradle 4+?, gradle-plugins dep should be upgraded, but current // version is not available as a maven artifact // getProject().getConvention().getPlugin(JavaPluginConvention.class).getSourceSets() // .getByName(SourceSet.MAIN_SOURCE_SET_NAME).getOutput().getClassesDir(); final List<Path> sourcePaths = Arrays.asList(getProject().getBuildDir().toPath().resolve("classes/java/main"), getProject().getBuildDir().toPath().resolve("resources/main")); getLogger().info("Source paths: {}", sourcePaths); final SwarmExecutor executor = new SwarmExecutor() .withModules(getModules()) .withProperty(BootstrapProperties.APP_NAME, finalName) .withClassPathEntries(sourcePaths) .withClassPathEntries(getClassPathEntries(sourcePaths, true)); if (extension.getMainClassName() != null) { getLogger().info("With Thorntail app main class " + extension.getMainClassName()); executor.withMainClass(extension.getMainClassName()); } else { getLogger().info("With default Thorntail app main class."); executor.withDefaultMainClass(); } return executor; }
Example #16
Source File: Main.java From thorntail with Apache License 2.0 | 5 votes |
public static void main(String... args) throws Throwable { try { Performance.start(); BootstrapUtil.convertSwarmSystemPropertiesToThorntail(); //TODO Move property key to -spi System.setProperty(BootstrapProperties.IS_UBERJAR, Boolean.TRUE.toString()); String processFile = System.getProperty(MAIN_PROCESS_FILE); if (processFile != null) { shutdownService = Executors.newSingleThreadExecutor(); shutdownService.submit(() -> { File uuidFile = new File(processFile); try { File watchedDir = uuidFile.getParentFile(); register(watchedDir); processEvents(watchedDir, uuidFile.toPath()); if (mainInvoker != null) { mainInvoker.stop(); } //Exit gracefully System.exit(0); } catch (Exception e) { e.printStackTrace(); } return null; } ); } new Main(args).run(); } catch (Throwable t) { t.printStackTrace(); throw t; } }
Example #17
Source File: RuntimeDeployer.java From thorntail with Apache License 2.0 | 5 votes |
private String determineDeploymentType() { if (this.defaultDeploymentType == null) { this.defaultDeploymentType = determineDeploymentTypeInternal(); System.setProperty(BootstrapProperties.DEFAULT_DEPLOYMENT_TYPE, this.defaultDeploymentType); } return this.defaultDeploymentType; }
Example #18
Source File: Swarm.java From thorntail with Apache License 2.0 | 5 votes |
private static boolean isFatJar() throws IOException { URL location = Swarm.class.getProtectionDomain().getCodeSource().getLocation(); Path root = null; if (location.getProtocol().equals("file")) { try { root = Paths.get(location.toURI()); } catch (URISyntaxException e) { throw new IOException(e); } } else if (location.toExternalForm().startsWith("jar:file:")) { return true; } if (Files.isRegularFile(root)) { try (JarFile jar = JarFiles.create(root.toFile())) { ZipEntry propsEntry = jar.getEntry("META-INF/wildfly-swarm.properties"); if (propsEntry != null) { try (InputStream in = jar.getInputStream(propsEntry)) { Properties props = new Properties(); props.load(in); if (props.containsKey(BootstrapProperties.APP_ARTIFACT)) { System.setProperty(BootstrapProperties.APP_ARTIFACT, props.getProperty(BootstrapProperties.APP_ARTIFACT)); } Set<String> names = props.stringPropertyNames(); for (String name : names) { String value = props.getProperty(name); if (System.getProperty(name) == null) { System.setProperty(name, value); } } } return true; } } } return false; }
Example #19
Source File: SecuredArchivePreparer.java From thorntail with Apache License 2.0 | 5 votes |
private static InputStream getKeycloakJsonFromClasspath(String resourceName) { InputStream keycloakJson = Thread.currentThread().getContextClassLoader().getResourceAsStream(resourceName); if (keycloakJson == null) { String appArtifact = System.getProperty(BootstrapProperties.APP_ARTIFACT); if (appArtifact != null) { try (InputStream in = loadAppArtifact(appArtifact)) { Archive<?> tmpArchive = ShrinkWrap.create(JARArchive.class); tmpArchive.as(ZipImporter.class).importFrom(in); Node jsonNode = tmpArchive.get(resourceName); if (jsonNode == null) { jsonNode = getKeycloakJsonNodeFromWebInf(tmpArchive, resourceName, true); } if (jsonNode == null) { jsonNode = getKeycloakJsonNodeFromWebInf(tmpArchive, resourceName, false); } if (jsonNode != null && jsonNode.getAsset() != null) { keycloakJson = jsonNode.getAsset().openStream(); } } catch (IOException e) { // ignore } } } return keycloakJson; }