use of org.apache.maven.model.Resource in project sling by apache.
the class ContentPackageProjectConfigurator method configure.
@Override
public void configure(ProjectConfigurationRequest configRequest, IProgressMonitor progressMonitor) throws CoreException {
IProject project = configRequest.getProject();
// delete all previous markers on this pom.xml set by any project configurator
deleteMarkers(configRequest.getPom());
if (!getPreferences().isContentPackageProjectConfiguratorEnabled()) {
trace("M2E project configurator for packing type 'content-package' was disabled through preference.");
return;
}
MavenProject mavenProject = configRequest.getMavenProject();
boolean active = !"false".equalsIgnoreCase(mavenProject.getProperties().getProperty(M2E_ACTIVE));
if (!active) {
trace("M2E project configurator for packing type 'content-package' was disabled with Maven property {0}", M2E_ACTIVE);
return;
}
trace("Configuring {0} with packaging 'content-package'...", mavenProject);
// core configuration for sling ide plugin
Resource folder = MavenProjectUtils.guessJcrRootFolder(mavenProject);
java.nio.file.Path contentSyncPath = mavenProject.getBasedir().toPath().relativize(Paths.get(folder.getDirectory()));
String jcrRootPath = contentSyncPath.toString();
ConfigurationHelper.convertToContentPackageProject(project, progressMonitor, Path.fromOSString(jcrRootPath));
if (getPreferences().isWtpFacetsEnabledInContentPackageProjectConfigurator()) {
new WtpProjectConfigurer(configRequest, project, jcrRootPath).configure(progressMonitor);
trace("WTP facets for {0} added", mavenProject);
} else {
trace("WTP facets for packing type 'content-package' are disabled through preferences.");
}
trace("Done converting .");
}
use of org.apache.maven.model.Resource in project jangaroo-tools by CoreMedia.
the class ExmlXsdMojo method executeExmlc.
@Override
protected void executeExmlc(Exmlc exmlc) {
if (exmlc.getConfig().getValidationMode() != ValidationMode.OFF) {
getLog().info("validating " + exmlc.getConfig().getSourceFiles().size() + " EXML files...");
}
// generate the XSD for that
File xsdFile = exmlc.generateXsd();
projectHelper.attachArtifact(getProject(), "xsd", xsdFile);
getLog().info("xsd-file '" + xsdFile + "' generated.");
// add target/generated-resources to project's resources so XSDs are always packaged:
Resource generatedResources = new Resource();
generatedResources.setDirectory(getGeneratedResourcesDirectory().getPath());
getProject().addResource(generatedResources);
getLog().info("added project resource '" + generatedResources + ".");
}
use of org.apache.maven.model.Resource in project cxf by apache.
the class AbstractCodeGeneratorMojo method getResourceLoader.
private ClassLoader getResourceLoader() throws MojoExecutionException {
if (resourceClassLoader == null) {
try {
List<?> runtimeClasspathElements = project.getRuntimeClasspathElements();
List<?> resources = project.getResources();
List<?> testResources = project.getTestResources();
URL[] runtimeUrls = new URL[runtimeClasspathElements.size() + resources.size() + testResources.size()];
for (int i = 0; i < runtimeClasspathElements.size(); i++) {
String element = (String) runtimeClasspathElements.get(i);
runtimeUrls[i] = new File(element).toURI().toURL();
}
for (int i = 0, j = runtimeClasspathElements.size(); i < resources.size(); i++, j++) {
Resource r = (Resource) resources.get(i);
runtimeUrls[j] = new File(r.getDirectory()).toURI().toURL();
}
for (int i = 0, j = runtimeClasspathElements.size() + resources.size(); i < testResources.size(); i++, j++) {
Resource r = (Resource) testResources.get(i);
runtimeUrls[j] = new File(r.getDirectory()).toURI().toURL();
}
resourceClassLoader = new URLClassLoader(runtimeUrls, Thread.currentThread().getContextClassLoader());
} catch (Exception e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
return resourceClassLoader;
}
use of org.apache.maven.model.Resource in project cxf by apache.
the class AbstractCodegenMoho method checkResources.
private void checkResources() {
File root = project.getBasedir();
Resource sourceRoot = null;
Resource testRoot = null;
File genroot = getGeneratedSourceRoot();
if (genroot != null) {
List<Resource> resources = project.getBuild().getResources();
for (Resource r : resources) {
File d = new File(root, r.getDirectory());
if (d.equals(genroot)) {
sourceRoot = r;
}
}
Resource r2 = scanForResources(genroot, sourceRoot);
if (r2 != sourceRoot) {
r2.setDirectory(getGeneratedSourceRoot().getAbsolutePath());
project.addResource(r2);
}
}
genroot = getGeneratedTestRoot();
if (genroot != null) {
List<Resource> resources = project.getBuild().getTestResources();
for (Resource r : resources) {
File d = new File(root, r.getDirectory());
if (d.equals(genroot)) {
testRoot = r;
}
}
Resource r2 = scanForResources(genroot, testRoot);
if (r2 != testRoot) {
r2.setDirectory(getGeneratedTestRoot().getAbsolutePath());
project.addTestResource(r2);
}
}
}
use of org.apache.maven.model.Resource in project camel by apache.
the class ValidateMojo method execute.
// CHECKSTYLE:OFF
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
CamelCatalog catalog = new DefaultCamelCatalog();
// add activemq as known component
catalog.addComponent("activemq", "org.apache.activemq.camel.component.ActiveMQComponent");
// enable did you mean
catalog.setSuggestionStrategy(new LuceneSuggestionStrategy());
// enable loading other catalog versions dynamically
catalog.setVersionManager(new MavenVersionManager());
// enable caching
catalog.enableCache();
if (downloadVersion) {
String catalogVersion = catalog.getCatalogVersion();
String version = findCamelVersion(project);
if (version != null && !version.equals(catalogVersion)) {
// the project uses a different Camel version so attempt to load it
getLog().info("Downloading Camel version: " + version);
boolean loaded = catalog.loadVersion(version);
if (!loaded) {
getLog().warn("Error downloading Camel version: " + version);
}
}
}
// if using the same version as the camel-maven-plugin we must still load it
if (catalog.getLoadedVersion() == null) {
catalog.loadVersion(catalog.getCatalogVersion());
}
if (catalog.getLoadedVersion() != null) {
getLog().info("Using Camel version: " + catalog.getLoadedVersion());
} else {
// force load version from the camel-maven-plugin
getLog().info("Using Camel version: " + catalog.getCatalogVersion());
}
List<CamelEndpointDetails> endpoints = new ArrayList<>();
List<CamelSimpleExpressionDetails> simpleExpressions = new ArrayList<>();
Set<File> javaFiles = new LinkedHashSet<File>();
Set<File> xmlFiles = new LinkedHashSet<File>();
// find all java route builder classes
if (includeJava) {
List list = project.getCompileSourceRoots();
for (Object obj : list) {
String dir = (String) obj;
findJavaFiles(new File(dir), javaFiles);
}
if (includeTest) {
list = project.getTestCompileSourceRoots();
for (Object obj : list) {
String dir = (String) obj;
findJavaFiles(new File(dir), javaFiles);
}
}
}
// find all xml routes
if (includeXml) {
List list = project.getResources();
for (Object obj : list) {
Resource dir = (Resource) obj;
findXmlFiles(new File(dir.getDirectory()), xmlFiles);
}
if (includeTest) {
list = project.getTestResources();
for (Object obj : list) {
Resource dir = (Resource) obj;
findXmlFiles(new File(dir.getDirectory()), xmlFiles);
}
}
}
for (File file : javaFiles) {
if (matchFile(file)) {
try {
List<CamelEndpointDetails> fileEndpoints = new ArrayList<>();
List<CamelSimpleExpressionDetails> fileSimpleExpressions = new ArrayList<>();
List<String> unparsable = new ArrayList<>();
// parse the java source code and find Camel RouteBuilder classes
String fqn = file.getPath();
String baseDir = ".";
JavaType out = Roaster.parse(file);
// we should only parse java classes (not interfaces and enums etc)
if (out != null && out instanceof JavaClassSource) {
JavaClassSource clazz = (JavaClassSource) out;
RouteBuilderParser.parseRouteBuilderEndpoints(clazz, baseDir, fqn, fileEndpoints, unparsable, includeTest);
RouteBuilderParser.parseRouteBuilderSimpleExpressions(clazz, baseDir, fqn, fileSimpleExpressions);
// add what we found in this file to the total list
endpoints.addAll(fileEndpoints);
simpleExpressions.addAll(fileSimpleExpressions);
// was there any unparsable?
if (logUnparseable && !unparsable.isEmpty()) {
for (String uri : unparsable) {
getLog().warn("Cannot parse endpoint uri " + uri + " in java file " + file);
}
}
}
} catch (Exception e) {
getLog().warn("Error parsing java file " + file + " code due " + e.getMessage(), e);
}
}
}
for (File file : xmlFiles) {
if (matchFile(file)) {
try {
List<CamelEndpointDetails> fileEndpoints = new ArrayList<>();
List<CamelSimpleExpressionDetails> fileSimpleExpressions = new ArrayList<>();
// parse the xml source code and find Camel routes
String fqn = file.getPath();
String baseDir = ".";
InputStream is = new FileInputStream(file);
XmlRouteParser.parseXmlRouteEndpoints(is, baseDir, fqn, fileEndpoints);
is.close();
// need a new stream
is = new FileInputStream(file);
XmlRouteParser.parseXmlRouteSimpleExpressions(is, baseDir, fqn, fileSimpleExpressions);
is.close();
// add what we found in this file to the total list
endpoints.addAll(fileEndpoints);
simpleExpressions.addAll(fileSimpleExpressions);
} catch (Exception e) {
getLog().warn("Error parsing xml file " + file + " code due " + e.getMessage(), e);
}
}
}
int endpointErrors = 0;
int unknownComponents = 0;
int incapableErrors = 0;
for (CamelEndpointDetails detail : endpoints) {
getLog().debug("Validating endpoint: " + detail.getEndpointUri());
EndpointValidationResult result = catalog.validateEndpointProperties(detail.getEndpointUri(), ignoreLenientProperties);
boolean ok = result.isSuccess();
if (!ok && ignoreUnknownComponent && result.getUnknownComponent() != null) {
// if we failed due unknown component then be okay if we should ignore that
unknownComponents++;
ok = true;
}
if (!ok && ignoreIncapable && result.getIncapable() != null) {
// if we failed due incapable then be okay if we should ignore that
incapableErrors++;
ok = true;
}
if (!ok) {
if (result.getUnknownComponent() != null) {
unknownComponents++;
} else if (result.getIncapable() != null) {
incapableErrors++;
} else {
endpointErrors++;
}
StringBuilder sb = new StringBuilder();
sb.append("Endpoint validation error at: ");
if (detail.getClassName() != null && detail.getLineNumber() != null) {
// this is from java code
sb.append(detail.getClassName());
if (detail.getMethodName() != null) {
sb.append(".").append(detail.getMethodName());
}
sb.append("(").append(asSimpleClassName(detail.getClassName())).append(".java:");
sb.append(detail.getLineNumber()).append(")");
} else if (detail.getLineNumber() != null) {
// this is from xml
String fqn = stripRootPath(asRelativeFile(detail.getFileName()));
if (fqn.endsWith(".xml")) {
fqn = fqn.substring(0, fqn.length() - 4);
fqn = asPackageName(fqn);
}
sb.append(fqn);
sb.append("(").append(asSimpleClassName(fqn)).append(".xml:");
sb.append(detail.getLineNumber()).append(")");
} else {
sb.append(detail.getFileName());
}
sb.append("\n\n");
String out = result.summaryErrorMessage(false);
sb.append(out);
sb.append("\n\n");
getLog().warn(sb.toString());
} else if (showAll) {
StringBuilder sb = new StringBuilder();
sb.append("Endpoint validation passsed at: ");
if (detail.getClassName() != null && detail.getLineNumber() != null) {
// this is from java code
sb.append(detail.getClassName());
if (detail.getMethodName() != null) {
sb.append(".").append(detail.getMethodName());
}
sb.append("(").append(asSimpleClassName(detail.getClassName())).append(".java:");
sb.append(detail.getLineNumber()).append(")");
} else if (detail.getLineNumber() != null) {
// this is from xml
String fqn = stripRootPath(asRelativeFile(detail.getFileName()));
if (fqn.endsWith(".xml")) {
fqn = fqn.substring(0, fqn.length() - 4);
fqn = asPackageName(fqn);
}
sb.append(fqn);
sb.append("(").append(asSimpleClassName(fqn)).append(".xml:");
sb.append(detail.getLineNumber()).append(")");
} else {
sb.append(detail.getFileName());
}
sb.append("\n");
sb.append("\n\t").append(result.getUri());
sb.append("\n\n");
getLog().info(sb.toString());
}
}
String endpointSummary;
if (endpointErrors == 0) {
int ok = endpoints.size() - endpointErrors - incapableErrors - unknownComponents;
endpointSummary = String.format("Endpoint validation success: (%s = passed, %s = invalid, %s = incapable, %s = unknown components)", ok, endpointErrors, incapableErrors, unknownComponents);
} else {
int ok = endpoints.size() - endpointErrors - incapableErrors - unknownComponents;
endpointSummary = String.format("Endpoint validation error: (%s = passed, %s = invalid, %s = incapable, %s = unknown components)", ok, endpointErrors, incapableErrors, unknownComponents);
}
if (endpointErrors > 0) {
getLog().warn(endpointSummary);
} else {
getLog().info(endpointSummary);
}
int simpleErrors = 0;
for (CamelSimpleExpressionDetails detail : simpleExpressions) {
SimpleValidationResult result;
boolean predicate = detail.isPredicate();
if (predicate) {
getLog().debug("Validating simple predicate: " + detail.getSimple());
result = catalog.validateSimplePredicate(detail.getSimple());
} else {
getLog().debug("Validating simple expression: " + detail.getSimple());
result = catalog.validateSimpleExpression(detail.getSimple());
}
if (!result.isSuccess()) {
simpleErrors++;
StringBuilder sb = new StringBuilder();
sb.append("Simple validation error at: ");
if (detail.getClassName() != null && detail.getLineNumber() != null) {
// this is from java code
sb.append(detail.getClassName());
if (detail.getMethodName() != null) {
sb.append(".").append(detail.getMethodName());
}
sb.append("(").append(asSimpleClassName(detail.getClassName())).append(".java:");
sb.append(detail.getLineNumber()).append(")");
} else if (detail.getLineNumber() != null) {
// this is from xml
String fqn = stripRootPath(asRelativeFile(detail.getFileName()));
if (fqn.endsWith(".xml")) {
fqn = fqn.substring(0, fqn.length() - 4);
fqn = asPackageName(fqn);
}
sb.append(fqn);
sb.append("(").append(asSimpleClassName(fqn)).append(".xml:");
sb.append(detail.getLineNumber()).append(")");
} else {
sb.append(detail.getFileName());
}
sb.append("\n");
String[] lines = result.getError().split("\n");
for (String line : lines) {
sb.append("\n\t").append(line);
}
sb.append("\n");
getLog().warn(sb.toString());
} else if (showAll) {
StringBuilder sb = new StringBuilder();
sb.append("Simple validation passed at: ");
if (detail.getClassName() != null && detail.getLineNumber() != null) {
// this is from java code
sb.append(detail.getClassName());
if (detail.getMethodName() != null) {
sb.append(".").append(detail.getMethodName());
}
sb.append("(").append(asSimpleClassName(detail.getClassName())).append(".java:");
sb.append(detail.getLineNumber()).append(")");
} else if (detail.getLineNumber() != null) {
// this is from xml
String fqn = stripRootPath(asRelativeFile(detail.getFileName()));
if (fqn.endsWith(".xml")) {
fqn = fqn.substring(0, fqn.length() - 4);
fqn = asPackageName(fqn);
}
sb.append(fqn);
sb.append("(").append(asSimpleClassName(fqn)).append(".xml:");
sb.append(detail.getLineNumber()).append(")");
} else {
sb.append(detail.getFileName());
}
sb.append("\n");
sb.append("\n\t").append(result.getSimple());
sb.append("\n\n");
getLog().info(sb.toString());
}
}
String simpleSummary;
if (simpleErrors == 0) {
int ok = simpleExpressions.size() - simpleErrors;
simpleSummary = String.format("Simple validation success: (%s = passed, %s = invalid)", ok, simpleErrors);
} else {
int ok = simpleExpressions.size() - simpleErrors;
simpleSummary = String.format("Simple validation error: (%s = passed, %s = invalid)", ok, simpleErrors);
}
if (failOnError && (endpointErrors > 0 || simpleErrors > 0)) {
throw new MojoExecutionException(endpointSummary + "\n" + simpleSummary);
}
if (simpleErrors > 0) {
getLog().warn(simpleSummary);
} else {
getLog().info(simpleSummary);
}
}
Aggregations