Java Code Examples for org.apache.maven.artifact.Artifact#setFile()
The following examples show how to use
org.apache.maven.artifact.Artifact#setFile() .
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: RepositoryUtil.java From netbeans with Apache License 2.0 | 6 votes |
private static @NonNull Artifact createArtifact(@NonNull NBVersionInfo info, @NullAllowed String classifier) { Artifact art; MavenEmbedder online = EmbedderFactory.getOnlineEmbedder(); if (info.getClassifier() != null || classifier != null) { art = online.createArtifactWithClassifier(info.getGroupId(), info.getArtifactId(), info.getVersion(), info.getType() != null ? info.getType() : "jar", //NOI18N classifier == null ? info.getClassifier() : classifier); } else { art = online.createArtifact(info.getGroupId(), info.getArtifactId(), info.getVersion(), null, info.getType() != null ? info.getType() : "jar"); //NOI18N } ArtifactRepository repo = online.getLocalRepository(); String localPath = repo.pathOf(art); art.setFile(FileUtil.normalizeFile(new File(online.getLocalRepositoryFile(), localPath))); return art; }
Example 2
Source File: Mojo.java From capsule-maven-plugin with MIT License | 6 votes |
Artifact toArtifact(final ArtifactResult ar) { if (ar == null) return null; final Artifact artifact = new org.apache.maven.artifact.DefaultArtifact( ar.getArtifact().getGroupId(), ar.getArtifact().getArtifactId(), ar.getArtifact().getVersion(), null, "jar", ar.getArtifact().getClassifier(), null); if (ar.getRequest().getDependencyNode() != null && ar.getRequest().getDependencyNode().getDependency() != null) { artifact.setScope(ar.getRequest().getDependencyNode().getDependency().getScope()); artifact.setOptional(ar.getRequest().getDependencyNode().getDependency().isOptional()); } if (artifact.getScope() == null || artifact.getScope().isEmpty()) artifact.setScope("compile"); artifact.setFile(ar.getArtifact().getFile()); return artifact; }
Example 3
Source File: PackageMojo.java From vertx-maven-plugin with Apache License 2.0 | 5 votes |
private void attachIfNeeded(File jar) { if (jar.isFile() && classifier != null && attach) { ArtifactHandler handler = new DefaultArtifactHandler("jar"); Artifact vertxJarArtifact = new DefaultArtifact(project.getGroupId(), project.getArtifactId(), project.getVersion(), "compile", "jar", classifier, handler); vertxJarArtifact.setFile(jar); this.project.addAttachedArtifact(vertxJarArtifact); } }
Example 4
Source File: DeployMojoSupport.java From ci.maven with Apache License 2.0 | 5 votes |
protected void installApp(Artifact artifact) throws Exception { if (artifact.getFile() == null || artifact.getFile().isDirectory()) { String warName = getAppFileName(project); File f = new File(project.getBuild().getDirectory() + "/" + warName); artifact.setFile(f); } if (!artifact.getFile().exists()) { throw new MojoExecutionException(messages.getString("error.install.app.missing")); } File destDir = new File(serverDirectory, getAppsDirectory()); log.info(MessageFormat.format(messages.getString("info.install.app"), artifact.getFile().getCanonicalPath())); Copy copyFile = (Copy) ant.createTask("copy"); copyFile.setFile(artifact.getFile()); String fileName = artifact.getFile().getName(); if (stripVersion) { fileName = stripVersionFromName(fileName, artifact.getBaseVersion()); copyFile.setTofile(new File(destDir, fileName)); } else { copyFile.setTodir(destDir); } // validate application configuration if appsDirectory="dropins" or inject // webApplication // to target server.xml if not found for appsDirectory="apps" validateAppConfig(fileName, artifact.getArtifactId()); deleteApplication(new File(serverDirectory, "apps"), artifact.getFile()); deleteApplication(new File(serverDirectory, "dropins"), artifact.getFile()); // application can be expanded if server.xml configure with <applicationManager // autoExpand="true"/> deleteApplication(new File(serverDirectory, "apps/expanded"), artifact.getFile()); copyFile.execute(); verifyAppStarted(fileName); }
Example 5
Source File: MavenEmbedder.java From netbeans with Apache License 2.0 | 5 votes |
static void normalizePath(Artifact a) { if (a != null) { File f = a.getFile(); if (f != null) { a.setFile(FileUtil.normalizeFile(f)); } } }
Example 6
Source File: VersionXmlGeneratorTest.java From webstart with MIT License | 5 votes |
public void testWithMultiJarResources() throws IOException, SAXException, ParserConfigurationException, MojoExecutionException { Artifact artifact1 = new DefaultArtifact( "groupId", "artifactId1", VersionRange.createFromVersion( "1.0" ), "scope", "jar", "classifier", null ); artifact1.setFile( new File( "bogus1.txt" ) ); Artifact artifact2 = new DefaultArtifact( "groupId", "artifactId2", VersionRange.createFromVersion( "1.0" ), "scope", "jar", "classifier", null ); artifact2.setFile( new File( "bogus2.txt" ) ); ResolvedJarResource jar1 = new ResolvedJarResource( artifact1 ); ResolvedJarResource jar2 = new ResolvedJarResource( artifact2 ); // jar1.setArtifact( artifact1 ); // jar2.setArtifact( artifact2 ); List<ResolvedJarResource> jarResources = new ArrayList<>( 2 ); jarResources.add( jar1 ); jarResources.add( jar2 ); new VersionXmlGenerator( "utf-8" ).generate( this.outputDir, jarResources ); String actualXml = readFileContents( this.expectedFile ); String expected = "<?xml version=\"1.0\"?><jnlp-versions>" + " <resource>" + " <pattern>" + " <name>bogus1.txt</name>" + " <version-id>1.0</version-id>" + " </pattern>" + " <file>artifactId1-1.0-classifier.jar</file>" + " </resource>" + " <resource>" + " <pattern>" + " <name>bogus2.txt</name>" + " <version-id>1.0</version-id>" + " </pattern>" + " <file>artifactId2-1.0-classifier.jar</file>" + " </resource>" + "</jnlp-versions>"; Assert.assertEquals( actualXml, expected ); Diff diff = new Diff( expected, actualXml ); Assert.assertTrue( diff.toString(), diff.similar() ); }
Example 7
Source File: ArtifactBuilder.java From extra-enforcer-rules with Apache License 2.0 | 5 votes |
public Artifact build() { Artifact artifact = new DefaultArtifact( groupId, artifactId, versionRange, scope, type, classifier, null ); artifact.setFile( fileOrDirectory ); return artifact; }
Example 8
Source File: A_ModuleGenerator.java From deadcode4j with Apache License 2.0 | 5 votes |
private Artifact addArtifact(MavenProject mavenProject, final boolean resolved) { Artifact artifact = new ArtifactStub() { private boolean resolved = false; @Override public boolean isResolved() { return this.resolved; } @Override public void setResolved(boolean b) { this.resolved = b; } @Override public File getFile() { return isResolved() ? super.getFile() : null; } }; artifact.setGroupId("de.is24.junit"); artifact.setArtifactId("dependency"); artifact.setVersion("42"); artifact.setScope("compile"); artifact.setResolved(resolved); artifact.setFile(tempFileRule.getTempFile()); mavenProject.setArtifactFilter(new ScopeArtifactFilter(SCOPE_COMPILE_PLUS_RUNTIME)); if (resolved) { mavenProject.setResolvedArtifacts(newHashSet(artifact)); } else { mavenProject.setArtifacts(newHashSet(artifact)); } return artifact; }
Example 9
Source File: ArtifactDeploymentTest.java From wildfly-maven-plugin with GNU Lesser General Public License v2.1 | 4 votes |
private Artifact createArtifact(final String classifier) { final Artifact artifact = new DefaultArtifact("dummy", "dummy", "1.0.0", "provided", "jar", classifier, new DefaultArtifactHandler()); artifact.setFile(new File(BASE_CONFIG_DIR, artifactName)); return artifact; }
Example 10
Source File: ResolveMojoTest.java From roboconf-platform with Apache License 2.0 | 4 votes |
@Test public void testWithValidRoboconfDependencies() throws Exception { // Prepare the project final String projectName = "project--valid"; File baseDir = this.resources.getBasedir( projectName ); Assert.assertNotNull( baseDir ); Assert.assertTrue( baseDir.isDirectory()); AbstractMojo mojo = findMojo( projectName, "resolve" ); this.rule.setVariableValueToObject( mojo, "repoSystem", newRepositorySystem()); this.rule.setVariableValueToObject( mojo, "repositories", new ArrayList<RemoteRepository>( 0 )); // Create a Roboconf application File dir = this.folder.newFolder(); File targetZipFile = this.folder.newFile(); Assert.assertTrue( targetZipFile.delete()); CreationBean bean = new CreationBean() .projectDescription( "some desc" ).projectName( "my-project" ) .groupId( "net.roboconf" ).projectVersion( "1.0-SNAPSHOT" ).mavenProject( false ); ProjectUtils.createProjectSkeleton( dir, bean ); ZipArchiver zipArchiver = new ZipArchiver(); zipArchiver.addDirectory( dir ); zipArchiver.setCompress( true ); zipArchiver.setDestFile( targetZipFile ); zipArchiver.createArchive(); Assert.assertTrue( targetZipFile.isFile()); // Add dependencies MavenProject project = (MavenProject) this.rule.getVariableValueFromObject( mojo, "project" ); project.setDependencyArtifacts( new HashSet<Artifact> ()); Artifact rbcfArtifact3 = new DefaultArtifact( "net.roboconf", "roboconf-core", "0.2", "runtime", "jar", null, new DefaultArtifactHandler()); rbcfArtifact3.setFile( targetZipFile ); project.getDependencyArtifacts().add( rbcfArtifact3 ); // Add it to our "local" repository this.artifactIdToArtifact.put( rbcfArtifact3.getArtifactId(), rbcfArtifact3 ); // Execute it File targetDir = new File( baseDir, MavenPluginConstants.TARGET_MODEL_DIRECTORY + "/" + Constants.PROJECT_DIR_GRAPH ); Assert.assertFalse( targetDir.isDirectory()); mojo.execute(); // Verify the import was copied in the right location File importDir = new File( targetDir, "net.roboconf/roboconf-core" ); Assert.assertTrue( importDir.isDirectory()); Assert.assertTrue( new File( importDir, "main.graph" ).isFile()); }
Example 11
Source File: DockerAssemblyManager.java From docker-maven-plugin with Apache License 2.0 | 4 votes |
private void setArtifactFile(MavenProject project, File artifactFile) { Artifact artifact = project.getArtifact(); if (artifact != null) { artifact.setFile(artifactFile); } }
Example 12
Source File: PackageMojo.java From ARCHIVE-wildfly-swarm with Apache License 2.0 | 4 votes |
@Override public void execute() throws MojoExecutionException, MojoFailureException { initProperties(false); final BuildTool tool = new BuildTool(); tool.projectArtifact( this.project.getArtifact().getGroupId(), this.project.getArtifact().getArtifactId(), this.project.getArtifact().getBaseVersion(), this.project.getArtifact().getType(), this.project.getArtifact().getFile()); this.project.getArtifacts() .forEach(dep -> tool.dependency(dep.getScope(), dep.getGroupId(), dep.getArtifactId(), dep.getBaseVersion(), dep.getType(), dep.getClassifier(), dep.getFile(), dep.getDependencyTrail().size() == 2)); List<Resource> resources = this.project.getResources(); for (Resource each : resources) { tool.resourceDirectory(each.getDirectory()); } for (String additionalModule : additionalModules) { File source = new File(this.project.getBuild().getOutputDirectory(), additionalModule); if (source.exists()) { tool.additionalModule(source.getAbsolutePath()); } } tool .properties(this.properties) .mainClass(this.mainClass) .bundleDependencies(this.bundleDependencies); MavenArtifactResolvingHelper resolvingHelper = new MavenArtifactResolvingHelper(this.resolver, this.repositorySystem, this.repositorySystemSession); this.remoteRepositories.forEach(resolvingHelper::remoteRepository); tool.artifactResolvingHelper(resolvingHelper); try { File jar = tool.build(this.project.getBuild().getFinalName(), Paths.get(this.projectBuildDir)); Artifact primaryArtifact = this.project.getArtifact(); ArtifactHandler handler = new DefaultArtifactHandler("jar"); Artifact swarmJarArtifact = new DefaultArtifact( primaryArtifact.getGroupId(), primaryArtifact.getArtifactId(), primaryArtifact.getBaseVersion(), primaryArtifact.getScope(), "jar", "swarm", handler ); swarmJarArtifact.setFile(jar); this.project.addAttachedArtifact(swarmJarArtifact); } catch (Exception e) { throw new MojoFailureException("Unable to create -swarm.jar", e); } }
Example 13
Source File: NativeLinkMojo.java From maven-native with MIT License | 4 votes |
/** * */ private void attachPrimaryArtifact() { Artifact artifact = this.project.getArtifact(); if ( null == this.classifier ) { artifact.setFile( new File( this.linkerOutputDirectory + "/" + this.project.getBuild().getFinalName() + "." + this.project.getArtifact().getArtifactHandler().getExtension() ) ); } else { // install primary artifact as a classifier DefaultArtifact clone = new DefaultArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersionRange().cloneOf(), artifact.getScope(), artifact.getType(), classifier, artifact.getArtifactHandler(), artifact.isOptional() ); clone.setRelease( artifact.isRelease() ); clone.setResolvedVersion( artifact.getVersion() ); clone.setResolved( artifact.isResolved() ); clone.setFile( artifact.getFile() ); if ( artifact.getAvailableVersions() != null ) { clone.setAvailableVersions( new ArrayList<>( artifact.getAvailableVersions() ) ); } clone.setBaseVersion( artifact.getBaseVersion() ); clone.setDependencyFilter( artifact.getDependencyFilter() ); if ( artifact.getDependencyTrail() != null ) { clone.setDependencyTrail( new ArrayList<>( artifact.getDependencyTrail() ) ); } clone.setDownloadUrl( artifact.getDownloadUrl() ); clone.setRepository( artifact.getRepository() ); clone.setFile( new File( this.linkerOutputDirectory + "/" + this.project.getBuild().getFinalName() + "." + this.project.getArtifact().getArtifactHandler().getExtension() ) ); project.setArtifact( clone ); } }
Example 14
Source File: SPICombineTest.java From vertx-maven-plugin with Apache License 2.0 | 4 votes |
@Test public void testCombineWithSpringDescriptors() throws Exception { File jar1 = new File("target/testCombine1Spring.jar"); File jar2 = new File("target/testCombine2Spring.jar"); File jar3 = new File("target/testCombine3Spring.jar"); JavaArchive jarArchive1 = ShrinkWrap.create(JavaArchive.class); jarArchive1.add(new StringAsset("com.test.demo.DemoSPI.impl.DemoSPIImpl"), "/META-INF/spring.foo"); jarArchive1.as(ZipExporter.class).exportTo(jar1, true); JavaArchive jarArchive2 = ShrinkWrap.create(JavaArchive.class); jarArchive2.add(new StringAsset("com.test.demo.DemoSPI.impl.DemoSPIImpl2"), "/META-INF/spring.foo"); jarArchive2.add(new StringAsset("com.test.demo.DemoSPI2.impl.DemoSPI2Impl2"), "/META-INF/spring.bar"); jarArchive2.as(ZipExporter.class).exportTo(jar2, true); JavaArchive jarArchive3 = ShrinkWrap.create(JavaArchive.class); jarArchive3.addClass(SPICombineTest.class); jarArchive3.as(ZipExporter.class).exportTo(jar3, true); Set<Artifact> artifacts = new LinkedHashSet<>(); Artifact a1 = new DefaultArtifact("org.acme", "a1", "1.0", "compile", "jar", "", null); a1.setFile(jar1); Artifact a2 = new DefaultArtifact("org.acme", "a2", "1.0", "compile", "jar", "", null); a2.setFile(jar2); Artifact a3 = new DefaultArtifact("org.acme", "a3", "1.0", "compile", "jar", "", null); a3.setFile(jar3); artifacts.add(a1); artifacts.add(a2); artifacts.add(a3); MavenProject project = new MavenProject(); project.setVersion("1.0"); project.setArtifactId("foo"); AbstractVertxMojo mojo = new AbstractVertxMojo() { @Override public void execute() throws MojoExecutionException, MojoFailureException { } }; mojo.setLog(new SystemStreamLog()); Build build = new Build(); build.setOutputDirectory("target/junk"); project.setBuild(build); ServiceFileCombinationConfig config = new ServiceFileCombinationConfig() .setProject(project) .setArtifacts(artifacts) .setArchive(ServiceUtils.getDefaultFatJar()) .setMojo(mojo); combiner.doCombine(config); File merged = new File("target/junk/META-INF/spring.foo"); assertThat(merged).isFile(); List<String> lines = FileUtils.readLines(merged, "UTF-8"); assertThat(lines).containsExactly("com.test.demo.DemoSPI.impl.DemoSPIImpl", "com.test.demo.DemoSPI.impl.DemoSPIImpl2"); Stream.of(jar1, jar2, jar3, new File("target/junk")).forEach(FileUtils::deleteQuietly); }
Example 15
Source File: SPICombineTest.java From vertx-maven-plugin with Apache License 2.0 | 4 votes |
@Test public void testCombineDiffSPI() throws Exception { File jar1 = new File("target/testCombineDiffSPI.jar"); File jar2 = new File("target/testCombineDiffSPI2.jar"); File jar3 = new File("target/testCombineDiffSPI3.jar"); File jar4 = new File("target/testCombineDiffSPI4.jar"); JavaArchive jarArchive1 = ShrinkWrap.create(JavaArchive.class); jarArchive1.addAsServiceProvider("com.test.demo.DemoSPI", "com.test.demo.DemoSPI.impl.DemoSPIImpl"); jarArchive1.as(ZipExporter.class).exportTo(jar1, true); JavaArchive jarArchive2 = ShrinkWrap.create(JavaArchive.class); jarArchive2.addAsServiceProvider("com.test.demo.DemoSPI", "com.test.demo.DemoSPI.impl.DemoSPIImpl2"); jarArchive2.as(ZipExporter.class).exportTo(jar2, true); JavaArchive jarArchive3 = ShrinkWrap.create(JavaArchive.class); jarArchive3.addClass(SPICombineTest.class); jarArchive3.as(ZipExporter.class).exportTo(jar3, true); JavaArchive jarArchive4 = ShrinkWrap.create(JavaArchive.class); jarArchive4.addAsServiceProvider("com.test.demo.DemoSPI", "com.test.demo.DemoSPI.impl.DemoSPIImpl4"); jarArchive4.as(ZipExporter.class).exportTo(jar4, true); Set<Artifact> artifacts = new LinkedHashSet<>(); Artifact a1 = new DefaultArtifact("org.acme", "a1", "1.0", "compile", "jar", "", null); a1.setFile(jar1); Artifact a2 = new DefaultArtifact("org.acme", "a2", "1.0", "compile", "jar", "", null); a2.setFile(jar2); Artifact a3 = new DefaultArtifact("org.acme", "a3", "1.0", "compile", "jar", "", null); a3.setFile(jar3); Artifact a4 = new DefaultArtifact("org.acme", "a4", "1.0", "compile", "jar", "", null); a4.setFile(jar4); artifacts.add(a1); artifacts.add(a2); artifacts.add(a3); artifacts.add(a4); MavenProject project = new MavenProject(); project.setVersion("1.0"); project.setArtifactId("foo"); AbstractVertxMojo mojo = new AbstractVertxMojo() { @Override public void execute() throws MojoExecutionException, MojoFailureException { } }; mojo.setLog(new SystemStreamLog()); Build build = new Build(); build.setOutputDirectory("target/junk"); project.setBuild(build); ServiceFileCombinationConfig config = new ServiceFileCombinationConfig() .setProject(project) .setArtifacts(artifacts) .setArchive(ServiceUtils.getDefaultFatJar()) .setMojo(mojo); combiner.doCombine(config); File merged = new File("target/junk/META-INF/services/com.test.demo.DemoSPI"); assertThat(merged).isFile(); List<String> lines = FileUtils.readLines(merged, "UTF-8"); assertThat(lines).hasSize(3).containsExactly( "com.test.demo.DemoSPI.impl.DemoSPIImpl", "com.test.demo.DemoSPI.impl.DemoSPIImpl2", "com.test.demo.DemoSPI.impl.DemoSPIImpl4"); Stream.of(jar1, jar2, jar3, jar4, new File("target/junk")).forEach(FileUtils::deleteQuietly); }
Example 16
Source File: SPICombineTest.java From vertx-maven-plugin with Apache License 2.0 | 4 votes |
@Test public void testCombine() throws Exception { File jar1 = new File("target/testCombine1.jar"); File jar2 = new File("target/testCombine2.jar"); File jar3 = new File("target/testCombine3.jar"); JavaArchive jarArchive1 = ShrinkWrap.create(JavaArchive.class); jarArchive1.addAsServiceProvider("com.test.demo.DemoSPI", "com.test.demo.DemoSPI.impl.DemoSPIImpl"); jarArchive1.as(ZipExporter.class).exportTo(jar1, true); JavaArchive jarArchive2 = ShrinkWrap.create(JavaArchive.class); jarArchive2.addAsServiceProvider("com.test.demo.DemoSPI", "com.test.demo.DemoSPI.impl.DemoSPIImpl2"); jarArchive2.addAsServiceProvider("com.test.demo.DemoSP2", "com.test.demo.DemoSPI2.impl.DemoSPI2Impl2"); jarArchive2.as(ZipExporter.class).exportTo(jar2, true); JavaArchive jarArchive3 = ShrinkWrap.create(JavaArchive.class); jarArchive3.addClass(SPICombineTest.class); jarArchive3.as(ZipExporter.class).exportTo(jar3, true); Set<Artifact> artifacts = new LinkedHashSet<>(); Artifact a1 = new DefaultArtifact("org.acme", "a1", "1.0", "compile", "jar", "", null); a1.setFile(jar1); Artifact a2 = new DefaultArtifact("org.acme", "a2", "1.0", "compile", "jar", "", null); a2.setFile(jar2); Artifact a3 = new DefaultArtifact("org.acme", "a3", "1.0", "compile", "jar", "", null); a3.setFile(jar3); artifacts.add(a1); artifacts.add(a2); artifacts.add(a3); MavenProject project = new MavenProject(); project.setVersion("1.0"); project.setArtifactId("foo"); AbstractVertxMojo mojo = new AbstractVertxMojo() { @Override public void execute() throws MojoExecutionException, MojoFailureException { } }; mojo.setLog(new SystemStreamLog()); Build build = new Build(); build.setOutputDirectory("target/junk"); project.setBuild(build); ServiceFileCombinationConfig config = new ServiceFileCombinationConfig() .setProject(project) .setArtifacts(artifacts) .setArchive(ServiceUtils.getDefaultFatJar()) .setMojo(mojo); combiner.doCombine(config); File merged = new File("target/junk/META-INF/services/com.test.demo.DemoSPI"); assertThat(merged).isFile(); List<String> lines = FileUtils.readLines(merged, "UTF-8"); assertThat(lines).containsExactly("com.test.demo.DemoSPI.impl.DemoSPIImpl", "com.test.demo.DemoSPI.impl.DemoSPIImpl2"); Stream.of(jar1, jar2, jar3, new File("target/junk")).forEach(FileUtils::deleteQuietly); }
Example 17
Source File: PackageMojo.java From vertx-maven-plugin with Apache License 2.0 | 4 votes |
@Override public void execute() throws MojoExecutionException, MojoFailureException { if (skip) { getLog().info("vertx:package skipped by configuration"); return; } // Fix empty classifier. if (classifier != null && classifier.trim().isEmpty()) { getLog().debug("The classifier is empty, it won't be used"); classifier = null; } if (classifier == null && !attach) { throw new MojoExecutionException("Cannot disable attachment of the created archive when it's the main " + "artifact"); } //TODO Archive should be a parameter. Archive archive = ServiceUtils.getDefaultFatJar(); if (launcher != null && !launcher.trim().isEmpty()) { archive.getManifest().putIfAbsent("Main-Class", launcher); } if (verticle != null && !verticle.trim().isEmpty()) { archive.getManifest().putIfAbsent("Main-Verticle", verticle); } List<ManifestCustomizerService> customizers = getManifestCustomizers(); customizers.forEach(customizer -> archive.getManifest().putAll(customizer.getEntries(this, project))); // Manage SPI combination combiner.doCombine(new ServiceFileCombinationConfig() .setStrategy(serviceProviderCombination) .setProject(project) .setArchive(archive) .setMojo(this) .setArtifacts(project.getArtifacts())); File jar; try { jar = packageService.doPackage( new PackageConfig() .setArtifacts(project.getArtifacts()) .setMojo(this) .setOutput(new File(projectBuildDir, computeOutputName(project, classifier))) .setProject(project) .setArchive(archive)); } catch (PackagingException e) { throw new MojoExecutionException("Unable to build the fat jar", e); } if (jar.isFile() && classifier != null && attach) { ArtifactHandler handler = new DefaultArtifactHandler("jar"); Artifact vertxJarArtifact = new DefaultArtifact(project.getGroupId(), project.getArtifactId(), project.getVersion(), "compile", "jar", classifier, handler); vertxJarArtifact.setFile(jar); this.project.addAttachedArtifact(vertxJarArtifact); } }
Example 18
Source File: SPICombineTest.java From vertx-maven-plugin with Apache License 2.0 | 4 votes |
@Test public void testCombineWithSpringDescriptors() throws Exception { File jar1 = new File("target/testCombine1Spring.jar"); File jar2 = new File("target/testCombine2Spring.jar"); File jar3 = new File("target/testCombine3Spring.jar"); JavaArchive jarArchive1 = ShrinkWrap.create(JavaArchive.class); jarArchive1.add(new StringAsset("com.test.demo.DemoSPI.impl.DemoSPIImpl"), "/META-INF/spring.foo"); jarArchive1.as(ZipExporter.class).exportTo(jar1, true); JavaArchive jarArchive2 = ShrinkWrap.create(JavaArchive.class); jarArchive2.add(new StringAsset("com.test.demo.DemoSPI.impl.DemoSPIImpl2"), "/META-INF/spring.foo"); jarArchive2.add(new StringAsset("com.test.demo.DemoSPI2.impl.DemoSPI2Impl2"), "/META-INF/spring.bar"); jarArchive2.as(ZipExporter.class).exportTo(jar2, true); JavaArchive jarArchive3 = ShrinkWrap.create(JavaArchive.class); jarArchive3.addClass(SPICombineTest.class); jarArchive3.as(ZipExporter.class).exportTo(jar3, true); Set<Artifact> artifacts = new LinkedHashSet<>(); Artifact a1 = new DefaultArtifact("org.acme", "a1", "1.0", "compile", "jar", "", null); a1.setFile(jar1); Artifact a2 = new DefaultArtifact("org.acme", "a2", "1.0", "compile", "jar", "", null); a2.setFile(jar2); Artifact a3 = new DefaultArtifact("org.acme", "a3", "1.0", "compile", "jar", "", null); a3.setFile(jar3); artifacts.add(a1); artifacts.add(a2); artifacts.add(a3); MavenProject project = new MavenProject(); project.setVersion("1.0"); project.setArtifactId("foo"); AbstractVertxMojo mojo = new AbstractVertxMojo() { @Override public void execute() throws MojoExecutionException, MojoFailureException { } }; mojo.setLog(new SystemStreamLog()); Build build = new Build(); build.setOutputDirectory("target/junk"); project.setBuild(build); ServiceFileCombinationConfig config = new ServiceFileCombinationConfig() .setProject(project) .setArtifacts(artifacts) .setArchive(ServiceUtils.getDefaultFatJar()) .setMojo(mojo); combiner.doCombine(config); File merged = new File("target/junk/META-INF/spring.foo"); assertThat(merged).isFile(); List<String> lines = FileUtils.readLines(merged, "UTF-8"); assertThat(lines).containsExactly("com.test.demo.DemoSPI.impl.DemoSPIImpl", "com.test.demo.DemoSPI.impl.DemoSPIImpl2"); Stream.of(jar1, jar2, jar3, new File("target/junk")).forEach(FileUtils::deleteQuietly); }
Example 19
Source File: SPICombineTest.java From vertx-maven-plugin with Apache License 2.0 | 4 votes |
@Test public void testCombineDiffSPI() throws Exception { File jar1 = new File("target/testCombineDiffSPI.jar"); File jar2 = new File("target/testCombineDiffSPI2.jar"); File jar3 = new File("target/testCombineDiffSPI3.jar"); File jar4 = new File("target/testCombineDiffSPI4.jar"); JavaArchive jarArchive1 = ShrinkWrap.create(JavaArchive.class); jarArchive1.addAsServiceProvider("com.test.demo.DemoSPI", "com.test.demo.DemoSPI.impl.DemoSPIImpl"); jarArchive1.as(ZipExporter.class).exportTo(jar1, true); JavaArchive jarArchive2 = ShrinkWrap.create(JavaArchive.class); jarArchive2.addAsServiceProvider("com.test.demo.DemoSPI", "com.test.demo.DemoSPI.impl.DemoSPIImpl2"); jarArchive2.as(ZipExporter.class).exportTo(jar2, true); JavaArchive jarArchive3 = ShrinkWrap.create(JavaArchive.class); jarArchive3.addClass(SPICombineTest.class); jarArchive3.as(ZipExporter.class).exportTo(jar3, true); JavaArchive jarArchive4 = ShrinkWrap.create(JavaArchive.class); jarArchive4.addAsServiceProvider("com.test.demo.DemoSPI", "com.test.demo.DemoSPI.impl.DemoSPIImpl4"); jarArchive4.as(ZipExporter.class).exportTo(jar4, true); Set<Artifact> artifacts = new LinkedHashSet<>(); Artifact a1 = new DefaultArtifact("org.acme", "a1", "1.0", "compile", "jar", "", null); a1.setFile(jar1); Artifact a2 = new DefaultArtifact("org.acme", "a2", "1.0", "compile", "jar", "", null); a2.setFile(jar2); Artifact a3 = new DefaultArtifact("org.acme", "a3", "1.0", "compile", "jar", "", null); a3.setFile(jar3); Artifact a4 = new DefaultArtifact("org.acme", "a4", "1.0", "compile", "jar", "", null); a4.setFile(jar4); artifacts.add(a1); artifacts.add(a2); artifacts.add(a3); artifacts.add(a4); MavenProject project = new MavenProject(); project.setVersion("1.0"); project.setArtifactId("foo"); AbstractVertxMojo mojo = new AbstractVertxMojo() { @Override public void execute() throws MojoExecutionException, MojoFailureException { } }; mojo.setLog(new SystemStreamLog()); Build build = new Build(); build.setOutputDirectory("target/junk"); project.setBuild(build); ServiceFileCombinationConfig config = new ServiceFileCombinationConfig() .setProject(project) .setArtifacts(artifacts) .setArchive(ServiceUtils.getDefaultFatJar()) .setMojo(mojo); combiner.doCombine(config); File merged = new File("target/junk/META-INF/services/com.test.demo.DemoSPI"); assertThat(merged).isFile(); List<String> lines = FileUtils.readLines(merged, "UTF-8"); assertThat(lines).hasSize(3).containsExactly( "com.test.demo.DemoSPI.impl.DemoSPIImpl", "com.test.demo.DemoSPI.impl.DemoSPIImpl2", "com.test.demo.DemoSPI.impl.DemoSPIImpl4"); Stream.of(jar1, jar2, jar3, jar4, new File("target/junk")).forEach(FileUtils::deleteQuietly); }
Example 20
Source File: SPICombineTest.java From vertx-maven-plugin with Apache License 2.0 | 4 votes |
@Test public void testCombine() throws Exception { File jar1 = new File("target/testCombine1.jar"); File jar2 = new File("target/testCombine2.jar"); File jar3 = new File("target/testCombine3.jar"); JavaArchive jarArchive1 = ShrinkWrap.create(JavaArchive.class); jarArchive1.addAsServiceProvider("com.test.demo.DemoSPI", "com.test.demo.DemoSPI.impl.DemoSPIImpl"); jarArchive1.as(ZipExporter.class).exportTo(jar1, true); JavaArchive jarArchive2 = ShrinkWrap.create(JavaArchive.class); jarArchive2.addAsServiceProvider("com.test.demo.DemoSPI", "com.test.demo.DemoSPI.impl.DemoSPIImpl2"); jarArchive2.addAsServiceProvider("com.test.demo.DemoSP2", "com.test.demo.DemoSPI2.impl.DemoSPI2Impl2"); jarArchive2.as(ZipExporter.class).exportTo(jar2, true); JavaArchive jarArchive3 = ShrinkWrap.create(JavaArchive.class); jarArchive3.addClass(SPICombineTest.class); jarArchive3.as(ZipExporter.class).exportTo(jar3, true); Set<Artifact> artifacts = new LinkedHashSet<>(); Artifact a1 = new DefaultArtifact("org.acme", "a1", "1.0", "compile", "jar", "", null); a1.setFile(jar1); Artifact a2 = new DefaultArtifact("org.acme", "a2", "1.0", "compile", "jar", "", null); a2.setFile(jar2); Artifact a3 = new DefaultArtifact("org.acme", "a3", "1.0", "compile", "jar", "", null); a3.setFile(jar3); artifacts.add(a1); artifacts.add(a2); artifacts.add(a3); MavenProject project = new MavenProject(); project.setVersion("1.0"); project.setArtifactId("foo"); AbstractVertxMojo mojo = new AbstractVertxMojo() { @Override public void execute() throws MojoExecutionException, MojoFailureException { } }; mojo.setLog(new SystemStreamLog()); Build build = new Build(); build.setOutputDirectory("target/junk"); project.setBuild(build); ServiceFileCombinationConfig config = new ServiceFileCombinationConfig() .setProject(project) .setArtifacts(artifacts) .setArchive(ServiceUtils.getDefaultFatJar()) .setMojo(mojo); combiner.doCombine(config); File merged = new File("target/junk/META-INF/services/com.test.demo.DemoSPI"); assertThat(merged).isFile(); List<String> lines = FileUtils.readLines(merged, "UTF-8"); assertThat(lines).containsExactly("com.test.demo.DemoSPI.impl.DemoSPIImpl", "com.test.demo.DemoSPI.impl.DemoSPIImpl2"); Stream.of(jar1, jar2, jar3, new File("target/junk")).forEach(FileUtils::deleteQuietly); }