Search in sources :

Example 36 with MojoExecutionException

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);
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) HashMap(java.util.HashMap) JMXConnector(javax.management.remote.JMXConnector) ArrayList(java.util.ArrayList) MBeanServerConnection(javax.management.MBeanServerConnection) RuntimeSshException(org.apache.sshd.common.RuntimeSshException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ObjectName(javax.management.ObjectName)

Example 37 with MojoExecutionException

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");
        }
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Bundle(org.osgi.framework.Bundle) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 38 with MojoExecutionException

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());
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) StringWriter(java.io.StringWriter) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) File(java.io.File) RuntimeSshException(org.apache.sshd.common.RuntimeSshException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) PrintWriter(java.io.PrintWriter)

Example 39 with MojoExecutionException

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);
    }
}
Also used : JavaDependencyContextRefiner(org.sonatype.aether.util.graph.transformer.JavaDependencyContextRefiner) DependencyCollectionException(org.sonatype.aether.collection.DependencyCollectionException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) CollectResult(org.sonatype.aether.collection.CollectResult) AndDependencySelector(org.sonatype.aether.util.graph.selector.AndDependencySelector) Dependency(org.sonatype.aether.graph.Dependency) CollectRequest(org.sonatype.aether.collection.CollectRequest) ChainedDependencyGraphTransformer(org.sonatype.aether.util.graph.transformer.ChainedDependencyGraphTransformer) OptionalDependencySelector(org.sonatype.aether.util.graph.selector.OptionalDependencySelector) DefaultRepositorySystemSession(org.sonatype.aether.util.DefaultRepositorySystemSession) JavaEffectiveScopeCalculator(org.sonatype.aether.util.graph.transformer.JavaEffectiveScopeCalculator) DependencyGraphTransformer(org.sonatype.aether.collection.DependencyGraphTransformer) ChainedDependencyGraphTransformer(org.sonatype.aether.util.graph.transformer.ChainedDependencyGraphTransformer) ConflictMarker(org.sonatype.aether.util.graph.transformer.ConflictMarker) ExclusionDependencySelector(org.sonatype.aether.util.graph.selector.ExclusionDependencySelector)

Example 40 with MojoExecutionException

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);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MavenResourcesExecution(org.apache.maven.shared.filtering.MavenResourcesExecution) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MavenFilteringException(org.apache.maven.shared.filtering.MavenFilteringException) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1221 IOException (java.io.IOException)656 File (java.io.File)572 MojoFailureException (org.apache.maven.plugin.MojoFailureException)275 Artifact (org.apache.maven.artifact.Artifact)162 ArrayList (java.util.ArrayList)151 FileInputStream (java.io.FileInputStream)77 MavenProject (org.apache.maven.project.MavenProject)76 HashMap (java.util.HashMap)68 Properties (java.util.Properties)63 FileOutputStream (java.io.FileOutputStream)61 Map (java.util.Map)60 URL (java.net.URL)59 MalformedURLException (java.net.MalformedURLException)57 ArchiverException (org.codehaus.plexus.archiver.ArchiverException)52 FileWriter (java.io.FileWriter)50 List (java.util.List)49 URLClassLoader (java.net.URLClassLoader)45 LinkedHashSet (java.util.LinkedHashSet)40 InputStream (java.io.InputStream)38