@SuppressWarnings("unchecked") @Test public void testDeployWithPomArtifactAndAttachedFeatureXmlRepoRegistrationFails() throws Exception { File artifactFeaturesAttachmentFile = File.createTempFile("someproject-features", ".xml"); try { FeaturesService featureService = niceMock(FeaturesService.class); featureService.addRepository(anyObject(URI.class)); EasyMock.expectLastCall().andThrow(new Exception("Not a feature repository")); replay(featureService); ServiceReference<FeaturesService> ref = niceMock(ServiceReference.class); BundleContext context = niceMock(BundleContext.class); expect(context.getServiceReference(eq(FeaturesService.class))).andReturn(ref); expect(context.getService(eq(ref))).andReturn(featureService); replay(context); Artifact artifact = niceMock(Artifact.class); replay(artifact); Artifact artifactFeaturesAttachment = mock(Artifact.class); expect(artifactFeaturesAttachment.getFile()).andReturn(artifactFeaturesAttachmentFile); expect(artifactFeaturesAttachment.getClassifier()).andReturn("features"); expect(artifactFeaturesAttachment.getType()).andReturn("xml"); replay(artifactFeaturesAttachment); RunMojo mojo = new RunMojo(); MavenProject project = new MavenProject(); project.setPackaging("pom"); project.setArtifact(artifact); project.addAttachedArtifact(artifactFeaturesAttachment); setPrivateField(mojo, "project", project); try { mojo.deploy(context, featureService); fail("Expected MojoExecutionException"); } catch (MojoExecutionException e) { assertEquals("Failed to register attachment as feature repository", e.getMessage()); } } finally { artifactFeaturesAttachmentFile.delete(); } }
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);  }