use of org.apache.maven.plugin.MojoFailureException in project maven-plugins by apache.
the class PmdViolationCheckMojoTest method testFailurePriority.
public void testFailurePriority() throws Exception {
File testPom = new File(getBasedir(), "src/test/resources/unit/default-configuration/default-configuration-plugin-config.xml");
final PmdReport mojo = (PmdReport) lookupMojo("pmd", testPom);
mojo.execute();
testPom = new File(getBasedir(), "src/test/resources/unit/default-configuration/pmd-check-failonpriority-plugin-config.xml");
PmdViolationCheckMojo pmdViolationMojo = (PmdViolationCheckMojo) lookupMojo("check", testPom);
pmdViolationMojo.execute();
testPom = new File(getBasedir(), "src/test/resources/unit/default-configuration/pmd-check-failandwarnonpriority-plugin-config.xml");
pmdViolationMojo = (PmdViolationCheckMojo) lookupMojo("check", testPom);
try {
pmdViolationMojo.execute();
fail("Exception Expected");
} catch (final MojoFailureException e) {
String message = e.getMessage();
if (message.contains("You have 5 PMD violations and 3 warnings.")) {
// expected
System.out.println("Caught expected message: " + e.getMessage());
} else {
throw new AssertionError("Expected: '" + message + "' to contain 'You have 5 PMD violations and 3 warnings.'");
}
}
}
use of org.apache.maven.plugin.MojoFailureException in project karaf by apache.
the class ArchiveMojo method execute.
public void execute() throws MojoExecutionException, MojoFailureException {
getLog().debug("Setting artifact file: " + targetFile);
org.apache.maven.artifact.Artifact artifact = project.getArtifact();
artifact.setFile(targetFile);
try {
//now pack up the server.
if (archiveTarGz) {
archive("tar.gz");
}
if (archiveZip) {
archive("zip");
}
} catch (Exception e) {
throw new MojoExecutionException("Could not archive plugin", e);
}
}
use of org.apache.maven.plugin.MojoFailureException in project karaf by apache.
the class RunMojo method execute.
public void execute() throws MojoExecutionException, MojoFailureException {
if (karafDirectory.exists()) {
getLog().info("Using Karaf container located " + karafDirectory.getAbsolutePath());
} else {
getLog().info("Extracting Karaf container");
try {
File karafArchiveFile = resolveFile(karafDistribution);
extract(karafArchiveFile, karafDirectory);
} catch (Exception e) {
throw new MojoFailureException("Can't extract Karaf container", e);
}
}
getLog().info("Starting Karaf container");
System.setProperty("karaf.home", karafDirectory.getAbsolutePath());
System.setProperty("karaf.base", karafDirectory.getAbsolutePath());
System.setProperty("karaf.data", karafDirectory.getAbsolutePath() + "/data");
System.setProperty("karaf.etc", karafDirectory.getAbsolutePath() + "/etc");
System.setProperty("karaf.instances", karafDirectory.getAbsolutePath() + "/instances");
System.setProperty("karaf.startLocalConsole", "false");
System.setProperty("karaf.startRemoteShell", startSsh);
System.setProperty("karaf.lock", "false");
Main main = new Main(new String[0]);
try {
main.launch();
while (main.getFramework().getState() != Bundle.ACTIVE) {
Thread.sleep(1000);
}
BundleContext bundleContext = main.getFramework().getBundleContext();
Object bootFinished = null;
while (bootFinished == null) {
Thread.sleep(1000);
ServiceReference ref = bundleContext.getServiceReference(BootFinished.class);
if (ref != null) {
bootFinished = bundleContext.getService(ref);
}
}
deploy(bundleContext);
if (keepRunning)
main.awaitShutdown();
main.destroy();
} catch (Throwable e) {
throw new MojoExecutionException("Can't start container", e);
} finally {
System.gc();
}
}
use of org.apache.maven.plugin.MojoFailureException in project karaf by apache.
the class GenerateDescriptorMojo method saveDependencyChanges.
protected void saveDependencyChanges(Collection<Bundle> addedBundles, Collection<Bundle> removedBundles, Collection<Dependency> addedDependencys, Collection<Dependency> removedDependencys, ObjectFactory objectFactory) throws Exception {
File addedFile = new File(filteredDependencyCache.getParentFile(), "dependencies.added.xml");
Features added = toFeatures(addedBundles, addedDependencys, objectFactory);
writeDependencies(added, addedFile);
File removedFile = new File(filteredDependencyCache.getParentFile(), "dependencies.removed.xml");
Features removed = toFeatures(removedBundles, removedDependencys, objectFactory);
writeDependencies(removed, removedFile);
StringWriter out = new StringWriter();
out.write(saveTreeListing());
out.write("Dependencies have changed:\n");
if (!addedBundles.isEmpty() || !addedDependencys.isEmpty()) {
out.write("\tAdded dependencies are saved here: " + addedFile.getAbsolutePath() + "\n");
if (logDependencyChanges) {
JaxbUtil.marshal(added, out);
}
}
if (!removedBundles.isEmpty() || !removedDependencys.isEmpty()) {
out.write("\tRemoved dependencies are saved here: " + removedFile.getAbsolutePath() + "\n");
if (logDependencyChanges) {
JaxbUtil.marshal(removed, out);
}
}
out.write("Delete " + dependencyCache.getAbsolutePath() + " if you are happy with the dependency changes.");
if (failOnDependencyChange) {
throw new MojoFailureException(out.toString());
} else {
getLog().warn(out.toString());
}
}
use of org.apache.maven.plugin.MojoFailureException in project karaf by apache.
the class GenerateServiceMetadata method execute.
public void execute() throws MojoExecutionException, MojoFailureException {
try {
boolean addSourceDirectory = false;
StringBuilder requirements = new StringBuilder();
StringBuilder capabilities = new StringBuilder();
ClassFinder finder = createFinder(classLoader);
List<Class<?>> classes = finder.findAnnotatedClasses(Services.class);
List<Class<?>> activators = new ArrayList<>();
for (Class<?> clazz : classes) {
URL classUrl = clazz.getClassLoader().getResource(clazz.getName().replace('.', '/') + ".class");
URL outputDirectoryUrl = new File(project.getBuild().getOutputDirectory()).toURI().toURL();
if (classUrl == null || !classUrl.getPath().startsWith(outputDirectoryUrl.getPath())) {
System.out.println("Ignoring " + classUrl);
continue;
}
if (BundleActivator.class.isAssignableFrom(clazz)) {
activators.add(clazz);
}
Properties props = new Properties();
Services services = clazz.getAnnotation(Services.class);
if (services != null) {
for (RequireService req : services.requires()) {
String fltWithClass = combine(req.filter(), "(objectClass=" + req.value().getName() + ")");
addServiceReq(requirements, fltWithClass);
props.setProperty(req.value().getName(), req.filter());
}
for (ProvideService cap : services.provides()) {
addServiceCap(capabilities, cap);
}
}
Managed managed = clazz.getAnnotation(Managed.class);
if (managed != null) {
props.setProperty("pid", managed.value());
}
File file = new File(outputDirectory, "OSGI-INF/karaf-tracker/" + clazz.getName());
file.getParentFile().mkdirs();
try (OutputStream os = buildContext.newFileOutputStream(file)) {
props.store(os, null);
}
addSourceDirectory = true;
}
if (addSourceDirectory) {
Resource resource = new Resource();
resource.setDirectory(outputDirectory);
project.addResource(resource);
}
project.getProperties().setProperty(requirementsProperty, requirements.toString());
project.getProperties().setProperty(capabilitiesProperty, capabilities.toString());
if (activators.size() == 1) {
project.getProperties().setProperty(activatorProperty, activators.get(0).getName());
}
project.getProperties().setProperty("BNDExtension-Private-Package", "org.apache.karaf.util.tracker");
project.getProperties().setProperty("BNDPrependExtension-Import-Package", "!org.apache.karaf.util.tracker.annotation");
List<Class<?>> services = finder.findAnnotatedClasses(Service.class);
Set<String> packages = new TreeSet<>();
for (Class<?> clazz : services) {
packages.add(clazz.getPackage().getName());
}
if (!packages.isEmpty()) {
project.getProperties().setProperty("BNDExtension-Karaf-Commands", join(packages, ","));
}
} catch (Exception e) {
throw new MojoExecutionException("Error building commands help", e);
}
}
Aggregations