use of org.apache.maven.plugin.MojoFailureException in project camel by apache.
the class PrepareCatalogSpringBootMojo method executeLanguages.
protected void executeLanguages(Set<String> starters) throws MojoExecutionException, MojoFailureException {
getLog().info("Copying all Camel language json descriptors");
// lets use sorted set/maps
Set<File> jsonFiles = new TreeSet<File>();
Set<File> languageFiles = new TreeSet<File>();
// find all languages from the components directory
if (componentsDir != null && componentsDir.isDirectory()) {
File[] languages = componentsDir.listFiles();
if (languages != null) {
for (File dir : languages) {
// skip camel-spring-dm
if (dir.isDirectory() && "camel-spring-dm".equals(dir.getName())) {
continue;
}
// the directory must be in the list of known starters
if (!starters.contains(dir.getName())) {
continue;
}
if (dir.isDirectory() && !"target".equals(dir.getName())) {
File target = new File(dir, "target/classes");
findLanguageFilesRecursive(target, jsonFiles, languageFiles, new CamelLanguagesFileFilter());
}
}
}
}
if (coreDir != null && coreDir.isDirectory()) {
File target = new File(coreDir, "target/classes");
findLanguageFilesRecursive(target, jsonFiles, languageFiles, new CamelLanguagesFileFilter());
}
getLog().info("Found " + languageFiles.size() + " language.properties files");
getLog().info("Found " + jsonFiles.size() + " language json files");
// make sure to create out dir
languagesOutDir.mkdirs();
for (File file : jsonFiles) {
// for spring-boot we need to amend the json file to use -starter as the artifact-id
try {
String text = loadText(new FileInputStream(file));
text = ARTIFACT_PATTERN.matcher(text).replaceFirst("\"artifactId\": \"camel-$1-starter\"");
// write new json file
File to = new File(languagesOutDir, file.getName());
FileOutputStream fos = new FileOutputStream(to, false);
fos.write(text.getBytes());
fos.close();
} catch (IOException e) {
throw new MojoFailureException("Cannot write json file " + file, e);
}
}
File all = new File(languagesOutDir, "../languages.properties");
try {
FileOutputStream fos = new FileOutputStream(all, false);
String[] names = languagesOutDir.list();
List<String> languages = new ArrayList<String>();
// sort the names
for (String name : names) {
if (name.endsWith(".json")) {
// strip out .json from the name
String languageName = name.substring(0, name.length() - 5);
languages.add(languageName);
}
}
Collections.sort(languages);
for (String name : languages) {
fos.write(name.getBytes());
fos.write("\n".getBytes());
}
fos.close();
} catch (IOException e) {
throw new MojoFailureException("Error writing to file " + all);
}
}
use of org.apache.maven.plugin.MojoFailureException in project camel by apache.
the class PrepareReadmeMojo method executeDataFormatsReadme.
protected void executeDataFormatsReadme(boolean coreOnly) throws MojoExecutionException, MojoFailureException {
Set<File> dataFormatFiles = new TreeSet<>();
if (dataFormatsDir != null && dataFormatsDir.isDirectory()) {
File[] files = dataFormatsDir.listFiles();
if (files != null) {
dataFormatFiles.addAll(Arrays.asList(files));
}
}
try {
List<DataFormatModel> models = new ArrayList<>();
for (File file : dataFormatFiles) {
String json = loadText(new FileInputStream(file));
DataFormatModel model = generateDataFormatModel(json);
// special for bindy as we have one common file
if (model.getName().startsWith("bindy")) {
model.setName("bindy");
}
models.add(model);
}
// sort the models
Collections.sort(models, new DataFormatComparator());
// how many different artifacts
int count = models.stream().map(DataFormatModel::getArtifactId).collect(toSet()).size();
// how many deprecated
long deprecated = models.stream().filter(m -> "true".equals(m.getDeprecated())).count();
// filter out camel-core
List<DataFormatModel> dataFormats = new ArrayList<>();
for (DataFormatModel model : models) {
if (coreOnly) {
if ("camel-core".equals(model.getArtifactId())) {
// only include core components
dataFormats.add(model);
}
} else {
// we want to include everything in the big file (also from camel-core)
dataFormats.add(model);
}
}
// update the big readme file in the core/components dir
File file;
if (coreOnly) {
file = new File(readmeCoreDir, "readme.adoc");
} else {
file = new File(readmeComponentsDir, "readme.adoc");
}
// update regular data formats
boolean exists = file.exists();
String changed = templateDataFormats(dataFormats, count, deprecated);
boolean updated = updateDataFormats(file, changed);
if (updated) {
getLog().info("Updated readme.adoc file: " + file);
} else if (exists) {
getLog().debug("No changes to readme.adoc file: " + file);
} else {
getLog().warn("No readme.adoc file: " + file);
}
} catch (IOException e) {
throw new MojoFailureException("Error due " + e.getMessage(), e);
}
}
use of org.apache.maven.plugin.MojoFailureException in project camel by apache.
the class PrepareReadmeMojo method executeLanguagesReadme.
protected void executeLanguagesReadme(boolean coreOnly) throws MojoExecutionException, MojoFailureException {
Set<File> languageFiles = new TreeSet<>();
if (languagesDir != null && languagesDir.isDirectory()) {
File[] files = languagesDir.listFiles();
if (files != null) {
languageFiles.addAll(Arrays.asList(files));
}
}
try {
List<LanguageModel> models = new ArrayList<>();
for (File file : languageFiles) {
String json = loadText(new FileInputStream(file));
LanguageModel model = generateLanguageModel(json);
models.add(model);
}
// sort the models
Collections.sort(models, new LanguageComparator());
// filter out camel-core
List<LanguageModel> languages = new ArrayList<>();
for (LanguageModel model : models) {
if (coreOnly) {
if ("camel-core".equals(model.getArtifactId())) {
// only include core components
languages.add(model);
}
} else {
// we want to include everything in the big file (also from camel-core)
languages.add(model);
}
}
// how many different artifacts
int count = languages.stream().map(LanguageModel::getArtifactId).collect(toSet()).size();
// how many deprecated
long deprecated = languages.stream().filter(l -> "true".equals(l.getDeprecated())).count();
// update the big readme file in the core/components dir
File file;
if (coreOnly) {
file = new File(readmeCoreDir, "readme.adoc");
} else {
file = new File(readmeComponentsDir, "readme.adoc");
}
// update regular data formats
boolean exists = file.exists();
String changed = templateLanguages(languages, count, deprecated);
boolean updated = updateLanguages(file, changed);
if (updated) {
getLog().info("Updated readme.adoc file: " + file);
} else if (exists) {
getLog().debug("No changes to readme.adoc file: " + file);
} else {
getLog().warn("No readme.adoc file: " + file);
}
} catch (IOException e) {
throw new MojoFailureException("Error due " + e.getMessage(), e);
}
}
use of org.apache.maven.plugin.MojoFailureException in project camel by apache.
the class PrepareCatalogKarafMojo method executeLanguages.
protected void executeLanguages(Set<String> features) throws MojoExecutionException, MojoFailureException {
getLog().info("Copying all Camel language json descriptors");
// lets use sorted set/maps
Set<File> jsonFiles = new TreeSet<File>();
Set<File> languageFiles = new TreeSet<File>();
// find all languages from the components directory
if (componentsDir != null && componentsDir.isDirectory()) {
File[] languages = componentsDir.listFiles();
if (languages != null) {
for (File dir : languages) {
// skip camel-spring-dm
if (dir.isDirectory() && "camel-spring-dm".equals(dir.getName())) {
continue;
}
// the directory must be in the list of known features
if (!features.contains(dir.getName())) {
continue;
}
if (dir.isDirectory() && !"target".equals(dir.getName())) {
File target = new File(dir, "target/classes");
findLanguageFilesRecursive(target, jsonFiles, languageFiles, new CamelLanguagesFileFilter());
}
}
}
}
if (coreDir != null && coreDir.isDirectory()) {
File target = new File(coreDir, "target/classes");
findLanguageFilesRecursive(target, jsonFiles, languageFiles, new CamelLanguagesFileFilter());
}
getLog().info("Found " + languageFiles.size() + " language.properties files");
getLog().info("Found " + jsonFiles.size() + " language json files");
// make sure to create out dir
languagesOutDir.mkdirs();
for (File file : jsonFiles) {
File to = new File(languagesOutDir, file.getName());
try {
copyFile(file, to);
} catch (IOException e) {
throw new MojoFailureException("Cannot copy file from " + file + " -> " + to, e);
}
}
File all = new File(languagesOutDir, "../languages.properties");
try {
FileOutputStream fos = new FileOutputStream(all, false);
String[] names = languagesOutDir.list();
List<String> languages = new ArrayList<String>();
// sort the names
for (String name : names) {
if (name.endsWith(".json")) {
// strip out .json from the name
String languageName = name.substring(0, name.length() - 5);
languages.add(languageName);
}
}
Collections.sort(languages);
for (String name : languages) {
fos.write(name.getBytes());
fos.write("\n".getBytes());
}
fos.close();
} catch (IOException e) {
throw new MojoFailureException("Error writing to file " + all);
}
}
use of org.apache.maven.plugin.MojoFailureException in project camel by apache.
the class PrepareCatalogKarafMojo method findKarafFeatures.
private Set<String> findKarafFeatures() throws MojoExecutionException, MojoFailureException {
// load features.xml file and parse it
Set<String> answer = new LinkedHashSet<>();
try {
InputStream is = new FileInputStream(new File(featuresDir, "features.xml"));
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setIgnoringComments(true);
dbf.setIgnoringElementContentWhitespace(true);
dbf.setNamespaceAware(false);
dbf.setValidating(false);
dbf.setXIncludeAware(false);
Document dom = dbf.newDocumentBuilder().parse(is);
NodeList children = dom.getElementsByTagName("features");
for (int i = 0; i < children.getLength(); i++) {
Node child = children.item(i);
if (child.getNodeType() == ELEMENT_NODE) {
NodeList children2 = child.getChildNodes();
for (int j = 0; j < children2.getLength(); j++) {
Node child2 = children2.item(j);
if ("feature".equals(child2.getNodeName())) {
String artifactId = child2.getAttributes().getNamedItem("name").getTextContent();
if (artifactId != null && artifactId.startsWith("camel-")) {
answer.add(artifactId);
}
}
}
}
}
} catch (Exception e) {
throw new MojoExecutionException("Error reading features.xml file", e);
}
return answer;
}
Aggregations