use of org.apache.maven.model.Resource in project camel by apache.
the class ValidateMojo method stripRootPath.
private String stripRootPath(String name) {
// strip out any leading source / resource directory
List list = project.getCompileSourceRoots();
for (Object obj : list) {
String dir = (String) obj;
dir = asRelativeFile(dir);
if (name.startsWith(dir)) {
return name.substring(dir.length() + 1);
}
}
list = project.getTestCompileSourceRoots();
for (Object obj : list) {
String dir = (String) obj;
dir = asRelativeFile(dir);
if (name.startsWith(dir)) {
return name.substring(dir.length() + 1);
}
}
List resources = project.getResources();
for (Object obj : resources) {
Resource resource = (Resource) obj;
String dir = asRelativeFile(resource.getDirectory());
if (name.startsWith(dir)) {
return name.substring(dir.length() + 1);
}
}
resources = project.getTestResources();
for (Object obj : resources) {
Resource resource = (Resource) obj;
String dir = asRelativeFile(resource.getDirectory());
if (name.startsWith(dir)) {
return name.substring(dir.length() + 1);
}
}
return name;
}
use of org.apache.maven.model.Resource in project camel by apache.
the class PackageComponentMojo method prepareComponent.
public static void prepareComponent(Log log, MavenProject project, MavenProjectHelper projectHelper, File componentOutDir, BuildContext buildContext) throws MojoExecutionException {
File camelMetaDir = new File(componentOutDir, "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, componentOutDir.getPath(), Collections.singletonList("**/component.properties"), Collections.emptyList());
}
if (!PackageHelper.haveResourcesChanged(log, project, buildContext, "META-INF/services/org/apache/camel/component")) {
return;
}
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/component");
if (f.exists() && f.isDirectory()) {
File[] files = f.listFiles();
if (files != null) {
for (File file : files) {
// skip directories as there may be a sub .resolver directory
if (file.isDirectory()) {
continue;
}
String name = file.getName();
if (name.charAt(0) != '.') {
count++;
if (buffer.length() > 0) {
buffer.append(" ");
}
buffer.append(name);
}
}
}
}
}
if (count > 0) {
Properties properties = new Properties();
String names = buffer.toString();
properties.put("components", 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, "component.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 component 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 ? "components: " : "component: ") + 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/component directory found. Are you sure you have created a Camel component?");
}
}
use of org.apache.maven.model.Resource in project camel by apache.
the class PackageHelper method haveResourcesChanged.
public static boolean haveResourcesChanged(Log log, MavenProject project, BuildContext buildContext, String suffix) {
String baseDir = project.getBasedir().getAbsolutePath();
for (Resource r : project.getBuild().getResources()) {
File file = new File(r.getDirectory());
if (file.isAbsolute()) {
file = new File(r.getDirectory().substring(baseDir.length() + 1));
}
String path = file.getPath() + "/" + suffix;
log.debug("checking if " + path + " (" + r.getDirectory() + "/" + suffix + ") has changed.");
if (buildContext.hasDelta(path)) {
log.debug("Indeed " + suffix + " has changed.");
return true;
}
}
return false;
}
use of org.apache.maven.model.Resource in project camel by apache.
the class SpringBootAutoConfigurationMojo method findDataFormatNames.
private List<String> findDataFormatNames() {
List<String> dataFormatNames = new ArrayList<String>();
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) {
// skip directories as there may be a sub .resolver directory
if (file.isDirectory()) {
continue;
}
String name = file.getName();
if (name.charAt(0) != '.') {
dataFormatNames.add(name);
}
}
}
}
}
return dataFormatNames;
}
use of org.apache.maven.model.Resource in project camel by apache.
the class UpdateReadmeMojo method findComponentNames.
private List<String> findComponentNames() {
List<String> componentNames = new ArrayList<String>();
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/component");
if (f.exists() && f.isDirectory()) {
File[] files = f.listFiles();
if (files != null) {
for (File file : files) {
// skip directories as there may be a sub .resolver directory
if (file.isDirectory()) {
continue;
}
String name = file.getName();
if (name.charAt(0) != '.') {
componentNames.add(name);
}
}
}
}
}
return componentNames;
}
Aggregations