use of org.apache.maven.artifact.Artifact in project spring-boot by spring-projects.
the class IncludeFilterTests method includeClassifierNoTargetClassifier.
@Test
public void includeClassifierNoTargetClassifier() throws ArtifactFilterException {
IncludeFilter filter = new IncludeFilter(Arrays.asList(createInclude("com.foo", "bar", "jdk5")));
Artifact artifact = createArtifact("com.foo", "bar");
Set result = filter.filter(Collections.singleton(artifact));
assertThat(result).isEmpty();
}
use of org.apache.maven.artifact.Artifact in project spring-boot by spring-projects.
the class IncludeFilterTests method includeMulti.
@Test
public void includeMulti() throws ArtifactFilterException {
IncludeFilter filter = new IncludeFilter(Arrays.asList(createInclude("com.foo", "bar"), createInclude("com.foo", "bar2"), createInclude("org.acme", "app")));
Set<Artifact> artifacts = new HashSet<>();
artifacts.add(createArtifact("com.foo", "bar"));
artifacts.add(createArtifact("com.foo", "bar"));
Artifact anotherAcme = createArtifact("org.acme", "another-app");
artifacts.add(anotherAcme);
Set result = filter.filter(artifacts);
assertThat(result).hasSize(2);
}
use of org.apache.maven.artifact.Artifact in project camel by apache.
the class PackageDataFormatMojo method prepareDataFormat.
public static void prepareDataFormat(Log log, MavenProject project, MavenProjectHelper projectHelper, File dataFormatOutDir, File schemaOutDir, BuildContext buildContext) throws MojoExecutionException {
File camelMetaDir = new File(dataFormatOutDir, "META-INF/services/org/apache/camel/");
// can stop the build before the end and eclipse always needs to know about that directory
if (projectHelper != null) {
projectHelper.addResource(project, dataFormatOutDir.getPath(), Collections.singletonList("**/dataformat.properties"), Collections.emptyList());
}
if (!PackageHelper.haveResourcesChanged(log, project, buildContext, "META-INF/services/org/apache/camel/dataformat")) {
return;
}
Map<String, String> javaTypes = new HashMap<String, String>();
StringBuilder buffer = new StringBuilder();
int count = 0;
for (Resource r : project.getBuild().getResources()) {
File f = new File(r.getDirectory());
if (!f.exists()) {
f = new File(project.getBasedir(), r.getDirectory());
}
f = new File(f, "META-INF/services/org/apache/camel/dataformat");
if (f.exists() && f.isDirectory()) {
File[] files = f.listFiles();
if (files != null) {
for (File file : files) {
String javaType = readClassFromCamelResource(file, buffer, buildContext);
if (!file.isDirectory() && file.getName().charAt(0) != '.') {
count++;
}
if (javaType != null) {
javaTypes.put(file.getName(), javaType);
}
}
}
}
}
// and create json schema model file for this data format
try {
if (count > 0) {
Artifact camelCore = findCamelCoreArtifact(project);
if (camelCore != null) {
File core = camelCore.getFile();
if (core != null) {
URL url = new URL("file", null, core.getAbsolutePath());
URLClassLoader loader = new URLClassLoader(new URL[] { url });
for (Map.Entry<String, String> entry : javaTypes.entrySet()) {
String name = entry.getKey();
String javaType = entry.getValue();
String modelName = asModelName(name);
InputStream is = loader.getResourceAsStream("org/apache/camel/model/dataformat/" + modelName + ".json");
if (is == null) {
// use file input stream if we build camel-core itself, and thus do not have a JAR which can be loaded by URLClassLoader
is = new FileInputStream(new File(core, "org/apache/camel/model/dataformat/" + modelName + ".json"));
}
String json = loadText(is);
DataFormatModel dataFormatModel = new DataFormatModel();
dataFormatModel.setName(name);
dataFormatModel.setTitle("");
dataFormatModel.setModelName(modelName);
dataFormatModel.setLabel("");
dataFormatModel.setDescription(project.getDescription());
dataFormatModel.setJavaType(javaType);
dataFormatModel.setGroupId(project.getGroupId());
dataFormatModel.setArtifactId(project.getArtifactId());
dataFormatModel.setVersion(project.getVersion());
List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("model", json, false);
for (Map<String, String> row : rows) {
if (row.containsKey("title")) {
String title = row.get("title");
dataFormatModel.setTitle(asModelTitle(name, title));
}
if (row.containsKey("label")) {
dataFormatModel.setLabel(row.get("label"));
}
if (row.containsKey("deprecated")) {
dataFormatModel.setDeprecated(row.get("deprecated"));
}
if (row.containsKey("javaType")) {
dataFormatModel.setModelJavaType(row.get("javaType"));
}
if (row.containsKey("firstVersion")) {
dataFormatModel.setFirstVersion(row.get("firstVersion"));
}
// override description for camel-core, as otherwise its too generic
if ("camel-core".equals(project.getArtifactId())) {
if (row.containsKey("description")) {
dataFormatModel.setDescription(row.get("description"));
}
}
}
// first version special for json
String firstVersion = prepareJsonFirstVersion(name);
if (firstVersion != null) {
dataFormatModel.setFirstVersion(firstVersion);
}
log.debug("Model " + dataFormatModel);
// build json schema for the data format
String properties = after(json, " \"properties\": {");
// special prepare for bindy/json properties
properties = prepareBindyProperties(name, properties);
properties = prepareJsonProperties(name, properties);
String schema = createParameterJsonSchema(dataFormatModel, properties);
log.debug("JSon schema\n" + schema);
// write this to the directory
File dir = new File(schemaOutDir, schemaSubDirectory(dataFormatModel.getJavaType()));
dir.mkdirs();
File out = new File(dir, name + ".json");
OutputStream fos = buildContext.newFileOutputStream(out);
fos.write(schema.getBytes());
fos.close();
log.debug("Generated " + out + " containing JSon schema for " + name + " data format");
}
}
}
}
} catch (Exception e) {
throw new MojoExecutionException("Error loading dataformat model from camel-core. Reason: " + e, e);
}
if (count > 0) {
Properties properties = new Properties();
String names = buffer.toString();
properties.put("dataFormats", names);
properties.put("groupId", project.getGroupId());
properties.put("artifactId", project.getArtifactId());
properties.put("version", project.getVersion());
properties.put("projectName", project.getName());
if (project.getDescription() != null) {
properties.put("projectDescription", project.getDescription());
}
camelMetaDir.mkdirs();
File outFile = new File(camelMetaDir, "dataformat.properties");
// which can cause a re-compile of all the source code
if (outFile.exists()) {
try {
Properties existing = new Properties();
InputStream is = new FileInputStream(outFile);
existing.load(is);
is.close();
// are the content the same?
if (existing.equals(properties)) {
log.debug("No dataformat changes detected");
return;
}
} catch (IOException e) {
// ignore
}
}
try {
OutputStream os = buildContext.newFileOutputStream(outFile);
properties.store(os, "Generated by camel-package-maven-plugin");
os.close();
log.info("Generated " + outFile + " containing " + count + " Camel " + (count > 1 ? "dataformats: " : "dataformat: ") + names);
} catch (IOException e) {
throw new MojoExecutionException("Failed to write properties to " + outFile + ". Reason: " + e, e);
}
} else {
log.debug("No META-INF/services/org/apache/camel/dataformat directory found. Are you sure you have created a Camel data format?");
}
}
use of org.apache.maven.artifact.Artifact in project camel by apache.
the class PackageLanguageMojo method prepareLanguage.
public static void prepareLanguage(Log log, MavenProject project, MavenProjectHelper projectHelper, File languageOutDir, File schemaOutDir, BuildContext buildContext) throws MojoExecutionException {
File camelMetaDir = new File(languageOutDir, "META-INF/services/org/apache/camel/");
// can stop the build before the end and eclipse always needs to know about that directory
if (projectHelper != null) {
projectHelper.addResource(project, languageOutDir.getPath(), Collections.singletonList("**/language.properties"), Collections.emptyList());
}
if (!PackageHelper.haveResourcesChanged(log, project, buildContext, "META-INF/services/org/apache/camel/language")) {
return;
}
Map<String, String> javaTypes = new HashMap<String, String>();
StringBuilder buffer = new StringBuilder();
int count = 0;
for (Resource r : project.getBuild().getResources()) {
File f = new File(r.getDirectory());
if (!f.exists()) {
f = new File(project.getBasedir(), r.getDirectory());
}
f = new File(f, "META-INF/services/org/apache/camel/language");
if (f.exists() && f.isDirectory()) {
File[] files = f.listFiles();
if (files != null) {
for (File file : files) {
String javaType = readClassFromCamelResource(file, buffer, buildContext);
if (!file.isDirectory() && file.getName().charAt(0) != '.') {
count++;
}
if (javaType != null) {
javaTypes.put(file.getName(), javaType);
}
}
}
}
}
// and create json schema model file for this data format
try {
if (count > 0) {
Artifact camelCore = findCamelCoreArtifact(project);
if (camelCore != null) {
File core = camelCore.getFile();
if (core != null) {
URL url = new URL("file", null, core.getAbsolutePath());
URLClassLoader loader = new URLClassLoader(new URL[] { url });
for (Map.Entry<String, String> entry : javaTypes.entrySet()) {
String name = entry.getKey();
String javaType = entry.getValue();
String modelName = asModelName(name);
InputStream is = loader.getResourceAsStream("org/apache/camel/model/language/" + modelName + ".json");
if (is == null) {
// use file input stream if we build camel-core itself, and thus do not have a JAR which can be loaded by URLClassLoader
is = new FileInputStream(new File(core, "org/apache/camel/model/language/" + modelName + ".json"));
}
String json = loadText(is);
LanguageModel languageModel = new LanguageModel();
languageModel.setName(name);
languageModel.setTitle("");
languageModel.setModelName(modelName);
languageModel.setLabel("");
languageModel.setDescription("");
languageModel.setJavaType(javaType);
languageModel.setGroupId(project.getGroupId());
languageModel.setArtifactId(project.getArtifactId());
languageModel.setVersion(project.getVersion());
List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("model", json, false);
for (Map<String, String> row : rows) {
if (row.containsKey("title")) {
// title may be special for some languages
String title = asTitle(name, row.get("title"));
languageModel.setTitle(title);
}
if (row.containsKey("description")) {
// description may be special for some languages
String desc = asDescription(name, row.get("description"));
languageModel.setDescription(desc);
}
if (row.containsKey("label")) {
languageModel.setLabel(row.get("label"));
}
if (row.containsKey("deprecated")) {
languageModel.setDeprecated(row.get("deprecated"));
}
if (row.containsKey("javaType")) {
languageModel.setModelJavaType(row.get("javaType"));
}
if (row.containsKey("firstVersion")) {
languageModel.setFirstVersion(row.get("firstVersion"));
}
}
log.debug("Model " + languageModel);
// build json schema for the data format
String properties = after(json, " \"properties\": {");
String schema = createParameterJsonSchema(languageModel, properties);
log.debug("JSon schema\n" + schema);
// write this to the directory
File dir = new File(schemaOutDir, schemaSubDirectory(languageModel.getJavaType()));
dir.mkdirs();
File out = new File(dir, name + ".json");
OutputStream fos = buildContext.newFileOutputStream(out);
fos.write(schema.getBytes());
fos.close();
buildContext.refresh(out);
log.debug("Generated " + out + " containing JSon schema for " + name + " language");
}
}
}
}
} catch (Exception e) {
throw new MojoExecutionException("Error loading language model from camel-core. Reason: " + e, e);
}
if (count > 0) {
Properties properties = new Properties();
String names = buffer.toString();
properties.put("languages", names);
properties.put("groupId", project.getGroupId());
properties.put("artifactId", project.getArtifactId());
properties.put("version", project.getVersion());
properties.put("projectName", project.getName());
if (project.getDescription() != null) {
properties.put("projectDescription", project.getDescription());
}
camelMetaDir.mkdirs();
File outFile = new File(camelMetaDir, "language.properties");
// which can cause a re-compile of all the source code
if (outFile.exists()) {
try {
Properties existing = new Properties();
InputStream is = new FileInputStream(outFile);
existing.load(is);
is.close();
// are the content the same?
if (existing.equals(properties)) {
log.debug("No language changes detected");
return;
}
} catch (IOException e) {
// ignore
}
}
try {
OutputStream os = buildContext.newFileOutputStream(outFile);
properties.store(os, "Generated by camel-package-maven-plugin");
os.close();
log.info("Generated " + outFile + " containing " + count + " Camel " + (count > 1 ? "languages: " : "language: ") + names);
} catch (IOException e) {
throw new MojoExecutionException("Failed to write properties to " + outFile + ". Reason: " + e, e);
}
} else {
log.debug("No META-INF/services/org/apache/camel/language directory found. Are you sure you have created a Camel language?");
}
}
use of org.apache.maven.artifact.Artifact in project camel by apache.
the class RunMojo method determineRelevantPluginDependencies.
/**
* Determine all plugin dependencies relevant to the executable. Takes
* includePlugins, and the executableDependency into consideration.
*
* @return a set of Artifact objects. (Empty set is returned if there are no
* relevant plugin dependencies.)
* @throws MojoExecutionException
*/
private Set<Artifact> determineRelevantPluginDependencies() throws MojoExecutionException {
Set<Artifact> relevantDependencies;
if (this.includePluginDependencies) {
if (this.executableDependency == null) {
getLog().debug("All Plugin Dependencies will be included.");
relevantDependencies = new HashSet<Artifact>(this.pluginDependencies);
} else {
getLog().debug("Selected plugin Dependencies will be included.");
Artifact executableArtifact = this.findExecutableArtifact();
Artifact executablePomArtifact = this.getExecutablePomArtifact(executableArtifact);
relevantDependencies = this.resolveExecutableDependencies(executablePomArtifact, false);
}
} else {
getLog().debug("Only Direct Plugin Dependencies will be included.");
PluginDescriptor descriptor = (PluginDescriptor) getPluginContext().get("pluginDescriptor");
try {
relevantDependencies = artifactResolver.resolveTransitively(MavenMetadataSource.createArtifacts(this.artifactFactory, descriptor.getPlugin().getDependencies(), null, null, null), this.project.getArtifact(), Collections.emptyMap(), this.localRepository, this.remoteRepositories, metadataSource, new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME), Collections.emptyList()).getArtifacts();
} catch (Exception ex) {
throw new MojoExecutionException("Encountered problems resolving dependencies of the plugin " + "in preparation for its execution.", ex);
}
}
return relevantDependencies;
}
Aggregations