use of org.apache.maven.plugin.MojoExecutionException in project karaf by apache.
the class DeployMojo method deployWithJmx.
protected void deployWithJmx(List<String> locations) throws MojoExecutionException {
try {
JMXServiceURL jmxServiceURL = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/" + instance);
ArrayList<String> list = new ArrayList<>();
if (user != null)
list.add(user);
if (password != null)
list.add(password);
HashMap env = new HashMap();
String[] credentials = list.toArray(new String[list.size()]);
env.put(JMXConnector.CREDENTIALS, credentials);
JMXConnector jmxConnector = null;
if (credentials.length > 0)
jmxConnector = JMXConnectorFactory.connect(jmxServiceURL, env);
else
jmxConnector = JMXConnectorFactory.connect(jmxServiceURL);
MBeanServerConnection mBeanServerConnection = jmxConnector.getMBeanServerConnection();
for (String location : locations) {
mBeanServerConnection.invoke(new ObjectName("org.apache.karaf:type=bundle,name=*"), "install", new Object[] { location, true }, new String[] { "java.lang.String", "boolean" });
}
} catch (Exception e) {
throw new MojoExecutionException("Can't deploy using JMX", e);
}
}
use of org.apache.maven.plugin.MojoExecutionException in project karaf by apache.
the class RunMojo method deploy.
private void deploy(BundleContext bundleContext) throws MojoExecutionException {
if (deployProjectArtifact) {
File artifact = project.getArtifact().getFile();
if (artifact != null && artifact.exists()) {
if (project.getPackaging().equals("bundle")) {
try {
Bundle bundle = bundleContext.installBundle(artifact.toURI().toURL().toString());
bundle.start();
} catch (Exception e) {
throw new MojoExecutionException("Can't deploy project artifact in container", e);
}
} else {
throw new MojoExecutionException("Packaging " + project.getPackaging() + " is not supported");
}
} else {
throw new MojoExecutionException("Project artifact doesn't exist");
}
}
}
use of org.apache.maven.plugin.MojoExecutionException in project karaf by apache.
the class ClientMojo method execute.
public void execute() throws MojoExecutionException {
// Add commands from scripts to already declared commands
if (scripts != null) {
for (File script : scripts) {
try (BufferedReader br = new BufferedReader(new FileReader(script))) {
String line;
while ((line = br.readLine()) != null) {
line = line.trim();
if (line.isEmpty()) {
continue;
}
commands.add(line);
}
} catch (Exception e) {
throw new MojoExecutionException(e, e.getMessage(), e.toString());
}
}
}
if (commands == null || commands.isEmpty()) {
getLog().warn("No OSGi command was specified");
return;
}
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw, true);
for (String cmd : commands) {
getLog().info(cmd);
pw.println(cmd);
}
execute(sw.toString());
}
use of org.apache.maven.plugin.MojoExecutionException in project karaf by apache.
the class Dependency30Helper method getDependencyTree.
private DependencyNode getDependencyTree(Artifact artifact) throws MojoExecutionException {
try {
CollectRequest collectRequest = new CollectRequest(new Dependency(artifact, "compile"), null, projectRepositories);
DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(repositorySystemSession);
session.setDependencySelector(new AndDependencySelector(new OptionalDependencySelector(), new ScopeDependencySelector1(), new ExclusionDependencySelector()));
DependencyGraphTransformer transformer = new ChainedDependencyGraphTransformer(new ConflictMarker(), new JavaEffectiveScopeCalculator(), new JavaDependencyContextRefiner());
session.setDependencyGraphTransformer(transformer);
CollectResult result = repositorySystem.collectDependencies(session, collectRequest);
return result.getRoot();
} catch (DependencyCollectionException e) {
throw new MojoExecutionException("Cannot build project dependency tree", e);
}
}
use of org.apache.maven.plugin.MojoExecutionException in project karaf by apache.
the class GenerateDescriptorMojo method filter.
protected void filter(File sourceFile, File targetFile) throws MojoExecutionException {
try {
if (StringUtils.isEmpty(encoding)) {
getLog().warn("File encoding has not been set, using platform encoding " + ReaderFactory.FILE_ENCODING + ", i.e. build is platform dependent!");
}
targetFile.getParentFile().mkdirs();
final MavenResourcesExecution mre = new MavenResourcesExecution();
mre.setMavenProject(project);
mre.setMavenSession(mavenSession);
mre.setFilters(null);
mre.setEscapedBackslashesInFilePath(true);
final LinkedHashSet<String> delimiters = new LinkedHashSet<>();
delimiters.add("${*}");
mre.setDelimiters(delimiters);
@SuppressWarnings("rawtypes") List filters = mavenFileFilter.getDefaultFilterWrappers(mre);
mavenFileFilter.copyFile(sourceFile, targetFile, true, filters, encoding, true);
} catch (MavenFilteringException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
Aggregations