@Test public void testArgs() throws IllegalAccessException, MojoFailureException, MojoExecutionException, IOException { final AtomicReference<String[]> capturedArgs = new AtomicReference<>(); final RunMojo mojo = newRunMojo(args -> { capturedArgs.set(args); throw new FastExit(); }); setPrivateField(mojo, "mainArgs", new String[]{"foo"}); try { mojo.execute(); } catch (final FastExit fe) { } assertArrayEquals(new String[]{"foo"}, capturedArgs.get()); }
public void execute() throws MojoExecutionException, MojoFailureException { final Properties originalProperties = new Properties(); originalProperties.putAll(System.getProperties()); final String[] args = handleArgs(karafDirectory, mainArgs == null ? new String[0] : mainArgs); if (karafDirectory.exists()) { getLog().info("Using Karaf container located " + karafDirectory.getAbsolutePath()); } else { getLog().info("Extracting Karaf container"); try { File karafArchiveFile = resolveFile(karafDistribution); extract(karafArchiveFile, karafDirectory); } catch (Exception e) { throw new MojoFailureException("Can't extract Karaf container", e); } } getLog().info("Starting Karaf container"); System.setProperty("karaf.home", karafDirectory.getAbsolutePath()); System.setProperty("karaf.base", karafDirectory.getAbsolutePath()); System.setProperty("karaf.data", karafDirectory.getAbsolutePath() + "/data"); System.setProperty("karaf.etc", karafDirectory.getAbsolutePath() + "/etc"); System.setProperty("karaf.log", karafDirectory.getAbsolutePath() + "/data/log"); System.setProperty("karaf.instances", karafDirectory.getAbsolutePath() + "/instances"); if (System.getProperty("karaf.startLocalConsole") == null) { System.setProperty("karaf.startLocalConsole", "false"); } System.setProperty("karaf.startRemoteShell", startSsh); System.setProperty("karaf.lock", "false"); if (consoleLogLevel != null && !consoleLogLevel.isEmpty()) { System.setProperty("karaf.log.console", consoleLogLevel); } if (systemProperties != null) { systemProperties.forEach(System::setProperty); } String featureBootFinished = BootFinished.class.getName(); Thread bootThread = Thread.currentThread(); ClassLoader classRealm = bootThread.getContextClassLoader(); ClassLoader bootLoader = new ClassLoader(classRealm) { @Override protected Class<?> loadClass(final String name, final boolean resolve) throws ClassNotFoundException { if (featureBootFinished.equals(name)) { throw new ClassNotFoundException( "avoid to use the classrealm loader which will prevent felix to match its reference"); } if (name != null && forbiddenDelegationPackages != null && forbiddenDelegationPackages.stream().anyMatch(name::startsWith)) { throw new ClassNotFoundException(name); } return super.loadClass(name, resolve); } }; final Main main = newMain(bootLoader, args); try { long start = System.nanoTime(); main.launch(); while (main.getFramework().getState() != Bundle.ACTIVE && checkDurationTimeout(start)) { waitForValidState(); } if (main.getFramework().getState() != Bundle.ACTIVE) { try { main.destroy(); } catch (final Throwable e) { getLog().debug(e.getMessage(), e); } throw startupTimeout(start); } BundleContext featureBundleCtx = null; Object bootFinished = null; while (bootFinished == null && checkDurationTimeout(start)) { waitForValidState(); if (featureBundleCtx == null) { featureBundleCtx = Stream.of(main.getFramework().getBundleContext().getBundles()) .filter(b -> b.getSymbolicName().equals("org.apache.karaf.deployer.features")) .findFirst() .map(Bundle::getBundleContext) .orElse(null); } if (featureBundleCtx == null) { continue; } ServiceReference<?> ref = featureBundleCtx.getServiceReference(featureBundleCtx.getBundle().loadClass(featureBootFinished)); if (ref != null) { bootFinished = featureBundleCtx.getService(ref); } } if (bootFinished == null) { try { main.destroy(); } catch (final Throwable e) { getLog().debug(e.getMessage(), e); } throw startupTimeout(start); } Object featureService = findFeatureService(featureBundleCtx); addFeatureRepositories(featureService); if (!deployAfterFeatures) { deploy(featureBundleCtx, featureService); } addFeatures(featureService); if (deployAfterFeatures) { deploy(featureBundleCtx, featureService); } if (keepRunning) main.awaitShutdown(); main.destroy(); } catch (Throwable e) { throw new MojoExecutionException("Can't start container", e); } finally { System.gc(); System.getProperties().clear(); System.getProperties().putAll(originalProperties); } }
RunMojo extends MojoSupport { public void execute() throws MojoExecutionException, MojoFailureException { final Properties originalProperties = new Properties(); originalProperties.putAll(System.getProperties()); final String[] args = handleArgs(karafDirectory, mainArgs == null ? new String[0] : mainArgs); if (karafDirectory.exists()) { getLog().info("Using Karaf container located " + karafDirectory.getAbsolutePath()); } else { getLog().info("Extracting Karaf container"); try { File karafArchiveFile = resolveFile(karafDistribution); extract(karafArchiveFile, karafDirectory); } catch (Exception e) { throw new MojoFailureException("Can't extract Karaf container", e); } } getLog().info("Starting Karaf container"); System.setProperty("karaf.home", karafDirectory.getAbsolutePath()); System.setProperty("karaf.base", karafDirectory.getAbsolutePath()); System.setProperty("karaf.data", karafDirectory.getAbsolutePath() + "/data"); System.setProperty("karaf.etc", karafDirectory.getAbsolutePath() + "/etc"); System.setProperty("karaf.log", karafDirectory.getAbsolutePath() + "/data/log"); System.setProperty("karaf.instances", karafDirectory.getAbsolutePath() + "/instances"); if (System.getProperty("karaf.startLocalConsole") == null) { System.setProperty("karaf.startLocalConsole", "false"); } System.setProperty("karaf.startRemoteShell", startSsh); System.setProperty("karaf.lock", "false"); if (consoleLogLevel != null && !consoleLogLevel.isEmpty()) { System.setProperty("karaf.log.console", consoleLogLevel); } if (systemProperties != null) { systemProperties.forEach(System::setProperty); } String featureBootFinished = BootFinished.class.getName(); Thread bootThread = Thread.currentThread(); ClassLoader classRealm = bootThread.getContextClassLoader(); ClassLoader bootLoader = new ClassLoader(classRealm) { @Override protected Class<?> loadClass(final String name, final boolean resolve) throws ClassNotFoundException { if (featureBootFinished.equals(name)) { throw new ClassNotFoundException( "avoid to use the classrealm loader which will prevent felix to match its reference"); } if (name != null && forbiddenDelegationPackages != null && forbiddenDelegationPackages.stream().anyMatch(name::startsWith)) { throw new ClassNotFoundException(name); } return super.loadClass(name, resolve); } }; final Main main = newMain(bootLoader, args); try { long start = System.nanoTime(); main.launch(); while (main.getFramework().getState() != Bundle.ACTIVE && checkDurationTimeout(start)) { waitForValidState(); } if (main.getFramework().getState() != Bundle.ACTIVE) { try { main.destroy(); } catch (final Throwable e) { getLog().debug(e.getMessage(), e); } throw startupTimeout(start); } BundleContext featureBundleCtx = null; Object bootFinished = null; while (bootFinished == null && checkDurationTimeout(start)) { waitForValidState(); if (featureBundleCtx == null) { featureBundleCtx = Stream.of(main.getFramework().getBundleContext().getBundles()) .filter(b -> b.getSymbolicName().equals("org.apache.karaf.deployer.features")) .findFirst() .map(Bundle::getBundleContext) .orElse(null); } if (featureBundleCtx == null) { continue; } ServiceReference<?> ref = featureBundleCtx.getServiceReference(featureBundleCtx.getBundle().loadClass(featureBootFinished)); if (ref != null) { bootFinished = featureBundleCtx.getService(ref); } } if (bootFinished == null) { try { main.destroy(); } catch (final Throwable e) { getLog().debug(e.getMessage(), e); } throw startupTimeout(start); } Object featureService = findFeatureService(featureBundleCtx); addFeatureRepositories(featureService); if (!deployAfterFeatures) { deploy(featureBundleCtx, featureService); } addFeatures(featureService); if (deployAfterFeatures) { deploy(featureBundleCtx, featureService); } if (keepRunning) main.awaitShutdown(); main.destroy(); } catch (Throwable e) { throw new MojoExecutionException("Can't start container", e); } finally { System.gc(); System.getProperties().clear(); System.getProperties().putAll(originalProperties); } } }
RunMojo extends MojoSupport { public void execute() throws MojoExecutionException, MojoFailureException { final Properties originalProperties = new Properties(); originalProperties.putAll(System.getProperties()); final String[] args = handleArgs(karafDirectory, mainArgs == null ? new String[0] : mainArgs); if (karafDirectory.exists()) { getLog().info("Using Karaf container located " + karafDirectory.getAbsolutePath()); } else { getLog().info("Extracting Karaf container"); try { File karafArchiveFile = resolveFile(karafDistribution); extract(karafArchiveFile, karafDirectory); } catch (Exception e) { throw new MojoFailureException("Can't extract Karaf container", e); } } getLog().info("Starting Karaf container"); System.setProperty("karaf.home", karafDirectory.getAbsolutePath()); System.setProperty("karaf.base", karafDirectory.getAbsolutePath()); System.setProperty("karaf.data", karafDirectory.getAbsolutePath() + "/data"); System.setProperty("karaf.etc", karafDirectory.getAbsolutePath() + "/etc"); System.setProperty("karaf.log", karafDirectory.getAbsolutePath() + "/data/log"); System.setProperty("karaf.instances", karafDirectory.getAbsolutePath() + "/instances"); if (System.getProperty("karaf.startLocalConsole") == null) { System.setProperty("karaf.startLocalConsole", "false"); } System.setProperty("karaf.startRemoteShell", startSsh); System.setProperty("karaf.lock", "false"); if (consoleLogLevel != null && !consoleLogLevel.isEmpty()) { System.setProperty("karaf.log.console", consoleLogLevel); } if (systemProperties != null) { systemProperties.forEach(System::setProperty); } String featureBootFinished = BootFinished.class.getName(); Thread bootThread = Thread.currentThread(); ClassLoader classRealm = bootThread.getContextClassLoader(); ClassLoader bootLoader = new ClassLoader(classRealm) { @Override protected Class<?> loadClass(final String name, final boolean resolve) throws ClassNotFoundException { if (featureBootFinished.equals(name)) { throw new ClassNotFoundException( "avoid to use the classrealm loader which will prevent felix to match its reference"); } if (name != null && forbiddenDelegationPackages != null && forbiddenDelegationPackages.stream().anyMatch(name::startsWith)) { throw new ClassNotFoundException(name); } return super.loadClass(name, resolve); } }; final Main main = newMain(bootLoader, args); try { long start = System.nanoTime(); main.launch(); while (main.getFramework().getState() != Bundle.ACTIVE && checkDurationTimeout(start)) { waitForValidState(); } if (main.getFramework().getState() != Bundle.ACTIVE) { try { main.destroy(); } catch (final Throwable e) { getLog().debug(e.getMessage(), e); } throw startupTimeout(start); } BundleContext featureBundleCtx = null; Object bootFinished = null; while (bootFinished == null && checkDurationTimeout(start)) { waitForValidState(); if (featureBundleCtx == null) { featureBundleCtx = Stream.of(main.getFramework().getBundleContext().getBundles()) .filter(b -> b.getSymbolicName().equals("org.apache.karaf.deployer.features")) .findFirst() .map(Bundle::getBundleContext) .orElse(null); } if (featureBundleCtx == null) { continue; } ServiceReference<?> ref = featureBundleCtx.getServiceReference(featureBundleCtx.getBundle().loadClass(featureBootFinished)); if (ref != null) { bootFinished = featureBundleCtx.getService(ref); } } if (bootFinished == null) { try { main.destroy(); } catch (final Throwable e) { getLog().debug(e.getMessage(), e); } throw startupTimeout(start); } Object featureService = findFeatureService(featureBundleCtx); addFeatureRepositories(featureService); if (!deployAfterFeatures) { deploy(featureBundleCtx, featureService); } addFeatures(featureService); if (deployAfterFeatures) { deploy(featureBundleCtx, featureService); } if (keepRunning) main.awaitShutdown(); main.destroy(); } catch (Throwable e) { throw new MojoExecutionException("Can't start container", e); } finally { System.gc(); System.getProperties().clear(); System.getProperties().putAll(originalProperties); } }  }
RunMojo extends MojoSupport { public void execute() throws MojoExecutionException, MojoFailureException { final Properties originalProperties = new Properties(); originalProperties.putAll(System.getProperties()); final String[] args = handleArgs(karafDirectory, mainArgs == null ? new String[0] : mainArgs); if (karafDirectory.exists()) { getLog().info("Using Karaf container located " + karafDirectory.getAbsolutePath()); } else { getLog().info("Extracting Karaf container"); try { File karafArchiveFile = resolveFile(karafDistribution); extract(karafArchiveFile, karafDirectory); } catch (Exception e) { throw new MojoFailureException("Can't extract Karaf container", e); } } getLog().info("Starting Karaf container"); System.setProperty("karaf.home", karafDirectory.getAbsolutePath()); System.setProperty("karaf.base", karafDirectory.getAbsolutePath()); System.setProperty("karaf.data", karafDirectory.getAbsolutePath() + "/data"); System.setProperty("karaf.etc", karafDirectory.getAbsolutePath() + "/etc"); System.setProperty("karaf.log", karafDirectory.getAbsolutePath() + "/data/log"); System.setProperty("karaf.instances", karafDirectory.getAbsolutePath() + "/instances"); if (System.getProperty("karaf.startLocalConsole") == null) { System.setProperty("karaf.startLocalConsole", "false"); } System.setProperty("karaf.startRemoteShell", startSsh); System.setProperty("karaf.lock", "false"); if (consoleLogLevel != null && !consoleLogLevel.isEmpty()) { System.setProperty("karaf.log.console", consoleLogLevel); } if (systemProperties != null) { systemProperties.forEach(System::setProperty); } String featureBootFinished = BootFinished.class.getName(); Thread bootThread = Thread.currentThread(); ClassLoader classRealm = bootThread.getContextClassLoader(); ClassLoader bootLoader = new ClassLoader(classRealm) { @Override protected Class<?> loadClass(final String name, final boolean resolve) throws ClassNotFoundException { if (featureBootFinished.equals(name)) { throw new ClassNotFoundException( "avoid to use the classrealm loader which will prevent felix to match its reference"); } if (name != null && forbiddenDelegationPackages != null && forbiddenDelegationPackages.stream().anyMatch(name::startsWith)) { throw new ClassNotFoundException(name); } return super.loadClass(name, resolve); } }; final Main main = newMain(bootLoader, args); try { long start = System.nanoTime(); main.launch(); while (main.getFramework().getState() != Bundle.ACTIVE && checkDurationTimeout(start)) { waitForValidState(); } if (main.getFramework().getState() != Bundle.ACTIVE) { try { main.destroy(); } catch (final Throwable e) { getLog().debug(e.getMessage(), e); } throw startupTimeout(start); } BundleContext featureBundleCtx = null; Object bootFinished = null; while (bootFinished == null && checkDurationTimeout(start)) { waitForValidState(); if (featureBundleCtx == null) { featureBundleCtx = Stream.of(main.getFramework().getBundleContext().getBundles()) .filter(b -> b.getSymbolicName().equals("org.apache.karaf.deployer.features")) .findFirst() .map(Bundle::getBundleContext) .orElse(null); } if (featureBundleCtx == null) { continue; } ServiceReference<?> ref = featureBundleCtx.getServiceReference(featureBundleCtx.getBundle().loadClass(featureBootFinished)); if (ref != null) { bootFinished = featureBundleCtx.getService(ref); } } if (bootFinished == null) { try { main.destroy(); } catch (final Throwable e) { getLog().debug(e.getMessage(), e); } throw startupTimeout(start); } Object featureService = findFeatureService(featureBundleCtx); addFeatureRepositories(featureService); if (!deployAfterFeatures) { deploy(featureBundleCtx, featureService); } addFeatures(featureService); if (deployAfterFeatures) { deploy(featureBundleCtx, featureService); } if (keepRunning) main.awaitShutdown(); main.destroy(); } catch (Throwable e) { throw new MojoExecutionException("Can't start container", e); } finally { System.gc(); System.getProperties().clear(); System.getProperties().putAll(originalProperties); } }  void execute(); static void extract(File sourceFile, File targetFolder); }
RunMojo extends MojoSupport { public void execute() throws MojoExecutionException, MojoFailureException { final Properties originalProperties = new Properties(); originalProperties.putAll(System.getProperties()); final String[] args = handleArgs(karafDirectory, mainArgs == null ? new String[0] : mainArgs); if (karafDirectory.exists()) { getLog().info("Using Karaf container located " + karafDirectory.getAbsolutePath()); } else { getLog().info("Extracting Karaf container"); try { File karafArchiveFile = resolveFile(karafDistribution); extract(karafArchiveFile, karafDirectory); } catch (Exception e) { throw new MojoFailureException("Can't extract Karaf container", e); } } getLog().info("Starting Karaf container"); System.setProperty("karaf.home", karafDirectory.getAbsolutePath()); System.setProperty("karaf.base", karafDirectory.getAbsolutePath()); System.setProperty("karaf.data", karafDirectory.getAbsolutePath() + "/data"); System.setProperty("karaf.etc", karafDirectory.getAbsolutePath() + "/etc"); System.setProperty("karaf.log", karafDirectory.getAbsolutePath() + "/data/log"); System.setProperty("karaf.instances", karafDirectory.getAbsolutePath() + "/instances"); if (System.getProperty("karaf.startLocalConsole") == null) { System.setProperty("karaf.startLocalConsole", "false"); } System.setProperty("karaf.startRemoteShell", startSsh); System.setProperty("karaf.lock", "false"); if (consoleLogLevel != null && !consoleLogLevel.isEmpty()) { System.setProperty("karaf.log.console", consoleLogLevel); } if (systemProperties != null) { systemProperties.forEach(System::setProperty); } String featureBootFinished = BootFinished.class.getName(); Thread bootThread = Thread.currentThread(); ClassLoader classRealm = bootThread.getContextClassLoader(); ClassLoader bootLoader = new ClassLoader(classRealm) { @Override protected Class<?> loadClass(final String name, final boolean resolve) throws ClassNotFoundException { if (featureBootFinished.equals(name)) { throw new ClassNotFoundException( "avoid to use the classrealm loader which will prevent felix to match its reference"); } if (name != null && forbiddenDelegationPackages != null && forbiddenDelegationPackages.stream().anyMatch(name::startsWith)) { throw new ClassNotFoundException(name); } return super.loadClass(name, resolve); } }; final Main main = newMain(bootLoader, args); try { long start = System.nanoTime(); main.launch(); while (main.getFramework().getState() != Bundle.ACTIVE && checkDurationTimeout(start)) { waitForValidState(); } if (main.getFramework().getState() != Bundle.ACTIVE) { try { main.destroy(); } catch (final Throwable e) { getLog().debug(e.getMessage(), e); } throw startupTimeout(start); } BundleContext featureBundleCtx = null; Object bootFinished = null; while (bootFinished == null && checkDurationTimeout(start)) { waitForValidState(); if (featureBundleCtx == null) { featureBundleCtx = Stream.of(main.getFramework().getBundleContext().getBundles()) .filter(b -> b.getSymbolicName().equals("org.apache.karaf.deployer.features")) .findFirst() .map(Bundle::getBundleContext) .orElse(null); } if (featureBundleCtx == null) { continue; } ServiceReference<?> ref = featureBundleCtx.getServiceReference(featureBundleCtx.getBundle().loadClass(featureBootFinished)); if (ref != null) { bootFinished = featureBundleCtx.getService(ref); } } if (bootFinished == null) { try { main.destroy(); } catch (final Throwable e) { getLog().debug(e.getMessage(), e); } throw startupTimeout(start); } Object featureService = findFeatureService(featureBundleCtx); addFeatureRepositories(featureService); if (!deployAfterFeatures) { deploy(featureBundleCtx, featureService); } addFeatures(featureService); if (deployAfterFeatures) { deploy(featureBundleCtx, featureService); } if (keepRunning) main.awaitShutdown(); main.destroy(); } catch (Throwable e) { throw new MojoExecutionException("Can't start container", e); } finally { System.gc(); System.getProperties().clear(); System.getProperties().putAll(originalProperties); } }  void execute(); static void extract(File sourceFile, File targetFolder);  }