use of org.apache.maven.model.Dependency in project gradle by gradle.
the class MavenPomFileGenerator method addDependency.
private void addDependency(MavenDependencyInternal dependency, String artifactId, String scope, String type, String classifier) {
Dependency mavenDependency = new Dependency();
mavenDependency.setGroupId(dependency.getGroupId());
mavenDependency.setArtifactId(artifactId);
mavenDependency.setVersion(mapToMavenSyntax(dependency.getVersion()));
mavenDependency.setType(type);
mavenDependency.setScope(scope);
mavenDependency.setClassifier(classifier);
for (ExcludeRule excludeRule : dependency.getExcludeRules()) {
Exclusion exclusion = new Exclusion();
exclusion.setGroupId(GUtil.elvis(excludeRule.getGroup(), "*"));
exclusion.setArtifactId(GUtil.elvis(excludeRule.getModule(), "*"));
mavenDependency.addExclusion(exclusion);
}
getModel().addDependency(mavenDependency);
}
use of org.apache.maven.model.Dependency in project meecrowave by apache.
the class MeecrowaveBundleMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if (skip) {
getLog().warn(getClass().getSimpleName() + " skipped");
return;
}
final File distroFolder = new File(buildDirectory, rootName == null ? artifactId + "-distribution" : rootName);
if (distroFolder.exists()) {
delete(distroFolder);
}
Stream.of("bin", "conf", "logs", "lib").forEach(i -> new File(distroFolder, i).mkdirs());
// TODO: add .bat support
for (final String ext : asList("sh", "bat")) {
try (final BufferedReader reader = new BufferedReader(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream("bin/meecrowave." + ext)))) {
write(new File(distroFolder, "bin/meecrowave." + ext), StrSubstitutor.replace(reader.lines().collect(joining("\n")), new HashMap<String, String>() {
{
put("main", main);
}
}));
} catch (final IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
copyProvidedFiles(distroFolder);
write(new File(distroFolder, "logs/you_can_safely_delete.txt"), DELETE_TEXT);
final Collection<String> includedArtifacts = project.getArtifacts().stream().filter(this::isIncluded).map(a -> {
addLib(distroFolder, a.getFile());
return a.getArtifactId();
}).collect(toList());
if (app.exists()) {
addLib(distroFolder, app);
}
if (enforceCommonsCli && !includedArtifacts.contains("commons-cli")) {
addLib(distroFolder, resolve("commons-cli", "commons-cli", "1.4", ""));
}
if (libs != null) {
libs.forEach(l -> {
final String[] c = l.split(":");
if (c.length != 3 && c.length != 4) {
throw new IllegalArgumentException("libs syntax is groupId:artifactId:version[:classifier]");
}
addLib(distroFolder, resolve(c[0], c[1], c[2], c.length == 4 ? c[3] : ""));
});
}
if (enforceMeecrowave && !includedArtifacts.contains("meecrowave-core")) {
final DependencyResolutionRequest request = new DefaultDependencyResolutionRequest();
request.setMavenProject(new MavenProject() {
{
getDependencies().add(new Dependency() {
{
setGroupId("org.apache.meecrowave");
setArtifactId("meecrowave-core");
setVersion(findVersion());
}
});
}
});
request.setRepositorySession(session);
try {
dependenciesResolver.resolve(request).getDependencyGraph().accept(new DependencyVisitor() {
@Override
public boolean visitEnter(final DependencyNode node) {
return true;
}
@Override
public boolean visitLeave(final DependencyNode node) {
final org.eclipse.aether.artifact.Artifact artifact = node.getArtifact();
if (artifact != null && !includedArtifacts.contains(artifact.getArtifactId())) {
addLib(distroFolder, artifact.getFile());
}
return true;
}
});
} catch (final DependencyResolutionException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
final Path prefix = skipArchiveRootFolder ? distroFolder.toPath() : distroFolder.getParentFile().toPath();
for (final String format : formats) {
getLog().info(format + "-ing Custom Meecrowave Distribution");
final File output = new File(buildDirectory, artifactId + "-meecrowave-distribution." + format);
switch(format.toLowerCase(ENGLISH)) {
case "tar.gz":
try (final TarArchiveOutputStream tarGz = new TarArchiveOutputStream(new GZIPOutputStream(new FileOutputStream(output)))) {
tarGz.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
for (final String entry : distroFolder.list()) {
tarGz(tarGz, new File(distroFolder, entry), prefix);
}
} catch (final IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
break;
case "zip":
try (final ZipArchiveOutputStream zos = new ZipArchiveOutputStream(new FileOutputStream(output))) {
for (final String entry : distroFolder.list()) {
zip(zos, new File(distroFolder, entry), prefix);
}
} catch (final IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
break;
default:
throw new IllegalArgumentException(format + " is not supported");
}
attach(format, output);
}
if (!keepExplodedFolder) {
delete(distroFolder);
}
}
use of org.apache.maven.model.Dependency in project drools by kiegroup.
the class AbstractKieCiTest method pomWithMvnDeps.
private String pomWithMvnDeps(Dependency releaseId, Dependency... dependencies) {
String pom = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + " xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd\">\n" + " <modelVersion>4.0.0</modelVersion>\n" + "\n" + " <groupId>" + releaseId.getGroupId() + "</groupId>\n" + " <artifactId>" + releaseId.getArtifactId() + "</artifactId>\n" + " <version>" + releaseId.getVersion() + "</version>\n" + "\n";
if (dependencies != null && dependencies.length > 0) {
pom += "<dependencies>\n";
for (Dependency dep : dependencies) {
pom += "<dependency>\n";
pom += " <groupId>" + dep.getGroupId() + "</groupId>\n";
pom += " <artifactId>" + dep.getArtifactId() + "</artifactId>\n";
pom += " <version>" + dep.getVersion() + "</version>\n";
if (!"".equals(dep.getScope()) && !"compile".equals(dep.getScope())) {
pom += " <scope>" + dep.getScope() + "</scope>\n";
}
if ("system".equals(dep.getScope())) {
pom += " <systemPath>" + dep.getSystemPath() + "</systemPath>\n";
}
pom += "</dependency>\n";
}
pom += "</dependencies>\n";
}
pom += "</project>";
return pom;
}
Aggregations