@Test public void testDeployWithExistingArtifactButProjectNotBundle() throws SecurityException, IllegalArgumentException, IllegalAccessException { BundleContext context = mock(BundleContext.class); Artifact artifact = mock(Artifact.class); File artifactFile = mock(File.class); expect(artifactFile.exists()).andReturn(true).times(2); expect(artifactFile.getAbsolutePath()).andReturn("foo.jar").times(1); expect(artifactFile.toURI()).andReturn(URI.create("file: replay(artifactFile); expect(artifact.getFile()).andReturn(artifactFile); replay(artifact); RunMojo mojo = new RunMojo(); MavenProject project = new MavenProject(); project.setArtifact(artifact); setPrivateField(mojo, "project", project); try { mojo.deploy(context, null); fail("Expected MojoExecutionException"); } catch (MojoExecutionException e) { assertEquals("Can't deploy project artifact in container", e.getMessage()); } }
void deploy(BundleContext bundleContext, Object featureService) throws MojoExecutionException { if (deployProjectArtifact) { File artifact = getProjectArtifact(); File attachedFeatureFile = getAttachedFeatureFile(project); boolean artifactExists = artifact != null && artifact.exists(); if (!artifactExists) { artifact = new File(project.getBuild().getDirectory(), project.getBuild().getFinalName() + ".jar"); artifactExists = artifact != null && artifact.exists(); } boolean attachedFeatureFileExists = attachedFeatureFile != null && attachedFeatureFile.exists(); if (attachedFeatureFileExists) { getLog().info("Deploying features repository " + attachedFeatureFile.getAbsolutePath()); addFeaturesAttachmentAsFeatureRepository(featureService, attachedFeatureFile); } else if (artifactExists) { try { getLog().info("Deploying bundle " + artifact.getAbsolutePath()); Bundle bundle = bundleContext.installBundle(artifact.toURI().toURL().toString()); bundle.start(); } catch (Exception e) { throw new MojoExecutionException("Can't deploy project artifact in container", e); } } else { throw new MojoExecutionException("No artifact to deploy"); } getLog().info("Artifact deployed"); } }
RunMojo extends MojoSupport { void deploy(BundleContext bundleContext, Object featureService) throws MojoExecutionException { if (deployProjectArtifact) { File artifact = getProjectArtifact(); File attachedFeatureFile = getAttachedFeatureFile(project); boolean artifactExists = artifact != null && artifact.exists(); if (!artifactExists) { artifact = new File(project.getBuild().getDirectory(), project.getBuild().getFinalName() + ".jar"); artifactExists = artifact != null && artifact.exists(); } boolean attachedFeatureFileExists = attachedFeatureFile != null && attachedFeatureFile.exists(); if (attachedFeatureFileExists) { getLog().info("Deploying features repository " + attachedFeatureFile.getAbsolutePath()); addFeaturesAttachmentAsFeatureRepository(featureService, attachedFeatureFile); } else if (artifactExists) { try { getLog().info("Deploying bundle " + artifact.getAbsolutePath()); Bundle bundle = bundleContext.installBundle(artifact.toURI().toURL().toString()); bundle.start(); } catch (Exception e) { throw new MojoExecutionException("Can't deploy project artifact in container", e); } } else { throw new MojoExecutionException("No artifact to deploy"); } getLog().info("Artifact deployed"); } } }
RunMojo extends MojoSupport { void deploy(BundleContext bundleContext, Object featureService) throws MojoExecutionException { if (deployProjectArtifact) { File artifact = getProjectArtifact(); File attachedFeatureFile = getAttachedFeatureFile(project); boolean artifactExists = artifact != null && artifact.exists(); if (!artifactExists) { artifact = new File(project.getBuild().getDirectory(), project.getBuild().getFinalName() + ".jar"); artifactExists = artifact != null && artifact.exists(); } boolean attachedFeatureFileExists = attachedFeatureFile != null && attachedFeatureFile.exists(); if (attachedFeatureFileExists) { getLog().info("Deploying features repository " + attachedFeatureFile.getAbsolutePath()); addFeaturesAttachmentAsFeatureRepository(featureService, attachedFeatureFile); } else if (artifactExists) { try { getLog().info("Deploying bundle " + artifact.getAbsolutePath()); Bundle bundle = bundleContext.installBundle(artifact.toURI().toURL().toString()); bundle.start(); } catch (Exception e) { throw new MojoExecutionException("Can't deploy project artifact in container", e); } } else { throw new MojoExecutionException("No artifact to deploy"); } getLog().info("Artifact deployed"); } }  }
RunMojo extends MojoSupport { void deploy(BundleContext bundleContext, Object featureService) throws MojoExecutionException { if (deployProjectArtifact) { File artifact = getProjectArtifact(); File attachedFeatureFile = getAttachedFeatureFile(project); boolean artifactExists = artifact != null && artifact.exists(); if (!artifactExists) { artifact = new File(project.getBuild().getDirectory(), project.getBuild().getFinalName() + ".jar"); artifactExists = artifact != null && artifact.exists(); } boolean attachedFeatureFileExists = attachedFeatureFile != null && attachedFeatureFile.exists(); if (attachedFeatureFileExists) { getLog().info("Deploying features repository " + attachedFeatureFile.getAbsolutePath()); addFeaturesAttachmentAsFeatureRepository(featureService, attachedFeatureFile); } else if (artifactExists) { try { getLog().info("Deploying bundle " + artifact.getAbsolutePath()); Bundle bundle = bundleContext.installBundle(artifact.toURI().toURL().toString()); bundle.start(); } catch (Exception e) { throw new MojoExecutionException("Can't deploy project artifact in container", e); } } else { throw new MojoExecutionException("No artifact to deploy"); } getLog().info("Artifact deployed"); } }  void execute(); static void extract(File sourceFile, File targetFolder); }
RunMojo extends MojoSupport { void deploy(BundleContext bundleContext, Object featureService) throws MojoExecutionException { if (deployProjectArtifact) { File artifact = getProjectArtifact(); File attachedFeatureFile = getAttachedFeatureFile(project); boolean artifactExists = artifact != null && artifact.exists(); if (!artifactExists) { artifact = new File(project.getBuild().getDirectory(), project.getBuild().getFinalName() + ".jar"); artifactExists = artifact != null && artifact.exists(); } boolean attachedFeatureFileExists = attachedFeatureFile != null && attachedFeatureFile.exists(); if (attachedFeatureFileExists) { getLog().info("Deploying features repository " + attachedFeatureFile.getAbsolutePath()); addFeaturesAttachmentAsFeatureRepository(featureService, attachedFeatureFile); } else if (artifactExists) { try { getLog().info("Deploying bundle " + artifact.getAbsolutePath()); Bundle bundle = bundleContext.installBundle(artifact.toURI().toURL().toString()); bundle.start(); } catch (Exception e) { throw new MojoExecutionException("Can't deploy project artifact in container", e); } } else { throw new MojoExecutionException("No artifact to deploy"); } getLog().info("Artifact deployed"); } }  void execute(); static void extract(File sourceFile, File targetFolder);  }