Search in sources :

Example 61 with MavenXpp3Reader

use of org.apache.maven.model.io.xpp3.MavenXpp3Reader in project zeppelin by apache.

the class SparkIntegrationTest method testInterpreterBasics.

private void testInterpreterBasics() throws IOException, InterpreterException, XmlPullParserException {
    // add jars & packages for testing
    InterpreterSetting sparkInterpreterSetting = interpreterSettingManager.getInterpreterSettingByName("spark");
    sparkInterpreterSetting.setProperty("spark.jars.packages", "com.maxmind.geoip2:geoip2:2.5.0");
    sparkInterpreterSetting.setProperty("SPARK_PRINT_LAUNCH_COMMAND", "true");
    sparkInterpreterSetting.setProperty("zeppelin.python.gatewayserver_address", "127.0.0.1");
    MavenXpp3Reader reader = new MavenXpp3Reader();
    Model model = reader.read(new FileReader("pom.xml"));
    sparkInterpreterSetting.setProperty("spark.jars", new File("target/zeppelin-interpreter-integration-" + model.getVersion() + ".jar").getAbsolutePath());
    // test SparkInterpreter
    Interpreter sparkInterpreter = interpreterFactory.getInterpreter("spark.spark", new ExecutionContext("user1", "note1", "test"));
    InterpreterContext context = new InterpreterContext.Builder().setNoteId("note1").setParagraphId("paragraph_1").build();
    InterpreterResult interpreterResult = sparkInterpreter.interpret("sc.version", context);
    assertEquals(interpreterResult.toString(), InterpreterResult.Code.SUCCESS, interpreterResult.code());
    String detectedSparkVersion = interpreterResult.message().get(0).getData();
    assertTrue(detectedSparkVersion + " doesn't contain " + this.sparkVersion, detectedSparkVersion.contains(this.sparkVersion));
    interpreterResult = sparkInterpreter.interpret("sc.range(1,10).sum()", context);
    assertEquals(interpreterResult.toString(), InterpreterResult.Code.SUCCESS, interpreterResult.code());
    assertTrue(interpreterResult.toString(), interpreterResult.message().get(0).getData().contains("45"));
    interpreterResult = sparkInterpreter.interpret("sc.getConf.get(\"spark.user.name\")", context);
    assertEquals(interpreterResult.toString(), InterpreterResult.Code.SUCCESS, interpreterResult.code());
    assertTrue(interpreterResult.toString(), interpreterResult.message().get(0).getData().contains("user1"));
    // test jars & packages can be loaded correctly
    interpreterResult = sparkInterpreter.interpret("import org.apache.zeppelin.interpreter.integration.DummyClass\n" + "import com.maxmind.geoip2._", context);
    assertEquals(interpreterResult.toString(), InterpreterResult.Code.SUCCESS, interpreterResult.code());
    // test PySparkInterpreter
    Interpreter pySparkInterpreter = interpreterFactory.getInterpreter("spark.pyspark", new ExecutionContext("user1", "note1", "test"));
    interpreterResult = pySparkInterpreter.interpret("sqlContext.createDataFrame([(1,'a'),(2,'b')], ['id','name']).registerTempTable('test')", context);
    assertEquals(interpreterResult.toString(), InterpreterResult.Code.SUCCESS, interpreterResult.code());
    // test IPySparkInterpreter
    Interpreter ipySparkInterpreter = interpreterFactory.getInterpreter("spark.ipyspark", new ExecutionContext("user1", "note1", "test"));
    interpreterResult = ipySparkInterpreter.interpret("sqlContext.table('test').show()", context);
    assertEquals(interpreterResult.toString(), InterpreterResult.Code.SUCCESS, interpreterResult.code());
    // test SparkSQLInterpreter
    Interpreter sqlInterpreter = interpreterFactory.getInterpreter("spark.sql", new ExecutionContext("user1", "note1", "test"));
    interpreterResult = sqlInterpreter.interpret("select count(1) as c from test", context);
    assertEquals(interpreterResult.toString(), InterpreterResult.Code.SUCCESS, interpreterResult.code());
    assertEquals(interpreterResult.toString(), InterpreterResult.Type.TABLE, interpreterResult.message().get(0).getType());
    assertEquals(interpreterResult.toString(), "c\n2\n", interpreterResult.message().get(0).getData());
    // test SparkRInterpreter
    Interpreter sparkrInterpreter = interpreterFactory.getInterpreter("spark.r", new ExecutionContext("user1", "note1", "test"));
    if (isSpark2() || isSpark3()) {
        interpreterResult = sparkrInterpreter.interpret("df <- as.DataFrame(faithful)\nhead(df)", context);
    } else {
        interpreterResult = sparkrInterpreter.interpret("df <- createDataFrame(sqlContext, faithful)\nhead(df)", context);
    }
    assertEquals(interpreterResult.toString(), InterpreterResult.Code.SUCCESS, interpreterResult.code());
    assertEquals(interpreterResult.toString(), InterpreterResult.Type.TEXT, interpreterResult.message().get(0).getType());
    assertTrue(interpreterResult.toString(), interpreterResult.message().get(0).getData().contains("eruptions waiting"));
}
Also used : Interpreter(org.apache.zeppelin.interpreter.Interpreter) ExecutionContext(org.apache.zeppelin.interpreter.ExecutionContext) InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting) Model(org.apache.maven.model.Model) InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) FileReader(java.io.FileReader) InterpreterContext(org.apache.zeppelin.interpreter.InterpreterContext) File(java.io.File)

Example 62 with MavenXpp3Reader

use of org.apache.maven.model.io.xpp3.MavenXpp3Reader in project morphia by mongodb.

the class MorphiaVersionTest method testVersion.

@Test
public void testVersion() throws Exception {
    MavenXpp3Reader reader = new MavenXpp3Reader();
    Model model = reader.read(new FileReader("../pom.xml"));
    Version version = Version.valueOf(model.getVersion());
    String minorVersion = format("%s%s", version.getMajorVersion(), version.getMinorVersion());
    // noinspection MisorderedAssertEqualsArguments
    assertEquals(MorphiaVersion23.class.getSimpleName().replaceAll("\\D", ""), minorVersion);
}
Also used : Version(com.github.zafarkhaja.semver.Version) Model(org.apache.maven.model.Model) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) FileReader(java.io.FileReader) Test(org.testng.annotations.Test)

Example 63 with MavenXpp3Reader

use of org.apache.maven.model.io.xpp3.MavenXpp3Reader in project maven-plugins by apache.

the class AnalyzeDuplicateMojo method execute.

/**
 * {@inheritDoc}
 */
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if (skip) {
        getLog().info("Skipping plugin execution");
        return;
    }
    MavenXpp3Reader pomReader = new MavenXpp3Reader();
    Model model = null;
    Reader reader = null;
    try {
        reader = ReaderFactory.newXmlReader(project.getFile());
        model = pomReader.read(reader);
        reader.close();
        reader = null;
    } catch (Exception e) {
        throw new MojoExecutionException("IOException: " + e.getMessage(), e);
    } finally {
        IOUtil.close(reader);
    }
    Set<String> duplicateDependencies = Collections.emptySet();
    if (model.getDependencies() != null) {
        duplicateDependencies = findDuplicateDependencies(model.getDependencies());
    }
    Set<String> duplicateDependenciesManagement = Collections.emptySet();
    if (model.getDependencyManagement() != null && model.getDependencyManagement().getDependencies() != null) {
        duplicateDependenciesManagement = findDuplicateDependencies(model.getDependencyManagement().getDependencies());
    }
    if (getLog().isInfoEnabled()) {
        StringBuilder sb = new StringBuilder();
        if (!duplicateDependencies.isEmpty()) {
            sb.append("List of duplicate dependencies defined in <dependencies/> in your pom.xml:\n");
            for (Iterator<String> it = duplicateDependencies.iterator(); it.hasNext(); ) {
                String dup = it.next();
                sb.append("\to ").append(dup);
                if (it.hasNext()) {
                    sb.append("\n");
                }
            }
        }
        if (!duplicateDependenciesManagement.isEmpty()) {
            if (sb.length() > 0) {
                sb.append("\n");
            }
            sb.append("List of duplicate dependencies defined in <dependencyManagement/> in your pom.xml:\n");
            for (Iterator<String> it = duplicateDependenciesManagement.iterator(); it.hasNext(); ) {
                String dup = it.next();
                sb.append("\to ").append(dup);
                if (it.hasNext()) {
                    sb.append("\n");
                }
            }
        }
        if (sb.length() > 0) {
            getLog().info(sb.toString());
        } else {
            getLog().info("No duplicate dependencies found in <dependencies/> or in <dependencyManagement/>");
        }
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Model(org.apache.maven.model.Model) Reader(java.io.Reader) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 64 with MavenXpp3Reader

use of org.apache.maven.model.io.xpp3.MavenXpp3Reader in project maven-plugins by apache.

the class PomUtils method loadPom.

/**
 * Loads the (raw) model from the specified POM file.
 *
 * @param pomFile The path to the POM file to load, must not be <code>null</code>.
 * @return The raw model, never <code>null</code>.
 * @throws MojoExecutionException If the POM file could not be loaded.
 */
public static Model loadPom(File pomFile) throws MojoExecutionException {
    Reader reader = null;
    try {
        reader = ReaderFactory.newXmlReader(pomFile);
        final Model model = new MavenXpp3Reader().read(reader, false);
        reader.close();
        reader = null;
        return model;
    } catch (XmlPullParserException e) {
        throw new MojoExecutionException("Failed to parse POM: " + pomFile, e);
    } catch (IOException e) {
        throw new MojoExecutionException("Failed to read POM: " + pomFile, e);
    } finally {
        IOUtil.close(reader);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Model(org.apache.maven.model.Model) Reader(java.io.Reader) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException)

Example 65 with MavenXpp3Reader

use of org.apache.maven.model.io.xpp3.MavenXpp3Reader in project maven-plugins by apache.

the class Project001Stub method readModelFromFile.

static Model readModelFromFile(File file) throws IOException, XmlPullParserException {
    MavenXpp3Reader pomReader = new MavenXpp3Reader();
    XmlStreamReader reader = null;
    try {
        reader = ReaderFactory.newXmlReader(file);
        final Model model = pomReader.read(reader);
        reader.close();
        reader = null;
        return model;
    } finally {
        IOUtil.close(reader);
    }
}
Also used : Model(org.apache.maven.model.Model) XmlStreamReader(org.codehaus.plexus.util.xml.XmlStreamReader) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader)

Aggregations

MavenXpp3Reader (org.apache.maven.model.io.xpp3.MavenXpp3Reader)66 Model (org.apache.maven.model.Model)61 IOException (java.io.IOException)40 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)34 FileReader (java.io.FileReader)28 File (java.io.File)18 FileNotFoundException (java.io.FileNotFoundException)17 Reader (java.io.Reader)15 Path (java.nio.file.Path)12 PluginException (org.bimserver.shared.exceptions.PluginException)11 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)10 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)10 SPluginBundle (org.bimserver.interfaces.objects.SPluginBundle)9 ArtifactDescriptorException (org.eclipse.aether.resolution.ArtifactDescriptorException)9 DelegatingClassLoader (org.bimserver.plugins.classloaders.DelegatingClassLoader)8 InputStream (java.io.InputStream)7 FileInputStream (java.io.FileInputStream)6 DefaultArtifactVersion (org.apache.maven.artifact.versioning.DefaultArtifactVersion)6 MavenXpp3Writer (org.apache.maven.model.io.xpp3.MavenXpp3Writer)6 StringReader (java.io.StringReader)5